Orocos Real-Time Toolkit
2.5.0
|
00001 /*************************************************************************** 00002 tag: Peter Soetens Mon Jan 19 14:11:20 CET 2004 XMLRPCMarshallInterface.hpp 00003 00004 XMLRPCMarshallInterface.hpp - description 00005 ------------------- 00006 begin : Mon January 19 2004 00007 copyright : (C) 2004 Peter Soetens 00008 email : peter.soetens@mech.kuleuven.ac.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 #ifndef PI_PROPERTIES_XMLRPCSERIALIZER 00039 #define PI_PROPERTIES_XMLRPCSERIALIZER 00040 00041 #include <iostream> 00042 #include <vector> 00043 #include <map> 00044 #include <string> 00045 #include "../Property.hpp" 00046 #include "../base/PropertyIntrospection.hpp" 00047 #include "MarshallInterface.hpp" 00048 #include "StreamProcessor.hpp" 00049 00050 00051 namespace RTT 00052 { namespace marsh { 00053 00054 using namespace std; 00055 00060 template<typename output_stream> 00061 class XMLRPCMarshaller 00062 : public MarshallInterface, public base::PropertyIntrospection, 00063 public StreamProcessor<output_stream> 00064 { 00065 public: 00066 XMLRPCMarshaller(output_stream &os) : 00067 StreamProcessor<output_stream>(os) 00068 {} 00069 00070 virtual void serialize(const Property<bool> &v) 00071 { 00072 *(this->s) << "<name>" << v.getName() << "</name>" 00073 << "<value><boolean>" << v.get() << "</boolean></value>\n"; 00074 } 00075 00076 virtual void serialize(const Property<char> &v) 00077 { 00078 *(this->s) << "<name>" << v.getName() << "</name>" 00079 << "<value><string>" << v.get() << "</string></value>\n"; 00080 } 00081 00082 virtual void serialize(const Property<int> &v) 00083 { 00084 *(this->s) << "<name>" << v.getName() << "</name>" 00085 << "<value><int>" << v.get() << "</int></value>\n"; 00086 } 00087 00088 virtual void serialize(const Property<double> &v) 00089 { 00090 *(this->s) << "<name>" << v.getName() << "</name>" 00091 << "<value><double>" << v.get() << "</double></value>\n"; 00092 } 00093 00094 virtual void serialize(const Property<std::string> &v) 00095 { 00096 *(this->s) << "<name>" << v.getName() << "</name>" 00097 << "<value><string>" << v.get() << "</string></value>\n"; 00098 } 00099 00100 virtual void serialize(const PropertyBag &v) 00101 { 00102 *(this->s) << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; 00103 *(this->s) << "<xmlrpc>\n"; 00104 00105 for ( 00106 std::vector<base::PropertyBase*>::const_iterator i = v.getProperties().begin(); 00107 i != v.getProperties().end(); 00108 i++ ) 00109 { 00110 (*i)->identify(this); 00111 } 00112 *(this->s) << "\n</xmlrpc>\n"; 00113 } 00114 virtual void serialize(const Property<PropertyBag> &b) 00115 { 00116 // cout << "double: " << v; 00117 *(this->s) <<"<struct><name>"<<b.getName()<<"</name>\n"; 00118 PropertyBag v = b.get(); 00119 for ( 00120 std::vector<base::PropertyBase*>::const_iterator i = v.getProperties().begin(); 00121 i != v.getProperties().end(); 00122 i++ ) 00123 { 00124 *(this->s) <<"<member>\n"; 00125 (*i)->identify(this); 00126 *(this->s) <<"</member>"; 00127 } 00128 *(this->s) <<"</struct>\n"; 00129 00130 } 00131 00132 virtual void introspect(const Property<bool> &v) 00133 { 00134 serialize(v); 00135 } 00136 00137 virtual void introspect(const Property<char> &v) 00138 { 00139 serialize(v); 00140 } 00141 00142 virtual void introspect(const Property<int> &v) 00143 { 00144 serialize(v); 00145 } 00146 00147 virtual void introspect(const Property<double> &v) 00148 { 00149 serialize(v); 00150 } 00151 00152 virtual void introspect(const Property<std::string> &v) 00153 { 00154 serialize(v); 00155 } 00156 00157 virtual void introspect(const Property<PropertyBag> &v) 00158 { 00159 serialize(v); 00160 } 00161 virtual void flush() 00162 {} 00163 }; 00164 }} 00165 #endif