diff options
author | Remko Tronçon <git@el-tramo.be> | 2010-10-27 19:06:56 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2010-10-27 19:07:55 (GMT) |
commit | 6810a2896f27e7ee07aee847f5e8dbccd1f6ec89 (patch) | |
tree | f7ea87f030e57cb4494a4f897506fb18fc3d2241 /Swiften/Component | |
parent | a7da393cfc807048d320ddba8a1c7d24ef23a46e (diff) | |
download | swift-contrib-6810a2896f27e7ee07aee847f5e8dbccd1f6ec89.zip swift-contrib-6810a2896f27e7ee07aee847f5e8dbccd1f6ec89.tar.bz2 |
Remove MainEventLoop singleton.
The event loop now needs to be explicitly passed to clients
using it.
Diffstat (limited to 'Swiften/Component')
-rw-r--r-- | Swiften/Component/Component.cpp | 2 | ||||
-rw-r--r-- | Swiften/Component/Component.h | 2 | ||||
-rw-r--r-- | Swiften/Component/CoreComponent.cpp | 6 | ||||
-rw-r--r-- | Swiften/Component/CoreComponent.h | 3 | ||||
-rw-r--r-- | Swiften/Component/UnitTest/ComponentConnectorTest.cpp | 15 |
5 files changed, 15 insertions, 13 deletions
diff --git a/Swiften/Component/Component.cpp b/Swiften/Component/Component.cpp index af3802d..579bca9 100644 --- a/Swiften/Component/Component.cpp +++ b/Swiften/Component/Component.cpp @@ -10,7 +10,7 @@ namespace Swift { -Component::Component(const JID& jid, const String& secret) : CoreComponent(jid, secret) { +Component::Component(EventLoop* eventLoop, const JID& jid, const String& secret) : CoreComponent(eventLoop, jid, secret) { softwareVersionResponder = new SoftwareVersionResponder(getIQRouter()); softwareVersionResponder->start(); } diff --git a/Swiften/Component/Component.h b/Swiften/Component/Component.h index a89deb3..b880725 100644 --- a/Swiften/Component/Component.h +++ b/Swiften/Component/Component.h @@ -19,7 +19,7 @@ namespace Swift { */ class Component : public CoreComponent { public: - Component(const JID& jid, const String& secret); + Component(EventLoop* eventLoop, const JID& jid, const String& secret); ~Component(); /** diff --git a/Swiften/Component/CoreComponent.cpp b/Swiften/Component/CoreComponent.cpp index c9d9051..af6ebe5 100644 --- a/Swiften/Component/CoreComponent.cpp +++ b/Swiften/Component/CoreComponent.cpp @@ -23,7 +23,7 @@ namespace Swift { -CoreComponent::CoreComponent(const JID& jid, const String& secret) : jid_(jid), secret_(secret), disconnectRequested_(false) { +CoreComponent::CoreComponent(EventLoop* eventLoop, const JID& jid, const String& secret) : eventLoop(eventLoop), resolver_(eventLoop), jid_(jid), secret_(secret), disconnectRequested_(false) { stanzaChannel_ = new ComponentSessionStanzaChannel(); stanzaChannel_->onMessageReceived.connect(boost::ref(onMessageReceived)); stanzaChannel_->onPresenceReceived.connect(boost::ref(onPresenceReceived)); @@ -31,8 +31,8 @@ CoreComponent::CoreComponent(const JID& jid, const String& secret) : jid_(jid), iqRouter_ = new IQRouter(stanzaChannel_); iqRouter_->setFrom(jid); - connectionFactory_ = new BoostConnectionFactory(&MainBoostIOServiceThread::getInstance().getIOService()); - timerFactory_ = new BoostTimerFactory(&MainBoostIOServiceThread::getInstance().getIOService()); + connectionFactory_ = new BoostConnectionFactory(&MainBoostIOServiceThread::getInstance().getIOService(), eventLoop); + timerFactory_ = new BoostTimerFactory(&MainBoostIOServiceThread::getInstance().getIOService(), eventLoop); tlsLayerFactory_ = new NullTLSLayerFactory(); } diff --git a/Swiften/Component/CoreComponent.h b/Swiften/Component/CoreComponent.h index 67f87ee..75e6bda 100644 --- a/Swiften/Component/CoreComponent.h +++ b/Swiften/Component/CoreComponent.h @@ -43,7 +43,7 @@ namespace Swift { */ class CoreComponent { public: - CoreComponent(const JID& jid, const String& secret); + CoreComponent(EventLoop* eventLoop, const JID& jid, const String& secret); ~CoreComponent(); void connect(const String& host, int port); @@ -88,6 +88,7 @@ namespace Swift { void handleDataWritten(const String&); private: + EventLoop* eventLoop; PlatformDomainNameResolver resolver_; JID jid_; String secret_; diff --git a/Swiften/Component/UnitTest/ComponentConnectorTest.cpp b/Swiften/Component/UnitTest/ComponentConnectorTest.cpp index 4648365..7d00b09 100644 --- a/Swiften/Component/UnitTest/ComponentConnectorTest.cpp +++ b/Swiften/Component/UnitTest/ComponentConnectorTest.cpp @@ -16,7 +16,6 @@ #include "Swiften/Network/HostAddressPort.h" #include "Swiften/Network/StaticDomainNameResolver.h" #include "Swiften/Network/DummyTimerFactory.h" -#include "Swiften/EventLoop/MainEventLoop.h" #include "Swiften/EventLoop/DummyEventLoop.h" using namespace Swift; @@ -38,8 +37,8 @@ class ComponentConnectorTest : public CppUnit::TestFixture { void setUp() { eventLoop = new DummyEventLoop(); - resolver = new StaticDomainNameResolver(); - connectionFactory = new MockConnectionFactory(); + resolver = new StaticDomainNameResolver(eventLoop); + connectionFactory = new MockConnectionFactory(eventLoop); timerFactory = new DummyTimerFactory(); } @@ -164,14 +163,14 @@ class ComponentConnectorTest : public CppUnit::TestFixture { struct MockConnection : public Connection { public: - MockConnection(const std::vector<HostAddressPort>& failingPorts, bool isResponsive) : failingPorts(failingPorts), isResponsive(isResponsive) {} + MockConnection(const std::vector<HostAddressPort>& failingPorts, bool isResponsive, EventLoop* eventLoop) : eventLoop(eventLoop), failingPorts(failingPorts), isResponsive(isResponsive) {} void listen() { assert(false); } void connect(const HostAddressPort& address) { hostAddressPort = address; if (isResponsive) { bool fail = std::find(failingPorts.begin(), failingPorts.end(), address) != failingPorts.end(); - MainEventLoop::postEvent(boost::bind(boost::ref(onConnectFinished), fail)); + eventLoop->postEvent(boost::bind(boost::ref(onConnectFinished), fail)); } } @@ -179,19 +178,21 @@ class ComponentConnectorTest : public CppUnit::TestFixture { void write(const ByteArray&) { assert(false); } HostAddressPort getLocalAddress() const { return HostAddressPort(); } + EventLoop* eventLoop; boost::optional<HostAddressPort> hostAddressPort; std::vector<HostAddressPort> failingPorts; bool isResponsive; }; struct MockConnectionFactory : public ConnectionFactory { - MockConnectionFactory() : isResponsive(true) { + MockConnectionFactory(EventLoop* eventLoop) : eventLoop(eventLoop), isResponsive(true) { } boost::shared_ptr<Connection> createConnection() { - return boost::shared_ptr<Connection>(new MockConnection(failingPorts, isResponsive)); + return boost::shared_ptr<Connection>(new MockConnection(failingPorts, isResponsive, eventLoop)); } + EventLoop* eventLoop; bool isResponsive; std::vector<HostAddressPort> failingPorts; }; |