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;
142 ContentInfo* pContentInfo = null;
143 ImageContentInfo* pImageContentInfo = null;
144 AudioContentInfo* pAudioContentInfo = null;
145 VideoContentInfo* pVideoContentInfo = null;
146 OtherContentInfo* pOtherContentInfo = null;
147 ContentType contentType;
149 // Checks the privilege
150 r = _AccessController::CheckUserPrivilege(_PRV_CONTENT_READ);
151 SysTryReturn(NID_CNT, r == E_SUCCESS, null, E_PRIVILEGE_DENIED,
152 "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
154 SysAssertf(__pContentManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
156 pContentInfo = __pContentManagerImpl->GetContentInfoN(contentId);
158 SysTryReturn(NID_CNT, pContentInfo != null, null, r, "[%s] GetContentInfoN failed.", GetErrorMessage(r));
164 ContentManager::UpdateContent(const ContentInfo& contentInfo)
167 result r = E_SUCCESS;
169 // Checks the privilege
170 r = _AccessController::CheckUserPrivilege(_PRV_CONTENT_WRITE);
171 SysTryReturn(NID_CNT, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
172 "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
174 SysAssertf(__pContentManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
176 r = __pContentManagerImpl->UpdateContent(contentInfo);
177 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] UpdateContent failed.", GetErrorMessage(r));
183 ContentManager::DeleteContent(const ContentId& contentId)
186 result r = E_SUCCESS;
188 // Checks the privilege
189 r = _AccessController::CheckUserPrivilege(_PRV_CONTENT_WRITE);
190 SysTryReturn(NID_CNT, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
191 "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
193 SysAssertf(__pContentManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
195 r = __pContentManagerImpl->DeleteContent(contentId);
196 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] DeleteContent failed.", GetErrorMessage(r));
202 ContentManager::AddContentUpdateEventListener(IContentUpdateEventListener& listener)
205 result r = E_SUCCESS;
207 SysAssertf(__pContentManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
209 r = __pContentManagerImpl->AddContentUpdateEventListener(listener);
210 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "[%s] AddContentUpdateEventListener failed.", GetErrorMessage(r));
216 ContentManager::RemoveContentUpdateEventListener(IContentUpdateEventListener& listener)
219 result r = E_SUCCESS;
221 SysAssertf(__pContentManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
223 r = __pContentManagerImpl->RemoveContentUpdateEventListener(listener);
224 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "[%s] RemoveContentUpdateEventListener failed.", GetErrorMessage(r));
230 ContentManager::ScanFile(const Tizen::Base::String& contentPath)
233 result r = E_SUCCESS;
235 // Checks the privilege
236 r = _AccessController::CheckUserPrivilege(_PRV_CONTENT_WRITE);
237 SysTryReturn(NID_CNT, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
238 "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
240 r = _ContentManagerImpl::ScanFile(contentPath);
241 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] ScanFile failed.", GetErrorMessage(r));
247 ContentManager::ScanDirectory(const Tizen::Base::String& directoryPath, bool recursive, IContentScanListener* pListener, RequestId& reqId)
250 result r = E_SUCCESS;
252 // Checks the privilege
253 r = _AccessController::CheckUserPrivilege(_PRV_CONTENT_WRITE);
254 SysTryReturn(NID_CNT, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
255 "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
257 r = _ContentManagerImpl::ScanDirectory(directoryPath, recursive, pListener, reqId);
258 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] ScanDirectory failed.", GetErrorMessage(r));