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 /Slimber | |
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 'Slimber')
-rw-r--r-- | Slimber/CLI/main.cpp | 2 | ||||
-rw-r--r-- | Slimber/Cocoa/CocoaController.mm | 3 | ||||
-rw-r--r-- | Slimber/Cocoa/main.h | 11 | ||||
-rw-r--r-- | Slimber/Cocoa/main.mm | 9 | ||||
-rw-r--r-- | Slimber/MainController.cpp | 6 | ||||
-rw-r--r-- | Slimber/MainController.h | 3 | ||||
-rw-r--r-- | Slimber/Server.cpp | 10 | ||||
-rw-r--r-- | Slimber/Server.h | 5 | ||||
-rw-r--r-- | Slimber/UnitTest/LinkLocalPresenceManagerTest.cpp | 2 |
9 files changed, 37 insertions, 14 deletions
diff --git a/Slimber/CLI/main.cpp b/Slimber/CLI/main.cpp index d254cb1..5252373 100644 --- a/Slimber/CLI/main.cpp +++ b/Slimber/CLI/main.cpp @@ -14,7 +14,7 @@ int main() { SimpleEventLoop eventLoop; DummyMenulet menulet; - MainController controller(&menulet); + MainController controller(&menulet, &eventLoop); eventLoop.run(); return 0; diff --git a/Slimber/Cocoa/CocoaController.mm b/Slimber/Cocoa/CocoaController.mm index 437d85a..a0c4ef4 100644 --- a/Slimber/Cocoa/CocoaController.mm +++ b/Slimber/Cocoa/CocoaController.mm @@ -2,6 +2,7 @@ #include "Slimber/MainController.h" #include "Slimber/Cocoa/CocoaMenulet.h" +#include "Slimber/Cocoa/main.h" @implementation CocoaController @@ -13,7 +14,7 @@ - (void) awakeFromNib { menulet = new CocoaMenulet(); - main = new MainController(menulet); + main = new MainController(menulet, eventLoop); } @end diff --git a/Slimber/Cocoa/main.h b/Slimber/Cocoa/main.h new file mode 100644 index 0000000..681139d --- /dev/null +++ b/Slimber/Cocoa/main.h @@ -0,0 +1,11 @@ +/* + * 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/EventLoop/Cocoa/CocoaEventLoop.h" + +extern Swift::CocoaEventLoop* eventLoop; diff --git a/Slimber/Cocoa/main.mm b/Slimber/Cocoa/main.mm index e267477..fc051e0 100644 --- a/Slimber/Cocoa/main.mm +++ b/Slimber/Cocoa/main.mm @@ -1,8 +1,13 @@ #include <Cocoa/Cocoa.h> +#include "Slimber/Cocoa/main.h" #include "Swiften/EventLoop/Cocoa/CocoaEventLoop.h" +Swift::CocoaEventLoop* eventLoop; + int main(int argc, char *argv[]) { - Swift::CocoaEventLoop eventLoop; - return NSApplicationMain(argc, const_cast<const char **>(argv)); + eventLoop = new Swift::CocoaEventLoop(); + int result = NSApplicationMain(argc, const_cast<const char **>(argv)); + delete eventLoop; + return result; } diff --git a/Slimber/MainController.cpp b/Slimber/MainController.cpp index 38c1a7c..e6c2ab5 100644 --- a/Slimber/MainController.cpp +++ b/Slimber/MainController.cpp @@ -22,8 +22,8 @@ using namespace Swift; -MainController::MainController(Menulet* menulet) : menulet(menulet) { - dnsSDQuerier = PlatformDNSSDQuerierFactory().createQuerier(); +MainController::MainController(Menulet* menulet, EventLoop* eventLoop) : menulet(menulet) { + dnsSDQuerier = PlatformDNSSDQuerierFactory(eventLoop).createQuerier(); assert(dnsSDQuerier); linkLocalServiceBrowser = new LinkLocalServiceBrowser(dnsSDQuerier); @@ -37,7 +37,7 @@ MainController::MainController(Menulet* menulet) : menulet(menulet) { vCardCollection = new FileVCardCollection( PlatformApplicationPathProvider("Slimber").getDataDir()); - server = new Server(5222, 5562, linkLocalServiceBrowser, vCardCollection); + server = new Server(5222, 5562, linkLocalServiceBrowser, vCardCollection, eventLoop); server->onStopped.connect( boost::bind(&MainController::handleServerStopped, this, _1)); server->onSelfConnected.connect( diff --git a/Slimber/MainController.h b/Slimber/MainController.h index de90932..4b341d9 100644 --- a/Slimber/MainController.h +++ b/Slimber/MainController.h @@ -16,6 +16,7 @@ namespace Swift { class LinkLocalServiceBrowser; class VCardCollection; class Server; + class EventLoop; } class MenuletController; @@ -23,7 +24,7 @@ class Menulet; class MainController { public: - MainController(Menulet* menulet); + MainController(Menulet* menulet, Swift::EventLoop* eventLoop); virtual ~MainController(); private: diff --git a/Slimber/Server.cpp b/Slimber/Server.cpp index 734f3b8..c6e700e 100644 --- a/Slimber/Server.cpp +++ b/Slimber/Server.cpp @@ -37,13 +37,15 @@ Server::Server( int clientConnectionPort, int linkLocalConnectionPort, LinkLocalServiceBrowser* linkLocalServiceBrowser, - VCardCollection* vCardCollection) : + VCardCollection* vCardCollection, + EventLoop* eventLoop) : linkLocalServiceRegistered(false), rosterRequested(false), clientConnectionPort(clientConnectionPort), linkLocalConnectionPort(linkLocalConnectionPort), linkLocalServiceBrowser(linkLocalServiceBrowser), vCardCollection(vCardCollection), + eventLoop(eventLoop), presenceManager(NULL), stopping(false) { linkLocalServiceBrowser->onServiceRegistered.connect( @@ -57,7 +59,7 @@ Server::~Server() { void Server::start() { assert(!serverFromClientConnectionServer); serverFromClientConnectionServer = BoostConnectionServer::create( - clientConnectionPort, &boostIOServiceThread.getIOService()); + clientConnectionPort, &boostIOServiceThread.getIOService(), eventLoop); serverFromClientConnectionServerSignalConnections.push_back( serverFromClientConnectionServer->onNewConnection.connect( boost::bind(&Server::handleNewClientConnection, this, _1))); @@ -67,7 +69,7 @@ void Server::start() { assert(!serverFromNetworkConnectionServer); serverFromNetworkConnectionServer = BoostConnectionServer::create( - linkLocalConnectionPort, &boostIOServiceThread.getIOService()); + linkLocalConnectionPort, &boostIOServiceThread.getIOService(), eventLoop); serverFromNetworkConnectionServerSignalConnections.push_back( serverFromNetworkConnectionServer->onNewConnection.connect( boost::bind(&Server::handleNewLinkLocalConnection, this, _1))); @@ -254,7 +256,7 @@ void Server::handleElementReceived(boost::shared_ptr<Element> element, boost::sh new LinkLocalConnector( *service, linkLocalServiceBrowser->getQuerier(), - BoostConnection::create(&boostIOServiceThread.getIOService()))); + BoostConnection::create(&boostIOServiceThread.getIOService(), eventLoop))); connector->onConnectFinished.connect( boost::bind(&Server::handleConnectFinished, this, connector, _1)); connectors.push_back(connector); diff --git a/Slimber/Server.h b/Slimber/Server.h index 864f705..039f351 100644 --- a/Slimber/Server.h +++ b/Slimber/Server.h @@ -32,6 +32,7 @@ namespace Swift { class SessionTracer; class RosterPayload; class Presence; + class EventLoop; class Server { public: @@ -39,7 +40,8 @@ namespace Swift { int clientConnectionPort, int linkLocalConnectionPort, LinkLocalServiceBrowser* browser, - VCardCollection* vCardCollection); + VCardCollection* vCardCollection, + EventLoop* eventLoop); ~Server(); void start(); @@ -102,6 +104,7 @@ namespace Swift { int linkLocalConnectionPort; LinkLocalServiceBrowser* linkLocalServiceBrowser; VCardCollection* vCardCollection; + EventLoop* eventLoop; LinkLocalPresenceManager* presenceManager; bool stopping; boost::shared_ptr<BoostConnectionServer> serverFromClientConnectionServer; diff --git a/Slimber/UnitTest/LinkLocalPresenceManagerTest.cpp b/Slimber/UnitTest/LinkLocalPresenceManagerTest.cpp index f8ee755..8c6710a 100644 --- a/Slimber/UnitTest/LinkLocalPresenceManagerTest.cpp +++ b/Slimber/UnitTest/LinkLocalPresenceManagerTest.cpp @@ -42,7 +42,7 @@ class LinkLocalPresenceManagerTest : public CppUnit::TestFixture { public: void setUp() { eventLoop = new DummyEventLoop(); - querier = boost::shared_ptr<FakeDNSSDQuerier>(new FakeDNSSDQuerier("wonderland.lit")); + querier = boost::shared_ptr<FakeDNSSDQuerier>(new FakeDNSSDQuerier("wonderland.lit", eventLoop)); browser = new LinkLocalServiceBrowser(querier); browser->start(); } |