summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Jingle')
-rw-r--r--Swiften/Jingle/AbstractJingleSessionListener.cpp42
-rw-r--r--Swiften/Jingle/AbstractJingleSessionListener.h26
-rw-r--r--Swiften/Jingle/FakeJingleSession.cpp3
-rw-r--r--Swiften/Jingle/FakeJingleSession.h25
-rw-r--r--Swiften/Jingle/JingleSession.cpp10
-rw-r--r--Swiften/Jingle/JingleSession.h23
-rw-r--r--Swiften/Jingle/JingleSessionImpl.cpp45
-rw-r--r--Swiften/Jingle/JingleSessionImpl.h14
-rw-r--r--Swiften/Jingle/JingleSessionListener.cpp12
-rw-r--r--Swiften/Jingle/JingleSessionListener.h40
-rw-r--r--Swiften/Jingle/SConscript2
11 files changed, 197 insertions, 45 deletions
diff --git a/Swiften/Jingle/AbstractJingleSessionListener.cpp b/Swiften/Jingle/AbstractJingleSessionListener.cpp
new file mode 100644
index 0000000..eaa1a47
--- /dev/null
+++ b/Swiften/Jingle/AbstractJingleSessionListener.cpp
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Swiften/Jingle/AbstractJingleSessionListener.h>
+
+#include <Swiften/Base/Log.h>
+
+using namespace Swift;
+
+void AbstractJingleSessionListener::handleSessionAcceptReceived(const JingleContentID&, boost::shared_ptr<JingleDescription>, boost::shared_ptr<JingleTransportPayload>) {
+ SWIFT_LOG(warning) << "Unimplemented" << std::endl;
+}
+
+void AbstractJingleSessionListener::handleSessionInfoReceived(boost::shared_ptr<JinglePayload>) {
+ SWIFT_LOG(warning) << "Unimplemented" << std::endl;
+}
+
+void AbstractJingleSessionListener::handleSessionTerminateReceived(boost::optional<JinglePayload::Reason>) {
+ SWIFT_LOG(warning) << "Unimplemented" << std::endl;
+}
+
+void AbstractJingleSessionListener::handleTransportAcceptReceived(const JingleContentID&, boost::shared_ptr<JingleTransportPayload>) {
+ SWIFT_LOG(warning) << "Unimplemented" << std::endl;
+}
+
+void AbstractJingleSessionListener::handleTransportInfoReceived(const JingleContentID&, boost::shared_ptr<JingleTransportPayload>) {
+ SWIFT_LOG(warning) << "Unimplemented" << std::endl;
+}
+
+void AbstractJingleSessionListener::handleTransportRejectReceived(const JingleContentID&, boost::shared_ptr<JingleTransportPayload>) {
+ SWIFT_LOG(warning) << "Unimplemented" << std::endl;
+}
+
+void AbstractJingleSessionListener::handleTransportReplaceReceived(const JingleContentID&, boost::shared_ptr<JingleTransportPayload>) {
+ SWIFT_LOG(warning) << "Unimplemented" << std::endl;
+}
+
+void AbstractJingleSessionListener::handleTransportInfoAcknowledged(const std::string&) {
+}
diff --git a/Swiften/Jingle/AbstractJingleSessionListener.h b/Swiften/Jingle/AbstractJingleSessionListener.h
new file mode 100644
index 0000000..4f76675
--- /dev/null
+++ b/Swiften/Jingle/AbstractJingleSessionListener.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/API.h>
+#include <Swiften/Base/Override.h>
+#include <Swiften/Jingle/JingleSessionListener.h>
+
+namespace Swift {
+ class SWIFTEN_API AbstractJingleSessionListener : public JingleSessionListener {
+ public:
+ virtual void handleSessionAcceptReceived(const JingleContentID&, boost::shared_ptr<JingleDescription>, boost::shared_ptr<JingleTransportPayload>) SWIFTEN_OVERRIDE;
+ virtual void handleSessionInfoReceived(boost::shared_ptr<JinglePayload>) SWIFTEN_OVERRIDE;
+ virtual void handleSessionTerminateReceived(boost::optional<JinglePayload::Reason>) SWIFTEN_OVERRIDE;
+ virtual void handleTransportAcceptReceived(const JingleContentID&, boost::shared_ptr<JingleTransportPayload>) SWIFTEN_OVERRIDE;
+ virtual void handleTransportInfoReceived(const JingleContentID&, boost::shared_ptr<JingleTransportPayload>) SWIFTEN_OVERRIDE;
+ virtual void handleTransportRejectReceived(const JingleContentID&, boost::shared_ptr<JingleTransportPayload>) SWIFTEN_OVERRIDE;
+ virtual void handleTransportReplaceReceived(const JingleContentID&, boost::shared_ptr<JingleTransportPayload>) SWIFTEN_OVERRIDE;
+ virtual void handleTransportInfoAcknowledged(const std::string& id) SWIFTEN_OVERRIDE;
+ };
+}
+
diff --git a/Swiften/Jingle/FakeJingleSession.cpp b/Swiften/Jingle/FakeJingleSession.cpp
index 82ec631..1df106a 100644
--- a/Swiften/Jingle/FakeJingleSession.cpp
+++ b/Swiften/Jingle/FakeJingleSession.cpp
@@ -33,8 +33,9 @@ void FakeJingleSession::sendAccept(const JingleContentID& id, JingleDescription:
calledCommands.push_back(AcceptCall(id, desc, payload));
}
-void FakeJingleSession::sendTransportInfo(const JingleContentID& id, JingleTransportPayload::ref payload) {
+std::string FakeJingleSession::sendTransportInfo(const JingleContentID& id, JingleTransportPayload::ref payload) {
calledCommands.push_back(InfoTransportCall(id, payload));
+ return idGenerator.generateID();
}
void FakeJingleSession::sendTransportAccept(const JingleContentID& id, JingleTransportPayload::ref payload) {
diff --git a/Swiften/Jingle/FakeJingleSession.h b/Swiften/Jingle/FakeJingleSession.h
index ec5cb09..651ac5f 100644
--- a/Swiften/Jingle/FakeJingleSession.h
+++ b/Swiften/Jingle/FakeJingleSession.h
@@ -4,6 +4,12 @@
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
#pragma once
#include <boost/shared_ptr.hpp>
@@ -12,7 +18,9 @@
#include <boost/variant.hpp>
#include <Swiften/Base/API.h>
+#include <Swiften/Base/SimpleIDGenerator.h>
#include <Swiften/Base/boost_bsignals.h>
+#include <Swiften/Base/Override.h>
#include <Swiften/JID/JID.h>
#include <Swiften/Elements/JinglePayload.h>
#include <Swiften/Jingle/JingleSession.h>
@@ -79,16 +87,17 @@ namespace Swift {
FakeJingleSession(const JID& initiator, const std::string& id);
virtual ~FakeJingleSession();
- virtual void sendInitiate(const JingleContentID&, JingleDescription::ref, JingleTransportPayload::ref);
- virtual void sendTerminate(JinglePayload::Reason::Type reason);
- virtual void sendInfo(boost::shared_ptr<Payload>);
- virtual void sendAccept(const JingleContentID&, JingleDescription::ref, JingleTransportPayload::ref = JingleTransportPayload::ref());
- virtual void sendTransportInfo(const JingleContentID&, JingleTransportPayload::ref);
- virtual void sendTransportAccept(const JingleContentID&, JingleTransportPayload::ref);
- virtual void sendTransportReject(const JingleContentID&, JingleTransportPayload::ref);
- virtual void sendTransportReplace(const JingleContentID&, JingleTransportPayload::ref);
+ virtual void sendInitiate(const JingleContentID&, JingleDescription::ref, JingleTransportPayload::ref) SWIFTEN_OVERRIDE;
+ virtual void sendTerminate(JinglePayload::Reason::Type reason) SWIFTEN_OVERRIDE;
+ virtual void sendInfo(boost::shared_ptr<Payload>) SWIFTEN_OVERRIDE;
+ virtual void sendAccept(const JingleContentID&, JingleDescription::ref, JingleTransportPayload::ref = JingleTransportPayload::ref()) SWIFTEN_OVERRIDE;
+ virtual std::string sendTransportInfo(const JingleContentID&, JingleTransportPayload::ref) SWIFTEN_OVERRIDE;
+ virtual void sendTransportAccept(const JingleContentID&, JingleTransportPayload::ref) SWIFTEN_OVERRIDE;
+ virtual void sendTransportReject(const JingleContentID&, JingleTransportPayload::ref) SWIFTEN_OVERRIDE;
+ virtual void sendTransportReplace(const JingleContentID&, JingleTransportPayload::ref) SWIFTEN_OVERRIDE;
public:
std::vector<Command> calledCommands;
+ SimpleIDGenerator idGenerator;
};
}
diff --git a/Swiften/Jingle/JingleSession.cpp b/Swiften/Jingle/JingleSession.cpp
index eb649f3..7e09014 100644
--- a/Swiften/Jingle/JingleSession.cpp
+++ b/Swiften/Jingle/JingleSession.cpp
@@ -1,5 +1,5 @@
/*
- * 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.
*/
@@ -7,8 +7,12 @@
#include <Swiften/Jingle/JingleSession.h>
#include <boost/smart_ptr/make_shared.hpp>
+#include <algorithm>
+#include <boost/function.hpp>
-namespace Swift {
+#include <Swiften/Base/foreach.h>
+
+using namespace Swift;
JingleSession::JingleSession(const JID& initiator, const std::string& id) : initiator(initiator), id(id) {
// initiator must always be a full JID; session lookup based on it wouldn't work otherwise
@@ -18,5 +22,3 @@ JingleSession::JingleSession(const JID& initiator, const std::string& id) : init
JingleSession::~JingleSession() {
}
-
-}
diff --git a/Swiften/Jingle/JingleSession.h b/Swiften/Jingle/JingleSession.h
index 150ad79..8307311 100644
--- a/Swiften/Jingle/JingleSession.h
+++ b/Swiften/Jingle/JingleSession.h
@@ -1,24 +1,26 @@
/*
- * Copyright (c) 2011 Remko Tronçon
+ * Copyright (c) 2011-2013 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
#pragma once
+#include <string>
+#include <vector>
#include <boost/shared_ptr.hpp>
#include <boost/optional.hpp>
-#include <string>
-
+#include <Swiften/Base/Listenable.h>
#include <Swiften/Base/boost_bsignals.h>
#include <Swiften/JID/JID.h>
#include <Swiften/Elements/JinglePayload.h>
namespace Swift {
+ class JingleSessionListener;
class JingleContentID;
- class JingleSession {
+ class JingleSession : public Listenable<JingleSessionListener> {
public:
typedef boost::shared_ptr<JingleSession> ref;
@@ -32,26 +34,19 @@ namespace Swift {
const std::string& getID() const {
return id;
}
+
virtual void sendInitiate(const JingleContentID&, JingleDescription::ref, JingleTransportPayload::ref) = 0;
virtual void sendTerminate(JinglePayload::Reason::Type reason) = 0;
virtual void sendInfo(boost::shared_ptr<Payload>) = 0;
virtual void sendAccept(const JingleContentID&, JingleDescription::ref, JingleTransportPayload::ref = JingleTransportPayload::ref()) = 0;
- virtual void sendTransportInfo(const JingleContentID&, JingleTransportPayload::ref) = 0;
+ virtual std::string sendTransportInfo(const JingleContentID&, JingleTransportPayload::ref) = 0;
virtual void sendTransportAccept(const JingleContentID&, JingleTransportPayload::ref) = 0;
virtual void sendTransportReject(const JingleContentID&, JingleTransportPayload::ref) = 0;
virtual void sendTransportReplace(const JingleContentID&, JingleTransportPayload::ref) = 0;
- public:
- boost::signal<void (const JingleContentID&, JingleDescription::ref, JingleTransportPayload::ref)> onSessionAcceptReceived;
- boost::signal<void (JinglePayload::ref)> onSessionInfoReceived;
- boost::signal<void (boost::optional<JinglePayload::Reason>)> onSessionTerminateReceived;
- boost::signal<void (const JingleContentID&, JingleTransportPayload::ref)> onTransportAcceptReceived;
- boost::signal<void (const JingleContentID&, JingleTransportPayload::ref)> onTransportInfoReceived;
- boost::signal<void (const JingleContentID&, JingleTransportPayload::ref)> onTransportRejectReceived;
- boost::signal<void (const JingleContentID&, JingleTransportPayload::ref)> onTransportReplaceReceived;
-
private:
JID initiator;
std::string id;
+ std::vector<JingleSessionListener*> listeners;
};
}
diff --git a/Swiften/Jingle/JingleSessionImpl.cpp b/Swiften/Jingle/JingleSessionImpl.cpp
index 53092fc..ff22d11 100644
--- a/Swiften/Jingle/JingleSessionImpl.cpp
+++ b/Swiften/Jingle/JingleSessionImpl.cpp
@@ -1,5 +1,5 @@
/*
- * 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.
*/
@@ -7,17 +7,19 @@
#include <Swiften/Jingle/JingleSessionImpl.h>
#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>
#include <Swiften/Queries/GenericRequest.h>
#include <Swiften/Base/Log.h>
-#include "Swiften/Serializer/PayloadSerializers/JinglePayloadSerializer.h"
-#include "Swiften/FileTransfer/JingleTransport.h"
+#include <Swiften/Serializer/PayloadSerializers/JinglePayloadSerializer.h>
namespace Swift {
@@ -27,11 +29,11 @@ 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;
}
@@ -45,19 +47,19 @@ void JingleSessionImpl::handleIncomingAction(JinglePayload::ref action) {
JingleTransportPayload::ref transport = content->getTransports().empty() ? JingleTransportPayload::ref() : content->getTransports()[0];
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
case JinglePayload::ContentAccept:
@@ -136,7 +138,7 @@ void JingleSessionImpl::sendTransportAccept(const JingleContentID& id, JingleTra
sendSetRequest(payload);
}
-void JingleSessionImpl::sendTransportInfo(const JingleContentID& id, JingleTransportPayload::ref transPayload) {
+std::string JingleSessionImpl::sendTransportInfo(const JingleContentID& id, JingleTransportPayload::ref transPayload) {
JinglePayload::ref payload = createPayload();
JingleContentPayload::ref content = boost::make_shared<JingleContentPayload>();
@@ -146,7 +148,7 @@ void JingleSessionImpl::sendTransportInfo(const JingleContentID& id, JingleTrans
payload->setAction(JinglePayload::TransportInfo);
payload->addPayload(content);
- sendSetRequest(payload);
+ return sendSetRequest(payload);
}
void JingleSessionImpl::sendTransportReject(const JingleContentID& /* id */, JingleTransportPayload::ref /* transPayload */) {
@@ -167,9 +169,13 @@ 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();
}
@@ -180,6 +186,15 @@ JinglePayload::ref JingleSessionImpl::createPayload() const {
return payload;
}
+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);
+}
}
diff --git a/Swiften/Jingle/JingleSessionImpl.h b/Swiften/Jingle/JingleSessionImpl.h
index 3c1559a..b7f4a55 100644
--- a/Swiften/Jingle/JingleSessionImpl.h
+++ b/Swiften/Jingle/JingleSessionImpl.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011 Remko Tronçon
+ * Copyright (c) 2011-2013 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -7,11 +7,14 @@
#pragma once
#include <boost/shared_ptr.hpp>
+#include <map>
#include <Swiften/Jingle/JingleSession.h>
+#include <Swiften/Queries/GenericRequest.h>
namespace Swift {
class IQRouter;
+ class Request;
class JingleSessionImpl : public JingleSession {
friend class JingleResponder;
@@ -24,19 +27,24 @@ namespace Swift {
virtual void sendTerminate(JinglePayload::Reason::Type reason);
virtual void sendInfo(boost::shared_ptr<Payload>);
virtual void sendAccept(const JingleContentID&, JingleDescription::ref, JingleTransportPayload::ref);
- virtual void sendTransportInfo(const JingleContentID&, JingleTransportPayload::ref);
+ virtual std::string sendTransportInfo(const JingleContentID&, JingleTransportPayload::ref);
virtual void sendTransportAccept(const JingleContentID&, JingleTransportPayload::ref);
virtual void sendTransportReject(const JingleContentID&, JingleTransportPayload::ref);
virtual void sendTransportReplace(const JingleContentID&, JingleTransportPayload::ref);
private:
+ typedef boost::shared_ptr<GenericRequest<JinglePayload> > RequestRef;
+
void handleIncomingAction(JinglePayload::ref);
- void sendSetRequest(JinglePayload::ref payload);
+ std::string sendSetRequest(JinglePayload::ref payload);
JinglePayload::ref createPayload() const;
+ void handleRequestResponse(RequestRef);
private:
IQRouter *iqRouter;
JID peerJID;
+ typedef std::map<RequestRef, boost::bsignals::connection > RequestsMap;
+ RequestsMap pendingRequests;
};
}
diff --git a/Swiften/Jingle/JingleSessionListener.cpp b/Swiften/Jingle/JingleSessionListener.cpp
new file mode 100644
index 0000000..75d3be9
--- /dev/null
+++ b/Swiften/Jingle/JingleSessionListener.cpp
@@ -0,0 +1,12 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Swiften/Jingle/JingleSessionListener.h>
+
+using namespace Swift;
+
+JingleSessionListener::~JingleSessionListener() {
+}
diff --git a/Swiften/Jingle/JingleSessionListener.h b/Swiften/Jingle/JingleSessionListener.h
new file mode 100644
index 0000000..e1270c4
--- /dev/null
+++ b/Swiften/Jingle/JingleSessionListener.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/API.h>
+#include <Swiften/Elements/JinglePayload.h>
+
+namespace Swift {
+ class JingleContentID;
+ class JingleTransportPayload;
+ class JingleDescription;
+
+ class SWIFTEN_API JingleSessionListener {
+ public:
+ virtual ~JingleSessionListener();
+
+ virtual void handleSessionAcceptReceived(
+ const JingleContentID&,
+ boost::shared_ptr<JingleDescription>,
+ boost::shared_ptr<JingleTransportPayload>) = 0;
+ virtual void handleSessionInfoReceived(boost::shared_ptr<JinglePayload>) = 0;
+ virtual void handleSessionTerminateReceived(boost::optional<JinglePayload::Reason>) = 0;
+ virtual void handleTransportAcceptReceived(
+ const JingleContentID&,
+ boost::shared_ptr<JingleTransportPayload>) = 0;
+ virtual void handleTransportInfoReceived(
+ const JingleContentID&,
+ boost::shared_ptr<JingleTransportPayload>) = 0;
+ virtual void handleTransportRejectReceived(
+ const JingleContentID&, boost::shared_ptr<JingleTransportPayload>) = 0;
+ virtual void handleTransportReplaceReceived(
+ const JingleContentID&, boost::shared_ptr<JingleTransportPayload>) = 0;
+
+ virtual void handleTransportInfoAcknowledged(const std::string& id) = 0;
+ };
+}
diff --git a/Swiften/Jingle/SConscript b/Swiften/Jingle/SConscript
index 5dcf293..546c1b2 100644
--- a/Swiften/Jingle/SConscript
+++ b/Swiften/Jingle/SConscript
@@ -2,6 +2,8 @@ Import("swiften_env")
sources = [
"JingleSession.cpp",
+ "JingleSessionListener.cpp",
+ "AbstractJingleSessionListener.cpp",
"JingleSessionImpl.cpp",
"IncomingJingleSessionHandler.cpp",
"JingleSessionManager.cpp",