diff options
author | Thomas Haller <thaller@redhat.com> | 2019-11-13 17:46:14 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2019-11-22 15:32:52 +0100 |
commit | c40ff42ae6a5282bed5cbe59ff86bf146ae71ffa (patch) | |
tree | 2c8ca267ba8187b5b279f8d0f468c28219174cd6 | |
parent | 9c5741ccd2b8d52df8d299ef53adc4b727654949 (diff) | |
download | NetworkManager-c40ff42ae6a5282bed5cbe59ff86bf146ae71ffa.tar.gz |
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.
-rw-r--r-- | shared/nm-glib-aux/nm-shared-utils.c | 51 | ||||
-rw-r--r-- | shared/nm-glib-aux/nm-shared-utils.h | 25 |
2 files changed, 76 insertions, 0 deletions
diff --git a/shared/nm-glib-aux/nm-shared-utils.c b/shared/nm-glib-aux/nm-shared-utils.c index 60f1bfaf81..6b290b4bc9 100644 --- a/shared/nm-glib-aux/nm-shared-utils.c +++ b/shared/nm-glib-aux/nm-shared-utils.c @@ -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; +} diff --git a/shared/nm-glib-aux/nm-shared-utils.h b/shared/nm-glib-aux/nm-shared-utils.h index 5f1edcb219..d04f99f666 100644 --- a/shared/nm-glib-aux/nm-shared-utils.h +++ b/shared/nm-glib-aux/nm-shared-utils.h @@ -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) { |