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.
18 * @file FCnt_DownloadRequestImpl.cpp
19 * @brief This is the implementation file for the _DownloadRequestImpl class.
23 #include <unique_ptr.h>
26 #include <FBaseSysLog.h>
27 #include <FCntDownloadRequest.h>
29 #include "FCnt_DownloadRequestImpl.h"
31 using namespace Tizen::Base;
32 using namespace Tizen::Base::Collection;
35 namespace Tizen { namespace Content
38 _DownloadRequestImpl::_DownloadRequestImpl(void)
39 : __notification(true)
40 , __networkType(DOWNLOAD_NETWORK_ALL)
42 __notifyExtraData.Construct();
43 __requestHeader.Construct();
46 _DownloadRequestImpl::_DownloadRequestImpl(const String& url)
48 , __notification(true)
49 , __networkType(DOWNLOAD_NETWORK_ALL)
51 __notifyExtraData.Construct();
52 __requestHeader.Construct();
55 _DownloadRequestImpl::_DownloadRequestImpl(const String& url, const String& dirPath)
58 , __notification(true)
59 , __networkType(DOWNLOAD_NETWORK_ALL)
61 __notifyExtraData.Construct();
62 __requestHeader.Construct();
65 _DownloadRequestImpl::_DownloadRequestImpl(const _DownloadRequestImpl& rhs)
67 , __dirPath(rhs.__dirPath)
68 , __fileName(rhs.__fileName)
69 , __notification(rhs.__notification)
70 , __networkType(rhs.__networkType)
72 __notifyExtraData.Construct(rhs.__notifyExtraData);
73 __requestHeader.Construct(rhs.__requestHeader);
76 _DownloadRequestImpl::~_DownloadRequestImpl(void)
82 _DownloadRequestImpl::operator =(const _DownloadRequestImpl& rhs)
85 __dirPath = rhs.__dirPath;
86 __fileName = rhs.__fileName;
87 __notification = rhs.__notification;
88 __networkType = rhs.__networkType;
89 __notifyExtraData.RemoveAll();
90 __notifyExtraData.Construct(rhs.__notifyExtraData);
91 __requestHeader.RemoveAll();
92 __requestHeader.Construct(rhs.__requestHeader);
98 _DownloadRequestImpl::operator ==(const _DownloadRequestImpl& rhs) const
105 if (__url == rhs.__url
106 && __dirPath == rhs.__dirPath
107 && __fileName == rhs.__fileName)
116 _DownloadRequestImpl::Equals(const Object& obj) const
118 const _DownloadRequestImpl* pOther = dynamic_cast< const _DownloadRequestImpl* >(&obj);
124 return (*this == *pOther);
128 _DownloadRequestImpl::GetHashCode(void) const
132 hashCode.Append(__url);
133 hashCode.Append(__dirPath);
134 hashCode.Append(__fileName);
136 return hashCode.GetHashCode();
140 _DownloadRequestImpl::SetDirectoryPath(const String& dirPath)
146 _DownloadRequestImpl::SetFileName(const String& fileName)
148 __fileName = fileName;
152 _DownloadRequestImpl::GetUrl(void) const
158 _DownloadRequestImpl::GetDirectoryPath(void) const
164 _DownloadRequestImpl::GetFileName(void) const
170 _DownloadRequestImpl::SetNotification(bool enable)
172 __notification = enable;
176 _DownloadRequestImpl::SetNotificationExtraData(const IMap* pExtraData)
179 String* pValue = null;
180 result r = E_SUCCESS;
182 std::unique_ptr<IMapEnumerator> pMapEnum(const_cast< IMap* >(pExtraData)->GetMapEnumeratorN());
183 while (pMapEnum->MoveNext() == E_SUCCESS)
185 pKey = dynamic_cast< String* >(pMapEnum->GetKey());
186 SysTryReturnResult(NID_CNT, pKey != null, E_INVALID_ARG, "The object is not a String class.");
188 pValue = dynamic_cast< String* >(pMapEnum->GetValue());
189 SysTryReturnResult(NID_CNT, pValue != null, E_INVALID_ARG, "The object is not a String class.");
191 r = __notifyExtraData.Add(new String(*pKey), new String(*pValue));
197 _DownloadRequestImpl::SetNetworkType(DownloadNetworkType type)
199 __networkType = type;
203 _DownloadRequestImpl::IsNotificationEnabled(void) const
205 return __notification;
209 _DownloadRequestImpl::GetNotificationExtraData(void) const
211 return &__notifyExtraData;
215 _DownloadRequestImpl::GetNetworkType(void) const
217 return __networkType;
221 _DownloadRequestImpl::AddRequestHeader(const String& field, const String& value)
223 SysTryReturnResult(NID_CNT, !field.IsEmpty(), E_INVALID_ARG, "The field is empty.");
224 SysTryReturnResult(NID_CNT, !__requestHeader.ContainsKey(field), E_INVALID_ARG, "The field already exist.");
225 return __requestHeader.Add(new String(field), new String(value));
229 _DownloadRequestImpl::SetRequestHeader(const String& field, const String& value)
231 SysTryReturnResult(NID_CNT, !field.IsEmpty(), E_INVALID_ARG, "The field is empty.");
232 SysTryReturnResult(NID_CNT, __requestHeader.ContainsKey(field), E_INVALID_ARG, "The field does not exist.");
233 return __requestHeader.SetValue(field, new String(value));
237 _DownloadRequestImpl::RemoveRequestHeader(const String& field)
239 SysTryReturnResult(NID_CNT, !field.IsEmpty(), E_INVALID_ARG, "The field is empty.");
240 SysTryReturnResult(NID_CNT, __requestHeader.ContainsKey(field), E_INVALID_ARG, "The field does not exist.");
241 return __requestHeader.Remove(field);
245 _DownloadRequestImpl::GetRequestHeaderN(const String& field)
247 String* pValue = null;
249 IMapEnumerator* pMapEnum = null;
251 pMapEnum = __requestHeader.GetMapEnumeratorN();
252 while (pMapEnum->MoveNext() == E_SUCCESS)
254 pKey = static_cast< String* > (pMapEnum->GetKey());
257 pValue = new String (*(static_cast< String* > (pMapEnum->GetValue())));
258 SysTryReturn(NID_CNT, pValue != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY]");
267 _DownloadRequestImpl*
268 _DownloadRequestImpl::GetInstance(const DownloadRequest* pRequest)
270 return pRequest->__pDownloadRequestImpl;
274 _DownloadRequestImpl::GetRequestHeader(void)
276 return &__requestHeader;
279 } } // Tizen::Content