• Main Page
  • Classes
  • Files
  • File List

Swiften/Client/CoreClient.h

00001 /*
00002  * Copyright (c) 2010-2012 Remko Tronçon
00003  * Licensed under the GNU General Public License v3.
00004  * See Documentation/Licenses/GPLv3.txt for more information.
00005  */
00006 
00007 #pragma once
00008 
00009 #include <string>
00010 #include <boost/shared_ptr.hpp>
00011 
00012 #include <Swiften/Base/API.h>
00013 #include <Swiften/Base/boost_bsignals.h>
00014 #include <Swiften/Entity/Entity.h>
00015 #include <Swiften/JID/JID.h>
00016 #include <Swiften/Client/ClientError.h>
00017 #include <Swiften/Client/ClientOptions.h>
00018 #include <Swiften/Base/SafeByteArray.h>
00019 #include <Swiften/TLS/CertificateWithKey.h>
00020 
00021 namespace Swift {
00022   class ChainedConnector;
00023   class Message;
00024   class Presence;
00025   class Error;
00026   class IQRouter;
00027   class TLSContextFactory;
00028   class ConnectionFactory;
00029   class Connection;
00030   class TimerFactory;
00031   class ClientSession;
00032   class StanzaChannel;
00033   class Stanza;
00034   class SessionStream;
00035   class CertificateTrustChecker;
00036   class NetworkFactories;
00037   class ClientSessionStanzaChannel;
00038 
00049   class SWIFTEN_API CoreClient : public Entity {
00050     public: 
00055       CoreClient(const JID& jid, const SafeByteArray& password, NetworkFactories* networkFactories);
00056       ~CoreClient();
00057 
00063       void setCertificate(CertificateWithKey::ref certificate);
00064 
00071       void connect(const ClientOptions& = ClientOptions());
00072 
00076       void disconnect();
00077 
00081       void sendMessage(boost::shared_ptr<Message>);
00082 
00086       void sendPresence(boost::shared_ptr<Presence>);
00087 
00091       void sendData(const std::string& data);
00092 
00096       IQRouter* getIQRouter() const {
00097         return iqRouter_;
00098       }
00099 
00104       bool isAvailable() const;
00105 
00111       bool isActive() const;
00112 
00117       const JID& getJID() const;
00118 
00127       bool getStreamManagementEnabled() const;
00128 
00132       bool isStreamEncrypted() const;
00133 
00134       StanzaChannel* getStanzaChannel() const;
00135 
00144       void setCertificateTrustChecker(CertificateTrustChecker*);
00145 
00146     public:
00153       boost::signal<void (const boost::optional<ClientError>&)> onDisconnected;
00154 
00159       boost::signal<void ()> onConnected;
00160 
00167       boost::signal<void (const SafeByteArray&)> onDataRead;
00168 
00175       boost::signal<void (const SafeByteArray&)> onDataWritten;
00176 
00180       boost::signal<void (boost::shared_ptr<Message>)> onMessageReceived;
00181 
00185       boost::signal<void (boost::shared_ptr<Presence>) > onPresenceReceived;
00186 
00193       boost::signal<void (boost::shared_ptr<Stanza>)> onStanzaAcked;
00194 
00195     protected:
00196       boost::shared_ptr<ClientSession> getSession() const {
00197         return session_;
00198       }
00199 
00200       NetworkFactories* getNetworkFactories() const {
00201         return networkFactories;
00202       }
00203 
00207       virtual void handleConnected() {};
00208 
00209     private:
00210       void handleConnectorFinished(boost::shared_ptr<Connection>, boost::shared_ptr<Error> error);
00211       void handleStanzaChannelAvailableChanged(bool available);
00212       void handleSessionFinished(boost::shared_ptr<Error>);
00213       void handleNeedCredentials();
00214       void handleDataRead(const SafeByteArray&);
00215       void handleDataWritten(const SafeByteArray&);
00216       void handlePresenceReceived(boost::shared_ptr<Presence>);
00217       void handleMessageReceived(boost::shared_ptr<Message>);
00218       void handleStanzaAcked(boost::shared_ptr<Stanza>);
00219       void purgePassword();
00220       void bindSessionToStream();
00221 
00222       void resetConnector();
00223       void resetSession();
00224       void forceReset();
00225 
00226     private:
00227       JID jid_;
00228       SafeByteArray password_;
00229       NetworkFactories* networkFactories;
00230       ClientSessionStanzaChannel* stanzaChannel_;
00231       IQRouter* iqRouter_;
00232       ClientOptions options;
00233       boost::shared_ptr<ChainedConnector> connector_;
00234       std::vector<ConnectionFactory*> proxyConnectionFactories;
00235       boost::shared_ptr<Connection> connection_;
00236       boost::shared_ptr<SessionStream> sessionStream_;
00237       boost::shared_ptr<ClientSession> session_;
00238       CertificateWithKey::ref certificate_;
00239       bool disconnectRequested_;
00240       CertificateTrustChecker* certificateTrustChecker;
00241   };
00242 }

Generated on Fri Oct 12 2012 21:00:19 for Swiften by  doxygen 1.7.1