summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2011-01-29 17:48:13 (GMT)
committerRemko Tronçon <git@el-tramo.be>2011-01-29 18:45:34 (GMT)
commit869c52b244c2d03313e9eda83fac05bf0fc3a619 (patch)
tree63f0518e15d0c23ece6eb55733c2ef44f710bf01 /Swiften/Examples/SendFile
parent11a7f5c48ea9c90e9adaaa06a96e0a9116234bff (diff)
downloadswift-contrib-869c52b244c2d03313e9eda83fac05bf0fc3a619.zip
swift-contrib-869c52b244c2d03313e9eda83fac05bf0fc3a619.tar.bz2
Added some experimental Jingle classes.
Diffstat (limited to 'Swiften/Examples/SendFile')
-rw-r--r--Swiften/Examples/SendFile/.gitignore1
-rw-r--r--Swiften/Examples/SendFile/ReceiveFile.cpp116
-rw-r--r--Swiften/Examples/SendFile/SConscript4
3 files changed, 120 insertions, 1 deletions
diff --git a/Swiften/Examples/SendFile/.gitignore b/Swiften/Examples/SendFile/.gitignore
index f8b7625..b40e042 100644
--- a/Swiften/Examples/SendFile/.gitignore
+++ b/Swiften/Examples/SendFile/.gitignore
@@ -1 +1,2 @@
SendFile
+ReceiveFile
diff --git a/Swiften/Examples/SendFile/ReceiveFile.cpp b/Swiften/Examples/SendFile/ReceiveFile.cpp
new file mode 100644
index 0000000..a6386cd
--- /dev/null
+++ b/Swiften/Examples/SendFile/ReceiveFile.cpp
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2010 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <boost/bind.hpp>
+#include <boost/filesystem.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+
+#include <Swiften/Client/Client.h>
+#include <Swiften/Network/BoostNetworkFactories.h>
+#include <Swiften/EventLoop/SimpleEventLoop.h>
+#include <Swiften/Client/ClientXMLTracer.h>
+#include <Swiften/FileTransfer/IncomingFileTransferManager.h>
+#include <Swiften/FileTransfer/FileWriteBytestream.h>
+#include <Swiften/Jingle/JingleSessionManager.h>
+
+using namespace Swift;
+
+SimpleEventLoop eventLoop;
+BoostNetworkFactories networkFactories(&eventLoop);
+
+int exitCode = 2;
+
+class FileReceiver {
+ public:
+ FileReceiver(const JID& jid, const String& password) : jid(jid), password(password), jingleSessionManager(NULL), incomingFileTransferManager(NULL) {
+ client = new Swift::Client(&eventLoop, &networkFactories, jid, password);
+ client->onConnected.connect(boost::bind(&FileReceiver::handleConnected, this));
+ client->onDisconnected.connect(boost::bind(&FileReceiver::handleDisconnected, this, _1));
+ //tracer = new ClientXMLTracer(client);
+ }
+
+ ~FileReceiver() {
+ delete incomingFileTransferManager;
+ delete jingleSessionManager;
+ //delete tracer;
+ client->onDisconnected.disconnect(boost::bind(&FileReceiver::handleDisconnected, this, _1));
+ client->onConnected.disconnect(boost::bind(&FileReceiver::handleConnected, this));
+ delete client;
+ }
+
+ void start() {
+ client->connect();
+ }
+
+ void stop() {
+ foreach(const IncomingFileTransfer::ref transfer, incomingFileTransfers) {
+ //transfer->stop();
+ }
+ client->disconnect();
+ }
+
+ private:
+ void handleConnected() {
+ client->sendPresence(Presence::create());
+ jingleSessionManager = new JingleSessionManager(client->getIQRouter());
+ incomingFileTransferManager = new IncomingFileTransferManager(jingleSessionManager, client->getIQRouter());
+ incomingFileTransferManager->onIncomingFileTransfer.connect(boost::bind(&FileReceiver::handleIncomingFileTransfer, this, _1));
+ }
+
+ void handleIncomingFileTransfer(IncomingFileTransfer::ref transfer) {
+ incomingFileTransfers.push_back(transfer);
+ transfer->accept(boost::make_shared<FileWriteBytestream>("out"));
+ //transfer->onFinished.connect(boost::bind(&FileReceiver::handleFileTransferFinished, this, _1));
+ //transfer->start();
+ }
+
+ void handleDisconnected(const boost::optional<ClientError>&) {
+ std::cerr << "Error!" << std::endl;
+ exit(-1);
+ }
+
+ /*
+ void handleFileTransferFinished(const boost::optional<FileTransferError>& error) {
+ std::cout << "File transfer finished" << std::endl;
+ if (error) {
+ exit(-1);
+ }
+ else {
+ exit(0);
+ }
+ }*/
+
+ void exit(int code) {
+ exitCode = code;
+ stop();
+ eventLoop.stop();
+ }
+
+ private:
+ JID jid;
+ String password;
+ Client* client;
+ ClientXMLTracer* tracer;
+ JingleSessionManager* jingleSessionManager;
+ IncomingFileTransferManager* incomingFileTransferManager;
+ std::vector<IncomingFileTransfer::ref> incomingFileTransfers;
+};
+
+
+int main(int argc, char* argv[]) {
+ if (argc != 3) {
+ std::cerr << "Usage: " << argv[0] << " <jid> <password>" << std::endl;
+ return -1;
+ }
+
+ JID jid(argv[1]);
+ FileReceiver fileReceiver(jid, String(argv[2]));
+ fileReceiver.start();
+
+ eventLoop.run();
+
+ return exitCode;
+}
diff --git a/Swiften/Examples/SendFile/SConscript b/Swiften/Examples/SendFile/SConscript
index 50cbe40..6986f22 100644
--- a/Swiften/Examples/SendFile/SConscript
+++ b/Swiften/Examples/SendFile/SConscript
@@ -10,4 +10,6 @@ myenv.MergeFlags(myenv.get("SQLITE_FLAGS", {}))
myenv.MergeFlags(myenv.get("LIBXML_FLAGS", ""))
myenv.MergeFlags(myenv.get("EXPAT_FLAGS", ""))
myenv.MergeFlags(myenv["PLATFORM_FLAGS"])
-tester = myenv.Program("SendFile", ["SendFile.cpp"])
+
+myenv.Program("SendFile", ["SendFile.cpp"])
+myenv.Program("ReceiveFile", ["ReceiveFile.cpp"])