2 * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 #include <bundle_internal.h>
24 #include <notification_ipc.h>
25 #include <notification_db.h>
26 #include <notification_type.h>
27 #include <notification_private.h>
28 #include <notification_debug.h>
29 #include <notification_setting.h>
30 #include <notification_setting_internal.h>
31 #include <notification_internal.h>
35 #define PROVIDER_BUS_NAME "org.tizen.data_provider_service"
36 #define PROVIDER_OBJECT_PATH "/org/tizen/data_provider_service"
37 #define PROVIDER_NOTI_INTERFACE_NAME "org.tizen.data_provider_noti_service"
39 #define DBUS_SERVICE_DBUS "org.freedesktop.DBus"
40 #define DBUS_PATH_DBUS "/org/freedesktop/DBus"
41 #define DBUS_INTERFACE_DBUS "org.freedesktop.DBus"
42 #define ERR_BUFFER_SIZE 1024
44 static const gchar *_bus_name = NULL;
45 static GDBusConnection *_gdbus_conn = NULL;
46 static int monitor_id = 0;
47 static int provider_monitor_id = 0;
48 static int is_master_started = 0;
50 typedef struct _result_cb_item {
51 void (*result_cb)(int priv_id, int result, void *data);
55 typedef struct _task_list task_list;
60 void (*task_cb) (void *data);
64 static task_list *g_task_list;
66 static int _ipc_monitor_register(void);
67 static int _ipc_monitor_deregister(void);
68 static void _do_deffered_task(void);
70 static void _print_noti(notification_h noti)
75 const char *tag = NULL;
76 notification_vibration_type_e vib_type = NOTIFICATION_VIBRATION_TYPE_NONE;
78 notification_get_pkgname(noti, &pkgname);
79 notification_get_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, &text);
80 notification_get_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, &content);
81 notification_get_tag(noti, &tag);
82 notification_get_vibration(noti, &vib_type, NULL);
84 NOTIFICATION_DBG("client print_noti pkgname = %s ", pkgname);
85 NOTIFICATION_DBG("client print_noti title = %s ", text);
86 NOTIFICATION_DBG("client print_noti content = %s ", content);
87 NOTIFICATION_DBG("client print_noti tag = %s ", tag);
88 NOTIFICATION_DBG("client print_noti priv_id = %d ", noti->priv_id);
89 NOTIFICATION_DBG("client print_noti vibration_path = %s ", noti->vibration_path);
90 NOTIFICATION_DBG("client print_noti vibration_type = %d ", vib_type);
93 static inline char *_string_get(char *string)
98 if (string[0] == '\0')
104 static int _dbus_init()
106 int ret = NOTIFICATION_ERROR_NONE;
107 GError *error = NULL;
109 if (_gdbus_conn == NULL) {
110 _gdbus_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
112 if (_gdbus_conn == NULL) {
114 NOTIFICATION_ERR("Failed to get dbus [%s]", error->message);
117 return NOTIFICATION_ERROR_IO_ERROR;
119 _bus_name = g_dbus_connection_get_unique_name(_gdbus_conn);
120 NOTIFICATION_DBG("bus name : %s", _bus_name);
122 notification_error_quark();
124 ret = NOTIFICATION_ERROR_NONE;
129 int notification_ipc_is_master_ready(void)
134 int ret = NOTIFICATION_ERROR_NONE;
137 if (ret != NOTIFICATION_ERROR_NONE) {
138 NOTIFICATION_ERR("Can't init dbus %d", ret);
139 is_master_started = 0;
140 return is_master_started;
143 result = g_dbus_connection_call_sync(
149 g_variant_new("(s)", PROVIDER_BUS_NAME),
150 G_VARIANT_TYPE("(b)"),
151 G_DBUS_CALL_FLAGS_NONE,
156 if (err || (result == NULL)) {
158 NOTIFICATION_ERR("No reply. error = %s", err->message);
161 NOTIFICATION_ERR("is master ready fail");
162 is_master_started = 0;
164 g_variant_get(result, "(b)", &name_exist);
167 NOTIFICATION_ERR("Name not exist %s", PROVIDER_BUS_NAME);
168 NOTIFICATION_ERR("the master has been stopped");
169 is_master_started = 0;
171 NOTIFICATION_DBG("the master has been started");
172 is_master_started = 1;
177 g_variant_unref(result);
179 return is_master_started;
182 /* TODO: dbus activation isn't enough ? */
184 * store tasks when daemon stopped
186 int notification_ipc_add_deffered_task(
187 void (*deferred_task_cb)(void *data),
194 (task_list *) malloc(sizeof(task_list));
196 if (list_new == NULL)
197 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
199 list_new->next = NULL;
200 list_new->prev = NULL;
202 list_new->task_cb = deferred_task_cb;
203 list_new->data = user_data;
205 if (g_task_list == NULL) {
206 g_task_list = list_new;
210 while (list->next != NULL)
213 list->next = list_new;
214 list_new->prev = list;
216 return NOTIFICATION_ERROR_NONE;
219 int notification_ipc_del_deffered_task(
220 void (*deferred_task_cb)(void *data))
223 task_list *list_prev;
224 task_list *list_next;
226 list_del = g_task_list;
228 if (list_del == NULL)
229 return NOTIFICATION_ERROR_INVALID_PARAMETER;
231 while (list_del->prev != NULL)
232 list_del = list_del->prev;
235 if (list_del->task_cb == deferred_task_cb) {
236 list_prev = list_del->prev;
237 list_next = list_del->next;
239 if (list_prev == NULL)
240 g_task_list = list_next;
242 list_prev->next = list_next;
244 if (list_next == NULL) {
245 if (list_prev != NULL)
246 list_prev->next = NULL;
248 list_next->prev = list_prev;
252 return NOTIFICATION_ERROR_NONE;
254 list_del = list_del->next;
255 } while (list_del != NULL);
257 return NOTIFICATION_ERROR_INVALID_PARAMETER;
260 static void _do_deffered_task(void)
263 task_list *list_temp;
265 if (g_task_list == NULL)
268 list_do = g_task_list;
271 while (list_do->prev != NULL)
272 list_do = list_do->prev;
274 while (list_do != NULL) {
275 if (list_do->task_cb != NULL) {
276 list_do->task_cb(list_do->data);
277 NOTIFICATION_DBG("called:%p", list_do->task_cb);
279 list_temp = list_do->next;
286 * functions to create operation list
288 static notification_op *_ipc_create_op(notification_op_type_e type,
289 int num_op, int *list_priv_id, int num_priv_id, notification_h *noti_list)
292 notification_op *op_list;
297 op_list = (notification_op *)malloc(sizeof(notification_op) * num_op);
299 if (op_list == NULL) {
300 NOTIFICATION_ERR("malloc failed");
304 memset(op_list, 0x0, sizeof(notification_op) * num_op);
306 for (i = 0; i < num_op; i++) {
307 (op_list + i)->type = type;
308 if (list_priv_id != NULL)
309 (op_list + i)->priv_id = *(list_priv_id + i);
310 if (noti_list != NULL)
311 (op_list + i)->noti = *(noti_list + i);
318 * utility functions creating notification packet
320 static inline char *_dup_string(const char *string)
323 char err_buf[ERR_BUFFER_SIZE];
327 if (string[0] == '\0')
330 ret = strdup(string);
332 NOTIFICATION_ERR("Error: %s\n", strerror_r(errno, err_buf, sizeof(err_buf)));
337 static inline bundle *_create_bundle_from_bundle_raw(bundle_raw *string)
341 if (string[0] == '\0')
344 return bundle_decode(string, strlen((char *)string));
347 static void _add_noti_notify(GVariant *parameters)
350 notification_op *noti_op;
351 GVariant *body = NULL;
353 NOTIFICATION_DBG("add noti notify");
354 noti = notification_create(NOTIFICATION_TYPE_NOTI);
356 NOTIFICATION_ERR("failed to create a notification");
360 g_variant_get(parameters, "(v)", &body);
361 notification_ipc_make_noti_from_gvariant(noti, body);
363 if (noti->flags_for_property & NOTIFICATION_PROP_DISABLE_UPDATE_ON_INSERT) {
364 NOTIFICATION_ERR("disable changed callback %d", noti->flags_for_property);
365 /* Disable changed cb */
367 /* Enable changed cb */
368 noti_op = _ipc_create_op(NOTIFICATION_OP_INSERT, 1, &(noti->priv_id), 1, ¬i);
370 if (noti_op != NULL) {
371 notification_call_changed_cb(noti_op, 1);
375 notification_free(noti);
378 static void _update_noti_notify(GVariant *parameters)
381 notification_op *noti_op;
382 GVariant *body = NULL;
384 noti = notification_create(NOTIFICATION_TYPE_NOTI);
386 NOTIFICATION_ERR("failed to create a notification");
389 g_variant_get(parameters, "(v)", &body);
390 notification_ipc_make_noti_from_gvariant(noti, body);
393 noti_op = _ipc_create_op(NOTIFICATION_OP_UPDATE, 1, &(noti->priv_id), 1, ¬i);
394 if (noti_op != NULL) {
395 notification_call_changed_cb(noti_op, 1);
398 notification_free(noti);
401 static void _refresh_noti_notify(GVariant *parameters)
403 notification_op *noti_op = _ipc_create_op(NOTIFICATION_OP_REFRESH, 1, NULL, 0, NULL);
405 if (noti_op != NULL) {
406 notification_call_changed_cb(noti_op, 1);
411 static void _delete_single_notify(GVariant *parameters)
415 notification_op *noti_op;
418 g_variant_get(parameters, "(ii)", &num_deleted, &priv_id);
420 noti_op = _ipc_create_op(NOTIFICATION_OP_DELETE, 1, &priv_id, 1, NULL);
421 if (noti_op != NULL) {
422 notification_call_changed_cb(noti_op, 1);
427 static void _delete_multiple_notify(GVariant *parameters)
431 notification_op *noti_op;
434 g_variant_get(parameters, "(a(i))", &iter);
435 while (g_variant_iter_loop(iter, "(i)", &buf[idx])) {
436 NOTIFICATION_DBG("delete_noti_multiple priv_id : %d", buf[idx]);
439 g_variant_iter_free(iter);
441 NOTIFICATION_DBG("data num deleted:%d", idx);
442 noti_op = _ipc_create_op(NOTIFICATION_OP_DELETE, idx, buf, idx, NULL);
444 if (noti_op == NULL) {
445 NOTIFICATION_ERR("_ipc_create_op failed");
448 notification_call_changed_cb(noti_op, idx);
452 static void _handle_noti_notify(GDBusConnection *connection,
453 const gchar *sender_name,
454 const gchar *object_path,
455 const gchar *interface_name,
456 const gchar *signal_name,
457 GVariant *parameters,
460 NOTIFICATION_DBG("signal_name: %s", signal_name);
462 if (g_strcmp0(signal_name, "add_noti_notify") == 0)
463 _add_noti_notify(parameters);
464 else if (g_strcmp0(signal_name, "update_noti_notify") == 0)
465 _update_noti_notify(parameters);
466 else if (g_strcmp0(signal_name, "delete_single_notify") == 0)
467 _delete_single_notify(parameters);
468 else if (g_strcmp0(signal_name, "delete_multiple_notify") == 0)
469 _delete_multiple_notify(parameters);
470 else if (g_strcmp0(signal_name, "refresh_noti_notify") == 0)
471 _refresh_noti_notify(parameters);
475 static int _dbus_signal_init()
478 int ret = NOTIFICATION_ERROR_NONE;
480 if (monitor_id == 0) {
481 id = g_dbus_connection_signal_subscribe(_gdbus_conn,
483 PROVIDER_NOTI_INTERFACE_NAME, /* interface */
485 PROVIDER_OBJECT_PATH, /* path */
487 G_DBUS_SIGNAL_FLAGS_NONE,
492 NOTIFICATION_DBG("subscribe id : %d", id);
494 ret = NOTIFICATION_ERROR_IO_ERROR;
495 NOTIFICATION_ERR("Failed to _register_noti_dbus_interface");
498 ret = NOTIFICATION_ERROR_NONE;
504 static int _send_sync_noti(GVariant *body, GDBusMessage **reply, char *cmd)
506 int ret = NOTIFICATION_ERROR_NONE;
510 msg = g_dbus_message_new_method_call(
512 PROVIDER_OBJECT_PATH,
513 PROVIDER_NOTI_INTERFACE_NAME,
516 NOTIFICATION_ERR("Can't allocate new method call");
518 g_variant_unref(body);
519 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
523 g_dbus_message_set_body(msg, body);
525 *reply = g_dbus_connection_send_message_with_reply_sync(
528 G_DBUS_SEND_MESSAGE_FLAGS_NONE,
537 ret = NOTIFICATION_ERROR_SERVICE_NOT_READY;
539 NOTIFICATION_ERR("No reply. cmd = %s, error = %s", cmd, err->message);
540 if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
541 ret = NOTIFICATION_ERROR_PERMISSION_DENIED;
547 if (g_dbus_message_to_gerror(*reply, &err)) {
548 if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
549 ret = NOTIFICATION_ERROR_PERMISSION_DENIED;
553 NOTIFICATION_ERR("_send_sync_noti cmd = %s, error %s, err code %d", cmd, err->message, ret);
557 NOTIFICATION_DBG("_send_sync_noti done !!");
558 return NOTIFICATION_ERROR_NONE;
562 static void _send_message_with_reply_async_cb(GDBusConnection *connection,
567 int result = NOTIFICATION_ERROR_NONE;
569 GDBusMessage *reply = NULL;
571 result_cb_item *cb_item = (result_cb_item *)user_data;
573 if (cb_item == NULL) {
574 NOTIFICATION_ERR("Failed to get a callback item");
578 reply = g_dbus_connection_send_message_with_reply_finish(
585 NOTIFICATION_ERR("No reply. error = %s", err->message);
588 result = NOTIFICATION_ERROR_SERVICE_NOT_READY;
590 } else if (g_dbus_message_to_gerror(reply, &err)) {
591 if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
592 result = NOTIFICATION_ERROR_PERMISSION_DENIED;
596 NOTIFICATION_ERR("_send_async_noti error %s", err->message);
600 NOTIFICATION_DBG("_send_async_noti done !![%d]", result);
602 if (result == NOTIFICATION_ERROR_NONE) {
603 body = g_dbus_message_get_body(reply);
604 g_variant_get(body, "(i)", &priv_id);
606 if (cb_item->result_cb)
607 cb_item->result_cb(priv_id, result, cb_item->data);
610 if (cb_item->result_cb)
611 cb_item->result_cb(NOTIFICATION_PRIV_ID_NONE, result, cb_item->data);
615 g_object_unref(reply);
619 static int _send_async_noti(GVariant *body, result_cb_item *cb_item, char *cmd)
623 msg = g_dbus_message_new_method_call(
625 PROVIDER_OBJECT_PATH,
626 PROVIDER_NOTI_INTERFACE_NAME,
629 NOTIFICATION_ERR("Can't allocate new method call");
630 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
634 g_dbus_message_set_body(msg, body);
636 g_dbus_connection_send_message_with_reply(
639 G_DBUS_SEND_MESSAGE_FLAGS_NONE,
643 (GAsyncReadyCallback)_send_message_with_reply_async_cb,
646 NOTIFICATION_DBG("_send_async_noti done !!");
649 return NOTIFICATION_ERROR_NONE;
652 int notification_ipc_request_insert(notification_h noti, int *priv_id)
655 int id = NOTIFICATION_PRIV_ID_NONE;
656 GDBusMessage *reply = NULL;
658 GVariant *reply_body;
660 result = _dbus_init();
661 if (result != NOTIFICATION_ERROR_NONE) {
662 NOTIFICATION_ERR("Can't init dbus %d", result);
666 /* Initialize private ID */
667 noti->priv_id = NOTIFICATION_PRIV_ID_NONE;
668 noti->group_id = NOTIFICATION_GROUP_ID_NONE;
669 noti->internal_group_id = NOTIFICATION_GROUP_ID_NONE;
672 body = notification_ipc_make_gvariant_from_noti(noti, false);
674 NOTIFICATION_ERR("cannot make gvariant");
675 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
678 result = _send_sync_noti(body, &reply, "add_noti");
679 NOTIFICATION_DBG("_send_sync_noti %d", result);
681 if (result == NOTIFICATION_ERROR_NONE) {
682 reply_body = g_dbus_message_get_body(reply);
683 g_variant_get(reply_body, "(i)", &id);
690 g_object_unref(reply);
692 NOTIFICATION_DBG("notification_ipc_request_insert done [priv_id : %d, result: %d]", id, result);
696 int notification_ipc_request_update(notification_h noti)
699 int priv_id = NOTIFICATION_PRIV_ID_NONE;
701 GDBusMessage *reply = NULL;
703 GVariant *reply_body;
705 result = _dbus_init();
706 if (result != NOTIFICATION_ERROR_NONE) {
707 NOTIFICATION_ERR("Can't init dbus %d", result);
711 body = notification_ipc_make_gvariant_from_noti(noti, false);
713 NOTIFICATION_ERR("cannot make gvariant");
714 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
717 result = _send_sync_noti(body, &reply, "update_noti");
718 if (result == NOTIFICATION_ERROR_NONE) {
719 reply_body = g_dbus_message_get_body(reply);
720 g_variant_get(reply_body, "(i)", &priv_id);
724 g_object_unref(reply);
726 NOTIFICATION_DBG("notification_ipc_request_update done [result: %d, priv_id :%d]", result, priv_id);
730 int notification_ipc_request_update_async(notification_h noti,
731 void (*result_cb)(int priv_id, int result, void *data), void *user_data)
734 result_cb_item *cb_item;
737 result = _dbus_init();
738 if (result != NOTIFICATION_ERROR_NONE) {
739 NOTIFICATION_ERR("Can't init dbus %d", result);
743 cb_item = calloc(1, sizeof(result_cb_item));
745 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
747 cb_item->result_cb = result_cb;
748 cb_item->data = user_data;
750 body = notification_ipc_make_gvariant_from_noti(noti, false);
752 NOTIFICATION_ERR("cannot make gvariant");
754 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
757 result = _send_async_noti(body, cb_item, "update_noti");
758 NOTIFICATION_DBG("notification_ipc_request_update_async done [result: %d]", result);
760 if (result != NOTIFICATION_ERROR_NONE) {
765 g_variant_unref(body);
770 int notification_ipc_request_refresh(void)
773 GDBusMessage *reply = NULL;
776 result = _dbus_init();
777 if (result != NOTIFICATION_ERROR_NONE) {
778 NOTIFICATION_ERR("Can't init dbus %d", result);
782 body = g_variant_new("(i)", NOTIFICATION_OP_REFRESH);
783 result = _send_sync_noti(body, &reply, "refresh_noti");
786 g_object_unref(reply);
788 NOTIFICATION_ERR("notification_ipc_request_refresh done [result: %d]", result);
792 int notification_ipc_request_delete_single(notification_type_e type, char *pkgname, int priv_id)
796 GDBusMessage *reply = NULL;
798 GVariant *reply_body;
800 result = _dbus_init();
801 if (result != NOTIFICATION_ERROR_NONE) {
802 NOTIFICATION_ERR("Can't init dbus %d", result);
806 body = g_variant_new("(si)", pkgname, priv_id);
807 result = _send_sync_noti(body, &reply, "del_noti_single");
809 if (result == NOTIFICATION_ERROR_NONE) {
810 reply_body = g_dbus_message_get_body(reply);
811 g_variant_get(reply_body, "(i)", &id);
815 g_object_unref(reply);
817 NOTIFICATION_ERR("notification_ipc_request_delete_single done [result: %d]", result);
821 int notification_ipc_request_delete_multiple(notification_type_e type, char *pkgname)
826 GVariant *reply_body;
827 GDBusMessage *reply = NULL;
829 result = _dbus_init();
830 if (result != NOTIFICATION_ERROR_NONE) {
831 NOTIFICATION_ERR("Can't init dbus %d", result);
838 body = g_variant_new("(si)", pkgname, type);
839 result = _send_sync_noti(body, &reply, "del_noti_multiple");
841 if (result == NOTIFICATION_ERROR_NONE) {
842 reply_body = g_dbus_message_get_body(reply);
843 g_variant_get(reply_body, "(i)", &num_deleted);
844 NOTIFICATION_ERR("num deleted:%d", num_deleted);
848 g_object_unref(reply);
853 int notification_ipc_request_load_noti_by_tag(notification_h noti, const char *pkgname, const char *tag)
856 GDBusMessage *reply = NULL;
858 GVariant *reply_body;
861 result = _dbus_init();
862 if (result != NOTIFICATION_ERROR_NONE) {
863 NOTIFICATION_ERR("Can't init dbus %d", result);
870 body = g_variant_new("(ss)", pkgname, tag);
871 result = _send_sync_noti(body, &reply, "load_noti_by_tag");
873 if (result == NOTIFICATION_ERROR_NONE) {
874 reply_body = g_dbus_message_get_body(reply);
875 g_variant_get(reply_body, "(v)", ¬i_body);
877 notification_ipc_make_noti_from_gvariant(noti, noti_body);
878 g_variant_unref(noti_body);
884 g_object_unref(reply);
886 NOTIFICATION_DBG("notification_ipc_request_load_noti_by_tag done [result: %d]", result);
890 int notification_ipc_request_load_noti_by_priv_id(notification_h noti, const char *pkgname, int priv_id)
893 GDBusMessage *reply = NULL;
895 GVariant *reply_body;
898 result = _dbus_init();
899 if (result != NOTIFICATION_ERROR_NONE) {
900 NOTIFICATION_ERR("Can't init dbus %d", result);
907 body = g_variant_new("(si)", pkgname, priv_id);
908 result = _send_sync_noti(body, &reply, "load_noti_by_priv_id");
910 if (result == NOTIFICATION_ERROR_NONE) {
911 reply_body = g_dbus_message_get_body(reply);
912 g_variant_get(reply_body, "(v)", ¬i_body);
914 notification_ipc_make_noti_from_gvariant(noti, noti_body);
915 g_variant_unref(noti_body);
920 g_object_unref(reply);
922 NOTIFICATION_DBG("notification_ipc_request_load_noti_by_priv_id done [result: %d]", result);
926 int notification_ipc_request_get_count(notification_type_e type,
927 const char *pkgname, int group_id, int priv_id, int *count)
930 GDBusMessage *reply = NULL;
932 GVariant *reply_body;
935 result = _dbus_init();
936 if (result != NOTIFICATION_ERROR_NONE) {
937 NOTIFICATION_ERR("Can't init dbus %d", result);
944 body = g_variant_new("(isii)", type, pkgname, group_id, priv_id);
945 result = _send_sync_noti(body, &reply, "get_noti_count");
947 if (result == NOTIFICATION_ERROR_NONE) {
948 reply_body = g_dbus_message_get_body(reply);
949 g_variant_get(reply_body, "(i)", &re_count);
952 NOTIFICATION_DBG("noti count [%d]", re_count);
956 g_object_unref(reply);
958 NOTIFICATION_DBG("notification_ipc_request_get_count done [result: %d]", result);
962 int notification_ipc_request_load_noti_grouping_list(notification_type_e type, int count,
963 notification_list_h *list)
966 GDBusMessage *reply = NULL;
968 GVariant *reply_body;
974 result = _dbus_init();
975 if (result != NOTIFICATION_ERROR_NONE) {
976 NOTIFICATION_ERR("Can't init dbus %d", result);
980 body = g_variant_new("(ii)", type, count);
981 result = _send_sync_noti(body, &reply, "load_noti_grouping_list");
983 if (result == NOTIFICATION_ERROR_NONE) {
984 reply_body = g_dbus_message_get_body(reply);
985 g_variant_get(reply_body, "(a(v))", &iter);
987 while (g_variant_iter_loop(iter, "(v)", &iter_body)) {
988 noti = notification_create(NOTIFICATION_TYPE_NOTI);
989 g_variant_get(iter_body, "(v)", ¬i_body);
990 notification_ipc_make_noti_from_gvariant(noti, noti_body);
992 *list = notification_list_append(*list, noti);
994 g_variant_iter_free(iter);
998 g_object_unref(reply);
1000 NOTIFICATION_DBG("notification_ipc_request_load_noti_grouping_list done [result: %d]", result);
1004 int notification_ipc_request_load_noti_detail_list(const char *pkgname,
1008 notification_list_h *list)
1011 GDBusMessage *reply = NULL;
1013 GVariant *reply_body;
1014 GVariant *iter_body;
1016 notification_h noti;
1017 GVariant *noti_body;
1019 result = _dbus_init();
1020 if (result != NOTIFICATION_ERROR_NONE) {
1021 NOTIFICATION_ERR("Can't init dbus %d", result);
1025 body = g_variant_new("(siii)", pkgname, group_id, priv_id, count);
1026 result = _send_sync_noti(body, &reply, "load_noti_detail_list");
1028 if (result == NOTIFICATION_ERROR_NONE) {
1029 reply_body = g_dbus_message_get_body(reply);
1030 g_variant_get(reply_body, "(a(v))", &iter);
1032 while (g_variant_iter_loop(iter, "(v)", &iter_body)) {
1033 noti = notification_create(NOTIFICATION_TYPE_NOTI);
1034 g_variant_get(iter_body, "(v)", ¬i_body);
1035 notification_ipc_make_noti_from_gvariant(noti, noti_body);
1037 *list = notification_list_append(*list, noti);
1039 g_variant_iter_free(iter);
1043 g_object_unref(reply);
1045 NOTIFICATION_DBG("notification_ipc_request_load_noti_detail_list done [result: %d]", result);
1049 int notification_ipc_request_get_setting_array(
1050 notification_setting_h *setting_array,
1054 GDBusMessage *reply = NULL;
1055 GVariant *reply_body;
1056 GVariant *iter_body;
1059 notification_setting_h result_setting_array;
1060 notification_setting_h temp;
1063 result = _dbus_init();
1064 if (result != NOTIFICATION_ERROR_NONE) {
1065 NOTIFICATION_ERR("Can't init dbus %d", result);
1069 result = _send_sync_noti(NULL, &reply, "get_setting_array");
1071 if (result == NOTIFICATION_ERROR_NONE) {
1072 reply_body = g_dbus_message_get_body(reply);
1073 g_variant_get(reply_body, "(ia(v))", &setting_cnt, &iter);
1075 NOTIFICATION_DBG("get setting arr cnt: %d", setting_cnt);
1076 result_setting_array = (struct notification_setting *)malloc(sizeof(struct notification_setting) * setting_cnt);
1077 if (result_setting_array == NULL) {
1078 NOTIFICATION_ERR("malloc failed");
1079 g_object_unref(reply);
1080 g_variant_iter_free(iter);
1081 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1085 while (g_variant_iter_loop(iter, "(v)", &iter_body)) {
1086 temp = result_setting_array + setting_idx;
1087 notification_ipc_make_setting_from_gvariant(temp, iter_body);
1091 *count = setting_cnt;
1092 *setting_array = result_setting_array;
1093 g_variant_iter_free(iter);
1097 g_object_unref(reply);
1099 NOTIFICATION_DBG("notification_ipc_request_get_setting_array done [result: %d]", result);
1103 int notification_ipc_request_get_setting_by_package_name(
1104 const char *package_name, notification_setting_h *setting)
1107 GDBusMessage *reply = NULL;
1109 GVariant *reply_body;
1110 GVariant *setting_body;
1111 notification_setting_h result_setting;
1113 result = _dbus_init();
1114 if (result != NOTIFICATION_ERROR_NONE) {
1115 NOTIFICATION_ERR("Can't init dbus %d", result);
1119 body = g_variant_new("(s)", package_name);
1120 result = _send_sync_noti(body, &reply, "get_setting_by_package_name");
1122 if (result == NOTIFICATION_ERROR_NONE) {
1123 reply_body = g_dbus_message_get_body(reply);
1124 g_variant_get(reply_body, "(v)", &setting_body);
1126 result_setting = (struct notification_setting *)malloc(sizeof(struct notification_setting));
1127 if (result_setting == NULL) {
1128 NOTIFICATION_ERR("malloc failed");
1129 g_object_unref(reply);
1130 g_variant_unref(body);
1131 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1133 notification_ipc_make_setting_from_gvariant(result_setting, setting_body);
1135 *setting = result_setting;
1136 g_variant_unref(setting_body);
1140 g_object_unref(reply);
1142 NOTIFICATION_DBG("notification_ipc_request_get_setting_by_package_name done [result: %d]", result);
1146 int notification_ipc_request_load_system_setting(notification_system_setting_h *setting)
1149 GDBusMessage *reply = NULL;
1150 GVariant *setting_body;
1151 GVariant *reply_body;
1152 notification_system_setting_h result_setting;
1154 result = _dbus_init();
1155 if (result != NOTIFICATION_ERROR_NONE) {
1156 NOTIFICATION_ERR("Can't init dbus %d", result);
1160 result = _send_sync_noti(NULL, &reply, "load_system_setting");
1162 if (result == NOTIFICATION_ERROR_NONE) {
1163 reply_body = g_dbus_message_get_body(reply);
1164 g_variant_get(reply_body, "(v)", &setting_body);
1166 result_setting = (struct notification_system_setting *)malloc(sizeof(struct notification_system_setting));
1167 if (result_setting == NULL) {
1168 NOTIFICATION_ERR("malloc failed");
1169 g_object_unref(reply);
1170 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1172 notification_ipc_make_system_setting_from_gvariant(result_setting, setting_body);
1174 *setting = result_setting;
1175 g_variant_unref(setting_body);
1179 g_object_unref(reply);
1181 NOTIFICATION_DBG("notification_ipc_request_load_system_setting done [result: %d]", result);
1185 int notification_ipc_update_setting(notification_setting_h setting)
1188 GDBusMessage *reply = NULL;
1191 result = _dbus_init();
1192 if (result != NOTIFICATION_ERROR_NONE) {
1193 NOTIFICATION_ERR("Can't init dbus %d", result);
1197 body = g_variant_new("(siii)",
1198 setting->package_name,
1199 (int)(setting->allow_to_notify),
1200 (int)(setting->do_not_disturb_except),
1201 (int)(setting->visibility_class));
1203 result = _send_sync_noti(body, &reply, "update_noti_setting");
1206 g_object_unref(reply);
1208 NOTIFICATION_DBG("notification_ipc_update_setting done [result: %d]", result);
1212 int notification_ipc_update_system_setting(notification_system_setting_h system_setting)
1215 GDBusMessage *reply = NULL;
1218 result = _dbus_init();
1219 if (result != NOTIFICATION_ERROR_NONE) {
1220 NOTIFICATION_ERR("Can't init dbus %d", result);
1224 body = g_variant_new("(ii)",
1225 (int)(system_setting->do_not_disturb),
1226 (int)(system_setting->visibility_class));
1228 result = _send_sync_noti(body, &reply, "update_noti_sys_setting");
1231 g_object_unref(reply);
1233 NOTIFICATION_DBG("notification_ipc_update_system_setting done [result: %d]", result);
1237 EXPORT_API GVariant *notification_ipc_make_gvariant_from_noti(notification_h noti, bool translate)
1239 NOTIFICATION_DBG("make gvariant from noti");
1241 int b_encode_len = 0;
1242 bundle_raw *args = NULL;
1243 bundle_raw *group_args = NULL;
1244 bundle_raw *b_image_path = NULL;
1245 bundle_raw *b_execute_option = NULL;
1246 bundle_raw *b_service_responding = NULL;
1247 bundle_raw *b_service_single_launch = NULL;
1248 bundle_raw *b_service_multi_launch = NULL;
1249 bundle_raw *b_event_handler[NOTIFICATION_EVENT_TYPE_MAX] = {NULL, };
1250 bundle_raw *b_text = NULL;
1251 bundle_raw *b_key = NULL;
1252 bundle_raw *b_format_args = NULL;
1253 GVariant *body = NULL;
1254 GVariant *result_body = NULL;
1255 GVariantBuilder builder;
1258 notification_translate_localized_text(noti);
1260 g_variant_builder_init(&builder, G_VARIANT_TYPE("a{iv}"));
1261 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_NOTI_TYPE, g_variant_new_int32(noti->type));
1262 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_LAYOUT, g_variant_new_int32(noti->layout));
1263 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_GROUP_ID, g_variant_new_int32(noti->group_id));
1264 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_INTERNAL_GROUP_ID, g_variant_new_int32(noti->internal_group_id));
1265 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_PRIV_ID, g_variant_new_int32(noti->priv_id));
1266 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_CALLER_PKGNAME, g_variant_new_string((const gchar *)noti->caller_pkgname));
1267 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_DISPLAY_APPLIST, g_variant_new_int32(noti->display_applist));
1270 bundle_encode(noti->args, (bundle_raw **)&args, NULL);
1271 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_ARGS, g_variant_new_string((const gchar *)args));
1274 bundle_free_encoded_rawdata(&args);
1277 if (noti->group_args) {
1278 bundle_encode(noti->group_args, (bundle_raw **)&group_args,
1280 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_GROUP_ARGS, g_variant_new_string((const gchar *)group_args));
1283 bundle_free_encoded_rawdata(&group_args);
1286 if (noti->b_execute_option) {
1287 bundle_encode(noti->b_execute_option,
1288 (bundle_raw **)&b_execute_option, &b_encode_len);
1289 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_EXECUTE_OPTION, g_variant_new_string((const gchar *)b_execute_option));
1291 if (b_execute_option)
1292 bundle_free_encoded_rawdata(&b_execute_option);
1295 if (noti->b_service_responding) {
1296 bundle_encode(noti->b_service_responding,
1297 (bundle_raw **)&b_service_responding, &b_encode_len);
1298 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_SERVICE_RESPONDING, g_variant_new_string((const gchar *)b_service_responding));
1300 if (b_service_responding)
1301 bundle_free_encoded_rawdata(&b_service_responding);
1304 if (noti->b_service_single_launch) {
1305 bundle_encode(noti->b_service_single_launch,
1306 (bundle_raw **)&b_service_single_launch, &b_encode_len);
1307 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_SERVICE_SINGLE_LAUNCH, g_variant_new_string((const gchar *)b_service_single_launch));
1309 if (b_service_single_launch)
1310 bundle_free_encoded_rawdata(&b_service_single_launch);
1313 if (noti->b_service_multi_launch) {
1314 bundle_encode(noti->b_service_multi_launch,
1315 (bundle_raw **)&b_service_multi_launch, &b_encode_len);
1316 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_SERVICE_MULTI_LAUNCH, g_variant_new_string((const gchar *)b_service_multi_launch));
1318 if (b_service_multi_launch)
1319 bundle_free_encoded_rawdata(&b_service_multi_launch);
1322 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
1323 if (noti->b_event_handler[i]) {
1324 bundle_encode(noti->b_event_handler[i],
1325 (bundle_raw **)&b_event_handler[i], &b_encode_len);
1326 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_BUTTON1_EVENT + i, g_variant_new_string((const gchar *)b_event_handler[i]));
1328 if (b_event_handler[i])
1329 bundle_free_encoded_rawdata(&b_event_handler[i]);
1333 if (noti->launch_pkgname)
1334 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_LAUNCH_PKGNAME, g_variant_new_string((const gchar *)noti->launch_pkgname));
1336 if (noti->domain != NULL)
1337 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_DOMAIN, g_variant_new_string((const gchar *)noti->domain));
1339 if (noti->dir != NULL)
1340 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_DIR, g_variant_new_string((const gchar *)noti->dir));
1343 bundle_encode(noti->b_text, (bundle_raw **)&b_text, &b_encode_len);
1344 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_TEXT, g_variant_new_string((const gchar *)b_text));
1347 bundle_free_encoded_rawdata(&b_text);
1351 bundle_encode(noti->b_key, (bundle_raw **)&b_key, &b_encode_len);
1352 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_KEY, g_variant_new_string((const gchar *)b_key));
1355 bundle_free_encoded_rawdata(&b_key);
1358 if (noti->b_format_args) {
1359 bundle_encode(noti->b_format_args,
1360 (bundle_raw **)&b_format_args, &b_encode_len);
1361 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_FORMAT_ARGS, g_variant_new_string((const gchar *)b_format_args));
1364 bundle_free_encoded_rawdata(&b_format_args);
1367 if (noti->num_format_args != 0)
1368 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_NUM_FORMAT_ARGS, g_variant_new_int32(noti->num_format_args));
1370 if (noti->b_image_path) {
1371 bundle_encode(noti->b_image_path,
1372 (bundle_raw **)&b_image_path, &b_encode_len);
1373 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_IMAGE_PATH, g_variant_new_string((const gchar *)b_image_path));
1376 bundle_free_encoded_rawdata(&b_image_path);
1379 if (noti->sound_type != NOTIFICATION_SOUND_TYPE_NONE)
1380 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_SOUND_TYPE, g_variant_new_int32(noti->sound_type));
1382 if (noti->sound_path)
1383 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_SOUND_PATH, g_variant_new_string((const gchar *)noti->sound_path));
1385 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_VIBRATION_TYPE, g_variant_new_int32(noti->vibration_type));
1387 if (noti->vibration_path)
1388 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_VIBRATION_PATH, g_variant_new_string((const gchar *)noti->vibration_path));
1390 if (noti->led_operation != NOTIFICATION_LED_OP_OFF)
1391 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_LED_OPERATION, g_variant_new_int32(noti->led_operation));
1393 if (noti->led_argb != 0)
1394 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_LED_ARGB, g_variant_new_int32(noti->led_argb));
1396 if (noti->led_on_ms != 0)
1397 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_LED_ON_MS, g_variant_new_int32(noti->led_on_ms));
1399 if (noti->led_off_ms != 0)
1400 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_LED_OFF_MS, g_variant_new_int32(noti->led_off_ms));
1402 if (noti->time != 0)
1403 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_TIME, g_variant_new_int32(noti->time));
1405 if (noti->insert_time != 0)
1406 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_INSERT_TIME, g_variant_new_int32(noti->insert_time));
1408 if (noti->flags_for_property != 0)
1409 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_FLAGS_FOR_PROPERTY, g_variant_new_int32(noti->flags_for_property));
1411 if (noti->progress_size != 0.0)
1412 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_PROGRESS_SIZE, g_variant_new_double(noti->progress_size));
1414 if (noti->progress_percentage != 0.0)
1415 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_PROGRESS_PERCENTAGE, g_variant_new_double(noti->progress_percentage));
1417 if (noti->app_icon_path != NULL)
1418 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_APP_ICON_PATH, g_variant_new_string((const gchar *)noti->app_icon_path));
1419 if (noti->app_name != NULL)
1420 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_APP_NAME, g_variant_new_string((const gchar *)noti->app_name));
1421 if (noti->temp_title != NULL)
1422 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_TEMP_TITLE, g_variant_new_string((const gchar *)noti->temp_title));
1423 if (noti->temp_content != NULL)
1424 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_TEMP_CONTENT, g_variant_new_string((const gchar *)noti->temp_content));
1425 if (noti->tag != NULL)
1426 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_TAG, g_variant_new_string((const gchar *)noti->tag));
1428 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_ONGOING_FLAG, g_variant_new_int32(noti->ongoing_flag));
1430 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_AUTO_REMOVE, g_variant_new_int32(noti->auto_remove));
1432 result_body = g_variant_builder_end(&builder);
1433 body = g_variant_new("(v)", result_body);
1438 static gboolean _variant_to_int_dict(GHashTable **dict, GVariant *variant)
1445 *dict = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, (GDestroyNotify)g_variant_unref);
1449 g_variant_iter_init(&iter, variant);
1450 while (g_variant_iter_next(&iter, "{iv}", &key, &value)) {
1451 hash_key = (int *)calloc(sizeof(int), 1);
1452 if (hash_key == NULL) {
1453 g_hash_table_unref(*dict);
1457 g_hash_table_insert(*dict, (gpointer)hash_key, value);
1462 static gboolean _variant_dict_lookup(GHashTable *dict,
1464 const gchar *format_string,
1470 value = g_hash_table_lookup(dict, (gpointer)&key);
1472 if (value == NULL || !g_variant_check_format_string(value, format_string, FALSE))
1475 va_start(ap, format_string);
1476 g_variant_get_va(value, format_string, NULL, &ap);
1483 * functions creating notification packet
1485 EXPORT_API int notification_ipc_make_noti_from_gvariant(notification_h noti,
1486 GVariant *variant) {
1488 NOTIFICATION_DBG("make noti from GVariant");
1492 char *caller_pkgname = NULL;
1493 char *launch_pkgname = NULL;
1494 bundle_raw *args = NULL;
1495 bundle_raw *group_args = NULL;
1496 bundle_raw *b_execute_option = NULL;
1497 bundle_raw *b_service_responding = NULL;
1498 bundle_raw *b_service_single_launch = NULL;
1499 bundle_raw *b_service_multi_launch = NULL;
1500 bundle_raw *b_event_handler[NOTIFICATION_EVENT_TYPE_MAX] = { NULL, };
1501 char *domain = NULL;
1503 bundle_raw *b_text = NULL;
1504 bundle_raw *b_key = NULL;
1505 bundle_raw *b_format_args = NULL;
1506 bundle_raw *b_image_path = NULL;
1507 char *sound_path = NULL;
1508 char *vibration_path = NULL;
1509 char *app_icon_path = NULL;
1510 char *app_name = NULL;
1511 char *temp_title = NULL;
1512 char *temp_content = NULL;
1516 NOTIFICATION_ERR("invalid data noti NULL");
1517 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1520 if (variant == NULL) {
1521 NOTIFICATION_ERR("invalid data variant NULL");
1522 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1525 if (!_variant_to_int_dict(&dict, variant))
1526 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1528 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_NOTI_TYPE, "i", ¬i->type);
1529 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_LAYOUT, "i", ¬i->layout);
1530 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_GROUP_ID, "i", ¬i->group_id);
1531 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_INTERNAL_GROUP_ID, "i", ¬i->internal_group_id);
1532 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_PRIV_ID, "i", ¬i->priv_id);
1533 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_CALLER_PKGNAME, "&s", &caller_pkgname);
1534 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_LAUNCH_PKGNAME, "&s", &launch_pkgname);
1535 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_ARGS, "&s", &args);
1536 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_GROUP_ARGS, "&s", &group_args);
1537 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_EXECUTE_OPTION, "&s", &b_execute_option);
1538 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_SERVICE_RESPONDING, "&s", &b_service_responding);
1539 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_SERVICE_SINGLE_LAUNCH, "&s", &b_service_single_launch);
1540 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_SERVICE_MULTI_LAUNCH, "&s", &b_service_multi_launch);
1541 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_BUTTON1_EVENT, "&s", &b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1]);
1542 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_BUTTON2_EVENT, "&s", &b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_2]);
1543 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_BUTTON3_EVENT, "&s", &b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_3]);
1544 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_BUTTON4_EVENT, "&s", &b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_4]);
1545 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_BUTTON5_EVENT, "&s", &b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_5]);
1546 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_BUTTON6_EVENT, "&s", &b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_6]);
1547 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_ICON_EVENT, "&s", &b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_ICON]);
1548 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_THUMBNAIL_EVENT, "&s", &b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL]);
1549 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_DOMAIN, "&s", &domain);
1550 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_DIR, "&s", &dir);
1551 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_TEXT, "&s", &b_text);
1552 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_KEY, "&s", &b_key);
1553 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_FORMAT_ARGS, "&s", &b_format_args);
1554 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_NUM_FORMAT_ARGS, "i", ¬i->num_format_args);
1555 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_IMAGE_PATH, "&s", &b_image_path);
1556 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_SOUND_TYPE, "i", ¬i->sound_type);
1557 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_SOUND_PATH, "&s", &sound_path);
1558 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_VIBRATION_TYPE, "i", ¬i->vibration_type);
1559 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_VIBRATION_PATH, "&s", &vibration_path);
1560 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_LED_OPERATION, "i", ¬i->led_operation);
1561 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_LED_ARGB, "i", ¬i->led_argb);
1562 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_LED_ON_MS, "i", ¬i->led_on_ms);
1563 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_LED_OFF_MS, "i", ¬i->led_off_ms);
1564 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_TIME, "i", ¬i->time);
1565 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_INSERT_TIME, "i", ¬i->insert_time);
1566 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_FLAGS_FOR_PROPERTY, "i", ¬i->flags_for_property);
1567 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_DISPLAY_APPLIST, "i", ¬i->display_applist);
1568 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_PROGRESS_SIZE, "d", ¬i->progress_size);
1569 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_PROGRESS_PERCENTAGE, "d", ¬i->progress_percentage);
1570 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_APP_ICON_PATH, "&s", &app_icon_path);
1571 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_APP_NAME, "&s", &app_name);
1572 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_TEMP_TITLE, "&s", &temp_title);
1573 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_TEMP_CONTENT, "&s", &temp_content);
1574 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_TAG, "&s", &tag);
1575 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_ONGOING_FLAG, "i", ¬i->ongoing_flag);
1576 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_AUTO_REMOVE, "i", ¬i->auto_remove);
1578 noti->caller_pkgname = _dup_string(caller_pkgname);
1579 noti->launch_pkgname = _dup_string(launch_pkgname);
1580 noti->args = _create_bundle_from_bundle_raw(args);
1581 noti->group_args = _create_bundle_from_bundle_raw(group_args);
1582 noti->b_execute_option = _create_bundle_from_bundle_raw(b_execute_option);
1583 noti->b_service_responding = _create_bundle_from_bundle_raw(
1584 b_service_responding);
1585 noti->b_service_single_launch = _create_bundle_from_bundle_raw(
1586 b_service_single_launch);
1587 noti->b_service_multi_launch = _create_bundle_from_bundle_raw(
1588 b_service_multi_launch);
1589 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
1590 noti->b_event_handler[i] = _create_bundle_from_bundle_raw(
1591 b_event_handler[i]);
1593 noti->domain = _dup_string(domain);
1594 noti->dir = _dup_string(dir);
1595 noti->b_text = _create_bundle_from_bundle_raw(b_text);
1596 noti->b_key = _create_bundle_from_bundle_raw(b_key);
1597 noti->b_format_args = _create_bundle_from_bundle_raw(b_format_args);
1598 noti->b_image_path = _create_bundle_from_bundle_raw(b_image_path);
1599 noti->sound_path = _dup_string(sound_path);
1600 noti->vibration_path = _dup_string(vibration_path);
1601 noti->app_icon_path = _dup_string(app_icon_path);
1602 noti->app_name = _dup_string(app_name);
1603 noti->temp_title = _dup_string(temp_title);
1604 noti->temp_content = _dup_string(temp_content);
1605 noti->tag = _dup_string(tag);
1607 g_hash_table_unref(dict);
1609 return NOTIFICATION_ERROR_NONE;
1612 EXPORT_API GVariant *notification_ipc_make_gvariant_from_system_setting(struct notification_system_setting *noti_setting)
1614 GVariant *body = NULL;
1615 body = g_variant_new("(ii)",
1616 noti_setting->do_not_disturb,
1617 noti_setting->visibility_class);
1621 EXPORT_API int notification_ipc_make_system_setting_from_gvariant(struct notification_system_setting *noti_setting,
1625 int visibility_class;
1627 if (noti_setting == NULL) {
1628 NOTIFICATION_ERR("invalid data");
1629 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1631 g_variant_get(variant,
1636 NOTIFICATION_DBG("system setting #### %d, %d",
1637 do_not_disturb, visibility_class);
1639 noti_setting->do_not_disturb = do_not_disturb;
1640 noti_setting->visibility_class = visibility_class;
1642 NOTIFICATION_DBG("system setting2 #### %d, %d",
1643 noti_setting->do_not_disturb, noti_setting->visibility_class);
1645 return NOTIFICATION_ERROR_NONE;
1648 EXPORT_API GVariant *notification_ipc_make_gvariant_from_setting(struct notification_setting *noti_setting)
1650 GVariant *body = NULL;
1652 body = g_variant_new("(siii)",
1653 noti_setting->package_name,
1654 noti_setting->allow_to_notify,
1655 noti_setting->do_not_disturb_except,
1656 noti_setting->visibility_class);
1661 EXPORT_API int notification_ipc_make_setting_from_gvariant(struct notification_setting *noti_setting,
1664 NOTIFICATION_DBG("notification_ipc_make_setting_from_gvariant !!!!");
1666 int allow_to_notify;
1667 int do_not_disturb_except;
1668 int visibility_class;
1670 if (noti_setting == NULL || variant == NULL) {
1671 NOTIFICATION_ERR("invalid data");
1672 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1674 g_variant_get(variant,
1678 &do_not_disturb_except,
1681 NOTIFICATION_DBG("setting from variant %s !!", pkgname);
1683 noti_setting->package_name = _dup_string(pkgname);
1684 noti_setting->allow_to_notify = allow_to_notify;
1685 noti_setting->do_not_disturb_except = do_not_disturb_except;
1686 noti_setting->visibility_class = visibility_class;
1688 NOTIFICATION_DBG("setting from variant %s, %s",
1689 noti_setting->package_name, pkgname);
1691 return NOTIFICATION_ERROR_NONE;
1694 static int _send_service_register()
1696 NOTIFICATION_DBG("service register");
1697 GDBusMessage *reply = NULL;
1699 notification_op *noti_op = NULL;
1701 result = _send_sync_noti(NULL, &reply, "noti_service_register");
1704 g_object_unref(reply);
1706 NOTIFICATION_DBG("_send_service_register done = %s, result = %d", _bus_name, result);
1707 noti_op = _ipc_create_op(NOTIFICATION_OP_SERVICE_READY, 1, NULL, 1, NULL);
1708 if (noti_op != NULL) {
1709 notification_call_changed_cb(noti_op, 1);
1716 static int _ipc_monitor_register(void)
1718 NOTIFICATION_ERR("register a service\n");
1720 return _send_service_register();
1723 static void _on_name_appeared(GDBusConnection *connection,
1725 const gchar *name_owner,
1728 NOTIFICATION_DBG("name appeared : %s", name);
1729 is_master_started = 1;
1730 _ipc_monitor_register();
1732 /* TODO: dbus activation isn't enough ? */
1733 _do_deffered_task();
1736 static void _on_name_vanished(GDBusConnection *connection,
1740 NOTIFICATION_DBG("name vanished : %s", name);
1741 is_master_started = 0;
1744 int notification_ipc_monitor_init(void)
1749 if (ret != NOTIFICATION_ERROR_NONE) {
1750 NOTIFICATION_ERR("Can't init dbus %d", ret);
1754 ret = _dbus_signal_init();
1755 if (ret != NOTIFICATION_ERROR_NONE) {
1756 NOTIFICATION_ERR("Can't signal_init %d", ret);
1760 ret = _ipc_monitor_register();
1761 if (ret != NOTIFICATION_ERROR_NONE) {
1762 NOTIFICATION_ERR("Can't init ipc_monitor_register %d", ret);
1766 if (provider_monitor_id == 0) {
1767 provider_monitor_id = g_bus_watch_name_on_connection(
1770 G_BUS_NAME_WATCHER_FLAGS_NONE,
1776 if (provider_monitor_id == 0) {
1777 g_dbus_connection_signal_unsubscribe(_gdbus_conn, monitor_id);
1779 NOTIFICATION_ERR("watch on name fail");
1780 return NOTIFICATION_ERROR_IO_ERROR;
1784 return NOTIFICATION_ERROR_NONE;
1787 static int _ipc_monitor_deregister(void)
1789 if (provider_monitor_id) {
1790 g_bus_unwatch_name(provider_monitor_id);
1791 provider_monitor_id = 0;
1795 g_dbus_connection_signal_unsubscribe(_gdbus_conn, monitor_id);
1799 return NOTIFICATION_ERROR_NONE;
1802 int notification_ipc_monitor_fini(void)
1804 return _ipc_monitor_deregister();