Commit ca21ca67 authored by Jonas Ådahl's avatar Jonas Ådahl Committed by Georges Basile Stavracas Neto

kms: Add API to add a GSource that'll be invoked in the impl context

The MetaKmsImpl implementation may need to add a GSource that should be
invoked in the right context; e.g. a idle callback, timeout etc. It
cannot just add it itself, since it's the responsibility of MetaKms to
determine what is the impl context and what is the main context, so add
API to MetaKms to ensure the callback is invoked correctly.

It's the responsibility of the caller to eventually remove and destroy
the GSource.

parent 2bbd2e55
......@@ -41,6 +41,10 @@ gboolean meta_kms_run_impl_task_sync (MetaKms *kms,
gpointer user_data,
GError **error);
GSource * meta_kms_add_source_in_impl (MetaKms *kms,
GSourceFunc func,
gpointer user_data);
gboolean meta_kms_in_impl_task (MetaKms *kms);
#define meta_assert_in_kms_impl(kms) \
......@@ -34,6 +34,12 @@ typedef struct _MetaKmsCallbackData
GDestroyNotify user_data_destroy;
} MetaKmsCallbackData;
typedef struct _MetaKmsSimpleImplSource
GSource source;
MetaKms *kms;
} MetaKmsSimpleImplSource;
struct _MetaKms
GObject parent;
......@@ -117,6 +123,48 @@ meta_kms_run_impl_task_sync (MetaKms *kms,
return ret;
static gboolean
simple_impl_source_dispatch (GSource *source,
GSourceFunc callback,
gpointer user_data)
MetaKmsSimpleImplSource *simple_impl_source =
(MetaKmsSimpleImplSource *) source;
MetaKms *kms = simple_impl_source->kms;
gboolean ret;
kms->in_impl_task = TRUE;
ret = callback (user_data);
kms->in_impl_task = FALSE;
return ret;
static GSourceFuncs simple_impl_source_funcs = {
.dispatch = simple_impl_source_dispatch,
GSource *
meta_kms_add_source_in_impl (MetaKms *kms,
GSourceFunc func,
gpointer user_data)
GSource *source;
MetaKmsSimpleImplSource *simple_impl_source;
meta_assert_in_kms_impl (kms);
source = g_source_new (&simple_impl_source_funcs,
sizeof (MetaKmsSimpleImplSource));
simple_impl_source = (MetaKmsSimpleImplSource *) source;
simple_impl_source->kms = kms;
g_source_set_callback (source, func, user_data, NULL);
g_source_attach (source, g_main_context_get_thread_default ());
return source;
meta_kms_in_impl_task (MetaKms *kms)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment