2005-06-17 Colin Walters <walters@verbum.org>
[platform/upstream/dbus.git] / tools / print-introspect.c
1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* gather-introspect.c  Dump introspection data from service to stdout
3  *
4  * Copyright (C) 2005  Red Hat, Inc.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25
26 #include <dbus/dbus-glib.h>
27
28 static void
29 usage (char *name, int ecode)
30 {
31   fprintf (stderr, "Usage: %s <service> <destination object path>\n", name);
32   exit (ecode);
33 }
34
35 int
36 main (int argc, char *argv[])
37 {
38   DBusGConnection *connection;
39   DBusGProxy *proxy;
40   DBusGPendingCall *call;
41   GError *error;
42   const char *service;
43   const char *path;
44   char *introspect_data;
45   
46   if (argc != 3)
47     usage (argv[0], 1);
48
49   service = argv[1];
50   path = argv[2];
51
52   g_type_init ();
53
54   error = NULL;
55   connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
56   if (connection == NULL)
57     {
58       fprintf (stderr, "Failed to open connection to session bus: %s\n",
59                error->message);
60       g_clear_error (&error);
61       exit (1);
62     }
63
64   proxy = dbus_g_proxy_new_for_name (connection,
65                                      service, path,
66                                      DBUS_INTERFACE_INTROSPECTABLE);
67   call = dbus_g_proxy_begin_call (proxy, "Introspect", G_TYPE_INVALID);
68   if (!dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_STRING,
69                               &introspect_data, G_TYPE_INVALID))
70     {
71       fprintf (stderr, "Failed to get introspection data: %s\n",
72                error->message);
73       g_clear_error (&error);
74       exit (1);
75     }
76       
77   printf ("%s", introspect_data);
78   g_free (introspect_data);
79
80   g_object_unref (proxy);
81
82   exit (0);
83 }