Add logic to send event by priv id 54/119954/5
authorseungha.son <seungha.son@samsung.com>
Tue, 21 Mar 2017 01:41:13 +0000 (10:41 +0900)
committerseungha.son <seungha.son@samsung.com>
Wed, 22 Mar 2017 08:06:01 +0000 (17:06 +0900)
Signed-off-by: seungha.son <seungha.son@samsung.com>
Change-Id: Icdf38b62c582b543a65eb0d72562bbdaa8a02523

include/notification_service.h
src/notification_service.c

index d7bb89b..d2cd57f 100755 (executable)
@@ -43,6 +43,7 @@ int notification_get_block_state(GVariant *parameters, GVariant **reply_body, ui
 int notification_load_dnd_allow_exception(GVariant *parameters, GVariant **reply_body, uid_t uid);
 int notification_update_dnd_allow_exception(GVariant *parameters, GVariant **reply_body, uid_t uid);
 int notification_send_noti_event(GVariant *parameters, GVariant **reply_body);
+int notification_send_noti_event_by_priv_id(GVariant *parameters, GVariant **reply_body);
 int notification_check_event_receiver(GVariant *parameters, GVariant **reply_body);
 int notification_reset_event_receiver(GVariant *parameters, GVariant **reply_body, const char *sender);
 int notification_register_dbus_interface();
index 68f9267..eff5676 100755 (executable)
@@ -161,6 +161,8 @@ static void _noti_dbus_method_call_handler(GDBusConnection *conn,
                ret = notification_update_dnd_allow_exception(parameters, &reply_body, uid);
        else if (g_strcmp0(method_name, "send_noti_event") == 0)
                ret = notification_send_noti_event(parameters, &reply_body);
+       else if (g_strcmp0(method_name, "send_noti_event_by_priv_id") == 0)
+               ret = notification_send_noti_event_by_priv_id(parameters, &reply_body);
        else if (g_strcmp0(method_name, "check_event_receiver") == 0)
                ret = notification_check_event_receiver(parameters, &reply_body);
        else if (g_strcmp0(method_name, "reset_event_handler") == 0)
@@ -342,6 +344,11 @@ int notification_register_dbus_interface()
                        "          <arg type='i' name='event_type' direction='in'/>"
                        "        </method>"
 
+                       "        <method name='send_noti_event_by_priv_id'>"
+                       "          <arg type='i' name='priv_id' direction='in'/>"
+                       "          <arg type='i' name='event_type' direction='in'/>"
+                       "        </method>"
+
                        "        <method name='check_event_receiver'>"
                        "          <arg type='i' name='priv_id' direction='in'/>"
                        "          <arg type='i' name='available' direction='out'/>"
@@ -752,7 +759,7 @@ int notification_load_noti_by_priv_id(GVariant *parameters, GVariant **reply_bod
                        return ret;
 
                DbgPrint("load_noti_by_priv_id pkgname : %s, priv_id : %d ", pkgname, priv_id);
-               ret = notification_noti_get_by_priv_id(noti, pkgname, priv_id, param_uid);
+               ret = notification_noti_get_by_priv_id(noti, priv_id);
 
                DbgPrint("notification_noti_get_by_priv_id ret : %d", ret);
                print_noti(noti);
@@ -1911,6 +1918,73 @@ int notification_send_noti_event(GVariant *parameters, GVariant **reply_body)
        return ret;
 }
 
+int notification_send_noti_event_by_priv_id(GVariant *parameters, GVariant **reply_body)
+{
+       int ret;
+       int event_type;
+       int priv_id;
+       bool event_flag = false;
+       notification_h noti;
+       GVariant *body = NULL;
+       event_sender_info_s *info;
+
+       noti = notification_create(NOTIFICATION_TYPE_NOTI);
+       if (noti != NULL) {
+               g_variant_get(parameters, "(ii)", &priv_id, &event_type);
+
+               ret = notification_noti_get_by_priv_id(noti, priv_id);
+               if (ret != NOTIFICATION_ERROR_NONE) {
+                       ErrPrint("failed to get notification by priv id [%d]", ret);
+                       notification_free(noti);
+                       return ret;
+               }
+
+               ret = notification_get_event_flag(noti, &event_flag);
+               if (ret != NOTIFICATION_ERROR_NONE || event_flag == false) {
+                       notification_free(noti);
+                       return NOTIFICATION_ERROR_INVALID_PARAMETER;
+               }
+
+               info = __find_sender_info_by_priv_id(priv_id);
+               if (info == NULL || info->busname == NULL) {
+                       notification_free(noti);
+                       return NOTIFICATION_ERROR_INVALID_PARAMETER;
+               }
+
+               if (!info->watcher_id) {
+                       if (!is_existed_busname(info->busname)) {
+                               __event_list = g_list_remove(g_list_first(__event_list), info);
+                               __free_event_info(info);
+                               notification_free(noti);
+                               return NOTIFICATION_ERROR_IO_ERROR;
+                       } else {
+                               info->watcher_id = __insert_sender_watcher_id(info);
+                       }
+               }
+
+               body = notification_ipc_make_gvariant_from_noti(noti, false);
+               if (body == NULL) {
+                       ErrPrint("Can't make gvariant to noti");
+                       notification_free(noti);
+                       return NOTIFICATION_ERROR_OUT_OF_MEMORY;
+               }
+
+               ret = send_event_notify_by_busname(g_variant_new("(vi)", body, event_type), "send_event", info->busname, PROVIDER_NOTI_EVENT_INTERFACE_NAME);
+               notification_free(noti);
+       } else {
+               return NOTIFICATION_ERROR_OUT_OF_MEMORY;
+       }
+
+       *reply_body = g_variant_new("()");
+       if (*reply_body == NULL) {
+               ErrPrint("cannot make reply body");
+               return NOTIFICATION_ERROR_OUT_OF_MEMORY;
+       }
+
+       DbgPrint("notification_send_noti_event_by_priv_id done !! %d", ret);
+       return ret;
+}
+
 int notification_check_event_receiver(GVariant *parameters, GVariant **reply_body)
 {
        int priv_id;