mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-27 22:46:15 +01:00
gsourceclosure: Add support for GUnixSignalWatchSource and GUnixFDSource
https://bugzilla.gnome.org/show_bug.cgi?id=701511
This commit is contained in:
parent
1da47d5ede
commit
8a89926532
@ -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);
|
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:
|
* g_unix_fd_source_new:
|
||||||
@ -334,13 +337,10 @@ GSource *
|
|||||||
g_unix_fd_source_new (gint fd,
|
g_unix_fd_source_new (gint fd,
|
||||||
GIOCondition condition)
|
GIOCondition condition)
|
||||||
{
|
{
|
||||||
static GSourceFuncs source_funcs = {
|
|
||||||
NULL, NULL, g_unix_fd_source_dispatch, NULL
|
|
||||||
};
|
|
||||||
GUnixFDSource *fd_source;
|
GUnixFDSource *fd_source;
|
||||||
GSource *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 = (GUnixFDSource *) source;
|
||||||
|
|
||||||
fd_source->fd = fd;
|
fd_source->fd = fd;
|
||||||
|
@ -434,7 +434,7 @@ G_LOCK_DEFINE_STATIC (unix_signal_lock);
|
|||||||
static GSList *unix_signal_watches;
|
static GSList *unix_signal_watches;
|
||||||
static GSList *unix_child_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_prepare,
|
||||||
g_unix_signal_watch_check,
|
g_unix_signal_watch_check,
|
||||||
|
@ -605,6 +605,10 @@ void g_main_context_invoke (GMainContext *context,
|
|||||||
GLIB_VAR GSourceFuncs g_timeout_funcs;
|
GLIB_VAR GSourceFuncs g_timeout_funcs;
|
||||||
GLIB_VAR GSourceFuncs g_child_watch_funcs;
|
GLIB_VAR GSourceFuncs g_child_watch_funcs;
|
||||||
GLIB_VAR GSourceFuncs g_idle_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
|
G_END_DECLS
|
||||||
|
|
||||||
|
@ -25,6 +25,9 @@
|
|||||||
#include "gmarshal.h"
|
#include "gmarshal.h"
|
||||||
#include "gvalue.h"
|
#include "gvalue.h"
|
||||||
#include "gvaluetypes.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)
|
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;
|
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 (¶ms[0], G_TYPE_INT);
|
||||||
|
g_value_set_int (¶ms[0], fd);
|
||||||
|
|
||||||
|
g_value_init (¶ms[1], G_TYPE_IO_CONDITION);
|
||||||
|
g_value_set_flags (¶ms[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 (¶ms[0]);
|
||||||
|
g_value_unset (¶ms[1]);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
source_closure_callback (gpointer data)
|
source_closure_callback (gpointer data)
|
||||||
{
|
{
|
||||||
@ -105,7 +139,14 @@ closure_callback_get (gpointer cb_data,
|
|||||||
{
|
{
|
||||||
if (source->source_funcs == &g_io_watch_funcs)
|
if (source->source_funcs == &g_io_watch_funcs)
|
||||||
closure_callback = (GSourceFunc)io_watch_closure_callback;
|
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 ||
|
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)
|
source->source_funcs == &g_idle_funcs)
|
||||||
closure_callback = source_closure_callback;
|
closure_callback = source_closure_callback;
|
||||||
}
|
}
|
||||||
@ -146,6 +187,10 @@ g_source_set_closure (GSource *source,
|
|||||||
g_return_if_fail (closure != NULL);
|
g_return_if_fail (closure != NULL);
|
||||||
|
|
||||||
if (!source->source_funcs->closure_callback &&
|
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_io_watch_funcs &&
|
||||||
source->source_funcs != &g_timeout_funcs &&
|
source->source_funcs != &g_timeout_funcs &&
|
||||||
source->source_funcs != &g_idle_funcs)
|
source->source_funcs != &g_idle_funcs)
|
||||||
|
Loading…
Reference in New Issue
Block a user