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.
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 <FSec_AccessController.h>
32 #include "FCnt_ContentManagerImpl.h"
34 using namespace Tizen::Base;
35 using namespace Tizen::Security;
37 namespace Tizen { namespace Content
40 ContentManager::ContentManager(void)
41 : __pContentManagerImpl(null)
46 ContentManager::~ContentManager(void)
48 delete __pContentManagerImpl;
52 ContentManager::Construct(void)
56 SysAssertf(__pContentManagerImpl == null,
57 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
59 _ContentManagerImpl* pContentManagerImpl = new (std::nothrow) _ContentManagerImpl();
60 SysTryReturn(NID_CNT, pContentManagerImpl != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Construct failed.");
62 r = pContentManagerImpl->Construct();
63 SysTryCatch(NID_CNT, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
65 __pContentManagerImpl = pContentManagerImpl;
70 delete pContentManagerImpl;
76 ContentManager::CreateContent(const ContentInfo& contentInfo)
81 // Checks the privilege
82 r = _AccessController::CheckUserPrivilege(_PRV_CONTENT_WRITE);
83 SysTryReturn(NID_CNT, r == E_SUCCESS, UuId::GetInvalidUuId(), E_PRIVILEGE_DENIED,
84 "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
86 SysAssertf(__pContentManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
88 ContentId contentId = __pContentManagerImpl->CreateContent(contentInfo);
90 SysTryReturn(NID_CNT, contentId != UuId::GetInvalidUuId(), UuId::GetInvalidUuId(), r, "[%s] CreateContent failed.", GetErrorMessage(r));
96 ContentManager::CreateContent(const ByteBuffer& byteBuffer, const String& destinationPath, const ContentInfo* pContentInfo)
101 // Checks the privilege
102 r = _AccessController::CheckUserPrivilege(_PRV_CONTENT_WRITE);
103 SysTryReturn(NID_CNT, r == E_SUCCESS, UuId::GetInvalidUuId(), E_PRIVILEGE_DENIED,
104 "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
106 SysAssertf(__pContentManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
108 ContentId contentId = __pContentManagerImpl->CreateContent(byteBuffer, destinationPath, pContentInfo);
110 SysTryReturn(NID_CNT, contentId != UuId::GetInvalidUuId(), UuId::GetInvalidUuId(), r, "[%s] CreateContent failed.", GetErrorMessage(r));
116 ContentManager::CreateContent(const String& sourcePath, const String& destinationPath, bool deleteSource,
117 const ContentInfo* pContentInfo)
120 result r = E_SUCCESS;
122 // Checks the privilege
123 r = _AccessController::CheckUserPrivilege(_PRV_CONTENT_WRITE);
124 SysTryReturn(NID_CNT, r == E_SUCCESS, UuId::GetInvalidUuId(), E_PRIVILEGE_DENIED,
125 "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
127 SysAssertf(__pContentManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
129 ContentId contentId = __pContentManagerImpl->CreateContent(sourcePath, destinationPath, deleteSource, pContentInfo);
131 SysTryReturn(NID_CNT, contentId != UuId::GetInvalidUuId(), UuId::GetInvalidUuId(), r, "[%s] CreateContent failed.", GetErrorMessage(r));
137 ContentManager::GetContentInfoN(const ContentId& contentId) const
140 result r = E_SUCCESS;
141 ContentInfo* pContentInfo = null;
143 // Checks the privilege
144 r = _AccessController::CheckUserPrivilege(_PRV_CONTENT_READ);
145 SysTryReturn(NID_CNT, r == E_SUCCESS, null, E_PRIVILEGE_DENIED,
146 "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
148 SysAssertf(__pContentManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
150 pContentInfo = __pContentManagerImpl->GetContentInfoN(contentId);
152 SysTryReturn(NID_CNT, pContentInfo != null, null, r, "[%s] GetContentInfoN failed.", GetErrorMessage(r));
158 ContentManager::UpdateContent(const ContentInfo& contentInfo)
161 result r = E_SUCCESS;
163 // Checks the privilege
164 r = _AccessController::CheckUserPrivilege(_PRV_CONTENT_WRITE);
165 SysTryReturn(NID_CNT, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
166 "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
168 SysAssertf(__pContentManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
170 r = __pContentManagerImpl->UpdateContent(contentInfo);
171 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] UpdateContent failed.", GetErrorMessage(r));
177 ContentManager::DeleteContent(const ContentId& contentId)
180 result r = E_SUCCESS;
182 // Checks the privilege
183 r = _AccessController::CheckUserPrivilege(_PRV_CONTENT_WRITE);
184 SysTryReturn(NID_CNT, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
185 "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
187 SysAssertf(__pContentManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
189 r = __pContentManagerImpl->DeleteContent(contentId);
190 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] DeleteContent failed.", GetErrorMessage(r));
196 ContentManager::AddContentUpdateEventListener(IContentUpdateEventListener& listener)
199 result r = E_SUCCESS;
201 SysAssertf(__pContentManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
203 r = __pContentManagerImpl->AddContentUpdateEventListener(listener);
204 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "[%s] AddContentUpdateEventListener failed.", GetErrorMessage(r));
210 ContentManager::RemoveContentUpdateEventListener(IContentUpdateEventListener& listener)
213 result r = E_SUCCESS;
215 SysAssertf(__pContentManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
217 r = __pContentManagerImpl->RemoveContentUpdateEventListener(listener);
218 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "[%s] RemoveContentUpdateEventListener failed.", GetErrorMessage(r));
224 ContentManager::ScanFile(const Tizen::Base::String& contentPath)
227 result r = E_SUCCESS;
229 // Checks the privilege
230 r = _AccessController::CheckUserPrivilege(_PRV_CONTENT_WRITE);
231 SysTryReturn(NID_CNT, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
232 "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
234 r = _ContentManagerImpl::ScanFile(contentPath);
235 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] ScanFile failed.", GetErrorMessage(r));
241 ContentManager::ScanDirectory(const Tizen::Base::String& directoryPath, bool recursive, IContentScanListener* pListener, RequestId& reqId)
244 result r = E_SUCCESS;
246 // Checks the privilege
247 r = _AccessController::CheckUserPrivilege(_PRV_CONTENT_WRITE);
248 SysTryReturn(NID_CNT, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
249 "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
251 r = _ContentManagerImpl::ScanDirectory(directoryPath, recursive, pListener, reqId);
252 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] ScanDirectory failed.", GetErrorMessage(r));