Fix an issue of ManagedNetConnectionStopped event and updating http proxy.
authorMyeongSeong Seo <ms49.seo@samsung.com>
Wed, 17 Apr 2013 07:58:13 +0000 (16:58 +0900)
committerMyeongSeong Seo <ms49.seo@samsung.com>
Wed, 17 Apr 2013 07:58:13 +0000 (16:58 +0900)
Change-Id: I31c127c2dde6069bcc0b5478b4c8ea4bc8eecd0f
Signed-off-by: MyeongSeong Seo <ms49.seo@samsung.com>
src/FNet_DefaultSystemNetConnection.cpp
src/FNet_DefaultSystemNetConnection.h
src/FNet_NetConnectionEvent.cpp
src/FNet_NetConnectionEvent.h
src/http/FNetHttp_HttpManagedNetConnectionEventListenerImpl.cpp
src/http/FNetHttp_HttpManagedNetConnectionEventListenerImpl.h
src/http/FNetHttp_HttpSessionImpl.cpp
src/inc/FNetHttp_HttpSessionImpl.h

index 2633b48..583c04d 100644 (file)
@@ -64,33 +64,40 @@ ActiveConnectionTypeChangedCallback(connection_type_e type, void* pUserData)
                        isBearerChanged = true;
                }
 
-               if (isBearerChanged)
-               {
-                       SysLog(NID_NET, "Invoke stop event, because bearer is changed.");
-                       pConnection->HandleStopEvent(E_NETWORK_FAILED);
-                       pConnection->UpdateConnectionInfo(null);
-               }
-
-               if (pConnection->GetConnectionState() == NET_CONNECTION_STATE_STARTED)
-               {
-                       SysLog(NID_NET, "Ignore the event, because this is already in started state.");
-                       return;
-               }
+               NetConnectionState oldState = pConnection->GetConnectionState();
 
                ret = connection_get_current_profile(connectionHandle, &profileHandle);
                SysTryReturnVoidResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
                                "[%s] A system error has been occurred. The return value from connection_get_current_profile() is %d", GetErrorMessage(E_SYSTEM), ret);
 
                pConnection->UpdateConnectionInfo(profileHandle);
-               pConnection->HandleStartEvent();
-
                connection_profile_destroy(profileHandle);
+
+               if (oldState != NET_CONNECTION_STATE_STARTED)
+               {
+                       pConnection->HandleStartEvent();
+               }
+               else if (isBearerChanged)
+               {
+                       pConnection->HandleChangedEvent();
+               }
+               else
+               {
+                       SysLog(NID_NET, "Ignore the event, because this is already in started state.");
+               }
        }
        else
        {
                // Not connected
-               pConnection->HandleStopEvent(E_NETWORK_FAILED);
-               pConnection->UpdateConnectionInfo(null);
+               if ((pConnection->GetConnectionState() != NET_CONNECTION_STATE_NONE) && (pConnection->GetConnectionState() != NET_CONNECTION_STATE_STOPPED))
+               {
+                       pConnection->UpdateConnectionInfo(null);
+                       pConnection->HandleStopEvent(E_NETWORK_FAILED);
+               }
+               else
+               {
+                       SysLog(NID_NET, "Ignore the event, because this is already in stopped state.");
+               }
        }
 }
 
@@ -173,6 +180,8 @@ _DefaultSystemNetConnection::HandleStartEvent(void)
        _NetConnectionEvent* pEvent = null;
        _NetConnectionEventArg* pEventArg = null;
 
+       SysLog(NID_NET, "[%ls] Notify started event.", _name.GetPointer());
+
        MutexGuard locked(*_pLock);
 
        unique_ptr<IEnumerator> pEnum(_pEventList->GetEnumeratorN());
@@ -201,6 +210,70 @@ _DefaultSystemNetConnection::HandleStartEvent(void)
 }
 
 void
+_DefaultSystemNetConnection::HandleStopEvent(result error)
+{
+       _NetConnectionEvent* pEvent = null;
+       _NetConnectionEventArg* pEventArg = null;
+
+       SysLog(NID_NET, "[%ls] Notify stopped event.", _name.GetPointer());
+
+       MutexGuard locked(*_pLock);
+
+       _refCount = 0;
+
+       unique_ptr<IEnumerator> pEnum(_pEventList->GetEnumeratorN());
+       if (pEnum != null)
+       {
+               while (pEnum->MoveNext() == E_SUCCESS)
+               {
+                       pEvent = dynamic_cast<_NetConnectionEvent*>(pEnum->GetCurrent());
+                       if (pEvent != null)
+                       {
+                               pEvent->SetConnectionState(NET_CONNECTION_STATE_STOPPED);
+                               pEventArg = new (std::nothrow) _NetConnectionEventArg(_NET_CONNECTION_EVENT_TYPE_STOPPED, error);
+                               if (pEventArg != null)
+                               {
+                                       pEvent->FireAsync(*pEventArg);
+                               }
+                       }
+               }
+       }
+
+       locked.Unlock();
+}
+
+void
+_DefaultSystemNetConnection::HandleChangedEvent(void)
+{
+       _NetConnectionEvent* pEvent = null;
+       _NetConnectionEventArg* pEventArg = null;
+
+       SysLog(NID_NET, "[%ls] Notify bearer changed event.", _name.GetPointer());
+
+       MutexGuard locked(*_pLock);
+
+       unique_ptr<IEnumerator> pEnum(_pEventList->GetEnumeratorN());
+       if (pEnum != null)
+       {
+               while (pEnum->MoveNext() == E_SUCCESS)
+               {
+                       pEvent = dynamic_cast<_NetConnectionEvent*>(pEnum->GetCurrent());
+                       if (pEvent != null)
+                       {
+                               pEvent->SetConnectionState(NET_CONNECTION_STATE_STARTED);
+                               pEventArg = new (std::nothrow) _NetConnectionEventArg(_NET_CONNECTION_EVENT_TYPE_CHANGED, E_SUCCESS);
+                               if (pEventArg != null)
+                               {
+                                       pEvent->FireAsync(*pEventArg);
+                               }
+                       }
+               }
+       }
+
+       locked.Unlock();
+}
+
+void
 _DefaultSystemNetConnection::UpdateConnectionInfo(void* pData)
 {
        connection_profile_h profileHandle = pData;
index ac1cbfa..e7f0cc8 100644 (file)
@@ -66,6 +66,9 @@ public:
        result Construct(void);
 
        virtual void HandleStartEvent(void);
+       virtual void HandleStopEvent(result error);
+
+       void HandleChangedEvent(void);
 
        void UpdateConnectionInfo(void* pData);
        void* GetConnectionHandle(void) const;
index 4f7f5d8..7341258 100644 (file)
@@ -340,6 +340,11 @@ _NetConnectionEvent::FireImpl(IEventListener& listener, const IEventArg& arg)
                        pManagedNetConnectionEventListener->OnManagedNetConnectionResumed(*pManagedNetConnection);
                        SysLog(NID_NET, "Called OnManagedNetConnectionResumed().");
                        break;
+               case _NET_CONNECTION_EVENT_TYPE_CHANGED:
+                       SysLog(NID_NET, "Calling OnManagedNetConnectionBearerChanged().");
+                       pManagedNetConnectionEventListener->OnManagedNetConnectionBearerChanged(*pManagedNetConnection);
+                       SysLog(NID_NET, "Called OnManagedNetConnectionBearerChanged().");
+                       break;
                default:
                        break;
                }
index d57a365..229229b 100644 (file)
@@ -55,7 +55,8 @@ enum _NetConnectionEventType
        _NET_CONNECTION_EVENT_TYPE_STARTED,
        _NET_CONNECTION_EVENT_TYPE_STOPPED,
        _NET_CONNECTION_EVENT_TYPE_SUSPENDED,
-       _NET_CONNECTION_EVENT_TYPE_RESUMED
+       _NET_CONNECTION_EVENT_TYPE_RESUMED,
+       _NET_CONNECTION_EVENT_TYPE_CHANGED
 };
 
 typedef Tizen::Base::Runtime::IEventListener* _NetListenerKey;
index a356f69..abe80dd 100644 (file)
@@ -98,6 +98,10 @@ void
 _HttpManagedNetConnectionEventListenerImpl::OnManagedNetConnectionBearerChanged(ManagedNetConnection& managedNetConnection)
 {
        SysLog(NID_NET_HTTP, "The network state is changed.");
+
+       ProcessUpdateProxy(managedNetConnection);
+
+       SysLog(NID_NET_HTTP, "Called OnManagedNetConnectionBearerChanged()");
 }
 
 bool
@@ -179,6 +183,39 @@ _HttpManagedNetConnectionEventListenerImpl::ProcessPendingTransactions(ManagedNe
 }
 
 void
+_HttpManagedNetConnectionEventListenerImpl::ProcessUpdateProxy(ManagedNetConnection& managedNetConnection)
+{
+       SysAssertf(__pHttpSessionImpl != null, "The __pHttpSessionImpl must not be null.");
+
+       result r = E_SUCCESS;
+
+       _ManagedNetConnectionImpl* pManagedNetConnectionImpl = _ManagedNetConnectionImpl::GetInstance(managedNetConnection);
+       SysAssertf(pManagedNetConnectionImpl != null, "pConnectionInfo must not be null.");
+
+       const NetConnectionInfo* pConnectionInfo = pManagedNetConnectionImpl->GetNetConnectionInfo();
+       SysAssertf(pConnectionInfo != null, "pConnectionInfo must not be null.");
+
+       const _NetConnectionInfoImpl* pConnectionInfoImpl = _NetConnectionInfoImpl::GetInstance(*pConnectionInfo);
+       SysAssertf(pConnectionInfoImpl != null, "pConnectionInfoImpl must not be null.");
+
+       String proxyAddressOfManagedMode = pConnectionInfoImpl->GetProxyAddress();
+       String deviceName = pConnectionInfoImpl->GetDeviceName();
+       SysLog(NID_NET_HTTP, "[Default Mode] Network is changed. the device name is %ls, the system proxy address is %ls.", deviceName.GetPointer(), proxyAddressOfManagedMode.GetPointer());
+
+       if (__pHttpSessionImpl->IsUserProxy() == true)
+       {
+               proxyAddressOfManagedMode = *__pHttpSessionImpl->GetProxyAddress();
+               SysLog(NID_NET_HTTP, "[Default Mode] Use a specific proxy address[%ls] of application.", proxyAddressOfManagedMode.GetPointer());
+       }
+       else
+       {
+               String* pPorxyAddress = new (std::nothrow) String(proxyAddressOfManagedMode);
+               SysTryReturnVoidResult(NID_NET_HTTP, pPorxyAddress != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
+               __pHttpSessionImpl->SetProxyAddress(pPorxyAddress);
+       }
+}
+
+void
 _HttpManagedNetConnectionEventListenerImpl::AbortPendingTransactions(ManagedNetConnection& managedNetConnection)
 {
        SysAssertf(__pHttpSessionImpl != null, "__pHttpSessionImpl must not be null.");
index ad5e888..6d1bb10 100644 (file)
@@ -62,6 +62,8 @@ public:
 private:
        void ProcessPendingTransactions(ManagedNetConnection& managedNetConnection);
 
+       void ProcessUpdateProxy(ManagedNetConnection& managedNetConnection);
+
        void AbortPendingTransactions(ManagedNetConnection& managedNetConnection);
 
 private:
index 0622d15..62fc975 100644 (file)
@@ -82,6 +82,7 @@ _HttpSessionImpl::_HttpSessionImpl(HttpSession* pHttpSession)
        , __isClosed(false)
        , __isAutoRedirectionEnabled(false)
        , __isAlreadyResumed(false)
+       , __isUserProxy(false)
        , __pHttpMultipleConnectionInfo(null)
        , __pCookieStorageMgr(null)
        , __pNetConnection(null)
@@ -315,6 +316,7 @@ _HttpSessionImpl::Construct(NetHttpSessionMode sessionMode, const String* pProxy
        {
                SysLog(NID_NET_HTTP, "The proxy address is %ls.", pProxyAddr->GetPointer());
 
+               __isUserProxy = true;
                pProxyAddress.reset(new (std::nothrow) String(*pProxyAddr));
                SysTryReturnResult(NID_NET_HTTP, pProxyAddress != null, E_OUT_OF_MEMORY,
                                        "Memory allocation failed.");
@@ -535,6 +537,7 @@ _HttpSessionImpl::Construct(const NetConnection& netConnection, NetHttpSessionMo
        {
                SysLog(NID_NET_HTTP, "The proxy address %ls.", pProxyAddr->GetPointer());
 
+               __isUserProxy = true;
                pProxyAddress.reset(new (std::nothrow) String(*pProxyAddr));
                SysTryReturnResult(NID_NET_HTTP, pProxyAddress != null, E_OUT_OF_MEMORY,
                                        "Memory allocation failed.");
@@ -903,6 +906,13 @@ _HttpSessionImpl::IsConnectionStarted(void) const
        return false;
 }
 
+bool
+_HttpSessionImpl::IsUserProxy(void) const
+{
+       return __isUserProxy;
+}
+
+
 void
 _HttpSessionImpl::IgnoreSslVerification(void)
 {
index 5801bc2..efa4464 100644 (file)
@@ -187,6 +187,8 @@ public:
 
        bool IsConnectionStarted(void) const;
 
+       bool IsUserProxy(void) const;
+
        HttpTransaction* OpenTransactionWithCurlN(CURL* pCurl, bool uncheckedMaxTransactions = false);
 
        HttpTransaction* ReopenTransactionWithAuthN(HttpTransaction& httpTransaction);
@@ -229,6 +231,7 @@ private:
        bool __isClosed;
        bool __isAutoRedirectionEnabled;
        bool __isAlreadyResumed;
+       bool __isUserProxy;
        class _HttpMultipleConnectionInfo* __pHttpMultipleConnectionInfo;
        HttpCookieStorageManager* __pCookieStorageMgr;
        Tizen::Net::NetConnection* __pNetConnection;