2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
18 * @file FCntContentManager.cpp
19 * @brief This is the implementation file for the %ContentManager class.
21 * This file contains implementation of the %ContentManager class.
24 #include <FBaseSysLog.h>
25 #include <FBaseByteBuffer.h>
26 #include <FCntContentManager.h>
27 #include <FCntImageContentInfo.h>
28 #include <FCntAudioContentInfo.h>
29 #include <FCntVideoContentInfo.h>
30 #include <FCntOtherContentInfo.h>
31 #include <FCnt_ContentManagerImpl.h>
32 #include <FSec_AccessController.h>
34 using namespace Tizen::Base;
35 using namespace Tizen::Security;
37 namespace Tizen { namespace Content
40 ContentManager::ContentManager(void)
47 ContentManager::~ContentManager(void)
57 ContentManager::Construct(void)
62 SysAssertf(__pImpl == null,
63 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
65 _ContentManagerImpl* pContentManagerImpl = new (std::nothrow) _ContentManagerImpl();
66 SysTryReturn(NID_CNT, pContentManagerImpl != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Construct failed.");
68 r = pContentManagerImpl->Construct();
69 SysTryCatch(NID_CNT, r == E_SUCCESS, , r, "[%S] Propagating.", GetErrorMessage(r));
71 __pImpl = pContentManagerImpl;
76 delete pContentManagerImpl;
77 pContentManagerImpl = null;
83 ContentManager::CreateContent(const ContentInfo& contentInfo)
88 // Checks the privilege
89 r = _AccessController::CheckUserPrivilege(_PRV_CONTENT_WRITE);
90 SysTryReturn(NID_CNT, r == E_SUCCESS, UuId::GetInvalidUuId(), E_PRIVILEGE_DENIED,
91 "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
93 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
95 ContentId contentId = __pImpl->CreateContent(contentInfo);
97 SysTryReturn(NID_CNT, contentId != UuId::GetInvalidUuId(), UuId::GetInvalidUuId(), r, "[%s] CreateContent failed.", GetErrorMessage(r));
103 ContentManager::CreateContent(const ByteBuffer& byteBuffer, const String& destinationPath, const ContentInfo* pContentInfo)
106 result r = E_SUCCESS;
108 // Checks the privilege
109 r = _AccessController::CheckUserPrivilege(_PRV_CONTENT_WRITE);
110 SysTryReturn(NID_CNT, r == E_SUCCESS, UuId::GetInvalidUuId(), E_PRIVILEGE_DENIED,
111 "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
113 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
115 ContentId contentId = __pImpl->CreateContent(byteBuffer, destinationPath, pContentInfo);
117 SysTryReturn(NID_CNT, contentId != UuId::GetInvalidUuId(), UuId::GetInvalidUuId(), r, "[%s] CreateContent failed.", GetErrorMessage(r));
123 ContentManager::CreateContent(const String& sourcePath, const String& destinationPath, bool deleteSource,
124 const ContentInfo* pContentInfo)
127 result r = E_SUCCESS;
129 // Checks the privilege
130 r = _AccessController::CheckUserPrivilege(_PRV_CONTENT_WRITE);
131 SysTryReturn(NID_CNT, r == E_SUCCESS, UuId::GetInvalidUuId(), E_PRIVILEGE_DENIED,
132 "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
134 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
136 ContentId contentId = __pImpl->CreateContent(sourcePath, destinationPath, deleteSource, pContentInfo);
138 SysTryReturn(NID_CNT, contentId != UuId::GetInvalidUuId(), UuId::GetInvalidUuId(), r, "[%s] CreateContent failed.", GetErrorMessage(r));
144 ContentManager::GetContentInfoN(const ContentId& contentId) const
147 result r = E_SUCCESS;
149 ContentInfo* pContentInfo = null;
150 ImageContentInfo* pImageContentInfo = null;
151 AudioContentInfo* pAudioContentInfo = null;
152 VideoContentInfo* pVideoContentInfo = null;
153 OtherContentInfo* pOtherContentInfo = null;
154 ContentType contentType;
156 // Checks the privilege
157 r = _AccessController::CheckUserPrivilege(_PRV_CONTENT_READ);
158 SysTryReturn(NID_CNT, r == E_SUCCESS, null, E_PRIVILEGE_DENIED,
159 "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
161 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
163 pContentInfo = __pImpl->GetContentInfoN(contentId);
165 SysTryCatch(NID_CNT, pContentInfo != null, , r, "[%s] GetContentInfoN failed.", GetErrorMessage(r));
167 contentType = pContentInfo->GetContentType();
169 if (contentType == CONTENT_TYPE_IMAGE)
171 pImageContentInfo = dynamic_cast <ImageContentInfo*>(pContentInfo);
172 SysTryCatch(NID_CNT, pImageContentInfo != null, , E_SYSTEM, "[E_SYSTEM] GetContentInfoN failed.");
174 return pImageContentInfo;
176 else if (contentType == CONTENT_TYPE_AUDIO)
178 pAudioContentInfo = dynamic_cast <AudioContentInfo*>(pContentInfo);
179 SysTryCatch(NID_CNT, pAudioContentInfo != null, , E_SYSTEM, "[E_SYSTEM] GetContentInfoN failed.");
181 return pAudioContentInfo;
183 else if (contentType == CONTENT_TYPE_VIDEO)
185 pVideoContentInfo = dynamic_cast <VideoContentInfo*>(pContentInfo);
186 SysTryCatch(NID_CNT, pVideoContentInfo != null, , E_SYSTEM, "[E_SYSTEM] GetContentInfoN failed.");
188 return pVideoContentInfo;
190 else if (contentType == CONTENT_TYPE_OTHER)
192 pOtherContentInfo = dynamic_cast <OtherContentInfo*>(pContentInfo);
193 SysTryCatch(NID_CNT, pOtherContentInfo != null, , E_SYSTEM, "[E_SYSTEM] GetContentInfoN failed.");
195 return pOtherContentInfo;
199 SysLogException(NID_CNT, E_SYSTEM, "[E_SYSTEM] contentType is CONTENT_TYPE_UNKNOWN.");
204 if (pContentInfo != null)
214 ContentManager::UpdateContent(const ContentInfo& contentInfo)
217 result r = E_SUCCESS;
219 // Checks the privilege
220 r = _AccessController::CheckUserPrivilege(_PRV_CONTENT_WRITE);
221 SysTryReturn(NID_CNT, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
222 "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
224 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
226 r = __pImpl->UpdateContent(contentInfo);
227 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] UpdateContent failed.", GetErrorMessage(r));
233 ContentManager::DeleteContent(const ContentId& contentId)
236 result r = E_SUCCESS;
238 // Checks the privilege
239 r = _AccessController::CheckUserPrivilege(_PRV_CONTENT_WRITE);
240 SysTryReturn(NID_CNT, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
241 "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
243 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
245 r = __pImpl->DeleteContent(contentId);
246 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] DeleteContent failed.", GetErrorMessage(r));
252 ContentManager::AddContentUpdateEventListener(IContentUpdateEventListener& listener)
255 result r = E_SUCCESS;
257 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
259 r = __pImpl->AddContentUpdateEventListener(listener);
260 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "[%s] AddContentUpdateEventListener failed.", GetErrorMessage(r));
266 ContentManager::RemoveContentUpdateEventListener(IContentUpdateEventListener& listener)
269 result r = E_SUCCESS;
271 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
273 r = __pImpl->RemoveContentUpdateEventListener(listener);
274 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "[%s] RemoveContentUpdateEventListener failed.", GetErrorMessage(r));
280 ContentManager::ScanFile(const Tizen::Base::String& contentPath)
283 result r = E_SUCCESS;
285 // Checks the privilege
286 r = _AccessController::CheckUserPrivilege(_PRV_CONTENT_WRITE);
287 SysTryReturn(NID_CNT, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
288 "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
290 r = _ContentManagerImpl::ScanFile(contentPath);
291 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] ScanFile failed.", GetErrorMessage(r));
297 ContentManager::ScanDirectory(const Tizen::Base::String& directoryPath, bool recursive, IContentScanListener* pListener, RequestId& reqId)
300 result r = E_SUCCESS;
302 // Checks the privilege
303 r = _AccessController::CheckUserPrivilege(_PRV_CONTENT_WRITE);
304 SysTryReturn(NID_CNT, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
305 "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
307 r = _ContentManagerImpl::ScanDirectory(directoryPath, recursive, pListener, reqId);
308 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] ScanDirectory failed.", GetErrorMessage(r));