summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2010-11-15 22:09:20 (GMT)
committerRemko Tronçon <git@el-tramo.be>2010-11-16 07:16:37 (GMT)
commit999f19158672bd6c91fa274a9f8e968b84f8a931 (patch)
treecbcf864514c0abc71414d187f6810619bbf0fea9 /Swiften
parent0f4fad3929097dca24d1ca92b06283811661e1f4 (diff)
downloadswift-999f19158672bd6c91fa274a9f8e968b84f8a931.zip
swift-999f19158672bd6c91fa274a9f8e968b84f8a931.tar.bz2
Pass NetworkFactories as an explicit dependency into client.
Diffstat (limited to 'Swiften')
-rw-r--r--Swiften/Client/Client.cpp2
-rw-r--r--Swiften/Client/Client.h2
-rw-r--r--Swiften/Client/CoreClient.cpp15
-rw-r--r--Swiften/Client/CoreClient.h6
-rw-r--r--Swiften/Component/Component.cpp2
-rw-r--r--Swiften/Component/Component.h2
-rw-r--r--Swiften/Component/CoreComponent.cpp15
-rw-r--r--Swiften/Component/CoreComponent.h8
-rw-r--r--Swiften/Examples/ConnectivityTest/ConnectivityTest.cpp11
-rw-r--r--Swiften/Examples/SendFile/SendFile.cpp10
-rw-r--r--Swiften/Examples/SendMessage/SendMessage.cpp10
-rw-r--r--Swiften/Network/BoostNetworkFactories.cpp23
-rw-r--r--Swiften/Network/BoostNetworkFactories.h37
-rw-r--r--Swiften/Network/MainBoostIOServiceThread.cpp18
-rw-r--r--Swiften/Network/NetworkFactories.cpp (renamed from Swiften/Network/MainBoostIOServiceThread.h)10
-rw-r--r--Swiften/Network/NetworkFactories.h23
-rw-r--r--Swiften/Network/SConscript3
-rw-r--r--Swiften/QA/ClientTest/ClientTest.cpp10
-rw-r--r--Swiften/SConscript4
19 files changed, 132 insertions, 79 deletions
diff --git a/Swiften/Client/Client.cpp b/Swiften/Client/Client.cpp
index 3b2c102..dcc8a79 100644
--- a/Swiften/Client/Client.cpp
+++ b/Swiften/Client/Client.cpp
@@ -27,7 +27,7 @@
namespace Swift {
-Client::Client(EventLoop* eventLoop, const JID& jid, const String& password, Storages* storages) : CoreClient(eventLoop, jid, password), storages(storages) {
+Client::Client(EventLoop* eventLoop, NetworkFactories* networkFactories, const JID& jid, const String& password, Storages* storages) : CoreClient(eventLoop, networkFactories, jid, password), storages(storages) {
memoryStorages = new MemoryStorages();
softwareVersionResponder = new SoftwareVersionResponder(getIQRouter());
diff --git a/Swiften/Client/Client.h b/Swiften/Client/Client.h
index fa45fdd..61d9e32 100644
--- a/Swiften/Client/Client.h
+++ b/Swiften/Client/Client.h
@@ -46,7 +46,7 @@ namespace Swift {
* this is NULL,
* all data will be stored in memory (and be lost on shutdown)
*/
- Client(EventLoop* eventLoop, const JID& jid, const String& password, Storages* storages = NULL);
+ Client(EventLoop* eventLoop, NetworkFactories* networkFactories, const JID& jid, const String& password, Storages* storages = NULL);
~Client();
diff --git a/Swiften/Client/CoreClient.cpp b/Swiften/Client/CoreClient.cpp
index 66fe23e..de0785f 100644
--- a/Swiften/Client/CoreClient.cpp
+++ b/Swiften/Client/CoreClient.cpp
@@ -8,14 +8,11 @@
#include <boost/bind.hpp>
-#include "Swiften/Network/MainBoostIOServiceThread.h"
-#include "Swiften/Network/BoostIOServiceThread.h"
#include "Swiften/Client/ClientSession.h"
#include "Swiften/TLS/PlatformTLSFactories.h"
#include "Swiften/TLS/CertificateVerificationError.h"
#include "Swiften/Network/Connector.h"
-#include "Swiften/Network/BoostConnectionFactory.h"
-#include "Swiften/Network/BoostTimerFactory.h"
+#include "Swiften/Network/NetworkFactories.h"
#include "Swiften/TLS/PKCS12Certificate.h"
#include "Swiften/Session/BasicSessionStream.h"
#include "Swiften/Queries/IQRouter.h"
@@ -24,7 +21,7 @@
namespace Swift {
-CoreClient::CoreClient(EventLoop* eventLoop, const JID& jid, const String& password) : resolver_(eventLoop), jid_(jid), password_(password), eventLoop(eventLoop), disconnectRequested_(false), certificateTrustChecker(NULL) {
+CoreClient::CoreClient(EventLoop* eventLoop, NetworkFactories* networkFactories, const JID& jid, const String& password) : resolver_(eventLoop), jid_(jid), password_(password), eventLoop(eventLoop), networkFactories(networkFactories), disconnectRequested_(false), certificateTrustChecker(NULL) {
stanzaChannel_ = new ClientSessionStanzaChannel();
stanzaChannel_->onMessageReceived.connect(boost::ref(onMessageReceived));
stanzaChannel_->onPresenceReceived.connect(boost::ref(onPresenceReceived));
@@ -32,8 +29,6 @@ CoreClient::CoreClient(EventLoop* eventLoop, const JID& jid, const String& passw
stanzaChannel_->onAvailableChanged.connect(boost::bind(&CoreClient::handleStanzaChannelAvailableChanged, this, _1));
iqRouter_ = new IQRouter(stanzaChannel_);
- connectionFactory_ = new BoostConnectionFactory(&MainBoostIOServiceThread::getInstance().getIOService(), eventLoop);
- timerFactory_ = new BoostTimerFactory(&MainBoostIOServiceThread::getInstance().getIOService(), eventLoop);
tlsFactories = new PlatformTLSFactories();
}
@@ -42,8 +37,6 @@ CoreClient::~CoreClient() {
std::cerr << "Warning: Client not disconnected properly" << std::endl;
}
delete tlsFactories;
- delete timerFactory_;
- delete connectionFactory_;
delete iqRouter_;
stanzaChannel_->onAvailableChanged.disconnect(boost::bind(&CoreClient::handleStanzaChannelAvailableChanged, this, _1));
@@ -65,7 +58,7 @@ void CoreClient::connect(const JID& jid) {
void CoreClient::connect(const String& host) {
disconnectRequested_ = false;
assert(!connector_);
- connector_ = Connector::create(host, &resolver_, connectionFactory_, timerFactory_);
+ connector_ = Connector::create(host, &resolver_, networkFactories->getConnectionFactory(), networkFactories->getTimerFactory());
connector_->onConnectFinished.connect(boost::bind(&CoreClient::handleConnectorFinished, this, _1));
connector_->setTimeoutMilliseconds(60*1000);
connector_->start();
@@ -82,7 +75,7 @@ void CoreClient::handleConnectorFinished(boost::shared_ptr<Connection> connectio
connection_ = connection;
assert(!sessionStream_);
- sessionStream_ = boost::shared_ptr<BasicSessionStream>(new BasicSessionStream(ClientStreamType, connection_, &payloadParserFactories_, &payloadSerializers_, tlsFactories->getTLSContextFactory(), timerFactory_));
+ sessionStream_ = boost::shared_ptr<BasicSessionStream>(new BasicSessionStream(ClientStreamType, connection_, &payloadParserFactories_, &payloadSerializers_, tlsFactories->getTLSContextFactory(), networkFactories->getTimerFactory()));
if (!certificate_.isEmpty()) {
sessionStream_->setTLSCertificate(PKCS12Certificate(certificate_, password_));
}
diff --git a/Swiften/Client/CoreClient.h b/Swiften/Client/CoreClient.h
index 628ced0..d104148 100644
--- a/Swiften/Client/CoreClient.h
+++ b/Swiften/Client/CoreClient.h
@@ -34,6 +34,7 @@ namespace Swift {
class EventLoop;
class PlatformTLSFactories;
class CertificateTrustChecker;
+ class NetworkFactories;
/**
* The central class for communicating with an XMPP server.
@@ -51,7 +52,7 @@ namespace Swift {
* Constructs a client for the given JID with the given password.
* The given eventLoop will be used to post events to.
*/
- CoreClient(EventLoop* eventLoop, const JID& jid, const String& password);
+ CoreClient(EventLoop* eventLoop, NetworkFactories* networkFactories, const JID& jid, const String& password);
~CoreClient();
void setCertificate(const String& certificate);
@@ -205,11 +206,10 @@ namespace Swift {
JID jid_;
String password_;
EventLoop* eventLoop;
+ NetworkFactories* networkFactories;
ClientSessionStanzaChannel* stanzaChannel_;
IQRouter* iqRouter_;
Connector::ref connector_;
- ConnectionFactory* connectionFactory_;
- TimerFactory* timerFactory_;
PlatformTLSFactories* tlsFactories;
FullPayloadParserFactoryCollection payloadParserFactories_;
FullPayloadSerializerCollection payloadSerializers_;
diff --git a/Swiften/Component/Component.cpp b/Swiften/Component/Component.cpp
index 579bca9..f3e2b81 100644
--- a/Swiften/Component/Component.cpp
+++ b/Swiften/Component/Component.cpp
@@ -10,7 +10,7 @@
namespace Swift {
-Component::Component(EventLoop* eventLoop, const JID& jid, const String& secret) : CoreComponent(eventLoop, jid, secret) {
+Component::Component(EventLoop* eventLoop, NetworkFactories* networkFactories, const JID& jid, const String& secret) : CoreComponent(eventLoop, networkFactories, jid, secret) {
softwareVersionResponder = new SoftwareVersionResponder(getIQRouter());
softwareVersionResponder->start();
}
diff --git a/Swiften/Component/Component.h b/Swiften/Component/Component.h
index b880725..1a04272 100644
--- a/Swiften/Component/Component.h
+++ b/Swiften/Component/Component.h
@@ -19,7 +19,7 @@ namespace Swift {
*/
class Component : public CoreComponent {
public:
- Component(EventLoop* eventLoop, const JID& jid, const String& secret);
+ Component(EventLoop* eventLoop, NetworkFactories* networkFactories, const JID& jid, const String& secret);
~Component();
/**
diff --git a/Swiften/Component/CoreComponent.cpp b/Swiften/Component/CoreComponent.cpp
index 2821dd2..656f967 100644
--- a/Swiften/Component/CoreComponent.cpp
+++ b/Swiften/Component/CoreComponent.cpp
@@ -8,12 +8,9 @@
#include <boost/bind.hpp>
-#include "Swiften/Network/MainBoostIOServiceThread.h"
-#include "Swiften/Network/BoostIOServiceThread.h"
#include "Swiften/Component/ComponentSession.h"
#include "Swiften/Network/Connector.h"
-#include "Swiften/Network/BoostConnectionFactory.h"
-#include "Swiften/Network/BoostTimerFactory.h"
+#include "Swiften/Network/NetworkFactories.h"
#include "Swiften/TLS/PKCS12Certificate.h"
#include "Swiften/Session/BasicSessionStream.h"
#include "Swiften/Queries/IQRouter.h"
@@ -22,7 +19,7 @@
namespace Swift {
-CoreComponent::CoreComponent(EventLoop* eventLoop, const JID& jid, const String& secret) : eventLoop(eventLoop), resolver_(eventLoop), jid_(jid), secret_(secret), disconnectRequested_(false) {
+CoreComponent::CoreComponent(EventLoop* eventLoop, NetworkFactories* networkFactories, const JID& jid, const String& secret) : eventLoop(eventLoop), networkFactories(networkFactories), resolver_(eventLoop), jid_(jid), secret_(secret), disconnectRequested_(false) {
stanzaChannel_ = new ComponentSessionStanzaChannel();
stanzaChannel_->onMessageReceived.connect(boost::ref(onMessageReceived));
stanzaChannel_->onPresenceReceived.connect(boost::ref(onPresenceReceived));
@@ -30,16 +27,12 @@ CoreComponent::CoreComponent(EventLoop* eventLoop, const JID& jid, const String&
iqRouter_ = new IQRouter(stanzaChannel_);
iqRouter_->setFrom(jid);
- connectionFactory_ = new BoostConnectionFactory(&MainBoostIOServiceThread::getInstance().getIOService(), eventLoop);
- timerFactory_ = new BoostTimerFactory(&MainBoostIOServiceThread::getInstance().getIOService(), eventLoop);
}
CoreComponent::~CoreComponent() {
if (session_ || connection_) {
std::cerr << "Warning: Component not disconnected properly" << std::endl;
}
- delete timerFactory_;
- delete connectionFactory_;
delete iqRouter_;
stanzaChannel_->onAvailableChanged.disconnect(boost::bind(&CoreComponent::handleStanzaChannelAvailableChanged, this, _1));
@@ -50,7 +43,7 @@ CoreComponent::~CoreComponent() {
void CoreComponent::connect(const String& host, int port) {
assert(!connector_);
- connector_ = ComponentConnector::create(host, port, &resolver_, connectionFactory_, timerFactory_);
+ connector_ = ComponentConnector::create(host, port, &resolver_, networkFactories->getConnectionFactory(), networkFactories->getTimerFactory());
connector_->onConnectFinished.connect(boost::bind(&CoreComponent::handleConnectorFinished, this, _1));
connector_->setTimeoutMilliseconds(60*1000);
connector_->start();
@@ -69,7 +62,7 @@ void CoreComponent::handleConnectorFinished(boost::shared_ptr<Connection> connec
connection_ = connection;
assert(!sessionStream_);
- sessionStream_ = boost::shared_ptr<BasicSessionStream>(new BasicSessionStream(ComponentStreamType, connection_, &payloadParserFactories_, &payloadSerializers_, NULL, timerFactory_));
+ sessionStream_ = boost::shared_ptr<BasicSessionStream>(new BasicSessionStream(ComponentStreamType, connection_, &payloadParserFactories_, &payloadSerializers_, NULL, networkFactories->getTimerFactory()));
sessionStream_->onDataRead.connect(boost::bind(&CoreComponent::handleDataRead, this, _1));
sessionStream_->onDataWritten.connect(boost::bind(&CoreComponent::handleDataWritten, this, _1));
sessionStream_->initialize();
diff --git a/Swiften/Component/CoreComponent.h b/Swiften/Component/CoreComponent.h
index 59466f7..dd4c5fd 100644
--- a/Swiften/Component/CoreComponent.h
+++ b/Swiften/Component/CoreComponent.h
@@ -25,8 +25,7 @@
namespace Swift {
class IQRouter;
- class ConnectionFactory;
- class TimerFactory;
+ class NetworkFactories;
class ComponentSession;
class BasicSessionStream;
@@ -42,7 +41,7 @@ namespace Swift {
*/
class CoreComponent {
public:
- CoreComponent(EventLoop* eventLoop, const JID& jid, const String& secret);
+ CoreComponent(EventLoop* eventLoop, NetworkFactories* networkFactories, const JID& jid, const String& secret);
~CoreComponent();
void connect(const String& host, int port);
@@ -88,14 +87,13 @@ namespace Swift {
private:
EventLoop* eventLoop;
+ NetworkFactories* networkFactories;
PlatformDomainNameResolver resolver_;
JID jid_;
String secret_;
ComponentSessionStanzaChannel* stanzaChannel_;
IQRouter* iqRouter_;
ComponentConnector::ref connector_;
- ConnectionFactory* connectionFactory_;
- TimerFactory* timerFactory_;
FullPayloadParserFactoryCollection payloadParserFactories_;
FullPayloadSerializerCollection payloadSerializers_;
boost::shared_ptr<Connection> connection_;
diff --git a/Swiften/Examples/ConnectivityTest/ConnectivityTest.cpp b/Swiften/Examples/ConnectivityTest/ConnectivityTest.cpp
index 9da5cdf..c090153 100644
--- a/Swiften/Examples/ConnectivityTest/ConnectivityTest.cpp
+++ b/Swiften/Examples/ConnectivityTest/ConnectivityTest.cpp
@@ -8,12 +8,12 @@
#include <boost/thread.hpp>
#include "Swiften/Client/Client.h"
-#include "Swiften/Network/BoostTimer.h"
+#include "Swiften/Network/Timer.h"
+#include "Swiften/Network/TimerFactory.h"
+#include "Swiften/Network/BoostNetworkFactories.h"
#include "Swiften/EventLoop/EventLoop.h"
#include "Swiften/Client/ClientXMLTracer.h"
#include "Swiften/EventLoop/SimpleEventLoop.h"
-#include "Swiften/Network/BoostIOServiceThread.h"
-#include "Swiften/Network/MainBoostIOServiceThread.h"
#include "Swiften/Disco/GetDiscoInfoRequest.h"
using namespace Swift;
@@ -21,6 +21,7 @@ using namespace Swift;
enum ExitCodes {OK = 0, CANNOT_CONNECT, CANNOT_AUTH, NO_RESPONSE, DISCO_ERROR};
SimpleEventLoop eventLoop;
+BoostNetworkFactories networkFactories(&eventLoop);
Client* client = 0;
JID recipient;
@@ -67,7 +68,7 @@ int main(int argc, char* argv[]) {
connectHost = argv[argi++];
}
- client = new Swift::Client(&eventLoop, JID(jid), String(argv[argi++]));
+ client = new Swift::Client(&eventLoop, &networkFactories, JID(jid), String(argv[argi++]));
char* timeoutChar = argv[argi++];
int timeout = atoi(timeoutChar);
timeout = (timeout ? timeout : 30) * 1000;
@@ -84,7 +85,7 @@ int main(int argc, char* argv[]) {
}
{
- BoostTimer::ref timer(BoostTimer::create(timeout, &MainBoostIOServiceThread::getInstance().getIOService(), &eventLoop));
+ Timer::ref timer = networkFactories.getTimerFactory()->createTimer(timeout);
timer->onTick.connect(boost::bind(&SimpleEventLoop::stop, &eventLoop));
timer->start();
diff --git a/Swiften/Examples/SendFile/SendFile.cpp b/Swiften/Examples/SendFile/SendFile.cpp
index f0a2d59..630daac 100644
--- a/Swiften/Examples/SendFile/SendFile.cpp
+++ b/Swiften/Examples/SendFile/SendFile.cpp
@@ -9,28 +9,30 @@
#include "Swiften/Client/Client.h"
#include "Swiften/Network/BoostTimer.h"
+#include "Swiften/Network/TimerFactory.h"
+#include "Swiften/Network/BoostNetworkFactories.h"
#include "Swiften/EventLoop/EventLoop.h"
#include "Swiften/Client/ClientXMLTracer.h"
#include "Swiften/EventLoop/SimpleEventLoop.h"
-#include "Swiften/Network/MainBoostIOServiceThread.h"
#include "Swiften/FileTransfer/OutgoingFileTransfer.h"
#include "Swiften/FileTransfer/FileReadBytestream.h"
#include "Swiften/FileTransfer/SOCKS5BytestreamServer.h"
#include "Swiften/Network/BoostConnectionServer.h"
-#include "Swiften/Network/BoostIOServiceThread.h"
using namespace Swift;
SimpleEventLoop eventLoop;
+BoostNetworkFactories networkFactories(&eventLoop);
+
int exitCode = 2;
class FileSender {
public:
FileSender(const JID& jid, const String& password, const JID& recipient, const boost::filesystem::path& file, int port) : jid(jid), password(password), recipient(recipient), file(file), transfer(NULL) {
- connectionServer = BoostConnectionServer::create(port, &MainBoostIOServiceThread::getInstance().getIOService(), &eventLoop);
+ connectionServer = BoostConnectionServer::create(port, &networkFactories.getIOServiceThread()->getIOService(), &eventLoop);
socksBytestreamServer = new SOCKS5BytestreamServer(connectionServer);
- client = new Swift::Client(&eventLoop, jid, password);
+ client = new Swift::Client(&eventLoop, &networkFactories, jid, password);
client->onConnected.connect(boost::bind(&FileSender::handleConnected, this));
client->onDisconnected.connect(boost::bind(&FileSender::handleDisconnected, this, _1));
//tracer = new ClientXMLTracer(client);
diff --git a/Swiften/Examples/SendMessage/SendMessage.cpp b/Swiften/Examples/SendMessage/SendMessage.cpp
index 567a351..8e28dab 100644
--- a/Swiften/Examples/SendMessage/SendMessage.cpp
+++ b/Swiften/Examples/SendMessage/SendMessage.cpp
@@ -8,16 +8,16 @@
#include <boost/thread.hpp>
#include "Swiften/Client/Client.h"
-#include "Swiften/Network/BoostTimer.h"
+#include "Swiften/Network/BoostNetworkFactories.h"
+#include "Swiften/Network/TimerFactory.h"
#include "Swiften/EventLoop/EventLoop.h"
#include "Swiften/Client/ClientXMLTracer.h"
#include "Swiften/EventLoop/SimpleEventLoop.h"
-#include "Swiften/Network/BoostIOServiceThread.h"
-#include "Swiften/Network/MainBoostIOServiceThread.h"
using namespace Swift;
SimpleEventLoop eventLoop;
+BoostNetworkFactories networkFactories(&eventLoop);
Client* client = 0;
JID recipient;
@@ -57,7 +57,7 @@ int main(int argc, char* argv[]) {
connectHost = argv[argi++];
}
- client = new Swift::Client(&eventLoop, JID(jid), String(argv[argi++]));
+ client = new Swift::Client(&eventLoop, &networkFactories, JID(jid), String(argv[argi++]));
client->setAlwaysTrustCertificates();
recipient = JID(argv[argi++]);
@@ -73,7 +73,7 @@ int main(int argc, char* argv[]) {
}
{
- BoostTimer::ref timer(BoostTimer::create(30000, &MainBoostIOServiceThread::getInstance().getIOService(), &eventLoop));
+ Timer::ref timer = networkFactories.getTimerFactory()->createTimer(30000);
timer->onTick.connect(boost::bind(&SimpleEventLoop::stop, &eventLoop));
timer->start();
diff --git a/Swiften/Network/BoostNetworkFactories.cpp b/Swiften/Network/BoostNetworkFactories.cpp
new file mode 100644
index 0000000..fc52b08
--- /dev/null
+++ b/Swiften/Network/BoostNetworkFactories.cpp
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2010 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include "Swiften/Network/BoostNetworkFactories.h"
+#include "Swiften/Network/BoostTimerFactory.h"
+#include "Swiften/Network/BoostConnectionFactory.h"
+
+namespace Swift {
+
+BoostNetworkFactories::BoostNetworkFactories(EventLoop* eventLoop) {
+ timerFactory = new BoostTimerFactory(&ioServiceThread.getIOService(), eventLoop);
+ connectionFactory = new BoostConnectionFactory(&ioServiceThread.getIOService(), eventLoop);
+}
+
+BoostNetworkFactories::~BoostNetworkFactories() {
+ delete connectionFactory;
+ delete timerFactory;
+}
+
+}
diff --git a/Swiften/Network/BoostNetworkFactories.h b/Swiften/Network/BoostNetworkFactories.h
new file mode 100644
index 0000000..3f8b557
--- /dev/null
+++ b/Swiften/Network/BoostNetworkFactories.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2010 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#pragma once
+
+#include "Swiften/Network/NetworkFactories.h"
+#include "Swiften/Network/BoostIOServiceThread.h"
+
+namespace Swift {
+ class EventLoop;
+
+ class BoostNetworkFactories : public NetworkFactories {
+ public:
+ BoostNetworkFactories(EventLoop* eventLoop);
+ ~BoostNetworkFactories();
+
+ virtual TimerFactory* getTimerFactory() const {
+ return timerFactory;
+ }
+
+ virtual ConnectionFactory* getConnectionFactory() const {
+ return connectionFactory;
+ }
+
+ BoostIOServiceThread* getIOServiceThread() {
+ return &ioServiceThread;
+ }
+
+ private:
+ BoostIOServiceThread ioServiceThread;
+ TimerFactory* timerFactory;
+ ConnectionFactory* connectionFactory;
+ };
+}
diff --git a/Swiften/Network/MainBoostIOServiceThread.cpp b/Swiften/Network/MainBoostIOServiceThread.cpp
deleted file mode 100644
index 9e4f1fc..0000000
--- a/Swiften/Network/MainBoostIOServiceThread.cpp
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- * Copyright (c) 2010 Remko Tronçon
- * Licensed under the GNU General Public License v3.
- * See Documentation/Licenses/GPLv3.txt for more information.
- */
-
-#include "Swiften/Network/MainBoostIOServiceThread.h"
-
-#include "Swiften/Network/BoostIOServiceThread.h"
-
-namespace Swift {
-
-BoostIOServiceThread& MainBoostIOServiceThread::getInstance() {
- static BoostIOServiceThread instance;
- return instance;
-}
-
-}
diff --git a/Swiften/Network/MainBoostIOServiceThread.h b/Swiften/Network/NetworkFactories.cpp
index 29cd4d3..361cb90 100644
--- a/Swiften/Network/MainBoostIOServiceThread.h
+++ b/Swiften/Network/NetworkFactories.cpp
@@ -4,13 +4,11 @@
* See Documentation/Licenses/GPLv3.txt for more information.
*/
-#pragma once
+#include "Swiften/Network/NetworkFactories.h"
namespace Swift {
- class BoostIOServiceThread;
- class MainBoostIOServiceThread {
- public:
- static BoostIOServiceThread& getInstance();
- };
+NetworkFactories::~NetworkFactories() {
+}
+
}
diff --git a/Swiften/Network/NetworkFactories.h b/Swiften/Network/NetworkFactories.h
new file mode 100644
index 0000000..23e2780
--- /dev/null
+++ b/Swiften/Network/NetworkFactories.h
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2010 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#pragma once
+
+namespace Swift {
+ class TimerFactory;
+ class ConnectionFactory;
+
+ /**
+ * An interface collecting network factories.
+ */
+ class NetworkFactories {
+ public:
+ virtual ~NetworkFactories();
+
+ virtual TimerFactory* getTimerFactory() const = 0;
+ virtual ConnectionFactory* getConnectionFactory() const = 0;
+ };
+}
diff --git a/Swiften/Network/SConscript b/Swiften/Network/SConscript
index b4946f9..f193407 100644
--- a/Swiften/Network/SConscript
+++ b/Swiften/Network/SConscript
@@ -9,7 +9,6 @@ sourceList = [
"BoostConnection.cpp",
"BoostConnectionFactory.cpp",
"BoostConnectionServer.cpp",
- "MainBoostIOServiceThread.cpp",
"BoostIOServiceThread.cpp",
"ConnectionFactory.cpp",
"ConnectionServer.cpp",
@@ -24,6 +23,8 @@ sourceList = [
"PlatformDomainNameServiceQuery.cpp",
"StaticDomainNameResolver.cpp",
"HostAddress.cpp",
+ "NetworkFactories.cpp",
+ "BoostNetworkFactories.cpp",
"Timer.cpp",
"BoostTimer.cpp"]
if myenv.get("HAVE_CARES", False) :
diff --git a/Swiften/QA/ClientTest/ClientTest.cpp b/Swiften/QA/ClientTest/ClientTest.cpp
index dd63056..511deb4 100644
--- a/Swiften/QA/ClientTest/ClientTest.cpp
+++ b/Swiften/QA/ClientTest/ClientTest.cpp
@@ -8,17 +8,17 @@
#include <boost/thread.hpp>
#include "Swiften/Client/Client.h"
-#include "Swiften/Network/BoostTimer.h"
+#include "Swiften/Network/TimerFactory.h"
+#include "Swiften/Network/BoostNetworkFactories.h"
#include "Swiften/EventLoop/EventLoop.h"
#include "Swiften/EventLoop/SimpleEventLoop.h"
#include "Swiften/Roster/GetRosterRequest.h"
#include "Swiften/Client/ClientXMLTracer.h"
-#include "Swiften/Network/BoostIOServiceThread.h"
-#include "Swiften/Network/MainBoostIOServiceThread.h"
using namespace Swift;
SimpleEventLoop eventLoop;
+BoostNetworkFactories networkFactories(&eventLoop);
Client* client = 0;
bool reconnected = false;
@@ -55,14 +55,14 @@ int main(int, char**) {
return -1;
}
- client = new Swift::Client(&eventLoop, JID(jid), String(pass));
+ client = new Swift::Client(&eventLoop, &networkFactories, JID(jid), String(pass));
ClientXMLTracer* tracer = new ClientXMLTracer(client);
client->onConnected.connect(&handleConnected);
client->setAlwaysTrustCertificates();
client->connect();
{
- boost::shared_ptr<BoostTimer> timer(BoostTimer::create(30000, &MainBoostIOServiceThread::getInstance().getIOService(), &eventLoop));
+ Timer::ref timer = networkFactories.getTimerFactory()->createTimer(30000);
timer->onTick.connect(boost::bind(&SimpleEventLoop::stop, &eventLoop));
timer->start();
diff --git a/Swiften/SConscript b/Swiften/SConscript
index 4c08692..7da329b 100644
--- a/Swiften/SConscript
+++ b/Swiften/SConscript
@@ -273,7 +273,7 @@ if env["SCONS_STAGE"] == "build" :
# Generate the Swiften header
swiften_header = "#pragma once\n"
top_path = env.Dir("..").abspath
- public_dirs = ["Avatars", "Base", "Chat", "Client", "Component", "Disco", "Elements", "JID", "MUC", "Presence", "Queries", "Roster", "StringCodecs", "TLS", "VCards"]
+ public_dirs = ["Avatars", "Base", "Chat", "Client", "Component", "Disco", "Elements", "JID", "MUC", "Network", "Presence", "Queries", "Roster", "StringCodecs", "TLS", "VCards"]
for public_dir in public_dirs :
for root, dirs, files in os.walk(env.Dir(public_dir).abspath) :
if root.endswith("UnitTest") :
@@ -283,6 +283,8 @@ if env["SCONS_STAGE"] == "build" :
for file in files :
if not file.endswith(".h") :
continue
+ if file.startswith("CAres") :
+ continue
swiften_header += "#include \"" + os.path.relpath(os.path.join(root, file), top_path) + "\"\n"
for file in ["EventLoop/SimpleEventLoop.h"] :
swiften_header += "#include \"Swiften/" + file + "\"\n"