summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Examples')
-rw-r--r--Swiften/Examples/BenchTool/BenchTool.cpp10
-rw-r--r--Swiften/Examples/ConnectivityTest/ConnectivityTest.cpp18
-rw-r--r--Swiften/Examples/ConnectivityTest/SConscript4
-rw-r--r--Swiften/Examples/LinkLocalTool/SConscript4
-rw-r--r--Swiften/Examples/NetworkTool/main.cpp14
-rw-r--r--Swiften/Examples/ParserTester/SConscript4
-rw-r--r--Swiften/Examples/SendFile/ReceiveFile.cpp32
-rw-r--r--Swiften/Examples/SendFile/SConscript4
-rw-r--r--Swiften/Examples/SendFile/SendFile.cpp18
-rw-r--r--Swiften/Examples/SendMessage/SConscript4
-rw-r--r--Swiften/Examples/SendMessage/SendMessage.cpp18
11 files changed, 62 insertions, 68 deletions
diff --git a/Swiften/Examples/BenchTool/BenchTool.cpp b/Swiften/Examples/BenchTool/BenchTool.cpp
index ba6cf84..9725b7e 100644
--- a/Swiften/Examples/BenchTool/BenchTool.cpp
+++ b/Swiften/Examples/BenchTool/BenchTool.cpp
@@ -20,13 +20,13 @@
using namespace Swift;
-SimpleEventLoop eventLoop;
-BoostNetworkFactories networkFactories(&eventLoop);
-int numberOfConnectedClients = 0;
-int numberOfInstances = 100;
+static SimpleEventLoop eventLoop;
+static BoostNetworkFactories networkFactories(&eventLoop);
+static int numberOfConnectedClients = 0;
+static int numberOfInstances = 100;
-void handleConnected() {
+static void handleConnected() {
numberOfConnectedClients++;
std::cout << "Connected " << numberOfConnectedClients << std::endl;
}
diff --git a/Swiften/Examples/ConnectivityTest/ConnectivityTest.cpp b/Swiften/Examples/ConnectivityTest/ConnectivityTest.cpp
index 636a52a..df2a23d 100644
--- a/Swiften/Examples/ConnectivityTest/ConnectivityTest.cpp
+++ b/Swiften/Examples/ConnectivityTest/ConnectivityTest.cpp
@@ -21,15 +21,15 @@ using namespace Swift;
enum ExitCodes {OK = 0, CANNOT_CONNECT, CANNOT_AUTH, NO_RESPONSE, DISCO_ERROR};
-SimpleEventLoop eventLoop;
-BoostNetworkFactories networkFactories(&eventLoop);
+static SimpleEventLoop eventLoop;
+static BoostNetworkFactories networkFactories(&eventLoop);
-Client* client = 0;
-JID recipient;
-int exitCode = CANNOT_CONNECT;
-boost::bsignals::connection errorConnection;
+static Client* client = 0;
+static JID recipient;
+static int exitCode = CANNOT_CONNECT;
+static boost::bsignals::connection errorConnection;
-void handleServerDiscoInfoResponse(boost::shared_ptr<DiscoInfo> /*info*/, ErrorPayload::ref error) {
+static void handleServerDiscoInfoResponse(boost::shared_ptr<DiscoInfo> /*info*/, ErrorPayload::ref error) {
if (!error) {
errorConnection.disconnect();
client->disconnect();
@@ -41,14 +41,14 @@ void handleServerDiscoInfoResponse(boost::shared_ptr<DiscoInfo> /*info*/, ErrorP
}
}
-void handleConnected() {
+static void handleConnected() {
exitCode = NO_RESPONSE;
GetDiscoInfoRequest::ref discoInfoRequest = GetDiscoInfoRequest::create(JID(), client->getIQRouter());
discoInfoRequest->onResponse.connect(&handleServerDiscoInfoResponse);
discoInfoRequest->send();
}
-void handleDisconnected(const boost::optional<ClientError>&) {
+static void handleDisconnected(const boost::optional<ClientError>&) {
exitCode = CANNOT_AUTH;
eventLoop.stop();
}
diff --git a/Swiften/Examples/ConnectivityTest/SConscript b/Swiften/Examples/ConnectivityTest/SConscript
index 7bc3892..55a0821 100644
--- a/Swiften/Examples/ConnectivityTest/SConscript
+++ b/Swiften/Examples/ConnectivityTest/SConscript
@@ -1,7 +1,7 @@
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"])
tester = myenv.Program("ConnectivityTest", ["ConnectivityTest.cpp"])
diff --git a/Swiften/Examples/LinkLocalTool/SConscript b/Swiften/Examples/LinkLocalTool/SConscript
index 788f5c1..18eb91f 100644
--- a/Swiften/Examples/LinkLocalTool/SConscript
+++ b/Swiften/Examples/LinkLocalTool/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"])
linkLocalTool = myenv.Program("LinkLocalTool", [
"main.cpp"
diff --git a/Swiften/Examples/NetworkTool/main.cpp b/Swiften/Examples/NetworkTool/main.cpp
index 00c12d2..10a0aa6 100644
--- a/Swiften/Examples/NetworkTool/main.cpp
+++ b/Swiften/Examples/NetworkTool/main.cpp
@@ -16,9 +16,9 @@
using namespace Swift;
-SimpleEventLoop eventLoop;
+static SimpleEventLoop eventLoop;
-void handleGetPublicIPRequestResponse(const boost::optional<HostAddress>& result) {
+static void handleGetPublicIPRequestResponse(const boost::optional<HostAddress>& result) {
if (result) {
std::cerr << "Result: " << result->toString() << std::endl;;
}
@@ -28,7 +28,7 @@ void handleGetPublicIPRequestResponse(const boost::optional<HostAddress>& result
eventLoop.stop();
}
-void handleGetForwardPortRequestResponse(const boost::optional<NATPortMapping>& result) {
+static void handleGetForwardPortRequestResponse(const boost::optional<NATPortMapping>& result) {
if (result) {
std::cerr << "Result: " << result->getPublicPort() << " -> " << result->getLocalPort() << std::endl;;
}
@@ -38,7 +38,7 @@ void handleGetForwardPortRequestResponse(const boost::optional<NATPortMapping>&
eventLoop.stop();
}
-void handleRemovePortForwardingRequestResponse(bool result) {
+static void handleRemovePortForwardingRequestResponse(bool result) {
if (result) {
std::cerr << "Result: OK" << std::endl;
}
@@ -58,7 +58,7 @@ int main(int argc, char* argv[]) {
if (std::string(argv[1]) == "get-public-ip") {
boost::shared_ptr<NATTraversalGetPublicIPRequest> query = natTraverser.createGetPublicIPRequest();
query->onResult.connect(boost::bind(&handleGetPublicIPRequestResponse, _1));
- query->run();
+ query->start();
eventLoop.run();
}
else if (std::string(argv[1]) == "add-port-forward") {
@@ -67,7 +67,7 @@ int main(int argc, char* argv[]) {
}
boost::shared_ptr<NATTraversalForwardPortRequest> query = natTraverser.createForwardPortRequest(boost::lexical_cast<int>(argv[2]), boost::lexical_cast<int>(argv[3]));
query->onResult.connect(boost::bind(&handleGetForwardPortRequestResponse, _1));
- query->run();
+ query->start();
eventLoop.run();
}
else if (std::string(argv[1]) == "remove-port-forward") {
@@ -76,7 +76,7 @@ int main(int argc, char* argv[]) {
}
boost::shared_ptr<NATTraversalRemovePortForwardingRequest> query = natTraverser.createRemovePortForwardingRequest(boost::lexical_cast<int>(argv[2]), boost::lexical_cast<int>(argv[3]));
query->onResult.connect(boost::bind(&handleRemovePortForwardingRequestResponse, _1));
- query->run();
+ query->start();
eventLoop.run();
}
else if (std::string(argv[1]) == "get-local-ip") {
diff --git a/Swiften/Examples/ParserTester/SConscript b/Swiften/Examples/ParserTester/SConscript
index 09cffc9..5c93552 100644
--- a/Swiften/Examples/ParserTester/SConscript
+++ b/Swiften/Examples/ParserTester/SConscript
@@ -1,7 +1,7 @@
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("ParserTester", ["ParserTester.cpp"])
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();
{
diff --git a/Swiften/Examples/SendMessage/SConscript b/Swiften/Examples/SendMessage/SConscript
index 8907d25..0466187 100644
--- a/Swiften/Examples/SendMessage/SConscript
+++ b/Swiften/Examples/SendMessage/SConscript
@@ -1,7 +1,7 @@
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"])
tester = myenv.Program("SendMessage", ["SendMessage.cpp"])
diff --git a/Swiften/Examples/SendMessage/SendMessage.cpp b/Swiften/Examples/SendMessage/SendMessage.cpp
index 07e289e..2a3170f 100644
--- a/Swiften/Examples/SendMessage/SendMessage.cpp
+++ b/Swiften/Examples/SendMessage/SendMessage.cpp
@@ -18,17 +18,17 @@
using namespace Swift;
-SimpleEventLoop eventLoop;
-BoostNetworkFactories networkFactories(&eventLoop);
+static SimpleEventLoop eventLoop;
+static BoostNetworkFactories networkFactories(&eventLoop);
-Client* client = 0;
-JID recipient;
-std::string messageBody;
-int exitCode = 2;
-boost::bsignals::connection errorConnection;
+static Client* client = 0;
+static JID recipient;
+static std::string messageBody;
+static int exitCode = 2;
+static boost::bsignals::connection errorConnection;
-void handleConnected() {
+static void handleConnected() {
boost::shared_ptr<Message> message(new Message());
message->setBody(messageBody);
message->setTo(recipient);
@@ -39,7 +39,7 @@ void handleConnected() {
eventLoop.stop();
}
-void handleDisconnected(const boost::optional<ClientError>&) {
+static void handleDisconnected(const boost::optional<ClientError>&) {
std::cerr << "Error!" << std::endl;
exitCode = 1;
eventLoop.stop();