From e975165e297e53801217c3c6696ee064dc0b2772 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 3 Dec 2014 01:06:28 +0000 Subject: Don't create a daemon module for each ice module (they can occur multiple times) create one for each ice object, cos that makes sense --- project2/ice/Jamfile.jam | 2 +- project2/ice/buildDaemon.cpp | 4 --- project2/ice/iceDaemon.cpp | 7 ++--- project2/ice/iceModule.cpp | 15 ++++++++- project2/ice/iceModule.h | 19 +++++------- project2/ice/slice2Daemon.cpp | 4 ++- project2/ice/slice2DaemonLoader.cpp | 46 ---------------------------- project2/ice/slice2DaemonLoader.h | 21 ------------- project2/ice/unittests/testDaemon.cpp | 4 +-- project2/ice/unittests/testDaemonCompile.cpp | 4 +-- 10 files changed, 32 insertions(+), 94 deletions(-) delete mode 100644 project2/ice/slice2DaemonLoader.cpp delete mode 100644 project2/ice/slice2DaemonLoader.h diff --git a/project2/ice/Jamfile.jam b/project2/ice/Jamfile.jam index 2a531cb..fe224b2 100644 --- a/project2/ice/Jamfile.jam +++ b/project2/ice/Jamfile.jam @@ -42,7 +42,7 @@ lib p2iceclient : ; lib p2icedaemon : - pch iceDaemon.cpp iceModule.cpp buildDaemon.cpp slice2Daemon.cpp slice2DaemonLoader.cpp iceViewSerializer.cpp + pch iceDaemon.cpp iceModule.cpp buildDaemon.cpp slice2Daemon.cpp iceViewSerializer.cpp : ../../libmisc glibmm diff --git a/project2/ice/buildDaemon.cpp b/project2/ice/buildDaemon.cpp index a6579c9..674ef21 100644 --- a/project2/ice/buildDaemon.cpp +++ b/project2/ice/buildDaemon.cpp @@ -1,7 +1,6 @@ #include #include "buildDaemon.h" #include "slice2Daemon.h" -#include "slice2DaemonLoader.h" BuildDaemon::BuildDaemon(const boost::filesystem::path & slice, const IceCompile::Deps & dep) : SliceCompile(slice, dep) @@ -19,9 +18,6 @@ BuildDaemon::Body(FILE * out, Slice::UnitPtr u) const { Slice2Daemon daemonBuilder(out); u->visit(&daemonBuilder, false); - - Slice2DaemonLoader daemonLoaderBuilder(out); - u->visit(&daemonLoaderBuilder, false); } boost::filesystem::path diff --git a/project2/ice/iceDaemon.cpp b/project2/ice/iceDaemon.cpp index b9211f9..2dae17e 100644 --- a/project2/ice/iceDaemon.cpp +++ b/project2/ice/iceDaemon.cpp @@ -73,11 +73,8 @@ IceDaemon::run() const Ice::ObjectAdapterPtr adapter = ic->createObjectAdapterWithEndpoints(adapterName, adapterEndpoint); Logger()->messagebf(LOG_DEBUG, " %s installing servants...", __PRETTY_FUNCTION__); - std::set interfaces; - InstanceSet::OnAll([this, adapter, &interfaces](IceDaemonAdapterHandlerLoader * loader) { - IceDaemonAdapterHandlerPtr interfacePtr = loader->create(); - interfacePtr->add(adapter, this, ic); - interfaces.insert(interfacePtr); + InstanceSet::OnAll([this, adapter](IceDaemonAdapterHandlerLoader * loader) { + loader->create(this)->add(adapter, ic); }); Logger()->messagebf(LOG_DEBUG, " %s starting...", __PRETTY_FUNCTION__); diff --git a/project2/ice/iceModule.cpp b/project2/ice/iceModule.cpp index c1e035e..7e39858 100644 --- a/project2/ice/iceModule.cpp +++ b/project2/ice/iceModule.cpp @@ -3,7 +3,8 @@ #include "iceDaemon.h" #include "instanceStore.impl.h" -IceDaemonModule::IceDaemonModule(const IceDaemon * id) : +IceDaemonModule::IceDaemonModule(const std::string & n, const IceDaemon * id) : + name(n), iceDaemon(id) { } @@ -18,5 +19,17 @@ IceDaemonModule::executeTask(const std::string & name, const ParamMap & params) iceDaemon->executeTask(name, params); } +void +IceDaemonModule::add(Ice::ObjectAdapterPtr adapter, Ice::CommunicatorPtr ic) +{ + adapter->add(this, ic->stringToIdentity(name)); +} + +void +IceDaemonModule::remove(Ice::ObjectAdapterPtr adapter, Ice::CommunicatorPtr ic) +{ + adapter->remove(ic->stringToIdentity(name)); +} + INSTANTIATESTORE(std::string, IceDaemonAdapterHandlerLoader); diff --git a/project2/ice/iceModule.h b/project2/ice/iceModule.h index 3886aef..168e134 100644 --- a/project2/ice/iceModule.h +++ b/project2/ice/iceModule.h @@ -12,26 +12,23 @@ typedef std::map ParamMap; class IceDaemon; -class IceDaemonModule { - protected: - IceDaemonModule(const IceDaemon *); +class IceDaemonModule : virtual public ::Ice::Object { + public: + void add(Ice::ObjectAdapterPtr, Ice::CommunicatorPtr); + void remove(Ice::ObjectAdapterPtr, Ice::CommunicatorPtr); protected: + IceDaemonModule(const std::string &, const IceDaemon *); + void executeTask(const std::string & name, const ParamMap & params) const; void executeView(const std::string & name, Slicer::ModelPartPtr p, const ParamMap & params) const; private: + const std::string name; const IceDaemon * const iceDaemon; }; -class IceDaemonAdapterHandler : public IntrusivePtrBase { - public: - virtual void add(Ice::ObjectAdapterPtr, const IceDaemon *, Ice::CommunicatorPtr) const = 0; - virtual void remove(Ice::ObjectAdapterPtr, Ice::CommunicatorPtr) const = 0; -}; - -typedef boost::intrusive_ptr IceDaemonAdapterHandlerPtr; -typedef GenLoader IceDaemonAdapterHandlerLoader; +typedef GenLoader IceDaemonAdapterHandlerLoader; #endif diff --git a/project2/ice/slice2Daemon.cpp b/project2/ice/slice2Daemon.cpp index 4cd879f..3e889d3 100644 --- a/project2/ice/slice2Daemon.cpp +++ b/project2/ice/slice2Daemon.cpp @@ -23,7 +23,7 @@ Slice2Daemon::visitClassDefStart(const Slice::ClassDefPtr & c) fprintf(code, "\tclass %sImpl : public IceDaemonModule, public %s {\n", c->name().c_str(), c->name().c_str()); fprintf(code, "\t\tpublic:\n"); fprintf(code, "\t\t\t%sImpl(const IceDaemon * id) :\n", c->name().c_str()); - fprintf(code, "\t\t\t\tIceDaemonModule(id)\n"); + fprintf(code, "\t\t\t\tIceDaemonModule(\"%s%s\", id)\n", module.c_str(), c->name().c_str()); fprintf(code, "\t\t\t{\n\t\t\t}\n\n"); return true; } @@ -58,6 +58,8 @@ void Slice2Daemon::visitClassDefEnd(const Slice::ClassDefPtr & c) { fprintf(code, "\t}; // class %sImpl\n\n", c->name().c_str()); + fprintf(code, "\tDECLARE_GENERIC_LOADER(\"%s-%s\", IceDaemonAdapterHandlerLoader, %sImpl);\n\n", + module.c_str(), c->name().c_str(), c->name().c_str()); } void diff --git a/project2/ice/slice2DaemonLoader.cpp b/project2/ice/slice2DaemonLoader.cpp deleted file mode 100644 index 81fd501..0000000 --- a/project2/ice/slice2DaemonLoader.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include -#include "slice2DaemonLoader.h" -#include - -Slice2DaemonLoader::Slice2DaemonLoader(FILE * c) : - code(c) -{ -} - -bool -Slice2DaemonLoader::visitModuleStart(const Slice::ModulePtr & m) -{ - module = m->name(); - fprintf(code, "// Loader for %s\n", m->name().c_str()); - fprintf(code, "class %sIceDaemonAdapterHandler : public IceDaemonAdapterHandler {\n", m->name().c_str()); - fprintf(code, "\tpublic:\n"); - return true; -} - -bool -Slice2DaemonLoader::visitClassDefStart(const Slice::ClassDefPtr & c) -{ - interfaces.push_back(c->name()); - return false; -} - -void -Slice2DaemonLoader::visitModuleEnd(const Slice::ModulePtr & m) -{ - fprintf(code, "\t\tvoid add(Ice::ObjectAdapterPtr adapter, const IceDaemon * id, Ice::CommunicatorPtr ic) const {\n"); - BOOST_FOREACH(const auto & i, interfaces) { - fprintf(code, "\t\t\tadapter->add(new %s::%sImpl(id), ic->stringToIdentity(\"%s%s\"));\n", - module.c_str(), i.c_str(), module.c_str(), i.c_str()); - } - fprintf(code, "\t\t}\n\n"); - fprintf(code, "\t\tvoid remove(Ice::ObjectAdapterPtr adapter, Ice::CommunicatorPtr ic) const {\n"); - BOOST_FOREACH(const auto & i, interfaces) { - fprintf(code, "\t\t\tadapter->remove(ic->stringToIdentity(\"%s%s\"));\n", - module.c_str(), i.c_str()); - } - fprintf(code, "\t\t}\n\n"); - fprintf(code, "};\n"); - fprintf(code, "DECLARE_GENERIC_LOADER(\"%s\", IceDaemonAdapterHandlerLoader, %sIceDaemonAdapterHandler);\n", m->name().c_str(), m->name().c_str()); - fprintf(code, "// End loader for%s\n\n", m->name().c_str()); -} - diff --git a/project2/ice/slice2DaemonLoader.h b/project2/ice/slice2DaemonLoader.h deleted file mode 100644 index 3c1fd5f..0000000 --- a/project2/ice/slice2DaemonLoader.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef ICEBUILDLOADER_H -#define ICEBUILDLOADER_H - -#include - -class Slice2DaemonLoader : public Slice::ParserVisitor { - public: - Slice2DaemonLoader(FILE * c); - - virtual bool visitModuleStart(const Slice::ModulePtr & m); - virtual bool visitClassDefStart(const Slice::ClassDefPtr & c); - virtual void visitModuleEnd(const Slice::ModulePtr & m); - - private: - FILE * code; - std::string module; - std::vector interfaces; -}; - -#endif - diff --git a/project2/ice/unittests/testDaemon.cpp b/project2/ice/unittests/testDaemon.cpp index fe0b0f5..74b95b2 100644 --- a/project2/ice/unittests/testDaemon.cpp +++ b/project2/ice/unittests/testDaemon.cpp @@ -61,7 +61,7 @@ void commonTests() { BOOST_TEST_CHECKPOINT("Verify loaded"); - BOOST_REQUIRE(IceDaemonAdapterHandlerLoader::getFor("UnitTest")); + BOOST_REQUIRE(IceDaemonAdapterHandlerLoader::getFor("UnitTest-SimpleInterface")); int dummy = 0; BOOST_TEST_CHECKPOINT("Run daemon"); @@ -133,7 +133,7 @@ void unloadTests() { BOOST_TEST_CHECKPOINT("Verify unloaded"); - BOOST_REQUIRE_THROW(IceDaemonAdapterHandlerLoader::createNew("UnitTest"), NotSupported); + BOOST_REQUIRE_THROW(IceDaemonAdapterHandlerLoader::createNew("UnitTest-SimpleInterface", NULL), NotSupported); } BOOST_AUTO_TEST_CASE( test_daemon ) diff --git a/project2/ice/unittests/testDaemonCompile.cpp b/project2/ice/unittests/testDaemonCompile.cpp index bc8052c..26eb651 100644 --- a/project2/ice/unittests/testDaemonCompile.cpp +++ b/project2/ice/unittests/testDaemonCompile.cpp @@ -16,7 +16,7 @@ void commonTests() { BOOST_TEST_CHECKPOINT("Verify loaded"); - BOOST_REQUIRE(IceDaemonAdapterHandlerLoader::getFor("UnitTest")); + BOOST_REQUIRE(IceDaemonAdapterHandlerLoader::getFor("UnitTest-SimpleInterface")); } static @@ -24,7 +24,7 @@ void unloadTests() { BOOST_TEST_CHECKPOINT("Verify unloaded"); - BOOST_REQUIRE_THROW(IceDaemonAdapterHandlerLoader::createNew("UnitTest"), NotSupported); + BOOST_REQUIRE_THROW(IceDaemonAdapterHandlerLoader::createNew("UnitTest-SimpleInterface", NULL), NotSupported); } BOOST_AUTO_TEST_CASE( compile_daemon_full ) -- cgit v1.2.3