gsourceclosure: Add support for GUnixSignalWatchSource and GUnixFDSource

https://bugzilla.gnome.org/show_bug.cgi?id=701511
This commit is contained in:
Dan Winship 2013-06-01 15:23:15 -03:00
parent 1da47d5ede
commit 8a89926532
4 changed files with 54 additions and 5 deletions

View File

@ -315,6 +315,9 @@ g_unix_fd_source_dispatch (GSource *source,
return (* func) (fd_source->fd, g_source_query_unix_fd (source, fd_source->tag), user_data);
}
GSourceFuncs g_unix_fd_source_funcs = {
NULL, NULL, g_unix_fd_source_dispatch, NULL
};
/**
* g_unix_fd_source_new:
@ -334,13 +337,10 @@ GSource *
g_unix_fd_source_new (gint fd,
GIOCondition condition)
{
static GSourceFuncs source_funcs = {
NULL, NULL, g_unix_fd_source_dispatch, NULL
};
GUnixFDSource *fd_source;
GSource *source;
source = g_source_new (&source_funcs, sizeof (GUnixFDSource));
source = g_source_new (&g_unix_fd_source_funcs, sizeof (GUnixFDSource));
fd_source = (GUnixFDSource *) source;
fd_source->fd = fd;

View File

@ -434,7 +434,7 @@ G_LOCK_DEFINE_STATIC (unix_signal_lock);
static GSList *unix_signal_watches;
static GSList *unix_child_watches;
static GSourceFuncs g_unix_signal_funcs =
GSourceFuncs g_unix_signal_funcs =
{
g_unix_signal_watch_prepare,
g_unix_signal_watch_check,

View File

@ -605,6 +605,10 @@ void g_main_context_invoke (GMainContext *context,
GLIB_VAR GSourceFuncs g_timeout_funcs;
GLIB_VAR GSourceFuncs g_child_watch_funcs;
GLIB_VAR GSourceFuncs g_idle_funcs;
#ifdef G_OS_UNIX
GLIB_VAR GSourceFuncs g_unix_signal_funcs;
GLIB_VAR GSourceFuncs g_unix_fd_source_funcs;
#endif
G_END_DECLS

View File

@ -25,6 +25,9 @@
#include "gmarshal.h"
#include "gvalue.h"
#include "gvaluetypes.h"
#ifdef G_OS_UNIX
#include "glib-unix.h"
#endif
G_DEFINE_BOXED_TYPE (GIOChannel, g_io_channel, g_io_channel_ref, g_io_channel_unref)
@ -76,6 +79,37 @@ io_watch_closure_callback (GIOChannel *channel,
return result;
}
#ifdef G_OS_UNIX
static gboolean
g_unix_fd_source_closure_callback (int fd,
GIOCondition condition,
gpointer data)
{
GClosure *closure = data;
GValue params[2] = { G_VALUE_INIT, G_VALUE_INIT };
GValue result_value = G_VALUE_INIT;
gboolean result;
g_value_init (&result_value, G_TYPE_BOOLEAN);
g_value_init (&params[0], G_TYPE_INT);
g_value_set_int (&params[0], fd);
g_value_init (&params[1], G_TYPE_IO_CONDITION);
g_value_set_flags (&params[1], condition);
g_closure_invoke (closure, &result_value, 2, params, NULL);
result = g_value_get_boolean (&result_value);
g_value_unset (&result_value);
g_value_unset (&params[0]);
g_value_unset (&params[1]);
return result;
}
#endif
static gboolean
source_closure_callback (gpointer data)
{
@ -105,7 +139,14 @@ closure_callback_get (gpointer cb_data,
{
if (source->source_funcs == &g_io_watch_funcs)
closure_callback = (GSourceFunc)io_watch_closure_callback;
#ifdef G_OS_UNIX
else if (source->source_funcs == &g_unix_fd_source_funcs)
closure_callback = (GSourceFunc)g_unix_fd_source_closure_callback;
#endif
else if (source->source_funcs == &g_timeout_funcs ||
#ifdef G_OS_UNIX
source->source_funcs == &g_unix_signal_funcs ||
#endif
source->source_funcs == &g_idle_funcs)
closure_callback = source_closure_callback;
}
@ -146,6 +187,10 @@ g_source_set_closure (GSource *source,
g_return_if_fail (closure != NULL);
if (!source->source_funcs->closure_callback &&
#ifdef G_OS_UNIX
source->source_funcs != &g_unix_fd_source_funcs &&
source->source_funcs != &g_unix_signal_funcs &&
#endif
source->source_funcs != &g_io_watch_funcs &&
source->source_funcs != &g_timeout_funcs &&
source->source_funcs != &g_idle_funcs)