/* * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include #include #include namespace Swift { void ComponentSessionStanzaChannel::setSession(std::shared_ptr session) { assert(!this->session); this->session = session; session->onInitialized.connect(boost::bind(&ComponentSessionStanzaChannel::handleSessionInitialized, this)); session->onFinished.connect(boost::bind(&ComponentSessionStanzaChannel::handleSessionFinished, this, _1)); session->onStanzaReceived.connect(boost::bind(&ComponentSessionStanzaChannel::handleStanza, this, _1)); } void ComponentSessionStanzaChannel::sendIQ(std::shared_ptr iq) { send(iq); } void ComponentSessionStanzaChannel::sendMessage(std::shared_ptr message) { send(message); } void ComponentSessionStanzaChannel::sendPresence(std::shared_ptr presence) { send(presence); } std::string ComponentSessionStanzaChannel::getNewIQID() { return idGenerator.generateID(); } void ComponentSessionStanzaChannel::send(std::shared_ptr stanza) { if (!isAvailable()) { std::cerr << "Warning: Component: Trying to send a stanza while disconnected." << std::endl; return; } session->sendStanza(stanza); } void ComponentSessionStanzaChannel::handleSessionFinished(std::shared_ptr) { session->onFinished.disconnect(boost::bind(&ComponentSessionStanzaChannel::handleSessionFinished, this, _1)); session->onStanzaReceived.disconnect(boost::bind(&ComponentSessionStanzaChannel::handleStanza, this, _1)); session->onInitialized.disconnect(boost::bind(&ComponentSessionStanzaChannel::handleSessionInitialized, this)); session.reset(); onAvailableChanged(false); } void ComponentSessionStanzaChannel::handleStanza(std::shared_ptr stanza) { std::shared_ptr message = std::dynamic_pointer_cast(stanza); if (message) { onMessageReceived(message); return; } std::shared_ptr presence = std::dynamic_pointer_cast(stanza); if (presence) { onPresenceReceived(presence); return; } std::shared_ptr iq = std::dynamic_pointer_cast(stanza); if (iq) { onIQReceived(iq); return; } } void ComponentSessionStanzaChannel::handleSessionInitialized() { onAvailableChanged(true); } }