summaryrefslogtreecommitdiff
path: root/src/notification_internal.c
blob: 1709a8e89fbbb322d6f183efb3620983c3a4983f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
/*
 * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <libintl.h>
#include <dbus/dbus.h>
#include <gio/gio.h>

#include <aul.h>
#include <tizen.h>
#include <bundle.h>
#include <bundle_internal.h>
#include <app_control.h>
#include <app_control_internal.h>
#include <pkgmgr-info.h>

#include <notification.h>
#include <notification_list.h>
#include <notification_debug.h>
#include <notification_private.h>
#include <notification_noti.h>
#include <notification_ongoing.h>
#include <notification_group.h>
#include <notification_ipc.h>
#include <notification_internal.h>
#include <notification_shared_file.h>

#define REGULAR_UID_MIN 5000

typedef struct _notification_cb_info notification_cb_info_s;
typedef struct _notification_event_cb_info notification_event_cb_info_s;

typedef enum __notification_cb_type {
	NOTIFICATION_CB_NORMAL = 1,
	NOTIFICATION_CB_DETAILED,
} _notification_cb_type_e;

struct _notification_cb_info {
	_notification_cb_type_e cb_type;
	void (*changed_cb)(void *data, notification_type_e type);
	void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op);
	void *data;
};

struct _notification_event_cb_info {
	int priv_id;
	event_handler_cb cb;
	void *userdata;
};

static GHashTable *_noti_cb_hash = NULL;
static GList *__noti_event_cb_list = NULL;

void notification_reset_event_handler_list(void)
{
	GList *iter;
	notification_event_cb_info_s *info;

	if (!__noti_event_cb_list)
		return;

	iter = g_list_first(__noti_event_cb_list);
	while (iter) {
		info = g_list_nth_data(iter, 0);
		if (info)
			notification_ipc_reset_event_handler(info->priv_id);
		iter = g_list_next(iter);
	}
}

/* LCOV_EXCL_START */
static void __free_changed_cb_info(gpointer data)
{
	notification_cb_info_s *noti_cb_info = (notification_cb_info_s *)data;

	if (noti_cb_info)
		free(noti_cb_info);
}
/* LCOV_EXCL_STOP */

void notification_call_changed_cb_for_uid(notification_op *op_list, int op_num, uid_t uid)
{
	notification_type_e type = NOTIFICATION_TYPE_NOTI;
	GList *noti_cb_list;
	notification_cb_info_s *noti_cb_info;

	if (_noti_cb_hash == NULL)
		return;

	noti_cb_list = (GList *)g_hash_table_lookup(_noti_cb_hash, GUINT_TO_POINTER(uid));
	if (noti_cb_list == NULL)
		return;

	if (op_list == NULL) {
		ERR("Invalid parameter");
		return;
	}

	noti_cb_list = g_list_first(noti_cb_list);
	notification_get_type(op_list->noti, &type);

	for (; noti_cb_list != NULL; noti_cb_list = noti_cb_list->next) {
		noti_cb_info = noti_cb_list->data;

		if (noti_cb_info->cb_type == NOTIFICATION_CB_NORMAL && noti_cb_info->changed_cb)
			noti_cb_info->changed_cb(noti_cb_info->data, type);

		if (noti_cb_info->cb_type == NOTIFICATION_CB_DETAILED && noti_cb_info->detailed_changed_cb) {
			noti_cb_info->detailed_changed_cb(noti_cb_info->data,
					type, op_list, op_num);
		}
	}
}

static gint __priv_id_compare(gconstpointer a, gconstpointer b)
{
	const notification_event_cb_info_s *info = NULL;

	if (!a)
		return -1;

	info = (notification_event_cb_info_s *)a;

	if (info->priv_id == GPOINTER_TO_INT(b))
		return 0;

	return 1;
}

void notification_call_event_handler_cb(notification_h noti, int event_type)
{
	int ret;
	int priv_id;
	GList *find_list;
	notification_event_cb_info_s *info;

	if (__noti_event_cb_list == NULL)
		return;

	ret = notification_get_id(noti, NULL, &priv_id);
	if (ret != NOTIFICATION_ERROR_NONE)
		return;

	__noti_event_cb_list = g_list_first(__noti_event_cb_list);
	find_list = g_list_find_custom(__noti_event_cb_list, GINT_TO_POINTER(priv_id),
				       (GCompareFunc)__priv_id_compare);
	if (find_list == NULL)
		return;

	info = g_list_nth_data(find_list, 0);
	info->cb(noti, event_type, info->userdata);
}

/* LCOV_EXCL_START */
void notification_delete_event_handler_cb(int priv_id)
{
	GList *delete_list;
	notification_event_cb_info_s *info;

	if (__noti_event_cb_list == NULL)
		return;

	__noti_event_cb_list = g_list_first(__noti_event_cb_list);
	delete_list = g_list_find_custom(__noti_event_cb_list, GINT_TO_POINTER(priv_id),
					 (GCompareFunc)__priv_id_compare);

	if (delete_list == NULL)
		return;

	info = g_list_nth_data(delete_list, 0);
	__noti_event_cb_list = g_list_remove(g_list_first(__noti_event_cb_list), info);

	if (info)
		free(info);

	if (__noti_event_cb_list == NULL)
		notification_ipc_event_monitor_fini();
}
/* LCOV_EXCL_STOP */

EXPORT_API int notification_add_deferred_task(
		void (*deferred_task_cb)(void *data), void *user_data)
{
	if (deferred_task_cb == NULL)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	return notification_ipc_add_deffered_task(deferred_task_cb, user_data);
}

EXPORT_API int notification_del_deferred_task(
		void (*deferred_task_cb)(void *data))
{
	if (deferred_task_cb == NULL)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	return notification_ipc_del_deffered_task(deferred_task_cb);
}

EXPORT_API int notification_resister_changed_cb_for_uid(
		void (*changed_cb)(void *data, notification_type_e type),
		void *user_data, uid_t uid)
{
	GList *noti_cb_list;
	notification_cb_info_s *noti_cb_info_new;

	if (changed_cb == NULL)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	if (_noti_cb_hash == NULL)
		_noti_cb_hash = g_hash_table_new(g_direct_hash, g_direct_equal);

	noti_cb_info_new = (notification_cb_info_s *)malloc(sizeof(notification_cb_info_s));
	if (noti_cb_info_new == NULL) {
		/* LCOV_EXCL_START */
		ERR("Failed to alloc memory");
		return NOTIFICATION_ERROR_OUT_OF_MEMORY;
		/* LCOV_EXCL_STOP */
	}

	noti_cb_info_new->cb_type = NOTIFICATION_CB_NORMAL;
	noti_cb_info_new->changed_cb = changed_cb;
	noti_cb_info_new->detailed_changed_cb = NULL;
	noti_cb_info_new->data = user_data;

	noti_cb_list = g_hash_table_lookup(_noti_cb_hash, GUINT_TO_POINTER(uid));

	if (noti_cb_list == NULL) {
		noti_cb_list = g_list_append(noti_cb_list, noti_cb_info_new);
		g_hash_table_insert(_noti_cb_hash, GUINT_TO_POINTER(uid), noti_cb_list);
	} else {
		noti_cb_list = g_list_append(noti_cb_list, noti_cb_info_new);
	}

	if (notification_ipc_monitor_init(uid) != NOTIFICATION_ERROR_NONE) {
		notification_unresister_changed_cb_for_uid(changed_cb, uid);
		return NOTIFICATION_ERROR_IO_ERROR;
	}

	return NOTIFICATION_ERROR_NONE;
}

