4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Seungtaek Chung <seungtaek.chung@samsung.com>, Mi-Ju Lee <miju52.lee@samsung.com>, Xi Zhichan <zhichan.xi@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
27 #include <bundle_internal.h>
29 #include <notification_ipc.h>
30 #include <notification_db.h>
31 #include <notification_type.h>
32 #include <notification_private.h>
33 #include <notification_debug.h>
34 #include <notification_setting.h>
35 #include <notification_setting_internal.h>
36 #include <notification_internal.h>
40 #define PROVIDER_BUS_NAME "org.tizen.data_provider_service"
41 #define PROVIDER_OBJECT_PATH "/org/tizen/data_provider_service"
42 #define PROVIDER_NOTI_INTERFACE_NAME "org.tizen.data_provider_noti_service"
44 #define DBUS_SERVICE_DBUS "org.freedesktop.DBus"
45 #define DBUS_PATH_DBUS "/org/freedesktop/DBus"
46 #define DBUS_INTERFACE_DBUS "org.freedesktop.DBus"
48 static const gchar *_bus_name = NULL;
49 static GDBusConnection *_gdbus_conn = NULL;
50 static int monitor_id = 0;
51 static int provider_monitor_id = 0;
52 static int is_master_started = 0;
54 static const char *NOTI_DATA_STRING[] = {
55 "NOTIFICATION_DATA_TYPE_NOTI_TYPE",
56 "NOTIFICATION_DATA_TYPE_LAYOUT",
57 "NOTIFICATION_DATA_TYPE_GROUP_ID",
58 "NOTIFICATION_DATA_TYPE_INTERNAL_GROUP_ID",
59 "NOTIFICATION_DATA_TYPE_PRIV_ID",
60 "NOTIFICATION_DATA_TYPE_CALLER_PKGNAME",
61 "NOTIFICATION_DATA_TYPE_LAUNCH_PKGNAME",
62 "NOTIFICATION_DATA_TYPE_ARGS",
63 "NOTIFICATION_DATA_TYPE_GROUP_ARGS",
64 "NOTIFICATION_DATA_TYPE_EXECUTE_OPTION",
65 "NOTIFICATION_DATA_TYPE_SERVICE_RESPONDING",
66 "NOTIFICATION_DATA_TYPE_SERVICE_SINGLE_LAUNCH",
67 "NOTIFICATION_DATA_TYPE_SERVICE_MULTI_LAUNCH",
68 "NOTIFICATION_DATA_TYPE_BUTTON1_EVENT",
69 "NOTIFICATION_DATA_TYPE_BUTTON2_EVENT",
70 "NOTIFICATION_DATA_TYPE_BUTTON3_EVENT",
71 "NOTIFICATION_DATA_TYPE_BUTTON4_EVENT",
72 "NOTIFICATION_DATA_TYPE_BUTTON5_EVENT",
73 "NOTIFICATION_DATA_TYPE_BUTTON6_EVENT",
74 "NOTIFICATION_DATA_TYPE_ICON_EVENT",
75 "NOTIFICATION_DATA_TYPE_THUMBNAIL_EVENT",
76 "NOTIFICATION_DATA_TYPE_DOMAIN",
77 "NOTIFICATION_DATA_TYPE_DIR",
78 "NOTIFICATION_DATA_TYPE_TEXT",
79 "NOTIFICATION_DATA_TYPE_KEY",
80 "NOTIFICATION_DATA_TYPE_FORMAT_ARGS",
81 "NOTIFICATION_DATA_TYPE_NUM_FORMAT_ARGS",
82 "NOTIFICATION_DATA_TYPE_IMAGE_PATH",
83 "NOTIFICATION_DATA_TYPE_SOUND_TYPE",
84 "NOTIFICATION_DATA_TYPE_SOUND_PATH",
85 "NOTIFICATION_DATA_TYPE_VIBRATION_TYPE",
86 "NOTIFICATION_DATA_TYPE_VIBRATION_PATH",
87 "NOTIFICATION_DATA_TYPE_LED_OPERATION",
88 "NOTIFICATION_DATA_TYPE_LED_ARGB",
89 "NOTIFICATION_DATA_TYPE_LED_ON_MS",
90 "NOTIFICATION_DATA_TYPE_LED_OFF_MS",
91 "NOTIFICATION_DATA_TYPE_TIME",
92 "NOTIFICATION_DATA_TYPE_INSERT_TIME",
93 "NOTIFICATION_DATA_TYPE_FLAGS_FOR_PROPERTY",
94 "NOTIFICATION_DATA_TYPE_DISPLAY_APPLIST",
95 "NOTIFICATION_DATA_TYPE_PROGRESS_SIZE",
96 "NOTIFICATION_DATA_TYPE_PROGRESS_PERCENTAGE",
97 "NOTIFICATION_DATA_TYPE_APP_ICON_PATH",
98 "NOTIFICATION_DATA_TYPE_APP_NAME",
99 "NOTIFICATION_DATA_TYPE_TEMP_TITLE",
100 "NOTIFICATION_DATA_TYPE_TEMP_CONTENT",
101 "NOTIFICATION_DATA_TYPE_TAG",
102 "NOTIFICATION_DATA_TYPE_ONGOING_FLAG",
103 "NOTIFICATION_DATA_TYPE_AUTO_REMOVE",
107 typedef struct _result_cb_item {
108 void (*result_cb)(int priv_id, int result, void *data);
112 typedef struct _task_list task_list;
117 void (*task_cb) (void *data);
121 static task_list *g_task_list;
123 static int _ipc_monitor_register(void);
124 static int _ipc_monitor_deregister(void);
125 static void _do_deffered_task(void);
127 static void _print_noti(notification_h noti) {
128 char *pkgname = NULL;
130 char *content = NULL;
131 const char *tag = NULL;
133 notification_get_pkgname(noti, &pkgname);
134 notification_get_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, &text);
135 notification_get_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, &content);
136 notification_get_tag(noti, &tag);
138 NOTIFICATION_DBG("client print_noti pkgname = %s ", pkgname );
139 NOTIFICATION_DBG("client print_noti title = %s ", text );
140 NOTIFICATION_DBG("client print_noti content = %s ", content );
141 NOTIFICATION_DBG("client print_noti tag = %s ", tag );
142 NOTIFICATION_DBG("client print_noti priv_id = %d ", noti->priv_id);
143 NOTIFICATION_DBG("client print_noti vibration_path = %s ", noti->vibration_path);
146 static inline char *_string_get(char *string)
151 if (string[0] == '\0')
158 int notification_ipc_is_master_ready(void)
164 result = g_dbus_connection_call_sync(
170 g_variant_new("(s)", PROVIDER_BUS_NAME),
171 G_VARIANT_TYPE("(b)"),
172 G_DBUS_CALL_FLAGS_NONE,
177 if (err || (result == NULL)) {
179 NOTIFICATION_ERR("No reply. error = %s", err->message);
182 is_master_started = 0;
184 g_variant_get(result, "(b)", &name_exist);
187 NOTIFICATION_ERR("Name not exist %s", PROVIDER_BUS_NAME);
188 NOTIFICATION_ERR("the master has been stopped");
189 is_master_started = 0;
191 NOTIFICATION_DBG("the master has been started");
192 is_master_started = 1;
197 g_variant_unref(result);
199 return is_master_started;
202 /* TODO: dbus activation isn't enough ? */
204 * store tasks when daemon stopped
206 int notification_ipc_add_deffered_task(
207 void (*deferred_task_cb)(void *data),
214 (task_list *) malloc(sizeof(task_list));
216 if (list_new == NULL)
217 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
219 list_new->next = NULL;
220 list_new->prev = NULL;
222 list_new->task_cb = deferred_task_cb;
223 list_new->data = user_data;
225 if (g_task_list == NULL) {
226 g_task_list = list_new;
230 while (list->next != NULL)
233 list->next = list_new;
234 list_new->prev = list;
236 return NOTIFICATION_ERROR_NONE;
239 int notification_ipc_del_deffered_task(
240 void (*deferred_task_cb)(void *data))
243 task_list *list_prev;
244 task_list *list_next;
246 list_del = g_task_list;
248 if (list_del == NULL)
249 return NOTIFICATION_ERROR_INVALID_PARAMETER;
251 while (list_del->prev != NULL)
252 list_del = list_del->prev;
255 if (list_del->task_cb == deferred_task_cb) {
256 list_prev = list_del->prev;
257 list_next = list_del->next;
259 if (list_prev == NULL)
260 g_task_list = list_next;
262 list_prev->next = list_next;
264 if (list_next == NULL) {
265 if (list_prev != NULL)
266 list_prev->next = NULL;
268 list_next->prev = list_prev;
272 return NOTIFICATION_ERROR_NONE;
274 list_del = list_del->next;
275 } while (list_del != NULL);
277 return NOTIFICATION_ERROR_INVALID_PARAMETER;
280 static void _do_deffered_task(void)
283 task_list *list_temp;
285 if (g_task_list == NULL)
288 list_do = g_task_list;
291 while (list_do->prev != NULL)
292 list_do = list_do->prev;
294 while (list_do != NULL) {
295 if (list_do->task_cb != NULL) {
296 list_do->task_cb(list_do->data);
297 NOTIFICATION_DBG("called:%p", list_do->task_cb);
299 list_temp = list_do->next;
306 * functions to create operation list
308 static notification_op *_ipc_create_op(notification_op_type_e type,
309 int num_op, int *list_priv_id, int num_priv_id, notification_h *noti_list)
312 notification_op *op_list;
317 op_list = (notification_op *)malloc(sizeof(notification_op) * num_op);
319 if (op_list == NULL) {
320 NOTIFICATION_ERR("malloc failed");
324 memset(op_list, 0x0, sizeof(notification_op) * num_op);
326 for (i = 0; i < num_op; i++) {
327 (op_list + i)->type = type;
328 if (list_priv_id != NULL)
329 (op_list + i)->priv_id = *(list_priv_id + i);
330 if (noti_list != NULL)
331 (op_list + i)->noti = *(noti_list + i);
338 * utility functions creating notification packet
340 static inline char *_dup_string(const char *string)
346 if (string[0] == '\0')
349 ret = strdup(string);
351 NOTIFICATION_ERR("Error: %s\n", strerror(errno));
356 static inline bundle *_create_bundle_from_bundle_raw(bundle_raw *string)
360 if (string[0] == '\0')
363 return bundle_decode(string, strlen((char *)string));
366 static void _add_noti_notify(GVariant *parameters)
369 notification_op *noti_op;
370 GVariant *body = NULL;
372 NOTIFICATION_DBG("add noti notify");
373 noti = notification_create(NOTIFICATION_TYPE_NOTI);
375 NOTIFICATION_ERR("failed to create a notification");
379 g_variant_get(parameters, "(v)", &body);
380 notification_ipc_make_noti_from_gvariant(noti, body);
382 if (noti->flags_for_property & NOTIFICATION_PROP_DISABLE_UPDATE_ON_INSERT) {
383 NOTIFICATION_ERR("disable changed callback %d", noti->flags_for_property);
384 /* Disable changed cb */
386 /* Enable changed cb */
387 noti_op = _ipc_create_op(NOTIFICATION_OP_INSERT, 1, &(noti->priv_id), 1, ¬i);
389 if (noti_op != NULL) {
390 notification_call_changed_cb(noti_op, 1);
394 notification_free(noti);
397 static void _update_noti_notify(GVariant *parameters)
400 notification_op *noti_op;
401 GVariant *body = NULL;
403 noti = notification_create(NOTIFICATION_TYPE_NOTI);
405 NOTIFICATION_ERR("failed to create a notification");
408 g_variant_get(parameters, "(v)", &body);
409 notification_ipc_make_noti_from_gvariant(noti, body);
412 noti_op = _ipc_create_op(NOTIFICATION_OP_UPDATE, 1, &(noti->priv_id), 1, ¬i);
413 if (noti_op != NULL) {
414 notification_call_changed_cb(noti_op, 1);
417 notification_free(noti);
420 static void _refresh_noti_notify(GVariant *parameters)
422 notification_op *noti_op = _ipc_create_op(NOTIFICATION_OP_REFRESH, 1, NULL, 0, NULL);
424 if (noti_op != NULL) {
425 notification_call_changed_cb(noti_op, 1);
430 static void _delete_single_notify(GVariant *parameters)
434 notification_op *noti_op;
437 g_variant_get(parameters, "(ii)", &num_deleted, &priv_id);
439 noti_op = _ipc_create_op(NOTIFICATION_OP_DELETE, 1, &priv_id, 1, NULL);
440 if (noti_op != NULL) {
441 notification_call_changed_cb(noti_op, 1);
446 static void _delete_multiple_notify(GVariant *parameters)
450 notification_op *noti_op;
453 g_variant_get(parameters, "(a(i))", &iter);
454 while (g_variant_iter_loop(iter, "(i)", &buf[idx])) {
455 NOTIFICATION_DBG("delete_noti_multiple priv_id : %d", buf[idx]);
458 g_variant_iter_free(iter);
460 NOTIFICATION_DBG("data num deleted:%d", idx);
461 noti_op = _ipc_create_op(NOTIFICATION_OP_DELETE, idx, buf, idx, NULL);
463 if (noti_op == NULL) {
464 NOTIFICATION_ERR("_ipc_create_op failed");
467 notification_call_changed_cb(noti_op, idx);
471 static void _handle_noti_notify(GDBusConnection *connection,
472 const gchar *sender_name,
473 const gchar *object_path,
474 const gchar *interface_name,
475 const gchar *signal_name,
476 GVariant *parameters,
479 NOTIFICATION_DBG("signal_name: %s", signal_name);
481 if (g_strcmp0(signal_name, "add_noti_notify") == 0)
482 _add_noti_notify(parameters);
483 else if (g_strcmp0(signal_name, "update_noti_notify") == 0)
484 _update_noti_notify(parameters);
485 else if (g_strcmp0(signal_name, "delete_single_notify") == 0)
486 _delete_single_notify(parameters);
487 else if (g_strcmp0(signal_name, "delete_multiple_notify") == 0)
488 _delete_multiple_notify(parameters);
489 else if (g_strcmp0(signal_name, "refresh_noti_notify") == 0)
490 _refresh_noti_notify(parameters);
494 static int _dbus_signal_init()
497 int ret = NOTIFICATION_ERROR_NONE;
499 if (monitor_id == 0) {
500 id = g_dbus_connection_signal_subscribe(_gdbus_conn,
502 PROVIDER_NOTI_INTERFACE_NAME, /* interface */
504 PROVIDER_OBJECT_PATH, /* path */
506 G_DBUS_SIGNAL_FLAGS_NONE,
511 NOTIFICATION_DBG("subscribe id : %d", id);
513 ret = NOTIFICATION_ERROR_IO_ERROR;
514 NOTIFICATION_ERR("Failed to _register_noti_dbus_interface");
517 ret = NOTIFICATION_ERROR_NONE;
524 static int _dbus_init()
526 int ret = NOTIFICATION_ERROR_NONE;
527 GError *error = NULL;
529 if (_gdbus_conn == NULL) {
530 _gdbus_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
532 if (_gdbus_conn == NULL) {
534 NOTIFICATION_ERR("Failed to get dbus [%s]", error->message);
537 return NOTIFICATION_ERROR_IO_ERROR;
539 _bus_name = g_dbus_connection_get_unique_name(_gdbus_conn);
540 NOTIFICATION_DBG("bus name : %s", _bus_name);
542 notification_error_quark();
544 ret = NOTIFICATION_ERROR_NONE;
549 static int _send_sync_noti(GVariant *body, GDBusMessage **reply, char *cmd)
551 int ret = NOTIFICATION_ERROR_NONE;
555 msg = g_dbus_message_new_method_call(
557 PROVIDER_OBJECT_PATH,
558 PROVIDER_NOTI_INTERFACE_NAME,
561 NOTIFICATION_ERR("Can't allocate new method call");
563 g_variant_unref(body);
564 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
568 g_dbus_message_set_body(msg, body);
570 *reply = g_dbus_connection_send_message_with_reply_sync(
573 G_DBUS_SEND_MESSAGE_FLAGS_NONE,
583 NOTIFICATION_ERR("No reply. cmd = %s, error = %s", cmd, err->message);
586 return NOTIFICATION_ERROR_SERVICE_NOT_READY;
589 if (g_dbus_message_to_gerror(*reply, &err)) {
591 NOTIFICATION_ERR("_send_sync_noti cmd = %s, error %s", cmd, err->message);
595 NOTIFICATION_DBG("_send_sync_noti done !!");
596 return NOTIFICATION_ERROR_NONE;
600 static void _send_message_with_reply_async_cb(GDBusConnection *connection,
605 int result = NOTIFICATION_ERROR_NONE;
607 GDBusMessage *reply = NULL;
609 result_cb_item *cb_item = (result_cb_item *)user_data;
611 if (cb_item == NULL) {
612 NOTIFICATION_ERR("Failed to get a callback item");
616 reply = g_dbus_connection_send_message_with_reply_finish(
623 NOTIFICATION_ERR("No reply. error = %s", err->message);
626 result = NOTIFICATION_ERROR_SERVICE_NOT_READY;
628 } else if (g_dbus_message_to_gerror(reply, &err)) {
631 NOTIFICATION_ERR("_send_async_noti error %s", err->message);
634 NOTIFICATION_DBG("_send_async_noti done !![%d]", result);
636 if (result == NOTIFICATION_ERROR_NONE) {
637 body = g_dbus_message_get_body(reply);
638 g_variant_get(body, "(i)", &priv_id);
640 if (cb_item->result_cb)
641 cb_item->result_cb(priv_id, result, cb_item->data);
644 if (cb_item->result_cb)
645 cb_item->result_cb(NOTIFICATION_PRIV_ID_NONE, result, cb_item->data);
649 g_object_unref(reply);
653 static int _send_async_noti(GVariant *body, result_cb_item *cb_item, char *cmd)
657 msg = g_dbus_message_new_method_call(
659 PROVIDER_OBJECT_PATH,
660 PROVIDER_NOTI_INTERFACE_NAME,
663 NOTIFICATION_ERR("Can't allocate new method call");
664 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
668 g_dbus_message_set_body(msg, body);
670 g_dbus_connection_send_message_with_reply(
673 G_DBUS_SEND_MESSAGE_FLAGS_NONE,
677 (GAsyncReadyCallback)_send_message_with_reply_async_cb,
680 NOTIFICATION_DBG("_send_async_noti done !!");
683 return NOTIFICATION_ERROR_NONE;
686 int notification_ipc_request_insert(notification_h noti, int *priv_id)
690 GDBusMessage *reply = NULL;
692 GVariant *reply_body;
694 result = _dbus_init();
695 if (result != NOTIFICATION_ERROR_NONE) {
696 NOTIFICATION_ERR("Can't init dbus %d", result);
700 /* Initialize private ID */
701 noti->priv_id = NOTIFICATION_PRIV_ID_NONE;
702 noti->group_id = NOTIFICATION_GROUP_ID_NONE;
703 noti->internal_group_id = NOTIFICATION_GROUP_ID_NONE;
706 body = notification_ipc_make_gvariant_from_noti(noti);
708 NOTIFICATION_ERR("cannot make gvariant");
709 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
712 result = _send_sync_noti(body, &reply, "add_noti");
713 NOTIFICATION_DBG("_send_sync_noti %d", result);
715 if (result == NOTIFICATION_ERROR_NONE) {
716 reply_body = g_dbus_message_get_body(reply);
717 g_variant_get(reply_body, "(i)", &id);
724 g_object_unref(reply);
726 NOTIFICATION_DBG("notification_ipc_request_insert done [priv_id : %d, result: %d]", *priv_id, result);
730 int notification_ipc_request_update(notification_h noti)
735 GDBusMessage *reply = NULL;
737 GVariant *reply_body;
739 result = _dbus_init();
740 if (result != NOTIFICATION_ERROR_NONE) {
741 NOTIFICATION_ERR("Can't init dbus %d", result);
745 body = notification_ipc_make_gvariant_from_noti(noti);
747 NOTIFICATION_ERR("cannot make gvariant");
748 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
751 result = _send_sync_noti(body, &reply, "update_noti");
752 if (result == NOTIFICATION_ERROR_NONE) {
753 reply_body = g_dbus_message_get_body(reply);
754 g_variant_get(reply_body, "(i)", &priv_id);
758 g_object_unref(reply);
760 NOTIFICATION_DBG("notification_ipc_request_update done [result: %d, priv_id :%d]", result, priv_id);
764 int notification_ipc_request_update_async(notification_h noti,
765 void (*result_cb)(int priv_id, int result, void *data), void *user_data)
768 result_cb_item *cb_item;
771 result = _dbus_init();
772 if (result != NOTIFICATION_ERROR_NONE) {
773 NOTIFICATION_ERR("Can't init dbus %d", result);
777 cb_item = calloc(1, sizeof(result_cb_item));
779 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
781 cb_item->result_cb = result_cb;
782 cb_item->data = user_data;
784 body = notification_ipc_make_gvariant_from_noti(noti);
786 NOTIFICATION_ERR("cannot make gvariant");
788 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
791 result = _send_async_noti(body, cb_item, "update_noti");
792 NOTIFICATION_DBG("notification_ipc_request_update_async done [result: %d]", result);
794 if (result != NOTIFICATION_ERROR_NONE) {
799 g_variant_unref(body);
804 int notification_ipc_request_refresh(void)
807 GDBusMessage *reply = NULL;
810 result = _dbus_init();
811 if (result != NOTIFICATION_ERROR_NONE) {
812 NOTIFICATION_ERR("Can't init dbus %d", result);
816 body = g_variant_new("(i)", NOTIFICATION_OP_REFRESH);
817 result = _send_sync_noti(body, &reply, "refresh_noti");
820 g_object_unref(reply);
822 NOTIFICATION_ERR("notification_ipc_request_refresh done [result: %d]", result);
826 int notification_ipc_request_delete_single(notification_type_e type, char *pkgname, int priv_id)
830 GDBusMessage *reply = NULL;
832 GVariant *reply_body;
834 result = _dbus_init();
835 if (result != NOTIFICATION_ERROR_NONE) {
836 NOTIFICATION_ERR("Can't init dbus %d", result);
840 body = g_variant_new("(si)", pkgname, priv_id);
841 result = _send_sync_noti(body, &reply, "del_noti_single");
843 if (result == NOTIFICATION_ERROR_NONE) {
844 reply_body = g_dbus_message_get_body(reply);
845 g_variant_get(reply_body, "(i)", &id);
849 g_object_unref(reply);
851 NOTIFICATION_ERR("notification_ipc_request_delete_single done [result: %d]", result);
855 int notification_ipc_request_delete_multiple(notification_type_e type, char *pkgname)
860 GVariant *reply_body;
861 GDBusMessage *reply = NULL;
863 result = _dbus_init();
864 if (result != NOTIFICATION_ERROR_NONE) {
865 NOTIFICATION_ERR("Can't init dbus %d", result);
869 body = g_variant_new("(si)", pkgname, type);
870 result = _send_sync_noti(body, &reply, "del_noti_multiple");
872 if (result == NOTIFICATION_ERROR_NONE) {
873 reply_body = g_dbus_message_get_body(reply);
874 g_variant_get(reply_body, "(i)", &num_deleted);
875 NOTIFICATION_ERR("num deleted:%d", num_deleted);
879 g_object_unref(reply);
884 int notification_ipc_request_load_noti_by_tag(notification_h noti, const char *pkgname, const char *tag)
887 GDBusMessage *reply = NULL;
889 GVariant *reply_body;
892 result = _dbus_init();
893 if (result != NOTIFICATION_ERROR_NONE) {
894 NOTIFICATION_ERR("Can't init dbus %d", result);
898 body = g_variant_new("(ss)", pkgname, tag);
899 result = _send_sync_noti(body, &reply, "load_noti_by_tag");
901 if (result == NOTIFICATION_ERROR_NONE) {
902 reply_body = g_dbus_message_get_body(reply);
903 g_variant_get(reply_body, "(v)", ¬i_body);
905 notification_ipc_make_noti_from_gvariant(noti, noti_body);
906 g_variant_unref(noti_body);
912 g_object_unref(reply);
914 NOTIFICATION_DBG("notification_ipc_request_load_noti_by_tag done [result: %d]", result);
918 int notification_ipc_request_load_noti_by_priv_id(notification_h noti, const char *pkgname, int priv_id)
921 GDBusMessage *reply = NULL;
923 GVariant *reply_body;
926 result = _dbus_init();
927 if (result != NOTIFICATION_ERROR_NONE) {
928 NOTIFICATION_ERR("Can't init dbus %d", result);
932 body = g_variant_new("(si)", pkgname, priv_id);
933 result = _send_sync_noti(body, &reply, "load_noti_by_priv_id");
935 if (result == NOTIFICATION_ERROR_NONE) {
936 reply_body = g_dbus_message_get_body(reply);
937 g_variant_get(reply_body, "(v)", ¬i_body);
939 notification_ipc_make_noti_from_gvariant(noti, noti_body);
940 g_variant_unref(noti_body);
945 g_object_unref(reply);
947 NOTIFICATION_DBG("notification_ipc_request_load_noti_by_priv_id done [result: %d]", result);
951 int notification_ipc_request_get_count(notification_type_e type,
952 const char *pkgname, int group_id, int priv_id, int *count)
955 GDBusMessage *reply = NULL;
957 GVariant *reply_body;
960 result = _dbus_init();
961 if (result != NOTIFICATION_ERROR_NONE) {
962 NOTIFICATION_ERR("Can't init dbus %d", result);
966 body = g_variant_new("(isii)", type, pkgname, group_id, priv_id);
967 result = _send_sync_noti(body, &reply, "get_noti_count");
969 if (result == NOTIFICATION_ERROR_NONE) {
970 reply_body = g_dbus_message_get_body(reply);
971 g_variant_get(reply_body, "(i)", &re_count);
974 NOTIFICATION_DBG("noti count [%d]", re_count);
978 g_object_unref(reply);
980 NOTIFICATION_DBG("notification_ipc_request_get_count done [result: %d]", result);
984 int notification_ipc_request_load_noti_grouping_list(notification_type_e type, int count,
985 notification_list_h *list)
988 GDBusMessage *reply = NULL;
990 GVariant *reply_body;
996 result = _dbus_init();
997 if (result != NOTIFICATION_ERROR_NONE) {
998 NOTIFICATION_ERR("Can't init dbus %d", result);
1002 body = g_variant_new("(ii)", type, count);
1003 result = _send_sync_noti(body, &reply, "load_noti_grouping_list");
1005 if (result == NOTIFICATION_ERROR_NONE) {
1006 reply_body = g_dbus_message_get_body(reply);
1007 g_variant_get(reply_body, "(a(v))", &iter);
1009 while (g_variant_iter_loop(iter, "(v)", &iter_body)) {
1010 noti = notification_create(NOTIFICATION_TYPE_NOTI);
1011 g_variant_get(iter_body, "(v)", ¬i_body);
1012 notification_ipc_make_noti_from_gvariant(noti, noti_body);
1014 *list = notification_list_append(*list, noti);
1016 g_variant_iter_free(iter);
1020 g_object_unref(reply);
1022 NOTIFICATION_DBG("notification_ipc_request_load_noti_grouping_list done [result: %d]", result);
1026 int notification_ipc_request_load_noti_detail_list(const char *pkgname,
1030 notification_list_h *list)
1033 GDBusMessage *reply = NULL;
1035 GVariant *reply_body;
1036 GVariant *iter_body;
1038 notification_h noti;
1039 GVariant *noti_body;
1041 result = _dbus_init();
1042 if (result != NOTIFICATION_ERROR_NONE) {
1043 NOTIFICATION_ERR("Can't init dbus %d", result);
1047 body = g_variant_new("(siii)", pkgname, group_id, priv_id, count);
1048 result = _send_sync_noti(body, &reply, "load_noti_detail_list");
1050 if (result == NOTIFICATION_ERROR_NONE) {
1051 reply_body = g_dbus_message_get_body(reply);
1052 g_variant_get(reply_body, "(a(v))", &iter);
1054 while (g_variant_iter_loop(iter, "(v)", &iter_body)) {
1055 noti = notification_create(NOTIFICATION_TYPE_NOTI);
1056 g_variant_get(iter_body, "(v)", ¬i_body);
1057 notification_ipc_make_noti_from_gvariant(noti, noti_body);
1059 *list = notification_list_append(*list, noti);
1061 g_variant_iter_free(iter);
1065 g_object_unref(reply);
1067 NOTIFICATION_DBG("notification_ipc_request_load_noti_detail_list done [result: %d]", result);
1071 int notification_ipc_request_get_setting_array(
1072 notification_setting_h *setting_array,
1076 GDBusMessage *reply = NULL;
1077 GVariant *reply_body;
1078 GVariant *iter_body;
1081 notification_setting_h result_setting_array;
1082 notification_setting_h temp;
1085 result = _dbus_init();
1086 if (result != NOTIFICATION_ERROR_NONE) {
1087 NOTIFICATION_ERR("Can't init dbus %d", result);
1091 result = _send_sync_noti(NULL, &reply, "get_setting_array");
1093 if (result == NOTIFICATION_ERROR_NONE) {
1094 reply_body = g_dbus_message_get_body(reply);
1095 g_variant_get(reply_body, "(ia(v))", &setting_cnt, &iter);
1097 NOTIFICATION_DBG("get setting arr cnt: %d", setting_cnt);
1098 result_setting_array = (struct notification_setting *)malloc(sizeof(struct notification_setting) * setting_cnt);
1099 if (result_setting_array == NULL) {
1100 NOTIFICATION_ERR("malloc failed");
1101 g_object_unref(reply);
1102 g_variant_iter_free(iter);
1103 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1107 while (g_variant_iter_loop(iter, "(v)", &iter_body)) {
1108 temp = result_setting_array + setting_idx;
1109 notification_ipc_make_setting_from_gvariant(temp, iter_body);
1113 *count = setting_cnt;
1114 *setting_array = result_setting_array;
1115 g_variant_iter_free(iter);
1119 g_object_unref(reply);
1121 NOTIFICATION_DBG("notification_ipc_request_get_setting_array done [result: %d]", result);
1125 int notification_ipc_request_get_setting_by_package_name(
1126 const char *package_name, notification_setting_h *setting)
1129 GDBusMessage *reply = NULL;
1131 GVariant *reply_body;
1132 GVariant *setting_body;
1133 notification_setting_h result_setting;
1135 result = _dbus_init();
1136 if (result != NOTIFICATION_ERROR_NONE) {
1137 NOTIFICATION_ERR("Can't init dbus %d", result);
1141 body = g_variant_new("(s)", package_name);
1142 result = _send_sync_noti(body, &reply, "get_setting_by_package_name");
1144 if (result == NOTIFICATION_ERROR_NONE) {
1145 reply_body = g_dbus_message_get_body(reply);
1146 g_variant_get(reply_body, "(v)", &setting_body);
1148 result_setting = (struct notification_setting *)malloc(sizeof(struct notification_setting));
1149 if (result_setting == NULL) {
1150 NOTIFICATION_ERR("malloc failed");
1151 g_object_unref(reply);
1152 g_variant_unref(body);
1153 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1155 notification_ipc_make_setting_from_gvariant(result_setting, setting_body);
1157 *setting = result_setting;
1158 g_variant_unref(setting_body);
1162 g_object_unref(reply);
1164 NOTIFICATION_DBG("notification_ipc_request_get_setting_by_package_name done [result: %d]", result);
1168 int notification_ipc_request_load_system_setting(notification_system_setting_h *setting)
1171 GDBusMessage *reply = NULL;
1172 GVariant *setting_body;
1173 GVariant *reply_body;
1174 notification_system_setting_h result_setting;
1176 result = _dbus_init();
1177 if (result != NOTIFICATION_ERROR_NONE) {
1178 NOTIFICATION_ERR("Can't init dbus %d", result);
1182 result = _send_sync_noti(NULL, &reply, "load_system_setting");
1184 if (result == NOTIFICATION_ERROR_NONE) {
1185 reply_body = g_dbus_message_get_body(reply);
1186 g_variant_get(reply_body, "(v)", &setting_body);
1188 result_setting = (struct notification_system_setting *)malloc(sizeof(struct notification_system_setting));
1189 if (result_setting == NULL) {
1190 NOTIFICATION_ERR("malloc failed");
1191 g_object_unref(reply);
1192 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1194 notification_ipc_make_system_setting_from_gvariant(result_setting, setting_body);
1196 *setting = result_setting;
1197 g_variant_unref(setting_body);
1201 g_object_unref(reply);
1203 NOTIFICATION_DBG("notification_ipc_request_load_system_setting done [result: %d]", result);
1207 int notification_ipc_update_setting(notification_setting_h setting)
1210 GDBusMessage *reply = NULL;
1213 result = _dbus_init();
1214 if (result != NOTIFICATION_ERROR_NONE) {
1215 NOTIFICATION_ERR("Can't init dbus %d", result);
1219 body = g_variant_new("(siii)",
1220 setting->package_name,
1221 (int)(setting->allow_to_notify),
1222 (int)(setting->do_not_disturb_except),
1223 (int)(setting->visibility_class));
1225 result = _send_sync_noti(body, &reply, "update_noti_setting");
1228 g_object_unref(reply);
1230 NOTIFICATION_DBG("notification_ipc_update_setting done [result: %d]", result);
1234 int notification_ipc_update_system_setting(notification_system_setting_h system_setting)
1237 GDBusMessage *reply = NULL;
1240 result = _dbus_init();
1241 if (result != NOTIFICATION_ERROR_NONE) {
1242 NOTIFICATION_ERR("Can't init dbus %d", result);
1246 body = g_variant_new("(ii)",
1247 (int)(system_setting->do_not_disturb),
1248 (int)(system_setting->visibility_class));
1250 result = _send_sync_noti(body, &reply, "update_noti_sys_setting");
1253 g_object_unref(reply);
1255 NOTIFICATION_DBG("notification_ipc_update_system_setting done [result: %d]", result);
1259 int notification_ipc_noti_setting_property_set(const char *pkgname, const char *property, const char *value)
1262 GDBusMessage *reply = NULL;
1265 result = _dbus_init();
1266 if (result != NOTIFICATION_ERROR_NONE) {
1267 NOTIFICATION_ERR("Can't init dbus %d", result);
1270 body = g_variant_new("(sss)", pkgname, property, value);
1272 result = _send_sync_noti(body, &reply, "set_noti_property");
1275 g_object_unref(reply);
1277 NOTIFICATION_DBG("notification_ipc_noti_setting_property_set done [result: %d]", result);
1281 int notification_ipc_noti_setting_property_get(const char *pkgname, const char *property, char **value)
1284 GDBusMessage *reply = NULL;
1286 GVariant *reply_body = NULL;
1289 result = _dbus_init();
1291 if (result != NOTIFICATION_ERROR_NONE) {
1292 NOTIFICATION_ERR("Can't init dbus %d", result);
1296 body = g_variant_new("(ss)", pkgname, property);
1297 result = _send_sync_noti(body, &reply, "get_noti_property");
1299 if (result == NOTIFICATION_ERROR_NONE) {
1300 reply_body = g_dbus_message_get_body(reply);
1301 g_variant_get(body, "(s)", &ret_val);
1303 if (ret_val != NULL) {
1304 *value = g_strdup(ret_val);
1310 g_object_unref(reply);
1312 NOTIFICATION_DBG("notification_ipc_noti_setting_property_get done [result: %d]", result);
1316 EXPORT_API GVariant *notification_ipc_make_gvariant_from_noti(notification_h noti)
1318 NOTIFICATION_DBG("make gvariant from noti");
1320 int b_encode_len = 0;
1321 bundle_raw *args = NULL;
1322 bundle_raw *group_args = NULL;
1323 bundle_raw *b_image_path = NULL;
1324 bundle_raw *b_execute_option = NULL;
1325 bundle_raw *b_service_responding = NULL;
1326 bundle_raw *b_service_single_launch = NULL;
1327 bundle_raw *b_service_multi_launch = NULL;
1328 bundle_raw *b_event_handler[NOTIFICATION_EVENT_TYPE_MAX] = {NULL, };
1329 bundle_raw *b_text = NULL;
1330 bundle_raw *b_key = NULL;
1331 bundle_raw *b_format_args = NULL;
1332 GVariant *body = NULL;
1333 GVariant *result_body = NULL;
1334 GVariantBuilder builder;
1336 g_variant_builder_init(&builder, G_VARIANT_TYPE("a{iv}"));
1337 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_NOTI_TYPE, g_variant_new_int32(noti->type));
1338 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_LAYOUT, g_variant_new_int32(noti->layout));
1339 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_GROUP_ID, g_variant_new_int32(noti->group_id));
1340 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_INTERNAL_GROUP_ID, g_variant_new_int32(noti->internal_group_id));
1341 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_PRIV_ID, g_variant_new_int32(noti->priv_id));
1342 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_CALLER_PKGNAME, g_variant_new_string((const gchar *)noti->caller_pkgname));
1343 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_DISPLAY_APPLIST, g_variant_new_int32(noti->display_applist));
1346 bundle_encode(noti->args, (bundle_raw **)&args, NULL);
1347 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_ARGS, g_variant_new_string((const gchar *)args));
1350 bundle_free_encoded_rawdata(&args);
1353 if (noti->group_args) {
1354 bundle_encode(noti->group_args, (bundle_raw **)&group_args,
1356 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_GROUP_ARGS, g_variant_new_string((const gchar *)group_args));
1359 bundle_free_encoded_rawdata(&group_args);
1362 if (noti->b_execute_option) {
1363 bundle_encode(noti->b_execute_option,
1364 (bundle_raw **)&b_execute_option, &b_encode_len);
1365 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_EXECUTE_OPTION, g_variant_new_string((const gchar *)b_execute_option));
1367 if (b_execute_option)
1368 bundle_free_encoded_rawdata(&b_execute_option);
1371 if (noti->b_service_responding) {
1372 bundle_encode(noti->b_service_responding,
1373 (bundle_raw **)&b_service_responding, &b_encode_len);
1374 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_SERVICE_RESPONDING, g_variant_new_string((const gchar *)b_service_responding));
1376 if (b_service_responding)
1377 bundle_free_encoded_rawdata(&b_service_responding);
1380 if (noti->b_service_single_launch) {
1381 bundle_encode(noti->b_service_single_launch,
1382 (bundle_raw **)&b_service_single_launch, &b_encode_len);
1383 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_SERVICE_SINGLE_LAUNCH, g_variant_new_string((const gchar *)b_service_single_launch));
1385 if (b_service_single_launch)
1386 bundle_free_encoded_rawdata(&b_service_single_launch);
1389 if (noti->b_service_multi_launch) {
1390 bundle_encode(noti->b_service_multi_launch,
1391 (bundle_raw **)&b_service_multi_launch, &b_encode_len);
1392 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_SERVICE_MULTI_LAUNCH, g_variant_new_string((const gchar *)b_service_multi_launch));
1394 if (b_service_multi_launch)
1395 bundle_free_encoded_rawdata(&b_service_multi_launch);
1398 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
1399 if (noti->b_event_handler[i]) {
1400 bundle_encode(noti->b_event_handler[i],
1401 (bundle_raw **)&b_event_handler[i], &b_encode_len);
1402 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_BUTTON1_EVENT + i, g_variant_new_string((const gchar *)b_event_handler[i]));
1404 if (b_event_handler[i])
1405 bundle_free_encoded_rawdata(&b_event_handler[i]);
1409 if (noti->launch_pkgname)
1410 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_LAUNCH_PKGNAME, g_variant_new_string((const gchar *)noti->launch_pkgname));
1412 if (noti->domain != NULL)
1413 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_DOMAIN, g_variant_new_string((const gchar *)noti->domain));
1415 if (noti->dir != NULL)
1416 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_DIR, g_variant_new_string((const gchar *)noti->dir));
1419 bundle_encode(noti->b_text, (bundle_raw **)&b_text, &b_encode_len);
1420 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_TEXT, g_variant_new_string((const gchar *)b_text));
1423 bundle_free_encoded_rawdata(&b_text);
1427 bundle_encode(noti->b_key, (bundle_raw **)&b_key, &b_encode_len);
1428 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_KEY, g_variant_new_string((const gchar *)b_key));
1431 bundle_free_encoded_rawdata(&b_key);
1434 if (noti->b_format_args) {
1435 bundle_encode(noti->b_format_args,
1436 (bundle_raw **)&b_format_args, &b_encode_len);
1437 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_FORMAT_ARGS, g_variant_new_string((const gchar *)b_format_args));
1440 bundle_free_encoded_rawdata(&b_format_args);
1443 if (noti->num_format_args != 0)
1444 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_NUM_FORMAT_ARGS, g_variant_new_int32(noti->num_format_args));
1446 if (noti->b_image_path) {
1447 bundle_encode(noti->b_image_path,
1448 (bundle_raw **)&b_image_path, &b_encode_len);
1449 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_IMAGE_PATH, g_variant_new_string((const gchar *)b_image_path));
1452 bundle_free_encoded_rawdata(&b_image_path);
1455 if (noti->sound_type != NOTIFICATION_SOUND_TYPE_NONE)
1456 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_SOUND_TYPE, g_variant_new_int32(noti->sound_type));
1458 if (noti->sound_path)
1459 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_SOUND_PATH, g_variant_new_string((const gchar *)noti->sound_path));
1461 if (noti->vibration_type != NOTIFICATION_VIBRATION_TYPE_NONE)
1462 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_VIBRATION_TYPE, g_variant_new_int32(noti->vibration_type));
1464 if (noti->vibration_path)
1465 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_VIBRATION_PATH, g_variant_new_string((const gchar *)noti->vibration_path));
1467 if (noti->led_operation != NOTIFICATION_LED_OP_OFF)
1468 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_LED_OPERATION, g_variant_new_int32(noti->led_operation));
1470 if (noti->led_argb != 0)
1471 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_LED_ARGB, g_variant_new_int32(noti->led_argb));
1473 if (noti->led_on_ms != 0)
1474 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_LED_ON_MS, g_variant_new_int32(noti->led_on_ms));
1476 if (noti->led_off_ms != 0)
1477 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_LED_OFF_MS, g_variant_new_int32(noti->led_off_ms));
1479 if (noti->time != 0)
1480 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_TIME, g_variant_new_int32(noti->time));
1482 if (noti->insert_time != 0)
1483 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_INSERT_TIME, g_variant_new_int32(noti->insert_time));
1485 if (noti->flags_for_property != 0)
1486 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_FLAGS_FOR_PROPERTY, g_variant_new_int32(noti->flags_for_property));
1488 if (noti->progress_size != 0.0)
1489 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_PROGRESS_SIZE, g_variant_new_double(noti->progress_size));
1491 if (noti->progress_percentage != 0.0)
1492 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_PROGRESS_PERCENTAGE, g_variant_new_double(noti->progress_percentage));
1494 if (noti->app_icon_path != NULL)
1495 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_APP_ICON_PATH, g_variant_new_string((const gchar *)noti->app_icon_path));
1496 if (noti->app_name != NULL)
1497 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_APP_NAME, g_variant_new_string((const gchar *)noti->app_name));
1498 if (noti->temp_title != NULL)
1499 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_TEMP_TITLE, g_variant_new_string((const gchar *)noti->temp_title));
1500 if (noti->temp_content != NULL)
1501 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_TEMP_CONTENT, g_variant_new_string((const gchar *)noti->temp_content));
1502 if (noti->tag != NULL)
1503 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_TAG, g_variant_new_string((const gchar *)noti->tag));
1505 if (noti->ongoing_flag != 0)
1506 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_ONGOING_FLAG, g_variant_new_int32(noti->ongoing_flag));
1507 if (noti->auto_remove != 0)
1508 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_AUTO_REMOVE, g_variant_new_int32(noti->auto_remove));
1510 result_body = g_variant_builder_end(&builder);
1511 body = g_variant_new("(v)", result_body);
1516 static gboolean _variant_to_int_dict(GHashTable **dict, GVariant *variant) {
1523 *dict = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, (GDestroyNotify)g_variant_unref);
1527 g_variant_iter_init(&iter, variant);
1528 while (g_variant_iter_next(&iter, "{iv}", &key, &value)) {
1529 hash_key = (int *)calloc(sizeof(int), 1);
1530 if (hash_key == NULL) {
1531 g_hash_table_remove_all(*dict);
1535 g_hash_table_insert(*dict, (gpointer)hash_key, value);
1540 static gboolean _variant_dict_lookup(GHashTable *dict,
1542 const gchar *format_string,
1548 value = g_hash_table_lookup(dict, (gpointer)&key);
1550 if (value == NULL || !g_variant_check_format_string(value, format_string, FALSE))
1553 va_start(ap, format_string);
1554 g_variant_get_va(value, format_string, NULL, &ap);
1561 * functions creating notification packet
1563 EXPORT_API int notification_ipc_make_noti_from_gvariant(notification_h noti,
1564 GVariant *variant) {
1566 NOTIFICATION_DBG("make noti from GVariant");
1570 char *caller_pkgname = NULL;
1571 char *launch_pkgname = NULL;
1572 bundle_raw *args = NULL;
1573 bundle_raw *group_args = NULL;
1574 bundle_raw *b_execute_option = NULL;
1575 bundle_raw *b_service_responding = NULL;
1576 bundle_raw *b_service_single_launch = NULL;
1577 bundle_raw *b_service_multi_launch = NULL;
1578 bundle_raw *b_event_handler[NOTIFICATION_EVENT_TYPE_MAX] = { NULL, };
1579 char *domain = NULL;
1581 bundle_raw *b_text = NULL;
1582 bundle_raw *b_key = NULL;
1583 bundle_raw *b_format_args = NULL;
1584 bundle_raw *b_image_path = NULL;
1585 char *sound_path = NULL;
1586 char *vibration_path = NULL;
1587 char *app_icon_path = NULL;
1588 char *app_name = NULL;
1589 char *temp_title = NULL;
1590 char *temp_content = NULL;
1594 NOTIFICATION_ERR("invalid data noti NULL");
1595 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1598 if (variant == NULL) {
1599 NOTIFICATION_ERR("invalid data variant NULL");
1600 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1603 if (!_variant_to_int_dict(&dict, variant))
1604 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1606 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_NOTI_TYPE, "i", ¬i->type);
1607 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_LAYOUT, "i", ¬i->layout);
1608 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_GROUP_ID, "i", ¬i->group_id);
1609 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_INTERNAL_GROUP_ID, "i", ¬i->internal_group_id);
1610 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_PRIV_ID, "i", ¬i->priv_id);
1611 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_CALLER_PKGNAME, "&s", &caller_pkgname);
1612 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_LAUNCH_PKGNAME, "&s", &launch_pkgname);
1613 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_ARGS, "&s", &args);
1614 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_GROUP_ARGS, "&s", &group_args);
1615 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_EXECUTE_OPTION, "&s", &b_execute_option);
1616 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_SERVICE_RESPONDING, "&s", &b_service_responding);
1617 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_SERVICE_SINGLE_LAUNCH, "&s", &b_service_single_launch);
1618 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_SERVICE_MULTI_LAUNCH, "&s", &b_service_multi_launch);
1619 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_BUTTON1_EVENT, "&s", ¬i->b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1]);
1620 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_BUTTON2_EVENT, "&s", ¬i->b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_2]);
1621 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_BUTTON3_EVENT, "&s", ¬i->b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_3]);
1622 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_BUTTON4_EVENT, "&s", ¬i->b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_4]);
1623 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_BUTTON5_EVENT, "&s", ¬i->b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_5]);
1624 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_BUTTON6_EVENT, "&s", ¬i->b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_6]);
1625 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_ICON_EVENT, "&s", ¬i->b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_ICON]);
1626 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_THUMBNAIL_EVENT, "&s", ¬i->b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL]);
1627 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_DOMAIN, "&s", &domain);
1628 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_DIR, "&s", &dir);
1629 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_TEXT, "&s", &b_text);
1630 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_KEY, "&s", &b_key);
1631 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_FORMAT_ARGS, "&s", &b_format_args);
1632 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_NUM_FORMAT_ARGS, "i", ¬i->num_format_args);
1633 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_IMAGE_PATH, "&s", &b_image_path);
1634 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_SOUND_TYPE, "i", ¬i->sound_type);
1635 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_SOUND_PATH, "&s", &sound_path);
1636 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_VIBRATION_TYPE, "i", ¬i->vibration_type);
1637 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_VIBRATION_PATH, "&s", &vibration_path);
1638 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_LED_OPERATION, "i", ¬i->led_operation);
1639 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_LED_ARGB, "i", ¬i->led_argb);
1640 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_LED_ON_MS, "i", ¬i->led_on_ms);
1641 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_LED_OFF_MS, "i", ¬i->led_off_ms);
1642 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_TIME, "i", ¬i->time);
1643 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_INSERT_TIME, "i", ¬i->insert_time);
1644 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_FLAGS_FOR_PROPERTY, "i", ¬i->flags_for_property);
1645 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_DISPLAY_APPLIST, "i", ¬i->display_applist);
1646 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_PROGRESS_SIZE, "d", ¬i->progress_size);
1647 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_PROGRESS_PERCENTAGE, "d", ¬i->progress_percentage);
1648 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_APP_ICON_PATH, "&s", &app_icon_path);
1649 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_APP_NAME, "&s", &app_name);
1650 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_TEMP_TITLE, "&s", &temp_title);
1651 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_TEMP_CONTENT, "&s", &temp_content);
1652 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_TAG, "&s", &tag);
1653 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_ONGOING_FLAG, "i", ¬i->ongoing_flag);
1654 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_AUTO_REMOVE, "i", ¬i->auto_remove);
1656 noti->caller_pkgname = _dup_string(caller_pkgname);
1657 noti->launch_pkgname = _dup_string(launch_pkgname);
1658 noti->args = _create_bundle_from_bundle_raw(args);
1659 noti->group_args = _create_bundle_from_bundle_raw(group_args);
1660 noti->b_execute_option = _create_bundle_from_bundle_raw(b_execute_option);
1661 noti->b_service_responding = _create_bundle_from_bundle_raw(
1662 b_service_responding);
1663 noti->b_service_single_launch = _create_bundle_from_bundle_raw(
1664 b_service_single_launch);
1665 noti->b_service_multi_launch = _create_bundle_from_bundle_raw(
1666 b_service_multi_launch);
1667 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
1668 noti->b_event_handler[i] = _create_bundle_from_bundle_raw(
1669 b_event_handler[i]);
1671 noti->domain = _dup_string(domain);
1672 noti->dir = _dup_string(dir);
1673 noti->b_text = _create_bundle_from_bundle_raw(b_text);
1674 noti->b_key = _create_bundle_from_bundle_raw(b_key);
1675 noti->b_format_args = _create_bundle_from_bundle_raw(b_format_args);
1676 noti->b_image_path = _create_bundle_from_bundle_raw(b_image_path);
1677 noti->sound_path = _dup_string(sound_path);
1678 noti->vibration_path = _dup_string(vibration_path);
1679 noti->app_icon_path = _dup_string(app_icon_path);
1680 noti->app_name = _dup_string(app_name);
1681 noti->temp_title = _dup_string(temp_title);
1682 noti->temp_content = _dup_string(temp_content);
1683 noti->tag = _dup_string(tag);
1685 g_hash_table_remove_all(dict);
1687 return NOTIFICATION_ERROR_NONE;
1690 EXPORT_API GVariant *notification_ipc_make_gvariant_from_system_setting(struct notification_system_setting *noti_setting)
1692 GVariant *body = NULL;
1693 body = g_variant_new("(ii)",
1694 noti_setting->do_not_disturb,
1695 noti_setting->visibility_class);
1699 EXPORT_API int notification_ipc_make_system_setting_from_gvariant(struct notification_system_setting *noti_setting,
1703 int visibility_class;
1705 if (noti_setting == NULL) {
1706 NOTIFICATION_ERR("invalid data");
1707 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1709 g_variant_get(variant,
1714 NOTIFICATION_DBG("system setting #### %d, %d",
1715 do_not_disturb, visibility_class);
1717 noti_setting->do_not_disturb = do_not_disturb;
1718 noti_setting->visibility_class = visibility_class;
1720 NOTIFICATION_DBG("system setting2 #### %d, %d",
1721 noti_setting->do_not_disturb, noti_setting->visibility_class);
1723 return NOTIFICATION_ERROR_NONE;
1726 EXPORT_API GVariant *notification_ipc_make_gvariant_from_setting(struct notification_setting *noti_setting)
1728 GVariant *body = NULL;
1730 body = g_variant_new("(siii)",
1731 noti_setting->package_name,
1732 noti_setting->allow_to_notify,
1733 noti_setting->do_not_disturb_except,
1734 noti_setting->visibility_class);
1739 EXPORT_API int notification_ipc_make_setting_from_gvariant(struct notification_setting *noti_setting,
1742 NOTIFICATION_DBG("notification_ipc_make_setting_from_gvariant !!!!");
1744 int allow_to_notify;
1745 int do_not_disturb_except;
1746 int visibility_class;
1748 if (noti_setting == NULL || variant == NULL) {
1749 NOTIFICATION_ERR("invalid data");
1750 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1752 g_variant_get(variant,
1756 &do_not_disturb_except,
1759 NOTIFICATION_DBG("setting from variant %s !!", pkgname);
1761 noti_setting->package_name = _dup_string(pkgname);
1762 noti_setting->allow_to_notify = allow_to_notify;
1763 noti_setting->do_not_disturb_except = do_not_disturb_except;
1764 noti_setting->visibility_class = visibility_class;
1766 NOTIFICATION_DBG("setting from variant %s, %s",
1767 noti_setting->package_name, pkgname);
1769 return NOTIFICATION_ERROR_NONE;
1772 static int _send_service_register()
1774 NOTIFICATION_DBG("service register");
1775 GDBusMessage *reply = NULL;
1778 result = _send_sync_noti(NULL, &reply, "noti_service_register");
1781 g_object_unref(reply);
1783 NOTIFICATION_ERR("_send_service_register done = %s, result = %d", _bus_name, result);
1787 static int _ipc_monitor_register(void)
1789 NOTIFICATION_ERR("register a service\n");
1791 return _send_service_register();
1794 static void _on_name_appeared(GDBusConnection *connection,
1796 const gchar *name_owner,
1799 NOTIFICATION_DBG("name appeared : %s", name);
1800 is_master_started = 1;
1801 _ipc_monitor_register();
1803 /* TODO: dbus activation isn't enough ? */
1804 _do_deffered_task();
1807 static void _on_name_vanished(GDBusConnection *connection,
1811 NOTIFICATION_DBG("name vanished : %s", name);
1812 is_master_started = 0;
1815 int notification_ipc_monitor_init(void)
1820 if (ret != NOTIFICATION_ERROR_NONE) {
1821 NOTIFICATION_ERR("Can't init dbus %d", ret);
1825 ret = _dbus_signal_init();
1826 if (ret != NOTIFICATION_ERROR_NONE) {
1827 NOTIFICATION_ERR("Can't signal_init %d", ret);
1831 ret = _ipc_monitor_register();
1832 if (ret != NOTIFICATION_ERROR_NONE) {
1833 NOTIFICATION_ERR("Can't init ipc_monitor_register %d", ret);
1837 if (provider_monitor_id == 0) {
1838 provider_monitor_id = g_bus_watch_name_on_connection(
1841 G_BUS_NAME_WATCHER_FLAGS_NONE,
1847 if (provider_monitor_id == 0) {
1848 g_dbus_connection_signal_unsubscribe(_gdbus_conn, monitor_id);
1850 NOTIFICATION_ERR("watch on name fail");
1851 return NOTIFICATION_ERROR_IO_ERROR;
1855 return NOTIFICATION_ERROR_NONE;
1858 static int _ipc_monitor_deregister(void)
1860 if (provider_monitor_id) {
1861 g_bus_unwatch_name(provider_monitor_id);
1862 provider_monitor_id = 0;
1866 g_dbus_connection_signal_unsubscribe(_gdbus_conn, monitor_id);
1870 return NOTIFICATION_ERROR_NONE;
1873 int notification_ipc_monitor_fini(void)
1875 return _ipc_monitor_deregister();