summaryrefslogtreecommitdiffstats
path: root/test/echo-server.c
blob: 99f97ffdae96492e8b851a53d4abfea55310ba03 (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
#include <dbus/dbus.h>
#include <stdio.h>
#include "watch.h"

static void
new_connection_callback (DBusServer     *server,
                         DBusConnection *new_connection,
                         void           *data)
{
  printf ("Got new connection\n");

  setup_connection (new_connection);
}

int
main (int    argc,
      char **argv)
{
  DBusServer *server;
  DBusResultCode result;

  if (argc < 2)
    {
      fprintf (stderr, "Give the server address as an argument\n");
      return 1;
    }

  server = dbus_server_listen (argv[1], &result);
  if (server == NULL)
    {
      fprintf (stderr, "Failed to start server on %s: %s\n",
               argv[1], dbus_result_to_string (result));
      return 1;
    }

  setup_server (server);

  dbus_server_set_new_connection_function (server,
                                           new_connection_callback,
                                           NULL, NULL);
  
  do_mainloop ();

  dbus_server_disconnect (server);
  dbus_server_unref (server);
  
  return 0;
}