blob: 56ba248a3eb70531dee68fc5350555802951df49 [file] [log] [blame]
Emeric Vigier2f625822012-08-06 11:09:52 -04001#include "propsgs-server.h"
2#include <iostream>
3#include <signal.h>
4
5static const char *PROPS_SERVER_NAME = "org.freedesktop.DBus.Examples.Properties";
6static const char *PROPS_SERVER_PATH = "/org/freedesktop/DBus/Examples/Properties";
7
8PropsServer::PropsServer(DBus::Connection &connection)
9 : DBus::ObjectAdaptor(connection, PROPS_SERVER_PATH)
10{
11 Version = 1;
12 Message = "default message";
13}
14
15void PropsServer::on_set_property
16(DBus::InterfaceAdaptor &interface, const std::string &property, const DBus::Variant &value)
17{
18 if (property == "Message")
19 {
20 std::cout << "'Message' has been changed\n";
21
22 std::string msg = value;
23 this->MessageChanged(msg);
24 }
25 if (property == "Data")
26 {
27 std::cout << "'Data' has been changed\n";
28
29 double data = value;
30 this->DataChanged(data);
31 }
32}
33
34DBus::BusDispatcher dispatcher;
35
36void niam(int sig)
37{
38 dispatcher.leave();
39}
40
41int main()
42{
43 signal(SIGTERM, niam);
44 signal(SIGINT, niam);
45
46 DBus::default_dispatcher = &dispatcher;
47
48 DBus::Connection conn = DBus::Connection::SessionBus();
49 conn.request_name(PROPS_SERVER_NAME);
50
51 PropsServer server(conn);
52
53 dispatcher.enter();
54
55 return 0;
56}