Commit 79d03f94 authored by Havoc Pennington's avatar Havoc Pennington

2003-10-02 Havoc Pennington <hp@pobox.com>

	* glib/dbus-gproxy.c (dbus_gproxy_call_no_reply): rename from
	dbus_gproxy_oneway_call

	* glib/dbus-gmain.c (dbus_connection_setup_with_g_main)
	(dbus_server_setup_with_g_main): fix to allow calling them more
	than once on the same args
	(dbus_bus_get_with_g_main): new function
parent dbffb387
2003-10-02 Havoc Pennington <hp@pobox.com>
* glib/dbus-gproxy.c (dbus_gproxy_call_no_reply): rename from
dbus_gproxy_oneway_call
* glib/dbus-gmain.c (dbus_connection_setup_with_g_main)
(dbus_server_setup_with_g_main): fix to allow calling them more
than once on the same args
(dbus_bus_get_with_g_main): new function
2003-10-02 Havoc Pennington <hp@redhat.com>
* doc/dbus-tutorial.xml: write some stuff
......
......@@ -51,11 +51,13 @@ typedef enum
void dbus_set_g_error (GError **gerror,
DBusError *derror);
void dbus_g_thread_init (void);
void dbus_connection_setup_with_g_main (DBusConnection *connection,
GMainContext *context);
void dbus_server_setup_with_g_main (DBusServer *server,
GMainContext *context);
void dbus_g_thread_init (void);
void dbus_connection_setup_with_g_main (DBusConnection *connection,
GMainContext *context);
void dbus_server_setup_with_g_main (DBusServer *server,
GMainContext *context);
DBusConnection* dbus_bus_get_with_g_main (DBusBusType type,
GError **error);
typedef struct DBusGObjectInfo DBusGObjectInfo;
typedef struct DBusGMethodInfo DBusGMethodInfo;
......@@ -137,7 +139,7 @@ gboolean dbus_gproxy_end_call (DBusGProxy *pr
GError **error,
int first_arg_type,
...);
void dbus_gproxy_oneway_call (DBusGProxy *proxy,
void dbus_gproxy_call_no_reply (DBusGProxy *proxy,
const char *method,
int first_arg_type,
...);
......
......@@ -443,6 +443,11 @@ create_source (void *connection_or_server,
* Pass in #NULL for the #GMainContext unless you're
* doing something specialized.
*
* 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.
*
* @param connection the connection
* @param context the #GMainContext or #NULL for default context
*/
......@@ -451,7 +456,29 @@ dbus_connection_setup_with_g_main (DBusConnection *connection,
GMainContext *context)
{
GSource *source;
/* 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;
/* So we can test for equality below */
if (context == NULL)
context = g_main_context_default ();
source = dbus_connection_get_data (connection, connection_slot);
if (source != NULL)
{
if (source->context == context)
return; /* nothing to do */
/* Remove the previous source and move to a new context */
dbus_connection_set_data (connection, connection_slot, NULL, NULL);
source = NULL;
}
source = create_source (connection, &dbus_connection_funcs, context);
if (!dbus_connection_set_watch_functions (connection,
......@@ -474,13 +501,6 @@ dbus_connection_setup_with_g_main (DBusConnection *connection,
g_source_attach (source, context);
/* 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 (!dbus_connection_set_data (connection, connection_slot, source,
(DBusFreeFunction)free_source))
goto nomem;
......@@ -496,6 +516,11 @@ dbus_connection_setup_with_g_main (DBusConnection *connection,
* 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.
*
* @param server the server
* @param context the #GMainContext or #NULL for default
*/
......@@ -505,6 +530,25 @@ dbus_server_setup_with_g_main (DBusServer *server,
{
GSource *source;
dbus_server_allocate_data_slot (&server_slot);
if (server_slot < 0)
goto nomem;
/* So we can test for equality below */
if (context == NULL)
context = g_main_context_default ();
source = dbus_server_get_data (server, server_slot);
if (source != NULL)
{
if (source->context == context)
return; /* nothing to do */
/* Remove the previous source and move to a new context */
dbus_server_set_data (server, server_slot, NULL, NULL);
source = NULL;
}
source = create_source (server, &dbus_server_funcs, context);
dbus_server_set_watch_functions (server,
......@@ -521,13 +565,6 @@ dbus_server_setup_with_g_main (DBusServer *server,
g_source_attach (source, context);
/* 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)
goto nomem;
if (!dbus_server_set_data (server, server_slot, source,
(DBusFreeFunction)free_source))
goto nomem;
......@@ -538,6 +575,40 @@ dbus_server_setup_with_g_main (DBusServer *server,
g_error ("Not enough memory to set up DBusServer for use with GLib");
}
/**
* Calls dbus_bus_get() then calls dbus_connection_setup_with_g_main()
* on the result and returns the bus connection.
*
* @param type bus type
* @param error address where an error can be returned.
* @returns a DBusConnection
*/
DBusConnection*
dbus_bus_get_with_g_main (DBusBusType type,
GError **error)
{
DBusConnection *connection;
DBusError derror;
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
dbus_error_init (&derror);
connection = dbus_bus_get (type, &derror);
if (connection == NULL)
{
dbus_set_g_error (error, &derror);
dbus_error_free (&derror);
}
else
{
/* does nothing if it's already been done */
dbus_connection_setup_with_g_main (connection, NULL);
}
return connection;
}
/**
* The implementation of DBUS_GERROR error domain. See documentation
* for GError in GLib reference manual.
......
......@@ -1089,10 +1089,10 @@ dbus_gproxy_end_call (DBusGProxy *proxy,
* @param first_arg_type type of the first argument
*/
void
dbus_gproxy_oneway_call (DBusGProxy *proxy,
const char *method,
int first_arg_type,
...)
dbus_gproxy_call_no_reply (DBusGProxy *proxy,
const char *method,
int first_arg_type,
...)
{
DBusMessage *message;
va_list args;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment