still more formating... prepare for merge

This commit is contained in:
Andreas Volz 2009-11-17 00:00:54 +01:00
parent a236363cce
commit f25787f2a0

View file

@ -40,9 +40,9 @@ extern const char *dbus_includes;
*/ */
void generate_proxy(Xml::Document &doc, const char *filename) void generate_proxy(Xml::Document &doc, const char *filename)
{ {
ostringstream body; ostringstream body;
ostringstream head; ostringstream head;
vector <string> include_vector; vector <string> include_vector;
head << header; head << header;
string filestring = filename; string filestring = filename;
@ -51,7 +51,7 @@ void generate_proxy(Xml::Document &doc, const char *filename)
string cond_comp = "__dbusxx__" + filestring + "__PROXY_MARSHAL_H"; string cond_comp = "__dbusxx__" + filestring + "__PROXY_MARSHAL_H";
head << "#ifndef " << cond_comp << endl head << "#ifndef " << cond_comp << endl
<< "#define " << cond_comp << endl; << "#define " << cond_comp << endl;
head << dbus_includes; head << dbus_includes;
@ -74,7 +74,7 @@ void generate_proxy(Xml::Document &doc, const char *filename)
// these interface names are skipped. // these interface names are skipped.
if (ifacename == "org.freedesktop.DBus.Introspectable" if (ifacename == "org.freedesktop.DBus.Introspectable"
||ifacename == "org.freedesktop.DBus.Properties") ||ifacename == "org.freedesktop.DBus.Properties")
{ {
cerr << "skipping interface " << ifacename << endl; cerr << "skipping interface " << ifacename << endl;
continue; continue;
@ -106,13 +106,13 @@ void generate_proxy(Xml::Document &doc, const char *filename)
// the code from class definiton up to opening of the constructor is generated... // the code from class definiton up to opening of the constructor is generated...
body << "class " << ifaceclass << endl body << "class " << ifaceclass << endl
<< ": public ::DBus::InterfaceProxy" << endl << ": public ::DBus::InterfaceProxy" << endl
<< "{" << endl << "{" << endl
<< "public:" << endl << "public:" << endl
<< endl << endl
<< tab << ifaceclass << "()" << endl << tab << ifaceclass << "()" << endl
<< tab << ": ::DBus::InterfaceProxy(\"" << ifacename << "\")" << endl << tab << ": ::DBus::InterfaceProxy(\"" << ifacename << "\")" << endl
<< tab << "{" << endl; << tab << "{" << endl;
// generates code to connect all the signal stubs; this is still inside the constructor // generates code to connect all the signal stubs; this is still inside the constructor
for (Xml::Nodes::iterator si = signals.begin(); si != signals.end(); ++si) for (Xml::Nodes::iterator si = signals.begin(); si != signals.end(); ++si)
@ -122,21 +122,21 @@ void generate_proxy(Xml::Document &doc, const char *filename)
string marshname = "_" + signal.get("name") + "_stub"; string marshname = "_" + signal.get("name") + "_stub";
body << tab << tab << "connect_signal(" body << tab << tab << "connect_signal("
<< ifaceclass << ", " << signal.get("name") << ", " << stub_name(signal.get("name")) << ifaceclass << ", " << signal.get("name") << ", " << stub_name(signal.get("name"))
<< ");" << endl; << ");" << endl;
} }
// the constructor ends here // the constructor ends here
body << tab << "}" << endl body << tab << "}" << endl
<< endl; << endl;
// write public block header for properties // write public block header for properties
body << "public:" << endl << endl body << "public:" << endl << endl
<< tab << "/* properties exported by this interface */" << endl; << tab << "/* properties exported by this interface */" << endl;
// this loop generates all properties // this loop generates all properties
for (Xml::Nodes::iterator pi = properties.begin (); for (Xml::Nodes::iterator pi = properties.begin ();
pi != properties.end (); ++pi) pi != properties.end (); ++pi)
{ {
Xml::Node & property = **pi; Xml::Node & property = **pi;
string prop_name = property.get ("name"); string prop_name = property.get ("name");
@ -144,26 +144,26 @@ void generate_proxy(Xml::Document &doc, const char *filename)
if (property_access == "read" || property_access == "readwrite") if (property_access == "read" || property_access == "readwrite")
{ {
body << tab << tab << "const " << signature_to_type (property.get("type")) body << tab << tab << "const " << signature_to_type (property.get("type"))
<< " " << prop_name << "() {" << endl; << " " << prop_name << "() {" << endl;
body << tab << tab << tab << "::DBus::CallMessage call ;\n "; body << tab << tab << tab << "::DBus::CallMessage call ;\n ";
body << tab << tab << tab body << tab << tab << tab
<< "call.member(\"Get\"); call.interface(\"org.freedesktop.DBus.Properties\");" << "call.member(\"Get\"); call.interface(\"org.freedesktop.DBus.Properties\");"
<< endl; << endl;
body << tab << tab << tab body << tab << tab << tab
<< "::DBus::MessageIter wi = call.writer(); " << endl; << "::DBus::MessageIter wi = call.writer(); " << endl;
body << tab << tab << tab body << tab << tab << tab
<< "const std::string interface_name = \"" << ifacename << "\";" << "const std::string interface_name = \"" << ifacename << "\";"
<< endl; << endl;
body << tab << tab << tab body << tab << tab << tab
<< "const std::string property_name = \"" << prop_name << "\";" << "const std::string property_name = \"" << prop_name << "\";"
<< endl; << endl;
body << tab << tab << tab << "wi << interface_name;" << endl; body << tab << tab << tab << "wi << interface_name;" << endl;
body << tab << tab << tab << "wi << property_name;" << endl; body << tab << tab << tab << "wi << property_name;" << endl;
body << tab << tab << tab body << tab << tab << tab
<< "::DBus::Message ret = this->invoke_method (call);" << endl; << "::DBus::Message ret = this->invoke_method (call);" << endl;
// TODO: support invoke_method_NoReply for properties // TODO: support invoke_method_NoReply for properties
body << tab << tab << tab body << tab << tab << tab
<< "::DBus::MessageIter ri = ret.reader ();" << endl; << "::DBus::MessageIter ri = ret.reader ();" << endl;
body << tab << tab << tab << "::DBus::Variant argout; " << endl; body << tab << tab << tab << "::DBus::Variant argout; " << endl;
body << tab << tab << tab << "ri >> argout;" << endl; body << tab << tab << tab << "ri >> argout;" << endl;
body << tab << tab << tab << "return argout;" << endl; body << tab << tab << tab << "return argout;" << endl;
@ -192,10 +192,10 @@ void generate_proxy(Xml::Document &doc, const char *filename)
// write public block header for methods // write public block header for methods
body << "public:" << endl body << "public:" << endl
<< endl << endl
<< tab << "/* methods exported by this interface," << endl << tab << "/* methods exported by this interface," << endl
<< tab << " * this functions will invoke the corresponding methods on the remote objects" << endl << tab << " * this functions will invoke the corresponding methods on the remote objects" << endl
<< tab << " */" << endl; << tab << " */" << endl;
// this loop generates all methods // this loop generates all methods
for (Xml::Nodes::iterator mi = methods.begin(); mi != methods.end(); ++mi) for (Xml::Nodes::iterator mi = methods.begin(); mi != methods.end(); ++mi)
@ -204,28 +204,28 @@ void generate_proxy(Xml::Document &doc, const char *filename)
Xml::Nodes args = method["arg"]; Xml::Nodes args = method["arg"];
Xml::Nodes args_in = args.select("direction","in"); Xml::Nodes args_in = args.select("direction","in");
Xml::Nodes args_out = args.select("direction","out"); Xml::Nodes args_out = args.select("direction","out");
Xml::Nodes annotations = args["annotation"]; Xml::Nodes annotations = args["annotation"];
Xml::Nodes method_annotations = method["annotation"]; Xml::Nodes method_annotations = method["annotation"];
Xml::Nodes annotations_noreply = method_annotations.select("name","org.freedesktop.DBus.Method.NoReply"); Xml::Nodes annotations_noreply = method_annotations.select("name","org.freedesktop.DBus.Method.NoReply");
Xml::Nodes annotations_object = annotations.select("name","org.freedesktop.DBus.Object"); Xml::Nodes annotations_object = annotations.select("name","org.freedesktop.DBus.Object");
string arg_object; string arg_object;
bool annotation_noreply_value = false; bool annotation_noreply_value = false;
// parse method level noreply annotations // parse method level noreply annotations
if (annotations_noreply.size() > 0) if (annotations_noreply.size() > 0)
{ {
string annotation_noreply_value_str = annotations_noreply.front()->get("value"); string annotation_noreply_value_str = annotations_noreply.front()->get("value");
if (annotation_noreply_value_str == "true") if (annotation_noreply_value_str == "true")
{ {
annotation_noreply_value = true; annotation_noreply_value = true;
} }
} }
if (annotations_object.size() > 0) if (annotations_object.size() > 0)
{ {
arg_object = annotations_object.front()->get("value"); arg_object = annotations_object.front()->get("value");
} }
if (args_out.size() == 0 || args_out.size() > 1) if (args_out.size() == 0 || args_out.size() > 1)
{ {
@ -233,14 +233,14 @@ void generate_proxy(Xml::Document &doc, const char *filename)
} }
else if (args_out.size() == 1) else if (args_out.size() == 1)
{ {
if (arg_object.length()) if (arg_object.length())
{ {
body << tab << arg_object << " "; body << tab << arg_object << " ";
} }
else else
{ {
body << tab << signature_to_type(args_out.front()->get("type")) << " "; body << tab << signature_to_type(args_out.front()->get("type")) << " ";
} }
} }
body << method.get("name") << "("; body << method.get("name") << "(";
@ -250,28 +250,28 @@ void generate_proxy(Xml::Document &doc, const char *filename)
for (Xml::Nodes::iterator ai = args_in.begin(); ai != args_in.end(); ++ai, ++i) for (Xml::Nodes::iterator ai = args_in.begin(); ai != args_in.end(); ++ai, ++i)
{ {
Xml::Node &arg = **ai; Xml::Node &arg = **ai;
Xml::Nodes annotations = arg["annotation"]; Xml::Nodes annotations = arg["annotation"];
Xml::Nodes annotations_object = annotations.select("name","org.freedesktop.DBus.Object"); Xml::Nodes annotations_object = annotations.select("name","org.freedesktop.DBus.Object");
string arg_object; string arg_object;
if (annotations_object.size() > 0) if (annotations_object.size() > 0)
{ {
arg_object = annotations_object.front()->get("value"); arg_object = annotations_object.front()->get("value");
} }
// generate basic signature only if no object name available... // generate basic signature only if no object name available...
if (!arg_object.length()) if (!arg_object.length())
{ {
body << "const " << signature_to_type(arg.get("type")) << "& "; body << "const " << signature_to_type(arg.get("type")) << "& ";
} }
// ...or generate object style if available // ...or generate object style if available
else else
{ {
body << "const " << arg_object << "& "; body << "const " << arg_object << "& ";
// store a object name to later generate header includes // store a object name to later generate header includes
include_vector.push_back (arg_object); include_vector.push_back (arg_object);
} }
string arg_name = arg.get("name"); string arg_name = arg.get("name");
if (arg_name.length()) if (arg_name.length())
@ -285,33 +285,33 @@ void generate_proxy(Xml::Document &doc, const char *filename)
if (args_out.size() > 1) if (args_out.size() > 1)
{ {
// generate all 'out' arguments for a method signature // generate all 'out' arguments for a method signature
unsigned int j = 0; unsigned int j = 0;
for (Xml::Nodes::iterator ao = args_out.begin(); ao != args_out.end(); ++ao, ++j) for (Xml::Nodes::iterator ao = args_out.begin(); ao != args_out.end(); ++ao, ++j)
{ {
Xml::Node &arg = **ao; Xml::Node &arg = **ao;
Xml::Nodes annotations = arg["annotation"]; Xml::Nodes annotations = arg["annotation"];
Xml::Nodes annotations_object = annotations.select("name","org.freedesktop.DBus.Object"); Xml::Nodes annotations_object = annotations.select("name","org.freedesktop.DBus.Object");
string arg_object; string arg_object;
if (annotations_object.size() > 0) if (annotations_object.size() > 0)
{ {
arg_object = annotations_object.front()->get("value"); arg_object = annotations_object.front()->get("value");
} }
// generate basic signature only if no object name available... // generate basic signature only if no object name available...
if (!arg_object.length()) if (!arg_object.length())
{ {
body << signature_to_type(arg.get("type")) << "&"; body << signature_to_type(arg.get("type")) << "&";
} }
// ...or generate object style if available // ...or generate object style if available
else else
{ {
body << arg_object << "& "; body << arg_object << "& ";
// store a object name to later generate header includes // store a object name to later generate header includes
include_vector.push_back (arg_object); include_vector.push_back (arg_object);
} }
string arg_name = arg.get("name"); string arg_name = arg.get("name");
if (arg_name.length()) if (arg_name.length())
@ -326,159 +326,159 @@ void generate_proxy(Xml::Document &doc, const char *filename)
body << ")" << endl; body << ")" << endl;
body << tab << "{" << endl body << tab << "{" << endl
<< tab << tab << "::DBus::CallMessage call;" << endl; << tab << tab << "::DBus::CallMessage call;" << endl;
if (args_in.size() > 0) if (args_in.size() > 0)
{ {
body << tab << tab << "::DBus::MessageIter wi = call.writer();" << endl body << tab << tab << "::DBus::MessageIter wi = call.writer();" << endl
<< endl; << endl;
} }
// generate all 'in' arguments for a method body // generate all 'in' arguments for a method body
i = 0; i = 0;
for (Xml::Nodes::iterator ai = args_in.begin(); ai != args_in.end(); ++ai, ++i) for (Xml::Nodes::iterator ai = args_in.begin(); ai != args_in.end(); ++ai, ++i)
{ {
Xml::Node &arg = **ai; Xml::Node &arg = **ai;
string arg_name = arg.get("name"); string arg_name = arg.get("name");
Xml::Nodes annotations = arg["annotation"]; Xml::Nodes annotations = arg["annotation"];
Xml::Nodes annotations_object = annotations.select("name","org.freedesktop.DBus.Object"); Xml::Nodes annotations_object = annotations.select("name","org.freedesktop.DBus.Object");
string arg_object; string arg_object;
if (annotations_object.size() > 0) if (annotations_object.size() > 0)
{ {
arg_object = annotations_object.front()->get("value"); arg_object = annotations_object.front()->get("value");
} }
if (!arg_name.length()) if (!arg_name.length())
{ {
arg_name = "argin"; arg_name = "argin";
arg_name += toString <uint> (i); arg_name += toString <uint> (i);
} }
// generate extra code to wrap object // generate extra code to wrap object
if (arg_object.length()) if (arg_object.length())
{ {
body << tab << tab << signature_to_type(arg.get("type")) << "_" << arg_name << ";" << endl; body << tab << tab << signature_to_type(arg.get("type")) << "_" << arg_name << ";" << endl;
body << tab << tab << "_" << arg_name << " << " << arg_name << ";" << endl; body << tab << tab << "_" << arg_name << " << " << arg_name << ";" << endl;
arg_name = string ("_") + arg_name; arg_name = string ("_") + arg_name;
} }
body << tab << tab << "wi << " << arg_name << ";" << endl; body << tab << tab << "wi << " << arg_name << ";" << endl;
} }
body << tab << tab << "call.member(\"" << method.get("name") << "\");" << endl; body << tab << tab << "call.member(\"" << method.get("name") << "\");" << endl;
// generate noreply/reply method calls // generate noreply/reply method calls
if (annotation_noreply_value) if (annotation_noreply_value)
{ {
if (args_out.size ()) if (args_out.size ())
{ {
cerr << "Function: " << method.get("name") << ":" << endl; cerr << "Function: " << method.get("name") << ":" << endl;
cerr << "Option 'org.freedesktop.DBus.Method.NoReply' not allowed for methods with 'out' variables!" << endl << "-> Option ignored!" << endl; cerr << "Option 'org.freedesktop.DBus.Method.NoReply' not allowed for methods with 'out' variables!" << endl << "-> Option ignored!" << endl;
body << tab << tab << "::DBus::Message ret = invoke_method (call);" << endl; body << tab << tab << "::DBus::Message ret = invoke_method (call);" << endl;
} }
else else
{ {
body << tab << tab << "assert (invoke_method_noreply (call));" << endl; // will only assert in case of no memory body << tab << tab << "assert (invoke_method_noreply (call));" << endl; // will only assert in case of no memory
} }
} }
else else
{ {
body << tab << tab << "::DBus::Message ret = invoke_method (call);" << endl; body << tab << tab << "::DBus::Message ret = invoke_method (call);" << endl;
} }
if (args_out.size() > 0) if (args_out.size() > 0)
{ {
body << tab << tab << "::DBus::MessageIter ri = ret.reader();" << endl body << tab << tab << "::DBus::MessageIter ri = ret.reader();" << endl
<< endl; << endl;
} }
// generate 'out' values as return if only one existing // generate 'out' values as return if only one existing
if (args_out.size() == 1) if (args_out.size() == 1)
{ {
Xml::Nodes annotations = args_out["annotation"]; Xml::Nodes annotations = args_out["annotation"];
Xml::Nodes annotations_object = annotations.select("name","org.freedesktop.DBus.Object"); Xml::Nodes annotations_object = annotations.select("name","org.freedesktop.DBus.Object");
string arg_object; string arg_object;
if (annotations_object.size() > 0) if (annotations_object.size() > 0)
{ {
arg_object = annotations_object.front()->get("value"); arg_object = annotations_object.front()->get("value");
} }
if (arg_object.length()) if (arg_object.length())
{ {
body << tab << tab << arg_object << " _argout;" << endl; body << tab << tab << arg_object << " _argout;" << endl;
} }
body << tab << tab << signature_to_type(args_out.front()->get("type")) << " argout;" << endl; body << tab << tab << signature_to_type(args_out.front()->get("type")) << " argout;" << endl;
body << tab << tab << "ri >> argout;" << endl; body << tab << tab << "ri >> argout;" << endl;
if (arg_object.length()) if (arg_object.length())
{ {
body << tab << tab << "_argout << argout;" << endl; body << tab << tab << "_argout << argout;" << endl;
body << tab << tab << "return _argout;" << endl; body << tab << tab << "return _argout;" << endl;
} }
else else
{ {
body << tab << tab << "return argout;" << endl; body << tab << tab << "return argout;" << endl;
} }
} }
else if (args_out.size() > 1) else if (args_out.size() > 1)
{ {
// generate multible 'out' value // generate multible 'out' value
unsigned int i = 0; unsigned int i = 0;
for (Xml::Nodes::iterator ao = args_out.begin(); ao != args_out.end(); ++ao, ++i) for (Xml::Nodes::iterator ao = args_out.begin(); ao != args_out.end(); ++ao, ++i)
{ {
Xml::Node &arg = **ao; Xml::Node &arg = **ao;
string arg_name = arg.get("name"); string arg_name = arg.get("name");
Xml::Nodes annotations = arg["annotation"]; Xml::Nodes annotations = arg["annotation"];
Xml::Nodes annotations_object = annotations.select("name","org.freedesktop.DBus.Object"); Xml::Nodes annotations_object = annotations.select("name","org.freedesktop.DBus.Object");
string arg_object; string arg_object;
if (annotations_object.size() > 0) if (annotations_object.size() > 0)
{ {
arg_object = annotations_object.front()->get("value"); arg_object = annotations_object.front()->get("value");
} }
if (!arg_name.length()) if (!arg_name.length())
{ {
arg_name = "argout" + toString <uint> (i); arg_name = "argout" + toString <uint> (i);
} }
if (arg_object.length()) if (arg_object.length())
{ {
body << tab << tab << signature_to_type(arg.get("type")) << "_" << arg_name << ";" << endl; body << tab << tab << signature_to_type(arg.get("type")) << "_" << arg_name << ";" << endl;
} }
if (arg_object.length()) if (arg_object.length())
{ {
body << tab << tab << "ri >> " << "_" << arg_name << ";" << endl; body << tab << tab << "ri >> " << "_" << arg_name << ";" << endl;
} }
else else
{ {
body << tab << tab << "ri >> " << arg_name << ";" << endl; body << tab << tab << "ri >> " << arg_name << ";" << endl;
} }
if (arg_object.length()) if (arg_object.length())
{ {
body << tab << tab << arg_name << " << " << "_" << arg_name << ";" << endl; body << tab << tab << arg_name << " << " << "_" << arg_name << ";" << endl;
} }
} }
} }
body << tab << "}" << endl body << tab << "}" << endl
<< endl; << endl;
} }
// write public block header for signals // write public block header for signals
body << endl body << endl
<< "public:" << endl << "public:" << endl
<< endl << endl
<< tab << "/* signal handlers for this interface" << endl << tab << "/* signal handlers for this interface" << endl
<< tab << " */" << endl; << tab << " */" << endl;
// this loop generates all signals // this loop generates all signals
for (Xml::Nodes::iterator si = signals.begin(); si != signals.end(); ++si) for (Xml::Nodes::iterator si = signals.begin(); si != signals.end(); ++si)
@ -494,28 +494,28 @@ void generate_proxy(Xml::Document &doc, const char *filename)
{ {
Xml::Node &arg = **ai; Xml::Node &arg = **ai;
string arg_name = arg.get("name"); string arg_name = arg.get("name");
Xml::Nodes annotations = arg["annotation"]; Xml::Nodes annotations = arg["annotation"];
Xml::Nodes annotations_object = annotations.select("name","org.freedesktop.DBus.Object"); Xml::Nodes annotations_object = annotations.select("name","org.freedesktop.DBus.Object");
string arg_object; string arg_object;
if (annotations_object.size() > 0) if (annotations_object.size() > 0)
{ {
arg_object = annotations_object.front()->get("value"); arg_object = annotations_object.front()->get("value");
} }
// generate basic signature only if no object name available... // generate basic signature only if no object name available...
if (!arg_object.length()) if (!arg_object.length())
{ {
body << "const " << signature_to_type(arg.get("type")) << "& "; body << "const " << signature_to_type(arg.get("type")) << "& ";
} }
// ...or generate object style if available // ...or generate object style if available
else else
{ {
body << "const " << arg_object << "& "; body << "const " << arg_object << "& ";
// store a object name to later generate header includes // store a object name to later generate header includes
include_vector.push_back (arg_object); include_vector.push_back (arg_object);
} }
if (arg_name.length()) if (arg_name.length())
body << arg_name; body << arg_name;
@ -530,10 +530,10 @@ void generate_proxy(Xml::Document &doc, const char *filename)
// write private block header for unmarshalers // write private block header for unmarshalers
body << endl body << endl
<< "private:" << endl << "private:" << endl
<< endl << endl
<< tab << "/* unmarshalers (to unpack the DBus message before calling the actual signal handler)" << endl << tab << "/* unmarshalers (to unpack the DBus message before calling the actual signal handler)" << endl
<< tab << " */" << endl; << tab << " */" << endl;
// generate all the unmarshalers // generate all the unmarshalers
for (Xml::Nodes::iterator si = signals.begin(); si != signals.end(); ++si) for (Xml::Nodes::iterator si = signals.begin(); si != signals.end(); ++si)
@ -542,12 +542,12 @@ void generate_proxy(Xml::Document &doc, const char *filename)
Xml::Nodes args = signal["arg"]; Xml::Nodes args = signal["arg"];
body << tab << "void " << stub_name(signal.get("name")) << "(const ::DBus::SignalMessage &sig)" << endl body << tab << "void " << stub_name(signal.get("name")) << "(const ::DBus::SignalMessage &sig)" << endl
<< tab << "{" << endl; << tab << "{" << endl;
if (args.size() > 0) if (args.size() > 0)
{ {
body << tab << tab << "::DBus::MessageIter ri = sig.reader();" << endl body << tab << tab << "::DBus::MessageIter ri = sig.reader();" << endl
<< endl; << endl;
} }
unsigned int i = 0; unsigned int i = 0;
@ -555,67 +555,67 @@ void generate_proxy(Xml::Document &doc, const char *filename)
{ {
Xml::Node &arg = **ai; Xml::Node &arg = **ai;
string arg_name = arg.get("name"); string arg_name = arg.get("name");
Xml::Nodes annotations = arg["annotation"]; Xml::Nodes annotations = arg["annotation"];
Xml::Nodes annotations_object = annotations.select("name","org.freedesktop.DBus.Object"); Xml::Nodes annotations_object = annotations.select("name","org.freedesktop.DBus.Object");
string arg_object; string arg_object;
if (annotations_object.size() > 0) if (annotations_object.size() > 0)
{ {
arg_object = annotations_object.front()->get("value"); arg_object = annotations_object.front()->get("value");
} }
body << tab << tab << signature_to_type(arg.get("type")) << " " ; body << tab << tab << signature_to_type(arg.get("type")) << " " ;
// use a default if no arg name given // use a default if no arg name given
if (!arg_name.length()) if (!arg_name.length())
{ {
arg_name = "arg" + toString <uint> (i); arg_name = "arg" + toString <uint> (i);
} }
body << arg_name << ";" << endl; body << arg_name << ";" << endl;
body << tab << tab << "ri >> " << arg_name << ";" << endl; body << tab << tab << "ri >> " << arg_name << ";" << endl;
// if a object type is used create a local variable and insert values with '<<' operation // if a object type is used create a local variable and insert values with '<<' operation
if (arg_object.length()) if (arg_object.length())
{ {
body << tab << tab << arg_object << " _" << arg_name << ";" << endl; body << tab << tab << arg_object << " _" << arg_name << ";" << endl;
body << tab << tab << "_" << arg_name << " << " << arg_name << ";" << endl; body << tab << tab << "_" << arg_name << " << " << arg_name << ";" << endl;
// store a object name to later generate header includes // store a object name to later generate header includes
include_vector.push_back (arg_object); include_vector.push_back (arg_object);
} }
} }
body << tab << tab << signal.get("name") << "("; body << tab << tab << signal.get("name") << "(";
// generate all arguments for the call to the virtual function // generate all arguments for the call to the virtual function
unsigned int j = 0; unsigned int j = 0;
for (Xml::Nodes::iterator ai = args.begin(); ai != args.end(); ++ai, ++j) for (Xml::Nodes::iterator ai = args.begin(); ai != args.end(); ++ai, ++j)
{ {
Xml::Node &arg = **ai; Xml::Node &arg = **ai;
string arg_name = arg.get("name"); string arg_name = arg.get("name");
Xml::Nodes annotations = arg["annotation"]; Xml::Nodes annotations = arg["annotation"];
Xml::Nodes annotations_object = annotations.select("name","org.freedesktop.DBus.Object"); Xml::Nodes annotations_object = annotations.select("name","org.freedesktop.DBus.Object");
string arg_object; string arg_object;
if (annotations_object.size() > 0) if (annotations_object.size() > 0)
{ {
arg_object = annotations_object.front()->get("value"); arg_object = annotations_object.front()->get("value");
} }
if (!arg_name.length()) if (!arg_name.length())
{ {
arg_name = "arg" + toString <uint> (j); arg_name = "arg" + toString <uint> (j);
} }
if (arg_object.length()) if (arg_object.length())
{ {
body << "_" << arg_name; body << "_" << arg_name;
} }
else else
{ {
body << arg_name; body << arg_name;
} }
if (ai+1 != args.end()) if (ai+1 != args.end())
body << ", "; body << ", ";
@ -627,7 +627,7 @@ void generate_proxy(Xml::Document &doc, const char *filename)
} }
body << "};" << endl body << "};" << endl
<< endl; << endl;
for (unsigned int i = 0; i < nspaces; ++i) for (unsigned int i = 0; i < nspaces; ++i)
{ {
@ -638,18 +638,18 @@ void generate_proxy(Xml::Document &doc, const char *filename)
body << "#endif //" << cond_comp << endl; body << "#endif //" << cond_comp << endl;
// remove all duplicates in the header include vector // remove all duplicates in the header include vector
vector<string>::const_iterator vec_end_it = unique (include_vector.begin (), include_vector.end ()); vector<string>::const_iterator vec_end_it = unique (include_vector.begin (), include_vector.end ());
for (vector<string>::const_iterator vec_it = include_vector.begin (); for (vector<string>::const_iterator vec_it = include_vector.begin ();
vec_it != vec_end_it; vec_it != vec_end_it;
++vec_it) ++vec_it)
{ {
const string &include = *vec_it; const string &include = *vec_it;
head << "#include " << "\"" << include << ".h" << "\"" << endl; head << "#include " << "\"" << include << ".h" << "\"" << endl;
} }
head << endl; head << endl;
ofstream file(filename); ofstream file(filename);
if (file.bad()) if (file.bad())
@ -658,8 +658,8 @@ void generate_proxy(Xml::Document &doc, const char *filename)
exit(-1); exit(-1);
} }
file << head.str (); file << head.str ();
file << body.str (); file << body.str ();
file.close(); file.close();
} }