summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-08-02 13:57:54 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-08-02 13:57:54 (GMT)
commit8c60e86c8fc2cf60825c0ffbd882693dccf0b33c (patch)
tree9c7cfd05f4a55fefc31cc559a362504fdbd7d4de /Slimber
parent475cec615cda74aa34d9519239e2f627256ef71d (diff)
downloadswift-contrib-8c60e86c8fc2cf60825c0ffbd882693dccf0b33c.zip
swift-contrib-8c60e86c8fc2cf60825c0ffbd882693dccf0b33c.tar.bz2
Slimber: Handle conflicts/restarts.
Diffstat (limited to 'Slimber')
-rw-r--r--Slimber/MainController.cpp33
-rw-r--r--Slimber/MainController.h3
-rw-r--r--Slimber/Server.cpp14
3 files changed, 37 insertions, 13 deletions
diff --git a/Slimber/MainController.cpp b/Slimber/MainController.cpp
index d723f3f..4e238d2 100644
--- a/Slimber/MainController.cpp
+++ b/Slimber/MainController.cpp
@@ -16,8 +16,11 @@
using namespace Swift;
MainController::MainController(Menulet* menulet) : menulet(menulet) {
+ menuletController = new MenuletController(menulet);
+ menuletController->onRestartRequested.connect(boost::bind(
+ &MainController::handleRestartRequested, this));
+
dnsSDQuerier = boost::shared_ptr<BonjourQuerier>(new BonjourQuerier());
- dnsSDQuerier->start();
linkLocalServiceBrowser = new LinkLocalServiceBrowser(dnsSDQuerier);
linkLocalServiceBrowser->onServiceAdded.connect(
@@ -26,7 +29,6 @@ MainController::MainController(Menulet* menulet) : menulet(menulet) {
boost::bind(&MainController::handleServicesChanged, this));
linkLocalServiceBrowser->onServiceChanged.connect(
boost::bind(&MainController::handleServicesChanged, this));
- linkLocalServiceBrowser->start();
vCardCollection = new FileVCardCollection(
PlatformApplication("Slimber").getSettingsDir());
@@ -37,14 +39,7 @@ MainController::MainController(Menulet* menulet) : menulet(menulet) {
server->onSelfConnected.connect(
boost::bind(&MainController::handleSelfConnected, this, _1));
- menuletController = new MenuletController(menulet);
- menuletController->onRestartRequested.connect(boost::bind(
- &MainController::handleRestartRequested, this));
-
- handleSelfConnected(false);
- handleServicesChanged();
-
- server->start();
+ start();
}
MainController::~MainController() {
@@ -56,6 +51,22 @@ MainController::~MainController() {
dnsSDQuerier->stop();
}
+void MainController::start() {
+ dnsSDQuerier->start();
+ linkLocalServiceBrowser->start();
+
+ handleSelfConnected(false);
+ handleServicesChanged();
+
+ server->start();
+}
+
+void MainController::stop() {
+ server->stop();
+ linkLocalServiceBrowser->stop();
+ dnsSDQuerier->stop();
+}
+
void MainController::handleSelfConnected(bool b) {
if (b) {
menuletController->setXMPPStatus("You are logged in", MenuletController::Online);
@@ -84,4 +95,6 @@ void MainController::handleServerStopped(boost::optional<ServerError> error) {
void MainController::handleRestartRequested() {
std::cout << "RESTART!" << std::endl;
+ stop();
+ start();
}
diff --git a/Slimber/MainController.h b/Slimber/MainController.h
index 4ff9afd..2c74e4c 100644
--- a/Slimber/MainController.h
+++ b/Slimber/MainController.h
@@ -26,6 +26,9 @@ class MainController {
void handleServerStopped(boost::optional<Swift::ServerError> error);
void handleRestartRequested();
+ void start();
+ void stop();
+
private:
Menulet* menulet;
boost::shared_ptr<Swift::DNSSDQuerier> dnsSDQuerier;
diff --git a/Slimber/Server.cpp b/Slimber/Server.cpp
index 44a5861..28e0659 100644
--- a/Slimber/Server.cpp
+++ b/Slimber/Server.cpp
@@ -57,7 +57,6 @@ void Server::start() {
boost::bind(&Server::handleNewClientConnection, this, _1));
serverFromClientConnectionServer->onStopped.connect(
boost::bind(&Server::handleClientConnectionServerStopped, this, _1));
- serverFromClientConnectionServer->start();
assert(!serverFromNetworkConnectionServer);
serverFromNetworkConnectionServer =
@@ -65,9 +64,8 @@ void Server::start() {
linkLocalConnectionPort, &boostIOServiceThread.getIOService()));
serverFromNetworkConnectionServer->onNewConnection.connect(
boost::bind(&Server::handleNewLinkLocalConnection, this, _1));
- serverFromClientConnectionServer->onStopped.connect(
+ serverFromNetworkConnectionServer->onStopped.connect(
boost::bind(&Server::handleLinkLocalConnectionServerStopped, this, _1));
- serverFromNetworkConnectionServer->start();
assert(!presenceManager);
presenceManager = new LinkLocalPresenceManager(linkLocalServiceBrowser);
@@ -75,6 +73,9 @@ void Server::start() {
boost::bind(&Server::handleRosterChanged, this, _1));
presenceManager->onPresenceChanged.connect(
boost::bind(&Server::handlePresenceChanged, this, _1));
+
+ serverFromClientConnectionServer->start();
+ serverFromNetworkConnectionServer->start();
}
void Server::stop() {
@@ -89,6 +90,7 @@ void Server::stop(boost::optional<ServerError> e) {
stopping = true;
delete presenceManager;
+ presenceManager = NULL;
if (serverFromClientSession) {
serverFromClientSession->finishSession();
@@ -106,9 +108,13 @@ void Server::stop(boost::optional<ServerError> e) {
if (serverFromNetworkConnectionServer) {
serverFromNetworkConnectionServer->stop();
+ serverFromNetworkConnectionServer->cancelAllEvents();
+ serverFromNetworkConnectionServer.reset();
}
if (serverFromClientConnectionServer) {
serverFromClientConnectionServer->stop();
+ serverFromClientConnectionServer->cancelAllEvents();
+ serverFromClientConnectionServer.reset();
}
stopping = false;
@@ -344,6 +350,7 @@ void Server::handlePresenceChanged(boost::shared_ptr<Presence> presence) {
}
void Server::handleClientConnectionServerStopped(boost::optional<BoostConnectionServer::Error> e) {
+ std::cout << "Client server stoppedd " << (bool) e << std::endl;
if (e) {
if (*e == BoostConnectionServer::Conflict) {
stop(ServerError(ServerError::C2SPortConflict));
@@ -358,6 +365,7 @@ void Server::handleClientConnectionServerStopped(boost::optional<BoostConnection
}
void Server::handleLinkLocalConnectionServerStopped(boost::optional<BoostConnectionServer::Error> e) {
+ std::cout << "LL server stoppedd " << (bool) e << std::endl;
if (e) {
if (*e == BoostConnectionServer::Conflict) {
stop(ServerError(ServerError::LinkLocalPortConflict));