fw4spl
Add.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2018.
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/op/Add.hpp"
8 
9 #include "fwServices/IService.hpp"
10 #include "fwServices/macros.hpp"
11 #include "fwServices/registry/ServiceFactory.hpp"
12 
13 #include <fwTools/fwID.hpp>
14 
15 #include <boost/lexical_cast.hpp>
16 
17 #include <vector>
18 
19 namespace fwServices
20 {
21 
22 //------------------------------------------------------------------------------
23 
24 ::fwServices::IService::sptr add( ::fwData::Object::sptr _obj,
25  const std::string& _serviceType,
26  const std::string& _implType,
27  const std::string& _uid)
28 {
29  FW_DEPRECATED_MSG("'fwServices::add(object, srvType, srvImpl[,uid])' is deprecated.", "20.0");
30  ::fwServices::IService::sptr srv;
31  srv = ::fwServices::registry::ServiceFactory::getDefault()->create( _serviceType, _implType );
32  FW_RAISE_IF("Failed to add " + _implType, !srv );
33  ::fwServices::OSR::registerService( _obj, srv );
34  if(!_uid.empty())
35  {
36  SLM_ASSERT( "Try to set ID: " + _uid + " but already has an ID: " + srv->getID(), !srv->hasID() );
37  srv->setID( _uid );
38  }
39  return srv;
40 }
41 
42 //------------------------------------------------------------------------------
43 
44 ::fwServices::IService::sptr add( const std::string& _implType, const std::string& _uid)
45 {
46  ::fwServices::IService::sptr srv;
47  srv = ::fwServices::registry::ServiceFactory::getDefault()->create( _implType );
48  ::fwServices::OSR::registerService( srv );
49  FW_RAISE_IF("Failed to add " + _implType, !srv );
50  if(!_uid.empty())
51  {
52  SLM_ASSERT( "Try to set ID: " + _uid + " but already has an ID: " + srv->getID(), !srv->hasID() );
53  srv->setID( _uid );
54  }
55  return srv;
56 }
57 
58 //------------------------------------------------------------------------------
59 
60 }
Namespace fwServices is dedicated to (mimic) the dynamic affectation of methods to (pure data) object...
#define FW_DEPRECATED_MSG(message, version)
Use this macro when deprecating a function to warn the developer.
Definition: spyLog.hpp:360
#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 ServiceFactory::sptr getDefault()
Return the unique Instance, create it if required at first access.
FWSERVICES_API::fwServices::IService::sptr add(::fwData::Object::sptr obj, const std::string &serviceType, const std::string &_implType, const std::string &_id="")
Create and attach to the object obj a service of type serviceType, implementation _implementationId w...
Definition: Add.cpp:24