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"
47 #define ERR_BUFFER_SIZE 1024
49 static const gchar *_bus_name = NULL;
50 static GDBusConnection *_gdbus_conn = NULL;
51 static int monitor_id = 0;
52 static int provider_monitor_id = 0;
53 static int is_master_started = 0;
55 typedef struct _result_cb_item {
56 void (*result_cb)(int priv_id, int result, void *data);
60 typedef struct _task_list task_list;
65 void (*task_cb) (void *data);
69 static task_list *g_task_list;
71 static int _ipc_monitor_register(void);
72 static int _ipc_monitor_deregister(void);
73 static void _do_deffered_task(void);
75 static void _print_noti(notification_h noti) {
79 const char *tag = NULL;
80 notification_vibration_type_e vib_type = NOTIFICATION_VIBRATION_TYPE_NONE;
82 notification_get_pkgname(noti, &pkgname);
83 notification_get_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, &text);
84 notification_get_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, &content);
85 notification_get_tag(noti, &tag);
86 notification_get_vibration(noti, &vib_type, NULL);
88 NOTIFICATION_DBG("client print_noti pkgname = %s ", pkgname );
89 NOTIFICATION_DBG("client print_noti title = %s ", text );
90 NOTIFICATION_DBG("client print_noti content = %s ", content );
91 NOTIFICATION_DBG("client print_noti tag = %s ", tag );
92 NOTIFICATION_DBG("client print_noti priv_id = %d ", noti->priv_id);
93 NOTIFICATION_DBG("client print_noti vibration_path = %s ", noti->vibration_path);
94 NOTIFICATION_DBG("client print_noti vibration_type = %d ", vib_type);
97 static inline char *_string_get(char *string)
102 if (string[0] == '\0')
109 int notification_ipc_is_master_ready(void)
115 result = g_dbus_connection_call_sync(
121 g_variant_new("(s)", PROVIDER_BUS_NAME),
122 G_VARIANT_TYPE("(b)"),
123 G_DBUS_CALL_FLAGS_NONE,
128 if (err || (result == NULL)) {
130 NOTIFICATION_ERR("No reply. error = %s", err->message);
133 is_master_started = 0;
135 g_variant_get(result, "(b)", &name_exist);
138 NOTIFICATION_ERR("Name not exist %s", PROVIDER_BUS_NAME);
139 NOTIFICATION_ERR("the master has been stopped");
140 is_master_started = 0;
142 NOTIFICATION_DBG("the master has been started");
143 is_master_started = 1;
148 g_variant_unref(result);
150 return is_master_started;
153 /* TODO: dbus activation isn't enough ? */
155 * store tasks when daemon stopped
157 int notification_ipc_add_deffered_task(
158 void (*deferred_task_cb)(void *data),
165 (task_list *) malloc(sizeof(task_list));
167 if (list_new == NULL)
168 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
170 list_new->next = NULL;
171 list_new->prev = NULL;
173 list_new->task_cb = deferred_task_cb;
174 list_new->data = user_data;
176 if (g_task_list == NULL) {
177 g_task_list = list_new;
181 while (list->next != NULL)
184 list->next = list_new;
185 list_new->prev = list;
187 return NOTIFICATION_ERROR_NONE;
190 int notification_ipc_del_deffered_task(
191 void (*deferred_task_cb)(void *data))
194 task_list *list_prev;
195 task_list *list_next;
197 list_del = g_task_list;
199 if (list_del == NULL)
200 return NOTIFICATION_ERROR_INVALID_PARAMETER;
202 while (list_del->prev != NULL)
203 list_del = list_del->prev;
206 if (list_del->task_cb == deferred_task_cb) {
207 list_prev = list_del->prev;
208 list_next = list_del->next;
210 if (list_prev == NULL)
211 g_task_list = list_next;
213 list_prev->next = list_next;
215 if (list_next == NULL) {
216 if (list_prev != NULL)
217 list_prev->next = NULL;
219 list_next->prev = list_prev;
223 return NOTIFICATION_ERROR_NONE;
225 list_del = list_del->next;
226 } while (list_del != NULL);
228 return NOTIFICATION_ERROR_INVALID_PARAMETER;
231 static void _do_deffered_task(void)
234 task_list *list_temp;
236 if (g_task_list == NULL)
239 list_do = g_task_list;
242 while (list_do->prev != NULL)
243 list_do = list_do->prev;
245 while (list_do != NULL) {
246 if (list_do->task_cb != NULL) {
247 list_do->task_cb(list_do->data);
248 NOTIFICATION_DBG("called:%p", list_do->task_cb);
250 list_temp = list_do->next;
257 * functions to create operation list
259 static notification_op *_ipc_create_op(notification_op_type_e type,
260 int num_op, int *list_priv_id, int num_priv_id, notification_h *noti_list)
263 notification_op *op_list;
268 op_list = (notification_op *)malloc(sizeof(notification_op) * num_op);
270 if (op_list == NULL) {
271 NOTIFICATION_ERR("malloc failed");
275 memset(op_list, 0x0, sizeof(notification_op) * num_op);
277 for (i = 0; i < num_op; i++) {
278 (op_list + i)->type = type;
279 if (list_priv_id != NULL)
280 (op_list + i)->priv_id = *(list_priv_id + i);
281 if (noti_list != NULL)
282 (op_list + i)->noti = *(noti_list + i);
289 * utility functions creating notification packet
291 static inline char *_dup_string(const char *string)
294 char err_buf[ERR_BUFFER_SIZE];
298 if (string[0] == '\0')
301 ret = strdup(string);
303 NOTIFICATION_ERR("Error: %s\n", strerror_r(errno, err_buf, sizeof(err_buf)));
308 static inline bundle *_create_bundle_from_bundle_raw(bundle_raw *string)
312 if (string[0] == '\0')
315 return bundle_decode(string, strlen((char *)string));
318 static void _add_noti_notify(GVariant *parameters)
321 notification_op *noti_op;
322 GVariant *body = NULL;
324 NOTIFICATION_DBG("add noti notify");
325 noti = notification_create(NOTIFICATION_TYPE_NOTI);
327 NOTIFICATION_ERR("failed to create a notification");
331 g_variant_get(parameters, "(v)", &body);
332 notification_ipc_make_noti_from_gvariant(noti, body);
334 if (noti->flags_for_property & NOTIFICATION_PROP_DISABLE_UPDATE_ON_INSERT) {
335 NOTIFICATION_ERR("disable changed callback %d", noti->flags_for_property);
336 /* Disable changed cb */
338 /* Enable changed cb */
339 noti_op = _ipc_create_op(NOTIFICATION_OP_INSERT, 1, &(noti->priv_id), 1, ¬i);
341 if (noti_op != NULL) {
342 notification_call_changed_cb(noti_op, 1);
346 notification_free(noti);
349 static void _update_noti_notify(GVariant *parameters)
352 notification_op *noti_op;
353 GVariant *body = NULL;
355 noti = notification_create(NOTIFICATION_TYPE_NOTI);
357 NOTIFICATION_ERR("failed to create a notification");
360 g_variant_get(parameters, "(v)", &body);
361 notification_ipc_make_noti_from_gvariant(noti, body);
364 noti_op = _ipc_create_op(NOTIFICATION_OP_UPDATE, 1, &(noti->priv_id), 1, ¬i);
365 if (noti_op != NULL) {
366 notification_call_changed_cb(noti_op, 1);
369 notification_free(noti);
372 static void _refresh_noti_notify(GVariant *parameters)
374 notification_op *noti_op = _ipc_create_op(NOTIFICATION_OP_REFRESH, 1, NULL, 0, NULL);
376 if (noti_op != NULL) {
377 notification_call_changed_cb(noti_op, 1);
382 static void _delete_single_notify(GVariant *parameters)
386 notification_op *noti_op;
389 g_variant_get(parameters, "(ii)", &num_deleted, &priv_id);
391 noti_op = _ipc_create_op(NOTIFICATION_OP_DELETE, 1, &priv_id, 1, NULL);
392 if (noti_op != NULL) {
393 notification_call_changed_cb(noti_op, 1);
398 static void _delete_multiple_notify(GVariant *parameters)
402 notification_op *noti_op;
405 g_variant_get(parameters, "(a(i))", &iter);
406 while (g_variant_iter_loop(iter, "(i)", &buf[idx])) {
407 NOTIFICATION_DBG("delete_noti_multiple priv_id : %d", buf[idx]);
410 g_variant_iter_free(iter);
412 NOTIFICATION_DBG("data num deleted:%d", idx);
413 noti_op = _ipc_create_op(NOTIFICATION_OP_DELETE, idx, buf, idx, NULL);
415 if (noti_op == NULL) {
416 NOTIFICATION_ERR("_ipc_create_op failed");
419 notification_call_changed_cb(noti_op, idx);
423 static void _handle_noti_notify(GDBusConnection *connection,
424 const gchar *sender_name,
425 const gchar *object_path,
426 const gchar *interface_name,
427 const gchar *signal_name,
428 GVariant *parameters,
431 NOTIFICATION_DBG("signal_name: %s", signal_name);
433 if (g_strcmp0(signal_name, "add_noti_notify") == 0)
434 _add_noti_notify(parameters);
435 else if (g_strcmp0(signal_name, "update_noti_notify") == 0)
436 _update_noti_notify(parameters);
437 else if (g_strcmp0(signal_name, "delete_single_notify") == 0)
438 _delete_single_notify(parameters);
439 else if (g_strcmp0(signal_name, "delete_multiple_notify") == 0)
440 _delete_multiple_notify(parameters);
441 else if (g_strcmp0(signal_name, "refresh_noti_notify") == 0)
442 _refresh_noti_notify(parameters);
446 static int _dbus_signal_init()
449 int ret = NOTIFICATION_ERROR_NONE;
451 if (monitor_id == 0) {
452 id = g_dbus_connection_signal_subscribe(_gdbus_conn,
454 PROVIDER_NOTI_INTERFACE_NAME, /* interface */
456 PROVIDER_OBJECT_PATH, /* path */
458 G_DBUS_SIGNAL_FLAGS_NONE,
463 NOTIFICATION_DBG("subscribe id : %d", id);
465 ret = NOTIFICATION_ERROR_IO_ERROR;
466 NOTIFICATION_ERR("Failed to _register_noti_dbus_interface");
469 ret = NOTIFICATION_ERROR_NONE;
476 static int _dbus_init()
478 int ret = NOTIFICATION_ERROR_NONE;
479 GError *error = NULL;
481 if (_gdbus_conn == NULL) {
482 _gdbus_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
484 if (_gdbus_conn == NULL) {
486 NOTIFICATION_ERR("Failed to get dbus [%s]", error->message);
489 return NOTIFICATION_ERROR_IO_ERROR;
491 _bus_name = g_dbus_connection_get_unique_name(_gdbus_conn);
492 NOTIFICATION_DBG("bus name : %s", _bus_name);
494 notification_error_quark();
496 ret = NOTIFICATION_ERROR_NONE;
501 static int _send_sync_noti(GVariant *body, GDBusMessage **reply, char *cmd)
503 int ret = NOTIFICATION_ERROR_NONE;
507 msg = g_dbus_message_new_method_call(
509 PROVIDER_OBJECT_PATH,
510 PROVIDER_NOTI_INTERFACE_NAME,
513 NOTIFICATION_ERR("Can't allocate new method call");
515 g_variant_unref(body);
516 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
520 g_dbus_message_set_body(msg, body);
522 *reply = g_dbus_connection_send_message_with_reply_sync(
525 G_DBUS_SEND_MESSAGE_FLAGS_NONE,
534 ret = NOTIFICATION_ERROR_SERVICE_NOT_READY;
536 NOTIFICATION_ERR("No reply. cmd = %s, error = %s", cmd, err->message);
537 if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
538 ret = NOTIFICATION_ERROR_PERMISSION_DENIED;
544 if (g_dbus_message_to_gerror(*reply, &err)) {
545 if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
546 ret = NOTIFICATION_ERROR_PERMISSION_DENIED;
550 NOTIFICATION_ERR("_send_sync_noti cmd = %s, error %s, err code %d", cmd, err->message, ret);
554 NOTIFICATION_DBG("_send_sync_noti done !!");
555 return NOTIFICATION_ERROR_NONE;
559 static void _send_message_with_reply_async_cb(GDBusConnection *connection,
564 int result = NOTIFICATION_ERROR_NONE;
566 GDBusMessage *reply = NULL;
568 result_cb_item *cb_item = (result_cb_item *)user_data;
570 if (cb_item == NULL) {
571 NOTIFICATION_ERR("Failed to get a callback item");
575 reply = g_dbus_connection_send_message_with_reply_finish(
582 NOTIFICATION_ERR("No reply. error = %s", err->message);
585 result = NOTIFICATION_ERROR_SERVICE_NOT_READY;
587 } else if (g_dbus_message_to_gerror(reply, &err)) {
588 if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
589 result = NOTIFICATION_ERROR_PERMISSION_DENIED;
593 NOTIFICATION_ERR("_send_async_noti error %s", err->message);
597 NOTIFICATION_DBG("_send_async_noti done !![%d]", result);
599 if (result == NOTIFICATION_ERROR_NONE) {
600 body = g_dbus_message_get_body(reply);
601 g_variant_get(body, "(i)", &priv_id);
603 if (cb_item->result_cb)
604 cb_item->result_cb(priv_id, result, cb_item->data);
607 if (cb_item->result_cb)
608 cb_item->result_cb(NOTIFICATION_PRIV_ID_NONE, result, cb_item->data);
612 g_object_unref(reply);
616 static int _send_async_noti(GVariant *body, result_cb_item *cb_item, char *cmd)
620 msg = g_dbus_message_new_method_call(
622 PROVIDER_OBJECT_PATH,
623 PROVIDER_NOTI_INTERFACE_NAME,
626 NOTIFICATION_ERR("Can't allocate new method call");
627 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
631 g_dbus_message_set_body(msg, body);
633 g_dbus_connection_send_message_with_reply(
636 G_DBUS_SEND_MESSAGE_FLAGS_NONE,
640 (GAsyncReadyCallback)_send_message_with_reply_async_cb,
643 NOTIFICATION_DBG("_send_async_noti done !!");
646 return NOTIFICATION_ERROR_NONE;
649 int notification_ipc_request_insert(notification_h noti, int *priv_id)
652 int id = NOTIFICATION_PRIV_ID_NONE;
653 GDBusMessage *reply = NULL;
655 GVariant *reply_body;
657 result = _dbus_init();
658 if (result != NOTIFICATION_ERROR_NONE) {
659 NOTIFICATION_ERR("Can't init dbus %d", result);
663 /* Initialize private ID */
664 noti->priv_id = NOTIFICATION_PRIV_ID_NONE;
665 noti->group_id = NOTIFICATION_GROUP_ID_NONE;
666 noti->internal_group_id = NOTIFICATION_GROUP_ID_NONE;
669 body = notification_ipc_make_gvariant_from_noti(noti);
671 NOTIFICATION_ERR("cannot make gvariant");
672 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
675 result = _send_sync_noti(body, &reply, "add_noti");
676 NOTIFICATION_DBG("_send_sync_noti %d", result);
678 if (result == NOTIFICATION_ERROR_NONE) {
679 reply_body = g_dbus_message_get_body(reply);
680 g_variant_get(reply_body, "(i)", &id);
687 g_object_unref(reply);
689 NOTIFICATION_DBG("notification_ipc_request_insert done [priv_id : %d, result: %d]", id, result);
693 int notification_ipc_request_update(notification_h noti)
696 int priv_id = NOTIFICATION_PRIV_ID_NONE;
698 GDBusMessage *reply = NULL;
700 GVariant *reply_body;
702 result = _dbus_init();
703 if (result != NOTIFICATION_ERROR_NONE) {
704 NOTIFICATION_ERR("Can't init dbus %d", result);
708 body = notification_ipc_make_gvariant_from_noti(noti);
710 NOTIFICATION_ERR("cannot make gvariant");
711 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
714 result = _send_sync_noti(body, &reply, "update_noti");
715 if (result == NOTIFICATION_ERROR_NONE) {
716 reply_body = g_dbus_message_get_body(reply);
717 g_variant_get(reply_body, "(i)", &priv_id);
721 g_object_unref(reply);
723 NOTIFICATION_DBG("notification_ipc_request_update done [result: %d, priv_id :%d]", result, priv_id);
727 int notification_ipc_request_update_async(notification_h noti,
728 void (*result_cb)(int priv_id, int result, void *data), void *user_data)
731 result_cb_item *cb_item;
734 result = _dbus_init();
735 if (result != NOTIFICATION_ERROR_NONE) {
736 NOTIFICATION_ERR("Can't init dbus %d", result);
740 cb_item = calloc(1, sizeof(result_cb_item));
742 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
744 cb_item->result_cb = result_cb;
745 cb_item->data = user_data;
747 body = notification_ipc_make_gvariant_from_noti(noti);
749 NOTIFICATION_ERR("cannot make gvariant");
751 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
754 result = _send_async_noti(body, cb_item, "update_noti");
755 NOTIFICATION_DBG("notification_ipc_request_update_async done [result: %d]", result);
757 if (result != NOTIFICATION_ERROR_NONE) {
762 g_variant_unref(body);
767 int notification_ipc_request_refresh(void)
770 GDBusMessage *reply = NULL;
773 result = _dbus_init();
774 if (result != NOTIFICATION_ERROR_NONE) {
775 NOTIFICATION_ERR("Can't init dbus %d", result);
779 body = g_variant_new("(i)", NOTIFICATION_OP_REFRESH);
780 result = _send_sync_noti(body, &reply, "refresh_noti");
783 g_object_unref(reply);
785 NOTIFICATION_ERR("notification_ipc_request_refresh done [result: %d]", result);
789 int notification_ipc_request_delete_single(notification_type_e type, char *pkgname, int priv_id)
793 GDBusMessage *reply = NULL;
795 GVariant *reply_body;
797 result = _dbus_init();
798 if (result != NOTIFICATION_ERROR_NONE) {
799 NOTIFICATION_ERR("Can't init dbus %d", result);
803 body = g_variant_new("(si)", pkgname, priv_id);
804 result = _send_sync_noti(body, &reply, "del_noti_single");
806 if (result == NOTIFICATION_ERROR_NONE) {
807 reply_body = g_dbus_message_get_body(reply);
808 g_variant_get(reply_body, "(i)", &id);
812 g_object_unref(reply);
814 NOTIFICATION_ERR("notification_ipc_request_delete_single done [result: %d]", result);
818 int notification_ipc_request_delete_multiple(notification_type_e type, char *pkgname)
823 GVariant *reply_body;
824 GDBusMessage *reply = NULL;
826 result = _dbus_init();
827 if (result != NOTIFICATION_ERROR_NONE) {
828 NOTIFICATION_ERR("Can't init dbus %d", result);
835 body = g_variant_new("(si)", pkgname, type);
836 result = _send_sync_noti(body, &reply, "del_noti_multiple");
838 if (result == NOTIFICATION_ERROR_NONE) {
839 reply_body = g_dbus_message_get_body(reply);
840 g_variant_get(reply_body, "(i)", &num_deleted);
841 NOTIFICATION_ERR("num deleted:%d", num_deleted);
845 g_object_unref(reply);
850 int notification_ipc_request_load_noti_by_tag(notification_h noti, const char *pkgname, const char *tag)
853 GDBusMessage *reply = NULL;
855 GVariant *reply_body;
858 result = _dbus_init();
859 if (result != NOTIFICATION_ERROR_NONE) {
860 NOTIFICATION_ERR("Can't init dbus %d", result);
867 body = g_variant_new("(ss)", pkgname, tag);
868 result = _send_sync_noti(body, &reply, "load_noti_by_tag");
870 if (result == NOTIFICATION_ERROR_NONE) {
871 reply_body = g_dbus_message_get_body(reply);
872 g_variant_get(reply_body, "(v)", ¬i_body);
874 notification_ipc_make_noti_from_gvariant(noti, noti_body);
875 g_variant_unref(noti_body);
881 g_object_unref(reply);
883 NOTIFICATION_DBG("notification_ipc_request_load_noti_by_tag done [result: %d]", result);
887 int notification_ipc_request_load_noti_by_priv_id(notification_h noti, const char *pkgname, int priv_id)
890 GDBusMessage *reply = NULL;
892 GVariant *reply_body;
895 result = _dbus_init();
896 if (result != NOTIFICATION_ERROR_NONE) {
897 NOTIFICATION_ERR("Can't init dbus %d", result);
904 body = g_variant_new("(si)", pkgname, priv_id);
905 result = _send_sync_noti(body, &reply, "load_noti_by_priv_id");
907 if (result == NOTIFICATION_ERROR_NONE) {
908 reply_body = g_dbus_message_get_body(reply);
909 g_variant_get(reply_body, "(v)", ¬i_body);
911 notification_ipc_make_noti_from_gvariant(noti, noti_body);
912 g_variant_unref(noti_body);
917 g_object_unref(reply);
919 NOTIFICATION_DBG("notification_ipc_request_load_noti_by_priv_id done [result: %d]", result);
923 int notification_ipc_request_get_count(notification_type_e type,
924 const char *pkgname, int group_id, int priv_id, int *count)
927 GDBusMessage *reply = NULL;
929 GVariant *reply_body;
932 result = _dbus_init();
933 if (result != NOTIFICATION_ERROR_NONE) {
934 NOTIFICATION_ERR("Can't init dbus %d", result);
941 body = g_variant_new("(isii)", type, pkgname, group_id, priv_id);
942 result = _send_sync_noti(body, &reply, "get_noti_count");
944 if (result == NOTIFICATION_ERROR_NONE) {
945 reply_body = g_dbus_message_get_body(reply);
946 g_variant_get(reply_body, "(i)", &re_count);
949 NOTIFICATION_DBG("noti count [%d]", re_count);
953 g_object_unref(reply);
955 NOTIFICATION_DBG("notification_ipc_request_get_count done [result: %d]", result);
959 int notification_ipc_request_load_noti_grouping_list(notification_type_e type, int count,
960 notification_list_h *list)
963 GDBusMessage *reply = NULL;
965 GVariant *reply_body;
971 result = _dbus_init();
972 if (result != NOTIFICATION_ERROR_NONE) {
973 NOTIFICATION_ERR("Can't init dbus %d", result);
977 body = g_variant_new("(ii)", type, count);
978 result = _send_sync_noti(body, &reply, "load_noti_grouping_list");
980 if (result == NOTIFICATION_ERROR_NONE) {
981 reply_body = g_dbus_message_get_body(reply);
982 g_variant_get(reply_body, "(a(v))", &iter);
984 while (g_variant_iter_loop(iter, "(v)", &iter_body)) {
985 noti = notification_create(NOTIFICATION_TYPE_NOTI);
986 g_variant_get(iter_body, "(v)", ¬i_body);
987 notification_ipc_make_noti_from_gvariant(noti, noti_body);
989 *list = notification_list_append(*list, noti);
991 g_variant_iter_free(iter);
995 g_object_unref(reply);
997 NOTIFICATION_DBG("notification_ipc_request_load_noti_grouping_list done [result: %d]", result);
1001 int notification_ipc_request_load_noti_detail_list(const char *pkgname,
1005 notification_list_h *list)
1008 GDBusMessage *reply = NULL;
1010 GVariant *reply_body;
1011 GVariant *iter_body;
1013 notification_h noti;
1014 GVariant *noti_body;
1016 result = _dbus_init();
1017 if (result != NOTIFICATION_ERROR_NONE) {
1018 NOTIFICATION_ERR("Can't init dbus %d", result);
1022 body = g_variant_new("(siii)", pkgname, group_id, priv_id, count);
1023 result = _send_sync_noti(body, &reply, "load_noti_detail_list");
1025 if (result == NOTIFICATION_ERROR_NONE) {
1026 reply_body = g_dbus_message_get_body(reply);
1027 g_variant_get(reply_body, "(a(v))", &iter);
1029 while (g_variant_iter_loop(iter, "(v)", &iter_body)) {
1030 noti = notification_create(NOTIFICATION_TYPE_NOTI);
1031 g_variant_get(iter_body, "(v)", ¬i_body);
1032 notification_ipc_make_noti_from_gvariant(noti, noti_body);
1034 *list = notification_list_append(*list, noti);
1036 g_variant_iter_free(iter);
1040 g_object_unref(reply);
1042 NOTIFICATION_DBG("notification_ipc_request_load_noti_detail_list done [result: %d]", result);
1046 int notification_ipc_request_get_setting_array(
1047 notification_setting_h *setting_array,
1051 GDBusMessage *reply = NULL;
1052 GVariant *reply_body;
1053 GVariant *iter_body;
1056 notification_setting_h result_setting_array;
1057 notification_setting_h temp;
1060 result = _dbus_init();
1061 if (result != NOTIFICATION_ERROR_NONE) {
1062 NOTIFICATION_ERR("Can't init dbus %d", result);
1066 result = _send_sync_noti(NULL, &reply, "get_setting_array");
1068 if (result == NOTIFICATION_ERROR_NONE) {
1069 reply_body = g_dbus_message_get_body(reply);
1070 g_variant_get(reply_body, "(ia(v))", &setting_cnt, &iter);
1072 NOTIFICATION_DBG("get setting arr cnt: %d", setting_cnt);
1073 result_setting_array = (struct notification_setting *)malloc(sizeof(struct notification_setting) * setting_cnt);
1074 if (result_setting_array == NULL) {
1075 NOTIFICATION_ERR("malloc failed");
1076 g_object_unref(reply);
1077 g_variant_iter_free(iter);
1078 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1082 while (g_variant_iter_loop(iter, "(v)", &iter_body)) {
1083 temp = result_setting_array + setting_idx;
1084 notification_ipc_make_setting_from_gvariant(temp, iter_body);
1088 *count = setting_cnt;
1089 *setting_array = result_setting_array;
1090 g_variant_iter_free(iter);
1094 g_object_unref(reply);
1096 NOTIFICATION_DBG("notification_ipc_request_get_setting_array done [result: %d]", result);
1100 int notification_ipc_request_get_setting_by_package_name(
1101 const char *package_name, notification_setting_h *setting)
1104 GDBusMessage *reply = NULL;
1106 GVariant *reply_body;
1107 GVariant *setting_body;
1108 notification_setting_h result_setting;
1110 result = _dbus_init();
1111 if (result != NOTIFICATION_ERROR_NONE) {
1112 NOTIFICATION_ERR("Can't init dbus %d", result);
1116 body = g_variant_new("(s)", package_name);
1117 result = _send_sync_noti(body, &reply, "get_setting_by_package_name");
1119 if (result == NOTIFICATION_ERROR_NONE) {
1120 reply_body = g_dbus_message_get_body(reply);
1121 g_variant_get(reply_body, "(v)", &setting_body);
1123 result_setting = (struct notification_setting *)malloc(sizeof(struct notification_setting));
1124 if (result_setting == NULL) {
1125 NOTIFICATION_ERR("malloc failed");
1126 g_object_unref(reply);
1127 g_variant_unref(body);
1128 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1130 notification_ipc_make_setting_from_gvariant(result_setting, setting_body);
1132 *setting = result_setting;
1133 g_variant_unref(setting_body);
1137 g_object_unref(reply);
1139 NOTIFICATION_DBG("notification_ipc_request_get_setting_by_package_name done [result: %d]", result);
1143 int notification_ipc_request_load_system_setting(notification_system_setting_h *setting)
1146 GDBusMessage *reply = NULL;
1147 GVariant *setting_body;
1148 GVariant *reply_body;
1149 notification_system_setting_h result_setting;
1151 result = _dbus_init();
1152 if (result != NOTIFICATION_ERROR_NONE) {
1153 NOTIFICATION_ERR("Can't init dbus %d", result);
1157 result = _send_sync_noti(NULL, &reply, "load_system_setting");
1159 if (result == NOTIFICATION_ERROR_NONE) {
1160 reply_body = g_dbus_message_get_body(reply);
1161 g_variant_get(reply_body, "(v)", &setting_body);
1163 result_setting = (struct notification_system_setting *)malloc(sizeof(struct notification_system_setting));
1164 if (result_setting == NULL) {
1165 NOTIFICATION_ERR("malloc failed");
1166 g_object_unref(reply);
1167 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1169 notification_ipc_make_system_setting_from_gvariant(result_setting, setting_body);
1171 *setting = result_setting;
1172 g_variant_unref(setting_body);
1176 g_object_unref(reply);
1178 NOTIFICATION_DBG("notification_ipc_request_load_system_setting done [result: %d]", result);
1182 int notification_ipc_update_setting(notification_setting_h setting)
1185 GDBusMessage *reply = NULL;
1188 result = _dbus_init();
1189 if (result != NOTIFICATION_ERROR_NONE) {
1190 NOTIFICATION_ERR("Can't init dbus %d", result);
1194 body = g_variant_new("(siii)",
1195 setting->package_name,
1196 (int)(setting->allow_to_notify),
1197 (int)(setting->do_not_disturb_except),
1198 (int)(setting->visibility_class));
1200 result = _send_sync_noti(body, &reply, "update_noti_setting");
1203 g_object_unref(reply);
1205 NOTIFICATION_DBG("notification_ipc_update_setting done [result: %d]", result);
1209 int notification_ipc_update_system_setting(notification_system_setting_h system_setting)
1212 GDBusMessage *reply = NULL;
1215 result = _dbus_init();
1216 if (result != NOTIFICATION_ERROR_NONE) {
1217 NOTIFICATION_ERR("Can't init dbus %d", result);
1221 body = g_variant_new("(ii)",
1222 (int)(system_setting->do_not_disturb),
1223 (int)(system_setting->visibility_class));
1225 result = _send_sync_noti(body, &reply, "update_noti_sys_setting");
1228 g_object_unref(reply);
1230 NOTIFICATION_DBG("notification_ipc_update_system_setting done [result: %d]", result);
1234 EXPORT_API GVariant *notification_ipc_make_gvariant_from_noti(notification_h noti)
1236 NOTIFICATION_DBG("make gvariant from noti");
1238 int b_encode_len = 0;
1239 bundle_raw *args = NULL;
1240 bundle_raw *group_args = NULL;
1241 bundle_raw *b_image_path = NULL;
1242 bundle_raw *b_execute_option = NULL;
1243 bundle_raw *b_service_responding = NULL;
1244 bundle_raw *b_service_single_launch = NULL;
1245 bundle_raw *b_service_multi_launch = NULL;
1246 bundle_raw *b_event_handler[NOTIFICATION_EVENT_TYPE_MAX] = {NULL, };
1247 bundle_raw *b_text = NULL;
1248 bundle_raw *b_key = NULL;
1249 bundle_raw *b_format_args = NULL;
1250 GVariant *body = NULL;
1251 GVariant *result_body = NULL;
1252 GVariantBuilder builder;
1254 g_variant_builder_init(&builder, G_VARIANT_TYPE("a{iv}"));
1255 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_NOTI_TYPE, g_variant_new_int32(noti->type));
1256 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_LAYOUT, g_variant_new_int32(noti->layout));
1257 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_GROUP_ID, g_variant_new_int32(noti->group_id));
1258 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_INTERNAL_GROUP_ID, g_variant_new_int32(noti->internal_group_id));
1259 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_PRIV_ID, g_variant_new_int32(noti->priv_id));
1260 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_CALLER_PKGNAME, g_variant_new_string((const gchar *)noti->caller_pkgname));
1261 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_DISPLAY_APPLIST, g_variant_new_int32(noti->display_applist));
1264 bundle_encode(noti->args, (bundle_raw **)&args, NULL);
1265 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_ARGS, g_variant_new_string((const gchar *)args));
1268 bundle_free_encoded_rawdata(&args);
1271 if (noti->group_args) {
1272 bundle_encode(noti->group_args, (bundle_raw **)&group_args,
1274 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_GROUP_ARGS, g_variant_new_string((const gchar *)group_args));
1277 bundle_free_encoded_rawdata(&group_args);
1280 if (noti->b_execute_option) {
1281 bundle_encode(noti->b_execute_option,
1282 (bundle_raw **)&b_execute_option, &b_encode_len);
1283 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_EXECUTE_OPTION, g_variant_new_string((const gchar *)b_execute_option));
1285 if (b_execute_option)
1286 bundle_free_encoded_rawdata(&b_execute_option);
1289 if (noti->b_service_responding) {
1290 bundle_encode(noti->b_service_responding,
1291 (bundle_raw **)&b_service_responding, &b_encode_len);
1292 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_SERVICE_RESPONDING, g_variant_new_string((const gchar *)b_service_responding));
1294 if (b_service_responding)
1295 bundle_free_encoded_rawdata(&b_service_responding);
1298 if (noti->b_service_single_launch) {
1299 bundle_encode(noti->b_service_single_launch,
1300 (bundle_raw **)&b_service_single_launch, &b_encode_len);
1301 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_SERVICE_SINGLE_LAUNCH, g_variant_new_string((const gchar *)b_service_single_launch));
1303 if (b_service_single_launch)
1304 bundle_free_encoded_rawdata(&b_service_single_launch);
1307 if (noti->b_service_multi_launch) {
1308 bundle_encode(noti->b_service_multi_launch,
1309 (bundle_raw **)&b_service_multi_launch, &b_encode_len);
1310 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_SERVICE_MULTI_LAUNCH, g_variant_new_string((const gchar *)b_service_multi_launch));
1312 if (b_service_multi_launch)
1313 bundle_free_encoded_rawdata(&b_service_multi_launch);
1316 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
1317 if (noti->b_event_handler[i]) {
1318 bundle_encode(noti->b_event_handler[i],
1319 (bundle_raw **)&b_event_handler[i], &b_encode_len);
1320 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_BUTTON1_EVENT + i, g_variant_new_string((const gchar *)b_event_handler[i]));
1322 if (b_event_handler[i])
1323 bundle_free_encoded_rawdata(&b_event_handler[i]);
1327 if (noti->launch_pkgname)
1328 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_LAUNCH_PKGNAME, g_variant_new_string((const gchar *)noti->launch_pkgname));
1330 if (noti->domain != NULL)
1331 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_DOMAIN, g_variant_new_string((const gchar *)noti->domain));
1333 if (noti->dir != NULL)
1334 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_DIR, g_variant_new_string((const gchar *)noti->dir));
1337 bundle_encode(noti->b_text, (bundle_raw **)&b_text, &b_encode_len);
1338 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_TEXT, g_variant_new_string((const gchar *)b_text));
1341 bundle_free_encoded_rawdata(&b_text);
1345 bundle_encode(noti->b_key, (bundle_raw **)&b_key, &b_encode_len);
1346 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_KEY, g_variant_new_string((const gchar *)b_key));
1349 bundle_free_encoded_rawdata(&b_key);
1352 if (noti->b_format_args) {
1353 bundle_encode(noti->b_format_args,
1354 (bundle_raw **)&b_format_args, &b_encode_len);
1355 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_FORMAT_ARGS, g_variant_new_string((const gchar *)b_format_args));
1358 bundle_free_encoded_rawdata(&b_format_args);
1361 if (noti->num_format_args != 0)
1362 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_NUM_FORMAT_ARGS, g_variant_new_int32(noti->num_format_args));
1364 if (noti->b_image_path) {
1365 bundle_encode(noti->b_image_path,
1366 (bundle_raw **)&b_image_path, &b_encode_len);
1367 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_IMAGE_PATH, g_variant_new_string((const gchar *)b_image_path));
1370 bundle_free_encoded_rawdata(&b_image_path);
1373 if (noti->sound_type != NOTIFICATION_SOUND_TYPE_NONE)
1374 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_SOUND_TYPE, g_variant_new_int32(noti->sound_type));
1376 if (noti->sound_path)
1377 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_SOUND_PATH, g_variant_new_string((const gchar *)noti->sound_path));
1379 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_VIBRATION_TYPE, g_variant_new_int32(noti->vibration_type));
1381 if (noti->vibration_path)
1382 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_VIBRATION_PATH, g_variant_new_string((const gchar *)noti->vibration_path));
1384 if (noti->led_operation != NOTIFICATION_LED_OP_OFF)
1385 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_LED_OPERATION, g_variant_new_int32(noti->led_operation));
1387 if (noti->led_argb != 0)
1388 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_LED_ARGB, g_variant_new_int32(noti->led_argb));
1390 if (noti->led_on_ms != 0)
1391 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_LED_ON_MS, g_variant_new_int32(noti->led_on_ms));
1393 if (noti->led_off_ms != 0)
1394 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_LED_OFF_MS, g_variant_new_int32(noti->led_off_ms));
1396 if (noti->time != 0)
1397 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_TIME, g_variant_new_int32(noti->time));
1399 if (noti->insert_time != 0)
1400 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_INSERT_TIME, g_variant_new_int32(noti->insert_time));
1402 if (noti->flags_for_property != 0)
1403 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_FLAGS_FOR_PROPERTY, g_variant_new_int32(noti->flags_for_property));
1405 if (noti->progress_size != 0.0)
1406 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_PROGRESS_SIZE, g_variant_new_double(noti->progress_size));
1408 if (noti->progress_percentage != 0.0)
1409 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_PROGRESS_PERCENTAGE, g_variant_new_double(noti->progress_percentage));
1411 if (noti->app_icon_path != NULL)
1412 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_APP_ICON_PATH, g_variant_new_string((const gchar *)noti->app_icon_path));
1413 if (noti->app_name != NULL)
1414 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_APP_NAME, g_variant_new_string((const gchar *)noti->app_name));
1415 if (noti->temp_title != NULL)
1416 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_TEMP_TITLE, g_variant_new_string((const gchar *)noti->temp_title));
1417 if (noti->temp_content != NULL)
1418 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_TEMP_CONTENT, g_variant_new_string((const gchar *)noti->temp_content));
1419 if (noti->tag != NULL)
1420 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_TAG, g_variant_new_string((const gchar *)noti->tag));
1422 if (noti->ongoing_flag != 0)
1423 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_ONGOING_FLAG, g_variant_new_int32(noti->ongoing_flag));
1424 if (noti->auto_remove != 0)
1425 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_AUTO_REMOVE, g_variant_new_int32(noti->auto_remove));
1427 result_body = g_variant_builder_end(&builder);
1428 body = g_variant_new("(v)", result_body);
1433 static gboolean _variant_to_int_dict(GHashTable **dict, GVariant *variant) {
1440 *dict = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, (GDestroyNotify)g_variant_unref);
1444 g_variant_iter_init(&iter, variant);
1445 while (g_variant_iter_next(&iter, "{iv}", &key, &value)) {
1446 hash_key = (int *)calloc(sizeof(int), 1);
1447 if (hash_key == NULL) {
1448 g_hash_table_unref(*dict);
1452 g_hash_table_insert(*dict, (gpointer)hash_key, value);
1457 static gboolean _variant_dict_lookup(GHashTable *dict,
1459 const gchar *format_string,
1465 value = g_hash_table_lookup(dict, (gpointer)&key);
1467 if (value == NULL || !g_variant_check_format_string(value, format_string, FALSE))
1470 va_start(ap, format_string);
1471 g_variant_get_va(value, format_string, NULL, &ap);
1478 * functions creating notification packet
1480 EXPORT_API int notification_ipc_make_noti_from_gvariant(notification_h noti,
1481 GVariant *variant) {
1483 NOTIFICATION_DBG("make noti from GVariant");
1487 char *caller_pkgname = NULL;
1488 char *launch_pkgname = NULL;
1489 bundle_raw *args = NULL;
1490 bundle_raw *group_args = NULL;
1491 bundle_raw *b_execute_option = NULL;
1492 bundle_raw *b_service_responding = NULL;
1493 bundle_raw *b_service_single_launch = NULL;
1494 bundle_raw *b_service_multi_launch = NULL;
1495 bundle_raw *b_event_handler[NOTIFICATION_EVENT_TYPE_MAX] = { NULL, };
1496 char *domain = NULL;
1498 bundle_raw *b_text = NULL;
1499 bundle_raw *b_key = NULL;
1500 bundle_raw *b_format_args = NULL;
1501 bundle_raw *b_image_path = NULL;
1502 char *sound_path = NULL;
1503 char *vibration_path = NULL;
1504 char *app_icon_path = NULL;
1505 char *app_name = NULL;
1506 char *temp_title = NULL;
1507 char *temp_content = NULL;
1511 NOTIFICATION_ERR("invalid data noti NULL");
1512 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1515 if (variant == NULL) {
1516 NOTIFICATION_ERR("invalid data variant NULL");
1517 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1520 if (!_variant_to_int_dict(&dict, variant))
1521 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1523 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_NOTI_TYPE, "i", ¬i->type);
1524 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_LAYOUT, "i", ¬i->layout);
1525 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_GROUP_ID, "i", ¬i->group_id);
1526 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_INTERNAL_GROUP_ID, "i", ¬i->internal_group_id);
1527 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_PRIV_ID, "i", ¬i->priv_id);
1528 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_CALLER_PKGNAME, "&s", &caller_pkgname);
1529 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_LAUNCH_PKGNAME, "&s", &launch_pkgname);
1530 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_ARGS, "&s", &args);
1531 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_GROUP_ARGS, "&s", &group_args);
1532 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_EXECUTE_OPTION, "&s", &b_execute_option);
1533 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_SERVICE_RESPONDING, "&s", &b_service_responding);
1534 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_SERVICE_SINGLE_LAUNCH, "&s", &b_service_single_launch);
1535 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_SERVICE_MULTI_LAUNCH, "&s", &b_service_multi_launch);
1536 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_BUTTON1_EVENT, "&s", ¬i->b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1]);
1537 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_BUTTON2_EVENT, "&s", ¬i->b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_2]);
1538 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_BUTTON3_EVENT, "&s", ¬i->b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_3]);
1539 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_BUTTON4_EVENT, "&s", ¬i->b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_4]);
1540 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_BUTTON5_EVENT, "&s", ¬i->b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_5]);
1541 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_BUTTON6_EVENT, "&s", ¬i->b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_6]);
1542 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_ICON_EVENT, "&s", ¬i->b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_ICON]);
1543 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_THUMBNAIL_EVENT, "&s", ¬i->b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL]);
1544 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_DOMAIN, "&s", &domain);
1545 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_DIR, "&s", &dir);
1546 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_TEXT, "&s", &b_text);
1547 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_KEY, "&s", &b_key);
1548 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_FORMAT_ARGS, "&s", &b_format_args);
1549 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_NUM_FORMAT_ARGS, "i", ¬i->num_format_args);
1550 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_IMAGE_PATH, "&s", &b_image_path);
1551 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_SOUND_TYPE, "i", ¬i->sound_type);
1552 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_SOUND_PATH, "&s", &sound_path);
1553 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_VIBRATION_TYPE, "i", ¬i->vibration_type);
1554 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_VIBRATION_PATH, "&s", &vibration_path);
1555 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_LED_OPERATION, "i", ¬i->led_operation);
1556 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_LED_ARGB, "i", ¬i->led_argb);
1557 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_LED_ON_MS, "i", ¬i->led_on_ms);
1558 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_LED_OFF_MS, "i", ¬i->led_off_ms);
1559 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_TIME, "i", ¬i->time);
1560 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_INSERT_TIME, "i", ¬i->insert_time);
1561 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_FLAGS_FOR_PROPERTY, "i", ¬i->flags_for_property);
1562 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_DISPLAY_APPLIST, "i", ¬i->display_applist);
1563 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_PROGRESS_SIZE, "d", ¬i->progress_size);
1564 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_PROGRESS_PERCENTAGE, "d", ¬i->progress_percentage);
1565 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_APP_ICON_PATH, "&s", &app_icon_path);
1566 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_APP_NAME, "&s", &app_name);
1567 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_TEMP_TITLE, "&s", &temp_title);
1568 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_TEMP_CONTENT, "&s", &temp_content);
1569 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_TAG, "&s", &tag);
1570 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_ONGOING_FLAG, "i", ¬i->ongoing_flag);
1571 _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_AUTO_REMOVE, "i", ¬i->auto_remove);
1573 noti->caller_pkgname = _dup_string(caller_pkgname);
1574 noti->launch_pkgname = _dup_string(launch_pkgname);
1575 noti->args = _create_bundle_from_bundle_raw(args);
1576 noti->group_args = _create_bundle_from_bundle_raw(group_args);
1577 noti->b_execute_option = _create_bundle_from_bundle_raw(b_execute_option);
1578 noti->b_service_responding = _create_bundle_from_bundle_raw(
1579 b_service_responding);
1580 noti->b_service_single_launch = _create_bundle_from_bundle_raw(
1581 b_service_single_launch);
1582 noti->b_service_multi_launch = _create_bundle_from_bundle_raw(
1583 b_service_multi_launch);
1584 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
1585 noti->b_event_handler[i] = _create_bundle_from_bundle_raw(
1586 b_event_handler[i]);
1588 noti->domain = _dup_string(domain);
1589 noti->dir = _dup_string(dir);
1590 noti->b_text = _create_bundle_from_bundle_raw(b_text);
1591 noti->b_key = _create_bundle_from_bundle_raw(b_key);
1592 noti->b_format_args = _create_bundle_from_bundle_raw(b_format_args);
1593 noti->b_image_path = _create_bundle_from_bundle_raw(b_image_path);
1594 noti->sound_path = _dup_string(sound_path);
1595 noti->vibration_path = _dup_string(vibration_path);
1596 noti->app_icon_path = _dup_string(app_icon_path);
1597 noti->app_name = _dup_string(app_name);
1598 noti->temp_title = _dup_string(temp_title);
1599 noti->temp_content = _dup_string(temp_content);
1600 noti->tag = _dup_string(tag);
1602 g_hash_table_unref(dict);
1604 return NOTIFICATION_ERROR_NONE;
1607 EXPORT_API GVariant *notification_ipc_make_gvariant_from_system_setting(struct notification_system_setting *noti_setting)
1609 GVariant *body = NULL;
1610 body = g_variant_new("(ii)",
1611 noti_setting->do_not_disturb,
1612 noti_setting->visibility_class);
1616 EXPORT_API int notification_ipc_make_system_setting_from_gvariant(struct notification_system_setting *noti_setting,
1620 int visibility_class;
1622 if (noti_setting == NULL) {
1623 NOTIFICATION_ERR("invalid data");
1624 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1626 g_variant_get(variant,
1631 NOTIFICATION_DBG("system setting #### %d, %d",
1632 do_not_disturb, visibility_class);
1634 noti_setting->do_not_disturb = do_not_disturb;
1635 noti_setting->visibility_class = visibility_class;
1637 NOTIFICATION_DBG("system setting2 #### %d, %d",
1638 noti_setting->do_not_disturb, noti_setting->visibility_class);
1640 return NOTIFICATION_ERROR_NONE;
1643 EXPORT_API GVariant *notification_ipc_make_gvariant_from_setting(struct notification_setting *noti_setting)
1645 GVariant *body = NULL;
1647 body = g_variant_new("(siii)",
1648 noti_setting->package_name,
1649 noti_setting->allow_to_notify,
1650 noti_setting->do_not_disturb_except,
1651 noti_setting->visibility_class);
1656 EXPORT_API int notification_ipc_make_setting_from_gvariant(struct notification_setting *noti_setting,
1659 NOTIFICATION_DBG("notification_ipc_make_setting_from_gvariant !!!!");
1661 int allow_to_notify;
1662 int do_not_disturb_except;
1663 int visibility_class;
1665 if (noti_setting == NULL || variant == NULL) {
1666 NOTIFICATION_ERR("invalid data");
1667 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1669 g_variant_get(variant,
1673 &do_not_disturb_except,
1676 NOTIFICATION_DBG("setting from variant %s !!", pkgname);
1678 noti_setting->package_name = _dup_string(pkgname);
1679 noti_setting->allow_to_notify = allow_to_notify;
1680 noti_setting->do_not_disturb_except = do_not_disturb_except;
1681 noti_setting->visibility_class = visibility_class;
1683 NOTIFICATION_DBG("setting from variant %s, %s",
1684 noti_setting->package_name, pkgname);
1686 return NOTIFICATION_ERROR_NONE;
1689 static int _send_service_register()
1691 NOTIFICATION_DBG("service register");
1692 GDBusMessage *reply = NULL;
1695 result = _send_sync_noti(NULL, &reply, "noti_service_register");
1698 g_object_unref(reply);
1700 NOTIFICATION_ERR("_send_service_register done = %s, result = %d", _bus_name, result);
1704 static int _ipc_monitor_register(void)
1706 NOTIFICATION_ERR("register a service\n");
1708 return _send_service_register();
1711 static void _on_name_appeared(GDBusConnection *connection,
1713 const gchar *name_owner,
1716 NOTIFICATION_DBG("name appeared : %s", name);
1717 is_master_started = 1;
1718 _ipc_monitor_register();
1720 /* TODO: dbus activation isn't enough ? */
1721 _do_deffered_task();
1724 static void _on_name_vanished(GDBusConnection *connection,
1728 NOTIFICATION_DBG("name vanished : %s", name);
1729 is_master_started = 0;
1732 int notification_ipc_monitor_init(void)
1737 if (ret != NOTIFICATION_ERROR_NONE) {
1738 NOTIFICATION_ERR("Can't init dbus %d", ret);
1742 ret = _dbus_signal_init();
1743 if (ret != NOTIFICATION_ERROR_NONE) {
1744 NOTIFICATION_ERR("Can't signal_init %d", ret);
1748 ret = _ipc_monitor_register();
1749 if (ret != NOTIFICATION_ERROR_NONE) {
1750 NOTIFICATION_ERR("Can't init ipc_monitor_register %d", ret);
1754 if (provider_monitor_id == 0) {
1755 provider_monitor_id = g_bus_watch_name_on_connection(
1758 G_BUS_NAME_WATCHER_FLAGS_NONE,
1764 if (provider_monitor_id == 0) {
1765 g_dbus_connection_signal_unsubscribe(_gdbus_conn, monitor_id);
1767 NOTIFICATION_ERR("watch on name fail");
1768 return NOTIFICATION_ERROR_IO_ERROR;
1772 return NOTIFICATION_ERROR_NONE;
1775 static int _ipc_monitor_deregister(void)
1777 if (provider_monitor_id) {
1778 g_bus_unwatch_name(provider_monitor_id);
1779 provider_monitor_id = 0;
1783 g_dbus_connection_signal_unsubscribe(_gdbus_conn, monitor_id);
1787 return NOTIFICATION_ERROR_NONE;
1790 int notification_ipc_monitor_fini(void)
1792 return _ipc_monitor_deregister();