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 #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
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