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
|
11067
|
24 /* Do not use this program. Use gaim-send instead. */
|
|
25
|
11055
|
26 #define DBUS_API_SUBJECT_TO_CHANGE
|
|
27
|
|
28 #include <string.h>
|
|
29 #include <dbus/dbus-glib.h>
|
|
30 #include <dbus/dbus-glib-bindings.h>
|
|
31 #include <glib-object.h>
|
|
32
|
|
33 #include "dbus-gaim.h"
|
11205
|
34 /* #include "dbus-client-bindings.c" */
|
11055
|
35
|
|
36 int
|
|
37 main (int argc, char **argv)
|
|
38 {
|
|
39 DBusGConnection *connection;
|
|
40 DBusGProxy *driver;
|
|
41 DBusGProxy *proxy;
|
|
42 GError *error;
|
|
43 guint32 result;
|
|
44 int i;
|
|
45
|
|
46
|
|
47 g_type_init ();
|
|
48
|
|
49 /* Connecting to dbus */
|
|
50
|
|
51 error = NULL;
|
|
52 connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
|
|
53
|
|
54 if (connection == NULL) {
|
|
55 g_assert (error != NULL);
|
|
56 g_critical("Failed to open connection to dbuso %s.",
|
|
57 error->message);
|
|
58 g_error_free(error);
|
|
59 return 1;
|
|
60 }
|
|
61
|
|
62 g_message("Connected to dbus");
|
|
63
|
|
64 /* Create a proxy object for the "bus driver" */
|
|
65
|
|
66 driver = dbus_g_proxy_new_for_name(connection,
|
|
67 DBUS_SERVICE_DBUS,
|
|
68 DBUS_PATH_DBUS,
|
|
69 DBUS_INTERFACE_DBUS);
|
|
70
|
|
71
|
|
72 /* Activate gaim */
|
|
73
|
|
74 error = NULL;
|
|
75 org_freedesktop_DBus_start_service_by_name(driver, DBUS_SERVICE_GAIM, 0,
|
|
76 &result, &error);
|
|
77
|
|
78 if (error) {
|
|
79 g_critical("Failed to activate the gaim object: %s.",
|
|
80 error->message);
|
|
81 g_clear_error(&error);
|
|
82 return 1;
|
|
83 }
|
|
84
|
|
85 g_message("Gaim object activated");
|
|
86
|
|
87
|
|
88 /* Create a proxy object for gaim */
|
|
89
|
|
90 error = NULL;
|
|
91 proxy = dbus_g_proxy_new_for_name_owner (connection,
|
|
92 DBUS_SERVICE_GAIM,
|
|
93 DBUS_PATH_GAIM,
|
|
94 DBUS_INTERFACE_GAIM,
|
|
95 &error);
|
|
96
|
|
97 if (proxy == NULL) {
|
|
98 g_assert(error);
|
|
99 g_critical("Failed to create proxy for name owner: %s.\n",
|
|
100 error->message);
|
|
101 g_clear_error(&error);
|
|
102 return 1;
|
|
103 }
|
|
104
|
|
105 g_message("Gaim proxy created");
|
|
106
|
|
107 /* Processing commands */
|
|
108
|
|
109 for(i=1; i<argc; i++) {
|
|
110 gboolean success = TRUE;
|
|
111 gchar *command = argv[i];
|
|
112
|
|
113 error = NULL;
|
|
114 g_print("Executing command: %s ...\n", command);
|
|
115
|
|
116 if (!strcmp(command, "quit"))
|
|
117 success = org_gaim_GaimInterface_quit(proxy, &error);
|
|
118 else if (!strcmp(command, "ping"))
|
|
119 success = org_gaim_GaimInterface_ping (proxy, &error);
|
|
120 else if (!strcmp(command, "connect"))
|
|
121 success = org_gaim_GaimInterface_connect_all (proxy, &error);
|
|
122 else
|
|
123 g_print("Unknown command: %s.\n", command);
|
|
124
|
|
125 if (!success)
|
|
126 g_print ("Command %s failed: %s.\n", command,
|
|
127 error->message);
|
|
128
|
|
129 g_clear_error(&error);
|
|
130 }
|
|
131
|
|
132 g_object_unref (G_OBJECT (proxy));
|
|
133 g_object_unref (G_OBJECT (driver));
|
|
134 g_print ("Successfully completed (%s).\n", argv[0]);
|
|
135
|
|
136 return 0;
|
|
137 }
|