summaryrefslogtreecommitdiff
path: root/examples/properties/propsgs-server.cpp
blob: 56ba248a3eb70531dee68fc5350555802951df49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "propsgs-server.h"
#include <iostream>
#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::cout << "'Message' has been changed\n";

    std::string msg = value;
    this->MessageChanged(msg);
  }
  if (property == "Data")
  {
    std::cout << "'Data' has been changed\n";

    double data = value;
    this->DataChanged(data);
  }
}

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;
}