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 FCntContentTransfer.cpp
19 * @brief This is the implementation file for the %ContentTransfer class.
21 * This file contains implementation of the %ContentTransfer class.
24 #include <FBaseSysLog.h>
25 #include <FCntContentTransfer.h>
26 #include <FBaseColIList.h>
27 #include <FBaseUtilUri.h>
28 #include <FCnt_ContentTransferImpl.h>
29 #include <FSec_AccessController.h>
31 using namespace Tizen::Base;
32 using namespace Tizen::Security;
34 namespace Tizen { namespace Content
36 ContentTransfer::ContentTransfer(void)
43 ContentTransfer::~ContentTransfer(void)
53 ContentTransfer::Construct(IContentTransferListener& listener)
58 SysAssertf(__pImpl == null,
59 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
61 _ContentTransferImpl* pContentTransferImpl = new (std::nothrow) _ContentTransferImpl();
62 SysTryReturn(NID_CNT, pContentTransferImpl != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Construct failed.");
64 r = pContentTransferImpl->Construct(listener);
65 SysTryCatch(NID_CNT, r == E_SUCCESS, , r, "[%S] Propagating.", GetErrorMessage(r));
67 __pImpl = pContentTransferImpl;
72 delete pContentTransferImpl;
73 pContentTransferImpl = null;
79 ContentTransfer::Cancel(RequestId reqId)
84 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
86 r = __pImpl->Cancel(reqId);
87 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] Cancel failed.", GetErrorMessage(r));
93 ContentTransfer::SetDefaultTimeout(int sec)
97 SysLog(NID_CNT, "__pImpl is null.");
100 __pImpl->SetDefaultTimeout(sec);
104 ContentTransfer::GetDefaultTimeout(void) const
108 SysLog(NID_CNT, "__pImpl is null.");
111 return __pImpl->GetDefaultTimeout();
115 ContentTransfer::Remove(RequestId reqId)
118 result r = E_SUCCESS;
120 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
122 r = __pImpl->Remove(reqId);
123 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] Remove failed.", GetErrorMessage(r));
129 ContentTransfer::RemoveAll(void)
132 result r = E_SUCCESS;
134 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
136 r = __pImpl->RemoveAll();
137 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] RemoveAll failed.", GetErrorMessage(r));
143 ContentTransfer::CancelAll(void)
146 result r = E_SUCCESS;
148 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
150 r = __pImpl->CancelAll();
151 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] CancelAll failed.", GetErrorMessage(r));
157 ContentTransfer::GetContentTransferInfoListN(void) const
161 SysLog(NID_CNT, "__pImpl is null.");
164 return __pImpl->GetContentTransferInfoListN();
168 ContentTransfer::GetContentTransferInfoListInProgressN(void) const
172 SysLog(NID_CNT, "__pImpl is null.");
175 return __pImpl->GetContentTransferInfoListInProgressN();
179 ContentTransfer::SetProgressIntervalByPercent(int percent)
183 SysLog(NID_CNT, "__pImpl is null.");
186 __pImpl->SetProgressIntervalByPercent(percent);
190 ContentTransfer::Download(const Utility::Uri& uri, int fileSize, const String& destFilePath, bool replace,
191 RequestId& reqId, IContentTransferListener* pListener, int sec)
194 result r = E_SUCCESS;
196 // Checks the privilege
197 r = _AccessController::CheckUserPrivilege(_PRV_DOWNLOAD);
198 SysTryReturn(NID_CNT, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
199 "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
201 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
203 r = __pImpl->Download(uri, fileSize, destFilePath, replace, reqId, pListener, sec);
204 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] Download failed.", GetErrorMessage(r));
210 ContentTransfer::Download(const Utility::Uri& uri, const String& filePath,
211 RequestId& reqId, bool replace, int timeout, int progressInterval)
214 result r = E_SUCCESS;
216 // Checks the privilege
217 r = _AccessController::CheckUserPrivilege(_PRV_DOWNLOAD);
218 SysTryReturn(NID_CNT, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
219 "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
221 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
223 r = __pImpl->Download(uri, filePath, reqId, replace, timeout, progressInterval);
224 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] Download failed.", GetErrorMessage(r));
230 ContentTransfer::DownloadToBuffer(const Utility::Uri& uri, int fileSize, RequestId& reqId,IContentTransferListener* pListener, int sec)
233 result r = E_SUCCESS;
235 r = _AccessController::CheckUserPrivilege(_PRV_DOWNLOAD);
236 SysTryReturn(NID_CNT, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
237 "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
239 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
241 r = __pImpl->DownloadToBuffer(uri, fileSize, reqId, pListener, sec);
242 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] DownloadToBuffer failed.", GetErrorMessage(r));
248 ContentTransfer::DownloadToBuffer(const Utility::Uri& uri, RequestId& reqId, int timeout, int progressInterval)
251 result r = E_SUCCESS;
253 r = _AccessController::CheckUserPrivilege(_PRV_DOWNLOAD);
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 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
259 r = __pImpl->DownloadToBuffer(uri, reqId, timeout, progressInterval);
260 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] DownloadToBuffer failed.", GetErrorMessage(r));