From: Junggyu Yu Date: Fri, 22 Mar 2013 04:48:53 +0000 (+0900) Subject: Modification about event handling for guaranteed caller thread X-Git-Tag: accepted/tizen_2.1/20130425.034729~45 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3724a91410d27c95cbe468abf01e47e7b1a09d35;p=framework%2Fosp%2Fnet.git Modification about event handling for guaranteed caller thread Change-Id: Idc1001e335be83e58f41716ab18e18b101dba429 --- diff --git a/src/inc/FNetWifi_IWifiManagerEventListener.h b/src/inc/FNetWifi_IWifiManagerEventListener.h index faa59b4..6508a7f 100644 --- a/src/inc/FNetWifi_IWifiManagerEventListener.h +++ b/src/inc/FNetWifi_IWifiManagerEventListener.h @@ -78,7 +78,7 @@ public: /** * @see IWifiManagerEventListener::OnWifiScanCompletedN() */ - virtual void OnWifiScanCompletedN(Tizen::Base::Collection::IList* pWifiBssInfoList, result r) = 0; + virtual void OnWifiScanCompleted(Tizen::Base::Collection::IList* pWifiBssInfoList, result r) = 0; /** * @see IWifiSystemMonitoringEventListener::OnWifiConnectionStateChanged() diff --git a/src/inc/FNetWifi_WifiManagerImpl.h b/src/inc/FNetWifi_WifiManagerImpl.h index 935ea1e..dafe913 100644 --- a/src/inc/FNetWifi_WifiManagerImpl.h +++ b/src/inc/FNetWifi_WifiManagerImpl.h @@ -38,6 +38,7 @@ class WifiManager; class IWifiManagerEventListener; class IWifiSystemMonitoringEventListener; class _WifiSystemAdapter; +class _WifiManagerEvent; class _WifiSystemMonitoringEvent; /** @@ -183,7 +184,7 @@ public: /** * @see IWifiManagerEventListener::OnWifiScanCompletedN() */ - virtual void OnWifiScanCompletedN(Tizen::Base::Collection::IList* pWifiBssInfoList, result r); + virtual void OnWifiScanCompleted(Tizen::Base::Collection::IList* pWifiBssInfoList, result r); /** * @see IWifiSystemMonitoringEventListener::OnWOnWifiConnectionStateChanged() @@ -250,8 +251,8 @@ private: private: _WifiSystemAdapter* __pWifiSystemAdapter; - _WifiSystemMonitoringEvent* __pMonitoringEvt; - IWifiManagerEventListener* __pManagerEvtListener; + std::unique_ptr<_WifiManagerEvent> __pMgrEvent; + std::unique_ptr<_WifiSystemMonitoringEvent> __pMonitoringEvent; WifiBssInfo* __pTargetApInfo; Tizen::Base::Runtime::Mutex __stateMutex; _WifiManagerState __currentState; diff --git a/src/inc/FNetWifi_WifiSystemAdapter.h b/src/inc/FNetWifi_WifiSystemAdapter.h index 00501d5..c8eb38d 100644 --- a/src/inc/FNetWifi_WifiSystemAdapter.h +++ b/src/inc/FNetWifi_WifiSystemAdapter.h @@ -35,7 +35,7 @@ namespace Tizen { namespace Net { namespace Wifi class WifiBssInfo; class _WifiManagerImpl; -class _WifiManagerEvent; +class _IWifiManagerEventListener; class _OSP_EXPORT_ _WifiSystemAdapter : public Tizen::Base::Object @@ -62,7 +62,7 @@ public: * @exception E_SUCCESS The method is successful. * @exception E_OBJ_NOT_FOUND The input instance is not registered. */ - result UnregisterManagerEventListener(const _IWifiManagerEventListener& listener); + result UnregisterManagerEventListener(_IWifiManagerEventListener& listener); /** * Activates the local Wifi device. @@ -295,7 +295,7 @@ private: _WifiSystemAdapter& operator=(const _WifiSystemAdapter& rhs); private: - std::unique_ptr<_WifiManagerEvent> __pWifiManagerEvent; + Tizen::Base::Collection::LinkedListT<_IWifiManagerEventListener*> __mgrEvtListenerList; WifiBssInfo* __pBssInfo; friend class std::default_delete<_WifiSystemAdapter>; diff --git a/src/inc/FNetWifi_WifiUtility.h b/src/inc/FNetWifi_WifiUtility.h index 89fe67c..4fa1eb8 100644 --- a/src/inc/FNetWifi_WifiUtility.h +++ b/src/inc/FNetWifi_WifiUtility.h @@ -206,6 +206,8 @@ public: */ static bool CheckAddressEquality(Tizen::Net::IpAddress* pFirstAddress, Tizen::Net::IpAddress* pSecondAddress); + static Tizen::Base::Collection::IList* GetWifiBssInfoListCloneN(const Tizen::Base::Collection::IList* pSrcList); + private: /** * This default constructor is intentionally declared as private because this class cannot be constructed. diff --git a/src/wifi/FNetWifi_WifiManagerEvent.cpp b/src/wifi/FNetWifi_WifiManagerEvent.cpp index 9c21c1a..3dcf3ed 100644 --- a/src/wifi/FNetWifi_WifiManagerEvent.cpp +++ b/src/wifi/FNetWifi_WifiManagerEvent.cpp @@ -28,9 +28,10 @@ #include #include #include +#include #include "FNetWifi_WifiManagerEvent.h" #include "FNetWifi_WifiManagerEventArg.h" -#include "FNetWifi_IWifiManagerEventListener.h" +#include "FNetWifi_WifiUtility.h" using namespace std; using namespace Tizen::Base; @@ -59,7 +60,7 @@ _WifiManagerEvent::FireImpl(Tizen::Base::Runtime::IEventListener& listener, cons result r = E_SUCCESS; IList* pBssInfoList = null; - _IWifiManagerEventListener* pEventListener = dynamic_cast<_IWifiManagerEventListener*>(&listener); + IWifiManagerEventListener* pEventListener = dynamic_cast(&listener); SysTryReturnVoidResult(NID_NET_WIFI, pEventListener != null, E_INVALID_ARG, "[E_INVALID_ARG] Listener argument is invalid."); const _WifiManagerEventArg* pEventArg = dynamic_cast(&arg); @@ -92,56 +93,14 @@ _WifiManagerEvent::FireImpl(Tizen::Base::Runtime::IEventListener& listener, cons break; case _WIFI_EVENT_SCAN_COMPLETED: SysLog(NID_NET_WIFI, "Firing Wi-Fi Manager Event (Type: _WIFI_EVENT_SCAN_COMPLETED)"); - pBssInfoList = GetWifiBssInfoListCloneN(pEventArg->GetBssInfoList()); + pBssInfoList = _WifiUtility::GetWifiBssInfoListCloneN(pEventArg->GetBssInfoList()); r = GetLastResult(); pEventListener->OnWifiScanCompletedN(pBssInfoList, r); break; - case _WIFI_EVENT_CONNECTION_CHNAGED: - SysLog(NID_NET_WIFI, "Firing Wi-Fi Manager Event (Type: _WIFI_EVENT_CONNECTION_CHNAGED)"); - pEventListener->OnWifiConnectionStateChanged(pEventArg->GetConnectionState()); - break; - case _WIFI_EVENT_SCAN_UPDATED: - SysLog(NID_NET_WIFI, "Firing Wi-Fi Manager Event (Type: _WIFI_EVENT_SCAN_UPDATED)"); - pEventListener->OnWifiSystemScanResultUpdated(); - break; default: break; } } -Tizen::Base::Collection::IList* -_WifiManagerEvent::GetWifiBssInfoListCloneN(const Tizen::Base::Collection::IList* pSrcList) -{ - result r = E_SUCCESS; - unique_ptr pDescList; - int count = 0; - - SysTryReturn(NID_NET_WIFI, pSrcList != null, null, E_FAILURE, "[E_FAILURE] Failed to get the BSS info list."); - - count = pSrcList->GetCount(); - - pDescList.reset(new (std::nothrow) ArrayList(SingleObjectDeleter)); - SysTryReturn(NID_NET_WIFI, pDescList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); - - r = pDescList->Construct(count); - r = TransExceptionsExclusive(r, E_FAILURE, E_OUT_OF_MEMORY); - SysTryReturn(NID_NET_WIFI, r == E_SUCCESS, null, r, "[%s] Failed to construct a new BSS info list.", GetErrorMessage(r)); - - for (int i = 0; i < count; i++) - { - const WifiBssInfo* pSrcBssInfo = dynamic_cast(pSrcList->GetAt(i)); - SysTryReturn(NID_NET_WIFI, pSrcBssInfo != null, null, E_FAILURE, "[E_FAILURE] Failed to get the BSS Info for the list."); - - WifiBssInfo* pDescBssInfo = new (std::nothrow) WifiBssInfo(*pSrcBssInfo); - SysTryReturn(NID_NET_WIFI, pDescBssInfo != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); - - r = pDescList->Add(*pDescBssInfo); - r = TransExceptionsExclusive(r, E_FAILURE, E_OUT_OF_MEMORY); - SysTryReturn(NID_NET_WIFI, r == E_SUCCESS, null, r, "[%s] Failed to add a new BSS info to the list.", GetErrorMessage(r)); - } - - return pDescList.release(); -} - } } } //Tizen::Net::Wifi diff --git a/src/wifi/FNetWifi_WifiManagerEvent.h b/src/wifi/FNetWifi_WifiManagerEvent.h index 2c6585d..6a01766 100644 --- a/src/wifi/FNetWifi_WifiManagerEvent.h +++ b/src/wifi/FNetWifi_WifiManagerEvent.h @@ -94,8 +94,6 @@ private: */ _WifiManagerEvent& operator=(const _WifiManagerEvent& rhs); - Tizen::Base::Collection::IList* GetWifiBssInfoListCloneN(const Tizen::Base::Collection::IList* pSrcList); - }; // _WifiManagerEvent } } } // Tizen::Net::Wifi diff --git a/src/wifi/FNetWifi_WifiManagerImpl.cpp b/src/wifi/FNetWifi_WifiManagerImpl.cpp index cd25670..b53dc78 100644 --- a/src/wifi/FNetWifi_WifiManagerImpl.cpp +++ b/src/wifi/FNetWifi_WifiManagerImpl.cpp @@ -31,8 +31,11 @@ #include "FNetWifi_WifiManagerImpl.h" #include "FNetWifi_WifiSystemAdapter.h" #include "FNetWifi_WifiIpcProxy.h" +#include "FNetWifi_WifiManagerEvent.h" +#include "FNetWifi_WifiManagerEventArg.h" #include "FNetWifi_WifiSystemMonitoringEvent.h" #include "FNetWifi_WifiSystemMonitoringEventArg.h" +#include "FNetWifi_WifiUtility.h" using namespace std; using namespace Tizen::Base; @@ -43,10 +46,10 @@ namespace Tizen { namespace Net { namespace Wifi { _WifiManagerImpl::_WifiManagerImpl(void) : __pWifiSystemAdapter(null) - , __pMonitoringEvt(null) - , __pManagerEvtListener(null) + , __pMgrEvent(null) + , __pMonitoringEvent(null) , __pTargetApInfo(null) - , __stateMutex() + , __stateMutex() , __currentState(WIFI_MANAGER_DEACTIVATED) , __currentScanState(WIFI_SCAN_IDLE) , __wasConnected(false) @@ -55,29 +58,22 @@ _WifiManagerImpl::_WifiManagerImpl(void) _WifiManagerImpl::~_WifiManagerImpl(void) { - if (__pWifiSystemAdapter != null) - { - __pWifiSystemAdapter->UnregisterManagerEventListener(*this); - } - - delete __pMonitoringEvt; + if (__pWifiSystemAdapter != null) + { + __pWifiSystemAdapter->UnregisterManagerEventListener(*this); + } } result _WifiManagerImpl::Construct(IWifiManagerEventListener& listener) { - result r = E_SUCCESS; - unique_ptr<_WifiSystemMonitoringEvent> pMonitoringEvt; + result r = E_SUCCESS; + unique_ptr<_WifiSystemMonitoringEvent> pMonitoringEvent; + unique_ptr<_WifiManagerEvent> pMgrEvent; SysAssertf(__pWifiSystemAdapter == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class."); - pMonitoringEvt.reset(new (std::nothrow) _WifiSystemMonitoringEvent()); - SysTryReturnResult(NID_NET_WIFI, pMonitoringEvt != null, E_OUT_OF_MEMORY, "Memory allocation failed."); - r = pMonitoringEvt->Construct(); - r = TransExceptionsExclusive(r, E_SYSTEM, E_OUT_OF_MEMORY); - SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Failed to construct the system monitoring event."); - r = __stateMutex.Create(); r = TransExceptionsExclusive(r, E_SYSTEM, E_OUT_OF_MEMORY); SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Failed to create mutex."); @@ -85,6 +81,27 @@ _WifiManagerImpl::Construct(IWifiManagerEventListener& listener) __pWifiSystemAdapter = _WifiSystemAdapter::GetInstance(); SysTryReturnResult(NID_NET_WIFI, __pWifiSystemAdapter != null, E_OUT_OF_MEMORY, "Failed to get Wi-Fi System adapter instance"); + pMonitoringEvent.reset(new (std::nothrow) _WifiSystemMonitoringEvent()); + SysTryReturnResult(NID_NET_WIFI, pMonitoringEvent != null, E_OUT_OF_MEMORY, "Memory allocation failed."); + r = pMonitoringEvent->Construct(); + r = TransExceptionsExclusive(r, E_SYSTEM, E_OUT_OF_MEMORY); + SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Failed to construct the system monitoring event."); + + pMgrEvent.reset(new (std::nothrow) _WifiManagerEvent()); + SysTryReturnResult(NID_NET_WIFI, pMgrEvent != null, E_OUT_OF_MEMORY, "The memory is insufficient."); + r = pMgrEvent->Construct(); + r = TransExceptionsExclusive(r, E_SYSTEM, E_OUT_OF_MEMORY); + SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, E_SYSTEM, "Failed to construct the event."); + + // add the IWifiManagerEventListener instance to a new created _WifiManagerEvent. + r = pMgrEvent->AddListener(listener, true); + SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, E_SYSTEM, + "Failed to add the application listener for WifiManager event"); + + __pWifiSystemAdapter->RegisterManagerEventListener(*this); + SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, E_SYSTEM, + "Failed to register the manager event listener to _WifiSystemAdapter."); + __stateMutex.Acquire(); if (__pWifiSystemAdapter->IsActivated()) @@ -102,9 +119,8 @@ _WifiManagerImpl::Construct(IWifiManagerEventListener& listener) __stateMutex.Release(); - __pManagerEvtListener = &listener; - __pMonitoringEvt = pMonitoringEvt.release(); - __pWifiSystemAdapter->RegisterManagerEventListener(*this); + __pMgrEvent = move(pMgrEvent); + __pMonitoringEvent = move(pMonitoringEvent); return r; } @@ -405,7 +421,7 @@ _WifiManagerImpl::AddSystemMonitoringEventListener(IWifiSystemMonitoringEventLis SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Propagating."); // add the specified new IWifiSystemMonitoringEventListener instance to the _WifiSystemMonitoringEvent. - r = __pMonitoringEvt->AddListener(listener, true); + r = __pMonitoringEvent->AddListener(listener, true); r = TransExceptionsExclusive(r, E_SYSTEM, E_OUT_OF_MEMORY, E_OBJ_ALREADY_EXIST); SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Failed to add the new listener."); @@ -427,7 +443,7 @@ _WifiManagerImpl::RemoveSystemMonitoringEventListener(IWifiSystemMonitoringEvent SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Propagating."); // remove the previous IWifiSystemMonitoringEventListener instance from the _WifiSystemMonitoringEvent. - r = __pMonitoringEvt->RemoveListener(listener); + r = __pMonitoringEvent->RemoveListener(listener); r = TransExceptionsExclusive(r, E_SYSTEM, E_OUT_OF_MEMORY, E_OBJ_NOT_FOUND); SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Failed to remove the previous listener."); @@ -507,7 +523,10 @@ _WifiManagerImpl::OnWifiActivated(result r) if (isFired) { - __pManagerEvtListener->OnWifiActivated(r); + _WifiManagerEventArg* pArg = new (std::nothrow) _WifiManagerEventArg(_WIFI_EVENT_ACTIVATED, r); + SysTryReturnVoidResult(NID_NET_WIFI, pArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + + __pMgrEvent->FireAsync(*pArg); } if ((isFired) && (IsFailed(r))) @@ -574,7 +593,10 @@ _WifiManagerImpl::OnWifiDeactivated(result r) if (isFired) { - __pManagerEvtListener->OnWifiDeactivated(r); + _WifiManagerEventArg* pArg = new (std::nothrow) _WifiManagerEventArg(_WIFI_EVENT_DEACTIVATED, r); + SysTryReturnVoidResult(NID_NET_WIFI, pArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + + __pMgrEvent->FireAsync(*pArg); } if ((isFired) && (IsFailed(r))) @@ -639,7 +661,10 @@ _WifiManagerImpl::OnWifiConnected(const Tizen::Base::String &ssid, result r) if (isFired) { - __pManagerEvtListener->OnWifiConnected(ssid, r); + _WifiManagerEventArg* pArg = new (std::nothrow) _WifiManagerEventArg(_WIFI_EVENT_CONNECTED, ssid, r); + SysTryReturnVoidResult(NID_NET_WIFI, pArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + + __pMgrEvent->FireAsync(*pArg); } if ((isFired) && (IsFailed(r))) @@ -684,11 +709,14 @@ _WifiManagerImpl::OnWifiDisconnected(void) } __stateMutex.Release(); - __wasConnected = false; + __wasConnected = false; if (isFired) { - __pManagerEvtListener->OnWifiDisconnected(); + _WifiManagerEventArg* pArg = new (std::nothrow) _WifiManagerEventArg(_WIFI_EVENT_DISCONNECTED); + SysTryReturnVoidResult(NID_NET_WIFI, pArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + + __pMgrEvent->FireAsync(*pArg); } SysLog(NID_NET_WIFI, "ExitPoint, [CurrentState:%s], [Scan State: %s], [DISCONNECTED_Event:%s]", @@ -700,20 +728,20 @@ _WifiManagerImpl::OnWifiRssiChanged(long rssi) { SysLog(NID_NET_WIFI, "Enter, [CurrentState:%s], [Scan State: %s]", GetStringOfCurrentState(), GetStringOfCurrentScanState()); + if (__currentState == WIFI_MANAGER_CONNECTED) { - SysLog(NID_NET_WIFI, "[CurrentState:%s], [RSSI_CHANGED_Event:Fired]", GetStringOfCurrentState()); - __pManagerEvtListener->OnWifiRssiChanged(rssi); - } - else - { - SysLog(NID_NET_WIFI, "[CurrentState:%s], [RSSI_CHANGED_Event:Not Fired]", GetStringOfCurrentState()); + _WifiManagerEventArg* pArg = new (std::nothrow) _WifiManagerEventArg(_WIFI_EVENT_RSSI_CHANGED, rssi); + SysTryReturnVoidResult(NID_NET_WIFI, pArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + + __pMgrEvent->FireAsync(*pArg); } } void -_WifiManagerImpl::OnWifiScanCompletedN(Tizen::Base::Collection::IList* pWifiBssInfoList, result r) +_WifiManagerImpl::OnWifiScanCompleted(Tizen::Base::Collection::IList* pWifiBssInfoList, result r) { + IList* pBssInfoList = null; bool isFired = false; SysLog(NID_NET_WIFI, "Enter, [CurrentState:%s], [Scan State: %s], [result:%s]", GetStringOfCurrentState(), GetStringOfCurrentScanState(), GetErrorMessage(r)); @@ -722,15 +750,19 @@ _WifiManagerImpl::OnWifiScanCompletedN(Tizen::Base::Collection::IList* pWifiBssI if (__currentScanState == WIFI_SCAN_SCANNING) { - isFired = true; - __currentScanState = WIFI_SCAN_IDLE; + isFired = true; + __currentScanState = WIFI_SCAN_IDLE; } __stateMutex.Release(); if (isFired == true) { - __pManagerEvtListener->OnWifiScanCompletedN(pWifiBssInfoList, r); + pBssInfoList = _WifiUtility::GetWifiBssInfoListCloneN(pWifiBssInfoList); + _WifiManagerEventArg* pArg = new (std::nothrow) _WifiManagerEventArg(_WIFI_EVENT_SCAN_COMPLETED, pBssInfoList, r); + SysTryReturnVoidResult(NID_NET_WIFI, pArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + + __pMgrEvent->FireAsync(*pArg); } SysLog(NID_NET_WIFI, "Exit, [CurrentState:%s], [Scan State: %s], [SCAN_COMPLETED_Event:%s]", @@ -746,7 +778,7 @@ _WifiManagerImpl::OnWifiConnectionStateChanged(WifiConnectionState state) _WifiSystemMonitoringEventArg* pArg = new (std::nothrow) _WifiSystemMonitoringEventArg(state); SysTryReturnVoidResult(NID_NET_WIFI, pArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); - __pMonitoringEvt->FireAsync(*pArg); + __pMonitoringEvent->FireAsync(*pArg); SysLog(NID_NET_WIFI, "Exit, [CurrentState:%s], [CONN_STATE_Event:Fired]", GetStringOfCurrentState()); } @@ -759,7 +791,7 @@ _WifiManagerImpl::OnWifiSystemScanResultUpdated(void) _WifiSystemMonitoringEventArg* pArg = new (std::nothrow) _WifiSystemMonitoringEventArg(); SysTryReturnVoidResult(NID_NET_WIFI, pArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); - __pMonitoringEvt->FireAsync(*pArg); + __pMonitoringEvent->FireAsync(*pArg); SysLog(NID_NET_WIFI, "Exit, [CurrentState:%s], [BACKSCAN_RESULT_Event:Fired]", GetStringOfCurrentState()); } diff --git a/src/wifi/FNetWifi_WifiSystemAdapter.cpp b/src/wifi/FNetWifi_WifiSystemAdapter.cpp index c50bd25..60fa709 100644 --- a/src/wifi/FNetWifi_WifiSystemAdapter.cpp +++ b/src/wifi/FNetWifi_WifiSystemAdapter.cpp @@ -25,8 +25,7 @@ #include #include #include "FNetWifi_WifiBssInfoImpl.h" -#include "FNetWifi_WifiManagerEvent.h" -#include "FNetWifi_WifiManagerEventArg.h" +#include "FNetWifi_IWifiManagerEventListener.h" #include "FNetWifi_WifiManagerImpl.h" #include "FNetWifi_WifiSystemAdapter.h" #include "FNetWifi_WifiSecurityInfoImpl.h" @@ -53,8 +52,8 @@ namespace Tizen { namespace Net { namespace Wifi { static _WifiSystemAdapter* pInstance = null; _WifiSystemAdapter::_WifiSystemAdapter(void) - : __pWifiManagerEvent() - , __pBssInfo(null) + : __mgrEvtListenerList() + , __pBssInfo(null) { } @@ -68,6 +67,7 @@ _WifiSystemAdapter::~_WifiSystemAdapter(void) wifi_unset_background_scan_cb(); err = wifi_deinitialize(); + if (err != WIFI_ERROR_NONE) { SysLogException(NID_NET_WIFI, E_SYSTEM, "[E_SYSTEM] Failed to de-initialize the wifi manager [0x%08X]", err); @@ -79,27 +79,21 @@ _WifiSystemAdapter::~_WifiSystemAdapter(void) result _WifiSystemAdapter::Construct(void) { - __pWifiManagerEvent.reset(new (std::nothrow) _WifiManagerEvent()); - SysTryReturnResult(NID_NET_WIFI, __pWifiManagerEvent != null, E_OUT_OF_MEMORY, "Memory allocation failed."); - - result r = __pWifiManagerEvent->Construct(); - SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Failed to construct event"); - int err = WIFI_ERROR_NONE; err = wifi_initialize(); SysTryReturnResult(NID_NET_WIFI, err == WIFI_ERROR_NONE, E_SYSTEM, "Failed to wifi_initialize()"); - err = wifi_set_device_state_changed_cb(OnWifiDeviceStateChanged, __pWifiManagerEvent.get()); + err = wifi_set_device_state_changed_cb(OnWifiDeviceStateChanged, null); SysTryReturnResult(NID_NET_WIFI, err == WIFI_ERROR_NONE, E_SYSTEM, "Failed to wifi_set_device_state_changed_cb()"); - err = wifi_set_connection_state_changed_cb(OnWifiConnectionStateChanged, __pWifiManagerEvent.get()); + err = wifi_set_connection_state_changed_cb(OnWifiConnectionStateChanged, null); SysTryReturnResult(NID_NET_WIFI, err == WIFI_ERROR_NONE, E_SYSTEM, "Failed to wifi_set_connection_state_changed_cb()"); - err = wifi_set_rssi_level_changed_cb(OnWifiRssiLevelChanged, __pWifiManagerEvent.get()); + err = wifi_set_rssi_level_changed_cb(OnWifiRssiLevelChanged, null); SysTryReturnResult(NID_NET_WIFI, err == WIFI_ERROR_NONE, E_SYSTEM, "Failed to wifi_set_rssi_level_changed_cb()"); - err = wifi_set_background_scan_cb(OnWifiBackgroundScanResultUpdated, __pWifiManagerEvent.get()); + err = wifi_set_background_scan_cb(OnWifiBackgroundScanResultUpdated, null); SysTryReturnResult(NID_NET_WIFI, err == WIFI_ERROR_NONE, E_SYSTEM, "Failed to wifi_set_background_scan_cb()"); return E_SUCCESS; @@ -150,13 +144,13 @@ _WifiSystemAdapter::GetInstance(void) result _WifiSystemAdapter::RegisterManagerEventListener(_IWifiManagerEventListener& listener) { - return __pWifiManagerEvent->AddListener(listener, true); + return __mgrEvtListenerList.Add(&listener); } result -_WifiSystemAdapter::UnregisterManagerEventListener(const _IWifiManagerEventListener& listener) +_WifiSystemAdapter::UnregisterManagerEventListener(_IWifiManagerEventListener& listener) { - return __pWifiManagerEvent->RemoveListener(listener); + return __mgrEvtListenerList.Remove(&listener); } result @@ -165,7 +159,7 @@ _WifiSystemAdapter::Activate(void) result r = E_SYSTEM; int err = WIFI_ERROR_NONE; - err = wifi_activate(OnWifiActivated, __pWifiManagerEvent.get()); + err = wifi_activate(OnWifiActivated, null); _WifiConvertErrorResult(err == WIFI_ERROR_OPERATION_FAILED, r, E_FAILURE); _WifiConvertErrorResult(err == WIFI_ERROR_INVALID_OPERATION, r, E_INVALID_OPERATION); _WifiConvertErrorResult(err == WIFI_ERROR_NONE, r, E_SUCCESS); @@ -180,7 +174,7 @@ _WifiSystemAdapter::Deactivate(void) result r = E_SYSTEM; int err = WIFI_ERROR_NONE; - err = wifi_deactivate(OnWifiDeactivated, __pWifiManagerEvent.get()); + err = wifi_deactivate(OnWifiDeactivated, null); _WifiConvertErrorResult(err == WIFI_ERROR_OPERATION_FAILED, r, E_FAILURE); _WifiConvertErrorResult(err == WIFI_ERROR_INVALID_OPERATION, r, E_INVALID_OPERATION); _WifiConvertErrorResult(err == WIFI_ERROR_NONE, r, E_SUCCESS); @@ -232,7 +226,7 @@ _WifiSystemAdapter::Scan(void) result r = E_FAILURE; int err = WIFI_ERROR_NONE; - err = wifi_scan(OnWifiScanCompleted, __pWifiManagerEvent.get()); + err = wifi_scan(OnWifiScanCompleted, null); _WifiConvertErrorResult(err == WIFI_ERROR_NONE, r, E_SUCCESS); SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Failed to scan for a nearby BSS. [0x%08X]", err); @@ -262,6 +256,7 @@ _WifiSystemAdapter::GetConnectionTargetInfoN(void) const SysTryReturn(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] Failed to get the connected AP handle."); pBssInfo = _WifiUtility::CreateWifiBssInfoInstanceN(pApHandle); + (void)wifi_ap_destroy(pApHandle); SysTryReturn(NID_NET_WIFI, pBssInfo != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); return pBssInfo; @@ -283,157 +278,204 @@ _WifiSystemAdapter::GetSystemScanResultN(void) const void _WifiSystemAdapter::OnWifiDeviceStateChanged(wifi_device_state_e state, void* pUserData) { - _WifiManagerEvent* pEvent = static_cast<_WifiManagerEvent*>(pUserData); - SysTryReturnVoidResult(NID_NET_WIFI, pEvent != null, E_SYSTEM, "[E_SYSTEM] _WifiManagerEvent is invalid."); - - _WifiManagerEventArg* pEventArg = null; result r = E_SUCCESS; + _IWifiManagerEventListener* pMgrEvtListener = null; + IEnumeratorT<_IWifiManagerEventListener*>* pEnum = null; + _WifiSystemAdapter* pAdapter = _WifiSystemAdapter::GetInstance(); + pEnum = pAdapter->__mgrEvtListenerList.GetEnumeratorN(); - switch (state) + while (pEnum->MoveNext() == E_SUCCESS) { - case WIFI_DEVICE_STATE_DEACTIVATED: - pEventArg = new (std::nothrow) _WifiManagerEventArg(_WIFI_EVENT_DEACTIVATED, r); - SysTryReturnVoidResult(NID_NET_WIFI, pEventArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); - - SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_DEACTIVATED],[result:%s]", GetErrorMessage(r)); - pEvent->Fire(*pEventArg); - break; - case WIFI_DEVICE_STATE_ACTIVATED: - pEventArg = new (std::nothrow) _WifiManagerEventArg(_WIFI_EVENT_ACTIVATED, r); - SysTryReturnVoidResult(NID_NET_WIFI, pEventArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + pEnum->GetCurrent(pMgrEvtListener); - SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_ACTIVATED],[result:%s]", GetErrorMessage(r)); - pEvent->Fire(*pEventArg); - break; + if(state == WIFI_DEVICE_STATE_ACTIVATED) + { + SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_ACTIVATED],[result:%s]", GetErrorMessage(r)); + pMgrEvtListener->OnWifiActivated(r); + } + else + { + SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_DEACTIVATED],[result:%s]", GetErrorMessage(r)); + pMgrEvtListener->OnWifiDeactivated(r); + } } + + delete pEnum; } void _WifiSystemAdapter::OnWifiActivated(wifi_error_e errorCode, void* pUserData) { result r = E_FAILURE; - int err = WIFI_ERROR_NONE; - _WifiManagerEvent* pEvent = static_cast<_WifiManagerEvent*>(pUserData); - SysTryReturnVoidResult(NID_NET_WIFI, pEvent != null, E_SYSTEM, "[E_SYSTEM] _WifiManagerEvent is invalid."); + _WifiConvertErrorResult(errorCode == WIFI_ERROR_NONE, r, E_SUCCESS); - _WifiManagerEventArg* pEventArg = null; - _WifiConvertErrorResult(err == WIFI_ERROR_NONE, r, E_SUCCESS); + _IWifiManagerEventListener* pMgrEvtListener = null; + IEnumeratorT<_IWifiManagerEventListener*>* pEnum = null; + _WifiSystemAdapter* pAdapter = _WifiSystemAdapter::GetInstance(); + pEnum = pAdapter->__mgrEvtListenerList.GetEnumeratorN(); - pEventArg = new (std::nothrow) _WifiManagerEventArg(_WIFI_EVENT_ACTIVATED, r); - SysTryReturnVoidResult(NID_NET_WIFI, pEventArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + while (pEnum->MoveNext() == E_SUCCESS) + { + pEnum->GetCurrent(pMgrEvtListener); - SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_ACTIVATED],[result:%s]", GetErrorMessage(r)); - pEvent->Fire(*pEventArg); + SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_ACTIVATED],[result:%s]", GetErrorMessage(r)); + pMgrEvtListener->OnWifiActivated(r); + } + + delete pEnum; } void _WifiSystemAdapter::OnWifiDeactivated(wifi_error_e errorCode, void* pUserData) { result r = E_FAILURE; - int err = WIFI_ERROR_NONE; - _WifiManagerEvent* pEvent = static_cast<_WifiManagerEvent*>(pUserData); - SysTryReturnVoidResult(NID_NET_WIFI, pEvent != null, E_SYSTEM, "[E_SYSTEM] _WifiManagerEvent is invalid."); + _WifiConvertErrorResult(errorCode == WIFI_ERROR_NONE, r, E_SUCCESS); - _WifiManagerEventArg* pEventArg = null; - _WifiConvertErrorResult(err == WIFI_ERROR_NONE, r, E_SUCCESS); + _IWifiManagerEventListener* pMgrEvtListener = null; + IEnumeratorT<_IWifiManagerEventListener*>* pEnum = null; + _WifiSystemAdapter* pAdapter = _WifiSystemAdapter::GetInstance(); + pEnum = pAdapter->__mgrEvtListenerList.GetEnumeratorN(); + + while (pEnum->MoveNext() == E_SUCCESS) + { + pEnum->GetCurrent(pMgrEvtListener); - pEventArg = new (std::nothrow) _WifiManagerEventArg(_WIFI_EVENT_DEACTIVATED, r); - SysTryReturnVoidResult(NID_NET_WIFI, pEventArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_DEACTIVATED],[result:%s]", GetErrorMessage(r)); + pMgrEvtListener->OnWifiDeactivated(r); + } - SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_DEACTIVATED],[result:%s]", GetErrorMessage(r)); - pEvent->Fire(*pEventArg); + delete pEnum; } void _WifiSystemAdapter::OnWifiConnected(wifi_error_e errorCode, void* pUserData) { - _WifiManagerEvent* pEvent = static_cast<_WifiManagerEvent*>(pUserData); - SysTryReturnVoidResult(NID_NET_WIFI, pEvent != null, E_SYSTEM, "[E_SYSTEM] _WifiManagerEvent is invalid."); - - _WifiManagerEventArg* pEventArg = null; result r = E_SUCCESS; - char* pEssid = null; _WifiConvertErrorResult(errorCode != WIFI_ERROR_NONE, r, E_FAILURE); _WifiConvertErrorResult(errorCode == WIFI_ERROR_INVALID_KEY, r, E_AUTHENTICATION); _WifiConvertErrorResult(errorCode == WIFI_ERROR_NO_REPLY, r, E_NOT_RESPONDING); _WifiConvertErrorResult(errorCode == WIFI_ERROR_DHCP_FAILED, r, E_DHCP); - if(r == E_SUCCESS) - { - wifi_ap_h apHandler; - int err = wifi_get_connected_ap(&apHandler); - _WifiConvertErrorResult(errorCode != WIFI_ERROR_NONE, r, E_FAILURE); - _WifiConvertErrorResult(err == WIFI_ERROR_OUT_OF_MEMORY, r, E_OUT_OF_MEMORY); + _IWifiManagerEventListener* pMgrEvtListener = null; + IEnumeratorT<_IWifiManagerEventListener*>* pEnum = null; + _WifiSystemAdapter* pAdapter = _WifiSystemAdapter::GetInstance(); + pEnum = pAdapter->__mgrEvtListenerList.GetEnumeratorN(); - wifi_ap_get_essid(apHandler, &pEssid); - String ssid(pEssid); - free(pEssid); - pEventArg = new (std::nothrow) _WifiManagerEventArg(_WIFI_EVENT_CONNECTED, ssid, r); - SysTryReturnVoidResult(NID_NET_WIFI, pEventArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); - } - else + while (pEnum->MoveNext() == E_SUCCESS) { - String ssid(L""); - pEventArg = new (std::nothrow) _WifiManagerEventArg(_WIFI_EVENT_CONNECTED, ssid, r); - SysTryReturnVoidResult(NID_NET_WIFI, pEventArg, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + pEnum->GetCurrent(pMgrEvtListener); + + if(r == E_SUCCESS) + { + char* pEssid = null; + wifi_ap_h apHandler; + int err = wifi_get_connected_ap(&apHandler); + _WifiConvertErrorResult(errorCode != WIFI_ERROR_NONE, r, E_FAILURE); + _WifiConvertErrorResult(err == WIFI_ERROR_OUT_OF_MEMORY, r, E_OUT_OF_MEMORY); + + wifi_ap_get_essid(apHandler, &pEssid); + String ssid(pEssid); + free(pEssid); + + (void)wifi_ap_destroy(apHandler); + + SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_CONNECTED],[result:%s]", GetErrorMessage(r)); + pMgrEvtListener->OnWifiConnected(ssid, r); + } + else + { + String ssid(L""); + + SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_CONNECTED],[result:%s]", GetErrorMessage(r)); + pMgrEvtListener->OnWifiConnected(ssid, r); + } } - pEvent->Fire(*pEventArg); + + delete pEnum; } void _WifiSystemAdapter::OnWifiConnectionStateChanged(wifi_connection_state_e state, wifi_ap_h apHandler, void *pUserData) { - _WifiManagerEvent* pEvent = static_cast<_WifiManagerEvent*>(pUserData); - SysTryReturnVoidResult(NID_NET_WIFI, pEvent != null, E_SYSTEM, "[E_SYSTEM] _WifiManagerEvent is invalid."); - - _WifiManagerEventArg* pEventArg = null; - char* pEssid = null; - + _IWifiManagerEventListener* pMgrEvtListener = null; + IEnumeratorT<_IWifiManagerEventListener*>* pEnum = null; + _WifiSystemAdapter* pAdapter = _WifiSystemAdapter::GetInstance(); + pEnum = pAdapter->__mgrEvtListenerList.GetEnumeratorN(); + switch(state) { case WIFI_CONNECTION_STATE_CONNECTED: - // Fire a CONNECTED event for notifying that the connection is established not by this system adapter. - wifi_ap_get_essid(apHandler, &pEssid); - pEventArg = new (std::nothrow) _WifiManagerEventArg(_WIFI_EVENT_CONNECTED, String(pEssid), E_SUCCESS); - free(pEssid); - SysTryReturnVoidResult(NID_NET_WIFI, pEventArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); - pEvent->FireAsync(*pEventArg); - - // Fire a CONNECTION_CHANGED event for notifying that the connection state is changed to 'CONNECTED' state. - // This seems a little redundant but the purpose of it is quite different from CONNECTED event. - pEventArg = new (std::nothrow) _WifiManagerEventArg(_WIFI_EVENT_CONNECTION_CHNAGED, WIFI_CONN_STATE_CONNECTED); - SysTryReturnVoidResult(NID_NET_WIFI, pEventArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); - pEvent->FireAsync(*pEventArg); + { + char* pEssid = null; + wifi_ap_get_essid(apHandler, &pEssid); + String ssid(pEssid); + free(pEssid); + + while (pEnum->MoveNext() == E_SUCCESS) + { + pEnum->GetCurrent(pMgrEvtListener); + + // Fire a CONNECTED event for notifying that the connection is established not by this system adapter. + SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_CONNECTED],[result:E_SUCCESS]"); + pMgrEvtListener->OnWifiConnected(ssid, E_SUCCESS); + + // Fire a CONNECTION_CHANGED event for notifying that the connection state is changed to 'CONNECTED' state. + // This seems a little redundant but the purpose of it is quite different from CONNECTED event. + SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_CONNECTION_STATE_CHANGED],[State:WIFI_CONNECTION_STATE_CONNECTED]"); + pMgrEvtListener->OnWifiConnectionStateChanged(WIFI_CONN_STATE_CONNECTED); + } + } break; case WIFI_CONNECTION_STATE_DISCONNECTED: - // Fire a DISCONNECTED event for notifying that the connection is broken off not by this system adapter. - pEventArg = new (std::nothrow) _WifiManagerEventArg(_WIFI_EVENT_DISCONNECTED); - SysTryReturnVoidResult(NID_NET_WIFI, pEventArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); - SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_DISCONNECTED]"); - pEvent->Fire(*pEventArg); - - // Fire a CONNECTION_CHANGED event for notifying that the connection state is changed to "IDLE' state. - // This seems a little redundant but the purpose of it is quite different from DISCONNECTED event. - pEventArg = new (std::nothrow) _WifiManagerEventArg(_WIFI_EVENT_CONNECTION_CHNAGED, WIFI_CONN_STATE_NOT_CONNECTED); - SysTryReturnVoidResult(NID_NET_WIFI, pEventArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); - pEvent->FireAsync(*pEventArg); + { + while (pEnum->MoveNext() == E_SUCCESS) + { + pEnum->GetCurrent(pMgrEvtListener); + + // Fire a DISCONNECTED event for notifying that the connection is broken off not by this system adapter. + SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_DISCONNECTED]"); + pMgrEvtListener->OnWifiDisconnected(); + + // Fire a CONNECTION_CHANGED event for notifying that the connection state is changed to "IDLE' state. + // This seems a little redundant but the purpose of it is quite different from DISCONNECTED event. + SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_CONNECTION_STATE_CHANGED],[State:WIFI_CONN_STATE_NOT_CONNECTED]"); + pMgrEvtListener->OnWifiConnectionStateChanged(WIFI_CONN_STATE_NOT_CONNECTED); + } + } break; case WIFI_CONNECTION_STATE_ASSOCIATION: - // Fire a CONNECTION_CHANGED event for notifying that the connection state is changed to "ASSOCIATING" state. - pEventArg = new (std::nothrow) _WifiManagerEventArg(_WIFI_EVENT_CONNECTION_CHNAGED, WIFI_CONN_STATE_ASSOCIATING); - SysTryReturnVoidResult(NID_NET_WIFI, pEventArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); - pEvent->FireAsync(*pEventArg); + { + while (pEnum->MoveNext() == E_SUCCESS) + { + pEnum->GetCurrent(pMgrEvtListener); + + // Fire a CONNECTION_CHANGED event for notifying that the connection state is changed to "ASSOCIATING" state. + SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_CONNECTION_STATE_CHANGED],[State:WIFI_CONN_STATE_ASSOCIATING]"); + pMgrEvtListener->OnWifiConnectionStateChanged(WIFI_CONN_STATE_ASSOCIATING); + } + } break; case WIFI_CONNECTION_STATE_CONFIGURATION: - // Fire a CONNECTION_CHANGED event for notifying that the connection state is changed to "CONFIGURING" state. - pEventArg = new (std::nothrow) _WifiManagerEventArg(_WIFI_EVENT_CONNECTION_CHNAGED, WIFI_CONN_STATE_CONFIGURING); - SysTryReturnVoidResult(NID_NET_WIFI, pEventArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); - pEvent->FireAsync(*pEventArg); + { + while (pEnum->MoveNext() == E_SUCCESS) + { + pEnum->GetCurrent(pMgrEvtListener); + + // Fire a CONNECTION_CHANGED event for notifying that the connection state is changed to "CONFIGURING" state. + SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_CONNECTION_STATE_CHANGED],[State:WIFI_CONN_STATE_CONFIGURING]"); + pMgrEvtListener->OnWifiConnectionStateChanged(WIFI_CONN_STATE_CONFIGURING); + } + } + break; + + default: break; - } + } + + delete pEnum; } bool @@ -489,38 +531,51 @@ _WifiSystemAdapter::OnWifiEachAccessPointChecked(wifi_ap_h pApHandle, void* pUse void _WifiSystemAdapter::OnWifiScanCompleted(wifi_error_e errorCode, void *pUserData) { - _WifiManagerEventArg* pEventArg = null; LinkedList* pBssInfoList = null; result r = E_FAILURE; _WifiConvertErrorResult(errorCode == WIFI_ERROR_NONE, r, E_SUCCESS); - _WifiManagerEvent* pEvent = static_cast<_WifiManagerEvent*>(pUserData); - SysTryReturnVoidResult(NID_NET_WIFI, pEvent != null, E_FAILURE, "[E_FAILURE] _WifiManagerEventArg is invalid."); - pBssInfoList = new (std::nothrow) LinkedList(SingleObjectDeleter); SysTryReturnVoidResult(NID_NET_WIFI, pBssInfoList != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); wifi_foreach_found_aps(OnWifiEachAccessPointFound, pBssInfoList); - pEventArg = new (std::nothrow) _WifiManagerEventArg(_WIFI_EVENT_SCAN_COMPLETED, pBssInfoList, r); - SysTryReturnVoidResult(NID_NET_WIFI, pEventArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); - pEvent->Fire(*pEventArg); + _IWifiManagerEventListener* pMgrEvtListener = null; + IEnumeratorT<_IWifiManagerEventListener*>* pEnum = null; + _WifiSystemAdapter* pAdapter = _WifiSystemAdapter::GetInstance(); + pEnum = pAdapter->__mgrEvtListenerList.GetEnumeratorN(); + + while (pEnum->MoveNext() == E_SUCCESS) + { + pEnum->GetCurrent(pMgrEvtListener); + + SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_SCAN_COMPLETED],[result:%s]", GetErrorMessage(r)); + pMgrEvtListener->OnWifiScanCompleted(pBssInfoList, r); + } + + delete pBssInfoList; + delete pEnum; } void _WifiSystemAdapter::OnWifiBackgroundScanResultUpdated(wifi_error_e errorCode, void* pUserData) { - _WifiManagerEvent* pEvent = null; - _WifiManagerEventArg* pEventArg = null; - if (errorCode == WIFI_ERROR_NONE) { - pEvent = static_cast<_WifiManagerEvent*>(pUserData); + _IWifiManagerEventListener* pMgrEvtListener = null; + IEnumeratorT<_IWifiManagerEventListener*>* pEnum = null; + _WifiSystemAdapter* pAdapter = _WifiSystemAdapter::GetInstance(); + pEnum = pAdapter->__mgrEvtListenerList.GetEnumeratorN(); - pEventArg = new (std::nothrow) _WifiManagerEventArg(_WIFI_EVENT_SCAN_UPDATED); - SysTryReturnVoidResult(NID_NET_WIFI, pEventArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + while (pEnum->MoveNext() == E_SUCCESS) + { + pEnum->GetCurrent(pMgrEvtListener); + + SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_SCAN_COMPLETED]"); + pMgrEvtListener->OnWifiSystemScanResultUpdated(); + } - pEvent->Fire(*pEventArg); + delete pEnum; } } @@ -638,7 +693,7 @@ _WifiSystemAdapter::Connect(const WifiBssInfo& targetApInfo) SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Failed to set eap authentication type."); } - err = wifi_connect(ap, OnWifiConnected, pInstance->__pWifiManagerEvent.get()); + err = wifi_connect(ap, OnWifiConnected, NULL); _WifiConvertErrorResult(err != WIFI_ERROR_NONE, r, E_FAILURE); return E_SUCCESS; } @@ -646,15 +701,21 @@ _WifiSystemAdapter::Connect(const WifiBssInfo& targetApInfo) void _WifiSystemAdapter::OnWifiRssiLevelChanged(wifi_rssi_level_e rssiLevel, void *pUserData) { - _WifiManagerEventArg* pEventArg = null; - _WifiManagerEvent* pEvent = static_cast<_WifiManagerEvent*>(pUserData); - SysTryReturnVoidResult(NID_NET_WIFI, pEvent != null, E_SYSTEM, "[E_SYSTEM] _WifiManagerEventArg is invalid."); - - pEventArg = new (std::nothrow) _WifiManagerEventArg(_WIFI_EVENT_RSSI_CHANGED, - _WifiUtility::ConvertLeveltoRssiValue(rssiLevel)); - SysTryReturnVoidResult(NID_NET_WIFI, pEventArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + long rssi = _WifiUtility::ConvertLeveltoRssiValue(rssiLevel); + _IWifiManagerEventListener* pMgrEvtListener = null; + IEnumeratorT<_IWifiManagerEventListener*>* pEnum = null; + _WifiSystemAdapter* pAdapter = _WifiSystemAdapter::GetInstance(); + pEnum = pAdapter->__mgrEvtListenerList.GetEnumeratorN(); + + while (pEnum->MoveNext() == E_SUCCESS) + { + pEnum->GetCurrent(pMgrEvtListener); + + SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_RSSI_LEVEL_CHANGED]"); + pMgrEvtListener->OnWifiRssiChanged(rssi); + } - pEvent->Fire(*pEventArg); + delete pEnum; } } } } // Tizen::Net::Wifi diff --git a/src/wifi/FNetWifi_WifiUtility.cpp b/src/wifi/FNetWifi_WifiUtility.cpp index 59902f6..b8e22b6 100644 --- a/src/wifi/FNetWifi_WifiUtility.cpp +++ b/src/wifi/FNetWifi_WifiUtility.cpp @@ -21,6 +21,8 @@ */ #include +#include +#include #include #include #include @@ -34,6 +36,7 @@ using namespace std; using namespace Tizen::Base; +using namespace Tizen::Base::Collection; using namespace Tizen::Net; namespace Tizen { namespace Net { namespace Wifi { @@ -734,6 +737,38 @@ _WifiUtility::CheckAddressEquality(Tizen::Net::IpAddress* pFirstAddress, Tizen:: return pFirstAddress->Equals(*pSecondAddress); } +Tizen::Base::Collection::IList* +_WifiUtility::GetWifiBssInfoListCloneN(const Tizen::Base::Collection::IList* pSrcList) +{ + result r = E_SUCCESS; + unique_ptr pDescList; + int count = 0; + + SysTryReturn(NID_NET_WIFI, pSrcList != null, null, E_FAILURE, "[E_FAILURE] Failed to get the BSS info list."); + + count = pSrcList->GetCount(); + + pDescList.reset(new (std::nothrow) ArrayList(SingleObjectDeleter)); + SysTryReturn(NID_NET_WIFI, pDescList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + + r = pDescList->Construct(count); + r = TransExceptionsExclusive(r, E_FAILURE, E_OUT_OF_MEMORY); + SysTryReturn(NID_NET_WIFI, r == E_SUCCESS, null, r, "[%s] Failed to construct a new BSS info list.", GetErrorMessage(r)); + for (int i = 0; i < count; i++) + { + const WifiBssInfo* pSrcBssInfo = dynamic_cast(pSrcList->GetAt(i)); + SysTryReturn(NID_NET_WIFI, pSrcBssInfo != null, null, E_FAILURE, "[E_FAILURE] Failed to get the BSS Info for the list."); + + WifiBssInfo* pDescBssInfo = new (std::nothrow) WifiBssInfo(*pSrcBssInfo); + SysTryReturn(NID_NET_WIFI, pDescBssInfo != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + + r = pDescList->Add(*pDescBssInfo); + r = TransExceptionsExclusive(r, E_FAILURE, E_OUT_OF_MEMORY); + SysTryReturn(NID_NET_WIFI, r == E_SUCCESS, null, r, "[%s] Failed to add a new BSS info to the list.", GetErrorMessage(r)); + } + + return pDescList.release(); +} } } } // Tizen::Net::Wifi