fw4spl
AppConfigParameters.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2016.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #include "fwServices/registry/AppConfigParameters.hpp"
8 
9 #include <fwData/Composite.hpp>
10 #include <fwData/Composite.hpp>
11 #include <fwData/String.hpp>
12 #include <fwRuntime/ConfigurationElement.hpp>
13 #include <fwRuntime/helper.hpp>
14 #include <fwRuntime/Runtime.hpp>
15 
16 #include <boost/regex.hpp>
17 
18 namespace fwServices
19 {
20 namespace registry
21 {
22 
23 AppConfigParameters::sptr AppConfigParameters::s_appConfigParameters = AppConfigParameters::New();
24 
25 //-----------------------------------------------------------------------------
26 
27 AppConfigParameters::sptr AppConfigParameters::getDefault()
28 {
29  return s_appConfigParameters;
30 }
31 
32 //-----------------------------------------------------------------------------
33 
35 {
36 }
37 
38 //-----------------------------------------------------------------------------
39 
41 {
42  std::vector< std::shared_ptr< ::fwRuntime::Extension > > extensions = ::fwRuntime::getAllExtensionsForPoint(
43  "::fwServices::registry::AppConfigParameters");
44  for( std::shared_ptr< ::fwRuntime::Extension > ext : extensions )
45  {
46  // Get id
47  std::string extensionId = ext->findConfigurationElement("id")->getValue();
48 
49  FieldAdaptorType parameters;
50 
51  // Get parmeters
52  ::fwRuntime::ConfigurationElement::csptr parametersConfig = ext->findConfigurationElement("parameters");
53  ::fwRuntime::ConfigurationElement::Container elements = parametersConfig->getElements();
54  for( ::fwRuntime::ConfigurationElement::sptr paramConfig : elements )
55  {
56  std::string name = paramConfig->getExistingAttributeValue("name");
57  std::string val = paramConfig->getExistingAttributeValue("value");
58  parameters[name] = val;
59  }
61  Registry::const_iterator iter = m_reg.find( extensionId );
62  SLM_ASSERT("The id " << extensionId
63  << " already exists in the application configuration parameter registry",
64  iter == m_reg.end());
65  m_reg[extensionId] = parameters;
66  }
67 }
68 
69 //-----------------------------------------------------------------------------
70 
72 {
73 }
74 
75 //-----------------------------------------------------------------------------
76 
78 {
80  m_reg.clear();
81 }
82 
83 //-----------------------------------------------------------------------------
84 
85 const FieldAdaptorType & AppConfigParameters::getParameters( const std::string & extensionId ) const
86 {
88  Registry::const_iterator iter = m_reg.find( extensionId );
89  SLM_ASSERT("The id " << extensionId << " is not found in the application configuration parameter registry",
90  iter != m_reg.end());
91  return iter->second;
92 }
93 
94 //-----------------------------------------------------------------------------
95 
96 } // namespace registry
97 
98 } // namespace fwServices
99 
Contains fwAtomsFilter::registry details.
FWSERVICES_API const FieldAdaptorType & getParameters(const std::string &extensionId) const
Get the parameters associated to extension id.
Namespace fwServices is dedicated to (mimic) the dynamic affectation of methods to (pure data) object...
FWSERVICES_API void parseBundleInformation()
Parse bundle information to retrieve config parameters declaration.
std::vector< std::shared_ptr< ConfigurationElement > > Container
Defines the configuration element container type.
::boost::unique_lock< ReadWriteMutex > WriteLock
Defines a lock of write type for read/write mutex.
mutable::fwCore::mt::ReadWriteMutex m_registryMutex
Used to protect the registry access.
std::map< std::string, std::string > FieldAdaptorType
Associations of <pattern, value>.
Definition: AppInfo.hpp:24
#define SLM_ASSERT(message, cond)
work like &#39;assert&#39; from &#39;cassert&#39;, with in addition a message logged by spylog (with FATAL loglevel) ...
Definition: spyLog.hpp:308
FWSERVICES_API void clearRegistry()
Clear the registry.
FWSERVICES_API AppConfigParameters()
Constructor.
static FWSERVICES_API AppConfigParameters::sptr getDefault()
Return the default global instance of AppConfigParameters.
::boost::shared_lock< ReadWriteMutex > ReadLock
Defines a lock of read type for read/write mutex.
Registry m_reg
Container of parameter information.
virtual FWSERVICES_API ~AppConfigParameters()
Destructor.
static AppConfigParameters::sptr s_appConfigParameters
The global instance of the app config parameters.