7 #include "fwServices/registry/ServiceConfig.hpp" 9 #include <fwRuntime/ConfigurationElement.hpp> 10 #include <fwRuntime/helper.hpp> 11 #include <fwRuntime/Runtime.hpp> 18 const std::string ServiceConfig::CONFIG_EXT_POINT =
"::fwServices::registry::ServiceConfig";
39 typedef std::shared_ptr< ::fwRuntime::Extension > ExtensionType;
41 std::vector< ExtensionType > extElements;
42 extElements = ::fwRuntime::getAllExtensionsForPoint(CONFIG_EXT_POINT);
43 for(ExtensionType ext : extElements)
46 SLM_ASSERT(
"Missing id element", ext->hasConfigurationElement(
"id"));
47 std::string
id = ext->findConfigurationElement(
"id")->getValue();
50 std::string service =
"";
51 if ( ext->hasConfigurationElement(
"service") )
53 service = ext->findConfigurationElement(
"service")->getValue();
57 std::string desc =
"No description available";
58 if ( ext->hasConfigurationElement(
"desc") )
60 desc = ext->findConfigurationElement(
"desc")->getValue();
64 ::fwRuntime::ConfigurationElement::csptr config = ext->findConfigurationElement(
"config");
74 (
const std::string& configId,
75 const std::string& service,
76 const std::string& desc,
77 ::fwRuntime::ConfigurationElement::csptr config)
81 OSLM_DEBUG(
"New service config registering : " 82 <<
" configId = " << configId
83 <<
" service = " << service
87 SLM_ASSERT(
"The service config with the id "<< configId <<
" already exists.",
90 ServiceConfigInfo::sptr info = ServiceConfigInfo::New();
91 info->service = service;
93 info->config = config;
94 m_reg[configId] = info;
114 const std::string& serviceImpl )
const 117 Registry::const_iterator iter =
m_reg.find( configId );
118 SLM_ASSERT(
"The id " << configId <<
" is not found in the application configuration registry",
119 iter !=
m_reg.end());
120 SLM_ASSERT(
"The id " << configId <<
" is not allowed for this service " << serviceImpl,
121 serviceImpl.empty() || iter->second->service.empty() || iter->second->service == serviceImpl);
122 return iter->second->config;
130 Registry::const_iterator iter =
m_reg.find( configId );
131 SLM_ASSERT(
"The id " << configId <<
" is not found in the application configuration registry",
132 iter !=
m_reg.end());
133 return iter->second->desc;
141 std::vector< std::string > configs;
143 for(Registry::value_type srvCfg :
m_reg)
145 ServiceConfigInfo::sptr info = srvCfg.second;
146 if ( (info->service.empty() && !matchingOnly ) || info->service == serviceImpl)
148 configs.push_back(srvCfg.first);
Contains fwAtomsFilter::registry details.
FWSERVICES_API::fwRuntime::ConfigurationElement::csptr getServiceConfig(const std::string &configId, const std::string &serviceImpl="") const
Returns the configuration with the given id for the service with the given implementation.
FWSERVICES_API void clearRegistry()
Clear the registry.
FWSERVICES_API void addServiceConfigInfo(const std::string &configId, const std::string &service, const std::string &desc,::fwRuntime::ConfigurationElement::csptr config)
Register a new service configuration.
Namespace fwServices is dedicated to (mimic) the dynamic affectation of methods to (pure data) object...
mutable::fwCore::mt::ReadWriteMutex m_registryMutex
Used to protect the registry access.
::boost::unique_lock< ReadWriteMutex > WriteLock
Defines a lock of write type for read/write mutex.
FWSERVICES_API std::vector< std::string > getAllConfigForService(std::string serviceImpl, bool matchingOnly=false) const
Returns a vector containing the names of the available config for the service with the given implemen...
Registry m_reg
Container of service information <configId, service config information>
FWSERVICES_API void parseBundleInformation()
Parses bundle information to retrieve service declaration.
FWSERVICES_API const std::string & getConfigDesc(const std::string &configId) const
Returns the description of the given configuration name.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
::boost::shared_lock< ReadWriteMutex > ReadLock
Defines a lock of read type for read/write mutex.
FWSERVICES_API ServiceConfig()
Constructor.
static ServiceConfig::sptr s_currentServiceConfig
The global instance of the service config.
static FWSERVICES_API ServiceConfig::sptr getDefault()
Return the default global instance of ServiceConfig.
virtual FWSERVICES_API ~ServiceConfig()
Destructor.
#define OSLM_DEBUG(message)