示例#1
0
/* Move to a new context */
static ConnectionSetup*
connection_setup_new_from_old (GMainContext    *context,
                               ConnectionSetup *old)
{
    GSList *tmp;
    ConnectionSetup *cs;

    g_assert (old->context != context);

    cs = connection_setup_new (context, old->connection);

    tmp = old->ios;
    while (tmp != NULL) {
        IOHandler *handler = tmp->data;

        connection_setup_add_watch (cs, handler->watch);

        tmp = tmp->next;
    }

    tmp = old->timeouts;
    while (tmp != NULL) {
        TimeoutHandler *handler = tmp->data;

        connection_setup_add_timeout (cs, handler->timeout);

        tmp = tmp->next;
    }

    return cs;
}
void
egg_dbus_connect_with_mainloop (DBusConnection *connection, GMainContext *context)
{
	ConnectionSetup *cs;

	if (context == NULL)
		context = g_main_context_default ();
	cs = connection_setup_new (context, connection);
	the_setup = cs;

	if (!dbus_connection_set_watch_functions (connection, add_watch,
	                                          remove_watch, watch_toggled,
	                                          cs, NULL))
		goto nomem;

	if (!dbus_connection_set_timeout_functions (connection, add_timeout,
	                                            remove_timeout, timeout_toggled,
	                                            cs, NULL))
		goto nomem;

	dbus_connection_set_wakeup_main_function (connection, wakeup_main, cs, NULL);

	return;

nomem:
	g_error ("Not enough memory to set up DBusConnection for use with GLib");
}
示例#3
0
/**
 * dbus_server_setup_with_g_main:
 * @server: the server
 * @context: the #GMainContext or #NULL for default
 *
 * Sets the watch and timeout functions of a #DBusServer
 * to integrate the server with the GLib main loop.
 * In most cases the context argument should be #NULL.
 *
 * If called twice for the same context, does nothing the second
 * time. If called once with context A and once with context B,
 * context B replaces context A as the context monitoring the
 * connection.
 */
void
dbus_server_setup (DBusServer   *server,
				   GMainContext *context)
{
    ConnectionSetup *old_setup;
    ConnectionSetup *cs;

    do {
        /* FIXME we never free the slot, so its refcount just keeps growing,
         * which is kind of broken.
         */
        dbus_server_allocate_data_slot (&server_slot);
        if (server_slot < 0)
            break;

        if (context == NULL)
            context = g_main_context_default ();

        cs = NULL;

        old_setup = dbus_server_get_data (server, server_slot);
        if (old_setup != NULL) {
            if (old_setup->context == context)
                return; /* nothing to do */

            cs = connection_setup_new_from_old (context, old_setup);

            /* Nuke the old setup */
            dbus_server_set_data (server, server_slot, NULL, NULL);
            old_setup = NULL;
        }

        if (cs == NULL)
            cs = connection_setup_new (context, NULL);

        if (!dbus_server_set_data (server, server_slot, cs,
                                   (DBusFreeFunction)connection_setup_free))
            break;

        if (!dbus_server_set_watch_functions (server,
                                              add_watch,
                                              remove_watch,
                                              watch_toggled,
                                              cs, NULL))
            break;

        if (!dbus_server_set_timeout_functions (server,
                                                add_timeout,
                                                remove_timeout,
                                                timeout_toggled,
                                                cs, NULL))
            break;

        return;
    } while (0);
    
    g_error ("Not enough memory to set up DBusServer for use with GLib");
}
示例#4
0
/**
 * Sets the watch and timeout functions of a #DBusConnection
 * to integrate the connection with the GUI HID's main loop.
 *
 * @param connection the connection
 */
void
pcb_dbus_connection_setup_with_mainloop (DBusConnection * connection) {
    //ConnectionSetup *cs;
    hidval temp;
    /* FIXME we never free the slot, so its refcount just keeps growing,
     * which is kind of broken.
     */
    //dbus_connection_allocate_data_slot (&connection_slot);
    //if (connection_slot < 0)
    //  goto nomem;
#if 0
    cs = connection_setup_new (connection);

    if (!dbus_connection_set_data (connection, connection_slot, cs,
                                   (DBusFreeFunction) connection_setup_free)) {
        goto nomem;
    }

#endif

    if (!dbus_connection_set_watch_functions (connection,
            watch_add,
            watch_remove,
            watch_toggled, NULL, NULL))
//                                            cs, NULL))
    {
        goto nomem;
    }

    if (!dbus_connection_set_timeout_functions (connection,
            timeout_add,
            timeout_remove,
            timeout_toggled, NULL, NULL))
//                                              cs, NULL))
    {
        goto nomem;
    }

    dbus_connection_set_dispatch_status_function (connection,
            dispatch_status_changed,
            NULL, NULL);
//                                                cs, NULL);
    /* Register a new mainloop hook to mop up any unfinished IO. */
    temp.ptr = (void *)connection;
    gui->add_block_hook (block_hook_cb, temp);
    return;
nomem:
    fprintf (stderr,
             "Not enough memory to set up DBusConnection for use with PCB\n");
}