summaryrefslogtreecommitdiff
path: root/examples/ecore/dbus_ecore.cpp
blob: c97e22c587bc95f9630750419e1154293edbebd6 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "dbus_ecore.h"

#include <xml.h>
#include <iostream>
#include <vector>

using namespace std;

static const char *DBUS_SERVER_NAME = "org.freedesktop.DBus";
static const char *DBUS_SERVER_PATH = "/org/freedesktop/DBus";

typedef vector <string> Names;

DBusBrowser::DBusBrowser(::DBus::Connection &conn)
  : ::DBus::ObjectProxy(conn, DBUS_SERVER_PATH, DBUS_SERVER_NAME)
{
  typedef std::vector< std::string > Names;

  Names names = ListNames();

  for (Names::iterator it = names.begin(); it != names.end(); ++it)
  {
    cout << *it << endl;
  }
}

void DBusBrowser::NameOwnerChanged(
  const std::string &name, const std::string &old_owner, const std::string &new_owner)
{
  cout << name << ": " << old_owner << " -> " << new_owner << endl;
}

void DBusBrowser::NameLost(const std::string &name)
{
  cout << name << " lost" << endl;
}

void DBusBrowser::NameAcquired(const std::string &name)
{
  cout << name << " acquired" << endl;
}

DBus::Ecore::BusDispatcher dispatcher;

void niam(int sig)
{
  ecore_main_loop_quit();
}

int main(int argc, char *argv[])
{
  signal(SIGTERM, niam);
  signal(SIGINT, niam);

  ecore_init();

  DBus::default_dispatcher = &dispatcher;

  DBus::Connection conn = DBus::Connection::SessionBus();

  DBusBrowser browser(conn);

  ecore_main_loop_begin();
  ecore_shutdown();

  return 0;
}