Commit 0899278e authored by Dan Williams's avatar Dan Williams
Browse files

2005-02-18 Dan Williams <dcbw@redhat.com>

	* libnm_glib/libnm_glib.[ch]
	  test/libnm_glib_test.c
		- Clean up libnm_glib API a bit, callback is now passed a libnm_glib_ctx
			and its data, and doesn't have to free the callback data anymore


git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@461 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
parent 5e893e0e
2005-02-18 Dan Williams <dcbw@redhat.com>
* libnm_glib/libnm_glib.[ch]
test/libnm_glib_test.c
- Clean up libnm_glib API a bit, callback is now passed a libnm_glib_ctx
and its data, and doesn't have to free the callback data anymore
2005-02-18 Dan Williams <dcbw@redhat.com>
* panel-applet/NMWirelessApplet.c
......
......@@ -31,14 +31,6 @@
#define DBUS_NO_SERVICE_ERROR "org.freedesktop.DBus.Error.ServiceDoesNotExist"
typedef struct libnm_glib_callback
{
gint id;
GMainContext *ctx;
GSourceFunc func;
gpointer user_data;
} libnm_glib_callback;
struct libnm_glib_ctx
{
unsigned char check;
......@@ -57,6 +49,15 @@ struct libnm_glib_ctx
libnm_glib_status nm_status;
};
typedef struct libnm_glib_callback
{
gint id;
GMainContext *gmain_ctx;
libnm_glib_ctx *libnm_glib_ctx;
libnm_glib_callback_func func;
gpointer user_data;
} libnm_glib_callback;
static void libnm_glib_schedule_dbus_watcher (libnm_glib_ctx *ctx);
static DBusConnection * libnm_glib_dbus_init (gpointer *user_data, GMainContext *context);
......@@ -112,21 +113,31 @@ static char *libnm_glib_get_nm_status (DBusConnection *con)
}
static gboolean libnm_glib_callback_helper (gpointer user_data)
{
libnm_glib_callback *cb_data = (libnm_glib_callback *)user_data;
g_return_val_if_fail (cb_data != NULL, FALSE);
g_return_val_if_fail (cb_data->func != NULL, FALSE);
g_return_val_if_fail (cb_data->libnm_glib_ctx != NULL, FALSE);
(*(cb_data->func)) (cb_data->libnm_glib_ctx, cb_data->user_data);
return FALSE; /* never reschedule ourselves */
}
static void libnm_glib_schedule_single_callback (libnm_glib_ctx *ctx, libnm_glib_callback *callback)
{
GSource *source;
libnm_glib_callback_data *data;
g_return_if_fail (ctx != NULL);
g_return_if_fail (callback != NULL);
data = g_malloc0 (sizeof (libnm_glib_callback_data));
data->libnm_ctx = ctx;
data->user_data = callback->user_data;
callback->libnm_glib_ctx = ctx;
source = g_idle_source_new ();
g_source_set_callback (source, callback->func, data, NULL);
g_source_attach (source, callback->ctx);
g_source_set_callback (source, libnm_glib_callback_helper, callback, NULL);
g_source_attach (source, callback->gmain_ctx);
g_source_unref (source);
}
......@@ -148,14 +159,6 @@ static void libnm_glib_call_callbacks (libnm_glib_ctx *ctx)
}
void libnm_glib_callback_data_free (libnm_glib_callback_data *data)
{
g_return_if_fail (data != NULL);
g_free (data);
}
static void libnm_glib_update_status (libnm_glib_ctx *ctx, char *status)
{
libnm_glib_status old_status;
......@@ -528,10 +531,9 @@ libnm_glib_status libnm_glib_get_network_status (const libnm_glib_ctx *ctx)
}
gint libnm_glib_register_callback (libnm_glib_ctx *ctx, GSourceFunc func, gpointer user_data, GMainContext *g_main_ctx)
gint libnm_glib_register_callback (libnm_glib_ctx *ctx, libnm_glib_callback_func func, gpointer user_data, GMainContext *g_main_ctx)
{
libnm_glib_callback *callback = NULL;
libnm_glib_callback_data *data = NULL;
g_return_val_if_fail (ctx != NULL, -1);
g_return_val_if_fail (func != NULL, -1);
......@@ -542,7 +544,8 @@ gint libnm_glib_register_callback (libnm_glib_ctx *ctx, GSourceFunc func, gpoint
callback->id = ctx->callback_id_last++;
callback->func = func;
callback->ctx = g_main_ctx;
callback->gmain_ctx = g_main_ctx;
callback->libnm_glib_ctx = ctx;
callback->user_data = user_data;
g_mutex_lock (ctx->callbacks_lock);
......
......@@ -39,11 +39,8 @@ typedef enum libnm_glib_status
typedef struct libnm_glib_ctx libnm_glib_ctx;
typedef struct libnm_glib_callback_data
{
libnm_glib_ctx *libnm_ctx;
gpointer *user_data;
} libnm_glib_callback_data;
typedef void (*libnm_glib_callback_func) (libnm_glib_ctx *libnm_ctx, gpointer user_data);
libnm_glib_ctx *libnm_glib_init (void);
......@@ -51,8 +48,7 @@ void libnm_glib_shutdown (libnm_glib_ctx *ctx);
libnm_glib_status libnm_glib_get_network_status (const libnm_glib_ctx *ctx);
gint libnm_glib_register_callback (libnm_glib_ctx *ctx, GSourceFunc func, gpointer user_data, GMainContext *g_main_ctx);
void libnm_glib_callback_data_free (libnm_glib_callback_data *data);
gint libnm_glib_register_callback (libnm_glib_ctx *ctx, libnm_glib_callback_func func, gpointer user_data, GMainContext *g_main_ctx);
void libnm_glib_unregister_callback (libnm_glib_ctx *ctx, gint id);
#ifdef __cplusplus
......
......@@ -26,15 +26,13 @@
#include "libnm_glib.h"
gboolean status_printer (gpointer user_data)
void status_printer (libnm_glib_ctx *ctx, gpointer user_data)
{
libnm_glib_callback_data *data = (libnm_glib_callback_data *)user_data;
libnm_glib_status status;
g_return_val_if_fail (data != NULL, FALSE);
g_return_val_if_fail (data->libnm_ctx != NULL, FALSE);
g_return_if_fail (ctx != NULL);
status = libnm_glib_get_network_status (data->libnm_ctx);
status = libnm_glib_get_network_status (ctx);
switch (status)
{
case LIBNM_NO_DBUS:
......@@ -56,8 +54,6 @@ gboolean status_printer (gpointer user_data)
fprintf (stderr, "Status: unknown\n");
break;
}
return FALSE;
}
......
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