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.
19 * @file FCnt_DownloadRequestImpl.cpp
20 * @brief This is the implementation file for the _DownloadRequestImpl class.
24 #include <unique_ptr.h>
27 #include <FBaseSysLog.h>
28 #include <FCntDownloadRequest.h>
30 #include "FCnt_DownloadRequestImpl.h"
32 using namespace Tizen::Base;
33 using namespace Tizen::Base::Collection;
36 namespace Tizen { namespace Content
39 _DownloadRequestImpl::_DownloadRequestImpl(void)
40 : __notification(true)
41 , __networkType(DOWNLOAD_NETWORK_ALL)
43 __notifyExtraData.Construct();
44 __requestHeader.Construct();
47 _DownloadRequestImpl::_DownloadRequestImpl(const String& url)
49 , __notification(true)
50 , __networkType(DOWNLOAD_NETWORK_ALL)
52 __notifyExtraData.Construct();
53 __requestHeader.Construct();
56 _DownloadRequestImpl::_DownloadRequestImpl(const String& url, const String& dirPath)
59 , __notification(true)
60 , __networkType(DOWNLOAD_NETWORK_ALL)
62 __notifyExtraData.Construct();
63 __requestHeader.Construct();
66 _DownloadRequestImpl::_DownloadRequestImpl(const _DownloadRequestImpl& rhs)
68 , __dirPath(rhs.__dirPath)
69 , __fileName(rhs.__fileName)
70 , __notification(rhs.__notification)
71 , __networkType(rhs.__networkType)
73 __notifyExtraData.Construct(rhs.__notifyExtraData);
74 __requestHeader.Construct(rhs.__requestHeader);
77 _DownloadRequestImpl::~_DownloadRequestImpl(void)
83 _DownloadRequestImpl::operator =(const _DownloadRequestImpl& rhs)
86 __dirPath = rhs.__dirPath;
87 __fileName = rhs.__fileName;
88 __notification = rhs.__notification;
89 __networkType = rhs.__networkType;
90 __notifyExtraData.RemoveAll();
91 __notifyExtraData.Construct(rhs.__notifyExtraData);
92 __requestHeader.RemoveAll();
93 __requestHeader.Construct(rhs.__requestHeader);
99 _DownloadRequestImpl::operator ==(const _DownloadRequestImpl& rhs) const
106 if (__url == rhs.__url
107 && __dirPath == rhs.__dirPath
108 && __fileName == rhs.__fileName)
117 _DownloadRequestImpl::Equals(const Object& obj) const
119 const _DownloadRequestImpl* pOther = dynamic_cast< const _DownloadRequestImpl* >(&obj);
125 return (*this == *pOther);
129 _DownloadRequestImpl::GetHashCode(void) const
133 hashCode.Append(__url);
134 hashCode.Append(__dirPath);
135 hashCode.Append(__fileName);
137 return hashCode.GetHashCode();
141 _DownloadRequestImpl::SetDirectoryPath(const String& dirPath)
147 _DownloadRequestImpl::SetFileName(const String& fileName)
149 __fileName = fileName;
153 _DownloadRequestImpl::GetUrl(void) const
159 _DownloadRequestImpl::GetDirectoryPath(void) const
165 _DownloadRequestImpl::GetFileName(void) const
171 _DownloadRequestImpl::SetNotification(bool enable)
173 __notification = enable;
177 _DownloadRequestImpl::SetNotificationExtraData(const IMap* pExtraData)
180 String* pValue = null;
181 result r = E_SUCCESS;
183 std::unique_ptr<IMapEnumerator> pMapEnum(const_cast< IMap* >(pExtraData)->GetMapEnumeratorN());
184 while (pMapEnum->MoveNext() == E_SUCCESS)
186 pKey = dynamic_cast< String* >(pMapEnum->GetKey());
187 SysTryReturnResult(NID_CNT, pKey != null, E_INVALID_ARG, "The object is not a String class.");
189 pValue = dynamic_cast< String* >(pMapEnum->GetValue());
190 SysTryReturnResult(NID_CNT, pValue != null, E_INVALID_ARG, "The object is not a String class.");
192 r = __notifyExtraData.Add(new String(*pKey), new String(*pValue));
198 _DownloadRequestImpl::SetNetworkType(DownloadNetworkType type)
200 __networkType = type;
204 _DownloadRequestImpl::IsNotificationEnabled(void) const
206 return __notification;
210 _DownloadRequestImpl::GetNotificationExtraData(void) const
212 return &__notifyExtraData;
216 _DownloadRequestImpl::GetNetworkType(void) const
218 return __networkType;
222 _DownloadRequestImpl::AddRequestHeader(const String& field, const String& value)
224 SysTryReturnResult(NID_CNT, !field.IsEmpty(), E_INVALID_ARG, "The field is empty.");
225 SysTryReturnResult(NID_CNT, !__requestHeader.ContainsKey(field), E_INVALID_ARG, "The field already exist.");
226 return __requestHeader.Add(new String(field), new String(value));
230 _DownloadRequestImpl::SetRequestHeader(const String& field, const String& value)
232 SysTryReturnResult(NID_CNT, !field.IsEmpty(), E_INVALID_ARG, "The field is empty.");
233 SysTryReturnResult(NID_CNT, __requestHeader.ContainsKey(field), E_INVALID_ARG, "The field does not exist.");
234 return __requestHeader.SetValue(field, new String(value));
238 _DownloadRequestImpl::RemoveRequestHeader(const String& field)
240 SysTryReturnResult(NID_CNT, !field.IsEmpty(), E_INVALID_ARG, "The field is empty.");
241 SysTryReturnResult(NID_CNT, __requestHeader.ContainsKey(field), E_INVALID_ARG, "The field does not exist.");
242 return __requestHeader.Remove(field);
246 _DownloadRequestImpl::GetRequestHeaderN(const String& field)
248 String* pValue = null;
250 IMapEnumerator* pMapEnum = null;
252 pMapEnum = __requestHeader.GetMapEnumeratorN();
253 while (pMapEnum->MoveNext() == E_SUCCESS)
255 pKey = static_cast< String* > (pMapEnum->GetKey());
258 pValue = new String (*(static_cast< String* > (pMapEnum->GetValue())));
259 SysTryReturn(NID_CNT, pValue != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY]");
268 _DownloadRequestImpl*
269 _DownloadRequestImpl::GetInstance(const DownloadRequest* pRequest)
271 return pRequest->__pDownloadRequestImpl;
275 _DownloadRequestImpl::GetRequestHeader(void)
277 return &__requestHeader;
280 } } // Tizen::Content