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>
39 #define NOTIFICATION_IPC_TIMEOUT 0.0
41 #if !defined(VCONFKEY_MASTER_STARTED)
42 #define VCONFKEY_MASTER_STARTED "memory/data-provider-master/started"
48 int server_cl_fd_ref_cnt;
50 const char *socket_file;
52 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);
56 int is_started_cb_set_svc;
57 int is_started_cb_set_task;
61 .server_cl_fd_ref_cnt = 0,
63 .socket_file = NOTIFICATION_ADDR,
65 .is_started_cb_set_svc = 0,
66 .is_started_cb_set_task = 0,
69 typedef struct _task_list task_list;
74 void (*task_cb) (void *data);
78 typedef struct _result_cb_item {
79 void (*result_cb)(int priv_id, int result, void *data);
83 static task_list *g_task_list;
85 static int notification_ipc_monitor_register(void);
86 static int notification_ipc_monitor_deregister(void);
87 static void _do_deffered_task(void);
88 static void _master_started_cb_task(keynode_t *node, void *data);
90 static inline char *_string_get(char *string)
95 if (string[0] == '\0') {
103 * functions to check state of master
105 static inline void _set_master_started_cb(vconf_callback_fn cb) {
108 ret = vconf_notify_key_changed(VCONFKEY_MASTER_STARTED,
111 NOTIFICATION_ERR("failed to notify key(%s) : %d",
112 VCONFKEY_MASTER_STARTED, ret);
116 static inline void _unset_master_started_cb(vconf_callback_fn cb) {
119 ret = vconf_ignore_key_changed(VCONFKEY_MASTER_STARTED,
122 NOTIFICATION_ERR("failed to notify key(%s) : %d",
123 VCONFKEY_MASTER_STARTED, ret);
127 int notification_ipc_is_master_ready(void)
129 int ret = -1, is_master_started = 0;
131 ret = vconf_get_bool(VCONFKEY_MASTER_STARTED, &is_master_started);
132 if (ret == 0 && is_master_started == 1) {
133 NOTIFICATION_ERR("the master has been started");
135 is_master_started = 0;
136 NOTIFICATION_ERR("the master has been stopped");
139 return is_master_started;
143 notification_ipc_add_deffered_task(
144 void (*deferred_task_cb)(void *data),
147 task_list *list = NULL;
148 task_list *list_new = NULL;
151 (task_list *) malloc(sizeof(task_list));
153 if (list_new == NULL) {
154 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
157 if (s_info.is_started_cb_set_task == 0) {
158 _set_master_started_cb(_master_started_cb_task);
159 s_info.is_started_cb_set_task = 1;
162 list_new->next = NULL;
163 list_new->prev = NULL;
165 list_new->task_cb = deferred_task_cb;
166 list_new->data = user_data;
168 if (g_task_list == NULL) {
169 g_task_list = list_new;
173 while (list->next != NULL) {
177 list->next = list_new;
178 list_new->prev = list;
180 return NOTIFICATION_ERROR_NONE;
184 notification_ipc_del_deffered_task(
185 void (*deferred_task_cb)(void *data))
187 task_list *list_del = NULL;
188 task_list *list_prev = NULL;
189 task_list *list_next = NULL;
191 list_del = g_task_list;
193 if (list_del == NULL) {
194 return NOTIFICATION_ERROR_INVALID_PARAMETER;
197 while (list_del->prev != NULL) {
198 list_del = list_del->prev;
202 if (list_del->task_cb == deferred_task_cb) {
203 list_prev = list_del->prev;
204 list_next = list_del->next;
206 if (list_prev == NULL) {
207 g_task_list = list_next;
209 list_prev->next = list_next;
212 if (list_next == NULL) {
213 if (list_prev != NULL) {
214 list_prev->next = NULL;
217 list_next->prev = list_prev;
222 if (g_task_list == NULL) {
223 if (s_info.is_started_cb_set_task == 1) {
224 _unset_master_started_cb(_master_started_cb_task);
225 s_info.is_started_cb_set_task = 0;
229 return NOTIFICATION_ERROR_NONE;
231 list_del = list_del->next;
232 } while (list_del != NULL);
234 return NOTIFICATION_ERROR_INVALID_PARAMETER;
237 static void _do_deffered_task(void) {
238 task_list *list_do = NULL;
239 task_list *list_temp = NULL;
241 if (g_task_list == NULL) {
245 list_do = g_task_list;
247 if (s_info.is_started_cb_set_task == 1) {
248 _unset_master_started_cb(_master_started_cb_task);
249 s_info.is_started_cb_set_task = 0;
252 while (list_do->prev != NULL) {
253 list_do = list_do->prev;
256 while (list_do != NULL) {
257 if (list_do->task_cb != NULL) {
258 list_do->task_cb(list_do->data);
259 NOTIFICATION_DBG("called:%p", list_do->task_cb);
261 list_temp = list_do->next;
267 static void _master_started_cb_service(keynode_t *node,
269 int ret = NOTIFICATION_ERROR_NONE;
271 if (notification_ipc_is_master_ready()) {
272 NOTIFICATION_ERR("try to register a notification service");
273 ret = notification_ipc_monitor_deregister();
274 if (ret != NOTIFICATION_ERROR_NONE) {
275 NOTIFICATION_ERR("failed to unregister a monitor");
277 ret = notification_ipc_monitor_register();
278 if (ret != NOTIFICATION_ERROR_NONE) {
279 NOTIFICATION_ERR("failed to register a monitor");
282 NOTIFICATION_ERR("try to unregister a notification service");
283 ret = notification_ipc_monitor_deregister();
284 if (ret != NOTIFICATION_ERROR_NONE) {
285 NOTIFICATION_ERR("failed to deregister a monitor");
290 static void _master_started_cb_task(keynode_t *node,
293 if (notification_ipc_is_master_ready()) {
299 * functions to create operation list
301 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)
304 notification_op *op_list = NULL;
310 op_list = (notification_op *)malloc(sizeof(notification_op) * num_op);
311 memset(op_list, 0x0, sizeof(notification_op) * num_op);
313 for (i = 0; i < num_op; i++) {
314 (op_list + i)->type = type;
315 if (list_priv_id != NULL) {
316 (op_list + i)->priv_id = *(list_priv_id + i);
318 if (noti_list != NULL) {
319 (op_list + i)->noti = *(noti_list + i);
327 * utility functions creating notification packet
329 static inline char *_dup_string(const char *string)
333 if (string == NULL) {
336 if (string[0] == '\0') {
340 ret = strdup(string);
342 NOTIFICATION_ERR("Error: %d\n", errno);
347 static inline bundle *_create_bundle_from_string(unsigned char *string)
349 if (string == NULL) {
352 if (string[0] == '\0') {
356 return bundle_decode(string, strlen((char *)string));
360 * functions creating notification packet
362 EXPORT_API int notification_ipc_make_noti_from_packet(notification_h noti, const struct packet *packet)
368 int internal_group_id;
370 char *caller_pkgname = NULL;
371 char *launch_pkgname = NULL;
372 unsigned char *args = NULL;
373 unsigned char *group_args = NULL;
374 unsigned char *b_execute_option = NULL;
375 unsigned char *b_service_responding = NULL;
376 unsigned char *b_service_single_launch = NULL;
377 unsigned char *b_service_multi_launch = NULL;
380 unsigned char *b_text = NULL;
381 unsigned char *b_key = NULL;
382 unsigned char *b_format_args = NULL;
384 unsigned char *b_image_path = NULL;
386 char *sound_path = NULL;
388 char *vibration_path = NULL;
395 int flags_for_property;
397 double progress_size;
398 double progress_percentage;
399 char *app_icon_path = NULL;
400 char *app_name = NULL;
401 char *temp_title = NULL;
402 char *temp_content = NULL;
406 NOTIFICATION_ERR("invalid data");
407 return NOTIFICATION_ERROR_INVALID_PARAMETER;
410 ret = packet_get(packet,
411 "iiiiisssssssssssssisisisiiiiiiiiddsssss",
422 &b_service_responding,
423 &b_service_single_launch,
424 &b_service_multi_launch,
445 &progress_percentage,
453 NOTIFICATION_ERR("failed to create a noti from packet");
454 return NOTIFICATION_ERROR_INVALID_PARAMETER;
458 * This is already allocated from the notification_create function.
459 * Before reallocate string to here.
460 * We have to release old one first.
462 free(noti->caller_pkgname);
463 noti->caller_pkgname = _dup_string(caller_pkgname);
464 noti->launch_pkgname = _dup_string(launch_pkgname);
465 noti->args = _create_bundle_from_string(args);
466 noti->group_args = _create_bundle_from_string(group_args);
467 noti->b_execute_option = _create_bundle_from_string(b_execute_option);
468 noti->b_service_responding = _create_bundle_from_string(b_service_responding);
469 noti->b_service_single_launch = _create_bundle_from_string(b_service_single_launch);
470 noti->b_service_multi_launch = _create_bundle_from_string(b_service_multi_launch);
471 noti->domain = _dup_string(domain);
472 noti->dir = _dup_string(dir);
473 noti->b_text = _create_bundle_from_string(b_text);
474 noti->b_key = _create_bundle_from_string(b_key);
475 noti->b_format_args = _create_bundle_from_string(b_format_args);
476 noti->b_image_path = _create_bundle_from_string(b_image_path);
477 noti->sound_path = _dup_string(sound_path);
478 noti->vibration_path = _dup_string(vibration_path);
479 noti->app_icon_path = _dup_string(app_icon_path);
480 noti->app_name = _dup_string(app_name);
481 noti->temp_title = _dup_string(temp_title);
482 noti->temp_content = _dup_string(temp_content);
485 noti->layout = layout;
486 noti->group_id = group_id;
487 noti->internal_group_id = internal_group_id;
488 noti->priv_id = priv_id;
489 noti->num_format_args = num_format_args;
490 noti->sound_type = sound_type;
491 noti->vibration_type = vibration_type;
492 noti->led_operation = led_operation;
493 noti->led_argb = led_argb;
494 noti->led_on_ms = led_on_ms;
495 noti->led_off_ms = led_off_ms;
497 noti->insert_time = insert_time;
498 noti->flags_for_property = flags_for_property;
499 noti->display_applist = display_applist;
500 noti->progress_size = progress_size;
501 noti->progress_percentage = progress_percentage;
502 noti->tag = _dup_string(tag);
504 return NOTIFICATION_ERROR_NONE;
507 EXPORT_API struct packet *notification_ipc_make_packet_from_noti(notification_h noti, const char *command, int packet_type)
509 int b_encode_len = 0;
510 struct packet *result = NULL;
512 char *group_args = NULL;
513 char *b_image_path = NULL;
514 char *b_execute_option = NULL;
515 char *b_service_responding = NULL;
516 char *b_service_single_launch = NULL;
517 char *b_service_multi_launch = NULL;
520 char *b_format_args = NULL;
521 struct packet *(*func_to_create_packet)(const char *command, const char *fmt, ...);
522 const char *title_key = NULL;
523 char buf_key[32] = { 0, };
525 /* Decode bundle to insert DB */
527 bundle_encode(noti->args, (bundle_raw **) & args, NULL);
529 if (noti->group_args) {
530 bundle_encode(noti->group_args, (bundle_raw **) & group_args,
534 if (noti->b_execute_option) {
535 bundle_encode(noti->b_execute_option,
536 (bundle_raw **) & b_execute_option, &b_encode_len);
538 if (noti->b_service_responding) {
539 bundle_encode(noti->b_service_responding,
540 (bundle_raw **) & b_service_responding, &b_encode_len);
542 if (noti->b_service_single_launch) {
543 bundle_encode(noti->b_service_single_launch,
544 (bundle_raw **) & b_service_single_launch, &b_encode_len);
546 if (noti->b_service_multi_launch) {
547 bundle_encode(noti->b_service_multi_launch,
548 (bundle_raw **) & b_service_multi_launch, &b_encode_len);
552 bundle_encode(noti->b_text, (bundle_raw **) & b_text, &b_encode_len);
555 bundle_encode(noti->b_key, (bundle_raw **) & b_key, &b_encode_len);
557 if (noti->b_format_args) {
558 bundle_encode(noti->b_format_args,
559 (bundle_raw **) & b_format_args, &b_encode_len);
562 if (noti->b_image_path) {
563 bundle_encode(noti->b_image_path,
564 (bundle_raw **) & b_image_path, &b_encode_len);
567 if (noti->b_key != NULL) {
568 snprintf(buf_key, sizeof(buf_key), "%d",
569 NOTIFICATION_TEXT_TYPE_TITLE);
571 title_key = bundle_get_val(noti->b_key, buf_key);
574 if (title_key == NULL && noti->b_text != NULL) {
575 snprintf(buf_key, sizeof(buf_key), "%d",
576 NOTIFICATION_TEXT_TYPE_TITLE);
578 title_key = bundle_get_val(noti->b_text, buf_key);
581 if (title_key == NULL) {
582 title_key = noti->caller_pkgname;
585 if (packet_type == 1)
586 func_to_create_packet = packet_create;
587 else if (packet_type == 2)
588 func_to_create_packet = packet_create_noack;
593 result = func_to_create_packet(command,
594 "iiiiisssssssssssssisisisiiiiiiiiddsssss",
598 noti->internal_group_id,
600 NOTIFICATION_CHECK_STR(noti->caller_pkgname),
601 NOTIFICATION_CHECK_STR(noti->launch_pkgname),
602 NOTIFICATION_CHECK_STR(args),
603 NOTIFICATION_CHECK_STR(group_args),
604 NOTIFICATION_CHECK_STR(b_execute_option),
605 NOTIFICATION_CHECK_STR(b_service_responding),
606 NOTIFICATION_CHECK_STR(b_service_single_launch),
607 NOTIFICATION_CHECK_STR(b_service_multi_launch),
608 NOTIFICATION_CHECK_STR(noti->domain),
609 NOTIFICATION_CHECK_STR(noti->dir),
610 NOTIFICATION_CHECK_STR(b_text),
611 NOTIFICATION_CHECK_STR(b_key),
612 NOTIFICATION_CHECK_STR(b_format_args),
613 noti->num_format_args,
614 NOTIFICATION_CHECK_STR(b_image_path),
616 NOTIFICATION_CHECK_STR(noti->sound_path),
617 noti->vibration_type,
618 NOTIFICATION_CHECK_STR(noti->vibration_path),
625 noti->flags_for_property,
626 noti->display_applist,
628 noti->progress_percentage,
629 NOTIFICATION_CHECK_STR(noti->app_icon_path),
630 NOTIFICATION_CHECK_STR(noti->app_name),
631 NOTIFICATION_CHECK_STR(noti->temp_title),
632 NOTIFICATION_CHECK_STR(noti->temp_content),
633 NOTIFICATION_CHECK_STR(noti->tag));
636 /* Free decoded data */
644 if (b_execute_option) {
645 free(b_execute_option);
647 if (b_service_responding) {
648 free(b_service_responding);
650 if (b_service_single_launch) {
651 free(b_service_single_launch);
653 if (b_service_multi_launch) {
654 free(b_service_multi_launch);
674 EXPORT_API struct packet *notification_ipc_make_reply_packet_from_noti(notification_h noti, struct packet *packet)
676 int b_encode_len = 0;
677 struct packet *result = NULL;
679 char *group_args = NULL;
680 char *b_image_path = NULL;
681 char *b_execute_option = NULL;
682 char *b_service_responding = NULL;
683 char *b_service_single_launch = NULL;
684 char *b_service_multi_launch = NULL;
687 char *b_format_args = NULL;
688 const char *title_key = NULL;
689 char buf_key[32] = { 0, };
691 /* Decode bundle to insert DB */
693 bundle_encode(noti->args, (bundle_raw **) & args, &b_encode_len);
695 if (noti->group_args) {
696 bundle_encode(noti->group_args, (bundle_raw **) & group_args,
700 if (noti->b_execute_option) {
701 bundle_encode(noti->b_execute_option,
702 (bundle_raw **) & b_execute_option, &b_encode_len);
704 if (noti->b_service_responding) {
705 bundle_encode(noti->b_service_responding,
706 (bundle_raw **) & b_service_responding, &b_encode_len);
708 if (noti->b_service_single_launch) {
709 bundle_encode(noti->b_service_single_launch,
710 (bundle_raw **) & b_service_single_launch, &b_encode_len);
712 if (noti->b_service_multi_launch) {
713 bundle_encode(noti->b_service_multi_launch,
714 (bundle_raw **) & b_service_multi_launch, &b_encode_len);
718 bundle_encode(noti->b_text, (bundle_raw **) & b_text, &b_encode_len);
721 bundle_encode(noti->b_key, (bundle_raw **) & b_key, &b_encode_len);
723 if (noti->b_format_args) {
724 bundle_encode(noti->b_format_args,
725 (bundle_raw **) & b_format_args, &b_encode_len);
728 if (noti->b_image_path) {
729 bundle_encode(noti->b_image_path,
730 (bundle_raw **) & b_image_path, &b_encode_len);
733 if (noti->b_key != NULL) {
734 snprintf(buf_key, sizeof(buf_key), "%d",
735 NOTIFICATION_TEXT_TYPE_TITLE);
737 title_key = bundle_get_val(noti->b_key, buf_key);
740 if (title_key == NULL && noti->b_text != NULL) {
741 snprintf(buf_key, sizeof(buf_key), "%d",
742 NOTIFICATION_TEXT_TYPE_TITLE);
744 title_key = bundle_get_val(noti->b_text, buf_key);
747 if (title_key == NULL) {
748 title_key = noti->caller_pkgname;
751 result = packet_create_reply(packet,
752 "iiiiisssssssssssssisisisiiiiiiiiddsssss",
756 noti->internal_group_id,
758 NOTIFICATION_CHECK_STR(noti->caller_pkgname),
759 NOTIFICATION_CHECK_STR(noti->launch_pkgname),
760 NOTIFICATION_CHECK_STR(args),
761 NOTIFICATION_CHECK_STR(group_args),
762 NOTIFICATION_CHECK_STR(b_execute_option),
763 NOTIFICATION_CHECK_STR(b_service_responding),
764 NOTIFICATION_CHECK_STR(b_service_single_launch),
765 NOTIFICATION_CHECK_STR(b_service_multi_launch),
766 NOTIFICATION_CHECK_STR(noti->domain),
767 NOTIFICATION_CHECK_STR(noti->dir),
768 NOTIFICATION_CHECK_STR(b_text),
769 NOTIFICATION_CHECK_STR(b_key),
770 NOTIFICATION_CHECK_STR(b_format_args),
771 noti->num_format_args,
772 NOTIFICATION_CHECK_STR(b_image_path),
774 NOTIFICATION_CHECK_STR(noti->sound_path),
775 noti->vibration_type,
776 NOTIFICATION_CHECK_STR(noti->vibration_path),
783 noti->flags_for_property,
784 noti->display_applist,
786 noti->progress_percentage,
787 NOTIFICATION_CHECK_STR(noti->app_icon_path),
788 NOTIFICATION_CHECK_STR(noti->app_name),
789 NOTIFICATION_CHECK_STR(noti->temp_title),
790 NOTIFICATION_CHECK_STR(noti->temp_content),
791 NOTIFICATION_CHECK_STR(noti->tag));
793 /* Free decoded data */
801 if (b_execute_option) {
802 free(b_execute_option);
804 if (b_service_responding) {
805 free(b_service_responding);
807 if (b_service_single_launch) {
808 free(b_service_single_launch);
810 if (b_service_multi_launch) {
811 free(b_service_multi_launch);
832 * functions to handler services
834 static struct packet *_handler_insert(pid_t pid, int handle, const struct packet *packet)
836 notification_h noti = NULL;
839 NOTIFICATION_ERR("a packet is null");
842 noti = notification_create(NOTIFICATION_TYPE_NOTI);
844 NOTIFICATION_ERR("failed to create a notification");
847 notification_ipc_make_noti_from_packet(noti, packet);
849 if (noti->flags_for_property
850 & NOTIFICATION_PROP_DISABLE_UPDATE_ON_INSERT) {
851 /* Disable changed cb */
853 /* Enable changed cb */
854 notification_op *noti_op = notification_ipc_create_op(NOTIFICATION_OP_INSERT, 1, &(noti->priv_id), 1, ¬i);
855 if (noti_op != NULL) {
856 notification_call_changed_cb(noti_op, 1);
860 notification_free(noti);
865 static struct packet *_handler_update(pid_t pid, int handle, const struct packet *packet)
867 notification_h noti = NULL;
870 NOTIFICATION_ERR("a packet is null");
874 noti = notification_create(NOTIFICATION_TYPE_NOTI);
876 NOTIFICATION_ERR("failed to create a notification");
880 notification_ipc_make_noti_from_packet(noti, packet);
882 notification_op *noti_op = notification_ipc_create_op(NOTIFICATION_OP_UPDATE, 1, &(noti->priv_id), 1, ¬i);
883 if (noti_op != NULL) {
884 notification_call_changed_cb(noti_op, 1);
888 notification_free(noti);
893 static struct packet *_handler_refresh(pid_t pid, int handle, const struct packet *packet)
896 NOTIFICATION_ERR("a packet is null");
899 notification_op *noti_op = notification_ipc_create_op(NOTIFICATION_OP_REFRESH, 1, NULL, 0, NULL);
900 if (noti_op != NULL) {
901 notification_call_changed_cb(noti_op, 1);
908 static struct packet *_handler_delete_single(pid_t pid, int handle, const struct packet *packet)
911 int priv_id = NOTIFICATION_PRIV_ID_NONE;
914 NOTIFICATION_ERR("a packet is null");
917 if (packet_get(packet, "ii", &num_deleted, &priv_id) == 2) {
918 notification_op *noti_op = notification_ipc_create_op(NOTIFICATION_OP_DELETE, 1, &priv_id, 1, NULL);
919 if (noti_op != NULL) {
920 notification_call_changed_cb(noti_op, 1);
928 static struct packet *_handler_delete_multiple(pid_t pid, int handle, const struct packet *packet)
934 NOTIFICATION_ERR("delete_noti_multiple");
937 NOTIFICATION_ERR("a packet is null");
940 ret = packet_get(packet, "iiiiiiiiiii", &num_deleted,
952 NOTIFICATION_ERR("packet data count:%d", ret);
953 NOTIFICATION_ERR("packet data num deleted:%d", num_deleted);
956 for (i = 0 ; i < 10 ; i++) {
957 NOTIFICATION_ERR("packet data[%d]:%d",i, buf[i]);
961 notification_op *noti_op = notification_ipc_create_op(
962 NOTIFICATION_OP_DELETE, num_deleted, buf, num_deleted, NULL);
963 if (noti_op != NULL) {
964 notification_call_changed_cb(noti_op, num_deleted);
972 static int _handler_service_register(pid_t pid, int handle, const struct packet *packet, void *data)
977 NOTIFICATION_ERR("Packet is not valid\n");
978 ret = NOTIFICATION_ERROR_INVALID_PARAMETER;
979 } else if (packet_get(packet, "i", &ret) != 1) {
980 NOTIFICATION_ERR("Packet is not valid\n");
981 ret = NOTIFICATION_ERROR_INVALID_PARAMETER;
984 notification_op *noti_op = notification_ipc_create_op(NOTIFICATION_OP_SERVICE_READY, 1, NULL, 1, NULL);
985 if (noti_op != NULL) {
986 notification_call_changed_cb(noti_op, 1);
995 * functions to initialize and register a monitor
997 static int notification_ipc_monitor_register(void)
1000 struct packet *packet;
1001 static struct method service_table[] = {
1004 .handler = _handler_insert,
1007 .cmd = "update_noti",
1008 .handler = _handler_update,
1011 .cmd = "refresh_noti",
1012 .handler = _handler_refresh,
1015 .cmd = "del_noti_single",
1016 .handler = _handler_delete_single,
1019 .cmd = "del_noti_multiple",
1020 .handler = _handler_delete_multiple,
1028 if (s_info.initialized == 1) {
1029 return NOTIFICATION_ERROR_NONE;
1031 s_info.initialized = 1;
1034 NOTIFICATION_ERR("register a service\n");
1036 com_core_packet_use_thread(1);
1037 s_info.server_fd = com_core_packet_client_init(s_info.socket_file, 0, service_table);
1038 if (s_info.server_fd < 0) {
1039 NOTIFICATION_ERR("Failed to make a connection to the master\n");
1040 return NOTIFICATION_ERROR_IO_ERROR;
1043 packet = packet_create("service_register", "");
1045 NOTIFICATION_ERR("Failed to build a packet\n");
1046 com_core_packet_client_fini(s_info.server_fd);
1047 return NOTIFICATION_ERROR_IO_ERROR;
1050 ret = com_core_packet_async_send(s_info.server_fd, packet, 1.0, _handler_service_register, NULL);
1051 NOTIFICATION_DBG("Service register sent: %d\n", ret);
1052 packet_destroy(packet);
1054 com_core_packet_client_fini(s_info.server_fd);
1055 s_info.server_fd = NOTIFICATION_ERROR_INVALID_PARAMETER;
1056 ret = NOTIFICATION_ERROR_IO_ERROR;
1058 ret = NOTIFICATION_ERROR_NONE;
1061 NOTIFICATION_DBG("Server FD: %d\n", s_info.server_fd);
1065 int notification_ipc_monitor_deregister(void)
1067 if (s_info.initialized == 0) {
1068 return NOTIFICATION_ERROR_NONE;
1071 com_core_packet_client_fini(s_info.server_fd);
1072 s_info.server_fd = NOTIFICATION_ERROR_INVALID_PARAMETER;
1074 s_info.initialized = 0;
1076 return NOTIFICATION_ERROR_NONE;
1079 int notification_ipc_monitor_init(void)
1081 int ret = NOTIFICATION_ERROR_NONE;
1083 if (notification_ipc_is_master_ready()) {
1084 ret = notification_ipc_monitor_register();
1087 if (s_info.is_started_cb_set_svc == 0) {
1088 _set_master_started_cb(_master_started_cb_service);
1089 s_info.is_started_cb_set_svc = 1;
1095 int notification_ipc_monitor_fini(void)
1097 int ret = NOTIFICATION_ERROR_NONE;
1099 if (s_info.is_started_cb_set_svc == 1) {
1100 _unset_master_started_cb(_master_started_cb_service);
1101 s_info.is_started_cb_set_svc = 0;
1104 ret = notification_ipc_monitor_deregister();
1110 * functions to request the service
1112 int notification_ipc_request_insert(notification_h noti, int *priv_id)
1115 int id = NOTIFICATION_PRIV_ID_NONE;
1116 struct packet *packet;
1117 struct packet *result;
1119 /* Initialize private ID */
1120 noti->priv_id = NOTIFICATION_PRIV_ID_NONE;
1121 noti->group_id = NOTIFICATION_GROUP_ID_NONE;
1122 noti->internal_group_id = NOTIFICATION_GROUP_ID_NONE;
1124 packet = notification_ipc_make_packet_from_noti(noti, "add_noti", 1);
1125 result = com_core_packet_oneshot_send(NOTIFICATION_ADDR,
1127 NOTIFICATION_IPC_TIMEOUT);
1128 packet_destroy(packet);
1130 if (result != NULL) {
1131 if (packet_get(result, "ii", &status, &id) != 2) {
1132 NOTIFICATION_ERR("Failed to get a result packet");
1133 packet_unref(result);
1134 return NOTIFICATION_ERROR_IO_ERROR;
1137 if (status != NOTIFICATION_ERROR_NONE) {
1138 packet_unref(result);
1141 packet_unref(result);
1143 NOTIFICATION_ERR("failed to receive answer(insert)");
1144 if (notification_ipc_is_master_ready() == 1) {
1145 return NOTIFICATION_ERROR_PERMISSION_DENIED;
1148 return NOTIFICATION_ERROR_SERVICE_NOT_READY;
1152 if (priv_id != NULL) {
1156 return NOTIFICATION_ERROR_NONE;
1159 int notification_ipc_request_delete_single(notification_type_e type, char *pkgname, int priv_id)
1162 int id = NOTIFICATION_PRIV_ID_NONE;
1163 struct packet *packet;
1164 struct packet *result;
1166 packet = packet_create("del_noti_single", "si", pkgname, priv_id);
1167 result = com_core_packet_oneshot_send(NOTIFICATION_ADDR,
1169 NOTIFICATION_IPC_TIMEOUT);
1170 packet_destroy(packet);
1172 if (result != NULL) {
1173 if (packet_get(result, "ii", &status, &id) != 2) {
1174 NOTIFICATION_ERR("Failed to get a result packet");
1175 packet_unref(result);
1176 return NOTIFICATION_ERROR_IO_ERROR;
1178 packet_unref(result);
1180 NOTIFICATION_ERR("failed to receive answer(delete)");
1181 if (notification_ipc_is_master_ready() == 1) {
1182 return NOTIFICATION_ERROR_PERMISSION_DENIED;
1185 return NOTIFICATION_ERROR_SERVICE_NOT_READY;
1192 int notification_ipc_request_delete_multiple(notification_type_e type, char *pkgname)
1195 int num_deleted = 0;
1196 struct packet *packet;
1197 struct packet *result;
1199 packet = packet_create("del_noti_multiple", "si", pkgname, type);
1200 result = com_core_packet_oneshot_send(NOTIFICATION_ADDR,
1202 NOTIFICATION_IPC_TIMEOUT);
1203 packet_destroy(packet);
1205 if (result != NULL) {
1206 if (packet_get(result, "ii", &status, &num_deleted) != 2) {
1207 NOTIFICATION_ERR("Failed to get a result packet");
1208 packet_unref(result);
1209 return NOTIFICATION_ERROR_IO_ERROR;
1211 NOTIFICATION_ERR("num deleted:%d", num_deleted);
1212 packet_unref(result);
1214 NOTIFICATION_ERR("failed to receive answer(delete multiple)");
1215 if (notification_ipc_is_master_ready() == 1) {
1216 return NOTIFICATION_ERROR_PERMISSION_DENIED;
1219 return NOTIFICATION_ERROR_SERVICE_NOT_READY;
1226 int notification_ipc_request_update(notification_h noti)
1229 int id = NOTIFICATION_PRIV_ID_NONE;
1230 struct packet *packet;
1231 struct packet *result;
1233 packet = notification_ipc_make_packet_from_noti(noti, "update_noti", 1);
1234 result = com_core_packet_oneshot_send(NOTIFICATION_ADDR,
1236 NOTIFICATION_IPC_TIMEOUT);
1237 packet_destroy(packet);
1239 if (result != NULL) {
1240 if (packet_get(result, "ii", &status, &id) != 2) {
1241 NOTIFICATION_ERR("Failed to get a result packet");
1242 packet_unref(result);
1243 return NOTIFICATION_ERROR_IO_ERROR;
1245 packet_unref(result);
1247 NOTIFICATION_ERR("failed to receive answer(update)");
1248 if (notification_ipc_is_master_ready() == 1) {
1249 return NOTIFICATION_ERROR_PERMISSION_DENIED;
1252 return NOTIFICATION_ERROR_SERVICE_NOT_READY;
1259 static int _notification_ipc_update_cb(pid_t pid, int handle, const struct packet *packet, void *data)
1262 int id = NOTIFICATION_PRIV_ID_NONE;
1263 result_cb_item *cb_item = (result_cb_item *)data;
1265 if (cb_item == NULL) {
1266 NOTIFICATION_ERR("Failed to get a callback item");
1267 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1269 s_info.server_cl_fd_ref_cnt = (s_info.server_cl_fd_ref_cnt <= 1) ? 0 : s_info.server_cl_fd_ref_cnt - 1;
1270 if (s_info.server_cl_fd_ref_cnt <= 0) {
1271 NOTIFICATION_DBG("REFCNT: %d (fd: %d)", s_info.server_cl_fd_ref_cnt, s_info.server_cl_fd);
1272 int fd_temp = s_info.server_cl_fd;
1273 s_info.server_cl_fd = -1;
1274 com_core_packet_client_fini(fd_temp);
1275 NOTIFICATION_DBG("FD(%d) finalized", fd_temp);
1278 if (packet != NULL) {
1279 if (packet_get(packet, "ii", &status, &id) != 2) {
1280 NOTIFICATION_ERR("Failed to get a result packet");
1281 status = NOTIFICATION_ERROR_IO_ERROR;
1285 if (cb_item->result_cb != NULL) {
1286 cb_item->result_cb(id, status, cb_item->data);
1293 int notification_ipc_request_update_async(notification_h noti,
1294 void (*result_cb)(int priv_id, int result, void *data), void *user_data)
1296 int ret = NOTIFICATION_ERROR_NONE;
1298 struct packet *packet = NULL;
1299 result_cb_item *cb_item = NULL;
1301 packet = notification_ipc_make_packet_from_noti(noti, "update_noti", 1);
1302 if (packet == NULL) {
1303 ret = NOTIFICATION_ERROR_INVALID_PARAMETER;
1307 cb_item = calloc(1, sizeof(result_cb_item));
1308 if (cb_item == NULL) {
1309 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
1313 if (s_info.server_cl_fd < 0) {
1314 com_core_packet_use_thread(1);
1315 s_info.server_cl_fd = com_core_packet_client_init(s_info.socket_file, 0, NULL);
1316 if (s_info.server_cl_fd < 0) {
1317 NOTIFICATION_DBG("Failed to init client: %d", s_info.server_cl_fd);
1318 if (notification_ipc_is_master_ready() == 1) {
1319 ret = NOTIFICATION_ERROR_PERMISSION_DENIED;
1322 ret = NOTIFICATION_ERROR_SERVICE_NOT_READY;
1326 s_info.server_cl_fd_ref_cnt = 1;
1328 s_info.server_cl_fd_ref_cnt++;
1331 cb_item->result_cb = result_cb;
1332 cb_item->data = user_data;
1334 NOTIFICATION_INFO("Connection count:%d, fd:%d", s_info.server_cl_fd_ref_cnt, s_info.server_cl_fd);
1336 ret_con = com_core_packet_async_send(s_info.server_cl_fd, packet, 0.0f,
1337 _notification_ipc_update_cb, cb_item);
1339 NOTIFICATION_ERR("Failed to request update, %d\n", ret_con);
1340 s_info.server_cl_fd_ref_cnt = (s_info.server_cl_fd_ref_cnt <= 1) ? 0 : s_info.server_cl_fd_ref_cnt - 1;
1341 if (s_info.server_cl_fd_ref_cnt <= 0) {
1342 int fd_temp = s_info.server_cl_fd;
1343 s_info.server_cl_fd = -1;
1344 com_core_packet_client_fini(fd_temp);
1345 NOTIFICATION_INFO("FD(%d) finalized", fd_temp);
1347 ret = NOTIFICATION_ERROR_IO_ERROR;
1350 ret = NOTIFICATION_ERROR_NONE;
1355 if (cb_item) free(cb_item);
1356 NOTIFICATION_ERR("Err: %d\n", ret);
1359 if (packet) packet_destroy(packet);
1364 int notification_ipc_request_refresh(void)
1367 struct packet *packet;
1368 struct packet *result;
1370 packet = packet_create("refresh_noti", "i", NOTIFICATION_OP_REFRESH);
1371 result = com_core_packet_oneshot_send(NOTIFICATION_ADDR,
1373 NOTIFICATION_IPC_TIMEOUT);
1374 packet_destroy(packet);
1376 if (result != NULL) {
1377 if (packet_get(result, "i", &status) != 1) {
1378 NOTIFICATION_ERR("Failed to get a result packet");
1379 packet_unref(result);
1380 return NOTIFICATION_ERROR_IO_ERROR;
1382 packet_unref(result);
1384 NOTIFICATION_ERR("failed to receive answer(refresh)");
1385 if (notification_ipc_is_master_ready() == 1) {
1386 return NOTIFICATION_ERROR_PERMISSION_DENIED;
1389 return NOTIFICATION_ERROR_SERVICE_NOT_READY;
1396 int notification_ipc_noti_setting_property_set(const char *pkgname, const char *property, const char *value)
1400 struct packet *packet;
1401 struct packet *result;
1403 packet = packet_create("set_noti_property", "sss", pkgname, property, value);
1404 result = com_core_packet_oneshot_send(NOTIFICATION_ADDR,
1406 NOTIFICATION_IPC_TIMEOUT);
1407 packet_destroy(packet);
1409 if (result != NULL) {
1410 if (packet_get(result, "ii", &status, &ret) != 2) {
1411 NOTIFICATION_ERR("Failed to get a result packet");
1412 packet_unref(result);
1413 return NOTIFICATION_ERROR_IO_ERROR;
1415 packet_unref(result);
1417 NOTIFICATION_ERR("failed to receive answer(delete)");
1418 if (notification_ipc_is_master_ready() == 1) {
1419 return NOTIFICATION_ERROR_PERMISSION_DENIED;
1422 return NOTIFICATION_ERROR_SERVICE_NOT_READY;
1429 int notification_ipc_noti_setting_property_get(const char *pkgname, const char *property, char **value)
1433 struct packet *packet;
1434 struct packet *result;
1436 packet = packet_create("get_noti_property", "ss", pkgname, property);
1437 result = com_core_packet_oneshot_send(NOTIFICATION_ADDR,
1439 NOTIFICATION_IPC_TIMEOUT);
1440 packet_destroy(packet);
1442 if (result != NULL) {
1443 if (packet_get(result, "is", &status, &ret) != 2) {
1444 NOTIFICATION_ERR("Failed to get a result packet");
1445 packet_unref(result);
1446 return NOTIFICATION_ERROR_IO_ERROR;
1448 if (status == NOTIFICATION_ERROR_NONE && ret != NULL) {
1449 *value = strdup(ret);
1451 packet_unref(result);
1453 NOTIFICATION_ERR("failed to receive answer(delete)");
1454 if (notification_ipc_is_master_ready() == 1) {
1455 return NOTIFICATION_ERROR_PERMISSION_DENIED;
1458 return NOTIFICATION_ERROR_SERVICE_NOT_READY;
1465 int notification_ipc_request_load_noti_by_tag(notification_h noti, const char *pkgname, const char *tag)
1467 struct packet *packet;
1468 struct packet *result;
1470 packet = packet_create("load_noti_by_tag", "ss", pkgname, tag);
1471 result = com_core_packet_oneshot_send(NOTIFICATION_ADDR,
1473 NOTIFICATION_IPC_TIMEOUT);
1474 packet_destroy(packet);
1476 if (result != NULL) {
1477 if (notification_ipc_make_noti_from_packet(noti, result) != NOTIFICATION_ERROR_NONE) {
1478 NOTIFICATION_ERR("Failed to get a result packet");
1479 packet_unref(result);
1480 return NOTIFICATION_ERROR_IO_ERROR;
1483 packet_unref(result);
1485 NOTIFICATION_ERR("failed to receive answer(load noti by tag)");
1486 if (notification_ipc_is_master_ready() == 1) {
1487 return NOTIFICATION_ERROR_PERMISSION_DENIED;
1490 return NOTIFICATION_ERROR_SERVICE_NOT_READY;
1494 return NOTIFICATION_ERROR_NONE;