From ad7be2bd9721c0ebf1ebeba7a1b7f36ebb3bffdf Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 23 Aug 2015 17:41:58 +0100 Subject: Add basic support for reading Project2 options from Ice properties --- project2/ice/Jamfile.jam | 2 +- project2/ice/iceboxDaemon.cpp | 5 ++++- project2/ice/iceboxOptionsSource.cpp | 25 +++++++++++++++++++++++++ project2/ice/iceboxOptionsSource.h | 20 ++++++++++++++++++++ project2/ice/unittests/testIceBoxDaemon.cpp | 11 ++++------- 5 files changed, 54 insertions(+), 9 deletions(-) create mode 100644 project2/ice/iceboxOptionsSource.cpp create mode 100644 project2/ice/iceboxOptionsSource.h diff --git a/project2/ice/Jamfile.jam b/project2/ice/Jamfile.jam index fc2b970..76ec226 100644 --- a/project2/ice/Jamfile.jam +++ b/project2/ice/Jamfile.jam @@ -62,7 +62,7 @@ lib p2icedaemon : ; lib p2icebox : - pch iceboxDaemon.cpp + pch [ glob icebox*.cpp ] : ../../libmisc glibmm diff --git a/project2/ice/iceboxDaemon.cpp b/project2/ice/iceboxDaemon.cpp index ad7849a..fa1afd8 100644 --- a/project2/ice/iceboxDaemon.cpp +++ b/project2/ice/iceboxDaemon.cpp @@ -6,6 +6,7 @@ #include #include #include +#include "iceboxOptionsSource.h" class IceBoxDaemon : public IceBox::Service, public AppInstance { public: @@ -21,6 +22,7 @@ class IceBoxDaemon : public IceBox::Service, public AppInstance { void start(const std::string &, const Ice::CommunicatorPtr & ic, const Ice::StringSeq &) { + OptionsSources::Add("service", new IceBoxOptionsSource(ic)); OptionsSource::loadSources([this] { return reqPlatform;} ); int argc = 0; char ** argv = nullptr; @@ -64,8 +66,9 @@ END_OPTIONS(IceBoxDaemon); extern "C" { IceBox::Service * - createProject2Daemon(Ice::CommunicatorPtr) + createProject2Daemon(Ice::CommunicatorPtr ic) { + OptionsSources::Add("admin", new IceBoxOptionsSource(ic)); return new IceBoxDaemon(); } } diff --git a/project2/ice/iceboxOptionsSource.cpp b/project2/ice/iceboxOptionsSource.cpp new file mode 100644 index 0000000..90eca8e --- /dev/null +++ b/project2/ice/iceboxOptionsSource.cpp @@ -0,0 +1,25 @@ +#include "iceboxOptionsSource.h" + +IceBoxOptionsSource::IceBoxOptionsSource(Ice::CommunicatorPtr i) : + ic(i), + startTime(boost::posix_time::microsec_clock::universal_time()) +{ +} + +boost::posix_time::ptime +IceBoxOptionsSource::modifiedTime() const +{ + return startTime; +} + +void +IceBoxOptionsSource::loadInto(const ConfigConsumer & consume, const Options::CurrentPlatform & currentPlatform) const +{ + if (!ic) return; + auto props = ic->getProperties(); + if (!props) return; + for (auto & prop : props->getPropertiesForPrefix("project2")) { + consume(prop.first.substr(9), "", prop.second, currentPlatform); + } +} + diff --git a/project2/ice/iceboxOptionsSource.h b/project2/ice/iceboxOptionsSource.h new file mode 100644 index 0000000..3127fa4 --- /dev/null +++ b/project2/ice/iceboxOptionsSource.h @@ -0,0 +1,20 @@ +#ifndef PROJECT2_ICEBOX_OPTIONSSOURCE_H +#define PROJECT2_ICEBOX_OPTIONSSOURCE_H + +#include +#include + +class IceBoxOptionsSource : public OptionsSource { + public: + IceBoxOptionsSource(Ice::CommunicatorPtr); + + void loadInto(const ConfigConsumer &, const Options::CurrentPlatform & platform) const; + boost::posix_time::ptime modifiedTime() const; + + private: + Ice::CommunicatorPtr ic; + boost::posix_time::ptime startTime; +}; + +#endif + diff --git a/project2/ice/unittests/testIceBoxDaemon.cpp b/project2/ice/unittests/testIceBoxDaemon.cpp index b6a2dd5..a2ba774 100644 --- a/project2/ice/unittests/testIceBoxDaemon.cpp +++ b/project2/ice/unittests/testIceBoxDaemon.cpp @@ -11,15 +11,14 @@ extern "C" { BOOST_AUTO_TEST_CASE( test_icebox_daemon ) { - Ice::StringSeq adminOpts; - Ice::CommunicatorPtr adminComm = Ice::initialize(adminOpts); + Ice::CommunicatorPtr adminComm = Ice::initialize(); BOOST_REQUIRE(adminComm); + adminComm->getProperties()->setProperty("project2.daemon.type", "TestDaemon"); IceBox::Service * service = createProject2Daemon(adminComm); BOOST_REQUIRE(service); - Ice::StringSeq serviceOpts; - Ice::CommunicatorPtr serviceComm = Ice::initialize(serviceOpts); + Ice::CommunicatorPtr serviceComm = Ice::initialize(); BOOST_REQUIRE(serviceComm); service->start("test_icebox_daemon", serviceComm, { }); @@ -52,7 +51,5 @@ class TestDaemon : public Daemon { 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); +DECLARE_COMPONENT_LOADER("TestDaemon", TestDaemon, DaemonLoader); -- cgit v1.2.3