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.
25 #include <FBaseSysLog.h>
26 #include <FBaseByteBuffer.h>
27 #include <FCntContentManager.h>
28 #include <FCntImageContentInfo.h>
29 #include <FCntAudioContentInfo.h>
30 #include <FCntVideoContentInfo.h>
31 #include <FCntOtherContentInfo.h>
32 #include <FCnt_ContentManagerImpl.h>
33 #include <FSec_AccessController.h>
36 using namespace Tizen::Base;
37 using namespace Tizen::Security;
39 namespace Tizen { namespace Content
42 ContentManager::ContentManager(void)
49 ContentManager::~ContentManager(void)
59 ContentManager::Construct(void)
64 SysAssertf(__pImpl == null,
65 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
67 _ContentManagerImpl* pContentManagerImpl = new (std::nothrow) _ContentManagerImpl();
68 SysTryReturn(NID_CNT, pContentManagerImpl != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Construct failed.");
70 r = pContentManagerImpl->Construct();
71 SysTryCatch(NID_CNT, r == E_SUCCESS, , r, "[%S] Propagating.", GetErrorMessage(r));
73 __pImpl = pContentManagerImpl;
78 delete pContentManagerImpl;
79 pContentManagerImpl = null;
85 ContentManager::CreateContent(const ContentInfo& contentInfo)
90 // Checks the privilege
91 r = _AccessController::CheckUserPrivilege(_PRV_CONTENT_WRITE);
92 SysTryReturn(NID_CNT, r == E_SUCCESS, UuId::GetInvalidUuId(), E_PRIVILEGE_DENIED,
93 "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
95 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
97 ContentId contentId = __pImpl->CreateContent(contentInfo);
99 SysTryReturn(NID_CNT, contentId != UuId::GetInvalidUuId(), UuId::GetInvalidUuId(), r, "[%s] CreateContent failed.", GetErrorMessage(r));
105 ContentManager::CreateContent(const ByteBuffer& byteBuffer, const String& destinationPath, const ContentInfo* pContentInfo)
108 result r = E_SUCCESS;
110 // Checks the privilege
111 r = _AccessController::CheckUserPrivilege(_PRV_CONTENT_WRITE);
112 SysTryReturn(NID_CNT, r == E_SUCCESS, UuId::GetInvalidUuId(), E_PRIVILEGE_DENIED,
113 "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
115 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
117 ContentId contentId = __pImpl->CreateContent(byteBuffer, destinationPath, pContentInfo);
119 SysTryReturn(NID_CNT, contentId != UuId::GetInvalidUuId(), UuId::GetInvalidUuId(), r, "[%s] CreateContent failed.", GetErrorMessage(r));
125 ContentManager::CreateContent(const String& sourcePath, const String& destinationPath, bool deleteSource,
126 const ContentInfo* pContentInfo)
129 result r = E_SUCCESS;
131 // Checks the privilege
132 r = _AccessController::CheckUserPrivilege(_PRV_CONTENT_WRITE);
133 SysTryReturn(NID_CNT, r == E_SUCCESS, UuId::GetInvalidUuId(), E_PRIVILEGE_DENIED,
134 "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
136 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
138 ContentId contentId = __pImpl->CreateContent(sourcePath, destinationPath, deleteSource, pContentInfo);
140 SysTryReturn(NID_CNT, contentId != UuId::GetInvalidUuId(), UuId::GetInvalidUuId(), r, "[%s] CreateContent failed.", GetErrorMessage(r));
146 ContentManager::GetContentInfoN(const ContentId& contentId) const
149 result r = E_SUCCESS;
151 ContentInfo* pContentInfo = null;
152 ImageContentInfo* pImageContentInfo = null;
153 AudioContentInfo* pAudioContentInfo = null;
154 VideoContentInfo* pVideoContentInfo = null;
155 OtherContentInfo* pOtherContentInfo = null;
156 ContentType contentType;
158 // Checks the privilege
159 r = _AccessController::CheckUserPrivilege(_PRV_CONTENT_READ);
160 SysTryReturn(NID_CNT, r == E_SUCCESS, null, E_PRIVILEGE_DENIED,
161 "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
163 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
165 pContentInfo = __pImpl->GetContentInfoN(contentId);
167 SysTryCatch(NID_CNT, pContentInfo != null, , r, "[%s] GetContentInfoN failed.", GetErrorMessage(r));
169 contentType = pContentInfo->GetContentType();
171 if (contentType == CONTENT_TYPE_IMAGE)
173 pImageContentInfo = dynamic_cast <ImageContentInfo*>(pContentInfo);
174 SysTryCatch(NID_CNT, pImageContentInfo != null, , E_SYSTEM, "[E_SYSTEM] GetContentInfoN failed.");
176 return pImageContentInfo;
178 else if (contentType == CONTENT_TYPE_AUDIO)
180 pAudioContentInfo = dynamic_cast <AudioContentInfo*>(pContentInfo);
181 SysTryCatch(NID_CNT, pAudioContentInfo != null, , E_SYSTEM, "[E_SYSTEM] GetContentInfoN failed.");
183 return pAudioContentInfo;
185 else if (contentType == CONTENT_TYPE_VIDEO)
187 pVideoContentInfo = dynamic_cast <VideoContentInfo*>(pContentInfo);
188 SysTryCatch(NID_CNT, pVideoContentInfo != null, , E_SYSTEM, "[E_SYSTEM] GetContentInfoN failed.");
190 return pVideoContentInfo;
192 else if (contentType == CONTENT_TYPE_OTHER)
194 pOtherContentInfo = dynamic_cast <OtherContentInfo*>(pContentInfo);
195 SysTryCatch(NID_CNT, pOtherContentInfo != null, , E_SYSTEM, "[E_SYSTEM] GetContentInfoN failed.");
197 return pOtherContentInfo;
201 SysLogException(NID_CNT, E_SYSTEM, "[E_SYSTEM] contentType is CONTENT_TYPE_UNKNOWN.");
206 if (pContentInfo != null)
216 ContentManager::UpdateContent(const ContentInfo& contentInfo)
219 result r = E_SUCCESS;
221 // Checks the privilege
222 r = _AccessController::CheckUserPrivilege(_PRV_CONTENT_WRITE);
223 SysTryReturn(NID_CNT, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
224 "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
226 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
228 r = __pImpl->UpdateContent(contentInfo);
229 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] UpdateContent failed.", GetErrorMessage(r));
235 ContentManager::DeleteContent(const ContentId& contentId)
238 result r = E_SUCCESS;
240 // Checks the privilege
241 r = _AccessController::CheckUserPrivilege(_PRV_CONTENT_WRITE);
242 SysTryReturn(NID_CNT, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
243 "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
245 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
247 r = __pImpl->DeleteContent(contentId);
248 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] DeleteContent failed.", GetErrorMessage(r));
254 ContentManager::ScanFile(const String& contentPath)
257 result r = E_SUCCESS;
259 // Checks the privilege
260 r = _AccessController::CheckUserPrivilege(_PRV_CONTENT_WRITE);
261 SysTryReturn(NID_CNT, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
262 "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
264 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
266 r = __pImpl->ScanFile(contentPath);
267 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] ScanFile failed.", GetErrorMessage(r));
273 ContentManager::ScanDirectory(const String& directoryPath, bool recursive, _IContentScanListener& listener)
276 result r = E_SUCCESS;
278 // Checks the privilege
279 r = _AccessController::CheckUserPrivilege(_PRV_CONTENT_WRITE);
280 SysTryReturn(NID_CNT, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
281 "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
283 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
285 r = __pImpl->ScanDirectory(directoryPath, recursive, listener);
286 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] ScanDirectory failed.", GetErrorMessage(r));