42 #ifdef OROPKG_CORELIB_PROPERTIES_MARSHALLING 43 #include ORODAT_CORELIB_PROPERTIES_MARSHALLING_INCLUDE 44 #include ORODAT_CORELIB_PROPERTIES_DEMARSHALLING_INCLUDE 46 #include "../Logger.hpp" 47 #include "../TaskContext.hpp" 49 #include "../types/PropertyComposition.hpp" 57 : target(task->provides().get())
67 #ifndef OROPKG_CORELIB_PROPERTIES_MARSHALLING 68 log(
Error) <<
"No Property DemarshallInterface configured !" << endlog();
73 log(
Error) <<
"Service " <<target->
getName()<<
" has no Properties to configure." << endlog();
77 log(
Info) <<
"Loading properties into Service '" <<target->
getName()
78 <<
"' with '"<<filename<<
"'."<< endlog();
85 log(
Error) <<
"Could not open file "<< filename << endlog();
90 vector<ActionInterface*> assignComs;
92 if ( demarshaller->deserialize( propbag ) )
118 log(
Error) <<
"Some error occured while parsing "<< filename.c_str() <<endlog();
124 <<
"Uncaught exception in deserialise !"<< endlog();
129 #endif // OROPKG_CORELIB_PROPERTIES_MARSHALLING 136 #ifndef OROPKG_CORELIB_PROPERTIES_MARSHALLING 137 log(
Error) <<
"No Property DemarshallInterface configured !" << endlog();
142 log(
Error) <<
"Service " <<target->
getName()<<
" has no Properties to configure." << endlog();
146 log(
Info) <<
"Configuring Service '" <<target->
getName()
147 <<
"' with '"<<filename<<
"'."<< endlog();
148 bool failure =
false;
154 log(
Error) <<
"Could not open file "<< filename << endlog();
160 if ( demarshaller->deserialize( propbag ) )
181 log(
Error) <<
"Some error occured while parsing "<< filename.c_str() <<endlog();
188 <<
"Uncaught exception in deserialise !"<< endlog();
193 #endif // OROPKG_CORELIB_PROPERTIES_MARSHALLING 200 #ifndef OROPKG_CORELIB_PROPERTIES_MARSHALLING 201 log(
Error) <<
"No Property Marshaller configured !" << endlog();
204 std::ofstream file( filename.c_str() );
215 OROCLS_CORELIB_PROPERTIES_MARSHALLING_DRIVER<std::ostream> marshaller( file );
216 marshaller.serialize( allProps );
218 log(
Info) <<
"Wrote "<< filename <<endlog();
221 log(
Error) <<
"Could not open file "<< filename <<
" for writing."<<endlog();
231 #ifndef OROPKG_CORELIB_PROPERTIES_MARSHALLING 232 log(
Error) <<
"No Property MarshallInterface configured !" << endlog();
238 <<
" does not have Properties to save." << endlog();
245 std::ifstream ifile( filename.c_str() );
249 log(
Info) << target->
getName()<<
" updating of file "<< filename << endlog();
252 if ( demarshaller.deserialize( allProps ) == false ) {
254 log(
Error) <<
"While updating "<< target->
getName() <<
" : Failed to read "<< filename << endlog();
259 log(
Info) <<
"Creating "<< filename << endlog();
260 return store(filename);
271 bool updater =
false;
273 log(
Info) <<
"Writing all properties of "<<target->
getName()<<
" to file "<< filename << endlog();
277 log(
Info) <<
"Refreshing properties in file "<< filename <<
" with values of properties of "<<target->
getName() << endlog();
280 if (updater ==
false) {
281 log(
Error) <<
"Could not update properties of file "<< filename <<
"."<<endlog();
288 std::ofstream file( filename.c_str() );
291 OROCLS_CORELIB_PROPERTIES_MARSHALLING_DRIVER<std::ostream> marshaller( file );
292 marshaller.serialize( allProps );
293 log(
Info) <<
"Wrote "<< filename <<endlog();
296 log(
Error) <<
"Could not open file "<< filename <<
" for writing."<<endlog();
310 #ifndef OROPKG_CORELIB_PROPERTIES_MARSHALLING 311 log(
Error) <<
"No Property DemarshallInterface configured !" << endlog();
315 log(
Info) <<
"Reading Property '" <<name
316 <<
"' from file '"<<filename<<
"'."<< endlog();
317 bool failure =
false;
323 log(
Error) <<
"Could not open file "<< filename << endlog();
328 if ( demarshaller->deserialize( propbag ) )
341 log(
Error) <<
"Some error occured while parsing "<< filename.c_str() <<endlog();
347 log(
Error) <<
"Uncaught exception in deserialise !"<< endlog();
352 #endif // OROPKG_CORELIB_PROPERTIES_MARSHALLING 358 #ifndef OROPKG_CORELIB_PROPERTIES_MARSHALLING 359 log(
Error) <<
"No Property MarshallInterface configured !" << endlog();
367 std::ifstream ifile( filename.c_str() );
371 log(
Info) <<
"Updating file "<< filename <<
" with properties of "<<target->
getName()<<endlog();
374 if ( demarshaller.deserialize( fileProps ) == false ) {
376 log(
Error) <<
"Failed to read "<< filename << endlog();
381 log(
Info) <<
"Creating "<< filename << endlog();
395 log(
Error) <<
"Could not update properties of file "<< filename <<
"."<<endlog();
400 std::ofstream file( filename.c_str() );
403 OROCLS_CORELIB_PROPERTIES_MARSHALLING_DRIVER<std::ostream> marshaller( file );
404 marshaller.serialize( fileProps );
405 log(
Info) <<
"Wrote Property "<<name <<
" to "<< filename <<endlog();
408 log(
Error) <<
"Could not open file "<< filename <<
" for writing."<<endlog();
const std::string & getName() const
Returns the name of this service instance.
bool updateProperty(PropertyBag &target, const PropertyBag &source, const std::string &name, const std::string &separator)
This function updates (recursively) the values of a single Property object of one Bag with the proper...
PropertyLoader(TaskContext *task)
Constructor.
bool updateProperties(PropertyBag &target, const PropertyBag &source)
This function updates (recursively) the values of Property objects of one Bag with the values of Prop...
bool configure(const std::string &filename, bool all=true) const
Read the XML cpf file and 'refresh' the matching properties of the given Service. ...
PropertyBag * properties()
Return a bag of all properties.
bool copyProperties(PropertyBag &target, const PropertyBag &source)
This function copies (recursively) the Properties of one Bag into another Bag.
This class fills up a given bag with the results of an introspection.
bool load(const std::string &filename) const
Read the XML cpf file and create (or refresh the matching properties) of the given Service...
bool RTT_API composePropertyBag(PropertyBag const &sourcebag, PropertyBag &target)
Uses the type composition to compose all typed properties from a property bag.
A container for holding references to properties.
void introspect(const PropertyBag &v)
Use this entry function to inspect a bag.
This class allows storage and retrieval of operations, ports, attributes and properties provided by a...
bool save(const std::string &filename, bool all=true) const
Write the XML cpf file with the properties of the given Service.
Convenient short notation for every sub-namespace of RTT.
void deletePropertyBag(PropertyBag &target)
This function iterates over a PropertyBag and recursively deletes all Property objects.
bool refreshProperty(const PropertyBag &target, const PropertyBase &source)
Refresh one Property in the target bag with the new value.
bool store(const std::string &filename) const
Stores all properties of a Service in a new file or overwrite an existing one.
Notify the Logger in which 'module' the message occured.
The TaskContext is the C++ representation of an Orocos component.
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
#define OROCLS_CORELIB_PROPERTIES_DEMARSHALLING_DRIVER
bool refreshProperties(const PropertyBag &target, const PropertyBag &source, bool allprops)
This function refreshes the values of the properties in one PropertyBag with the values of the proper...