summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xCMakeLists.txt3
-rw-r--r--src/FLocCoordinates.cpp8
-rw-r--r--src/FLoc_AlarmRequestInfo.h85
-rw-r--r--src/FLoc_ILocProviderEventListener.h7
-rw-r--r--src/FLoc_ILocationManagerListener.h6
-rw-r--r--src/FLoc_LocProviderEventArg.h1
-rw-r--r--src/FLoc_LocationManager.cpp255
-rw-r--r--src/FLoc_LocationManager.h46
-rw-r--r--src/FLoc_LocationProviderImpl.cpp88
-rw-r--r--src/FLoc_LocationProviderImpl.h40
-rw-r--r--src/FLoc_MathUtils.cpp2
-rw-r--r--src/FLoc_MathUtils.h2
-rw-r--r--src/FLoc_SyncLocationRequestInfo.h37
-rw-r--r--src/FLoc_WaitLoopListener.h68
14 files changed, 448 insertions, 200 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9697a40..9595e61 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -6,12 +6,12 @@ SET(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/cmake_build_tmp/output)
INCLUDE_DIRECTORIES (
${ROOTSTRAP_ROOT}/usr/include/location
+ ${ROOTSTRAP_ROOT}/usr/include
inc
src
/usr/include/osp
/usr/include/osp/app
/usr/include/osp/base
- /usr/include/osp/io
/usr/include/osp/system
/usr/include/osp/security
)
@@ -48,6 +48,7 @@ TARGET_LINK_LIBRARIES(${this_target} "-L/usr/lib/osp -losp-appfw")
TARGET_LINK_LIBRARIES(${this_target} "-L/usr/lib/osp -losp-uifw")
TARGET_LINK_LIBRARIES(${this_target} "-lcapi-location-manager")
TARGET_LINK_LIBRARIES(${this_target} "-lpthread")
+TARGET_LINK_LIBRARIES(${this_target} "-lalarm")
SET_TARGET_PROPERTIES(${this_target}
PROPERTIES
diff --git a/src/FLocCoordinates.cpp b/src/FLocCoordinates.cpp
index 5ec1284..80ae61e 100644
--- a/src/FLocCoordinates.cpp
+++ b/src/FLocCoordinates.cpp
@@ -129,10 +129,10 @@ result
Coordinates::Set(double latitude, double longitude, double altitude)
{
SysSecureTryReturn(NID_LOC, (MIN_LATITUDE <= latitude) && (latitude <= MAX_LATITUDE),
- E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The latitude(%lf) must be in the range [-90.0, 90.0].", latitude);
+ E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The latitude(%lf) must be in the range [-90.0, 90.0].", latitude);
SysSecureTryReturn(NID_LOC, (MIN_LONGITUDE <= longitude) && (longitude <= MAX_LONGITUDE),
- E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The longitude(%lf) must be in the range [-180.0, 180.0].", longitude);
+ E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The longitude(%lf) must be in the range [-180.0, 180.0].", longitude);
__latitude = latitude;
__longitude = longitude;
@@ -144,7 +144,7 @@ result
Coordinates::SetLatitude(double latitude)
{
SysSecureTryReturn(NID_LOC, (MIN_LATITUDE <= latitude) && (latitude <= MAX_LATITUDE),
- E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The latitude(%lf) must be in the range [-90.0, 90.0].", latitude);
+ E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The latitude(%lf) must be in the range [-90.0, 90.0].", latitude);
__latitude = latitude;
return E_SUCCESS;
}
@@ -153,7 +153,7 @@ result
Coordinates::SetLongitude(double longitude)
{
SysSecureTryReturn(NID_LOC, (MIN_LONGITUDE <= longitude) && (longitude <= MAX_LONGITUDE),
- E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The longitude(%lf) must be in the range [-180.0, 180.0].", longitude);
+ E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The longitude(%lf) must be in the range [-180.0, 180.0].", longitude);
__longitude = longitude;
return E_SUCCESS;
}
diff --git a/src/FLoc_AlarmRequestInfo.h b/src/FLoc_AlarmRequestInfo.h
new file mode 100644
index 0000000..3fe184d
--- /dev/null
+++ b/src/FLoc_AlarmRequestInfo.h
@@ -0,0 +1,85 @@
+//
+// 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_AlarmRequestInfo.h
+ * @brief This is the header file for the %_AlarmRequestInfo class.
+ *
+ * This header file contains the declarations of the %_AlarmRequestInfo class member variables.
+ */
+
+#ifndef _FLOC_INTERNAL_ALARM_REQUEST_INFO_H_
+#define _FLOC_INTERNAL_ALARM_REQUEST_INFO_H_
+
+#include <FBaseObject.h>
+#include <FLocTypes.h>
+
+namespace Tizen { namespace Locations
+{
+
+class _ILocationManagerListener;
+
+class _AlarmRequestInfo
+ : public Tizen::Base::Object
+{
+public:
+ _AlarmRequestInfo(int interval, _ILocationManagerListener* pListener, RequestId reqId)
+ : Tizen::Base::Object()
+ , __interval(interval)
+ , __alarmId(-1)
+ , __reqId(reqId)
+ , __pListener(pListener)
+ {
+ }
+
+ ~_AlarmRequestInfo(void)
+ {
+ }
+
+ _AlarmRequestInfo(const _AlarmRequestInfo& rhs)
+ : Tizen::Base::Object()
+ , __interval(rhs.__interval)
+ , __alarmId(rhs.__alarmId)
+ , __reqId(rhs.__reqId)
+ , __pListener(rhs.__pListener)
+ {
+ }
+
+ int GetInterval(void) const {return __interval;}
+
+ RequestId GetRequestId(void) const {return __reqId;}
+
+ void SetAlarmId(int alarmId) {__alarmId = alarmId;}
+
+ _ILocationManagerListener* GetListener(void) const {return __pListener;}
+
+ int GetAlarmId(void) const {return __alarmId;}
+
+private:
+ _AlarmRequestInfo(void);
+
+ _AlarmRequestInfo& operator =(const _AlarmRequestInfo& rhs);
+
+private:
+ int __interval;
+ int __alarmId;
+ RequestId __reqId;
+ _ILocationManagerListener* __pListener;
+
+};
+}}
+#endif //_FLOC_INTERNAL_ALARM_REQUEST_INFO_H_
diff --git a/src/FLoc_ILocProviderEventListener.h b/src/FLoc_ILocProviderEventListener.h
index 3c0934f..b090936 100644
--- a/src/FLoc_ILocProviderEventListener.h
+++ b/src/FLoc_ILocProviderEventListener.h
@@ -77,6 +77,13 @@ public:
*/
virtual void OnRegionMonitoringStatusChanged(Tizen::Locations::LocationServiceStatus locSvcStatus) = 0;
+ /**
+ * Called when the alarm expiry event is fired from the location provider impl class to break the context. @n
+ *
+ * @since 2.0
+ */
+ virtual void OnAlarmExpiredEventReceived(void) = 0;
+
}; //_ILocProviderEventListener
}} // Tizen::Locations
diff --git a/src/FLoc_ILocationManagerListener.h b/src/FLoc_ILocationManagerListener.h
index 93cf389..85f2256 100644
--- a/src/FLoc_ILocationManagerListener.h
+++ b/src/FLoc_ILocationManagerListener.h
@@ -59,6 +59,12 @@ public:
*/
virtual void OnLocationUpdated(RequestId reqId, const Tizen::Locations::Location& location) = 0;
+ /**
+ * Called when the alarm requested by the location provider has expired. @n
+ *
+ * @since 2.0
+ */
+ virtual void OnAlarmExpired(void) = 0;
}; //_ILocationManagerListener
}} // Tizen::Locations
diff --git a/src/FLoc_LocProviderEventArg.h b/src/FLoc_LocProviderEventArg.h
index 4468117..42ccc2e 100644
--- a/src/FLoc_LocProviderEventArg.h
+++ b/src/FLoc_LocProviderEventArg.h
@@ -39,6 +39,7 @@ enum _LocProviderEventType
_LOC_PRV_EVENT_SEND_LOC,
_LOC_PRV_EVENT_SEND_LOC_SVC_CB,
_LOC_PRV_EVENT_SEND_MONITOR_SVC_CB,
+ _LOC_PRV_EVENT_SEND_ALARM_EXPIRY,
};
class _LocProviderEventArg
diff --git a/src/FLoc_LocationManager.cpp b/src/FLoc_LocationManager.cpp
index 634c950..bd5e449 100644
--- a/src/FLoc_LocationManager.cpp
+++ b/src/FLoc_LocationManager.cpp
@@ -25,6 +25,7 @@
#include <cassert>
#include <iostream>
#include <pthread.h>
+#include <stdlib.h>
#include <unique_ptr.h>
#include <FBaseColArrayList.h>
#include <FBaseInteger.h>
@@ -32,11 +33,11 @@
#include <FBaseRtMutex.h>
#include <FBaseRtTimer.h>
#include <FBaseRtMonitor.h>
-#include <FBaseRtWaitingLoop.h>
#include <FBaseSysLog.h>
#include <FLocCoordinates.h>
#include <FSysSystemTime.h>
#include <FSys_PowerManagerImpl.h>
+#include "FLoc_AlarmRequestInfo.h"
#include "FLoc_Config.h"
#include "FLoc_LocationImpl.h"
#include "FLoc_LocationManager.h"
@@ -172,10 +173,13 @@ _LocationManager::RegisterLocationMonitor(_LocationMonitor* pLocationMonitor)
RequestId reqId;
const int ARRAY_LIST_CAPACITY = 1;
+ Location location = GetLastKnownLocation();
+ Tizen::Base::DateTime lastLocTime = location.GetTimestamp();
+
result r = StartLocationUpdates(pLocationMonitor->GetAccuracy(), 1, null, reqId);
SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Error to request location updates.", GetErrorMessage(r));
- std::unique_ptr< _SyncLocationRequestInfo > pSyncLocationRequestInfo(new (std::nothrow) _SyncLocationRequestInfo(pLocationMonitor, reqId));
+ std::unique_ptr< _SyncLocationRequestInfo > pSyncLocationRequestInfo(new (std::nothrow) _SyncLocationRequestInfo(pLocationMonitor, reqId, lastLocTime));
std::unique_ptr< Tizen::Base::Collection::ArrayList, Tizen::Base::Collection::AllElementsDeleter > pArgList(new (std::nothrow) ArrayList());
SysTryCatch(NID_LOC, pSyncLocationRequestInfo != null && pArgList != null, , E_OUT_OF_MEMORY,
"[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
@@ -198,6 +202,59 @@ CATCH:
return r;
}
+result
+_LocationManager::RequestStartAlarm(int interval, _ILocationManagerListener* pListener, RequestId reqId)
+{
+ const int ARRAY_LIST_CAPACITY = 1;
+
+ std::unique_ptr< Tizen::Base::Collection::ArrayList, Tizen::Base::Collection::AllElementsDeleter > pArgList(new (std::nothrow) ArrayList());
+ SysTryReturn(NID_LOC, pArgList, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ std::unique_ptr< _AlarmRequestInfo > pAlarmRequestInfo(new (std::nothrow) _AlarmRequestInfo(interval, pListener, reqId));
+ SysTryReturn(NID_LOC, pAlarmRequestInfo, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ result r = pArgList->Construct(ARRAY_LIST_CAPACITY);
+ SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Array Construct failed. Propogating.", GetErrorMessage(r));
+ r = pArgList->Add(*pAlarmRequestInfo.get());
+ SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Arraylist addition of an object failed. Propogating", GetErrorMessage(r));
+
+ pAlarmRequestInfo.release();
+
+ r = SendUserEvent(REQ_ID_START_ALARM, pArgList.get());
+ SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to send the user event. Propagating.", GetErrorMessage(r));
+
+ pArgList.release();
+
+ SysLog(NID_LOC, "Success to add the alarm.");
+ return E_SUCCESS;
+}
+
+result
+_LocationManager::RequestStopAlarm(RequestId reqId)
+{
+ SysLog(NID_LOC, "Alarm stop requested for request ID (%d).", reqId);
+ const int ARRAY_LIST_CAPACITY = 1;
+
+ std::unique_ptr< Tizen::Base::Collection::ArrayList, Tizen::Base::Collection::AllElementsDeleter > pArgList(new (std::nothrow) ArrayList());
+ SysTryReturn(NID_LOC, pArgList, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ std::unique_ptr< Integer > pReqId(new (std::nothrow) Integer(static_cast< int >(reqId)));
+ SysTryReturn(NID_LOC, pReqId, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ result r = pArgList->Construct(ARRAY_LIST_CAPACITY);
+ SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Array Construct failed. Propogating.", GetErrorMessage(r));
+ r = pArgList->Add(*pReqId);
+ SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Arraylist addition of an object failed. Propogating.", GetErrorMessage(r));
+
+ pReqId.release();
+
+ r = SendUserEvent(REQ_ID_STOP_ALARM, pArgList.get());
+ SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to send the user event. Propagating.", GetErrorMessage(r));
+
+ pArgList.release();
+ return E_SUCCESS;
+}
+
Location
_LocationManager::GetLastKnownLocation(void)
{
@@ -227,8 +284,8 @@ _LocationManager::GetLastKnownLocation(void)
r = synchronizer.Wait();
SysTryCatch(NID_LOC, r == E_SUCCESS, synchronizer.Exit(), r, "[%s] Propogating", GetErrorMessage(r));
synchronizer.Exit();
- SysLog(NID_LOC, "Last location(validity: %x, method: %ls) retrieved.",
- location.IsValid(), location.GetExtraInfo(L"location_method").GetPointer());
+ SysLog(NID_LOC, "Last location(validity: %x, method: %ls) retrieved.",
+ location.IsValid(), location.GetExtraInfo(L"location_method").GetPointer());
return location;
@@ -325,7 +382,6 @@ _LocationManager::RemoveFromLocRequestInfoList(RequestId reqId)
__pLocUpdateTimer->Cancel();
location_manager_stop(__gpsHandler.handle);
location_manager_stop(__wpsHandler.handle);
-
Reset();
}
else
@@ -338,35 +394,12 @@ _LocationManager::RemoveFromLocRequestInfoList(RequestId reqId)
void
_LocationManager::AddToSyncLocationRequestInfoList(_SyncLocationRequestInfo& syncLocRequestInfo)
{
- static bool hasRetrievalStarted = false;
+ result r = syncLocRequestInfo.StartTimer(*this);
+ SysTryCatch(NID_LOC, r == E_SUCCESS, , r, "[%s] Failed to start the sync timer.", GetErrorMessage(r));
- result r = __pSyncLocRequestInfoList->Add(syncLocRequestInfo);
+ r = __pSyncLocRequestInfoList->Add(syncLocRequestInfo);
SysTryCatch(NID_LOC, r == E_SUCCESS, , r, "[%s] Failed to add the sync request into the list.", GetErrorMessage(r));
- if (hasRetrievalStarted == true)
- {
- SysLog(NID_LOC, "The retrieval under process.");
- return;
- }
- while (__pSyncLocRequestInfoList->GetCount() != 0)
- {
- hasRetrievalStarted = true;
- const int WAIT_TIME = 1000;
- WaitingLoop::GetInstance()->Wait(WAIT_TIME);
-
- int count = __pSyncLocRequestInfoList->GetCount();
- for (int i = 0; i < count; i++)
- {
- _SyncLocationRequestInfo* pSyncLocRequestInfo = static_cast< _SyncLocationRequestInfo* >(__pSyncLocRequestInfoList->GetAt(i));
- if (pSyncLocRequestInfo != null)
- {
- SysLog(NID_LOC, "Handle the sync location request with request ID (%ld)", pSyncLocRequestInfo->GetRequestId());
-
- HandleSyncRetrievalTimerExpiry(*pSyncLocRequestInfo);
- }
- }
- }
- hasRetrievalStarted = false;
return;
CATCH:
@@ -383,6 +416,47 @@ _LocationManager::RemoveSyncLocRetrievalRequest(_SyncLocationRequestInfo& syncLo
}
void
+_LocationManager::AddToAlarmRequestInfoList(_AlarmRequestInfo& alarmRequestInfo)
+{
+ alarm_id_t alarmId;
+ int res = alarmmgr_add_alarm_withcb(ALARM_TYPE_DEFAULT, alarmRequestInfo.GetInterval(), 0, AlarmExpiryCallback, this, &alarmId);
+ SysTryReturnVoidResult(NID_LOC, res == ALARMMGR_RESULT_SUCCESS, E_SYSTEM, "Failed to add the alarm for next cycle.");
+
+ SysLog(NID_LOC, "The alarm ID (%d) will be set to the request.", alarmId);
+ alarmRequestInfo.SetAlarmId(alarmId);
+
+ std::unique_ptr< _AlarmRequestInfo > pNewAlarmRequestInfo(new (std::nothrow) _AlarmRequestInfo(alarmRequestInfo));
+ SysTryReturnVoidResult(NID_LOC, pNewAlarmRequestInfo, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+ result r = __pAlarmRequestInfoList->Add(*pNewAlarmRequestInfo.get());
+ SysTryReturnVoidResult(NID_LOC, r == E_SUCCESS, E_SYSTEM, "Failed to add the alarm request into list.");
+ pNewAlarmRequestInfo.release();
+
+ return;
+}
+
+void
+_LocationManager::RemoveFromAlarmRequestInfoList(RequestId reqId)
+{
+ int count = __pAlarmRequestInfoList->GetCount();
+ SysLog(NID_LOC, "Total count of Alarm Request pending is (%d).", count);
+
+ for (int i = 0; i < count; i++)
+ {
+ const _AlarmRequestInfo* pAlarmRequestInfo = static_cast< const _AlarmRequestInfo* >(__pAlarmRequestInfoList->GetAt(i));
+ if (reqId == pAlarmRequestInfo->GetRequestId())
+ {
+ int res = alarmmgr_remove_alarm(pAlarmRequestInfo->GetAlarmId());
+ SysTryLog(NID_LOC, res == ALARMMGR_RESULT_SUCCESS, "Failed to remove the Alarm.");
+ SysLog(NID_LOC, "The alarm with request Id (%d) and Alarm Id (%d) will be removed.", reqId, pAlarmRequestInfo->GetAlarmId());
+ __pAlarmRequestInfoList->RemoveAt(i);
+ break;
+ }
+ }
+
+ return;
+}
+
+void
_LocationManager::RestartLocationUpdates(void)
{
int count = __pLocRequestInfoList->GetCount();
@@ -491,20 +565,20 @@ _LocationManager::HandleSyncRetrievalTimerExpiry(_SyncLocationRequestInfo& syncL
LocationAccuracy accuracy = LOC_ACCURACY_INVALID;
DateTime timestamp = DateTime::GetMinValue();
- Location location = GetRecentLocationAvailable();
+ const Location* pBestLoc = FindBestLocation();
SysLog(NID_LOC, "Location(timestamp: %ls, validity: %x, accuracy: %f) is retrieved.",
- location.GetTimestamp().ToString().GetPointer(), location.IsValid(), location.GetHorizontalAccuracy());
- if (location.IsValid())
+ pBestLoc->GetTimestamp().ToString().GetPointer(), pBestLoc->IsValid(), pBestLoc->GetHorizontalAccuracy());
+ if (pBestLoc->IsValid())
{
- accuracy = GetAccuracyLevel(location.GetHorizontalAccuracy());
- timestamp = location.GetTimestamp();
+ accuracy = GetAccuracyLevel(pBestLoc->GetHorizontalAccuracy());
+ timestamp = pBestLoc->GetTimestamp();
}
bool inTime = syncLocRequestInfo.IsInTime(timestamp);
bool accurate = syncLocRequestInfo.IsAccuracySatisfying(accuracy);
if (inTime && accurate)
{
- unique_ptr< Location > pLocation(new (std::nothrow) Location(location));
+ unique_ptr< Location > pLocation(new (std::nothrow) Location(*pBestLoc));
SysTryCatchLabel(NID_LOC, pLocation != null, , NOTIFY, E_OUT_OF_MEMORY,
"[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
syncLocRequestInfo.GetLocationMonitor()->SetLocation(pLocation.get());
@@ -516,7 +590,7 @@ _LocationManager::HandleSyncRetrievalTimerExpiry(_SyncLocationRequestInfo& syncL
{
if (inTime)
{
- unique_ptr< Location > pLocation(new (std::nothrow) Location(location));
+ unique_ptr< Location > pLocation(new (std::nothrow) Location(*pBestLoc));
SysTryCatchLabel(NID_LOC, pLocation != null, , NOTIFY, E_OUT_OF_MEMORY,
"[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
syncLocRequestInfo.GetLocationMonitor()->SetLocation(pLocation.get());
@@ -532,7 +606,7 @@ _LocationManager::HandleSyncRetrievalTimerExpiry(_SyncLocationRequestInfo& syncL
}
SysLog(NID_LOC, "Wait for next location(Tick: %d).", syncLocRequestInfo.GetTickCount());
- syncLocRequestInfo.IncrementTickCount();
+ syncLocRequestInfo.StartTimer(*this);
return;
NOTIFY:
@@ -738,7 +812,7 @@ _LocationManager::GetLastKnownLocation(location_method_e nativeLocMethod)
int res = location_manager_get_last_position(nativeHandle, &altitude, &latitude, &longitude, &timestampPosition);
SysTryCatch(NID_LOC, res == 0, , E_SYSTEM, "[E_SYSTEM] Failed to fetch last position from nativeHandle(%x).", nativeHandle);
SysSecureLog(NID_LOC, "Last position(latitude: %lf, longitude: %lf, altitude: %lf, timestamp: %ld",
- latitude, longitude, altitude, timestampPosition);
+ latitude, longitude, altitude, timestampPosition);
Coordinates coord;
coord.Set(latitude, longitude, altitude);
@@ -763,7 +837,7 @@ _LocationManager::GetLastKnownLocation(location_method_e nativeLocMethod)
if (res == 0)
{
SysLog(NID_LOC, "Last velocity(climb: %lf, direction: %lf, speed: %lf, timestamp: %ld)",
- climb, direction, speed, timestampVelocity);
+ climb, direction, speed, timestampVelocity);
pLocationImpl->SetCourse(direction);
pLocationImpl->SetSpeed(speed);
}
@@ -780,14 +854,14 @@ _LocationManager::GetLastKnownLocation(location_method_e nativeLocMethod)
long timeDiff = abs(timestampPosition - timestampSatellite);
res = gps_status_foreach_last_satellites_in_view(nativeHandle, SatelliteInfoUpdated, &satInfo);
SysLog(NID_LOC, "Last satellite(foreachResult: %d, inUse: %d, inView: %d, timestamp: %ld, timeDiff: %ld)",
- res, satUsedCount, satViewCount, timestampSatellite, timeDiff);
+ res, satUsedCount, satViewCount, timestampSatellite, timeDiff);
satInfo.Trim();
SysLog(NID_LOC, "Last satellite(info: %ls)", satInfo.GetPointer());
pLocationImpl->SetExtraInfo(L"satellite", satInfo);
}
}
- pLocationImpl->SetTimestamp(((long long)timestampPosition) * 1000); // in milliseconds
+ pLocationImpl->SetTimestamp(((long long) timestampPosition) * 1000); // in milliseconds
pLocationImpl->SetValidity(true);
pLocationImpl->SetExtraInfo(L"location_method", locationMethod);
}
@@ -828,7 +902,7 @@ _LocationManager::GetRecentLocationAvailable(void)
}
}
-void
+void
_LocationManager::UpdateLocRequestInfoList(RequestId reqId, int interval)
{
int count = __pLocRequestInfoList->GetCount();
@@ -955,7 +1029,7 @@ _LocationManager::GetLocation(location_method_e nativeLocMethod)
}
res = location_manager_get_position(nativeHandle, &altitude, &latitude, &longitude, &timestamp);
- SysTryReturnResult(NID_LOC, res == 0, E_SYSTEM, "Failed to obtain the natvie location information for the method (%x)", nativeLocMethod);
+ SysTryReturnResult(NID_LOC, res == 0, E_SYSTEM, "Failed to obtain the natvie location information for the method (%x)", nativeLocMethod);
if (res == 0)
{
@@ -993,16 +1067,21 @@ _LocationManager::OnStart(void)
int res = -1;
- std::unique_ptr< Tizen::Base::Collection::ArrayList, AllElementsDeleter > pLocInfoRequestList(new (std::nothrow) ArrayList());
+ std::unique_ptr< Tizen::Base::Collection::ArrayList, AllElementsDeleter > pLocInfoRequestList(new (std::nothrow) ArrayList(SingleObjectDeleter));
SysTryReturn(NID_LOC, pLocInfoRequestList != null, false, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
result r = pLocInfoRequestList->Construct();
SysTryReturn(NID_LOC, r == E_SUCCESS, false, E_SYSTEM, "[E_SYSTEM] Failed to construct the Location Request list.");
- std::unique_ptr< Tizen::Base::Collection::ArrayList, AllElementsDeleter > pSyncLocInfoRequestList(new (std::nothrow) ArrayList());
+ std::unique_ptr< Tizen::Base::Collection::ArrayList, AllElementsDeleter > pSyncLocInfoRequestList(new (std::nothrow) ArrayList(SingleObjectDeleter));
SysTryReturn(NID_LOC, pSyncLocInfoRequestList != null, false, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
r = pSyncLocInfoRequestList->Construct();
SysTryReturn(NID_LOC, r == E_SUCCESS, false, E_SYSTEM, "[E_SYSTEM] Failed to construct the Sync Location Request list.");
+ std::unique_ptr< Tizen::Base::Collection::ArrayList, AllElementsDeleter > pAlarmInfoRequestList(new (std::nothrow) ArrayList(SingleObjectDeleter));
+ SysTryReturn(NID_LOC, pAlarmInfoRequestList != null, false, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+ r = pAlarmInfoRequestList->Construct();
+ SysTryReturn(NID_LOC, r == E_SUCCESS, false, E_SYSTEM, "[E_SYSTEM] Failed to construct the Sync Location Request list.");
+
unique_ptr< Tizen::Locations::Location > pGpsLocation(_LocationImpl::GetLocationInstanceN());
SysTryReturn(NID_LOC, pGpsLocation != null, false, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
unique_ptr< Tizen::Locations::Location > pWpsLocation(_LocationImpl::GetLocationInstanceN());
@@ -1024,9 +1103,10 @@ _LocationManager::OnStart(void)
__pLocRequestInfoList = std::move(pLocInfoRequestList);
__pSyncLocRequestInfoList = std::move(pSyncLocInfoRequestList);
+ __pAlarmRequestInfoList = std::move(pAlarmInfoRequestList);
__pLocUpdateTimer = std::move(pLocUpdateTimer);
- __gpsHandler.pLocation= std::move(pGpsLocation);
- __wpsHandler.pLocation= std::move(pWpsLocation);
+ __gpsHandler.pLocation = std::move(pGpsLocation);
+ __wpsHandler.pLocation = std::move(pWpsLocation);
r = __pInitMonitor->Enter();
SysTryCatch(NID_LOC, r == E_SUCCESS, , r, "[%s] Failed to Enter Monitor. Propagating.", GetErrorMessage(r));
@@ -1180,6 +1260,32 @@ _LocationManager::OnUserEventReceivedN(RequestId requestId, IList* pArgs)
}
break;
+ case REQ_ID_START_ALARM:
+ {
+ SysLog(NID_LOC, "REQ_ID_START_ALARM");
+ SysTryReturnVoidResult(NID_LOC, pArgs, E_INVALID_ARG, "[E_INVALID_ARG] Null argument encountered. Ignored.");
+ _AlarmRequestInfo* pAlarmRequestInfo = null;
+ SysTryCatch(NID_LOC, pArgs->GetCount() == ARRAY_LIST_CAPACITY, pArgs->RemoveAll(true), E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument encountered. Ignored.");
+ pAlarmRequestInfo = static_cast< _AlarmRequestInfo* >(pArgs->GetAt(0));
+ SysTryCatch(NID_LOC, pAlarmRequestInfo, , E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument encountered. Ignored.");
+
+ AddToAlarmRequestInfoList(*pAlarmRequestInfo);
+ }
+ break;
+
+ case REQ_ID_STOP_ALARM:
+ {
+ SysLog(NID_LOC, "REQ_ID_STOP_ALARM");
+ SysTryReturnVoidResult(NID_LOC, pArgs, E_INVALID_ARG, "[E_INVALID_ARG] Null argument encountered. Ignored.");
+ Integer* pReqId = null;
+ SysTryCatch(NID_LOC, pArgs->GetCount() == ARRAY_LIST_CAPACITY, pArgs->RemoveAll(true), E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument encountered. Ignored.");
+ pReqId = static_cast< Integer* >(pArgs->GetAt(0));
+ SysTryCatch(NID_LOC, pReqId, , E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument encountered. Ignored.");
+
+ RemoveFromAlarmRequestInfoList(static_cast< long >(pReqId->ToInt()));
+ }
+ break;
+
}
if (pArgs)
@@ -1262,6 +1368,21 @@ _LocationManager::OnTimerExpired(Tizen::Base::Runtime::Timer& timer)
__pLocUpdateTimer->Start(__timerInterval * 1000);
SendLocationCallbacks();
}
+ else
+ {
+ int count = __pSyncLocRequestInfoList->GetCount();
+ for (int i = 0; i < count; i++)
+ {
+ _SyncLocationRequestInfo* pSyncLocRequestInfo = static_cast< _SyncLocationRequestInfo* >(__pSyncLocRequestInfoList->GetAt(i));
+ if (pSyncLocRequestInfo != null && pSyncLocRequestInfo->Equals(timer))
+ {
+ SysLog(NID_LOC, "Timer expired for the sync location request with request ID (%ld)", pSyncLocRequestInfo->GetRequestId());
+
+ HandleSyncRetrievalTimerExpiry(*pSyncLocRequestInfo);
+ break;
+ }
+ }
+ }
return;
}
@@ -1321,6 +1442,36 @@ _LocationManager::WpsServiceUpdateCallback(location_service_state_e state, void*
pThis->__wpsHandler.serviceState = state;
}
+int
+_LocationManager::AlarmExpiryCallback(alarm_id_t alarm_id, void* user_param)
+{
+ SysLog(NID_LOC, "The Alarm expired successfully for the alarm ID (%d).", alarm_id);
+ if (user_param == null)
+ {
+ SysLog(NID_LOC, "The user parameter is null. So cannot handle the callback.");
+ return -1;
+ }
+
+ _LocationManager* pThis = static_cast< _LocationManager* >(user_param);
+ int count = pThis->__pAlarmRequestInfoList->GetCount();
+
+ for (int i = 0; i < count; i++)
+ {
+ _AlarmRequestInfo* pAlarmRequestInfo = static_cast< _AlarmRequestInfo* >(pThis->__pAlarmRequestInfoList->GetAt(i));
+ if (pAlarmRequestInfo)
+ {
+ if (alarm_id == pAlarmRequestInfo->GetAlarmId())
+ {
+ pAlarmRequestInfo->GetListener()->OnAlarmExpired();
+ pThis->__pAlarmRequestInfoList->RemoveAt(i);
+ break;
+ }
+ }
+ }
+
+ return 0;
+}
+
void
_LocationManager::InitLocationManager(void)
{
@@ -1334,8 +1485,8 @@ _LocationManager::InitLocationManager(void)
r = pLocMgr->Start();
SysTryReturnVoidResult(NID_LOC, r == E_SUCCESS, r, "[%s] Failed to start the Location Manager. Propagating.", GetErrorMessage(r));
- r = pLocMgr->WaitThreadStart();
- SysTryReturnVoidResult(NID_LOC, r == E_SUCCESS, r, "[%s] Failed to WaitThreadStart. Propagating.", GetErrorMessage(r));
+ r = pLocMgr->WaitUntilThreadStart();
+ SysTryReturnVoidResult(NID_LOC, r == E_SUCCESS, r, "[%s] Failed to WaitUntilThreadStart. Propagating.", GetErrorMessage(r));
__pUniqueInstance = pLocMgr.release();
std::atexit(DestroyLocationManager);
@@ -1348,7 +1499,7 @@ _LocationManager::DestroyLocationManager(void)
}
result
-_LocationManager::WaitThreadStart()
+_LocationManager::WaitUntilThreadStart()
{
result r = __pInitMonitor->Enter();
SysTryReturnResult(NID_LOC, r == E_SUCCESS, r, "[%s] Failed to Enter Monitor. Propagating.", GetErrorMessage(r));
diff --git a/src/FLoc_LocationManager.h b/src/FLoc_LocationManager.h
index 5723199..a8fc009 100644
--- a/src/FLoc_LocationManager.h
+++ b/src/FLoc_LocationManager.h
@@ -26,17 +26,18 @@
#define _FLOC_INTERNAL_LOCATION_MANAGER_H_
#include <unique_ptr.h>
+#include <alarm.h>
#include <location/locations.h>
#include <FBaseColAllElementsDeleter.h>
#include <FBaseRtEventDrivenThread.h>
#include <FLocLocation.h>
#include "FLoc_ILocationManagerListener.h"
#include "FLoc_Types.h"
-#include "FLoc_WaitLoopListener.h"
namespace Tizen { namespace Locations
{
+class _AlarmRequestInfo;
class _LocationMonitor;
class _LocationRequestInfo;
class _SyncLocationRequestInfo;
@@ -70,23 +71,29 @@ public:
//
result RegisterLocationMonitor(_LocationMonitor* pLocationMonitor);
- // This method returns the stored location.
+ // This method adds the alarm request into the list of requests and requests for alarm from the core alarm manager.
//
// @since 2.0
//
- Location GetLastKnownLocation(void);
+ result RequestStartAlarm(int interval, _ILocationManagerListener* pListener, RequestId reqId);
- // This method converts the horizontal accuracy in meters to the LocationAccuracy enum type.
+ // This method removes the alarm request from the list of requests and requests the removal of alarm from the core alarm manager.
//
// @since 2.0
//
- LocationAccuracy GetAccuracyLevel(double horAcc) const;
+ result RequestStopAlarm(RequestId reqId);
- // This method returns the wait loop listener of this class.
+ // This method returns the stored location.
//
// @since 2.0
//
- _WaitLoopListener* GetWaitLoopListener(void){return &__waitLoopListener;}
+ Location GetLastKnownLocation(void);
+
+ // This method converts the horizontal accuracy in meters to the LocationAccuracy enum type.
+ //
+ // @since 2.0
+ //
+ LocationAccuracy GetAccuracyLevel(double horAcc) const;
// This method returns the single instance of the location maanger.
//
@@ -143,6 +150,18 @@ private:
//
void RemoveSyncLocRetrievalRequest(_SyncLocationRequestInfo& syncLocRequestInfo);
+ // The method adds the _AlarmRequestInfo instance corresponding to a reqId from the array list.
+ //
+ // @since 2.0
+ //
+ void AddToAlarmRequestInfoList(_AlarmRequestInfo& alarmRequestInfo);
+
+ // The method removes the _AlarmRequestInfo instance from the list.
+ //
+ // @since 2.0
+ //
+ void RemoveFromAlarmRequestInfoList(RequestId reqId);
+
// The method restarts both GPS and WPS native location providers.
//
// @since 2.0
@@ -183,13 +202,12 @@ private:
//
// @since 2.0
//
- result WaitThreadStart();
+ result WaitUntilThreadStart();
// 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.
@@ -264,6 +282,12 @@ private:
//
static void WpsServiceUpdateCallback(location_service_state_e state, void* user_data);
+ // This method is called by the core alarm manager when the requested alarm is expired.
+ //
+ // @since 2.0
+ //
+ static int AlarmExpiryCallback(alarm_id_t alarm_id, void* user_param);
+
// This method initializes the single instance of the location manager.
//
// @since 2.0
@@ -285,6 +309,8 @@ private:
const static RequestId REQ_ID_SYNC_LOC_RETRIEVAL = 6;
const static RequestId REQ_ID_GET_LAST_LOCATION = 7;
const static RequestId REQ_ID_UPDATE_INTERVAL = 8;
+ const static RequestId REQ_ID_START_ALARM = 9;
+ const static RequestId REQ_ID_STOP_ALARM = 10;
enum _LocationMethodRequested
{
@@ -330,9 +356,9 @@ private:
_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::Collection::ArrayList, Tizen::Base::Collection::AllElementsDeleter > __pAlarmRequestInfoList;
std::unique_ptr< Tizen::Base::Runtime::Timer > __pLocUpdateTimer;
static _LocationManager* __pUniqueInstance;
- _WaitLoopListener __waitLoopListener;
Tizen::Base::Runtime::Monitor* __pInitMonitor;
friend class std::default_delete< _LocationManager >;
diff --git a/src/FLoc_LocationProviderImpl.cpp b/src/FLoc_LocationProviderImpl.cpp
index 2d25b79..dcb75da 100644
--- a/src/FLoc_LocationProviderImpl.cpp
+++ b/src/FLoc_LocationProviderImpl.cpp
@@ -39,7 +39,6 @@
#include <FLocTypes.h>
#include <FSysPowerManager.h>
#include <FSysSystemTime.h>
-#include <FSys_AlarmImpl.h>
#include <FSys_SettingInfoImpl.h>
#include "FLoc_LocationImpl.h"
#include "FLoc_LocationManager.h"
@@ -89,21 +88,16 @@ _LocationProviderImpl::Construct(const LocationCriteria& criteria, ILocationProv
_LocationManager* pLocationManager = _LocationManager::GetInstance();
SysTryReturn(NID_LOC, pLocationManager != null, GetLastResult(), GetLastResult(), "[%s] Failed to get the location manager instance.", GetErrorMessage(GetLastResult()));
- std::unique_ptr< Tizen::Base::Collection::ArrayList, AllElementsDeleter > pRegionList(new (std::nothrow) ArrayList());
+ std::unique_ptr< Tizen::Base::Collection::ArrayList, AllElementsDeleter > pRegionList(new (std::nothrow) ArrayList(SingleObjectDeleter));
SysTryReturn(NID_LOC, pRegionList != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
result r = pRegionList->Construct();
SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to construct the list. Propagating.", GetErrorMessage(r));
- std::unique_ptr< Tizen::Base::Runtime::Timer> pTimer (new (std::nothrow) Timer());
+ std::unique_ptr< Tizen::Base::Runtime::Timer > pTimer(new (std::nothrow) Timer());
SysTryReturn(NID_LOC, pTimer != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
r = pTimer->Construct(*this);
SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to construct the timer. Propagating.", GetErrorMessage(r));
- std::unique_ptr< Tizen::System::Alarm> pAlarm (new (std::nothrow) Alarm());
- SysTryReturn(NID_LOC, pAlarm != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
- r = pAlarm->Construct(*this);
- SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to construct the alarm. Propagating.", GetErrorMessage(r));
-
UiApp* pAppInstance = Tizen::App::UiApp::GetInstance();
if (pAppInstance != null)
{
@@ -116,7 +110,7 @@ _LocationProviderImpl::Construct(const LocationCriteria& criteria, ILocationProv
std::unique_ptr< Tizen::Locations::Location > pLastLocation(_LocationImpl::GetLocationInstanceN());
SysTryReturn(NID_LOC, pLastLocation != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
- std::unique_ptr<Tizen::Locations::Location> pLastRegionLocation (_LocationImpl::GetLocationInstanceN());
+ std::unique_ptr< Tizen::Locations::Location > pLastRegionLocation(_LocationImpl::GetLocationInstanceN());
SysTryReturn(NID_LOC, pLastRegionLocation != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
_Event::Initialize();
@@ -124,10 +118,9 @@ _LocationProviderImpl::Construct(const LocationCriteria& criteria, ILocationProv
__regionMonitor.pRegionList = std::move(pRegionList);
__regionMonitor.pTimer = std::move(pTimer);
- __regionMonitor.pAlarm = std::move(pAlarm);
__regionMonitor.pLocation = std::move(pLastRegionLocation);
__locationUpdater.pLocation = std::move(pLastLocation);
-
+
__criteria = criteria;
__pLocationListener = &listener;
__pLocationManager = pLocationManager;
@@ -266,7 +259,7 @@ _LocationProviderImpl::RemoveMonitoringRegion(RegionId regionId)
_RegionInfo* pRegionInfo = static_cast< _RegionInfo* >(__regionMonitor.pRegionList->GetAt(i));
if (regionId == pRegionInfo->GetRegionId())
{
- __regionMonitor.pRegionList->RemoveAt(i, true);
+ __regionMonitor.pRegionList->RemoveAt(i);
isIdValid = true;
break;
}
@@ -413,6 +406,23 @@ _LocationProviderImpl::OnLocationUpdated(RequestId reqId, const Tizen::Locations
}
void
+_LocationProviderImpl::OnAlarmExpired(void)
+{
+ SysLog(NID_LOC, "The call back of the Alarm expiry is called from location manager.");
+
+ std::unique_ptr< _LocProviderEventArg > pLocProviderEventArg(new (std::nothrow) _LocProviderEventArg());
+ SysTryReturnVoidResult(NID_LOC, pLocProviderEventArg, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ pLocProviderEventArg->SetEventType(_LOC_PRV_EVENT_SEND_ALARM_EXPIRY);
+
+ result r = _Event::FireAsync(*pLocProviderEventArg);
+ SysTryReturnVoidResult(NID_LOC, r == E_SUCCESS, r, "[%s] Failed to fire the event.", GetErrorMessage(r));
+ pLocProviderEventArg.release();
+
+ return;
+}
+
+void
_LocationProviderImpl::OnLocationEventReceivedN(RequestId reqId, Tizen::Locations::Location& location)
{
SysLog(NID_LOC, "Location Event received.");
@@ -461,10 +471,10 @@ _LocationProviderImpl::OnLocationEventReceivedN(RequestId reqId, Tizen::Location
bool gpsEnabled = false;
_SettingInfoImpl::GetValue(L"http://tizen.org/setting/location.gps", gpsEnabled);
SysLog(NID_LOC, "The GPS settings value is %d", gpsEnabled);
-
+
__regionMonitor.speed = location.GetSpeed() * 0.2777778;
- if ( currentAccuracy <= lastLocAccuracy || timeDifference > DEFAULT_THRESHOLD_LOC_VALIDITY_TIME_OUT) // Copy the location only if it is new and accuracy is better than before.
+ if (currentAccuracy <= lastLocAccuracy || timeDifference > DEFAULT_THRESHOLD_LOC_VALIDITY_TIME_OUT) // Copy the location only if it is new and accuracy is better than before.
{
*__regionMonitor.pLocation = location;
}
@@ -480,7 +490,7 @@ _LocationProviderImpl::OnLocationEventReceivedN(RequestId reqId, Tizen::Location
else
{
SysLog(NID_LOC, "Location criteria (accuracy: %ld) is not met for handling region monitoring.", currentAccuracy);
- }
+ }
}
}
@@ -500,6 +510,14 @@ _LocationProviderImpl::OnRegionMonitoringStatusChanged(Tizen::Locations::Locatio
}
void
+_LocationProviderImpl::OnAlarmExpiredEventReceived(void)
+{
+ SysLog(NID_LOC, "Region Monitor Alarm expired event received.");
+ result r = ActivateRegionMonitoring(true);
+ SysTryReturnVoidResult(NID_LOC, r == E_SUCCESS, r, "[%s] Failed to start the region monitoring. Propogating.", GetErrorMessage(r));
+}
+
+void
_LocationProviderImpl::OnActiveAppChanged(const Tizen::App::AppId& appId)
{
Tizen::App::App* pApp = Tizen::App::App::GetInstance();
@@ -534,14 +552,6 @@ _LocationProviderImpl::OnActiveAppChanged(const Tizen::App::AppId& appId)
}
void
-_LocationProviderImpl::OnAlarmExpired(Alarm& alarm)
-{
- SysLog(NID_LOC, "Region Monitor Alarm expired.");
- result r = ActivateRegionMonitoring(true);
- SysTryReturnVoidResult(NID_LOC, r == E_SUCCESS, r, "[%s] Failed to start the region monitoring. Propogating.", GetErrorMessage(r));
-}
-
-void
_LocationProviderImpl::OnTimerExpired(Timer& timer)
{
SysLog(NID_LOC, "Region Monitor timer expired due to unavailability of location information.");
@@ -565,7 +575,7 @@ _LocationProviderImpl::StartLocationUpdates(LocationUpdateType updateType, int i
__locationUpdater.distanceThreshold = distance;
}
- if (!__locationUpdater.awakeEnabled)
+ if (!__locationUpdater.awakeEnabled)
{
UiApp* pAppInstance = Tizen::App::UiApp::GetInstance();
if (pAppInstance == null)
@@ -599,11 +609,11 @@ _LocationProviderImpl::StartLocationUpdates(LocationUpdateType updateType, int i
r = __pLocationManager->StartLocationUpdates(__criteria.GetAccuracy(), __locationUpdater.updateInterval, this, __locationUpdater.reqId);
SysTryCatch(NID_LOC, r == E_SUCCESS, , r, "[%s] Failed to start the Native location updates. Propagating.", GetErrorMessage(r));
__locationUpdater.status = LOC_SVC_STATUS_NOT_FIXED;
- }
+ }
}
else
{
- __locationUpdater.status = LOC_SVC_STATUS_PAUSED;
+ __locationUpdater.status = LOC_SVC_STATUS_PAUSED;
}
__locationUpdater.type = updateType;
@@ -672,6 +682,10 @@ _LocationProviderImpl::FireImpl(Tizen::Base::Runtime::IEventListener& listener,
case _LOC_PRV_EVENT_SEND_MONITOR_SVC_CB:
pLocProviderEventListener->OnRegionMonitoringStatusChanged(pEventArg->GetLocServiceStatus());
break;
+
+ case _LOC_PRV_EVENT_SEND_ALARM_EXPIRY:
+ pLocProviderEventListener->OnAlarmExpiredEventReceived();
+ break;
}
}
@@ -818,9 +832,9 @@ _LocationProviderImpl::GetRegionCurrentState(const _RegionInfo& region, const Lo
TryReturn(location.GetHorizontalAccuracy() >= 0.0, REGION_STATE_UNKNOWN, "Location received with invalid accuracy");
SysSecureLog(NID_LOC, "[RegionID %d] Region Information is (Center latitude: %lf, Center longitude: %lf, Region radius:%lf", region.GetRegionId(), region.GetCoordinate().GetLatitude(),
- region.GetCoordinate().GetLongitude(), region.GetRadius());
+ region.GetCoordinate().GetLongitude(), region.GetRadius());
SysSecureLog(NID_LOC, "[RegionID %d] Location Information is (Latitude: %lf, Longitude: %lf, Horizontal accuracy:%lf", region.GetRegionId(), location.GetCoordinates().GetLatitude(),
- location.GetCoordinates().GetLongitude(), location.GetHorizontalAccuracy());
+ location.GetCoordinates().GetLongitude(), location.GetHorizontalAccuracy());
_RegionState regionState = REGION_STATE_UNKNOWN;
double distanceBtwCenters = region.GetCoordinate().GetDistanceTo(location.GetCoordinates());
@@ -944,25 +958,25 @@ _LocationProviderImpl::ActivateRegionMonitoring(bool startUpdate)
}
result r = __regionMonitor.pTimer->Start(DEFAULT_WAITING_TIME * 1000);
- SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to start the timer. Propogating.", GetErrorMessage(r));
+ SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to start the timer. Propogating.", GetErrorMessage(r));
if (startUpdate)
{
_LocationImpl::GetInstance(*__regionMonitor.pLocation)->SetValidity(false);
- _LocationImpl::GetInstance(*__regionMonitor.pLocation)->SetTimestamp(currentTime);
+ _LocationImpl::GetInstance(*__regionMonitor.pLocation)->SetTimestamp(currentTime);
r = __pLocationManager->StartLocationUpdates(__criteria.GetAccuracy(), MIN_LOCATION_UPDATE_INTERVAL, this, __regionMonitor.reqId);
SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to start the location updates. Propogating.", GetErrorMessage(r));
SysLog(NID_LOC, "Location updates started.");
}
-
+
return E_SUCCESS;
}
void
_LocationProviderImpl::StopRegionMonitoring(void)
{
- result r = _AlarmImpl::GetInstance(__regionMonitor.pAlarm.get())->Cancel();
+ result r = __pLocationManager->RequestStopAlarm(__regionMonitor.reqId);
SysTryLog(NID_LOC, r == E_SUCCESS, "[%s] Failed to stop the alarm. Ignored.", GetErrorMessage(r));
r = __regionMonitor.pTimer->Cancel();
@@ -992,7 +1006,7 @@ _LocationProviderImpl::SetNextRegionMonitoringTime(void)
const int bufferTime = 5; //Buffer of 5 seconds for determining the alarmTime;
double minDistance = _MathUtils::GetShortestDistance(*__regionMonitor.pLocation, *__regionMonitor.pRegionList);
- long long newAlarmTime = ((int) minDistance / speed) - bufferTime; //Calculate the alarm time based on the shortest distance between current location and nearest region boundary.
+ long long newAlarmTime = ((int) minDistance / speed) - bufferTime; //Calculate the alarm time based on the shortest distance between current location and nearest region boundary.
if (newAlarmTime < DEFAULT_REGION_MONITORING_CYCLE_INTERVAL)
{
@@ -1008,11 +1022,9 @@ _LocationProviderImpl::SetNextRegionMonitoringTime(void)
result r = __pLocationManager->StopLocationUpdates(__regionMonitor.reqId);
SysTryLog(NID_LOC, r == E_SUCCESS, "Failed to stop the location updates.");
-
- alarmDateTime.AddSeconds(alarmTime);
- r = _AlarmImpl::GetInstance(__regionMonitor.pAlarm.get())->Set(alarmDateTime, 0, null);
- SysTryLog(NID_LOC, r == E_SUCCESS, "Failed to set the alarm for next cycle.");
-
+
+ r = __pLocationManager->RequestStartAlarm(alarmTime, this, __regionMonitor.reqId);
+
SysLog(NID_LOC, "Next alarm expires after %ld seconds.", alarmTime);
}
}}
diff --git a/src/FLoc_LocationProviderImpl.h b/src/FLoc_LocationProviderImpl.h
index e00f64c..450380b 100644
--- a/src/FLoc_LocationProviderImpl.h
+++ b/src/FLoc_LocationProviderImpl.h
@@ -32,8 +32,6 @@
#include <FBaseRtITimerEventListener.h>
#include <FBaseRtTimer.h>
#include <FLocLocationCriteria.h>
-#include <FSysAlarm.h>
-#include <FSysIAlarmEventListener.h>
#include <FBaseRt_Event.h>
#include <FLoc_Config.h>
#include "FLoc_ILocationManagerListener.h"
@@ -61,7 +59,6 @@ class _LocationProviderImpl
, public Tizen::Locations::_ILocProviderEventListener
, public Tizen::App::IActiveAppEventListener
, public Tizen::Base::Runtime::ITimerEventListener
- , public Tizen::System::IAlarmEventListener
{
public:
/**
@@ -162,6 +159,11 @@ private:
virtual void OnLocationUpdated(RequestId reqId, const Tizen::Locations::Location& location);
/**
+ * @see @ref Tizen::Locations::_ILocationManagerListener::OnAlarmExpired()
+ */
+ virtual void OnAlarmExpired(void);
+
+ /**
* @see @ref Tizen::Locations::_ILocProviderEventListener::OnLocationEventReceivedN()
*/
virtual void OnLocationEventReceivedN(RequestId reqId, Tizen::Locations::Location& location);
@@ -177,14 +179,14 @@ private:
virtual void OnRegionMonitoringStatusChanged(Tizen::Locations::LocationServiceStatus locSvcStatus);
/**
- * @see @ref Tizen::App::IActiveAppEventListener::OnActiveAppChanged()
+ * @see @ref Tizen::Locations::_ILocProviderEventListener::OnAlarmExpiredEventReceived()
*/
- virtual void OnActiveAppChanged(const Tizen::App::AppId& appId);
+ virtual void OnAlarmExpiredEventReceived(void);
/**
- * @see @ref Tizen::System::IAlarmEventListener::OnAlarmExpired()
+ * @see @ref Tizen::App::IActiveAppEventListener::OnActiveAppChanged()
*/
- virtual void OnAlarmExpired(Tizen::System::Alarm& alarm);
+ virtual void OnActiveAppChanged(const Tizen::App::AppId& appId);
/**
* @see @ref Tizen::Base::Runtime::ITimerEventListener::OnTimerExpired()
@@ -275,7 +277,7 @@ private:
, awakeEnabled(false)
, updateInterval(0)
, status(LOC_SVC_STATUS_IDLE)
- , type(_LOCATION_UPDATE_TYPE_NONE)
+ , type(_LOCATION_UPDATE_TYPE_NONE)
, reqId(-1)
, distanceThreshold(0.0)
, pLocation(null)
@@ -285,7 +287,7 @@ private:
~_LocationUpdater(void)
{
}
-
+
public:
bool firstLocationUpdate;
bool awakeEnabled;
@@ -294,18 +296,18 @@ private:
LocationUpdateType type;
RequestId reqId;
double distanceThreshold;
- std::unique_ptr<Tizen::Locations::Location> pLocation;
- }__locationUpdater;
-
+ std::unique_ptr< Tizen::Locations::Location > pLocation;
+ }
+ __locationUpdater;
+
class _RegionMonitor
{
public:
_RegionMonitor(void)
: reqId(-1)
, status(LOC_SVC_STATUS_IDLE)
- , speed (DEFAULT_AVG_SPEED)
+ , speed(DEFAULT_AVG_SPEED)
, pTimer(null)
- , pAlarm(null)
, pLocation(null)
, pRegionList(null)
{
@@ -314,16 +316,16 @@ private:
~_RegionMonitor(void)
{
}
-
+
public:
RequestId reqId;
LocationServiceStatus status;
double speed;
- std::unique_ptr<Tizen::Base::Runtime::Timer> pTimer;
- std::unique_ptr<Tizen::System::Alarm> pAlarm;
- std::unique_ptr<Tizen::Locations::Location> pLocation;
+ std::unique_ptr< Tizen::Base::Runtime::Timer > pTimer;
+ std::unique_ptr< Tizen::Locations::Location > pLocation;
std::unique_ptr< Tizen::Base::Collection::ArrayList, Tizen::Base::Collection::AllElementsDeleter > pRegionList;
- }__regionMonitor;
+ }
+ __regionMonitor;
LocationAccuracy __lastLocationAccuracy;
LocationCriteria __criteria;
diff --git a/src/FLoc_MathUtils.cpp b/src/FLoc_MathUtils.cpp
index f7f1c54..f050a6a 100644
--- a/src/FLoc_MathUtils.cpp
+++ b/src/FLoc_MathUtils.cpp
@@ -77,7 +77,7 @@ _MathUtils::GetShortestDistance(const Location& location, const Tizen::Base::Col
for (int i = 0; i < count; i++)
{
- const _RegionInfo* pRegionInfo = static_cast<const _RegionInfo*> (regionList.GetAt(i));
+ const _RegionInfo* pRegionInfo = static_cast< const _RegionInfo* >(regionList.GetAt(i));
if (pRegionInfo)
{
Coordinates regionCoordinate = pRegionInfo->GetCoordinate();
diff --git a/src/FLoc_MathUtils.h b/src/FLoc_MathUtils.h
index 7459b2d..018026b 100644
--- a/src/FLoc_MathUtils.h
+++ b/src/FLoc_MathUtils.h
@@ -29,7 +29,7 @@
namespace Tizen { namespace Base { namespace Collection
{
- class IList;
+class IList;
}}}
namespace Tizen { namespace Locations
diff --git a/src/FLoc_SyncLocationRequestInfo.h b/src/FLoc_SyncLocationRequestInfo.h
index f286707..e7b72cb 100644
--- a/src/FLoc_SyncLocationRequestInfo.h
+++ b/src/FLoc_SyncLocationRequestInfo.h
@@ -42,28 +42,52 @@ class _SyncLocationRequestInfo
: public Tizen::Base::Object
{
public:
- _SyncLocationRequestInfo(_LocationMonitor* pLocMonitor, RequestId reqId)
+ _SyncLocationRequestInfo(_LocationMonitor* pLocMonitor, RequestId reqId, const Tizen::Base::DateTime& requestTime)
: Tizen::Base::Object()
+ , __oldLocTime(requestTime)
, __pLocMonitor(pLocMonitor)
+ , __pTimer(null)
, __reqId(reqId)
, __tickCount(0)
{
- Tizen::System::SystemTime::GetCurrentTime(__requestTime);
}
~_SyncLocationRequestInfo(void) {}
_LocationMonitor* GetLocationMonitor(void) const {return __pLocMonitor;}
+ result StartTimer(Tizen::Base::Runtime::ITimerEventListener& listener)
+ {
+ result r = E_SUCCESS;
+
+ if (__pTimer == null)
+ {
+ std::unique_ptr< Tizen::Base::Runtime::Timer > pTimer(new (std::nothrow) Tizen::Base::Runtime::Timer());
+ SysTryReturn(NID_LOC, pTimer != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
+ "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+ r = pTimer->Construct(listener);
+ SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to construct the timer.", GetErrorMessage(r));
+
+ __pTimer = std::move(pTimer);
+ }
+
+ const int DEFAULT_TIME_OUT = 1000;
+ r = __pTimer->Start(DEFAULT_TIME_OUT);
+ SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to start the timer.", GetErrorMessage(r));
+ __tickCount++;
+ return E_SUCCESS;
+ }
+
+ bool Equals(const Tizen::Base::Runtime::Timer& timer) {return __pTimer->Equals(timer);}
+
RequestId GetRequestId(void) const {return __reqId;}
int GetTickCount(void) const {return __tickCount;}
- void IncrementTickCount(void) { __tickCount++;}
-
bool IsInTime(const Tizen::Base::DateTime& timestamp)
{
- return (timestamp > __requestTime) ? true : false;
+ SysSecureLog(NID_LOC, "Previous location time is (%ls) and the current location time is (%ls)", __oldLocTime.ToString().GetPointer(), timestamp.ToString().GetPointer());
+ return (timestamp > __oldLocTime) ? true : false;
}
bool IsAccuracySatisfying(LocationAccuracy accuracy)
@@ -84,8 +108,9 @@ private:
_SyncLocationRequestInfo& operator =(const _SyncLocationRequestInfo& rhs);
private:
- Tizen::Base::DateTime __requestTime;
+ Tizen::Base::DateTime __oldLocTime;
_LocationMonitor* __pLocMonitor;
+ std::unique_ptr< Tizen::Base::Runtime::Timer > __pTimer;
RequestId __reqId;
int __tickCount;
}; //_SyncLocationRequestInfo
diff --git a/src/FLoc_WaitLoopListener.h b/src/FLoc_WaitLoopListener.h
deleted file mode 100644
index be41387..0000000
--- a/src/FLoc_WaitLoopListener.h
+++ /dev/null
@@ -1,68 +0,0 @@
-//
-// 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