eventsystem_cb es_cb;
eventsystem_handler ep_cb;
};
+ void *user_data;
} eventmap_s;
typedef struct eventinfo {
static sysevent_info_s s_info;
static int __eventsystem_check_user_send_validation(const char *event_name);
-static int __eventsystem_requet_destination_list(const char *event_name, GList **dest_list);
+static int __eventsystem_request_destination_list(const char *event_name, GList **dest_list);
static int __eventsystem_check_sender_validation(int sender_pid,
const char *event_name, char **sender);
-
-static int __event_compare_name_cb(gconstpointer a, gconstpointer b)
-{
- eventmap_s *key1 = (eventmap_s *)a;
- eventmap_s *key2 = (eventmap_s *)b;
- return strcmp(key1->interface_name, key2->interface_name) |
- strcmp(key1->member_name, key2->member_name);
-}
+static eventmap_s *__create_eventmap(const char *interface_name,
+ const char *member_name, const char *event_name,
+ int event_type, eventsystem_cb callback, void *user_data);
+static void __destroy_eventmap(gpointer data);
+static int __eventsystem_launch_on_event_for_userevent(const char *event_name,
+ bundle *data, gboolean trusted);
static int __event_compare_reg_id_cb(gconstpointer a, gconstpointer b)
{
GVariant *parameters, gpointer user_data)
{
int len;
- eventmap_s em;
+ eventmap_s *em = (eventmap_s *)user_data;
GList *cb_list = NULL;
bundle *buf = NULL;
bundle_raw *raw = NULL;
- em.interface_name = (char *)interface_name;
- em.member_name = (char *)signal_name;
+ if (!em) {
+ _E("Critical error!");
+ return;
+ }
_D("sender_name(%s), interface_name(%s), signal_name(%s)",
sender_name, interface_name, signal_name);
- cb_list = g_list_find_custom(system_event_list, &em,
- (GCompareFunc)__event_compare_name_cb);
+ cb_list = g_list_find(system_event_list, em);
if (cb_list == NULL)
return;
buf = bundle_decode((bundle_raw *)raw, len);
- em.event_name = ((eventmap_s *)cb_list->data)->event_name;
- em.ep_cb = ((eventmap_s *)cb_list->data)->ep_cb;
- if (em.ep_cb)
- em.ep_cb(em.event_name, buf, user_data);
+ if (em->ep_cb)
+ em->ep_cb(em->event_name, buf, em->user_data);
bundle_free_encoded_rawdata(&raw);
bundle_free(buf);
const gchar *interface_name, const gchar *signal_name,
GVariant *parameters, gpointer user_data)
{
- GList *cb_list = NULL;
- eventmap_s em;
+ GList *cb_list;
+ eventmap_s *em = (eventmap_s *)user_data;
bundle_raw *raw = NULL;
int len;
- em.interface_name = (char *)interface_name;
- em.member_name = (char *)signal_name;
-
- cb_list = g_list_find_custom(system_event_list, &em,
- (GCompareFunc)__event_compare_name_cb);
+ if (!em) {
+ _E("Critical error!");
+ return;
+ }
+ cb_list = g_list_find(system_event_list, em);
if (cb_list == NULL) {
_E("not interested event");
return;
}
- em.event_name = ((eventmap_s *)cb_list->data)->event_name;
-
if (sender_pid > 0 && __check_interface_validation_user((char *)interface_name)) {
if (__check_validation_usrevent_sender(sender_pid,
- (const char *)interface_name, em.event_name) < 0) {
+ (const char *)interface_name, em->event_name) < 0) {
_E("invalid sender");
return;
}
}
g_variant_get(parameters, "(us)", &len, &raw);
- em.es_cb = ((eventmap_s *)cb_list->data)->es_cb;
- if (em.es_cb)
- em.es_cb(em.event_name, raw, len, user_data);
+ if (em->es_cb)
+ em->es_cb(em->event_name, raw, len, em->user_data);
bundle_free_encoded_rawdata(&raw);
}
static int __eventsystem_register_event_internal(const char *event_name,
eventmap_s **em_s, void *user_data)
{
- eventmap_s *em = NULL;
- char *interface_name = NULL;
- char *object_path = NULL;
- char *member_name = NULL;
- char *sender_name = NULL;
+ eventmap_s *em;
+ char *interface_name;
+ char *object_path;
+ char *member_name;
GDBusSignalCallback filter;
GBusType bus_type;
guint subscription_id = 0;
ret = ES_R_ERROR;
goto out_3;
}
- sender_name = NULL;
bus_type = G_BUS_TYPE_SYSTEM;
goto out_4;
}
+ em = __create_eventmap(interface_name, member_name, event_name,
+ evt_type, NULL, user_data);
+ if (!em) {
+ ret = ES_R_ENOMEM;
+ goto out_4;
+ }
+
subscription_id = g_dbus_connection_signal_subscribe(conn,
- sender_name, /* sender */
+ NULL, /* sender */
interface_name,
member_name, /* member */
object_path, /* object_path */
NULL, /* arg0 */
G_DBUS_SIGNAL_FLAGS_NONE,
filter,
- user_data,
+ em,
NULL); /* user_data_free_func */
_D("event_name(%s), interface_name(%s)", event_name, interface_name);
member_name, subscription_id, bus_type);
if (subscription_id != 0) {
- em = calloc(1, sizeof(eventmap_s));
- if (!em) {
- _E("memory alloc failed");
- ret = ES_R_ENOMEM;
- } else {
- em->interface_name = strdup(interface_name);
- em->member_name = strdup(member_name);
- em->event_name = strdup(event_name);
- em->bus_type = bus_type;
- em->reg_id = subscription_id;
- em->event_type = evt_type;
-
- if (!em->interface_name || !em->member_name || !em->event_name) {
- _E("out_of_memory");
- FREE_AND_NULL(em->interface_name);
- FREE_AND_NULL(em->member_name);
- FREE_AND_NULL(em->event_name);
- FREE_AND_NULL(em);
- ret = ES_R_ENOMEM;
- goto out_4;
- }
+ em->bus_type = bus_type;
+ em->reg_id = subscription_id;
- *em_s = em;
- ret = ES_R_OK;
- }
+ *em_s = em;
+ ret = ES_R_OK;
} else {
_D("dbus subscribe: error(%d), event(%s)", subscription_id, event_name);
+ __destroy_eventmap(em);
ret = ES_R_ERROR;
}
system_event_list = g_list_remove(system_event_list, cb_list->data);
- FREE_AND_NULL(em_data->interface_name);
- FREE_AND_NULL(em_data->member_name);
- FREE_AND_NULL(em_data->event_name);
- FREE_AND_NULL(em_data);
+ __destroy_eventmap(em_data);
g_object_unref(conn);
}
}
tmp_list = g_list_next(tmp_list);
}
- g_list_free_full(dest_list, __eventsystem_free_trusted_list);
} else {
_E("dest_list is null");
}
*/
int eventsystem_send_user_event(const char *event_name, bundle *data, bool is_trusted)
{
- int ret = 0;
+ int ret = ES_R_OK;
eventinfo_s *evti = NULL;
struct last_data_item *item;
bundle_raw *raw = NULL;
int len;
+ GDBusConnection *conn = NULL;
+ GList *trusted_dest_list = NULL;
/* check validation */
retvm_if(!event_name, ES_R_EINVAL, "Invalid argument : event_name is NULL");
if (!evti->event_name) {
_E("memory alloc failed");
ret = ES_R_ENOMEM;
- goto out_1;
+ goto out;
}
evti->interface_name = __get_encoded_interface_name(evti->event_name);
if (!evti->interface_name) {
_E("interface_name is NULL");
ret = ES_R_ERROR;
- goto out_2;
+ goto out;
}
evti->member_name = strdup(EVENT_SYSTEM_MEMBER);
if (!evti->member_name) {
_E("memory alloc failed");
ret = ES_R_ENOMEM;
- goto out_3;
+ goto out;
}
evti->object_path = __get_object_path(evti->interface_name);
if (!evti->object_path) {
_E("object_path is NULL");
ret = ES_R_ERROR;
- goto out_4;
+ goto out;
}
evti->destination_name = NULL;
evti->is_user_event = true;
evti->is_trusted = is_trusted;
- GDBusConnection *conn = NULL;
if (__get_gdbus_shared_connection(&conn, G_BUS_TYPE_SESSION, ES_TYPE_USER) == ES_R_OK) {
- if (is_trusted) {
- GList *dest_list = NULL;
- ret = __eventsystem_requet_destination_list(evti->event_name, &dest_list);
- if (ret < 0) {
- _E("failed to get dest list");
- ret = ES_R_ERROR;
- } else {
- ret = __eventsystem_send_trusted_event(conn, evti,
- data, dest_list);
- }
- } else {
- ret = __eventsystem_send_event(conn, evti, data);
- }
-
if (bundle_encode(data, &raw, &len)) {
_E("Unable to encode bundle");
ret = ES_R_ERROR;
- goto out_5;
+ goto out;
}
item = (struct last_data_item *)g_hash_table_lookup(last_data_tbl,
}
bundle_free_encoded_rawdata(&raw);
+
+ if (is_trusted) {
+ if (__eventsystem_request_destination_list(evti->event_name, &trusted_dest_list) < 0) {
+ _E("failed to get dest list");
+ ret = ES_R_ERROR;
+ goto out;
+ }
+ if (__eventsystem_send_trusted_event(conn, evti, data, trusted_dest_list) < 0) {
+ _E("failed to send trusted event");
+ ret = ES_R_ERROR;
+ goto out;
+ }
+
+ if (__eventsystem_launch_on_event_for_userevent(evti->event_name, data, TRUE) < 0)
+ _E("Failed to launch on event for userevent");
+ } else {
+ if (__eventsystem_send_event(conn, evti, data) < 0) {
+ _E("failed to send event");
+ ret = ES_R_ERROR;
+ goto out;
+ }
+
+ if (__eventsystem_launch_on_event_for_userevent(evti->event_name, data, FALSE) < 0)
+ _E("Failed to launch on event for userevent");
+ }
} else {
_E("getting gdbus-connetion error");
ret = ES_R_ERROR;
}
+out:
if (conn)
g_object_unref(conn);
-
-out_5:
+ if (trusted_dest_list)
+ g_list_free_full(trusted_dest_list, __eventsystem_free_trusted_list);
FREE_AND_NULL(evti->object_path);
-out_4:
FREE_AND_NULL(evti->member_name);
-out_3:
FREE_AND_NULL(evti->interface_name);
-out_2:
FREE_AND_NULL(evti->event_name);
-out_1:
FREE_AND_NULL(evti);
return ret;
return ret;
}
-static int __eventsystem_requet_destination_list(const char *event_name, GList **dest_list)
+static int __eventsystem_request_destination_list(const char *event_name, GList **dest_list)
{
int ret = ES_R_ERROR;
GDBusConnection *conn = NULL;
goto out_2;
}
- g_variant_get(value, "(iis)", &result, &len, &raw);
+ g_variant_get(value, "(ii&s)", &result, &len, &raw);
_D("result(%d), len(%d)", result, len);
if (!result && raw && len > 0) {
callback(event_name, raw, len, user_data);
- bundle_free_encoded_rawdata(&raw);
+ ret = ES_R_OK;
+ } else {
+ ret = ES_R_ERROR;
}
- ret = ES_R_OK;
-
out_2:
g_object_unref(proxy);
g_variant_unref(value);
return ret;
}
+static int __eventsystem_launch_on_event_for_userevent(const char *event_name,
+ bundle *data, gboolean trusted)
+{
+ int ret = ES_R_EINVAL;
+ GDBusConnection *conn = NULL;
+ GError *error = NULL;
+ GDBusProxy *proxy = NULL;
+ GVariant *param = NULL;
+ GVariant *value = NULL;
+ gint result = 0;
+ bundle_raw *raw = NULL;
+ bundle *buf = data;
+ int len;
+
+ if (!_initialized)
+ __initialize();
+
+ if (__get_gdbus_shared_connection(&conn, G_BUS_TYPE_SYSTEM, ES_TYPE_SYSTEM) < 0) {
+ _E("getting gdbus-connetion error");
+ ret = ES_R_ERROR;
+ goto out_1;
+ }
+
+ proxy = g_dbus_proxy_new_sync(conn,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL,
+ ESD_BUS_NAME, ESD_OBJECT_PATH, ESD_INTERFACE_NAME,
+ NULL, &error);
+ if (proxy == NULL) {
+ _E("failed to create new proxy, error(%s)", error->message);
+ g_error_free(error);
+ ret = ES_R_ERROR;
+ goto out_1;
+ }
+
+ bundle_encode(buf, &raw, &len);
+
+ param = g_variant_new("(ssib)", event_name, raw, len, trusted);
+ value = g_dbus_proxy_call_sync(proxy, "LaunchOnEventFromUserEvent", param,
+ G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+ if (error != NULL) {
+ _E("proxy call sync error(%s)", error->message);
+ g_error_free(error);
+ ret = ES_R_ERROR;
+ goto out_2;
+ }
+
+ _D("Launch on event from user event (%s)", event_name);
+
+ g_variant_get(value, "(i)", &result);
+
+ _D("result(%d)", result);
+
+ ret = result;
+
+out_2:
+ bundle_free_encoded_rawdata(&raw);
+ g_object_unref(proxy);
+ g_variant_unref(value);
+out_1:
+ if (conn)
+ g_object_unref(conn);
+
+ return ret;
+}
+
+
static void _send_last_user_event(const char *event_name,
bundle *data, void *user_data)
{
return ret;
}
+static void __destroy_eventmap(gpointer data)
+{
+ eventmap_s *em = (eventmap_s *)data;
+
+ if (!em)
+ return;
+
+ if (em->interface_name)
+ free(em->interface_name);
+ if (em->member_name)
+ free(em->member_name);
+ if (em->event_name)
+ free(em->event_name);
+ free(em);
+}
+
+static eventmap_s *__create_eventmap(const char *interface_name,
+ const char *member_name, const char *event_name,
+ int event_type, eventsystem_cb callback, void *user_data)
+{
+ eventmap_s *em;
+
+ em = calloc(1, sizeof(eventmap_s));
+ if (!em) {
+ _E("Out of memory");
+ return NULL;
+ }
+
+ em->interface_name = strdup(interface_name);
+ if (!em->interface_name) {
+ _E("Failed to duplicate interface name");
+ __destroy_eventmap(em);
+ return NULL;
+ }
+
+ em->member_name = strdup(member_name);
+ if (!em->member_name) {
+ _E("Failed to duplicate member name");
+ __destroy_eventmap(em);
+ return NULL;
+ }
+
+ em->event_name = strdup(event_name);
+ if (!em->event_name) {
+ _E("Failed to duplicate event name");
+ __destroy_eventmap(em);
+ return NULL;
+ }
+
+ em->event_type = event_type;
+ em->es_cb = callback;
+ em->user_data = user_data;
+
+ return em;
+}
+
int eventsystem_register_application_event(const char *event_name, unsigned int *reg_id,
int *event_type, eventsystem_cb callback, void *user_data)
{
eventmap_s *em;
- char *interface_name = NULL;
- char *object_path = NULL;
- char *member_name = NULL;
- char *sender_name = NULL;
+ char *interface_name;
+ char *object_path;
+ char *member_name;
GDBusSignalCallback filter;
GBusType bus_type;
- guint subscription_id = 0;
+ guint subscription_id = 0;
int ret = 0;
GDBusConnection *conn = NULL;
object_path = __get_object_path(interface_name);
if (!object_path) {
_E("failed get object_path");
- FREE_AND_NULL(interface_name);
- FREE_AND_NULL(member_name);
- return ES_R_ERROR;
+ ret = ES_R_ERROR;
+ goto end;
}
- sender_name = NULL;
_D("interface_name(%s), object_path(%s)", interface_name, object_path);
- _D(" member_name(%s), sender_name(%s), type(%d), bus_type(%d)",
- member_name, sender_name, *event_type, bus_type);
+ _D(" member_name(%s), type(%d), bus_type(%d)",
+ member_name, *event_type, bus_type);
if (__get_gdbus_shared_connection(&conn, bus_type, *event_type) < 0) {
_E("getting gdbus-connetion error");
- FREE_AND_NULL(interface_name);
- FREE_AND_NULL(object_path);
- FREE_AND_NULL(member_name);
- return ES_R_ERROR;
+ ret = ES_R_ERROR;
+ goto end;
}
#ifdef APPFW_EVENT_SYSTEM_EARLIER_FEATURE
__eventsystem_request_earlier_data(event_name, callback, user_data);
#endif
+ em = __create_eventmap(interface_name, member_name, event_name,
+ *event_type, callback, user_data);
+ if (!em) {
+ ret = ES_R_ENOMEM;
+ goto end;
+ }
+
subscription_id = g_dbus_connection_signal_subscribe(conn,
- sender_name, /* sender */
+ NULL, /* sender */
interface_name,
member_name, /* member */
object_path, /* object_path */
NULL, /* arg0 */
G_DBUS_SIGNAL_FLAGS_NONE,
filter,
- user_data,
+ em,
NULL); /* user_data_free_func */
_D("event_name(%s), subscription_id(%d)", event_name, subscription_id);
if (subscription_id != 0) {
- em = calloc(1, sizeof(eventmap_s));
- if (!em) {
- _E("memory alloc failed");
- ret = ES_R_ENOMEM;
- } else {
- em->interface_name = strdup(interface_name);
- em->member_name = strdup(member_name);
- em->event_name = strdup(event_name);
- em->es_cb = callback;
- em->bus_type = bus_type;
- em->reg_id = subscription_id;
- em->event_type = *event_type;
-
- if (!em->interface_name || !em->member_name ||
- !em->event_name) {
- _E("out_of_memory");
- FREE_AND_NULL(em->interface_name);
- FREE_AND_NULL(em->member_name);
- FREE_AND_NULL(em->event_name);
- FREE_AND_NULL(em);
- ret = ES_R_ENOMEM;
+ em->bus_type = bus_type;
+ em->reg_id = subscription_id;
+
+ system_event_list = g_list_append(system_event_list, em);
+ *reg_id = subscription_id;
+
+ ret = ES_R_OK;
+
+ if (em->bus_type == G_BUS_TYPE_SESSION &&
+ em->event_type == ES_TYPE_USER) {
+ if (s_info.own_name_session_bus == NULL) {
+ _E("session bus is not ready");
+ ret = ES_R_ERROR;
+ g_dbus_connection_signal_unsubscribe(conn, subscription_id);
+ __destroy_eventmap(em);
} else {
- system_event_list =
- g_list_append(system_event_list, em);
- *reg_id = subscription_id;
-
- ret = ES_R_OK;
-
- if (em->bus_type == G_BUS_TYPE_SESSION &&
- em->event_type == ES_TYPE_USER) {
- if (s_info.own_name_session_bus == NULL) {
- _E("session bus is not ready");
- ret = ES_R_ERROR;
- } else {
- if (__eventsystem_setup_trusted_peer(event_name,
+ if (__eventsystem_setup_trusted_peer(event_name,
s_info.own_name_session_bus) < 0) {
- _E("failed to setup trusted peer");
- ret = ES_R_ERROR;
- }
- }
+ _E("failed to setup trusted peer");
+ ret = ES_R_ERROR;
+ g_dbus_connection_signal_unsubscribe(conn, subscription_id);
+ __destroy_eventmap(em);
}
}
}
} else {
_E("dbus subscribe: error(%d)", subscription_id);
+ __destroy_eventmap(em);
ret = ES_R_ERROR;
}
+ if (*event_type == ES_TYPE_USER)
+ __request_esd_for_last_data(event_name, true);
+end:
FREE_AND_NULL(interface_name);
FREE_AND_NULL(object_path);
FREE_AND_NULL(member_name);
if (conn)
g_object_unref(conn);
- __request_esd_for_last_data(event_name, true);
-
return ret;
}
int eventsystem_unregister_application_event(unsigned int reg_id)
{
eventmap_s em;
- eventmap_s *em_data = NULL;
+ eventmap_s *em_data;
GBusType bus_type;
- GList *cb_list = NULL;
+ GList *cb_list;
GDBusConnection *conn = NULL;
eventsystem_event_type evt_type;
em.reg_id = reg_id;
cb_list = g_list_find_custom(system_event_list, &em,
- (GCompareFunc)__event_compare_reg_id_cb);
- if (cb_list) {
- em_data = (eventmap_s *)cb_list->data;
-
- bus_type = em_data->bus_type;
- evt_type = em_data->event_type;
+ (GCompareFunc)__event_compare_reg_id_cb);
+ if (!cb_list) {
+ _E("not found matched item");
+ return ES_R_ERROR;
+ }
- _D("unsubscribe: reg_id(%d), bus_type(%d)", reg_id, bus_type);
+ em_data = (eventmap_s *)cb_list->data;
- if (__get_gdbus_shared_connection(&conn, bus_type, evt_type) < 0) {
- _E("getting gdbus-connetion error");
- return ES_R_ERROR;
- }
- g_dbus_connection_signal_unsubscribe(conn, reg_id);
+ bus_type = em_data->bus_type;
+ evt_type = em_data->event_type;
- system_event_list = g_list_remove(system_event_list, cb_list->data);
+ _D("unsubscribe: reg_id(%d), bus_type(%d)", reg_id, bus_type);
- FREE_AND_NULL(em_data->interface_name);
- FREE_AND_NULL(em_data->member_name);
- FREE_AND_NULL(em_data->event_name);
- FREE_AND_NULL(em_data);
- g_object_unref(conn);
- } else {
- _E("not found matched item");
+ if (__get_gdbus_shared_connection(&conn, bus_type, evt_type) < 0) {
+ _E("getting gdbus-connetion error");
return ES_R_ERROR;
}
+ g_dbus_connection_signal_unsubscribe(conn, reg_id);
+
+ system_event_list = g_list_remove(system_event_list, cb_list->data);
+
+ __destroy_eventmap(em_data);
+ g_object_unref(conn);
return ES_R_OK;
}