diff options
-rw-r--r-- | src/FLoc_LocationManager.cpp | 47 | ||||
-rw-r--r-- | src/FLoc_LocationManager.h | 8 |
2 files changed, 49 insertions, 6 deletions
diff --git a/src/FLoc_LocationManager.cpp b/src/FLoc_LocationManager.cpp index 394590e..634c950 100644 --- a/src/FLoc_LocationManager.cpp +++ b/src/FLoc_LocationManager.cpp @@ -66,11 +66,13 @@ _LocationManager::_LocationManager(void) , __pLocRequestInfoList(null) , __pSyncLocRequestInfoList(null) , __pLocUpdateTimer(null) + , __pInitMonitor(null) { } _LocationManager::~_LocationManager(void) { + delete __pInitMonitor; } result @@ -684,7 +686,17 @@ _LocationManager::Reset(void) result _LocationManager::Construct() { - return EventDrivenThread::Construct(); + result r = EventDrivenThread::Construct(); + SysTryReturnResult(NID_LOC, r == E_SUCCESS, r, "[%s] Failed to Construct", GetErrorMessage(r)); + + std::unique_ptr< Monitor > pMonitor(new (std::nothrow) Monitor()); + SysTryReturnResult(NID_LOC, pMonitor, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); + r = pMonitor->Construct(); + SysTryReturnResult(NID_LOC, r == E_SUCCESS, r, "[%s] Failed to Construct Monitor. Propagating.", GetErrorMessage(r)); + + __pInitMonitor = pMonitor.release(); + + return E_SUCCESS; } Location @@ -977,6 +989,8 @@ _LocationManager::GetLocation(location_method_e nativeLocMethod) bool _LocationManager::OnStart(void) { + SysTryReturn(NID_LOC, __pInitMonitor, false, E_INVALID_STATE, "[E_INVALID_STATE] __pInitMonitor must not be null."); + int res = -1; std::unique_ptr< Tizen::Base::Collection::ArrayList, AllElementsDeleter > pLocInfoRequestList(new (std::nothrow) ArrayList()); @@ -1014,7 +1028,13 @@ _LocationManager::OnStart(void) __gpsHandler.pLocation= std::move(pGpsLocation); __wpsHandler.pLocation= std::move(pWpsLocation); - __waitLoopListener.SetValue(true); + r = __pInitMonitor->Enter(); + SysTryCatch(NID_LOC, r == E_SUCCESS, , r, "[%s] Failed to Enter Monitor. Propagating.", GetErrorMessage(r)); + r = __pInitMonitor->Notify(); + SysTryCatch(NID_LOC, r == E_SUCCESS, , r, "[%s] Failed to Notify Monitor. Propagating.", GetErrorMessage(r)); + r = __pInitMonitor->Exit(); + SysTryCatch(NID_LOC, r == E_SUCCESS, , r, "[%s] Failed to Exit Monitor. Propagating.", GetErrorMessage(r)); + SysLog(NID_LOC, "All the resources for location manager successfully created."); return true; @@ -1034,7 +1054,8 @@ CATCH: void _LocationManager::OnStop(void) { - __waitLoopListener.SetValue(false); + delete __pInitMonitor; + __pInitMonitor = null; if (__gpsHandler.handle) { @@ -1308,11 +1329,13 @@ _LocationManager::InitLocationManager(void) unique_ptr< _LocationManager > pLocMgr(new (std::nothrow) _LocationManager()); SysTryReturnVoidResult(NID_LOC, pLocMgr, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); result r = pLocMgr->Construct(); - SysTryReturnVoidResult(NID_LOC, r == E_SUCCESS, r, "[%s] Falied to construct the Location Manager. Propagating.", GetErrorMessage(r)); + SysTryReturnVoidResult(NID_LOC, r == E_SUCCESS, r, "[%s] Failed to construct the Location Manager. Propagating.", GetErrorMessage(r)); + r = pLocMgr->Start(); - SysTryReturnVoidResult(NID_LOC, r == E_SUCCESS, r, "[%s] Falied to start the Location Manager. Propagating.", GetErrorMessage(r)); + SysTryReturnVoidResult(NID_LOC, r == E_SUCCESS, r, "[%s] Failed to start the Location Manager. Propagating.", GetErrorMessage(r)); - WaitingLoop::GetInstance()->Wait(*pLocMgr->GetWaitLoopListener()); + r = pLocMgr->WaitThreadStart(); + SysTryReturnVoidResult(NID_LOC, r == E_SUCCESS, r, "[%s] Failed to WaitThreadStart. Propagating.", GetErrorMessage(r)); __pUniqueInstance = pLocMgr.release(); std::atexit(DestroyLocationManager); @@ -1324,4 +1347,16 @@ _LocationManager::DestroyLocationManager(void) delete __pUniqueInstance; } +result +_LocationManager::WaitThreadStart() +{ + result r = __pInitMonitor->Enter(); + SysTryReturnResult(NID_LOC, r == E_SUCCESS, r, "[%s] Failed to Enter Monitor. Propagating.", GetErrorMessage(r)); + r = __pInitMonitor->Wait(); + SysTryReturnResult(NID_LOC, r == E_SUCCESS, r, "[%s] Failed to Wait Monitor. Propagating.", GetErrorMessage(r)); + r = __pInitMonitor->Exit(); + SysTryReturnResult(NID_LOC, r == E_SUCCESS, r, "[%s] Failed to Exit Monitor. Propagating.", GetErrorMessage(r)); + + return E_SUCCESS; +} }} diff --git a/src/FLoc_LocationManager.h b/src/FLoc_LocationManager.h index af29cea..5723199 100644 --- a/src/FLoc_LocationManager.h +++ b/src/FLoc_LocationManager.h @@ -179,10 +179,17 @@ private: // void Reset(void); + // The method is wait for OnStart method. + // + // @since 2.0 + // + result WaitThreadStart(); + // The method calls the construct method of the event driven thread. // // @since 2.0 // + result Construct(void); // This method is gets the last known location from Native side for the given method. @@ -326,6 +333,7 @@ private: std::unique_ptr< Tizen::Base::Runtime::Timer > __pLocUpdateTimer; static _LocationManager* __pUniqueInstance; _WaitLoopListener __waitLoopListener; + Tizen::Base::Runtime::Monitor* __pInitMonitor; friend class std::default_delete< _LocationManager >; }; // class _LocationManager |