2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
17 * @file FCntContentManager.cpp
18 * @brief This is the implementation file for the %ContentManager class.
20 * This file contains implementation of the %ContentManager class.
23 #include <FBaseSysLog.h>
24 #include <FBaseByteBuffer.h>
25 #include <FCntContentManager.h>
26 #include <FCntImageContentInfo.h>
27 #include <FCntAudioContentInfo.h>
28 #include <FCntVideoContentInfo.h>
29 #include <FCntOtherContentInfo.h>
30 #include <FCnt_ContentManagerImpl.h>
31 #include <FSec_AccessController.h>
33 using namespace Tizen::Base;
34 using namespace Tizen::Security;
36 namespace Tizen { namespace Content
39 ContentManager::ContentManager(void)
46 ContentManager::~ContentManager(void)
56 ContentManager::Construct(void)
61 SysAssertf(__pImpl == null,
62 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
64 _ContentManagerImpl* pContentManagerImpl = new (std::nothrow) _ContentManagerImpl();
65 SysTryReturn(NID_CNT, pContentManagerImpl != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Construct failed.");
67 r = pContentManagerImpl->Construct();
68 SysTryCatch(NID_CNT, r == E_SUCCESS, , r, "[%S] Propagating.", GetErrorMessage(r));
70 __pImpl = pContentManagerImpl;
75 delete pContentManagerImpl;
76 pContentManagerImpl = null;
82 ContentManager::CreateContent(const ContentInfo& contentInfo)
87 // Checks the privilege
88 r = _AccessController::CheckUserPrivilege(_PRV_CONTENT_WRITE);
89 SysTryReturn(NID_CNT, r == E_SUCCESS, UuId::GetInvalidUuId(), E_PRIVILEGE_DENIED,
90 "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
92 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
94 ContentId contentId = __pImpl->CreateContent(contentInfo);
96 SysTryReturn(NID_CNT, contentId != UuId::GetInvalidUuId(), UuId::GetInvalidUuId(), r, "[%s] CreateContent failed.", GetErrorMessage(r));
102 ContentManager::CreateContent(const ByteBuffer& byteBuffer, const String& destinationPath, const ContentInfo* pContentInfo)
105 result r = E_SUCCESS;
107 // Checks the privilege
108 r = _AccessController::CheckUserPrivilege(_PRV_CONTENT_WRITE);
109 SysTryReturn(NID_CNT, r == E_SUCCESS, UuId::GetInvalidUuId(), E_PRIVILEGE_DENIED,
110 "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
112 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
114 ContentId contentId = __pImpl->CreateContent(byteBuffer, destinationPath, pContentInfo);
116 SysTryReturn(NID_CNT, contentId != UuId::GetInvalidUuId(), UuId::GetInvalidUuId(), r, "[%s] CreateContent failed.", GetErrorMessage(r));
122 ContentManager::CreateContent(const String& sourcePath, const String& destinationPath, bool deleteSource,
123 const ContentInfo* pContentInfo)
126 result r = E_SUCCESS;
128 // Checks the privilege
129 r = _AccessController::CheckUserPrivilege(_PRV_CONTENT_WRITE);
130 SysTryReturn(NID_CNT, r == E_SUCCESS, UuId::GetInvalidUuId(), E_PRIVILEGE_DENIED,
131 "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
133 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
135 ContentId contentId = __pImpl->CreateContent(sourcePath, destinationPath, deleteSource, pContentInfo);
137 SysTryReturn(NID_CNT, contentId != UuId::GetInvalidUuId(), UuId::GetInvalidUuId(), r, "[%s] CreateContent failed.", GetErrorMessage(r));
143 ContentManager::GetContentInfoN(const ContentId& contentId) const
146 result r = E_SUCCESS;
148 ContentInfo* pContentInfo = null;
149 ImageContentInfo* pImageContentInfo = null;
150 AudioContentInfo* pAudioContentInfo = null;
151 VideoContentInfo* pVideoContentInfo = null;
152 OtherContentInfo* pOtherContentInfo = null;
153 ContentType contentType;
155 // Checks the privilege
156 r = _AccessController::CheckUserPrivilege(_PRV_CONTENT_READ);
157 SysTryReturn(NID_CNT, r == E_SUCCESS, null, E_PRIVILEGE_DENIED,
158 "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
160 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
162 pContentInfo = __pImpl->GetContentInfoN(contentId);
164 SysTryCatch(NID_CNT, pContentInfo != null, , r, "[%s] GetContentInfoN failed.", GetErrorMessage(r));
166 contentType = pContentInfo->GetContentType();
168 if (contentType == CONTENT_TYPE_IMAGE)
170 pImageContentInfo = dynamic_cast <ImageContentInfo*>(pContentInfo);
171 SysTryCatch(NID_CNT, pImageContentInfo != null, , E_SYSTEM, "[E_SYSTEM] GetContentInfoN failed.");
173 return pImageContentInfo;
175 else if (contentType == CONTENT_TYPE_AUDIO)
177 pAudioContentInfo = dynamic_cast <AudioContentInfo*>(pContentInfo);
178 SysTryCatch(NID_CNT, pAudioContentInfo != null, , E_SYSTEM, "[E_SYSTEM] GetContentInfoN failed.");
180 return pAudioContentInfo;
182 else if (contentType == CONTENT_TYPE_VIDEO)
184 pVideoContentInfo = dynamic_cast <VideoContentInfo*>(pContentInfo);
185 SysTryCatch(NID_CNT, pVideoContentInfo != null, , E_SYSTEM, "[E_SYSTEM] GetContentInfoN failed.");
187 return pVideoContentInfo;
189 else if (contentType == CONTENT_TYPE_OTHER)
191 pOtherContentInfo = dynamic_cast <OtherContentInfo*>(pContentInfo);
192 SysTryCatch(NID_CNT, pOtherContentInfo != null, , E_SYSTEM, "[E_SYSTEM] GetContentInfoN failed.");
194 return pOtherContentInfo;
198 SysLogException(NID_CNT, E_SYSTEM, "[E_SYSTEM] contentType is CONTENT_TYPE_UNKNOWN.");
203 if (pContentInfo != null)
213 ContentManager::UpdateContent(const ContentInfo& contentInfo)
216 result r = E_SUCCESS;
218 // Checks the privilege
219 r = _AccessController::CheckUserPrivilege(_PRV_CONTENT_WRITE);
220 SysTryReturn(NID_CNT, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
221 "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
223 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
225 r = __pImpl->UpdateContent(contentInfo);
226 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] UpdateContent failed.", GetErrorMessage(r));
232 ContentManager::DeleteContent(const ContentId& contentId)
235 result r = E_SUCCESS;
237 // Checks the privilege
238 r = _AccessController::CheckUserPrivilege(_PRV_CONTENT_WRITE);
239 SysTryReturn(NID_CNT, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
240 "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
242 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
244 r = __pImpl->DeleteContent(contentId);
245 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] DeleteContent failed.", GetErrorMessage(r));
251 ContentManager::AddContentUpdateEventListener(IContentUpdateEventListener& listener)
254 result r = E_SUCCESS;
256 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
258 r = __pImpl->AddContentUpdateEventListener(listener);
259 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "[%s] AddContentUpdateEventListener failed.", GetErrorMessage(r));
265 ContentManager::RemoveContentUpdateEventListener(IContentUpdateEventListener& listener)
268 result r = E_SUCCESS;
270 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
272 r = __pImpl->RemoveContentUpdateEventListener(listener);
273 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "[%s] RemoveContentUpdateEventListener failed.", GetErrorMessage(r));
279 ContentManager::ScanFile(const Tizen::Base::String& contentPath)
282 result r = E_SUCCESS;
284 // Checks the privilege
285 r = _AccessController::CheckUserPrivilege(_PRV_CONTENT_WRITE);
286 SysTryReturn(NID_CNT, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
287 "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
289 r = _ContentManagerImpl::ScanFile(contentPath);
290 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] ScanFile failed.", GetErrorMessage(r));
296 ContentManager::ScanDirectory(const Tizen::Base::String& directoryPath, bool recursive, IContentScanListener* pListener, RequestId& reqId)
299 result r = E_SUCCESS;
301 // Checks the privilege
302 r = _AccessController::CheckUserPrivilege(_PRV_CONTENT_WRITE);
303 SysTryReturn(NID_CNT, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
304 "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
306 r = _ContentManagerImpl::ScanDirectory(directoryPath, recursive, pListener, reqId);
307 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] ScanDirectory failed.", GetErrorMessage(r));