summaryrefslogtreecommitdiffstats
path: root/test/echo-server.c
blob: 27e10e72c28a40665e77dbcac435cf217f7899aa (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
#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");

  dbus_connection_set_max_live_messages_size (new_connection,
                                              10);
  
  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;
}