merge from official dbus-c++ fd.org repo
Merge git://anongit.freedesktop.org/git/dbus/dbus-c++ Conflicts: configure.ac examples/Makefile.am
This commit is contained in:
commit
fc54ec2a0b
17 changed files with 275 additions and 41 deletions
|
@ -202,6 +202,7 @@ AC_OUTPUT(
|
|||
doc/Doxyfile
|
||||
examples/Makefile
|
||||
examples/properties/Makefile
|
||||
examples/properties_get_set/Makefile
|
||||
examples/echo/Makefile
|
||||
examples/ecore/Makefile
|
||||
examples/hal/Makefile
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
SUBDIRS = properties echo hal glib ecore
|
||||
SUBDIRS = properties properties_get_set echo hal glib
|
||||
|
||||
MAINTAINERCLEANFILES = \
|
||||
Makefile.in
|
||||
|
|
|
@ -10,9 +10,7 @@ echo_server_LDADD = $(top_builddir)/src/libdbus-c++-1.la
|
|||
echo-server-glue.h: echo-introspect.xml
|
||||
$(top_builddir)/tools/dbusxx-xml2cpp $^ --adaptor=$@
|
||||
|
||||
if HAVE_PTHREAD
|
||||
noinst_PROGRAMS += echo-client-mt
|
||||
endif
|
||||
|
||||
echo_client_mt_SOURCES = echo-client-glue.h echo-client.h echo-client.cpp
|
||||
echo_client_mt_LDADD = $(top_builddir)/src/libdbus-c++-1.la @PTHREAD_LIBS@
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include "echo-client-glue.h"
|
||||
|
||||
class EchoClient
|
||||
: public org::freedesktop::DBus::EchoDemo,
|
||||
: public org::freedesktop::DBus::EchoDemo_proxy,
|
||||
public DBus::IntrospectableProxy,
|
||||
public DBus::ObjectProxy
|
||||
{
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include "echo-server-glue.h"
|
||||
|
||||
class EchoServer
|
||||
: public org::freedesktop::DBus::EchoDemo,
|
||||
: public org::freedesktop::DBus::EchoDemo_adaptor,
|
||||
public DBus::IntrospectableAdaptor,
|
||||
public DBus::ObjectAdaptor
|
||||
{
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include "props-glue.h"
|
||||
|
||||
class PropsServer
|
||||
: public org::freedesktop::DBus::PropsDemo,
|
||||
: public org::freedesktop::DBus::PropsDemo_adaptor,
|
||||
public DBus::IntrospectableAdaptor,
|
||||
public DBus::PropertiesAdaptor,
|
||||
public DBus::ObjectAdaptor
|
||||
|
|
26
examples/properties_get_set/Makefile.am
Normal file
26
examples/properties_get_set/Makefile.am
Normal file
|
@ -0,0 +1,26 @@
|
|||
EXTRA_DIST = propsget-introspect.xml
|
||||
|
||||
AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include
|
||||
|
||||
noinst_PROGRAMS = propsgs-server propsgs-client
|
||||
|
||||
propsgs_server_SOURCES = propsgs-glue.h propsgs-server.h propsgs-server.cpp
|
||||
propsgs_server_LDADD = $(top_builddir)/src/libdbus-c++-1.la
|
||||
|
||||
propsgs_client_SOURCES = propsgs-glue.h propsgs-client.h propsgs-client.cpp
|
||||
propsgs_client_LDADD = $(top_builddir)/src/libdbus-c++-1.la -lpthread
|
||||
|
||||
propsgs-glue-adaptor.h: propsgs-introspect.xml
|
||||
$(top_builddir)/tools/dbusxx-xml2cpp $^ --adaptor=$@ --
|
||||
|
||||
propsgs-glue-proxy.h: propsgs-introspect.xml
|
||||
$(top_builddir)/tools/dbusxx-xml2cpp $^ --proxy=$@ --
|
||||
|
||||
BUILT_SOURCES = propsgs-glue-adaptor.h propsgs-glue-proxy.h
|
||||
CLEANFILES = $(BUILT_SOURCES)
|
||||
|
||||
dist-hook:
|
||||
cd $(distdir); rm -f $(BUILT_SOURCES)
|
||||
|
||||
MAINTAINERCLEANFILES = \
|
||||
Makefile.in
|
75
examples/properties_get_set/propsgs-client.cpp
Normal file
75
examples/properties_get_set/propsgs-client.cpp
Normal file
|
@ -0,0 +1,75 @@
|
|||
#include "propsgs-client.h"
|
||||
#include <signal.h>
|
||||
#include <iostream>
|
||||
|
||||
using namespace org::freedesktop::DBus;
|
||||
|
||||
#define P(x) std::cout << #x << " = " << x << std::endl;
|
||||
|
||||
static const char *PROPS_SERVER_NAME = "org.freedesktop.DBus.Examples.Properties";
|
||||
static const char *PROPS_SERVER_PATH = "/org/freedesktop/DBus/Examples/Properties";
|
||||
|
||||
PropsClient::PropsClient(DBus::Connection &connection, const char *path, const char *name)
|
||||
: DBus::ObjectProxy(connection, path, name)
|
||||
{
|
||||
}
|
||||
|
||||
void PropsClient::MessageChanged(const std::string& message){
|
||||
std::cout << "message received: " << message << std::endl;
|
||||
};
|
||||
|
||||
DBus::BusDispatcher dispatcher;
|
||||
|
||||
PropsClient * client;
|
||||
|
||||
void niam(int sig)
|
||||
{
|
||||
dispatcher.leave();
|
||||
pthread_exit(NULL);
|
||||
delete client;
|
||||
}
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
void * test_property_proxy(void * input){
|
||||
P("1");
|
||||
sleep(2);
|
||||
P(client->Version());
|
||||
|
||||
P("2");
|
||||
sleep(1);
|
||||
P(client->Message());
|
||||
|
||||
P("3");
|
||||
sleep(1);
|
||||
client->Message( "message set by property access" );
|
||||
|
||||
P("4");
|
||||
sleep(1);
|
||||
P(client->Message());
|
||||
|
||||
P("5");
|
||||
sleep(1);
|
||||
client->Data( 1.1 );
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGTERM, niam);
|
||||
signal(SIGINT, niam);
|
||||
|
||||
DBus::default_dispatcher = &dispatcher;
|
||||
|
||||
DBus::Connection conn = DBus::Connection::SessionBus();
|
||||
|
||||
client = new PropsClient(conn, PROPS_SERVER_PATH, PROPS_SERVER_NAME );
|
||||
|
||||
pthread_t thread;
|
||||
pthread_create(&thread, NULL, test_property_proxy, 0);
|
||||
|
||||
P("dispatcher.enter();");
|
||||
|
||||
dispatcher.enter();
|
||||
|
||||
return 0;
|
||||
}
|
20
examples/properties_get_set/propsgs-client.h
Normal file
20
examples/properties_get_set/propsgs-client.h
Normal file
|
@ -0,0 +1,20 @@
|
|||
#ifndef __DEMO_PROPS_SERVER_H
|
||||
#define __DEMO_PROPS_SERVER_H
|
||||
|
||||
#include <dbus-c++/dbus.h>
|
||||
#include "propsgs-glue-proxy.h"
|
||||
|
||||
class PropsClient
|
||||
: public org::freedesktop::DBus::PropsGSDemo_proxy,
|
||||
public DBus::IntrospectableProxy,
|
||||
// public DBus::PropertiesProxy,
|
||||
public DBus::ObjectProxy
|
||||
{
|
||||
public:
|
||||
|
||||
PropsClient(DBus::Connection &connection, const char *path, const char *name);
|
||||
|
||||
void MessageChanged(const std::string& message);
|
||||
};
|
||||
|
||||
#endif//__DEMO_PROPS_SERVER_H
|
11
examples/properties_get_set/propsgs-introspect.xml
Normal file
11
examples/properties_get_set/propsgs-introspect.xml
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" ?>
|
||||
<node name="/org/freedesktop/DBus/Examples/Properties">
|
||||
<interface name="org.freedesktop.DBus.PropsGSDemo">
|
||||
<property name="Version" type="i" access="read"/>
|
||||
<property name="Message" type="s" access="readwrite"/>
|
||||
<property name="Data" type="d" access="write"/>
|
||||
<signal name="MessageChanged">
|
||||
<arg name="message" type="s"/>
|
||||
</signal>
|
||||
</interface>
|
||||
</node>
|
46
examples/properties_get_set/propsgs-server.cpp
Normal file
46
examples/properties_get_set/propsgs-server.cpp
Normal file
|
@ -0,0 +1,46 @@
|
|||
#include "propsgs-server.h"
|
||||
#include <signal.h>
|
||||
|
||||
static const char *PROPS_SERVER_NAME = "org.freedesktop.DBus.Examples.Properties";
|
||||
static const char *PROPS_SERVER_PATH = "/org/freedesktop/DBus/Examples/Properties";
|
||||
|
||||
PropsServer::PropsServer(DBus::Connection &connection)
|
||||
: DBus::ObjectAdaptor(connection, PROPS_SERVER_PATH)
|
||||
{
|
||||
Version = 1;
|
||||
Message = "default message";
|
||||
}
|
||||
|
||||
void PropsServer::on_set_property
|
||||
(DBus::InterfaceAdaptor &interface, const std::string &property, const DBus::Variant &value)
|
||||
{
|
||||
if (property == "Message")
|
||||
{
|
||||
std::string msg = value;
|
||||
this->MessageChanged(msg);
|
||||
}
|
||||
}
|
||||
|
||||
DBus::BusDispatcher dispatcher;
|
||||
|
||||
void niam(int sig)
|
||||
{
|
||||
dispatcher.leave();
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGTERM, niam);
|
||||
signal(SIGINT, niam);
|
||||
|
||||
DBus::default_dispatcher = &dispatcher;
|
||||
|
||||
DBus::Connection conn = DBus::Connection::SessionBus();
|
||||
conn.request_name(PROPS_SERVER_NAME);
|
||||
|
||||
PropsServer server(conn);
|
||||
|
||||
dispatcher.enter();
|
||||
|
||||
return 0;
|
||||
}
|
21
examples/properties_get_set/propsgs-server.h
Normal file
21
examples/properties_get_set/propsgs-server.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
#ifndef __DEMO_PROPS_SERVER_H
|
||||
#define __DEMO_PROPS_SERVER_H
|
||||
|
||||
#include <dbus-c++/dbus.h>
|
||||
#include "propsgs-glue-adaptor.h"
|
||||
|
||||
class PropsServer
|
||||
: public org::freedesktop::DBus::PropsGSDemo_adaptor,
|
||||
public DBus::IntrospectableAdaptor,
|
||||
public DBus::PropertiesAdaptor,
|
||||
public DBus::ObjectAdaptor
|
||||
{
|
||||
public:
|
||||
|
||||
PropsServer(DBus::Connection &connection);
|
||||
|
||||
void on_set_property
|
||||
(DBus::InterfaceAdaptor &interface, const std::string &property, const DBus::Variant &value);
|
||||
};
|
||||
|
||||
#endif//__DEMO_PROPS_SERVER_H
|
|
@ -27,10 +27,7 @@
|
|||
|
||||
#include "dbus-c++-config.h"
|
||||
|
||||
#ifdef HAVE_PTHREAD_H
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
#include <list>
|
||||
|
||||
#include "api.h"
|
||||
|
@ -141,15 +138,7 @@ public:
|
|||
|
||||
private:
|
||||
|
||||
#if defined HAVE_PTHREAD_H
|
||||
|
||||
pthread_mutex_t _mutex;
|
||||
|
||||
#elif defined HAVE_WIN32
|
||||
|
||||
//TODO: use a critical section
|
||||
|
||||
#endif
|
||||
};
|
||||
|
||||
class DXXAPI DefaultMainLoop
|
||||
|
|
|
@ -78,42 +78,22 @@ DefaultWatch::~DefaultWatch()
|
|||
|
||||
DefaultMutex::DefaultMutex()
|
||||
{
|
||||
#if defined HAVE_PTHREAD_H
|
||||
|
||||
pthread_mutex_init(&_mutex, NULL);
|
||||
|
||||
#elif defined HAVE_WIN32
|
||||
#endif
|
||||
}
|
||||
|
||||
DefaultMutex::~DefaultMutex()
|
||||
{
|
||||
#if defined HAVE_PTHREAD_H
|
||||
|
||||
pthread_mutex_destroy(&_mutex);
|
||||
|
||||
#elif defined HAVE_WIN32
|
||||
#endif
|
||||
}
|
||||
|
||||
void DefaultMutex::lock()
|
||||
{
|
||||
#if defined HAVE_PTHREAD_H
|
||||
|
||||
pthread_mutex_lock(&_mutex);
|
||||
|
||||
#elif defined HAVE_WIN32
|
||||
#endif
|
||||
}
|
||||
|
||||
void DefaultMutex::unlock()
|
||||
{
|
||||
#if defined HAVE_PTHREAD_H
|
||||
|
||||
pthread_mutex_unlock(&_mutex);
|
||||
|
||||
#elif defined HAVE_WIN32
|
||||
#endif
|
||||
}
|
||||
|
||||
DefaultMainLoop::DefaultMainLoop()
|
||||
|
|
|
@ -74,7 +74,9 @@ void InterfaceAdaptor::emit_signal(const SignalMessage &sig)
|
|||
{
|
||||
SignalMessage &sig2 = const_cast<SignalMessage &>(sig);
|
||||
|
||||
sig2.interface(name().c_str());
|
||||
if (sig2.interface() == NULL)
|
||||
sig2.interface(name().c_str());
|
||||
|
||||
_emit_signal(sig2);
|
||||
}
|
||||
|
||||
|
@ -151,6 +153,8 @@ Message InterfaceProxy::invoke_method(const CallMessage &call)
|
|||
{
|
||||
CallMessage &call2 = const_cast<CallMessage &>(call);
|
||||
|
||||
call2.interface(name().c_str());
|
||||
if (call.interface() == NULL)
|
||||
call2.interface(name().c_str());
|
||||
|
||||
return _invoke_method(call2);
|
||||
}
|
||||
|
|
|
@ -324,8 +324,11 @@ void ObjectProxy::unregister_obj()
|
|||
|
||||
Message ObjectProxy::_invoke_method(CallMessage &call)
|
||||
{
|
||||
call.path(path().c_str());
|
||||
call.destination(service().c_str());
|
||||
if (call.path() == NULL)
|
||||
call.path(path().c_str());
|
||||
|
||||
if (call.destination() == NULL)
|
||||
call.destination(service().c_str());
|
||||
|
||||
return conn().send_blocking(call);
|
||||
}
|
||||
|
|
|
@ -257,6 +257,8 @@ void generate_proxy(Xml::Document &doc, const char *filename)
|
|||
|
||||
getline(ss, ifaceclass);
|
||||
|
||||
ifaceclass += "_proxy";
|
||||
|
||||
cerr << "generating code for interface " << ifacename << "..." << endl;
|
||||
|
||||
file << "class " << ifaceclass << endl
|
||||
|
@ -281,6 +283,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 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
|
||||
<< "::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 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;
|
||||
}
|
||||
}
|
||||
|
||||
file << "public:" << endl
|
||||
<< endl
|
||||
|
@ -560,6 +618,8 @@ void generate_adaptor(Xml::Document &doc, const char *filename)
|
|||
|
||||
getline(ss, ifaceclass);
|
||||
|
||||
ifaceclass += "_adaptor";
|
||||
|
||||
cerr << "generating code for interface " << ifacename << "..." << endl;
|
||||
|
||||
file << "class " << ifaceclass << endl
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue