11055
|
1 /*
|
|
2 * gaim
|
|
3 *
|
|
4 * Gaim is the legal property of its developers, whose names are too numerous
|
|
5 * to list here. Please refer to the COPYRIGHT file distributed with this
|
|
6 * source distribution.
|
|
7 *
|
|
8 * This program is free software; you can redistribute it and/or modify
|
|
9 * it under the terms of the GNU General Public License as published by
|
|
10 * the Free Software Foundation; either version 2 of the License, or
|
|
11 * (at your option) any later version.
|
|
12 *
|
|
13 * This program is distributed in the hope that it will be useful,
|
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16 * GNU General Public License for more details.
|
|
17 *
|
|
18 * You should have received a copy of the GNU General Public License
|
|
19 * along with this program; if not, write to the Free Software
|
|
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
21 *
|
|
22 */
|
|
23
|
|
24 #define DBUS_API_SUBJECT_TO_CHANGE
|
|
25
|
|
26 #include <string.h>
|
|
27 #include <dbus/dbus-glib.h>
|
|
28 #include <dbus/dbus-glib-bindings.h>
|
|
29 #include <glib-object.h>
|
|
30
|
|
31 #include "dbus-gaim.h"
|
|
32 #include "dbus-client-bindings.c"
|
|
33
|
|
34 int
|
|
35 main (int argc, char **argv)
|
|
36 {
|
|
37 DBusGConnection *connection;
|
|
38 DBusGProxy *driver;
|
|
39 DBusGProxy *proxy;
|
|
40 GError *error;
|
|
41 guint32 result;
|
|
42 int i;
|
|
43
|
|
44
|
|
45 g_type_init ();
|
|
46
|
|
47 /* Connecting to dbus */
|
|
48
|
|
49 error = NULL;
|
|
50 connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
|
|
51
|
|
52 if (connection == NULL) {
|
|
53 g_assert (error != NULL);
|
|
54 g_critical("Failed to open connection to dbuso %s.",
|
|
55 error->message);
|
|
56 g_error_free(error);
|
|
57 return 1;
|
|
58 }
|
|
59
|
|
60 g_message("Connected to dbus");
|
|
61
|
|
62 /* Create a proxy object for the "bus driver" */
|
|
63
|
|
64 driver = dbus_g_proxy_new_for_name(connection,
|
|
65 DBUS_SERVICE_DBUS,
|
|
66 DBUS_PATH_DBUS,
|
|
67 DBUS_INTERFACE_DBUS);
|
|
68
|
|
69
|
|
70 /* Activate gaim */
|
|
71
|
|
72 error = NULL;
|
|
73 org_freedesktop_DBus_start_service_by_name(driver, DBUS_SERVICE_GAIM, 0,
|
|
74 &result, &error);
|
|
75
|
|
76 if (error) {
|
|
77 g_critical("Failed to activate the gaim object: %s.",
|
|
78 error->message);
|
|
79 g_clear_error(&error);
|
|
80 return 1;
|
|
81 }
|
|
82
|
|
83 g_message("Gaim object activated");
|
|
84
|
|
85
|
|
86 /* Create a proxy object for gaim */
|
|
87
|
|
88 error = NULL;
|
|
89 proxy = dbus_g_proxy_new_for_name_owner (connection,
|
|
90 DBUS_SERVICE_GAIM,
|
|
91 DBUS_PATH_GAIM,
|
|
92 DBUS_INTERFACE_GAIM,
|
|
93 &error);
|
|
94
|
|
95 if (proxy == NULL) {
|
|
96 g_assert(error);
|
|
97 g_critical("Failed to create proxy for name owner: %s.\n",
|
|
98 error->message);
|
|
99 g_clear_error(&error);
|
|
100 return 1;
|
|
101 }
|
|
102
|
|
103 g_message("Gaim proxy created");
|
|
104
|
|
105 /* Processing commands */
|
|
106
|
|
107 for(i=1; i<argc; i++) {
|
|
108 gboolean success = TRUE;
|
|
109 gchar *command = argv[i];
|
|
110
|
|
111 error = NULL;
|
|
112 g_print("Executing command: %s ...\n", command);
|
|
113
|
|
114 if (!strcmp(command, "quit"))
|
|
115 success = org_gaim_GaimInterface_quit(proxy, &error);
|
|
116 else if (!strcmp(command, "ping"))
|
|
117 success = org_gaim_GaimInterface_ping (proxy, &error);
|
|
118 else if (!strcmp(command, "connect"))
|
|
119 success = org_gaim_GaimInterface_connect_all (proxy, &error);
|
|
120 else
|
|
121 g_print("Unknown command: %s.\n", command);
|
|
122
|
|
123 if (!success)
|
|
124 g_print ("Command %s failed: %s.\n", command,
|
|
125 error->message);
|
|
126
|
|
127 g_clear_error(&error);
|
|
128 }
|
|
129
|
|
130 g_object_unref (G_OBJECT (proxy));
|
|
131 g_object_unref (G_OBJECT (driver));
|
|
132 g_print ("Successfully completed (%s).\n", argv[0]);
|
|
133
|
|
134 return 0;
|
|
135 }
|