diff options
Diffstat (limited to 'Swiften/Jingle/JingleSessionImpl.cpp')
-rw-r--r-- | Swiften/Jingle/JingleSessionImpl.cpp | 47 |
1 files changed, 31 insertions, 16 deletions
diff --git a/Swiften/Jingle/JingleSessionImpl.cpp b/Swiften/Jingle/JingleSessionImpl.cpp index 98c5196..ff22d11 100644 --- a/Swiften/Jingle/JingleSessionImpl.cpp +++ b/Swiften/Jingle/JingleSessionImpl.cpp @@ -1,4 +1,4 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2013 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. @@ -8,7 +8,10 @@ #include <boost/smart_ptr/make_shared.hpp> +#include <boost/bind.hpp> +#include <algorithm> #include <Swiften/Parser/PayloadParsers/JingleParser.h> #include <Swiften/Jingle/JingleContentID.h> +#include <Swiften/Jingle/JingleSessionListener.h> #include <Swiften/Elements/JingleContentPayload.h> #include <Swiften/Queries/Request.h> @@ -17,6 +20,5 @@ #include <Swiften/Base/Log.h> -#include "Swiften/Serializer/PayloadSerializers/JinglePayloadSerializer.h" -#include "Swiften/FileTransfer/JingleTransport.h" +#include <Swiften/Serializer/PayloadSerializers/JinglePayloadSerializer.h> namespace Swift { @@ -28,9 +30,9 @@ JingleSessionImpl::JingleSessionImpl(const JID& initiator, const JID& peerJID, c void JingleSessionImpl::handleIncomingAction(JinglePayload::ref action) { if (action->getAction() == JinglePayload::SessionTerminate) { - onSessionTerminateReceived(action->getReason()); + notifyListeners(&JingleSessionListener::handleSessionTerminateReceived, action->getReason()); return; } if (action->getAction() == JinglePayload::SessionInfo) { - onSessionInfoReceived(action); + notifyListeners(&JingleSessionListener::handleSessionInfoReceived, action); return; } @@ -46,17 +48,17 @@ void JingleSessionImpl::handleIncomingAction(JinglePayload::ref action) { switch(action->getAction()) { case JinglePayload::SessionAccept: - onSessionAcceptReceived(contentID, description, transport); + notifyListeners(&JingleSessionListener::handleSessionAcceptReceived, contentID, description, transport); return; case JinglePayload::TransportAccept: - onTransportAcceptReceived(contentID, transport); + notifyListeners(&JingleSessionListener::handleTransportAcceptReceived, contentID, transport); return; case JinglePayload::TransportInfo: - onTransportInfoReceived(contentID, transport); + notifyListeners(&JingleSessionListener::handleTransportInfoReceived, contentID, transport); return; case JinglePayload::TransportReject: - onTransportRejectReceived(contentID, transport); + notifyListeners(&JingleSessionListener::handleTransportRejectReceived, contentID, transport); return; case JinglePayload::TransportReplace: - onTransportReplaceReceived(contentID, transport); + notifyListeners(&JingleSessionListener::handleTransportReplaceReceived, contentID, transport); return; // following unused Jingle actions @@ -77,5 +79,5 @@ void JingleSessionImpl::handleIncomingAction(JinglePayload::ref action) { return; } - std::cerr << "Unhandled Jingle action!!! ACTION: " << action->getAction() << std::endl; + assert(false); } @@ -137,5 +139,5 @@ void JingleSessionImpl::sendTransportAccept(const JingleContentID& id, JingleTra } -void JingleSessionImpl::sendTransportInfo(const JingleContentID& id, JingleTransportPayload::ref transPayload) { +std::string JingleSessionImpl::sendTransportInfo(const JingleContentID& id, JingleTransportPayload::ref transPayload) { JinglePayload::ref payload = createPayload(); @@ -147,5 +149,5 @@ void JingleSessionImpl::sendTransportInfo(const JingleContentID& id, JingleTrans payload->addPayload(content); - sendSetRequest(payload); + return sendSetRequest(payload); } @@ -168,7 +170,11 @@ void JingleSessionImpl::sendTransportReplace(const JingleContentID& id, JingleTr -void JingleSessionImpl::sendSetRequest(JinglePayload::ref payload) { - boost::shared_ptr<GenericRequest<JinglePayload> > request = boost::make_shared<GenericRequest<JinglePayload> >(IQ::Set, peerJID, payload, iqRouter); - request->send(); +std::string JingleSessionImpl::sendSetRequest(JinglePayload::ref payload) { + boost::shared_ptr<GenericRequest<JinglePayload> > request = boost::make_shared<GenericRequest<JinglePayload> >( + IQ::Set, peerJID, payload, iqRouter); + pendingRequests.insert(std::make_pair( + request, + request->onResponse.connect(boost::bind(&JingleSessionImpl::handleRequestResponse, this, request)))); + return request->send(); } @@ -181,4 +187,13 @@ JinglePayload::ref JingleSessionImpl::createPayload() const { } +void JingleSessionImpl::handleRequestResponse(RequestRef request) { + RequestsMap::iterator i = pendingRequests.find(request); + assert(i != pendingRequests.end()); + if (i->first->getPayloadGeneric()->getAction() == JinglePayload::TransportInfo) { + notifyListeners(&JingleSessionListener::handleTransportInfoAcknowledged, i->first->getID()); + } + i->second.disconnect(); + pendingRequests.erase(i); +} |