change waiting loop to monitor tizen_2.1 accepted/tizen/20130520.101529 submit/tizen/20130517.045536 submit/tizen_2.1/20130514.054212
authorchanil.byun <chanil.byun@samsung.com>
Thu, 25 Apr 2013 09:11:41 +0000 (18:11 +0900)
committerchanil.byun <chanil.byun@samsung.com>
Thu, 25 Apr 2013 12:30:20 +0000 (21:30 +0900)
Change-Id: I81ead12bd6e99ba624d45f0f51f0dc5054ea6a59
Signed-off-by: chanil.byun <chanil.byun@samsung.com>
src/FLoc_LocationManager.cpp
src/FLoc_LocationManager.h

index 394590e..634c950 100644 (file)
@@ -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;
+}
 }}
index af29cea..5723199 100644 (file)
@@ -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