mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-29 12:40:11 +01:00
shared: add nm_g_*_source_new() and nm_g_source_attach() helpers
Small utilities to make is more convenient to create and attach GSource instances.
This commit is contained in:
parent
9c5741ccd2
commit
c40ff42ae6
2 changed files with 76 additions and 0 deletions
|
|
@ -11,6 +11,7 @@
|
|||
#include <poll.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <glib-unix.h>
|
||||
|
||||
#include "nm-errno.h"
|
||||
|
||||
|
|
@ -3388,3 +3389,53 @@ nm_utils_parse_debug_string (const char *string,
|
|||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
GSource *
|
||||
nm_g_idle_source_new (int priority,
|
||||
GSourceFunc func,
|
||||
gpointer user_data,
|
||||
GDestroyNotify destroy_notify)
|
||||
{
|
||||
GSource *source;
|
||||
|
||||
source = g_idle_source_new ();
|
||||
if (priority != G_PRIORITY_DEFAULT)
|
||||
g_source_set_priority (source, priority);
|
||||
g_source_set_callback (source, func, user_data, destroy_notify);
|
||||
return source;
|
||||
}
|
||||
|
||||
GSource *
|
||||
nm_g_timeout_source_new (guint timeout_ms,
|
||||
int priority,
|
||||
GSourceFunc func,
|
||||
gpointer user_data,
|
||||
GDestroyNotify destroy_notify)
|
||||
{
|
||||
GSource *source;
|
||||
|
||||
source = g_timeout_source_new (timeout_ms);
|
||||
if (priority != G_PRIORITY_DEFAULT)
|
||||
g_source_set_priority (source, priority);
|
||||
g_source_set_callback (source, func, user_data, destroy_notify);
|
||||
return source;
|
||||
}
|
||||
|
||||
GSource *
|
||||
nm_g_unix_signal_source_new (int signum,
|
||||
int priority,
|
||||
GSourceFunc handler,
|
||||
gpointer user_data,
|
||||
GDestroyNotify notify)
|
||||
{
|
||||
GSource *source;
|
||||
|
||||
source = g_unix_signal_source_new (signum);
|
||||
|
||||
if (priority != G_PRIORITY_DEFAULT)
|
||||
g_source_set_priority (source, priority);
|
||||
g_source_set_callback (source, handler, user_data, notify);
|
||||
return source;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -931,6 +931,31 @@ NM_AUTO_DEFINE_FCN0 (GSource *, _nm_auto_destroy_and_unref_gsource, nm_g_source_
|
|||
NM_AUTO_DEFINE_FCN0 (GMainContext *, _nm_auto_pop_gmaincontext, g_main_context_pop_thread_default)
|
||||
#define nm_auto_pop_gmaincontext nm_auto (_nm_auto_pop_gmaincontext)
|
||||
|
||||
GSource *nm_g_idle_source_new (int priority,
|
||||
GSourceFunc func,
|
||||
gpointer user_data,
|
||||
GDestroyNotify destroy_notify);
|
||||
|
||||
GSource *nm_g_timeout_source_new (guint timeout_ms,
|
||||
int priority,
|
||||
GSourceFunc func,
|
||||
gpointer user_data,
|
||||
GDestroyNotify destroy_notify);
|
||||
|
||||
GSource *nm_g_unix_signal_source_new (int signum,
|
||||
int priority,
|
||||
GSourceFunc handler,
|
||||
gpointer user_data,
|
||||
GDestroyNotify notify);
|
||||
|
||||
static inline GSource *
|
||||
nm_g_source_attach (GSource *source,
|
||||
GMainContext *context)
|
||||
{
|
||||
g_source_attach (source, context);
|
||||
return source;
|
||||
}
|
||||
|
||||
static inline GMainContext *
|
||||
nm_g_main_context_push_thread_default (GMainContext *context)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue