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.
31 #include <com-core_packet.h>
33 #include <notification_ipc.h>
34 #include <notification_db.h>
35 #include <notification_type.h>
36 #include <notification_private.h>
37 #include <notification_debug.h>
38 #include <notification_setting_internal.h>
40 #define NOTIFICATION_IPC_TIMEOUT 0.0
42 #if !defined(VCONFKEY_MASTER_STARTED)
43 #define VCONFKEY_MASTER_STARTED "memory/data-provider-master/started"
49 int server_cl_fd_ref_cnt;
51 const char *socket_file;
53 int (*request_cb)(const char *appid, const char *name, int type, const char *content, const char *icon, pid_t pid, double period, int allow_duplicate, void *data);
57 int is_started_cb_set_svc;
58 int is_started_cb_set_task;
62 .server_cl_fd_ref_cnt = 0,
64 .socket_file = NOTIFICATION_ADDR,
66 .is_started_cb_set_svc = 0,
67 .is_started_cb_set_task = 0,
70 typedef struct _task_list task_list;
75 void (*task_cb) (void *data);
79 typedef struct _result_cb_item {
80 void (*result_cb)(int priv_id, int result, void *data);
84 static task_list *g_task_list;
86 static int notification_ipc_monitor_register(void);
87 static int notification_ipc_monitor_deregister(void);
88 static void _do_deffered_task(void);
89 static void _master_started_cb_task(keynode_t *node, void *data);
91 static inline char *_string_get(char *string)
96 if (string[0] == '\0') {
104 * functions to check state of master
106 static inline void _set_master_started_cb(vconf_callback_fn cb) {
109 ret = vconf_notify_key_changed(VCONFKEY_MASTER_STARTED,
112 NOTIFICATION_ERR("failed to notify key(%s) : %d",
113 VCONFKEY_MASTER_STARTED, ret);
117 static inline void _unset_master_started_cb(vconf_callback_fn cb) {
120 ret = vconf_ignore_key_changed(VCONFKEY_MASTER_STARTED,
123 NOTIFICATION_ERR("failed to notify key(%s) : %d",
124 VCONFKEY_MASTER_STARTED, ret);
128 int notification_ipc_is_master_ready(void)
130 int ret = -1, is_master_started = 0;
132 ret = vconf_get_bool(VCONFKEY_MASTER_STARTED, &is_master_started);
133 if (ret == 0 && is_master_started == 1) {
134 NOTIFICATION_ERR("the master has been started");
136 is_master_started = 0;
137 NOTIFICATION_ERR("the master has been stopped");
140 return is_master_started;
144 notification_ipc_add_deffered_task(
145 void (*deferred_task_cb)(void *data),
148 task_list *list = NULL;
149 task_list *list_new = NULL;
152 (task_list *) malloc(sizeof(task_list));
154 if (list_new == NULL) {
155 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
158 if (s_info.is_started_cb_set_task == 0) {
159 _set_master_started_cb(_master_started_cb_task);
160 s_info.is_started_cb_set_task = 1;
163 list_new->next = NULL;
164 list_new->prev = NULL;
166 list_new->task_cb = deferred_task_cb;
167 list_new->data = user_data;
169 if (g_task_list == NULL) {
170 g_task_list = list_new;
174 while (list->next != NULL) {
178 list->next = list_new;
179 list_new->prev = list;
181 return NOTIFICATION_ERROR_NONE;
185 notification_ipc_del_deffered_task(
186 void (*deferred_task_cb)(void *data))
188 task_list *list_del = NULL;
189 task_list *list_prev = NULL;
190 task_list *list_next = NULL;
192 list_del = g_task_list;
194 if (list_del == NULL) {
195 return NOTIFICATION_ERROR_INVALID_PARAMETER;
198 while (list_del->prev != NULL) {
199 list_del = list_del->prev;
203 if (list_del->task_cb == deferred_task_cb) {
204 list_prev = list_del->prev;
205 list_next = list_del->next;
207 if (list_prev == NULL) {
208 g_task_list = list_next;
210 list_prev->next = list_next;
213 if (list_next == NULL) {
214 if (list_prev != NULL) {
215 list_prev->next = NULL;
218 list_next->prev = list_prev;
223 if (g_task_list == NULL) {
224 if (s_info.is_started_cb_set_task == 1) {
225 _unset_master_started_cb(_master_started_cb_task);
226 s_info.is_started_cb_set_task = 0;
230 return NOTIFICATION_ERROR_NONE;
232 list_del = list_del->next;
233 } while (list_del != NULL);
235 return NOTIFICATION_ERROR_INVALID_PARAMETER;
238 static void _do_deffered_task(void) {
239 task_list *list_do = NULL;
240 task_list *list_temp = NULL;
242 if (g_task_list == NULL) {
246 list_do = g_task_list;
248 if (s_info.is_started_cb_set_task == 1) {
249 _unset_master_started_cb(_master_started_cb_task);
250 s_info.is_started_cb_set_task = 0;
253 while (list_do->prev != NULL) {
254 list_do = list_do->prev;
257 while (list_do != NULL) {
258 if (list_do->task_cb != NULL) {
259 list_do->task_cb(list_do->data);
260 NOTIFICATION_DBG("called:%p", list_do->task_cb);
262 list_temp = list_do->next;
268 static void _master_started_cb_service(keynode_t *node,
270 int ret = NOTIFICATION_ERROR_NONE;
272 if (notification_ipc_is_master_ready()) {
273 NOTIFICATION_ERR("try to register a notification service");
274 ret = notification_ipc_monitor_deregister();
275 if (ret != NOTIFICATION_ERROR_NONE) {
276 NOTIFICATION_ERR("failed to unregister a monitor");
278 ret = notification_ipc_monitor_register();
279 if (ret != NOTIFICATION_ERROR_NONE) {
280 NOTIFICATION_ERR("failed to register a monitor");
283 NOTIFICATION_ERR("try to unregister a notification service");
284 ret = notification_ipc_monitor_deregister();
285 if (ret != NOTIFICATION_ERROR_NONE) {
286 NOTIFICATION_ERR("failed to deregister a monitor");
291 static void _master_started_cb_task(keynode_t *node,
294 if (notification_ipc_is_master_ready()) {
300 * functions to create operation list
302 notification_op *notification_ipc_create_op(notification_op_type_e type, int num_op, int *list_priv_id, int num_priv_id, notification_h *noti_list)
305 notification_op *op_list = NULL;
311 op_list = (notification_op *)malloc(sizeof(notification_op) * num_op);
312 memset(op_list, 0x0, sizeof(notification_op) * num_op);
314 for (i = 0; i < num_op; i++) {
315 (op_list + i)->type = type;
316 if (list_priv_id != NULL) {
317 (op_list + i)->priv_id = *(list_priv_id + i);
319 if (noti_list != NULL) {
320 (op_list + i)->noti = *(noti_list + i);
328 * utility functions creating notification packet
330 static inline char *_dup_string(const char *string)
334 if (string == NULL) {
337 if (string[0] == '\0') {
341 ret = strdup(string);
343 NOTIFICATION_ERR("Error: %s\n", strerror(errno));
348 static inline bundle *_create_bundle_from_string(unsigned char *string)
350 if (string == NULL) {
353 if (string[0] == '\0') {
357 return bundle_decode(string, strlen((char *)string));
361 * functions creating notification packet
363 EXPORT_API int notification_ipc_make_noti_from_packet(notification_h noti, const struct packet *packet)
370 int internal_group_id;
372 char *caller_pkgname = NULL;
373 char *launch_pkgname = NULL;
374 unsigned char *args = NULL;
375 unsigned char *group_args = NULL;
376 unsigned char *b_execute_option = NULL;
377 unsigned char *b_service_responding = NULL;
378 unsigned char *b_service_single_launch = NULL;
379 unsigned char *b_service_multi_launch = NULL;
380 unsigned char *b_event_handler[NOTIFICATION_EVENT_TYPE_MAX] = { NULL, };
383 unsigned char *b_text = NULL;
384 unsigned char *b_key = NULL;
385 unsigned char *b_format_args = NULL;
387 unsigned char *b_image_path = NULL;
389 char *sound_path = NULL;
391 char *vibration_path = NULL;
398 int flags_for_property;
400 double progress_size;
401 double progress_percentage;
402 char *app_icon_path = NULL;
403 char *app_name = NULL;
404 char *temp_title = NULL;
405 char *temp_content = NULL;
409 NOTIFICATION_ERR("invalid data");
410 return NOTIFICATION_ERROR_INVALID_PARAMETER;
413 ret = packet_get(packet,
414 "iiiiisssssssssssssssssssssisisisiiiiiiiiddsssss",
425 &b_service_responding,
426 &b_service_single_launch,
427 &b_service_multi_launch,
428 &b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1],
429 &b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_2],
430 &b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_3],
431 &b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_4],
432 &b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_5],
433 &b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_6],
434 &b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_ICON],
435 &b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL],
456 &progress_percentage,
464 NOTIFICATION_ERR("failed to create a noti from packet");
465 return NOTIFICATION_ERROR_INVALID_PARAMETER;
469 * This is already allocated from the notification_create function.
470 * Before reallocate string to here.
471 * We have to release old one first.
473 free(noti->caller_pkgname);
474 noti->caller_pkgname = _dup_string(caller_pkgname);
475 noti->launch_pkgname = _dup_string(launch_pkgname);
476 noti->args = _create_bundle_from_string(args);
477 noti->group_args = _create_bundle_from_string(group_args);
478 noti->b_execute_option = _create_bundle_from_string(b_execute_option);
479 noti->b_service_responding = _create_bundle_from_string(b_service_responding);
480 noti->b_service_single_launch = _create_bundle_from_string(b_service_single_launch);
481 noti->b_service_multi_launch = _create_bundle_from_string(b_service_multi_launch);
482 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
483 noti->b_event_handler[i] = _create_bundle_from_string(b_event_handler[i]);
485 noti->domain = _dup_string(domain);
486 noti->dir = _dup_string(dir);
487 noti->b_text = _create_bundle_from_string(b_text);
488 noti->b_key = _create_bundle_from_string(b_key);
489 noti->b_format_args = _create_bundle_from_string(b_format_args);
490 noti->b_image_path = _create_bundle_from_string(b_image_path);
491 noti->sound_path = _dup_string(sound_path);
492 noti->vibration_path = _dup_string(vibration_path);
493 noti->app_icon_path = _dup_string(app_icon_path);
494 noti->app_name = _dup_string(app_name);
495 noti->temp_title = _dup_string(temp_title);
496 noti->temp_content = _dup_string(temp_content);
499 noti->layout = layout;
500 noti->group_id = group_id;
501 noti->internal_group_id = internal_group_id;
502 noti->priv_id = priv_id;
503 noti->num_format_args = num_format_args;
504 noti->sound_type = sound_type;
505 noti->vibration_type = vibration_type;
506 noti->led_operation = led_operation;
507 noti->led_argb = led_argb;
508 noti->led_on_ms = led_on_ms;
509 noti->led_off_ms = led_off_ms;
511 noti->insert_time = insert_time;
512 noti->flags_for_property = flags_for_property;
513 noti->display_applist = display_applist;
514 noti->progress_size = progress_size;
515 noti->progress_percentage = progress_percentage;
516 noti->tag = _dup_string(tag);
518 return NOTIFICATION_ERROR_NONE;
521 EXPORT_API struct packet *notification_ipc_make_packet_from_noti(notification_h noti, const char *command, int packet_type)
524 int b_encode_len = 0;
525 struct packet *result = NULL;
527 char *group_args = NULL;
528 char *b_image_path = NULL;
529 char *b_execute_option = NULL;
530 char *b_service_responding = NULL;
531 char *b_service_single_launch = NULL;
532 char *b_service_multi_launch = NULL;
533 char *b_event_handler[NOTIFICATION_EVENT_TYPE_MAX] = { NULL , };
536 char *b_format_args = NULL;
537 struct packet *(*func_to_create_packet)(const char *command, const char *fmt, ...);
538 const char *title_key = NULL;
539 char buf_key[32] = { 0, };
541 /* Decode bundle to insert DB */
543 bundle_encode(noti->args, (bundle_raw **) & args, NULL);
545 if (noti->group_args) {
546 bundle_encode(noti->group_args, (bundle_raw **) & group_args,
550 if (noti->b_execute_option) {
551 bundle_encode(noti->b_execute_option,
552 (bundle_raw **) & b_execute_option, &b_encode_len);
554 if (noti->b_service_responding) {
555 bundle_encode(noti->b_service_responding,
556 (bundle_raw **) & b_service_responding, &b_encode_len);
558 if (noti->b_service_single_launch) {
559 bundle_encode(noti->b_service_single_launch,
560 (bundle_raw **) & b_service_single_launch, &b_encode_len);
562 if (noti->b_service_multi_launch) {
563 bundle_encode(noti->b_service_multi_launch,
564 (bundle_raw **) & b_service_multi_launch, &b_encode_len);
567 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
568 if (noti->b_event_handler[i]) {
569 bundle_encode(noti->b_event_handler[i],
570 (bundle_raw **) & b_event_handler[i], &b_encode_len);
575 bundle_encode(noti->b_text, (bundle_raw **) & b_text, &b_encode_len);
578 bundle_encode(noti->b_key, (bundle_raw **) & b_key, &b_encode_len);
580 if (noti->b_format_args) {
581 bundle_encode(noti->b_format_args,
582 (bundle_raw **) & b_format_args, &b_encode_len);
585 if (noti->b_image_path) {
586 bundle_encode(noti->b_image_path,
587 (bundle_raw **) & b_image_path, &b_encode_len);
590 if (noti->b_key != NULL) {
591 snprintf(buf_key, sizeof(buf_key), "%d",
592 NOTIFICATION_TEXT_TYPE_TITLE);
594 title_key = bundle_get_val(noti->b_key, buf_key);
597 if (title_key == NULL && noti->b_text != NULL) {
598 snprintf(buf_key, sizeof(buf_key), "%d",
599 NOTIFICATION_TEXT_TYPE_TITLE);
601 title_key = bundle_get_val(noti->b_text, buf_key);
604 if (title_key == NULL) {
605 title_key = noti->caller_pkgname;
608 if (packet_type == 1)
609 func_to_create_packet = packet_create;
610 else if (packet_type == 2)
611 func_to_create_packet = packet_create_noack;
616 result = func_to_create_packet(command,
617 "iiiiisssssssssssssssssssssisisisiiiiiiiiddsssss",
621 noti->internal_group_id,
623 NOTIFICATION_CHECK_STR(noti->caller_pkgname),
624 NOTIFICATION_CHECK_STR(noti->launch_pkgname),
625 NOTIFICATION_CHECK_STR(args),
626 NOTIFICATION_CHECK_STR(group_args),
627 NOTIFICATION_CHECK_STR(b_execute_option),
628 NOTIFICATION_CHECK_STR(b_service_responding),
629 NOTIFICATION_CHECK_STR(b_service_single_launch),
630 NOTIFICATION_CHECK_STR(b_service_multi_launch),
631 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1]),
632 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_2]),
633 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_3]),
634 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_4]),
635 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_5]),
636 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_6]),
637 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_ICON]),
638 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL]),
639 NOTIFICATION_CHECK_STR(noti->domain),
640 NOTIFICATION_CHECK_STR(noti->dir),
641 NOTIFICATION_CHECK_STR(b_text),
642 NOTIFICATION_CHECK_STR(b_key),
643 NOTIFICATION_CHECK_STR(b_format_args),
644 noti->num_format_args,
645 NOTIFICATION_CHECK_STR(b_image_path),
647 NOTIFICATION_CHECK_STR(noti->sound_path),
648 noti->vibration_type,
649 NOTIFICATION_CHECK_STR(noti->vibration_path),
656 noti->flags_for_property,
657 noti->display_applist,
659 noti->progress_percentage,
660 NOTIFICATION_CHECK_STR(noti->app_icon_path),
661 NOTIFICATION_CHECK_STR(noti->app_name),
662 NOTIFICATION_CHECK_STR(noti->temp_title),
663 NOTIFICATION_CHECK_STR(noti->temp_content),
664 NOTIFICATION_CHECK_STR(noti->tag));
667 /* Free decoded data */
675 if (b_execute_option) {
676 free(b_execute_option);
678 if (b_service_responding) {
679 free(b_service_responding);
681 if (b_service_single_launch) {
682 free(b_service_single_launch);
684 if (b_service_multi_launch) {
685 free(b_service_multi_launch);
688 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
689 if (b_event_handler[i]) {
690 free(b_event_handler[i]);
711 EXPORT_API struct packet *notification_ipc_make_reply_packet_from_noti(notification_h noti, struct packet *packet)
714 int b_encode_len = 0;
715 struct packet *result = NULL;
717 char *group_args = NULL;
718 char *b_image_path = NULL;
719 char *b_execute_option = NULL;
720 char *b_service_responding = NULL;
721 char *b_service_single_launch = NULL;
722 char *b_service_multi_launch = NULL;
723 char *b_event_handler[NOTIFICATION_EVENT_TYPE_MAX] = { NULL , };
726 char *b_format_args = NULL;
727 const char *title_key = NULL;
728 char buf_key[32] = { 0, };
730 /* Decode bundle to insert DB */
732 bundle_encode(noti->args, (bundle_raw **) & args, &b_encode_len);
734 if (noti->group_args) {
735 bundle_encode(noti->group_args, (bundle_raw **) & group_args,
739 if (noti->b_execute_option) {
740 bundle_encode(noti->b_execute_option,
741 (bundle_raw **) & b_execute_option, &b_encode_len);
743 if (noti->b_service_responding) {
744 bundle_encode(noti->b_service_responding,
745 (bundle_raw **) & b_service_responding, &b_encode_len);
747 if (noti->b_service_single_launch) {
748 bundle_encode(noti->b_service_single_launch,
749 (bundle_raw **) & b_service_single_launch, &b_encode_len);
751 if (noti->b_service_multi_launch) {
752 bundle_encode(noti->b_service_multi_launch,
753 (bundle_raw **) & b_service_multi_launch, &b_encode_len);
756 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
757 if (noti->b_event_handler[i]) {
758 bundle_encode(noti->b_event_handler[i],
759 (bundle_raw **) & b_event_handler[i], &b_encode_len);
764 bundle_encode(noti->b_text, (bundle_raw **) & b_text, &b_encode_len);
767 bundle_encode(noti->b_key, (bundle_raw **) & b_key, &b_encode_len);
769 if (noti->b_format_args) {
770 bundle_encode(noti->b_format_args,
771 (bundle_raw **) & b_format_args, &b_encode_len);
774 if (noti->b_image_path) {
775 bundle_encode(noti->b_image_path,
776 (bundle_raw **) & b_image_path, &b_encode_len);
779 if (noti->b_key != NULL) {
780 snprintf(buf_key, sizeof(buf_key), "%d",
781 NOTIFICATION_TEXT_TYPE_TITLE);
783 title_key = bundle_get_val(noti->b_key, buf_key);
786 if (title_key == NULL && noti->b_text != NULL) {
787 snprintf(buf_key, sizeof(buf_key), "%d",
788 NOTIFICATION_TEXT_TYPE_TITLE);
790 title_key = bundle_get_val(noti->b_text, buf_key);
793 if (title_key == NULL) {
794 title_key = noti->caller_pkgname;
797 result = packet_create_reply(packet,
798 "iiiiisssssssssssssssssssssisisisiiiiiiiiddsssss",
802 noti->internal_group_id,
804 NOTIFICATION_CHECK_STR(noti->caller_pkgname),
805 NOTIFICATION_CHECK_STR(noti->launch_pkgname),
806 NOTIFICATION_CHECK_STR(args),
807 NOTIFICATION_CHECK_STR(group_args),
808 NOTIFICATION_CHECK_STR(b_execute_option),
809 NOTIFICATION_CHECK_STR(b_service_responding),
810 NOTIFICATION_CHECK_STR(b_service_single_launch),
811 NOTIFICATION_CHECK_STR(b_service_multi_launch),
812 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1]),
813 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_2]),
814 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_3]),
815 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_4]),
816 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_5]),
817 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_6]),
818 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_ICON]),
819 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL]),
820 NOTIFICATION_CHECK_STR(noti->domain),
821 NOTIFICATION_CHECK_STR(noti->dir),
822 NOTIFICATION_CHECK_STR(b_text),
823 NOTIFICATION_CHECK_STR(b_key),
824 NOTIFICATION_CHECK_STR(b_format_args),
825 noti->num_format_args,
826 NOTIFICATION_CHECK_STR(b_image_path),
828 NOTIFICATION_CHECK_STR(noti->sound_path),
829 noti->vibration_type,
830 NOTIFICATION_CHECK_STR(noti->vibration_path),
837 noti->flags_for_property,
838 noti->display_applist,
840 noti->progress_percentage,
841 NOTIFICATION_CHECK_STR(noti->app_icon_path),
842 NOTIFICATION_CHECK_STR(noti->app_name),
843 NOTIFICATION_CHECK_STR(noti->temp_title),
844 NOTIFICATION_CHECK_STR(noti->temp_content),
845 NOTIFICATION_CHECK_STR(noti->tag));
847 /* Free decoded data */
855 if (b_execute_option) {
856 free(b_execute_option);
858 if (b_service_responding) {
859 free(b_service_responding);
861 if (b_service_single_launch) {
862 free(b_service_single_launch);
864 if (b_service_multi_launch) {
865 free(b_service_multi_launch);
868 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
869 if (b_event_handler[i]) {
870 free(b_event_handler[i]);
892 * functions to handler services
894 static struct packet *_handler_insert(pid_t pid, int handle, const struct packet *packet)
896 notification_h noti = NULL;
899 NOTIFICATION_ERR("a packet is null");
902 noti = notification_create(NOTIFICATION_TYPE_NOTI);
904 NOTIFICATION_ERR("failed to create a notification");
907 notification_ipc_make_noti_from_packet(noti, packet);
909 if (noti->flags_for_property
910 & NOTIFICATION_PROP_DISABLE_UPDATE_ON_INSERT) {
911 /* Disable changed cb */
913 /* Enable changed cb */
914 notification_op *noti_op = notification_ipc_create_op(NOTIFICATION_OP_INSERT, 1, &(noti->priv_id), 1, ¬i);
915 if (noti_op != NULL) {
916 notification_call_changed_cb(noti_op, 1);
920 notification_free(noti);
925 static struct packet *_handler_update(pid_t pid, int handle, const struct packet *packet)
927 notification_h noti = NULL;
930 NOTIFICATION_ERR("a packet is null");
934 noti = notification_create(NOTIFICATION_TYPE_NOTI);
936 NOTIFICATION_ERR("failed to create a notification");
940 notification_ipc_make_noti_from_packet(noti, packet);
942 notification_op *noti_op = notification_ipc_create_op(NOTIFICATION_OP_UPDATE, 1, &(noti->priv_id), 1, ¬i);
943 if (noti_op != NULL) {
944 notification_call_changed_cb(noti_op, 1);
948 notification_free(noti);
953 static struct packet *_handler_refresh(pid_t pid, int handle, const struct packet *packet)
956 NOTIFICATION_ERR("a packet is null");
959 notification_op *noti_op = notification_ipc_create_op(NOTIFICATION_OP_REFRESH, 1, NULL, 0, NULL);
960 if (noti_op != NULL) {
961 notification_call_changed_cb(noti_op, 1);
968 static struct packet *_handler_delete_single(pid_t pid, int handle, const struct packet *packet)
971 int priv_id = NOTIFICATION_PRIV_ID_NONE;
974 NOTIFICATION_ERR("a packet is null");
977 if (packet_get(packet, "ii", &num_deleted, &priv_id) == 2) {
978 notification_op *noti_op = notification_ipc_create_op(NOTIFICATION_OP_DELETE, 1, &priv_id, 1, NULL);
979 if (noti_op != NULL) {
980 notification_call_changed_cb(noti_op, 1);
988 static struct packet *_handler_delete_multiple(pid_t pid, int handle, const struct packet *packet)
994 NOTIFICATION_ERR("delete_noti_multiple");
997 NOTIFICATION_ERR("a packet is null");
1000 ret = packet_get(packet, "iiiiiiiiiii", &num_deleted,
1012 NOTIFICATION_ERR("packet data count:%d", ret);
1013 NOTIFICATION_ERR("packet data num deleted:%d", num_deleted);
1016 for (i = 0 ; i < 10 ; i++) {
1017 NOTIFICATION_ERR("packet data[%d]:%d",i, buf[i]);
1021 notification_op *noti_op = notification_ipc_create_op(
1022 NOTIFICATION_OP_DELETE, num_deleted, buf, num_deleted, NULL);
1023 if (noti_op != NULL) {
1024 notification_call_changed_cb(noti_op, num_deleted);
1032 static int _handler_service_register(pid_t pid, int handle, const struct packet *packet, void *data)
1037 NOTIFICATION_ERR("Packet is not valid\n");
1038 ret = NOTIFICATION_ERROR_INVALID_PARAMETER;
1039 } else if (packet_get(packet, "i", &ret) != 1) {
1040 NOTIFICATION_ERR("Packet is not valid\n");
1041 ret = NOTIFICATION_ERROR_INVALID_PARAMETER;
1044 notification_op *noti_op = notification_ipc_create_op(NOTIFICATION_OP_SERVICE_READY, 1, NULL, 1, NULL);
1045 if (noti_op != NULL) {
1046 notification_call_changed_cb(noti_op, 1);
1055 * functions to initialize and register a monitor
1057 static int notification_ipc_monitor_register(void)
1060 struct packet *packet;
1061 static struct method service_table[] = {
1064 .handler = _handler_insert,
1067 .cmd = "update_noti",
1068 .handler = _handler_update,
1071 .cmd = "refresh_noti",
1072 .handler = _handler_refresh,
1075 .cmd = "del_noti_single",
1076 .handler = _handler_delete_single,
1079 .cmd = "del_noti_multiple",
1080 .handler = _handler_delete_multiple,
1088 if (s_info.initialized == 1) {
1089 return NOTIFICATION_ERROR_NONE;
1091 s_info.initialized = 1;
1094 NOTIFICATION_ERR("register a service\n");
1096 com_core_packet_use_thread(1);
1097 s_info.server_fd = com_core_packet_client_init(s_info.socket_file, 0, service_table);
1098 if (s_info.server_fd < 0) {
1099 NOTIFICATION_ERR("Failed to make a connection to the master\n");
1100 return NOTIFICATION_ERROR_IO_ERROR;
1103 packet = packet_create("service_register", "");
1105 NOTIFICATION_ERR("Failed to build a packet\n");
1106 com_core_packet_client_fini(s_info.server_fd);
1107 return NOTIFICATION_ERROR_IO_ERROR;
1110 ret = com_core_packet_async_send(s_info.server_fd, packet, 1.0, _handler_service_register, NULL);
1111 NOTIFICATION_DBG("Service register sent: %d\n", ret);
1112 packet_destroy(packet);
1114 com_core_packet_client_fini(s_info.server_fd);
1115 s_info.server_fd = NOTIFICATION_ERROR_INVALID_PARAMETER;
1116 ret = NOTIFICATION_ERROR_IO_ERROR;
1118 ret = NOTIFICATION_ERROR_NONE;
1121 NOTIFICATION_DBG("Server FD: %d\n", s_info.server_fd);
1125 int notification_ipc_monitor_deregister(void)
1127 if (s_info.initialized == 0) {
1128 return NOTIFICATION_ERROR_NONE;
1131 com_core_packet_client_fini(s_info.server_fd);
1132 s_info.server_fd = NOTIFICATION_ERROR_INVALID_PARAMETER;
1134 s_info.initialized = 0;
1136 return NOTIFICATION_ERROR_NONE;
1139 int notification_ipc_monitor_init(void)
1141 int ret = NOTIFICATION_ERROR_NONE;
1143 if (notification_ipc_is_master_ready()) {
1144 ret = notification_ipc_monitor_register();
1147 if (s_info.is_started_cb_set_svc == 0) {
1148 _set_master_started_cb(_master_started_cb_service);
1149 s_info.is_started_cb_set_svc = 1;
1155 int notification_ipc_monitor_fini(void)
1157 int ret = NOTIFICATION_ERROR_NONE;
1159 if (s_info.is_started_cb_set_svc == 1) {
1160 _unset_master_started_cb(_master_started_cb_service);
1161 s_info.is_started_cb_set_svc = 0;
1164 ret = notification_ipc_monitor_deregister();
1170 * functions to request the service
1172 int notification_ipc_request_insert(notification_h noti, int *priv_id)
1175 int id = NOTIFICATION_PRIV_ID_NONE;
1176 struct packet *packet;
1177 struct packet *result;
1179 /* Initialize private ID */
1180 noti->priv_id = NOTIFICATION_PRIV_ID_NONE;
1181 noti->group_id = NOTIFICATION_GROUP_ID_NONE;
1182 noti->internal_group_id = NOTIFICATION_GROUP_ID_NONE;
1184 packet = notification_ipc_make_packet_from_noti(noti, "add_noti", 1);
1185 result = com_core_packet_oneshot_send(NOTIFICATION_ADDR,
1187 NOTIFICATION_IPC_TIMEOUT);
1188 packet_destroy(packet);
1190 if (result != NULL) {
1191 if (packet_get(result, "ii", &status, &id) != 2) {
1192 NOTIFICATION_ERR("Failed to get a result packet");
1193 packet_unref(result);
1194 return NOTIFICATION_ERROR_IO_ERROR;
1197 if (status != NOTIFICATION_ERROR_NONE) {
1198 packet_unref(result);
1201 packet_unref(result);
1203 NOTIFICATION_ERR("failed to receive answer(insert)");
1204 if (notification_ipc_is_master_ready() == 1) {
1205 return NOTIFICATION_ERROR_PERMISSION_DENIED;
1208 return NOTIFICATION_ERROR_SERVICE_NOT_READY;
1212 if (priv_id != NULL) {
1216 return NOTIFICATION_ERROR_NONE;
1219 int notification_ipc_request_delete_single(notification_type_e type, char *pkgname, int priv_id)
1222 int id = NOTIFICATION_PRIV_ID_NONE;
1223 struct packet *packet;
1224 struct packet *result;
1226 packet = packet_create("del_noti_single", "si", pkgname, priv_id);
1227 result = com_core_packet_oneshot_send(NOTIFICATION_ADDR,
1229 NOTIFICATION_IPC_TIMEOUT);
1230 packet_destroy(packet);
1232 if (result != NULL) {
1233 if (packet_get(result, "ii", &status, &id) != 2) {
1234 NOTIFICATION_ERR("Failed to get a result packet");
1235 packet_unref(result);
1236 return NOTIFICATION_ERROR_IO_ERROR;
1238 packet_unref(result);
1240 NOTIFICATION_ERR("failed to receive answer(delete)");
1241 if (notification_ipc_is_master_ready() == 1) {
1242 return NOTIFICATION_ERROR_PERMISSION_DENIED;
1245 return NOTIFICATION_ERROR_SERVICE_NOT_READY;
1252 int notification_ipc_request_delete_multiple(notification_type_e type, char *pkgname)
1255 int num_deleted = 0;
1256 struct packet *packet;
1257 struct packet *result;
1259 packet = packet_create("del_noti_multiple", "si", pkgname, type);
1260 result = com_core_packet_oneshot_send(NOTIFICATION_ADDR,
1262 NOTIFICATION_IPC_TIMEOUT);
1263 packet_destroy(packet);
1265 if (result != NULL) {
1266 if (packet_get(result, "ii", &status, &num_deleted) != 2) {
1267 NOTIFICATION_ERR("Failed to get a result packet");
1268 packet_unref(result);
1269 return NOTIFICATION_ERROR_IO_ERROR;
1271 NOTIFICATION_ERR("num deleted:%d", num_deleted);
1272 packet_unref(result);
1274 NOTIFICATION_ERR("failed to receive answer(delete multiple)");
1275 if (notification_ipc_is_master_ready() == 1) {
1276 return NOTIFICATION_ERROR_PERMISSION_DENIED;
1279 return NOTIFICATION_ERROR_SERVICE_NOT_READY;
1286 int notification_ipc_request_update(notification_h noti)
1289 int id = NOTIFICATION_PRIV_ID_NONE;
1290 struct packet *packet;
1291 struct packet *result;
1293 packet = notification_ipc_make_packet_from_noti(noti, "update_noti", 1);
1294 result = com_core_packet_oneshot_send(NOTIFICATION_ADDR,
1296 NOTIFICATION_IPC_TIMEOUT);
1297 packet_destroy(packet);
1299 if (result != NULL) {
1300 if (packet_get(result, "ii", &status, &id) != 2) {
1301 NOTIFICATION_ERR("Failed to get a result packet");
1302 packet_unref(result);
1303 return NOTIFICATION_ERROR_IO_ERROR;
1305 packet_unref(result);
1307 NOTIFICATION_ERR("failed to receive answer(update)");
1308 if (notification_ipc_is_master_ready() == 1) {
1309 return NOTIFICATION_ERROR_PERMISSION_DENIED;
1312 return NOTIFICATION_ERROR_SERVICE_NOT_READY;
1319 static int _notification_ipc_update_cb(pid_t pid, int handle, const struct packet *packet, void *data)
1322 int id = NOTIFICATION_PRIV_ID_NONE;
1323 result_cb_item *cb_item = (result_cb_item *)data;
1325 if (cb_item == NULL) {
1326 NOTIFICATION_ERR("Failed to get a callback item");
1327 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1329 s_info.server_cl_fd_ref_cnt = (s_info.server_cl_fd_ref_cnt <= 1) ? 0 : s_info.server_cl_fd_ref_cnt - 1;
1330 if (s_info.server_cl_fd_ref_cnt <= 0) {
1331 NOTIFICATION_DBG("REFCNT: %d (fd: %d)", s_info.server_cl_fd_ref_cnt, s_info.server_cl_fd);
1332 int fd_temp = s_info.server_cl_fd;
1333 s_info.server_cl_fd = -1;
1334 com_core_packet_client_fini(fd_temp);
1335 NOTIFICATION_DBG("FD(%d) finalized", fd_temp);
1338 if (packet != NULL) {
1339 if (packet_get(packet, "ii", &status, &id) != 2) {
1340 NOTIFICATION_ERR("Failed to get a result packet");
1341 status = NOTIFICATION_ERROR_IO_ERROR;
1345 if (cb_item->result_cb != NULL) {
1346 cb_item->result_cb(id, status, cb_item->data);
1353 int notification_ipc_request_update_async(notification_h noti,
1354 void (*result_cb)(int priv_id, int result, void *data), void *user_data)
1356 int ret = NOTIFICATION_ERROR_NONE;
1358 struct packet *packet = NULL;
1359 result_cb_item *cb_item = NULL;
1361 packet = notification_ipc_make_packet_from_noti(noti, "update_noti", 1);
1362 if (packet == NULL) {
1363 ret = NOTIFICATION_ERROR_INVALID_PARAMETER;
1367 cb_item = calloc(1, sizeof(result_cb_item));
1368 if (cb_item == NULL) {
1369 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
1373 if (s_info.server_cl_fd < 0) {
1374 com_core_packet_use_thread(1);
1375 s_info.server_cl_fd = com_core_packet_client_init(s_info.socket_file, 0, NULL);
1376 if (s_info.server_cl_fd < 0) {
1377 NOTIFICATION_DBG("Failed to init client: %d", s_info.server_cl_fd);
1378 if (notification_ipc_is_master_ready() == 1) {
1379 ret = NOTIFICATION_ERROR_PERMISSION_DENIED;
1382 ret = NOTIFICATION_ERROR_SERVICE_NOT_READY;
1386 s_info.server_cl_fd_ref_cnt = 1;
1388 s_info.server_cl_fd_ref_cnt++;
1391 cb_item->result_cb = result_cb;
1392 cb_item->data = user_data;
1394 NOTIFICATION_INFO("Connection count:%d, fd:%d", s_info.server_cl_fd_ref_cnt, s_info.server_cl_fd);
1396 ret_con = com_core_packet_async_send(s_info.server_cl_fd, packet, 0.0f,
1397 _notification_ipc_update_cb, cb_item);
1399 NOTIFICATION_ERR("Failed to request update, %d\n", ret_con);
1400 s_info.server_cl_fd_ref_cnt = (s_info.server_cl_fd_ref_cnt <= 1) ? 0 : s_info.server_cl_fd_ref_cnt - 1;
1401 if (s_info.server_cl_fd_ref_cnt <= 0) {
1402 int fd_temp = s_info.server_cl_fd;
1403 s_info.server_cl_fd = -1;
1404 com_core_packet_client_fini(fd_temp);
1405 NOTIFICATION_INFO("FD(%d) finalized", fd_temp);
1407 ret = NOTIFICATION_ERROR_IO_ERROR;
1410 ret = NOTIFICATION_ERROR_NONE;
1415 if (cb_item) free(cb_item);
1416 NOTIFICATION_ERR("Err: %d\n", ret);
1419 if (packet) packet_destroy(packet);
1424 int notification_ipc_request_refresh(void)
1427 struct packet *packet;
1428 struct packet *result;
1430 packet = packet_create("refresh_noti", "i", NOTIFICATION_OP_REFRESH);
1431 result = com_core_packet_oneshot_send(NOTIFICATION_ADDR,
1433 NOTIFICATION_IPC_TIMEOUT);
1434 packet_destroy(packet);
1436 if (result != NULL) {
1437 if (packet_get(result, "i", &status) != 1) {
1438 NOTIFICATION_ERR("Failed to get a result packet");
1439 packet_unref(result);
1440 return NOTIFICATION_ERROR_IO_ERROR;
1442 packet_unref(result);
1444 NOTIFICATION_ERR("failed to receive answer(refresh)");
1445 if (notification_ipc_is_master_ready() == 1) {
1446 return NOTIFICATION_ERROR_PERMISSION_DENIED;
1449 return NOTIFICATION_ERROR_SERVICE_NOT_READY;
1457 int notification_ipc_update_setting(notification_setting_h setting)
1461 struct packet *packet;
1462 struct packet *result;
1464 packet = packet_create("update_noti_setting", "siii", setting->package_name, (int)(setting->allow_to_notify), (int)(setting->do_not_disturb_except), (int)(setting->visibility_class));
1465 result = com_core_packet_oneshot_send(NOTIFICATION_ADDR,
1467 NOTIFICATION_IPC_TIMEOUT);
1468 packet_destroy(packet);
1470 if (result != NULL) {
1471 if (packet_get(result, "ii", &status, &ret) != 2) {
1472 NOTIFICATION_ERR("Failed to get a result packet");
1473 packet_unref(result);
1474 return NOTIFICATION_ERROR_IO_ERROR;
1476 packet_unref(result);
1478 NOTIFICATION_ERR("failed to receive answer(delete)");
1479 if (notification_ipc_is_master_ready() == 1) {
1480 return NOTIFICATION_ERROR_PERMISSION_DENIED;
1483 return NOTIFICATION_ERROR_SERVICE_NOT_READY;
1490 int notification_ipc_update_system_setting(notification_system_setting_h system_setting)
1494 struct packet *packet = NULL;
1495 struct packet *result = NULL;
1497 packet = packet_create("update_noti_sys_setting", "ii", (int)(system_setting->do_not_disturb), (int)(system_setting->visibility_class));
1498 if (packet == NULL) {
1499 NOTIFICATION_ERR("packet_create failed.");
1502 result = com_core_packet_oneshot_send(NOTIFICATION_ADDR, packet, NOTIFICATION_IPC_TIMEOUT);
1503 packet_destroy(packet);
1505 if (result != NULL) {
1506 if (packet_get(result, "ii", &status, &ret) != 2) {
1507 NOTIFICATION_ERR("Failed to get a result packet");
1508 status = NOTIFICATION_ERROR_IO_ERROR;
1513 NOTIFICATION_ERR("failed to receive answer(delete)");
1514 if (notification_ipc_is_master_ready() == 1) {
1515 status = NOTIFICATION_ERROR_PERMISSION_DENIED;
1519 status = NOTIFICATION_ERROR_SERVICE_NOT_READY;
1525 packet_unref(result);
1531 int notification_ipc_noti_setting_property_set(const char *pkgname, const char *property, const char *value)
1535 struct packet *packet;
1536 struct packet *result;
1538 packet = packet_create("set_noti_property", "sss", pkgname, property, value);
1539 result = com_core_packet_oneshot_send(NOTIFICATION_ADDR,
1541 NOTIFICATION_IPC_TIMEOUT);
1542 packet_destroy(packet);
1544 if (result != NULL) {
1545 if (packet_get(result, "ii", &status, &ret) != 2) {
1546 NOTIFICATION_ERR("Failed to get a result packet");
1547 packet_unref(result);
1548 return NOTIFICATION_ERROR_IO_ERROR;
1550 packet_unref(result);
1552 NOTIFICATION_ERR("failed to receive answer(delete)");
1553 if (notification_ipc_is_master_ready() == 1) {
1554 return NOTIFICATION_ERROR_PERMISSION_DENIED;
1557 return NOTIFICATION_ERROR_SERVICE_NOT_READY;
1564 int notification_ipc_noti_setting_property_get(const char *pkgname, const char *property, char **value)
1568 struct packet *packet;
1569 struct packet *result;
1571 packet = packet_create("get_noti_property", "ss", pkgname, property);
1572 result = com_core_packet_oneshot_send(NOTIFICATION_ADDR,
1574 NOTIFICATION_IPC_TIMEOUT);
1575 packet_destroy(packet);
1577 if (result != NULL) {
1578 if (packet_get(result, "is", &status, &ret) != 2) {
1579 NOTIFICATION_ERR("Failed to get a result packet");
1580 packet_unref(result);
1581 return NOTIFICATION_ERROR_IO_ERROR;
1583 if (status == NOTIFICATION_ERROR_NONE && ret != NULL) {
1584 *value = strdup(ret);
1586 packet_unref(result);
1588 NOTIFICATION_ERR("failed to receive answer(delete)");
1589 if (notification_ipc_is_master_ready() == 1) {
1590 return NOTIFICATION_ERROR_PERMISSION_DENIED;
1593 return NOTIFICATION_ERROR_SERVICE_NOT_READY;
1600 int notification_ipc_request_load_noti_by_tag(notification_h noti, const char *pkgname, const char *tag)
1602 struct packet *packet;
1603 struct packet *result;
1605 packet = packet_create("load_noti_by_tag", "ss", pkgname, tag);
1606 result = com_core_packet_oneshot_send(NOTIFICATION_ADDR,
1608 NOTIFICATION_IPC_TIMEOUT);
1609 packet_destroy(packet);
1611 if (result != NULL) {
1612 if (notification_ipc_make_noti_from_packet(noti, result) != NOTIFICATION_ERROR_NONE) {
1613 NOTIFICATION_ERR("Failed to get a result packet");
1614 packet_unref(result);
1615 return NOTIFICATION_ERROR_IO_ERROR;
1618 packet_unref(result);
1620 NOTIFICATION_ERR("failed to receive answer(load noti by tag)");
1621 if (notification_ipc_is_master_ready() == 1) {
1622 return NOTIFICATION_ERROR_PERMISSION_DENIED;
1625 return NOTIFICATION_ERROR_SERVICE_NOT_READY;
1629 return NOTIFICATION_ERROR_NONE;