From 77f6d3cf8aeaa373453a6f5b00b4c00e46ebc998 Mon Sep 17 00:00:00 2001 From: pd Date: Sat, 16 Aug 2008 16:20:00 +0200 Subject: [PATCH] =?UTF-8?q?added=20writing=20of=20properties=20in=20xml2cp?= =?UTF-8?q?p.cpp=20(Jo=C3=A3o=20Xavier)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/xml2cpp.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/tools/xml2cpp.cpp b/tools/xml2cpp.cpp index 25a32d2..439a419 100644 --- a/tools/xml2cpp.cpp +++ b/tools/xml2cpp.cpp @@ -281,6 +281,62 @@ void generate_proxy(Xml::Document &doc, const char *filename) file << tab << "}" << endl << endl; +/// write properties + file << "public:" << endl << endl + << tab << "/* properties exported by this interface */" << endl; + + for (Xml::Nodes::iterator pi = properties.begin (); + pi != properties.end (); ++pi) + { + Xml::Node & property = **pi; + string prop_name = property.get ("name"); + string property_access = property.get ("access"); + if (property_access == "read" || property_access == "readwrite") + { + file << tab << tab << "const " << signature_to_type (property.get("type")) + << " " << prop_name << "() {" << endl; + file << tab << tab << tab << "::DBus::CallMessage call ;\n "; + file << tab << tab << tab + << "call.member(\"Get\"); call.interface(\"org.freedesktop.DBus.Properties\");" + << endl; + file << tab << tab << tab + << "::DBus::MessageIter wi = call.writer(); " << endl; + file << tab << tab << tab + << "const DBus::String interface_name = \"" << ifacename << "\";" + << endl; + file << tab << tab << tab + << "const DBus::String property_name = \"" << prop_name << "\";" + << endl; + file << tab << tab << tab << "wi << interface_name;" << endl; + file << tab << tab << tab << "wi << property_name;" << endl; + file << tab << tab << tab + << "::DBus::Message ret = this->invoke_method (call);" << endl; + file << tab << tab << tab + << "::DBus::MessageIter ri = ret.reader ();" << endl; + file << tab << tab << tab << "::DBus::Variant argout; " << endl; + file << tab << tab << tab << "ri >> argout;" << endl; + file << tab << tab << tab << "return argout;" << endl; + file << tab << tab << "};" << endl; + } + + if (property_access == "write" || property_access == "readwrite") + { + file << tab << tab << "void " << prop_name << "( const "<< signature_to_type (property.get("type")) << " & input" << ") {" << endl; + file << tab << tab << tab << "::DBus::CallMessage call ;\n "; + file << tab << tab << tab <<"call.member(\"Set\"); call.interface( \"org.freedesktop.DBus.Properties\");"<< endl; + file << tab << tab << tab <<"::DBus::MessageIter wi = call.writer(); " << endl; + file << tab << tab << tab <<"DBus::Variant value;" << endl; + file << tab << tab << tab <<"::DBus::MessageIter vi = value.writer ();" << endl; + file << tab << tab << tab <<"vi << input;" << endl; + file << tab << tab << tab <<"const DBus::String interface_name = \"" << ifacename << "\";" << endl; + file << tab << tab << tab <<"const DBus::String property_name = \"" << prop_name << "\";"<< endl; + file << tab << tab << tab <<"wi << interface_name;" << endl; + file << tab << tab << tab <<"wi << property_name;" << endl; + file << tab << tab << tab <<"wi << value;" << endl; + file << tab << tab << tab <<"::DBus::Message ret = this->invoke_method (call);" << endl; + file << tab << tab << "};" << endl; + } + } file << "public:" << endl << endl