summaryrefslogtreecommitdiffstats
path: root/test/echo-server.c
blob: 9cfcd307bf6d1331d14667d33b84b63533ef4481 (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
#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;
  DBusError error;

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

  dbus_error_init (&error);
  server = dbus_server_listen (argv[1], &error);
  if (server == NULL)
    {
      fprintf (stderr, "Failed to start server on %s: %s\n",
               argv[1], error.message);
      dbus_error_free (&error);
      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;
}