summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2015-07-21 01:31:47 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2015-07-21 09:00:28 +0100
commite999b4a7b312bd0237ea61d20f533eeb0e8b5755 (patch)
tree558fe923b56980195299abd194516748d275037f
parentSwitch to run rule for capturing output (diff)
downloadproject2-e999b4a7b312bd0237ea61d20f533eeb0e8b5755.tar.bz2
project2-e999b4a7b312bd0237ea61d20f533eeb0e8b5755.tar.xz
project2-e999b4a7b312bd0237ea61d20f533eeb0e8b5755.zip
Split daemon run into setup, run, teardown to avoid race conditions waiting for run to complete setup steps
-rw-r--r--project2/daemon/lib/daemon.cpp10
-rw-r--r--project2/daemon/lib/daemon.h2
-rw-r--r--project2/daemon/p2daemonAppEngine.cpp2
-rw-r--r--project2/ice/iceDaemon.cpp7
-rw-r--r--project2/ice/iceDaemon.h5
-rw-r--r--project2/ice/unittests/testDaemon.cpp2
6 files changed, 25 insertions, 3 deletions
diff --git a/project2/daemon/lib/daemon.cpp b/project2/daemon/lib/daemon.cpp
index 2f1760f..bde0f45 100644
--- a/project2/daemon/lib/daemon.cpp
+++ b/project2/daemon/lib/daemon.cpp
@@ -9,5 +9,15 @@ Daemon::~Daemon()
{
}
+void
+Daemon::setup() const
+{
+}
+
+void
+Daemon::teardown() const
+{
+}
+
INSTANTIATESTORE(std::string, DaemonLoader);
diff --git a/project2/daemon/lib/daemon.h b/project2/daemon/lib/daemon.h
index acb4abf..d565e57 100644
--- a/project2/daemon/lib/daemon.h
+++ b/project2/daemon/lib/daemon.h
@@ -10,7 +10,9 @@ class Daemon : public IntrusivePtrBase {
Daemon();
virtual ~Daemon();
+ virtual void setup() const;
virtual void run() const = 0;
+ virtual void teardown() const;
virtual void shutdown() const = 0;
};
diff --git a/project2/daemon/p2daemonAppEngine.cpp b/project2/daemon/p2daemonAppEngine.cpp
index f6fc178..42b4cda 100644
--- a/project2/daemon/p2daemonAppEngine.cpp
+++ b/project2/daemon/p2daemonAppEngine.cpp
@@ -101,7 +101,9 @@ DaemonAppEngine::process()
Glib::signal_timeout().connect_seconds(sigc::mem_fun(this, &DaemonAppEngine::periodicCallback), periodicTimeout);
evThread = new std::thread(&Glib::MainLoop::run, main_loop.operator->());
Logger()->messagebf(LOG_INFO, "%s: Starting daemon.", __PRETTY_FUNCTION__);
+ daemon->setup();
daemon->run();
+ daemon->teardown();
Logger()->messagebf(LOG_INFO, "%s: Daemon exitted.", __PRETTY_FUNCTION__);
}
diff --git a/project2/ice/iceDaemon.cpp b/project2/ice/iceDaemon.cpp
index 860cd86..14e7c90 100644
--- a/project2/ice/iceDaemon.cpp
+++ b/project2/ice/iceDaemon.cpp
@@ -67,7 +67,7 @@ IceDaemon::shutdown() const
}
void
-IceDaemon::run() const
+IceDaemon::setup() const
{
Logger()->messagebf(LOG_DEBUG, " %s creating adapter %s [%s]...", __PRETTY_FUNCTION__, adapterName, adapterEndpoint);
Ice::ObjectAdapterPtr adapter = ic->createObjectAdapterWithEndpoints(adapterName, adapterEndpoint);
@@ -79,7 +79,12 @@ IceDaemon::run() const
Logger()->messagebf(LOG_DEBUG, " %s starting...", __PRETTY_FUNCTION__);
adapter->activate();
+}
+
+void
+IceDaemon::run() const
+{
Logger()->messagebf(LOG_INFO, " %s running...", __PRETTY_FUNCTION__);
ic->waitForShutdown();
diff --git a/project2/ice/iceDaemon.h b/project2/ice/iceDaemon.h
index 3164699..41343ec 100644
--- a/project2/ice/iceDaemon.h
+++ b/project2/ice/iceDaemon.h
@@ -10,8 +10,9 @@ class IceDaemon : public Daemon, IceBase {
IceDaemon(int & argc, char ** argv);
virtual ~IceDaemon();
- void run() const;
- void shutdown() const;
+ void setup() const override;
+ void run() const override;
+ void shutdown() const override;
void executeTask(const std::string & name, const ParamMap & params) const;
void executeView(const std::string & name, Slicer::ModelPartPtr p, const ParamMap & params) const;
diff --git a/project2/ice/unittests/testDaemon.cpp b/project2/ice/unittests/testDaemon.cpp
index 0740966..4015f4a 100644
--- a/project2/ice/unittests/testDaemon.cpp
+++ b/project2/ice/unittests/testDaemon.cpp
@@ -103,6 +103,7 @@ commonTests()
int dummy = 0;
BOOST_TEST_CHECKPOINT("Run daemon");
DaemonPtr id = new IceDaemon(dummy, NULL);
+ id->setup();
std::thread run(&Daemon::run, id.get());
BOOST_TEST_CHECKPOINT("Create and verify proxies");
@@ -186,6 +187,7 @@ commonTests()
id->shutdown();
run.join();
+ id->teardown();
ic->destroy();
}