major D-Bus code update

git-svn-id: http://dev.openwengo.org/svn/openwengo/wengophone-ng/branches/wengophone-dbus-api/libs/dbus@7715 30a43799-04e7-0310-8b2b-ea0d24f86d0e
This commit is contained in:
pdurante 2006-09-23 23:25:34 +00:00
parent acfeb85b87
commit 42ea920aeb
41 changed files with 958 additions and 1506 deletions

View file

@ -25,7 +25,7 @@
#ifndef __DBUSXX_TOOLS_INTROSPECT_H
#define __DBUSXX_TOOLS_INTROSPECT_H
#include <dbus-c++/dbus-c++.h>
#include <dbus-c++/dbus.h>
#include <string>
class IntrospectedObject : public DBus::IntrospectableProxy, public DBus::ObjectProxy

View file

@ -38,12 +38,14 @@ using namespace DBus;
static const char* tab = " ";
static const char* header = "\n\
/* This file was automatically generated by dbusxx-xml2cpp; DO NOT EDIT! */\n\
/*\n\
* This file was automatically generated by dbusxx-xml2cpp; DO NOT EDIT!\n\
*/\n\
\n\
";
static const char* dbus_includes = "\n\
#include <dbus-c++/dbus-c++.h>\n\
#include <dbus-c++/dbus.h>\n\
\n\
";
@ -51,8 +53,8 @@ typedef map<string,string> TypeCache;
void usage( const char* argv0 )
{
cerr << endl << "Usage: " << argv0 << " <xmlfile> [ --client=<outfile.h> ] [ --adaptor=<outfile.h> ]"
<< endl << endl;
cerr << endl << "Usage: " << argv0 << " <xmlfile> [ --proxy=<outfile.h> ] [ --adaptor=<outfile.h> ]"
<< endl << endl;
exit(-1);
}
@ -60,7 +62,7 @@ void underscorize( std::string& str )
{
for(unsigned int i = 0; i < str.length(); ++i)
{
if(!isalpha(str[i])) str[i] = '_';
if(!isalpha(str[i]) && !isdigit(str[i])) str[i] = '_';
}
}
@ -83,19 +85,19 @@ const char* atomic_type_to_string( char t )
{
static struct { char type; char* name; } atos[] =
{
{ 'y', "DBus::Byte" },
{ 'b', "DBus::Bool" },
{ 'n', "DBus::Int16" },
{ 'q', "DBus::UInt16" },
{ 'i', "DBus::Int32" },
{ 'u', "DBus::UInt32" },
{ 'x', "DBus::Int64" },
{ 't', "DBus::UInt64" },
{ 'd', "DBus::Double" },
{ 's', "DBus::String" },
{ 'o', "DBus::Path" },
{ 'g', "DBus::Signature" },
{ 'v', "DBus::Variant" },
{ 'y', "::DBus::Byte" },
{ 'b', "::DBus::Bool" },
{ 'n', "::DBus::Int16" },
{ 'q', "::DBus::UInt16" },
{ 'i', "::DBus::Int32" },
{ 'u', "::DBus::UInt32" },
{ 'x', "::DBus::Int64" },
{ 't', "::DBus::UInt64" },
{ 'd', "::DBus::Double" },
{ 's', "::DBus::String" },
{ 'o', "::DBus::Path" },
{ 'g', "::DBus::Signature" },
{ 'v', "::DBus::Variant" },
{ '\0', "" }
};
int i;
@ -124,7 +126,7 @@ void _parse_signature( const std::string& signature, std::string& type, size_t&
{
case '{':
{
type += "DBus::Dict< ";
type += "std::map< ";
const char* atom = atomic_type_to_string(signature[++i]);
if(!atom)
@ -139,7 +141,7 @@ void _parse_signature( const std::string& signature, std::string& type, size_t&
}
default:
{
type += "DBus::Array< ";
type += "std::vector< ";
break;
}
}
@ -149,7 +151,7 @@ void _parse_signature( const std::string& signature, std::string& type, size_t&
}
case '(':
{
type += "DBus::Struct< ";
type += "::DBus::Struct< ";
++i;
_parse_signature(signature, type, i);
type += " >";
@ -188,7 +190,7 @@ std::string signature_to_type( const std::string& signature )
return type;
}
void generate_client( Xml::Document& doc, const char* filename )
void generate_proxy( Xml::Document& doc, const char* filename )
{
cerr << "writing " << filename << endl;
@ -225,13 +227,13 @@ void generate_client( Xml::Document& doc, const char* filename )
cerr << "generating code for interface " << ifacename << "..." << endl;
file << "class " << ifaceclass << " : public DBus::InterfaceProxy" << endl
<< "{" << endl
<< "public:" << endl
<< endl
<< tab << ifaceclass << "()" << endl
<< tab << ": DBus::InterfaceProxy(\"" << ifacename << "\")" << endl
<< tab << "{" << endl;
file << "class " << ifaceclass << " : public ::DBus::InterfaceProxy" << endl
<< "{" << endl
<< "public:" << endl
<< endl
<< tab << ifaceclass << "()" << endl
<< tab << ": ::DBus::InterfaceProxy(\"" << ifacename << "\")" << endl
<< tab << "{" << endl;
for(Xml::Nodes::iterator si = signals.begin(); si != signals.end(); ++si)
{
@ -243,7 +245,7 @@ void generate_client( Xml::Document& doc, const char* filename )
}
file << tab << "}" << endl
<< endl;
<< endl;
for(Xml::Nodes::iterator j = methods.begin(); j != methods.end(); ++j)
{
@ -297,9 +299,9 @@ void generate_client( Xml::Document& doc, const char* filename )
}
file << tab << "{" << endl
<< tab << tab << "DBus::CallMessage call;" << endl
<< tab << tab << "DBus::MessageIter wi = call.w_iter();" << endl
<< endl;
<< tab << tab << "::DBus::CallMessage call;" << endl
<< tab << tab << "::DBus::MessageIter wi = call.writer();" << endl
<< endl;
for(Xml::Nodes::iterator ai = args_in.begin(); ai != args_in.end(); ++ai)
{
@ -307,17 +309,17 @@ void generate_client( Xml::Document& doc, const char* filename )
}
file << tab << tab << "call.member(\"" << methodname << "\");" << endl
<< tab << tab << "DBus::Message ret = invoke_method(call);" << endl
<< tab << tab << "DBus::MessageIter ri = ret.r_iter();" << endl
<< endl;
<< tab << tab << "::DBus::Message ret = invoke_method(call);" << endl
<< tab << tab << "::DBus::MessageIter ri = ret.reader();" << endl
<< endl;
file << tab << "}" << endl
<< endl;
<< endl;
}
file << "};" << endl
<< endl;
<< endl;
}
#endif
file << "#endif//" << cond_comp << endl;
@ -343,7 +345,7 @@ void generate_adaptor( Xml::Document& doc, const char* filename )
std::string cond_comp = "__dbusxx__" + filestring + "__ADAPTOR_MARSHAL_H";
file << "#ifndef " << cond_comp << endl
<< "#define " << cond_comp << endl;
<< "#define " << cond_comp << endl;
file << dbus_includes;
@ -355,12 +357,14 @@ void generate_adaptor( Xml::Document& doc, const char* filename )
Xml::Node& iface = **i;
Xml::Nodes methods = iface["method"];
Xml::Nodes signals = iface["signal"];
Xml::Nodes properties = iface["property"];
Xml::Nodes ms;
ms.insert(ms.end(), methods.begin(), methods.end());
ms.insert(ms.end(), signals.begin(), signals.end());
std::string ifacename = iface.get("name");
if(ifacename.find("org.freedesktop.DBus") == 0)
if(ifacename == "org.freedesktop.DBus.Introspectable"
||ifacename == "org.freedesktop.DBus.Properties")
{
cerr << "skipping interface " << ifacename << endl;
continue;
@ -386,36 +390,53 @@ void generate_adaptor( Xml::Document& doc, const char* filename )
cerr << "generating code for interface " << ifacename << "..." << endl;
file << "class " << ifaceclass << " : public DBus::InterfaceAdaptor" << endl
<< "{" << endl
<< "public:" << endl
<< endl
<< tab << ifaceclass << "()" << endl
<< tab << ": DBus::InterfaceAdaptor(\"" << ifacename << "\")" << endl
<< tab << "{" << endl;
file << "class " << ifaceclass << endl
<< ": public ::DBus::InterfaceAdaptor" << endl
<< "{" << endl
<< "public:" << endl
<< endl
<< tab << ifaceclass << "()" << endl
<< tab << ": ::DBus::InterfaceAdaptor(\"" << ifacename << "\")" << endl
<< tab << "{" << endl;
for(Xml::Nodes::iterator pi = properties.begin(); pi != properties.end(); ++pi)
{
Xml::Node& property = **pi;
file << tab << tab << "bind_property("
<< property.get("name") << ", "
<< ( property.get("access").find("read") != string::npos
? "true"
: "false" )
<< ", "
<< ( property.get("access").find("write") != string::npos
? "true"
: "false" )
<< ");" << endl;
}
for(Xml::Nodes::iterator mi = methods.begin(); mi != methods.end(); ++mi)
{
Xml::Node& method = **mi;
file << tab << tab << "register_method("
<< ifaceclass << ", " << method.get("name") << ", "<< stub_name(method.get("name"))
<< ");" << endl;
<< ifaceclass << ", " << method.get("name") << ", "<< stub_name(method.get("name"))
<< ");" << endl;
}
file << tab << "}" << endl
<< endl;
<< endl;
file << tab << "DBus::IntrospectedInterface* const introspect() const " << endl
<< tab << "{" << endl;
file << tab << "::DBus::IntrospectedInterface* const introspect() const " << endl
<< tab << "{" << endl;
for(Xml::Nodes::iterator mi = ms.begin(); mi != ms.end(); ++mi)
{
Xml::Node& method = **mi;
Xml::Nodes args = method["arg"];
file << tab << tab << "static DBus::IntrospectedArgument " << method.get("name") << "_args[] = " << endl
<< tab << tab << "{" << endl;
file << tab << tab << "static ::DBus::IntrospectedArgument " << method.get("name") << "_args[] = " << endl
<< tab << tab << "{" << endl;
for(Xml::Nodes::iterator ai = args.begin(); ai != args.end(); ++ai)
{
@ -432,15 +453,15 @@ void generate_adaptor( Xml::Document& doc, const char* filename )
file << "0, ";
}
file << "\"" << arg.get("type") << "\", "
<< ( arg.get("direction") == "in" ? "true" : "false" )
<< " }," << endl;
<< ( arg.get("direction") == "in" ? "true" : "false" )
<< " }," << endl;
}
file << tab << tab << tab << "{ 0, 0, 0 }" << endl
<< tab << tab << "};" << endl;
<< tab << tab << "};" << endl;
}
file << tab << tab << "static DBus::IntrospectedMethod " << ifaceclass << "_methods[] = " << endl
<< tab << tab << "{" << endl;
file << tab << tab << "static ::DBus::IntrospectedMethod " << ifaceclass << "_methods[] = " << endl
<< tab << tab << "{" << endl;
for(Xml::Nodes::iterator mi = methods.begin(); mi != methods.end(); ++mi)
{
@ -450,10 +471,10 @@ void generate_adaptor( Xml::Document& doc, const char* filename )
}
file << tab << tab << tab << "{ 0, 0 }" << endl
<< tab << tab << "};" << endl;
<< tab << tab << "};" << endl;
file << tab << tab << "static DBus::IntrospectedMethod " << ifaceclass << "_signals[] = " << endl
<< tab << tab << "{" << endl;
file << tab << tab << "static ::DBus::IntrospectedMethod " << ifaceclass << "_signals[] = " << endl
<< tab << tab << "{" << endl;
for(Xml::Nodes::iterator si = signals.begin(); si != signals.end(); ++si)
{
@ -463,23 +484,66 @@ void generate_adaptor( Xml::Document& doc, const char* filename )
}
file << tab << tab << tab << "{ 0, 0 }" << endl
<< tab << tab << "};" << endl;
<< tab << tab << "};" << endl;
file << tab << tab << "static DBus::IntrospectedInterface " << ifaceclass << "_interface = " << endl
<< tab << tab << "{" << endl
<< tab << tab << tab << "\"" << ifacename << "\"," << endl
<< tab << tab << tab << ifaceclass << "_methods," << endl
<< tab << tab << tab << ifaceclass << "_signals," << endl
<< tab << tab << "};" << endl
<< tab << tab << "return &" << ifaceclass << "_interface;" << endl
<< tab << "}" << endl
<< endl;
file << 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 << "{ "
<< "\"" << property.get("name") << "\", "
<< "\"" << property.get("type") << "\", "
<< ( property.get("access").find("read") != string::npos
? "true"
: "false" )
<< ", "
<< ( property.get("access").find("write") != string::npos
? "true"
: "false" )
<< " }," << endl;
}
file << tab << tab << tab << "{ 0, 0, 0, 0 }" << endl
<< tab << tab << "};" << endl;
file << tab << tab << "static ::DBus::IntrospectedInterface " << ifaceclass << "_interface = " << endl
<< tab << tab << "{" << endl
<< tab << tab << tab << "\"" << ifacename << "\"," << endl
<< tab << tab << tab << ifaceclass << "_methods," << endl
<< tab << tab << tab << ifaceclass << "_signals," << endl
<< tab << tab << tab << ifaceclass << "_properties" << endl
<< tab << tab << "};" << endl
<< tab << tab << "return &" << ifaceclass << "_interface;" << endl
<< tab << "}" << endl
<< endl;
file << "public:" << endl
<< endl
<< tab << "/* methods exported by this interface," << endl
<< tab << " * you will have to implement them in your ObjectAdaptor" << endl
<< tab << " */" << endl;
<< endl
<< tab << "/* properties exposed by this interface, use" << endl
<< tab << " * property() and property(value) to get and set a particular property" << endl
<< tab << " */" << endl;
for(Xml::Nodes::iterator pi = properties.begin(); pi != properties.end(); ++pi)
{
Xml::Node& property = **pi;
std::string name = property.get("name");
std::string type = property.get("type");
std::string type_name = signature_to_type(type);
file << tab << "::DBus::PropertyAdaptor< " << type_name << " > " << name << ";" << endl;
}
file << endl;
file << "public:" << endl
<< endl
<< tab << "/* methods exported by this interface," << endl
<< tab << " * you will have to implement them in your ObjectAdaptor" << endl
<< tab << " */" << endl;
for(Xml::Nodes::iterator mi = methods.begin(); mi != methods.end(); ++mi)
{
@ -535,10 +599,10 @@ void generate_adaptor( Xml::Document& doc, const char* filename )
}
file << endl
<< "protected:" << endl
<< endl
<< tab << "/* signals emitted by this interface" << endl
<< tab << " */" << endl;
<< "protected:" << endl
<< endl
<< tab << "/* signals emitted by this interface" << endl
<< tab << " */" << endl;
for(Xml::Nodes::iterator si = signals.begin(); si != signals.end(); ++si)
{
@ -559,13 +623,13 @@ void generate_adaptor( Xml::Document& doc, const char* filename )
}
file << " )" << endl
<< tab << "{" << endl
<< tab << tab << "DBus::SignalMessage sig(\"" << signal.get("name") <<"\");" << endl;;
<< tab << "{" << endl
<< tab << tab << "::DBus::SignalMessage sig(\"" << signal.get("name") <<"\");" << endl;;
if(args.size() > 0)
{
file << tab << tab << "DBus::MessageIter wi = sig.w_iter();" << endl;
file << tab << tab << "::DBus::MessageIter wi = sig.writer();" << endl;
for(unsigned int i = 0; i < args.size(); ++i)
{
@ -574,14 +638,14 @@ void generate_adaptor( Xml::Document& doc, const char* filename )
}
file << tab << tab << "emit_signal(sig);" << endl
<< tab << "}" << endl;
<< tab << "}" << endl;
}
file << endl
<< "private:" << endl
<< endl
<< tab << "/* marshalers (to unpack the DBus message before calling the actual interface method)" << endl
<< tab << " */" << endl;
<< "private:" << endl
<< endl
<< tab << "/* marshalers (to unpack the DBus message before calling the actual interface method)" << endl
<< tab << " */" << endl;
for(Xml::Nodes::iterator mi = methods.begin(); mi != methods.end(); ++mi)
{
@ -590,17 +654,17 @@ 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
<< tab << "{" << endl
<< tab << tab << "DBus::MessageIter ri = call.r_iter();" << endl
<< endl;
file << tab << "::DBus::Message " << stub_name(method.get("name")) << "( const ::DBus::CallMessage& call )" << endl
<< tab << "{" << endl
<< tab << tab << "::DBus::MessageIter ri = call.reader();" << endl
<< endl;
unsigned int i = 1;
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 << ";"
<< " ri >> argin" << i << ";" << endl;
<< " ri >> argin" << i << ";" << endl;
}
if(args_out.size() == 0)
@ -643,11 +707,11 @@ void generate_adaptor( Xml::Document& doc, const char* filename )
file << ");" << endl;
file << tab << tab << "DBus::ReturnMessage reply(call);" << endl;
file << tab << tab << "::DBus::ReturnMessage reply(call);" << endl;
if(args_out.size() > 0)
{
file << tab << tab << "DBus::MessageIter wi = reply.w_iter();" << endl;
file << tab << tab << "::DBus::MessageIter wi = reply.writer();" << endl;
for(unsigned int i = 0; i < args_out.size(); ++i)
{
@ -661,7 +725,7 @@ void generate_adaptor( Xml::Document& doc, const char* filename )
}
file << "};" << endl
<< endl;
<< endl;
for(size_t i = 0; i < nspaces; ++i)
{
@ -682,21 +746,21 @@ int main( int argc, char** argv )
usage(argv[0]);
}
bool client_mode, adaptor_mode;
char *client, *adaptor;
bool proxy_mode, adaptor_mode;
char *proxy, *adaptor;
client_mode = false;
client = 0;
proxy_mode = false;
proxy = 0;
adaptor_mode = false;
adaptor = 0;
for(int a = 1; a < argc; ++a)
{
if(!strncmp(argv[a], "--client=", 9))
if(!strncmp(argv[a], "--proxy=", 8))
{
client_mode = true;
client = argv[a] +9;
proxy_mode = true;
proxy = argv[a] +8;
}
else
if(!strncmp(argv[a], "--adaptor=", 10))
@ -706,7 +770,7 @@ int main( int argc, char** argv )
}
}
if(!client_mode && !adaptor_mode) usage(argv[0]);
if(!proxy_mode && !adaptor_mode) usage(argv[0]);
ifstream xmlfile(argv[1]);
@ -735,7 +799,7 @@ int main( int argc, char** argv )
return -1;
}
if(client_mode) generate_client(doc, client);
if(proxy_mode) generate_proxy(doc, proxy);
if(adaptor_mode) generate_adaptor(doc, adaptor);
return 0;

View file

@ -25,7 +25,7 @@
#ifndef __DBUSXX_TOOLS_XML2CPP_H
#define __DBUSXX_TOOLS_XML2CPP_H
#include <dbus-c++/dbus-c++.h>
#include <dbus-c++/dbus.h>
#include <dbus/dbus.h>
#endif//__DBUSXX_TOOLS_XML2CPP_H