return NULL;
}
+static GMainContext *_vconf_get_tizen_glib_context(void)
+{
+ static GMainContext *context;
+ static int initialized;
+ const char *env;
+
+ if (initialized)
+ return context;
+
+ env = getenv("TIZEN_GLIB_CONTEXT");
+ if (env)
+ context = (GMainContext *)strtoul(env, NULL, 10);
+
+ initialized = 1;
+ return context;
+}
-static int _vconf_add_noti(struct noti *noti, vconf_callback_fn cb, void *user_data)
+static int _vconf_add_noti(struct noti *noti, vconf_callback_fn cb, void *user_data,
+ bool use_tizen_context)
{
struct noti_cb *noticb;
+ GMainContext *context;
if (!noti || !cb) {
LOGE("Invalid parameter");
noticb->user_data = user_data;
noticb->active = true;
noticb->in_cb = false;
- noticb->thread_ctx = g_main_context_ref_thread_default();
+
+ if (use_tizen_context) {
+ context = _vconf_get_tizen_glib_context();
+ if (context)
+ noticb->thread_ctx = g_main_context_ref(context);
+ }
noti->noti_list = g_list_append(noti->noti_list, noticb);
}
static int _vconf_create_noti(const char *key, vconf_callback_fn cb,
- void *user_data, struct noti **new_noti)
+ void *user_data, bool use_tizen_context, struct noti **new_noti)
{
int r;
struct noti *noti;
return ENOMEM;
}
- r = _vconf_add_noti(noti, cb, user_data);
+ r = _vconf_add_noti(noti, cb, user_data, use_tizen_context);
if (r != 0) {
free(noti->key);
free(noti);
}
/* LCOV_EXCL_STOP */
-EXPORT int vconf_notify_key_changed(const char *key, vconf_callback_fn cb,
- void *user_data)
+static int _vconf_notify_key_changed(const char *key, vconf_callback_fn cb,
+ void *user_data, bool use_tizen_context)
{
int r;
struct noti *noti;
noti = g_hash_table_lookup(noti_tbl, key);
if (!noti) {
- r = _vconf_create_noti(key, cb, user_data, ¬i);
+ r = _vconf_create_noti(key, cb, user_data, use_tizen_context, ¬i);
if (r != 0) {
_vconf_con_close();
_vconf_mutex_unlock();
r = _vconf_con_open();
}
} else {
- r = _vconf_add_noti(noti, cb, user_data);
+ r = _vconf_add_noti(noti, cb, user_data, use_tizen_context);
}
_vconf_con_close();
return 0;
}
+EXPORT int vconf_notify_key_changed(const char *key, vconf_callback_fn cb,
+ void *user_data)
+{
+ return _vconf_notify_key_changed(key, cb, user_data, false);
+}
+
+EXPORT int vconf_notify_key_changed_for_ui_thread(const char *key, vconf_callback_fn cb,
+ void *user_data)
+{
+ return _vconf_notify_key_changed(key, cb, user_data, true);
+}
+
static int _vconf_unregister_noti(struct noti *noti)
{
int cnt;
int vconf_get_ext_errno(void);
/**
+ * @brief Adds a change callback for the given key, which is called when the key is set or unset.
+ * @details The changed information (#keynode_t) of the key is delivered to #vconf_callback_fn,
+ * or if the key is deleted, the @link #keynode_t keynode @endlink has #VCONF_TYPE_NONE as type.
+ *
+ * @details Multiple vconf_callback_fn functions may exist for one key.
+ *
+ * @details The callback is invoked in the tizen glib context of the glib main loop for ui thread.
+ *
+ * @param[in] in_key The key
+ * @param[in] cb The callback function
+ * @param[in] user_data The callback data
+ *
+ * @return @c 0 on success,
+ * otherwise @c -1 on error
+ *
+ * @see vconf_notify_key_changed()
+ * @see vconf_ignore_key_changed()
+ */
+int vconf_notify_key_changed_for_ui_thread(const char *in_key, vconf_callback_fn cb,
+ void *user_data);
+
+/**
* @}
*/