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