#include "config.h" #include #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); }