better variable names

This commit is contained in:
Andreas Volz 2008-08-31 20:22:03 +02:00
parent 5f23f7d124
commit d6ce34b78c

View file

@ -199,20 +199,20 @@ string signature_to_type(const string &signature)
void generate_proxy(Xml::Document &doc, const char *filename)
{
ostringstream file;
ostringstream headerStream;
vector <string> includeVector;
ostringstream body;
ostringstream head;
vector <string> include_vector;
headerStream << header;
head << header;
string filestring = filename;
underscorize(filestring);
string cond_comp = "__dbusxx__" + filestring + "__PROXY_MARSHAL_H";
headerStream << "#ifndef " << cond_comp << endl;
headerStream << "#define " << cond_comp << endl;
head << "#ifndef " << cond_comp << endl;
head << "#define " << cond_comp << endl;
headerStream << dbus_includes;
head << dbus_includes;
Xml::Node &root = *(doc.root);
Xml::Nodes interfaces = root["interface"];
@ -247,11 +247,11 @@ void generate_proxy(Xml::Document &doc, const char *filename)
{
getline(ss, nspace, '.');
file << "namespace " << nspace << " {" << endl;
body << "namespace " << nspace << " {" << endl;
++nspaces;
}
file << endl;
body << endl;
string ifaceclass;
@ -263,7 +263,7 @@ void generate_proxy(Xml::Document &doc, const char *filename)
cerr << "generating code for interface " << ifacename << "..." << endl;
// the code from class definiton up to opening of the constructor is generated...
file << "class " << ifaceclass << endl
body << "class " << ifaceclass << endl
<< " : public ::DBus::InterfaceProxy" << endl
<< "{" << endl
<< "public:" << endl
@ -279,17 +279,17 @@ void generate_proxy(Xml::Document &doc, const char *filename)
string marshname = "_" + signal.get("name") + "_stub";
file << tab << tab << "connect_signal("
body << tab << tab << "connect_signal("
<< ifaceclass << ", " << signal.get("name") << ", " << stub_name(signal.get("name"))
<< ");" << endl;
}
// the constructor ends here
file << tab << "}" << endl
body << tab << "}" << endl
<< endl;
// write public block header for properties
file << "public:" << endl << endl
body << "public:" << endl << endl
<< tab << "/* properties exported by this interface */" << endl;
// this loop generates all properties
@ -301,53 +301,53 @@ void generate_proxy(Xml::Document &doc, const char *filename)
string property_access = property.get ("access");
if (property_access == "read" || property_access == "readwrite")
{
file << tab << tab << "const " << signature_to_type (property.get("type"))
body << tab << tab << "const " << signature_to_type (property.get("type"))
<< " " << prop_name << "() {" << endl;
file << tab << tab << tab << "::DBus::CallMessage call ;\n ";
file << tab << tab << tab
body << tab << tab << tab << "::DBus::CallMessage call ;\n ";
body << tab << tab << tab
<< "call.member(\"Get\"); call.interface(\"org.freedesktop.DBus.Properties\");"
<< endl;
file << tab << tab << tab
body << tab << tab << tab
<< "::DBus::MessageIter wi = call.writer(); " << endl;
file << tab << tab << tab
body << tab << tab << tab
<< "const std::string interface_name = \"" << ifacename << "\";"
<< endl;
file << tab << tab << tab
body << tab << tab << tab
<< "const std::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
body << tab << tab << tab << "wi << interface_name;" << endl;
body << tab << tab << tab << "wi << property_name;" << endl;
body << tab << tab << tab
<< "::DBus::Message ret = this->invoke_method (call);" << endl;
file << tab << tab << tab
body << 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;
body << tab << tab << tab << "::DBus::Variant argout; " << endl;
body << tab << tab << tab << "ri >> argout;" << endl;
body << tab << tab << tab << "return argout;" << endl;
body << 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 std::string interface_name = \"" << ifacename << "\";" << endl;
file << tab << tab << tab <<"const std::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;
body << tab << tab << "void " << prop_name << "( const "<< signature_to_type (property.get("type")) << " & input" << ") {" << endl;
body << tab << tab << tab << "::DBus::CallMessage call ;\n ";
body << tab << tab << tab <<"call.member(\"Set\"); call.interface( \"org.freedesktop.DBus.Properties\");"<< endl;
body << tab << tab << tab <<"::DBus::MessageIter wi = call.writer(); " << endl;
body << tab << tab << tab <<"::DBus::Variant value;" << endl;
body << tab << tab << tab <<"::DBus::MessageIter vi = value.writer ();" << endl;
body << tab << tab << tab <<"vi << input;" << endl;
body << tab << tab << tab <<"const std::string interface_name = \"" << ifacename << "\";" << endl;
body << tab << tab << tab <<"const std::string property_name = \"" << prop_name << "\";"<< endl;
body << tab << tab << tab <<"wi << interface_name;" << endl;
body << tab << tab << tab <<"wi << property_name;" << endl;
body << tab << tab << tab <<"wi << value;" << endl;
body << tab << tab << tab <<"::DBus::Message ret = this->invoke_method (call);" << endl;
body << tab << tab << "};" << endl;
}
}
// write public block header for methods
file << "public:" << endl
body << "public:" << endl
<< endl
<< tab << "/* methods exported by this interface," << endl
<< tab << " * this functions will invoke the corresponding methods on the remote objects" << endl
@ -363,29 +363,29 @@ void generate_proxy(Xml::Document &doc, const char *filename)
if (args_out.size() == 0 || args_out.size() > 1)
{
file << tab << "void ";
body << tab << "void ";
}
else if (args_out.size() == 1)
{
file << tab << signature_to_type(args_out.front()->get("type")) << " ";
body << tab << signature_to_type(args_out.front()->get("type")) << " ";
}
file << method.get("name") << "(";
body << method.get("name") << "(";
unsigned int i = 0;
for (Xml::Nodes::iterator ai = args_in.begin(); ai != args_in.end(); ++ai, ++i)
{
Xml::Node &arg = **ai;
file << "const " << signature_to_type(arg.get("type")) << "& ";
body << "const " << signature_to_type(arg.get("type")) << "& ";
string arg_name = arg.get("name");
if (arg_name.length())
file << arg_name;
body << arg_name;
else
file << "argin" << i;
body << "argin" << i;
if ((i+1 != args_in.size() || args_out.size() > 1))
file << ", ";
body << ", ";
}
if (args_out.size() > 1)
@ -394,26 +394,26 @@ void generate_proxy(Xml::Document &doc, const char *filename)
for (Xml::Nodes::iterator ao = args_out.begin(); ao != args_out.end(); ++ao, ++i)
{
Xml::Node &arg = **ao;
file << signature_to_type(arg.get("type")) << "&";
body << signature_to_type(arg.get("type")) << "&";
string arg_name = arg.get("name");
if (arg_name.length())
file << " " << arg_name;
body << " " << arg_name;
else
file << " argout" << i;
body << " argout" << i;
if (i+1 != args_out.size())
file << ", ";
body << ", ";
}
}
file << ")" << endl;
body << ")" << endl;
file << tab << "{" << endl
body << tab << "{" << endl
<< tab << tab << "::DBus::CallMessage call;" << endl;
if (args_in.size() > 0)
{
file << tab << tab << "::DBus::MessageIter wi = call.writer();" << endl
body << tab << tab << "::DBus::MessageIter wi = call.writer();" << endl
<< endl;
}
@ -423,26 +423,26 @@ void generate_proxy(Xml::Document &doc, const char *filename)
Xml::Node &arg = **ai;
string arg_name = arg.get("name");
if (arg_name.length())
file << tab << tab << "wi << " << arg_name << ";" << endl;
body << tab << tab << "wi << " << arg_name << ";" << endl;
else
file << tab << tab << "wi << argin" << j << ";" << endl;
body << tab << tab << "wi << argin" << j << ";" << endl;
}
file << tab << tab << "call.member(\"" << method.get("name") << "\");" << endl
body << tab << tab << "call.member(\"" << method.get("name") << "\");" << endl
<< tab << tab << "::DBus::Message ret = invoke_method(call);" << endl;
if (args_out.size() > 0)
{
file << tab << tab << "::DBus::MessageIter ri = ret.reader();" << endl
body << tab << tab << "::DBus::MessageIter ri = ret.reader();" << endl
<< endl;
}
if (args_out.size() == 1)
{
file << tab << tab << signature_to_type(args_out.front()->get("type")) << " argout;" << endl;
file << tab << tab << "ri >> argout;" << endl;
file << tab << tab << "return argout;" << endl;
body << tab << tab << signature_to_type(args_out.front()->get("type")) << " argout;" << endl;
body << tab << tab << "ri >> argout;" << endl;
body << tab << tab << "return argout;" << endl;
}
else if (args_out.size() > 1)
{
@ -453,18 +453,18 @@ void generate_proxy(Xml::Document &doc, const char *filename)
string arg_name = arg.get("name");
if (arg_name.length())
file << tab << tab << "ri >> " << arg.get("name") << ";" << endl;
body << tab << tab << "ri >> " << arg.get("name") << ";" << endl;
else
file << tab << tab << "ri >> argout" << i << ";" << endl;
body << tab << tab << "ri >> argout" << i << ";" << endl;
}
}
file << tab << "}" << endl
body << tab << "}" << endl
<< endl;
}
// write public block header for signals
file << endl
body << endl
<< "public:" << endl
<< endl
<< tab << "/* signal handlers for this interface" << endl
@ -476,7 +476,7 @@ void generate_proxy(Xml::Document &doc, const char *filename)
Xml::Node &signal = **si;
Xml::Nodes args = signal["arg"];
file << tab << "virtual void " << signal.get("name") << "(";
body << tab << "virtual void " << signal.get("name") << "(";
// this loop generates all argument for a signal
unsigned int i = 0;
@ -490,30 +490,30 @@ void generate_proxy(Xml::Document &doc, const char *filename)
// generate basic signature only if no object name available...
if (!arg_object.length())
{
file << "const " << signature_to_type(arg.get("type")) << "& ";
body << "const " << signature_to_type(arg.get("type")) << "& ";
}
// ...or generate object style if available
else
{
file << "const " << arg_object << "& ";
body << "const " << arg_object << "& ";
// store a object name to later generate header includes
includeVector.push_back (arg_object);
include_vector.push_back (arg_object);
}
if (arg_name.length())
file << arg_name;
body << arg_name;
else
file << "argin" << i;
body << "argin" << i;
if ((ai+1 != args.end()))
file << ", ";
body << ", ";
}
file << ") = 0;" << endl;
body << ") = 0;" << endl;
}
// write private block header for unmarshalers
file << endl
body << endl
<< "private:" << endl
<< endl
<< tab << "/* unmarshalers (to unpack the DBus message before calling the actual signal handler)" << endl
@ -525,12 +525,12 @@ void generate_proxy(Xml::Document &doc, const char *filename)
Xml::Node &signal = **si;
Xml::Nodes args = signal["arg"];
file << 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;
if (args.size() > 0)
{
file << tab << tab << "::DBus::MessageIter ri = sig.reader();" << endl
body << tab << tab << "::DBus::MessageIter ri = sig.reader();" << endl
<< endl;
}
@ -538,7 +538,7 @@ void generate_proxy(Xml::Document &doc, const char *filename)
for (Xml::Nodes::iterator ai = args.begin(); ai != args.end(); ++ai, ++i)
{
Xml::Node &arg = **ai;
file << tab << tab << signature_to_type(arg.get("type")) << " " ;
body << tab << tab << signature_to_type(arg.get("type")) << " " ;
string arg_name = arg.get("name");
@ -550,18 +550,18 @@ void generate_proxy(Xml::Document &doc, const char *filename)
arg_name = "arg";
}
file << arg_name << ";" << endl;
file << tab << tab << "ri >> " << arg_name << ";" << endl;
body << 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 (arg_object.length())
{
file << tab << tab << arg_object << " _" << arg_name << ";" << endl;
file << tab << tab << "_" << arg_name << " << " << arg_name << ";" << endl;
body << tab << tab << arg_object << " _" << arg_name << ";" << endl;
body << tab << tab << "_" << arg_name << " << " << arg_name << ";" << endl;
}
}
file << tab << tab << signal.get("name") << "(";
body << tab << tab << signal.get("name") << "(";
// generate all arguments for the call to the virtual function
unsigned int j = 0;
@ -579,84 +579,79 @@ void generate_proxy(Xml::Document &doc, const char *filename)
if (arg_object.length())
{
file << "_" << arg_name;
body << "_" << arg_name;
}
else
{
file << arg_name;
body << arg_name;
}
if (ai+1 != args.end())
file << ", ";
body << ", ";
}
file << ");" << endl;
body << ");" << endl;
file << tab << "}" << endl;
body << tab << "}" << endl;
}
file << "};" << endl
body << "};" << endl
<< endl;
for (unsigned int i = 0; i < nspaces; ++i)
{
file << "} ";
body << "} ";
}
file << endl;
body << endl;
}
file << "#endif //" << cond_comp << endl;
body << "#endif //" << cond_comp << endl;
cerr << "writing " << filename << endl;
// remove all duplicates in the header include vector
vector<string>::const_iterator vec_end_it = unique (includeVector.begin (), includeVector.end ());
vector<string>::const_iterator vec_end_it = unique (include_vector.begin (), include_vector.end ());
for (vector<string>::const_iterator vec_it = includeVector.begin ();
for (vector<string>::const_iterator vec_it = include_vector.begin ();
vec_it != vec_end_it;
++vec_it)
{
const string &include = *vec_it;
headerStream << "#include " << "\"" << include << ".h" << "\"" << endl;
head << "#include " << "\"" << include << ".h" << "\"" << endl;
}
headerStream << endl;
head << endl;
ofstream fileX(filename);
if (file.bad())
{
cerr << "unable to write file " << filename << endl;
exit(-1);
}
fileX << headerStream.str ();
fileX << file.str ();
fileX.close();
}
void generate_adaptor(Xml::Document &doc, const char *filename)
{
cerr << "writing " << filename << endl;
ofstream file(filename);
if (file.bad())
{
cerr << "unable to write file " << filename << endl;
exit(-1);
}
file << head.str ();
file << body.str ();
file << header;
file.close();
}
void generate_adaptor(Xml::Document &doc, const char *filename)
{
ostringstream body;
ostringstream head;
vector <string> include_vector;
body << header;
string filestring = filename;
underscorize(filestring);
string cond_comp = "__dbusxx__" + filestring + "__ADAPTOR_MARSHAL_H";
file << "#ifndef " << cond_comp << endl
body << "#ifndef " << cond_comp << endl
<< "#define " << cond_comp << endl;
file << dbus_includes;
body << dbus_includes;
Xml::Node &root = *(doc.root);
Xml::Nodes interfaces = root["interface"];
@ -687,11 +682,11 @@ void generate_adaptor(Xml::Document &doc, const char *filename)
{
getline(ss, nspace, '.');
file << "namespace " << nspace << " {" << endl;
body << "namespace " << nspace << " {" << endl;
++nspaces;
}
file << endl;
body << endl;
string ifaceclass;
@ -701,7 +696,7 @@ void generate_adaptor(Xml::Document &doc, const char *filename)
cerr << "generating code for interface " << ifacename << "..." << endl;
file << "class " << ifaceclass << endl
body << "class " << ifaceclass << endl
<< ": public ::DBus::InterfaceAdaptor" << endl
<< "{" << endl
<< "public:" << endl
@ -714,7 +709,7 @@ void generate_adaptor(Xml::Document &doc, const char *filename)
{
Xml::Node &property = **pi;
file << tab << tab << "bind_property("
body << tab << tab << "bind_property("
<< property.get("name") << ", "
<< "\"" << property.get("type") << "\", "
<< (property.get("access").find("read") != string::npos
@ -731,15 +726,15 @@ void generate_adaptor(Xml::Document &doc, const char *filename)
{
Xml::Node &method = **mi;
file << tab << tab << "register_method("
body << tab << tab << "register_method("
<< ifaceclass << ", " << method.get("name") << ", "<< stub_name(method.get("name"))
<< ");" << endl;
}
file << tab << "}" << endl
body << tab << "}" << endl
<< endl;
file << tab << "::DBus::IntrospectedInterface *const introspect() const " << endl
body << tab << "::DBus::IntrospectedInterface *const introspect() const " << endl
<< tab << "{" << endl;
for (Xml::Nodes::iterator mi = ms.begin(); mi != ms.end(); ++mi)
@ -747,65 +742,65 @@ void generate_adaptor(Xml::Document &doc, const char *filename)
Xml::Node &method = **mi;
Xml::Nodes args = method["arg"];
file << tab << tab << "static ::DBus::IntrospectedArgument " << method.get("name") << "_args[] = " << endl
body << tab << tab << "static ::DBus::IntrospectedArgument " << method.get("name") << "_args[] = " << endl
<< tab << tab << "{" << endl;
for (Xml::Nodes::iterator ai = args.begin(); ai != args.end(); ++ai)
{
Xml::Node &arg = **ai;
file << tab << tab << tab << "{ ";
body << tab << tab << tab << "{ ";
if (arg.get("name").length())
{
file << "\"" << arg.get("name") << "\", ";
body << "\"" << arg.get("name") << "\", ";
}
else
{
file << "0, ";
body << "0, ";
}
file << "\"" << arg.get("type") << "\", "
body << "\"" << arg.get("type") << "\", "
<< (arg.get("direction") == "in" ? "true" : "false")
<< " }," << endl;
}
file << tab << tab << tab << "{ 0, 0, 0 }" << endl
body << tab << tab << tab << "{ 0, 0, 0 }" << endl
<< tab << tab << "};" << endl;
}
file << tab << tab << "static ::DBus::IntrospectedMethod " << ifaceclass << "_methods[] = " << endl
body << tab << tab << "static ::DBus::IntrospectedMethod " << ifaceclass << "_methods[] = " << endl
<< tab << tab << "{" << endl;
for (Xml::Nodes::iterator mi = methods.begin(); mi != methods.end(); ++mi)
{
Xml::Node &method = **mi;
file << tab << tab << tab << "{ \"" << method.get("name") << "\", " << method.get("name") << "_args }," << endl;
body << tab << tab << tab << "{ \"" << method.get("name") << "\", " << method.get("name") << "_args }," << endl;
}
file << tab << tab << tab << "{ 0, 0 }" << endl
body << tab << tab << tab << "{ 0, 0 }" << endl
<< tab << tab << "};" << endl;
file << tab << tab << "static ::DBus::IntrospectedMethod " << ifaceclass << "_signals[] = " << endl
body << tab << tab << "static ::DBus::IntrospectedMethod " << ifaceclass << "_signals[] = " << endl
<< tab << tab << "{" << endl;
for (Xml::Nodes::iterator si = signals.begin(); si != signals.end(); ++si)
{
Xml::Node &method = **si;
file << tab << tab << tab << "{ \"" << method.get("name") << "\", " << method.get("name") << "_args }," << endl;
body << tab << tab << tab << "{ \"" << method.get("name") << "\", " << method.get("name") << "_args }," << endl;
}
file << tab << tab << tab << "{ 0, 0 }" << endl
body << tab << tab << tab << "{ 0, 0 }" << endl
<< tab << tab << "};" << endl;
file << tab << tab << "static ::DBus::IntrospectedProperty " << ifaceclass << "_properties[] = " << endl
body << tab << tab << "static ::DBus::IntrospectedProperty " << ifaceclass << "_properties[] = " << endl
<< tab << tab << "{" << endl;
for (Xml::Nodes::iterator pi = properties.begin(); pi != properties.end(); ++pi)
{
Xml::Node &property = **pi;
file << tab << tab << tab << "{ "
body << tab << tab << tab << "{ "
<< "\"" << property.get("name") << "\", "
<< "\"" << property.get("type") << "\", "
<< (property.get("access").find("read") != string::npos
@ -819,10 +814,10 @@ void generate_adaptor(Xml::Document &doc, const char *filename)
}
file << tab << tab << tab << "{ 0, 0, 0, 0 }" << endl
body << tab << tab << tab << "{ 0, 0, 0, 0 }" << endl
<< tab << tab << "};" << endl;
file << tab << tab << "static ::DBus::IntrospectedInterface " << ifaceclass << "_interface = " << endl
body << tab << tab << "static ::DBus::IntrospectedInterface " << ifaceclass << "_interface = " << endl
<< tab << tab << "{" << endl
<< tab << tab << tab << "\"" << ifacename << "\"," << endl
<< tab << tab << tab << ifaceclass << "_methods," << endl
@ -833,7 +828,7 @@ void generate_adaptor(Xml::Document &doc, const char *filename)
<< tab << "}" << endl
<< endl;
file << "public:" << endl
body << "public:" << endl
<< endl
<< tab << "/* properties exposed by this interface, use" << endl
<< tab << " * property() and property(value) to get and set a particular property" << endl
@ -846,12 +841,12 @@ void generate_adaptor(Xml::Document &doc, const char *filename)
string type = property.get("type");
string type_name = signature_to_type(type);
file << tab << "::DBus::PropertyAdaptor< " << type_name << " > " << name << ";" << endl;
body << tab << "::DBus::PropertyAdaptor< " << type_name << " > " << name << ";" << endl;
}
file << endl;
body << endl;
file << "public:" << endl
body << "public:" << endl
<< endl
<< tab << "/* methods exported by this interface," << endl
<< tab << " * you will have to implement them in your ObjectAdaptor" << endl
@ -864,31 +859,31 @@ void generate_adaptor(Xml::Document &doc, const char *filename)
Xml::Nodes args_in = args.select("direction","in");
Xml::Nodes args_out = args.select("direction","out");
file << tab << "virtual ";
body << tab << "virtual ";
if (args_out.size() == 0 || args_out.size() > 1)
{
file << "void ";
body << "void ";
}
else if (args_out.size() == 1)
{
file << signature_to_type(args_out.front()->get("type")) << " ";
body << signature_to_type(args_out.front()->get("type")) << " ";
}
file << method.get("name") << "(";
body << method.get("name") << "(";
unsigned int i = 0;
for (Xml::Nodes::iterator ai = args_in.begin(); ai != args_in.end(); ++ai, ++i)
{
Xml::Node &arg = **ai;
file << "const " << signature_to_type(arg.get("type")) << "& ";
body << "const " << signature_to_type(arg.get("type")) << "& ";
string arg_name = arg.get("name");
if (arg_name.length())
file << arg_name;
body << arg_name;
if ((i+1 != args_in.size() || args_out.size() > 1))
file << ", ";
body << ", ";
}
if (args_out.size() > 1)
@ -897,20 +892,20 @@ void generate_adaptor(Xml::Document &doc, const char *filename)
for (Xml::Nodes::iterator ao = args_out.begin(); ao != args_out.end(); ++ao, ++i)
{
Xml::Node &arg = **ao;
file << signature_to_type(arg.get("type")) << "&";
body << signature_to_type(arg.get("type")) << "&";
string arg_name = arg.get("name");
if (arg_name.length())
file << " " << arg_name;
body << " " << arg_name;
if (i+1 != args_out.size())
file << ", ";
body << ", ";
}
}
file << ") = 0;" << endl;
body << ") = 0;" << endl;
}
file << endl
body << endl
<< "public:" << endl
<< endl
<< tab << "/* signal emitters for this interface" << endl
@ -921,39 +916,39 @@ void generate_adaptor(Xml::Document &doc, const char *filename)
Xml::Node &signal = **si;
Xml::Nodes args = signal["arg"];
file << tab << "void " << signal.get("name") << "(";
body << tab << "void " << signal.get("name") << "(";
unsigned int i = 0;
for (Xml::Nodes::iterator a = args.begin(); a != args.end(); ++a, ++i)
{
Xml::Node &arg = **a;
file << "const " << signature_to_type(arg.get("type")) << "& arg" << i+1;
body << "const " << signature_to_type(arg.get("type")) << "& arg" << i+1;
if (i+1 != args.size())
file << ", ";
body << ", ";
}
file << ")" << endl
body << ")" << endl
<< tab << "{" << endl
<< tab << tab << "::DBus::SignalMessage sig(\"" << signal.get("name") <<"\");" << endl;;
if (args.size() > 0)
{
file << tab << tab << "::DBus::MessageIter wi = sig.writer();" << endl;
body << tab << tab << "::DBus::MessageIter wi = sig.writer();" << endl;
for (unsigned int i = 0; i < args.size(); ++i)
{
file << tab << tab << "wi << arg" << i+1 << ";" << endl;
body << tab << tab << "wi << arg" << i+1 << ";" << endl;
}
}
file << tab << tab << "emit_signal(sig);" << endl
body << tab << tab << "emit_signal(sig);" << endl
<< tab << "}" << endl;
}
file << endl
body << endl
<< "private:" << endl
<< endl
<< tab << "/* unmarshalers (to unpack the DBus message before calling the actual interface method)" << endl
@ -966,7 +961,7 @@ void generate_adaptor(Xml::Document &doc, const char *filename)
Xml::Nodes args_in = args.select("direction","in");
Xml::Nodes args_out = args.select("direction","out");
file << tab << "::DBus::Message " << stub_name(method.get("name")) << "(const ::DBus::CallMessage &call)" << endl
body << tab << "::DBus::Message " << stub_name(method.get("name")) << "(const ::DBus::CallMessage &call)" << endl
<< tab << "{" << endl
<< tab << tab << "::DBus::MessageIter ri = call.reader();" << endl
<< endl;
@ -975,17 +970,17 @@ void generate_adaptor(Xml::Document &doc, const char *filename)
for (Xml::Nodes::iterator ai = args_in.begin(); ai != args_in.end(); ++ai, ++i)
{
Xml::Node &arg = **ai;
file << tab << tab << signature_to_type(arg.get("type")) << " argin" << i << ";"
body << tab << tab << signature_to_type(arg.get("type")) << " argin" << i << ";"
<< " ri >> argin" << i << ";" << endl;
}
if (args_out.size() == 0)
{
file << tab << tab;
body << tab << tab;
}
else if (args_out.size() == 1)
{
file << tab << tab << signature_to_type(args_out.front()->get("type")) << " argout1 = ";
body << tab << tab << signature_to_type(args_out.front()->get("type")) << " argout1 = ";
}
else
{
@ -993,60 +988,70 @@ void generate_adaptor(Xml::Document &doc, const char *filename)
for (Xml::Nodes::iterator ao = args_out.begin(); ao != args_out.end(); ++ao, ++i)
{
Xml::Node &arg = **ao;
file << tab << tab << signature_to_type(arg.get("type")) << " argout" << i << ";" << endl;
body << tab << tab << signature_to_type(arg.get("type")) << " argout" << i << ";" << endl;
}
file << tab << tab;
body << tab << tab;
}
file << method.get("name") << "(";
body << method.get("name") << "(";
for (unsigned int i = 0; i < args_in.size(); ++i)
{
file << "argin" << i+1;
body << "argin" << i+1;
if ((i+1 != args_in.size() || args_out.size() > 1))
file << ", ";
body << ", ";
}
if (args_out.size() > 1)
for (unsigned int i = 0; i < args_out.size(); ++i)
{
file << "argout" << i+1;
body << "argout" << i+1;
if (i+1 != args_out.size())
file << ", ";
body << ", ";
}
file << ");" << endl;
body << ");" << endl;
file << tab << tab << "::DBus::ReturnMessage reply(call);" << endl;
body << tab << tab << "::DBus::ReturnMessage reply(call);" << endl;
if (args_out.size() > 0)
{
file << tab << tab << "::DBus::MessageIter wi = reply.writer();" << endl;
body << tab << tab << "::DBus::MessageIter wi = reply.writer();" << endl;
for (unsigned int i = 0; i < args_out.size(); ++i)
{
file << tab << tab << "wi << argout" << i+1 << ";" << endl;
body << tab << tab << "wi << argout" << i+1 << ";" << endl;
}
}
file << tab << tab << "return reply;" << endl;
body << tab << tab << "return reply;" << endl;
file << tab << "}" << endl;
body << tab << "}" << endl;
}
file << "};" << endl
body << "};" << endl
<< endl;
for (unsigned int i = 0; i < nspaces; ++i)
{
file << "} ";
body << "} ";
}
file << endl;
body << endl;
}
file << "#endif//" << cond_comp << endl;
body << "#endif//" << cond_comp << endl;
ofstream file(filename);
if (file.bad())
{
cerr << "unable to write file " << filename << endl;
exit(-1);
}
file << head.str ();
file << body.str ();
file.close();
}