EXPORT_API int notification_resister_changed_cb(
		void (*changed_cb)(void *data, notification_type_e type),
		void *user_data)
{
	return notification_resister_changed_cb_for_uid(changed_cb, user_data, getuid());
}

static gint _noti_changed_compare(gconstpointer a, gconstpointer b)
{
	const struct _notification_cb_info *info = NULL;

	if (!a)
		return -1;
	info = (notification_cb_info_s *)a;

	if (info->changed_cb == b)
		return 0;

	return 1;
}

EXPORT_API int notification_unresister_changed_cb_for_uid(
		void (*changed_cb)(void *data, notification_type_e type), uid_t uid)
{
	notification_cb_info_s *noti_cb_info;
	GList *noti_cb_list;
	GList *delete_cb_list;

	if (changed_cb == NULL)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	if (_noti_cb_hash == NULL)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	noti_cb_list = (GList *)g_hash_table_lookup(_noti_cb_hash, GUINT_TO_POINTER(uid));
	if (noti_cb_list == NULL)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	noti_cb_list = g_list_first(noti_cb_list);
	delete_cb_list = g_list_find_custom(noti_cb_list, (gconstpointer)changed_cb,
					    (GCompareFunc)_noti_changed_compare);
	if (delete_cb_list) {
		noti_cb_info = g_list_nth_data(delete_cb_list, 0);
		noti_cb_list = g_list_delete_link(noti_cb_list, delete_cb_list);
		__free_changed_cb_info(noti_cb_info);

		if (noti_cb_list == NULL) {
			g_hash_table_steal(_noti_cb_hash, GUINT_TO_POINTER(uid));
		} else {
			noti_cb_list = g_list_first(noti_cb_list);
			g_hash_table_replace(_noti_cb_hash, GUINT_TO_POINTER(uid), noti_cb_list);
		}

	} else {
		return NOTIFICATION_ERROR_INVALID_PARAMETER;
	}

	if (g_hash_table_size(_noti_cb_hash) == 0)
		notification_ipc_monitor_fini();

	return NOTIFICATION_ERROR_NONE;
}

EXPORT_API int notification_unresister_changed_cb(
		void (*changed_cb)(void *data, notification_type_e type))
{
	return notification_unresister_changed_cb_for_uid(changed_cb, getuid());
}

EXPORT_API int notification_update_progress(notification_h noti,
		int priv_id,
		double progress)
{
	int ret;
	int input_priv_id;
	char *caller_app_id;
	double input_progress;

	if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
		if (noti == NULL)
			return NOTIFICATION_ERROR_INVALID_PARAMETER;

		input_priv_id = noti->priv_id;
	} else {
		input_priv_id = priv_id;
	}

	if (noti == NULL)
		caller_app_id = notification_get_app_id_by_pid(getpid());
	else
		caller_app_id = strdup(noti->caller_app_id);

	if (progress < 0.0)
		input_progress = 0.0;
	else if (progress > 1.0)
		input_progress = 1.0;
	else
		input_progress = progress;

	ret = notification_ongoing_update_progress(caller_app_id, input_priv_id,
			input_progress);

	if (caller_app_id)
		free(caller_app_id);

	return ret;
}

EXPORT_API int notification_update_size(notification_h noti,
		int priv_id,
		double size)
{
	int ret;
	int input_priv_id;
	char *caller_app_id;
	double input_size;

	if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
		if (noti == NULL)
			return NOTIFICATION_ERROR_INVALID_PARAMETER;

		input_priv_id = noti->priv_id;
	} else {
		input_priv_id = priv_id;
	}

	if (noti == NULL)
		caller_app_id = notification_get_app_id_by_pid(getpid());
	else
		caller_app_id = strdup(noti->caller_app_id);

	if (size < 0.0)
		input_size = 0.0;
	else
		input_size = size;

	ret = notification_ongoing_update_size(caller_app_id, input_priv_id,
			input_size);

	if (caller_app_id)
		free(caller_app_id);

	return ret;
}

EXPORT_API int notification_update_content(notification_h noti,
		int priv_id,
		const char *content)
{
	char *caller_app_id;
	int input_priv_id;
	int ret;

	if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
		if (noti == NULL)
			return NOTIFICATION_ERROR_INVALID_PARAMETER;

		input_priv_id = noti->priv_id;
	} else {
		input_priv_id = priv_id;
	}

	if (noti == NULL)
		caller_app_id = notification_get_app_id_by_pid(getpid());
	else
		caller_app_id = strdup(noti->caller_app_id);

	ret = notification_ongoing_update_content(caller_app_id, input_priv_id,
			content);

	if (caller_app_id)
		free(caller_app_id);

	return ret;
}

/* notification_set_icon will be removed */
/* LCOV_EXCL_START */
EXPORT_API int notification_set_icon(notification_h noti,
		const char *icon_path)
{
	return notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, icon_path);
}
/* LCOV_EXCL_STOP */

/* notification_get_icon will be removed */
/* LCOV_EXCL_START */
EXPORT_API int notification_get_icon(notification_h noti,
		char **icon_path)
{
	int ret = NOTIFICATION_ERROR_NONE;
	char *ret_image_path = NULL;

	ret = notification_get_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
				&ret_image_path);

	if (ret == NOTIFICATION_ERROR_NONE && icon_path != NULL)
		*icon_path = ret_image_path;

	return ret;
}
/* LCOV_EXCL_STOP */

EXPORT_API int notification_translate_localized_text(notification_h noti)
{
	int ret = NOTIFICATION_ERROR_NONE;
	char *ret_text = NULL;
	char buf_key[32];
	char *bundle_val = NULL;
	char *new_text;
	bundle *b;
	notification_text_type_e type = NOTIFICATION_TEXT_TYPE_TITLE;

	noti->is_translation = false;

	for (; type <= NOTIFICATION_TEXT_TYPE_MAX; type++) {
		ret = notification_get_text(noti, type, &ret_text);
		if (ret == NOTIFICATION_ERROR_NONE && ret_text) {
			if (noti->b_text == NULL) {
				noti->b_text = bundle_create();
				if (noti->b_text == NULL)
					return NOTIFICATION_ERROR_OUT_OF_MEMORY;
			}

			b = noti->b_text;

			new_text = strdup(ret_text);

			snprintf(buf_key, sizeof(buf_key), "%d", type);
			bundle_get_str(b, buf_key, &bundle_val);
			if (bundle_val != NULL)
				bundle_del(b, buf_key);

			bundle_add_str(b, buf_key, new_text);
			free(new_text);
			new_text = NULL;

			noti->num_format_args = 0;
			bundle_val = NULL;
		}
	}

	noti->is_translation = true;

	return ret;
}

/* LCOV_EXCL_START */
EXPORT_API int notification_set_title(notification_h noti,
		const char *title,
		const char *loc_title)
{
	return notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
				title, loc_title,
				NOTIFICATION_VARIABLE_TYPE_NONE);
}
/* LCOV_EXCL_STOP */

/* LCOV_EXCL_START */
EXPORT_API int notification_get_title(notification_h noti,
		char **title,
		char **loc_title)
{
	int ret;
	char *ret_text = NULL;

	ret = notification_get_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
				&ret_text);

	if (title != NULL)
		*title = ret_text;

	if (loc_title != NULL)
		*loc_title = NULL;

	return ret;
}
/* LCOV_EXCL_STOP */

/* LCOV_EXCL_START */
EXPORT_API int notification_set_content(notification_h noti,
		const char *content,
		const char *loc_content)
{
	return notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
				content, loc_content,
				NOTIFICATION_VARIABLE_TYPE_NONE);
}
/* LCOV_EXCL_STOP */

/* LCOV_EXCL_START */
EXPORT_API int notification_get_content(notification_h noti,
		char **content,
		char **loc_content)
{
	int ret;
	char *ret_text = NULL;

	ret = notification_get_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
				&ret_text);

	if (content != NULL)
		*content = ret_text;

	if (loc_content != NULL)
		*loc_content = NULL;

	return ret;
}
/* LCOV_EXCL_STOP */

/* LCOV_EXCL_START */
EXPORT_API int notification_set_application(notification_h noti,
		const char *app_id)
{
	if (noti == NULL || app_id == NULL)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	if (noti->launch_app_id)
		free(noti->launch_app_id);

	noti->launch_app_id = strdup(app_id);

	return NOTIFICATION_ERROR_NONE;
}
/* LCOV_EXCL_STOP */

/* LCOV_EXCL_START */
EXPORT_API int notification_get_application(notification_h noti,
		char **app_id)
{
	if (noti == NULL || app_id == NULL)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	if (noti->launch_app_id)
		*app_id = noti->launch_app_id;
	else
		*app_id = noti->caller_app_id;

	return NOTIFICATION_ERROR_NONE;
}
/* LCOV_EXCL_STOP */

/* LCOV_EXCL_START */
EXPORT_API int notification_set_args(notification_h noti, bundle *args,
		bundle *group_args)
{
	if (noti == NULL || args == NULL)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	if (noti->args)
		bundle_free(noti->args);

	noti->args = bundle_dup(args);

	if (noti->group_args) {
		bundle_free(noti->group_args);
		noti->group_args = NULL;
	}

	if (group_args != NULL)
		noti->group_args = bundle_dup(group_args);

	return NOTIFICATION_ERROR_NONE;
}
/* LCOV_EXCL_STOP */

/* LCOV_EXCL_START */
EXPORT_API int notification_get_args(notification_h noti,
		bundle **args,
		bundle **group_args)
{
	if (noti == NULL || args == NULL)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	if (noti->args)
		*args = noti->args;
	else
		*args = NULL;

	if (group_args != NULL && noti->group_args)
		*group_args = noti->group_args;

	return NOTIFICATION_ERROR_NONE;
}
/* LCOV_EXCL_STOP */

/* LCOV_EXCL_START */
int notification_get_grouping_list_for_uid(notification_type_e type, int count,
		notification_list_h *list, uid_t uid)
{
	notification_list_h get_list = NULL;
	int ret = 0;

	if (list == NULL)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	ret = notification_noti_get_grouping_list(type, 1, count, &get_list, NULL, uid);
	if (ret != NOTIFICATION_ERROR_NONE)
		return ret;

	*list = get_list;

	return NOTIFICATION_ERROR_NONE;
}

EXPORT_API int notification_get_grouping_list(notification_type_e type, int count,
		notification_list_h *list)
{
	return notification_get_grouping_list_for_uid(type, count, list, getuid());
}
/* LCOV_EXCL_STOP */

/* LCOV_EXCL_START */
EXPORT_API int notification_delete_group_by_group_id(const char *app_id,
		notification_type_e type,
		int group_id)
{
	int ret;
	char *caller_app_id;

	if (app_id == NULL)
		caller_app_id = notification_get_app_id_by_pid(getpid());
	else
		caller_app_id = strdup(app_id);

	ret = notification_ipc_request_delete_multiple(type, caller_app_id, getuid());

	if (caller_app_id)
		free(caller_app_id);

	return ret;
}
/* LCOV_EXCL_STOP */

/* LCOV_EXCL_START */
int notification_delete_group_by_priv_id_for_uid(const char *app_id,
		notification_type_e type,
		int priv_id, uid_t uid)
{
	int ret;
	char *caller_app_id;

	if (app_id == NULL)
		caller_app_id = notification_get_app_id_by_pid(getpid());
	else
		caller_app_id = strdup(app_id);

	ret = notification_ipc_request_delete_single(type, caller_app_id, priv_id, uid);

	if (caller_app_id)
		free(caller_app_id);

	return ret;
}
/* LCOV_EXCL_STOP */

/* LCOV_EXCL_START */
EXPORT_API int notification_delete_group_by_priv_id(const char *app_id,
		notification_type_e type,
		int priv_id)
{
	return notification_delete_group_by_priv_id_for_uid(app_id, type, priv_id, getuid());
}

int notification_get_count_for_uid(notification_type_e type,
		const char *app_id,
		int group_id,
		int priv_id, int *count,
		uid_t uid)
{
	int ret;
	char *caller_app_id;

	if (count == NULL)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	if (app_id == NULL)
		caller_app_id = notification_get_app_id_by_pid(getpid());
	else
		caller_app_id = strdup(app_id);

	ret = notification_ipc_request_get_count(
			type,
			caller_app_id,
			group_id,
			priv_id,
			count,
			uid);

	if (caller_app_id)
		free(caller_app_id);

	return ret;
}
/* LCOV_EXCL_STOP */

/* LCOV_EXCL_START */
EXPORT_API int notification_get_count(notification_type_e type,
		const char *app_id,
		int group_id,
		int priv_id, int *count)
{
	return notification_get_count_for_uid(type, app_id, group_id, priv_id, count, getuid());
}

int notification_clear_for_uid(notification_type_e type, uid_t uid)
{
	if (type <= NOTIFICATION_TYPE_NONE || type > NOTIFICATION_TYPE_MAX)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	return notification_ipc_request_delete_multiple(type, NULL, uid);
}
/* LCOV_EXCL_STOP */

/* LCOV_EXCL_START */
EXPORT_API int notification_clear(notification_type_e type)
{
	return notification_clear_for_uid(type, getuid());
}

EXPORT_API int notification_op_get_data(notification_op *noti_op, notification_op_data_type_e type,
		void *data)
{
	if (noti_op == NULL || data == NULL)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	switch (type) {
	case NOTIFICATION_OP_DATA_TYPE:
		*((int *)data) = noti_op->type;
		break;
	case NOTIFICATION_OP_DATA_PRIV_ID:
		*((int *)data) = noti_op->priv_id;
		break;
	case NOTIFICATION_OP_DATA_NOTI:
		*((notification_h *)data) = noti_op->noti;
		break;
	case NOTIFICATION_OP_DATA_EXTRA_INFO_1:
		*((int *)data) = noti_op->extra_info_1;
		break;
	case NOTIFICATION_OP_DATA_EXTRA_INFO_2:
		*((int *)data) = noti_op->extra_info_2;
		break;
	default:
		return NOTIFICATION_ERROR_INVALID_PARAMETER;
	}

	return NOTIFICATION_ERROR_NONE;
}
/* LCOV_EXCL_STOP */

/* LCOV_EXCL_START */
EXPORT_API int notification_set_pkgname(notification_h noti,
		const char *pkgname)
{
	return notification_set_app_id(noti, pkgname);
}
/* LCOV_EXCL_STOP */

EXPORT_API int notification_set_app_id(notification_h noti,
		const char *app_id)
{
	if (noti == NULL || app_id == NULL)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	/* Remove previous caller app_id */
	if (noti->caller_app_id) {
		free(noti->caller_app_id);
		noti->caller_app_id = NULL;
	}

	noti->caller_app_id = strdup(app_id);

	return NOTIFICATION_ERROR_NONE;
}

/* LCOV_EXCL_START */
int notification_delete_all_by_type_for_uid(const char *app_id,
		notification_type_e type, uid_t uid)
{
	int ret;
	char *caller_app_id;

	if (type <= NOTIFICATION_TYPE_NONE || type > NOTIFICATION_TYPE_MAX)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	if (app_id == NULL)
		caller_app_id = notification_get_app_id_by_pid(getpid());
	else
		caller_app_id = strdup(app_id);

	ret = notification_ipc_request_delete_multiple(type, caller_app_id, uid);

	if (caller_app_id)
		free(caller_app_id);

	return ret;
}
/* LCOV_EXCL_STOP */

/* LCOV_EXCL_START */
EXPORT_API int notification_delete_all_by_type(const char *app_id,
		notification_type_e type)
{
	return notification_delete_all_by_type_for_uid(app_id, type, getuid());
}

int notification_delete_by_priv_id_for_uid(const char *app_id,
		notification_type_e type,
		int priv_id,
		uid_t uid)
{
	int ret;
	char *caller_app_id;

	if (priv_id <= NOTIFICATION_PRIV_ID_NONE)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	if (app_id == NULL)
		caller_app_id = notification_get_app_id_by_pid(getpid());
	else
		caller_app_id = strdup(app_id);

	ret = notification_ipc_request_delete_single(type, caller_app_id, priv_id, uid);

	if (caller_app_id)
		free(caller_app_id);

	return ret;
}
/* LCOV_EXCL_STOP */

/* LCOV_EXCL_START */
EXPORT_API int notification_delete_by_priv_id(const char *app_id,
		notification_type_e type,
		int priv_id)
{
	return notification_delete_by_priv_id_for_uid(app_id, type, priv_id, getuid());
}

EXPORT_API int notification_set_execute_option(notification_h noti,
		notification_execute_type_e type,
		const char *text,
		const char *key,
		bundle *service_handle)
{
	char buf_key[32] = { 0, };
	char *ret_val = NULL;
	bundle *b = NULL;

	if (noti == NULL)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
			|| type > NOTIFICATION_EXECUTE_TYPE_MAX)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	if (noti->b_execute_option == NULL)
		noti->b_execute_option = bundle_create();

	b = noti->b_execute_option;

	if (text != NULL) {
		snprintf(buf_key, sizeof(buf_key), "text%d", type);

		bundle_get_str(b, buf_key, &ret_val);
		if (ret_val != NULL)
			bundle_del(b, buf_key);

		bundle_add_str(b, buf_key, text);
	}

	if (key != NULL) {
		snprintf(buf_key, sizeof(buf_key), "key%d", type);

		bundle_get_str(b, buf_key, &ret_val);
		if (ret_val != NULL)
			bundle_del(b, buf_key);

		bundle_add_str(b, buf_key, key);
	}

	switch ((int)type) {
	case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
		if (noti->b_service_responding != NULL) {
			bundle_free(noti->b_service_responding);
			noti->b_service_responding = NULL;
		}

		if (service_handle != NULL)
			noti->b_service_responding = bundle_dup(service_handle);

		break;
	case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
		if (noti->b_service_single_launch != NULL) {
			bundle_free(noti->b_service_single_launch);
			noti->b_service_single_launch = NULL;
		}

		if (service_handle != NULL)
			noti->b_service_single_launch =
				bundle_dup(service_handle);

		break;
	case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
		if (noti->b_service_multi_launch != NULL) {
			bundle_free(noti->b_service_multi_launch);
			noti->b_service_multi_launch = NULL;
		}

		if (service_handle != NULL)
			noti->b_service_multi_launch =
				bundle_dup(service_handle);

		break;
	}

	return NOTIFICATION_ERROR_NONE;
}
/* LCOV_EXCL_STOP */

/* LCOV_EXCL_START */
EXPORT_API int notification_get_id(notification_h noti,
		int *group_id, int *priv_id)
{
	if (noti == NULL)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	if (group_id) {
		if (noti->group_id < NOTIFICATION_GROUP_ID_NONE)
			*group_id = NOTIFICATION_GROUP_ID_NONE;
		else
			*group_id = noti->group_id;
	}

	if (priv_id)
		*priv_id = noti->priv_id;

	return NOTIFICATION_ERROR_NONE;
}
/* LCOV_EXCL_STOP */

EXPORT_API int notification_set_priv_id(notification_h noti, int priv_id)
{
	if (noti == NULL || priv_id <= 0)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	noti->priv_id = priv_id;

	return NOTIFICATION_ERROR_NONE;
}

/* LCOV_EXCL_START */
notification_h notification_load_for_uid(char *app_id,
		int priv_id, uid_t uid)
{
	int ret;
	notification_h noti;

	noti = (notification_h)calloc(1, sizeof(struct _notification));
	if (noti == NULL) {
		ERR("Failed to alloc memory");
		set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
		return NULL;
	}

	ret = notification_ipc_request_load_noti_by_priv_id(noti, app_id, priv_id, uid);
	if (ret != NOTIFICATION_ERROR_NONE) {
		notification_free(noti);
		set_last_result(ret);
		return NULL;
	}

	set_last_result(NOTIFICATION_ERROR_NONE);

	return noti;
}
/* LCOV_EXCL_STOP */

/* LCOV_EXCL_START */
EXPORT_API notification_h notification_load(char *app_id,
		int priv_id)
{
	return notification_load_for_uid(app_id, priv_id, getuid());
}
/* LCOV_EXCL_STOP */

/* LCOV_EXCL_START */
EXPORT_API notification_h notification_new(notification_type_e type,
		int group_id, int priv_id)
{
	return notification_create(type);
}

static void _notification_get_text_domain(notification_h noti)
{
}
/* LCOV_EXCL_STOP */

/* LCOV_EXCL_START */
EXPORT_API int notification_get_execute_option(notification_h noti,
		notification_execute_type_e type,
		const char **text,
		bundle **service_handle)
{
	char buf_key[32] = { 0, };
	char *ret_val = NULL;
	char *get_str = NULL;
	bundle *b = NULL;

	if (noti == NULL)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
			|| type > NOTIFICATION_EXECUTE_TYPE_MAX)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	switch (type) {
	case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
		b = noti->b_service_responding;
		break;
	case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
		b = noti->b_service_single_launch;
		break;
	case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
		b = noti->b_service_multi_launch;
		break;
	default:
		break;
	}

	if (b != NULL) {
		if (text != NULL) {
			if (noti->domain == NULL || noti->dir == NULL)
				_notification_get_text_domain(noti);

			snprintf(buf_key, sizeof(buf_key), "key%d", type);

			bundle_get_str(b, buf_key, &ret_val);
			if (ret_val != NULL && noti->domain != NULL
					&& noti->dir != NULL) {
				bindtextdomain(noti->domain, noti->dir);

				get_str = dgettext(noti->domain, ret_val);

				*text = get_str;
			} else if (ret_val != NULL) {
				get_str = dgettext("sys_string", ret_val);

				*text = get_str;
			} else {
				snprintf(buf_key, sizeof(buf_key), "text%d",
						type);

				bundle_get_str(b, buf_key, &ret_val);

				*text = ret_val;
			}
		}
	}

	if (service_handle != NULL)
		*service_handle = b;

	return NOTIFICATION_ERROR_NONE;
}
/* LCOV_EXCL_STOP */

EXPORT_API int notification_insert_for_uid(notification_h noti,
		int *priv_id, uid_t uid)
{
	int ret;
	int id;

	if (noti == NULL)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	if (noti->type <= NOTIFICATION_TYPE_NONE
			|| noti->type > NOTIFICATION_TYPE_MAX)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	noti->uid = uid;
	noti->insert_time = time(NULL);

	ret = notification_ipc_request_insert(noti, &id);
	if (ret != NOTIFICATION_ERROR_NONE)
		return ret;

	noti->priv_id = id;

	/* If priv_id is valid data, set priv_id */
	if (priv_id != NULL)
		*priv_id = noti->priv_id;

	return NOTIFICATION_ERROR_NONE;
}

EXPORT_API int notification_insert(notification_h noti,
		int *priv_id)
{
	return notification_insert_for_uid(noti, priv_id, getuid());
}

EXPORT_API int notification_update_async_for_uid(notification_h noti,
		void (*result_cb)(int priv_id, int result, void *data), void *user_data, uid_t uid)
{
	if (noti == NULL)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	noti->uid = uid;
	/* Update insert time ? */
	noti->insert_time = time(NULL);

	return notification_ipc_request_update_async(noti, result_cb, user_data);
}

EXPORT_API int notification_update_async(notification_h noti,
		void (*result_cb)(int priv_id, int result, void *data), void *user_data)
{
	return notification_update_async_for_uid(noti, result_cb, user_data, getuid());
}

EXPORT_API int notification_register_detailed_changed_cb_for_uid(
		void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
		void *user_data, uid_t uid)
{
	GList *noti_cb_list = NULL;
	notification_cb_info_s *noti_cb_info_new = NULL;

	if (detailed_changed_cb == NULL)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	if (_noti_cb_hash == NULL)
		_noti_cb_hash = g_hash_table_new(g_direct_hash, g_direct_equal);

	noti_cb_info_new = (notification_cb_info_s *)malloc(sizeof(notification_cb_info_s));
	if (noti_cb_info_new == NULL) {
		/* LCOV_EXCL_START */
		ERR("Failed to alloc memory");
		return NOTIFICATION_ERROR_OUT_OF_MEMORY;
		/* LCOV_EXCL_STOP */
	}

	noti_cb_info_new->cb_type = NOTIFICATION_CB_DETAILED;
	noti_cb_info_new->changed_cb = NULL;
	noti_cb_info_new->detailed_changed_cb = detailed_changed_cb;
	noti_cb_info_new->data = user_data;

	noti_cb_list = g_hash_table_lookup(_noti_cb_hash, GUINT_TO_POINTER(uid));

	if (noti_cb_list == NULL) {
		noti_cb_list = g_list_append(noti_cb_list, noti_cb_info_new);
		g_hash_table_insert(_noti_cb_hash, GUINT_TO_POINTER(uid), noti_cb_list);
	} else {
		noti_cb_list = g_list_append(noti_cb_list, noti_cb_info_new);
	}

	if (notification_ipc_monitor_init(uid) != NOTIFICATION_ERROR_NONE) {
		notification_unregister_detailed_changed_cb_for_uid(detailed_changed_cb, user_data, uid);
		return NOTIFICATION_ERROR_IO_ERROR;
	}

	return NOTIFICATION_ERROR_NONE;
}

EXPORT_API int notification_register_detailed_changed_cb(
		void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
		void *user_data)
{
	return notification_register_detailed_changed_cb_for_uid(detailed_changed_cb, user_data, getuid());
}

static gint _noti_detailed_changed_compare(gconstpointer a, gconstpointer b)
{
	const struct _notification_cb_info *info = NULL;

	if (!a)
		return -1;
	info = (notification_cb_info_s *)a;

	if (info->detailed_changed_cb == b)
		return 0;

	return 1;
}

EXPORT_API int notification_unregister_detailed_changed_cb_for_uid(
		void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
		void *user_data, uid_t uid)
{
	notification_cb_info_s *noti_cb_info;
	GList *noti_cb_list;
	GList *delete_cb_list;

	if (detailed_changed_cb == NULL)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	if (_noti_cb_hash == NULL)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	noti_cb_list = (GList *)g_hash_table_lookup(_noti_cb_hash, GUINT_TO_POINTER(uid));

	if (noti_cb_list == NULL)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	noti_cb_list = g_list_first(noti_cb_list);
	delete_cb_list = g_list_find_custom(noti_cb_list, (gconstpointer)detailed_changed_cb,
					    (GCompareFunc)_noti_detailed_changed_compare);

	if (delete_cb_list) {
		noti_cb_info = (notification_cb_info_s *)g_list_nth_data(delete_cb_list, 0);
		noti_cb_list = g_list_delete_link(noti_cb_list, delete_cb_list);
		__free_changed_cb_info(noti_cb_info);
		if (noti_cb_list == NULL) {
			g_hash_table_steal(_noti_cb_hash, GUINT_TO_POINTER(uid));
		} else {
			noti_cb_list = g_list_first(noti_cb_list);
			g_hash_table_replace(_noti_cb_hash, GUINT_TO_POINTER(uid), noti_cb_list);
		}

	} else {
		return NOTIFICATION_ERROR_INVALID_PARAMETER;
	}

	if (g_hash_table_size(_noti_cb_hash) == 0)
		notification_ipc_monitor_fini();

	return NOTIFICATION_ERROR_NONE;

}

EXPORT_API int notification_unregister_detailed_changed_cb(
		void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
		void *user_data)
{
	return notification_unregister_detailed_changed_cb_for_uid(detailed_changed_cb, user_data, getuid());
}

/* LCOV_EXCL_START */
EXPORT_API int notification_is_service_ready(void)
{
	return notification_ipc_is_master_ready();
}
/* LCOV_EXCL_STOP */

EXPORT_API int notification_set_uid(notification_h noti,
		uid_t uid)
{
	if (noti == NULL)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	noti->uid = uid;
	return NOTIFICATION_ERROR_NONE;
}

EXPORT_API int notification_get_uid(notification_h noti,
		uid_t *uid)
{
	if (noti == NULL || uid == NULL)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	*uid = noti->uid;
	return NOTIFICATION_ERROR_NONE;
}

static GList *__copy_private_file(notification_h noti)
{
	bundle *dst_b;
	bundle *src_b;
	char buf_key[32];
	char *src_path;
	char *dst_path;
	int i;
	GList *file_list = NULL;
	int ret;

	if (noti->b_priv_image_path && noti->b_image_path) {
		dst_b = noti->b_priv_image_path;
		src_b = noti->b_image_path;
		for (i = NOTIFICATION_IMAGE_TYPE_ICON; i <= NOTIFICATION_IMAGE_TYPE_MAX; i++) {
			src_path = NULL;
			dst_path = NULL;

			snprintf(buf_key, sizeof(buf_key), "%d", i);

			bundle_get_str(dst_b, buf_key, &dst_path);
			if (dst_path == NULL)
				continue;

			bundle_get_str(src_b, buf_key, &src_path);
			if (src_path == NULL)
				continue;

			ret = notification_copy_private_file(src_path, dst_path);
			if (ret == NOTIFICATION_ERROR_NONE)
				file_list = g_list_append(file_list, strdup(dst_path));
		}
	}
	if (noti->sound_path && noti->priv_sound_path) {
		ret = notification_copy_private_file(noti->sound_path,
						     noti->priv_sound_path);
		if (ret == NOTIFICATION_ERROR_NONE)
			file_list = g_list_append(file_list,
						  strdup(noti->priv_sound_path));
	}

	if (noti->vibration_path && noti->priv_vibration_path) {
		ret = notification_copy_private_file(noti->vibration_path,
						     noti->priv_vibration_path);
		if (ret == NOTIFICATION_ERROR_NONE)
			file_list = g_list_append(file_list,
						  strdup(noti->priv_vibration_path));
	}

	return file_list;
}

/* LCOV_EXCL_START */
static void __remove_private_file(gpointer data, gpointer user_data)
{
	GFile *src = NULL;
	char *path = (char *)data;

	src = g_file_new_for_path(path);
	if (src) {
		g_file_delete(src, NULL, NULL);
		g_object_unref(src);
	}
}
/* LCOV_EXCL_STOP */

EXPORT_API int notification_post_for_uid(notification_h noti, uid_t uid)
{
	int ret = 0;
	int id = 0;
	GList *file_list;

	if (noti == NULL)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	if (noti->type <= NOTIFICATION_TYPE_NONE
			|| noti->type > NOTIFICATION_TYPE_MAX)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	/* Save insert time */
	noti->insert_time = time(NULL);
	noti->uid = uid;

	file_list = __copy_private_file(noti);
	ret = notification_ipc_request_insert(noti, &id);
	if (ret == NOTIFICATION_ERROR_NONE) {
		noti->priv_id = id;
		INFO("Posted notification id[%d]", id);
	} else {
		g_list_foreach(file_list, __remove_private_file, NULL);
	}

	if (file_list)
		g_list_free_full(file_list, free);

	return ret;
}

EXPORT_API int notification_update_for_uid(notification_h noti, uid_t uid)
{
	if (noti == NULL) {
		notification_ipc_request_refresh(uid);
		return NOTIFICATION_ERROR_INVALID_PARAMETER;
	}

	noti->uid = uid;
	/* Update insert time ? */
	noti->insert_time = time(NULL);

	return notification_ipc_request_update(noti);
}

EXPORT_API int notification_delete_for_uid(notification_h noti, uid_t uid)
{
	if (noti == NULL)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	return notification_ipc_request_delete_single(NOTIFICATION_TYPE_NONE,
				noti->caller_app_id, noti->priv_id, uid);
}

EXPORT_API int notification_delete_all_for_uid(notification_type_e type, uid_t uid)
{
	int ret = 0;
	char *caller_app_id = NULL;

	if (type <= NOTIFICATION_TYPE_NONE || type > NOTIFICATION_TYPE_MAX)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	caller_app_id = notification_get_app_id_by_pid(getpid());

	ret = notification_ipc_request_delete_multiple(type, caller_app_id, uid);

	if (caller_app_id)
		free(caller_app_id);

	return ret;
}

EXPORT_API notification_h notification_load_by_tag_for_uid(const char *tag, uid_t uid)
{
	int ret;
	notification_h noti;
	char *caller_app_id;

	if (tag == NULL) {
		ERR("Invalid tag");
		set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
		return NULL;
	}

	caller_app_id = notification_get_app_id_by_pid(getpid());
	if (!caller_app_id) {
		/* LCOV_EXCL_START */
		ERR("Failed to get a package name");
		set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
		return NULL;
		/* LCOV_EXCL_STOP */
	}

	noti = (notification_h)calloc(1, sizeof(struct _notification));
	if (noti == NULL) {
		/* LCOV_EXCL_START */
		ERR("Failed to alloc a new notification");
		set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
		free(caller_app_id);

		return NULL;
		/* LCOV_EXCL_STOP */
	}

	ret = notification_ipc_request_load_noti_by_tag(noti, caller_app_id, (char *)tag, uid);
	free(caller_app_id);

	set_last_result(ret);
	if (ret != NOTIFICATION_ERROR_NONE) {
		notification_free(noti);
		return NULL;
	}

	return noti;
}

EXPORT_API notification_h notification_create_from_package_template(const char *app_id, const char *template_name)
{
	int ret;
	notification_h noti;

	if (app_id == NULL || template_name == NULL) {
		ERR("Invalid parameter");
		set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
		return NULL;
	}

	noti = (notification_h)calloc(1, sizeof(struct _notification));
	if (noti == NULL) {
		/* LCOV_EXCL_START */
		ERR("Failed to alloc memory");
		set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
		return NULL;
		/* LCOV_EXCL_STOP */
	}

	ret = notification_ipc_request_create_from_package_template(noti, app_id, template_name);
	set_last_result(ret);
	if (ret != NOTIFICATION_ERROR_NONE) {
		notification_free(noti);
		return NULL;
	}

	return noti;
}

EXPORT_API int notification_set_default_button(notification_h noti, notification_button_index_e index)
{
	if (noti == NULL)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	if (index < 0 || index > NOTIFICATION_BUTTON_6)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	noti->default_button_index = index;

	return NOTIFICATION_ERROR_NONE;
}

EXPORT_API int notification_get_default_button(notification_h noti, notification_button_index_e *index)
{
	if (noti == NULL || index == NULL)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	*index = noti->default_button_index;

	return NOTIFICATION_ERROR_NONE;
}

EXPORT_API int notification_get_ongoing_value_type(notification_h noti, notification_ongoing_value_type_e *type)
{
	if (noti == NULL || type == NULL)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	*type = noti->ongoing_value_type;

	return NOTIFICATION_ERROR_NONE;
}

EXPORT_API int notification_set_ongoing_value_type(notification_h noti, notification_ongoing_value_type_e type)
{
	if (noti == NULL)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	if (type < NOTIFICATION_ONGOING_VALUE_TYPE_PERCENT || type > NOTIFICATION_ONGOING_VALUE_TYPE_TIME)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	noti->ongoing_value_type = type;

	return NOTIFICATION_ERROR_NONE;
}

EXPORT_API int notification_get_ongoing_time(notification_h noti, int *current, int *duration)
{
	if (noti == NULL || current == NULL || duration == NULL)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	*current = noti->ongoing_current;
	*duration = noti->ongoing_duration;

	return NOTIFICATION_ERROR_NONE;
}

EXPORT_API int notification_set_ongoing_time(notification_h noti, int current, int duration)
{
	if (noti == NULL)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	if (current < 0 || duration < 0 || current > duration)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	noti->ongoing_current = current;
	noti->ongoing_duration = duration;

	return NOTIFICATION_ERROR_NONE;
}

EXPORT_API int notification_get_hide_timeout(notification_h noti, int *timeout)
{
	if (noti == NULL || timeout == NULL)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	*timeout = noti->hide_timeout;

	return NOTIFICATION_ERROR_NONE;
}

EXPORT_API int notification_set_hide_timeout(notification_h noti, int timeout)
{
	if (noti == NULL || timeout < 0)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	noti->hide_timeout = timeout;

	return NOTIFICATION_ERROR_NONE;
}

EXPORT_API int notification_get_delete_timeout(notification_h noti, int *timeout)
{
	if (noti == NULL || timeout == NULL)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	*timeout = noti->delete_timeout;

	return NOTIFICATION_ERROR_NONE;
}

EXPORT_API int notification_set_delete_timeout(notification_h noti, int timeout)
{
	if (noti == NULL || timeout < 0)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	noti->delete_timeout = timeout;

	return NOTIFICATION_ERROR_NONE;
}

EXPORT_API int notification_get_text_input_max_length(notification_h noti, int *text_input_max_length)
{
	if (noti == NULL || text_input_max_length == NULL)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	*text_input_max_length = noti->text_input_max_length;

	return NOTIFICATION_ERROR_NONE;
}

EXPORT_API int notification_post_with_event_cb_for_uid(notification_h noti, event_handler_cb cb,
							void *userdata, uid_t uid)
{
	int ret;
	int priv_id;
	notification_event_cb_info_s *info = NULL;
	GList *find_list;

	if (noti == NULL || cb == NULL)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	if (noti->type <= NOTIFICATION_TYPE_NONE || noti->type > NOTIFICATION_TYPE_MAX)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	noti->insert_time = time(NULL);
	noti->event_flag = true;
	noti->uid = uid;

	ret = notification_ipc_request_insert(noti, &priv_id);
	if (ret != NOTIFICATION_ERROR_NONE)
		return ret;

	noti->priv_id = priv_id;

	__noti_event_cb_list = g_list_first(__noti_event_cb_list);
	find_list = g_list_find_custom(__noti_event_cb_list, GINT_TO_POINTER(priv_id),
				       (GCompareFunc)__priv_id_compare);

	if (find_list) {
		info = g_list_nth_data(find_list, 0);
		info->cb = cb;
		info->userdata = userdata;
	} else {
		info = (notification_event_cb_info_s *)malloc(sizeof(notification_event_cb_info_s));
		if (info == NULL) {
			/* LCOV_EXCL_START */
			ERR("Failed to alloc memory");
			return NOTIFICATION_ERROR_OUT_OF_MEMORY;
			/* LCOV_EXCL_STOP */
		}
		info->priv_id = priv_id;
		info->cb = cb;
		info->userdata = userdata;
		__noti_event_cb_list = g_list_append(__noti_event_cb_list, info);
	}

	return ret;
}

EXPORT_API int notification_post_with_event_cb(notification_h noti, event_handler_cb cb, void *userdata)
{
	return notification_post_with_event_cb_for_uid(noti, cb, userdata, getuid());
}

EXPORT_API int notification_send_event(notification_h noti, int event_type)
{
	int ret;
	bool event_flag;

	if (noti == NULL)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	if (!((event_type >= NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1
		&& event_type <= NOTIFICATION_EVENT_TYPE_MAX) ||
		(event_type >= NOTIFICATION_EVENT_TYPE_HIDDEN_BY_USER
		&& event_type <= NOTIFICATION_EVENT_TYPE_HIDDEN_BY_EXTERNAL) ||
		(event_type >= NOTIFICATION_EVENT_TYPE_PRESSED
		&& event_type <= NOTIFICATION_EVENT_TYPE_DELETED)))
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	ret = notification_get_event_flag(noti, &event_flag);
	if (ret != NOTIFICATION_ERROR_NONE || event_flag == false)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	ret = notification_ipc_send_event(noti, event_type, -1);

	return ret;
}

EXPORT_API int notification_send_event_by_priv_id(int priv_id, int event_type)
{
	int ret;

	if (priv_id <= 0)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	if (!((event_type >= NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1
		&& event_type <= NOTIFICATION_EVENT_TYPE_MAX) ||
		(event_type >= NOTIFICATION_EVENT_TYPE_HIDDEN_BY_USER
		&& event_type <= NOTIFICATION_EVENT_TYPE_HIDDEN_BY_EXTERNAL) ||
		(event_type >= NOTIFICATION_EVENT_TYPE_PRESSED
		&& event_type <= NOTIFICATION_EVENT_TYPE_DELETED)))
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	ret = notification_ipc_send_event(NULL, event_type, priv_id);
	return ret;
}

EXPORT_API int notification_get_event_flag(notification_h noti, bool *flag)
{
	if (noti == NULL || flag == NULL)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	*flag = noti->event_flag;

	return NOTIFICATION_ERROR_NONE;
}

EXPORT_API int notification_check_event_receiver_available(notification_h noti, bool *available)
{
	int ret;
	int priv_id;

	if (noti == NULL || available == NULL)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	ret = notification_get_id(noti, NULL, &priv_id);
	if (ret != NOTIFICATION_ERROR_NONE) {
		ERR("Failed to get priv id");
		return ret;
	}

	ret = notification_ipc_check_event_receiver(priv_id, available);

	return ret;
}

static bundle *_create_bundle_from_bundle_raw(bundle_raw *string)
{
	if (string == NULL || string[0] == '\0')
		return NULL;

	return bundle_decode(string, strlen((char *)string));
}

EXPORT_API int notification_set_extention_data(notification_h noti, const char *key, bundle *value)
{
	return notification_set_extension_data(noti, key, value);
}

EXPORT_API int notification_set_extension_data(notification_h noti, const char *key, bundle *value)
{
	int ret;
	int len = 0;
	char *del = NULL;
	bundle_raw *raw = NULL;

	if (noti == NULL || key == NULL)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	if (noti->args == NULL)
		noti->args = bundle_create();

	if (value == NULL) {
		ret = bundle_del(noti->args, key);
		if (ret == BUNDLE_ERROR_NONE)
			return NOTIFICATION_ERROR_NONE;
		else
			return NOTIFICATION_ERROR_INVALID_PARAMETER;
	}

	bundle_get_str(noti->args, key, &del);
	if (del != NULL) {
		bundle_del(noti->args, key);
		del = NULL;
	}

	bundle_encode(value, &raw, &len);
	bundle_add_str(noti->args, key, (const char *)raw);
	bundle_free_encoded_rawdata(&raw);

	return NOTIFICATION_ERROR_NONE;
}

EXPORT_API int notification_get_extention_data(notification_h noti, const char *key, bundle **value)
{
	return notification_get_extension_data(noti, key, value);
}

EXPORT_API int notification_get_extension_data(notification_h noti, const char *key, bundle **value)
{
	char *ret_str;
	bundle *args;

	if (noti == NULL || key == NULL || value == NULL)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	if (noti->args == NULL)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	args = noti->args;

	bundle_get_str(args, key, &ret_str);
	if (ret_str == NULL)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	*value = _create_bundle_from_bundle_raw((bundle_raw *)ret_str);
	if (*value == NULL)
		return NOTIFICATION_ERROR_IO_ERROR;

	return NOTIFICATION_ERROR_NONE;
}

#define KEY_LEN 40
#define EXTENSION_EVENT_KEY "_NOTIFICATION_EXTENSION_EVENT_"
EXPORT_API int notification_set_extension_event_handler(notification_h noti,
					notification_event_type_extension_e event,
					app_control_h event_handler)
{
	int err;
	int ret = NOTIFICATION_ERROR_NONE;
	int len;
	bundle *app_control_bundle = NULL;
	bundle_raw *b_raw = NULL;
	char key[KEY_LEN];
	char *del = NULL;

	if (noti == NULL || event_handler == NULL) {
		ERR("Invalid parameter");
		return NOTIFICATION_ERROR_INVALID_PARAMETER;
	}

	if (event < NOTIFICATION_EVENT_TYPE_HIDDEN_BY_USER ||
	    event > NOTIFICATION_EVENT_TYPE_HIDDEN_BY_EXTERNAL) {
		ERR("Invalid event [%d]", event);
		return NOTIFICATION_ERROR_INVALID_PARAMETER;
	}

	if (noti->args == NULL)
		noti->args = bundle_create();

	snprintf(key, sizeof(key), "%s%d", EXTENSION_EVENT_KEY, event);
	bundle_get_str(noti->args, key, &del);
	if (del != NULL) {
		bundle_del(noti->args, key);
		del = NULL;
	}

	err = app_control_export_as_bundle(event_handler, &app_control_bundle);
	if (err != APP_CONTROL_ERROR_NONE) {
		/* LCOV_EXCL_START */
		ERR("Failed to export app_control to bundle [%d]", err);
		ret = NOTIFICATION_ERROR_IO_ERROR;
		goto out;
		/* LCOV_EXCL_STOP */
	}

	err = bundle_encode(app_control_bundle, &b_raw, &len);
	if (err != BUNDLE_ERROR_NONE) {
		/* LCOV_EXCL_START */
		ERR("Failed to encode bundle [%d]", err);
		ret = NOTIFICATION_ERROR_IO_ERROR;
		goto out;
		/* LCOV_EXCL_STOP */
	}

	err = bundle_add_str(noti->args, key, (const char *)b_raw);
	if (err != BUNDLE_ERROR_NONE) {
		/* LCOV_EXCL_START */
		ERR("Failed to add str to bundle [%d]", err);
		ret = NOTIFICATION_ERROR_IO_ERROR;
		goto out;
		/* LCOV_EXCL_STOP */
	}

out:
	if (b_raw)
		bundle_free_encoded_rawdata(&b_raw);
	if (app_control_bundle)
		bundle_free(app_control_bundle);

	return ret;
}

EXPORT_API int notification_get_extension_event_handler(notification_h noti,
					notification_event_type_extension_e event,
					app_control_h *event_handler)
{
	int err;
	int ret = NOTIFICATION_ERROR_NONE;
	char *ret_str = NULL;
	char key[KEY_LEN];
	bundle *app_control_bundle = NULL;
	app_control_h ret_app_control = NULL;

	if (noti == NULL || event_handler == NULL) {
		ERR("Invalid parameter");
		return NOTIFICATION_ERROR_INVALID_PARAMETER;
	}

	if (event < NOTIFICATION_EVENT_TYPE_HIDDEN_BY_USER ||
	    event > NOTIFICATION_EVENT_TYPE_HIDDEN_BY_EXTERNAL) {
		ERR("Invalid event [%d]", event);
		return NOTIFICATION_ERROR_INVALID_PARAMETER;
	}

	snprintf(key, sizeof(key), "%s%d", EXTENSION_EVENT_KEY, event);

	bundle_get_str(noti->args, key, &ret_str);
	if (ret_str == NULL) {
		ERR("No handler, Invalid event[%d]", event);
		return NOTIFICATION_ERROR_INVALID_PARAMETER;
	}

	app_control_bundle = _create_bundle_from_bundle_raw((bundle_raw *)ret_str);
	if (app_control_bundle == NULL) {
		/* LCOV_EXCL_START */
		ERR("Failed to create bundle");
		return NOTIFICATION_ERROR_IO_ERROR;
		/* LCOV_EXCL_STOP */
	}

	err = app_control_create(&ret_app_control);
	if (err != APP_CONTROL_ERROR_NONE) {
		/* LCOV_EXCL_START */
		ERR("Failed to create app control [%d]", err);
		ret = NOTIFICATION_ERROR_IO_ERROR;
		goto out;
		/* LCOV_EXCL_STOP */
	}

	err = app_control_import_from_bundle(ret_app_control, app_control_bundle);
	if (err != APP_CONTROL_ERROR_NONE) {
		/* LCOV_EXCL_START */
		ERR("Failed to import app control from bundle [%d]", err);
		app_control_destroy(ret_app_control);
		ret = NOTIFICATION_ERROR_IO_ERROR;
		goto out;
		/* LCOV_EXCL_STOP */
	}

	*event_handler = ret_app_control;

out:
	if (app_control_bundle)
		bundle_free(app_control_bundle);

	return ret;
}

EXPORT_API int notification_get_all_count_for_uid(notification_type_e type, int *count, uid_t uid)
{
	int ret;

	if (count == NULL) {
		ERR("Invalid parameter - count is null");
		return NOTIFICATION_ERROR_INVALID_PARAMETER;
	}

	if (type < NOTIFICATION_TYPE_NONE || type > NOTIFICATION_TYPE_MAX) {
		ERR("Invalid parameter - wrong type");
		return NOTIFICATION_ERROR_INVALID_PARAMETER;
	}

	ret = notification_ipc_request_get_all_count(type, count, uid);
	if (ret != NOTIFICATION_ERROR_NONE) {
		ERR("Failed to get count [%d]", ret);
		return ret;
	}

	return ret;
}

EXPORT_API int notification_get_all_count(notification_type_e type, int *count)
{
	return notification_get_all_count_for_uid(type, count, getuid());
}

EXPORT_API int notification_set_app_label(notification_h noti, char *label)
{
	if (noti == NULL || label == NULL)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	if (noti->app_label)
		free(noti->app_label);

	noti->app_label = strdup(label);

	return NOTIFICATION_ERROR_NONE;
}

EXPORT_API int notification_get_app_label(notification_h noti, char **label)
{
	if (noti == NULL || label == NULL)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	if (noti->app_label)
		*label = noti->app_label;

	return NOTIFICATION_ERROR_NONE;
}

static void __set_caller_info(bundle *b, const char *appid, uid_t uid)
{
	pkgmgrinfo_appinfo_h handle;
	char buf[12];
	char *pkgid = NULL;
	int r;

	snprintf(buf, sizeof(buf), "%u", uid);
	bundle_del(b, AUL_K_ORG_CALLER_UID);
	bundle_add(b, AUL_K_ORG_CALLER_UID, buf);

	bundle_del(b, AUL_K_ORG_CALLER_APPID);
	bundle_add(b, AUL_K_ORG_CALLER_APPID, appid);

	r = pkgmgrinfo_appinfo_get_usr_appinfo(appid, uid, &handle);
	if (r != PMINFO_R_OK)
		return;

	pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
	if (pkgid) {
		bundle_del(b, AUL_K_ORG_CALLER_PKGID);
		bundle_add(b, AUL_K_ORG_CALLER_PKGID, pkgid);
	}
	pkgmgrinfo_appinfo_destroy_appinfo(handle);
}

static void __set_indirect_request(bundle *b)
{
	bundle_del(b, AUL_K_REQUEST_TYPE);
	bundle_add(b, AUL_K_REQUEST_TYPE, "indirect-request");
}

EXPORT_API int notification_set_indirect_request(notification_h noti,
		pid_t pid, uid_t uid)
{
	char appid[256] = { 0, };
	int r;
	int i;

	if (noti == NULL || pid <= 1 || uid < REGULAR_UID_MIN)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	r = aul_app_get_appid_bypid(pid, appid, sizeof(appid));
	if (r != AUL_R_OK)
		return NOTIFICATION_ERROR_INVALID_PARAMETER;

	if (noti->b_service_responding) {
		__set_caller_info(noti->b_service_responding, appid, uid);
		__set_indirect_request(noti->b_service_responding);
	}

	if (noti->b_service_single_launch) {
		__set_caller_info(noti->b_service_single_launch, appid, uid);
		__set_indirect_request(noti->b_service_single_launch);
	}

	if (noti->b_service_multi_launch) {
		__set_caller_info(noti->b_service_multi_launch, appid, uid);
		__set_indirect_request(noti->b_service_multi_launch);
	}

	for (i = 0; i <= NOTIFICATION_EVENT_TYPE_MAX; i++) {
		if (noti->b_event_handler[i]) {
			__set_caller_info(noti->b_event_handler[i], appid, uid);
			__set_indirect_request(noti->b_event_handler[i]);
		}
	}

	return NOTIFICATION_ERROR_NONE;
}