diff options
| author | Remko Tronçon <git@el-tramo.be> | 2009-11-20 18:23:22 (GMT) |
|---|---|---|
| committer | Remko Tronçon <git@el-tramo.be> | 2009-11-20 18:23:22 (GMT) |
| commit | 059ace39c432a89845e245604af03f5f71e1da84 (patch) | |
| tree | 0c756410892adac6be4640cec4391c26798459a7 /Swiften/Client/Client.cpp | |
| parent | cf8e2aca04c9a4021448f829e5b264dad25b28c8 (diff) | |
| download | swift-059ace39c432a89845e245604af03f5f71e1da84.zip swift-059ace39c432a89845e245604af03f5f71e1da84.tar.bz2 | |
Added ClientSessionTest.
Diffstat (limited to 'Swiften/Client/Client.cpp')
| -rw-r--r-- | Swiften/Client/Client.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/Swiften/Client/Client.cpp b/Swiften/Client/Client.cpp index 2a6d8a0..2bd039a 100644 --- a/Swiften/Client/Client.cpp +++ b/Swiften/Client/Client.cpp @@ -16,97 +16,97 @@ namespace Swift { Client::Client(const JID& jid, const String& password) : IQRouter(this), jid_(jid), password_(password) { connectionFactory_ = new BoostConnectionFactory(&MainBoostIOServiceThread::getInstance().getIOService()); timerFactory_ = new BoostTimerFactory(&MainBoostIOServiceThread::getInstance().getIOService()); tlsLayerFactory_ = new PlatformTLSLayerFactory(); } Client::~Client() { if (session_ || connection_) { std::cerr << "Warning: Client not disconnected properly" << std::endl; } delete tlsLayerFactory_; delete timerFactory_; delete connectionFactory_; } bool Client::isAvailable() { return session_; } void Client::connect() { assert(!connector_); connector_ = boost::shared_ptr<Connector>(new Connector(jid_.getDomain(), &resolver_, connectionFactory_)); connector_->onConnectFinished.connect(boost::bind(&Client::handleConnectorFinished, this, _1)); connector_->start(); } void Client::handleConnectorFinished(boost::shared_ptr<Connection> connection) { // TODO: Add domain name resolver error connector_.reset(); if (!connection) { onError(ClientError::ConnectionError); } else { assert(!connection_); connection_ = connection; assert(!sessionStream_); sessionStream_ = boost::shared_ptr<BasicSessionStream>(new BasicSessionStream(connection_, &payloadParserFactories_, &payloadSerializers_, tlsLayerFactory_, timerFactory_)); if (!certificate_.isEmpty()) { sessionStream_->setTLSCertificate(PKCS12Certificate(certificate_, password_)); } sessionStream_->onDataRead.connect(boost::bind(&Client::handleDataRead, this, _1)); sessionStream_->onDataWritten.connect(boost::bind(&Client::handleDataWritten, this, _1)); sessionStream_->initialize(); - session_ = boost::shared_ptr<ClientSession>(new ClientSession(jid_, sessionStream_)); + session_ = ClientSession::create(jid_, sessionStream_); session_->onInitialized.connect(boost::bind(boost::ref(onConnected))); session_->onFinished.connect(boost::bind(&Client::handleSessionFinished, this, _1)); session_->onNeedCredentials.connect(boost::bind(&Client::handleNeedCredentials, this)); session_->onElementReceived.connect(boost::bind(&Client::handleElement, this, _1)); session_->start(); } } void Client::disconnect() { if (session_) { session_->finish(); session_.reset(); } closeConnection(); } void Client::closeConnection() { if (sessionStream_) { sessionStream_.reset(); } if (connection_) { connection_->disconnect(); connection_.reset(); } } void Client::send(boost::shared_ptr<Stanza> stanza) { session_->sendElement(stanza); } void Client::sendIQ(boost::shared_ptr<IQ> iq) { send(iq); } void Client::sendMessage(boost::shared_ptr<Message> message) { send(message); } void Client::sendPresence(boost::shared_ptr<Presence> presence) { send(presence); } String Client::getNewIQID() { return idGenerator_.generateID(); } void Client::handleElement(boost::shared_ptr<Element> element) { boost::shared_ptr<Message> message = boost::dynamic_pointer_cast<Message>(element); |
Swift