23typedef std::map< std::string, std::weak_ptr<asg::IAsgService> >
ServiceMap_t;
29 std::mutex s_serviceMutex;
35 put(
const std::shared_ptr<IAsgService>& pservice )
37 using namespace msgComponentConfig;
43 "Received a null pointer" );
44 return StatusCode::FAILURE;
48 const std::string&
name = pservice->name();
52 "The received service doesn't have a name" );
53 return StatusCode::FAILURE;
56 std::lock_guard<std::mutex> lock (s_serviceMutex);
58 auto& currentService = s_services[
name];
59 if (currentService.lock())
62 << name <<
"\" already registered");
63 return StatusCode::FAILURE;
66 currentService = pservice;
67 return StatusCode::SUCCESS;
72 std::shared_ptr<IAsgService> ServiceStore::
73 get(
const std::string& name,
bool silent )
75 using namespace msgToolHandle;
77 std::lock_guard<std::mutex> lock (s_serviceMutex);
78 auto iservice = s_services.find( name );
80 std::shared_ptr<IAsgService>
result;
81 if( iservice != s_services.end() )
82 result = iservice->second.lock();
84 if( ! silent && !result )
85 ANA_MSG_ERROR (
"Service with name \"" << name <<
"\" not found");
91 void ServiceStore::dumpServiceConfig ()
93 using namespace asg::msgProperty;
97 std::map<std::string,std::map<std::string,std::string> >
properties;
99 std::lock_guard<std::mutex> lock (s_serviceMutex);
100 for (
auto& service : s_services)
102 auto myservice = service.second.lock();
105 auto& myproperties =
properties[service.first];
106 asg::IAsgService *myservicePtr = myservice.get();
107 myproperties[
""] = std::string (
typeid(*myservicePtr).name()) +
"/" + service.first;
108 for (
auto& property :
dynamic_cast<const AsgService*
>(myservice.get())->getPropertyMgr()->getProperties())
110 std::string asString;
111 if (property.second->getString (asString).isFailure())
113 ANA_MSG_ERROR (
"on property " << property.first <<
" for service " << service.first);
114 myproperties[
property.first] =
"<<invalid>>";
116 myproperties[
property.first] = asString;
124 for (
const auto& myproperties : properties)
126 for (
auto& property : myproperties.second)
128 std::cout << myproperties.first;
129 if (!property.first.empty())
130 std::cout <<
"." <<
property.first;
131 std::cout <<
" = " <<
property.second <<
"\n";
134 std::cout << std::flush;
std::map< std::string, std::weak_ptr< asg::IAsgService > > ServiceMap_t
Convenience type definition.
#define ATLAS_THREAD_SAFE
Base class for the dual-use service implementation classes.
::StatusCode StatusCode
StatusCode definition for legacy code.