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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
#include "config.h"
#include <dbus/dbus-glib.h>
#include "browser-service/browser-service.h"
#include "browser-service/channel-proxy.h"
static void
request_started_cb (DBusGProxy *channel,
const char *request)
{
g_print ("%s: %s\n", G_STRFUNC, request);
}
static void
request_stopped_cb (DBusGProxy *channel,
const char *request,
guint status,
gpointer user_data)
{
GMainLoop *loop = user_data;
g_print ("%s: %s: status=%d\n", G_STRFUNC, request, status);
g_main_loop_quit (loop);
}
static void
data_available_cb (DBusGProxy *channel,
const char *request,
GArray *data)
{
g_print ("%s: %s: count=%d\n", G_STRFUNC, request, data->len);
g_print ("%s...\n", g_strndup(data->data, MIN (data->len, 60)));
}
int
main (int argc,
char **argv)
{
DBusGConnection *session = NULL;
DBusGProxy *service = NULL;
DBusGProxy *channel = NULL;
GMainLoop *loop = NULL;
GError *error = NULL;
char *path = NULL;
g_type_init ();
loop = g_main_loop_new (NULL, FALSE);
session = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
if (!session)
goto OUT;
service = gruschler_browser_service_new (session, &error);
if (!service)
goto OUT;
g_print ("service name: %s\n", dbus_g_proxy_get_bus_name (service));
channel = gruschler_browser_service_new_channel (service,
"http://www.facebook.com/home.php",
&error);
g_print ("channel path: %s\n", dbus_g_proxy_get_path (channel));
dbus_g_proxy_connect_signal (channel, "RequestStarted",
G_CALLBACK (request_started_cb), loop, NULL);
dbus_g_proxy_connect_signal (channel, "RequestStopped",
G_CALLBACK (request_stopped_cb), loop, NULL);
dbus_g_proxy_connect_signal (channel, "DataAvailable",
G_CALLBACK (data_available_cb), loop, NULL);
if (!gruschler_channel_proxy_open (channel, &error))
goto OUT;
g_main_loop_run (loop);
OUT:
if (error)
{
g_printerr ("%s(%d): %s\n",
g_quark_to_string (error->domain),
error->code, error->message);
g_error_free (error);
}
if (channel)
g_object_unref (channel);
if (service)
g_object_unref (service);
if (loop)
g_main_loop_unref (loop);
g_free (path);
return (error ? 1 : 0);
}
|