2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 FNetHttp_HttpManagedNetConnectionEventListenerImpl.cpp
20 * @brief This is the implementation file for the _HttpManagedNetConnectionEventListenerImpl Class.
23 #include <FNetManagedNetConnection.h>
24 #include <FNetHttpHttpTransaction.h>
25 #include <FBaseSysLog.h>
26 #include "FNet_NetConnectionInfoImpl.h"
27 #include "FNet_ManagedNetConnectionImpl.h"
28 #include "FNetHttp_HttpSessionImpl.h"
29 #include "FNetHttp_HttpTransactionImpl.h"
30 #include "FNetHttp_HttpCommon.h"
31 #include "FNetHttp_HttpManagedNetConnectionEventListenerImpl.h"
32 #include "FNetHttp_HttpTransactionEvent.h"
33 #include "FNetHttp_HttpTransactionEventArg.h"
35 using namespace Tizen::Net;
36 using namespace Tizen::Base;
37 using namespace Tizen::Base::Collection;
39 namespace Tizen { namespace Net { namespace Http
42 _HttpManagedNetConnectionEventListenerImpl::_HttpManagedNetConnectionEventListenerImpl(_HttpSessionImpl* pHttpSessionImpl)
43 : __isReceivedEvent(false)
44 , __pHttpSessionImpl(pHttpSessionImpl)
48 _HttpManagedNetConnectionEventListenerImpl::~_HttpManagedNetConnectionEventListenerImpl()
53 _HttpManagedNetConnectionEventListenerImpl::OnManagedNetConnectionStarted(ManagedNetConnection& managedNetConnection)
55 SysLog(NID_NET_HTTP, "The network state is started.");
57 ProcessPendingTransactions(managedNetConnection);
59 SysLog(NID_NET_HTTP, "Called OnManagedNetConnectionStarted()");
63 _HttpManagedNetConnectionEventListenerImpl::OnManagedNetConnectionStopped(ManagedNetConnection& managedNetConnection, NetConnectionStoppedReason reason)
66 SysLog(NID_NET_HTTP, "The network state is stopped with reason(%d).", reason);
68 if (!__isReceivedEvent)
70 AbortPendingTransactions(managedNetConnection);
71 __pHttpSessionImpl->SetSessionState(false);
75 r = __pHttpSessionImpl->Disconnect();
78 SysLog(NID_NET_HTTP, "Failed to disconnect the HttpSession.");
82 SysLog(NID_NET_HTTP, "Called OnManagedNetConnectionStopped()");
86 _HttpManagedNetConnectionEventListenerImpl::OnManagedNetConnectionSuspended(ManagedNetConnection& managedNetConnection)
88 SysLog(NID_NET_HTTP, "The network state is suspended.");
92 _HttpManagedNetConnectionEventListenerImpl::OnManagedNetConnectionResumed(ManagedNetConnection& managedNetConnection)
94 SysLog(NID_NET_HTTP, "The network state is resumed.");
98 _HttpManagedNetConnectionEventListenerImpl::OnManagedNetConnectionBearerChanged(ManagedNetConnection& managedNetConnection)
100 SysLog(NID_NET_HTTP, "The network state is changed.");
104 _HttpManagedNetConnectionEventListenerImpl::IsEventReceived(void) const
106 return __isReceivedEvent;
110 _HttpManagedNetConnectionEventListenerImpl::SetReceivedEvent(bool isReceivedEvent)
112 __isReceivedEvent = isReceivedEvent;
116 _HttpManagedNetConnectionEventListenerImpl::ProcessPendingTransactions(ManagedNetConnection& managedNetConnection)
118 SysAssertf(__pHttpSessionImpl != null, "The __pHttpSessionImpl must not be null.");
120 result r = E_SUCCESS;
122 if (__isReceivedEvent == false)
124 _ManagedNetConnectionImpl* pManagedNetConnectionImpl = _ManagedNetConnectionImpl::GetInstance(managedNetConnection);
125 SysAssertf(pManagedNetConnectionImpl != null, "pConnectionInfo must not be null.");
127 const NetConnectionInfo* pConnectionInfo = pManagedNetConnectionImpl->GetNetConnectionInfo();
128 SysAssertf(pConnectionInfo != null, "pConnectionInfo must not be null.");
130 const _NetConnectionInfoImpl* pConnectionInfoImpl = _NetConnectionInfoImpl::GetInstance(*pConnectionInfo);
131 SysAssertf(pConnectionInfoImpl != null, "pConnectionInfoImpl must not be null.");
133 String proxyAddressOfManagedMode = pConnectionInfoImpl->GetProxyAddress();
134 String deviceName = pConnectionInfoImpl->GetDeviceName();
135 SysLog(NID_NET_HTTP, "[Preference Mode] Network is started. the device name is %ls, the system proxy address is %ls.", deviceName.GetPointer(), proxyAddressOfManagedMode.GetPointer());
137 if (__pHttpSessionImpl->GetProxyAddress() != null)
139 proxyAddressOfManagedMode = *__pHttpSessionImpl->GetProxyAddress();
140 SysLog(NID_NET_HTTP, "[Preference Mode] Use a specific proxy address[%ls] of application.", proxyAddressOfManagedMode.GetPointer());
144 String* pPorxyAddress = new (std::nothrow) String(proxyAddressOfManagedMode);
145 SysTryReturnVoidResult(NID_NET_HTTP, pPorxyAddress != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
146 __pHttpSessionImpl->SetProxyAddress(pPorxyAddress);
149 __pHttpSessionImpl->SetDeviceName(deviceName);
151 HttpTransaction* pHttpTransaction = null;
152 _HttpTransactionImpl* pHttpTransactionImpl = null;
153 ArrayList* pTransactionList = __pHttpSessionImpl->GetActiveTransactions();
154 SysAssertf(pTransactionList != null, "__pHttpSessionImpl must not be null.");
156 int countOfActiveTransactions = pTransactionList->GetCount();
158 for (int i = 0; i < countOfActiveTransactions; i++)
160 pHttpTransaction = static_cast< HttpTransaction* >(pTransactionList->GetAt(i));
161 if (pHttpTransaction != null)
163 pHttpTransactionImpl = _HttpTransactionImpl::GetInstance(*pHttpTransaction);
164 SysAssertf(pHttpTransactionImpl != null, "__pHttpSessionImpl must not be null.");
166 if (pHttpTransactionImpl->IsPendingTransaction())
168 r = pHttpTransactionImpl->SubmitPendingTransaction(deviceName, proxyAddressOfManagedMode);
171 SysLog(NID_NET_HTTP, "Failed to submit the pending HttpTransaction.");
177 __isReceivedEvent = true;
182 _HttpManagedNetConnectionEventListenerImpl::AbortPendingTransactions(ManagedNetConnection& managedNetConnection)
184 SysAssertf(__pHttpSessionImpl != null, "__pHttpSessionImpl must not be null.");
186 result r = E_SUCCESS;
188 r = managedNetConnection.SetManagedNetConnectionEventListener(null);
191 SysLog(NID_NET_HTTP, "Failed to unset the ManagedNetConnectionEventListener.");
194 HttpTransaction* pHttpTransaction = null;
195 _HttpTransactionImpl* pHttpTransactionImpl = null;
196 ArrayList* pTransactionList = __pHttpSessionImpl->GetActiveTransactions();
197 SysAssertf(pTransactionList != null, "__pHttpSessionImpl must not be null.");
199 int countOfActiveTransactions = pTransactionList->GetCount();
201 for (int i = 0; i < countOfActiveTransactions; i++)
203 pHttpTransaction = static_cast< HttpTransaction* >(pTransactionList->GetAt(i));
204 if (pHttpTransaction != null)
206 pHttpTransactionImpl = _HttpTransactionImpl::GetInstance(*pHttpTransaction);
207 SysAssertf(pHttpTransactionImpl != null, "__pHttpSessionImpl must not be null.");
209 if (pHttpTransactionImpl->IsPendingTransaction())
211 //Fire the event(_HTTP_TRANSACTION_EVENT_TYPE_ABORTED) - E_NETWORK_UNAVAILABLE
212 pHttpTransactionImpl->GetHttpTransactionEvent()->FireTransactionAbortedEvent(E_NETWORK_UNAVAILABLE);
216 __isReceivedEvent = true;
219 } } } // Tizen::Net::Http