From beb63c47b68760cf4619239b81f06e61639699dd Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 11 Jun 2017 15:36:44 +0100 Subject: Keep a static pointer to the current IceTray::Service instance --- icetray/icetray/icetrayService.cpp | 22 ++++++++++++++++++++++ icetray/icetray/icetrayService.h | 7 +++++++ 2 files changed, 29 insertions(+) diff --git a/icetray/icetray/icetrayService.cpp b/icetray/icetray/icetrayService.cpp index aff6a8a..7f66cd1 100644 --- a/icetray/icetray/icetrayService.cpp +++ b/icetray/icetray/icetrayService.cpp @@ -2,8 +2,30 @@ #include #include #include "icetrayService.h" +#include namespace IceTray { + Service * Service::current = nullptr; + + Service::Service() + { + BOOST_ASSERT(!current); + current = this; + } + + Service::~Service() + { + BOOST_ASSERT(current); + current = nullptr; + } + + Service * + Service::getCurrent() + { + BOOST_ASSERT(current); + return current; + } + void Service::start(const std::string & name, const Ice::CommunicatorPtr & ic, const Ice::StringSeq & args) { adp = ic->createObjectAdapter(name); diff --git a/icetray/icetray/icetrayService.h b/icetray/icetray/icetrayService.h index c59028a..69ab487 100644 --- a/icetray/icetray/icetrayService.h +++ b/icetray/icetray/icetrayService.h @@ -9,6 +9,9 @@ namespace IceTray { class DLL_PUBLIC Service : public IceBox::Service, public AdHoc::AbstractPluginImplementation { public: + Service(); + virtual ~Service(); + virtual void addObjects(const std::string & name, const Ice::CommunicatorPtr & ic, const Ice::StringSeq &, const Ice::ObjectAdapterPtr &) = 0; void start(const std::string & name, const Ice::CommunicatorPtr & ic, const Ice::StringSeq & args) override; @@ -17,7 +20,11 @@ namespace IceTray { DatabasePoolPtr getConnectionPool(const Ice::CommunicatorPtr & ic, const std::string & type, const std::string & prefix); + static Service * getCurrent(); Ice::ObjectAdapterPtr adp; + + private: + static Service * current; }; typedef IceInternal::Handle ServicePtr; -- cgit v1.2.3