Orocos Real-Time Toolkit  2.6.0
MarshallingService.cpp
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         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); // all
00106     }
00107     bool MarshallingService::updateProperties(const std::string& filename) const
00108     {
00109         PropertyLoader pl(mowner);
00110         return pl.configure( filename, false); // not all
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 }