7 #include "fwActivities/registry/Activities.hpp" 9 #include <fwData/Vector.hpp> 11 #include <fwRuntime/ConfigurationElement.hpp> 12 #include <fwRuntime/Convert.hpp> 13 #include <fwRuntime/helper.hpp> 14 #include <fwRuntime/Runtime.hpp> 16 #include <boost/foreach.hpp> 17 #include <boost/regex.hpp> 26 ActivityAppConfigParam::ActivityAppConfigParam(
const ConfigType& config) :
27 replace(config.get<
std::string>(
"<xmlattr>.replace"))
31 by = config.get_optional<std::string>(
"<xmlattr>.uid").get_value_or(
"");
34 by = config.get<std::string>(
"<xmlattr>.by");
41 ActivityAppConfig::ActivityAppConfig(
const ConfigType& config) :
42 id(config.
get<
std::string>(
"<xmlattr>.id"))
44 if(config.count(
"parameters") == 1 )
46 const ConfigType& configParameters = config.get_child(
"parameters");
47 BOOST_FOREACH(
const ConfigType::value_type& v, configParameters.equal_range(
"parameter") )
49 ActivityAppConfigParam parameter( v.second );
50 parameters.push_back( parameter );
53 OSLM_ASSERT(
"At most 1 <parameters> tag is allowed", config.count(
"parameters") < 2);
58 ActivityRequirementKey::ActivityRequirementKey(
const ConfigType& config) :
59 key(config.get_value<
std::string>()),
60 path(config.get_optional<
std::string>(
"<xmlattr>.path").get_value_or(
""))
66 ActivityRequirement::ActivityRequirement(
const ConfigType& config) :
67 name(config.
get<
std::string>(
"<xmlattr>.name")),
68 type(config.
get<
std::string>(
"<xmlattr>.type")),
69 container(config.get_optional<
std::string>(
"<xmlattr>.container").get_value_or(
"")),
70 description(config.get_optional<
std::string>(
"desc").get_value_or(
"")),
71 validator(config.get_optional<
std::string>(
"validator").get_value_or(
"")),
72 minOccurs(config.get_optional<unsigned int>(
"<xmlattr>.minOccurs").get_value_or(1)),
73 maxOccurs(config.get_optional<unsigned int>(
"<xmlattr>.maxOccurs").get_value_or(1))
75 BOOST_FOREACH(
const ConfigType::value_type& v, config.equal_range(
"key") )
77 keys.push_back(ActivityRequirementKey(v.second));
80 if (config.get_optional<std::string>(
"<xmlattr>.maxOccurs").get_value_or(
"") ==
"*")
82 this->maxOccurs = std::numeric_limits<unsigned int>::max();
85 std::string createStr = config.get_optional<std::string>(
"<xmlattr>.create").get_value_or(
"false");
86 SLM_ASSERT(
"'create' attribute must be 'true' or 'false'", createStr ==
"true" || createStr ==
"false");
87 create = (createStr ==
"true");
88 SLM_ASSERT(
"Create option is only available if minOccurs = 0 and maxOccurs = 1",
89 !create || (minOccurs == 0 && maxOccurs == 1));
92 "minOccurs value shall be equal or greater than 0 and lower or equal to maxOccurs (" << maxOccurs <<
")",
93 0 <= minOccurs && minOccurs <= maxOccurs);
94 OSLM_TRACE(
"ActivityRequirement : " << name <<
" : " << type <<
", " << minOccurs <<
"-" << maxOccurs
95 <<
"(" << description <<
")");
106 bundleId(ext->getBundle()->getIdentifier()),
107 bundleVersion(ext->getBundle()->
getVersion().string()),
120 ActivityRequirement requirement( ::fwRuntime::Convert::toPropertyTree(*elem).get_child(
"requirement") );
121 requirements.push_back( requirement );
123 MinMaxType& minMax = m_requirementCount[requirement.type];
125 minMax.first += requirement.minOccurs;
127 if (requirement.maxOccurs < (std::numeric_limits<unsigned int>::max() - minMax.second) )
129 minMax.second += requirement.maxOccurs;
133 minMax.second = std::numeric_limits<unsigned int>::max();
140 builderImpl = builderCfg->getValue();
144 builderImpl =
"::fwActivities::builder::ActivitySeriesInitData";
151 std::string validatorImplStr = validatorCfg->getValue();
152 if(!validatorImplStr.empty())
154 validatorsImpl.push_back( validatorImplStr );
161 auto validators = ::fwRuntime::Convert::toPropertyTree(validatorsCfg).get_child(
"validators");
162 BOOST_FOREACH(
auto const &validator, validators.equal_range(
"validator") )
164 validatorsImpl.push_back( validator.second.get_value<std::string>() );
169 if (validatorsImpl.empty())
171 validatorsImpl.push_back(
"::fwActivities::validator::DefaultActivity");
177 bool ActivityInfo::usableWith(DataCountType dataCounts)
const 179 bool ok = dataCounts.size() <= m_requirementCount.size();
183 for(
const RequirementsMinMaxCount::value_type& reqCount : m_requirementCount )
185 const MinMaxType& reqMinMax = reqCount.second;
186 DataCountType::iterator iter = dataCounts.find(reqCount.first);
187 if (iter != dataCounts.end())
189 unsigned int dataCount = iter->second;
190 ok = dataCount && reqMinMax.first <= dataCount && dataCount <= reqMinMax.second;
191 dataCounts.erase(iter);
195 ok = (reqMinMax.first == 0);
205 for(
const DataCountType::value_type& dataCount : dataCounts )
207 if(m_requirementCount.find(dataCount.first) == m_requirementCount.end())
222 Activities::sptr Activities::s_activities = Activities::New();
226 Activities::sptr Activities::getDefault()
233 Activities::~Activities()
239 void Activities::parseBundleInformation()
241 std::vector< SPTR( ::fwRuntime::Extension ) > extensions
242 = ::fwRuntime::getAllExtensionsForPoint(
"::fwActivities::registry::Activities");
244 this->parseBundleInformation(extensions);
259 SLM_ASSERT(
"The id " << info.id <<
"(" << info.title <<
")" 260 <<
" already exists in the Activities registry", m_reg.find( info.id ) == m_reg.end());
261 m_reg.insert( Registry::value_type(info.id, info) );
267 Activities::Activities()
273 void Activities::clearRegistry()
281 bool Activities::hasInfo(
const std::string& extensionId )
const 284 Registry::const_iterator iter = m_reg.find( extensionId );
285 return iter != m_reg.end();
290 std::vector< ActivityInfo > Activities::getInfos()
const 292 std::vector< ActivityInfo > infos;
296 for( Registry::value_type val : m_reg )
298 infos.push_back( val.second );
306 ActivityInfo::DataCountType Activities::getDataCount( const ::fwData::Vector::csptr& data )
const 308 ActivityInfo::DataCountType dataCount;
310 for( const ::fwData::Object::csptr& obj : *data)
312 ++dataCount[obj->getClassname()];
320 std::vector< ActivityInfo > Activities::getInfos( const ::fwData::Vector::csptr& data )
const 322 ActivityInfo::DataCountType dataCount = this->getDataCount(data);
323 std::vector< ActivityInfo > infos;
327 for(
const Registry::value_type& regValue : m_reg )
330 if (activity.usableWith(dataCount))
332 infos.push_back(activity);
341 std::vector< std::string > Activities::getKeys()
const 343 std::vector< std::string > keys;
347 for( Registry::value_type val : m_reg )
349 keys.push_back( val.first );
357 const ActivityInfo Activities::getInfo(
const std::string& extensionId )
const 360 Registry::const_iterator iter = m_reg.find( extensionId );
361 SLM_ASSERT(
"The id " << extensionId <<
" is not found in the application configuration parameter registry",
362 iter != m_reg.end());
Contains fwAtomsFilter::registry details.
FWSERVICES_API::fwServices::IService::sptr get(::fwData::Object::sptr obj, std::string serviceType)
Get the first service of type serviceType which is attached to obj.
FWRUNTIME_API std::shared_ptr< ConfigurationElement > findConfigurationElement(const std::string &identifier, const std::string &pointIdentifier)
Retrieve the configuation element with the given identifier for the given extension point...
Holds Activities configuration.
#define OSLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
Defines the extension class.
#define OSLM_TRACE(message)
::boost::unique_lock< ReadWriteMutex > WriteLock
Defines a lock of write type for read/write mutex.
The namespace fwRuntime contains classes to manage bundle, configuration element, extension point in ...
mutable::fwCore::mt::ReadWriteMutex m_registryMutex
Used to protect the registry access.
#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.
FWRUNTIME_API std::shared_ptr< Bundle > getBundle() const
Retrieves the bundle that owns the extension.
Namespace containing activities data and builder.
FWRUNTIME_API::boost::filesystem::path getBundleResourceFilePath(const std::string &bundleIdentifier, const ::boost::filesystem::path &path) noexcept
Retrieve a filesystem valid path for a path relative to the bundle having the specified identifier...
FWATOMSPATCH_API std::string getVersion(const ::fwAtoms::Object::sptr &obj)
Get version of an object.
Container::iterator Iterator
Defines the configuration element container type.
FWRUNTIME_API const std::shared_ptr< ConfigurationElement > findConfigurationElement(const std::string &name) const
Retrieves the first configuration corresponding to the specified name.
#define OSLM_DEBUG(message)