From 63bd94e3f45f74babe43bacbf5da6c132535e3f7 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 9 Jun 2019 10:47:18 +0100 Subject: Adds IceCube support --- icetray/dryice/dryice.h | 11 +++++- icetray/icetray/icecube.cpp | 5 +++ icetray/icetray/icecube.h | 62 +++++++++++++++++++++++++++++++ icetray/icetray/icetrayService.h | 2 + icetray/unittests/testIceTray.cpp | 17 +++++++++ icetray/unittests/testIceTrayReplace.cpp | 1 + icetray/unittests/testIceTrayService.ice | 5 +++ icetray/unittests/testIceTrayServiceI.cpp | 13 ++++++- icetray/unittests/testIceTrayServiceI.h | 6 +++ 9 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 icetray/icetray/icecube.cpp create mode 100644 icetray/icetray/icecube.h diff --git a/icetray/dryice/dryice.h b/icetray/dryice/dryice.h index a934efa..237c31f 100644 --- a/icetray/dryice/dryice.h +++ b/icetray/dryice/dryice.h @@ -5,9 +5,10 @@ #include #include #include "icetrayService.h" +#include "icecube.h" namespace IceTray { - class DLL_PUBLIC DryIce { + class DLL_PUBLIC DryIce : private Cube { public: DryIce(const Ice::StringSeq & = Ice::StringSeq()); DryIce(const DryIce &) = delete; @@ -22,6 +23,14 @@ namespace IceTray { void replace(const std::string &, const Ice::ObjectPtr &); + template + static auto replace(const Args & ... args) + { + pm()->remove(typeid(T).name()); + return add(args...); + } + + Ice::CommunicatorPtr ic; IceTray::ServicePtr s; }; diff --git a/icetray/icetray/icecube.cpp b/icetray/icetray/icecube.cpp new file mode 100644 index 0000000..2908c16 --- /dev/null +++ b/icetray/icetray/icecube.cpp @@ -0,0 +1,5 @@ +#include "icecube.h" +#include + +INSTANTIATEPLUGINOF(IceTray::CubePlugIn); + diff --git a/icetray/icetray/icecube.h b/icetray/icetray/icecube.h new file mode 100644 index 0000000..f2a3454 --- /dev/null +++ b/icetray/icetray/icecube.h @@ -0,0 +1,62 @@ +#ifndef ICETRAY_ICECUBE_H +#define ICETRAY_ICECUBE_H + +#include +#include +#include +#include "icetrayService.h" + +namespace IceTray { + class CubePlugIn : public AdHoc::AbstractPluginImplementation { }; + + template + class CubePlugInOf : public CubePlugIn, public I { + using I::I; + }; + + class CubeObject : public CubePlugIn { + public: + explicit inline CubeObject(Ice::ObjectPrxPtr o) : obj(std::move(o)) { } + Ice::ObjectPrxPtr obj; + }; + + class Cube { + protected: + static inline auto pm() { return &Service::getCurrent()->servicePlugins; } + + public: + template + static auto addObject(const Ice::ObjectAdapterPtr & adp, const std::string & name, const Args & ... args) + { + static_assert(std::is_convertible::value); + static_assert(std::is_convertible::value); + auto prx = adp->add(std::make_shared(args...), Ice::stringToIdentity(name)); + return pm()->add(std::make_shared(prx), + typeid(typename T::ProxyType).name(), __FILE__, __LINE__); + } + + template + static auto add(const Args & ... args) + { + static_assert(std::is_convertible *, T *>::value); + return pm()->add(std::make_shared>(args...), typeid(T).name(), __FILE__, __LINE__); + } + + template + static auto get() + { + if constexpr (std::is_convertible::value) { + using Prx = typename T::ProxyType; + auto c = pm()->getImplementation(typeid(Prx).name()); + return Ice::uncheckedCast(std::dynamic_pointer_cast(c)->obj); + } + else { + auto c = pm()->getImplementation(typeid(T).name()); + return std::dynamic_pointer_cast(c); + } + } + }; +} + +#endif + diff --git a/icetray/icetray/icetrayService.h b/icetray/icetray/icetrayService.h index 6ea6a77..6c48a71 100644 --- a/icetray/icetray/icetrayService.h +++ b/icetray/icetray/icetrayService.h @@ -30,10 +30,12 @@ namespace IceTray { void shutdownLoggers(); friend class DryIce; + friend class Cube; Ice::ObjectAdapterPtr adp; static Service * current; std::set logWriters; OptionsCollation optionsCollation; + AdHoc::PluginManager servicePlugins; }; typedef std::shared_ptr ServicePtr; diff --git a/icetray/unittests/testIceTray.cpp b/icetray/unittests/testIceTray.cpp index d5cda0b..307d0d7 100644 --- a/icetray/unittests/testIceTray.cpp +++ b/icetray/unittests/testIceTray.cpp @@ -43,6 +43,23 @@ BOOST_AUTO_TEST_CASE( services ) p->method2(1, "test"); } +BOOST_AUTO_TEST_CASE( cube_services_proxy ) +{ + auto prx = IceTray::Cube::get(); + BOOST_REQUIRE(prx); + prx->ice_ping(); + prx->method1(); + prx->method2(1, "test"); +} + +BOOST_AUTO_TEST_CASE( cube_services_local ) +{ + auto ptr = IceTray::Cube::get(); + BOOST_REQUIRE(ptr); + ptr->method1(); + ptr->method2(1, "test"); +} + BOOST_AUTO_TEST_CASE( getIceComponents ) { BOOST_REQUIRE(getService()); diff --git a/icetray/unittests/testIceTrayReplace.cpp b/icetray/unittests/testIceTrayReplace.cpp index 1558326..ac176b4 100644 --- a/icetray/unittests/testIceTrayReplace.cpp +++ b/icetray/unittests/testIceTrayReplace.cpp @@ -21,6 +21,7 @@ class Service : public IceTray::DryIce { Service() { replace("test", std::make_shared()); + replace(); } }; diff --git a/icetray/unittests/testIceTrayService.ice b/icetray/unittests/testIceTrayService.ice index e0a3dad..fc0caf4 100644 --- a/icetray/unittests/testIceTrayService.ice +++ b/icetray/unittests/testIceTrayService.ice @@ -3,5 +3,10 @@ module TestIceTray { void method1(); void method2(int id, string name); }; + + local interface TestCube { + void method1(); + void method2(int id, string name); + }; }; diff --git a/icetray/unittests/testIceTrayServiceI.cpp b/icetray/unittests/testIceTrayServiceI.cpp index 09c2ac6..33cdde4 100644 --- a/icetray/unittests/testIceTrayServiceI.cpp +++ b/icetray/unittests/testIceTrayServiceI.cpp @@ -8,6 +8,7 @@ #include #include #include +#include "icecube.h" class Foo { }; @@ -66,9 +67,19 @@ namespace TestIceTray { BOOST_VERIFY((fetchCache(sql::testIceTrayServiceTestSql, 10, id, name)) == (fetchCache(sql::testIceTrayServiceTestSql, 10, id, name))); } + void TestCubeI::method1() + { + } + + void TestCubeI::method2(Ice::Int, const std::string &) + { + } + void TestService::addObjects(const std::string &, const Ice::CommunicatorPtr & ic, const Ice::StringSeq &, const Ice::ObjectAdapterPtr & adp) { - adp->add(std::make_shared(getConnectionPool(ic, "postgresql", "icetraydb")), Ice::stringToIdentity("test")); + IceTray::Cube::addObject( + adp, "test", getConnectionPool(ic, "postgresql", "icetraydb")); + IceTray::Cube::add(); } NAMEDFACTORY("default", TestService, IceTray::ServiceFactory); diff --git a/icetray/unittests/testIceTrayServiceI.h b/icetray/unittests/testIceTrayServiceI.h index d300668..ef2f3a6 100644 --- a/icetray/unittests/testIceTrayServiceI.h +++ b/icetray/unittests/testIceTrayServiceI.h @@ -21,6 +21,12 @@ namespace TestIceTray { public: void addObjects(const std::string &, const Ice::CommunicatorPtr &, const Ice::StringSeq &, const Ice::ObjectAdapterPtr &) override; }; + + class TestCubeI : public TestCube { + public: + void method1() override; + void method2(Ice::Int id, const std::string & name) override; + }; } #endif -- cgit v1.2.3