summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorpd <shackan@aris-ubuntu804.(none)>2008-08-16 16:29:31 +0200
committerpd <shackan@aris-ubuntu804.(none)>2008-08-16 16:29:31 +0200
commitacc230eb98c48086750d9548bbc938674d31092b (patch)
tree320a75aaabda625243925d023d65ee637ca2b5fd /examples
parent52ce50e9440166c9c9c25eb7ba0703ff063a63b3 (diff)
downloaddbus-c++-acc230eb98c48086750d9548bbc938674d31092b.tar.gz
Added properties proxy example (João Xavier)
Diffstat (limited to 'examples')
-rw-r--r--examples/properties_get_set/Makefile.am26
-rw-r--r--examples/properties_get_set/propsgs-client.cpp75
-rw-r--r--examples/properties_get_set/propsgs-client.h20
-rw-r--r--examples/properties_get_set/propsgs-introspect.xml11
-rw-r--r--examples/properties_get_set/propsgs-server.cpp46
-rw-r--r--examples/properties_get_set/propsgs-server.h21
6 files changed, 199 insertions, 0 deletions
diff --git a/examples/properties_get_set/Makefile.am b/examples/properties_get_set/Makefile.am
new file mode 100644
index 0000000..6e5419d
--- /dev/null
+++ b/examples/properties_get_set/Makefile.am
@@ -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
diff --git a/examples/properties_get_set/propsgs-client.cpp b/examples/properties_get_set/propsgs-client.cpp
new file mode 100644
index 0000000..b47ad39
--- /dev/null
+++ b/examples/properties_get_set/propsgs-client.cpp
@@ -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;
+}
diff --git a/examples/properties_get_set/propsgs-client.h b/examples/properties_get_set/propsgs-client.h
new file mode 100644
index 0000000..85595d5
--- /dev/null
+++ b/examples/properties_get_set/propsgs-client.h
@@ -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
diff --git a/examples/properties_get_set/propsgs-introspect.xml b/examples/properties_get_set/propsgs-introspect.xml
new file mode 100644
index 0000000..5c0e74f
--- /dev/null
+++ b/examples/properties_get_set/propsgs-introspect.xml
@@ -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>
diff --git a/examples/properties_get_set/propsgs-server.cpp b/examples/properties_get_set/propsgs-server.cpp
new file mode 100644
index 0000000..8339d20
--- /dev/null
+++ b/examples/properties_get_set/propsgs-server.cpp
@@ -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;
+}
diff --git a/examples/properties_get_set/propsgs-server.h b/examples/properties_get_set/propsgs-server.h
new file mode 100644
index 0000000..a3169d6
--- /dev/null
+++ b/examples/properties_get_set/propsgs-server.h
@@ -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