07614cbfef86eaea33f6717e05d8ddcdcdaada2d
[platform/framework/native/content.git] / src / FCnt_ContentManagerImpl.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 /**
17  * @file                FCnt_ContentManagerImpl.cpp
18  * @brief               This is the implementation file for the %_ContentManagerImpl class.
19  *
20  * This file contains implementation of the %_ContentManagerImpl class.
21  */
22
23 #include <new>
24 #include <stdlib.h>
25 #include <aul/aul.h>
26 #include <FAppApp.h>
27 #include <FBaseSysLog.h>
28 #include <FBaseDateTime.h>
29 #include <FBaseInteger.h>
30 #include <FBaseByteBuffer.h>
31 #include <FBaseUtilStringTokenizer.h>
32 #include <FCntContentManager.h>
33 #include <FCntContentManagerUtil.h>
34 #include <FCntImageContentInfo.h>
35 #include <FCntAudioContentInfo.h>
36 #include <FCntVideoContentInfo.h>
37 #include <FCntOtherContentInfo.h>
38 #include <FCntImageMetadata.h>
39 #include <FCntAudioMetadata.h>
40 #include <FCntVideoMetadata.h>
41 #include <FCntIContentScanListener.h>
42 #include <FCntIContentUpdateEventListener.h>
43 #include <FIoDirectory.h>
44 #include <FSysEnvironment.h>
45 #include <FApp_AppInfo.h>
46 #include <FBase_StringConverter.h>
47 #include <FIo_FileImpl.h>
48 #include "FCnt_ContentManagerImpl.h"
49 #include "FCnt_ContentManagerUtilImpl.h"
50 #include "FCnt_ContentInfoImpl.h"
51 #include "FCnt_ImageContentInfoImpl.h"
52 #include "FCnt_AudioContentInfoImpl.h"
53 #include "FCnt_VideoContentInfoImpl.h"
54 #include "FCnt_OtherContentInfoImpl.h"
55 #include "FCnt_ContentInfoHelper.h"
56
57 using namespace std;
58 using namespace Tizen::App;
59 using namespace Tizen::Base;
60 using namespace Tizen::Base::Collection;
61 using namespace Tizen::Base::Utility;
62 using namespace Tizen::Io;
63 using namespace Tizen::Locations;
64 using namespace Tizen::System;
65
66 namespace Tizen { namespace Content
67 {
68
69 static const int SYSTEM_TYPE_IMAGE = 0;
70 static const int SYSTEM_TYPE_VIDEO = 1;
71 static const int SYSTEM_TYPE_SOUND = 2;
72 static const int SYSTEM_TYPE_MUSIC = 3;
73 static const int SYSTEM_TYPE_OTHER = 4;
74 static const double DEFAULT_COORDINATE = -200.0;
75
76 // For extern declaration in FCntTypes.h
77 const wchar_t OSP_HOME[] = L"/Home/";
78 const wchar_t OSP_HOME_EXT[] = L"/HomeExt/";
79 const wchar_t OSP_MEDIA_PHONE[] = L"/Media/";
80 const wchar_t OSP_MEDIA_MMC[] = L"/Storagecard/Media/";
81
82 static result
83 ConvertError(int error)
84 {
85         result r = E_SUCCESS;
86
87         switch (error)
88         {
89         case MEDIA_CONTENT_ERROR_NONE:
90                 r = E_SUCCESS;
91                 break;
92
93         case MEDIA_CONTENT_ERROR_INVALID_PARAMETER:
94                 r = E_INVALID_ARG;
95                 break;
96
97         case MEDIA_CONTENT_ERROR_OUT_OF_MEMORY:
98                 r = E_OUT_OF_MEMORY;
99                 break;
100
101         case MEDIA_CONTENT_ERROR_DB_BUSY:
102                 r = E_SERVICE_BUSY;
103                 break;
104
105         case MEDIA_CONTENT_ERROR_DB_FAILED:
106                 r = E_SYSTEM;
107                 break;
108
109         default:
110                 r = E_SYSTEM;
111                 break;
112         }
113
114         return r;
115 }
116
117 static void
118 OnScanCompleted(media_content_error_e error, void* user_data)
119 {
120         SysLog(NID_CNT, "OnScanCompleted callback method is called.");
121
122         ClearLastResult();
123         result r = E_SUCCESS;
124         String scanPath(L"");
125         IContentScanListener* pListener = null;
126         RequestId reqId;
127         unique_ptr< _ScanResult > pScanResult;
128
129         SysTryLogCatch(NID_CNT, user_data != null, , "OnScanCompleted failed.");
130
131         pScanResult = unique_ptr< _ScanResult >(static_cast< _ScanResult* >(user_data));
132
133         SysTryLogCatch(NID_CNT, pScanResult != null, , "OnScanCompleted failed.");
134         SysTryLogCatch(NID_CNT, pScanResult->pScanListener != null, , "Listener is null. OnScanCompleted succeeded.");
135
136         scanPath = pScanResult->scanPath;
137         pListener = pScanResult->pScanListener;
138         reqId = pScanResult->requestId;
139
140         r = ConvertError(error);
141
142         pListener->OnContentScanCompleted(reqId, scanPath, r);
143         SysLog(NID_CNT, "OnContentScanCompleted fired.");
144
145 CATCH:
146         int val = media_content_disconnect();
147         SysTryLog(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, "The disconnection failed[%d].", val);
148 }
149
150 static void
151 OnContentUpdateCompleted(media_content_error_e error, int pid, media_content_db_update_item_type_e update_item,
152                 media_content_db_update_type_e update_type, media_content_type_e media_type, char* uuid, char* path, char* mime_type, void* user_data)
153 {
154         SysLog(NID_CNT, "OnContentUpdateCompleted callback method is called.");
155
156         result r = E_SUCCESS;
157
158         SysTryLogReturn(NID_CNT, user_data != null, , "OnContentUpdateCompleted failed.");
159
160         _ContentManagerImpl* pTempManagerImpl = static_cast< _ContentManagerImpl* >(user_data);
161         SysTryLogReturn(NID_CNT, pTempManagerImpl != null, , "pTempManagerImpl is null.");
162
163         IContentUpdateEventListener* pListener = pTempManagerImpl->GetListener();
164         SysTryLogReturn(NID_CNT, pListener != null, , "IContentUpdateEventListener is null.");
165
166         if (error != MEDIA_CONTENT_ERROR_NONE)
167         {
168                 r = E_SYSTEM;
169         }
170
171         switch (update_item)
172         {
173         case MEDIA_ITEM_FILE:
174         {
175                 ContentType contentType = CONTENT_TYPE_UNKNOWN;
176
177                 switch (media_type)
178                 {
179                 case MEDIA_CONTENT_TYPE_IMAGE:
180                         contentType = CONTENT_TYPE_IMAGE;
181                         break;
182
183                 case MEDIA_CONTENT_TYPE_VIDEO:
184                         contentType = CONTENT_TYPE_VIDEO;
185                         break;
186
187                 case MEDIA_CONTENT_TYPE_SOUND:
188                         // fall through
189                 case MEDIA_CONTENT_TYPE_MUSIC:
190                         contentType = CONTENT_TYPE_AUDIO;
191                         break;
192
193                 case MEDIA_CONTENT_TYPE_OTHERS:
194                         contentType = CONTENT_TYPE_OTHER;
195                         break;
196
197                 default:
198                         r = E_SYSTEM;
199                         SysLog(NID_CNT, "media_type is invalid.");
200                         break;
201                 }
202
203                 String str(uuid);
204                 ContentId contentId;
205
206                 result res = UuId::Parse(str, contentId);
207                 SysTryLogReturn(NID_CNT, !IsFailed(res), , "Failed to parse to the content ID.");
208
209                 switch (update_type)
210                 {
211                 case MEDIA_CONTENT_INSERT:
212                         pListener->OnContentFileCreated(contentId, contentType, r);
213                         break;
214
215                 case MEDIA_CONTENT_DELETE:
216                         pListener->OnContentFileDeleted(contentId, contentType, r);
217                         break;
218
219                 case MEDIA_CONTENT_UPDATE:
220                         pListener->OnContentFileUpdated(contentId, contentType, r);
221                         break;
222
223                 default:
224                         SysLog(NID_CNT, "update_type is invalid.");
225                         break;
226                 }
227                 break;
228         }
229
230         case MEDIA_ITEM_DIRECTORY:
231         {
232                 String directoryPath(path);
233
234                 pListener->OnContentDirectoryScanCompleted(directoryPath, r);
235                 break;
236         }
237
238         default:
239                 SysLog(NID_CNT, "update_item is invalid.");
240                 break;
241         }
242
243         SysLog(NID_CNT, "Fire the OnContentUpdateCompleted method.");
244 }
245
246 _ContentManagerImpl::_ContentManagerImpl(void)
247         : __isConnected(false)
248         , __pListener(null)
249 {
250
251 }
252
253 _ContentManagerImpl::~_ContentManagerImpl(void)
254 {
255         int val;
256
257         if (GetListener())
258         {
259                 val = media_content_unset_db_updated_cb();
260                 SysLog(NID_CNT, "media_content_unset_db_updated_cb result[%d].", val);
261         }
262
263         val = media_content_disconnect();
264         SysLog(NID_CNT, "media_content_disconnect result[%d].", val);
265 }
266
267 _ContentManagerImpl*
268 _ContentManagerImpl::GetInstance(ContentManager& contentManager)
269 {
270         return contentManager.__pContentManagerImpl;
271 }
272
273 const _ContentManagerImpl*
274 _ContentManagerImpl::GetInstance(const ContentManager& contentManager)
275 {
276         return contentManager.__pContentManagerImpl;
277 }
278
279 result
280 _ContentManagerImpl::Construct(void)
281 {
282         int val = media_content_connect();
283         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM,
284                         "The connection failed[%d].", val);
285
286         SysLog(NID_CNT, "media_content_connect result[%d].", val);
287
288         __isConnected = true;
289
290         return E_SUCCESS;
291 }
292
293 ContentId
294 _ContentManagerImpl::CreateContent(const ContentInfo& contentInfo)
295 {
296         ClearLastResult();
297
298         _ContentInfoImpl* pInfoImpl = const_cast< _ContentInfoImpl* >(_ContentInfoImpl::GetInstance(contentInfo));
299         SysTryReturn(NID_CNT, pInfoImpl != null, UuId::GetInvalidUuId(), E_INVALID_ARG,
300                         "[E_INVALID_ARG] Invalid argument is used. ContentInfo is invalid.");
301
302         String contentPath(pInfoImpl->GetPhysicalContentPath());
303         String changedPath(L"");
304
305         result r = ChangeTizenPathToCompat(contentPath, changedPath);
306         SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] Failed to perform ChangeTizenPathToCompat.", GetErrorMessage(r));
307
308         SysTryReturn(NID_CNT, _FileImpl::IsFileExist(changedPath), UuId::GetInvalidUuId(), E_FILE_NOT_FOUND,
309                         "[%s] The file cound not be found.", GetErrorMessage(E_FILE_NOT_FOUND));
310
311         SysTryReturn(NID_CNT, pInfoImpl->GetContentId() == UuId::GetInvalidUuId(), UuId::GetInvalidUuId(),
312                         E_INVALID_ARG, "[E_INVALID_ARG] The contentId is not empty.");
313
314         // Compare the type of input parameter and system
315         ContentType inputType = pInfoImpl->GetContentType();
316         ContentType sysType = _ContentManagerUtilImpl::CheckContentType(contentPath, true);
317
318         ClearLastResult();
319
320         if (inputType != sysType)
321         {
322                 if (!(inputType == CONTENT_TYPE_OTHER && sysType == CONTENT_TYPE_UNKNOWN))
323                 {
324                         SysLogException(NID_CNT, E_INVALID_ARG,
325                                         "[E_INVALID_ARG] The type is not match[%d, %d].", inputType, sysType);
326                         return UuId::GetInvalidUuId();
327                 }
328         }
329
330         // Save data to database with contentPath.
331         unique_ptr<char[]> pStr(_StringConverter::CopyToCharArrayN(contentPath));
332         SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
333                         "[E_OUT_OF_MEMORY] The memory is insufficient.");
334
335         media_info_h tempMediaInfo = null;
336         unique_ptr<media_info_s, _MediaInfoDeleter> pMediaInfo(null);
337
338         int val = media_info_insert_to_db(pStr.get(), &tempMediaInfo);
339         SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
340                         "The registration to database failed[%d].", val);
341
342         pMediaInfo.reset(tempMediaInfo);
343
344         ContentId contentId = SaveDataToDatabase(pMediaInfo.get(), pInfoImpl);
345         r = GetLastResult();
346         SysTryCatch(NID_CNT, contentId != UuId::GetInvalidUuId(), , r,
347                         "[%s] The registration to database failed.", GetErrorMessage(r));
348
349         return contentId;
350
351 CATCH:
352         // There are two steps(insert and update) for content registration.
353         // If the update failed after inserting, the inserted data SHOULD be deleted from here.
354         char* pTempMediaId = null;
355         unique_ptr<char, CharDeleter> pMediaId(null);
356         val = media_info_get_media_id(pMediaInfo.get(), &pTempMediaId);
357         if (pTempMediaId != null)
358         {
359                 pMediaId.reset(pTempMediaId);
360         }
361         else
362         {
363                 SysLog(NID_CNT, "Failed to perform media_info_get_media_id operation.");
364                 return UuId::GetInvalidUuId();
365         }
366
367         val = media_info_delete_from_db(pMediaId.get());
368         SysLog(NID_CNT, "The result of deletion from database[%d].", val);
369
370         return UuId::GetInvalidUuId();
371 }
372
373 ContentId
374 _ContentManagerImpl::CreateContent(const ByteBuffer& byteBuffer, const String& destinationPath,
375                                             const ContentInfo* pContentInfo)
376 {
377         ClearLastResult();
378
379         // Check parameters(for length)
380         SysTryReturn(NID_CNT, byteBuffer.GetRemaining() > 0, UuId::GetInvalidUuId(), E_INVALID_ARG,
381                         "[E_INVALID_ARG] byteBuffer is invalid.");
382
383         // Check parameters(for path compatibility)
384         SysTryReturn(NID_CNT, VerifyMediaFilePathCompatibility(destinationPath), UuId::GetInvalidUuId(),
385                         E_INVALID_ARG, "[E_INVALID_ARG] %ls is not compatible.", destinationPath.GetPointer());
386         SysTryReturn(NID_CNT, !_FileImpl::IsFileExist(destinationPath), UuId::GetInvalidUuId(), E_FILE_ALREADY_EXIST,
387                         "[E_FILE_ALREADY_EXIST] The specified file already exists.");
388
389         // Create a file with bytebuffer
390         unique_ptr<File> pFile(new (nothrow) File);
391         SysTryReturn(NID_CNT, pFile != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
392                         "[E_OUT_OF_MEMORY] The memory is insufficient.");
393
394         result r = pFile->Construct(destinationPath, L"w+");
395         SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), r,
396                         "[%s] The destination file can not be created.", GetErrorMessage(r));
397
398         _FileImpl* pFileImpl = _FileImpl::GetInstance(*pFile);
399         SysTryReturn(NID_CNT, pFileImpl != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
400                         "[E_OUT_OF_MEMORY] The memory is insufficient.");
401
402         r = pFileImpl->Write(byteBuffer);
403         SysTryReturn(NID_CNT, !(IsFailed(r)), UuId::GetInvalidUuId(), r,
404                         "[%s] The data can not be written in the destination file.", GetErrorMessage(r));
405
406         // for release file pointer
407         pFile.reset();
408
409         int val = 0;
410         ContentId contentId;
411         _ContentInfoImpl* pInfoImpl = null;
412         _ImageContentInfoImpl imageContentInfoImpl;
413         _AudioContentInfoImpl audioContentInfoImpl;
414         _VideoContentInfoImpl videoContentInfoImpl;
415         _OtherContentInfoImpl otherContentInfoImpl;
416         media_info_h tempMediaInfo = null;
417         unique_ptr<media_info_s, _MediaInfoDeleter> pMediaInfo(null);
418         unique_ptr<char[]> pStr(null);
419         String destPath(L"");
420
421         r = ChangeCompatPathToTizen(destinationPath, destPath);
422         SysTryCatch(NID_CNT, !IsFailed(r), , r, "[%s] Failed to perform ChangedCompatPathToTizen.", GetErrorMessage(r));
423
424         if (pContentInfo != null)
425         {
426                 pInfoImpl = const_cast< _ContentInfoImpl* >(_ContentInfoImpl::GetInstance(*pContentInfo));
427                 SysTryCatch(NID_CNT, pInfoImpl != null, , E_INVALID_ARG,
428                                 "[E_INVALID_ARG] Invalid argument is used. ContentInfo is invalid.");
429
430                 SysTryCatch(NID_CNT, pInfoImpl->GetContentId() == UuId::GetInvalidUuId(), , E_INVALID_ARG,
431                                 "[E_INVALID_ARG] The content already exists in database.");
432
433                 // Compare the type of input parameter and system
434                 // CheckContentType() need actual file. so it should be checked after creating the file.
435                 ContentType sysType = _ContentManagerUtilImpl::CheckContentType(destinationPath, true);
436                 ContentType inputType = pInfoImpl->GetContentType();
437
438                 ClearLastResult();
439
440                 if (inputType != sysType)
441                 {
442                         if (!(inputType == CONTENT_TYPE_OTHER && sysType == CONTENT_TYPE_UNKNOWN))
443                         {
444                                 SysLogException(NID_CNT, E_INVALID_ARG,
445                                                 "[E_INVALID_ARG] The type is not match[%d, %d].", inputType, sysType);
446                                 goto CATCH;
447                         }
448                 }
449
450                 // Sets the content path
451                 pInfoImpl->SetContentPath(destPath);
452         }
453         else
454         {
455                 ContentType contentType = _ContentManagerUtilImpl::CheckContentType(destinationPath, true);
456
457                 ClearLastResult();
458
459                 // Set the content path
460                 if (contentType == CONTENT_TYPE_IMAGE)
461                 {
462                         r = imageContentInfoImpl.Construct(&destinationPath);
463                         SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY,
464                                         "[E_OUT_OF_MEMORY] Failed to perform Construct for ImageContentInfoImpl.");
465
466                         imageContentInfoImpl.SetContentPath(destPath);
467                         pInfoImpl = dynamic_cast< _ContentInfoImpl* >(&imageContentInfoImpl);
468                 }
469                 else if (contentType == CONTENT_TYPE_AUDIO)
470                 {
471                         r = audioContentInfoImpl.Construct(&destinationPath);
472                         SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY,
473                                         "[E_OUT_OF_MEMORY] Failed to perform Construct for AudioContentInfoImpl.");
474
475                         audioContentInfoImpl.SetContentPath(destPath);
476                         pInfoImpl = dynamic_cast< _ContentInfoImpl* >(&audioContentInfoImpl);
477                 }
478                 else if (contentType == CONTENT_TYPE_VIDEO)
479                 {
480                         r = videoContentInfoImpl.Construct(&destinationPath);
481                         SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY,
482                                         "[E_OUT_OF_MEMORY] Failed to perform Construct for VideoContentInfoImpl.");
483
484                         videoContentInfoImpl.SetContentPath(destPath);
485                         pInfoImpl = dynamic_cast< _ContentInfoImpl* >(&videoContentInfoImpl);
486                 }
487                 else
488                 {
489                         r = otherContentInfoImpl.Construct(&destinationPath);
490                         SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY,
491                                         "[E_OUT_OF_MEMORY] Failed to perform Construct for OtherContentInfoImpl.");
492
493                         otherContentInfoImpl.SetContentPath(destPath);
494                         pInfoImpl = dynamic_cast< _ContentInfoImpl* >(&otherContentInfoImpl);
495                 }
496         }
497
498         // Register the content to database directly.
499         pStr.reset(_StringConverter::CopyToCharArrayN(destPath));
500         SysTryCatch(NID_CNT, pStr != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
501
502         val = media_info_insert_to_db(pStr.get(), &tempMediaInfo);
503         SysTryCatch(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, , ConvertError(val),
504                         "media_info_insert_to_db failed[%d].", val);
505
506         pMediaInfo.reset(tempMediaInfo);
507
508         contentId = SaveDataToDatabase(pMediaInfo.get(), pInfoImpl);
509         r = GetLastResult();
510         SysTryCatch(NID_CNT, contentId != UuId::GetInvalidUuId(), , r,
511                         "[%s] SaveDataToDatabase failed.", GetErrorMessage(r));
512
513         return contentId;
514
515 CATCH:
516         result saveResult = GetLastResult();
517
518         // If the destination file is made by this method, it should be deleted when error occurs.
519         r = _FileImpl::Remove(destinationPath);
520         SysLog(NID_CNT, "Remove[%s].", GetErrorMessage(r));
521
522         if (pMediaInfo != null)
523         {
524                 char* pTempMediaId = null;
525                 unique_ptr<char, CharDeleter> pMediaId(null);
526                 val = media_info_get_media_id(pMediaInfo.get(), &pTempMediaId);
527                 if (pTempMediaId != null)
528                 {
529                         pMediaId.reset(pTempMediaId);
530                 }
531                 else
532                 {
533                         SysLog(NID_CNT, "Failed to perform media_info_get_media_id operation.");
534                         return UuId::GetInvalidUuId();
535                 }
536
537                 val = media_info_delete_from_db(pMediaId.get());
538                 SysLog(NID_CNT, "The result of deletion from database[%d].", val);
539         }
540
541         SetLastResult(saveResult);
542         return UuId::GetInvalidUuId();
543 }
544
545 ContentId
546 _ContentManagerImpl::CreateContent(const String& sourcePath, const String& destinationPath, bool deleteSource,
547                                             const ContentInfo* pContentInfo)
548 {
549         ClearLastResult();
550
551         // Check parameters(for type)
552         SysTryReturn(NID_CNT, _FileImpl::GetFileExtension(sourcePath) == _FileImpl::GetFileExtension(destinationPath),
553                         UuId::GetInvalidUuId(), E_INVALID_ARG, "[E_INVALID_ARG] There is a mismatch between the type of source and dest path.");
554
555         // Check parameters(for path compatibility)
556         SysTryReturn(NID_CNT, VerifyHomeFilePathCompatibility(sourcePath), UuId::GetInvalidUuId(), E_INVALID_ARG,
557                         "[E_INVALID_ARG] %ls is not compatible.", sourcePath.GetPointer());
558         SysTryReturn(NID_CNT, VerifyMediaFilePathCompatibility(destinationPath), UuId::GetInvalidUuId(),
559                         E_INVALID_ARG, "[E_INVALID_ARG] %ls is not compatible.", destinationPath.GetPointer());
560
561         result r = _FileImpl::Copy(sourcePath, destinationPath, true);
562         SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), r, "[%s] Copying the file failed.", GetErrorMessage(r));
563
564         int val = 0;
565         ContentId contentId;
566         _ContentInfoImpl* pInfoImpl = null;
567         _ImageContentInfoImpl imageContentInfoImpl;
568         _AudioContentInfoImpl audioContentInfoImpl;
569         _VideoContentInfoImpl videoContentInfoImpl;
570         _OtherContentInfoImpl otherContentInfoImpl;
571         media_info_h tempMediaInfo = null;
572         unique_ptr<media_info_s, _MediaInfoDeleter> pMediaInfo(null);
573         unique_ptr<char[]> pStr(null);
574         String destPath(L"");
575
576         r = ChangeCompatPathToTizen(destinationPath, destPath);
577         SysTryCatch(NID_CNT, !IsFailed(r), , r, "[%s] Failed to perform ChangedCompatPathToTizen.", GetErrorMessage(r));
578
579         if (pContentInfo != null)
580         {
581                 pInfoImpl = const_cast< _ContentInfoImpl* >(_ContentInfoImpl::GetInstance(*pContentInfo));
582                 SysTryCatch(NID_CNT, pInfoImpl != null, , E_INVALID_ARG,
583                                 "[E_INVALID_ARG] Invalid argument is used. ContentInfo is invalid.");
584
585                 SysTryCatch(NID_CNT, pInfoImpl->GetContentId() == UuId::GetInvalidUuId(), , E_INVALID_ARG,
586                                 "[E_INVALID_ARG] The content already exists in database.");
587
588                 // Compare the type of input parameter and system
589                 // CheckContentType() need actual file. so it should be checked after creating the file.
590                 ContentType sysType = _ContentManagerUtilImpl::CheckContentType(destinationPath, true);
591                 ContentType inputType = pInfoImpl->GetContentType();
592
593                 ClearLastResult();
594
595                 if (inputType != sysType)
596                 {
597                         if (!(inputType == CONTENT_TYPE_OTHER && sysType == CONTENT_TYPE_UNKNOWN))
598                         {
599                                 SysLogException(NID_CNT, E_INVALID_ARG,
600                                                  "[E_INVALID_ARG] The type is not match[%d, %d].", inputType, sysType);
601                                 goto CATCH;
602                         }
603                 }
604
605                 // Set the content path
606                 pInfoImpl->SetContentPath(destPath);
607         }
608         else
609         {
610                 ContentType contentType = _ContentManagerUtilImpl::CheckContentType(destinationPath, true);
611
612                 ClearLastResult();
613
614                 // Set the content path
615                 if (contentType == CONTENT_TYPE_IMAGE)
616                 {
617                         r = imageContentInfoImpl.Construct(&destinationPath);
618                         SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY,
619                                         "[E_OUT_OF_MEMORY] Failed to perform Construct for ImageContentInfoImpl.");
620
621                         imageContentInfoImpl.SetContentPath(destPath);
622                         pInfoImpl = dynamic_cast< _ContentInfoImpl* >(&imageContentInfoImpl);
623                 }
624                 else if (contentType == CONTENT_TYPE_AUDIO)
625                 {
626                         r = audioContentInfoImpl.Construct(&destinationPath);
627                         SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY,
628                                         "[E_OUT_OF_MEMORY] Failed to perform Construct for AudioContentInfoImpl.");
629
630                         audioContentInfoImpl.SetContentPath(destPath);
631                         pInfoImpl = dynamic_cast< _ContentInfoImpl* >(&audioContentInfoImpl);
632                 }
633                 else if (contentType == CONTENT_TYPE_VIDEO)
634                 {
635                         r = videoContentInfoImpl.Construct(&destinationPath);
636                         SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY,
637                                         "[E_OUT_OF_MEMORY] Failed to perform Construct for VideoContentInfoImpl.");
638
639                         videoContentInfoImpl.SetContentPath(destPath);
640                         pInfoImpl = dynamic_cast< _ContentInfoImpl* >(&videoContentInfoImpl);
641                 }
642                 else
643                 {
644                         r = otherContentInfoImpl.Construct(&destinationPath);
645                         SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY,
646                                         "[E_OUT_OF_MEMORY] Failed to perform Construct for OtherContentInfoImpl.");
647
648                         otherContentInfoImpl.SetContentPath(destPath);
649                         pInfoImpl = dynamic_cast< _ContentInfoImpl* >(&otherContentInfoImpl);
650                 }
651         }
652
653         pStr.reset(_StringConverter::CopyToCharArrayN(destPath));
654         SysTryCatch(NID_CNT, pStr != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
655
656         val = media_info_insert_to_db(pStr.get(), &tempMediaInfo);
657         SysTryCatch(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, , ConvertError(val),
658                         "media_info_insert_to_db failed[%d].", val);
659
660         pMediaInfo.reset(tempMediaInfo);
661
662         contentId = SaveDataToDatabase(pMediaInfo.get(), pInfoImpl);
663         r = GetLastResult();
664         SysTryCatch(NID_CNT, contentId != UuId::GetInvalidUuId(), , r,
665                         "[%s] SaveDataToDatabase failed.", GetErrorMessage(r));
666
667         if (deleteSource)
668         {
669                 unique_ptr<char[]> pContentPath(_StringConverter::CopyToCharArrayN(sourcePath));
670                 SysTryCatch(NID_CNT, !IsFailed(r), , E_OUT_OF_MEMORY, "[%s] pContentPath is null.", GetErrorMessage(E_OUT_OF_MEMORY));
671
672                 r = _FileImpl::Remove(sourcePath);
673                 SysTryCatch(NID_CNT, !IsFailed(r), , r, "[%s] Failed to perform Remove operation.", GetErrorMessage(r));
674
675                 val = media_content_scan_file(pContentPath.get());
676                 SysTryLog(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, "Failed to perform media_content_scan_file[%d].", val);
677         }
678
679         return contentId;
680
681 CATCH:
682         result saveResult = GetLastResult();
683
684         r = _FileImpl::Remove(destinationPath);
685         SysLog(NID_CNT, "Remove[%s].", GetErrorMessage(r));
686
687         if (pMediaInfo != null)
688         {
689                 char* pTempMediaId = null;
690                 unique_ptr<char, CharDeleter> pMediaId(null);
691                 val = media_info_get_media_id(pMediaInfo.get(), &pTempMediaId);
692                 if (pTempMediaId != null)
693                 {
694                         pMediaId.reset(pTempMediaId);
695                 }
696                 else
697                 {
698                         SysLog(NID_CNT, "Failed to perform media_info_get_media_id operation.");
699                         return UuId::GetInvalidUuId();
700                 }
701
702                 val = media_info_delete_from_db(pMediaId.get());
703                 SysLog(NID_CNT, "The result of deletion from database[%d].", val);
704         }
705
706         SetLastResult(saveResult);
707         return UuId::GetInvalidUuId();
708 }
709
710 ContentInfo*
711 _ContentManagerImpl::GetContentInfoN(const ContentId& contentId) const
712 {
713         ClearLastResult();
714
715         SysTryReturn(NID_CNT, contentId != UuId::GetInvalidUuId(), null, E_INVALID_ARG,
716                         "[E_INVALID_ARG] The contentId is invalid.");
717
718         unique_ptr<char[]> pStr(_StringConverter::CopyToCharArrayN(contentId.ToString()));
719         SysTryReturn(NID_CNT, pStr != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
720
721         media_info_h tempMediaInfo = null;
722         unique_ptr<media_info_s, _MediaInfoDeleter> pMediaInfo(null);
723         int val = media_info_get_media_from_db(pStr.get(), &tempMediaInfo);
724         SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, null, ConvertError(val),
725                         "media_info_get_media_from_db failed[%d].", val);
726
727         pMediaInfo.reset(tempMediaInfo);
728
729         media_content_type_e systemType = MEDIA_CONTENT_TYPE_IMAGE;
730         val = media_info_get_media_type(pMediaInfo.get(), &systemType);
731         SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, null, ConvertError(val),
732                         "media_info_get_media_type failed[%d].", val);
733
734         char* pTempFilePath = null;
735         val = media_info_get_file_path(pMediaInfo.get(), &pTempFilePath);
736         SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, null, ConvertError(val),
737                         "media_info_get_file_path failed[%d].", val);
738
739         unique_ptr<char, CharDeleter> pFilePath(pTempFilePath);
740         String contentPath(pFilePath.get());
741         String changedPath(L"");
742
743         result r = E_SUCCESS;
744
745         r = ChangeTizenPathToCompat(contentPath, changedPath);
746         SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] Failed to perform ChangeTizenPathToCompat.", GetErrorMessage(r));
747
748         SysTryReturn(NID_CNT, _FileImpl::IsFileExist(changedPath), null, E_FILE_NOT_FOUND,
749                         "[E_FILE_NOT_FOUND] The file corresponding to contentId could not be found.");
750
751         if (systemType == SYSTEM_TYPE_IMAGE)
752         {
753                 unique_ptr< ImageContentInfo > pImageContentInfo(new (nothrow) ImageContentInfo);
754                 SysTryReturn(NID_CNT, pImageContentInfo != null, null, E_OUT_OF_MEMORY,
755                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
756
757                 r = pImageContentInfo->Construct(&changedPath);
758                 r = ConvertErrorToResult(r);
759                 SysTryReturn(NID_CNT, !IsFailed(r), null, r,
760                                 "[%s] Failed to perform Construct operation to ImageContentInfo.", GetErrorMessage(r));
761
762                 _ImageContentInfoImpl* pImageContentInfoImpl = _ImageContentInfoImpl::GetInstance(*(pImageContentInfo.get()));
763                 SysTryReturn(NID_CNT, pImageContentInfoImpl != null, null, E_OUT_OF_MEMORY,
764                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
765
766                 r = MakeContentInfo(pMediaInfo.get(), systemType, pImageContentInfoImpl);
767                 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
768
769                 return pImageContentInfo.release();
770         }
771         else if (systemType == SYSTEM_TYPE_SOUND || systemType == SYSTEM_TYPE_MUSIC)
772         {
773                 unique_ptr< AudioContentInfo > pAudioContentInfo(new (nothrow) AudioContentInfo);
774                 SysTryReturn(NID_CNT, pAudioContentInfo != null, null, E_OUT_OF_MEMORY,
775                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
776
777                 r = pAudioContentInfo->Construct(&changedPath);
778                 r = ConvertErrorToResult(r);
779                 SysTryReturn(NID_CNT, !IsFailed(r), null, r,
780                                 "[%s] Failed to perform Construct operation to AudioContentInfo.", GetErrorMessage(r));
781
782                 _AudioContentInfoImpl* pAudioContentInfoImpl = _AudioContentInfoImpl::GetInstance(*(pAudioContentInfo.get()));
783                 SysTryReturn(NID_CNT, pAudioContentInfoImpl != null, null, E_OUT_OF_MEMORY,
784                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
785
786                 r = MakeContentInfo(pMediaInfo.get(), systemType, pAudioContentInfoImpl);
787                 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
788
789                 return pAudioContentInfo.release();
790         }
791         else if (systemType == SYSTEM_TYPE_VIDEO)
792         {
793                 unique_ptr< VideoContentInfo > pVideoContentInfo(new (nothrow) VideoContentInfo);
794                 SysTryReturn(NID_CNT, pVideoContentInfo != null, null, E_OUT_OF_MEMORY,
795                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
796
797                 r = pVideoContentInfo->Construct(&changedPath);
798                 r = ConvertErrorToResult(r);
799                 SysTryReturn(NID_CNT, !IsFailed(r), null, r,
800                                 "[%s] Failed to perform Construct operation to VideoContentInfo.", GetErrorMessage(r));
801
802                 _VideoContentInfoImpl* pVideoContentInfoImpl = _VideoContentInfoImpl::GetInstance(*(pVideoContentInfo.get()));
803                 SysTryReturn(NID_CNT, pVideoContentInfoImpl != null, null, E_OUT_OF_MEMORY,
804                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
805
806                 r = MakeContentInfo(pMediaInfo.get(), systemType, pVideoContentInfoImpl);
807                 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
808
809                 return pVideoContentInfo.release();
810         }
811         else if (systemType == SYSTEM_TYPE_OTHER)
812         {
813                 unique_ptr< OtherContentInfo > pOtherContentInfo(new (nothrow) OtherContentInfo);
814                 SysTryReturn(NID_CNT, pOtherContentInfo != null, null, E_OUT_OF_MEMORY,
815                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
816
817                 r = pOtherContentInfo->Construct(&changedPath);
818                 r = ConvertErrorToResult(r);
819                 SysTryReturn(NID_CNT, !IsFailed(r), null, r,
820                                 "[%s] Failed to perform Construct operation to OtherContentInfo.", GetErrorMessage(r));
821
822                 _OtherContentInfoImpl* pOtherContentInfoImpl = _OtherContentInfoImpl::GetInstance(*(pOtherContentInfo.get()));
823                 SysTryReturn(NID_CNT, pOtherContentInfoImpl != null, null, E_OUT_OF_MEMORY,
824                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
825
826                 r = MakeContentInfo(pMediaInfo.get(), systemType, pOtherContentInfoImpl);
827                 SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
828
829                 return pOtherContentInfo.release();
830         }
831         else
832         {
833                 SysLogException(NID_CNT, E_INVALID_ARG, "[E_INVALID_ARG] Unsupported type");
834                 return null;
835         }
836 }
837
838 result
839 _ContentManagerImpl::UpdateContent(const ContentInfo& contentInfo)
840 {
841         const _ContentInfoImpl* pInfoImpl = _ContentInfoImpl::GetInstance(contentInfo);
842         SysTryReturnResult(NID_CNT, pInfoImpl != null, E_INVALID_ARG, "Invalid argument is used. ContentInfo is invalid.");
843
844         ContentId contentId = pInfoImpl->GetContentId();
845         SysTryReturnResult(NID_CNT, contentId != UuId::GetInvalidUuId(), E_INVALID_ARG, "The content id is invalid.");
846         SysTryReturnResult(NID_CNT, _FileImpl::IsFileExist(pInfoImpl->GetContentPath()), E_FILE_NOT_FOUND,
847                         "The file corresponding to contentInfo could not be found.");
848
849         result r = UpdateDataToDatabase(pInfoImpl);
850         SysTryReturnResult(NID_CNT, !IsFailed(r), r, "UpdateDataToDatabase failed.");
851
852         return r;
853 }
854
855 result
856 _ContentManagerImpl::DeleteContent(const ContentId& contentId)
857 {
858         SysTryReturnResult(NID_CNT, contentId != UuId::GetInvalidUuId(), E_INVALID_ARG, "The contentId is invalid.");
859
860         unique_ptr<char[]> pContentId(_StringConverter::CopyToCharArrayN(contentId.ToString()));
861         SysTryReturnResult(NID_CNT, pContentId != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
862
863         result r = E_SUCCESS;
864         int val = 0;
865         media_info_h tempMediaInfo = null;
866         unique_ptr<media_info_s, _MediaInfoDeleter> pMediaInfo(null);
867
868         val = media_info_get_media_from_db(pContentId.get(), &tempMediaInfo);
869         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
870                         "media_info_get_media_from_db failed[%d].", val);
871
872         pMediaInfo.reset(tempMediaInfo);
873
874         char* pTempPath = null;
875
876         val = media_info_get_file_path(pMediaInfo.get(), &pTempPath);
877         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
878                         "media_info_get_file_path failed[%d].", val);
879
880         unique_ptr<char, CharDeleter> pContentPath(pTempPath);
881         String contentPath(pContentPath.get());
882         String changedPath(L"");
883
884         r = ChangeTizenPathToCompat(contentPath, changedPath);
885         SysTryReturnResult(NID_CNT, !IsFailed(r), r, "[%s] Failed to perform ChangeTizenPathToCompat.", GetErrorMessage(r));
886
887         SysTryReturnResult(NID_CNT, _FileImpl::IsFileExist(changedPath), E_FILE_NOT_FOUND,
888                         "The file corresponding to contentId could not be found.");
889
890         val = media_info_delete_from_db(pContentId.get());
891         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
892                         "media_info_delete_From_db failed[%d].", val);
893
894         r = _FileImpl::Remove(changedPath);
895         SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "The file is not deleted.");
896
897         return r;
898 }
899
900 result
901 _ContentManagerImpl::AddContentUpdateEventListener(IContentUpdateEventListener& listener)
902 {
903         SysTryReturnResult(NID_CNT, GetListener() == null, E_OBJ_ALREADY_EXIST, "IContentUpdateEventListener is already set.");
904
905         SetListener(&listener);
906
907         int val = media_content_set_db_updated_cb(OnContentUpdateCompleted, this);
908         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "media_content_set_db_updated_cb failed[%d].", val);
909
910         return E_SUCCESS;
911 }
912
913 result
914 _ContentManagerImpl::RemoveContentUpdateEventListener(IContentUpdateEventListener& listener)
915 {
916         SysTryReturnResult(NID_CNT, GetListener() == &listener, E_OBJ_NOT_FOUND, "The input listener is not equal to the registered listener.");
917
918         int val = media_content_unset_db_updated_cb();
919         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "media_content_unset_db_updated_cb failed[%d].", val);
920
921         SetListener(null);
922
923         return E_SUCCESS;
924 }
925
926 result
927 _ContentManagerImpl::ScanFile(const Tizen::Base::String& contentPath)
928 {
929         SysSecureLog(NID_CNT, "The scan path is [%ls].", contentPath.GetPointer());
930
931         unique_ptr<char[]> pContentPath(_StringConverter::CopyToCharArrayN(contentPath));
932         SysTryReturnResult(NID_CNT, pContentPath, E_SYSTEM, "pContentPath is NULL.");
933
934         int val = media_content_connect();
935         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "The connection failed[%d].", val);
936
937         val = media_content_scan_file(pContentPath.get());
938         result r = ConvertError(val);
939         SysTryCatch(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, , r, "[%s] media_content_scan_file failed[%d].", GetErrorMessage(r), val);
940
941         val = media_content_disconnect();
942         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "The disconnection failed[%d].", val);
943
944         return E_SUCCESS;
945
946 CATCH:
947         val = media_content_disconnect();
948         SysTryLog(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, "The disconnection failed[%d].", val);
949
950         return r;
951 }
952
953 result
954 _ContentManagerImpl::ScanDirectory(const Tizen::Base::String& directoryPath, bool recursive, IContentScanListener* pListener, RequestId& reqId)
955 {
956         static RequestId requestId = 0;
957
958         SysLog(NID_CNT, "The scan path is [%ls].", directoryPath.GetPointer());
959
960         unique_ptr<char[]> pDirPath(_StringConverter::CopyToCharArrayN(directoryPath));
961         SysTryReturnResult(NID_CNT, pDirPath, E_SYSTEM, "pDirPath is NULL.");
962
963         int val = media_content_connect();
964         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "The connection failed[%d].", val);
965
966         unique_ptr< _ScanResult > pScanResult(new (nothrow) _ScanResult);
967         SysTryReturnResult(NID_CNT, pScanResult != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
968
969         reqId = requestId++;
970
971         pScanResult->scanPath = directoryPath;
972         pScanResult->pScanListener = pListener;
973         pScanResult->requestId = reqId;
974
975         val = media_content_scan_folder(pDirPath.get(), recursive, OnScanCompleted, pScanResult.release());
976         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val), "media_content_scan_folder failed[%d].", val);
977
978         return E_SUCCESS;
979 }
980
981 result
982 _ContentManagerImpl::UpdateDataToDatabase(const _ContentInfoImpl* pContentInfoImpl) const
983 {
984         SysTryReturnResult(NID_CNT, pContentInfoImpl != null, E_INVALID_ARG, "pContentInfoImpl is null.");
985
986         media_info_h tempMediaInfo = null;
987         unique_ptr<media_info_s, _MediaInfoDeleter> pMediaInfo(null);
988         unique_ptr<char[]> pContentId(_StringConverter::CopyToCharArrayN((pContentInfoImpl->GetContentId()).ToString()));
989         SysTryReturnResult(NID_CNT, pContentId != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
990
991         int val = media_info_get_media_from_db(pContentId.get(), &tempMediaInfo);
992         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
993                         "media_info_get_media_from_db failed[%d].", val);
994
995         pMediaInfo.reset(tempMediaInfo);
996
997         result r = E_SUCCESS;
998         unique_ptr<char[]> pValue(null);
999
1000         // author
1001         pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetAuthor()));
1002         SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1003
1004         val = media_info_set_author(pMediaInfo.get(), pValue.get());
1005         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1006                         "media_info_set_author failed[%d].", val);
1007
1008         // category
1009         pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetCategory()));
1010         SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1011
1012         val = media_info_set_category(pMediaInfo.get(), pValue.get());
1013         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1014                         "media_info_set_category failed[%d].", val);
1015
1016         // content name
1017         pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetContentName()));
1018         SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1019
1020         val = media_info_set_content_name(pMediaInfo.get(), pValue.get());
1021         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1022                         "media_info_set_content_name failed[%d].", val);
1023
1024         // description
1025         pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetDescription()));
1026         SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1027
1028         val = media_info_set_description(pMediaInfo.get(), pValue.get());
1029         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1030                         "media_info_set_description failed[%d].", val);
1031
1032         // keyword
1033         pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetKeyword()));
1034         SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1035
1036         val = media_info_set_keyword(pMediaInfo.get(), pValue.get());
1037         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1038                         "media_info_set_keyword failed[%d].", val);
1039
1040         // location tag
1041         pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetLocationTag()));
1042         SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1043
1044         val = media_info_set_location_tag(pMediaInfo.get(), pValue.get());
1045         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1046                         "media_info_set_location_tag failed[%d].", val);
1047
1048         // provider
1049         pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetProvider()));
1050         SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1051
1052         val = media_info_set_provider(pMediaInfo.get(), pValue.get());
1053         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1054                         "media_info_set_provider failed[%d].", val);
1055
1056         // rating
1057         pValue.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetRating()));
1058         SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
1059
1060         val = media_info_set_age_rating(pMediaInfo.get(), pValue.get());
1061         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1062                         "media_info_set_age_rating failed[%d].", val);
1063
1064         // latitude, longitude, altitude
1065         if (Double::Compare(pContentInfoImpl->GetLatitude(), DEFAULT_COORDINATE) != 0 &&
1066                         Double::Compare(pContentInfoImpl->GetLongitude(), DEFAULT_COORDINATE) != 0)
1067         {
1068                 val = media_info_set_latitude(pMediaInfo.get(), pContentInfoImpl->GetLatitude());
1069                 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1070                                 "media_info_set_latitude failed[%d].", val);
1071
1072                 val = media_info_set_longitude(pMediaInfo.get(), pContentInfoImpl->GetLongitude());
1073                 SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1074                                 "media_info_set_longitude failed[%d].", val);
1075
1076                 if (Double::Compare(pContentInfoImpl->GetAltitude(), DEFAULT_COORDINATE) != 0)
1077                 {
1078                         val = media_info_set_altitude(pMediaInfo.get(), pContentInfoImpl->GetAltitude());
1079                         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1080                                         "media_info_set_altitude failed[%d].", val);
1081                 }
1082         }
1083
1084         val = media_info_update_to_db(pMediaInfo.get());
1085         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1086                         "media_info_update_to_db failed[%d].", val);
1087
1088         return r;
1089 }
1090
1091 ContentId
1092 _ContentManagerImpl::SaveDataToDatabase(const media_info_h pMediaInfo,
1093                                                                                                 _ContentInfoImpl* pContentInfoImpl) const
1094 {
1095         ClearLastResult();
1096         result r = E_SUCCESS;
1097
1098         SysTryReturn(NID_CNT, pContentInfoImpl != null, UuId::GetInvalidUuId(), E_INVALID_ARG,
1099                         "[E_INVALID_ARG] Invalid argument is used. ContentInfo is invalid.");
1100
1101         String contentPath(pContentInfoImpl->GetPhysicalContentPath());
1102         String changedPath(L"");
1103
1104         r = ChangeTizenPathToCompat(contentPath, changedPath);
1105         SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), r,
1106                         "[%s] Failed to perform ChangeTizenPathToCompat.", GetErrorMessage(r));
1107
1108         String mimeType(L"");
1109         String extension = _FileImpl::GetFileExtension(changedPath);
1110         r = GetLastResult();
1111         if (IsFailed(r))
1112         {
1113                 ClearLastResult();
1114
1115                 SysLog(NID_CNT, "[%s] Failed to perform GetFileExtension operation.", GetErrorMessage(r));
1116
1117                 unique_ptr<char[]> pTempPath(_StringConverter::CopyToCharArrayN(contentPath));
1118                 SysTryReturn(NID_CNT, pTempPath != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1119                                 "[E_OUT_OF_MEMORY] The memory is insufficient.");
1120
1121                 char tempType[255] = {0, };
1122                 int ret = aul_get_mime_from_file(pTempPath.get(), tempType, sizeof(tempType));
1123                 SysTryReturn(NID_CNT, ret == AUL_R_OK, UuId::GetInvalidUuId(), E_INVALID_ARG,
1124                                 "[E_INVALID_ARG] Failed to perform aul_get_mime_from_file operation.");
1125
1126                 r = mimeType.Append(tempType);
1127                 SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1128                                 "[E_OUT_OF_MEMORY] Failed to perform Append operation.");
1129
1130         }
1131
1132         // If the content format is JPG and it has GPS data, it will be saved in database automatically.
1133         if (extension == L"jpg" || extension == L"jpeg" || extension == L"JPG" || extension == L"JPEG" || mimeType.Contains(L"jpeg"))
1134         {
1135                 SysLog(NID_CNT, "The format of content is jpg.");
1136
1137                 ImageMetadata* pImageMetadata = _ContentManagerUtilImpl::GetImageMetaN(changedPath, true);
1138                 if (pImageMetadata != null)
1139                 {
1140                         pContentInfoImpl->SetLatitude(pImageMetadata->GetLatitude());
1141                         pContentInfoImpl->SetLongitude(pImageMetadata->GetLongitude());
1142
1143                         delete pImageMetadata;
1144                 }
1145
1146                 ClearLastResult();
1147         }
1148
1149         int val = 0;
1150         unique_ptr<char[]> pStr(null);
1151
1152         // author
1153         pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetAuthor()));
1154         SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1155                         "[E_OUT_OF_MEMORY] The memory is insufficient.");
1156
1157         val = media_info_set_author(pMediaInfo, pStr.get());
1158         SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1159                         "media_info_set_author failed[%d].", val);
1160
1161         // category
1162         pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetCategory()));
1163         SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1164                         "[E_OUT_OF_MEMORY] The memory is insufficient.");
1165
1166         val = media_info_set_category(pMediaInfo, pStr.get());
1167         SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1168                         "media_info_set_category failed[%d].", val);
1169
1170         // content name
1171         pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetContentName()));
1172         SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1173                         "[E_OUT_OF_MEMORY] The memory is insufficient.");
1174
1175         val = media_info_set_content_name(pMediaInfo, pStr.get());
1176         SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1177                         "media_info_set_content_name failed[%d].", val);
1178
1179         // description
1180         pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetDescription()));
1181         SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1182                         "[E_OUT_OF_MEMORY] The memory is insufficient.");
1183
1184         val = media_info_set_description(pMediaInfo, pStr.get());
1185         SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1186                         "media_info_set_description failed[%d].", val);
1187
1188         // keyword
1189         pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetKeyword()));
1190         SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1191                         "[E_OUT_OF_MEMORY] The memory is insufficient.");
1192
1193         val = media_info_set_keyword(pMediaInfo, pStr.get());
1194         SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1195                         "media_info_set_keyword failed[%d].", val);
1196
1197         // location tag
1198         pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetLocationTag()));
1199         SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1200                         "[E_OUT_OF_MEMORY] The memory is insufficient.");
1201
1202         val = media_info_set_location_tag(pMediaInfo, pStr.get());
1203         SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1204                         "media_info_set_location_tag failed[%d].", val);
1205
1206         // provider
1207         pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetProvider()));
1208         SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1209                         "[E_OUT_OF_MEMORY] The memory is insufficient.");
1210
1211         val = media_info_set_provider(pMediaInfo, pStr.get());
1212         SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1213                         "media_info_set_provider failed[%d].", val);
1214
1215         // rating
1216         pStr.reset(_StringConverter::CopyToCharArrayN(pContentInfoImpl->GetRating()));
1217         SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
1218                         "[E_OUT_OF_MEMORY] The memory is insufficient.");
1219
1220         val = media_info_set_age_rating(pMediaInfo, pStr.get());
1221         SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1222                         "media_info_set_age_rating failed[%d].", val);
1223
1224         // latitude, longitude, altitude
1225         if (Double::Compare(pContentInfoImpl->GetLatitude(), DEFAULT_COORDINATE) != 0 &&
1226                         Double::Compare(pContentInfoImpl->GetLongitude(), DEFAULT_COORDINATE) != 0)
1227         {
1228                 val = media_info_set_latitude(pMediaInfo, pContentInfoImpl->GetLatitude());
1229                 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1230                                 "media_info_set_latitude failed[%d].", val);
1231
1232                 val = media_info_set_longitude(pMediaInfo, pContentInfoImpl->GetLongitude());
1233                 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1234                                 "media_info_set_longitude failed[%d].", val);
1235
1236                 if (Double::Compare(pContentInfoImpl->GetAltitude(), DEFAULT_COORDINATE) != 0)
1237                 {
1238                         val = media_info_set_altitude(pMediaInfo, pContentInfoImpl->GetAltitude());
1239                         SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1240                                         "media_info_set_altitude failed[%d].", val);
1241                 }
1242         }
1243
1244         val = media_info_update_to_db(pMediaInfo);
1245         SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1246                         "media_info_update_to_db failed[%d].", val);
1247
1248         char* pTempMediaId = null;
1249         unique_ptr<char, CharDeleter> pMediaId(null);
1250
1251         val = media_info_get_media_id(pMediaInfo, &pTempMediaId);
1252         if (pTempMediaId != null)
1253         {
1254                 pMediaId.reset(pTempMediaId);
1255         }
1256         else
1257         {
1258                 SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
1259                                 "media_info_get_media_id failed[%d].", val);
1260         }
1261
1262         String tempContentId(pMediaId.get());
1263         ContentId contentId;
1264
1265         r = UuId::Parse(tempContentId, contentId);
1266         SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), E_INVALID_ARG,
1267                         "[E_INVALID_ARG] UuId::Parse failed.");
1268
1269         return contentId;
1270 }
1271
1272 result
1273 _ContentManagerImpl::MakeContentInfo(const media_info_h pMediaInfo, int systemType, void* pInfoImpl) const
1274 {
1275         SysTryReturnResult(NID_CNT, pMediaInfo != null && pInfoImpl != null, E_INVALID_ARG,
1276                         "The specified parameter is invalid.");
1277
1278         _ContentInfoImpl* pContentInfoImpl = static_cast< _ContentInfoImpl* >(pInfoImpl);
1279
1280         result r = E_SUCCESS;
1281         char* pTempValue = null;
1282         unique_ptr<char, CharDeleter> pStrValue(null);
1283
1284         // contentId
1285         int val = media_info_get_media_id(pMediaInfo, &pTempValue);
1286         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1287                         "media_info_get_media_id failed[%d].", val);
1288
1289         if (pTempValue != null)
1290         {
1291                 pStrValue.reset(pTempValue);
1292
1293                 String strContentId(pStrValue.get());
1294                 ContentId contentId;
1295
1296                 r = UuId::Parse(strContentId, contentId);
1297                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "The content id can not be parsed.");
1298
1299                 pContentInfoImpl->SetContentId(contentId);
1300
1301                 SysLog(NID_CNT, "INFO: contentId[%ls]", strContentId.GetPointer());
1302         }
1303
1304         // contentPath
1305         val = media_info_get_file_path(pMediaInfo, &pTempValue);
1306         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1307                         "media_info_get_file_path failed[%d].", val);
1308
1309         if (pTempValue != null)
1310         {
1311                 pStrValue.reset(pTempValue);
1312
1313                 String strFilePath(pStrValue.get());
1314
1315                 pContentInfoImpl->SetContentPath(strFilePath);
1316                 SysSecureLog(NID_CNT, "INFO: contentPath[%ls]", (pContentInfoImpl->GetContentPath()).GetPointer());
1317         }
1318
1319         // mimeType
1320         val = media_info_get_mime_type(pMediaInfo, &pTempValue);
1321         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1322                         "media_info_get_mime_type failed[%d].", val);
1323
1324         if (pTempValue != null)
1325         {
1326                 pStrValue.reset(pTempValue);
1327
1328                 pContentInfoImpl->SetMimeType(pStrValue.get());
1329
1330                 SysLog(NID_CNT, "INFO: mimeType[%ls]", (pContentInfoImpl->GetMimeType()).GetPointer());
1331         }
1332
1333         // contentSize
1334         unsigned long long longlongValue = 0;
1335         val = media_info_get_size(pMediaInfo, &longlongValue);
1336         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1337                         "media_info_get_size failed[%d].", val);
1338         pContentInfoImpl->SetContentSize(longlongValue);
1339         SysLog(NID_CNT, "INFO: contentSize[%llu]", longlongValue);
1340
1341         // storageType
1342         media_content_storage_e storageType;
1343         val = media_info_get_storage_type(pMediaInfo, &storageType);
1344         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1345                         "media_info_get_storage_type failed[%d].", val);
1346         pContentInfoImpl->SetStorageType(storageType);
1347         SysLog(NID_CNT, "INFO: storageType[%d]", storageType);
1348
1349         // isDrm
1350         bool tempDrm = false;
1351
1352         val = media_info_is_drm(pMediaInfo, &tempDrm);
1353         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1354                         "media_info_is_drm failed[%d].", val);
1355
1356         pContentInfoImpl->SetDrmProtected(tempDrm);
1357
1358         SysLog(NID_CNT, "INFO: isDrm[%d]", pContentInfoImpl->IsDrmProtected());
1359
1360         // dateTime
1361         time_t addedTime = 0;
1362         val = media_info_get_added_time(pMediaInfo, &addedTime);
1363         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1364                         "media_info_get_added_time failed[%d].", val);
1365
1366         DateTime dt;
1367         r = dt.SetValue(1970, 1, 1);
1368         SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform datetime.SetValue operation.");
1369         r = dt.AddSeconds(addedTime);// need to check addedTime is secs/millisec
1370         SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform datetime.AddSeconds operation.");
1371
1372         pContentInfoImpl->SetDateTime(dt);
1373         SysLog(NID_CNT, "INFO: dateTime[%ls]", ((pContentInfoImpl->GetDateTime()).ToString()).GetPointer());
1374
1375         // modifiedTime
1376         time_t modifiedTime = 0;
1377         val = media_info_get_modified_time(pMediaInfo, &modifiedTime);
1378         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1379                         "media_info_get_modified_time failed[%d].", val);
1380
1381         r = dt.SetValue(1970, 1, 1);
1382         SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform datetime.SetValue operation.");
1383         r = dt.AddSeconds(modifiedTime);
1384         SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform datetime.AddSeconds operation.");
1385
1386         pContentInfoImpl->SetModifiedTime(dt);
1387         SysLog(NID_CNT, "INFO: modifiedTime[%ls]", ((pContentInfoImpl->GetModifiedTime()).ToString()).GetPointer());
1388
1389         // thumbnailPath
1390         val = media_info_get_thumbnail_path(pMediaInfo, &pTempValue);
1391         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1392                         "media_info_get_thumbnail_path failed[%d].", val);
1393
1394         if (pTempValue != null)
1395         {
1396                 pStrValue.reset(pTempValue);
1397                 String thumbnailPath(pStrValue.get());
1398
1399                 pContentInfoImpl->SetThumbnailPath(thumbnailPath);
1400                 SysLog(NID_CNT, "INFO: thumbnailPath[%ls]", (pContentInfoImpl->GetThumbnailPath()).GetPointer());
1401         }
1402
1403         // author
1404         val = media_info_get_author(pMediaInfo, &pTempValue);
1405         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1406                         "media_info_get_author failed[%d].", val);
1407
1408         if (pTempValue != null)
1409         {
1410                 pStrValue.reset(pTempValue);
1411
1412                 pContentInfoImpl->SetAuthor(String(pStrValue.get()));
1413
1414                 SysLog(NID_CNT, "INFO: author[%ls]", (pContentInfoImpl->GetAuthor()).GetPointer());
1415         }
1416
1417         // category
1418         val = media_info_get_category(pMediaInfo, &pTempValue);
1419         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1420                         "media_info_get_category failed[%d].", val);
1421
1422         if (pTempValue != null)
1423         {
1424                 pStrValue.reset(pTempValue);
1425
1426                 pContentInfoImpl->SetCategory(String(pStrValue.get()));
1427
1428                 SysLog(NID_CNT, "INFO: category[%ls]", (pContentInfoImpl->GetCategory()).GetPointer());
1429         }
1430
1431         // contentName
1432         val = media_info_get_content_name(pMediaInfo, &pTempValue);
1433         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1434                         "media_info_get_content_name failed[%d].", val);
1435
1436         if (pTempValue != null)
1437         {
1438                 pStrValue.reset(pTempValue);
1439
1440                 pContentInfoImpl->SetContentName(String(pStrValue.get()));
1441
1442                 SysSecureLog(NID_CNT, "INFO: contentName[%ls]", (pContentInfoImpl->GetContentName()).GetPointer());
1443         }
1444
1445         // description
1446         val = media_info_get_description(pMediaInfo, &pTempValue);
1447         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1448                         "media_info_get_description failed[%d].", val);
1449
1450         if (pTempValue != null)
1451         {
1452                 pStrValue.reset(pTempValue);
1453
1454                 pContentInfoImpl->SetDescription(String(pStrValue.get()));
1455
1456                 SysLog(NID_CNT, "INFO: description[%ls]", (pContentInfoImpl->GetDescription()).GetPointer());
1457         }
1458
1459         // keyword
1460         val = media_info_get_keyword(pMediaInfo, &pTempValue);
1461         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1462                         "media_info_get_keyword failed[%d].", val);
1463
1464         if (pTempValue != null)
1465         {
1466                 pStrValue.reset(pTempValue);
1467
1468                 pContentInfoImpl->SetKeyword(String(pStrValue.get()));
1469
1470                 SysLog(NID_CNT, "INFO: keyword[%ls]", (pContentInfoImpl->GetKeyword()).GetPointer());
1471         }
1472
1473         // locationTag
1474         val = media_info_get_location_tag(pMediaInfo, &pTempValue);
1475         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1476                         "media_info_get_location_tag failed[%d].", val);
1477
1478         if (pTempValue != null)
1479         {
1480                 pStrValue.reset(pTempValue);
1481
1482                 pContentInfoImpl->SetLocationTag(String(pStrValue.get()));
1483
1484                 SysSecureLog(NID_CNT, "INFO: locationTag[%ls]", (pContentInfoImpl->GetLocationTag()).GetPointer());
1485         }
1486
1487         // provider
1488         val = media_info_get_provider(pMediaInfo, &pTempValue);
1489         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1490                         "media_info_get_provider failed[%d].", val);
1491
1492         if (pTempValue != null)
1493         {
1494                 pStrValue.reset(pTempValue);
1495
1496                 pContentInfoImpl->SetProvider(String(pStrValue.get()));
1497
1498                 SysLog(NID_CNT, "INFO: provider[%ls]", (pContentInfoImpl->GetProvider()).GetPointer());
1499         }
1500
1501         // rating
1502         val = media_info_get_age_rating(pMediaInfo, &pTempValue);
1503         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1504                         "media_info_get_age_rating failed[%d].", val);
1505
1506         if (pTempValue != null)
1507         {
1508                 pStrValue.reset(pTempValue);
1509
1510                 pContentInfoImpl->SetRating(String(pStrValue.get()));
1511
1512                 SysLog(NID_CNT, "INFO: rating[%ls]", (pContentInfoImpl->GetRating()).GetPointer());
1513         }
1514
1515         // coordinates
1516         Coordinates coordinates;
1517         double doubleValue = 0;
1518         val = media_info_get_latitude(pMediaInfo, &doubleValue);
1519         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1520                         "media_info_get_latitude failed[%d].", val);
1521
1522         if (Double::Compare(doubleValue, DEFAULT_COORDINATE) != 0)
1523         {
1524                 pContentInfoImpl->SetLatitude(doubleValue);
1525                 coordinates.SetLatitude(doubleValue);
1526         }
1527         SysSecureLog(NID_CNT, "INFO: latitude[%f]", pContentInfoImpl->GetLatitude());
1528
1529         val = media_info_get_longitude(pMediaInfo, &doubleValue);
1530         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1531                         "media_info_get_longitude failed[%d].", val);
1532
1533         if (Double::Compare(doubleValue, DEFAULT_COORDINATE) != 0)
1534         {
1535                 pContentInfoImpl->SetLongitude(doubleValue);
1536                 coordinates.SetLongitude(doubleValue);
1537         }
1538         SysSecureLog(NID_CNT, "INFO: longitude[%f]", pContentInfoImpl->GetLongitude());
1539
1540         val = media_info_get_altitude(pMediaInfo, &doubleValue);
1541         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1542                         "media_info_get_altitude failed[%d].", val);
1543
1544         if (Double::Compare(doubleValue, DEFAULT_COORDINATE) != 0)
1545         {
1546                 pContentInfoImpl->SetAltitude(doubleValue);
1547                 coordinates.SetAltitude(doubleValue);
1548         }
1549         SysLog(NID_CNT, "INFO: altitude[%f]", pContentInfoImpl->GetAltitude());
1550
1551         pContentInfoImpl->SetCoordinates(coordinates);
1552
1553         // contentType and metadata
1554         if (systemType == SYSTEM_TYPE_IMAGE)
1555         {
1556                 r = MakeImageContentInfo(pMediaInfo, pInfoImpl);
1557                 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform MakeImageContentInfo operation.");
1558         }
1559         else if (systemType == SYSTEM_TYPE_SOUND || systemType == SYSTEM_TYPE_MUSIC)
1560         {
1561                 r = MakeAudioContentInfo(pMediaInfo, pInfoImpl);
1562                 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform MakeAudioContentInfo operation.");
1563         }
1564         else if (systemType == MEDIA_CONTENT_TYPE_VIDEO)
1565         {
1566                 r = MakeVideoContentInfo(pMediaInfo, pInfoImpl);
1567                 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform MakeVideoContentInfo operation.");
1568         }
1569         else if (systemType == SYSTEM_TYPE_OTHER)
1570         {
1571                 pContentInfoImpl->SetContentType(CONTENT_TYPE_OTHER);
1572                 SysLog(NID_CNT, "META: ContentType[%d]", pContentInfoImpl->GetContentType());
1573         }
1574
1575         return r;
1576 }
1577
1578 result
1579 _ContentManagerImpl::MakeImageContentInfo(const media_info_h pMediaInfo, void* pInfoImpl) const
1580 {
1581         result r = E_SUCCESS;
1582         int intValue = 0;
1583         bool boolValue = false;
1584         image_meta_h pTempMeta = null;
1585         unique_ptr<image_meta_h, _ImageMetaDeleter> pImageMeta(null);
1586
1587         SysTryReturnResult(NID_CNT, pInfoImpl != null, E_OUT_OF_MEMORY, "pInfoImpl is null.");
1588
1589         _ContentInfoImpl* pContentInfoImpl = static_cast< _ContentInfoImpl* >(pInfoImpl);
1590         SysTryReturnResult(NID_CNT, pContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to perform static cast for _ContentInfoImpl.");
1591
1592         pContentInfoImpl->SetContentType(CONTENT_TYPE_IMAGE);
1593         SysLog(NID_CNT, "META: ContentType[%d]", pContentInfoImpl->GetContentType());
1594
1595         int val = media_info_get_image(pMediaInfo, &pTempMeta);
1596         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1597                         "media_info_get_image failed[%d].", val);
1598
1599         pImageMeta.reset(&pTempMeta);
1600
1601         _ImageContentInfoImpl* pImageContentInfoImpl = static_cast< _ImageContentInfoImpl* >(pInfoImpl);
1602         SysTryReturnResult(NID_CNT, pImageContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to perform static cast for _ImageContentInfoImpl.");
1603
1604         // width
1605         val = image_meta_get_width(*(pImageMeta.get()), &intValue);
1606         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1607                         "image_meta_get_width failed[%d].", val);
1608
1609         pImageContentInfoImpl->SetWidth(intValue);
1610         SysLog(NID_CNT, "META: width[%d]", intValue);
1611
1612         // height
1613         val = image_meta_get_height(*(pImageMeta.get()), &intValue);
1614         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1615                         "image_meta_get_height failed[%d].", val);
1616
1617         pImageContentInfoImpl->SetHeight(intValue);
1618         SysLog(NID_CNT, "META: height[%d]", intValue);
1619
1620         // orientation
1621         media_content_orientation_e orientation;
1622         val = image_meta_get_orientation(*(pImageMeta.get()), &orientation);
1623         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1624                         "image_meta_get_orientation failed[%d].", val);
1625
1626         pImageContentInfoImpl->SetOrientation(static_cast< ImageOrientationType >(orientation));
1627         SysLog(NID_CNT, "META: orientation[%d]", orientation);
1628
1629         char* pTempValue = null;
1630         unique_ptr<char, CharDeleter> pStrValue(null);
1631
1632         // title
1633         val = media_info_get_display_name(pMediaInfo, &pTempValue);
1634         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1635                         "media_info_get_display_name failed[%d].", val);
1636
1637         if (pTempValue != null)
1638         {
1639                 pStrValue.reset(pTempValue);
1640
1641                 int pos = 0;
1642                 String fileName;
1643                 String strTitle(pStrValue.get());
1644
1645                 result r = strTitle.LastIndexOf(L'.', strTitle.GetLength() - 1, pos);
1646                 if (r == E_SUCCESS)
1647                 {
1648                         r = strTitle.SubString(0, pos, fileName);
1649                         SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "The title is invalid.");
1650                 }
1651                 else
1652                 {
1653                         // Without extension
1654                         r = E_SUCCESS;
1655                         fileName = strTitle;
1656                 }
1657
1658                 pImageContentInfoImpl->SetTitle(fileName);
1659
1660                 SysLog(NID_CNT, "META: title[%ls]", fileName.GetPointer());
1661         }
1662
1663         // dateTaken
1664         val = image_meta_get_date_taken(*(pImageMeta.get()), &pTempValue);
1665         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1666                         "image_meta_get_date_taken failed[%d].", val);
1667
1668         DateTime dt;
1669
1670         if (pTempValue != null)
1671         {
1672                 pStrValue.reset(pTempValue);
1673                 String dateTaken(pStrValue.get());
1674                 String newDateTaken(L"");
1675
1676                 // detour the unexpected datetaken format
1677                 String tempDelim(L"+-Z");
1678                 String token;
1679
1680                 StringTokenizer tempStrTok(dateTaken, tempDelim);
1681
1682                 r = tempStrTok.GetNextToken(token);
1683                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
1684
1685                 dateTaken = token;
1686
1687                 String delim(L": ");
1688                 String year(L"");
1689
1690                 StringTokenizer strTok(dateTaken, delim);
1691
1692                 r = strTok.SetDelimiters(delim);
1693                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform SetDelimiters operation.");
1694
1695                 r = strTok.GetNextToken(token);
1696                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
1697
1698                 year = token;
1699
1700                 // Append month
1701                 r = strTok.GetNextToken(token);
1702                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
1703
1704                 r = newDateTaken.Append(token);
1705                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1706
1707                 r = newDateTaken.Append(L"/");
1708                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1709
1710                 // Append day
1711                 r = strTok.GetNextToken(token);
1712                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
1713
1714                 r = newDateTaken.Append(token);
1715                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1716
1717                 r = newDateTaken.Append(L"/");
1718                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1719
1720                 // Append year
1721                 r = newDateTaken.Append(year);
1722                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1723
1724                 r = newDateTaken.Append(L" ");
1725                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1726
1727                 String newDelim(L" ");
1728
1729                 r = strTok.SetDelimiters(newDelim);
1730                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform SetDelimiters operation.");
1731
1732                 r = strTok.GetNextToken(token);
1733                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform GetNextToken operation.");
1734
1735                 r = newDateTaken.Append(token);
1736                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_OUT_OF_MEMORY, "Failed to perform Append operation.");
1737
1738                 r = DateTime::Parse(newDateTaken, dt);
1739                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform Parse operation for DateTime.");
1740         }
1741         else
1742         {
1743                 dt = DateTime::GetMinValue();
1744         }
1745
1746         pImageContentInfoImpl->SetImageTakenDate(dt);
1747         SysLog(NID_CNT, "META: dateTaken[%ls]", dt.ToString().GetPointer());
1748
1749         // isBurstShot
1750         val = image_meta_is_burst_shot(*(pImageMeta.get()), &boolValue);
1751         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1752                         "image_meta_is_burst_shot failed[%d].", val);
1753
1754         pImageContentInfoImpl->SetBurstShot(boolValue);
1755         SysLog(NID_CNT, "META: isBurstShot[%d]", boolValue);
1756
1757         // burstShotId
1758         val = image_meta_get_burst_id(*(pImageMeta.get()), &pTempValue);
1759         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1760                         "image_meta_get_burst_id failed[%d].", val);
1761
1762         if (pTempValue != null)
1763         {
1764                 pStrValue.reset(pTempValue);
1765                 String burstShotId(pStrValue.get());
1766
1767                 pImageContentInfoImpl->SetBurstShotId(burstShotId);
1768                 SysLog(NID_CNT, "META: burstShotId[%ls]", burstShotId.GetPointer());
1769         }
1770
1771         return E_SUCCESS;
1772 }
1773
1774 result
1775 _ContentManagerImpl::MakeAudioContentInfo(const media_info_h pMediaInfo, void* pInfoImpl) const
1776 {
1777         int intValue = 0;
1778         audio_meta_h pTempMeta = null;
1779         unique_ptr<audio_meta_h, _AudioMetaDeleter> pAudioMeta(null);
1780
1781         SysTryReturnResult(NID_CNT, pInfoImpl != null, E_OUT_OF_MEMORY, "pInfoImpl is null.");
1782
1783         _ContentInfoImpl* pContentInfoImpl = static_cast< _ContentInfoImpl* >(pInfoImpl);
1784         SysTryReturnResult(NID_CNT, pContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to perform static cast for _ContentInfoImpl.");
1785
1786         pContentInfoImpl->SetContentType(CONTENT_TYPE_AUDIO);
1787         SysLog(NID_CNT, "META: ContentType[%d]", pContentInfoImpl->GetContentType());
1788
1789         int val = media_info_get_audio(pMediaInfo, &pTempMeta);
1790         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1791                         "media_info_get_audio failed[%d].", val);
1792
1793         pAudioMeta.reset(&pTempMeta);
1794
1795         _AudioContentInfoImpl* pAudioContentInfoImpl = static_cast< _AudioContentInfoImpl* >(pInfoImpl);
1796         SysTryReturnResult(NID_CNT, pAudioContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to perform static cast for _AudioContentInfoImpl.");
1797
1798         // bitrate
1799         val = audio_meta_get_bit_rate(*(pAudioMeta.get()), &intValue);
1800         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1801                         "audio_meta_get_bit_rate failed[%d].", val);
1802
1803         pAudioContentInfoImpl->SetBitrate(intValue);
1804         SysLog(NID_CNT, "META: bitrate[%d]", intValue);
1805
1806         char* pTempValue = null;
1807         unique_ptr<char, CharDeleter> pStrValue(null);
1808
1809         // releaseYear
1810         val = audio_meta_get_year(*(pAudioMeta.get()), &pTempValue);
1811         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1812                         "audio_meta_get_year failed[%d].", val);
1813
1814         if (pTempValue != null)
1815         {
1816                 pStrValue.reset(pTempValue);
1817
1818                 String strYear(pStrValue.get());
1819
1820                 if (strYear.CompareTo(L"Unknown") != 0)
1821                 {
1822                         result r = Integer::Parse(strYear, intValue);
1823                         if (IsFailed(r))
1824                         {
1825                                 // It is one of the metadata. If error occurs, skip it for other metadata.
1826                                 intValue = 0;
1827                                 r = E_SUCCESS;
1828                                 SysLog(NID_CNT, "META: releaseYear - invalid data[%ls]", strYear.GetPointer());
1829                         }
1830
1831                         pAudioContentInfoImpl->SetReleaseYear(intValue);
1832                         SysLog(NID_CNT, "META: releaseYear[%d]", intValue);
1833                 }
1834         }
1835
1836         // title
1837         val = audio_meta_get_title(*(pAudioMeta.get()), &pTempValue);
1838         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1839                         "audio_meta_get_title failed[%d].", val);
1840
1841         if (pTempValue != null)
1842         {
1843                 pStrValue.reset(pTempValue);
1844
1845                 pAudioContentInfoImpl->SetTitle(String(pStrValue.get()));
1846
1847                 SysLog(NID_CNT, "META: title[%ls]", (String(pStrValue.get())).GetPointer());
1848         }
1849
1850         // albumName
1851         val = audio_meta_get_album(*(pAudioMeta.get()), &pTempValue);
1852         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1853                         "audio_meta_get_album failed[%d].", val);
1854
1855         if (pTempValue != null)
1856         {
1857                 pStrValue.reset(pTempValue);
1858
1859                 pAudioContentInfoImpl->SetAlbumName(String(pStrValue.get()));
1860
1861                 SysLog(NID_CNT, "META: albumName[%ls]", (String(pStrValue.get())).GetPointer());
1862         }
1863
1864         // artist
1865         val = audio_meta_get_artist(*(pAudioMeta.get()), &pTempValue);
1866         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1867                         "audio_meta_get_artist failed[%d].", val);
1868
1869         if (pTempValue != null)
1870         {
1871                 pStrValue.reset(pTempValue);
1872
1873                 pAudioContentInfoImpl->SetArtist(String(pStrValue.get()));
1874
1875                 SysLog(NID_CNT, "META: artist[%ls]", (String(pStrValue.get())).GetPointer());
1876         }
1877
1878         // composer
1879         val = audio_meta_get_composer(*(pAudioMeta.get()), &pTempValue);
1880         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1881                         "audio_meta_get_composer failed[%d].", val);
1882
1883         if (pTempValue != null)
1884         {
1885                 pStrValue.reset(pTempValue);
1886
1887                 pAudioContentInfoImpl->SetComposer(String(pStrValue.get()));
1888
1889                 SysLog(NID_CNT, "META: composer[%ls]", (String(pStrValue.get())).GetPointer());
1890         }
1891
1892         // genre
1893         val = audio_meta_get_genre(*(pAudioMeta.get()), &pTempValue);
1894         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1895                         "audio_meta_get_genre failed[%d].", val);
1896
1897         if (pTempValue != null)
1898         {
1899                 pStrValue.reset(pTempValue);
1900
1901                 pAudioContentInfoImpl->SetGenre(String(pStrValue.get()));
1902
1903                 SysLog(NID_CNT, "META: genre[%ls]", (String(pStrValue.get())).GetPointer());
1904         }
1905
1906         // copyright
1907         val = audio_meta_get_copyright(*(pAudioMeta.get()), &pTempValue);
1908         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1909                         "audio_meta_get_copyright failed[%d].", val);
1910
1911         if (pTempValue != null)
1912         {
1913                 pStrValue.reset(pTempValue);
1914
1915                 pAudioContentInfoImpl->SetCopyright(String(pStrValue.get()));
1916
1917                 SysLog(NID_CNT, "META: copyright[%ls]", (String(pStrValue.get())).GetPointer());
1918         }
1919
1920         // trackInfo
1921         val = audio_meta_get_track_num(*(pAudioMeta.get()), &pTempValue);
1922         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1923                         "audio_meta_get_track_num failed[%d].", val);
1924
1925         if (pTempValue != null)
1926         {
1927                 pStrValue.reset(pTempValue);
1928
1929                 pAudioContentInfoImpl->SetTrackInfo(String(pStrValue.get()));
1930
1931                 SysLog(NID_CNT, "META: trackInfo[%ls]", (String(pStrValue.get())).GetPointer());
1932         }
1933
1934         // duration
1935         val = audio_meta_get_duration(*(pAudioMeta.get()), &intValue);
1936         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1937                         "audio_meta_get_duration failed[%d].", val);
1938
1939         pAudioContentInfoImpl->SetDuration(intValue);
1940         SysLog(NID_CNT, "META: duration[%d]", intValue);
1941
1942         return E_SUCCESS;
1943 }
1944
1945 result
1946 _ContentManagerImpl::MakeVideoContentInfo(const media_info_h pMediaInfo, void* pInfoImpl) const
1947 {
1948         int intValue = 0;
1949         video_meta_h pTempMeta = null;
1950         unique_ptr<video_meta_h, _VideoMetaDeleter> pVideoMeta(null);
1951
1952         SysTryReturnResult(NID_CNT, pInfoImpl != null, E_OUT_OF_MEMORY, "pInfoImpl is null.");
1953
1954         _ContentInfoImpl* pContentInfoImpl = static_cast< _ContentInfoImpl* >(pInfoImpl);
1955         SysTryReturnResult(NID_CNT, pContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to perform static cast for _ContentInfoImpl.");
1956
1957         pContentInfoImpl->SetContentType(CONTENT_TYPE_VIDEO);
1958         SysLog(NID_CNT, "META: ContentType[%d]", pContentInfoImpl->GetContentType());
1959
1960         int val = media_info_get_video(pMediaInfo, &pTempMeta);
1961         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1962                         "media_info_get_video failed[%d].", val);
1963
1964         pVideoMeta.reset(&pTempMeta);
1965
1966         _VideoContentInfoImpl* pVideoContentInfoImpl = static_cast< _VideoContentInfoImpl* >(pInfoImpl);
1967         SysTryReturnResult(NID_CNT, pVideoContentInfoImpl != null, E_OUT_OF_MEMORY, "Failed to perform static cast for _VideoContentInfoImpl.");
1968
1969         // width
1970         val = video_meta_get_width(*(pVideoMeta.get()), &intValue);
1971         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1972                         "video_meta_get_width failed[%d].", val);
1973
1974         pVideoContentInfoImpl->SetWidth(intValue);
1975         SysLog(NID_CNT, "META: width[%d]", intValue);
1976
1977         // height
1978         val = video_meta_get_height(*(pVideoMeta.get()), &intValue);
1979         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1980                         "video_meta_get_height failed[%d].", val);
1981
1982         pVideoContentInfoImpl->SetHeight(intValue);
1983         SysLog(NID_CNT, "META: height[%d]", intValue);
1984
1985         char* pTempValue = null;
1986         unique_ptr<char, CharDeleter> pStrValue(null);
1987
1988         // artist
1989         val = video_meta_get_artist(*(pVideoMeta.get()), &pTempValue);
1990         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
1991                         "video_meta_get_artist failed[%d].", val);
1992
1993         if (pTempValue != null)
1994         {
1995                 pStrValue.reset(pTempValue);
1996
1997                 pVideoContentInfoImpl->SetArtist(String(pStrValue.get()));
1998
1999                 SysLog(NID_CNT, "META: artist[%ls]", (String(pStrValue.get())).GetPointer());
2000         }
2001
2002         // genre
2003         val = video_meta_get_genre(*(pVideoMeta.get()), &pTempValue);
2004         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
2005                         "video_meta_get_genre failed[%d].", val);
2006
2007         if (pTempValue != null)
2008         {
2009                 pStrValue.reset(pTempValue);
2010
2011                 pVideoContentInfoImpl->SetGenre(String(pStrValue.get()));
2012
2013                 SysLog(NID_CNT, "META: genre[%ls]", (String(pStrValue.get())).GetPointer());
2014         }
2015
2016         // title
2017         val = video_meta_get_title(*(pVideoMeta.get()), &pTempValue);
2018         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
2019                         "video_meta_get_title failed[%d].", val);
2020
2021         if (pTempValue != null)
2022         {
2023                 pStrValue.reset(pTempValue);
2024
2025                 pVideoContentInfoImpl->SetTitle(String(pStrValue.get()));
2026
2027                 SysLog(NID_CNT, "META: title[%ls]", (String(pStrValue.get())).GetPointer());
2028         }
2029
2030         // albumName
2031         val = video_meta_get_album(*(pVideoMeta.get()), &pTempValue);
2032         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
2033                         "video_meta_get_album failed[%d].", val);
2034
2035         if (pTempValue != null)
2036         {
2037                 pStrValue.reset(pTempValue);
2038
2039                 pVideoContentInfoImpl->SetAlbumName(String(pStrValue.get()));
2040
2041                 SysLog(NID_CNT, "META: albumName[%ls]", (String(pStrValue.get())).GetPointer());
2042         }
2043
2044         // duration
2045         val = video_meta_get_duration(*(pVideoMeta.get()), &intValue);
2046         SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
2047                         "video_meta_get_duration failed[%d].", val);
2048
2049         pVideoContentInfoImpl->SetDuration(intValue);
2050         SysLog(NID_CNT, "META: duration[%d]", intValue);
2051
2052         // Get some information from metadata extractor when calling VideoContentInfo (framerate, audio bitrate, video bitrate)
2053
2054         return E_SUCCESS;
2055 }
2056
2057 bool
2058 _ContentManagerImpl::VerifyHomeFilePathCompatibility(const String& contentPath) const
2059 {
2060         if (!_AppInfo::IsOspCompat())
2061         {
2062                 if (contentPath.StartsWith(OSP_HOME, 0) || contentPath.StartsWith(OSP_HOME_EXT, 0))
2063                 {
2064                         SysLogException(NID_CNT, E_INVALID_ARG,
2065                                         "[E_INVALID_ARG] /Home/ or /HomeExt/ is not supported from Tizen 2.0.");
2066                         return false;
2067                 }
2068                 if (!(contentPath.StartsWith(App::App::GetInstance()->GetAppRootPath(), 0) ||
2069                                 contentPath.StartsWith(Environment::GetExternalStoragePath(), 0)))
2070                 {
2071                         SysLogException(NID_CNT, E_INVALID_ARG, "[E_INVALID_ARG] The path is not supported.");
2072                         return false;
2073                 }
2074         }
2075         else
2076         {
2077                 SysTryReturn(NID_CNT, contentPath.StartsWith(OSP_HOME, 0) || contentPath.StartsWith(OSP_HOME_EXT, 0),
2078                                 false, E_INVALID_ARG, "[E_INVALID_ARG] The path should start with /Home or /HomeExt.");
2079         }
2080
2081         return true;
2082 }
2083
2084 bool
2085 _ContentManagerImpl::VerifyMediaFilePathCompatibility(const String& contentPath) const
2086 {
2087         ClearLastResult();
2088
2089         if (!_AppInfo::IsOspCompat())
2090         {
2091                 if (!(contentPath.StartsWith(Environment::GetMediaPath(), 0) ||
2092                                 contentPath.StartsWith(Environment::GetExternalStoragePath(), 0)))
2093                 {
2094                         SysLogException(NID_CNT, E_INVALID_ARG, "[%s] This path is not supported.", GetErrorMessage(E_INVALID_ARG));
2095                         return false;
2096                 }
2097         }
2098         else
2099         {
2100                 // prior to 2.0
2101                 if (!(contentPath.StartsWith(OSP_MEDIA_PHONE, 0)) ||
2102                                 (contentPath.StartsWith(OSP_MEDIA_MMC, 0)))
2103                 {
2104                         SysLogException(NID_CNT, E_INVALID_ARG, "[%s] The path should start with /Media, or /Storagecard/Media.", GetErrorMessage(E_INVALID_ARG));
2105                         return false;
2106                 }
2107         }
2108
2109         return true;
2110 }
2111
2112 result
2113 _ContentManagerImpl::ChangeTizenPathToCompat(const String& contentPath, String& changedPath) const
2114 {
2115         result r = E_SUCCESS;
2116         changedPath = contentPath;
2117
2118         // If the api version is 2.0, the content path has to be changed.
2119         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
2120         {
2121                 r = _FileImpl::ConvertPhysicalToVirtualPath(contentPath, changedPath);
2122                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG,
2123                                 "[%s] Failed to convert physical path to virtual path.", GetErrorMessage(E_INVALID_ARG));
2124         }
2125
2126         return r;
2127 }
2128
2129 result
2130 _ContentManagerImpl::ChangeCompatPathToTizen(const String& contentPath, String& changedPath) const
2131 {
2132         result r = E_SUCCESS;
2133         changedPath = contentPath;
2134
2135         // If the api version is 2.0, the content path has to be changed.
2136         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
2137         {
2138                 r = _FileImpl::ConvertVirtualToPhysicalPath(contentPath, changedPath);
2139                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG,
2140                                 "[%s] Failed to convert virtual path to physical path.", GetErrorMessage(E_INVALID_ARG));
2141         }
2142
2143         return r;
2144 }
2145
2146 void
2147 _ContentManagerImpl::SetListener(IContentUpdateEventListener* pListener)
2148 {
2149         __pListener = pListener;
2150 }
2151
2152 IContentUpdateEventListener*
2153 _ContentManagerImpl::GetListener(void) const
2154 {
2155         return __pListener;
2156 }
2157
2158 result
2159 _ContentManagerImpl::ConvertErrorToResult(result res) const
2160 {
2161         result r = E_SUCCESS;
2162
2163         switch (res)
2164         {
2165         case E_IO:
2166                 r = E_SYSTEM;
2167                 break;
2168
2169         default:
2170                 r = res;
2171                 break;
2172         }
2173         return r;
2174 }
2175
2176 }}