Wait before returning the instance till the Location manager initialization is complete
authorNandan SR <nandan.sr@samsung.com>
Thu, 4 Apr 2013 10:43:12 +0000 (16:13 +0530)
committerNandan SR <nandan.sr@samsung.com>
Fri, 5 Apr 2013 03:42:58 +0000 (09:12 +0530)
Change-Id: Iec005a6c1c5db96f65e141fa9312d184f64a75d3
Signed-off-by: Nandan SR <nandan.sr@samsung.com>
src/FLoc_LocationManager.cpp
src/FLoc_LocationManager.h
src/FLoc_WaitLoopListener.h [new file with mode: 0644]

index 9afa9ac..37a7b7f 100644 (file)
@@ -66,7 +66,6 @@ _LocationManager::_LocationManager(void)
        , __pLocRequestInfoList(null)
        , __pSyncLocRequestInfoList(null)
        , __pLocUpdateTimer(null)
-       , __initialized(false)
 {
 }
 
@@ -268,7 +267,7 @@ _LocationManager::GetAccuracyLevel(double horAcc) const
 bool
 _LocationManager::IsAppEnabled(void)
 {
-       SysTryReturn(NID_LOC, __initialized, false, E_SYSTEM, "[%s] Location manager is not initialized.", GetErrorMessage(E_SYSTEM));
+       SysTryReturn(NID_LOC, __waitLoopListener.GetValue(), false, E_SYSTEM, "[%s] Location manager is not initialized.", GetErrorMessage(E_SYSTEM));
 
        Boolean enable(false);
        Monitor synchronizer;
@@ -1059,7 +1058,7 @@ _LocationManager::OnStart(void)
        __gpsHandler.pLocation= std::move(pGpsLocation);
        __wpsHandler.pLocation= std::move(pWpsLocation);
 
-       __initialized = true;
+       __waitLoopListener.SetValue(true);
        SysLog(NID_LOC, "All the resources for location manager successfully created.");
        return true;
 
@@ -1079,7 +1078,7 @@ CATCH:
 void
 _LocationManager::OnStop(void)
 {
-       __initialized = false;
+       __waitLoopListener.SetValue(false);
 
        if (__gpsHandler.handle)
        {
@@ -1380,6 +1379,8 @@ _LocationManager::InitLocationManager(void)
        r = pLocMgr->Start();
        SysTryReturnVoidResult(NID_LOC, r == E_SUCCESS, r, "[%s] Falied to start the Location Manager. Propagating.", GetErrorMessage(r));
 
+       WaitingLoop::GetInstance()->Wait(*pLocMgr->GetWaitLoopListener());
+
        __pUniqueInstance = pLocMgr.release();
        std::atexit(DestroyLocationManager);
 }
index dbf524f..4a75f71 100644 (file)
@@ -32,6 +32,7 @@
 #include <FLocLocation.h>
 #include "FLoc_ILocationManagerListener.h"
 #include "FLoc_Types.h"
+#include "FLoc_WaitLoopListener.h"
 
 namespace Tizen { namespace Locations
 {
@@ -87,6 +88,12 @@ public:
        //
        bool IsAppEnabled(void);
 
+       // This method returns the wait loop listener of this class.
+       //
+       // @since 2.0
+       //
+       _WaitLoopListener* GetWaitLoopListener(void){return &__waitLoopListener;}
+
        // This method returns the single instance of the location maanger.
        //
        // @since 2.0
@@ -303,17 +310,17 @@ private:
        }
        __locationMgrState;
 
-       class __LocationManagerHandle
+       class _LocationManagerHandle
        {
        public:
-               __LocationManagerHandle(void)
+               _LocationManagerHandle(void)
                        : serviceState(LOCATIONS_SERVICE_DISABLED)
                        , handle(null)
                        , pLocation(null)
                {
                }
 
-               ~__LocationManagerHandle(void)
+               ~_LocationManagerHandle(void)
                {
                }
 
@@ -326,13 +333,13 @@ private:
        LocationAccuracy __minRequestedAccuracy;
        int __timerInterval;
        int __timerTicks;
-       __LocationManagerHandle __gpsHandler;
-       __LocationManagerHandle __wpsHandler;
+       _LocationManagerHandle __gpsHandler;
+       _LocationManagerHandle __wpsHandler;
        std::unique_ptr< Tizen::Base::Collection::ArrayList, Tizen::Base::Collection::AllElementsDeleter > __pLocRequestInfoList;
        std::unique_ptr< Tizen::Base::Collection::ArrayList, Tizen::Base::Collection::AllElementsDeleter > __pSyncLocRequestInfoList;
        std::unique_ptr< Tizen::Base::Runtime::Timer > __pLocUpdateTimer;
        static _LocationManager* __pUniqueInstance;
-       bool __initialized;
+       _WaitLoopListener __waitLoopListener;
 
        friend class std::default_delete< _LocationManager >;
 };      // class _LocationManager
diff --git a/src/FLoc_WaitLoopListener.h b/src/FLoc_WaitLoopListener.h
new file mode 100644 (file)
index 0000000..be41387
--- /dev/null
@@ -0,0 +1,68 @@
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+/**
+ * @file       FLoc_WaitLoopListener.h
+ * @brief      This is the header file for the %_WaitLoopListener class.
+ *
+ * This header file contains the declarations of the %_WaitLoopListener class methods.
+ */
+
+#ifndef _FLOC_INTERNAL_WAITLOOP_LISTENER_H_
+#define _FLOC_INTERNAL_WAITLOOP_LISTENER_H_
+
+#include <FBaseRtIWaitingLoopCondition.h>
+
+namespace Tizen { namespace Locations
+{
+
+class _WaitLoopListener
+       : public Tizen::Base::Object
+       , public Tizen::Base::Runtime::IWaitingLoopCondition
+{
+public:
+       _WaitLoopListener(void)
+               : Tizen::Base::Object()
+               , __isThreadInitialized(false)
+       {
+       }
+
+       ~_WaitLoopListener(void)
+       {
+       }
+
+       void SetValue(bool isInit)
+       {
+               __isThreadInitialized = isInit;
+       }
+
+       bool GetValue(void)
+       {
+               return __isThreadInitialized;
+       }
+
+private:
+       virtual bool IsMet(void)
+       {
+               return (__isThreadInitialized == true) ? true : false;
+       }
+
+private:
+       bool __isThreadInitialized;
+} ;// class _WaitLoopListener
+}} // Tizen::Locations
+#endif // _FLOC_INTERNAL_WAITLOOP_LISTENER_H_
\ No newline at end of file