}
#ifdef APPFW_EVENT_SYSTEM_EARLIER_FEATURE
+typedef struct callback_data {
+ char *event_name;
+ bundle_raw *bundle_data;
+ int len;
+ eventsystem_cb callback;
+ void *user_data;
+} callback_data_s;
+
+static gboolean __g_idle_cb_for_handler(gpointer data)
+{
+ callback_data_s *cb_data = (callback_data_s *)data;
+ if (!cb_data->callback) {
+ LOGE("handler is NULL. It may be already destroyed by user.");
+ free(cb_data->bundle_data);
+ free(cb_data->event_name);
+ free(cb_data);
+ return G_SOURCE_REMOVE;
+ }
+
+ cb_data->callback(cb_data->event_name, cb_data->bundle_data, cb_data->len,
+ cb_data->user_data);
+ free(cb_data->bundle_data);
+ free(cb_data->event_name);
+ free(cb_data);
+ return G_SOURCE_REMOVE;
+}
+
static int __eventsystem_request_earlier_data(const char *event_name,
eventsystem_cb callback, void *user_data)
{
gint result = 0;
bundle_raw *raw = NULL;
int len = 0;
+ callback_data_s *cb_data = NULL;
+ GMainContext* context = g_main_context_ref_thread_default();
+ GSource* source = NULL;
if (!_initialized)
__initialize();
_D("result(%d), len(%d)", result, len);
if (!result && raw && len > 0) {
- callback(event_name, raw, len, user_data);
+ cb_data = calloc(1, sizeof(callback_data_s));
+ if (cb_data == NULL) {
+ LOGE("calloc failed");
+ ret = ES_R_ENOMEM;
+ goto out_2;
+ }
+
+ cb_data->bundle_data = calloc(1, len);
+ if (cb_data->bundle_data == NULL) {
+ LOGE("calloc failed");
+ free(cb_data);
+ ret = ES_R_ENOMEM;
+ goto out_2;
+ }
+ memcpy(cb_data->bundle_data, raw, len);
+
+ cb_data->event_name = strdup(event_name);
+ if (cb_data->event_name == NULL) {
+ LOGE("strdup failed");
+ free(cb_data->bundle_data);
+ free(cb_data);
+ ret = ES_R_ENOMEM;
+ goto out_2;
+ }
+
+ cb_data->len = len;
+ cb_data->callback = callback;
+ cb_data->user_data = user_data;
+
+ source = g_idle_source_new();
+ if (source == NULL) {
+ _E("g_idle_source_new() is failed");
+ free(cb_data->bundle_data);
+ free(cb_data->event_name);
+ free(cb_data);
+ ret = ES_R_ENOMEM;
+ goto out_2;
+ }
+
+ g_source_set_callback(source, __g_idle_cb_for_handler, cb_data, NULL);
+ g_source_set_priority(source, G_PRIORITY_HIGH);
+ g_source_attach(source, context);
+ g_source_unref(source);
+ g_main_context_unref(context);
+
ret = ES_R_OK;
} else {
ret = ES_R_ERROR;