Merge "[content] Fix extracting orientation because of changing hardware" into devel_...
[platform/framework/native/content.git] / src / FCntContentManager.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
15 //
16 /**
17  * @file                FCntContentManager.cpp
18  * @brief               This is the implementation file for the %ContentManager class.
19  *
20  * This file contains implementation of the %ContentManager class.
21  */
22
23 #include <new>
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"
33
34 using namespace Tizen::Base;
35 using namespace Tizen::Security;
36
37 namespace Tizen { namespace Content
38 {
39
40 ContentManager::ContentManager(void)
41         : __pContentManagerImpl(null)
42 {
43
44 }
45
46 ContentManager::~ContentManager(void)
47 {
48         delete __pContentManagerImpl;
49 }
50
51 result
52 ContentManager::Construct(void)
53 {
54         result r = E_SUCCESS;
55
56         SysAssertf(__pContentManagerImpl == null,
57                         "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
58
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.");
61
62         r = pContentManagerImpl->Construct();
63         SysTryCatch(NID_CNT, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
64
65         __pContentManagerImpl = pContentManagerImpl;
66
67         return r;
68
69 CATCH:
70         delete pContentManagerImpl;
71
72         return r;
73 }
74
75 ContentId
76 ContentManager::CreateContent(const ContentInfo& contentInfo)
77 {
78         ClearLastResult();
79         result r = E_SUCCESS;
80
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.");
85
86         SysAssertf(__pContentManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
87
88         ContentId contentId = __pContentManagerImpl->CreateContent(contentInfo);
89         r = GetLastResult();
90         SysTryReturn(NID_CNT, contentId != UuId::GetInvalidUuId(), UuId::GetInvalidUuId(), r, "[%s] CreateContent failed.", GetErrorMessage(r));
91
92         return contentId;
93 }
94
95 ContentId
96 ContentManager::CreateContent(const ByteBuffer& byteBuffer, const String& destinationPath, const ContentInfo* pContentInfo)
97 {
98         ClearLastResult();
99         result r = E_SUCCESS;
100
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.");
105
106         SysAssertf(__pContentManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
107
108         ContentId contentId = __pContentManagerImpl->CreateContent(byteBuffer, destinationPath, pContentInfo);
109         r = GetLastResult();
110         SysTryReturn(NID_CNT, contentId != UuId::GetInvalidUuId(), UuId::GetInvalidUuId(), r, "[%s] CreateContent failed.", GetErrorMessage(r));
111
112         return contentId;
113 }
114
115 ContentId
116 ContentManager::CreateContent(const String& sourcePath, const String& destinationPath, bool deleteSource,
117                                                           const ContentInfo* pContentInfo)
118 {
119         ClearLastResult();
120         result r = E_SUCCESS;
121
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.");
126
127         SysAssertf(__pContentManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
128
129         ContentId contentId = __pContentManagerImpl->CreateContent(sourcePath, destinationPath, deleteSource, pContentInfo);
130         r = GetLastResult();
131         SysTryReturn(NID_CNT, contentId != UuId::GetInvalidUuId(), UuId::GetInvalidUuId(), r, "[%s] CreateContent failed.", GetErrorMessage(r));
132
133         return contentId;
134 }
135
136 ContentInfo*
137 ContentManager::GetContentInfoN(const ContentId& contentId) const
138 {
139         ClearLastResult();
140         result r = E_SUCCESS;
141
142         ContentInfo* pContentInfo = null;
143         ImageContentInfo* pImageContentInfo = null;
144         AudioContentInfo* pAudioContentInfo = null;
145         VideoContentInfo* pVideoContentInfo = null;
146         OtherContentInfo* pOtherContentInfo = null;
147         ContentType contentType;
148
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.");
153
154         SysAssertf(__pContentManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
155
156         pContentInfo = __pContentManagerImpl->GetContentInfoN(contentId);
157         r = GetLastResult();
158         SysTryReturn(NID_CNT, pContentInfo != null, null, r, "[%s] GetContentInfoN failed.", GetErrorMessage(r));
159
160         return pContentInfo;
161 }
162
163 result
164 ContentManager::UpdateContent(const ContentInfo& contentInfo)
165 {
166         ClearLastResult();
167         result r = E_SUCCESS;
168
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.");
173
174         SysAssertf(__pContentManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
175
176         r = __pContentManagerImpl->UpdateContent(contentInfo);
177         SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] UpdateContent failed.", GetErrorMessage(r));
178
179         return r;
180 }
181
182 result
183 ContentManager::DeleteContent(const ContentId& contentId)
184 {
185         ClearLastResult();
186         result r = E_SUCCESS;
187
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.");
192
193         SysAssertf(__pContentManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
194
195         r = __pContentManagerImpl->DeleteContent(contentId);
196         SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] DeleteContent failed.", GetErrorMessage(r));
197
198         return r;
199 }
200
201 result
202 ContentManager::AddContentUpdateEventListener(IContentUpdateEventListener& listener)
203 {
204         ClearLastResult();
205         result r = E_SUCCESS;
206
207         SysAssertf(__pContentManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
208
209         r = __pContentManagerImpl->AddContentUpdateEventListener(listener);
210         SysTryReturnResult(NID_CNT, !IsFailed(r), r, "[%s] AddContentUpdateEventListener failed.", GetErrorMessage(r));
211
212         return r;
213 }
214
215 result
216 ContentManager::RemoveContentUpdateEventListener(IContentUpdateEventListener& listener)
217 {
218         ClearLastResult();
219         result r = E_SUCCESS;
220
221         SysAssertf(__pContentManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
222
223         r = __pContentManagerImpl->RemoveContentUpdateEventListener(listener);
224         SysTryReturnResult(NID_CNT, !IsFailed(r), r, "[%s] RemoveContentUpdateEventListener failed.", GetErrorMessage(r));
225
226         return r;
227 }
228
229 result
230 ContentManager::ScanFile(const Tizen::Base::String& contentPath)
231 {
232         ClearLastResult();
233         result r = E_SUCCESS;
234
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.");
239
240         r = _ContentManagerImpl::ScanFile(contentPath);
241         SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] ScanFile failed.", GetErrorMessage(r));
242
243         return r;
244 }
245
246 result
247 ContentManager::ScanDirectory(const Tizen::Base::String& directoryPath, bool recursive, IContentScanListener* pListener, RequestId& reqId)
248 {
249         ClearLastResult();
250         result r = E_SUCCESS;
251
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.");
256
257         r = _ContentManagerImpl::ScanDirectory(directoryPath, recursive, pListener, reqId);
258         SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] ScanDirectory failed.", GetErrorMessage(r));
259
260         return r;
261 }
262
263 }}