diff options
-rw-r--r-- | project2/Jamfile.jam | 1 | ||||
-rw-r--r-- | project2/ice/Jamfile.jam | 24 | ||||
-rw-r--r-- | project2/ice/iceboxDaemon.cpp | 72 | ||||
-rw-r--r-- | project2/ice/unittests/Jamfile.jam | 8 | ||||
-rw-r--r-- | project2/ice/unittests/testIceBoxDaemon.cpp | 58 |
5 files changed, 161 insertions, 2 deletions
diff --git a/project2/Jamfile.jam b/project2/Jamfile.jam index 7197c4b..8de52d5 100644 --- a/project2/Jamfile.jam +++ b/project2/Jamfile.jam @@ -25,6 +25,7 @@ alias p2daemonparts : : : : build-project console ; build-project cgi ; build-project daemon ; +build-project ice ; # Ensure tests are run (final targets don't reference projects, but specific libraries) build-project common//unittests ; diff --git a/project2/ice/Jamfile.jam b/project2/ice/Jamfile.jam index 9677e15..fc2b970 100644 --- a/project2/ice/Jamfile.jam +++ b/project2/ice/Jamfile.jam @@ -6,6 +6,7 @@ alias glibmm : : : : lib dl ; lib Slice ; lib Ice ; +lib IceBox ; lib IceUtil ; lib pthread ; lib boost_filesystem ; @@ -16,8 +17,8 @@ build-project unittests ; cpp-pch pch : pch.hpp : <library>..//adhocutil <library>../common//p2common - <library>glibmm - <library>slicer + <library>glibmm + <library>slicer ; lib p2iceclient : @@ -60,6 +61,25 @@ lib p2icedaemon : <include>. ; +lib p2icebox : + pch iceboxDaemon.cpp + : + <include>../../libmisc + <library>glibmm + <library>../daemon/lib//p2daemonlib + <library>..//p2parts + <library>dl + <library>Ice + <library>IceBox + <library>IceUtil + : : + <library>../daemon/lib//p2daemonlib + <library>Ice + <library>IceBox + <library>IceUtil + <include>. + ; + lib p2ice : pch iceConvert.cpp iceCompile.cpp sliceCompile.cpp buildComms.cpp slice2Common.cpp iceBase.cpp : diff --git a/project2/ice/iceboxDaemon.cpp b/project2/ice/iceboxDaemon.cpp new file mode 100644 index 0000000..ad7849a --- /dev/null +++ b/project2/ice/iceboxDaemon.cpp @@ -0,0 +1,72 @@ +#include <pch.hpp> +#include <IceBox/IceBox.h> +#include <Ice/Communicator.h> +#include <Ice/Logger.h> +#include <optionsSource.h> +#include <daemon.h> +#include <thread> +#include <appInstance.h> + +class IceBoxDaemon : public IceBox::Service, public AppInstance { + public: + IceBoxDaemon() + { + Plugable::onAllComponents(boost::bind(&ComponentLoader::onBegin, _1)); + } + + ~IceBoxDaemon() + { + Plugable::onAllComponents(boost::bind(&ComponentLoader::onIdle, _1)); + } + + void start(const std::string &, const Ice::CommunicatorPtr & ic, const Ice::StringSeq &) + { + OptionsSource::loadSources([this] { return reqPlatform;} ); + int argc = 0; + char ** argv = nullptr; + ic->getLogger()->print("Creating daemon: " + daemonType); + daemon = DaemonLoader::createNew(daemonType, argc, argv); + daemon->setup(); + daemonThread = new std::thread(&Daemon::run, daemon); + } + + void stop() + { + daemon->shutdown(); + daemonThread->join(); + delete daemonThread; + daemonThread = nullptr; + daemon->teardown(); + daemon.reset(); + } + + INITOPTIONS; + static Glib::ustring daemonType; + static Glib::ustring reqPlatform; + static int periodicTimeout; + + private: + DaemonPtr daemon; + std::thread * daemonThread; +}; + +Glib::ustring IceBoxDaemon::daemonType; +Glib::ustring IceBoxDaemon::reqPlatform; +int IceBoxDaemon::periodicTimeout; + +DECLARE_OPTIONS(IceBoxDaemon, "Project2 IceBox options") +("daemon.type", Options::value(&daemonType), "The core daemon module to run") +("daemon.platform", Options::value(&reqPlatform), "Platform") +("daemon.periodicTimeout", Options::value(&periodicTimeout, 60), + "Delay between occurrences of component periodic calls (default 60s)") +END_OPTIONS(IceBoxDaemon); + + +extern "C" { + IceBox::Service * + createProject2Daemon(Ice::CommunicatorPtr) + { + return new IceBoxDaemon(); + } +} + diff --git a/project2/ice/unittests/Jamfile.jam b/project2/ice/unittests/Jamfile.jam index fe4ce51..8b7e766 100644 --- a/project2/ice/unittests/Jamfile.jam +++ b/project2/ice/unittests/Jamfile.jam @@ -120,3 +120,11 @@ run testDaemon : ; +run + testIceBoxDaemon.cpp + : : : + <library>..//p2icebox + <library>../../ut//p2ut + : + testIceBoxDaemon + ; diff --git a/project2/ice/unittests/testIceBoxDaemon.cpp b/project2/ice/unittests/testIceBoxDaemon.cpp new file mode 100644 index 0000000..b6a2dd5 --- /dev/null +++ b/project2/ice/unittests/testIceBoxDaemon.cpp @@ -0,0 +1,58 @@ +#define BOOST_TEST_MODULE IceBoxDaemon +#include <boost/test/unit_test.hpp> +#include <IceBox/IceBox.h> +#include <Ice/Initialize.h> +#include <Ice/Communicator.h> +#include <daemon.h> + +extern "C" { + IceBox::Service * createProject2Daemon(Ice::CommunicatorPtr); +} + +BOOST_AUTO_TEST_CASE( test_icebox_daemon ) +{ + Ice::StringSeq adminOpts; + Ice::CommunicatorPtr adminComm = Ice::initialize(adminOpts); + BOOST_REQUIRE(adminComm); + + IceBox::Service * service = createProject2Daemon(adminComm); + BOOST_REQUIRE(service); + + Ice::StringSeq serviceOpts; + Ice::CommunicatorPtr serviceComm = Ice::initialize(serviceOpts); + BOOST_REQUIRE(serviceComm); + + service->start("test_icebox_daemon", serviceComm, { }); + + service->stop(); + + delete service; + + serviceComm->destroy(); + adminComm->destroy(); +} + +class TestDaemon : public Daemon { + public: + TestDaemon(int &, char **) : + stop(false) + { + } + + void run() const + { + while (!stop) sleep(1); + } + + void shutdown() const + { + stop = true; + } + + private: + mutable bool stop; +}; +// DECLARE_COMPONENT_LOADER("TestDaemon", TestDaemon, DaemonLoader); +// This doesn't have a name yet because there's no current way to inject settings for daemon.type +DECLARE_COMPONENT_LOADER("", TestDaemon, DaemonLoader); + |