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 typedef struct _result_cb_item {
55 void (*result_cb)(int priv_id, int result, void *data);
59 typedef struct _task_list task_list;
64 void (*task_cb) (void *data);
68 static task_list *g_task_list;
70 static int _ipc_monitor_register(void);
71 static int _ipc_monitor_deregister(void);
72 static void _do_deffered_task(void);
74 static void _print_noti(notification_h noti) {
78 const char *tag = NULL;
80 notification_get_pkgname(noti, &pkgname);
81 notification_get_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, &text);
82 notification_get_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, &content);
83 notification_get_tag(noti, &tag);
85 NOTIFICATION_DBG("client print_noti pkgname = %s ", pkgname );
86 NOTIFICATION_DBG("client print_noti title = %s ", text );
87 NOTIFICATION_DBG("client print_noti content = %s ", content );
88 NOTIFICATION_DBG("client print_noti tag = %s ", tag );
89 NOTIFICATION_DBG("client print_noti priv_id = %d ", noti->priv_id);
90 NOTIFICATION_DBG("client print_noti vibration_path = %s ", noti->vibration_path);
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)
293 if (string[0] == '\0')
296 ret = strdup(string);
298 NOTIFICATION_ERR("Error: %s\n", strerror(errno));
303 static inline bundle *_create_bundle_from_bundle_raw(bundle_raw *string)
307 if (string[0] == '\0')
310 return bundle_decode(string, strlen((char *)string));
313 static void _add_noti_notify(GVariant *parameters)
316 notification_op *noti_op;
317 GVariant *body = NULL;
319 NOTIFICATION_DBG("add noti notify");
320 noti = notification_create(NOTIFICATION_TYPE_NOTI);
322 NOTIFICATION_ERR("failed to create a notification");
326 g_variant_get(parameters, "(v)", &body);
327 notification_ipc_make_noti_from_gvariant(noti, body);
329 if (noti->flags_for_property & NOTIFICATION_PROP_DISABLE_UPDATE_ON_INSERT) {
330 NOTIFICATION_ERR("disable changed callback %d", noti->flags_for_property);
331 /* Disable changed cb */
333 /* Enable changed cb */
334 noti_op = _ipc_create_op(NOTIFICATION_OP_INSERT, 1, &(noti->priv_id), 1, ¬i);
336 if (noti_op != NULL) {
337 notification_call_changed_cb(noti_op, 1);
341 notification_free(noti);
344 static void _update_noti_notify(GVariant *parameters)
347 notification_op *noti_op;
348 GVariant *body = NULL;
350 noti = notification_create(NOTIFICATION_TYPE_NOTI);
352 NOTIFICATION_ERR("failed to create a notification");
355 g_variant_get(parameters, "(v)", &body);
356 notification_ipc_make_noti_from_gvariant(noti, body);
359 noti_op = _ipc_create_op(NOTIFICATION_OP_UPDATE, 1, &(noti->priv_id), 1, ¬i);
360 if (noti_op != NULL) {
361 notification_call_changed_cb(noti_op, 1);
364 notification_free(noti);
367 static void _refresh_noti_notify(GVariant *parameters)
369 notification_op *noti_op = _ipc_create_op(NOTIFICATION_OP_REFRESH, 1, NULL, 0, NULL);
371 if (noti_op != NULL) {
372 notification_call_changed_cb(noti_op, 1);
377 static void _delete_single_notify(GVariant *parameters)
381 notification_op *noti_op;
384 g_variant_get(parameters, "(ii)", &num_deleted, &priv_id);
386 noti_op = _ipc_create_op(NOTIFICATION_OP_DELETE, 1, &priv_id, 1, NULL);
387 if (noti_op != NULL) {
388 notification_call_changed_cb(noti_op, 1);
393 static void _delete_multiple_notify(GVariant *parameters)
397 notification_op *noti_op;
400 g_variant_get(parameters, "(a(i))", &iter);
401 while (g_variant_iter_loop(iter, "(i)", &buf[idx])) {
402 NOTIFICATION_DBG("delete_noti_multiple priv_id : %d", buf[idx]);
405 g_variant_iter_free(iter);
407 NOTIFICATION_DBG("data num deleted:%d", idx);
408 noti_op = _ipc_create_op(NOTIFICATION_OP_DELETE, idx, buf, idx, NULL);
410 if (noti_op == NULL) {
411 NOTIFICATION_ERR("_ipc_create_op failed");
414 notification_call_changed_cb(noti_op, idx);
418 static void _handle_noti_notify(GDBusConnection *connection,
419 const gchar *sender_name,
420 const gchar *object_path,
421 const gchar *interface_name,
422 const gchar *signal_name,
423 GVariant *parameters,
426 NOTIFICATION_DBG("signal_name: %s", signal_name);
428 if (g_strcmp0(signal_name, "add_noti_notify") == 0)
429 _add_noti_notify(parameters);
430 else if (g_strcmp0(signal_name, "update_noti_notify") == 0)
431 _update_noti_notify(parameters);
432 else if (g_strcmp0(signal_name, "delete_single_notify") == 0)
433 _delete_single_notify(parameters);
434 else if (g_strcmp0(signal_name, "delete_multiple_notify") == 0)
435 _delete_multiple_notify(parameters);
436 else if (g_strcmp0(signal_name, "refresh_noti_notify") == 0)
437 _refresh_noti_notify(parameters);
441 static int _dbus_signal_init()
444 int ret = NOTIFICATION_ERROR_NONE;
446 if (monitor_id == 0) {
447 id = g_dbus_connection_signal_subscribe(_gdbus_conn,
449 PROVIDER_NOTI_INTERFACE_NAME, /* interface */
451 PROVIDER_OBJECT_PATH, /* path */
453 G_DBUS_SIGNAL_FLAGS_NONE,
458 NOTIFICATION_DBG("subscribe id : %d", id);
460 ret = NOTIFICATION_ERROR_IO_ERROR;
461 NOTIFICATION_ERR("Failed to _register_noti_dbus_interface");
464 ret = NOTIFICATION_ERROR_NONE;
471 static int _dbus_init()
473 int ret = NOTIFICATION_ERROR_NONE;
474 GError *error = NULL;
476 if (_gdbus_conn == NULL) {
477 _gdbus_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
479 if (_gdbus_conn == NULL) {
481 NOTIFICATION_ERR("Failed to get dbus [%s]", error->message);
484 return NOTIFICATION_ERROR_IO_ERROR;
486 _bus_name = g_dbus_connection_get_unique_name(_gdbus_conn);
487 NOTIFICATION_DBG("bus name : %s", _bus_name);
489 notification_error_quark();
491 ret = NOTIFICATION_ERROR_NONE;
496 static int _send_sync_noti(GVariant *body, GDBusMessage **reply, char *cmd)
498 int ret = NOTIFICATION_ERROR_NONE;
502 msg = g_dbus_message_new_method_call(
504 PROVIDER_OBJECT_PATH,
505 PROVIDER_NOTI_INTERFACE_NAME,
508 NOTIFICATION_ERR("Can't allocate new method call");
510 g_variant_unref(body);
511 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
515 g_dbus_message_set_body(msg, body);
517 *reply = g_dbus_connection_send_message_with_reply_sync(
520 G_DBUS_SEND_MESSAGE_FLAGS_NONE,
529 ret = NOTIFICATION_ERROR_SERVICE_NOT_READY;
531 NOTIFICATION_ERR("No reply. cmd = %s, error = %s", cmd, err->message);
532 if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
533 ret = NOTIFICATION_ERROR_PERMISSION_DENIED;
539 if (g_dbus_message_to_gerror(*reply, &err)) {
541 NOTIFICATION_ERR("_send_sync_noti cmd = %s, error %s", cmd, err->message);
545 NOTIFICATION_DBG("_send_sync_noti done !!");
546 return NOTIFICATION_ERROR_NONE;
550 static void _send_message_with_reply_async_cb(GDBusConnection *connection,
555 int result = NOTIFICATION_ERROR_NONE;
557 GDBusMessage *reply = NULL;
559 result_cb_item *cb_item = (result_cb_item *)user_data;
561 if (cb_item == NULL) {
562 NOTIFICATION_ERR("Failed to get a callback item");
566 reply = g_dbus_connection_send_message_with_reply_finish(
573 NOTIFICATION_ERR("No reply. error = %s", err->message);
576 result = NOTIFICATION_ERROR_SERVICE_NOT_READY;
578 } else if (g_dbus_message_to_gerror(reply, &err)) {
581 NOTIFICATION_ERR("_send_async_noti error %s", err->message);
584 NOTIFICATION_DBG("_send_async_noti done !![%d]", result);
586 if (result == NOTIFICATION_ERROR_NONE) {
587 body = g_dbus_message_get_body(reply);
588 g_variant_get(body, "(i)", &priv_id);
590 if (cb_item->result_cb)
591 cb_item->result_cb(priv_id, result, cb_item->data);
594 if (cb_item->result_cb)
595 cb_item->result_cb(NOTIFICATION_PRIV_ID_NONE, result, cb_item->data);
599 g_object_unref(reply);
603 static int _send_async_noti(GVariant *body, result_cb_item *cb_item, char *cmd)
607 msg = g_dbus_message_new_method_call(
609 PROVIDER_OBJECT_PATH,
610 PROVIDER_NOTI_INTERFACE_NAME,
613 NOTIFICATION_ERR("Can't allocate new method call");
614 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
618 g_dbus_message_set_body(msg, body);
620 g_dbus_connection_send_message_with_reply(
623 G_DBUS_SEND_MESSAGE_FLAGS_NONE,
627 (GAsyncReadyCallback)_send_message_with_reply_async_cb,
630 NOTIFICATION_DBG("_send_async_noti done !!");
633 return NOTIFICATION_ERROR_NONE;
636 int notification_ipc_request_insert(notification_h noti, int *priv_id)
640 GDBusMessage *reply = NULL;
642 GVariant *reply_body;
644 result = _dbus_init();
645 if (result != NOTIFICATION_ERROR_NONE) {
646 NOTIFICATION_ERR("Can't init dbus %d", result);
650 /* Initialize private ID */
651 noti->priv_id = NOTIFICATION_PRIV_ID_NONE;
652 noti->group_id = NOTIFICATION_GROUP_ID_NONE;
653 noti->internal_group_id = NOTIFICATION_GROUP_ID_NONE;
656 body = notification_ipc_make_gvariant_from_noti(noti);
658 NOTIFICATION_ERR("cannot make gvariant");
659 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
662 result = _send_sync_noti(body, &reply, "add_noti");
663 NOTIFICATION_DBG("_send_sync_noti %d", result);
665 if (result == NOTIFICATION_ERROR_NONE) {
666 reply_body = g_dbus_message_get_body(reply);
667 g_variant_get(reply_body, "(i)", &id);
674 g_object_unref(reply);
676 NOTIFICATION_DBG("notification_ipc_request_insert done [priv_id : %d, result: %d]", *priv_id, result);
680 int notification_ipc_request_update(notification_h noti)
685 GDBusMessage *reply = NULL;
687 GVariant *reply_body;
689 result = _dbus_init();
690 if (result != NOTIFICATION_ERROR_NONE) {
691 NOTIFICATION_ERR("Can't init dbus %d", result);
695 body = notification_ipc_make_gvariant_from_noti(noti);
697 NOTIFICATION_ERR("cannot make gvariant");
698 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
701 result = _send_sync_noti(body, &reply, "update_noti");
702 if (result == NOTIFICATION_ERROR_NONE) {
703 reply_body = g_dbus_message_get_body(reply);
704 g_variant_get(reply_body, "(i)", &priv_id);
708 g_object_unref(reply);
710 NOTIFICATION_DBG("notification_ipc_request_update done [result: %d, priv_id :%d]", result, priv_id);
714 int notification_ipc_request_update_async(notification_h noti,
715 void (*result_cb)(int priv_id, int result, void *data), void *user_data)
718 result_cb_item *cb_item;
721 result = _dbus_init();
722 if (result != NOTIFICATION_ERROR_NONE) {
723 NOTIFICATION_ERR("Can't init dbus %d", result);
727 cb_item = calloc(1, sizeof(result_cb_item));
729 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
731 cb_item->result_cb = result_cb;
732 cb_item->data = user_data;
734 body = notification_ipc_make_gvariant_from_noti(noti);
736 NOTIFICATION_ERR("cannot make gvariant");
738 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
741 result = _send_async_noti(body, cb_item, "update_noti");
742 NOTIFICATION_DBG("notification_ipc_request_update_async done [result: %d]", result);
744 if (result != NOTIFICATION_ERROR_NONE) {
749 g_variant_unref(body);
754 int notification_ipc_request_refresh(void)
757 GDBusMessage *reply = NULL;
760 result = _dbus_init();
761 if (result != NOTIFICATION_ERROR_NONE) {
762 NOTIFICATION_ERR("Can't init dbus %d", result);
766 body = g_variant_new("(i)", NOTIFICATION_OP_REFRESH);
767 result = _send_sync_noti(body, &reply, "refresh_noti");
770 g_object_unref(reply);
772 NOTIFICATION_ERR("notification_ipc_request_refresh done [result: %d]", result);
776 int notification_ipc_request_delete_single(notification_type_e type, char *pkgname, int priv_id)
780 GDBusMessage *reply = NULL;
782 GVariant *reply_body;
784 result = _dbus_init();
785 if (result != NOTIFICATION_ERROR_NONE) {
786 NOTIFICATION_ERR("Can't init dbus %d", result);
790 body = g_variant_new("(si)", pkgname, priv_id);
791 result = _send_sync_noti(body, &reply, "del_noti_single");
793 if (result == NOTIFICATION_ERROR_NONE) {
794 reply_body = g_dbus_message_get_body(reply);
795 g_variant_get(reply_body, "(i)", &id);
799 g_object_unref(reply);
801 NOTIFICATION_ERR("notification_ipc_request_delete_single done [result: %d]", result);
805 int notification_ipc_request_delete_multiple(notification_type_e type, char *pkgname)
810 GVariant *reply_body;
811 GDBusMessage *reply = NULL;
813 result = _dbus_init();
814 if (result != NOTIFICATION_ERROR_NONE) {
815 NOTIFICATION_ERR("Can't init dbus %d", result);
819 body = g_variant_new("(si)", pkgname, type);
820 result = _send_sync_noti(body, &reply, "del_noti_multiple");
822 if (result == NOTIFICATION_ERROR_NONE) {
823 reply_body = g_dbus_message_get_body(reply);
824 g_variant_get(reply_body, "(i)", &num_deleted);
825 NOTIFICATION_ERR("num deleted:%d", num_deleted);
829 g_object_unref(reply);
834 int notification_ipc_request_load_noti_by_tag(notification_h noti, const char *pkgname, const char *tag)
837 GDBusMessage *reply = NULL;
839 GVariant *reply_body;
842 result = _dbus_init();
843 if (result != NOTIFICATION_ERROR_NONE) {
844 NOTIFICATION_ERR("Can't init dbus %d", result);
848 body = g_variant_new("(ss)", pkgname, tag);
849 result = _send_sync_noti(body, &reply, "load_noti_by_tag");
851 if (result == NOTIFICATION_ERROR_NONE) {
852 reply_body = g_dbus_message_get_body(reply);
853 g_variant_get(reply_body, "(v)", ¬i_body);
855 notification_ipc_make_noti_from_gvariant(noti, noti_body);
856 g_variant_unref(noti_body);
862 g_object_unref(reply);
864 NOTIFICATION_DBG("notification_ipc_request_load_noti_by_tag done [result: %d]", result);
868 int notification_ipc_request_load_noti_by_priv_id(notification_h noti, const char *pkgname, int priv_id)
871 GDBusMessage *reply = NULL;
873 GVariant *reply_body;
876 result = _dbus_init();
877 if (result != NOTIFICATION_ERROR_NONE) {
878 NOTIFICATION_ERR("Can't init dbus %d", result);
882 body = g_variant_new("(si)", pkgname, priv_id);
883 result = _send_sync_noti(body, &reply, "load_noti_by_priv_id");
885 if (result == NOTIFICATION_ERROR_NONE) {
886 reply_body = g_dbus_message_get_body(reply);
887 g_variant_get(reply_body, "(v)", ¬i_body);
889 notification_ipc_make_noti_from_gvariant(noti, noti_body);
890 g_variant_unref(noti_body);
895 g_object_unref(reply);
897 NOTIFICATION_DBG("notification_ipc_request_load_noti_by_priv_id done [result: %d]", result);
901 int notification_ipc_request_get_count(notification_type_e type,
902 const char *pkgname, int group_id, int priv_id, int *count)
905 GDBusMessage *reply = NULL;
907 GVariant *reply_body;
910 result = _dbus_init();
911 if (result != NOTIFICATION_ERROR_NONE) {
912 NOTIFICATION_ERR("Can't init dbus %d", result);
916 body = g_variant_new("(isii)", type, pkgname, group_id, priv_id);
917 result = _send_sync_noti(body, &reply, "get_noti_count");
919 if (result == NOTIFICATION_ERROR_NONE) {
920 reply_body = g_dbus_message_get_body(reply);
921 g_variant_get(reply_body, "(i)", &re_count);
924 NOTIFICATION_DBG("noti count [%d]", re_count);
928 g_object_unref(reply);
930 NOTIFICATION_DBG("notification_ipc_request_get_count done [result: %d]", result);
934 int notification_ipc_request_load_noti_grouping_list(notification_type_e type, int count,
935 notification_list_h *list)
938 GDBusMessage *reply = NULL;
940 GVariant *reply_body;
946 result = _dbus_init();
947 if (result != NOTIFICATION_ERROR_NONE) {
948 NOTIFICATION_ERR("Can't init dbus %d", result);
952 body = g_variant_new("(ii)", type, count);
953 result = _send_sync_noti(body, &reply, "load_noti_grouping_list");
955 if (result == NOTIFICATION_ERROR_NONE) {
956 reply_body = g_dbus_message_get_body(reply);
957 g_variant_get(reply_body, "(a(v))", &iter);
959 while (g_variant_iter_loop(iter, "(v)", &iter_body)) {
960 noti = notification_create(NOTIFICATION_TYPE_NOTI);
961 g_variant_get(iter_body, "(v)", ¬i_body);
962 notification_ipc_make_noti_from_gvariant(noti, noti_body);
964 *list = notification_list_append(*list, noti);
966 g_variant_iter_free(iter);
970 g_object_unref(reply);
972 NOTIFICATION_DBG("notification_ipc_request_load_noti_grouping_list done [result: %d]", result);
976 int notification_ipc_request_load_noti_detail_list(const char *pkgname,
980 notification_list_h *list)
983 GDBusMessage *reply = NULL;
985 GVariant *reply_body;
991 result = _dbus_init();
992 if (result != NOTIFICATION_ERROR_NONE) {
993 NOTIFICATION_ERR("Can't init dbus %d", result);
997 body = g_variant_new("(siii)", pkgname, group_id, priv_id, count);
998 result = _send_sync_noti(body, &reply, "load_noti_detail_list");
1000 if (result == NOTIFICATION_ERROR_NONE) {
1001 reply_body = g_dbus_message_get_body(reply);
1002 g_variant_get(reply_body, "(a(v))", &iter);
1004 while (g_variant_iter_loop(iter, "(v)", &iter_body)) {
1005 noti = notification_create(NOTIFICATION_TYPE_NOTI);
1006 g_variant_get(iter_body, "(v)", ¬i_body);
1007 notification_ipc_make_noti_from_gvariant(noti, noti_body);
1009 *list = notification_list_append(*list, noti);
1011 g_variant_iter_free(iter);
1015 g_object_unref(reply);
1017 NOTIFICATION_DBG("notification_ipc_request_load_noti_detail_list done [result: %d]", result);
1021 int notification_ipc_request_get_setting_array(
1022 notification_setting_h *setting_array,
1026 GDBusMessage *reply = NULL;
1027 GVariant *reply_body;
1028 GVariant *iter_body;
1031 notification_setting_h result_setting_array;
1032 notification_setting_h temp;
1035 result = _dbus_init();
1036 if (result != NOTIFICATION_ERROR_NONE) {
1037 NOTIFICATION_ERR("Can't init dbus %d", result);
1041 result = _send_sync_noti(NULL, &reply, "get_setting_array");
1043 if (result == NOTIFICATION_ERROR_NONE) {
1044 reply_body = g_dbus_message_get_body(reply);
1045 g_variant_get(reply_body, "(ia(v))", &setting_cnt, &iter);
1047 NOTIFICATION_DBG("get setting arr cnt: %d", setting_cnt);
1048 result_setting_array = (struct notification_setting *)malloc(sizeof(struct notification_setting) * setting_cnt);
1049 if (result_setting_array == NULL) {
1050 NOTIFICATION_ERR("malloc failed");
1051 g_object_unref(reply);
1052 g_variant_iter_free(iter);
1053 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1057 while (g_variant_iter_loop(iter, "(v)", &iter_body)) {
1058 temp = result_setting_array + setting_idx;
1059 notification_ipc_make_setting_from_gvariant(temp, iter_body);
1063 *count = setting_cnt;
1064 *setting_array = result_setting_array;
1065 g_variant_iter_free(iter);
1069 g_object_unref(reply);
1071 NOTIFICATION_DBG("notification_ipc_request_get_setting_array done [result: %d]", result);
1075 int notification_ipc_request_get_setting_by_package_name(
1076 const char *package_name, notification_setting_h *setting)
1079 GDBusMessage *reply = NULL;
1081 GVariant *reply_body;
1082 GVariant *setting_body;
1083 notification_setting_h result_setting;
1085 result = _dbus_init();
1086 if (result != NOTIFICATION_ERROR_NONE) {
1087 NOTIFICATION_ERR("Can't init dbus %d", result);
1091 body = g_variant_new("(s)", package_name);
1092 result = _send_sync_noti(body, &reply, "get_setting_by_package_name");
1094 if (result == NOTIFICATION_ERROR_NONE) {
1095 reply_body = g_dbus_message_get_body(reply);
1096 g_variant_get(reply_body, "(v)", &setting_body);
1098 result_setting = (struct notification_setting *)malloc(sizeof(struct notification_setting));
1099 if (result_setting == NULL) {
1100 NOTIFICATION_ERR("malloc failed");
1101 g_object_unref(reply);
1102 g_variant_unref(body);
1103 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1105 notification_ipc_make_setting_from_gvariant(result_setting, setting_body);
1107 *setting = result_setting;
1108 g_variant_unref(setting_body);
1112 g_object_unref(reply);
1114 NOTIFICATION_DBG("notification_ipc_request_get_setting_by_package_name done [result: %d]", result);
1118 int notification_ipc_request_load_system_setting(notification_system_setting_h *setting)
1121 GDBusMessage *reply = NULL;
1122 GVariant *setting_body;
1123 GVariant *reply_body;
1124 notification_system_setting_h result_setting;
1126 result = _dbus_init();
1127 if (result != NOTIFICATION_ERROR_NONE) {
1128 NOTIFICATION_ERR("Can't init dbus %d", result);
1132 result = _send_sync_noti(NULL, &reply, "load_system_setting");
1134 if (result == NOTIFICATION_ERROR_NONE) {
1135 reply_body = g_dbus_message_get_body(reply);
1136 g_variant_get(reply_body, "(v)", &setting_body);
1138 result_setting = (struct notification_system_setting *)malloc(sizeof(struct notification_system_setting));
1139 if (result_setting == NULL) {
1140 NOTIFICATION_ERR("malloc failed");
1141 g_object_unref(reply);
1142 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1144 notification_ipc_make_system_setting_from_gvariant(result_setting, setting_body);
1146 *setting = result_setting;
1147 g_variant_unref(setting_body);
1151 g_object_unref(reply);
1153 NOTIFICATION_DBG("notification_ipc_request_load_system_setting done [result: %d]", result);
1157 int notification_ipc_update_setting(notification_setting_h setting)
1160 GDBusMessage *reply = NULL;
1163 result = _dbus_init();
1164 if (result != NOTIFICATION_ERROR_NONE) {
1165 NOTIFICATION_ERR("Can't init dbus %d", result);
1169 body = g_variant_new("(siii)",
1170 setting->package_name,
1171 (int)(setting->allow_to_notify),
1172 (int)(setting->do_not_disturb_except),
1173 (int)(setting->visibility_class));
1175 result = _send_sync_noti(body, &reply, "update_noti_setting");
1178 g_object_unref(reply);
1180 NOTIFICATION_DBG("notification_ipc_update_setting done [result: %d]", result);
1184 int notification_ipc_update_system_setting(notification_system_setting_h system_setting)
1187 GDBusMessage *reply = NULL;
1190 result = _dbus_init();
1191 if (result != NOTIFICATION_ERROR_NONE) {
1192 NOTIFICATION_ERR("Can't init dbus %d", result);
1196 body = g_variant_new("(ii)",
1197 (int)(system_setting->do_not_disturb),
1198 (int)(system_setting->visibility_class));
1200 result = _send_sync_noti(body, &reply, "update_noti_sys_setting");
1203 g_object_unref(reply);
1205 NOTIFICATION_DBG("notification_ipc_update_system_setting done [result: %d]", result);
1209 EXPORT_API GVariant *notification_ipc_make_gvariant_from_noti(notification_h noti)
1211 NOTIFICATION_DBG("make gvariant from noti");
1213 int b_encode_len = 0;
1214 bundle_raw *args = NULL;
1215 bundle_raw *group_args = NULL;
1216 bundle_raw *b_image_path = NULL;
1217 bundle_raw *b_execute_option = NULL;
1218 bundle_raw *b_service_responding = NULL;
1219 bundle_raw *b_service_single_launch = NULL;
1220 bundle_raw *b_service_multi_launch = NULL;
1221 bundle_raw *b_event_handler[NOTIFICATION_EVENT_TYPE_MAX] = {NULL, };
1222 bundle_raw *b_text = NULL;
1223 bundle_raw *b_key = NULL;
1224 bundle_raw *b_format_args = NULL;
1225 GVariant *body = NULL;
1226 GVariant *result_body = NULL;
1227 GVariantBuilder builder;
1229 g_variant_builder_init(&builder, G_VARIANT_TYPE("a{iv}"));
1230 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_NOTI_TYPE, g_variant_new_int32(noti->type));
1231 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_LAYOUT, g_variant_new_int32(noti->layout));
1232 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_GROUP_ID, g_variant_new_int32(noti->group_id));
1233 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_INTERNAL_GROUP_ID, g_variant_new_int32(noti->internal_group_id));
1234 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_PRIV_ID, g_variant_new_int32(noti->priv_id));
1235 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_CALLER_PKGNAME, g_variant_new_string((const gchar *)noti->caller_pkgname));
1236 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_DISPLAY_APPLIST, g_variant_new_int32(noti->display_applist));
1239 bundle_encode(noti->args, (bundle_raw **)&args, NULL);
1240 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_ARGS, g_variant_new_string((const gchar *)args));
1243 bundle_free_encoded_rawdata(&args);
1246 if (noti->group_args) {
1247 bundle_encode(noti->group_args, (bundle_raw **)&group_args,
1249 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_GROUP_ARGS, g_variant_new_string((const gchar *)group_args));
1252 bundle_free_encoded_rawdata(&group_args);
1255 if (noti->b_execute_option) {
1256 bundle_encode(noti->b_execute_option,
1257 (bundle_raw **)&b_execute_option, &b_encode_len);
1258 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_EXECUTE_OPTION, g_variant_new_string((const gchar *)b_execute_option));
1260 if (b_execute_option)
1261 bundle_free_encoded_rawdata(&b_execute_option);
1264 if (noti->b_service_responding) {
1265 bundle_encode(noti->b_service_responding,
1266 (bundle_raw **)&b_service_responding, &b_encode_len);
1267 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_SERVICE_RESPONDING, g_variant_new_string((const gchar *)b_service_responding));
1269 if (b_service_responding)
1270 bundle_free_encoded_rawdata(&b_service_responding);
1273 if (noti->b_service_single_launch) {
1274 bundle_encode(noti->b_service_single_launch,
1275 (bundle_raw **)&b_service_single_launch, &b_encode_len);
1276 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_SERVICE_SINGLE_LAUNCH, g_variant_new_string((const gchar *)b_service_single_launch));
1278 if (b_service_single_launch)
1279 bundle_free_encoded_rawdata(&b_service_single_launch);
1282 if (noti->b_service_multi_launch) {
1283 bundle_encode(noti->b_service_multi_launch,
1284 (bundle_raw **)&b_service_multi_launch, &b_encode_len);
1285 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_SERVICE_MULTI_LAUNCH, g_variant_new_string((const gchar *)b_service_multi_launch));
1287 if (b_service_multi_launch)
1288 bundle_free_encoded_rawdata(&b_service_multi_launch);
1291 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
1292 if (noti->b_event_handler[i]) {
1293 bundle_encode(noti->b_event_handler[i],
1294 (bundle_raw **)&b_event_handler[i], &b_encode_len);
1295 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_BUTTON1_EVENT + i, g_variant_new_string((const gchar *)b_event_handler[i]));
1297 if (b_event_handler[i])
1298 bundle_free_encoded_rawdata(&b_event_handler[i]);
1302 if (noti->launch_pkgname)
1303 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_LAUNCH_PKGNAME, g_variant_new_string((const gchar *)noti->launch_pkgname));
1305 if (noti->domain != NULL)
1306 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_DOMAIN, g_variant_new_string((const gchar *)noti->domain));
1308 if (noti->dir != NULL)
1309 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_DIR, g_variant_new_string((const gchar *)noti->dir));
1312 bundle_encode(noti->b_text, (bundle_raw **)&b_text, &b_encode_len);
1313 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_TEXT, g_variant_new_string((const gchar *)b_text));
1316 bundle_free_encoded_rawdata(&b_text);
1320 bundle_encode(noti->b_key, (bundle_raw **)&b_key, &b_encode_len);
1321 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_KEY, g_variant_new_string((const gchar *)b_key));
1324 bundle_free_encoded_rawdata(&b_key);
1327 if (noti->b_format_args) {
1328 bundle_encode(noti->b_format_args,
1329 (bundle_raw **)&b_format_args, &b_encode_len);
1330 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_FORMAT_ARGS, g_variant_new_string((const gchar *)b_format_args));
1333 bundle_free_encoded_rawdata(&b_format_args);
1336 if (noti->num_format_args != 0)
1337 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_NUM_FORMAT_ARGS, g_variant_new_int32(noti->num_format_args));
1339 if (noti->b_image_path) {
1340 bundle_encode(noti->b_image_path,
1341 (bundle_raw **)&b_image_path, &b_encode_len);
1342 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_IMAGE_PATH, g_variant_new_string((const gchar *)b_image_path));
1345 bundle_free_encoded_rawdata(&b_image_path);
1348 if (noti->sound_type != NOTIFICATION_SOUND_TYPE_NONE)
1349 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_SOUND_TYPE, g_variant_new_int32(noti->sound_type));
1351 if (noti->sound_path)
1352 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_SOUND_PATH, g_variant_new_string((const gchar *)noti->sound_path));
1354 if (noti->vibration_type != NOTIFICATION_VIBRATION_TYPE_NONE)
1355 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_VIBRATION_TYPE, g_variant_new_int32(noti->vibration_type));
1357 if (noti->vibration_path)
1358 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_VIBRATION_PATH, g_variant_new_string((const gchar *)noti->vibration_path));
1360 if (noti->led_operation != NOTIFICATION_LED_OP_OFF)
1361 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_LED_OPERATION, g_variant_new_int32(noti->led_operation));
1363 if (noti->led_argb != 0)
1364 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_LED_ARGB, g_variant_new_int32(noti->led_argb));
1366 if (noti->led_on_ms != 0)
1367 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_LED_ON_MS, g_variant_new_int32(noti->led_on_ms));
1369 if (noti->led_off_ms != 0)
1370 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_LED_OFF_MS, g_variant_new_int32(noti->led_off_ms));
1372 if (noti->time != 0)
1373 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_TIME, g_variant_new_int32(noti->time));
1375 if (noti->insert_time != 0)
1376 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_INSERT_TIME, g_variant_new_int32(noti->insert_time));
1378 if (noti->flags_for_property != 0)
1379 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_FLAGS_FOR_PROPERTY, g_variant_new_int32(noti->flags_for_property));
1381 if (noti->progress_size != 0.0)
1382 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_PROGRESS_SIZE, g_variant_new_double(noti->progress_size));
1384 if (noti->progress_percentage != 0.0)
1385 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_PROGRESS_PERCENTAGE, g_variant_new_double(noti->progress_percentage));
1387 if (noti->app_icon_path != NULL)
1388 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_APP_ICON_PATH, g_variant_new_string((const gchar *)noti->app_icon_path));
1389 if (noti->app_name != NULL)
1390 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_APP_NAME, g_variant_new_string((const gchar *)noti->app_name));
1391 if (noti->temp_title != NULL)
1392 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_TEMP_TITLE, g_variant_new_string((const gchar *)noti->temp_title));
1393 if (noti->temp_content != NULL)
1394 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_TEMP_CONTENT, g_variant_new_string((const gchar *)noti->temp_content));
1395 if (noti->tag != NULL)
1396 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_TAG, g_variant_new_string((const gchar *)noti->tag));
1398 if (noti->ongoing_flag != 0)
1399 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_ONGOING_FLAG, g_variant_new_int32(noti->ongoing_flag));
1400 if (noti->auto_remove != 0)
1401 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_AUTO_REMOVE, g_variant_new_int32(noti->auto_remove));
1403 result_body = g_variant_builder_end(&builder);
1404 body = g_variant_new("(v)", result_body);
1409 static gboolean _variant_to_int_dict(GHashTable **dict, GVariant *variant) {
1416 *dict = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, (GDestroyNotify)g_variant_unref);
1420 g_variant_iter_init(&iter, variant);
1421 while (g_variant_iter_next(&iter, "{iv}", &key, &value)) {
1422 hash_key = (int *)calloc(sizeof(int), 1);
1423 if (hash_key == NULL) {
1424 g_hash_table_remove_all(*dict);
1428 g_hash_table_insert(*dict, (gpointer)hash_key, value);
1433 static gboolean _variant_dict_lookup(GHashTable *dict,
1435 const gchar *format_string,
1441 value = g_hash_table_lookup(dict, (gpointer)&key);
1443 if (value == NULL || !g_variant_check_format_string(value, format_string, FALSE))
1446 va_start(ap, format_string);
1447 g_variant_get_va(value, format_string, NULL, &ap);
1454 * functions creating notification packet
1456 EXPORT_API int notification_ipc_make_noti_from_gvariant(notification_h noti,
1457 GVariant *variant) {
1459 NOTIFICATION_DBG("make noti from GVariant");
1463 char *caller_pkgname = NULL;
1464 char *launch_pkgname = NULL;
1465 bundle_raw *args = NULL;
1466 bundle_raw *group_args = NULL;
1467 bundle_raw *b_execute_option = NULL;
1468 bundle_raw *b_service_responding = NULL;
1469 bundle_raw *b_service_single_launch = NULL;
1470 bundle_raw *b_service_multi_launch = NULL;
1471 bundle_raw *b_event_handler[NOTIFICATION_EVENT_TYPE_MAX] = { NULL, };
1472 char *domain = NULL;
1474 bundle_raw *b_text = NULL;
1475 bundle_raw *b_key = NULL;
1476 bundle_raw *b_format_args = NULL;
1477 bundle_raw *b_image_path = NULL;
1478 char *sound_path = NULL;
1479 char *vibration_path = NULL;
1480 char *app_icon_path = NULL;
1481 char *app_name = NULL;
1482 char *temp_title = NULL;
1483 char *temp_content = NULL;
1487 NOTIFICATION_ERR("invalid data noti NULL");
1488 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1491 if (variant == NULL) {
1492 NOTIFICATION_ERR("invalid data variant NULL");
1493 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1496 if (!_variant_to_int_dict(&dict, variant))
1497 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1499 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_NOTI_TYPE, "i", ¬i->type);
1500 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_LAYOUT, "i", ¬i->layout);
1501 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_GROUP_ID, "i", ¬i->group_id);
1502 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_INTERNAL_GROUP_ID, "i", ¬i->internal_group_id);
1503 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_PRIV_ID, "i", ¬i->priv_id);
1504 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_CALLER_PKGNAME, "&s", &caller_pkgname);
1505 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_LAUNCH_PKGNAME, "&s", &launch_pkgname);
1506 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_ARGS, "&s", &args);
1507 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_GROUP_ARGS, "&s", &group_args);
1508 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_EXECUTE_OPTION, "&s", &b_execute_option);
1509 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_SERVICE_RESPONDING, "&s", &b_service_responding);
1510 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_SERVICE_SINGLE_LAUNCH, "&s", &b_service_single_launch);
1511 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_SERVICE_MULTI_LAUNCH, "&s", &b_service_multi_launch);
1512 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_BUTTON1_EVENT, "&s", ¬i->b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1]);
1513 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_BUTTON2_EVENT, "&s", ¬i->b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_2]);
1514 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_BUTTON3_EVENT, "&s", ¬i->b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_3]);
1515 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_BUTTON4_EVENT, "&s", ¬i->b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_4]);
1516 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_BUTTON5_EVENT, "&s", ¬i->b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_5]);
1517 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_BUTTON6_EVENT, "&s", ¬i->b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_6]);
1518 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_ICON_EVENT, "&s", ¬i->b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_ICON]);
1519 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_THUMBNAIL_EVENT, "&s", ¬i->b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL]);
1520 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_DOMAIN, "&s", &domain);
1521 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_DIR, "&s", &dir);
1522 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_TEXT, "&s", &b_text);
1523 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_KEY, "&s", &b_key);
1524 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_FORMAT_ARGS, "&s", &b_format_args);
1525 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_NUM_FORMAT_ARGS, "i", ¬i->num_format_args);
1526 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_IMAGE_PATH, "&s", &b_image_path);
1527 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_SOUND_TYPE, "i", ¬i->sound_type);
1528 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_SOUND_PATH, "&s", &sound_path);
1529 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_VIBRATION_TYPE, "i", ¬i->vibration_type);
1530 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_VIBRATION_PATH, "&s", &vibration_path);
1531 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_LED_OPERATION, "i", ¬i->led_operation);
1532 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_LED_ARGB, "i", ¬i->led_argb);
1533 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_LED_ON_MS, "i", ¬i->led_on_ms);
1534 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_LED_OFF_MS, "i", ¬i->led_off_ms);
1535 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_TIME, "i", ¬i->time);
1536 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_INSERT_TIME, "i", ¬i->insert_time);
1537 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_FLAGS_FOR_PROPERTY, "i", ¬i->flags_for_property);
1538 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_DISPLAY_APPLIST, "i", ¬i->display_applist);
1539 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_PROGRESS_SIZE, "d", ¬i->progress_size);
1540 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_PROGRESS_PERCENTAGE, "d", ¬i->progress_percentage);
1541 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_APP_ICON_PATH, "&s", &app_icon_path);
1542 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_APP_NAME, "&s", &app_name);
1543 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_TEMP_TITLE, "&s", &temp_title);
1544 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_TEMP_CONTENT, "&s", &temp_content);
1545 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_TAG, "&s", &tag);
1546 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_ONGOING_FLAG, "i", ¬i->ongoing_flag);
1547 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_AUTO_REMOVE, "i", ¬i->auto_remove);
1549 noti->caller_pkgname = _dup_string(caller_pkgname);
1550 noti->launch_pkgname = _dup_string(launch_pkgname);
1551 noti->args = _create_bundle_from_bundle_raw(args);
1552 noti->group_args = _create_bundle_from_bundle_raw(group_args);
1553 noti->b_execute_option = _create_bundle_from_bundle_raw(b_execute_option);
1554 noti->b_service_responding = _create_bundle_from_bundle_raw(
1555 b_service_responding);
1556 noti->b_service_single_launch = _create_bundle_from_bundle_raw(
1557 b_service_single_launch);
1558 noti->b_service_multi_launch = _create_bundle_from_bundle_raw(
1559 b_service_multi_launch);
1560 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
1561 noti->b_event_handler[i] = _create_bundle_from_bundle_raw(
1562 b_event_handler[i]);
1564 noti->domain = _dup_string(domain);
1565 noti->dir = _dup_string(dir);
1566 noti->b_text = _create_bundle_from_bundle_raw(b_text);
1567 noti->b_key = _create_bundle_from_bundle_raw(b_key);
1568 noti->b_format_args = _create_bundle_from_bundle_raw(b_format_args);
1569 noti->b_image_path = _create_bundle_from_bundle_raw(b_image_path);
1570 noti->sound_path = _dup_string(sound_path);
1571 noti->vibration_path = _dup_string(vibration_path);
1572 noti->app_icon_path = _dup_string(app_icon_path);
1573 noti->app_name = _dup_string(app_name);
1574 noti->temp_title = _dup_string(temp_title);
1575 noti->temp_content = _dup_string(temp_content);
1576 noti->tag = _dup_string(tag);
1578 g_hash_table_remove_all(dict);
1580 return NOTIFICATION_ERROR_NONE;
1583 EXPORT_API GVariant *notification_ipc_make_gvariant_from_system_setting(struct notification_system_setting *noti_setting)
1585 GVariant *body = NULL;
1586 body = g_variant_new("(ii)",
1587 noti_setting->do_not_disturb,
1588 noti_setting->visibility_class);
1592 EXPORT_API int notification_ipc_make_system_setting_from_gvariant(struct notification_system_setting *noti_setting,
1596 int visibility_class;
1598 if (noti_setting == NULL) {
1599 NOTIFICATION_ERR("invalid data");
1600 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1602 g_variant_get(variant,
1607 NOTIFICATION_DBG("system setting #### %d, %d",
1608 do_not_disturb, visibility_class);
1610 noti_setting->do_not_disturb = do_not_disturb;
1611 noti_setting->visibility_class = visibility_class;
1613 NOTIFICATION_DBG("system setting2 #### %d, %d",
1614 noti_setting->do_not_disturb, noti_setting->visibility_class);
1616 return NOTIFICATION_ERROR_NONE;
1619 EXPORT_API GVariant *notification_ipc_make_gvariant_from_setting(struct notification_setting *noti_setting)
1621 GVariant *body = NULL;
1623 body = g_variant_new("(siii)",
1624 noti_setting->package_name,
1625 noti_setting->allow_to_notify,
1626 noti_setting->do_not_disturb_except,
1627 noti_setting->visibility_class);
1632 EXPORT_API int notification_ipc_make_setting_from_gvariant(struct notification_setting *noti_setting,
1635 NOTIFICATION_DBG("notification_ipc_make_setting_from_gvariant !!!!");
1637 int allow_to_notify;
1638 int do_not_disturb_except;
1639 int visibility_class;
1641 if (noti_setting == NULL || variant == NULL) {
1642 NOTIFICATION_ERR("invalid data");
1643 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1645 g_variant_get(variant,
1649 &do_not_disturb_except,
1652 NOTIFICATION_DBG("setting from variant %s !!", pkgname);
1654 noti_setting->package_name = _dup_string(pkgname);
1655 noti_setting->allow_to_notify = allow_to_notify;
1656 noti_setting->do_not_disturb_except = do_not_disturb_except;
1657 noti_setting->visibility_class = visibility_class;
1659 NOTIFICATION_DBG("setting from variant %s, %s",
1660 noti_setting->package_name, pkgname);
1662 return NOTIFICATION_ERROR_NONE;
1665 static int _send_service_register()
1667 NOTIFICATION_DBG("service register");
1668 GDBusMessage *reply = NULL;
1671 result = _send_sync_noti(NULL, &reply, "noti_service_register");
1674 g_object_unref(reply);
1676 NOTIFICATION_ERR("_send_service_register done = %s, result = %d", _bus_name, result);
1680 static int _ipc_monitor_register(void)
1682 NOTIFICATION_ERR("register a service\n");
1684 return _send_service_register();
1687 static void _on_name_appeared(GDBusConnection *connection,
1689 const gchar *name_owner,
1692 NOTIFICATION_DBG("name appeared : %s", name);
1693 is_master_started = 1;
1694 _ipc_monitor_register();
1696 /* TODO: dbus activation isn't enough ? */
1697 _do_deffered_task();
1700 static void _on_name_vanished(GDBusConnection *connection,
1704 NOTIFICATION_DBG("name vanished : %s", name);
1705 is_master_started = 0;
1708 int notification_ipc_monitor_init(void)
1713 if (ret != NOTIFICATION_ERROR_NONE) {
1714 NOTIFICATION_ERR("Can't init dbus %d", ret);
1718 ret = _dbus_signal_init();
1719 if (ret != NOTIFICATION_ERROR_NONE) {
1720 NOTIFICATION_ERR("Can't signal_init %d", ret);
1724 ret = _ipc_monitor_register();
1725 if (ret != NOTIFICATION_ERROR_NONE) {
1726 NOTIFICATION_ERR("Can't init ipc_monitor_register %d", ret);
1730 if (provider_monitor_id == 0) {
1731 provider_monitor_id = g_bus_watch_name_on_connection(
1734 G_BUS_NAME_WATCHER_FLAGS_NONE,
1740 if (provider_monitor_id == 0) {
1741 g_dbus_connection_signal_unsubscribe(_gdbus_conn, monitor_id);
1743 NOTIFICATION_ERR("watch on name fail");
1744 return NOTIFICATION_ERROR_IO_ERROR;
1748 return NOTIFICATION_ERROR_NONE;
1751 static int _ipc_monitor_deregister(void)
1753 if (provider_monitor_id) {
1754 g_bus_unwatch_name(provider_monitor_id);
1755 provider_monitor_id = 0;
1759 g_dbus_connection_signal_unsubscribe(_gdbus_conn, monitor_id);
1763 return NOTIFICATION_ERROR_NONE;
1766 int notification_ipc_monitor_fini(void)
1768 return _ipc_monitor_deregister();