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;
79 notification_vibration_type_e vib_type = NOTIFICATION_VIBRATION_TYPE_NONE;
81 notification_get_pkgname(noti, &pkgname);
82 notification_get_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, &text);
83 notification_get_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, &content);
84 notification_get_tag(noti, &tag);
85 notification_get_vibration(noti, &vib_type, NULL);
87 NOTIFICATION_DBG("client print_noti pkgname = %s ", pkgname );
88 NOTIFICATION_DBG("client print_noti title = %s ", text );
89 NOTIFICATION_DBG("client print_noti content = %s ", content );
90 NOTIFICATION_DBG("client print_noti tag = %s ", tag );
91 NOTIFICATION_DBG("client print_noti priv_id = %d ", noti->priv_id);
92 NOTIFICATION_DBG("client print_noti vibration_path = %s ", noti->vibration_path);
93 NOTIFICATION_DBG("client print_noti vibration_type = %d ", vib_type);
96 static inline char *_string_get(char *string)
101 if (string[0] == '\0')
108 int notification_ipc_is_master_ready(void)
114 result = g_dbus_connection_call_sync(
120 g_variant_new("(s)", PROVIDER_BUS_NAME),
121 G_VARIANT_TYPE("(b)"),
122 G_DBUS_CALL_FLAGS_NONE,
127 if (err || (result == NULL)) {
129 NOTIFICATION_ERR("No reply. error = %s", err->message);
132 is_master_started = 0;
134 g_variant_get(result, "(b)", &name_exist);
137 NOTIFICATION_ERR("Name not exist %s", PROVIDER_BUS_NAME);
138 NOTIFICATION_ERR("the master has been stopped");
139 is_master_started = 0;
141 NOTIFICATION_DBG("the master has been started");
142 is_master_started = 1;
147 g_variant_unref(result);
149 return is_master_started;
152 /* TODO: dbus activation isn't enough ? */
154 * store tasks when daemon stopped
156 int notification_ipc_add_deffered_task(
157 void (*deferred_task_cb)(void *data),
164 (task_list *) malloc(sizeof(task_list));
166 if (list_new == NULL)
167 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
169 list_new->next = NULL;
170 list_new->prev = NULL;
172 list_new->task_cb = deferred_task_cb;
173 list_new->data = user_data;
175 if (g_task_list == NULL) {
176 g_task_list = list_new;
180 while (list->next != NULL)
183 list->next = list_new;
184 list_new->prev = list;
186 return NOTIFICATION_ERROR_NONE;
189 int notification_ipc_del_deffered_task(
190 void (*deferred_task_cb)(void *data))
193 task_list *list_prev;
194 task_list *list_next;
196 list_del = g_task_list;
198 if (list_del == NULL)
199 return NOTIFICATION_ERROR_INVALID_PARAMETER;
201 while (list_del->prev != NULL)
202 list_del = list_del->prev;
205 if (list_del->task_cb == deferred_task_cb) {
206 list_prev = list_del->prev;
207 list_next = list_del->next;
209 if (list_prev == NULL)
210 g_task_list = list_next;
212 list_prev->next = list_next;
214 if (list_next == NULL) {
215 if (list_prev != NULL)
216 list_prev->next = NULL;
218 list_next->prev = list_prev;
222 return NOTIFICATION_ERROR_NONE;
224 list_del = list_del->next;
225 } while (list_del != NULL);
227 return NOTIFICATION_ERROR_INVALID_PARAMETER;
230 static void _do_deffered_task(void)
233 task_list *list_temp;
235 if (g_task_list == NULL)
238 list_do = g_task_list;
241 while (list_do->prev != NULL)
242 list_do = list_do->prev;
244 while (list_do != NULL) {
245 if (list_do->task_cb != NULL) {
246 list_do->task_cb(list_do->data);
247 NOTIFICATION_DBG("called:%p", list_do->task_cb);
249 list_temp = list_do->next;
256 * functions to create operation list
258 static notification_op *_ipc_create_op(notification_op_type_e type,
259 int num_op, int *list_priv_id, int num_priv_id, notification_h *noti_list)
262 notification_op *op_list;
267 op_list = (notification_op *)malloc(sizeof(notification_op) * num_op);
269 if (op_list == NULL) {
270 NOTIFICATION_ERR("malloc failed");
274 memset(op_list, 0x0, sizeof(notification_op) * num_op);
276 for (i = 0; i < num_op; i++) {
277 (op_list + i)->type = type;
278 if (list_priv_id != NULL)
279 (op_list + i)->priv_id = *(list_priv_id + i);
280 if (noti_list != NULL)
281 (op_list + i)->noti = *(noti_list + i);
288 * utility functions creating notification packet
290 static inline char *_dup_string(const char *string)
296 if (string[0] == '\0')
299 ret = strdup(string);
301 NOTIFICATION_ERR("Error: %s\n", strerror(errno));
306 static inline bundle *_create_bundle_from_bundle_raw(bundle_raw *string)
310 if (string[0] == '\0')
313 return bundle_decode(string, strlen((char *)string));
316 static void _add_noti_notify(GVariant *parameters)
319 notification_op *noti_op;
320 GVariant *body = NULL;
322 NOTIFICATION_DBG("add noti notify");
323 noti = notification_create(NOTIFICATION_TYPE_NOTI);
325 NOTIFICATION_ERR("failed to create a notification");
329 g_variant_get(parameters, "(v)", &body);
330 notification_ipc_make_noti_from_gvariant(noti, body);
332 if (noti->flags_for_property & NOTIFICATION_PROP_DISABLE_UPDATE_ON_INSERT) {
333 NOTIFICATION_ERR("disable changed callback %d", noti->flags_for_property);
334 /* Disable changed cb */
336 /* Enable changed cb */
337 noti_op = _ipc_create_op(NOTIFICATION_OP_INSERT, 1, &(noti->priv_id), 1, ¬i);
339 if (noti_op != NULL) {
340 notification_call_changed_cb(noti_op, 1);
344 notification_free(noti);
347 static void _update_noti_notify(GVariant *parameters)
350 notification_op *noti_op;
351 GVariant *body = NULL;
353 noti = notification_create(NOTIFICATION_TYPE_NOTI);
355 NOTIFICATION_ERR("failed to create a notification");
358 g_variant_get(parameters, "(v)", &body);
359 notification_ipc_make_noti_from_gvariant(noti, body);
362 noti_op = _ipc_create_op(NOTIFICATION_OP_UPDATE, 1, &(noti->priv_id), 1, ¬i);
363 if (noti_op != NULL) {
364 notification_call_changed_cb(noti_op, 1);
367 notification_free(noti);
370 static void _refresh_noti_notify(GVariant *parameters)
372 notification_op *noti_op = _ipc_create_op(NOTIFICATION_OP_REFRESH, 1, NULL, 0, NULL);
374 if (noti_op != NULL) {
375 notification_call_changed_cb(noti_op, 1);
380 static void _delete_single_notify(GVariant *parameters)
384 notification_op *noti_op;
387 g_variant_get(parameters, "(ii)", &num_deleted, &priv_id);
389 noti_op = _ipc_create_op(NOTIFICATION_OP_DELETE, 1, &priv_id, 1, NULL);
390 if (noti_op != NULL) {
391 notification_call_changed_cb(noti_op, 1);
396 static void _delete_multiple_notify(GVariant *parameters)
400 notification_op *noti_op;
403 g_variant_get(parameters, "(a(i))", &iter);
404 while (g_variant_iter_loop(iter, "(i)", &buf[idx])) {
405 NOTIFICATION_DBG("delete_noti_multiple priv_id : %d", buf[idx]);
408 g_variant_iter_free(iter);
410 NOTIFICATION_DBG("data num deleted:%d", idx);
411 noti_op = _ipc_create_op(NOTIFICATION_OP_DELETE, idx, buf, idx, NULL);
413 if (noti_op == NULL) {
414 NOTIFICATION_ERR("_ipc_create_op failed");
417 notification_call_changed_cb(noti_op, idx);
421 static void _handle_noti_notify(GDBusConnection *connection,
422 const gchar *sender_name,
423 const gchar *object_path,
424 const gchar *interface_name,
425 const gchar *signal_name,
426 GVariant *parameters,
429 NOTIFICATION_DBG("signal_name: %s", signal_name);
431 if (g_strcmp0(signal_name, "add_noti_notify") == 0)
432 _add_noti_notify(parameters);
433 else if (g_strcmp0(signal_name, "update_noti_notify") == 0)
434 _update_noti_notify(parameters);
435 else if (g_strcmp0(signal_name, "delete_single_notify") == 0)
436 _delete_single_notify(parameters);
437 else if (g_strcmp0(signal_name, "delete_multiple_notify") == 0)
438 _delete_multiple_notify(parameters);
439 else if (g_strcmp0(signal_name, "refresh_noti_notify") == 0)
440 _refresh_noti_notify(parameters);
444 static int _dbus_signal_init()
447 int ret = NOTIFICATION_ERROR_NONE;
449 if (monitor_id == 0) {
450 id = g_dbus_connection_signal_subscribe(_gdbus_conn,
452 PROVIDER_NOTI_INTERFACE_NAME, /* interface */
454 PROVIDER_OBJECT_PATH, /* path */
456 G_DBUS_SIGNAL_FLAGS_NONE,
461 NOTIFICATION_DBG("subscribe id : %d", id);
463 ret = NOTIFICATION_ERROR_IO_ERROR;
464 NOTIFICATION_ERR("Failed to _register_noti_dbus_interface");
467 ret = NOTIFICATION_ERROR_NONE;
474 static int _dbus_init()
476 int ret = NOTIFICATION_ERROR_NONE;
477 GError *error = NULL;
479 if (_gdbus_conn == NULL) {
480 _gdbus_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
482 if (_gdbus_conn == NULL) {
484 NOTIFICATION_ERR("Failed to get dbus [%s]", error->message);
487 return NOTIFICATION_ERROR_IO_ERROR;
489 _bus_name = g_dbus_connection_get_unique_name(_gdbus_conn);
490 NOTIFICATION_DBG("bus name : %s", _bus_name);
492 notification_error_quark();
494 ret = NOTIFICATION_ERROR_NONE;
499 static int _send_sync_noti(GVariant *body, GDBusMessage **reply, char *cmd)
501 int ret = NOTIFICATION_ERROR_NONE;
505 msg = g_dbus_message_new_method_call(
507 PROVIDER_OBJECT_PATH,
508 PROVIDER_NOTI_INTERFACE_NAME,
511 NOTIFICATION_ERR("Can't allocate new method call");
513 g_variant_unref(body);
514 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
518 g_dbus_message_set_body(msg, body);
520 *reply = g_dbus_connection_send_message_with_reply_sync(
523 G_DBUS_SEND_MESSAGE_FLAGS_NONE,
532 ret = NOTIFICATION_ERROR_SERVICE_NOT_READY;
534 NOTIFICATION_ERR("No reply. cmd = %s, error = %s", cmd, err->message);
535 if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
536 ret = NOTIFICATION_ERROR_PERMISSION_DENIED;
542 if (g_dbus_message_to_gerror(*reply, &err)) {
544 NOTIFICATION_ERR("_send_sync_noti cmd = %s, error %s", cmd, err->message);
548 NOTIFICATION_DBG("_send_sync_noti done !!");
549 return NOTIFICATION_ERROR_NONE;
553 static void _send_message_with_reply_async_cb(GDBusConnection *connection,
558 int result = NOTIFICATION_ERROR_NONE;
560 GDBusMessage *reply = NULL;
562 result_cb_item *cb_item = (result_cb_item *)user_data;
564 if (cb_item == NULL) {
565 NOTIFICATION_ERR("Failed to get a callback item");
569 reply = g_dbus_connection_send_message_with_reply_finish(
576 NOTIFICATION_ERR("No reply. error = %s", err->message);
579 result = NOTIFICATION_ERROR_SERVICE_NOT_READY;
581 } else if (g_dbus_message_to_gerror(reply, &err)) {
584 NOTIFICATION_ERR("_send_async_noti error %s", err->message);
587 NOTIFICATION_DBG("_send_async_noti done !![%d]", result);
589 if (result == NOTIFICATION_ERROR_NONE) {
590 body = g_dbus_message_get_body(reply);
591 g_variant_get(body, "(i)", &priv_id);
593 if (cb_item->result_cb)
594 cb_item->result_cb(priv_id, result, cb_item->data);
597 if (cb_item->result_cb)
598 cb_item->result_cb(NOTIFICATION_PRIV_ID_NONE, result, cb_item->data);
602 g_object_unref(reply);
606 static int _send_async_noti(GVariant *body, result_cb_item *cb_item, char *cmd)
610 msg = g_dbus_message_new_method_call(
612 PROVIDER_OBJECT_PATH,
613 PROVIDER_NOTI_INTERFACE_NAME,
616 NOTIFICATION_ERR("Can't allocate new method call");
617 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
621 g_dbus_message_set_body(msg, body);
623 g_dbus_connection_send_message_with_reply(
626 G_DBUS_SEND_MESSAGE_FLAGS_NONE,
630 (GAsyncReadyCallback)_send_message_with_reply_async_cb,
633 NOTIFICATION_DBG("_send_async_noti done !!");
636 return NOTIFICATION_ERROR_NONE;
639 int notification_ipc_request_insert(notification_h noti, int *priv_id)
643 GDBusMessage *reply = NULL;
645 GVariant *reply_body;
647 result = _dbus_init();
648 if (result != NOTIFICATION_ERROR_NONE) {
649 NOTIFICATION_ERR("Can't init dbus %d", result);
653 /* Initialize private ID */
654 noti->priv_id = NOTIFICATION_PRIV_ID_NONE;
655 noti->group_id = NOTIFICATION_GROUP_ID_NONE;
656 noti->internal_group_id = NOTIFICATION_GROUP_ID_NONE;
659 body = notification_ipc_make_gvariant_from_noti(noti);
661 NOTIFICATION_ERR("cannot make gvariant");
662 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
665 result = _send_sync_noti(body, &reply, "add_noti");
666 NOTIFICATION_DBG("_send_sync_noti %d", result);
668 if (result == NOTIFICATION_ERROR_NONE) {
669 reply_body = g_dbus_message_get_body(reply);
670 g_variant_get(reply_body, "(i)", &id);
677 g_object_unref(reply);
679 NOTIFICATION_DBG("notification_ipc_request_insert done [priv_id : %d, result: %d]", *priv_id, result);
683 int notification_ipc_request_update(notification_h noti)
688 GDBusMessage *reply = NULL;
690 GVariant *reply_body;
692 result = _dbus_init();
693 if (result != NOTIFICATION_ERROR_NONE) {
694 NOTIFICATION_ERR("Can't init dbus %d", result);
698 body = notification_ipc_make_gvariant_from_noti(noti);
700 NOTIFICATION_ERR("cannot make gvariant");
701 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
704 result = _send_sync_noti(body, &reply, "update_noti");
705 if (result == NOTIFICATION_ERROR_NONE) {
706 reply_body = g_dbus_message_get_body(reply);
707 g_variant_get(reply_body, "(i)", &priv_id);
711 g_object_unref(reply);
713 NOTIFICATION_DBG("notification_ipc_request_update done [result: %d, priv_id :%d]", result, priv_id);
717 int notification_ipc_request_update_async(notification_h noti,
718 void (*result_cb)(int priv_id, int result, void *data), void *user_data)
721 result_cb_item *cb_item;
724 result = _dbus_init();
725 if (result != NOTIFICATION_ERROR_NONE) {
726 NOTIFICATION_ERR("Can't init dbus %d", result);
730 cb_item = calloc(1, sizeof(result_cb_item));
732 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
734 cb_item->result_cb = result_cb;
735 cb_item->data = user_data;
737 body = notification_ipc_make_gvariant_from_noti(noti);
739 NOTIFICATION_ERR("cannot make gvariant");
741 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
744 result = _send_async_noti(body, cb_item, "update_noti");
745 NOTIFICATION_DBG("notification_ipc_request_update_async done [result: %d]", result);
747 if (result != NOTIFICATION_ERROR_NONE) {
752 g_variant_unref(body);
757 int notification_ipc_request_refresh(void)
760 GDBusMessage *reply = NULL;
763 result = _dbus_init();
764 if (result != NOTIFICATION_ERROR_NONE) {
765 NOTIFICATION_ERR("Can't init dbus %d", result);
769 body = g_variant_new("(i)", NOTIFICATION_OP_REFRESH);
770 result = _send_sync_noti(body, &reply, "refresh_noti");
773 g_object_unref(reply);
775 NOTIFICATION_ERR("notification_ipc_request_refresh done [result: %d]", result);
779 int notification_ipc_request_delete_single(notification_type_e type, char *pkgname, int priv_id)
783 GDBusMessage *reply = NULL;
785 GVariant *reply_body;
787 result = _dbus_init();
788 if (result != NOTIFICATION_ERROR_NONE) {
789 NOTIFICATION_ERR("Can't init dbus %d", result);
793 body = g_variant_new("(si)", pkgname, priv_id);
794 result = _send_sync_noti(body, &reply, "del_noti_single");
796 if (result == NOTIFICATION_ERROR_NONE) {
797 reply_body = g_dbus_message_get_body(reply);
798 g_variant_get(reply_body, "(i)", &id);
802 g_object_unref(reply);
804 NOTIFICATION_ERR("notification_ipc_request_delete_single done [result: %d]", result);
808 int notification_ipc_request_delete_multiple(notification_type_e type, char *pkgname)
813 GVariant *reply_body;
814 GDBusMessage *reply = NULL;
816 result = _dbus_init();
817 if (result != NOTIFICATION_ERROR_NONE) {
818 NOTIFICATION_ERR("Can't init dbus %d", result);
825 body = g_variant_new("(si)", pkgname, type);
826 result = _send_sync_noti(body, &reply, "del_noti_multiple");
828 if (result == NOTIFICATION_ERROR_NONE) {
829 reply_body = g_dbus_message_get_body(reply);
830 g_variant_get(reply_body, "(i)", &num_deleted);
831 NOTIFICATION_ERR("num deleted:%d", num_deleted);
835 g_object_unref(reply);
840 int notification_ipc_request_load_noti_by_tag(notification_h noti, const char *pkgname, const char *tag)
843 GDBusMessage *reply = NULL;
845 GVariant *reply_body;
848 result = _dbus_init();
849 if (result != NOTIFICATION_ERROR_NONE) {
850 NOTIFICATION_ERR("Can't init dbus %d", result);
857 body = g_variant_new("(ss)", pkgname, tag);
858 result = _send_sync_noti(body, &reply, "load_noti_by_tag");
860 if (result == NOTIFICATION_ERROR_NONE) {
861 reply_body = g_dbus_message_get_body(reply);
862 g_variant_get(reply_body, "(v)", ¬i_body);
864 notification_ipc_make_noti_from_gvariant(noti, noti_body);
865 g_variant_unref(noti_body);
871 g_object_unref(reply);
873 NOTIFICATION_DBG("notification_ipc_request_load_noti_by_tag done [result: %d]", result);
877 int notification_ipc_request_load_noti_by_priv_id(notification_h noti, const char *pkgname, int priv_id)
880 GDBusMessage *reply = NULL;
882 GVariant *reply_body;
885 result = _dbus_init();
886 if (result != NOTIFICATION_ERROR_NONE) {
887 NOTIFICATION_ERR("Can't init dbus %d", result);
894 body = g_variant_new("(si)", pkgname, priv_id);
895 result = _send_sync_noti(body, &reply, "load_noti_by_priv_id");
897 if (result == NOTIFICATION_ERROR_NONE) {
898 reply_body = g_dbus_message_get_body(reply);
899 g_variant_get(reply_body, "(v)", ¬i_body);
901 notification_ipc_make_noti_from_gvariant(noti, noti_body);
902 g_variant_unref(noti_body);
907 g_object_unref(reply);
909 NOTIFICATION_DBG("notification_ipc_request_load_noti_by_priv_id done [result: %d]", result);
913 int notification_ipc_request_get_count(notification_type_e type,
914 const char *pkgname, int group_id, int priv_id, int *count)
917 GDBusMessage *reply = NULL;
919 GVariant *reply_body;
922 result = _dbus_init();
923 if (result != NOTIFICATION_ERROR_NONE) {
924 NOTIFICATION_ERR("Can't init dbus %d", result);
931 body = g_variant_new("(isii)", type, pkgname, group_id, priv_id);
932 result = _send_sync_noti(body, &reply, "get_noti_count");
934 if (result == NOTIFICATION_ERROR_NONE) {
935 reply_body = g_dbus_message_get_body(reply);
936 g_variant_get(reply_body, "(i)", &re_count);
939 NOTIFICATION_DBG("noti count [%d]", re_count);
943 g_object_unref(reply);
945 NOTIFICATION_DBG("notification_ipc_request_get_count done [result: %d]", result);
949 int notification_ipc_request_load_noti_grouping_list(notification_type_e type, int count,
950 notification_list_h *list)
953 GDBusMessage *reply = NULL;
955 GVariant *reply_body;
961 result = _dbus_init();
962 if (result != NOTIFICATION_ERROR_NONE) {
963 NOTIFICATION_ERR("Can't init dbus %d", result);
967 body = g_variant_new("(ii)", type, count);
968 result = _send_sync_noti(body, &reply, "load_noti_grouping_list");
970 if (result == NOTIFICATION_ERROR_NONE) {
971 reply_body = g_dbus_message_get_body(reply);
972 g_variant_get(reply_body, "(a(v))", &iter);
974 while (g_variant_iter_loop(iter, "(v)", &iter_body)) {
975 noti = notification_create(NOTIFICATION_TYPE_NOTI);
976 g_variant_get(iter_body, "(v)", ¬i_body);
977 notification_ipc_make_noti_from_gvariant(noti, noti_body);
979 *list = notification_list_append(*list, noti);
981 g_variant_iter_free(iter);
985 g_object_unref(reply);
987 NOTIFICATION_DBG("notification_ipc_request_load_noti_grouping_list done [result: %d]", result);
991 int notification_ipc_request_load_noti_detail_list(const char *pkgname,
995 notification_list_h *list)
998 GDBusMessage *reply = NULL;
1000 GVariant *reply_body;
1001 GVariant *iter_body;
1003 notification_h noti;
1004 GVariant *noti_body;
1006 result = _dbus_init();
1007 if (result != NOTIFICATION_ERROR_NONE) {
1008 NOTIFICATION_ERR("Can't init dbus %d", result);
1012 body = g_variant_new("(siii)", pkgname, group_id, priv_id, count);
1013 result = _send_sync_noti(body, &reply, "load_noti_detail_list");
1015 if (result == NOTIFICATION_ERROR_NONE) {
1016 reply_body = g_dbus_message_get_body(reply);
1017 g_variant_get(reply_body, "(a(v))", &iter);
1019 while (g_variant_iter_loop(iter, "(v)", &iter_body)) {
1020 noti = notification_create(NOTIFICATION_TYPE_NOTI);
1021 g_variant_get(iter_body, "(v)", ¬i_body);
1022 notification_ipc_make_noti_from_gvariant(noti, noti_body);
1024 *list = notification_list_append(*list, noti);
1026 g_variant_iter_free(iter);
1030 g_object_unref(reply);
1032 NOTIFICATION_DBG("notification_ipc_request_load_noti_detail_list done [result: %d]", result);
1036 int notification_ipc_request_get_setting_array(
1037 notification_setting_h *setting_array,
1041 GDBusMessage *reply = NULL;
1042 GVariant *reply_body;
1043 GVariant *iter_body;
1046 notification_setting_h result_setting_array;
1047 notification_setting_h temp;
1050 result = _dbus_init();
1051 if (result != NOTIFICATION_ERROR_NONE) {
1052 NOTIFICATION_ERR("Can't init dbus %d", result);
1056 result = _send_sync_noti(NULL, &reply, "get_setting_array");
1058 if (result == NOTIFICATION_ERROR_NONE) {
1059 reply_body = g_dbus_message_get_body(reply);
1060 g_variant_get(reply_body, "(ia(v))", &setting_cnt, &iter);
1062 NOTIFICATION_DBG("get setting arr cnt: %d", setting_cnt);
1063 result_setting_array = (struct notification_setting *)malloc(sizeof(struct notification_setting) * setting_cnt);
1064 if (result_setting_array == NULL) {
1065 NOTIFICATION_ERR("malloc failed");
1066 g_object_unref(reply);
1067 g_variant_iter_free(iter);
1068 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1072 while (g_variant_iter_loop(iter, "(v)", &iter_body)) {
1073 temp = result_setting_array + setting_idx;
1074 notification_ipc_make_setting_from_gvariant(temp, iter_body);
1078 *count = setting_cnt;
1079 *setting_array = result_setting_array;
1080 g_variant_iter_free(iter);
1084 g_object_unref(reply);
1086 NOTIFICATION_DBG("notification_ipc_request_get_setting_array done [result: %d]", result);
1090 int notification_ipc_request_get_setting_by_package_name(
1091 const char *package_name, notification_setting_h *setting)
1094 GDBusMessage *reply = NULL;
1096 GVariant *reply_body;
1097 GVariant *setting_body;
1098 notification_setting_h result_setting;
1100 result = _dbus_init();
1101 if (result != NOTIFICATION_ERROR_NONE) {
1102 NOTIFICATION_ERR("Can't init dbus %d", result);
1106 body = g_variant_new("(s)", package_name);
1107 result = _send_sync_noti(body, &reply, "get_setting_by_package_name");
1109 if (result == NOTIFICATION_ERROR_NONE) {
1110 reply_body = g_dbus_message_get_body(reply);
1111 g_variant_get(reply_body, "(v)", &setting_body);
1113 result_setting = (struct notification_setting *)malloc(sizeof(struct notification_setting));
1114 if (result_setting == NULL) {
1115 NOTIFICATION_ERR("malloc failed");
1116 g_object_unref(reply);
1117 g_variant_unref(body);
1118 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1120 notification_ipc_make_setting_from_gvariant(result_setting, setting_body);
1122 *setting = result_setting;
1123 g_variant_unref(setting_body);
1127 g_object_unref(reply);
1129 NOTIFICATION_DBG("notification_ipc_request_get_setting_by_package_name done [result: %d]", result);
1133 int notification_ipc_request_load_system_setting(notification_system_setting_h *setting)
1136 GDBusMessage *reply = NULL;
1137 GVariant *setting_body;
1138 GVariant *reply_body;
1139 notification_system_setting_h result_setting;
1141 result = _dbus_init();
1142 if (result != NOTIFICATION_ERROR_NONE) {
1143 NOTIFICATION_ERR("Can't init dbus %d", result);
1147 result = _send_sync_noti(NULL, &reply, "load_system_setting");
1149 if (result == NOTIFICATION_ERROR_NONE) {
1150 reply_body = g_dbus_message_get_body(reply);
1151 g_variant_get(reply_body, "(v)", &setting_body);
1153 result_setting = (struct notification_system_setting *)malloc(sizeof(struct notification_system_setting));
1154 if (result_setting == NULL) {
1155 NOTIFICATION_ERR("malloc failed");
1156 g_object_unref(reply);
1157 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1159 notification_ipc_make_system_setting_from_gvariant(result_setting, setting_body);
1161 *setting = result_setting;
1162 g_variant_unref(setting_body);
1166 g_object_unref(reply);
1168 NOTIFICATION_DBG("notification_ipc_request_load_system_setting done [result: %d]", result);
1172 int notification_ipc_update_setting(notification_setting_h setting)
1175 GDBusMessage *reply = NULL;
1178 result = _dbus_init();
1179 if (result != NOTIFICATION_ERROR_NONE) {
1180 NOTIFICATION_ERR("Can't init dbus %d", result);
1184 body = g_variant_new("(siii)",
1185 setting->package_name,
1186 (int)(setting->allow_to_notify),
1187 (int)(setting->do_not_disturb_except),
1188 (int)(setting->visibility_class));
1190 result = _send_sync_noti(body, &reply, "update_noti_setting");
1193 g_object_unref(reply);
1195 NOTIFICATION_DBG("notification_ipc_update_setting done [result: %d]", result);
1199 int notification_ipc_update_system_setting(notification_system_setting_h system_setting)
1202 GDBusMessage *reply = NULL;
1205 result = _dbus_init();
1206 if (result != NOTIFICATION_ERROR_NONE) {
1207 NOTIFICATION_ERR("Can't init dbus %d", result);
1211 body = g_variant_new("(ii)",
1212 (int)(system_setting->do_not_disturb),
1213 (int)(system_setting->visibility_class));
1215 result = _send_sync_noti(body, &reply, "update_noti_sys_setting");
1218 g_object_unref(reply);
1220 NOTIFICATION_DBG("notification_ipc_update_system_setting done [result: %d]", result);
1224 EXPORT_API GVariant *notification_ipc_make_gvariant_from_noti(notification_h noti)
1226 NOTIFICATION_DBG("make gvariant from noti");
1228 int b_encode_len = 0;
1229 bundle_raw *args = NULL;
1230 bundle_raw *group_args = NULL;
1231 bundle_raw *b_image_path = NULL;
1232 bundle_raw *b_execute_option = NULL;
1233 bundle_raw *b_service_responding = NULL;
1234 bundle_raw *b_service_single_launch = NULL;
1235 bundle_raw *b_service_multi_launch = NULL;
1236 bundle_raw *b_event_handler[NOTIFICATION_EVENT_TYPE_MAX] = {NULL, };
1237 bundle_raw *b_text = NULL;
1238 bundle_raw *b_key = NULL;
1239 bundle_raw *b_format_args = NULL;
1240 GVariant *body = NULL;
1241 GVariant *result_body = NULL;
1242 GVariantBuilder builder;
1244 g_variant_builder_init(&builder, G_VARIANT_TYPE("a{iv}"));
1245 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_NOTI_TYPE, g_variant_new_int32(noti->type));
1246 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_LAYOUT, g_variant_new_int32(noti->layout));
1247 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_GROUP_ID, g_variant_new_int32(noti->group_id));
1248 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_INTERNAL_GROUP_ID, g_variant_new_int32(noti->internal_group_id));
1249 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_PRIV_ID, g_variant_new_int32(noti->priv_id));
1250 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_CALLER_PKGNAME, g_variant_new_string((const gchar *)noti->caller_pkgname));
1251 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_DISPLAY_APPLIST, g_variant_new_int32(noti->display_applist));
1254 bundle_encode(noti->args, (bundle_raw **)&args, NULL);
1255 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_ARGS, g_variant_new_string((const gchar *)args));
1258 bundle_free_encoded_rawdata(&args);
1261 if (noti->group_args) {
1262 bundle_encode(noti->group_args, (bundle_raw **)&group_args,
1264 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_GROUP_ARGS, g_variant_new_string((const gchar *)group_args));
1267 bundle_free_encoded_rawdata(&group_args);
1270 if (noti->b_execute_option) {
1271 bundle_encode(noti->b_execute_option,
1272 (bundle_raw **)&b_execute_option, &b_encode_len);
1273 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_EXECUTE_OPTION, g_variant_new_string((const gchar *)b_execute_option));
1275 if (b_execute_option)
1276 bundle_free_encoded_rawdata(&b_execute_option);
1279 if (noti->b_service_responding) {
1280 bundle_encode(noti->b_service_responding,
1281 (bundle_raw **)&b_service_responding, &b_encode_len);
1282 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_SERVICE_RESPONDING, g_variant_new_string((const gchar *)b_service_responding));
1284 if (b_service_responding)
1285 bundle_free_encoded_rawdata(&b_service_responding);
1288 if (noti->b_service_single_launch) {
1289 bundle_encode(noti->b_service_single_launch,
1290 (bundle_raw **)&b_service_single_launch, &b_encode_len);
1291 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_SERVICE_SINGLE_LAUNCH, g_variant_new_string((const gchar *)b_service_single_launch));
1293 if (b_service_single_launch)
1294 bundle_free_encoded_rawdata(&b_service_single_launch);
1297 if (noti->b_service_multi_launch) {
1298 bundle_encode(noti->b_service_multi_launch,
1299 (bundle_raw **)&b_service_multi_launch, &b_encode_len);
1300 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_SERVICE_MULTI_LAUNCH, g_variant_new_string((const gchar *)b_service_multi_launch));
1302 if (b_service_multi_launch)
1303 bundle_free_encoded_rawdata(&b_service_multi_launch);
1306 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
1307 if (noti->b_event_handler[i]) {
1308 bundle_encode(noti->b_event_handler[i],
1309 (bundle_raw **)&b_event_handler[i], &b_encode_len);
1310 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_BUTTON1_EVENT + i, g_variant_new_string((const gchar *)b_event_handler[i]));
1312 if (b_event_handler[i])
1313 bundle_free_encoded_rawdata(&b_event_handler[i]);
1317 if (noti->launch_pkgname)
1318 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_LAUNCH_PKGNAME, g_variant_new_string((const gchar *)noti->launch_pkgname));
1320 if (noti->domain != NULL)
1321 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_DOMAIN, g_variant_new_string((const gchar *)noti->domain));
1323 if (noti->dir != NULL)
1324 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_DIR, g_variant_new_string((const gchar *)noti->dir));
1327 bundle_encode(noti->b_text, (bundle_raw **)&b_text, &b_encode_len);
1328 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_TEXT, g_variant_new_string((const gchar *)b_text));
1331 bundle_free_encoded_rawdata(&b_text);
1335 bundle_encode(noti->b_key, (bundle_raw **)&b_key, &b_encode_len);
1336 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_KEY, g_variant_new_string((const gchar *)b_key));
1339 bundle_free_encoded_rawdata(&b_key);
1342 if (noti->b_format_args) {
1343 bundle_encode(noti->b_format_args,
1344 (bundle_raw **)&b_format_args, &b_encode_len);
1345 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_FORMAT_ARGS, g_variant_new_string((const gchar *)b_format_args));
1348 bundle_free_encoded_rawdata(&b_format_args);
1351 if (noti->num_format_args != 0)
1352 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_NUM_FORMAT_ARGS, g_variant_new_int32(noti->num_format_args));
1354 if (noti->b_image_path) {
1355 bundle_encode(noti->b_image_path,
1356 (bundle_raw **)&b_image_path, &b_encode_len);
1357 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_IMAGE_PATH, g_variant_new_string((const gchar *)b_image_path));
1360 bundle_free_encoded_rawdata(&b_image_path);
1363 if (noti->sound_type != NOTIFICATION_SOUND_TYPE_NONE)
1364 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_SOUND_TYPE, g_variant_new_int32(noti->sound_type));
1366 if (noti->sound_path)
1367 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_SOUND_PATH, g_variant_new_string((const gchar *)noti->sound_path));
1369 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_VIBRATION_TYPE, g_variant_new_int32(noti->vibration_type));
1371 if (noti->vibration_path)
1372 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_VIBRATION_PATH, g_variant_new_string((const gchar *)noti->vibration_path));
1374 if (noti->led_operation != NOTIFICATION_LED_OP_OFF)
1375 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_LED_OPERATION, g_variant_new_int32(noti->led_operation));
1377 if (noti->led_argb != 0)
1378 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_LED_ARGB, g_variant_new_int32(noti->led_argb));
1380 if (noti->led_on_ms != 0)
1381 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_LED_ON_MS, g_variant_new_int32(noti->led_on_ms));
1383 if (noti->led_off_ms != 0)
1384 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_LED_OFF_MS, g_variant_new_int32(noti->led_off_ms));
1386 if (noti->time != 0)
1387 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_TIME, g_variant_new_int32(noti->time));
1389 if (noti->insert_time != 0)
1390 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_INSERT_TIME, g_variant_new_int32(noti->insert_time));
1392 if (noti->flags_for_property != 0)
1393 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_FLAGS_FOR_PROPERTY, g_variant_new_int32(noti->flags_for_property));
1395 if (noti->progress_size != 0.0)
1396 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_PROGRESS_SIZE, g_variant_new_double(noti->progress_size));
1398 if (noti->progress_percentage != 0.0)
1399 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_PROGRESS_PERCENTAGE, g_variant_new_double(noti->progress_percentage));
1401 if (noti->app_icon_path != NULL)
1402 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_APP_ICON_PATH, g_variant_new_string((const gchar *)noti->app_icon_path));
1403 if (noti->app_name != NULL)
1404 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_APP_NAME, g_variant_new_string((const gchar *)noti->app_name));
1405 if (noti->temp_title != NULL)
1406 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_TEMP_TITLE, g_variant_new_string((const gchar *)noti->temp_title));
1407 if (noti->temp_content != NULL)
1408 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_TEMP_CONTENT, g_variant_new_string((const gchar *)noti->temp_content));
1409 if (noti->tag != NULL)
1410 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_TAG, g_variant_new_string((const gchar *)noti->tag));
1412 if (noti->ongoing_flag != 0)
1413 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_ONGOING_FLAG, g_variant_new_int32(noti->ongoing_flag));
1414 if (noti->auto_remove != 0)
1415 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_AUTO_REMOVE, g_variant_new_int32(noti->auto_remove));
1417 result_body = g_variant_builder_end(&builder);
1418 body = g_variant_new("(v)", result_body);
1423 static gboolean _variant_to_int_dict(GHashTable **dict, GVariant *variant) {
1430 *dict = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, (GDestroyNotify)g_variant_unref);
1434 g_variant_iter_init(&iter, variant);
1435 while (g_variant_iter_next(&iter, "{iv}", &key, &value)) {
1436 hash_key = (int *)calloc(sizeof(int), 1);
1437 if (hash_key == NULL) {
1438 g_hash_table_remove_all(*dict);
1442 g_hash_table_insert(*dict, (gpointer)hash_key, value);
1447 static gboolean _variant_dict_lookup(GHashTable *dict,
1449 const gchar *format_string,
1455 value = g_hash_table_lookup(dict, (gpointer)&key);
1457 if (value == NULL || !g_variant_check_format_string(value, format_string, FALSE))
1460 va_start(ap, format_string);
1461 g_variant_get_va(value, format_string, NULL, &ap);
1468 * functions creating notification packet
1470 EXPORT_API int notification_ipc_make_noti_from_gvariant(notification_h noti,
1471 GVariant *variant) {
1473 NOTIFICATION_DBG("make noti from GVariant");
1477 char *caller_pkgname = NULL;
1478 char *launch_pkgname = NULL;
1479 bundle_raw *args = NULL;
1480 bundle_raw *group_args = NULL;
1481 bundle_raw *b_execute_option = NULL;
1482 bundle_raw *b_service_responding = NULL;
1483 bundle_raw *b_service_single_launch = NULL;
1484 bundle_raw *b_service_multi_launch = NULL;
1485 bundle_raw *b_event_handler[NOTIFICATION_EVENT_TYPE_MAX] = { NULL, };
1486 char *domain = NULL;
1488 bundle_raw *b_text = NULL;
1489 bundle_raw *b_key = NULL;
1490 bundle_raw *b_format_args = NULL;
1491 bundle_raw *b_image_path = NULL;
1492 char *sound_path = NULL;
1493 char *vibration_path = NULL;
1494 char *app_icon_path = NULL;
1495 char *app_name = NULL;
1496 char *temp_title = NULL;
1497 char *temp_content = NULL;
1501 NOTIFICATION_ERR("invalid data noti NULL");
1502 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1505 if (variant == NULL) {
1506 NOTIFICATION_ERR("invalid data variant NULL");
1507 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1510 if (!_variant_to_int_dict(&dict, variant))
1511 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1513 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_NOTI_TYPE, "i", ¬i->type);
1514 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_LAYOUT, "i", ¬i->layout);
1515 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_GROUP_ID, "i", ¬i->group_id);
1516 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_INTERNAL_GROUP_ID, "i", ¬i->internal_group_id);
1517 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_PRIV_ID, "i", ¬i->priv_id);
1518 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_CALLER_PKGNAME, "&s", &caller_pkgname);
1519 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_LAUNCH_PKGNAME, "&s", &launch_pkgname);
1520 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_ARGS, "&s", &args);
1521 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_GROUP_ARGS, "&s", &group_args);
1522 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_EXECUTE_OPTION, "&s", &b_execute_option);
1523 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_SERVICE_RESPONDING, "&s", &b_service_responding);
1524 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_SERVICE_SINGLE_LAUNCH, "&s", &b_service_single_launch);
1525 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_SERVICE_MULTI_LAUNCH, "&s", &b_service_multi_launch);
1526 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_BUTTON1_EVENT, "&s", ¬i->b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1]);
1527 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_BUTTON2_EVENT, "&s", ¬i->b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_2]);
1528 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_BUTTON3_EVENT, "&s", ¬i->b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_3]);
1529 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_BUTTON4_EVENT, "&s", ¬i->b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_4]);
1530 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_BUTTON5_EVENT, "&s", ¬i->b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_5]);
1531 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_BUTTON6_EVENT, "&s", ¬i->b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_6]);
1532 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_ICON_EVENT, "&s", ¬i->b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_ICON]);
1533 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_THUMBNAIL_EVENT, "&s", ¬i->b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL]);
1534 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_DOMAIN, "&s", &domain);
1535 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_DIR, "&s", &dir);
1536 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_TEXT, "&s", &b_text);
1537 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_KEY, "&s", &b_key);
1538 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_FORMAT_ARGS, "&s", &b_format_args);
1539 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_NUM_FORMAT_ARGS, "i", ¬i->num_format_args);
1540 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_IMAGE_PATH, "&s", &b_image_path);
1541 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_SOUND_TYPE, "i", ¬i->sound_type);
1542 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_SOUND_PATH, "&s", &sound_path);
1543 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_VIBRATION_TYPE, "i", ¬i->vibration_type);
1544 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_VIBRATION_PATH, "&s", &vibration_path);
1545 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_LED_OPERATION, "i", ¬i->led_operation);
1546 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_LED_ARGB, "i", ¬i->led_argb);
1547 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_LED_ON_MS, "i", ¬i->led_on_ms);
1548 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_LED_OFF_MS, "i", ¬i->led_off_ms);
1549 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_TIME, "i", ¬i->time);
1550 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_INSERT_TIME, "i", ¬i->insert_time);
1551 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_FLAGS_FOR_PROPERTY, "i", ¬i->flags_for_property);
1552 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_DISPLAY_APPLIST, "i", ¬i->display_applist);
1553 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_PROGRESS_SIZE, "d", ¬i->progress_size);
1554 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_PROGRESS_PERCENTAGE, "d", ¬i->progress_percentage);
1555 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_APP_ICON_PATH, "&s", &app_icon_path);
1556 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_APP_NAME, "&s", &app_name);
1557 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_TEMP_TITLE, "&s", &temp_title);
1558 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_TEMP_CONTENT, "&s", &temp_content);
1559 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_TAG, "&s", &tag);
1560 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_ONGOING_FLAG, "i", ¬i->ongoing_flag);
1561 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_AUTO_REMOVE, "i", ¬i->auto_remove);
1563 noti->caller_pkgname = _dup_string(caller_pkgname);
1564 noti->launch_pkgname = _dup_string(launch_pkgname);
1565 noti->args = _create_bundle_from_bundle_raw(args);
1566 noti->group_args = _create_bundle_from_bundle_raw(group_args);
1567 noti->b_execute_option = _create_bundle_from_bundle_raw(b_execute_option);
1568 noti->b_service_responding = _create_bundle_from_bundle_raw(
1569 b_service_responding);
1570 noti->b_service_single_launch = _create_bundle_from_bundle_raw(
1571 b_service_single_launch);
1572 noti->b_service_multi_launch = _create_bundle_from_bundle_raw(
1573 b_service_multi_launch);
1574 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
1575 noti->b_event_handler[i] = _create_bundle_from_bundle_raw(
1576 b_event_handler[i]);
1578 noti->domain = _dup_string(domain);
1579 noti->dir = _dup_string(dir);
1580 noti->b_text = _create_bundle_from_bundle_raw(b_text);
1581 noti->b_key = _create_bundle_from_bundle_raw(b_key);
1582 noti->b_format_args = _create_bundle_from_bundle_raw(b_format_args);
1583 noti->b_image_path = _create_bundle_from_bundle_raw(b_image_path);
1584 noti->sound_path = _dup_string(sound_path);
1585 noti->vibration_path = _dup_string(vibration_path);
1586 noti->app_icon_path = _dup_string(app_icon_path);
1587 noti->app_name = _dup_string(app_name);
1588 noti->temp_title = _dup_string(temp_title);
1589 noti->temp_content = _dup_string(temp_content);
1590 noti->tag = _dup_string(tag);
1592 g_hash_table_remove_all(dict);
1594 return NOTIFICATION_ERROR_NONE;
1597 EXPORT_API GVariant *notification_ipc_make_gvariant_from_system_setting(struct notification_system_setting *noti_setting)
1599 GVariant *body = NULL;
1600 body = g_variant_new("(ii)",
1601 noti_setting->do_not_disturb,
1602 noti_setting->visibility_class);
1606 EXPORT_API int notification_ipc_make_system_setting_from_gvariant(struct notification_system_setting *noti_setting,
1610 int visibility_class;
1612 if (noti_setting == NULL) {
1613 NOTIFICATION_ERR("invalid data");
1614 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1616 g_variant_get(variant,
1621 NOTIFICATION_DBG("system setting #### %d, %d",
1622 do_not_disturb, visibility_class);
1624 noti_setting->do_not_disturb = do_not_disturb;
1625 noti_setting->visibility_class = visibility_class;
1627 NOTIFICATION_DBG("system setting2 #### %d, %d",
1628 noti_setting->do_not_disturb, noti_setting->visibility_class);
1630 return NOTIFICATION_ERROR_NONE;
1633 EXPORT_API GVariant *notification_ipc_make_gvariant_from_setting(struct notification_setting *noti_setting)
1635 GVariant *body = NULL;
1637 body = g_variant_new("(siii)",
1638 noti_setting->package_name,
1639 noti_setting->allow_to_notify,
1640 noti_setting->do_not_disturb_except,
1641 noti_setting->visibility_class);
1646 EXPORT_API int notification_ipc_make_setting_from_gvariant(struct notification_setting *noti_setting,
1649 NOTIFICATION_DBG("notification_ipc_make_setting_from_gvariant !!!!");
1651 int allow_to_notify;
1652 int do_not_disturb_except;
1653 int visibility_class;
1655 if (noti_setting == NULL || variant == NULL) {
1656 NOTIFICATION_ERR("invalid data");
1657 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1659 g_variant_get(variant,
1663 &do_not_disturb_except,
1666 NOTIFICATION_DBG("setting from variant %s !!", pkgname);
1668 noti_setting->package_name = _dup_string(pkgname);
1669 noti_setting->allow_to_notify = allow_to_notify;
1670 noti_setting->do_not_disturb_except = do_not_disturb_except;
1671 noti_setting->visibility_class = visibility_class;
1673 NOTIFICATION_DBG("setting from variant %s, %s",
1674 noti_setting->package_name, pkgname);
1676 return NOTIFICATION_ERROR_NONE;
1679 static int _send_service_register()
1681 NOTIFICATION_DBG("service register");
1682 GDBusMessage *reply = NULL;
1685 result = _send_sync_noti(NULL, &reply, "noti_service_register");
1688 g_object_unref(reply);
1690 NOTIFICATION_ERR("_send_service_register done = %s, result = %d", _bus_name, result);
1694 static int _ipc_monitor_register(void)
1696 NOTIFICATION_ERR("register a service\n");
1698 return _send_service_register();
1701 static void _on_name_appeared(GDBusConnection *connection,
1703 const gchar *name_owner,
1706 NOTIFICATION_DBG("name appeared : %s", name);
1707 is_master_started = 1;
1708 _ipc_monitor_register();
1710 /* TODO: dbus activation isn't enough ? */
1711 _do_deffered_task();
1714 static void _on_name_vanished(GDBusConnection *connection,
1718 NOTIFICATION_DBG("name vanished : %s", name);
1719 is_master_started = 0;
1722 int notification_ipc_monitor_init(void)
1727 if (ret != NOTIFICATION_ERROR_NONE) {
1728 NOTIFICATION_ERR("Can't init dbus %d", ret);
1732 ret = _dbus_signal_init();
1733 if (ret != NOTIFICATION_ERROR_NONE) {
1734 NOTIFICATION_ERR("Can't signal_init %d", ret);
1738 ret = _ipc_monitor_register();
1739 if (ret != NOTIFICATION_ERROR_NONE) {
1740 NOTIFICATION_ERR("Can't init ipc_monitor_register %d", ret);
1744 if (provider_monitor_id == 0) {
1745 provider_monitor_id = g_bus_watch_name_on_connection(
1748 G_BUS_NAME_WATCHER_FLAGS_NONE,
1754 if (provider_monitor_id == 0) {
1755 g_dbus_connection_signal_unsubscribe(_gdbus_conn, monitor_id);
1757 NOTIFICATION_ERR("watch on name fail");
1758 return NOTIFICATION_ERROR_IO_ERROR;
1762 return NOTIFICATION_ERROR_NONE;
1765 static int _ipc_monitor_deregister(void)
1767 if (provider_monitor_id) {
1768 g_bus_unwatch_name(provider_monitor_id);
1769 provider_monitor_id = 0;
1773 g_dbus_connection_signal_unsubscribe(_gdbus_conn, monitor_id);
1777 return NOTIFICATION_ERROR_NONE;
1780 int notification_ipc_monitor_fini(void)
1782 return _ipc_monitor_deregister();