2 * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 #include <bundle_internal.h>
24 #include <notification_ipc.h>
25 #include <notification_db.h>
26 #include <notification_type.h>
27 #include <notification_private.h>
28 #include <notification_debug.h>
29 #include <notification_setting.h>
30 #include <notification_setting_internal.h>
31 #include <notification_internal.h>
35 #define PROVIDER_BUS_NAME "org.tizen.data_provider_service"
36 #define PROVIDER_OBJECT_PATH "/org/tizen/data_provider_service"
37 #define PROVIDER_NOTI_INTERFACE_NAME "org.tizen.data_provider_noti_service"
39 #define DBUS_SERVICE_DBUS "org.freedesktop.DBus"
40 #define DBUS_PATH_DBUS "/org/freedesktop/DBus"
41 #define DBUS_INTERFACE_DBUS "org.freedesktop.DBus"
42 #define ERR_BUFFER_SIZE 1024
44 static const gchar *_bus_name = NULL;
45 static GDBusConnection *_gdbus_conn = NULL;
46 static int monitor_id = 0;
47 static int provider_monitor_id = 0;
48 static int is_master_started = 0;
50 typedef struct _result_cb_item {
51 void (*result_cb)(int priv_id, int result, void *data);
55 typedef struct _task_list task_list;
60 void (*task_cb) (void *data);
64 static task_list *g_task_list;
66 static int _ipc_monitor_register(void);
67 static int _ipc_monitor_deregister(void);
68 static void _do_deffered_task(void);
70 static void _print_noti(notification_h noti)
75 const char *tag = NULL;
76 notification_vibration_type_e vib_type = NOTIFICATION_VIBRATION_TYPE_NONE;
78 notification_get_pkgname(noti, &pkgname);
79 notification_get_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, &text);
80 notification_get_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, &content);
81 notification_get_tag(noti, &tag);
82 notification_get_vibration(noti, &vib_type, NULL);
84 NOTIFICATION_DBG("client print_noti pkgname = %s ", pkgname);
85 NOTIFICATION_DBG("client print_noti title = %s ", text);
86 NOTIFICATION_DBG("client print_noti content = %s ", content);
87 NOTIFICATION_DBG("client print_noti tag = %s ", tag);
88 NOTIFICATION_DBG("client print_noti priv_id = %d ", noti->priv_id);
89 NOTIFICATION_DBG("client print_noti vibration_path = %s ", noti->vibration_path);
90 NOTIFICATION_DBG("client print_noti vibration_type = %d ", vib_type);
93 static inline char *_string_get(char *string)
98 if (string[0] == '\0')
105 int notification_ipc_is_master_ready(void)
111 result = g_dbus_connection_call_sync(
117 g_variant_new("(s)", PROVIDER_BUS_NAME),
118 G_VARIANT_TYPE("(b)"),
119 G_DBUS_CALL_FLAGS_NONE,
124 if (err || (result == NULL)) {
126 NOTIFICATION_ERR("No reply. error = %s", err->message);
129 is_master_started = 0;
131 g_variant_get(result, "(b)", &name_exist);
134 NOTIFICATION_ERR("Name not exist %s", PROVIDER_BUS_NAME);
135 NOTIFICATION_ERR("the master has been stopped");
136 is_master_started = 0;
138 NOTIFICATION_DBG("the master has been started");
139 is_master_started = 1;
144 g_variant_unref(result);
146 return is_master_started;
149 /* TODO: dbus activation isn't enough ? */
151 * store tasks when daemon stopped
153 int notification_ipc_add_deffered_task(
154 void (*deferred_task_cb)(void *data),
161 (task_list *) malloc(sizeof(task_list));
163 if (list_new == NULL)
164 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
166 list_new->next = NULL;
167 list_new->prev = NULL;
169 list_new->task_cb = deferred_task_cb;
170 list_new->data = user_data;
172 if (g_task_list == NULL) {
173 g_task_list = list_new;
177 while (list->next != NULL)
180 list->next = list_new;
181 list_new->prev = list;
183 return NOTIFICATION_ERROR_NONE;
186 int notification_ipc_del_deffered_task(
187 void (*deferred_task_cb)(void *data))
190 task_list *list_prev;
191 task_list *list_next;
193 list_del = g_task_list;
195 if (list_del == NULL)
196 return NOTIFICATION_ERROR_INVALID_PARAMETER;
198 while (list_del->prev != NULL)
199 list_del = list_del->prev;
202 if (list_del->task_cb == deferred_task_cb) {
203 list_prev = list_del->prev;
204 list_next = list_del->next;
206 if (list_prev == NULL)
207 g_task_list = list_next;
209 list_prev->next = list_next;
211 if (list_next == NULL) {
212 if (list_prev != NULL)
213 list_prev->next = NULL;
215 list_next->prev = list_prev;
219 return NOTIFICATION_ERROR_NONE;
221 list_del = list_del->next;
222 } while (list_del != NULL);
224 return NOTIFICATION_ERROR_INVALID_PARAMETER;
227 static void _do_deffered_task(void)
230 task_list *list_temp;
232 if (g_task_list == NULL)
235 list_do = g_task_list;
238 while (list_do->prev != NULL)
239 list_do = list_do->prev;
241 while (list_do != NULL) {
242 if (list_do->task_cb != NULL) {
243 list_do->task_cb(list_do->data);
244 NOTIFICATION_DBG("called:%p", list_do->task_cb);
246 list_temp = list_do->next;
253 * functions to create operation list
255 static notification_op *_ipc_create_op(notification_op_type_e type,
256 int num_op, int *list_priv_id, int num_priv_id, notification_h *noti_list)
259 notification_op *op_list;
264 op_list = (notification_op *)malloc(sizeof(notification_op) * num_op);
266 if (op_list == NULL) {
267 NOTIFICATION_ERR("malloc failed");
271 memset(op_list, 0x0, sizeof(notification_op) * num_op);
273 for (i = 0; i < num_op; i++) {
274 (op_list + i)->type = type;
275 if (list_priv_id != NULL)
276 (op_list + i)->priv_id = *(list_priv_id + i);
277 if (noti_list != NULL)
278 (op_list + i)->noti = *(noti_list + i);
285 * utility functions creating notification packet
287 static inline char *_dup_string(const char *string)
290 char err_buf[ERR_BUFFER_SIZE];
294 if (string[0] == '\0')
297 ret = strdup(string);
299 NOTIFICATION_ERR("Error: %s\n", strerror_r(errno, err_buf, sizeof(err_buf)));
304 static inline bundle *_create_bundle_from_bundle_raw(bundle_raw *string)
308 if (string[0] == '\0')
311 return bundle_decode(string, strlen((char *)string));
314 static void _add_noti_notify(GVariant *parameters)
317 notification_op *noti_op;
318 GVariant *body = NULL;
320 NOTIFICATION_DBG("add noti notify");
321 noti = notification_create(NOTIFICATION_TYPE_NOTI);
323 NOTIFICATION_ERR("failed to create a notification");
327 g_variant_get(parameters, "(v)", &body);
328 notification_ipc_make_noti_from_gvariant(noti, body);
330 if (noti->flags_for_property & NOTIFICATION_PROP_DISABLE_UPDATE_ON_INSERT) {
331 NOTIFICATION_ERR("disable changed callback %d", noti->flags_for_property);
332 /* Disable changed cb */
334 /* Enable changed cb */
335 noti_op = _ipc_create_op(NOTIFICATION_OP_INSERT, 1, &(noti->priv_id), 1, ¬i);
337 if (noti_op != NULL) {
338 notification_call_changed_cb(noti_op, 1);
342 notification_free(noti);
345 static void _update_noti_notify(GVariant *parameters)
348 notification_op *noti_op;
349 GVariant *body = NULL;
351 noti = notification_create(NOTIFICATION_TYPE_NOTI);
353 NOTIFICATION_ERR("failed to create a notification");
356 g_variant_get(parameters, "(v)", &body);
357 notification_ipc_make_noti_from_gvariant(noti, body);
360 noti_op = _ipc_create_op(NOTIFICATION_OP_UPDATE, 1, &(noti->priv_id), 1, ¬i);
361 if (noti_op != NULL) {
362 notification_call_changed_cb(noti_op, 1);
365 notification_free(noti);
368 static void _refresh_noti_notify(GVariant *parameters)
370 notification_op *noti_op = _ipc_create_op(NOTIFICATION_OP_REFRESH, 1, NULL, 0, NULL);
372 if (noti_op != NULL) {
373 notification_call_changed_cb(noti_op, 1);
378 static void _delete_single_notify(GVariant *parameters)
382 notification_op *noti_op;
385 g_variant_get(parameters, "(ii)", &num_deleted, &priv_id);
387 noti_op = _ipc_create_op(NOTIFICATION_OP_DELETE, 1, &priv_id, 1, NULL);
388 if (noti_op != NULL) {
389 notification_call_changed_cb(noti_op, 1);
394 static void _delete_multiple_notify(GVariant *parameters)
398 notification_op *noti_op;
401 g_variant_get(parameters, "(a(i))", &iter);
402 while (g_variant_iter_loop(iter, "(i)", &buf[idx])) {
403 NOTIFICATION_DBG("delete_noti_multiple priv_id : %d", buf[idx]);
406 g_variant_iter_free(iter);
408 NOTIFICATION_DBG("data num deleted:%d", idx);
409 noti_op = _ipc_create_op(NOTIFICATION_OP_DELETE, idx, buf, idx, NULL);
411 if (noti_op == NULL) {
412 NOTIFICATION_ERR("_ipc_create_op failed");
415 notification_call_changed_cb(noti_op, idx);
419 static void _handle_noti_notify(GDBusConnection *connection,
420 const gchar *sender_name,
421 const gchar *object_path,
422 const gchar *interface_name,
423 const gchar *signal_name,
424 GVariant *parameters,
427 NOTIFICATION_DBG("signal_name: %s", signal_name);
429 if (g_strcmp0(signal_name, "add_noti_notify") == 0)
430 _add_noti_notify(parameters);
431 else if (g_strcmp0(signal_name, "update_noti_notify") == 0)
432 _update_noti_notify(parameters);
433 else if (g_strcmp0(signal_name, "delete_single_notify") == 0)
434 _delete_single_notify(parameters);
435 else if (g_strcmp0(signal_name, "delete_multiple_notify") == 0)
436 _delete_multiple_notify(parameters);
437 else if (g_strcmp0(signal_name, "refresh_noti_notify") == 0)
438 _refresh_noti_notify(parameters);
442 static int _dbus_signal_init()
445 int ret = NOTIFICATION_ERROR_NONE;
447 if (monitor_id == 0) {
448 id = g_dbus_connection_signal_subscribe(_gdbus_conn,
450 PROVIDER_NOTI_INTERFACE_NAME, /* interface */
452 PROVIDER_OBJECT_PATH, /* path */
454 G_DBUS_SIGNAL_FLAGS_NONE,
459 NOTIFICATION_DBG("subscribe id : %d", id);
461 ret = NOTIFICATION_ERROR_IO_ERROR;
462 NOTIFICATION_ERR("Failed to _register_noti_dbus_interface");
465 ret = NOTIFICATION_ERROR_NONE;
472 static int _dbus_init()
474 int ret = NOTIFICATION_ERROR_NONE;
475 GError *error = NULL;
477 if (_gdbus_conn == NULL) {
478 _gdbus_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
480 if (_gdbus_conn == NULL) {
482 NOTIFICATION_ERR("Failed to get dbus [%s]", error->message);
485 return NOTIFICATION_ERROR_IO_ERROR;
487 _bus_name = g_dbus_connection_get_unique_name(_gdbus_conn);
488 NOTIFICATION_DBG("bus name : %s", _bus_name);
490 notification_error_quark();
492 ret = NOTIFICATION_ERROR_NONE;
497 static int _send_sync_noti(GVariant *body, GDBusMessage **reply, char *cmd)
499 int ret = NOTIFICATION_ERROR_NONE;
503 msg = g_dbus_message_new_method_call(
505 PROVIDER_OBJECT_PATH,
506 PROVIDER_NOTI_INTERFACE_NAME,
509 NOTIFICATION_ERR("Can't allocate new method call");
511 g_variant_unref(body);
512 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
516 g_dbus_message_set_body(msg, body);
518 *reply = g_dbus_connection_send_message_with_reply_sync(
521 G_DBUS_SEND_MESSAGE_FLAGS_NONE,
530 ret = NOTIFICATION_ERROR_SERVICE_NOT_READY;
532 NOTIFICATION_ERR("No reply. cmd = %s, error = %s", cmd, err->message);
533 if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
534 ret = NOTIFICATION_ERROR_PERMISSION_DENIED;
540 if (g_dbus_message_to_gerror(*reply, &err)) {
541 if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
542 ret = NOTIFICATION_ERROR_PERMISSION_DENIED;
546 NOTIFICATION_ERR("_send_sync_noti cmd = %s, error %s, err code %d", cmd, err->message, ret);
550 NOTIFICATION_DBG("_send_sync_noti done !!");
551 return NOTIFICATION_ERROR_NONE;
555 static void _send_message_with_reply_async_cb(GDBusConnection *connection,
560 int result = NOTIFICATION_ERROR_NONE;
562 GDBusMessage *reply = NULL;
564 result_cb_item *cb_item = (result_cb_item *)user_data;
566 if (cb_item == NULL) {
567 NOTIFICATION_ERR("Failed to get a callback item");
571 reply = g_dbus_connection_send_message_with_reply_finish(
578 NOTIFICATION_ERR("No reply. error = %s", err->message);
581 result = NOTIFICATION_ERROR_SERVICE_NOT_READY;
583 } else if (g_dbus_message_to_gerror(reply, &err)) {
584 if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
585 result = NOTIFICATION_ERROR_PERMISSION_DENIED;
589 NOTIFICATION_ERR("_send_async_noti error %s", err->message);
593 NOTIFICATION_DBG("_send_async_noti done !![%d]", result);
595 if (result == NOTIFICATION_ERROR_NONE) {
596 body = g_dbus_message_get_body(reply);
597 g_variant_get(body, "(i)", &priv_id);
599 if (cb_item->result_cb)
600 cb_item->result_cb(priv_id, result, cb_item->data);
603 if (cb_item->result_cb)
604 cb_item->result_cb(NOTIFICATION_PRIV_ID_NONE, result, cb_item->data);
608 g_object_unref(reply);
612 static int _send_async_noti(GVariant *body, result_cb_item *cb_item, char *cmd)
616 msg = g_dbus_message_new_method_call(
618 PROVIDER_OBJECT_PATH,
619 PROVIDER_NOTI_INTERFACE_NAME,
622 NOTIFICATION_ERR("Can't allocate new method call");
623 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
627 g_dbus_message_set_body(msg, body);
629 g_dbus_connection_send_message_with_reply(
632 G_DBUS_SEND_MESSAGE_FLAGS_NONE,
636 (GAsyncReadyCallback)_send_message_with_reply_async_cb,
639 NOTIFICATION_DBG("_send_async_noti done !!");
642 return NOTIFICATION_ERROR_NONE;
645 int notification_ipc_request_insert(notification_h noti, int *priv_id)
648 int id = NOTIFICATION_PRIV_ID_NONE;
649 GDBusMessage *reply = NULL;
651 GVariant *reply_body;
653 result = _dbus_init();
654 if (result != NOTIFICATION_ERROR_NONE) {
655 NOTIFICATION_ERR("Can't init dbus %d", result);
659 /* Initialize private ID */
660 noti->priv_id = NOTIFICATION_PRIV_ID_NONE;
661 noti->group_id = NOTIFICATION_GROUP_ID_NONE;
662 noti->internal_group_id = NOTIFICATION_GROUP_ID_NONE;
665 body = notification_ipc_make_gvariant_from_noti(noti);
667 NOTIFICATION_ERR("cannot make gvariant");
668 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
671 result = _send_sync_noti(body, &reply, "add_noti");
672 NOTIFICATION_DBG("_send_sync_noti %d", result);
674 if (result == NOTIFICATION_ERROR_NONE) {
675 reply_body = g_dbus_message_get_body(reply);
676 g_variant_get(reply_body, "(i)", &id);
683 g_object_unref(reply);
685 NOTIFICATION_DBG("notification_ipc_request_insert done [priv_id : %d, result: %d]", id, result);
689 int notification_ipc_request_update(notification_h noti)
692 int priv_id = NOTIFICATION_PRIV_ID_NONE;
694 GDBusMessage *reply = NULL;
696 GVariant *reply_body;
698 result = _dbus_init();
699 if (result != NOTIFICATION_ERROR_NONE) {
700 NOTIFICATION_ERR("Can't init dbus %d", result);
704 body = notification_ipc_make_gvariant_from_noti(noti);
706 NOTIFICATION_ERR("cannot make gvariant");
707 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
710 result = _send_sync_noti(body, &reply, "update_noti");
711 if (result == NOTIFICATION_ERROR_NONE) {
712 reply_body = g_dbus_message_get_body(reply);
713 g_variant_get(reply_body, "(i)", &priv_id);
717 g_object_unref(reply);
719 NOTIFICATION_DBG("notification_ipc_request_update done [result: %d, priv_id :%d]", result, priv_id);
723 int notification_ipc_request_update_async(notification_h noti,
724 void (*result_cb)(int priv_id, int result, void *data), void *user_data)
727 result_cb_item *cb_item;
730 result = _dbus_init();
731 if (result != NOTIFICATION_ERROR_NONE) {
732 NOTIFICATION_ERR("Can't init dbus %d", result);
736 cb_item = calloc(1, sizeof(result_cb_item));
738 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
740 cb_item->result_cb = result_cb;
741 cb_item->data = user_data;
743 body = notification_ipc_make_gvariant_from_noti(noti);
745 NOTIFICATION_ERR("cannot make gvariant");
747 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
750 result = _send_async_noti(body, cb_item, "update_noti");
751 NOTIFICATION_DBG("notification_ipc_request_update_async done [result: %d]", result);
753 if (result != NOTIFICATION_ERROR_NONE) {
758 g_variant_unref(body);
763 int notification_ipc_request_refresh(void)
766 GDBusMessage *reply = NULL;
769 result = _dbus_init();
770 if (result != NOTIFICATION_ERROR_NONE) {
771 NOTIFICATION_ERR("Can't init dbus %d", result);
775 body = g_variant_new("(i)", NOTIFICATION_OP_REFRESH);
776 result = _send_sync_noti(body, &reply, "refresh_noti");
779 g_object_unref(reply);
781 NOTIFICATION_ERR("notification_ipc_request_refresh done [result: %d]", result);
785 int notification_ipc_request_delete_single(notification_type_e type, char *pkgname, int priv_id)
789 GDBusMessage *reply = NULL;
791 GVariant *reply_body;
793 result = _dbus_init();
794 if (result != NOTIFICATION_ERROR_NONE) {
795 NOTIFICATION_ERR("Can't init dbus %d", result);
799 body = g_variant_new("(si)", pkgname, priv_id);
800 result = _send_sync_noti(body, &reply, "del_noti_single");
802 if (result == NOTIFICATION_ERROR_NONE) {
803 reply_body = g_dbus_message_get_body(reply);
804 g_variant_get(reply_body, "(i)", &id);
808 g_object_unref(reply);
810 NOTIFICATION_ERR("notification_ipc_request_delete_single done [result: %d]", result);
814 int notification_ipc_request_delete_multiple(notification_type_e type, char *pkgname)
819 GVariant *reply_body;
820 GDBusMessage *reply = NULL;
822 result = _dbus_init();
823 if (result != NOTIFICATION_ERROR_NONE) {
824 NOTIFICATION_ERR("Can't init dbus %d", result);
831 body = g_variant_new("(si)", pkgname, type);
832 result = _send_sync_noti(body, &reply, "del_noti_multiple");
834 if (result == NOTIFICATION_ERROR_NONE) {
835 reply_body = g_dbus_message_get_body(reply);
836 g_variant_get(reply_body, "(i)", &num_deleted);
837 NOTIFICATION_ERR("num deleted:%d", num_deleted);
841 g_object_unref(reply);
846 int notification_ipc_request_load_noti_by_tag(notification_h noti, const char *pkgname, const char *tag)
849 GDBusMessage *reply = NULL;
851 GVariant *reply_body;
854 result = _dbus_init();
855 if (result != NOTIFICATION_ERROR_NONE) {
856 NOTIFICATION_ERR("Can't init dbus %d", result);
863 body = g_variant_new("(ss)", pkgname, tag);
864 result = _send_sync_noti(body, &reply, "load_noti_by_tag");
866 if (result == NOTIFICATION_ERROR_NONE) {
867 reply_body = g_dbus_message_get_body(reply);
868 g_variant_get(reply_body, "(v)", ¬i_body);
870 notification_ipc_make_noti_from_gvariant(noti, noti_body);
871 g_variant_unref(noti_body);
877 g_object_unref(reply);
879 NOTIFICATION_DBG("notification_ipc_request_load_noti_by_tag done [result: %d]", result);
883 int notification_ipc_request_load_noti_by_priv_id(notification_h noti, const char *pkgname, int priv_id)
886 GDBusMessage *reply = NULL;
888 GVariant *reply_body;
891 result = _dbus_init();
892 if (result != NOTIFICATION_ERROR_NONE) {
893 NOTIFICATION_ERR("Can't init dbus %d", result);
900 body = g_variant_new("(si)", pkgname, priv_id);
901 result = _send_sync_noti(body, &reply, "load_noti_by_priv_id");
903 if (result == NOTIFICATION_ERROR_NONE) {
904 reply_body = g_dbus_message_get_body(reply);
905 g_variant_get(reply_body, "(v)", ¬i_body);
907 notification_ipc_make_noti_from_gvariant(noti, noti_body);
908 g_variant_unref(noti_body);
913 g_object_unref(reply);
915 NOTIFICATION_DBG("notification_ipc_request_load_noti_by_priv_id done [result: %d]", result);
919 int notification_ipc_request_get_count(notification_type_e type,
920 const char *pkgname, int group_id, int priv_id, int *count)
923 GDBusMessage *reply = NULL;
925 GVariant *reply_body;
928 result = _dbus_init();
929 if (result != NOTIFICATION_ERROR_NONE) {
930 NOTIFICATION_ERR("Can't init dbus %d", result);
937 body = g_variant_new("(isii)", type, pkgname, group_id, priv_id);
938 result = _send_sync_noti(body, &reply, "get_noti_count");
940 if (result == NOTIFICATION_ERROR_NONE) {
941 reply_body = g_dbus_message_get_body(reply);
942 g_variant_get(reply_body, "(i)", &re_count);
945 NOTIFICATION_DBG("noti count [%d]", re_count);
949 g_object_unref(reply);
951 NOTIFICATION_DBG("notification_ipc_request_get_count done [result: %d]", result);
955 int notification_ipc_request_load_noti_grouping_list(notification_type_e type, int count,
956 notification_list_h *list)
959 GDBusMessage *reply = NULL;
961 GVariant *reply_body;
967 result = _dbus_init();
968 if (result != NOTIFICATION_ERROR_NONE) {
969 NOTIFICATION_ERR("Can't init dbus %d", result);
973 body = g_variant_new("(ii)", type, count);
974 result = _send_sync_noti(body, &reply, "load_noti_grouping_list");
976 if (result == NOTIFICATION_ERROR_NONE) {
977 reply_body = g_dbus_message_get_body(reply);
978 g_variant_get(reply_body, "(a(v))", &iter);
980 while (g_variant_iter_loop(iter, "(v)", &iter_body)) {
981 noti = notification_create(NOTIFICATION_TYPE_NOTI);
982 g_variant_get(iter_body, "(v)", ¬i_body);
983 notification_ipc_make_noti_from_gvariant(noti, noti_body);
985 *list = notification_list_append(*list, noti);
987 g_variant_iter_free(iter);
991 g_object_unref(reply);
993 NOTIFICATION_DBG("notification_ipc_request_load_noti_grouping_list done [result: %d]", result);
997 int notification_ipc_request_load_noti_detail_list(const char *pkgname,
1001 notification_list_h *list)
1004 GDBusMessage *reply = NULL;
1006 GVariant *reply_body;
1007 GVariant *iter_body;
1009 notification_h noti;
1010 GVariant *noti_body;
1012 result = _dbus_init();
1013 if (result != NOTIFICATION_ERROR_NONE) {
1014 NOTIFICATION_ERR("Can't init dbus %d", result);
1018 body = g_variant_new("(siii)", pkgname, group_id, priv_id, count);
1019 result = _send_sync_noti(body, &reply, "load_noti_detail_list");
1021 if (result == NOTIFICATION_ERROR_NONE) {
1022 reply_body = g_dbus_message_get_body(reply);
1023 g_variant_get(reply_body, "(a(v))", &iter);
1025 while (g_variant_iter_loop(iter, "(v)", &iter_body)) {
1026 noti = notification_create(NOTIFICATION_TYPE_NOTI);
1027 g_variant_get(iter_body, "(v)", ¬i_body);
1028 notification_ipc_make_noti_from_gvariant(noti, noti_body);
1030 *list = notification_list_append(*list, noti);
1032 g_variant_iter_free(iter);
1036 g_object_unref(reply);
1038 NOTIFICATION_DBG("notification_ipc_request_load_noti_detail_list done [result: %d]", result);
1042 int notification_ipc_request_get_setting_array(
1043 notification_setting_h *setting_array,
1047 GDBusMessage *reply = NULL;
1048 GVariant *reply_body;
1049 GVariant *iter_body;
1052 notification_setting_h result_setting_array;
1053 notification_setting_h temp;
1056 result = _dbus_init();
1057 if (result != NOTIFICATION_ERROR_NONE) {
1058 NOTIFICATION_ERR("Can't init dbus %d", result);
1062 result = _send_sync_noti(NULL, &reply, "get_setting_array");
1064 if (result == NOTIFICATION_ERROR_NONE) {
1065 reply_body = g_dbus_message_get_body(reply);
1066 g_variant_get(reply_body, "(ia(v))", &setting_cnt, &iter);
1068 NOTIFICATION_DBG("get setting arr cnt: %d", setting_cnt);
1069 result_setting_array = (struct notification_setting *)malloc(sizeof(struct notification_setting) * setting_cnt);
1070 if (result_setting_array == NULL) {
1071 NOTIFICATION_ERR("malloc failed");
1072 g_object_unref(reply);
1073 g_variant_iter_free(iter);
1074 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1078 while (g_variant_iter_loop(iter, "(v)", &iter_body)) {
1079 temp = result_setting_array + setting_idx;
1080 notification_ipc_make_setting_from_gvariant(temp, iter_body);
1084 *count = setting_cnt;
1085 *setting_array = result_setting_array;
1086 g_variant_iter_free(iter);
1090 g_object_unref(reply);
1092 NOTIFICATION_DBG("notification_ipc_request_get_setting_array done [result: %d]", result);
1096 int notification_ipc_request_get_setting_by_package_name(
1097 const char *package_name, notification_setting_h *setting)
1100 GDBusMessage *reply = NULL;
1102 GVariant *reply_body;
1103 GVariant *setting_body;
1104 notification_setting_h result_setting;
1106 result = _dbus_init();
1107 if (result != NOTIFICATION_ERROR_NONE) {
1108 NOTIFICATION_ERR("Can't init dbus %d", result);
1112 body = g_variant_new("(s)", package_name);
1113 result = _send_sync_noti(body, &reply, "get_setting_by_package_name");
1115 if (result == NOTIFICATION_ERROR_NONE) {
1116 reply_body = g_dbus_message_get_body(reply);
1117 g_variant_get(reply_body, "(v)", &setting_body);
1119 result_setting = (struct notification_setting *)malloc(sizeof(struct notification_setting));
1120 if (result_setting == NULL) {
1121 NOTIFICATION_ERR("malloc failed");
1122 g_object_unref(reply);
1123 g_variant_unref(body);
1124 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1126 notification_ipc_make_setting_from_gvariant(result_setting, setting_body);
1128 *setting = result_setting;
1129 g_variant_unref(setting_body);
1133 g_object_unref(reply);
1135 NOTIFICATION_DBG("notification_ipc_request_get_setting_by_package_name done [result: %d]", result);
1139 int notification_ipc_request_load_system_setting(notification_system_setting_h *setting)
1142 GDBusMessage *reply = NULL;
1143 GVariant *setting_body;
1144 GVariant *reply_body;
1145 notification_system_setting_h result_setting;
1147 result = _dbus_init();
1148 if (result != NOTIFICATION_ERROR_NONE) {
1149 NOTIFICATION_ERR("Can't init dbus %d", result);
1153 result = _send_sync_noti(NULL, &reply, "load_system_setting");
1155 if (result == NOTIFICATION_ERROR_NONE) {
1156 reply_body = g_dbus_message_get_body(reply);
1157 g_variant_get(reply_body, "(v)", &setting_body);
1159 result_setting = (struct notification_system_setting *)malloc(sizeof(struct notification_system_setting));
1160 if (result_setting == NULL) {
1161 NOTIFICATION_ERR("malloc failed");
1162 g_object_unref(reply);
1163 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1165 notification_ipc_make_system_setting_from_gvariant(result_setting, setting_body);
1167 *setting = result_setting;
1168 g_variant_unref(setting_body);
1172 g_object_unref(reply);
1174 NOTIFICATION_DBG("notification_ipc_request_load_system_setting done [result: %d]", result);
1178 int notification_ipc_update_setting(notification_setting_h setting)
1181 GDBusMessage *reply = NULL;
1184 result = _dbus_init();
1185 if (result != NOTIFICATION_ERROR_NONE) {
1186 NOTIFICATION_ERR("Can't init dbus %d", result);
1190 body = g_variant_new("(siii)",
1191 setting->package_name,
1192 (int)(setting->allow_to_notify),
1193 (int)(setting->do_not_disturb_except),
1194 (int)(setting->visibility_class));
1196 result = _send_sync_noti(body, &reply, "update_noti_setting");
1199 g_object_unref(reply);
1201 NOTIFICATION_DBG("notification_ipc_update_setting done [result: %d]", result);
1205 int notification_ipc_update_system_setting(notification_system_setting_h system_setting)
1208 GDBusMessage *reply = NULL;
1211 result = _dbus_init();
1212 if (result != NOTIFICATION_ERROR_NONE) {
1213 NOTIFICATION_ERR("Can't init dbus %d", result);
1217 body = g_variant_new("(ii)",
1218 (int)(system_setting->do_not_disturb),
1219 (int)(system_setting->visibility_class));
1221 result = _send_sync_noti(body, &reply, "update_noti_sys_setting");
1224 g_object_unref(reply);
1226 NOTIFICATION_DBG("notification_ipc_update_system_setting done [result: %d]", result);
1230 EXPORT_API GVariant *notification_ipc_make_gvariant_from_noti(notification_h noti)
1232 NOTIFICATION_DBG("make gvariant from noti");
1234 int b_encode_len = 0;
1235 bundle_raw *args = NULL;
1236 bundle_raw *group_args = NULL;
1237 bundle_raw *b_image_path = NULL;
1238 bundle_raw *b_execute_option = NULL;
1239 bundle_raw *b_service_responding = NULL;
1240 bundle_raw *b_service_single_launch = NULL;
1241 bundle_raw *b_service_multi_launch = NULL;
1242 bundle_raw *b_event_handler[NOTIFICATION_EVENT_TYPE_MAX] = {NULL, };
1243 bundle_raw *b_text = NULL;
1244 bundle_raw *b_key = NULL;
1245 bundle_raw *b_format_args = NULL;
1246 GVariant *body = NULL;
1247 GVariant *result_body = NULL;
1248 GVariantBuilder builder;
1250 g_variant_builder_init(&builder, G_VARIANT_TYPE("a{iv}"));
1251 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_NOTI_TYPE, g_variant_new_int32(noti->type));
1252 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_LAYOUT, g_variant_new_int32(noti->layout));
1253 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_GROUP_ID, g_variant_new_int32(noti->group_id));
1254 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_INTERNAL_GROUP_ID, g_variant_new_int32(noti->internal_group_id));
1255 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_PRIV_ID, g_variant_new_int32(noti->priv_id));
1256 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_CALLER_PKGNAME, g_variant_new_string((const gchar *)noti->caller_pkgname));
1257 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_DISPLAY_APPLIST, g_variant_new_int32(noti->display_applist));
1260 bundle_encode(noti->args, (bundle_raw **)&args, NULL);
1261 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_ARGS, g_variant_new_string((const gchar *)args));
1264 bundle_free_encoded_rawdata(&args);
1267 if (noti->group_args) {
1268 bundle_encode(noti->group_args, (bundle_raw **)&group_args,
1270 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_GROUP_ARGS, g_variant_new_string((const gchar *)group_args));
1273 bundle_free_encoded_rawdata(&group_args);
1276 if (noti->b_execute_option) {
1277 bundle_encode(noti->b_execute_option,
1278 (bundle_raw **)&b_execute_option, &b_encode_len);
1279 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_EXECUTE_OPTION, g_variant_new_string((const gchar *)b_execute_option));
1281 if (b_execute_option)
1282 bundle_free_encoded_rawdata(&b_execute_option);
1285 if (noti->b_service_responding) {
1286 bundle_encode(noti->b_service_responding,
1287 (bundle_raw **)&b_service_responding, &b_encode_len);
1288 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_SERVICE_RESPONDING, g_variant_new_string((const gchar *)b_service_responding));
1290 if (b_service_responding)
1291 bundle_free_encoded_rawdata(&b_service_responding);
1294 if (noti->b_service_single_launch) {
1295 bundle_encode(noti->b_service_single_launch,
1296 (bundle_raw **)&b_service_single_launch, &b_encode_len);
1297 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_SERVICE_SINGLE_LAUNCH, g_variant_new_string((const gchar *)b_service_single_launch));
1299 if (b_service_single_launch)
1300 bundle_free_encoded_rawdata(&b_service_single_launch);
1303 if (noti->b_service_multi_launch) {
1304 bundle_encode(noti->b_service_multi_launch,
1305 (bundle_raw **)&b_service_multi_launch, &b_encode_len);
1306 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_SERVICE_MULTI_LAUNCH, g_variant_new_string((const gchar *)b_service_multi_launch));
1308 if (b_service_multi_launch)
1309 bundle_free_encoded_rawdata(&b_service_multi_launch);
1312 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
1313 if (noti->b_event_handler[i]) {
1314 bundle_encode(noti->b_event_handler[i],
1315 (bundle_raw **)&b_event_handler[i], &b_encode_len);
1316 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_BUTTON1_EVENT + i, g_variant_new_string((const gchar *)b_event_handler[i]));
1318 if (b_event_handler[i])
1319 bundle_free_encoded_rawdata(&b_event_handler[i]);
1323 if (noti->launch_pkgname)
1324 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_LAUNCH_PKGNAME, g_variant_new_string((const gchar *)noti->launch_pkgname));
1326 if (noti->domain != NULL)
1327 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_DOMAIN, g_variant_new_string((const gchar *)noti->domain));
1329 if (noti->dir != NULL)
1330 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_DIR, g_variant_new_string((const gchar *)noti->dir));
1333 bundle_encode(noti->b_text, (bundle_raw **)&b_text, &b_encode_len);
1334 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_TEXT, g_variant_new_string((const gchar *)b_text));
1337 bundle_free_encoded_rawdata(&b_text);
1341 bundle_encode(noti->b_key, (bundle_raw **)&b_key, &b_encode_len);
1342 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_KEY, g_variant_new_string((const gchar *)b_key));
1345 bundle_free_encoded_rawdata(&b_key);
1348 if (noti->b_format_args) {
1349 bundle_encode(noti->b_format_args,
1350 (bundle_raw **)&b_format_args, &b_encode_len);
1351 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_FORMAT_ARGS, g_variant_new_string((const gchar *)b_format_args));
1354 bundle_free_encoded_rawdata(&b_format_args);
1357 if (noti->num_format_args != 0)
1358 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_NUM_FORMAT_ARGS, g_variant_new_int32(noti->num_format_args));
1360 if (noti->b_image_path) {
1361 bundle_encode(noti->b_image_path,
1362 (bundle_raw **)&b_image_path, &b_encode_len);
1363 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_IMAGE_PATH, g_variant_new_string((const gchar *)b_image_path));
1366 bundle_free_encoded_rawdata(&b_image_path);
1369 if (noti->sound_type != NOTIFICATION_SOUND_TYPE_NONE)
1370 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_SOUND_TYPE, g_variant_new_int32(noti->sound_type));
1372 if (noti->sound_path)
1373 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_SOUND_PATH, g_variant_new_string((const gchar *)noti->sound_path));
1375 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_VIBRATION_TYPE, g_variant_new_int32(noti->vibration_type));
1377 if (noti->vibration_path)
1378 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_VIBRATION_PATH, g_variant_new_string((const gchar *)noti->vibration_path));
1380 if (noti->led_operation != NOTIFICATION_LED_OP_OFF)
1381 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_LED_OPERATION, g_variant_new_int32(noti->led_operation));
1383 if (noti->led_argb != 0)
1384 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_LED_ARGB, g_variant_new_int32(noti->led_argb));
1386 if (noti->led_on_ms != 0)
1387 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_LED_ON_MS, g_variant_new_int32(noti->led_on_ms));
1389 if (noti->led_off_ms != 0)
1390 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_LED_OFF_MS, g_variant_new_int32(noti->led_off_ms));
1392 if (noti->time != 0)
1393 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_TIME, g_variant_new_int32(noti->time));
1395 if (noti->insert_time != 0)
1396 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_INSERT_TIME, g_variant_new_int32(noti->insert_time));
1398 if (noti->flags_for_property != 0)
1399 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_FLAGS_FOR_PROPERTY, g_variant_new_int32(noti->flags_for_property));
1401 if (noti->progress_size != 0.0)
1402 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_PROGRESS_SIZE, g_variant_new_double(noti->progress_size));
1404 if (noti->progress_percentage != 0.0)
1405 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_PROGRESS_PERCENTAGE, g_variant_new_double(noti->progress_percentage));
1407 if (noti->app_icon_path != NULL)
1408 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_APP_ICON_PATH, g_variant_new_string((const gchar *)noti->app_icon_path));
1409 if (noti->app_name != NULL)
1410 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_APP_NAME, g_variant_new_string((const gchar *)noti->app_name));
1411 if (noti->temp_title != NULL)
1412 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_TEMP_TITLE, g_variant_new_string((const gchar *)noti->temp_title));
1413 if (noti->temp_content != NULL)
1414 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_TEMP_CONTENT, g_variant_new_string((const gchar *)noti->temp_content));
1415 if (noti->tag != NULL)
1416 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_TAG, g_variant_new_string((const gchar *)noti->tag));
1418 if (noti->ongoing_flag != 0)
1419 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_ONGOING_FLAG, g_variant_new_int32(noti->ongoing_flag));
1420 if (noti->auto_remove != 0)
1421 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_AUTO_REMOVE, g_variant_new_int32(noti->auto_remove));
1423 result_body = g_variant_builder_end(&builder);
1424 body = g_variant_new("(v)", result_body);
1429 static gboolean _variant_to_int_dict(GHashTable **dict, GVariant *variant)
1436 *dict = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, (GDestroyNotify)g_variant_unref);
1440 g_variant_iter_init(&iter, variant);
1441 while (g_variant_iter_next(&iter, "{iv}", &key, &value)) {
1442 hash_key = (int *)calloc(sizeof(int), 1);
1443 if (hash_key == NULL) {
1444 g_hash_table_unref(*dict);
1448 g_hash_table_insert(*dict, (gpointer)hash_key, value);
1453 static gboolean _variant_dict_lookup(GHashTable *dict,
1455 const gchar *format_string,
1461 value = g_hash_table_lookup(dict, (gpointer)&key);
1463 if (value == NULL || !g_variant_check_format_string(value, format_string, FALSE))
1466 va_start(ap, format_string);
1467 g_variant_get_va(value, format_string, NULL, &ap);
1474 * functions creating notification packet
1476 EXPORT_API int notification_ipc_make_noti_from_gvariant(notification_h noti,
1477 GVariant *variant) {
1479 NOTIFICATION_DBG("make noti from GVariant");
1483 char *caller_pkgname = NULL;
1484 char *launch_pkgname = NULL;
1485 bundle_raw *args = NULL;
1486 bundle_raw *group_args = NULL;
1487 bundle_raw *b_execute_option = NULL;
1488 bundle_raw *b_service_responding = NULL;
1489 bundle_raw *b_service_single_launch = NULL;
1490 bundle_raw *b_service_multi_launch = NULL;
1491 bundle_raw *b_event_handler[NOTIFICATION_EVENT_TYPE_MAX] = { NULL, };
1492 char *domain = NULL;
1494 bundle_raw *b_text = NULL;
1495 bundle_raw *b_key = NULL;
1496 bundle_raw *b_format_args = NULL;
1497 bundle_raw *b_image_path = NULL;
1498 char *sound_path = NULL;
1499 char *vibration_path = NULL;
1500 char *app_icon_path = NULL;
1501 char *app_name = NULL;
1502 char *temp_title = NULL;
1503 char *temp_content = NULL;
1507 NOTIFICATION_ERR("invalid data noti NULL");
1508 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1511 if (variant == NULL) {
1512 NOTIFICATION_ERR("invalid data variant NULL");
1513 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1516 if (!_variant_to_int_dict(&dict, variant))
1517 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1519 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_NOTI_TYPE, "i", ¬i->type);
1520 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_LAYOUT, "i", ¬i->layout);
1521 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_GROUP_ID, "i", ¬i->group_id);
1522 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_INTERNAL_GROUP_ID, "i", ¬i->internal_group_id);
1523 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_PRIV_ID, "i", ¬i->priv_id);
1524 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_CALLER_PKGNAME, "&s", &caller_pkgname);
1525 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_LAUNCH_PKGNAME, "&s", &launch_pkgname);
1526 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_ARGS, "&s", &args);
1527 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_GROUP_ARGS, "&s", &group_args);
1528 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_EXECUTE_OPTION, "&s", &b_execute_option);
1529 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_SERVICE_RESPONDING, "&s", &b_service_responding);
1530 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_SERVICE_SINGLE_LAUNCH, "&s", &b_service_single_launch);
1531 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_SERVICE_MULTI_LAUNCH, "&s", &b_service_multi_launch);
1532 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_BUTTON1_EVENT, "&s", ¬i->b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1]);
1533 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_BUTTON2_EVENT, "&s", ¬i->b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_2]);
1534 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_BUTTON3_EVENT, "&s", ¬i->b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_3]);
1535 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_BUTTON4_EVENT, "&s", ¬i->b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_4]);
1536 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_BUTTON5_EVENT, "&s", ¬i->b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_5]);
1537 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_BUTTON6_EVENT, "&s", ¬i->b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_6]);
1538 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_ICON_EVENT, "&s", ¬i->b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_ICON]);
1539 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_THUMBNAIL_EVENT, "&s", ¬i->b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL]);
1540 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_DOMAIN, "&s", &domain);
1541 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_DIR, "&s", &dir);
1542 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_TEXT, "&s", &b_text);
1543 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_KEY, "&s", &b_key);
1544 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_FORMAT_ARGS, "&s", &b_format_args);
1545 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_NUM_FORMAT_ARGS, "i", ¬i->num_format_args);
1546 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_IMAGE_PATH, "&s", &b_image_path);
1547 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_SOUND_TYPE, "i", ¬i->sound_type);
1548 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_SOUND_PATH, "&s", &sound_path);
1549 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_VIBRATION_TYPE, "i", ¬i->vibration_type);
1550 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_VIBRATION_PATH, "&s", &vibration_path);
1551 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_LED_OPERATION, "i", ¬i->led_operation);
1552 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_LED_ARGB, "i", ¬i->led_argb);
1553 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_LED_ON_MS, "i", ¬i->led_on_ms);
1554 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_LED_OFF_MS, "i", ¬i->led_off_ms);
1555 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_TIME, "i", ¬i->time);
1556 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_INSERT_TIME, "i", ¬i->insert_time);
1557 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_FLAGS_FOR_PROPERTY, "i", ¬i->flags_for_property);
1558 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_DISPLAY_APPLIST, "i", ¬i->display_applist);
1559 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_PROGRESS_SIZE, "d", ¬i->progress_size);
1560 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_PROGRESS_PERCENTAGE, "d", ¬i->progress_percentage);
1561 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_APP_ICON_PATH, "&s", &app_icon_path);
1562 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_APP_NAME, "&s", &app_name);
1563 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_TEMP_TITLE, "&s", &temp_title);
1564 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_TEMP_CONTENT, "&s", &temp_content);
1565 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_TAG, "&s", &tag);
1566 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_ONGOING_FLAG, "i", ¬i->ongoing_flag);
1567 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_AUTO_REMOVE, "i", ¬i->auto_remove);
1569 noti->caller_pkgname = _dup_string(caller_pkgname);
1570 noti->launch_pkgname = _dup_string(launch_pkgname);
1571 noti->args = _create_bundle_from_bundle_raw(args);
1572 noti->group_args = _create_bundle_from_bundle_raw(group_args);
1573 noti->b_execute_option = _create_bundle_from_bundle_raw(b_execute_option);
1574 noti->b_service_responding = _create_bundle_from_bundle_raw(
1575 b_service_responding);
1576 noti->b_service_single_launch = _create_bundle_from_bundle_raw(
1577 b_service_single_launch);
1578 noti->b_service_multi_launch = _create_bundle_from_bundle_raw(
1579 b_service_multi_launch);
1580 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
1581 noti->b_event_handler[i] = _create_bundle_from_bundle_raw(
1582 b_event_handler[i]);
1584 noti->domain = _dup_string(domain);
1585 noti->dir = _dup_string(dir);
1586 noti->b_text = _create_bundle_from_bundle_raw(b_text);
1587 noti->b_key = _create_bundle_from_bundle_raw(b_key);
1588 noti->b_format_args = _create_bundle_from_bundle_raw(b_format_args);
1589 noti->b_image_path = _create_bundle_from_bundle_raw(b_image_path);
1590 noti->sound_path = _dup_string(sound_path);
1591 noti->vibration_path = _dup_string(vibration_path);
1592 noti->app_icon_path = _dup_string(app_icon_path);
1593 noti->app_name = _dup_string(app_name);
1594 noti->temp_title = _dup_string(temp_title);
1595 noti->temp_content = _dup_string(temp_content);
1596 noti->tag = _dup_string(tag);
1598 g_hash_table_unref(dict);
1600 return NOTIFICATION_ERROR_NONE;
1603 EXPORT_API GVariant *notification_ipc_make_gvariant_from_system_setting(struct notification_system_setting *noti_setting)
1605 GVariant *body = NULL;
1606 body = g_variant_new("(ii)",
1607 noti_setting->do_not_disturb,
1608 noti_setting->visibility_class);
1612 EXPORT_API int notification_ipc_make_system_setting_from_gvariant(struct notification_system_setting *noti_setting,
1616 int visibility_class;
1618 if (noti_setting == NULL) {
1619 NOTIFICATION_ERR("invalid data");
1620 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1622 g_variant_get(variant,
1627 NOTIFICATION_DBG("system setting #### %d, %d",
1628 do_not_disturb, visibility_class);
1630 noti_setting->do_not_disturb = do_not_disturb;
1631 noti_setting->visibility_class = visibility_class;
1633 NOTIFICATION_DBG("system setting2 #### %d, %d",
1634 noti_setting->do_not_disturb, noti_setting->visibility_class);
1636 return NOTIFICATION_ERROR_NONE;
1639 EXPORT_API GVariant *notification_ipc_make_gvariant_from_setting(struct notification_setting *noti_setting)
1641 GVariant *body = NULL;
1643 body = g_variant_new("(siii)",
1644 noti_setting->package_name,
1645 noti_setting->allow_to_notify,
1646 noti_setting->do_not_disturb_except,
1647 noti_setting->visibility_class);
1652 EXPORT_API int notification_ipc_make_setting_from_gvariant(struct notification_setting *noti_setting,
1655 NOTIFICATION_DBG("notification_ipc_make_setting_from_gvariant !!!!");
1657 int allow_to_notify;
1658 int do_not_disturb_except;
1659 int visibility_class;
1661 if (noti_setting == NULL || variant == NULL) {
1662 NOTIFICATION_ERR("invalid data");
1663 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1665 g_variant_get(variant,
1669 &do_not_disturb_except,
1672 NOTIFICATION_DBG("setting from variant %s !!", pkgname);
1674 noti_setting->package_name = _dup_string(pkgname);
1675 noti_setting->allow_to_notify = allow_to_notify;
1676 noti_setting->do_not_disturb_except = do_not_disturb_except;
1677 noti_setting->visibility_class = visibility_class;
1679 NOTIFICATION_DBG("setting from variant %s, %s",
1680 noti_setting->package_name, pkgname);
1682 return NOTIFICATION_ERROR_NONE;
1685 static int _send_service_register()
1687 NOTIFICATION_DBG("service register");
1688 GDBusMessage *reply = NULL;
1691 result = _send_sync_noti(NULL, &reply, "noti_service_register");
1694 g_object_unref(reply);
1696 NOTIFICATION_ERR("_send_service_register done = %s, result = %d", _bus_name, result);
1700 static int _ipc_monitor_register(void)
1702 NOTIFICATION_ERR("register a service\n");
1704 return _send_service_register();
1707 static void _on_name_appeared(GDBusConnection *connection,
1709 const gchar *name_owner,
1712 NOTIFICATION_DBG("name appeared : %s", name);
1713 is_master_started = 1;
1714 _ipc_monitor_register();
1716 /* TODO: dbus activation isn't enough ? */
1717 _do_deffered_task();
1720 static void _on_name_vanished(GDBusConnection *connection,
1724 NOTIFICATION_DBG("name vanished : %s", name);
1725 is_master_started = 0;
1728 int notification_ipc_monitor_init(void)
1733 if (ret != NOTIFICATION_ERROR_NONE) {
1734 NOTIFICATION_ERR("Can't init dbus %d", ret);
1738 ret = _dbus_signal_init();
1739 if (ret != NOTIFICATION_ERROR_NONE) {
1740 NOTIFICATION_ERR("Can't signal_init %d", ret);
1744 ret = _ipc_monitor_register();
1745 if (ret != NOTIFICATION_ERROR_NONE) {
1746 NOTIFICATION_ERR("Can't init ipc_monitor_register %d", ret);
1750 if (provider_monitor_id == 0) {
1751 provider_monitor_id = g_bus_watch_name_on_connection(
1754 G_BUS_NAME_WATCHER_FLAGS_NONE,
1760 if (provider_monitor_id == 0) {
1761 g_dbus_connection_signal_unsubscribe(_gdbus_conn, monitor_id);
1763 NOTIFICATION_ERR("watch on name fail");
1764 return NOTIFICATION_ERROR_IO_ERROR;
1768 return NOTIFICATION_ERROR_NONE;
1771 static int _ipc_monitor_deregister(void)
1773 if (provider_monitor_id) {
1774 g_bus_unwatch_name(provider_monitor_id);
1775 provider_monitor_id = 0;
1779 g_dbus_connection_signal_unsubscribe(_gdbus_conn, monitor_id);
1783 return NOTIFICATION_ERROR_NONE;
1786 int notification_ipc_monitor_fini(void)
1788 return _ipc_monitor_deregister();