blob: 01eb403628519f294263416a2a816a8d6d03f408 [file] [log] [blame]
Emeric Vigier2f625822012-08-06 11:09:52 -04001#include "propsgs-client.h"
2#include <iostream>
3#include <signal.h>
4#include <pthread.h>
5
6using namespace org::freedesktop::DBus;
7
8static const char *PROPS_SERVER_NAME = "org.freedesktop.DBus.Examples.Properties";
9static const char *PROPS_SERVER_PATH = "/org/freedesktop/DBus/Examples/Properties";
10
11PropsClient::PropsClient(DBus::Connection &connection, const char *path, const char *name)
12 : DBus::ObjectProxy(connection, path, name)
13{
14}
15
16void PropsClient::MessageChanged(const std::string &message)
17{
18 std::cout << "MessageChanged signal, new value: " << message << "\n";
19};
20
21void PropsClient::DataChanged(const double &data)
22{
23 std::cout << "DataChanged signal, new value:" << data << "\n";
24};
25
26void *test_property_proxy(void *input)
27{
28 PropsClient *client = static_cast<PropsClient *>(input);
29
30 std::cout << "read property 'Version', value:" << client->Version() << "\n";
31
32 std::cout << "read property 'Message', value:" << client->Message() << "\n";
33
34 client->Message("message set by property access");
35 std::cout << "wrote property 'Message'\n";
36
37 std::cout << "read property 'Message', value:" << client->Message() << "\n";
38
39 client->Data(1.1);
40 std::cout << "wrote property 'Data'\n";
41
42 return NULL;
43}
44
45DBus::BusDispatcher dispatcher;
46
47void niam(int sig)
48{
49 dispatcher.leave();
50 pthread_exit(NULL);
51}
52
53int main()
54{
55 signal(SIGTERM, niam);
56 signal(SIGINT, niam);
57
58 DBus::default_dispatcher = &dispatcher;
59
60 DBus::_init_threading();
61
62 DBus::Connection conn = DBus::Connection::SessionBus();
63
64 PropsClient client(conn, PROPS_SERVER_PATH, PROPS_SERVER_NAME);
65
66 pthread_t thread;
67 pthread_create(&thread, NULL, test_property_proxy, &client);
68
69 dispatcher.enter();
70
71 return 0;
72}