00001
00002
00003
00004
00005
00006
00007 #pragma once
00008
00009 #include <boost/shared_ptr.hpp>
00010
00011 #include <Swiften/Base/API.h>
00012 #include <Swiften/Base/boost_bsignals.h>
00013 #include <Swiften/Base/Error.h>
00014 #include <Swiften/Network/PlatformDomainNameResolver.h>
00015 #include <Swiften/Component/ComponentConnector.h>
00016 #include <Swiften/Component/ComponentSession.h>
00017 #include <Swiften/Component/ComponentError.h>
00018 #include <Swiften/Elements/Presence.h>
00019 #include <Swiften/Elements/Message.h>
00020 #include <Swiften/JID/JID.h>
00021 #include <string>
00022 #include <Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h>
00023 #include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h>
00024 #include <Swiften/Component/ComponentSessionStanzaChannel.h>
00025 #include <Swiften/Entity/Entity.h>
00026 #include <Swiften/Base/SafeByteArray.h>
00027
00028 namespace Swift {
00029 class IQRouter;
00030 class NetworkFactories;
00031 class ComponentSession;
00032 class BasicSessionStream;
00033
00044 class SWIFTEN_API CoreComponent : public Entity {
00045 public:
00046 CoreComponent(EventLoop* eventLoop, NetworkFactories* networkFactories, const JID& jid, const std::string& secret);
00047 ~CoreComponent();
00048
00049 void connect(const std::string& host, int port);
00050 void disconnect();
00051
00052 void sendMessage(boost::shared_ptr<Message>);
00053 void sendPresence(boost::shared_ptr<Presence>);
00054
00055 IQRouter* getIQRouter() const {
00056 return iqRouter_;
00057 }
00058
00059 StanzaChannel* getStanzaChannel() const {
00060 return stanzaChannel_;
00061 }
00062
00063 bool isAvailable() const {
00064 return stanzaChannel_->isAvailable();
00065 }
00066
00070 const JID& getJID() const {
00071 return jid_;
00072 }
00073
00074 public:
00075 boost::signal<void (const ComponentError&)> onError;
00076 boost::signal<void ()> onConnected;
00077 boost::signal<void (const SafeByteArray&)> onDataRead;
00078 boost::signal<void (const SafeByteArray&)> onDataWritten;
00079
00080 boost::signal<void (boost::shared_ptr<Message>)> onMessageReceived;
00081 boost::signal<void (boost::shared_ptr<Presence>) > onPresenceReceived;
00082
00083 private:
00084 void handleConnectorFinished(boost::shared_ptr<Connection>);
00085 void handleStanzaChannelAvailableChanged(bool available);
00086 void handleSessionFinished(boost::shared_ptr<Error>);
00087 void handleDataRead(const SafeByteArray&);
00088 void handleDataWritten(const SafeByteArray&);
00089
00090 private:
00091 EventLoop* eventLoop;
00092 NetworkFactories* networkFactories;
00093 PlatformDomainNameResolver resolver_;
00094 JID jid_;
00095 std::string secret_;
00096 ComponentSessionStanzaChannel* stanzaChannel_;
00097 IQRouter* iqRouter_;
00098 ComponentConnector::ref connector_;
00099 boost::shared_ptr<Connection> connection_;
00100 boost::shared_ptr<BasicSessionStream> sessionStream_;
00101 boost::shared_ptr<ComponentSession> session_;
00102 bool disconnectRequested_;
00103 };
00104 }