summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Examples/SendFile')
-rw-r--r--Swiften/Examples/SendFile/ReceiveFile.cpp32
-rw-r--r--Swiften/Examples/SendFile/SConscript4
-rw-r--r--Swiften/Examples/SendFile/SendFile.cpp18
3 files changed, 24 insertions, 30 deletions
diff --git a/Swiften/Examples/SendFile/ReceiveFile.cpp b/Swiften/Examples/SendFile/ReceiveFile.cpp
index 39b3cc3..c777fee 100644
--- a/Swiften/Examples/SendFile/ReceiveFile.cpp
+++ b/Swiften/Examples/SendFile/ReceiveFile.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.
*/
@@ -10,6 +10,7 @@
#include <iostream>
#include <Swiften/Elements/Presence.h>
+#include <Swiften/Base/Log.h>
#include <Swiften/Base/foreach.h>
#include <Swiften/Client/Client.h>
#include <Swiften/Elements/DiscoInfo.h>
@@ -20,24 +21,22 @@
#include <Swiften/FileTransfer/IncomingFileTransferManager.h>
#include <Swiften/FileTransfer/FileWriteBytestream.h>
#include <Swiften/Jingle/JingleSessionManager.h>
-#include <Swiften/FileTransfer/DefaultLocalJingleTransportCandidateGeneratorFactory.h>
-#include <Swiften/FileTransfer/DefaultRemoteJingleTransportCandidateSelectorFactory.h>
#include <Swiften/FileTransfer/SOCKS5BytestreamRegistry.h>
#include <Swiften/FileTransfer/FileTransferManager.h>
using namespace Swift;
-SimpleEventLoop eventLoop;
-BoostNetworkFactories networkFactories(&eventLoop);
+static SimpleEventLoop eventLoop;
+static BoostNetworkFactories networkFactories(&eventLoop);
-int exitCode = 2;
+static int exitCode = 2;
static const std::string CLIENT_NAME = "Swiften FT Test";
static const std::string CLIENT_NODE = "http://swift.im";
class FileReceiver {
public:
- FileReceiver(const JID& jid, const std::string& password) : jid(jid), password(password), jingleSessionManager(NULL), incomingFileTransferManager(NULL) {
+ FileReceiver(const JID& jid, const std::string& password) : jid(jid), password(password) {
client = new Swift::Client(jid, password, &networkFactories);
client->onConnected.connect(boost::bind(&FileReceiver::handleConnected, this));
client->onDisconnected.connect(boost::bind(&FileReceiver::handleDisconnected, this, _1));
@@ -64,8 +63,7 @@ class FileReceiver {
private:
void handleConnected() {
- Swift::logging = true;
- client->getFileTransferManager()->startListeningOnPort(9999);
+ Log::setLogLevel(Log::debug);
client->getFileTransferManager()->onIncomingFileTransfer.connect(boost::bind(&FileReceiver::handleIncomingFileTransfer, this, _1));
DiscoInfo discoInfo;
@@ -83,9 +81,9 @@ class FileReceiver {
void handleIncomingFileTransfer(IncomingFileTransfer::ref transfer) {
SWIFT_LOG(debug) << "foo" << std::endl;
incomingFileTransfers.push_back(transfer);
- transfer->accept(boost::make_shared<FileWriteBytestream>("out"));
- //transfer->onFinished.connect(boost::bind(&FileReceiver::handleFileTransferFinished, this, _1));
- //transfer->start();
+ boost::shared_ptr<FileWriteBytestream> out = boost::make_shared<FileWriteBytestream>("out");
+ transfer->onFinished.connect(boost::bind(&FileReceiver::handleFileTransferFinished, this, _1, out));
+ transfer->accept(out);
}
void handleDisconnected(const boost::optional<ClientError>&) {
@@ -93,16 +91,18 @@ class FileReceiver {
exit(-1);
}
- /*
- void handleFileTransferFinished(const boost::optional<FileTransferError>& error) {
+ void handleFileTransferFinished(
+ const boost::optional<FileTransferError>& error,
+ boost::shared_ptr<FileWriteBytestream> out) {
std::cout << "File transfer finished" << std::endl;
+ out->close();
if (error) {
exit(-1);
}
else {
exit(0);
}
- }*/
+ }
void exit(int code) {
exitCode = code;
@@ -115,8 +115,6 @@ class FileReceiver {
std::string password;
Client* client;
ClientXMLTracer* tracer;
- JingleSessionManager* jingleSessionManager;
- IncomingFileTransferManager* incomingFileTransferManager;
std::vector<IncomingFileTransfer::ref> incomingFileTransfers;
};
diff --git a/Swiften/Examples/SendFile/SConscript b/Swiften/Examples/SendFile/SConscript
index d335513..e0f1256 100644
--- a/Swiften/Examples/SendFile/SConscript
+++ b/Swiften/Examples/SendFile/SConscript
@@ -1,8 +1,8 @@
Import("env")
myenv = env.Clone()
-myenv.MergeFlags(myenv["SWIFTEN_FLAGS"])
-myenv.MergeFlags(myenv["SWIFTEN_DEP_FLAGS"])
+myenv.UseFlags(myenv["SWIFTEN_FLAGS"])
+myenv.UseFlags(myenv["SWIFTEN_DEP_FLAGS"])
myenv.Program("SendFile", ["SendFile.cpp"])
myenv.Program("ReceiveFile", ["ReceiveFile.cpp"])
diff --git a/Swiften/Examples/SendFile/SendFile.cpp b/Swiften/Examples/SendFile/SendFile.cpp
index a926170..b056842 100644
--- a/Swiften/Examples/SendFile/SendFile.cpp
+++ b/Swiften/Examples/SendFile/SendFile.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.
*/
@@ -11,6 +11,7 @@
#include <Swiften/Client/Client.h>
#include <Swiften/Elements/Presence.h>
+#include <Swiften/Base/Log.h>
#include <Swiften/Network/BoostTimer.h>
#include <Swiften/Network/TimerFactory.h>
#include <Swiften/Network/BoostNetworkFactories.h>
@@ -25,20 +26,16 @@
#include <Swiften/FileTransfer/OutgoingFileTransfer.h>
#include <Swiften/Jingle/JingleSessionManager.h>
#include <Swiften/Disco/EntityCapsManager.h>
-#include <Swiften/FileTransfer/DefaultLocalJingleTransportCandidateGeneratorFactory.h>
-#include <Swiften/FileTransfer/DefaultRemoteJingleTransportCandidateSelectorFactory.h>
#include <Swiften/Base/ByteArray.h>
-#include <Swiften/StringCodecs/MD5.h>
-#include <Swiften/StringCodecs/SHA1.h>
#include <Swiften/StringCodecs/Hexify.h>
#include <Swiften/FileTransfer/FileTransferManager.h>
using namespace Swift;
-SimpleEventLoop eventLoop;
-BoostNetworkFactories networkFactories(&eventLoop);
+static SimpleEventLoop eventLoop;
+static BoostNetworkFactories networkFactories(&eventLoop);
-int exitCode = 2;
+static int exitCode = 2;
class FileSender {
public:
@@ -66,9 +63,8 @@ class FileSender {
void handleConnected() {
client->sendPresence(Presence::create());
- client->getFileTransferManager()->startListeningOnPort(19999);
//ByteArray fileData;
- //readByteArrayFromFile(fileData, file.string());
+ //readByteArrayFromFile(fileData, file);
// gather file information
/*StreamInitiationFileInfo fileInfo;
@@ -143,7 +139,7 @@ int main(int argc, char* argv[]) {
JID sender(argv[1]);
JID recipient(argv[3]);
- Swift::logging = true;
+ Log::setLogLevel(Log::debug);
FileSender fileSender(sender, std::string(argv[2]), recipient, boost::filesystem::path(argv[4]));
fileSender.start();
{