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.
25 #include <FBaseSysLog.h>
26 #include <FCntContentTransfer.h>
27 #include <FBaseColIList.h>
28 #include <FBaseUtilUri.h>
29 #include <FCnt_ContentTransferImpl.h>
30 #include <FSec_AccessController.h>
33 using namespace Tizen::Base;
34 using namespace Tizen::Security;
36 namespace Tizen { namespace Content
38 ContentTransfer::ContentTransfer(void)
45 ContentTransfer::~ContentTransfer(void)
55 ContentTransfer::Construct(IContentTransferListener& listener)
60 SysAssertf(__pImpl == null,
61 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
63 _ContentTransferImpl* pContentTransferImpl = new (std::nothrow) _ContentTransferImpl();
64 SysTryReturn(NID_CNT, pContentTransferImpl != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Construct failed.");
66 r = pContentTransferImpl->Construct(listener);
67 SysTryCatch(NID_CNT, r == E_SUCCESS, , r, "[%S] Propagating.", GetErrorMessage(r));
69 __pImpl = pContentTransferImpl;
74 delete pContentTransferImpl;
75 pContentTransferImpl = null;
81 ContentTransfer::Cancel(RequestId reqId)
86 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
88 r = __pImpl->Cancel(reqId);
89 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] Cancel failed.", GetErrorMessage(r));
95 ContentTransfer::SetDefaultTimeout(int sec)
99 SysLog(NID_CNT, "__pImpl is null.");
102 __pImpl->SetDefaultTimeout(sec);
106 ContentTransfer::GetDefaultTimeout(void) const
110 SysLog(NID_CNT, "__pImpl is null.");
113 return __pImpl->GetDefaultTimeout();
117 ContentTransfer::Remove(RequestId reqId)
120 result r = E_SUCCESS;
122 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
124 r = __pImpl->Remove(reqId);
125 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] Remove failed.", GetErrorMessage(r));
131 ContentTransfer::RemoveAll(void)
134 result r = E_SUCCESS;
136 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
138 r = __pImpl->RemoveAll();
139 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] RemoveAll failed.", GetErrorMessage(r));
145 ContentTransfer::CancelAll(void)
148 result r = E_SUCCESS;
150 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
152 r = __pImpl->CancelAll();
153 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] CancelAll failed.", GetErrorMessage(r));
159 ContentTransfer::GetContentTransferInfoListN(void) const
163 SysLog(NID_CNT, "__pImpl is null.");
166 return __pImpl->GetContentTransferInfoListN();
170 ContentTransfer::GetContentTransferInfoListInProgressN(void) const
174 SysLog(NID_CNT, "__pImpl is null.");
177 return __pImpl->GetContentTransferInfoListInProgressN();
181 ContentTransfer::SetProgressIntervalByPercent(int percent)
185 SysLog(NID_CNT, "__pImpl is null.");
188 __pImpl->SetProgressIntervalByPercent(percent);
192 ContentTransfer::Download(const Utility::Uri& uri, int fileSize, const String& destFilePath, bool replace,
193 RequestId& reqId, IContentTransferListener* pListener, int sec)
196 result r = E_SUCCESS;
198 // Checks the privilege
199 r = _AccessController::CheckUserPrivilege(_PRV_DOWNLOAD);
200 SysTryReturn(NID_CNT, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
201 "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
203 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
205 r = __pImpl->Download(uri, fileSize, destFilePath, replace, reqId, pListener, sec);
206 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] Download failed.", GetErrorMessage(r));
212 ContentTransfer::Download(const Utility::Uri& uri, const String& filePath,
213 RequestId& reqId, bool replace, int timeout, int progressInterval)
216 result r = E_SUCCESS;
218 // Checks the privilege
219 r = _AccessController::CheckUserPrivilege(_PRV_DOWNLOAD);
220 SysTryReturn(NID_CNT, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
221 "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
223 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
225 r = __pImpl->Download(uri, filePath, reqId, replace, timeout, progressInterval);
226 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] Download failed.", GetErrorMessage(r));
232 ContentTransfer::DownloadToBuffer(const Utility::Uri& uri, int fileSize, RequestId& reqId,IContentTransferListener* pListener, int sec)
235 result r = E_SUCCESS;
237 r = _AccessController::CheckUserPrivilege(_PRV_DOWNLOAD);
238 SysTryReturn(NID_CNT, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
239 "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
241 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
243 r = __pImpl->DownloadToBuffer(uri, fileSize, reqId, pListener, sec);
244 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] DownloadToBuffer failed.", GetErrorMessage(r));
250 ContentTransfer::DownloadToBuffer(const Utility::Uri& uri, RequestId& reqId, int timeout, int progressInterval)
253 result r = E_SUCCESS;
255 r = _AccessController::CheckUserPrivilege(_PRV_DOWNLOAD);
256 SysTryReturn(NID_CNT, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
257 "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
259 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
261 r = __pImpl->DownloadToBuffer(uri, reqId, timeout, progressInterval);
262 SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] DownloadToBuffer failed.", GetErrorMessage(r));