MarshallingService.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002   tag: FMTC  Tue Mar 11 21:49:27 CET 2008  MarshallingService.cpp
00003 
00004                         MarshallingService.cpp -  description
00005                            -------------------
00006     begin                : Tue March 11 2008
00007     copyright            : (C) 2008 FMTC
00008     email                : peter.soetens@fmtc.be
00009 
00010  ***************************************************************************
00011  *   This library is free software; you can redistribute it and/or         *
00012  *   modify it under the terms of the GNU General Public                   *
00013  *   License as published by the Free Software Foundation;                 *
00014  *   version 2 of the License.                                             *
00015  *                                                                         *
00016  *   As a special exception, you may use this file as part of a free       *
00017  *   software library without restriction.  Specifically, if other files   *
00018  *   instantiate templates or use macros or inline functions from this     *
00019  *   file, or you compile this file and link it with other files to        *
00020  *   produce an executable, this file does not by itself cause the         *
00021  *   resulting executable to be covered by the GNU General Public          *
00022  *   License.  This exception does not however invalidate any other        *
00023  *   reasons why the executable file might be covered by the GNU General   *
00024  *   Public License.                                                       *
00025  *                                                                         *
00026  *   This library is distributed in the hope that it will be useful,       *
00027  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00028  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00029  *   Lesser General Public License for more details.                       *
00030  *                                                                         *
00031  *   You should have received a copy of the GNU General Public             *
00032  *   License along with this library; if not, write to the Free Software   *
00033  *   Foundation, Inc., 59 Temple Place,                                    *
00034  *   Suite 330, Boston, MA  02111-1307  USA                                *
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 //ORO_SERVICE_PLUGIN( RTT::marsh::MarshallingService )
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 
00070         this->addOperation("storeProperties", &MarshallingService::storeProperties, this)
00071                 .doc("Store properties in a file and overwrite any existing content.")
00072                 .arg("Filename", "The file to write the Properties to.");
00073 
00074         this->addOperation("readProperties", &MarshallingService::readProperties, this)
00075                 .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.");
00076         this->addOperation("readProperty", &MarshallingService::readProperty, this)
00077                 .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.");
00078 
00079         this->addOperation("updateProperties", &MarshallingService::updateProperties, this)
00080                 .doc("Read some Properties from a file. Updates only matching properties. Returns false upon type mismatch.")
00081                 .arg("Filename", "The file to read the Properties from.");
00082         this->addOperation("updateFile", &MarshallingService::updateFile, this)
00083                 .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.");
00084 
00085         this->addOperation("writeProperties", &MarshallingService::writeProperties, this)
00086                 .doc("Write all Properties to a file, but keep existing ones in that file.").arg("Filename", "The file to write the Properties to.");
00087         this->addOperation("writeProperty", &MarshallingService::writeProperty, this)
00088                 .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.");
00089 
00090         this->addOperation("loadServiceProperties",&MarshallingService::loadServiceProperties, this)
00091                 .doc("Read, and create if necessary, Properties from a file.")
00092                 .arg("Filename","The file to read the (new) Properties from.")
00093                 .arg("Servicename","The Service to load the (new) Properties to.");
00094         this->addOperation("storeServiceProperties", &MarshallingService::storeServiceProperties, this)
00095                 .doc("Store properties in a file and overwrite any existing content.")
00096                 .arg("Filename", "The file to write the Properties to.")
00097                 .arg("Servicename","The Service store the Properties of.");
00098 
00099         this->addOperation("readServiceProperties", &MarshallingService::readServiceProperties, this)
00100                 .doc("Read all Properties from a file. Returns false if one or more properties are missing or have a wrong type in that file.")
00101                 .arg("Filename", "The file to read the Properties from.")
00102                 .arg("Servicename","The Service to load the Properties to.");
00103         this->addOperation("readServiceProperty", &MarshallingService::readServiceProperty, this)
00104                 .doc("Read a single Property from a file.")
00105                 .arg("Name", "The name of (or the path to) the property to read.")
00106                 .arg("Filename", "The file to read the Property from.")
00107             .arg("Servicename","The Service to load the Property to.");
00108 
00109         this->addOperation("updateServiceProperties", &MarshallingService::updateServiceProperties, this)
00110                 .doc("Read some Properties from a file. Updates only matching properties. Returns false upon type mismatch.")
00111                 .arg("Filename", "The file to read the Properties from.")
00112                 .arg("Servicename","The Service to update the Properties of.");
00113 
00114         this->addOperation("updateServiceFile", &MarshallingService::updateServiceFile, this)
00115                 .doc("Write some Properties to a file, ie, only the ones that are already present in the file.")
00116                 .arg("Filename", "The file to write the Properties to.")
00117                 .arg("Servicename","The Service to update the Properties of.");
00118 
00119         this->addOperation("writeServiceProperties", &MarshallingService::writeServiceProperties, this)
00120                 .doc("Write all Properties to a file, but keep existing ones in that file.")
00121                 .arg("Filename", "The file to write the Properties to.")
00122                 .arg("Servicename","The Service to write the Properties of.");
00123 
00124         this->addOperation("writeServiceProperty", &MarshallingService::writeServiceProperty, this)
00125                 .doc("Write a single Property to a file and keep existing ones in that file.")
00126                 .arg("Name", "The name of (or the path to) the property to write.")
00127                 .arg("Filename", "The file to write the Properties to.")
00128                 .arg("Servicename","The Service to write the Property of.");
00129 
00130     }
00131 
00132     bool MarshallingService::loadProperties(const std::string& filename) const
00133     {
00134         PropertyLoader pl(this->getParent().get());
00135         return pl.load( filename );
00136     }
00137 
00138     bool MarshallingService::storeProperties(const std::string& filename) const
00139     {
00140         PropertyLoader pl(this->getParent().get());
00141         return pl.store( filename );
00142     }
00143 
00144     bool MarshallingService::readProperties(const std::string& filename) const
00145     {
00146         PropertyLoader pl(this->getParent().get());
00147         return pl.configure( filename, true); // all
00148     }
00149     bool MarshallingService::updateProperties(const std::string& filename) const
00150     {
00151         PropertyLoader pl(this->getParent().get());
00152         return pl.configure( filename, false); // not all
00153     }
00154     bool MarshallingService::writeProperties(const std::string& filename) const
00155     {
00156         PropertyLoader pl(this->getParent().get());
00157         return pl.save( filename, true);
00158     }
00159     bool MarshallingService::updateFile(const std::string& filename) const
00160     {
00161         PropertyLoader pl(this->getParent().get());
00162         return pl.save( filename, false);
00163     }
00164 
00165     bool MarshallingService::readProperty(const std::string& name, const std::string& filename) {
00166         PropertyLoader pl(this->getParent().get());
00167         return pl.configure(filename, name);
00168     }
00169 
00170     bool MarshallingService::writeProperty(const std::string& name, const std::string& filename) {
00171         PropertyLoader pl(this->getParent().get());
00172         return pl.save(filename, name);
00173     }
00174 
00175 
00176     bool MarshallingService::loadServiceProperties(const std::string& filename, const std::string& servicename) const
00177     {
00178         if(!this->getParent()->hasService(servicename)){
00179             Logger::In(this->getName());
00180             log(Error)<<this->getParent()->getName()<<" does not have a service called "<<servicename<<endlog();
00181             return false;
00182         }
00183         PropertyLoader pl(this->getParent()->provides(servicename).get());
00184         return pl.load( filename );
00185     }
00186 
00187     bool MarshallingService::storeServiceProperties(const std::string& filename, const std::string& servicename) const
00188     {
00189         if(!this->getParent()->hasService(servicename)){
00190             Logger::In(this->getName());
00191             log(Error)<<this->getParent()->getName()<<" does not have a service called "<<servicename<<endlog();
00192             return false;
00193         }
00194         PropertyLoader pl(this->getParent()->provides(servicename).get());
00195         return pl.store( filename );
00196     }
00197 
00198     bool MarshallingService::readServiceProperties(const std::string& filename, const std::string& servicename) const
00199     {
00200         if(!this->getParent()->hasService(servicename)){
00201             Logger::In(this->getName());
00202             log(Error)<<this->getParent()->getName()<<" does not have a service called "<<servicename<<endlog();
00203             return false;
00204         }
00205         PropertyLoader pl(this->getParent()->provides(servicename).get());
00206         return pl.configure( filename, true); // all
00207     }
00208     bool MarshallingService::updateServiceProperties(const std::string& filename, const std::string& servicename) const
00209     {
00210         if(!this->getParent()->hasService(servicename)){
00211             Logger::In(this->getName());
00212             log(Error)<<this->getParent()->getName()<<" does not have a service called "<<servicename<<endlog();
00213             return false;
00214         }
00215         PropertyLoader pl(this->getParent()->provides(servicename).get());
00216         return pl.configure( filename, false); // not all
00217     }
00218     bool MarshallingService::writeServiceProperties(const std::string& filename, const std::string& servicename) const
00219     {
00220         if(!this->getParent()->hasService(servicename)){
00221             Logger::In(this->getName());
00222             log(Error)<<this->getParent()->getName()<<" does not have a service called "<<servicename<<endlog();
00223             return false;
00224         }
00225         PropertyLoader pl(this->getParent()->provides(servicename).get());
00226         return pl.save( filename, true);
00227     }
00228     bool MarshallingService::updateServiceFile(const std::string& filename, const std::string& servicename) const
00229     {
00230         if(!this->getParent()->hasService(servicename)){
00231             Logger::In(this->getName());
00232             log(Error)<<this->getParent()->getName()<<" does not have a service called "<<servicename<<endlog();
00233             return false;
00234         }
00235         PropertyLoader pl(this->getParent()->provides(servicename).get());
00236         return pl.save( filename, false);
00237     }
00238 
00239     bool MarshallingService::readServiceProperty(const std::string& name, const std::string& filename, const std::string& servicename) {
00240         if(!this->getParent()->hasService(servicename)){
00241             Logger::In(this->getName());
00242             log(Error)<<this->getParent()->getName()<<" does not have a service called "<<servicename<<endlog();
00243             return false;
00244         }
00245         PropertyLoader pl(this->getParent()->provides(servicename).get());
00246         return pl.configure(filename, name);
00247     }
00248 
00249     bool MarshallingService::writeServiceProperty(const std::string& name, const std::string& filename, const std::string& servicename) {
00250         if(!this->getParent()->hasService(servicename)){
00251             Logger::In(this->getName());
00252             log(Error)<<this->getParent()->getName()<<" does not have a service called "<<servicename<<endlog();
00253             return false;
00254         }
00255         PropertyLoader pl(this->getParent()->provides(servicename).get());
00256         return pl.save(filename, name);
00257     }
00258 
00259 
00260 }


rtt
Author(s): RTT Developers
autogenerated on Wed Aug 26 2015 16:15:49