7 #include "fwRuntime/io/ProfileReader.hpp" 9 #include "fwRuntime/io/Validator.hpp" 10 #include "fwRuntime/operations.hpp" 11 #include "fwRuntime/profile/Activater.hpp" 12 #include "fwRuntime/profile/Profile.hpp" 13 #include "fwRuntime/profile/Starter.hpp" 14 #include "fwRuntime/Runtime.hpp" 15 #include "fwRuntime/RuntimeException.hpp" 17 #include <boost/filesystem/operations.hpp> 19 #include <libxml/parser.h> 30 std::string ProfileReader::ID(
"id");
31 std::string ProfileReader::NAME(
"name");
32 std::string ProfileReader::VALUE(
"value");
33 std::string ProfileReader::VERSION(
"version");
34 std::string ProfileReader::CHECK_SINGLE_INSTANCE(
"check-single-instance");
35 std::string ProfileReader::ACTIVATE(
"activate");
36 std::string ProfileReader::START(
"start");
37 std::string ProfileReader::PARAM(
"param");
38 std::string ProfileReader::DIS_EXT_PT(
"disable-extension-point");
39 std::string ProfileReader::DIS_EXT(
"disable-extension");
46 boost::filesystem::path normalizedPath(path);
47 normalizedPath.normalize();
50 if(boost::filesystem::exists(normalizedPath) ==
false || boost::filesystem::is_directory(normalizedPath) ==
true)
56 auto profileXSDLocation = ::fwRuntime::getLibraryResourceFilePath(
"fwRuntime-" FWRUNTIME_VER
"/profile.xsd");
60 if( validator.
validate(normalizedPath) == false )
66 xmlDocPtr document = xmlParseFile(normalizedPath.string().c_str());
75 xmlNodePtr rootNode = xmlDocGetRootElement(document);
77 char* pName = (
char*) xmlGetProp(rootNode, (
const xmlChar*) NAME.c_str());
78 char* pVersion = (
char*) xmlGetProp(rootNode, (
const xmlChar*) VERSION.c_str());
79 char* pChkInst = (
char*) xmlGetProp(rootNode, (
const xmlChar*) CHECK_SINGLE_INSTANCE.c_str());
81 SLM_ASSERT(
"Application profile MUST have a name attribute", pName);
82 SLM_ASSERT(
"Application profile MUST have a version attribute", pVersion);
84 std::string sName( pName );
85 std::string sVersion( pVersion );
86 bool checkSingleInstance = pChkInst && std::string(pChkInst) ==
"true";
93 std::shared_ptr< ::fwRuntime::profile::Profile > profile = processProfile(rootNode);
95 profile->setFilePath(normalizedPath);
96 profile->setName(sName);
97 profile->setVersion(sVersion);
98 profile->setCheckSingleInstance(checkSingleInstance);
101 xmlFreeDoc(document);
104 catch(std::exception& exception)
106 xmlFreeDoc(document);
113 std::shared_ptr< ::fwRuntime::profile::Profile > ProfileReader::processProfile(xmlNodePtr node)
118 SPTR(Profile) profile = std::make_shared<Profile>();
119 xmlNodePtr curChild = node->children;
120 for(curChild = node->children; curChild != 0; curChild = curChild->next)
122 if(xmlStrcmp(curChild->name, (
const xmlChar*) ACTIVATE.c_str()) == 0)
124 profile->add( processActivater(curChild) );
128 if(xmlStrcmp(curChild->name, (
const xmlChar*) START.c_str()) == 0)
130 profile->add( processStarter(curChild) );
139 std::shared_ptr< ::fwRuntime::profile::Activater > ProfileReader::processActivater(xmlNodePtr node)
143 std::string identifier;
145 for(curAttr = node->properties; curAttr != 0; curAttr = curAttr->next)
147 if(xmlStrcmp(curAttr->name, (
const xmlChar*) ID.c_str()) == 0)
149 identifier = (
const char*) curAttr->children->content;
153 if(xmlStrcmp(curAttr->name, (
const xmlChar*) VERSION.c_str()) == 0)
155 version = (
const char*) curAttr->children->content;
161 using ::fwRuntime::profile::Activater;
162 std::shared_ptr< Activater > activater(
new Activater(identifier, version) );
165 xmlNodePtr curChild = node->children;
166 for(curChild = node->children; curChild != 0; curChild = curChild->next)
168 if(xmlStrcmp(curChild->name, (
const xmlChar*) PARAM.c_str()) == 0)
170 processActivaterParam( curChild, activater );
174 if(xmlStrcmp(curChild->name, (
const xmlChar*) DIS_EXT_PT.c_str()) == 0)
176 processActivaterDisableExtensionPoint( curChild, activater );
180 if(xmlStrcmp(curChild->name, (
const xmlChar*) DIS_EXT.c_str()) == 0)
182 processActivaterDisableExtension( curChild, activater );
192 void ProfileReader::processActivaterParam(xmlNodePtr node, std::shared_ptr< ::fwRuntime::profile::Activater > activater)
196 std::string identifier;
198 for(curAttr = node->properties; curAttr != 0; curAttr = curAttr->next)
200 if(xmlStrcmp(curAttr->name, (
const xmlChar*) ID.c_str()) == 0)
202 identifier = (
const char*) curAttr->children->content;
206 if(xmlStrcmp(curAttr->name, (
const xmlChar*) VALUE.c_str()) == 0)
208 value = (
const char*) curAttr->children->content;
213 activater->addParameter( identifier, value );
218 void ProfileReader::processActivaterDisableExtensionPoint(xmlNodePtr node,
219 std::shared_ptr< ::fwRuntime::profile::Activater > activater)
223 std::string identifier;
224 for(curAttr = node->properties; curAttr != 0; curAttr = curAttr->next)
226 if(xmlStrcmp(curAttr->name, (
const xmlChar*) ID.c_str()) == 0)
228 identifier = (
const char*) curAttr->children->content;
234 activater->addDisableExtensionPoint( identifier );
239 void ProfileReader::processActivaterDisableExtension(xmlNodePtr node,
240 std::shared_ptr< ::fwRuntime::profile::Activater > activater)
244 std::string identifier;
245 for(curAttr = node->properties; curAttr != 0; curAttr = curAttr->next)
247 if(xmlStrcmp(curAttr->name, (
const xmlChar*) ID.c_str()) == 0)
249 identifier = (
const char*) curAttr->children->content;
255 activater->addDisableExtension( identifier );
260 std::shared_ptr< ::fwRuntime::profile::Starter > ProfileReader::processStarter(xmlNodePtr node)
264 std::string identifier;
266 for(curAttr = node->properties; curAttr != 0; curAttr = curAttr->next)
268 if(xmlStrcmp(curAttr->name, (
const xmlChar*) ID.c_str()) == 0)
270 identifier = (
const char*) curAttr->children->content;
274 if(xmlStrcmp(curAttr->name, (
const xmlChar*) VERSION.c_str()) == 0)
276 version = (
const char*) curAttr->children->content;
282 using ::fwRuntime::profile::Starter;
283 std::shared_ptr< Starter > starter(
new Starter(identifier,
Version(version)) );
The namespace fwRuntime::profile contains classes to manage bundle declares in profile.xml file (activate/start/stop).
Defines the runtime exception class.
FWRUNTIME_API const std::string getErrorLog() const
Retrieves the error log content.
FWRUNTIME_API bool validate(const boost::filesystem::path &xmlFile)
Validates the given file.
The namespace fwRuntime contains classes to manage bundle, configuration element, extension point in ...
Implements an XML validator.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
static FWRUNTIME_API std::shared_ptr< ::fwRuntime::profile::Profile > createProfile(const boost::filesystem::path &path)
Creates a profile from an xml file located at the given path.
Holds version information for libraries and bundles.