Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #include "MarshallingService.hpp"
00041 #include "../TaskContext.hpp"
00042 #include "../plugin/ServicePlugin.hpp"
00043
00044 #include "rtt-config.h"
00045 #if !defined(ORO_EMBEDDED)
00046 #include "../OperationCaller.hpp"
00047 #endif
00048 #include "PropertyLoader.hpp"
00049
00050
00051 ORO_SERVICE_NAMED_PLUGIN(RTT::marsh::MarshallingService, "marshalling")
00052
00053 namespace RTT {
00054 using namespace detail;
00055
00056 MarshallingService::shared_ptr MarshallingService::Create(TaskContext* parent){
00057 shared_ptr sp(new MarshallingService(parent));
00058 parent->provides()->addService( sp );
00059 return sp;
00060 }
00061
00062 MarshallingService::MarshallingService(TaskContext* parent)
00063 : Service("marshalling", parent)
00064 {
00065 this->doc("Property marshalling interface. Use this service to read and write properties from/to a file.");
00066 this->addOperation("loadProperties",&MarshallingService::loadProperties, this)
00067 .doc("Read, and create if necessary, Properties from a file.")
00068 .arg("Filename","The file to read the (new) Properties from.");
00069 this->addOperation("storeProperties", &MarshallingService::storeProperties, this)
00070 .doc("Store properties in a file and overwrite any existing content.")
00071 .arg("Filename", "The file to write the Properties to.");
00072
00073 this->addOperation("readProperties", &MarshallingService::readProperties, this)
00074 .doc("Read all Properties from a file. Returns false if one or more properties are missing or have a wrong type in that file.").arg("Filename", "The file to read the Properties from.");
00075 this->addOperation("readProperty", &MarshallingService::readProperty, this)
00076 .doc("Read a single Property from a file.").arg("Name", "The name of (or the path to) the property to read.").arg("Filename", "The file to read the Properties from.");
00077
00078 this->addOperation("updateProperties", &MarshallingService::updateProperties, this)
00079 .doc("Read some Properties from a file. Updates only matching properties. Returns false upon type mismatch.")
00080 .arg("Filename", "The file to read the Properties from.");
00081 this->addOperation("updateFile", &MarshallingService::updateFile, this)
00082 .doc("Write some Properties to a file, ie, only the ones that are already present in the file.").arg("Filename", "The file to write the Properties to.");
00083
00084 this->addOperation("writeProperties", &MarshallingService::writeProperties, this)
00085 .doc("Write all Properties to a file, but keep existing ones in that file.").arg("Filename", "The file to write the Properties to.");
00086 this->addOperation("writeProperty", &MarshallingService::writeProperty, this)
00087 .doc("Write a single Property to a file and keep existing ones in that file.").arg("Name", "The name of (or the path to) the property to write.").arg("Filename", "The file to write the Properties to.");
00088 }
00089
00090 bool MarshallingService::loadProperties(const std::string& filename) const
00091 {
00092 PropertyLoader pl(mowner);
00093 return pl.load( filename );
00094 }
00095
00096 bool MarshallingService::storeProperties(const std::string& filename) const
00097 {
00098 PropertyLoader pl(mowner);
00099 return pl.store( filename );
00100 }
00101
00102 bool MarshallingService::readProperties(const std::string& filename) const
00103 {
00104 PropertyLoader pl(mowner);
00105 return pl.configure( filename, true);
00106 }
00107 bool MarshallingService::updateProperties(const std::string& filename) const
00108 {
00109 PropertyLoader pl(mowner);
00110 return pl.configure( filename, false);
00111 }
00112 bool MarshallingService::writeProperties(const std::string& filename) const
00113 {
00114 PropertyLoader pl(mowner);
00115 return pl.save( filename, true);
00116 }
00117 bool MarshallingService::updateFile(const std::string& filename) const
00118 {
00119 PropertyLoader pl(mowner);
00120 return pl.save( filename, false);
00121 }
00122
00123 bool MarshallingService::readProperty(const std::string& name, const std::string& filename) {
00124 PropertyLoader pl(mowner);
00125 return pl.configure(filename, name);
00126 }
00127
00128 bool MarshallingService::writeProperty(const std::string& name, const std::string& filename) {
00129 PropertyLoader pl(mowner);
00130 return pl.save(filename, name);
00131 }
00132
00133
00134 }