Skip to content
Snippets Groups Projects
Commit a10ee91b authored by George Kiagiadakis's avatar George Kiagiadakis
Browse files

core: add idle & timeout method variants that take a GClosure

parent 6501307d
No related branches found
No related tags found
No related merge requests found
......@@ -495,6 +495,34 @@ wp_core_idle_add (WpCore * self, GSource **source, GSourceFunc function,
*source = g_source_ref (s);
}
/**
* wp_core_idle_add_closure: (rename-to wp_core_idle_add)
* @self: the core
* @source: (out) (optional): the source
* @closure: the closure to invoke
*
* Adds an idle callback to be called in the same #GMainContext as the
* one used by this core.
*
* This is the same as wp_core_idle_add(), but it allows you to specify
* a #GClosure instead of a C callback.
*/
void
wp_core_idle_add_closure (WpCore * self, GSource **source, GClosure * closure)
{
g_autoptr (GSource) s = NULL;
g_return_if_fail (WP_IS_CORE (self));
g_return_if_fail (closure != NULL);
s = g_idle_source_new ();
g_source_set_closure (s, closure);
g_source_attach (s, self->context);
if (source)
*source = g_source_ref (s);
}
/**
* wp_core_timeout_add:
* @self: the core
......@@ -513,7 +541,7 @@ wp_core_idle_add (WpCore * self, GSource **source, GSourceFunc function,
* used by this core instead of the default context.
*/
void
wp_core_timeout_add (WpCore * self, GSource **source, guint64 timeout_ms,
wp_core_timeout_add (WpCore * self, GSource **source, guint timeout_ms,
GSourceFunc function, gpointer data, GDestroyNotify destroy)
{
g_autoptr (GSource) s = NULL;
......@@ -528,6 +556,36 @@ wp_core_timeout_add (WpCore * self, GSource **source, guint64 timeout_ms,
*source = g_source_ref (s);
}
/**
* wp_core_timeout_add_closure: (rename-to wp_core_timeout_add)
* @self: the core
* @source: (out) (optional): the source
* @timeout_ms: the timeout in milliseconds
* @closure: the closure to invoke
*
* Adds a timeout callback to be called at regular intervals in the same
* #GMainContext as the one used by this core.
*
* This is the same as wp_core_timeout_add(), but it allows you to specify
* a #GClosure instead of a C callback.
*/
void
wp_core_timeout_add_closure (WpCore * self, GSource **source, guint timeout_ms,
GClosure * closure)
{
g_autoptr (GSource) s = NULL;
g_return_if_fail (WP_IS_CORE (self));
g_return_if_fail (closure != NULL);
s = g_timeout_source_new (timeout_ms);
g_source_set_closure (s, closure);
g_source_attach (s, self->context);
if (source)
*source = g_source_ref (s);
}
/**
* wp_core_sync:
* @self: the core
......
......@@ -54,9 +54,17 @@ void wp_core_idle_add (WpCore * self, GSource **source, GSourceFunc function,
gpointer data, GDestroyNotify destroy);
WP_API
void wp_core_timeout_add (WpCore * self, GSource **source, guint64 timeout_ms,
void wp_core_idle_add_closure (WpCore * self, GSource **source,
GClosure * closure);
WP_API
void wp_core_timeout_add (WpCore * self, GSource **source, guint timeout_ms,
GSourceFunc function, gpointer data, GDestroyNotify destroy);
WP_API
void wp_core_timeout_add_closure (WpCore * self, GSource **source,
guint timeout_ms, GClosure * closure);
WP_API
gboolean wp_core_sync (WpCore * self, GCancellable * cancellable,
GAsyncReadyCallback callback, gpointer user_data);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment