summaryrefslogtreecommitdiff
path: root/src/common/media-svc.c
blob: 5861df23e8132ee0fe76ca5af712a8d88d768186 (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
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
/*
 * libmedia-service
 *
 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
 *
 * Contact: Hyunjun Ko <zzoon.ko@samsung.com>, Haejeong Kim <backto.kim@samsung.com>
 *
 * 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 <string.h>
#include <errno.h>
#include <media-util.h>
#include "media-svc.h"
#include "media-svc-media.h"
#include "media-svc-debug.h"
#include "media-svc-util.h"
#include "media-svc-db-utils.h"
#include "media-svc-env.h"
#include "media-svc-media-folder.h"
#include "media-svc-album.h"
#include "media-svc-noti.h"
#include "media-svc-storage.h"

static __thread int g_media_svc_item_validity_data_cnt = 1;
static __thread int g_media_svc_item_validity_cur_data_cnt = 0;

static __thread int g_media_svc_move_item_data_cnt = 1;
static __thread int g_media_svc_move_item_cur_data_cnt = 0;

static __thread int g_media_svc_insert_item_data_cnt = 1;
static __thread int g_media_svc_insert_item_cur_data_cnt = 0;

static __thread int g_media_svc_update_item_data_cnt = 1;
static __thread int g_media_svc_update_item_cur_data_cnt = 0;

static __thread int g_media_svc_insert_folder_data_cnt = 1;
static __thread int g_media_svc_insert_folder_cur_data_cnt = 0;

/* Flag for items to be published by notification */
static __thread int g_insert_with_noti = FALSE;

#define DEFAULT_MEDIA_SVC_STORAGE_ID "media"

typedef struct {
	int media_type;
	char *path;
} media_svc_item_info_s;

static bool __media_svc_check_storage(media_svc_storage_type_e storage_type, bool check_all)
{
	if (check_all == TRUE) {
		if ((storage_type != MEDIA_SVC_STORAGE_INTERNAL)
			&& (storage_type != MEDIA_SVC_STORAGE_EXTERNAL)
			&& (storage_type != MEDIA_SVC_STORAGE_EXTERNAL_USB)
			&& (storage_type != MEDIA_SVC_STORAGE_CLOUD)) {
			media_svc_error("storage type is incorrect[%d]", storage_type);
			return FALSE;
		}
	} else {
		if ((storage_type != MEDIA_SVC_STORAGE_INTERNAL)
			&& (storage_type != MEDIA_SVC_STORAGE_EXTERNAL)
			&& (storage_type != MEDIA_SVC_STORAGE_EXTERNAL_USB)) {
			media_svc_error("storage type is incorrect[%d]", storage_type);
			return FALSE;
		}
	}

	return TRUE;
}

int media_svc_connect(MediaSvcHandle **handle, uid_t uid, bool need_write)
{
	int ret = MS_MEDIA_ERR_NONE;
	MediaDBHandle *db_handle = NULL;

	media_svc_debug_fenter();

	ret = media_db_connect(&db_handle, uid, need_write);
	if (ret != MS_MEDIA_ERR_NONE)
		return ret;

	*handle = db_handle;
	return MS_MEDIA_ERR_NONE;
}

int media_svc_disconnect(MediaSvcHandle *handle)
{
	MediaDBHandle *db_handle = (MediaDBHandle *)handle;

	media_svc_debug_fenter();

	media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");

	int ret = MS_MEDIA_ERR_NONE;

	ret = media_db_disconnect(db_handle);
	return ret;
}

int media_svc_get_user_version(MediaSvcHandle *handle, int *user_version)
{
	sqlite3 *db_handle = (sqlite3 *)handle;

	return _media_svc_get_user_version(db_handle, user_version);
}

int media_svc_create_table(uid_t uid)
{
	int ret = MS_MEDIA_ERR_NONE;
	char *sql = NULL;

	media_svc_debug_fenter();

	ret = _media_svc_init_table_query(MEDIA_SVC_DB_TABLE_MEDIA);
	if (ret != MS_MEDIA_ERR_NONE) {
		media_svc_error("_media_svc_init_table_query fail.");
		goto ERROR;
	}

	/*create media table*/
	ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_MEDIA, MEDIA_SVC_DB_LIST_MEDIA, uid);
	if (ret != MS_MEDIA_ERR_NONE) {
		media_svc_error("_media_svc_make_table_query fail.");
		goto ERROR;
	}

	/*create folder table*/
	ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_FOLDER, MEDIA_SVC_DB_LIST_FOLDER, uid);
	if (ret != MS_MEDIA_ERR_NONE) {
		media_svc_error("_media_svc_make_table_query fail.");
		goto ERROR;
	}

	/*create playlist_map table*/
	ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_PLAYLIST_MAP, MEDIA_SVC_DB_LIST_PLAYLIST_MAP, uid);
	if (ret != MS_MEDIA_ERR_NONE) {
		media_svc_error("_media_svc_make_table_query fail.");
		goto ERROR;
	}

	/*create playlist table*/
	ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_PLAYLIST, MEDIA_SVC_DB_LIST_PLAYLIST, uid);
	if (ret != MS_MEDIA_ERR_NONE) {
		media_svc_error("_media_svc_make_table_query fail.");
		goto ERROR;
	}

	/* create album table*/
	ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_ALBUM, MEDIA_SVC_DB_LIST_ALBUM, uid);
	if (ret != MS_MEDIA_ERR_NONE) {
		media_svc_error("_media_svc_make_table_query fail.");
		goto ERROR;
	}

	/*create tag_map table*/
	ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_TAG_MAP, MEDIA_SVC_DB_LIST_TAG_MAP, uid);
	if (ret != MS_MEDIA_ERR_NONE) {
		media_svc_error("_media_svc_make_table_query fail.");
		goto ERROR;
	}

	/*create tag table*/
	ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_TAG, MEDIA_SVC_DB_LIST_TAG, uid);
	if (ret != MS_MEDIA_ERR_NONE) {
		media_svc_error("_media_svc_make_table_query fail.");
		goto ERROR;
	}

	/*create bookmark table*/
	ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_BOOKMARK, MEDIA_SVC_DB_LIST_BOOKMARK, uid);
	if (ret != MS_MEDIA_ERR_NONE) {
		media_svc_error("_media_svc_make_table_query fail.");
		goto ERROR;
	}

	/*create storage table. from tizen 2.4*/
	ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_STORAGE, MEDIA_SVC_DB_LIST_STORAGE, uid);
	if (ret != MS_MEDIA_ERR_NONE) {
		media_svc_error("_media_svc_make_table_query fail.");
		goto ERROR;
	}

#if 0
	/*init storage table*/
	ret = _media_svc_init_storage(db_handle, uid);
	if (ret != MS_MEDIA_ERR_NONE) {
		media_svc_error("_media_svc_make_table_query fail.");
		goto ERROR;
	}

#endif
	/*create face table. from tizen 3.0*/
	ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_FACE_SCAN_LIST, MEDIA_SVC_DB_LIST_FACE_SCAN_LIST, uid);
	if (ret != MS_MEDIA_ERR_NONE) {
		media_svc_error("_media_svc_make_table_query fail.");
		goto ERROR;
	}

	ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_FACE, MEDIA_SVC_DB_LIST_FACE, uid);
	if (ret != MS_MEDIA_ERR_NONE) {
		media_svc_error("_media_svc_make_table_query fail.");
		goto ERROR;
	}

	sql = sqlite3_mprintf("pragma user_version = %d;", LATEST_VERSION_NUMBER);
	ret = _media_svc_sql_query(sql, uid);
	if (ret != MS_MEDIA_ERR_NONE) {
		media_svc_error("user_version update fail.");
		goto ERROR;
	}

	_media_svc_destroy_table_query();

	media_svc_debug_fleave();

	return MS_MEDIA_ERR_NONE;
ERROR:
	_media_svc_destroy_table_query();

	media_svc_debug_fleave();

	return ret;
}

int media_svc_get_storage_type(const char *path, media_svc_storage_type_e *storage_type, uid_t uid)
{
	int ret = MS_MEDIA_ERR_NONE;
	media_svc_storage_type_e type;

	ret = _media_svc_get_storage_type_by_path(path, &type, uid);
	media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "_media_svc_get_storage_type_by_path failed : %d", ret);

	*storage_type = type;

	return ret;
}

int media_svc_get_file_info(MediaSvcHandle *handle, const char *storage_id, const char *path, time_t *modified_time, unsigned long long *size)
{
	int ret = MS_MEDIA_ERR_NONE;
	sqlite3 *db_handle = (sqlite3 *)handle;

	media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
	media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");

	ret = _media_svc_get_fileinfo_by_path(db_handle, storage_id, path, modified_time, size);

	return ret;
}

int media_svc_check_item_exist_by_path(MediaSvcHandle *handle, const char *storage_id, const char *path)
{
	int ret = MS_MEDIA_ERR_NONE;
	sqlite3 *db_handle = (sqlite3 *)handle;
	int count = -1;

	media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
	media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
	media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "Path is NULL");

	ret = _media_svc_count_record_with_path(db_handle, storage_id, path, &count);
	media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);

	if (count > 0) {
		media_svc_debug("item is exist in database");
		return MS_MEDIA_ERR_NONE;
	} else {
		media_svc_debug("item is not exist in database");
		return MS_MEDIA_ERR_DB_NO_RECORD;
	}

	return MS_MEDIA_ERR_NONE;
}

int media_svc_insert_item_begin(int data_cnt, int with_noti, int from_pid)
{
	media_svc_debug("Transaction data count : [%d]", data_cnt);

	media_svc_retvm_if(data_cnt < 1, MS_MEDIA_ERR_INVALID_PARAMETER, "data_cnt shuld be bigger than 1");

	g_media_svc_insert_item_data_cnt = data_cnt;
	g_media_svc_insert_item_cur_data_cnt = 0;

	/* Prepare for making noti item list */
	if (with_noti) {
		media_svc_debug("making noti list from pid[%d]", from_pid);
		if (_media_svc_create_noti_list(data_cnt) != MS_MEDIA_ERR_NONE)
			return MS_MEDIA_ERR_OUT_OF_MEMORY;

		_media_svc_set_noti_from_pid(from_pid);
		g_insert_with_noti = TRUE;
	}

	return MS_MEDIA_ERR_NONE;
}

int media_svc_insert_item_end(uid_t uid)
{
	int ret = MS_MEDIA_ERR_NONE;

	media_svc_debug_fenter();

	if (g_media_svc_insert_item_cur_data_cnt > 0) {

		ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_INSERT_ITEM, uid);
		if (g_insert_with_noti) {
			media_svc_debug("sending noti list");
			_media_svc_publish_noti_list(g_media_svc_insert_item_cur_data_cnt);
			_media_svc_destroy_noti_list(g_media_svc_insert_item_cur_data_cnt);
			g_insert_with_noti = FALSE;
			_media_svc_set_noti_from_pid(-1);
		}
	}

	g_media_svc_insert_item_data_cnt = 1;
	g_media_svc_insert_item_cur_data_cnt = 0;

	return ret;
}

int media_svc_insert_item_bulk(MediaSvcHandle *handle, const char *storage_id, media_svc_storage_type_e storage_type, const char *path, int is_burst, uid_t uid)
{
	int ret = MS_MEDIA_ERR_NONE;
	sqlite3 *db_handle = (sqlite3 *)handle;
	char folder_uuid[MEDIA_SVC_UUID_SIZE + 1] = {0, };
	media_svc_media_type_e media_type;

	media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
	media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
	media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
	media_svc_retvm_if(__media_svc_check_storage(storage_type, FALSE) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");

	media_svc_content_info_s content_info;
	memset(&content_info, 0, sizeof(media_svc_content_info_s));

	/*Set media info*/
	/* if drm_contentinfo is not NULL, the file is OMA DRM.*/
	ret = _media_svc_set_media_info(&content_info, storage_id, storage_type, path, &media_type, FALSE);
	if (ret != MS_MEDIA_ERR_NONE)
		return ret;

	if (media_type == MEDIA_SVC_MEDIA_TYPE_OTHER) {
		/*Do nothing.*/
	} else if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) {
		ret = _media_svc_extract_image_metadata(db_handle, &content_info);
	} else {
		ret = _media_svc_extract_media_metadata(db_handle, &content_info, uid);
	}
	media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);

	/*Set or Get folder id*/
	ret = _media_svc_get_and_append_folder_id_by_path(db_handle, storage_id, path, storage_type, folder_uuid, uid);
	media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);

	ret = __media_svc_malloc_and_strncpy(&content_info.folder_uuid, folder_uuid);
	media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);

	if (g_media_svc_insert_item_data_cnt == 1) {

		ret = _media_svc_insert_item_with_data(db_handle, storage_id, &content_info, is_burst, FALSE, uid);
		media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);

		if (g_insert_with_noti)
			_media_svc_insert_item_to_noti_list(&content_info, g_media_svc_insert_item_cur_data_cnt++);

	} else if (g_media_svc_insert_item_cur_data_cnt < (g_media_svc_insert_item_data_cnt - 1)) {

		ret = _media_svc_insert_item_with_data(db_handle, storage_id, &content_info, is_burst, TRUE, uid);
		media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);

		if (g_insert_with_noti)
			_media_svc_insert_item_to_noti_list(&content_info, g_media_svc_insert_item_cur_data_cnt);

		g_media_svc_insert_item_cur_data_cnt++;

	} else if (g_media_svc_insert_item_cur_data_cnt == (g_media_svc_insert_item_data_cnt - 1)) {

		ret = _media_svc_insert_item_with_data(db_handle, storage_id, &content_info, is_burst, TRUE, uid);
		media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);

		if (g_insert_with_noti)
			_media_svc_insert_item_to_noti_list(&content_info, g_media_svc_insert_item_cur_data_cnt);

		ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_INSERT_ITEM, uid);
		media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);

		if (g_insert_with_noti) {
			_media_svc_publish_noti_list(g_media_svc_insert_item_cur_data_cnt + 1);
			_media_svc_destroy_noti_list(g_media_svc_insert_item_cur_data_cnt + 1);

			/* Recreate noti list */
			ret = _media_svc_create_noti_list(g_media_svc_insert_item_data_cnt);
			media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
		}

		g_media_svc_insert_item_cur_data_cnt = 0;

	} else {
		media_svc_error("Error in media_svc_insert_item_bulk");
		_media_svc_destroy_content_info(&content_info);
		return MS_MEDIA_ERR_INTERNAL;
	}

	_media_svc_destroy_content_info(&content_info);

	return MS_MEDIA_ERR_NONE;
}

int media_svc_insert_item_immediately(MediaSvcHandle *handle, const char *storage_id, media_svc_storage_type_e storage_type, const char *path, uid_t uid)
{
	int ret = MS_MEDIA_ERR_NONE;
	sqlite3 *db_handle = (sqlite3 *)handle;
	char folder_uuid[MEDIA_SVC_UUID_SIZE + 1] = {0, };
	media_svc_media_type_e media_type;
	int ini_val = _media_svc_get_ini_value();

	media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
	media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
	media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
	media_svc_retvm_if(__media_svc_check_storage(storage_type, FALSE) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");

	media_svc_content_info_s content_info;
	memset(&content_info, 0, sizeof(media_svc_content_info_s));

	/*Set media info*/
	ret = _media_svc_set_media_info(&content_info, storage_id, storage_type, path, &media_type, FALSE);
	if (ret != MS_MEDIA_ERR_NONE) {
		return ret;
	}

	if (media_type == MEDIA_SVC_MEDIA_TYPE_OTHER) {
		/*Do nothing.*/
	} else if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) {
		ret = _media_svc_extract_image_metadata(db_handle, &content_info);
	} else {
		ret = _media_svc_extract_media_metadata(db_handle, &content_info, uid);
	}

	media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);

	/*Set or Get folder id*/
	ret = _media_svc_get_and_append_folder_id_by_path(db_handle, storage_id, path, storage_type, folder_uuid, uid);
	media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);

	ret = __media_svc_malloc_and_strncpy(&content_info.folder_uuid, folder_uuid);
	media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
#if 1
	/* Extracting thumbnail */
	if (ini_val == 1) {
		if (content_info.thumbnail_path == NULL) {
			if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
				char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
				int width = 0;
				int height = 0;

				ret = _media_svc_request_thumbnail_with_origin_size(content_info.path, thumb_path, sizeof(thumb_path), &width, &height, uid);
				if (ret == MS_MEDIA_ERR_NONE)
					ret = __media_svc_malloc_and_strncpy(&(content_info.thumbnail_path), thumb_path);

				if (content_info.media_meta.width <= 0)
					content_info.media_meta.width = width;

				if (content_info.media_meta.height <= 0)
					content_info.media_meta.height = height;
			}
		}
	}
#endif

	ret = _media_svc_insert_item_with_data(db_handle, storage_id, &content_info, FALSE, FALSE, uid);

	if (ret == MS_MEDIA_ERR_NONE) {
		media_svc_debug("Insertion is successful. Sending noti for this");
		_media_svc_publish_noti(MS_MEDIA_ITEM_FILE, MS_MEDIA_ITEM_INSERT, content_info.path, content_info.media_type, content_info.media_uuid, content_info.mime_type);
	} else if (ret == MS_MEDIA_ERR_DB_CONSTRAINT_FAIL) {
		media_svc_error("This item is already inserted. This may be normal operation because other process already did this");
	}

	_media_svc_destroy_content_info(&content_info);
	return ret;
}

int media_svc_move_item(MediaSvcHandle *handle, const char *storage_id, media_svc_storage_type_e src_storage, const char *src_path,
			media_svc_storage_type_e dest_storage, const char *dest_path, uid_t uid)
{
	int ret = MS_MEDIA_ERR_NONE;
	sqlite3 *db_handle = (sqlite3 *)handle;
	char *file_name = NULL;
	char *folder_path = NULL;
	int modified_time = 0;
	char folder_uuid[MEDIA_SVC_UUID_SIZE + 1] = {0, };
	char old_thumb_path[MEDIA_SVC_PATHNAME_SIZE] = {0, };
	char new_thumb_path[MEDIA_SVC_PATHNAME_SIZE] = {0, };
	int media_type = -1;

	media_svc_debug_fenter();

	media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
	media_svc_retvm_if(!STRING_VALID(src_path), MS_MEDIA_ERR_INVALID_PARAMETER, "src_path is NULL");
	media_svc_retvm_if(!STRING_VALID(dest_path), MS_MEDIA_ERR_INVALID_PARAMETER, "dest_path is NULL");
	media_svc_retvm_if(__media_svc_check_storage(src_storage, FALSE) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid src_storage");
	media_svc_retvm_if(__media_svc_check_storage(dest_storage, FALSE) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid dest_storage");

	/*check and update folder*/
	ret = _media_svc_get_and_append_folder_id_by_path(db_handle, storage_id, dest_path, dest_storage, folder_uuid, uid);
	media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);

	/*get filename*/
	file_name = g_path_get_basename(dest_path);

	/*get modified_time*/
	modified_time = _media_svc_get_file_time(dest_path);

	/*get thumbnail_path to update. only for Imgae and Video items. Audio share album_art(thumbnail)*/
	ret = _media_svc_get_media_type_by_path(db_handle, storage_id, src_path, &media_type);
	if (ret != MS_MEDIA_ERR_NONE) {
		media_svc_error("_media_svc_get_media_type_by_path failed");
		SAFE_FREE(file_name);
		return ret;
	}

	if ((media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) || (media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO)) {
		/*get old thumbnail_path*/
		ret = _media_svc_get_thumbnail_path_by_path(db_handle, storage_id, src_path, old_thumb_path);
		if ((ret != MS_MEDIA_ERR_NONE) && (ret != MS_MEDIA_ERR_DB_NO_RECORD)) {
			media_svc_error("_media_svc_get_thumbnail_path_by_path failed");
			SAFE_FREE(file_name);
			return ret;
		}

		/* If old thumb path is default or not */
		char *default_thumbnail_path = _media_svc_get_thumb_default_path(uid);
		if (STRING_VALID(default_thumbnail_path) && (strncmp(old_thumb_path, default_thumbnail_path, strlen(default_thumbnail_path)) == 0))
			strncpy(new_thumb_path, default_thumbnail_path, sizeof(new_thumb_path));
		else
			_media_svc_get_thumbnail_path(dest_storage, new_thumb_path, dest_path, THUMB_EXT, uid);

		SAFE_FREE(default_thumbnail_path);
	}

	if (g_media_svc_move_item_data_cnt == 1) {

		/*update item*/
		if ((media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) || (media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO)) {
			ret = _media_svc_update_item_by_path(storage_id, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, new_thumb_path, FALSE, uid);
		} else {
			ret = _media_svc_update_item_by_path(storage_id, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, NULL, FALSE, uid);
		}
		SAFE_FREE(file_name);
		media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);

		media_svc_debug("Move is successful. Sending noti for this");

		/* Get notification info */
		media_svc_noti_item *noti_item = NULL;
		ret = _media_svc_get_noti_info(db_handle, storage_id, dest_path, MS_MEDIA_ITEM_FILE, &noti_item);
		media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);

		/* Send notification for move */
		_media_svc_publish_noti(MS_MEDIA_ITEM_FILE, MS_MEDIA_ITEM_UPDATE, src_path, media_type, noti_item->media_uuid, noti_item->mime_type);
		_media_svc_destroy_noti_item(noti_item);

		/*update folder modified_time*/
		folder_path = g_path_get_dirname(dest_path);
		ret = _media_svc_update_folder_modified_time_by_folder_uuid(folder_uuid, folder_path, FALSE, uid);
		SAFE_FREE(folder_path);
		media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);

		ret = _media_svc_update_folder_table(storage_id, uid);
		media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);

	} else if (g_media_svc_move_item_cur_data_cnt < (g_media_svc_move_item_data_cnt - 1)) {

		/*update item*/
		if ((media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) || (media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO)) {
			ret = _media_svc_update_item_by_path(storage_id, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, new_thumb_path, TRUE, uid);
		} else {
			ret = _media_svc_update_item_by_path(storage_id, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, NULL, TRUE, uid);
		}
		SAFE_FREE(file_name);
		media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);

		/*update folder modified_time*/
		folder_path = g_path_get_dirname(dest_path);
		ret = _media_svc_update_folder_modified_time_by_folder_uuid(folder_uuid, folder_path, TRUE, uid);
		SAFE_FREE(folder_path);
		media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);

		g_media_svc_move_item_cur_data_cnt++;

	} else if (g_media_svc_move_item_cur_data_cnt == (g_media_svc_move_item_data_cnt - 1)) {

		/*update item*/
		if ((media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) || (media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO)) {
			ret = _media_svc_update_item_by_path(storage_id, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, new_thumb_path, TRUE, uid);
		} else {
			ret = _media_svc_update_item_by_path(storage_id, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, NULL, TRUE, uid);
		}
		SAFE_FREE(file_name);
		media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);

		/*update folder modified_time*/
		folder_path = g_path_get_dirname(dest_path);
		ret = _media_svc_update_folder_modified_time_by_folder_uuid(folder_uuid, folder_path, TRUE, uid);
		SAFE_FREE(folder_path);
		media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);

		/*update db*/
		ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_MOVE_ITEM, uid);
		media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);

		g_media_svc_move_item_cur_data_cnt = 0;

	} else {
		media_svc_error("Error in media_svc_move_item");
		return MS_MEDIA_ERR_INTERNAL;
	}

	/*rename thumbnail file*/
/*	if ((media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) || (media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO)) { */
	if ((strlen(old_thumb_path) > 0) && (STRING_VALID(MEDIA_SVC_THUMB_DEFAULT_PATH)) && (strncmp(old_thumb_path, MEDIA_SVC_THUMB_DEFAULT_PATH, strlen(MEDIA_SVC_THUMB_DEFAULT_PATH)) != 0)) {
		ret = _media_svc_rename_file(old_thumb_path, new_thumb_path);
		if (ret != MS_MEDIA_ERR_NONE)
			media_svc_error("_media_svc_rename_file failed : %d", ret);
	}
/*	} */

	return MS_MEDIA_ERR_NONE;
}

int media_svc_set_item_validity_begin(int data_cnt)
{
	media_svc_debug("Transaction data count : [%d]", data_cnt);

	media_svc_retvm_if(data_cnt < 1, MS_MEDIA_ERR_INVALID_PARAMETER, "data_cnt shuld be bigger than 1");

	g_media_svc_item_validity_data_cnt = data_cnt;
	g_media_svc_item_validity_cur_data_cnt = 0;

	return MS_MEDIA_ERR_NONE;
}

int media_svc_set_item_validity_end(uid_t uid)
{
	int ret = MS_MEDIA_ERR_NONE;

	media_svc_debug_fenter();

	if (g_media_svc_item_validity_cur_data_cnt > 0) {

		ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_SET_ITEM_VALIDITY, uid);
	}

	g_media_svc_item_validity_data_cnt = 1;
	g_media_svc_item_validity_cur_data_cnt = 0;

	return ret;
}

int media_svc_set_item_validity(const char *storage_id, const char *path, int validity, uid_t uid)
{
	int ret = MS_MEDIA_ERR_NONE;

	media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
	media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");

	media_svc_debug("path=[%s], validity=[%d]", path, validity);

	if (g_media_svc_item_validity_data_cnt == 1) {

		return _media_svc_update_item_validity(storage_id, path, validity, FALSE, uid);

	} else if (g_media_svc_item_validity_cur_data_cnt < (g_media_svc_item_validity_data_cnt - 1)) {

		ret = _media_svc_update_item_validity(storage_id, path, validity, TRUE, uid);
		media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);

		g_media_svc_item_validity_cur_data_cnt++;

	} else if (g_media_svc_item_validity_cur_data_cnt == (g_media_svc_item_validity_data_cnt - 1)) {

		ret = _media_svc_update_item_validity(storage_id, path, validity, TRUE, uid);
		media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);

		ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_SET_ITEM_VALIDITY, uid);
		media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);

		g_media_svc_item_validity_cur_data_cnt = 0;

	} else {

		media_svc_error("Error in media_svc_set_item_validity");
		return MS_MEDIA_ERR_INTERNAL;
	}

	return MS_MEDIA_ERR_NONE;
}

int media_svc_delete_item_by_path(MediaSvcHandle *handle, const char *storage_id, const char *path, uid_t uid)
{
	int ret = MS_MEDIA_ERR_NONE;
	sqlite3 *db_handle = (sqlite3 *)handle;
	char thumb_path[MEDIA_SVC_PATHNAME_SIZE] = {0, };

	media_svc_debug_fenter();

	media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
	media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
	media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");

	int media_type = -1;
	ret = _media_svc_get_media_type_by_path(db_handle, storage_id, path, &media_type);
	media_svc_retv_if((ret != MS_MEDIA_ERR_NONE), ret);

#if 0
	if ((media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) || (media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO)) {
		/*Get thumbnail path to delete*/
		ret = _media_svc_get_thumbnail_path_by_path(db_handle, storage_id, path, thumb_path);
		media_svc_retv_if((ret != MS_MEDIA_ERR_NONE) && (ret != MS_MEDIA_ERR_DB_NO_RECORD), ret);
	} else if ((media_type == MEDIA_SVC_MEDIA_TYPE_SOUND) || (media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC)) {
		int count = 0;
		ret = _media_svc_get_media_count_with_album_id_by_path(db_handle, path, &count);
		media_svc_retv_if((ret != MS_MEDIA_ERR_NONE), ret);

		if (count == 1) {
			/*Get thumbnail path to delete*/
			ret = _media_svc_get_thumbnail_path_by_path(db_handle, storage_id, path, thumb_path);
			media_svc_retv_if((ret != MS_MEDIA_ERR_NONE) && (ret != MS_MEDIA_ERR_DB_NO_RECORD), ret);
		}
	}
#endif
	/*Get thumbnail path to delete*/
	ret = _media_svc_get_thumbnail_path_by_path(db_handle, storage_id, path, thumb_path);
	media_svc_retv_if((ret != MS_MEDIA_ERR_NONE) && (ret != MS_MEDIA_ERR_DB_NO_RECORD), ret);

	if (g_media_svc_insert_item_data_cnt == 1) {

		/* Get notification info */
		media_svc_noti_item *noti_item = NULL;
		ret = _media_svc_get_noti_info(db_handle, storage_id, path, MS_MEDIA_ITEM_FILE, &noti_item);
		media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);

		/*Delete item*/
		ret = _media_svc_delete_item_by_path(storage_id, path, FALSE, uid);
		if (ret != MS_MEDIA_ERR_NONE) {
			media_svc_error("_media_svc_delete_item_by_path failed : %d", ret);
			_media_svc_destroy_noti_item(noti_item);

			return ret;
		}

		/* Send notification */
		media_svc_debug("Deletion is successful. Sending noti for this");
		_media_svc_publish_noti(MS_MEDIA_ITEM_FILE, MS_MEDIA_ITEM_DELETE, path, media_type, noti_item->media_uuid, noti_item->mime_type);
		_media_svc_destroy_noti_item(noti_item);
	} else {
		ret = _media_svc_delete_item_by_path(storage_id, path, TRUE, uid);
		if (ret != MS_MEDIA_ERR_NONE) {
			media_svc_error("_media_svc_delete_item_by_path failed : %d", ret);
			return ret;
		}

	}

	/*Delete thumbnail*/
	char *default_thumbnail_path = _media_svc_get_thumb_default_path(uid);
	if ((strlen(thumb_path) > 0) && ((STRING_VALID(default_thumbnail_path)) && (strncmp(thumb_path, default_thumbnail_path, strlen(default_thumbnail_path)) != 0))) {
/*
		int thumb_count = 1;
		// Get count of media, which contains same thumbnail for music
		if ((media_type == MEDIA_SVC_MEDIA_TYPE_SOUND) ||(media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC)) {
			ret = _media_svc_get_thumbnail_count(db_handle, storage_id, thumb_path, &thumb_count);
			if (ret != MS_MEDIA_ERR_NONE) {
				media_svc_error("Failed to get thumbnail count : %d", ret);
			}
		}

		if (thumb_count == 1) {
*/
			ret = _media_svc_remove_file(thumb_path);
			if (ret != MS_MEDIA_ERR_NONE) {
				media_svc_error("fail to remove thumbnail file.");
			}
//		}
	}

	SAFE_FREE(default_thumbnail_path);

	return MS_MEDIA_ERR_NONE;
}

int media_svc_delete_all_items_in_storage(const char *storage_id, media_svc_storage_type_e storage_type, uid_t uid)
{
	int ret = MS_MEDIA_ERR_NONE;

	media_svc_debug("media_svc_delete_all_items_in_storage [%d]", storage_type);

	media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
	media_svc_retvm_if(__media_svc_check_storage(storage_type, FALSE) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");

	ret = _media_svc_truncate_table(storage_id, storage_type, uid);
	media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);

	if (storage_type != MEDIA_SVC_STORAGE_EXTERNAL_USB) {
		char *internal_thumb_path = _media_svc_get_thumb_internal_path(uid);
		char *external_thumb_path = _media_svc_get_thumb_external_path(uid);

		const char *dirpath = (storage_type == MEDIA_SVC_STORAGE_INTERNAL) ? internal_thumb_path : external_thumb_path;

		/* remove thumbnails */
		if (STRING_VALID(dirpath))
			ret = _media_svc_remove_all_files_in_dir(dirpath);
		SAFE_FREE(internal_thumb_path);
		SAFE_FREE(external_thumb_path);
		media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
	}

	return MS_MEDIA_ERR_NONE;
}

int media_svc_delete_invalid_items_in_storage(MediaSvcHandle *handle, const char *storage_id, media_svc_storage_type_e storage_type, uid_t uid)
{
	sqlite3 *db_handle = (sqlite3 *)handle;

	media_svc_debug_fenter();

	media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
	media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
	media_svc_retvm_if(__media_svc_check_storage(storage_type, FALSE) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");

	/*Delete from DB and remove thumbnail files*/
	return _media_svc_delete_invalid_items(db_handle, storage_id, storage_type, uid);
}

int media_svc_delete_invalid_items_in_folder(MediaSvcHandle *handle, const char *storage_id, const char *folder_path, bool is_recursive, uid_t uid)
{
	sqlite3 *db_handle = (sqlite3 *)handle;

	media_svc_debug_fenter();

	media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
	media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");

	/*Delete from DB and remove thumbnail files*/
	return _media_svc_delete_invalid_folder_items(db_handle, storage_id, folder_path, is_recursive, uid);
}

int media_svc_set_all_storage_items_validity(const char *storage_id, media_svc_storage_type_e storage_type, int validity, uid_t uid)
{
	media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
	media_svc_retvm_if(__media_svc_check_storage(storage_type, FALSE) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");

	return _media_svc_update_storage_item_validity(storage_id, storage_type, validity, uid);
}

int media_svc_set_folder_items_validity(MediaSvcHandle *handle, const char *storage_id, const char *folder_path, int validity, int recursive, uid_t uid)
{
	sqlite3 *db_handle = (sqlite3 *)handle;

	media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
	media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
	media_svc_retvm_if(!STRING_VALID(folder_path), MS_MEDIA_ERR_INVALID_PARAMETER, "folder_path is NULL");

	if (recursive)
		return _media_svc_update_recursive_folder_item_validity(storage_id, folder_path, validity, uid);
	else
		return _media_svc_update_folder_item_validity(db_handle, storage_id, folder_path, validity, uid);
}

int media_svc_refresh_item(MediaSvcHandle *handle, const char *storage_id, media_svc_storage_type_e storage_type, const char *path, uid_t uid)
{
	int ret = MS_MEDIA_ERR_NONE;
	sqlite3 *db_handle = (sqlite3 *)handle;
	media_svc_media_type_e media_type;
	int ini_val = _media_svc_get_ini_value();

	media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
	media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
	media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
	media_svc_retvm_if(__media_svc_check_storage(storage_type, FALSE) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");

	media_svc_content_info_s content_info;
	memset(&content_info, 0, sizeof(media_svc_content_info_s));

	/*Set media info*/
	ret = _media_svc_set_media_info(&content_info, storage_id, storage_type, path, &media_type, TRUE);
	if (ret != MS_MEDIA_ERR_NONE) {
		return ret;
	}

	/* Initialize thumbnail information to remake thumbnail. */
	if (ini_val == 1) {
		char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1];
		ret = _media_svc_get_thumbnail_path_by_path(db_handle, storage_id, path, thumb_path);
		if (ret != MS_MEDIA_ERR_NONE) {
			_media_svc_destroy_content_info(&content_info);
			return ret;
		}

		if (g_file_test(thumb_path, G_FILE_TEST_EXISTS) && (STRING_VALID(MEDIA_SVC_THUMB_DEFAULT_PATH)) && (strncmp(thumb_path, MEDIA_SVC_THUMB_DEFAULT_PATH, strlen(MEDIA_SVC_THUMB_DEFAULT_PATH)) != 0)) {
			ret = _media_svc_remove_file(thumb_path);
			if (ret != MS_MEDIA_ERR_NONE) {
				media_svc_error("_media_svc_remove_file failed : %s", thumb_path);
			}
		}

		ret = _media_svc_update_thumbnail_path(storage_id, path, NULL, uid);
		if (ret != MS_MEDIA_ERR_NONE) {
			_media_svc_destroy_content_info(&content_info);
			return ret;
		}
	}

	/* Get notification info */
	media_svc_noti_item *noti_item = NULL;
	ret = _media_svc_get_noti_info(db_handle, storage_id, path, MS_MEDIA_ITEM_FILE, &noti_item);
	if (ret != MS_MEDIA_ERR_NONE) {
		_media_svc_destroy_content_info(&content_info);
		return ret;
	}

	media_type = noti_item->media_type;
	content_info.media_type = media_type;

	if (media_type == MEDIA_SVC_MEDIA_TYPE_OTHER) {
		/*Do nothing.*/
	} else if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) {
		ret = _media_svc_extract_image_metadata(db_handle, &content_info);
	} else {
		ret = _media_svc_extract_media_metadata(db_handle, &content_info, uid);
	}

	if (ret != MS_MEDIA_ERR_NONE) {
		_media_svc_destroy_noti_item(noti_item);
		_media_svc_destroy_content_info(&content_info);
		return ret;
	}
#if 1
	/* Extracting thumbnail */
	if (ini_val == 1) {
		if (content_info.thumbnail_path == NULL) {
			if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
				char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
				int width = 0;
				int height = 0;

				ret = _media_svc_request_thumbnail_with_origin_size(content_info.path, thumb_path, sizeof(thumb_path), &width, &height, uid);
				if (ret == MS_MEDIA_ERR_NONE) {
					ret = __media_svc_malloc_and_strncpy(&(content_info.thumbnail_path), thumb_path);
				}

				if (content_info.media_meta.width <= 0)
					content_info.media_meta.width = width;

				if (content_info.media_meta.height <= 0)
					content_info.media_meta.height = height;
			}
		}
	}

#endif

	ret = _media_svc_update_item_with_data(storage_id, &content_info, uid);

	if (ret == MS_MEDIA_ERR_NONE) {
		media_svc_debug("Update is successful. Sending noti for this");
		_media_svc_publish_noti(MS_MEDIA_ITEM_FILE, MS_MEDIA_ITEM_UPDATE, content_info.path, noti_item->media_type, noti_item->media_uuid, noti_item->mime_type);
	} else {
		media_svc_error("_media_svc_update_item_with_data failed : %d", ret);
	}

	_media_svc_destroy_content_info(&content_info);
	_media_svc_destroy_noti_item(noti_item);

	return ret;
}

int media_svc_rename_folder(MediaSvcHandle *handle, const char *storage_id, const char *src_path, const char *dst_path, uid_t uid)
{
	sqlite3 *db_handle = (sqlite3 *)handle;
	int ret = MS_MEDIA_ERR_NONE;

	media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
	media_svc_retvm_if(src_path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "src_path is NULL");
	media_svc_retvm_if(dst_path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "dst_path is NULL");

	media_svc_debug("Src path : %s, Dst Path : %s", src_path, dst_path);

	ret = _media_svc_sql_begin_trans(uid);
	media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);

	/* Update all folder record's modified date, which are changed above */
	char *update_folder_modified_time_sql = NULL;
	time_t date;
	time(&date);

	update_folder_modified_time_sql = sqlite3_mprintf("UPDATE folder SET modified_time = %d WHERE path LIKE '%q';", date, dst_path);

	ret = media_db_request_update_db_batch(update_folder_modified_time_sql, uid);
	sqlite3_free(update_folder_modified_time_sql);

	if (ret != SQLITE_OK) {
		media_svc_error("failed to update folder modified time");
		_media_svc_sql_rollback_trans(uid);

		return MS_MEDIA_ERR_DB_INTERNAL;
	}

	/* Update all items */
	char *select_all_sql = NULL;
	sqlite3_stmt *sql_stmt = NULL;
	char dst_child_path[MEDIA_SVC_PATHNAME_SIZE + 1];

	snprintf(dst_child_path, sizeof(dst_child_path), "%s/%%", dst_path);

	select_all_sql = sqlite3_mprintf("SELECT media_uuid, path, thumbnail_path, media_type from media where folder_uuid IN ( SELECT folder_uuid FROM folder where path='%q' or path like '%q');", dst_path, dst_child_path);

	media_svc_debug("[SQL query] : %s", select_all_sql);

	ret = _media_svc_sql_prepare_to_step_simple(db_handle, select_all_sql, &sql_stmt);
	if (ret != MS_MEDIA_ERR_NONE) {
		media_svc_error("error when media_svc_rename_folder. err = [%d]", ret);
		_media_svc_sql_rollback_trans(uid);
		return ret;
	}

	while (sqlite3_step(sql_stmt) == SQLITE_ROW) {
		char media_uuid[MEDIA_SVC_UUID_SIZE + 1] = {0, };
		char media_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
		char media_thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
		char media_new_thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
		/*int media_type; */
		bool no_thumb = FALSE;

		if (STRING_VALID((const char *)sqlite3_column_text(sql_stmt, 0))) {
			strncpy(media_uuid,	(const char *)sqlite3_column_text(sql_stmt, 0), sizeof(media_uuid));
			media_uuid[sizeof(media_uuid) - 1] = '\0';
		} else {
			media_svc_error("media UUID is NULL");
			return MS_MEDIA_ERR_DB_INTERNAL;
		}

		if (STRING_VALID((const char *)sqlite3_column_text(sql_stmt, 1))) {
			strncpy(media_path,	(const char *)sqlite3_column_text(sql_stmt, 1), sizeof(media_path));
			media_path[sizeof(media_path) - 1] = '\0';
		} else {
			media_svc_error("media path is NULL");
			return MS_MEDIA_ERR_DB_INTERNAL;
		}

		if (STRING_VALID((const char *)sqlite3_column_text(sql_stmt, 2))) {
			strncpy(media_thumb_path,	(const char *)sqlite3_column_text(sql_stmt, 2), sizeof(media_thumb_path));
			media_thumb_path[sizeof(media_thumb_path) - 1] = '\0';
		} else {
			media_svc_debug("media thumb path doesn't exist in DB");
			no_thumb = TRUE;
		}

		/*media_type = sqlite3_column_int(sql_stmt, 3); */

		/* Update path, thumbnail path of this item */
		char *replaced_path = NULL;
		replaced_path = _media_svc_replace_path(media_path, src_path, dst_path);
		if (replaced_path == NULL) {
			media_svc_error("_media_svc_replace_path failed");
			SQLITE3_FINALIZE(sql_stmt);
			_media_svc_sql_rollback_trans(uid);
			return MS_MEDIA_ERR_INTERNAL;
		}

		media_svc_debug("New media path : %s", replaced_path);
		media_svc_storage_type_e storage_type;

		if (!no_thumb) {
			/* If old thumb path is default or not */
			char *default_thumbnail_path = _media_svc_get_thumb_default_path(uid);
			if (STRING_VALID(default_thumbnail_path) && (strncmp(media_thumb_path, default_thumbnail_path, strlen(default_thumbnail_path)) == 0)) {
				strncpy(media_new_thumb_path, default_thumbnail_path, sizeof(media_new_thumb_path) - 1);
			} else {
				ret = _media_svc_get_storage_type_by_path(replaced_path, &storage_type, uid);
				if (ret != MS_MEDIA_ERR_NONE) {
					media_svc_error("_media_svc_get_storage_type_by_path failed : %d", ret);
					SAFE_FREE(replaced_path);
					SAFE_FREE(default_thumbnail_path);
					_media_svc_sql_rollback_trans(uid);
					return ret;
				}

				ret = _media_svc_get_thumbnail_path(storage_type, media_new_thumb_path, replaced_path, THUMB_EXT, uid);
				if (ret != MS_MEDIA_ERR_NONE) {
					media_svc_error("_media_svc_get_thumbnail_path failed : %d", ret);
					SAFE_FREE(replaced_path);
					SAFE_FREE(default_thumbnail_path);
					SQLITE3_FINALIZE(sql_stmt);
					_media_svc_sql_rollback_trans(uid);
					return ret;
				}
			}

			SAFE_FREE(default_thumbnail_path);

			/*media_svc_debug("New media thumbnail path : %s", media_new_thumb_path); */
		}

		char *update_item_sql = NULL;

		if (no_thumb) {
			update_item_sql = sqlite3_mprintf("UPDATE media SET path='%q' WHERE media_uuid='%q'", replaced_path, media_uuid);
		} else {
#if 0
			if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
				update_item_sql = sqlite3_mprintf("UPDATE media SET path='%q', thumbnail_path='%q' WHERE media_uuid='%q'", replaced_path, media_new_thumb_path, media_uuid);
			} else {
				update_item_sql = sqlite3_mprintf("UPDATE media SET path='%q', thumbnail_path='%q' WHERE media_uuid='%q'", replaced_path, media_thumb_path, media_uuid);
			}
#else
			update_item_sql = sqlite3_mprintf("UPDATE media SET path='%q', thumbnail_path='%q' WHERE media_uuid='%q'", replaced_path, media_new_thumb_path, media_uuid);
#endif
		}

		ret = media_db_request_update_db_batch(update_item_sql, uid);
		sqlite3_free(update_item_sql);
		SAFE_FREE(replaced_path);

		if (ret != SQLITE_OK) {
			media_svc_error("failed to update item");
			SQLITE3_FINALIZE(sql_stmt);
			_media_svc_sql_rollback_trans(uid);

			return MS_MEDIA_ERR_DB_INTERNAL;
		}

		/* Rename thumbnail file of file system */
		char *default_thumbnail_path = _media_svc_get_thumb_default_path(uid);
		if ((!no_thumb) && (strncmp(media_thumb_path, default_thumbnail_path, strlen(default_thumbnail_path)) != 0)) {
			ret = _media_svc_rename_file(media_thumb_path, media_new_thumb_path);
			if (ret != MS_MEDIA_ERR_NONE) {
				media_svc_error("_media_svc_rename_file failed : %d", ret);
			}
		}

		SAFE_FREE(default_thumbnail_path);
	}

	SQLITE3_FINALIZE(sql_stmt);

	ret = _media_svc_sql_end_trans(uid);
	if (ret != MS_MEDIA_ERR_NONE) {
		media_svc_error("mb_svc_sqlite3_commit_trans failed.. Now start to rollback");
		_media_svc_sql_rollback_trans(uid);
		return ret;
	}

	media_svc_debug("Folder update is successful. Sending noti for this");
	/* Get notification info */
	media_svc_noti_item *noti_item = NULL;
	ret = _media_svc_get_noti_info(db_handle, storage_id, dst_path, MS_MEDIA_ITEM_DIRECTORY, &noti_item);
	media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);

	_media_svc_publish_noti(MS_MEDIA_ITEM_DIRECTORY, MS_MEDIA_ITEM_UPDATE, src_path, -1, noti_item->media_uuid, NULL);
	_media_svc_destroy_noti_item(noti_item);

	return MS_MEDIA_ERR_NONE;
}

int media_svc_request_update_db(const char *db_query, uid_t uid)
{
	media_svc_retvm_if(!STRING_VALID(db_query), MS_MEDIA_ERR_INVALID_PARAMETER, "db_query is NULL");

	return _media_svc_sql_query(db_query, uid);
}

int media_svc_send_dir_update_noti(MediaSvcHandle *handle, const char *storage_id, const char *dir_path, const char *folder_id, media_item_update_type_e update_type, int pid)
{
	int ret = MS_MEDIA_ERR_NONE;
	sqlite3 *db_handle = (sqlite3 *)handle;
	char *uuid = NULL;

	media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
	media_svc_retvm_if(!STRING_VALID(dir_path), MS_MEDIA_ERR_INVALID_PARAMETER, "dir_path is NULL");

	/* Get notification info */
	media_svc_noti_item *noti_item = NULL;
	ret = _media_svc_get_noti_info(db_handle, storage_id, dir_path, MS_MEDIA_ITEM_DIRECTORY, &noti_item);
	media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);

	if (folder_id != NULL) {
		uuid = folder_id;
	} else {
		uuid = noti_item->media_uuid;
	}

	ret = _media_svc_publish_dir_noti(MS_MEDIA_ITEM_DIRECTORY, MS_MEDIA_ITEM_UPDATE, dir_path, -1, noti_item->media_uuid, NULL, pid);
	ret = _media_svc_publish_dir_noti_v2(MS_MEDIA_ITEM_DIRECTORY, update_type, dir_path, -1, uuid, NULL, pid);
	_media_svc_destroy_noti_item(noti_item);

	return ret;
}

int media_svc_count_invalid_items_in_folder(MediaSvcHandle *handle, const char *storage_id, const char *folder_path, int *count)
{
	sqlite3 *db_handle = (sqlite3 *)handle;

	media_svc_debug_fenter();

	media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
	media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
	media_svc_retvm_if(folder_path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "folder_path is NULL");
	media_svc_retvm_if(count == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "count is NULL");

	return _media_svc_count_invalid_folder_items(db_handle, storage_id, folder_path, count);
}

int media_svc_check_db_upgrade(MediaSvcHandle *handle, bool *need_full_scan, int user_version, uid_t uid)
{
	sqlite3 *db_handle = (sqlite3 *)handle;

	media_svc_debug_fenter();

	media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");

	return _media_svc_check_db_upgrade(db_handle, need_full_scan, user_version, uid);
}

int media_svc_check_db_corrupt(MediaSvcHandle *handle)
{
	sqlite3 *db_handle = (sqlite3 *)handle;

	media_svc_debug_fenter();

	media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");

	return _media_db_check_corrupt(db_handle);
}

int media_svc_get_folder_list(MediaSvcHandle *handle, char *start_path, char ***folder_list, time_t **modified_time_list, int **item_num_list, int *count)
{
	sqlite3 *db_handle = (sqlite3 *)handle;

	media_svc_debug_fenter();

	media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
	media_svc_retvm_if(count == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "count is NULL");

	return _media_svc_get_all_folders(db_handle, start_path, folder_list, modified_time_list, item_num_list, count);
}

int media_svc_update_folder_time(MediaSvcHandle *handle, const char *storage_id, const char *folder_path, uid_t uid)
{
	int ret = MS_MEDIA_ERR_NONE;
	sqlite3 *db_handle = (sqlite3 *)handle;
	time_t sto_time = 0;
	int cur_time = _media_svc_get_file_time(folder_path);
	char folder_uuid[MEDIA_SVC_UUID_SIZE + 1] = {0, };

	media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");

	ret = _media_svc_get_folder_info_by_foldername(db_handle, storage_id, folder_path, folder_uuid, &sto_time);
	if (ret == MS_MEDIA_ERR_NONE) {
		if (sto_time != cur_time) {
			ret = _media_svc_update_folder_modified_time_by_folder_uuid(folder_uuid, folder_path, FALSE, uid);
		}
	}

	return ret;
}

int media_svc_update_item_begin(int data_cnt)
{
	media_svc_debug("Transaction data count : [%d]", data_cnt);

	media_svc_retvm_if(data_cnt < 1, MS_MEDIA_ERR_INVALID_PARAMETER, "data_cnt shuld be bigger than 1");

	g_media_svc_update_item_data_cnt = data_cnt;
	g_media_svc_update_item_cur_data_cnt = 0;

	return MS_MEDIA_ERR_NONE;
}

int media_svc_update_item_end(uid_t uid)
{
	int ret = MS_MEDIA_ERR_NONE;

	media_svc_debug_fenter();

	if (g_media_svc_update_item_cur_data_cnt > 0) {

		ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_UPDATE_ITEM, uid);
	}

	g_media_svc_update_item_data_cnt = 1;
	g_media_svc_update_item_cur_data_cnt = 0;

	return ret;
}

int media_svc_update_item_meta(MediaSvcHandle *handle, const char *file_path, int storage_type, uid_t uid)
{
	int ret = MS_MEDIA_ERR_NONE;
	sqlite3 *db_handle = (sqlite3 *)handle;

	media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");

	media_svc_media_type_e media_type;
	media_svc_retvm_if(!STRING_VALID(file_path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
	media_svc_retvm_if(__media_svc_check_storage(storage_type, FALSE) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");

	media_svc_content_info_s content_info;
	memset(&content_info, 0, sizeof(media_svc_content_info_s));

	/*Set media info*/
	ret = _media_svc_set_media_info(&content_info, DEFAULT_MEDIA_SVC_STORAGE_ID, storage_type, file_path, &media_type, FALSE);
	if (ret != MS_MEDIA_ERR_NONE) {
		return ret;
	}

	if (media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC) {
		ret = _media_svc_extract_music_metadata_for_update(db_handle, &content_info, media_type);
	} else {
		return MS_MEDIA_ERR_NONE;
	}

	if (ret != MS_MEDIA_ERR_NONE) {
		_media_svc_destroy_content_info(&content_info);
		return ret;
	}

	if (g_media_svc_update_item_data_cnt == 1) {

		ret = _media_svc_update_meta_with_data(&content_info);
		media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);

	} else if (g_media_svc_update_item_cur_data_cnt < (g_media_svc_update_item_data_cnt - 1)) {

		ret = _media_svc_update_meta_with_data(&content_info);
		media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);

		g_media_svc_update_item_cur_data_cnt++;

	} else if (g_media_svc_update_item_cur_data_cnt == (g_media_svc_update_item_data_cnt - 1)) {

		ret = _media_svc_update_meta_with_data(&content_info);
		media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);

		ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_UPDATE_ITEM, uid);
		media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);

		g_media_svc_update_item_cur_data_cnt = 0;

	} else {
		media_svc_error("Error in media_svc_update_item_meta");
		_media_svc_destroy_content_info(&content_info);
		return MS_MEDIA_ERR_INTERNAL;
	}

	_media_svc_destroy_content_info(&content_info);

	return ret;
}

int media_svc_publish_noti(media_item_type_e update_item, media_item_update_type_e update_type, const char *path, media_type_e media_type, const char *uuid, const char *mime_type)
{
	return _media_svc_publish_noti(update_item, update_type, path, media_type, uuid, mime_type);
}

int media_svc_get_pinyin(const char *src_str, char **pinyin_str)
{
	media_svc_retvm_if(!STRING_VALID(src_str), MS_MEDIA_ERR_INVALID_PARAMETER, "String is NULL");

	return _media_svc_get_pinyin_str(src_str, pinyin_str);
}

int media_svc_check_pinyin_support(bool *support)
{
	*support = _media_svc_check_pinyin_support();

	return MS_MEDIA_ERR_NONE;
}

int media_svc_set_storage_validity(MediaSvcHandle *handle, const char *storage_id, int validity, uid_t uid)
{
	int ret = MS_MEDIA_ERR_NONE;
	sqlite3 * db_handle = (sqlite3 *)handle;

	media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");

	ret = _media_svc_update_storage_validity(storage_id, validity, uid);
	media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "update storage validity failed: %d", ret);

	ret = _media_svc_update_media_view(db_handle, uid);
	media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "update media view failed : %d", ret);

	return ret;
}

int media_svc_get_storage_id(MediaSvcHandle *handle, const char *path, char *storage_id)
{
	int ret = MS_MEDIA_ERR_NONE;
	sqlite3 * db_handle = (sqlite3 *)handle;

	media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
	media_svc_retvm_if(path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");

	ret = _media_svc_get_storage_uuid(db_handle, path, storage_id);

	return ret;
}

int media_svc_get_storage_path(MediaSvcHandle *handle, const char *storage_uuid, char **storage_path)
{
	int ret = MS_MEDIA_ERR_NONE;
	sqlite3 * db_handle = (sqlite3 *)handle;

	media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
	media_svc_retvm_if(storage_uuid == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_uuid is NULL");

	ret = _media_svc_get_storage_path(db_handle, storage_uuid, storage_path);

	return ret;
}

int media_svc_get_storage_scan_status(MediaSvcHandle *handle, const char *storage_uuid, media_svc_scan_status_type_e *storage_status)
{
	int ret = MS_MEDIA_ERR_NONE;
	sqlite3 * db_handle = (sqlite3 *)handle;

	media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
	media_svc_retvm_if(storage_uuid == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_uuid is NULL");

	ret = _media_svc_get_storage_scan_status(db_handle, storage_uuid, storage_status);

	return ret;
}

int media_svc_set_storage_scan_status(const char *storage_uuid, media_svc_scan_status_type_e storage_status, uid_t uid)
{
	int ret = MS_MEDIA_ERR_NONE;

	ret = _media_svc_set_storage_scan_status(storage_uuid, storage_status, uid);

	return ret;
}

int media_svc_get_storage_list(MediaSvcHandle *handle, char ***storage_list, char ***storage_id_list, int **scan_status_list, int *count)
{
	sqlite3 * db_handle = (sqlite3 *)handle;

	media_svc_debug_fenter();

	media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
	media_svc_retvm_if(count == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "count is NULL");

	return _media_svc_get_all_storage(db_handle, storage_list, storage_id_list, scan_status_list, count);
}

static int __media_svc_copy_para_to_content(media_svc_content_info_s *content_info, media_svc_content_info_s *new_content_info)
{
	int ret = MS_MEDIA_ERR_NONE;

	media_svc_retvm_if(content_info == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
	media_svc_retvm_if(new_content_info == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");

	if (content_info->storage_type == MEDIA_SVC_STORAGE_CLOUD) {
		new_content_info->size = content_info->size;
		new_content_info->modified_time = content_info->modified_time;
		new_content_info->is_drm = content_info->is_drm;
		new_content_info->media_type = content_info->media_type;

		if (STRING_VALID(content_info->mime_type)) {
			ret = __media_svc_malloc_and_strncpy(&new_content_info->mime_type, content_info->mime_type);
			if (ret != MS_MEDIA_ERR_NONE)
				media_svc_error("strcpy mime_type failed");
		}

		if (STRING_VALID(content_info->thumbnail_path)) {
			ret = __media_svc_malloc_and_strncpy(&new_content_info->thumbnail_path, content_info->thumbnail_path);
			if (ret != MS_MEDIA_ERR_NONE)
				media_svc_error("strcpy thumbnail_path failed");
		}

		new_content_info->media_meta.duration = content_info->media_meta.duration;
		new_content_info->media_meta.width = content_info->media_meta.width;
		new_content_info->media_meta.height = content_info->media_meta.height;
	}

	if (content_info->added_time > 0)
		new_content_info->added_time = content_info->added_time;
	new_content_info->last_played_time = content_info->last_played_time;
	new_content_info->played_count = content_info->played_count;
	new_content_info->favourate = content_info->favourate;

	if (STRING_VALID(content_info->file_name)) {
			ret = __media_svc_malloc_and_strncpy(&new_content_info->file_name, content_info->file_name);
			if (ret != MS_MEDIA_ERR_NONE)
				media_svc_error("strcpy file_name failed");
	}

	if (STRING_VALID(content_info->media_meta.title)) {
		ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.title, content_info->media_meta.title);
		if (ret != MS_MEDIA_ERR_NONE)
			media_svc_error("strcpy title failed");
	}

	if (STRING_VALID(content_info->media_meta.album)) {
		ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.album, content_info->media_meta.album);
		if (ret != MS_MEDIA_ERR_NONE)
			media_svc_error("strcpy album failed");
	}

	if (STRING_VALID(content_info->media_meta.artist)) {
		ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.artist, content_info->media_meta.artist);
		if (ret != MS_MEDIA_ERR_NONE)
			media_svc_error("strcpy artist failed");
	}

	if (STRING_VALID(content_info->media_meta.genre)) {
		ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.genre, content_info->media_meta.genre);
		if (ret != MS_MEDIA_ERR_NONE)
			media_svc_error("strcpy genre failed");
	}

	if (STRING_VALID(content_info->media_meta.composer)) {
		ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.composer, content_info->media_meta.composer);
		if (ret != MS_MEDIA_ERR_NONE)
			media_svc_error("strcpy composer failed");
	}

	if (STRING_VALID(content_info->media_meta.year)) {
		ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.year, content_info->media_meta.year);
		if (ret != MS_MEDIA_ERR_NONE)
			media_svc_error("strcpy year failed");
	}

	if (STRING_VALID(content_info->media_meta.recorded_date)) {
		ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.recorded_date, content_info->media_meta.recorded_date);
		if (ret != MS_MEDIA_ERR_NONE)
			media_svc_error("strcpy recorded_date failed");
	}

	if (STRING_VALID(content_info->media_meta.copyright)) {
		ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.copyright, content_info->media_meta.copyright);
		if (ret != MS_MEDIA_ERR_NONE)
			media_svc_error("strcpy copyright failed");
	}

	if (STRING_VALID(content_info->media_meta.track_num)) {
		ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.track_num, content_info->media_meta.track_num);
		if (ret != MS_MEDIA_ERR_NONE)
			media_svc_error("strcpy track_num failed");
	}

	if (STRING_VALID(content_info->media_meta.description)) {
		ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.description, content_info->media_meta.description);
		if (ret != MS_MEDIA_ERR_NONE)
			media_svc_error("strcpy description failed");
	}

	if (STRING_VALID(content_info->media_meta.weather)) {
		ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.weather, content_info->media_meta.weather);
		if (ret != MS_MEDIA_ERR_NONE)
			media_svc_error("strcpy weather failed");
	}

	if (STRING_VALID(content_info->media_meta.category)) {
		ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.category, content_info->media_meta.category);
		if (ret != MS_MEDIA_ERR_NONE)
			media_svc_error("strcpy category failed");
	}

	if (STRING_VALID(content_info->media_meta.keyword)) {
		ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.keyword, content_info->media_meta.keyword);
		if (ret != MS_MEDIA_ERR_NONE)
			media_svc_error("strcpy keyword failed");
	}

	if (STRING_VALID(content_info->media_meta.location_tag)) {
		ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.location_tag, content_info->media_meta.location_tag);
		if (ret != MS_MEDIA_ERR_NONE)
			media_svc_error("strcpy location_tag failed");
	}

	if (STRING_VALID(content_info->media_meta.content_name)) {
		ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.content_name, content_info->media_meta.content_name);
		if (ret != MS_MEDIA_ERR_NONE)
			media_svc_error("strcpy content_name failed");
	}

	if (STRING_VALID(content_info->media_meta.age_rating)) {
		ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.age_rating, content_info->media_meta.age_rating);
		if (ret != MS_MEDIA_ERR_NONE)
			media_svc_error("strcpy age_rating failed");
	}

	if (STRING_VALID(content_info->media_meta.author)) {
		ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.author, content_info->media_meta.author);
		if (ret != MS_MEDIA_ERR_NONE)
			media_svc_error("strcpy author failed");
	}

	if (STRING_VALID(content_info->media_meta.provider)) {
		ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.provider, content_info->media_meta.provider);
		if (ret != MS_MEDIA_ERR_NONE)
			media_svc_error("strcpy provider failed");
	}

	if (STRING_VALID(content_info->media_meta.datetaken)) {
		ret = __media_svc_malloc_and_strncpy(&new_content_info->media_meta.datetaken, content_info->media_meta.datetaken);
		if (ret != MS_MEDIA_ERR_NONE)
			media_svc_error("strcpy datetaken failed");

		new_content_info->timeline = __media_svc_get_timeline_from_str(content_info->media_meta.datetaken);
		if (new_content_info->timeline == 0) {
			media_svc_error("Failed to get timeline : %s", new_content_info->media_meta.datetaken);
			new_content_info->timeline = new_content_info->modified_time;
		} else {
			media_svc_debug("Timeline : %ld", new_content_info->timeline);
		}
	}

	//new_content_info->media_meta.bitrate = content_info->media_meta.bitrate;
	//new_content_info->media_meta.samplerate = content_info->media_meta.samplerate;
	//new_content_info->media_meta.channel = content_info->media_meta.channel;
	//new_content_info->media_meta.orientation = content_info->media_meta.orientation;

	if (content_info->media_meta.longitude != MEDIA_SVC_DEFAULT_GPS_VALUE)
		new_content_info->media_meta.longitude = content_info->media_meta.longitude;
	if (content_info->media_meta.latitude != MEDIA_SVC_DEFAULT_GPS_VALUE)
		new_content_info->media_meta.latitude = content_info->media_meta.latitude;
	if (content_info->media_meta.altitude != MEDIA_SVC_DEFAULT_GPS_VALUE)
		new_content_info->media_meta.altitude = content_info->media_meta.altitude;

	new_content_info->media_meta.rating = content_info->media_meta.rating;

	return 0;
}

int media_svc_insert_item_immediately_with_data(MediaSvcHandle *handle, media_svc_content_info_s *content_info, uid_t uid)
{
	int ret = MS_MEDIA_ERR_NONE;
	sqlite3 *db_handle = (sqlite3 *)handle;
	char folder_uuid[MEDIA_SVC_UUID_SIZE + 1] = {0, };
	bool append_album = FALSE;

	/* Checking parameters if they are valid */
	media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
	media_svc_retvm_if(content_info == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "content_info is NULL");
	media_svc_retvm_if(!STRING_VALID(content_info->path), MS_MEDIA_ERR_INVALID_PARAMETER, "file_path is NULL");

	if (content_info->storage_type == MEDIA_SVC_STORAGE_CLOUD) {
		media_svc_retvm_if(!STRING_VALID(content_info->mime_type), MS_MEDIA_ERR_INVALID_PARAMETER, "mime_type is NULL");

		if ((content_info->media_type < MEDIA_SVC_MEDIA_TYPE_IMAGE) || (content_info->media_type > MEDIA_SVC_MEDIA_TYPE_OTHER)) {
			media_svc_error("invalid media_type condition[%d]", content_info->media_type);
			return MS_MEDIA_ERR_INVALID_PARAMETER;
		}

		if (content_info->size <= 0) {
			media_svc_error("invalid size condition[%d]", content_info->size);
			return MS_MEDIA_ERR_INVALID_PARAMETER;
		}

		if (content_info->modified_time <= 0) {
			media_svc_error("invalid modified_time condition[%d]", content_info->modified_time);
			return MS_MEDIA_ERR_INVALID_PARAMETER;
		}
	}

	media_svc_debug("storage[%d], path[%s], media_type[%d]", content_info->storage_type, content_info->path, content_info->media_type);

	media_svc_content_info_s _new_content_info;
	memset(&_new_content_info, 0, sizeof(media_svc_content_info_s));

	media_svc_media_type_e media_type;

	ret = _media_svc_set_media_info(&_new_content_info, content_info->storage_uuid, content_info->storage_type, content_info->path, &media_type, FALSE);
	media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "fail _media_svc_set_media_info");

	if (content_info->storage_type != MEDIA_SVC_STORAGE_CLOUD) {
		if (media_type == MEDIA_SVC_MEDIA_TYPE_OTHER) {
			/*Do nothing.*/
		} else if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) {
			ret = _media_svc_extract_image_metadata(db_handle, &_new_content_info);
		} else {
			ret = _media_svc_extract_media_metadata(db_handle, &_new_content_info, uid);
		}

		media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);

		/* Extracting thumbnail */
		int ini_val = _media_svc_get_ini_value();
		if (ini_val == 1) {
			if (_new_content_info.thumbnail_path == NULL) {
				if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
					char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
					int width = 0;
					int height = 0;

					ret = _media_svc_request_thumbnail_with_origin_size(_new_content_info.path, thumb_path, sizeof(thumb_path), &width, &height, uid);
					if (ret == MS_MEDIA_ERR_NONE) {
						ret = __media_svc_malloc_and_strncpy(&(_new_content_info.thumbnail_path), thumb_path);
					}

					if (_new_content_info.media_meta.width <= 0)
						_new_content_info.media_meta.width = width;

					if (_new_content_info.media_meta.height <= 0)
						_new_content_info.media_meta.height = height;
				}
			}
		}
	}

	/* set othere data to the structure, which is passed as parameters */
	__media_svc_copy_para_to_content(content_info, &_new_content_info);

	/* Set or Get folder id */
	ret = _media_svc_get_and_append_folder_id_by_path(handle, _new_content_info.storage_uuid, _new_content_info.path, _new_content_info.storage_type, folder_uuid, uid);
	media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);

	ret = __media_svc_malloc_and_strncpy(&_new_content_info.folder_uuid, folder_uuid);
	media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &_new_content_info);

	/* register album table data */

	int album_id = 0;
	if (_new_content_info.media_type == MEDIA_SVC_MEDIA_TYPE_SOUND || _new_content_info.media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC) {
		ret = _media_svc_get_album_id(handle, _new_content_info.media_meta.album, _new_content_info.media_meta.artist, &album_id);

		if (ret != MS_MEDIA_ERR_NONE) {
			if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
				media_svc_debug("album does not exist. So start to make album art");
				append_album = TRUE;
			} else {
				media_svc_debug("other error");
				append_album = FALSE;
			}
		} else {
			_new_content_info.album_id = album_id;
			append_album = FALSE;

			if ((!strncmp(_new_content_info.media_meta.album, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))) ||
				(!strncmp(_new_content_info.media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN)))) {

				media_svc_debug("Unknown album or artist already exists. Extract thumbnail for Unknown.");
			} else {

				media_svc_debug("album already exists. don't need to make album art");
				ret = _media_svc_get_album_art_by_album_id(handle, album_id, &_new_content_info.thumbnail_path);
				media_svc_retv_del_if((ret != MS_MEDIA_ERR_NONE) && (ret != MS_MEDIA_ERR_DB_NO_RECORD), ret, &_new_content_info);
			}
		}
	}

	if (append_album == TRUE) {

		if ((strncmp(_new_content_info.media_meta.album, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))) &&
			(strncmp(_new_content_info.media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))))
			ret = _media_svc_append_album(handle, _new_content_info.media_meta.album, _new_content_info.media_meta.artist, _new_content_info.thumbnail_path, &album_id, uid);
		else
			ret = _media_svc_append_album(handle, _new_content_info.media_meta.album, _new_content_info.media_meta.artist, NULL, &album_id, uid);

		_new_content_info.album_id = album_id;
	}

	/* Insert to db - calling _media_svc_insert_item_with_data */
	ret = _media_svc_insert_item_with_data(db_handle, _new_content_info.storage_uuid, &_new_content_info, FALSE, FALSE, uid);

	if (ret == MS_MEDIA_ERR_NONE) {
		media_svc_debug("Insertion is successful.");
	}

	if (ret == MS_MEDIA_ERR_DB_CONSTRAINT_FAIL) {
		media_svc_error("This item is already inserted. This may be normal operation because other process already did this");
	}

	_media_svc_destroy_content_info(&_new_content_info);

	/* handling returned value - important */
	return ret;
}

void media_svc_destroy_content_info(media_svc_content_info_s *content_info)
{
	_media_svc_destroy_content_info(content_info);
}

int media_svc_generate_uuid(char **uuid)
{
	char *gen_uuid = NULL;
	gen_uuid = _media_info_generate_uuid();
	media_svc_retvm_if(gen_uuid == NULL, MS_MEDIA_ERR_INTERNAL, "Fail to generate uuid");

	*uuid = strdup(gen_uuid);

	return MS_MEDIA_ERR_NONE;
}

int media_svc_get_mmc_info(MediaSvcHandle *handle, char **storage_name, char **storage_path, int *validity, bool *info_exist)
{
	sqlite3 * db_handle = (sqlite3 *)handle;

	media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");

	return _media_svc_get_mmc_info(db_handle, storage_name, storage_path, validity, info_exist);
}

int media_svc_check_storage(MediaSvcHandle *handle, const char *storage_id, const char *storage_name, char **storage_path, int *validity)
{
	sqlite3 * db_handle = (sqlite3 *)handle;

	media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
	media_svc_retvm_if(storage_id == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
	media_svc_retvm_if(storage_path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_path is NULL");
	media_svc_retvm_if(validity == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "validity is NULL");

	return _media_svc_check_storage(db_handle, storage_id, storage_name, storage_path, validity);
}

int media_svc_update_storage(MediaSvcHandle *handle, const char *storage_id, const char *storage_path, uid_t uid)
{
	sqlite3 * db_handle = (sqlite3 *)handle;

	media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
	media_svc_retvm_if(storage_id == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
	media_svc_retvm_if(storage_path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_path is NULL");

	return _media_svc_update_storage_path(db_handle, storage_id, storage_path, uid);
}

int media_svc_insert_storage(MediaSvcHandle *handle, const char *storage_id, const char *storage_name, const char *storage_path, const char *storage_account, media_svc_storage_type_e storage_type, uid_t uid)
{
	int ret = MS_MEDIA_ERR_NONE;
	sqlite3 *db_handle = (sqlite3 *)handle;

	media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
	media_svc_retvm_if(storage_id == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
	media_svc_retvm_if(storage_path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_path is NULL");
	media_svc_retvm_if(__media_svc_check_storage(storage_type, TRUE) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");

	ret = _media_svc_append_storage(storage_id, storage_name, storage_path, storage_account, storage_type, uid);
	media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "append storage failed : %d", ret);

	if (strcmp(storage_id, MEDIA_SVC_DB_TABLE_MEDIA)) {
		ret = _media_svc_create_media_table_with_id(storage_id, uid);
		media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "create media table failed : %d", ret);

		ret = _media_svc_update_media_view(db_handle, uid);
		media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "update media view failed : %d", ret);
	}

	return ret;
}

int media_svc_delete_storage(MediaSvcHandle *handle, const char *storage_id, const char *storage_name, uid_t uid)
{
	int ret = MS_MEDIA_ERR_NONE;
	sqlite3 *db_handle = (sqlite3 *)handle;
	media_svc_storage_type_e storage_type;

	media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
	media_svc_retvm_if(storage_id == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");

	ret = _media_svc_get_storage_type(db_handle, storage_id, &storage_type);
	media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "_media_svc_get_storage_type_by_path failed : %d", ret);

	ret = _media_svc_delete_storage(storage_id, storage_name, uid);
	media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "remove storage failed : %d", ret);

	ret = _media_svc_delete_folder_by_storage_id(storage_id, storage_type, uid);
	if (ret != MS_MEDIA_ERR_NONE) {
		media_svc_error("fail to _media_svc_delete_folder_by_storage_id. error : [%d]", ret);
	}

	if ((storage_type == MEDIA_SVC_STORAGE_EXTERNAL_USB) || (storage_type == MEDIA_SVC_STORAGE_CLOUD)) {
		ret = _media_svc_drop_media_table(storage_id, uid);
		media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "drop table failed : %d", ret);

		ret = _media_svc_update_media_view(db_handle, uid);
		media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "update media view failed : %d", ret);
	}

	return ret;
}

int media_svc_insert_folder_begin(int data_cnt)
{
	media_svc_debug("Transaction data count : [%d]", data_cnt);

	media_svc_retvm_if(data_cnt < 1, MS_MEDIA_ERR_INVALID_PARAMETER, "data_cnt shuld be bigger than 1");

	g_media_svc_insert_folder_data_cnt = data_cnt;
	g_media_svc_insert_folder_cur_data_cnt = 0;

	return MS_MEDIA_ERR_NONE;
}

int media_svc_insert_folder_end(uid_t uid)
{
	int ret = MS_MEDIA_ERR_NONE;

	media_svc_debug_fenter();

	if (g_media_svc_insert_folder_cur_data_cnt > 0) {

		ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_INSERT_FOLDER, uid);
	}

	g_media_svc_insert_folder_data_cnt = 1;
	g_media_svc_insert_folder_cur_data_cnt = 0;

	return ret;
}

int media_svc_insert_folder(MediaSvcHandle *handle, const char *storage_id, media_svc_storage_type_e storage_type, const char *path, uid_t uid)
{
	int ret = MS_MEDIA_ERR_NONE;
	sqlite3 * db_handle = (sqlite3 *)handle;
	char folder_uuid[MEDIA_SVC_UUID_SIZE+1] = {0,};

	media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
	media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
	media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
	media_svc_retvm_if(__media_svc_check_storage(storage_type, FALSE) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");

	if (g_media_svc_insert_folder_data_cnt == 1) {

		ret = _media_svc_get_and_append_folder_id_by_folder_path(handle, storage_id, path, storage_type, folder_uuid, FALSE, uid);

	} else if (g_media_svc_insert_folder_cur_data_cnt < (g_media_svc_insert_folder_data_cnt - 1)) {

		ret = _media_svc_get_and_append_folder_id_by_folder_path(handle, storage_id, path, storage_type, folder_uuid, TRUE, uid);
		media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);

		g_media_svc_insert_folder_cur_data_cnt++;

	} else if (g_media_svc_insert_folder_cur_data_cnt == (g_media_svc_insert_folder_data_cnt - 1)) {

		ret = _media_svc_get_and_append_folder_id_by_folder_path(handle, storage_id, path, storage_type, folder_uuid, TRUE, uid);
		media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);

		ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_INSERT_FOLDER, uid);
		media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);

		g_media_svc_insert_folder_cur_data_cnt = 0;

	} else {
		media_svc_error("Error in media_svc_set_insert_folder");
		return MS_MEDIA_ERR_INTERNAL;
	}

	return ret;
}

int media_svc_delete_invalid_folder(const char *storage_id, uid_t uid)
{
	int ret = MS_MEDIA_ERR_NONE;

	ret = _media_svc_delete_invalid_folder(storage_id, uid);

	return ret;
}

int media_svc_set_folder_validity(MediaSvcHandle *handle, const char *storage_id, const char *start_path, int validity, bool is_recursive, uid_t uid)
{
	int ret = MS_MEDIA_ERR_NONE;
	sqlite3 * db_handle = (sqlite3 *)handle;

	media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");

	ret = _media_svc_set_folder_validity(db_handle, storage_id, start_path, validity, is_recursive, uid);

	return ret;
}

int media_svc_insert_item_pass1(MediaSvcHandle *handle, const char *storage_id, media_svc_storage_type_e storage_type, const char *path, int is_burst, uid_t uid)
{
	int ret = MS_MEDIA_ERR_NONE;
	sqlite3 * db_handle = (sqlite3 *)handle;
	char folder_uuid[MEDIA_SVC_UUID_SIZE+1] = {0,};
	media_svc_media_type_e media_type;

	media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
	media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
	media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
	media_svc_retvm_if(__media_svc_check_storage(storage_type, FALSE) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");

	media_svc_content_info_s content_info;
	memset(&content_info, 0, sizeof(media_svc_content_info_s));

	/*Set basic media info*/
	ret = _media_svc_set_media_info(&content_info, storage_id, storage_type, path, &media_type, FALSE);
	if (ret != MS_MEDIA_ERR_NONE) {
		media_svc_error("_media_svc_set_media_info fail %d", ret);
		return ret;
	}

	//media_svc_debug("total %d, cur %d insert flag %d", g_media_svc_insert_item_data_cnt, g_media_svc_insert_item_cur_data_cnt, g_insert_with_noti);

	/*Set or Get folder id*/
	ret = _media_svc_get_and_append_folder_id_by_path(db_handle, storage_id, path, storage_type, folder_uuid, uid);
	media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);

	ret = __media_svc_malloc_and_strncpy(&content_info.folder_uuid, folder_uuid);
	media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);

	if (g_media_svc_insert_item_data_cnt == 1) {

		ret = _media_svc_insert_item_pass1(db_handle, storage_id, &content_info, is_burst, FALSE, uid);
		media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);

		if (g_insert_with_noti)
			_media_svc_insert_item_to_noti_list(&content_info, g_media_svc_insert_item_cur_data_cnt++);
	} else if (g_media_svc_insert_item_cur_data_cnt < (g_media_svc_insert_item_data_cnt - 1)) {

		ret = _media_svc_insert_item_pass1(db_handle, storage_id, &content_info, is_burst, TRUE, uid);
		media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);

		if (g_insert_with_noti)
			_media_svc_insert_item_to_noti_list(&content_info, g_media_svc_insert_item_cur_data_cnt);

		media_svc_debug("g_media_svc_insert_item_cur_data_cnt %d", g_media_svc_insert_item_cur_data_cnt);
		g_media_svc_insert_item_cur_data_cnt++;

	} else if (g_media_svc_insert_item_cur_data_cnt == (g_media_svc_insert_item_data_cnt - 1)) {

		ret = _media_svc_insert_item_pass1(db_handle, storage_id, &content_info, is_burst, TRUE, uid);
		media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);

		if (g_insert_with_noti)
			_media_svc_insert_item_to_noti_list(&content_info, g_media_svc_insert_item_cur_data_cnt);

		ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_INSERT_ITEM, uid);
		media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);

		media_svc_debug("_media_svc_list_query_do over");

		if (g_insert_with_noti) {
			media_svc_debug("publish noti list %d", g_media_svc_insert_item_cur_data_cnt);
			_media_svc_publish_noti_list(g_media_svc_insert_item_cur_data_cnt + 1);
			_media_svc_destroy_noti_list(g_media_svc_insert_item_cur_data_cnt + 1);

			/* Recreate noti list */
			ret = _media_svc_create_noti_list(g_media_svc_insert_item_data_cnt);
			media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
		}

		g_media_svc_insert_item_cur_data_cnt = 0;

	} else {
		media_svc_error("Error in media_svc_insert_item_pass1");
		_media_svc_destroy_content_info(&content_info);
		return MS_MEDIA_ERR_INTERNAL;
	}

	_media_svc_destroy_content_info(&content_info);

	return MS_MEDIA_ERR_NONE;
}

int media_svc_insert_item_pass2(MediaSvcHandle *handle, const char *storage_id, media_svc_storage_type_e storage_type, int scan_type, const char *extract_path, int is_burst, uid_t uid)
{
	int ret = MS_MEDIA_ERR_NONE;
	sqlite3 * db_handle = (sqlite3 *)handle;
	sqlite3_stmt *sql_stmt = NULL;
	media_svc_media_type_e media_type;
	media_svc_content_info_s content_info;
	GArray *db_data_array = NULL;
	media_svc_item_info_s *db_data = NULL;
	int idx = 0;
	char *sql = NULL;

	media_svc_debug_fenter();

	media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
	media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
	media_svc_retvm_if(__media_svc_check_storage(storage_type, FALSE) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");

	if (scan_type == MS_MSG_DIRECTORY_SCANNING) {
		sql = sqlite3_mprintf("SELECT path, media_type FROM '%s' WHERE validity = 1 AND title IS NULL AND path LIKE '%q/%%'", storage_id, extract_path);
	} else if (scan_type == MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) {
		char folder_uuid[MEDIA_SVC_UUID_SIZE+1] = {0, };
		ret = _media_svc_get_folder_id_by_foldername(handle, storage_id, extract_path, folder_uuid, uid);
		media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);

		sql = sqlite3_mprintf("SELECT path, media_type FROM '%s' WHERE validity = 1 AND title IS NULL AND folder_uuid = '%q'", storage_id, folder_uuid);
	} else { /*Storage Scanning*/
		sql = sqlite3_mprintf("SELECT path, media_type FROM '%s' WHERE validity = 1 AND title IS NULL", storage_id);
	}

	ret = _media_svc_sql_prepare_to_step_simple(handle, sql, &sql_stmt);
	if (ret != MS_MEDIA_ERR_NONE) {
		media_svc_error("error when get list. err = [%d]", ret);
		return ret;
	}

	db_data_array = g_array_new(FALSE, FALSE, sizeof(media_svc_item_info_s*));
	if (db_data_array == NULL) {
		media_svc_error("db_data_array is NULL. Out of memory");
		return MS_MEDIA_ERR_OUT_OF_MEMORY;
	}

	while (sqlite3_step(sql_stmt) == SQLITE_ROW) {
		db_data = NULL;
		db_data = malloc(sizeof(media_svc_item_info_s));
		if (db_data == NULL) {
			media_svc_error("Out of memory");
			continue;
		}

		db_data->path = g_strdup((const char *)sqlite3_column_text(sql_stmt, 0));
		db_data->media_type = (int)sqlite3_column_int(sql_stmt, 1);

		g_array_append_val(db_data_array, db_data);
	}

	SQLITE3_FINALIZE(sql_stmt);

	while (db_data_array->len != 0) {
		db_data = NULL;
		db_data = g_array_index(db_data_array, media_svc_item_info_s*, 0);
		g_array_remove_index(db_data_array, 0);

		if ((db_data == NULL) || (db_data->path == NULL)) {
			media_svc_error("invalid db data");
			continue;
		}

		media_type = db_data->media_type;
		media_svc_debug("path is %s, media type %d", db_data->path, media_type);
		memset(&content_info, 0, sizeof(media_svc_content_info_s));
		__media_svc_malloc_and_strncpy(&content_info.path, db_data->path);

		content_info.media_type = media_type;
		content_info.storage_type = storage_type;

		_media_svc_set_default_value(&content_info, FALSE);

		if (media_type == MEDIA_SVC_MEDIA_TYPE_OTHER) {
			/*Do nothing.*/
		} else if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) {
			ret = _media_svc_extract_image_metadata(db_handle, &content_info);
		} else {
			ret = _media_svc_extract_media_metadata(db_handle, &content_info, uid);
		}

		ret = _media_svc_insert_item_pass2(storage_id, &content_info, is_burst, TRUE, uid);

		_media_svc_destroy_content_info(&content_info);
		SAFE_FREE(db_data->path);
		SAFE_FREE(db_data);
		idx++;
	}

	if (idx > 0)
		ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_UPDATE_ITEM, uid);

	g_array_free(db_data_array, FALSE);
	db_data_array = NULL;

	media_svc_debug_fleave();

	return MS_MEDIA_ERR_NONE;
}

int media_svc_delete_invalid_folder_by_path(MediaSvcHandle *handle, const char *storage_id, const char *folder_path, uid_t uid, int *delete_count)
{
	int ret = MS_MEDIA_ERR_NONE;
	sqlite3 * db_handle = (sqlite3 *)handle;

	media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");

	ret = _media_svc_delete_invalid_folder_by_path(db_handle, storage_id, folder_path, uid, delete_count);

	return ret;
}

int media_svc_check_folder_exist_by_path(MediaSvcHandle *handle, const char *storage_id, const char *folder_path)
{
	int ret = MS_MEDIA_ERR_NONE;
	sqlite3 * db_handle = (sqlite3 *)handle;
	int count = -1;

	media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
	media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
	media_svc_retvm_if(!STRING_VALID(folder_path), MS_MEDIA_ERR_INVALID_PARAMETER, "Path is NULL");

	ret = _media_svc_count_folder_with_path(db_handle, storage_id, folder_path, &count);
	media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);

	if (count > 0) {
		media_svc_debug("item is exist in database");
		return MS_MEDIA_ERR_NONE;
	} else {
		media_svc_debug("item is not exist in database");
		return MS_MEDIA_ERR_DB_NO_RECORD;
	}

	return MS_MEDIA_ERR_NONE;
}

int media_svc_check_subfolder_by_path(MediaSvcHandle *handle, const char *storage_id, const char *folder_path, int *count)
{
	int ret = MS_MEDIA_ERR_NONE;
	sqlite3 * db_handle = (sqlite3 *)handle;
	int cnt = -1;

	media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
	media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
	media_svc_retvm_if(!STRING_VALID(folder_path), MS_MEDIA_ERR_INVALID_PARAMETER, "Path is NULL");

	*count = 0;
	ret = _media_svc_count_subfolder_with_path(db_handle, storage_id, folder_path, &cnt);
	media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
	*count = cnt;

	if (cnt > 0) {
		media_svc_debug("item is exist in database");
		return MS_MEDIA_ERR_NONE;
	} else {
		media_svc_debug("item is not exist in database");
		return MS_MEDIA_ERR_DB_NO_RECORD;
	}

	return MS_MEDIA_ERR_NONE;
}

int media_svc_get_folder_id(MediaSvcHandle *handle, const char *storage_id, const char *path, char *folder_id)
{
	int ret = MS_MEDIA_ERR_NONE;
	sqlite3 * db_handle = (sqlite3 *)handle;

	media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
	media_svc_retvm_if(path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");

	ret = _media_svc_get_folder_uuid(db_handle, storage_id, path, folder_id);

	return ret;
}

int media_svc_append_query(const char *query, uid_t uid)
{
	int ret = MS_MEDIA_ERR_NONE;

	media_svc_retvm_if(query == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "query is NULL");

	ret = _media_svc_append_query_list(query, uid);

	return ret;
}

int media_svc_send_query(uid_t uid)
{
	int ret = MS_MEDIA_ERR_NONE;

	ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_UPDATE_COMMON, uid);

	return ret;
}