fw4spl
Bundles/core/dataReg/src/dataReg/parser/List.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2017.
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 "dataReg/parser/List.hpp"
8 
9 #include <fwData/List.hpp>
10 
11 #include <fwServices/macros.hpp>
12 
13 #include <boost/foreach.hpp>
14 
15 fwServicesRegisterMacro( ::fwServices::IXMLParser, ::dataReg::parser::List, ::fwData::List );
16 
17 namespace dataReg
18 {
19 namespace parser
20 {
21 
22 //------------------------------------------------------------------------------
23 
24 bool List::refObjectValidator( ::fwRuntime::ConfigurationElement::sptr _cfgElement )
25 {
26  bool isOk = true;
27 
28  for( ::fwRuntime::ConfigurationElement::Iterator configEltIter = _cfgElement->begin();
29  configEltIter != _cfgElement->end();
30  ++configEltIter)
31  {
32  std::string subElementName = (*configEltIter)->getName();
33  if( subElementName != "service" &&
34  subElementName != "serviceList" )
35  {
36  OSLM_ERROR(
37  "xml subelement \""<< subElementName <<
38  "\" for element object is not supported for the moment when you use a reference on item List.");
39  isOk = false;
40  }
41  }
42 
43  return isOk;
44 }
45 
46 //------------------------------------------------------------------------------
47 
49 {
50  SLM_FATAL("This method is deprecated, and thus shouldn't be used.");
51 }
52 
53 //------------------------------------------------------------------------------
54 
55 void List::createConfig( ::fwTools::Object::sptr _obj )
56 {
57  // Declaration of attributes values
58  const std::string OBJECT_BUILD_MODE = "src";
59  const std::string BUILD_OBJECT = "new";
60  const std::string GET_OBJECT = "ref";
61 
62  ::fwData::List::sptr dataList = ::fwData::List::dynamicCast(_obj);
63  SLM_ASSERT("The passed object must be a fwData::List", dataList);
64 
65  for( ::fwRuntime::ConfigurationElement::csptr elem : m_cfg->getElements() )
66  {
67  if( elem->getName() == "item" )
68  {
69 
70  // Test build mode
71  std::string buildMode = BUILD_OBJECT;
72 
73  if ( elem->hasAttribute( OBJECT_BUILD_MODE ) )
74  {
75  buildMode = elem->getExistingAttributeValue( OBJECT_BUILD_MODE );
76  OSLM_ASSERT( "The buildMode \""<< buildMode <<"\" is not supported, it should be either BUILD_OBJECT"
77  "or GET_OBJECT.",
78  buildMode == BUILD_OBJECT || buildMode == GET_OBJECT );
79  }
80 
81  if( buildMode == BUILD_OBJECT )
82  {
83 
84  // Create and manage object config
85  ::fwServices::IAppConfigManager::sptr ctm = ::fwServices::IAppConfigManager::New();
86  ctm->::fwServices::IAppConfigManager::setConfig( elem );
87 
88  m_ctmContainer.push_back( ctm );
89  ctm->create();
90  ::fwData::Object::sptr localObj = ctm->getConfigRoot();
91 
92  // Add object
93  SLM_ASSERT("A ::fwData::List can contain only ::fwData::Object", localObj );
94  dataList->getContainer().push_back( localObj );
95 
96  }
97  else // if( buildMode == GET_OBJECT )
98  {
99  SLM_FATAL("ACH => Todo");
100  }
101  }
102  }
103 }
104 
105 //------------------------------------------------------------------------------
106 
107 void List::startConfig()
108 {
109  for( ::fwServices::IAppConfigManager::sptr ctm : m_ctmContainer )
110  {
111  ctm->start();
112  }
113 }
114 
115 //------------------------------------------------------------------------------
116 
117 void List::updateConfig()
118 {
119  for( ::fwServices::IAppConfigManager::sptr ctm : m_ctmContainer )
120  {
121  ctm->update();
122  }
123 }
124 
125 //------------------------------------------------------------------------------
126 
127 void List::stopConfig()
128 {
129  BOOST_REVERSE_FOREACH( ::fwServices::IAppConfigManager::sptr ctm, m_ctmContainer )
130  {
131  ctm->stop();
132  }
133 }
134 
135 //------------------------------------------------------------------------------
136 
137 void List::destroyConfig()
138 {
139  BOOST_REVERSE_FOREACH( ::fwServices::IAppConfigManager::sptr ctm, m_ctmContainer )
140  {
141  ctm->destroy();
142  }
143  m_ctmContainer.clear();
144 }
145 
146 //------------------------------------------------------------------------------
147 
148 } //namespace parser
149 } //namespace dataReg
150 
#define OSLM_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:310
The namespace dataReg (data registration) contains classes which allow to parse the xml configuration...
virtual DATAREG_API void updating() override
Updating method : create List object.
Specific service for the construction of a List and its associated services from an XML-based descrip...
#define SLM_FATAL(message)
Definition: spyLog.hpp:283
#define OSLM_ERROR(message)
Definition: spyLog.hpp:274
This class defines a list of objects.
#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
static FWSERVICES_API std::shared_ptr< IAppConfigManager > New()
Service type for the construction of an object and associated services from an XML-based description...
Definition: IXMLParser.hpp:36
Container::iterator Iterator
Defines the configuration element container type.