e1e035ec36b943b5dcb8616cff120a636974284f
[platform/core/api/notification.git] / src / notification_ipc.c
1 /*
2  * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <stdio.h>
18 #include <string.h>
19 #include <stdlib.h>
20 #include <errno.h>
21 #include <vconf.h>
22 #include <bundle_internal.h>
23
24 #include <notification_ipc.h>
25 #include <notification_db.h>
26 #include <notification_type.h>
27 #include <notification_private.h>
28 #include <notification_debug.h>
29 #include <notification_setting.h>
30 #include <notification_setting_internal.h>
31 #include <notification_internal.h>
32
33 #include <gio/gio.h>
34
35 #define PROVIDER_BUS_NAME "org.tizen.data_provider_service"
36 #define PROVIDER_OBJECT_PATH "/org/tizen/data_provider_service"
37 #define PROVIDER_NOTI_INTERFACE_NAME "org.tizen.data_provider_noti_service"
38
39 #define DBUS_SERVICE_DBUS "org.freedesktop.DBus"
40 #define DBUS_PATH_DBUS "/org/freedesktop/DBus"
41 #define DBUS_INTERFACE_DBUS "org.freedesktop.DBus"
42 #define ERR_BUFFER_SIZE         1024
43
44 static const gchar *_bus_name = NULL;
45 static GDBusConnection *_gdbus_conn = NULL;
46 static int monitor_id = 0;
47 static int provider_monitor_id = 0;
48 static int is_master_started = 0;
49
50 typedef struct _result_cb_item {
51         void (*result_cb)(int priv_id, int result, void *data);
52         void *data;
53 } result_cb_item;
54
55 typedef struct _task_list task_list;
56 struct _task_list {
57         task_list *prev;
58         task_list *next;
59
60         void (*task_cb) (void *data);
61         void *data;
62 };
63
64 static task_list *g_task_list;
65
66 static int _ipc_monitor_register(void);
67 static int _ipc_monitor_deregister(void);
68 static void _do_deffered_task(void);
69
70 static void _print_noti(notification_h noti)
71 {
72         char *pkgname = NULL;
73         char *text = NULL;
74         char *content = NULL;
75         const char *tag = NULL;
76         notification_vibration_type_e vib_type = NOTIFICATION_VIBRATION_TYPE_NONE;
77
78         notification_get_pkgname(noti, &pkgname);
79         notification_get_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, &text);
80         notification_get_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, &content);
81         notification_get_tag(noti, &tag);
82         notification_get_vibration(noti, &vib_type, NULL);
83
84         NOTIFICATION_DBG("client print_noti  pkgname  = %s ", pkgname);
85         NOTIFICATION_DBG("client print_noti  title  = %s ", text);
86         NOTIFICATION_DBG("client print_noti  content  = %s ", content);
87         NOTIFICATION_DBG("client print_noti  tag  = %s ", tag);
88         NOTIFICATION_DBG("client print_noti  priv_id  = %d ", noti->priv_id);
89         NOTIFICATION_DBG("client print_noti  vibration_path  = %s ", noti->vibration_path);
90         NOTIFICATION_DBG("client print_noti  vibration_type  = %d ", vib_type);
91 }
92
93 static inline char *_string_get(char *string)
94 {
95         if (string == NULL)
96                 return NULL;
97
98         if (string[0] == '\0')
99                 return NULL;
100
101         return string;
102 }
103
104 static int _dbus_init()
105 {
106         int ret = NOTIFICATION_ERROR_NONE;
107         GError *error = NULL;
108
109         if (_gdbus_conn == NULL) {
110                 _gdbus_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
111
112                 if (_gdbus_conn == NULL) {
113                         if (error != NULL) {
114                                 NOTIFICATION_ERR("Failed to get dbus [%s]", error->message);
115                                 g_error_free(error);
116                         }
117                         return NOTIFICATION_ERROR_IO_ERROR;
118                 }
119                 _bus_name = g_dbus_connection_get_unique_name(_gdbus_conn);
120                 NOTIFICATION_DBG("bus name : %s", _bus_name);
121
122                 notification_error_quark();
123
124                 ret = NOTIFICATION_ERROR_NONE;
125         }
126         return ret;
127 }
128
129 int notification_ipc_is_master_ready(void)
130 {
131         GVariant *result;
132         GError *err = NULL;
133         gboolean name_exist;
134         int ret = NOTIFICATION_ERROR_NONE;
135
136         ret = _dbus_init();
137         if (ret != NOTIFICATION_ERROR_NONE) {
138                 NOTIFICATION_ERR("Can't init dbus %d", ret);
139                 is_master_started = 0;
140                 return is_master_started;
141         }
142
143         result = g_dbus_connection_call_sync(
144                         _gdbus_conn,
145                         DBUS_SERVICE_DBUS,
146                         DBUS_PATH_DBUS,
147                         DBUS_INTERFACE_DBUS,
148                         "NameHasOwner",
149                         g_variant_new("(s)", PROVIDER_BUS_NAME),
150                         G_VARIANT_TYPE("(b)"),
151                         G_DBUS_CALL_FLAGS_NONE,
152                         -1,
153                         NULL,
154                         &err);
155
156         if (err || (result == NULL)) {
157                 if (err) {
158                         NOTIFICATION_ERR("No reply. error = %s", err->message);
159                         g_error_free(err);
160                 }
161                 NOTIFICATION_ERR("is master ready fail");
162                 is_master_started = 0;
163         } else {
164                 g_variant_get(result, "(b)", &name_exist);
165
166                 if (!name_exist) {
167                         NOTIFICATION_ERR("Name not exist %s", PROVIDER_BUS_NAME);
168                         NOTIFICATION_ERR("the master has been stopped");
169                         is_master_started = 0;
170                 } else {
171                         NOTIFICATION_DBG("the master has been started");
172                         is_master_started = 1;
173                 }
174         }
175
176         if (result)
177                 g_variant_unref(result);
178
179         return is_master_started;
180 }
181
182 /* TODO: dbus activation isn't enough ? */
183 /*
184  * store tasks when daemon stopped
185  */
186 int notification_ipc_add_deffered_task(
187                 void (*deferred_task_cb)(void *data),
188                 void *user_data)
189 {
190         task_list *list;
191         task_list *list_new;
192
193         list_new =
194             (task_list *) malloc(sizeof(task_list));
195
196         if (list_new == NULL)
197                 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
198
199         list_new->next = NULL;
200         list_new->prev = NULL;
201
202         list_new->task_cb = deferred_task_cb;
203         list_new->data = user_data;
204
205         if (g_task_list == NULL) {
206                 g_task_list = list_new;
207         } else {
208                 list = g_task_list;
209
210                 while (list->next != NULL)
211                         list = list->next;
212
213                 list->next = list_new;
214                 list_new->prev = list;
215         }
216         return NOTIFICATION_ERROR_NONE;
217 }
218
219 int notification_ipc_del_deffered_task(
220                 void (*deferred_task_cb)(void *data))
221 {
222         task_list *list_del;
223         task_list *list_prev;
224         task_list *list_next;
225
226         list_del = g_task_list;
227
228         if (list_del == NULL)
229                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
230
231         while (list_del->prev != NULL)
232                 list_del = list_del->prev;
233
234         do {
235                 if (list_del->task_cb == deferred_task_cb) {
236                         list_prev = list_del->prev;
237                         list_next = list_del->next;
238
239                         if (list_prev == NULL)
240                                 g_task_list = list_next;
241                         else
242                                 list_prev->next = list_next;
243
244                         if (list_next == NULL) {
245                                 if (list_prev != NULL)
246                                         list_prev->next = NULL;
247                         } else {
248                                 list_next->prev = list_prev;
249                         }
250
251                         free(list_del);
252                         return NOTIFICATION_ERROR_NONE;
253                 }
254                 list_del = list_del->next;
255         } while (list_del != NULL);
256
257         return NOTIFICATION_ERROR_INVALID_PARAMETER;
258 }
259
260 static void _do_deffered_task(void)
261 {
262         task_list *list_do;
263         task_list *list_temp;
264
265         if (g_task_list == NULL)
266                 return;
267
268         list_do = g_task_list;
269         g_task_list = NULL;
270
271         while (list_do->prev != NULL)
272                 list_do = list_do->prev;
273
274         while (list_do != NULL) {
275                 if (list_do->task_cb != NULL) {
276                         list_do->task_cb(list_do->data);
277                         NOTIFICATION_DBG("called:%p", list_do->task_cb);
278                 }
279                 list_temp = list_do->next;
280                 free(list_do);
281                 list_do = list_temp;
282         }
283 }
284
285 /*!
286  * functions to create operation list
287  */
288 static notification_op *_ipc_create_op(notification_op_type_e type,
289                 int num_op, int *list_priv_id, int num_priv_id, notification_h *noti_list)
290 {
291         int i;
292         notification_op *op_list;
293
294         if (num_op <= 0)
295                 return NULL;
296
297         op_list = (notification_op *)malloc(sizeof(notification_op) * num_op);
298
299         if (op_list == NULL) {
300                 NOTIFICATION_ERR("malloc failed");
301                 return NULL;
302         }
303
304         memset(op_list, 0x0, sizeof(notification_op) * num_op);
305
306         for (i = 0; i < num_op; i++) {
307                 (op_list + i)->type = type;
308                 if (list_priv_id != NULL)
309                         (op_list + i)->priv_id = *(list_priv_id + i);
310                 if (noti_list != NULL)
311                         (op_list + i)->noti = *(noti_list + i);
312         }
313
314         return op_list;
315 }
316
317 /*!
318  * utility functions creating notification packet
319  */
320 static inline char *_dup_string(const char *string)
321 {
322         char *ret;
323         char err_buf[ERR_BUFFER_SIZE];
324
325         if (string == NULL)
326                 return NULL;
327         if (string[0] == '\0')
328                 return NULL;
329
330         ret = strdup(string);
331         if (!ret)
332                 NOTIFICATION_ERR("Error: %s\n", strerror_r(errno, err_buf, sizeof(err_buf)));
333
334         return ret;
335 }
336
337 static inline bundle *_create_bundle_from_bundle_raw(bundle_raw *string)
338 {
339         if (string == NULL)
340                 return NULL;
341         if (string[0] == '\0')
342                 return NULL;
343
344         return bundle_decode(string, strlen((char *)string));
345 }
346
347 static void _add_noti_notify(GVariant *parameters)
348 {
349         notification_h noti;
350         notification_op *noti_op;
351         GVariant *body = NULL;
352
353         NOTIFICATION_DBG("add noti notify");
354         noti = notification_create(NOTIFICATION_TYPE_NOTI);
355         if (!noti) {
356                 NOTIFICATION_ERR("failed to create a notification");
357                 return;
358         }
359
360         g_variant_get(parameters, "(v)", &body);
361         notification_ipc_make_noti_from_gvariant(noti, body);
362         _print_noti(noti);
363         if (noti->flags_for_property & NOTIFICATION_PROP_DISABLE_UPDATE_ON_INSERT) {
364                 NOTIFICATION_ERR("disable changed callback %d", noti->flags_for_property);
365                 /* Disable changed cb */
366         } else {
367                 /* Enable changed cb */
368                 noti_op = _ipc_create_op(NOTIFICATION_OP_INSERT, 1, &(noti->priv_id), 1, &noti);
369
370                 if (noti_op != NULL) {
371                         notification_call_changed_cb(noti_op, 1);
372                         free(noti_op);
373                 }
374         }
375         notification_free(noti);
376 }
377
378 static void _update_noti_notify(GVariant *parameters)
379 {
380         notification_h noti;
381         notification_op *noti_op;
382         GVariant *body = NULL;
383
384         noti = notification_create(NOTIFICATION_TYPE_NOTI);
385         if (!noti) {
386                 NOTIFICATION_ERR("failed to create a notification");
387                 return;
388         }
389         g_variant_get(parameters, "(v)", &body);
390         notification_ipc_make_noti_from_gvariant(noti, body);
391         _print_noti(noti);
392
393         noti_op = _ipc_create_op(NOTIFICATION_OP_UPDATE, 1, &(noti->priv_id), 1, &noti);
394         if (noti_op != NULL) {
395                 notification_call_changed_cb(noti_op, 1);
396                 free(noti_op);
397         }
398         notification_free(noti);
399 }
400
401 static void _refresh_noti_notify(GVariant *parameters)
402 {
403         notification_op *noti_op = _ipc_create_op(NOTIFICATION_OP_REFRESH, 1, NULL, 0, NULL);
404
405         if (noti_op != NULL) {
406                 notification_call_changed_cb(noti_op, 1);
407                 free(noti_op);
408         }
409 }
410
411 static void _delete_single_notify(GVariant *parameters)
412 {
413         int num_deleted;
414         int priv_id;
415         notification_op *noti_op;
416
417         /* num_deleted ?? */
418         g_variant_get(parameters, "(ii)", &num_deleted, &priv_id);
419
420         noti_op = _ipc_create_op(NOTIFICATION_OP_DELETE, 1, &priv_id, 1, NULL);
421         if (noti_op != NULL) {
422                 notification_call_changed_cb(noti_op, 1);
423                 free(noti_op);
424         }
425 }
426
427 static void _delete_multiple_notify(GVariant *parameters)
428 {
429         int buf[100] = {0,};
430         int idx = 0;
431         notification_op *noti_op;
432         GVariantIter *iter;
433
434         g_variant_get(parameters, "(a(i))", &iter);
435         while (g_variant_iter_loop(iter, "(i)", &buf[idx])) {
436                 NOTIFICATION_DBG("delete_noti_multiple priv_id : %d", buf[idx]);
437                 idx++;
438         }
439         g_variant_iter_free(iter);
440
441         NOTIFICATION_DBG("data num deleted:%d", idx);
442         noti_op = _ipc_create_op(NOTIFICATION_OP_DELETE, idx, buf, idx, NULL);
443
444         if (noti_op == NULL) {
445                 NOTIFICATION_ERR("_ipc_create_op failed");
446                 return;
447         }
448         notification_call_changed_cb(noti_op, idx);
449         free(noti_op);
450 }
451
452 static void _handle_noti_notify(GDBusConnection *connection,
453                 const gchar     *sender_name,
454                 const gchar     *object_path,
455                 const gchar     *interface_name,
456                 const gchar     *signal_name,
457                 GVariant        *parameters,
458                 gpointer         user_data)
459 {
460         NOTIFICATION_DBG("signal_name: %s", signal_name);
461
462         if (g_strcmp0(signal_name, "add_noti_notify") == 0)
463                 _add_noti_notify(parameters);
464         else if (g_strcmp0(signal_name, "update_noti_notify") == 0)
465                 _update_noti_notify(parameters);
466         else if (g_strcmp0(signal_name, "delete_single_notify") == 0)
467                 _delete_single_notify(parameters);
468         else if (g_strcmp0(signal_name, "delete_multiple_notify") == 0)
469                 _delete_multiple_notify(parameters);
470         else if (g_strcmp0(signal_name, "refresh_noti_notify") == 0)
471                 _refresh_noti_notify(parameters);
472 }
473
474
475 static int _dbus_signal_init()
476 {
477         int id;
478         int ret = NOTIFICATION_ERROR_NONE;
479
480         if (monitor_id == 0) {
481                 id = g_dbus_connection_signal_subscribe(_gdbus_conn,
482                                 PROVIDER_BUS_NAME,
483                                 PROVIDER_NOTI_INTERFACE_NAME,   /*      interface */
484                                 NULL,                           /*      member */
485                                 PROVIDER_OBJECT_PATH,           /*      path */
486                                 NULL,                           /*      arg0 */
487                                 G_DBUS_SIGNAL_FLAGS_NONE,
488                                 _handle_noti_notify,
489                                 NULL,
490                                 NULL);
491
492                 NOTIFICATION_DBG("subscribe id : %d", id);
493                 if (id == 0) {
494                         ret = NOTIFICATION_ERROR_IO_ERROR;
495                         NOTIFICATION_ERR("Failed to _register_noti_dbus_interface");
496                 } else {
497                         monitor_id = id;
498                         ret = NOTIFICATION_ERROR_NONE;
499                 }
500         }
501         return ret;
502 }
503
504 static int _send_sync_noti(GVariant *body, GDBusMessage **reply, char *cmd)
505 {
506         int ret = NOTIFICATION_ERROR_NONE;
507         GError *err = NULL;
508         GDBusMessage *msg;
509
510         msg = g_dbus_message_new_method_call(
511                         PROVIDER_BUS_NAME,
512                         PROVIDER_OBJECT_PATH,
513                         PROVIDER_NOTI_INTERFACE_NAME,
514                         cmd);
515         if (!msg) {
516                 NOTIFICATION_ERR("Can't allocate new method call");
517                 if (body)
518                         g_variant_unref(body);
519                 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
520         }
521
522         if (body != NULL)
523                 g_dbus_message_set_body(msg, body);
524
525         *reply = g_dbus_connection_send_message_with_reply_sync(
526                         _gdbus_conn,
527                         msg,
528                         G_DBUS_SEND_MESSAGE_FLAGS_NONE,
529                         -1,
530                         NULL,
531                         NULL,
532                         &err);
533
534         g_object_unref(msg);
535
536         if (!*reply) {
537                 ret = NOTIFICATION_ERROR_SERVICE_NOT_READY;
538                 if (err != NULL) {
539                         NOTIFICATION_ERR("No reply. cmd = %s,  error = %s", cmd, err->message);
540                         if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
541                                 ret = NOTIFICATION_ERROR_PERMISSION_DENIED;
542                         g_error_free(err);
543                 }
544                 return ret;
545         }
546
547         if (g_dbus_message_to_gerror(*reply, &err)) {
548                 if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
549                         ret = NOTIFICATION_ERROR_PERMISSION_DENIED;
550                 else
551                         ret = err->code;
552
553                 NOTIFICATION_ERR("_send_sync_noti cmd = %s, error %s, err code %d", cmd, err->message, ret);
554                 g_error_free(err);
555                 return ret;
556         }
557         NOTIFICATION_DBG("_send_sync_noti done !!");
558         return NOTIFICATION_ERROR_NONE;
559
560 }
561
562 static void _send_message_with_reply_async_cb(GDBusConnection *connection,
563                 GAsyncResult *res,
564                 gpointer user_data)
565 {
566         GVariant *body;
567         int result = NOTIFICATION_ERROR_NONE;
568         int priv_id;
569         GDBusMessage *reply = NULL;
570         GError *err = NULL;
571         result_cb_item *cb_item = (result_cb_item *)user_data;
572
573         if (cb_item == NULL) {
574                 NOTIFICATION_ERR("Failed to get a callback item");
575                 return;
576         }
577
578         reply = g_dbus_connection_send_message_with_reply_finish(
579                         connection,
580                         res,
581                         &err);
582
583         if (!reply) {
584                 if (err != NULL) {
585                         NOTIFICATION_ERR("No reply. error = %s", err->message);
586                         g_error_free(err);
587                 }
588                 result = NOTIFICATION_ERROR_SERVICE_NOT_READY;
589
590         } else if (g_dbus_message_to_gerror(reply, &err)) {
591                 if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
592                         result = NOTIFICATION_ERROR_PERMISSION_DENIED;
593                 else
594                         result = err->code;
595
596                 NOTIFICATION_ERR("_send_async_noti error %s", err->message);
597                 g_error_free(err);
598         }
599
600         NOTIFICATION_DBG("_send_async_noti done !![%d]", result);
601
602         if (result == NOTIFICATION_ERROR_NONE) {
603                 body = g_dbus_message_get_body(reply);
604                 g_variant_get(body, "(i)", &priv_id);
605
606                 if (cb_item->result_cb)
607                         cb_item->result_cb(priv_id, result, cb_item->data);
608
609         } else {
610                 if (cb_item->result_cb)
611                         cb_item->result_cb(NOTIFICATION_PRIV_ID_NONE, result, cb_item->data);
612         }
613
614         if (reply)
615                 g_object_unref(reply);
616         free(cb_item);
617 }
618
619 static int _send_async_noti(GVariant *body, result_cb_item *cb_item, char *cmd)
620 {
621         GDBusMessage *msg;
622
623         msg = g_dbus_message_new_method_call(
624                         PROVIDER_BUS_NAME,
625                         PROVIDER_OBJECT_PATH,
626                         PROVIDER_NOTI_INTERFACE_NAME,
627                         cmd);
628         if (!msg) {
629                 NOTIFICATION_ERR("Can't allocate new method call");
630                 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
631         }
632
633         if (body != NULL)
634                 g_dbus_message_set_body(msg, body);
635
636         g_dbus_connection_send_message_with_reply(
637                         _gdbus_conn,
638                         msg,
639                         G_DBUS_SEND_MESSAGE_FLAGS_NONE,
640                         -1,
641                         NULL,
642                         NULL,
643                         (GAsyncReadyCallback)_send_message_with_reply_async_cb,
644                         cb_item);
645
646         NOTIFICATION_DBG("_send_async_noti done !!");
647
648         g_object_unref(msg);
649         return NOTIFICATION_ERROR_NONE;
650 }
651
652 int notification_ipc_request_insert(notification_h noti, int *priv_id)
653 {
654         int result;
655         int id = NOTIFICATION_PRIV_ID_NONE;
656         GDBusMessage *reply = NULL;
657         GVariant *body;
658         GVariant *reply_body;
659
660         result = _dbus_init();
661         if (result != NOTIFICATION_ERROR_NONE) {
662                 NOTIFICATION_ERR("Can't init dbus %d", result);
663                 return result;
664         }
665
666         /* Initialize private ID */
667         noti->priv_id = NOTIFICATION_PRIV_ID_NONE;
668         noti->group_id = NOTIFICATION_GROUP_ID_NONE;
669         noti->internal_group_id = NOTIFICATION_GROUP_ID_NONE;
670
671         _print_noti(noti);
672         body = notification_ipc_make_gvariant_from_noti(noti, false);
673         if (body == NULL) {
674                 NOTIFICATION_ERR("cannot make gvariant");
675                 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
676         }
677
678         result = _send_sync_noti(body, &reply, "add_noti");
679         NOTIFICATION_DBG("_send_sync_noti %d", result);
680
681         if (result == NOTIFICATION_ERROR_NONE) {
682                 reply_body = g_dbus_message_get_body(reply);
683                 g_variant_get(reply_body, "(i)", &id);
684
685                 if (priv_id != NULL)
686                         *priv_id = id;
687         }
688
689         if (reply)
690                 g_object_unref(reply);
691
692         NOTIFICATION_DBG("notification_ipc_request_insert done [priv_id : %d, result: %d]", id, result);
693         return result;
694 }
695
696 int notification_ipc_request_update(notification_h noti)
697 {
698         int result;
699         int priv_id = NOTIFICATION_PRIV_ID_NONE;
700
701         GDBusMessage *reply = NULL;
702         GVariant *body;
703         GVariant *reply_body;
704
705         result = _dbus_init();
706         if (result != NOTIFICATION_ERROR_NONE) {
707                 NOTIFICATION_ERR("Can't init dbus %d", result);
708                 return result;
709         }
710
711         body = notification_ipc_make_gvariant_from_noti(noti, false);
712         if (body == NULL) {
713                 NOTIFICATION_ERR("cannot make gvariant");
714                 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
715         }
716
717         result = _send_sync_noti(body, &reply, "update_noti");
718         if (result == NOTIFICATION_ERROR_NONE) {
719                 reply_body = g_dbus_message_get_body(reply);
720                 g_variant_get(reply_body, "(i)", &priv_id);
721         }
722
723         if (reply)
724                 g_object_unref(reply);
725
726         NOTIFICATION_DBG("notification_ipc_request_update done [result: %d, priv_id :%d]", result, priv_id);
727         return result;
728 }
729
730 int notification_ipc_request_update_async(notification_h noti,
731                 void (*result_cb)(int priv_id, int result, void *data), void *user_data)
732 {
733         int result;
734         result_cb_item *cb_item;
735         GVariant *body;
736
737         result = _dbus_init();
738         if (result != NOTIFICATION_ERROR_NONE) {
739                 NOTIFICATION_ERR("Can't init dbus %d", result);
740                 return result;
741         }
742
743         cb_item = calloc(1, sizeof(result_cb_item));
744         if (cb_item == NULL)
745                 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
746
747         cb_item->result_cb = result_cb;
748         cb_item->data = user_data;
749
750         body = notification_ipc_make_gvariant_from_noti(noti, false);
751         if (body == NULL) {
752                 NOTIFICATION_ERR("cannot make gvariant");
753                 free(cb_item);
754                 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
755         }
756
757         result = _send_async_noti(body, cb_item, "update_noti");
758         NOTIFICATION_DBG("notification_ipc_request_update_async done [result: %d]", result);
759
760         if (result != NOTIFICATION_ERROR_NONE) {
761                 free(cb_item);
762                 cb_item = NULL;
763         }
764
765         g_variant_unref(body);
766
767         return result;
768 }
769
770 int notification_ipc_request_refresh(void)
771 {
772         int result;
773         GDBusMessage *reply = NULL;
774         GVariant *body;
775
776         result = _dbus_init();
777         if (result != NOTIFICATION_ERROR_NONE) {
778                 NOTIFICATION_ERR("Can't init dbus %d", result);
779                 return result;
780         }
781
782         body = g_variant_new("(i)", NOTIFICATION_OP_REFRESH);
783         result = _send_sync_noti(body, &reply, "refresh_noti");
784
785         if (reply)
786                 g_object_unref(reply);
787
788         NOTIFICATION_ERR("notification_ipc_request_refresh done [result: %d]", result);
789         return result;
790 }
791
792 int notification_ipc_request_delete_single(notification_type_e type, char *pkgname, int priv_id)
793 {
794         int result;
795         int id;
796         GDBusMessage *reply = NULL;
797         GVariant *body;
798         GVariant *reply_body;
799
800         result = _dbus_init();
801         if (result != NOTIFICATION_ERROR_NONE) {
802                 NOTIFICATION_ERR("Can't init dbus %d", result);
803                 return result;
804         }
805
806         body = g_variant_new("(si)", pkgname, priv_id);
807         result = _send_sync_noti(body, &reply, "del_noti_single");
808
809         if (result == NOTIFICATION_ERROR_NONE) {
810                 reply_body = g_dbus_message_get_body(reply);
811                 g_variant_get(reply_body, "(i)", &id);
812         }
813
814         if (reply)
815                 g_object_unref(reply);
816
817         NOTIFICATION_ERR("notification_ipc_request_delete_single done [result: %d]", result);
818         return result;
819 }
820
821 int notification_ipc_request_delete_multiple(notification_type_e type, char *pkgname)
822 {
823         int result;
824         int num_deleted;
825         GVariant *body;
826         GVariant *reply_body;
827         GDBusMessage *reply = NULL;
828
829         result = _dbus_init();
830         if (result != NOTIFICATION_ERROR_NONE) {
831                 NOTIFICATION_ERR("Can't init dbus %d", result);
832                 return result;
833         }
834
835         if (!pkgname)
836                 pkgname = "";
837
838         body = g_variant_new("(si)", pkgname, type);
839         result = _send_sync_noti(body, &reply, "del_noti_multiple");
840
841         if (result == NOTIFICATION_ERROR_NONE) {
842                 reply_body = g_dbus_message_get_body(reply);
843                 g_variant_get(reply_body, "(i)", &num_deleted);
844                 NOTIFICATION_ERR("num deleted:%d", num_deleted);
845         }
846
847         if (reply)
848                 g_object_unref(reply);
849
850         return result;
851 }
852
853 int notification_ipc_request_load_noti_by_tag(notification_h noti, const char *pkgname, const char *tag)
854 {
855         int result;
856         GDBusMessage *reply = NULL;
857         GVariant *body;
858         GVariant *reply_body;
859         GVariant *noti_body;
860
861         result = _dbus_init();
862         if (result != NOTIFICATION_ERROR_NONE) {
863                 NOTIFICATION_ERR("Can't init dbus %d", result);
864                 return result;
865         }
866
867         if (!pkgname)
868                 pkgname = "";
869
870         body = g_variant_new("(ss)", pkgname, tag);
871         result = _send_sync_noti(body, &reply, "load_noti_by_tag");
872
873         if (result == NOTIFICATION_ERROR_NONE) {
874                 reply_body = g_dbus_message_get_body(reply);
875                 g_variant_get(reply_body, "(v)", &noti_body);
876
877                 notification_ipc_make_noti_from_gvariant(noti, noti_body);
878                 g_variant_unref(noti_body);
879                 _print_noti(noti);
880
881         }
882
883         if (reply)
884                 g_object_unref(reply);
885
886         NOTIFICATION_DBG("notification_ipc_request_load_noti_by_tag done [result: %d]", result);
887         return result;
888 }
889
890 int notification_ipc_request_load_noti_by_priv_id(notification_h noti, const char *pkgname, int priv_id)
891 {
892         int result;
893         GDBusMessage *reply = NULL;
894         GVariant *body;
895         GVariant *reply_body;
896         GVariant *noti_body;
897
898         result = _dbus_init();
899         if (result != NOTIFICATION_ERROR_NONE) {
900                 NOTIFICATION_ERR("Can't init dbus %d", result);
901                 return result;
902         }
903
904         if (!pkgname)
905                 pkgname = "";
906
907         body = g_variant_new("(si)", pkgname, priv_id);
908         result = _send_sync_noti(body, &reply, "load_noti_by_priv_id");
909
910         if (result == NOTIFICATION_ERROR_NONE) {
911                 reply_body = g_dbus_message_get_body(reply);
912                 g_variant_get(reply_body, "(v)", &noti_body);
913
914                 notification_ipc_make_noti_from_gvariant(noti, noti_body);
915                 g_variant_unref(noti_body);
916                 _print_noti(noti);
917         }
918
919         if (reply)
920                 g_object_unref(reply);
921
922         NOTIFICATION_DBG("notification_ipc_request_load_noti_by_priv_id done [result: %d]", result);
923         return result;
924 }
925
926 int notification_ipc_request_get_count(notification_type_e type,
927                     const char *pkgname, int group_id, int priv_id, int *count)
928 {
929         int result;
930         GDBusMessage *reply = NULL;
931         GVariant *body;
932         GVariant *reply_body;
933         int re_count;
934
935         result = _dbus_init();
936         if (result != NOTIFICATION_ERROR_NONE) {
937                 NOTIFICATION_ERR("Can't init dbus %d", result);
938                 return result;
939         }
940
941         if (!pkgname)
942                 pkgname = "";
943
944         body = g_variant_new("(isii)", type, pkgname, group_id, priv_id);
945         result = _send_sync_noti(body, &reply, "get_noti_count");
946
947         if (result == NOTIFICATION_ERROR_NONE) {
948                 reply_body = g_dbus_message_get_body(reply);
949                 g_variant_get(reply_body, "(i)", &re_count);
950
951                 *count = re_count;
952                 NOTIFICATION_DBG("noti count [%d]", re_count);
953         }
954
955         if (reply)
956                 g_object_unref(reply);
957
958         NOTIFICATION_DBG("notification_ipc_request_get_count done [result: %d]", result);
959         return result;
960 }
961
962 int notification_ipc_request_load_noti_grouping_list(notification_type_e type, int count,
963                 notification_list_h *list)
964 {
965         int result;
966         GDBusMessage *reply = NULL;
967         GVariant *body;
968         GVariant *reply_body;
969         GVariant *iter_body;
970         GVariantIter *iter;
971         notification_h noti;
972         GVariant *noti_body;
973
974         result = _dbus_init();
975         if (result != NOTIFICATION_ERROR_NONE) {
976                 NOTIFICATION_ERR("Can't init dbus %d", result);
977                 return result;
978         }
979
980         body = g_variant_new("(ii)", type, count);
981         result = _send_sync_noti(body, &reply, "load_noti_grouping_list");
982
983         if (result == NOTIFICATION_ERROR_NONE) {
984                 reply_body = g_dbus_message_get_body(reply);
985                 g_variant_get(reply_body, "(a(v))", &iter);
986
987                 while (g_variant_iter_loop(iter, "(v)", &iter_body)) {
988                         noti = notification_create(NOTIFICATION_TYPE_NOTI);
989                         g_variant_get(iter_body, "(v)", &noti_body);
990                         notification_ipc_make_noti_from_gvariant(noti, noti_body);
991                         _print_noti(noti);
992                         *list = notification_list_append(*list, noti);
993                 }
994                 g_variant_iter_free(iter);
995         }
996
997         if (reply)
998                 g_object_unref(reply);
999
1000         NOTIFICATION_DBG("notification_ipc_request_load_noti_grouping_list done [result: %d]", result);
1001         return result;
1002 }
1003
1004 int notification_ipc_request_load_noti_detail_list(const char *pkgname,
1005                 int group_id,
1006                 int priv_id,
1007                 int count,
1008                 notification_list_h *list)
1009 {
1010         int result;
1011         GDBusMessage *reply = NULL;
1012         GVariant *body;
1013         GVariant *reply_body;
1014         GVariant *iter_body;
1015         GVariantIter *iter;
1016         notification_h noti;
1017         GVariant *noti_body;
1018
1019         result = _dbus_init();
1020         if (result != NOTIFICATION_ERROR_NONE) {
1021                 NOTIFICATION_ERR("Can't init dbus %d", result);
1022                 return result;
1023         }
1024
1025         body = g_variant_new("(siii)", pkgname, group_id, priv_id, count);
1026         result = _send_sync_noti(body, &reply, "load_noti_detail_list");
1027
1028         if (result == NOTIFICATION_ERROR_NONE) {
1029                 reply_body = g_dbus_message_get_body(reply);
1030                 g_variant_get(reply_body, "(a(v))", &iter);
1031
1032                 while (g_variant_iter_loop(iter, "(v)", &iter_body)) {
1033                         noti = notification_create(NOTIFICATION_TYPE_NOTI);
1034                         g_variant_get(iter_body, "(v)", &noti_body);
1035                         notification_ipc_make_noti_from_gvariant(noti, noti_body);
1036                         _print_noti(noti);
1037                         *list = notification_list_append(*list, noti);
1038                 }
1039                 g_variant_iter_free(iter);
1040         }
1041
1042         if (reply)
1043                 g_object_unref(reply);
1044
1045         NOTIFICATION_DBG("notification_ipc_request_load_noti_detail_list done [result: %d]", result);
1046         return result;
1047 }
1048
1049 int notification_ipc_request_get_setting_array(
1050                 notification_setting_h *setting_array,
1051                 int *count)
1052 {
1053         int result;
1054         GDBusMessage *reply = NULL;
1055         GVariant *reply_body;
1056         GVariant *iter_body;
1057         GVariantIter *iter;
1058         int setting_cnt;
1059         notification_setting_h result_setting_array;
1060         notification_setting_h temp;
1061         int setting_idx;
1062
1063         result = _dbus_init();
1064         if (result != NOTIFICATION_ERROR_NONE) {
1065                 NOTIFICATION_ERR("Can't init dbus %d", result);
1066                 return result;
1067         }
1068
1069         result = _send_sync_noti(NULL, &reply, "get_setting_array");
1070
1071         if (result == NOTIFICATION_ERROR_NONE) {
1072                 reply_body = g_dbus_message_get_body(reply);
1073                 g_variant_get(reply_body, "(ia(v))", &setting_cnt, &iter);
1074
1075                 NOTIFICATION_DBG("get setting arr cnt: %d", setting_cnt);
1076                 result_setting_array = (struct notification_setting *)malloc(sizeof(struct notification_setting) * setting_cnt);
1077                 if (result_setting_array == NULL) {
1078                         NOTIFICATION_ERR("malloc failed");
1079                         g_object_unref(reply);
1080                         g_variant_iter_free(iter);
1081                         return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1082                 }
1083
1084                 setting_idx = 0;
1085                 while (g_variant_iter_loop(iter, "(v)", &iter_body)) {
1086                         temp = result_setting_array + setting_idx;
1087                         notification_ipc_make_setting_from_gvariant(temp, iter_body);
1088                         setting_idx++;
1089                 }
1090
1091                 *count = setting_cnt;
1092                 *setting_array = result_setting_array;
1093                 g_variant_iter_free(iter);
1094         }
1095
1096         if (reply)
1097                 g_object_unref(reply);
1098
1099         NOTIFICATION_DBG("notification_ipc_request_get_setting_array done [result: %d]", result);
1100         return result;
1101 }
1102
1103 int notification_ipc_request_get_setting_by_package_name(
1104                 const char *package_name, notification_setting_h *setting)
1105 {
1106         int result;
1107         GDBusMessage *reply = NULL;
1108         GVariant *body;
1109         GVariant *reply_body;
1110         GVariant *setting_body;
1111         notification_setting_h result_setting;
1112
1113         result = _dbus_init();
1114         if (result != NOTIFICATION_ERROR_NONE) {
1115                 NOTIFICATION_ERR("Can't init dbus %d", result);
1116                 return result;
1117         }
1118
1119         body = g_variant_new("(s)", package_name);
1120         result = _send_sync_noti(body, &reply, "get_setting_by_package_name");
1121
1122         if (result == NOTIFICATION_ERROR_NONE) {
1123                 reply_body = g_dbus_message_get_body(reply);
1124                 g_variant_get(reply_body, "(v)", &setting_body);
1125
1126                 result_setting = (struct notification_setting *)malloc(sizeof(struct notification_setting));
1127                 if (result_setting == NULL) {
1128                         NOTIFICATION_ERR("malloc failed");
1129                         g_object_unref(reply);
1130                         g_variant_unref(body);
1131                         return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1132                 }
1133                 notification_ipc_make_setting_from_gvariant(result_setting, setting_body);
1134
1135                 *setting = result_setting;
1136                 g_variant_unref(setting_body);
1137         }
1138
1139         if (reply)
1140                 g_object_unref(reply);
1141
1142         NOTIFICATION_DBG("notification_ipc_request_get_setting_by_package_name done [result: %d]", result);
1143         return result;
1144 }
1145
1146 int notification_ipc_request_load_system_setting(notification_system_setting_h *setting)
1147 {
1148         int result;
1149         GDBusMessage *reply = NULL;
1150         GVariant *setting_body;
1151         GVariant *reply_body;
1152         notification_system_setting_h result_setting;
1153
1154         result = _dbus_init();
1155         if (result != NOTIFICATION_ERROR_NONE) {
1156                 NOTIFICATION_ERR("Can't init dbus %d", result);
1157                 return result;
1158         }
1159
1160         result = _send_sync_noti(NULL, &reply, "load_system_setting");
1161
1162         if (result == NOTIFICATION_ERROR_NONE) {
1163                 reply_body = g_dbus_message_get_body(reply);
1164                 g_variant_get(reply_body, "(v)", &setting_body);
1165
1166                 result_setting = (struct notification_system_setting *)malloc(sizeof(struct notification_system_setting));
1167                 if (result_setting == NULL) {
1168                         NOTIFICATION_ERR("malloc failed");
1169                         g_object_unref(reply);
1170                         return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1171                 }
1172                 notification_ipc_make_system_setting_from_gvariant(result_setting, setting_body);
1173
1174                 *setting = result_setting;
1175                 g_variant_unref(setting_body);
1176         }
1177
1178         if (reply)
1179                 g_object_unref(reply);
1180
1181         NOTIFICATION_DBG("notification_ipc_request_load_system_setting done [result: %d]", result);
1182         return result;
1183 }
1184
1185 int notification_ipc_update_setting(notification_setting_h setting)
1186 {
1187         int result;
1188         GDBusMessage *reply = NULL;
1189         GVariant *body;
1190
1191         result = _dbus_init();
1192         if (result != NOTIFICATION_ERROR_NONE) {
1193                 NOTIFICATION_ERR("Can't init dbus %d", result);
1194                 return result;
1195         }
1196
1197         body = g_variant_new("(siii)",
1198                         setting->package_name,
1199                         (int)(setting->allow_to_notify),
1200                         (int)(setting->do_not_disturb_except),
1201                         (int)(setting->visibility_class));
1202
1203         result = _send_sync_noti(body, &reply, "update_noti_setting");
1204
1205         if (reply)
1206                 g_object_unref(reply);
1207
1208         NOTIFICATION_DBG("notification_ipc_update_setting done [result: %d]", result);
1209         return result;
1210 }
1211
1212 int notification_ipc_update_system_setting(notification_system_setting_h system_setting)
1213 {
1214         int result;
1215         GDBusMessage *reply = NULL;
1216         GVariant *body;
1217
1218         result = _dbus_init();
1219         if (result != NOTIFICATION_ERROR_NONE) {
1220                 NOTIFICATION_ERR("Can't init dbus %d", result);
1221                 return result;
1222         }
1223
1224         body = g_variant_new("(ii)",
1225                         (int)(system_setting->do_not_disturb),
1226                         (int)(system_setting->visibility_class));
1227
1228         result = _send_sync_noti(body, &reply, "update_noti_sys_setting");
1229
1230         if (reply)
1231                 g_object_unref(reply);
1232
1233         NOTIFICATION_DBG("notification_ipc_update_system_setting done [result: %d]", result);
1234         return result;
1235 }
1236
1237 EXPORT_API GVariant *notification_ipc_make_gvariant_from_noti(notification_h noti, bool translate)
1238 {
1239         NOTIFICATION_DBG("make gvariant from noti");
1240         int i = 0;
1241         int b_encode_len = 0;
1242         bundle_raw *args = NULL;
1243         bundle_raw *group_args = NULL;
1244         bundle_raw *b_image_path = NULL;
1245         bundle_raw *b_execute_option = NULL;
1246         bundle_raw *b_service_responding = NULL;
1247         bundle_raw *b_service_single_launch = NULL;
1248         bundle_raw *b_service_multi_launch = NULL;
1249         bundle_raw *b_event_handler[NOTIFICATION_EVENT_TYPE_MAX] = {NULL, };
1250         bundle_raw *b_text = NULL;
1251         bundle_raw *b_key = NULL;
1252         bundle_raw *b_format_args = NULL;
1253         GVariant *body = NULL;
1254         GVariant *result_body = NULL;
1255         GVariantBuilder builder;
1256
1257         if (translate)
1258                 notification_translate_localized_text(noti);
1259
1260         g_variant_builder_init(&builder, G_VARIANT_TYPE("a{iv}"));
1261         g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_NOTI_TYPE, g_variant_new_int32(noti->type));
1262         g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_LAYOUT, g_variant_new_int32(noti->layout));
1263         g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_GROUP_ID, g_variant_new_int32(noti->group_id));
1264         g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_INTERNAL_GROUP_ID, g_variant_new_int32(noti->internal_group_id));
1265         g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_PRIV_ID, g_variant_new_int32(noti->priv_id));
1266         g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_CALLER_PKGNAME, g_variant_new_string((const gchar *)noti->caller_pkgname));
1267         g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_DISPLAY_APPLIST, g_variant_new_int32(noti->display_applist));
1268
1269         if (noti->args) {
1270                 bundle_encode(noti->args, (bundle_raw **)&args, NULL);
1271                 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_ARGS, g_variant_new_string((const gchar *)args));
1272
1273                 if (args)
1274                         bundle_free_encoded_rawdata(&args);
1275         }
1276
1277         if (noti->group_args) {
1278                 bundle_encode(noti->group_args, (bundle_raw **)&group_args,
1279                               &b_encode_len);
1280                 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_GROUP_ARGS, g_variant_new_string((const gchar *)group_args));
1281
1282                 if (group_args)
1283                         bundle_free_encoded_rawdata(&group_args);
1284         }
1285
1286         if (noti->b_execute_option) {
1287                 bundle_encode(noti->b_execute_option,
1288                               (bundle_raw **)&b_execute_option, &b_encode_len);
1289                 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_EXECUTE_OPTION, g_variant_new_string((const gchar *)b_execute_option));
1290
1291                 if (b_execute_option)
1292                         bundle_free_encoded_rawdata(&b_execute_option);
1293         }
1294
1295         if (noti->b_service_responding) {
1296                 bundle_encode(noti->b_service_responding,
1297                               (bundle_raw **)&b_service_responding, &b_encode_len);
1298                 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_SERVICE_RESPONDING, g_variant_new_string((const gchar *)b_service_responding));
1299
1300                 if (b_service_responding)
1301                         bundle_free_encoded_rawdata(&b_service_responding);
1302         }
1303
1304         if (noti->b_service_single_launch) {
1305                 bundle_encode(noti->b_service_single_launch,
1306                               (bundle_raw **)&b_service_single_launch, &b_encode_len);
1307                 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_SERVICE_SINGLE_LAUNCH, g_variant_new_string((const gchar *)b_service_single_launch));
1308
1309                 if (b_service_single_launch)
1310                         bundle_free_encoded_rawdata(&b_service_single_launch);
1311         }
1312
1313         if (noti->b_service_multi_launch) {
1314                 bundle_encode(noti->b_service_multi_launch,
1315                               (bundle_raw **)&b_service_multi_launch, &b_encode_len);
1316                 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_SERVICE_MULTI_LAUNCH, g_variant_new_string((const gchar *)b_service_multi_launch));
1317
1318                 if (b_service_multi_launch)
1319                         bundle_free_encoded_rawdata(&b_service_multi_launch);
1320         }
1321
1322         for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
1323                 if (noti->b_event_handler[i]) {
1324                         bundle_encode(noti->b_event_handler[i],
1325                                         (bundle_raw **)&b_event_handler[i], &b_encode_len);
1326                         g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_BUTTON1_EVENT + i, g_variant_new_string((const gchar *)b_event_handler[i]));
1327
1328                         if (b_event_handler[i])
1329                                 bundle_free_encoded_rawdata(&b_event_handler[i]);
1330                 }
1331         }
1332
1333         if (noti->launch_pkgname)
1334                 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_LAUNCH_PKGNAME, g_variant_new_string((const gchar *)noti->launch_pkgname));
1335
1336         if (noti->domain != NULL)
1337                 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_DOMAIN, g_variant_new_string((const gchar *)noti->domain));
1338
1339         if (noti->dir != NULL)
1340                 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_DIR, g_variant_new_string((const gchar *)noti->dir));
1341
1342         if (noti->b_text) {
1343                 bundle_encode(noti->b_text, (bundle_raw **)&b_text, &b_encode_len);
1344                 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_TEXT, g_variant_new_string((const gchar *)b_text));
1345
1346                 if (b_text)
1347                         bundle_free_encoded_rawdata(&b_text);
1348         }
1349
1350         if (noti->b_key) {
1351                 bundle_encode(noti->b_key, (bundle_raw **)&b_key, &b_encode_len);
1352                 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_KEY, g_variant_new_string((const gchar *)b_key));
1353
1354                 if (b_key)
1355                         bundle_free_encoded_rawdata(&b_key);
1356         }
1357
1358         if (noti->b_format_args) {
1359                 bundle_encode(noti->b_format_args,
1360                               (bundle_raw **)&b_format_args, &b_encode_len);
1361                 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_FORMAT_ARGS, g_variant_new_string((const gchar *)b_format_args));
1362
1363                 if (b_format_args)
1364                         bundle_free_encoded_rawdata(&b_format_args);
1365         }
1366
1367         if (noti->num_format_args != 0)
1368                 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_NUM_FORMAT_ARGS, g_variant_new_int32(noti->num_format_args));
1369
1370         if (noti->b_image_path) {
1371                 bundle_encode(noti->b_image_path,
1372                               (bundle_raw **)&b_image_path, &b_encode_len);
1373                 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_IMAGE_PATH, g_variant_new_string((const gchar *)b_image_path));
1374
1375                 if (b_image_path)
1376                         bundle_free_encoded_rawdata(&b_image_path);
1377         }
1378
1379         if (noti->sound_type != NOTIFICATION_SOUND_TYPE_NONE)
1380                 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_SOUND_TYPE, g_variant_new_int32(noti->sound_type));
1381
1382         if (noti->sound_path)
1383                 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_SOUND_PATH, g_variant_new_string((const gchar *)noti->sound_path));
1384
1385         g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_VIBRATION_TYPE, g_variant_new_int32(noti->vibration_type));
1386
1387         if (noti->vibration_path)
1388                 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_VIBRATION_PATH, g_variant_new_string((const gchar *)noti->vibration_path));
1389
1390         if (noti->led_operation != NOTIFICATION_LED_OP_OFF)
1391                 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_LED_OPERATION, g_variant_new_int32(noti->led_operation));
1392
1393         if (noti->led_argb != 0)
1394                 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_LED_ARGB, g_variant_new_int32(noti->led_argb));
1395
1396         if (noti->led_on_ms != 0)
1397                 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_LED_ON_MS, g_variant_new_int32(noti->led_on_ms));
1398
1399         if (noti->led_off_ms != 0)
1400                 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_LED_OFF_MS, g_variant_new_int32(noti->led_off_ms));
1401
1402         if (noti->time != 0)
1403                 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_TIME, g_variant_new_int32(noti->time));
1404
1405         if (noti->insert_time != 0)
1406                 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_INSERT_TIME, g_variant_new_int32(noti->insert_time));
1407
1408         if (noti->flags_for_property != 0)
1409                 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_FLAGS_FOR_PROPERTY, g_variant_new_int32(noti->flags_for_property));
1410
1411         if (noti->progress_size != 0.0)
1412                 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_PROGRESS_SIZE, g_variant_new_double(noti->progress_size));
1413
1414         if (noti->progress_percentage != 0.0)
1415                 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_PROGRESS_PERCENTAGE, g_variant_new_double(noti->progress_percentage));
1416
1417         if (noti->app_icon_path != NULL)
1418                 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_APP_ICON_PATH, g_variant_new_string((const gchar *)noti->app_icon_path));
1419         if (noti->app_name != NULL)
1420                 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_APP_NAME, g_variant_new_string((const gchar *)noti->app_name));
1421         if (noti->temp_title != NULL)
1422                 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_TEMP_TITLE, g_variant_new_string((const gchar *)noti->temp_title));
1423         if (noti->temp_content != NULL)
1424                 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_TEMP_CONTENT, g_variant_new_string((const gchar *)noti->temp_content));
1425         if (noti->tag != NULL)
1426                 g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_TAG, g_variant_new_string((const gchar *)noti->tag));
1427
1428         g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_ONGOING_FLAG, g_variant_new_int32(noti->ongoing_flag));
1429
1430         g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_AUTO_REMOVE, g_variant_new_int32(noti->auto_remove));
1431
1432         result_body = g_variant_builder_end(&builder);
1433         body = g_variant_new("(v)", result_body);
1434
1435         return body;
1436 }
1437
1438 static gboolean _variant_to_int_dict(GHashTable **dict, GVariant *variant)
1439 {
1440         GVariantIter iter;
1441         int key;
1442         int *hash_key;
1443         GVariant *value;
1444
1445         *dict = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, (GDestroyNotify)g_variant_unref);
1446         if (*dict == NULL)
1447                 return FALSE;
1448
1449         g_variant_iter_init(&iter, variant);
1450         while (g_variant_iter_next(&iter, "{iv}", &key, &value)) {
1451                 hash_key = (int *)calloc(sizeof(int), 1);
1452                 if (hash_key == NULL) {
1453                         g_hash_table_unref(*dict);
1454                         return FALSE;
1455                 }
1456                 *hash_key = key;
1457                 g_hash_table_insert(*dict, (gpointer)hash_key, value);
1458         }
1459         return TRUE;
1460 }
1461
1462 static gboolean _variant_dict_lookup(GHashTable *dict,
1463                 int key,
1464                 const gchar  *format_string,
1465                 ...)
1466 {
1467         GVariant *value;
1468         va_list ap;
1469
1470         value = g_hash_table_lookup(dict, (gpointer)&key);
1471
1472         if (value == NULL || !g_variant_check_format_string(value, format_string, FALSE))
1473                 return FALSE;
1474
1475         va_start(ap, format_string);
1476         g_variant_get_va(value, format_string, NULL, &ap);
1477         va_end(ap);
1478
1479         return TRUE;
1480 }
1481
1482 /*!
1483  * functions creating notification packet
1484  */
1485 EXPORT_API int notification_ipc_make_noti_from_gvariant(notification_h noti,
1486                 GVariant *variant) {
1487
1488         NOTIFICATION_DBG("make noti from GVariant");
1489         GHashTable *dict;
1490
1491         int i;
1492         char *caller_pkgname = NULL;
1493         char *launch_pkgname = NULL;
1494         bundle_raw *args = NULL;
1495         bundle_raw *group_args = NULL;
1496         bundle_raw *b_execute_option = NULL;
1497         bundle_raw *b_service_responding = NULL;
1498         bundle_raw *b_service_single_launch = NULL;
1499         bundle_raw *b_service_multi_launch = NULL;
1500         bundle_raw *b_event_handler[NOTIFICATION_EVENT_TYPE_MAX] = { NULL, };
1501         char *domain = NULL;
1502         char *dir = NULL;
1503         bundle_raw *b_text = NULL;
1504         bundle_raw *b_key = NULL;
1505         bundle_raw *b_format_args = NULL;
1506         bundle_raw *b_image_path = NULL;
1507         char *sound_path = NULL;
1508         char *vibration_path = NULL;
1509         char *app_icon_path = NULL;
1510         char *app_name = NULL;
1511         char *temp_title = NULL;
1512         char *temp_content = NULL;
1513         char *tag = NULL;
1514
1515         if (noti == NULL) {
1516                 NOTIFICATION_ERR("invalid data noti NULL");
1517                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1518         }
1519
1520         if (variant == NULL) {
1521                 NOTIFICATION_ERR("invalid data variant NULL");
1522                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1523         }
1524
1525         if (!_variant_to_int_dict(&dict, variant))
1526                 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1527
1528         _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_NOTI_TYPE, "i", &noti->type);
1529         _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_LAYOUT, "i", &noti->layout);
1530         _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_GROUP_ID, "i", &noti->group_id);
1531         _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_INTERNAL_GROUP_ID, "i", &noti->internal_group_id);
1532         _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_PRIV_ID, "i", &noti->priv_id);
1533         _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_CALLER_PKGNAME, "&s", &caller_pkgname);
1534         _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_LAUNCH_PKGNAME, "&s", &launch_pkgname);
1535         _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_ARGS, "&s", &args);
1536         _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_GROUP_ARGS, "&s", &group_args);
1537         _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_EXECUTE_OPTION, "&s", &b_execute_option);
1538         _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_SERVICE_RESPONDING, "&s", &b_service_responding);
1539         _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_SERVICE_SINGLE_LAUNCH, "&s", &b_service_single_launch);
1540         _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_SERVICE_MULTI_LAUNCH, "&s", &b_service_multi_launch);
1541         _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_BUTTON1_EVENT, "&s", &b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1]);
1542         _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_BUTTON2_EVENT, "&s", &b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_2]);
1543         _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_BUTTON3_EVENT, "&s", &b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_3]);
1544         _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_BUTTON4_EVENT, "&s", &b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_4]);
1545         _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_BUTTON5_EVENT, "&s", &b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_5]);
1546         _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_BUTTON6_EVENT, "&s", &b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_6]);
1547         _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_ICON_EVENT, "&s", &b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_ICON]);
1548         _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_THUMBNAIL_EVENT, "&s", &b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL]);
1549         _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_DOMAIN, "&s", &domain);
1550         _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_DIR, "&s", &dir);
1551         _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_TEXT, "&s", &b_text);
1552         _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_KEY, "&s", &b_key);
1553         _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_FORMAT_ARGS, "&s", &b_format_args);
1554         _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_NUM_FORMAT_ARGS, "i", &noti->num_format_args);
1555         _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_IMAGE_PATH, "&s", &b_image_path);
1556         _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_SOUND_TYPE, "i", &noti->sound_type);
1557         _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_SOUND_PATH, "&s", &sound_path);
1558         _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_VIBRATION_TYPE, "i", &noti->vibration_type);
1559         _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_VIBRATION_PATH, "&s", &vibration_path);
1560         _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_LED_OPERATION, "i", &noti->led_operation);
1561         _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_LED_ARGB, "i", &noti->led_argb);
1562         _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_LED_ON_MS, "i", &noti->led_on_ms);
1563         _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_LED_OFF_MS, "i", &noti->led_off_ms);
1564         _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_TIME, "i", &noti->time);
1565         _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_INSERT_TIME, "i", &noti->insert_time);
1566         _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_FLAGS_FOR_PROPERTY, "i", &noti->flags_for_property);
1567         _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_DISPLAY_APPLIST, "i", &noti->display_applist);
1568         _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_PROGRESS_SIZE, "d", &noti->progress_size);
1569         _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_PROGRESS_PERCENTAGE, "d", &noti->progress_percentage);
1570         _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_APP_ICON_PATH, "&s", &app_icon_path);
1571         _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_APP_NAME, "&s", &app_name);
1572         _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_TEMP_TITLE, "&s", &temp_title);
1573         _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_TEMP_CONTENT, "&s", &temp_content);
1574         _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_TAG, "&s", &tag);
1575         _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_ONGOING_FLAG, "i", &noti->ongoing_flag);
1576         _variant_dict_lookup(dict, NOTIFICATION_DATA_TYPE_AUTO_REMOVE, "i", &noti->auto_remove);
1577
1578         noti->caller_pkgname = _dup_string(caller_pkgname);
1579         noti->launch_pkgname = _dup_string(launch_pkgname);
1580         noti->args = _create_bundle_from_bundle_raw(args);
1581         noti->group_args = _create_bundle_from_bundle_raw(group_args);
1582         noti->b_execute_option = _create_bundle_from_bundle_raw(b_execute_option);
1583         noti->b_service_responding = _create_bundle_from_bundle_raw(
1584                         b_service_responding);
1585         noti->b_service_single_launch = _create_bundle_from_bundle_raw(
1586                         b_service_single_launch);
1587         noti->b_service_multi_launch = _create_bundle_from_bundle_raw(
1588                         b_service_multi_launch);
1589         for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
1590                 noti->b_event_handler[i] = _create_bundle_from_bundle_raw(
1591                                 b_event_handler[i]);
1592         }
1593         noti->domain = _dup_string(domain);
1594         noti->dir = _dup_string(dir);
1595         noti->b_text = _create_bundle_from_bundle_raw(b_text);
1596         noti->b_key = _create_bundle_from_bundle_raw(b_key);
1597         noti->b_format_args = _create_bundle_from_bundle_raw(b_format_args);
1598         noti->b_image_path = _create_bundle_from_bundle_raw(b_image_path);
1599         noti->sound_path = _dup_string(sound_path);
1600         noti->vibration_path = _dup_string(vibration_path);
1601         noti->app_icon_path = _dup_string(app_icon_path);
1602         noti->app_name = _dup_string(app_name);
1603         noti->temp_title = _dup_string(temp_title);
1604         noti->temp_content = _dup_string(temp_content);
1605         noti->tag = _dup_string(tag);
1606
1607         g_hash_table_unref(dict);
1608
1609         return NOTIFICATION_ERROR_NONE;
1610 }
1611
1612 EXPORT_API GVariant *notification_ipc_make_gvariant_from_system_setting(struct notification_system_setting *noti_setting)
1613 {
1614         GVariant *body = NULL;
1615         body = g_variant_new("(ii)",
1616                         noti_setting->do_not_disturb,
1617                         noti_setting->visibility_class);
1618         return body;
1619 }
1620
1621 EXPORT_API int notification_ipc_make_system_setting_from_gvariant(struct notification_system_setting *noti_setting,
1622                 GVariant *variant)
1623 {
1624         int do_not_disturb;
1625         int visibility_class;
1626
1627         if (noti_setting == NULL) {
1628                 NOTIFICATION_ERR("invalid data");
1629                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1630         }
1631         g_variant_get(variant,
1632                         "(ii)",
1633                         &do_not_disturb,
1634                         &visibility_class);
1635
1636         NOTIFICATION_DBG("system setting  #### %d, %d",
1637                         do_not_disturb, visibility_class);
1638
1639         noti_setting->do_not_disturb = do_not_disturb;
1640         noti_setting->visibility_class = visibility_class;
1641
1642         NOTIFICATION_DBG("system setting2  #### %d, %d",
1643                         noti_setting->do_not_disturb, noti_setting->visibility_class);
1644
1645         return NOTIFICATION_ERROR_NONE;
1646 }
1647
1648 EXPORT_API GVariant *notification_ipc_make_gvariant_from_setting(struct notification_setting *noti_setting)
1649 {
1650         GVariant *body = NULL;
1651
1652         body = g_variant_new("(siii)",
1653                         noti_setting->package_name,
1654                         noti_setting->allow_to_notify,
1655                         noti_setting->do_not_disturb_except,
1656                         noti_setting->visibility_class);
1657
1658         return body;
1659 }
1660
1661 EXPORT_API int notification_ipc_make_setting_from_gvariant(struct notification_setting *noti_setting,
1662                 GVariant *variant)
1663 {
1664         NOTIFICATION_DBG("notification_ipc_make_setting_from_gvariant !!!!");
1665         char *pkgname;
1666         int allow_to_notify;
1667         int do_not_disturb_except;
1668         int visibility_class;
1669
1670         if (noti_setting == NULL || variant == NULL) {
1671                 NOTIFICATION_ERR("invalid data");
1672                 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1673         }
1674         g_variant_get(variant,
1675                         "(&siii)",
1676                         &pkgname,
1677                         &allow_to_notify,
1678                         &do_not_disturb_except,
1679                         &visibility_class);
1680
1681         NOTIFICATION_DBG("setting from variant %s !!", pkgname);
1682
1683         noti_setting->package_name = _dup_string(pkgname);
1684         noti_setting->allow_to_notify = allow_to_notify;
1685         noti_setting->do_not_disturb_except = do_not_disturb_except;
1686         noti_setting->visibility_class = visibility_class;
1687
1688         NOTIFICATION_DBG("setting from variant %s, %s",
1689                         noti_setting->package_name, pkgname);
1690
1691         return NOTIFICATION_ERROR_NONE;
1692 }
1693
1694 static int _send_service_register()
1695 {
1696         NOTIFICATION_DBG("service register");
1697         GDBusMessage *reply = NULL;
1698         int result;
1699         notification_op *noti_op = NULL;
1700
1701         result = _send_sync_noti(NULL, &reply, "noti_service_register");
1702
1703         if (reply)
1704                 g_object_unref(reply);
1705
1706         NOTIFICATION_DBG("_send_service_register done = %s, result = %d", _bus_name, result);
1707         noti_op = _ipc_create_op(NOTIFICATION_OP_SERVICE_READY, 1, NULL, 1, NULL);
1708         if (noti_op != NULL) {
1709                 notification_call_changed_cb(noti_op, 1);
1710                 free(noti_op);
1711         }
1712
1713         return result;
1714 }
1715
1716 static int _ipc_monitor_register(void)
1717 {
1718         NOTIFICATION_ERR("register a service\n");
1719
1720         return  _send_service_register();
1721 }
1722
1723 static void _on_name_appeared(GDBusConnection *connection,
1724                 const gchar     *name,
1725                 const gchar     *name_owner,
1726                 gpointer         user_data)
1727 {
1728         NOTIFICATION_DBG("name appeared : %s", name);
1729         is_master_started = 1;
1730         _ipc_monitor_register();
1731
1732         /* TODO: dbus activation isn't enough ? */
1733         _do_deffered_task();
1734 }
1735
1736 static void _on_name_vanished(GDBusConnection *connection,
1737                 const gchar     *name,
1738                 gpointer         user_data)
1739 {
1740         NOTIFICATION_DBG("name vanished : %s", name);
1741         is_master_started = 0;
1742 }
1743
1744 int notification_ipc_monitor_init(void)
1745 {
1746         int ret;
1747
1748         ret = _dbus_init();
1749         if (ret != NOTIFICATION_ERROR_NONE) {
1750                 NOTIFICATION_ERR("Can't init dbus %d", ret);
1751                 return ret;
1752         }
1753
1754         ret = _dbus_signal_init();
1755         if (ret != NOTIFICATION_ERROR_NONE) {
1756                 NOTIFICATION_ERR("Can't signal_init %d", ret);
1757                 return ret;
1758         }
1759
1760         ret = _ipc_monitor_register();
1761         if (ret != NOTIFICATION_ERROR_NONE) {
1762                 NOTIFICATION_ERR("Can't init ipc_monitor_register %d", ret);
1763                 return ret;
1764         }
1765
1766         if (provider_monitor_id == 0) {
1767                 provider_monitor_id = g_bus_watch_name_on_connection(
1768                                 _gdbus_conn,
1769                                 PROVIDER_BUS_NAME,
1770                                 G_BUS_NAME_WATCHER_FLAGS_NONE,
1771                                 _on_name_appeared,
1772                                 _on_name_vanished,
1773                                 NULL,
1774                                 NULL);
1775
1776                 if (provider_monitor_id == 0) {
1777                         g_dbus_connection_signal_unsubscribe(_gdbus_conn, monitor_id);
1778                         monitor_id = 0;
1779                         NOTIFICATION_ERR("watch on name fail");
1780                         return NOTIFICATION_ERROR_IO_ERROR;
1781                 }
1782         }
1783
1784         return NOTIFICATION_ERROR_NONE;
1785 }
1786
1787 static int _ipc_monitor_deregister(void)
1788 {
1789         if (provider_monitor_id) {
1790                 g_bus_unwatch_name(provider_monitor_id);
1791                 provider_monitor_id = 0;
1792         }
1793
1794         if (monitor_id) {
1795                 g_dbus_connection_signal_unsubscribe(_gdbus_conn, monitor_id);
1796                 monitor_id = 0;
1797         }
1798
1799         return NOTIFICATION_ERROR_NONE;
1800 }
1801
1802 int notification_ipc_monitor_fini(void)
1803 {
1804         return  _ipc_monitor_deregister();
1805 }
1806