Tizen 2.1 base
[platform/framework/native/content.git] / src / FCntDownloadManager.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 /**
19  * @file        FCntDownloadManager.cpp
20  * @brief       This is the implementation file for the DownloadManager class.
21  *
22  */
23
24 #include <FBaseSysLog.h>
25 #include <FSec_AccessController.h>
26 #include <FCntDownloadManager.h>
27 #include <FCntDownloadRequest.h>
28 #include <FCntIDownloadListener.h>
29
30 #include "FCnt_DownloadManagerImpl.h"
31
32 using namespace Tizen::Base;
33 using namespace Tizen::Base::Collection;
34 using namespace Tizen::Security;
35
36 namespace Tizen { namespace Content
37 {
38
39 DownloadManager::DownloadManager(void)
40         : __pDownloadManagerImpl(null)
41 {
42 }
43
44 DownloadManager::~DownloadManager(void)
45 {
46         delete __pDownloadManagerImpl;
47 }
48
49 DownloadManager*
50 DownloadManager::GetInstance(void)
51 {
52         result r = E_SUCCESS;
53         static DownloadManager* pManager = null;
54
55         if (pManager == null)
56         {
57                 pManager = new (std::nothrow) DownloadManager;
58                 SysTryReturn(NID_CNT, pManager != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
59
60                 _DownloadManagerImpl* pImpl = _DownloadManagerImpl::GetInstance();
61                 SysTryCatch(NID_CNT, pImpl != null, , E_SYSTEM, "[E_SYSTEM] Failed to initialize download manager.");
62
63                 pManager->__pDownloadManagerImpl = pImpl;
64         }
65
66         return pManager;
67
68 CATCH:
69         delete pManager;
70         pManager = null;
71
72         return null;
73 }
74
75 result
76 DownloadManager::Start(const DownloadRequest& request, RequestId& reqId)
77 {
78         SysAssertf(__pDownloadManagerImpl != null, "Not yet constructed. Construct() should be called before use.\n");
79
80         result r = _AccessController::CheckUserPrivilege(_PRV_DOWNLOAD);
81         SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_PRIVILEGE_DENIED,
82                         "The application does not have the privilege to call this method.");
83
84         return __pDownloadManagerImpl->Start(request, reqId);
85 }
86
87
88 result
89 DownloadManager::Pause(RequestId reqId)
90 {
91         SysAssertf(__pDownloadManagerImpl != null, "Not yet constructed. Construct() should be called before use.\n");
92
93         return __pDownloadManagerImpl->Pause(reqId);
94 }
95
96 result
97 DownloadManager::Resume(RequestId reqId)
98 {
99         SysAssertf(__pDownloadManagerImpl != null, "Not yet constructed. Construct() should be called before use.\n");
100
101         return __pDownloadManagerImpl->Resume(reqId);
102 }
103
104 result
105 DownloadManager::Cancel(RequestId reqId)
106 {
107         SysAssertf(__pDownloadManagerImpl != null, "Not yet constructed. Construct() should be called before use.\n");
108
109         return __pDownloadManagerImpl->Cancel(reqId);
110 }
111
112
113 DownloadRequest*
114 DownloadManager::GetDownloadRequestN(RequestId reqId) const
115 {
116         SysAssertf(__pDownloadManagerImpl != null, "Not yet constructed. Construct() should be called before use.\n");
117
118         return __pDownloadManagerImpl->GetDownloadRequestN(reqId);
119 }
120
121 DownloadState
122 DownloadManager::GetState(RequestId reqId) const
123 {
124         SysAssertf(__pDownloadManagerImpl != null, "Not yet constructed. Construct() should be called before use.\n");
125
126         return (DownloadState)__pDownloadManagerImpl->GetState(reqId);
127 }
128
129 result
130 DownloadManager::GetMimeType(RequestId reqId, String& mimeType) const
131 {
132         SysAssertf(__pDownloadManagerImpl != null, "Not yet constructed. Construct() should be called before use.\n");
133
134         return __pDownloadManagerImpl->GetMimeType(reqId, mimeType);
135 }
136
137 /*
138 result
139 DownloadManager::SetAllowedNetwork(unsigned long flags)
140 {
141         SysAssertf(__pDownloadManagerImpl != null, "Not yet constructed. Construct() should be called before use.\n");
142
143         return __pDownloadManagerImpl->SetAllowedNetwork(flags);
144 }
145
146 result
147 DownloadManager::GetProgress(RequestId reqId, int& progress) const
148 {
149         SysAssertf(__pDownloadManagerImpl != null, "Not yet constructed. Construct() should be called before use.\n");
150
151         return __pDownloadManagerImpl->GetProgress(reqId, progress);
152 }
153 */
154
155 void
156 DownloadManager::SetDownloadListener(IDownloadListener* pListener)
157 {
158         __pDownloadManagerImpl->SetDownloadListener(pListener);
159 }
160
161 } } // Tizen::Content