7 #include "ctrlCamp/SCopy.hpp" 9 #include <fwCom/Signal.hpp> 10 #include <fwCom/Signal.hxx> 11 #include <fwCom/Signals.hpp> 13 #include <fwData/mt/ObjectWriteLock.hpp> 15 #include <fwDataCamp/exception/ObjectNotFound.hpp> 16 #include <fwDataCamp/getObject.hpp> 23 const ::fwServices::IService::KeyType s_SOURCE_INPUT =
"source";
24 const ::fwServices::IService::KeyType s_TARGET_INOUT =
"target";
29 m_mode(ModeType::UPDATE)
44 typedef ::fwRuntime::ConfigurationElement::sptr ConfigurationType;
46 m_hasExtractTag =
false;
47 const ConfigurationType inCfg =
m_configuration->findConfigurationElement(
"in");
48 SLM_ASSERT(
"One 'in' tag is required.", inCfg);
50 const std::vector< ConfigurationType > inoutCfg =
m_configuration->find(
"inout");
51 const std::vector< ConfigurationType > outCfg =
m_configuration->find(
"out");
52 SLM_ASSERT(
"One 'inout' or one 'out' tag is required.", inoutCfg.size() + outCfg.size() == 1);
54 const std::vector< ConfigurationType > extractCfg = inCfg->find(
"extract");
55 SLM_ASSERT(
"Only one 'extract' tag is authorized.", extractCfg.size() <= 1);
56 if (extractCfg.size() == 1)
58 ConfigurationType cfg = extractCfg[0];
59 SLM_ASSERT(
"Missing attribute 'from'.", cfg->hasAttribute(
"from"));
60 m_path = cfg->getAttributeValue(
"from");
61 m_hasExtractTag =
true;
64 const ConfigurationType modeConfig =
m_configuration->findConfigurationElement(
"mode");
67 auto mode = modeConfig->getValue();
68 if(mode ==
"copyOnStart")
70 m_mode = ModeType::START;
72 else if(mode ==
"copyOnUpdate")
74 m_mode = ModeType::UPDATE;
78 SLM_ERROR(
"Mode " + mode +
" unknown. It should be either 'copyOnStart' or 'copyOnUpdate'");
87 if(m_mode == ModeType::START)
97 if(m_mode == ModeType::UPDATE)
103 SLM_ERROR(
"Object copy was request but the mode is to 'copyOnStart'");
112 this->
setOutput(s_TARGET_INOUT,
nullptr);
120 ::fwData::Object::sptr target;
121 ::fwData::Object::csptr source;
122 target = this->getInOut< ::fwData::Object >(s_TARGET_INOUT);
128 ::fwData::Object::csptr sourceObject = this->getInput< ::fwData::Object >(s_SOURCE_INPUT);
131 ::fwData::Object::sptr object;
134 object = ::fwDataCamp::getObject( sourceObject, m_path,
true );
138 SLM_WARN(
"Object from '"+ m_path +
"' not found");
140 catch(std::exception& e)
142 OSLM_FATAL(
"Unhandled exception: " << e.what());
145 SLM_WARN_IF(
"Object from '"+ m_path +
"' not found", !
object);
153 source = sourceObject;
168 target->deepCopy(source);
virtual CTRLCAMP_API void starting() override
Does nothing.
CTRLCAMP_API SCopy()
Constructor.
Class allowing to block a Connection.
The namespace ctrlCamp contains services using camp.
A helper to lock object on exclusive mode.
virtual CTRLCAMP_API void updating() override
Does nothing.
#define SLM_WARN(message)
UpdateSlotType::sptr m_slotUpdate
Slot to call update method.
#define SLM_ERROR(message)
FWSERVICES_API void setOutput(const ::fwServices::IService::KeyType &key, const ::fwData::Object::sptr &object, size_t index=0)
Register an output object at a given key in the OSR, replacing it if it already exists.
This interface defines service API. It can be considered as a default type for services using fwCamp...
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
static FWDATA_API::fwData::Object::sptr copy(const ::fwData::Object::csptr &source)
return a copy of the source. if source is a null pointer, return a null pointer.
Object not found exception.
Base class for each data object.
virtual CTRLCAMP_API void configuring() override
Configure the service before starting. Apply the configuration to service.
::fwRuntime::ConfigurationElement::sptr m_configuration
Configuration element used to configure service internal state using a generic XML like structure TOD...
#define OSLM_FATAL(message)
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_MODIFIED_SIG
Key in m_signals map of signal m_sigModified.
This service copies an object and updates its own object or the defined target. It can either copy th...
virtual CTRLCAMP_API void stopping() override
Does nothing.
CTRLCAMP_API ~SCopy()
Destructor.
#define SLM_WARN_IF(message, cond)