summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHyungKyu Song <hk76.song@samsung.com>2013-02-16 00:54:53 +0900
committerHyungKyu Song <hk76.song@samsung.com>2013-02-16 00:54:53 +0900
commit8c7894c54c39a04d17933a69bc3fa14f53b3ecad (patch)
tree3dcc50119fd81620ef470dc0b1b6b5649bd57b1e
parentc1a543306e2817a31055185f9163c217d7f3b8e2 (diff)
downloadlocations-tizen_2.0.tar.gz
locations-tizen_2.0.tar.bz2
locations-tizen_2.0.zip
-rw-r--r--AUTHORS4
-rwxr-xr-xCMakeLists.txt81
-rwxr-xr-xLICENSE.APLv2202
-rwxr-xr-xNOTICE3
-rw-r--r--inc/FLocCoordinates.h281
-rw-r--r--inc/FLocILocationProviderListener.h200
-rw-r--r--inc/FLocLocation.h210
-rw-r--r--inc/FLocLocationCriteria.h144
-rwxr-xr-xinc/FLocLocationProvider.h359
-rw-r--r--inc/FLocTypes.h83
-rw-r--r--inc/FLocations.h56
-rw-r--r--osp-location.manifest5
-rwxr-xr-xosp-locations.pc.in14
-rwxr-xr-xpackaging/osp-locations.spec85
-rw-r--r--src/FLocCoordinates.cpp391
-rw-r--r--src/FLocLocation.cpp149
-rw-r--r--src/FLocLocationCriteria.cpp102
-rw-r--r--src/FLocLocationProvider.cpp201
-rw-r--r--src/FLoc_Config.h33
-rw-r--r--src/FLoc_EllipsoidModel.cpp141
-rw-r--r--src/FLoc_EllipsoidModel.h78
-rw-r--r--src/FLoc_ILocProviderEventListener.h84
-rw-r--r--src/FLoc_ILocationManagerListener.h66
-rw-r--r--src/FLoc_LocProviderEventArg.h119
-rw-r--r--src/FLoc_LocationImpl.cpp288
-rw-r--r--src/FLoc_LocationImpl.h205
-rw-r--r--src/FLoc_LocationManager.cpp1393
-rw-r--r--src/FLoc_LocationManager.h308
-rw-r--r--src/FLoc_LocationMonitor.cpp116
-rw-r--r--src/FLoc_LocationMonitor.h75
-rw-r--r--src/FLoc_LocationProviderImpl.cpp923
-rw-r--r--src/FLoc_LocationProviderImpl.h255
-rw-r--r--src/FLoc_LocationRequestInfo.h83
-rw-r--r--src/FLoc_MathUtils.cpp73
-rw-r--r--src/FLoc_MathUtils.h65
-rw-r--r--src/FLoc_RegionInfo.h86
-rw-r--r--src/FLoc_SyncLocationRequestInfo.h117
-rw-r--r--src/FLoc_Types.h54
38 files changed, 7132 insertions, 0 deletions
diff --git a/AUTHORS b/AUTHORS
new file mode 100644
index 0000000..b30f921
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1,4 @@
+NANDAN S R <nandan.sr at samsung dot com>
+PRATTYUSH BANERJEE <prattyush.b samsung dot com>
+HYUNMI KWAK <hyunmi.kwak at samsung dot com>
+MOONBAE SONG <moonbae.song at samsung dot com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100755
index 0000000..49827e9
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,81 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+
+SET (this_target osp-locations)
+
+SET(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/cmake_build_tmp/output)
+
+INCLUDE_DIRECTORIES (
+ ${ROOTSTRAP_ROOT}/usr/include/location
+ inc
+ src
+ /usr/include/osp
+ /usr/include/osp/app
+ /usr/include/osp/base
+ /usr/include/osp/system
+ /usr/include/osp/security
+ )
+
+SET (${this_target}_SOURCE_FILES
+ src/FLocCoordinates.cpp
+ src/FLocLocationCriteria.cpp
+ src/FLocLocation.cpp
+ src/FLocLocationProvider.cpp
+ src/FLoc_EllipsoidModel.cpp
+ src/FLoc_LocationImpl.cpp
+ src/FLoc_LocationManager.cpp
+ src/FLoc_LocationProviderImpl.cpp
+ src/FLoc_MathUtils.cpp
+ src/FLoc_LocationMonitor.cpp
+ )
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wall" )
+
+## SET C COMPILER FLAGS
+SET(CMAKE_C_FLAGS "${OSP_DEBUG_FLAGS} ${OSP_OPT_FLAGS} ${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ${OSP_COMPILER_FLAGS}")
+
+## SET CPP COMPILER FLAGS
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
+SET(CMAKE_CXX_FLAGS "${OSP_DEBUG_FLAGS} ${OSP_OPT_FLAGS} ${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} ${OSP_COMPILER_FLAGS}")
+
+## Create Library
+ADD_LIBRARY (${this_target} SHARED ${${this_target}_SOURCE_FILES})
+
+## SET LINKER FLAGS
+SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
+
+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")
+
+SET_TARGET_PROPERTIES(${this_target}
+ PROPERTIES
+ VERSION ${FULLVER}
+ SOVERSION ${MAJORVER}
+ CLEAN_DIRECT_OUTPUT 1
+ )
+
+ADD_CUSTOM_COMMAND(TARGET ${this_target}
+ POST_BUILD
+ COMMAND ${CMAKE_COMMAND} -E copy ${LIBRARY_OUTPUT_PATH}/${CMAKE_SHARED_LIBRARY_PREFIX}${this_target}${CMAKE_SHARED_LIBRARY_SUFFIX} ${LIBRARY_OUTPUT_PATH}/debug/${CMAKE_SHARED_LIBRARY_PREFIX}${this_target}${CMAKE_SHARED_LIBRARY_SUFFIX}.${FULLVER}
+ COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_SHARED_LIBRARY_PREFIX}${this_target}${CMAKE_SHARED_LIBRARY_SUFFIX}.${FULLVER} ${LIBRARY_OUTPUT_PATH}/debug/${CMAKE_SHARED_LIBRARY_PREFIX}${this_target}${CMAKE_SHARED_LIBRARY_SUFFIX}.${MAJORVER}
+ COMMAND ${CMAKE_STRIP} --strip-unneeded ${LIBRARY_OUTPUT_PATH}/${CMAKE_SHARED_LIBRARY_PREFIX}${this_target}${CMAKE_SHARED_LIBRARY_SUFFIX}
+ COMMENT "strip ${this_target}"
+ )
+
+INSTALL(DIRECTORY ${LIBRARY_OUTPUT_PATH}/ DESTINATION lib/osp
+ FILES_MATCHING PATTERN "*.so*"
+ PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
+ GROUP_EXECUTE GROUP_READ
+ WORLD_EXECUTE WORLD_READ)
+INSTALL(DIRECTORY ${LIBRARY_OUTPUT_PATH}/debug/ DESTINATION lib/osp/debug
+ FILES_MATCHING PATTERN "*.so*"
+ PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
+ GROUP_EXECUTE GROUP_READ
+ WORLD_EXECUTE WORLD_READ)
+
+INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/inc/ DESTINATION include/osp FILES_MATCHING PATTERN "*.h")
+
+# pkgconfig file
+CONFIGURE_FILE(${this_target}.pc.in ${CMAKE_SOURCE_DIR}/${this_target}.pc @ONLY)
+INSTALL(FILES ${CMAKE_SOURCE_DIR}/${this_target}.pc DESTINATION lib/pkgconfig)
diff --git a/LICENSE.APLv2 b/LICENSE.APLv2
new file mode 100755
index 0000000..d645695
--- /dev/null
+++ b/LICENSE.APLv2
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ 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.
diff --git a/NOTICE b/NOTICE
new file mode 100755
index 0000000..b616854
--- /dev/null
+++ b/NOTICE
@@ -0,0 +1,3 @@
+Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
+Except as noted, this software is licensed under Apache License, Version 2.
+Please, see the LICENSE.APLv2 file for Apache License terms and conditions.
diff --git a/inc/FLocCoordinates.h b/inc/FLocCoordinates.h
new file mode 100644
index 0000000..c5d6096
--- /dev/null
+++ b/inc/FLocCoordinates.h
@@ -0,0 +1,281 @@
+//
+// 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 FLocCoordinates.h
+* @brief This is the header file for the %Coordinates class.
+*
+* This header file contains the declarations of the %Coordinates class.
+*/
+
+#ifndef _FLOC_COORDINATES_H_
+#define _FLOC_COORDINATES_H_
+
+#include <FBaseObject.h>
+#include <FLocTypes.h>
+
+namespace Tizen { namespace Base
+{
+class String;
+}}
+
+namespace Tizen { namespace Locations
+{
+
+/**
+* @class Coordinates
+* @brief This class represents a geographical point.
+*
+* @since 2.0
+*
+* @final This class is not intended for extension.
+*
+* The %Coordinates class represents a geographical point specified by latitude, longitude, and altitude values and provides
+* geographic calculations between two points.
+*
+* The latitude and longitude in decimal degrees are sometimes represented in degrees, minutes, and seconds format. For example, 40.1874 degrees
+* can also be represented in "40:11.25"(40 degrees and 11.25 minutes) or "40:11:15.0" (40 degrees, 11 minutes and 15.0 seconds).
+* This class provides methods for converting a coordinate value to degrees and minutes or degrees, minutes, and seconds representation.
+*/
+class _OSP_EXPORT_ Coordinates
+ : public Tizen::Base::Object
+{
+public:
+ /**
+ * Initializes an instance of %Coordinates with the values of latitude, longitude, and altitude to Not-a-Number.
+ *
+ * An application should set values of the coordinates using Set() method to specify it.
+ *
+ * @since 2.0
+ */
+ Coordinates(void);
+
+ /**
+ * Copying of objects using this copy constructor is allowed.
+ *
+ * @since 2.0
+ *
+ * @param[in] rhs An instance of %Coordinates to copy
+ */
+ Coordinates(const Coordinates& rhs);
+
+ /**
+ * This destructor overrides Tizen::Base::Object::~Object().
+ *
+ * @since 2.0
+ */
+ virtual ~Coordinates(void);
+
+ /**
+ * Compares the calling instance with the specified instance for equality.
+ *
+ * @since 2.0
+ *
+ * @return @c true if all the fields in the objects are equal, @n
+ * else @c false
+ * @param[in] rhs The object to compare
+ */
+ virtual bool Equals(const Tizen::Base::Object& rhs) const;
+
+ /**
+ * Gets the hash value of the calling instance.
+ *
+ * @since 2.0
+ *
+ * @return The hash value of the calling instance
+ */
+ virtual int GetHashCode(void) const;
+
+ /**
+ * Sets the latitude, longitude, and altitude values of the coordinates.
+ *
+ * An application should specify latitude and longitude values in the valid ranges of [-90.0, +90.0] and [-180.0, +180.0], respectively.
+ * Otherwise, the %Set() method returns an @c E_INVALID_ARG exception.
+ *
+ * @since 2.0
+ *
+ * @return An error code
+ * @param[in] latitude The latitude of the coordinates in decimal degrees within the range [-90.0, +90.0]
+ * @param[in] longitude The longitude of the coordinates in decimal degrees within the range [-180.0, +180.0]
+ * @param[in] altitude The altitude of the coordinates in meters
+ * @exception E_SUCCESS This method is successful.
+ * @exception E_INVALID_ARG The specified @c latitude or @c longitude is invalid.
+ * @see GetLatitude()
+ * @see GetLongitude()
+ * @see GetAltitude()
+ */
+ result Set(double latitude, double longitude, double altitude);
+
+ /**
+ * Sets the latitude value of the coordinates.
+ *
+ * An application should specify latitude value in the valid range of [-90.0, +90.0].
+ * Otherwise, the %SetLatitude() method returns an @c E_INVALID_ARG exception.
+ *
+ * @since 2.0
+ *
+ * @return An error code
+ * @param[in] latitude The latitude of the coordinates in decimal degrees within the range [-90.0, +90.0]
+ * @exception E_SUCCESS This method is successful.
+ * @exception E_INVALID_ARG The specified @c latitude is invalid.
+ * @see GetLatitude()
+ */
+ result SetLatitude(double latitude);
+
+ /**
+ * Sets the longitude value of the coordinates.
+ *
+ * An application should specify longitude value in the valid range of [-180.0, +180.0].
+ * Otherwise, the %SetLongitude() method returns an @c E_INVALID_ARG exception.
+ *
+ * @since 2.0
+ *
+ * @return An error code
+ * @param[in] longitude The longitude of the coordinates in decimal degrees within the range [-180.0, +180.0]
+ * @exception E_SUCCESS This method is successful.
+ * @exception E_INVALID_ARG The specified @c longitude is invalid.
+ * @see GetLongitude()
+ */
+ result SetLongitude(double longitude);
+
+ /**
+ * Sets the altitude value of the coordinates.
+ *
+ * @since 2.0
+ *
+ * @param[in] altitude The altitude of the coordinates in meters
+ * @see GetAltitude()
+ */
+ void SetAltitude(double altitude);
+
+ /**
+ * Gets the latitude value of the coordinates.
+ *
+ * @since 2.0
+ *
+ * @return The latitude in decimal degrees within the range [-90.0, +90.0], @n
+ * else @c NaN if it is not available
+ * @see SetLatitude()
+ */
+ double GetLatitude(void) const;
+
+ /**
+ * Gets the longitude value of the coordinates.
+ *
+ * @since 2.0
+ *
+ * @return The longitude in decimal degrees within the range [-180.0, +180.0], @n
+ * else @c NaN if it is not available
+ * @see SetLongitude()
+ */
+ double GetLongitude(void) const;
+
+ /**
+ * Gets the altitude value of the coordinates.
+ *
+ * @since 2.0
+ *
+ * @return The altitude in meters, @n
+ * else @c NaN if it is not available
+ * @see SetAltitude()
+ */
+ double GetAltitude(void) const;
+
+ /**
+ * Calculates the azimuth value.
+ *
+ * The coordinates are the starting point and @c dest is the destination for the azimuth calculation.
+ * The azimuth is measured clockwise from true north based on the WGS84 ellipsoid model.
+ *
+ * The altitude value is not considered in calculation.
+ *
+ * @since 2.0
+ *
+ * @return The azimuth value in decimal degrees within the range [0.0, +360.0], @n
+ * else @c NaN if the latitude or the longitude of two points has an @c NaN value
+ * @param[in] dest The destination coordinates
+ */
+ double GetAzimuth(const Coordinates& dest) const;
+
+ /**
+ * Calculates the geodetic distance to the given coordinates.
+ *
+ * The distance calculation is based on the WGS84 ellipsoid model.
+ *
+ * The altitude value is not considered in calculation.
+ *
+ * @since 2.0
+ *
+ * @return The distance to the given coordinates in meters, @n
+ * else @c NaN if the latitude or the longitude of two points has an @c NaN value
+ * @param[in] to The destination coordinates
+ */
+ double GetDistanceTo(const Coordinates& to) const;
+
+ /**
+ * Converts the coordinate value into string.
+ *
+ * An application specifies formats like @c COORDINATE_FORMAT_DEGREE_MINUTE or @c COORDINATE_FORMAT_DEGREE_MINUTE_SECOND for the result string.
+ *
+ * @since 2.0
+ *
+ * @return An error code
+ * @param[in] degree The coordinate in degrees within the range [-180.0, +180.0]
+ * @param[in] format The desired format
+ * @param[out] string The converted result in string
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_INVALID_ARG The specified @c degree or @c format is invalid.
+ * @see Parse()
+ */
+ static result ToString(double degree, CoordinateFormat format, Tizen::Base::String& string);
+
+ /**
+ * Converts a string into coordinate degree.
+ *
+ * The @c string should be in @c COORDINATE_FORMAT_DEGREE_MINUTE or @c COORDINATE_FORMAT_DEGREE_MINUTE_SECOND format.
+ *
+ * @since 2.0
+ *
+ * @return An error code
+ * @param[in] string The string in degree-minute or degree-minute-second representation
+ * @param[out] degree The converted result in decimal degrees
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_INVALID_ARG The specified @c string is not in CoordinateFormat.
+ * @see ToString()
+ */
+ static result Parse(const Tizen::Base::String& string, double& degree);
+
+ /**
+ * Copying of objects using this copy assignment operator is allowed.
+ *
+ * @since 2.0
+ *
+ * @return A reference to the current instance
+ * @param[in] rhs An instance of %Coordinates to assign
+ */
+ Coordinates& operator =(const Coordinates& rhs);
+
+private:
+ double __latitude;
+ double __longitude;
+ double __altitude;
+
+ class _CoordinatesImpl* __pImpl;
+ friend class _CoordinatesImpl;
+}; // Coordinates
+}} // Tizen::Locations
+#endif // _FLOC_COORDINATES_H_
diff --git a/inc/FLocILocationProviderListener.h b/inc/FLocILocationProviderListener.h
new file mode 100644
index 0000000..44b03b9
--- /dev/null
+++ b/inc/FLocILocationProviderListener.h
@@ -0,0 +1,200 @@
+//
+// 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 FLocILocationProviderListener.h
+* @brief This is the header file for the %ILocationProviderListener interface.
+*
+* This header file contains the declarations of the %ILocationProviderListener interface.
+*/
+
+#ifndef _FLOC_ILOCATION_PROVIDER_LISTENER_H_
+#define _FLOC_ILOCATION_PROVIDER_LISTENER_H_
+
+#include <FBaseRtIEventListener.h>
+#include <FLocTypes.h>
+
+namespace Tizen { namespace Locations
+{
+
+class Location;
+
+/**
+* @interface ILocationProviderListener
+* @brief This interface defines listener interfaces to get asynchronous notifications from the location provider.
+*
+* @since 2.0
+*
+* The %ILocationProviderListener interface defines listener interfaces to get asynchronous notifications from the location provider.
+* An application should implement this listener interface and construct the location provider with the listener
+* to get the asynchronous notifications for the location updates and region monitoring requests.
+*
+* @see LocationProvider
+*/
+class _OSP_EXPORT_ ILocationProviderListener
+ : virtual public Tizen::Base::Runtime::IEventListener
+{
+public:
+ /**
+ * This polymorphic destructor should be overridden if required. This way, the destructors of the derived classes are called
+ * when the destructor of this interface is called.
+ *
+ * @since 2.0
+ */
+ virtual ~ILocationProviderListener(void) {}
+
+ /**
+ * Called when the location update is running.
+ *
+ * The location update is started when an application calls the LocationProvider::StartLocationUpdatesByInterval() or LocationProvider::StartLocationUpdatesByDistance() methods.
+ *
+ * Note that, the updated locations may not always fall into the requested accuracy level that the application has specified in the criteria.
+ * The application is able to filter out less accurate locations by checking the location accuracy with the Location::GetHorizontalAccuracy() method
+ * if it matters to the application.
+ *
+ * During updating locations, along with changes in the location's accuracy, changes in the service status are also notified.
+ *
+ * @since 2.0
+ *
+ * @param[in] location The location to update
+ * @remarks An application should implement this method when it requests for the location updates and wants to handle the updated locations.
+ * @see OnAccuracyChanged()
+ * @see OnLocationUpdateStatusChanged()
+ */
+ virtual void OnLocationUpdated(const Tizen::Locations::Location& location) { }
+
+ /**
+ * Called when the location provider detects a movement entering into the registered region.
+ *
+ * A region is registered for monitoring by calling LocationProvider::AddMonitoringRegion() and is identified by the region ID.
+ *
+ * While monitoring regions, the changes in the location's accuracy and the changes in the service status are notified.
+ *
+ * @since 2.0
+ *
+ * @param[in] regionId The ID for the registered region
+ * @remarks An application should implement this method when it requests for the region monitoring and wants to handle the movement into the region.
+ * @see OnAccuracyChanged()
+ * @see OnRegionMonitoringStatusChanged()
+ */
+ virtual void OnRegionEntered(Tizen::Locations::RegionId regionId) { }
+
+ /**
+ * Called when the location provider detects a movement leaving from the registered region.
+ *
+ * A region is registered for monitoring by calling LocationProvider::AddMonitoringRegion() and identified by the region ID.
+ *
+ * While monitoring regions, the changes in the location's accuracy and the changes in the service status are notified.
+ *
+ * @since 2.0
+ *
+ * @param[in] regionId The ID for the registered region
+ * @remarks An application should implement this method when it requests the region monitoring and wants to handle the movement out of the region.
+ * @see OnAccuracyChanged()
+ * @see OnRegionMonitoringStatusChanged()
+ */
+ virtual void OnRegionLeft(Tizen::Locations::RegionId regionId) { }
+
+ /**
+ * Called when the service status of the location updates change.
+ *
+ * The status changes to @c LOC_SVC_STATUS_RUNNING, when the location provider successfully runs the requested service.
+ *
+ * The status changes to @c LOC_SVC_STATUS_NOT_FIXED, when the location provider is not able to run the requested service because it
+ * cannot fix the current location due to poor circumstances such as weak radio for positioning.
+ * When this status continues for a fairly long time, it is recommended to cancel the request. The request should be run after some time in order to avoid excessive battery consumption.
+ *
+ * When the user withdraws the permission for an application to use the location information, the status changes to
+ * @c LOC_SVC_STATUS_DENIED and the location provider stops all ongoing services to the application.
+ * In that case, the application might ask the user to grant permission to continue the aborted service
+ * or to finalize all resources for the location provider.
+ *
+ * The status @c LOC_SVC_STATUS_PAUSED is displayed when the location provider pauses the ongoing service. This happens when the application requests for the location updates without keeping the location updates awake. The status will be changed to others
+ * once the location provider resumes the paused service.
+ *
+ * Note that, the application can get notifications about the location updates and accuracy changes
+ * only when the service status is @c LOC_SVC_STATUS_RUNNING.
+ *
+ * @since 2.0
+ *
+ * @param[in] status The service status of the location updates
+ * @remarks An application should implement this method when it requests for the location updates and wants to handle status changes of the service.
+ */
+ virtual void OnLocationUpdateStatusChanged(Tizen::Locations::LocationServiceStatus status) { }
+
+
+ /**
+ * Called when the service status of the region monitoring changes.
+ *
+ * The status changes to @c LOC_SVC_STATUS_RUNNING, when the location provider successfully runs the requested service.
+ *
+ * The status changes to @c LOC_SVC_STATUS_NOT_FIXED, when the location provider is not able to run the requested service because it
+ * cannot fix the location that is suitable for monitoring the regions.
+ *
+ * When the user withdraws the permission for an application to use the location information, the status changes to
+ * @c LOC_SVC_STATUS_DENIED and the location provider stops all ongoing services to the application.
+ * In that case, the application might ask the user to grant permission to continue the aborted service
+ * or to finalize all resources for the location provider.
+ *
+ * Note that, the application can get notifications about the movement around regions and accuracy changes
+ * only when the service status is @c LOC_SVC_STATUS_RUNNING.
+ *
+ * @since 2.0
+ *
+ * @param[in] status The service status of the region monitoring
+ * @remarks An application should implement this method when it requests for the region monitoring and wants to handle status changes of the service.
+ */
+ virtual void OnRegionMonitoringStatusChanged(Tizen::Locations::LocationServiceStatus status) { }
+
+
+ /**
+ * Called when the accuracy level of the location changes.
+ *
+ * The location provider tries to provide accurate location services as specified in the criteria,
+ * but the location provided by location provider may not always fall into the requested accuracy level.
+ * The %OnAccuracyChanged() listener method is called whenever the current accuracy of the location provided by location provider is changed.
+ *
+ * The accuracy changes to @c LOC_ACCURACY_INVALID when the location provider is not running any services in @c LOC_SVC_STATUS_RUNNING
+ * status.
+ *
+ * @since 2.0
+ *
+ * @param[in] accuracy The accuracy of the location
+ */
+ virtual void OnAccuracyChanged(Tizen::Locations::LocationAccuracy accuracy) = 0;
+
+protected:
+ //
+ //This method is for internal use only. Using this method can cause behavioral, security-related,
+ //and consistency-related issues in the application.
+ //
+ virtual void ILocationProviderListener_Reserved1(void) { }
+
+ //
+ //This method is for internal use only. Using this method can cause behavioral, security-related,
+ //and consistency-related issues in the application.
+ //
+ virtual void ILocationProviderListener_Reserved2(void) { }
+
+ //
+ //This method is for internal use only. Using this method can cause behavioral, security-related,
+ //and consistency-related issues in the application.
+ //
+ virtual void ILocationProviderListener_Reserved3(void) { }
+}; // ILocationProviderListener
+}} // Tizen::Locations
+#endif // _FLOC_ILOCATION_PROVIDER_LISTENER_H_
diff --git a/inc/FLocLocation.h b/inc/FLocLocation.h
new file mode 100644
index 0000000..8163c27
--- /dev/null
+++ b/inc/FLocLocation.h
@@ -0,0 +1,210 @@
+//
+// 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 FLocLocation.h
+ * @brief This is the header file for the %Location class.
+ *
+ * This header file contains the declarations of the %Location class.
+ */
+
+#ifndef _FLOC_LOCATION_H_
+#define _FLOC_LOCATION_H_
+
+#include <FBaseObject.h>
+
+namespace Tizen { namespace Base
+{
+class String;
+class DateTime;
+}}
+
+namespace Tizen { namespace Locations
+{
+class Coordinates;
+
+/**
+* @class Location
+* @brief This class contains and provides information about a location including its geographical coordinates, altitude, and so on.
+*
+* @since 2.0
+*
+* @final This class is not intended for extension.
+*
+* The %Location class contains all information about a location that the location provider fixed at a certain moment.
+* It basically provides geographical coordinates and horizontal accuracy that gives the estimated error about the coordinates,
+* while the altitude, vertical accuracy, speed, and course at the location are optionally provided.
+* It also contains detailed and specific positioning information, such as satellites used to fix the location.
+*
+* An application obtains the %Location instances from LocationProvider.
+*/
+class _OSP_EXPORT_ Location
+ : public Tizen::Base::Object
+{
+public:
+ /**
+ * Copying of objects using this copy constructor is allowed.
+ *
+ * @since 2.0
+ *
+ * @param[in] rhs An instance of %Location to copy
+ */
+ Location(const Location& rhs);
+
+ /**
+ * This destructor overrides Tizen::Base::Object::~Object().
+ *
+ * @since 2.0
+ */
+ virtual ~Location(void);
+
+ /**
+ * Compares the calling instance with the specified instance for equality.
+ *
+ * @since 2.0
+ *
+ * @return @c true if all the fields in the objects are equal, @n
+ * else @c false
+ * @param[in] rhs The object to compare
+ */
+ virtual bool Equals(const Tizen::Base::Object& rhs) const;
+
+ /**
+ * Gets the hash value of the calling instance.
+ *
+ * @since 2.0
+ *
+ * @return The hash value of the calling instance
+ */
+ virtual int GetHashCode(void) const;
+
+ /**
+ * Gets the horizontal accuracy.
+ *
+ * @since 2.0
+ *
+ * @return The horizontal accuracy in meters, @n
+ * else @c NaN if it is not available
+ */
+ double GetHorizontalAccuracy(void) const;
+
+ /**
+ * Gets the vertical accuracy.
+ *
+ * @since 2.0
+ *
+ * @return The vertical accuracy in meters, @n
+ * else @c NaN if it is not available
+ */
+ double GetVerticalAccuracy(void) const;
+
+ /**
+ * Gets the course.
+ *
+ * The course is the angle of moving direction measured clockwise from true north.
+ *
+ * @since 2.0
+ *
+ * @return The course in degrees within the range [0.0, +360.0], @n
+ * else @c NaN if it is not available
+ */
+ double GetCourse(void) const;
+
+ /**
+ * Gets the coordinates.
+ *
+ * @since 2.0
+ *
+ * @return The geographical coordinates
+ */
+ Coordinates GetCoordinates(void) const;
+
+ /**
+ * Gets the ground speed.
+ *
+ * @since 2.0
+ *
+ * @return The speed in km/h, @n
+ * else @c NaN if it is not available
+ */
+ double GetSpeed(void) const;
+
+ /**
+ * Gets the timestamp when this location is fixed.
+ *
+ * @since 2.0
+ *
+ * @return The fix time in UTC
+ */
+ Tizen::Base::DateTime GetTimestamp(void) const;
+
+ /**
+ * Gets the detailed positioning information.
+ *
+ * The detailed positioning information is queried using a key, and the %GetExtraInfo() method returns the information corresponding to the key.
+ * <table>
+ <tr><th>Key</th><th>Information</th></tr>
+ <tr><td>location_method</td><td>Positioning technology used to fix this location. Possible values are "gps" and "network".</td></tr>
+ <tr><td>satellite</td>
+ <td>GPS satellite information in the semicolon-separated satellite sentences.
+ Each sentence forms "PRN, Elevation, Azimuth, SNR, Active" where PRN is a satellite ID, Elevation is in degree, Azimuth is in degree,
+ SNR is a signal to nose ratio in dBHZ, and Active is @c 1, if the satellite is in use for positioning, or @c 0.
+ For example, it can be "02, 40.0, 83.0, 35.0, 1; 15, 30.0, 65.0, 35.0, 0; 22, 80.0, 120.0, 40.0, 1;".</td>
+ </tr></table>
+ *
+ * @since 2.0
+ *
+ * @return The information corresponding to the key, @n
+ * else an empty string if the @c key is invalid or the requested information is not available for this location
+ * @param[in] key The key to the positioning information
+ */
+ Tizen::Base::String GetExtraInfo(const Tizen::Base::String& key) const;
+
+ /**
+ * Checks the validity for this location.
+ *
+ * @since 2.0
+ *
+ * @return @c true if the location is valid, @n
+ * else @c false
+ */
+ bool IsValid(void) const;
+
+ /**
+ * Copying of objects using this copy assignment operator is allowed.
+ *
+ * @since 2.0
+ *
+ * @return A reference to the current instance
+ * @param[in] rhs An instance of %Location to assign
+ */
+ Location& operator =(const Location& rhs);
+
+private:
+ //
+ // This default constructor is intentionally declared as private so that only the platform can create an instance.
+ //
+ // @since 2.0
+ //
+ Location(void);
+
+private:
+ class _LocationImpl* __pImpl;
+ friend class _LocationImpl;
+}; // Location
+}} // Tizen::Locations
+#endif // _FLOC_LOCATION_H_
diff --git a/inc/FLocLocationCriteria.h b/inc/FLocLocationCriteria.h
new file mode 100644
index 0000000..cc62824
--- /dev/null
+++ b/inc/FLocLocationCriteria.h
@@ -0,0 +1,144 @@
+//
+// 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 FLocLocationCriteria.h
+ * @brief This is the header file for the %LocationCriteria class.
+ *
+ * This header file contains the declarations of the %LocationCriteria class.
+ */
+
+#ifndef _FLOC_LOCATION_CRITERIA_H_
+#define _FLOC_LOCATION_CRITERIA_H_
+
+#include <FBaseObject.h>
+#include <FLocTypes.h>
+
+namespace Tizen { namespace Locations
+{
+
+/**
+* @class LocationCriteria
+* @brief This class provides methods to specify the service quality that an application wants for the location provider.
+*
+* @since 2.0
+*
+* @final This class is not intended for extension.
+*
+* The %LocationCriteria class provides methods to specify the service quality that an application wants for the location provider.
+* The application specifies the location criteria based on its scenario and gives it to the location provider.
+*
+* The accuracy in the location criteria is for specifying the accuracy levels for the location provider.
+* The accuracy @c LOC_ACCURACY_ANY is for getting locations of any accuracy that the location provider provides.
+* The application can get more accurate locations as it takes higher accuracy levels from @c LOC_ACCURACY_ONE_KILOMETER,
+* @c LOC_ACCURACY_HUNDRED_METERS, @c LOC_ACCURACY_TEN_METERS, and @c LOC_ACCURACY_FINEST.
+* The application should be aware that higher accuracy levels makes the location provider run costly positioning systems more. Considering proper
+* accuracy levels helps the system to provide efficient services to the user.
+*
+* @see LocationProvider
+*/
+class _OSP_EXPORT_ LocationCriteria
+ : public Tizen::Base::Object
+{
+public:
+ /**
+ * Initializes an instance of %LocationCriteria with the accuracy set to @c LOC_ACCURACY_ANY.
+ *
+ * @since 2.0
+ * @see SetAccuracy()
+ */
+ LocationCriteria(void);
+
+ /**
+ * This is the copy constructor for the %LocationCriteria class.
+ *
+ * Copying of objects using this copy constructor is allowed.
+ *
+ * @since 2.0
+ *
+ * @param[in] rhs An instance of %LocationCriteria to copy
+ */
+ LocationCriteria(const LocationCriteria& rhs);
+
+ /**
+ * This destructor overrides Tizen::Base::Object::~Object().
+ *
+ * @since 2.0
+ */
+ virtual ~LocationCriteria(void);
+
+ /**
+ * Compares the calling instance with the specified instance for equality.
+ *
+ * @since 2.0
+ *
+ * @return @c true if all the fields in the objects are equal, @n
+ * else @c false
+ * @param[in] rhs The object to compare
+ */
+ virtual bool Equals(const Tizen::Base::Object& rhs) const;
+
+ /**
+ * Gets the hash value of the calling instance.
+ *
+ * @since 2.0
+ *
+ * @return The hash value of the calling instance
+ */
+ virtual int GetHashCode(void) const;
+
+ /**
+ * Sets the desired accuracy.
+ *
+ * @since 2.0
+ *
+ * @return An error code
+ * @param[in] accuracy The desired accuracy
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_INVALID_ARG The specified @c accuracy is invalid.
+ * @see GetAccuracy()
+ */
+ result SetAccuracy(LocationAccuracy accuracy);
+
+ /**
+ * Gets the desired accuracy of this location criteria.
+ *
+ * @since 2.0
+ *
+ * @return The accuracy of this location criteria
+ * @see SetAccuracy()
+ */
+ LocationAccuracy GetAccuracy(void) const;
+
+ /**
+ * Copying of objects using this copy assignment operator is allowed.
+ *
+ * @since 2.0
+ *
+ * @return A reference to the current instance
+ * @param[in] rhs An instance of %LocationCriteria to assign
+ */
+ LocationCriteria& operator =(const LocationCriteria& rhs);
+
+private:
+ LocationAccuracy __accuracy;
+
+ class _LocationCriteriaImpl* __pImpl;
+ friend class _LocationCriteriaImpl;
+}; // LocationCriteria
+}} // Tizen::Locations
+#endif // _FLOC_LOCATION_CRITERIA_H_
diff --git a/inc/FLocLocationProvider.h b/inc/FLocLocationProvider.h
new file mode 100755
index 0000000..33a6c60
--- /dev/null
+++ b/inc/FLocLocationProvider.h
@@ -0,0 +1,359 @@
+//
+// 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 FLocLocationProvider.h
+ * @brief This is the header file for the %LocationProvider class.
+ *
+ * This header file contains the declarations of the %LocationProvider class.
+ */
+
+#ifndef _FLOC_LOCATION_PROVIDER_H_
+#define _FLOC_LOCATION_PROVIDER_H_
+
+#include <FBaseObject.h>
+#include <FLocTypes.h>
+
+namespace Tizen { namespace Locations
+{
+class LocationCriteria;
+class Location;
+class ILocationProviderListener;
+
+/**
+* @class LocationProvider
+* @brief This class provides methods to get locations and enable region monitoring.
+*
+* @since 2.0
+*
+* @final This class is not intended for extension.
+*
+* The %LocationProvider class is a fundamental module that provides location-based services: location providing and region monitoring.
+* The location provider is constructed with a location criteria and offers the services trying to satisfy it in a best-effort manner.
+* An application gets locations by simply calling the GetLocation() method, or requesting asynchronous location updates with the
+* StartLocationUpdatesByInterval() and StartLocationUpdatesByDistance() methods. An application can also register regions by calling the
+* AddMonitoringRegion() method to be notified when moving into or out of regions. It gets asynchronous location updates and notifications
+* from the region monitoring by assigning a listener, which implements the ILocationProviderListener interface, to the location provider.
+*
+* @see LocationCriteria
+*/
+class _OSP_EXPORT_ LocationProvider
+ : public Tizen::Base::Object
+{
+public:
+ /**
+ * The object is not fully constructed after this constructor is called. For full construction, the Construct() method must be called right after
+ * calling this constructor.
+ *
+ * @since 2.0
+ */
+ LocationProvider(void);
+
+ /**
+ * This destructor overrides Tizen::Base::Object::~Object().
+ *
+ * @since 2.0
+ */
+ virtual ~LocationProvider(void);
+
+ /**
+ * Initializes this instance of %LocationProvider with the specified @c criteria and @c listener.
+ *
+ * An application chooses the desired service quality based on its scenario and constructs the location provider with the specified
+ * @c criteria. The desired accuracy for locations is a configurable property of LocationCriteria.
+ * The location provider tries to provides locations and services based on the specified @c criteria.
+ *
+ * The @c listener is notified on asynchronous location updates or region monitoring events.
+ *
+ * @since 2.0
+ *
+ * @return An error code
+ * @param[in] criteria The desired location criteria
+ * @param[in] listener The listener to register
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_SYSTEM A system error has occurred.
+ */
+ result Construct(const LocationCriteria& criteria, ILocationProviderListener& listener);
+
+ /**
+ * Requests the location updates service with the specific @c interval.
+ *
+ * Once the location updates have started and the location provider has fixed the current location, the location is delivered
+ * to the listener by calling the ILocationProviderListener::OnLocationUpdated() method.
+ * The location provider is trying to provide accurate locations as requested in the criteria, but locations updated by the location provider
+ * do not always fall into the requested accuracy level. It provides locations in low-grade accuracy if that is all it can offer
+ * or can not even provide locations when it hardly fixes the current location. The location provider notifies the listener whenever the accuracy
+ * level of ongoing updates are changed by calling the ILocationProviderListener::OnAccuracyChanged() method.
+ *
+ * The location updates can be paused by the location provider when the application is unable to point locations out to the user
+ * for the moment. This is possible for the following situations:
+ * - The application is not running in foreground.
+ * - The screen is off.
+ * In this case, the location provider notifies the status @c LOC_SVC_STATUS_PAUSED to the listener.
+ * It resumes the paused location updates when the application gets out of the situations.
+ * To get the location updates all the time, the application should use the KeepLocationUpdateAwake() method.
+ *
+ * The change in the service status that the location provider is providing are notified to the listener
+ * by calling the ILocationProviderListener::OnLocationUpdateStatusChanged() method.
+ *
+ * If the location updates are already started by calling the StartLocationUpdatesByInterval() or StartLocationUpdatesByDistance() methods,
+ * the location provider cancels the prior request and restarts the updates with the specified parameter.
+ *
+ * @since 2.0
+ * @privilege %http://tizen.org/privilege/location
+ *
+ * @return An error code
+ * @param[in] interval The update interval in seconds
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_INVALID_ARG The specified @c interval is less than @c 1.
+ * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
+ * @exception E_USER_NOT_CONSENTED The user blocks an application from using the location information.
+ * @see StopLocationUpdates()
+ */
+ result StartLocationUpdatesByInterval(int interval);
+
+ /**
+ * Requests the location updates service with the specific @c distance filter.
+ *
+ * Once the location updates have started, the initial location is delivered soon after it becomes available to the listener
+ * by calling the ILocationProviderListener::OnLocationUpdated() method. Then the location provider updates subsequent locations
+ * when it changes over the specified @c distance.
+ *
+ * The location updates can be paused by the location provider when the application is unable to point locations out to the user
+ * for the moment. This is possible for the following situations:
+ * - The application is not running in foreground.
+ * - The screen is off.
+ * In this case, the location provider notifies the status @c LOC_SVC_STATUS_PAUSED to the listener.
+ * It resumes the paused location updates when the application gets out of the situations.
+ * To get the location updates all the time, the application should use the KeepLocationUpdateAwake() method.
+ *
+ * Along with the service status, the accuracy level that the location provider is currently providing
+ * is notified to the listener on changes by calling the ILocationProviderListener::OnLocationUpdateStatusChanged()
+ * and ILocationProviderListener::OnAccuracyChanged() methods respectively.
+ *
+ * If the location updates are already started by calling the StartLocationUpdatesByInterval() or StartLocationUpdatesByDistance() methods,
+ * the location provider cancels the prior request and restarts the updates with the specified parameter.
+ *
+ * @since 2.0
+ * @privilege %http://tizen.org/privilege/location
+ *
+ * @return An error code
+ * @param[in] distance The distance in meters
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_INVALID_ARG The specified @c distance is less than or equal to @c 0.0 or @c NaN.
+ * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
+ * @exception E_USER_NOT_CONSENTED The user blocks an application from using the location information.
+ * @see StopLocationUpdates()
+ */
+ result StartLocationUpdatesByDistance(double distance);
+
+ /**
+ * Stops the location updates.
+ *
+ * @since 2.0
+ *
+ * @return An error code
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_INVALID_OPERATION The location updates has not been requested.
+ * @see StartLocationUpdatesByInterval()
+ * @see StartLocationUpdatesByDistance()
+ */
+ result StopLocationUpdates(void);
+
+ /**
+ * Keeps the location updates awake or not.
+ *
+ * The location provider can pause the ongoing location updates when the application is unable to point locations out to the user
+ * for the moment. This is possible for the following situations:
+ * - The application is not running in foreground.
+ * - The screen is off.
+ *
+ * To get the location updates all the time, the application should use the StartLocationUpdatesByInterval() or
+ * StartLocationUpdatesByDistance() methods together with the %KeepLocationUpdateAwake() method turning the flag @c enable on.
+ * The application should be cautious about doing so since it can make the system awake
+ * during the location updates.
+ *
+ * @since 2.0
+ * @privilege %http://tizen.org/privilege/location and %http://tizen.org/privilege/power @n
+ * Both privileges are required.
+ *
+ * @return An error code
+ * @param[in] enable Set to @c true to keep the location updates awake, @n
+ * else @c false
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
+ * @see StartLocationUpdatesByInterval()
+ * @see StartLocationUpdatesByDistance()
+ * @see StopLocationUpdates()
+ */
+ result KeepLocationUpdateAwake(bool enable);
+
+ /**
+ * Adds a region for monitoring.
+ *
+ * A region is defined by a center point and a radius.
+ * The location provider starts the region monitoring service until all regions are removed. When it detects a movement that crosses the
+ * boundary of a registered region, it notifies the application by calling ILocationProviderListener::OnRegionEntered() or
+ * ILocationProviderListener::OnRegionLeft() with the region identifier that is returned by the %AddMonitoringRegion() method.
+ * The altitude of @c regionCenter is not considered in monitoring.
+ *
+ * Along with the service status, the accuracy level that the location provider is currently providing
+ * is notified to the listener on changes by calling the ILocationProviderListener::OnRegionMonitoringStatusChanged()
+ * and ILocationProviderListener::OnAccuracyChanged() methods respectively.
+ *
+ * Note that, the monitoring service can sometimes makes the system awake by running costly positioning devices.
+ *
+ * @since 2.0
+ * @privilege %http://tizen.org/privilege/location and %http://tizen.org/privilege/power @n
+ * Both privileges are required.
+ *
+ * @return An error code
+ * @param[in] regionCenter The center coordinate of the region
+ * @param[in] radius The monitoring radius in meters
+ * @param[out] regionId The ID for the registered region
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_INVALID_ARG The @c radius is not in the supported monitoring raidus range, which currently is [50, 100000] meters, @n
+ * else the @c radius or the latitude or the longitude of @c regionCenter is @c NaN
+ * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
+ * @exception E_USER_NOT_CONSENTED The user blocks an application from using the location information.
+ * @see RemoveMonitoringRegion()
+ * @see RemoveAllMonitoringRegions()
+ */
+ result AddMonitoringRegion(const Coordinates& regionCenter, double radius, RegionId& regionId);
+
+ /**
+ * Removes the monitoring region.
+ *
+ * @since 2.0
+ *
+ * @return An error code
+ * @param[in] regionId The region ID to remove
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_INVALID_ARG The specified @c regionId is invalid.
+ * @see AddMonitoringRegion()
+ */
+ result RemoveMonitoringRegion(RegionId regionId);
+
+ /**
+ * Removes all regions that the location provider monitors.
+ *
+ * @since 2.0
+ *
+ * @see AddMonitoringRegion()
+ */
+ void RemoveAllMonitoringRegions(void);
+
+ /**
+ * Gets the current service status of the location updates.
+ *
+ * The location updates service is started by calling the StartLocationUpdatesByInterval() or StartLocationUpdatesByDistance()
+ * method. If an application has not made valid requests for the service, the %GetLocationUpdateStatus() method returns @c LOC_SVC_STATUS_IDLE.
+ * Otherwise, it returns the service status notified last by the ILocationProviderListener::OnLocationUpdateStatusChanged() listener method.
+ *
+ * @since 2.0
+ * @return The current service status of the location updates
+ */
+ LocationServiceStatus GetLocationUpdateStatus(void) const;
+
+ /**
+ * Gets the current service status of the region monitoring.
+ *
+ * The region monitoring service is started by calling the AddMonitoringRegion() method.
+ * If an application has not made valid requests for the service, the %GetRegionMonitoringStatus() method returns @c LOC_SVC_STATUS_IDLE.
+ * Otherwise, it returns the service status notified last by the ILocationProviderListener::OnRegionMonitoringStatusChanged() listener method.
+ *
+ * @since 2.0
+ * @return The current status of the region monitoring service
+ */
+ LocationServiceStatus GetRegionMonitoringStatus(void) const;
+
+ /**
+ * Gets the accuracy level that the location provider is currently providing.
+ *
+ * If an application has not made valid requests for location updates and region monitoring, the %GetCurrentAccuracy() method
+ * returns @c LOC_ACCURACY_INVALID.
+ * Otherwise, it returns the accuracy level last notified by the ILocationProviderListener::OnAccuracyChanged() listener method.
+ *
+ * @since 2.0
+ * @return The current location accuracy
+ */
+ LocationAccuracy GetCurrentAccuracy(void) const;
+
+ /**
+ * Gets a current location.
+ *
+ * An application can simply get the current location with the %GetLocation() method.
+ *
+ * The location provider runs and waits for positioning systems to fix the current location as requested in the criteria.
+ * If it is not fixed in some time, this method call is aborted and returns a location in low-grade accuracy or even
+ * an invalid location with an @c E_LOCATION_UNAVAILABLE error.
+ *
+ * @since 2.0
+ * @privilege %http://tizen.org/privilege/location
+ *
+ * @return The current location
+ * @param[in] criteria The desired location criteria
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_LOCATION_UNAVAILABLE The location provider fails to fix the current location.
+ * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
+ * @exception E_USER_NOT_CONSENTED The user blocks an application from using the location information.
+ * @exception E_SYSTEM A system error has occurred.
+ * @remarks This method call takes time as the location provider runs and waits for positioning system.
+ * If the method is called from the application's main thread, it makes the application unresponsive until it returns.
+ * If an application wants to be responsive, especially within the user interaction, it should use this method
+ * in a separated thread using Tizen::Base::Runtime::Thread class,
+ * rather than in the application's main thread which handles the ui events.
+ * @remarks The specific error code can be accessed using the GetLastResult() method.
+ */
+ static Location GetLocation(const LocationCriteria& criteria);
+
+ /**
+ * Gets the last known location.
+ *
+ * The %GetLastKnownLocation() method returns the last location the system keeps.
+ * It is always a good idea to prefer using this method than requesting current locations
+ * since using the last location preserves the location provider from running costly positioning systems.
+ *
+ * @since 2.0
+ * @privilege %http://tizen.org/privilege/location
+ *
+ * @return The last location
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_LOCATION_UNAVAILABLE The last location is unavailable.
+ * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
+ * @exception E_USER_NOT_CONSENTED The user blocks an application from using the location information.
+ * @remarks The specific error code can be accessed using the GetLastResult() method.
+ */
+ static Location GetLastKnownLocation(void);
+
+private:
+ //
+ // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
+ //
+ LocationProvider(const LocationProvider& rhs);
+
+ //
+ // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
+ //
+ LocationProvider& operator =(const LocationProvider& rhs);
+
+private:
+ class _LocationProviderImpl* __pImpl;
+ friend class _LocationProviderImpl;
+}; //LocationProvider
+}} // Tizen::Locations
+#endif // _FLOC_LOCATION_PROVIDER_H_
diff --git a/inc/FLocTypes.h b/inc/FLocTypes.h
new file mode 100644
index 0000000..e24341f
--- /dev/null
+++ b/inc/FLocTypes.h
@@ -0,0 +1,83 @@
+//
+// 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 FLocTypes.h
+* @brief This is the header file for the types and constants in the Locations namespace.
+*
+* This header file contains the declarations for the types and constants in the Locations namespace.
+*/
+
+#ifndef _FLOC_TYPES_H_
+#define _FLOC_TYPES_H_
+
+namespace Tizen { namespace Locations
+{
+/**
+* A region ID that identifies a monitoring region registered to LocationProvider.
+*
+* @since 2.0
+*/
+typedef int RegionId;
+
+/**
+* @enum CoordinateFormat
+*
+* Defines the format for angle representation in degrees, minutes, and seconds.
+*
+* @since 2.0
+*/
+enum CoordinateFormat
+{
+ COORDINATE_FORMAT_DEGREE_MINUTE = 0, /**< The "DD:MM.mm" format, where DD is degrees, MM is minutes, and mm is decimal fraction of a minute */
+ COORDINATE_FORMAT_DEGREE_MINUTE_SECOND, /**< The "DD:MM:SS.ss" format, where DD is degrees, MM is minutes, SS is seconds, and ss is decimal fraction of a second */
+};
+
+/**
+* @enum LocationAccuracy
+*
+* Defines the accuracy of the location.
+*
+* @since 2.0
+*/
+enum LocationAccuracy
+{
+ LOC_ACCURACY_INVALID = 0, /**< Invalid accuracy @n The location provider uses this value when the location is not available. */
+ LOC_ACCURACY_FINEST, /**< The accuracy of the location is the finest that the location provider provides */
+ LOC_ACCURACY_TEN_METERS, /**< The accuracy of the location is under 10 meters */
+ LOC_ACCURACY_HUNDRED_METERS, /**< The accuracy of the location is under 100 meters */
+ LOC_ACCURACY_ONE_KILOMETER, /**< The accuracy of the location is under 1 kilometer */
+ LOC_ACCURACY_ANY, /**< The accuracy of the location can be anything that the location provider provides */
+};
+
+/**
+* @enum LocationServiceStatus
+*
+* Defines the location service status that the location provider provides.
+*
+* @since 2.0
+*/
+enum LocationServiceStatus
+{
+ LOC_SVC_STATUS_IDLE = 0, /**< The status of the location service is idle */
+ LOC_SVC_STATUS_RUNNING, /**< The location provider is successfully running the requested service */
+ LOC_SVC_STATUS_PAUSED, /**< The location provider has paused the location service */
+ LOC_SVC_STATUS_DENIED, /**< The location provider is unable to provide services because the user restricted the use of location service */
+ LOC_SVC_STATUS_NOT_FIXED, /**< The location provider is trying to run the service by fixing the current location */
+};
+}} // Tizen::Locations
+#endif // _FLOC_TYPES_H_
diff --git a/inc/FLocations.h b/inc/FLocations.h
new file mode 100644
index 0000000..858d2fc
--- /dev/null
+++ b/inc/FLocations.h
@@ -0,0 +1,56 @@
+//
+// 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 FLocations.h
+ * @brief This is the header file for the %Locations namespace.
+ *
+ * This header file contains the declarations and descriptions of the %Locations namespace.
+ *
+ */
+#ifndef _FLOCATIONS_H_
+#define _FLOCATIONS_H_
+
+// Includes
+#include "FLocCoordinates.h"
+#include "FLocILocationProviderListener.h"
+#include "FLocLocation.h"
+#include "FLocLocationCriteria.h"
+#include "FLocLocationProvider.h"
+#include "FLocTypes.h"
+
+/**
+ * @namespace Tizen::Locations
+ * @brief This namespace contains the classes and interfaces for the location-related information and services.
+ * @since 2.0
+ *
+ * @remarks @b Header @b %file: @b \#include @b <FLocations.h> @n
+ * @b Library : @b osp-locations
+ *
+ * The %Locations namespace contains the classes and interfaces for the location-related information and services.
+ *
+ * For more information on the %Locations namespace features, see <a href="../org.tizen.native.appprogramming/html/guide/locations/locations_namespace.htm">Locations Guide</a>.
+ *
+ * The following diagram illustrates the relationships between the classes belonging to the %Locations namespace.
+ * @image html locations_namespace_classdiagram.png
+ */
+
+namespace Tizen { namespace Locations
+{
+}} // Tizen::Locations
+
+#endif // _FLOCATIONS_H_
diff --git a/osp-location.manifest b/osp-location.manifest
new file mode 100644
index 0000000..ae3e6f7
--- /dev/null
+++ b/osp-location.manifest
@@ -0,0 +1,5 @@
+<manifest>
+ <request>
+ <domain name="_"/>
+ </request>
+</manifest> \ No newline at end of file
diff --git a/osp-locations.pc.in b/osp-locations.pc.in
new file mode 100755
index 0000000..eb6c3b7
--- /dev/null
+++ b/osp-locations.pc.in
@@ -0,0 +1,14 @@
+# Package Information for pkg-config
+
+prefix=@PREFIX@
+exec_prefix=/usr
+libdir=/usr/lib/osp
+includedir=/usr/include/osp
+
+Name: @PC_NAME@
+Description: @PACKAGE_DESCRIPTION@
+Version: @VERSION@
+Requires: @PC_REQUIRED@
+Libs: -L${libdir} @PC_LDFLAGS@
+Cflags: -I${includedir}
+
diff --git a/packaging/osp-locations.spec b/packaging/osp-locations.spec
new file mode 100755
index 0000000..29333a0
--- /dev/null
+++ b/packaging/osp-locations.spec
@@ -0,0 +1,85 @@
+%define debug_package %{nil}
+%define __strip /bin/true
+
+Name: osp-locations
+Summary: osp locations library
+Version: 1.2.0.0
+Release: 2
+Group: System/Libraries
+License: TO_BE/FILLED_IN
+Source0: %{name}-%{version}.tar.gz
+BuildRequires: cmake
+BuildRequires: pkgconfig(capi-location-manager)
+BuildRequires: pkgconfig(osp-appfw)
+BuildRequires: pkgconfig(osp-uifw)
+BuildRequires: osp-appfw-internal-devel
+BuildRequires: osp-uifw-internal-devel
+
+# runtime requires
+Requires: osp-appfw
+Requires: osp-uifw
+
+%description
+osp locations library
+
+%package devel
+Summary: osp locations library (Development)
+Group: TO_BE/FILLED_IN
+Requires: %{name} = %{version}-%{release}
+
+%description devel
+osp locations library (DEV)
+
+%package internal-devel
+Summary: osp locations library (Internal)
+Group: TO_BE/FILLED_IN
+Requires: %{name} = %{version}-%{release}
+
+%description internal-devel
+osp locations library (Internal-DEV)
+
+%package debug
+Summary: osp locations library (Development)
+Group: TO_BE/FILLED_IN
+Requires: %{name} = %{version}-%{release}
+
+%description debug
+osp locations library (DEV)
+
+%prep
+%setup -q
+
+%build
+MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
+%ifarch %{ix86}
+CXXFLAGS="$CXXFLAGS -D_OSP_DEBUG_ -D_OSP_X86_ -D_OSP_EMUL_" cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DFULLVER=%{version} -DMAJORVER=${MAJORVER}
+%else
+CXXFLAGS="-O2 -g -pipe -Wall -fno-exceptions -Wformat -Wformat-security -Wl,--as-needed -fmessage-length=0 -march=armv7-a -mtune=cortex-a8 -mlittle-endian -mfpu=neon -mfloat-abi=softfp -D__SOFTFP__ -mthumb -Wa,-mimplicit-it=thumb -funwind-tables -D_OSP_DEBUG_ -D_OSP_ARMEL_" cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DFULLVER=%{version} -DMAJORVER=${MAJORVER}
+%endif
+
+# Call make instruction with smp support
+make %{?jobs:-j%jobs}
+
+%install
+rm -rf %{buildroot}
+mkdir -p %{buildroot}/usr/share/license
+cp %{_builddir}/%{name}-%{version}/LICENSE.APLv2 %{buildroot}/usr/share/license/%{name}
+
+%make_install
+
+%post -p /sbin/ldconfig
+
+%postun -p /sbin/ldconfig
+
+%files
+/usr/share/license/%{name}
+%{_libdir}/osp/*.so*
+
+%files devel
+%{_includedir}/osp/*.h
+%{_libdir}/pkgconfig/osp-locations.pc
+
+%files internal-devel
+
+%files debug
+%{_libdir}/osp/debug/*.so*
diff --git a/src/FLocCoordinates.cpp b/src/FLocCoordinates.cpp
new file mode 100644
index 0000000..f8e71db
--- /dev/null
+++ b/src/FLocCoordinates.cpp
@@ -0,0 +1,391 @@
+//
+// 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.
+//
+
+#include <new>
+#include <math.h>
+#include <FBaseDouble.h>
+#include <FBaseInteger.h>
+#include <FBaseSysLog.h>
+#include <FBaseUtilMath.h>
+#include <FBaseUtilStringTokenizer.h>
+#include <FLocCoordinates.h>
+#include "FLoc_EllipsoidModel.h"
+#include "FLoc_MathUtils.h"
+#include "FLoc_Types.h"
+
+using namespace Tizen::Base;
+using namespace Tizen::Base::Utility;
+
+namespace Tizen { namespace Locations
+{
+Coordinates::Coordinates(void)
+ : Tizen::Base::Object()
+ , __latitude(Tizen::Locations::NaN)
+ , __longitude(Tizen::Locations::NaN)
+ , __altitude(Tizen::Locations::NaN)
+ , __pImpl(null)
+{
+ SysAssertf(Double::IsNaN(__latitude), "Latitude is not initialized to NaN");
+ SysAssertf(Double::IsNaN(__longitude), "Longitude is not initialized to NaN");
+ SysAssertf(Double::IsNaN(__altitude), "Altitude is not initialized to NaN");
+}
+
+Coordinates::Coordinates(const Coordinates& rhs)
+ : Tizen::Base::Object()
+ , __latitude(rhs.__latitude)
+ , __longitude(rhs.__longitude)
+ , __altitude(rhs.__altitude)
+ , __pImpl(null)
+{
+}
+
+Coordinates::~Coordinates(void)
+{
+}
+
+bool
+Coordinates::Equals(const Tizen::Base::Object& rhs) const
+{
+ const Coordinates* pRhs = dynamic_cast< const Coordinates* >(&rhs);
+
+ if (pRhs == null)
+ {
+ return false;
+ }
+
+ bool latitudeCheck = false;
+ bool longitudeCheck = false;
+ bool altitudeCheck = false;
+
+ if (Double::IsNaN(__latitude) || Double::IsNaN(pRhs->__latitude))
+ {
+ if (Double::IsNaN(__latitude) && Double::IsNaN(pRhs->__latitude))
+ {
+ latitudeCheck = true;
+ }
+ }
+ else if (Double::Compare(__latitude, pRhs->__latitude) == 0)
+ {
+ latitudeCheck = true;
+ }
+
+ if (Double::IsNaN(__longitude) || Double::IsNaN(pRhs->__longitude))
+ {
+ if (Double::IsNaN(__longitude) && Double::IsNaN(pRhs->__longitude))
+ {
+ longitudeCheck = true;
+ }
+ }
+ else
+ {
+ if (Double::Compare(__longitude, pRhs->__longitude) == 0)
+ {
+ longitudeCheck = true;
+ }
+ // Min and max longitudes lines meet together. (longitude -180 == +180)
+ else if (Double::Compare(fabs(__longitude) + fabs(pRhs->__longitude), MAX_LONGITUDE * 2) == 0)
+ {
+ SysLog(NID_LOC, "Both longitudes are equal as 180 is equal to -180");
+ longitudeCheck = true;
+ }
+ }
+
+ if (Double::IsNaN(__altitude) || Double::IsNaN(pRhs->__altitude))
+ {
+ if (Double::IsNaN(__altitude) && Double::IsNaN(pRhs->__altitude))
+ {
+ altitudeCheck = true;
+ }
+ }
+ else if (Double::Compare(__altitude, pRhs->__altitude) == 0)
+ {
+ altitudeCheck = true;
+ }
+
+ return (latitudeCheck && longitudeCheck && altitudeCheck);
+}
+
+int
+Coordinates::GetHashCode(void) const
+{
+ int hashCode = Double::GetHashCode(__latitude) * 37;
+
+ hashCode += Double::GetHashCode(__longitude) * 37;
+ hashCode += Double::GetHashCode(__altitude) * 37;
+
+ return hashCode;
+}
+
+result
+Coordinates::Set(double latitude, double longitude, double altitude)
+{
+ SysTryReturn(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);
+
+ SysTryReturn(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);
+
+ __latitude = latitude;
+ __longitude = longitude;
+ __altitude = altitude;
+
+ return E_SUCCESS;
+}
+
+result
+Coordinates::SetLatitude(double latitude)
+{
+ SysTryReturn(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);
+
+ __latitude = latitude;
+ return E_SUCCESS;
+}
+
+result
+Coordinates::SetLongitude(double longitude)
+{
+ SysTryReturn(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);
+
+ __longitude = longitude;
+ return E_SUCCESS;
+}
+
+void
+Coordinates::SetAltitude(double altitude)
+{
+ __altitude = altitude;
+}
+
+double
+Coordinates::GetLatitude(void) const
+{
+ return __latitude;
+}
+
+double
+Coordinates::GetLongitude(void) const
+{
+ return __longitude;
+}
+
+double
+Coordinates::GetAltitude(void) const
+{
+ return __altitude;
+}
+
+double
+Coordinates::GetAzimuth(const Coordinates& dest) const
+{
+ if ((Double::IsNaN(dest.GetLatitude()) == true) || (Double::IsNaN(dest.GetLongitude()) == true) || (Double::IsNaN(__latitude) == true) || (Double::IsNaN(__longitude) == true))
+ {
+ return Tizen::Locations::NaN;
+ }
+
+ if (Double::Compare(MAX_LATITUDE, GetLatitude()) == 0 && Double::Compare(MAX_LATITUDE, dest.GetLatitude()) != 0)
+ {
+ return 180.0;
+ }
+
+ if (Double::Compare(MIN_LATITUDE, GetLatitude()) == 0 && Double::Compare(MIN_LATITUDE, dest.GetLatitude()) != 0)
+ {
+ return 0.0;
+ }
+
+ if (Equals(dest) ||
+ (Double::Compare(MIN_LATITUDE, GetLatitude()) == 0 && Double::Compare(MIN_LATITUDE, dest.GetLatitude()) == 0) ||
+ (Double::Compare(MAX_LATITUDE, GetLatitude()) == 0 && Double::Compare(MAX_LATITUDE, dest.GetLatitude()) == 0))
+ {
+ return 0.0;
+ }
+
+ return _EllipsoidModel::GetAzimuth(GetLatitude(), GetLongitude(), dest.GetLatitude(), dest.GetLongitude());
+}
+
+double
+Coordinates::GetDistanceTo(const Coordinates& to) const
+{
+ if ((Double::IsNaN(to.GetLatitude()) == true) || (Double::IsNaN(to.GetLongitude()) == true) || (Double::IsNaN(__latitude) == true) || (Double::IsNaN(__longitude) == true))
+ {
+ return Tizen::Locations::NaN;
+ }
+
+ return _EllipsoidModel::GetDistance(GetLatitude(), GetLongitude(), to.GetLatitude(), to.GetLongitude());
+}
+
+result
+Coordinates::ToString(double degree, CoordinateFormat format, Tizen::Base::String& string)
+{
+ SysTryReturn(NID_LOC, format == COORDINATE_FORMAT_DEGREE_MINUTE || format == COORDINATE_FORMAT_DEGREE_MINUTE_SECOND, E_INVALID_ARG, E_INVALID_ARG,
+ "[E_INVALID_ARG] The specified format(%x) is not proper.", format);
+
+ SysTryReturn(NID_LOC, MIN_LONGITUDE <= degree && degree < MAX_LONGITUDE, E_INVALID_ARG, E_INVALID_ARG,
+ "[E_INVALID_ARG] The supplied degree(%lf) is out of [-180, 180] range.", degree);
+
+ double intPart = 0.0;
+ double fractionalPart = 0.0;
+
+ fractionalPart = modf(degree, &intPart);
+ int degreeValue = (int) intPart;
+
+ if (degree < 0)
+ {
+ fractionalPart *= -1.0;
+ }
+
+ String ret;
+ const int bufferSize = 20;
+ if (format == COORDINATE_FORMAT_DEGREE_MINUTE)
+ {
+ double minute = fractionalPart * 60;
+ double minuteFraction = modf(minute, &intPart);
+
+ if (Double::Compare(minuteFraction, 0.0) == 0)
+ {
+ ret.Format(bufferSize, L"%d:%02d", degreeValue, (int) minute);
+ }
+ else
+ {
+ ret.Format(bufferSize, L"%d:%02.5f", degreeValue, minute);
+ }
+ }
+ else // if (COORDINATE_FORMAT_DEGREE_MINUTE_SECOND == outputType)
+ {
+ fractionalPart = modf(fractionalPart * 60, &intPart);
+
+ int minute = (int) intPart;
+ double second = fractionalPart * 60;
+ double secondFraction = modf(second, &intPart);
+
+ if (Double::Compare(second, 0.0) == 0 && Double::Compare(secondFraction, 0.0) == 0)
+ {
+ ret.Format(bufferSize, L"%d:%02d", degreeValue, (int) minute);
+ }
+ else
+ {
+ if (Double::Compare(secondFraction, 0.0) == 0)
+ {
+ ret.Format(bufferSize, L"%d:%02d:%02d", degreeValue, (int) minute, (int) second);
+ }
+ else
+ {
+ ret.Format(bufferSize, L"%d:%02d:%02.3f", degreeValue, (int) minute, second);
+ }
+ }
+ }
+
+ string = ret;
+ return E_SUCCESS;
+}
+
+result
+Coordinates::Parse(const Tizen::Base::String& string, double& degree)
+{
+ result r = E_SUCCESS;
+ double ret = 0.0;
+ CoordinateFormat type = COORDINATE_FORMAT_DEGREE_MINUTE;
+
+ StringTokenizer tokenizer(string, L":");
+ SysTryReturn(NID_LOC, tokenizer.GetTokenCount() <= 3, E_INVALID_ARG, E_INVALID_ARG,
+ "[E_INVALID_ARG] The coordinate(%ls) is in invalid format.", string.GetPointer());
+
+ if (3 == tokenizer.GetTokenCount())
+ {
+ type = COORDINATE_FORMAT_DEGREE_MINUTE_SECOND;
+ }
+
+ String degreeValue(L"0");
+ tokenizer.GetNextToken(degreeValue);
+
+ int sign = 1;
+ int degreeInt = 0;
+ r = Integer::Decode(degreeValue, degreeInt);
+ SysTryReturn(NID_LOC, r == E_SUCCESS, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Failed to decode the degree part.");
+ SysTryReturn(NID_LOC, MIN_LONGITUDE <= degreeInt && degreeInt <= MAX_LONGITUDE, E_INVALID_ARG, E_INVALID_ARG,
+ "[E_INVALID_ARG] Degree(%d) is out of [-180, 180] range.", degreeInt);
+
+ String minute(L"0");
+ if (E_OUT_OF_RANGE == tokenizer.GetNextToken(minute))
+ {
+ degree = degreeInt;
+ return E_SUCCESS;
+ }
+
+ if (degreeInt < 0)
+ {
+ sign = -1;
+ degreeInt *= sign;
+ }
+
+ if (COORDINATE_FORMAT_DEGREE_MINUTE == type) // "DD:MM.DM"
+ {
+ SysTryReturn(NID_LOC, minute.GetLength() <= 8, E_INVALID_ARG, E_INVALID_ARG,
+ "[E_INVALID_ARG] Minute(%ls) is too long.", minute.GetPointer());
+
+ double minuteDouble = 0.0;
+ r = Double::Parse(minute, minuteDouble);
+ SysTryReturn(NID_LOC, r == E_SUCCESS, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Failed to decode the minute part.");
+ SysTryReturn(NID_LOC, 0.0 <= minuteDouble && minuteDouble < 60.0, E_INVALID_ARG, E_INVALID_ARG,
+ "[E_INVALID_ARG] Minute(%f) is out of [0, 60] range.", minuteDouble);
+ ret = sign * (((double) degreeInt) + (minuteDouble / 60.0));
+ }
+ else // if (COORDINATE_FORMAT_DEGREE_MINUTE_SECOND == type) "DD:MM:SS.SM"
+ {
+ String second(L"0");
+ tokenizer.GetNextToken(second);
+ SysTryReturn(NID_LOC, second.GetLength() <= 6, E_INVALID_ARG, E_INVALID_ARG,
+ "[E_INVALID_ARG] Second(%ls) is too long.", second.GetPointer());
+
+ int minuteInt = 0;
+ r = Integer::Decode(minute, minuteInt);
+ SysTryReturn(NID_LOC, r == E_SUCCESS, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Failed to decode the minute part.");
+ SysTryReturn(NID_LOC, 0 <= minuteInt && minuteInt <= 59, E_INVALID_ARG, E_INVALID_ARG,
+ "[E_INVALID_ARG] Minute(%d) is out of [0, 59] range.", minuteInt);
+
+ double secondDouble = 0.0;
+ r = Double::Parse(second, secondDouble);
+ SysTryReturn(NID_LOC, r == E_SUCCESS, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Failed to decode the second part.");
+ SysTryReturn(NID_LOC, 0.0 <= secondDouble && secondDouble < 60.0, E_INVALID_ARG, E_INVALID_ARG,
+ "[E_INVALID_ARG] Second(%f) is out of [0, 60] range.", secondDouble);
+
+ ret = sign * (((double) degreeInt) + ((double) minuteInt / 60.0) + (secondDouble / 3600.0));
+ }
+
+ SysTryReturn(NID_LOC, MIN_LONGITUDE <= ret && ret < MAX_LONGITUDE, E_INVALID_ARG, E_INVALID_ARG,
+ "[E_INVALID_ARG] Converted coordinate(%f) is out of [-180, 180] range.", ret);
+
+ degree = ret;
+ return E_SUCCESS;
+}
+
+Coordinates&
+Coordinates::operator =(const Coordinates& rhs)
+{
+ if (this == &rhs)
+ {
+ return *this;
+ }
+
+ __latitude = rhs.__latitude;
+ __longitude = rhs.__longitude;
+ __altitude = rhs.__altitude;
+
+ return *this;
+}
+}}
diff --git a/src/FLocLocation.cpp b/src/FLocLocation.cpp
new file mode 100644
index 0000000..6e33c17
--- /dev/null
+++ b/src/FLocLocation.cpp
@@ -0,0 +1,149 @@
+//
+// 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.
+//
+
+#include <new>
+#include <FBaseDateTime.h>
+#include <FBaseSysLog.h>
+#include <FLocLocation.h>
+#include "FLoc_LocationImpl.h"
+
+using namespace Tizen::Base;
+
+namespace Tizen { namespace Locations
+{
+
+Location::Location(void)
+ : Tizen::Base::Object()
+ , __pImpl(null)
+{
+ __pImpl = new (std::nothrow) _LocationImpl();
+
+ if (__pImpl == null)
+ {
+ SetLastResult(E_OUT_OF_MEMORY);
+ }
+}
+
+Location::Location(const Location& rhs)
+ : Tizen::Base::Object()
+ , __pImpl(null)
+{
+ __pImpl = new (std::nothrow) _LocationImpl(*_LocationImpl::GetInstance(rhs));
+ if (__pImpl == null)
+ {
+ SetLastResult(E_OUT_OF_MEMORY);
+ }
+}
+
+Location::~Location(void)
+{
+ delete __pImpl;
+}
+
+bool
+Location::Equals(const Tizen::Base::Object& rhs) const
+{
+ SysAssertf(__pImpl != null, "The location object is in an invalid state.");
+
+ const Location* pRhs = dynamic_cast< const Location* >(&rhs);
+
+ if (pRhs == null)
+ {
+ return false;
+ }
+
+ return __pImpl->Equals(*_LocationImpl::GetInstance(*pRhs));
+}
+
+int
+Location::GetHashCode(void) const
+{
+ SysAssertf(__pImpl != null, "The location object is in an invalid state.");
+ return __pImpl->GetHashCode();
+}
+
+double
+Location::GetHorizontalAccuracy(void) const
+{
+ SysAssertf(__pImpl != null, "The location object is in an invalid state.");
+ return __pImpl->GetHorizontalAccuracy();
+}
+
+double
+Location::GetVerticalAccuracy(void) const
+{
+ SysAssertf(__pImpl != null, "The location object is in an invalid state.");
+ return __pImpl->GetVerticalAccuracy();
+}
+
+double
+Location::GetCourse(void) const
+{
+ SysAssertf(__pImpl != null, "The location object is in an invalid state.");
+ return __pImpl->GetCourse();
+}
+
+Coordinates
+Location::GetCoordinates(void) const
+{
+ SysAssertf(__pImpl != null, "The location object is in an invalid state.");
+ return __pImpl->GetCoordinates();
+}
+
+double
+Location::GetSpeed(void) const
+{
+ SysAssertf(__pImpl != null, "The location object is in an invalid state.");
+ return __pImpl->GetSpeed();
+}
+
+Tizen::Base::DateTime
+Location::GetTimestamp(void) const
+{
+ SysAssertf(__pImpl != null, "The location object is in an invalid state.");
+ return __pImpl->GetTimestamp();
+}
+
+Tizen::Base::String
+Location::GetExtraInfo(const Tizen::Base::String& key) const
+{
+ SysAssertf(__pImpl != null, "The location object is in an invalid state.");
+ return __pImpl->GetExtraInfo(key);
+}
+
+bool
+Location::IsValid(void) const
+{
+ SysAssertf(__pImpl != null, "The location object is in an invalid state.");
+ return __pImpl->IsValid();
+}
+
+Location&
+Location::operator =(const Location& rhs)
+{
+ SysAssertf(__pImpl != null, "The location object is in an invalid state.");
+
+ if (this == &rhs)
+ {
+ return *this;
+ }
+
+ *__pImpl = *_LocationImpl::GetInstance(rhs);
+
+ return *this;
+}
+}}
diff --git a/src/FLocLocationCriteria.cpp b/src/FLocLocationCriteria.cpp
new file mode 100644
index 0000000..5753735
--- /dev/null
+++ b/src/FLocLocationCriteria.cpp
@@ -0,0 +1,102 @@
+//
+// 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.
+//
+
+#include <FBaseSysLog.h>
+#include <FSecAccessController.h>
+#include <FLocLocationCriteria.h>
+#include <FSec_AccessControlTypes.h>
+
+using namespace Tizen::Security;
+
+namespace Tizen { namespace Locations
+{
+
+LocationCriteria::LocationCriteria(void)
+ : Tizen::Base::Object()
+ , __accuracy(LOC_ACCURACY_ANY)
+ , __pImpl(null)
+{
+}
+
+LocationCriteria::LocationCriteria(const LocationCriteria& rhs)
+ : Tizen::Base::Object()
+ , __accuracy(rhs.__accuracy)
+ , __pImpl(null)
+{
+}
+
+LocationCriteria::~LocationCriteria(void)
+{
+}
+
+bool
+LocationCriteria::Equals(const Base::Object& rhs) const
+{
+ const LocationCriteria* pRhs = dynamic_cast< const LocationCriteria* >(&rhs);
+
+ if (pRhs == null)
+ {
+ return false;
+ }
+
+ if (__accuracy != pRhs->__accuracy)
+ {
+ return false;
+ }
+
+ return true;
+}
+
+int
+LocationCriteria::GetHashCode(void) const
+{
+ int hashCode = 0;
+
+ hashCode = __accuracy * 37;
+
+ return hashCode;
+}
+
+result
+LocationCriteria::SetAccuracy(LocationAccuracy accuracy)
+{
+ SysTryReturn(NID_LOC, accuracy >= LOC_ACCURACY_FINEST && accuracy <= LOC_ACCURACY_ANY, E_INVALID_ARG, E_INVALID_ARG,
+ "[E_INVALID_ARG] The accuracy value is out of range.");
+
+ __accuracy = accuracy;
+ return E_SUCCESS;
+}
+
+LocationAccuracy
+LocationCriteria::GetAccuracy(void) const
+{
+ return __accuracy;
+}
+
+LocationCriteria&
+LocationCriteria::operator =(const LocationCriteria& rhs)
+{
+ if (this == &rhs)
+ {
+ return *this;
+ }
+
+ __accuracy = rhs.__accuracy;
+
+ return *this;
+}
+}}
diff --git a/src/FLocLocationProvider.cpp b/src/FLocLocationProvider.cpp
new file mode 100644
index 0000000..94ed2ae
--- /dev/null
+++ b/src/FLocLocationProvider.cpp
@@ -0,0 +1,201 @@
+//
+// 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 FLocLocationProvider.cpp
+ * @brief This is the implementation file for the %LocationProvider class.
+ *
+ * This header file contains the definitions of the %LocationProvider class.
+ */
+
+#include <FBaseSysLog.h>
+#include <FLocLocation.h>
+#include <FLocLocationProvider.h>
+#include <FSecAccessController.h>
+#include <FSec_AccessControlTypes.h>
+#include "FLoc_LocationImpl.h"
+#include "FLoc_LocationProviderImpl.h"
+
+using namespace Tizen::Security;
+
+namespace Tizen { namespace Locations
+{
+
+LocationProvider::LocationProvider(void)
+ : Tizen::Base::Object()
+ , __pImpl(null)
+{
+}
+
+LocationProvider::~LocationProvider(void)
+{
+ delete __pImpl;
+}
+
+result
+LocationProvider::Construct(const LocationCriteria& criteria, ILocationProviderListener& listener)
+{
+ SysAssertf(__pImpl == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
+
+ __pImpl = new (std::nothrow) _LocationProviderImpl();
+ SysTryReturnResult(NID_LOC, __pImpl, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ result r = __pImpl->Construct(criteria, listener);
+ SysTryCatch(NID_LOC, r == E_SUCCESS, , r, "[%s] Failed to construct location Provider.", GetErrorMessage(r));
+
+ return E_SUCCESS;
+
+CATCH:
+ delete __pImpl;
+ __pImpl = null;
+ return r;
+}
+
+result
+LocationProvider::StartLocationUpdatesByInterval(int interval)
+{
+ result r = AccessController::CheckPrivilege(_PRV_LOCATION);
+ SysTryReturn(NID_LOC, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
+
+ SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+ r = __pImpl->StartLocationUpdatesByInterval(interval);
+ SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to start the location updates by interval.", GetErrorMessage(r));
+
+ return E_SUCCESS;
+}
+
+result
+LocationProvider::StartLocationUpdatesByDistance(double distance)
+{
+ result r = AccessController::CheckPrivilege(_PRV_LOCATION);
+ SysTryReturn(NID_LOC, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
+
+ SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+ r = __pImpl->StartLocationUpdatesByDistance(distance);
+ SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to start the location updates by distance.", GetErrorMessage(r));
+
+ return E_SUCCESS;
+}
+
+result
+LocationProvider::StopLocationUpdates(void)
+{
+ SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+ result r = __pImpl->StopLocationUpdates();
+ SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to stop the location updates.", GetErrorMessage(r));
+
+ return E_SUCCESS;
+}
+
+result
+LocationProvider::KeepLocationUpdateAwake(bool enable)
+{
+ result r = AccessController::CheckPrivilege(_PRV_LOCATION);
+ SysTryReturn(NID_LOC, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
+
+ r = AccessController::CheckPrivilege(_PRV_POWER);
+ SysTryReturn(NID_LOC, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
+
+ SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+ __pImpl->KeepLocationUpdateAwake(enable);
+ return E_SUCCESS;
+}
+
+result
+LocationProvider::AddMonitoringRegion(const Coordinates& regionCenter, double radius, RegionId& regionId)
+{
+ result r = AccessController::CheckPrivilege(_PRV_LOCATION);
+ SysTryReturn(NID_LOC, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
+
+ r = AccessController::CheckPrivilege(_PRV_POWER);
+ SysTryReturn(NID_LOC, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
+
+ SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+ r = __pImpl->AddMonitoringRegion(regionCenter, radius, regionId);
+ SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to add monitoring region.", GetErrorMessage(r));
+
+ return E_SUCCESS;
+}
+
+result
+LocationProvider::RemoveMonitoringRegion(RegionId regionId)
+{
+ SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+ result r = __pImpl->RemoveMonitoringRegion(regionId);
+ SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to remove monitoring region with Id (%d).", GetErrorMessage(r), regionId);
+
+ return E_SUCCESS;
+}
+
+void
+LocationProvider::RemoveAllMonitoringRegions(void)
+{
+ SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+ return __pImpl->RemoveAllMonitoringRegions();
+}
+
+LocationServiceStatus
+LocationProvider::GetLocationUpdateStatus(void) const
+{
+ SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+ return __pImpl->GetLocationUpdateStatus();
+}
+
+LocationServiceStatus
+LocationProvider::GetRegionMonitoringStatus(void) const
+{
+ SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+ return __pImpl->GetRegionMonitoringStatus();
+}
+
+LocationAccuracy
+LocationProvider::GetCurrentAccuracy(void) const
+{
+ SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+ return __pImpl->GetCurrentAccuracy();
+}
+
+Location
+LocationProvider::GetLocation(const LocationCriteria& criteria)
+{
+ result r = AccessController::CheckPrivilege(_PRV_LOCATION);
+ SysTryReturn(NID_LOC, r == E_SUCCESS, _LocationImpl::GetLocationInstance(), E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
+
+ return _LocationProviderImpl::GetLocation(criteria);
+}
+
+Location
+LocationProvider::GetLastKnownLocation(void)
+{
+ result r = AccessController::CheckPrivilege(_PRV_LOCATION);
+ SysTryReturn(NID_LOC, r == E_SUCCESS, _LocationImpl::GetLocationInstance(), E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
+
+ return _LocationProviderImpl::GetLastKnownLocation();
+}
+
+
+}}
diff --git a/src/FLoc_Config.h b/src/FLoc_Config.h
new file mode 100644
index 0000000..83d336a
--- /dev/null
+++ b/src/FLoc_Config.h
@@ -0,0 +1,33 @@
+//
+// 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_Config.h
+ * @brief This header file contains the constants used in the location namespace internally.
+ *
+ */
+
+#ifndef _FLOC_INTERNAL_CONFIG_H_
+#define _FLOC_INTERNAL_CONFIG_H_
+
+namespace Tizen { namespace Locations
+{
+
+const int MAX_WAIT_TIME_FOR_SYNC_LOC = 5;
+
+}} // Tizen::Locations
+#endif //_FLOC_INTERNAL_CONFIG_H_ \ No newline at end of file
diff --git a/src/FLoc_EllipsoidModel.cpp b/src/FLoc_EllipsoidModel.cpp
new file mode 100644
index 0000000..8143941
--- /dev/null
+++ b/src/FLoc_EllipsoidModel.cpp
@@ -0,0 +1,141 @@
+//
+// 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_EllipsoidModel.h
+ * @brief This is the implementation file for the _EllipsoidModel class.
+ *
+ * This header file contains implementation of the _EllipsoidModel class.
+ */
+
+#include <math.h>
+#include <FBaseDouble.h>
+#include "FLoc_EllipsoidModel.h"
+#include "FLoc_MathUtils.h"
+
+using namespace Tizen::Base;
+
+namespace Tizen { namespace Locations
+{
+
+const double _EllipsoidModel::SEMI_MAJOR_AXIS = 6378137.0; //in meter
+const double _EllipsoidModel::SEMI_MINOR_AXIS = 6356752.3142; // in meter
+const double _EllipsoidModel::FLATTENING = 298.257223563;
+const double _EllipsoidModel::EARTH_RADIUS = _EllipsoidModel::SEMI_MAJOR_AXIS;
+
+float
+_EllipsoidModel::GetDistance(double lat1, double lon1, double lat2, double lon2)
+{
+ return SolveInverseProblem(lat1, lon1, lat2, lon2, RT_DISTANCE);
+}
+
+float
+_EllipsoidModel::GetAzimuth(double lat1, double lon1, double lat2, double lon2)
+{
+ return SolveInverseProblem(lat1, lon1, lat2, lon2, RT_FORWARD_AZIMUTH);
+}
+
+float
+_EllipsoidModel::SolveInverseProblem(double lat1, double lon1, double lat2, double lon2, ResultType type)
+{
+ // References: Direct and inverse solutions of geodesics on the ellipsoid with application of nested equations
+ // The section 4, Inverse Formula, is used.
+ // Instead of the equations (3), (4), and (6), the simplified ones (3a), (4a), and (6a) are adopted.
+
+ const int ITERATION_MAX = 10;
+ const double DELTA_TOLERANCE = 1.0e-12;
+ const double a = EARTH_RADIUS; // WGS-84 major axis (6378137.0)
+ const double b = SEMI_MINOR_AXIS; // WGS-84 semi-minor axis
+ const double f = 1.0 / FLATTENING; // inverse flattening
+
+ double L = (_MathUtils::DEG2RAD* lon2) -(_MathUtils::DEG2RAD* lon1); // difference in longitude, positive east.
+ double U1 = atan((1.0 - f) * tan(_MathUtils::DEG2RAD * lat1)); // reduced latitude
+ double U2 = atan((1.0 - f) * tan(_MathUtils::DEG2RAD * lat2)); // reduced latitude
+
+ double cosU1 = cos(U1);
+ double cosU2 = cos(U2);
+ double sinU1 = sin(U1);
+ double sinU2 = sin(U2);
+ double cosU1cosU2 = cosU1 * cosU2;
+ double sinU1sinU2 = sinU1 * sinU2;
+
+ double sigma = 0.0; // angular distance P1, P2 on the sphere
+ double lambda = L; // difference in longitude on an auxiliary sphere. use L for first approximation.
+ double A = 0.0, B = 0.0, C = 0.0, sinSigma = 0.0, cosSigma = 0.0, cos2SM = 0.0;
+ int i = 0;
+
+ while (i < ITERATION_MAX)
+ {
+ double sinAlpha = 0.0, cosSqAlpha = 0.0, uSq = 0.0, delta = 0.0;
+ double lambdaOld = lambda;
+
+ double cosLambda = cos(lambda);
+ double sinLambda = sin(lambda);
+
+ double t1 = cosU2 * sinLambda;
+ double t2 = cosU1 * sinU2 - sinU1 * cosU2 * cosLambda;
+ sinSigma = sqrt(t1 * t1 + t2 * t2); // (14)
+ cosSigma = sinU1sinU2 + cosU1cosU2 * cosLambda; // (15)
+
+ sigma = atan2(sinSigma, cosSigma); // (16)
+
+ sinAlpha = Double::Compare(sinSigma, 0.0) == 0 ? 0.0 : cosU1cosU2 * sinLambda / sinSigma; // (17)
+ cosSqAlpha = 1.0 - (sinAlpha * sinAlpha);
+ cos2SM = Double::Compare(cosSqAlpha, 0.0) == 0 ? 0.0 : cosSigma - (2.0 * sinU1sinU2 / cosSqAlpha); // (18)
+
+ uSq = cosSqAlpha * ((a * a - b * b) / (b * b)); // u^2 = cos(alpha)^2 * (a^2 = b^2) / b^2
+
+ A = 1.0 + (uSq / 256.0) * (64.0 + uSq * (-12.0 - (5.0 * uSq))); // (3a)
+ B = (uSq / 512.0) * (128.0 + uSq * (-64.0 + (37.0 * uSq))); // (4a)
+ C = (f / 16.0) * cosSqAlpha * (4.0 + f * (4.0 - 3.0 * cosSqAlpha)); // (10)
+
+ lambda = L + ((1.0 - C) * f * sinAlpha * (sigma + C * sinSigma * (cos2SM + (C * cosSigma * (-1.0 + 2.0 * cos2SM * cos2SM))))); // from (11)
+
+ delta = (lambda - lambdaOld) / lambda;
+ if (fabs(delta) < DELTA_TOLERANCE)
+ {
+ break;
+ }
+ ++i;
+ }
+
+ float ret = 0.0F;
+ if (RT_DISTANCE == type)
+ {
+ double deltaSigma = B * sinSigma * (cos2SM + (B / 4.0) * (cosSigma * (-1.0 + 2.0 * cos2SM * cos2SM))); // (6a)
+
+ ret = b * A * (sigma - deltaSigma);
+
+ }
+ else if (RT_FORWARD_AZIMUTH == type)
+ {
+ double cosLambda = cos(lambda);
+ double sinLambda = sin(lambda);
+
+ ret = atan2(cosU2 * sinLambda, cosU1 * sinU2 - sinU1 * cosU2 * cosLambda); // (20)
+
+ if (ret < 0.0F)
+ {
+ ret += _MathUtils::PI2;
+ }
+ ret *= _MathUtils::RAD2DEG;
+ }
+
+ return ret;
+}
+
+} } // Tizen::Locations
diff --git a/src/FLoc_EllipsoidModel.h b/src/FLoc_EllipsoidModel.h
new file mode 100644
index 0000000..68d1195
--- /dev/null
+++ b/src/FLoc_EllipsoidModel.h
@@ -0,0 +1,78 @@
+//
+// 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_EllipsoidModel.h
+ * @brief This is the header file for the _EllipsoidModel class.
+ *
+ * This header file contains declaration of the _EllipsoidModel class.
+ */
+
+#ifndef _FLOC_INTERNAL_ELLIPSOID_MODEL_H_
+#define _FLOC_INTERNAL_ELLIPSOID_MODEL_H_
+
+namespace Tizen { namespace Locations
+{
+
+/**
+ * @class _EllipsoidModel
+ * @since 2.0
+
+ * This class provides fundamental geodetic constants and operations according to the WGS84 datum.
+ *
+ * References:
+ * @li R.E. Deakin and M.N. Hunter, (2009) 'Geodesics on an ellipsoid - Bessel's method'
+ * @li T.Vincenty, 'Direct and inverse solutions of geodesics on the ellipsoid with application of nested equations'
+ */
+class _EllipsoidModel
+{
+public:
+ static const double SEMI_MAJOR_AXIS;
+ static const double SEMI_MINOR_AXIS;
+ static const double FLATTENING;
+ static const double EARTH_RADIUS;
+
+public:
+ /**
+ * Calculates the geodesic distance between the cooridnates P1(lat1, lon1) and P2(lat2, lon2).
+ *
+ * @since 2.0
+ */
+ static float GetDistance(double lat1, double lon1, double lat2, double lon2);
+
+ /**
+ * Calculates the forward azimuth of the cooridnates P1(lat1, lon1) and P2(lat2, lon2).
+ *
+ * @since 2.0
+ */
+ static float GetAzimuth(double lat1, double lon1, double lat2, double lon2);
+
+private:
+ enum ResultType
+ {
+ RT_DISTANCE,
+ RT_FORWARD_AZIMUTH
+ };
+
+ _EllipsoidModel(void);
+ static float SolveInverseProblem(double lat1, double lon1, double lat2, double lon2, ResultType type);
+}; // class _EllipsoidModel
+
+} } // Tizen::Locations
+
+#endif // _FLOC_INTERNAL_ELLIPSOID_MODEL_H_
diff --git a/src/FLoc_ILocProviderEventListener.h b/src/FLoc_ILocProviderEventListener.h
new file mode 100644
index 0000000..3c0934f
--- /dev/null
+++ b/src/FLoc_ILocProviderEventListener.h
@@ -0,0 +1,84 @@
+//
+// 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_ILocProviderEventListener.h
+* @brief This is the header file for the %_ILocProviderEventListener interface.
+*
+* This header file contains the declarations of the %_ILocProviderEventListener interface. @n
+*/
+
+#ifndef _FLOC_ILOC_PROVIDER_EVENT_LISTENER_H_
+#define _FLOC_ILOC_PROVIDER_EVENT_LISTENER_H_
+
+#include <FBaseRtIEventListener.h>
+
+namespace Tizen { namespace Locations
+{
+
+class Location;
+
+/**
+* @interface _ILocationProviderListener
+* @brief This interface provides a listener that receives location update event.
+*
+* @since 2.0
+*/
+
+class _ILocProviderEventListener
+ : virtual public Tizen::Base::Runtime::IEventListener
+{
+public:
+ /**
+ * This is the destructor for this class.
+ *
+ * @since 2.0
+ */
+ virtual ~_ILocProviderEventListener(void) {}
+
+ /**
+ * Called when the event is fired from the location provider impl class to break the context. @n
+ *
+ * @since 2.0
+ *
+ * @param[in] location The received %Location
+ */
+ virtual void OnLocationEventReceivedN(RequestId reqId, Tizen::Locations::Location& location) = 0;
+
+ /**
+ * Called when the callback should be called from the provider context. @n
+ *
+ * @since 2.0
+ *
+ * @param[in] locSvcStatus The current status of the location udpates.
+ */
+ virtual void OnLocationUpdateStatusChanged(Tizen::Locations::LocationServiceStatus locSvcStatus) = 0;
+
+ /**
+ * Called when the callback should be called from the provider context. @n
+ *
+ * @since 2.0
+ *
+ * @param[in] locSvcStatus The current status of the region monitoring.
+ */
+ virtual void OnRegionMonitoringStatusChanged(Tizen::Locations::LocationServiceStatus locSvcStatus) = 0;
+
+}; //_ILocProviderEventListener
+
+}} // Tizen::Locations
+
+#endif // _FLOC_ILOC_PROVIDER_EVENT_LISTENER_H_
diff --git a/src/FLoc_ILocationManagerListener.h b/src/FLoc_ILocationManagerListener.h
new file mode 100644
index 0000000..93cf389
--- /dev/null
+++ b/src/FLoc_ILocationManagerListener.h
@@ -0,0 +1,66 @@
+//
+// 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_ILocationManagerListener.h
+* @brief This is the header file for the %_ILocationManagerListener interface.
+*
+* This header file contains the declarations of the %_ILocationManagerListener interface. @n
+*/
+
+#ifndef _FLOC_ILOCATION_MANAGER_LISTENER_H_
+#define _FLOC_ILOCATION_MANAGER_LISTENER_H_
+
+#include <FBaseRtIEventListener.h>
+
+namespace Tizen { namespace Locations
+{
+
+class Location;
+
+/**
+* @interface _ILocationManagerListener
+* @brief This interface provides a listener that receives location update callback.
+*
+* @since 2.0
+*/
+
+class _ILocationManagerListener
+ : virtual public Tizen::Base::Runtime::IEventListener
+{
+public:
+ /**
+ * This is the destructor for this class.
+ *
+ * @since 2.0
+ */
+ virtual ~_ILocationManagerListener(void) {}
+
+ /**
+ * Called periodically based on the interval defined when location is requested to the location manager. @n
+ *
+ * @since 2.0
+ *
+ * @param[in] location The received %Location
+ */
+ virtual void OnLocationUpdated(RequestId reqId, const Tizen::Locations::Location& location) = 0;
+
+}; //_ILocationManagerListener
+
+}} // Tizen::Locations
+
+#endif // _FLOC_ILOCATION_MANAGER_LISTENER_H_
diff --git a/src/FLoc_LocProviderEventArg.h b/src/FLoc_LocProviderEventArg.h
new file mode 100644
index 0000000..4468117
--- /dev/null
+++ b/src/FLoc_LocProviderEventArg.h
@@ -0,0 +1,119 @@
+//
+// 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_LocProviderEventArg.h
+ * @brief This is the header file for the %_LocProviderEventArg class.
+ *
+ * This header file contains the declarations of the %_LocProviderEventArg class member variables.
+ */
+
+#ifndef _FLOC_INTERNAL_LOC_PROVIDER_EVENT_ARG_H_
+#define _FLOC_INTERNAL_LOC_PROVIDER_EVENT_ARG_H_
+
+#include <FBaseObject.h>
+#include <FBaseRtIEventArg.h>
+#include <FLocTypes.h>
+
+namespace Tizen { namespace Locations
+{
+
+class Location;
+
+enum _LocProviderEventType
+{
+ _LOC_PRV_EVENT_SEND_LOC,
+ _LOC_PRV_EVENT_SEND_LOC_SVC_CB,
+ _LOC_PRV_EVENT_SEND_MONITOR_SVC_CB,
+};
+
+class _LocProviderEventArg
+ : public Tizen::Base::Object
+ , public Tizen::Base::Runtime::IEventArg
+{
+public:
+ _LocProviderEventArg(void)
+ : Tizen::Base::Object()
+ , __pLocation(null)
+ {
+ }
+
+ virtual ~_LocProviderEventArg(void)
+ {
+ delete __pLocation;
+ }
+
+ void SetLocation(Location* pLocation)
+ {
+ if (__pLocation)
+ {
+ delete __pLocation;
+ }
+ __pLocation = pLocation;
+ }
+
+ Location* GetLocationN(void)
+ {
+ Location* pLocation = __pLocation;
+ __pLocation = null;
+ return pLocation;
+ }
+
+ void SetLocServiceStatus(LocationServiceStatus locSvcStatus)
+ {
+ __locSvcStatus = locSvcStatus;
+ }
+
+ LocationServiceStatus GetLocServiceStatus(void)
+ {
+ return __locSvcStatus;
+ }
+
+ void SetEventType(_LocProviderEventType eventType)
+ {
+ __locProvEventType = eventType;
+ }
+
+ _LocProviderEventType GetEventType(void)
+ {
+ return __locProvEventType;
+ }
+
+ void SetRequestId(RequestId reqId)
+ {
+ __reqId = reqId;
+ }
+
+ RequestId GetRequestId(void)
+ {
+ return __reqId;
+ }
+
+private:
+ _LocProviderEventArg(const _LocProviderEventArg& rhs);
+
+ _LocProviderEventArg& operator =(const _LocProviderEventArg& rhs);
+
+private:
+ LocationServiceStatus __locSvcStatus;
+ _LocProviderEventType __locProvEventType;
+ Location* __pLocation;
+ RequestId __reqId;
+}; // class _LocProviderEventArg
+}}
+
+#endif //_FLOC_INTERNAL_LOC_PROVIDER_EVENT_ARG_H_
diff --git a/src/FLoc_LocationImpl.cpp b/src/FLoc_LocationImpl.cpp
new file mode 100644
index 0000000..b072933
--- /dev/null
+++ b/src/FLoc_LocationImpl.cpp
@@ -0,0 +1,288 @@
+//
+// 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.
+//
+
+#include <new>
+#include <unique_ptr.h>
+#include <FBaseColArrayList.h>
+#include <FBaseSysLog.h>
+#include <FBaseDouble.h>
+#include <FBaseDouble.h>
+#include <FBaseUtilMath.h>
+#include <FLocCoordinates.h>
+#include <FLocLocation.h>
+#include "FLoc_LocationImpl.h"
+#include "FLoc_Types.h"
+
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+using namespace Tizen::Base::Utility;
+using namespace std;
+
+namespace Tizen { namespace Locations
+{
+
+_LocationImpl::_LocationImpl(void)
+ : __speed(Tizen::Locations::NaN)
+ , __course(Tizen::Locations::NaN)
+ , __horizontalAccuracy(Tizen::Locations::NaN)
+ , __verticalAccuracy(Tizen::Locations::NaN)
+ , __timestamp(0)
+ , __locationMethod("")
+ , __satelliteInformation("")
+ , __isLocationValid(false)
+ , __isDenied(false)
+{
+}
+
+_LocationImpl::_LocationImpl(const _LocationImpl& rhs)
+ : __coordinate(rhs.__coordinate)
+ , __speed(rhs.__speed)
+ , __course(rhs.__course)
+ , __horizontalAccuracy(rhs.__horizontalAccuracy)
+ , __verticalAccuracy(rhs.__verticalAccuracy)
+ , __timestamp(rhs.__timestamp)
+ , __locationMethod(rhs.__locationMethod)
+ , __satelliteInformation(rhs.__satelliteInformation)
+ , __isLocationValid(rhs.__isLocationValid)
+ , __isDenied(rhs.__isDenied)
+{
+}
+
+_LocationImpl::~_LocationImpl(void)
+{
+}
+
+bool
+_LocationImpl::Equals(const _LocationImpl& rhs) const
+{
+ return *this == rhs;
+}
+
+int
+_LocationImpl::GetHashCode(void) const
+{
+ int hashCode = 0;
+
+ hashCode += __coordinate.GetHashCode();
+ hashCode += Double::GetHashCode(__speed) * 37;
+ hashCode += Double::GetHashCode(__course) * 37;
+ hashCode += Double::GetHashCode(__horizontalAccuracy) * 37;
+ hashCode += Double::GetHashCode(__verticalAccuracy) * 37;
+ hashCode += __locationMethod.GetHashCode();
+ hashCode += __satelliteInformation.GetHashCode();
+ hashCode *= (__isLocationValid ? 37 : 17);
+
+ if (hashCode < 0)
+ {
+ hashCode *= (-1);
+ }
+
+ return hashCode;
+}
+
+DateTime
+_LocationImpl::GetTimestamp(void) const
+{
+ TimeSpan timespan(__timestamp);
+ DateTime dateTime;
+
+ dateTime.SetValue(1970, 1, 1);
+ dateTime.Add(timespan);
+
+ SysLog(NID_LOC, "The location timeStamp is (%ls)", dateTime.ToString().GetPointer());
+
+ return dateTime;
+}
+
+Tizen::Base::String
+_LocationImpl::GetExtraInfo(const Tizen::Base::String& key) const
+{
+ String reqValue = L"";
+
+ if (key.Equals(L"location_method", true))
+ {
+ reqValue = __locationMethod;
+ }
+ else if (key.Equals(L"satellite", true))
+ {
+ reqValue = __satelliteInformation;
+ }
+
+ SysLog(NID_LOC, "Requested information is '%ls' for the key '%ls'.", reqValue.GetPointer(), key.GetPointer());
+
+ return reqValue;
+}
+
+_LocationImpl*
+_LocationImpl::GetInstance(Location& obj)
+{
+ return obj.__pImpl;
+}
+
+const _LocationImpl*
+_LocationImpl::GetInstance(const Location& obj)
+{
+ return obj.__pImpl;
+}
+
+Location*
+_LocationImpl::GetLocationInstanceN(void)
+{
+ Location* pLoc = new (std::nothrow) Location();
+ SysTryReturn(NID_LOC, pLoc != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+ return pLoc;
+}
+
+Location
+_LocationImpl::GetLocationInstance(void)
+{
+ Location invalidLoc;
+
+ return invalidLoc;
+}
+
+result
+_LocationImpl::SetCoordinates(const Coordinates& coordinate)
+{
+ result r = E_SUCCESS;
+
+ r = __coordinate.Set(coordinate.GetLatitude(), coordinate.GetLongitude(), coordinate.GetAltitude());
+ SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Setting the latitude/longitude value failed.", GetErrorMessage(r));
+
+ return E_SUCCESS;
+}
+
+void
+_LocationImpl::SetExtraInfo(const Tizen::Base::String& key, const Tizen::Base::String& value)
+{
+ if (key.Equals(L"location_method", true))
+ {
+ __locationMethod = value;
+ }
+ else if (key.Equals(L"satellite", true))
+ {
+ __satelliteInformation = value;
+ }
+}
+
+_LocationImpl&
+_LocationImpl::operator =(const _LocationImpl& rhs)
+{
+ if (this == &rhs)
+ {
+ return *this;
+ }
+
+ __coordinate = rhs.__coordinate;
+ __speed = rhs.__speed;
+ __course = rhs.__course;
+ __horizontalAccuracy = rhs.__horizontalAccuracy;
+ __verticalAccuracy = rhs.__verticalAccuracy;
+ __timestamp = rhs.__timestamp;
+ __locationMethod = rhs.__locationMethod;
+ __satelliteInformation = rhs.__satelliteInformation;
+ __isLocationValid = rhs.__isLocationValid;
+
+ return *this;
+}
+
+bool
+_LocationImpl::operator ==(const _LocationImpl& rhs) const
+{
+
+ if (!__coordinate.Equals(rhs.__coordinate))
+ {
+ return false;
+ }
+
+ if (__timestamp != rhs.__timestamp)
+ {
+ return false;
+ }
+
+ if (__locationMethod != rhs.__locationMethod)
+ {
+ return false;
+ }
+
+ if (!__satelliteInformation.Equals(rhs.__satelliteInformation))
+ {
+ return false;
+ }
+
+ if (__isLocationValid != rhs.__isLocationValid)
+ {
+ return false;
+ }
+
+ bool speedCheck = false;
+ bool courseCheck = false;
+ bool horAccCheck = false;
+ bool verAccCheck = false;
+
+ if (Double::IsNaN(__speed) || Double::IsNaN(rhs.__speed))
+ {
+ if (Double::IsNaN(__speed) && Double::IsNaN(rhs.__speed))
+ {
+ speedCheck = true;
+ }
+ }
+ else if (Double::Compare(__speed, rhs.__speed) == 0)
+ {
+ speedCheck = true;
+ }
+
+ if (Double::IsNaN(__course) || Double::IsNaN(rhs.__course))
+ {
+ if (Double::IsNaN(__course) && Double::IsNaN(rhs.__course))
+ {
+ courseCheck = true;
+ }
+ }
+ else if (Double::Compare(__course, rhs.__course) == 0)
+ {
+ courseCheck = true;
+ }
+
+ if (Double::IsNaN(__horizontalAccuracy) || Double::IsNaN(rhs.__horizontalAccuracy))
+ {
+ if (Double::IsNaN(__horizontalAccuracy) && Double::IsNaN(rhs.__horizontalAccuracy))
+ {
+ horAccCheck = true;
+ }
+ }
+ else if (Double::Compare(__horizontalAccuracy, rhs.__horizontalAccuracy) == 0)
+ {
+ horAccCheck = true;
+ }
+
+ if (Double::IsNaN(__verticalAccuracy) || Double::IsNaN(rhs.__verticalAccuracy))
+ {
+ if (Double::IsNaN(__verticalAccuracy) && Double::IsNaN(rhs.__verticalAccuracy))
+ {
+ verAccCheck = true;
+ }
+ }
+ else if (Double::Compare(__verticalAccuracy, rhs.__verticalAccuracy) == 0)
+ {
+ verAccCheck = true;
+ }
+
+ return (speedCheck && courseCheck && horAccCheck && verAccCheck);
+}
+
+}}
diff --git a/src/FLoc_LocationImpl.h b/src/FLoc_LocationImpl.h
new file mode 100644
index 0000000..b38caa0
--- /dev/null
+++ b/src/FLoc_LocationImpl.h
@@ -0,0 +1,205 @@
+//
+// 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_LocationImpl.h
+ * @brief This is the header file for the _LocationImpl class.
+ *
+ * This header file contains the declarations of the _LocationImpl class.
+ */
+
+#ifndef _FLOC_INTERNAL_LOCATION_IMPL_H_
+#define _FLOC_INTERNAL_LOCATION_IMPL_H_
+
+#include <unique_ptr.h>
+#include <FBaseObject.h>
+#include <FBaseDateTime.h>
+#include <FLocCoordinates.h>
+#include <FLocLocation.h>
+#include "FLoc_Types.h"
+
+namespace Tizen { namespace Locations
+{
+
+class _LocationImpl
+{
+
+public:
+ /**
+ * This is the default constructor for this class.
+ */
+ _LocationImpl(void);
+
+ /**
+ * This is the copy constructor for the _LocationImpl class.
+ */
+ _LocationImpl(const _LocationImpl& rhs);
+
+ /**
+ * This is the destructor for this class.
+ */
+ virtual ~_LocationImpl(void);
+
+ /**
+ * @see @ref Tizen::Locations::Location::Equals()
+ */
+ virtual bool Equals(const _LocationImpl& rhs) const;
+
+ /**
+ * @see @ref Tizen::Locations::Location::GetHashCode()
+ */
+ virtual int GetHashCode(void) const;
+
+ /**
+ * @see @ref Tizen::Locations::Location::GetHorizontalAccuracy()
+ */
+ double GetHorizontalAccuracy(void) const {return __horizontalAccuracy;}
+
+ /**
+ * @see @ref Tizen::Locations::Location::GetVerticalAccuracy()
+ */
+ double GetVerticalAccuracy(void) const {return __verticalAccuracy;}
+
+ /**
+ * @see @ref Tizen::Locations::Location::GetCourse()
+ */
+ double GetCourse(void) const { return __course;}
+
+ /**
+ * @see @ref Tizen::Locations::Location::GetCoordinate()
+ */
+ Coordinates GetCoordinates(void) const { return __coordinate;}
+
+ /**
+ * @see @ref Tizen::Locations::Location::GetSpeed()
+ */
+ double GetSpeed(void) const { return __speed;}
+
+ /**
+ * @see @ref Tizen::Locations::Location::GetTimestamp()
+ */
+ Tizen::Base::DateTime GetTimestamp(void) const;
+
+ /**
+ * @see @ref Tizen::Locations::Location::GetExtraInfo()
+ */
+ Tizen::Base::String GetExtraInfo(const Tizen::Base::String& key) const;
+
+ /**
+ * @see @ref Tizen::Locations::Location::IsValid()
+ */
+ bool IsValid(void) const {return __isLocationValid;}
+
+ /**
+ * Sets the horizonal Accuracy value of the %_LocationImpl instance
+ */
+ void SetHorizontalAccuracy(double horizontalAcc) {__horizontalAccuracy = horizontalAcc;}
+
+ /**
+ * Sets the vertical Accuracy value of the %_LocationImpl instance
+ */
+ void SetVerticalAccuracy(double verticalAcc) {__verticalAccuracy = verticalAcc;}
+
+ /**
+ * Sets the course value of the %_LocationImpl instance
+ */
+ void SetCourse(double course) { __course = course;}
+
+ /**
+ * Sets the Coordinate value of the %_LocationImpl instance
+ */
+ result SetCoordinates(const Coordinates& coordinate);
+
+ /**
+ * Sets the speed value of the %_LocationImpl instance
+ */
+ void SetSpeed(double speed) { __speed = speed;}
+
+ /**
+ * Sets the Time stamp value of the %_LocationImpl instance
+ */
+ void SetTimestamp(long long timestamp) {__timestamp = timestamp;}
+
+ /**
+ * Sets the Satellite Information of the %_LocationImpl instance
+ */
+ void SetExtraInfo(const Tizen::Base::String& key, const Tizen::Base::String& value);
+
+ /**
+ * Sets the validity of the location.
+ */
+ void SetValidity(bool validity){__isLocationValid = validity;}
+
+ //
+ // Gets the timestamp in ms.
+ //
+ long long GetTimestampInMs(void){return __timestamp;}
+
+ //
+ // Turns on the denied flag.
+ //
+ void TurnOnDeniedFlag(void) {__isDenied = true;}
+
+ //
+ // Returns the denied flag.
+ //
+ bool IsDenied(void) {return __isDenied;}
+
+ /**
+ * Gets the Impl instance of the given %Location object
+ */
+ static _LocationImpl* GetInstance(Location& obj);
+
+ /**
+ * Gets the Impl instance of the given %Location object
+ */
+ static const _LocationImpl* GetInstance(const Location& obj);
+
+ //
+ //@Internal: Gets the new instance of %Location.
+ //
+ static Location* GetLocationInstanceN(void);
+
+ //
+ //@Internal: Gets the new instance of %Location.
+ //
+ static Location GetLocationInstance(void);
+
+ /**
+ * Assigns the value of the specified _LocationImpl object to the current instance.
+ */
+ _LocationImpl& operator =(const _LocationImpl& rhs);
+
+ /**
+ * Compares the calling instance with the specified instance.
+ */
+ bool operator ==(const _LocationImpl& rhs) const;
+
+private:
+ Coordinates __coordinate;
+ double __speed;
+ double __course;
+ double __horizontalAccuracy;
+ double __verticalAccuracy;
+ long long __timestamp;
+ Tizen::Base::String __locationMethod;
+ Tizen::Base::String __satelliteInformation;
+ bool __isLocationValid;
+ bool __isDenied;
+}; // _LocationImpl
+} } // Tizen::Location
+#endif // _FLOC_INTERNAL_LOCATION_IMPL_H_
diff --git a/src/FLoc_LocationManager.cpp b/src/FLoc_LocationManager.cpp
new file mode 100644
index 0000000..6c1002d
--- /dev/null
+++ b/src/FLoc_LocationManager.cpp
@@ -0,0 +1,1393 @@
+//
+// 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_LocationManager.cpp
+ * @brief This is the implementation file for the %_LocationManager class.
+ *
+ * This implementation file contains the definitions of the %_LocationManager class.
+ */
+
+#include <cassert>
+#include <iostream>
+#include <pthread.h>
+#include <unique_ptr.h>
+#include <FBaseColArrayList.h>
+#include <FBaseInteger.h>
+#include <FBaseBoolean.h>
+#include <FBaseRtMutex.h>
+#include <FBaseRtTimer.h>
+#include <FBaseRtMonitor.h>
+#include <FBaseSysLog.h>
+#include <FLocCoordinates.h>
+#include <FSysSystemTime.h>
+#include <FSys_PowerManagerImpl.h>
+#include "FLoc_Config.h"
+#include "FLoc_LocationImpl.h"
+#include "FLoc_LocationManager.h"
+#include "FLoc_LocationMonitor.h"
+#include "FLoc_LocationRequestInfo.h"
+#include "FLoc_SyncLocationRequestInfo.h"
+
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+using namespace Tizen::Base::Runtime;
+using namespace Tizen::Base::Utility;
+using namespace Tizen::System;
+using namespace std;
+
+namespace Tizen { namespace Locations
+{
+
+_LocationManager* _LocationManager::__pUniqueInstance = null;
+
+_LocationManager::_LocationManager(void)
+ : Tizen::Base::Runtime::EventDrivenThread()
+ , __locMethodRequested(LOC_METHOD_REQUESTED_NONE)
+ , __locationMgrState(LOC_MGR_STATE_IDLE)
+ , __minRequestedAccuracy(LOC_ACCURACY_INVALID)
+ , __nativeGPSServiceState(LOCATIONS_SERVICE_DISABLED)
+ , __nativeWPSServiceState(LOCATIONS_SERVICE_DISABLED)
+ , __nativeCPSServiceState(LOCATIONS_SERVICE_DISABLED)
+ , __timerInterval(0)
+ , __timerTicks(0)
+ , __gpsHandler(null)
+ , __wpsHandler(null)
+ , __cpsHandler(null)
+ , __pCurrentLocation(null)
+ , __pLocRequestInfoList(null)
+ , __pSyncLocRequestInfoList(null)
+ , __pLocUpdateTimer(null)
+{
+}
+
+_LocationManager::~_LocationManager(void)
+{
+}
+
+result
+_LocationManager::StartLocationUpdates(LocationAccuracy accuracy, int interval, _ILocationManagerListener* pListener, RequestId& reqId)
+{
+ static RequestId nextLocRequestId = 1;
+
+ result r = E_SUCCESS;
+ 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< _LocationRequestInfo > pLocRequestInfo(new (std::nothrow) _LocationRequestInfo(accuracy, interval, pListener, nextLocRequestId));
+ SysTryReturn(NID_LOC, pLocRequestInfo, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ r = pArgList->Construct(ARRAY_LIST_CAPACITY);
+ SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Array Construct failed. Propogating.", GetErrorMessage(r));
+
+ r = pArgList->Add(*pLocRequestInfo);
+ SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Arraylist addition of an object failed. Propogating", GetErrorMessage(r));
+
+ pLocRequestInfo.release();
+
+ r = SendUserEvent(REQ_ID_START_LOC_UPDATES, pArgList.get());
+ SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to send the user event. Propagating.", GetErrorMessage(r));
+
+ reqId = nextLocRequestId;
+ nextLocRequestId++;
+
+ pArgList.release();
+
+ SysLog(NID_LOC, "Request ID (%ld) is assigned for the location request with accuracy (%d) and interval (%d).", reqId, accuracy, interval);
+
+ return E_SUCCESS;
+}
+
+result
+_LocationManager::StopLocationUpdates(RequestId reqId)
+{
+ SysLog(NID_LOC, "Location update stop requested for request ID (%d).", reqId);
+
+ result r = E_SUCCESS;
+ 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));
+
+ 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_LOC_UPDATES, 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;
+}
+
+result
+_LocationManager::RegisterLocationMonitor(_LocationMonitor* pLocationMonitor)
+{
+ RequestId reqId;
+ const int ARRAY_LIST_CAPACITY = 1;
+
+ 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< 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));
+
+ r = pArgList->Construct(ARRAY_LIST_CAPACITY);
+ SysTryCatch(NID_LOC, r == E_SUCCESS, , r, "[%s] Array Construct failed. Propogating.", GetErrorMessage(r));
+
+ r = pArgList->Add(*pSyncLocationRequestInfo.get());
+ SysTryCatch(NID_LOC, r == E_SUCCESS, , r, "[%s] Arraylist addition of an object failed. Propogating.", GetErrorMessage(r));
+
+ pSyncLocationRequestInfo.release();
+
+ r = SendUserEvent(REQ_ID_SYNC_LOC_RETRIEVAL, pArgList.get());
+ SysTryCatch(NID_LOC, r == E_SUCCESS, , r, "[%s] Failed to send the user event. Propagating.", GetErrorMessage(r));
+
+ pArgList.release();
+
+ return E_SUCCESS;
+
+CATCH:
+ StopLocationUpdates(reqId);
+ return r;
+}
+
+Location
+_LocationManager::GetLastKnownLocation(void)
+{
+ Location location = _LocationImpl::GetLocationInstance();
+
+ Monitor synchronizer;
+ result r = synchronizer.Construct();
+ SysTryReturn(NID_LOC, r == E_SUCCESS, location, r, "[%s] Propogating.", GetErrorMessage(r));
+
+ std::unique_ptr< Tizen::Base::Collection::ArrayList > pArgList(new (std::nothrow) ArrayList());
+ SysTryReturn(NID_LOC, pArgList, location, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+ r = pArgList->Construct();
+ SysTryReturn(NID_LOC, r == E_SUCCESS, location, r, "[%s] Propogating.", GetErrorMessage(r));
+
+ r = pArgList->Add(location);
+ SysTryReturn(NID_LOC, r == E_SUCCESS, location, r, "[%s] Propogating.", GetErrorMessage(r));
+ r = pArgList->Add(synchronizer);
+ SysTryCatch(NID_LOC, r == E_SUCCESS, pArgList->RemoveAll(false), r, "[%s] Propogating", GetErrorMessage(r));
+
+ r = synchronizer.Enter();
+ SysTryCatch(NID_LOC, r == E_SUCCESS, pArgList->RemoveAll(false), r, "[%s] Propogating", GetErrorMessage(r));
+
+ r = SendUserEvent(REQ_ID_GET_LAST_LOCATION, pArgList.get());
+ SysTryCatch(NID_LOC, r == E_SUCCESS, pArgList->RemoveAll(false); synchronizer.Exit(), r, "[%s] Propogating", GetErrorMessage(r));
+ pArgList.release();
+
+ SysLog(NID_LOC, "Wait the location manager to get the last location.");
+ 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());
+
+ return location;
+
+CATCH:
+ return location;
+}
+
+LocationAccuracy
+_LocationManager::GetAccuracyLevel(double horAcc) const
+{
+ if (horAcc <= 5.0)
+ {
+ return LOC_ACCURACY_FINEST;
+ }
+ else if (horAcc <= 10.0)
+ {
+ return LOC_ACCURACY_TEN_METERS;
+ }
+ else if (horAcc <= 100.0)
+ {
+ return LOC_ACCURACY_HUNDRED_METERS;
+ }
+ else if (horAcc <= 1000.0)
+ {
+ return LOC_ACCURACY_ONE_KILOMETER;
+ }
+ else if (horAcc <= 10000.0)
+ {
+ return LOC_ACCURACY_ANY;
+ }
+ else
+ {
+ return LOC_ACCURACY_INVALID;
+ }
+}
+
+bool
+_LocationManager::IsAppEnabled(void)
+{
+ Boolean enable(false);
+ Monitor synchronizer;
+ result r = synchronizer.Construct();
+ SysTryReturn(NID_LOC, r == E_SUCCESS, false, r, "[%s] Propogating.", GetErrorMessage(r));
+
+ std::unique_ptr< Tizen::Base::Collection::ArrayList > pArgList(new (std::nothrow) ArrayList());
+ SysTryReturn(NID_LOC, pArgList, false, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+ r = pArgList->Construct();
+ SysTryReturn(NID_LOC, r == E_SUCCESS, false, r, "[%s] Propogating.", GetErrorMessage(r));
+
+ r = pArgList->Add(enable);
+ SysTryCatch(NID_LOC, r == E_SUCCESS, , r, "[%s] Propogating", GetErrorMessage(r));
+ r = pArgList->Add(synchronizer);
+ SysTryCatch(NID_LOC, r == E_SUCCESS, , r, "[%s] Propogating", GetErrorMessage(r));
+
+ r = synchronizer.Enter();
+ SysTryCatch(NID_LOC, r == E_SUCCESS, , r, "[%s] Propogating", GetErrorMessage(r));
+
+ r = SendUserEvent(REQ_ID_GET_APP_ACCESSIBILITY, pArgList.get());
+ SysTryCatch(NID_LOC, r == E_SUCCESS, synchronizer.Exit(), r, "[%s] Propogating", GetErrorMessage(r));
+ pArgList.release();
+
+ SysLog(NID_LOC, "Wait the location manager to check the app is allowed to use location.");
+ r = synchronizer.Wait();
+ SysTryCatch(NID_LOC, r == E_SUCCESS, synchronizer.Exit(), r, "[%s] Propogating", GetErrorMessage(r));
+ SysLog(NID_LOC, "Application setting state is '%ls'.", enable.ToString().GetPointer());
+ synchronizer.Exit();
+
+ return enable.ToBool();
+
+CATCH:
+ return false;
+}
+
+_LocationManager*
+_LocationManager::GetInstance(void)
+{
+ static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
+ if (__pUniqueInstance == null)
+ {
+ ClearLastResult();
+ pthread_once(&onceBlock, InitLocationManager);
+
+ result r = GetLastResult();
+ if (IsFailed(r))
+ {
+ onceBlock = PTHREAD_ONCE_INIT;
+ }
+ }
+
+ return __pUniqueInstance;
+}
+
+void
+_LocationManager::AddToLocRequestInfoList(const _LocationRequestInfo* pLocRequestInfo)
+{
+ std::unique_ptr< _LocationRequestInfo > pNewLocRequestInfo(new (std::nothrow) _LocationRequestInfo(*pLocRequestInfo));
+ SysTryReturnVoidResult(NID_LOC, pNewLocRequestInfo, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+ __pLocRequestInfoList->Add(*pNewLocRequestInfo.get());
+ pNewLocRequestInfo.release();
+
+ if (__minRequestedAccuracy == LOC_ACCURACY_INVALID)
+ {
+ result r = _PowerManagerImpl::PowerControl(1, 1);
+ SysTryReturnVoidResult(NID_LOC, r == E_SUCCESS, r, "[%s] Failed to keep the CPU in awake state.", GetErrorMessage(r));
+ }
+
+ SysLog(NID_LOC, "Total count of request info is (%d).", __pLocRequestInfoList->GetCount());
+ RestartLocationUpdates();
+ RestartUpdateTimer();
+}
+
+void
+_LocationManager::RemoveFromLocRequestInfoList(RequestId reqId)
+{
+ const int LIST_COUNT_ZERO = 0;
+
+ int count = __pLocRequestInfoList->GetCount();
+
+ for (int i = 0; i < count; i++)
+ {
+ const _LocationRequestInfo* pLocRequestInfo = static_cast< const _LocationRequestInfo* >(__pLocRequestInfoList->GetAt(i));
+ if (reqId == pLocRequestInfo->GetRequestId())
+ {
+ __pLocRequestInfoList->RemoveAt(i);
+ break;
+ }
+ }
+
+ SysLog(NID_LOC, "Total count of request info is (%d).", __pLocRequestInfoList->GetCount());
+
+ if (__pLocRequestInfoList->GetCount() == LIST_COUNT_ZERO)
+ {
+ _PowerManagerImpl::PowerControl(1, 0);
+
+ __pLocUpdateTimer->Cancel();
+ location_manager_stop(__gpsHandler);
+ location_manager_stop(__wpsHandler);
+ location_manager_stop(__cpsHandler);
+
+ Reset();
+ }
+ else
+ {
+ RestartLocationUpdates();
+ RestartUpdateTimer();
+ }
+}
+
+void
+_LocationManager::AddToSyncLocationRequestInfoList(_SyncLocationRequestInfo& syncLocRequestInfo)
+{
+ result r = E_SUCCESS;
+
+ r = syncLocRequestInfo.StartTimer(*this);
+ SysTryCatch(NID_LOC, r == E_SUCCESS, , r, "[%s] Failed to start the sync timer.", GetErrorMessage(r));
+
+ r = __pSyncLocRequestInfoList->Add(syncLocRequestInfo);
+ SysTryCatch(NID_LOC, r == E_SUCCESS, , r, "[%s] Failed to add the sync request into the list.", GetErrorMessage(r));
+
+ return;
+
+CATCH:
+ StopLocationUpdates(syncLocRequestInfo.GetRequestId());
+ syncLocRequestInfo.GetLocationMonitor()->Notify();
+ delete &syncLocRequestInfo;
+}
+
+void
+_LocationManager::RemoveSyncLocRetrievalRequest(_SyncLocationRequestInfo& syncLocRequestInfo)
+{
+ StopLocationUpdates(syncLocRequestInfo.GetRequestId());
+ __pSyncLocRequestInfoList->Remove(syncLocRequestInfo, true);
+}
+
+void
+_LocationManager::RestartLocationUpdates(void)
+{
+ int count = __pLocRequestInfoList->GetCount();
+ int result = 0;
+ bool isAccuracyChanged = false;
+
+ for (int i = 0; i < count; i++)
+ {
+ const _LocationRequestInfo* pLocRequestInfo = static_cast< const _LocationRequestInfo* >(__pLocRequestInfoList->GetAt(i));
+ if (__minRequestedAccuracy > pLocRequestInfo->GetAccuracy() || __minRequestedAccuracy == LOC_ACCURACY_INVALID)
+ {
+ __minRequestedAccuracy = pLocRequestInfo->GetAccuracy();
+ isAccuracyChanged = true;
+ }
+ }
+
+ if (!isAccuracyChanged)
+ {
+ return;
+ }
+
+ SysLog(NID_LOC, "Location updates are restarted and new minimum requested Accuracy is (%d).", __minRequestedAccuracy);
+
+ __pLocUpdateTimer->Cancel();
+
+ location_manager_stop(__gpsHandler);
+ location_manager_stop(__wpsHandler);
+ location_manager_stop(__cpsHandler);
+
+ __nativeGPSServiceState = LOCATIONS_SERVICE_DISABLED;
+ __nativeWPSServiceState = LOCATIONS_SERVICE_DISABLED;
+ __nativeCPSServiceState = LOCATIONS_SERVICE_DISABLED;
+
+
+ result = location_manager_start(__gpsHandler);
+ SysTryLog(NID_LOC, result == 0, "Failed to start the location updates for GPS.");
+
+ result = location_manager_start(__wpsHandler);
+ SysTryLog(NID_LOC, result == 0, "Failed to start the location updates for WPS.");
+
+ result = location_manager_start(__cpsHandler);
+ SysTryLog(NID_LOC, result == 0, "Failed to start the location updates for CPS.");
+
+ __locationMgrState = LOC_MGR_STATE_FAST_SENSING;
+ __locMethodRequested = LOC_METHOD_REQUESTED_ALL;
+
+}
+
+void
+_LocationManager::RestartUpdateTimer(void)
+{
+ int gcd = 1;
+ int count = __pLocRequestInfoList->GetCount();
+ result r = E_SUCCESS;
+
+ if (count > 0)
+ {
+ const _LocationRequestInfo* pLocRequestInfo = static_cast< _LocationRequestInfo* >(__pLocRequestInfoList->GetAt(0));
+ gcd = pLocRequestInfo->GetInterval();
+
+
+ for (int i = 1; i < count; i++)
+ {
+ pLocRequestInfo = static_cast< const _LocationRequestInfo* >(__pLocRequestInfoList->GetAt(i));
+ int interval = pLocRequestInfo->GetInterval();
+
+ if (gcd != interval)
+ {
+ while (gcd != 0 && interval != 0)
+ {
+ ((gcd > interval) ? gcd : interval) %= ((gcd > interval) ? interval : gcd);
+ }
+ gcd += interval;
+ }
+ }
+ }
+
+ __timerInterval = gcd;
+ __timerTicks = 0;
+
+ SysLog(NID_LOC, "Updated Timer interval is (%d).", __timerInterval);
+
+ r = __pLocUpdateTimer->Start(__timerInterval * 1000);
+ if (IsFailed(r))
+ {
+ SysLog(NID_LOC, "Failed to start the Location update timer.");
+ }
+}
+
+void
+_LocationManager::HandleSyncRetrievalTimerExpiry(_SyncLocationRequestInfo& syncLocRequestInfo)
+{
+ LocationAccuracy accuracy = LOC_ACCURACY_INVALID;
+ DateTime timestamp = DateTime::GetMinValue();
+
+ Location location = GetRecentLocationAvailable();
+ SysLog(NID_LOC, "Location(timestamp: %ls, validity: %x, accuracy: %f) is retrieved.",
+ location.GetTimestamp().ToString().GetPointer(), location.IsValid(), location.GetHorizontalAccuracy());
+ if (location.IsValid())
+ {
+ accuracy = GetAccuracyLevel(location.GetHorizontalAccuracy());
+ timestamp = location.GetTimestamp();
+ }
+
+ bool inTime = syncLocRequestInfo.IsInTime(timestamp);
+ bool accurate = syncLocRequestInfo.IsAccuracySatisfying(accuracy);
+ if (inTime && accurate)
+ {
+ unique_ptr< Location > pLocation(new (std::nothrow) Location(location));
+ SysTryCatchLabel(NID_LOC, pLocation != null, , NOTIFY, E_OUT_OF_MEMORY,
+ "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+ syncLocRequestInfo.GetLocationMonitor()->SetLocation(pLocation.get());
+ pLocation.release();
+
+ goto NOTIFY;
+ }
+ if (syncLocRequestInfo.GetTickCount() > MAX_WAIT_TIME_FOR_SYNC_LOC)
+ {
+ if (inTime)
+ {
+ unique_ptr< Location > pLocation(new (std::nothrow) Location(location));
+ SysTryCatchLabel(NID_LOC, pLocation != null, , NOTIFY, E_OUT_OF_MEMORY,
+ "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+ syncLocRequestInfo.GetLocationMonitor()->SetLocation(pLocation.get());
+ pLocation.release();
+
+ goto NOTIFY;
+ }
+ else
+ {
+ SysLog(NID_LOC, "Unable to fix the current location in %d ticks.", MAX_WAIT_TIME_FOR_SYNC_LOC);
+ goto NOTIFY;
+ }
+ }
+
+ SysLog(NID_LOC, "Wait for next location(Tick: %d).", syncLocRequestInfo.GetTickCount());
+ syncLocRequestInfo.StartTimer(*this);
+ return;
+
+NOTIFY:
+ syncLocRequestInfo.GetLocationMonitor()->Notify();
+ RemoveSyncLocRetrievalRequest(syncLocRequestInfo);
+}
+
+result
+_LocationManager::SetLocationInformation(double latitude, double longitude, double altitude, time_t timestamp, location_method_e locMethod)
+{
+ SysLog(NID_LOC, "Location Information is: Latitude (%lf), Longitude (%lf), Altitude (%lf), TimeStamp (%ld), Location method (%d)", latitude, longitude, altitude, timestamp, locMethod);
+
+ int res = -1;
+ LocationAccuracy requiredAcc;
+ int rangeValue = 0;
+
+ //Accuracy details.
+ location_accuracy_level_e accLevel = LOCATIONS_ACCURACY_NONE;
+ double horAcc = Tizen::Locations::NaN;
+ double verAcc = Tizen::Locations::NaN;
+
+ //Velocity details.
+ double climb = Tizen::Locations::NaN;
+ double direction = Tizen::Locations::NaN;
+ double speed = Tizen::Locations::NaN;
+ time_t time_stamp = 0;
+
+ RequestId requestId;
+
+ Location locationData = _LocationImpl::GetLocationInstance();
+ _LocationImpl* pLocDataImpl = _LocationImpl::GetInstance(locationData);
+
+ switch (locMethod)
+ {
+ case LOCATIONS_METHOD_GPS:
+ {
+ res = location_manager_get_accuracy(__gpsHandler, &accLevel, &horAcc, &verAcc);
+ SysLog(NID_LOC, "Get Accuracy: Result (%d), Horizontal Acc (%lf), Vertical Acc (%lf)", res, horAcc, verAcc);
+ SysTryReturnResult(NID_LOC, res == 0, E_SYSTEM, "Invalid accuracy values from Native Location Provider.");
+
+ res = location_manager_get_velocity(__gpsHandler, &climb, &direction, &speed, &time_stamp);
+ SysLog(NID_LOC, "Get Velocity: Result (%d), Climb (%lf), Direction (%lf), Speed (%lf), Time stamp (%ld)", res, climb, direction, speed, time_stamp);
+ SysTryReturnResult(NID_LOC, res == 0, E_SYSTEM, "Invalid accuracy values from Native Location Provider.");
+
+ pLocDataImpl->SetExtraInfo(L"location_method", L"gps");
+ requestId = REQ_ID_SUSTAIN_GPS;
+ }
+ break;
+
+ case LOCATIONS_METHOD_WPS:
+ {
+ res = location_manager_get_accuracy(__wpsHandler, &accLevel, &horAcc, &verAcc);
+ SysLog(NID_LOC, "Get Accuracy: Result (%d), Horizontal Acc (%lf), Vertical Acc (%lf)", res, horAcc, verAcc);
+ SysTryReturnResult(NID_LOC, res == 0, E_SYSTEM, "Invalid accuracy values from Native Location Provider.");
+
+ res = location_manager_get_velocity(__wpsHandler, &climb, &direction, &speed, &time_stamp);
+ SysTryLog(NID_LOC, res == 0, "Get Velocity: Result (%d), Climb (%lf), Direction (%lf), Speed (%lf), Time stamp (%ld)", res, climb, direction, speed, time_stamp);
+
+ pLocDataImpl->SetExtraInfo(L"location_method", L"network");
+ requestId = REQ_ID_SUSTAIN_WPS;
+ }
+ break;
+
+ case LOCATIONS_METHOD_CPS:
+ {
+ res = location_manager_get_accuracy(__cpsHandler, &accLevel, &horAcc, &verAcc);
+ SysLog(NID_LOC, "Get Accuracy: Result (%d), Horizontal Acc (%lf), Vertical Acc (%lf)", res, horAcc, verAcc);
+ SysTryReturnResult(NID_LOC, res == 0, E_SYSTEM, "Invalid accuracy values from Native Location Provider.");
+
+ pLocDataImpl->SetExtraInfo(L"location_method", L"network");
+ requestId = REQ_ID_SUSTAIN_CPS;
+ }
+ break;
+
+ default:
+ SysTryReturn(NID_LOC, false, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The location method is not valid");
+
+ }
+
+ Coordinates coordinates;
+ coordinates.Set(latitude, longitude, altitude);
+ pLocDataImpl->SetCoordinates(coordinates);
+ pLocDataImpl->SetHorizontalAccuracy(horAcc);
+ pLocDataImpl->SetVerticalAccuracy(verAcc);
+ pLocDataImpl->SetTimestamp((long long) timestamp * 1000);
+ pLocDataImpl->SetCourse(direction);
+ pLocDataImpl->SetSpeed(speed);
+ pLocDataImpl->SetValidity(true);
+ *__pCurrentLocation = locationData;
+
+ requiredAcc = __minRequestedAccuracy;
+ switch (requiredAcc)
+ {
+ case LOC_ACCURACY_FINEST:
+ rangeValue = ACCURACY_FINEST;
+ break;
+
+ case LOC_ACCURACY_TEN_METERS:
+ rangeValue = ACCURACY_TEN_MTRS;
+ break;
+
+ case LOC_ACCURACY_HUNDRED_METERS:
+ rangeValue = ACCURACY_HUNDRED_MTRS;
+ break;
+
+ case LOC_ACCURACY_ONE_KILOMETER:
+ rangeValue = ACCURACY_ONE_KILOMETER;
+ break;
+
+ case LOC_ACCURACY_ANY:
+ rangeValue = ACCURACY_ANY;
+ break;
+
+ case LOC_ACCURACY_INVALID:
+ // follow through
+ default:
+ SysAssertf(false, "The Accuracy value is not defined.");
+ }
+
+ if (__locationMgrState == LOC_MGR_STATE_FAST_SENSING && horAcc <= rangeValue)
+ {
+ SysLog(NID_LOC, "State is LOC_MGR_STATE_FAST_SENSING and accuracy is within range. RequestId is (%d)", requestId);
+ __locationMgrState = LOC_MGR_STATE_FAST_SENSING_SETTLED;
+ SendUserEvent(requestId, null);
+ }
+ else if (__locationMgrState == LOC_MGR_STATE_FAST_SENSING_SETTLED && horAcc > rangeValue)
+ {
+ SysLog(NID_LOC, "State is LOC_MGR_STATE_FAST_SENSING_SETTLED and accuracy is out of range. Restart location updates.");
+ SendUserEvent(REQ_ID_RESTART_LOC_UPDATES, null);
+ }
+
+ return E_SUCCESS;
+}
+
+void
+_LocationManager::SendLocationCallbacks(void)
+{
+ bool isAllowed = GetAppAccessibility();
+ SysLog(NID_LOC, "Send location(validity: %x) and accessibility(%x) through the callback.", __pCurrentLocation->IsValid(), isAllowed);
+
+ unique_ptr< Location > pLocation(new (std::nothrow) Location(*__pCurrentLocation));
+ SysTryReturnVoidResult(NID_LOC, pLocation != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ int interval = __timerTicks * __timerInterval;
+ for (int i = 0; i < __pLocRequestInfoList->GetCount(); i++)
+ {
+ const _LocationRequestInfo* pLocRequestInfo = static_cast< const _LocationRequestInfo* >(__pLocRequestInfoList->GetAt(i));
+ if (interval % pLocRequestInfo->GetInterval() == 0 && pLocRequestInfo->GetListener() != null)
+ {
+ if (!isAllowed)
+ {
+ _LocationImpl::GetInstance(*pLocation)->TurnOnDeniedFlag();
+ }
+ pLocRequestInfo->GetListener()->OnLocationUpdated(pLocRequestInfo->GetRequestId(), *pLocation.get());
+ }
+ }
+}
+
+void
+_LocationManager::Reset(void)
+{
+ __locMethodRequested = LOC_METHOD_REQUESTED_NONE;
+ __locationMgrState = LOC_MGR_STATE_IDLE;
+ __minRequestedAccuracy = LOC_ACCURACY_INVALID;
+ __timerInterval = 0;
+ __timerTicks = 0;
+ __nativeGPSServiceState = LOCATIONS_SERVICE_DISABLED;
+ __nativeWPSServiceState = LOCATIONS_SERVICE_DISABLED;
+ __nativeCPSServiceState = LOCATIONS_SERVICE_DISABLED;
+}
+
+result
+_LocationManager::Construct()
+{
+ return EventDrivenThread::Construct();
+}
+
+bool
+_LocationManager::OnStart(void)
+{
+ int res = -1;
+ result r = E_SUCCESS;
+
+ unique_ptr< Mutex > pMutex(new (std::nothrow) Mutex());
+ SysTryReturn(NID_LOC, pMutex != null, false, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ r = pMutex->Create();
+ SysTryReturn(NID_LOC, r == E_SUCCESS, false, E_SYSTEM, "[E_SYSTEM] Failed to construct the mutex.");
+
+ std::unique_ptr< Tizen::Base::Collection::ArrayList, AllElementsDeleter > pLocInfoRequestList(new (std::nothrow) ArrayList());
+ SysTryReturn(NID_LOC, pLocInfoRequestList != null, false, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ 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());
+ 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.");
+
+ unique_ptr< Tizen::Locations::Location > pLocation(_LocationImpl::GetLocationInstanceN());
+ SysTryReturn(NID_LOC, pLocation != null, false, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ std::unique_ptr< Tizen::Base::Runtime::Timer > pLocUpdateTimer(new (std::nothrow) Timer());
+ r = pLocUpdateTimer->Construct(*this);
+ SysTryReturn(NID_LOC, r == E_SUCCESS, false, E_SYSTEM, "[E_SYSTEM] Failed to construct the location timer.");
+
+ res = location_manager_create(LOCATIONS_METHOD_GPS, &__gpsHandler);
+ SysTryReturn(NID_LOC, res == 0, false, E_SYSTEM, "[E_SYSTEM] Failed to create Native GPS Location provider.");
+
+ res = location_manager_set_service_state_changed_cb(__gpsHandler, GpsServiceUpdateCallback, this);
+ SysTryCatch(NID_LOC, res == 0, , E_SYSTEM, "[E_SYSTEM] Failed to register service callback for Native GPS Location provider.");
+
+ res = location_manager_create(LOCATIONS_METHOD_WPS, &__wpsHandler);
+ SysTryCatch(NID_LOC, res == 0, , E_SYSTEM, "[E_SYSTEM] Failed to create Native WPS Location provider.");
+
+ res = location_manager_set_service_state_changed_cb(__wpsHandler, WpsServiceUpdateCallback, this);
+ SysTryCatch(NID_LOC, res == 0, , E_SYSTEM, "[E_SYSTEM] Failed to register service callback for Native WPS Location provider.");
+
+ res = location_manager_create(LOCATIONS_METHOD_CPS, &__cpsHandler);
+ SysTryCatch(NID_LOC, res == 0, , E_SYSTEM, "[E_SYSTEM] Failed to create Native CPS Location provider.");
+
+ res = location_manager_set_service_state_changed_cb(__cpsHandler, CpsServiceUpdateCallback, this);
+ SysTryCatch(NID_LOC, res == 0, , E_SYSTEM, "[E_SYSTEM] Failed to register service callback for Native CPS Location provider.");
+
+ __pLocRequestInfoList = std::move(pLocInfoRequestList);
+ __pSyncLocRequestInfoList = std::move(pSyncLocInfoRequestList);
+ __pLocUpdateTimer = std::move(pLocUpdateTimer);
+ __pCurrentLocation = std::move(pLocation);
+
+ return true;
+
+CATCH:
+ if (__gpsHandler)
+ {
+ location_manager_destroy(__gpsHandler);
+ }
+
+ if (__wpsHandler)
+ {
+ location_manager_destroy(__wpsHandler);
+ }
+
+ if (__cpsHandler)
+ {
+ location_manager_destroy(__cpsHandler);
+ }
+ return false;
+}
+
+void
+_LocationManager::OnStop(void)
+{
+ if (__gpsHandler)
+ {
+ location_manager_destroy(__gpsHandler);
+ }
+
+ if (__wpsHandler)
+ {
+ location_manager_destroy(__wpsHandler);
+ }
+
+ if (__cpsHandler)
+ {
+ location_manager_destroy(__cpsHandler);
+ }
+}
+
+void
+_LocationManager::OnUserEventReceivedN(RequestId requestId, IList* pArgs)
+{
+ const int ARRAY_LIST_CAPACITY = 1;
+
+ switch (requestId)
+ {
+ case REQ_ID_START_LOC_UPDATES:
+ {
+ SysLog(NID_LOC, "REQ_ID_START_LOC_UPDATES");
+ SysTryReturnVoidResult(NID_LOC, pArgs, E_INVALID_ARG, "[E_INVALID_ARG] Null argument encountered. Ignored.");
+ _LocationRequestInfo* pLocRequestInfo = null;
+ SysTryCatch(NID_LOC, pArgs->GetCount() == ARRAY_LIST_CAPACITY, pArgs->RemoveAll(true), E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument encountered. Ignored.");
+ pLocRequestInfo = static_cast< _LocationRequestInfo* >(pArgs->GetAt(0));
+ SysTryCatch(NID_LOC, pLocRequestInfo, , E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument encountered. Ignored.");
+
+ AddToLocRequestInfoList(pLocRequestInfo);
+ }
+ break;
+
+ case REQ_ID_STOP_LOC_UPDATES:
+ {
+ SysLog(NID_LOC, "REQ_ID_STOP_LOC_UPDATES");
+ 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.");
+
+ RemoveFromLocRequestInfoList(static_cast< long >(pReqId->ToInt()));
+ }
+ break;
+
+ case REQ_ID_RESTART_LOC_UPDATES:
+ {
+ SysLog(NID_LOC, "REQ_ID_RESTART_LOC_UPDATES.");
+ RestartLocationUpdates();
+ }
+ break;
+
+ case REQ_ID_SUSTAIN_GPS:
+ {
+ SysLog(NID_LOC, "REQ_ID_SUSTAIN_GPS.");
+ location_manager_stop(__wpsHandler);
+ location_manager_stop(__cpsHandler);
+ __locMethodRequested = LOC_METHOD_REQUESTED_GPS;
+ }
+ break;
+
+ case REQ_ID_SUSTAIN_WPS:
+ {
+ SysLog(NID_LOC, "REQ_ID_SUSTAIN_WPS.");
+ location_manager_stop(__gpsHandler);
+ location_manager_stop(__cpsHandler);
+ __locMethodRequested = LOC_METHOD_REQUESTED_WPS;
+ }
+ break;
+
+ case REQ_ID_SUSTAIN_CPS:
+ {
+ SysLog(NID_LOC, "REQ_ID_SUSTAIN_CPS.");
+ location_manager_stop(__gpsHandler);
+ location_manager_stop(__wpsHandler);
+ __locMethodRequested = LOC_METHOD_REQUESTED_CPS;
+ }
+ break;
+
+ case REQ_ID_SYNC_LOC_RETRIEVAL:
+ {
+ SysLog(NID_LOC, "REQ_ID_SYNC_LOC_RETRIEVAL.");
+ SysTryReturnVoidResult(NID_LOC, pArgs, E_INVALID_ARG, "[E_INVALID_ARG] Null argument encountered. Ignored.");
+ _SyncLocationRequestInfo* pSyncLocRequestInfo = null;
+ SysTryCatch(NID_LOC, pArgs->GetCount() == ARRAY_LIST_CAPACITY, , E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument encountered. Ignored.");
+ pSyncLocRequestInfo = static_cast< _SyncLocationRequestInfo* >(pArgs->GetAt(0));
+ SysTryCatch(NID_LOC, pSyncLocRequestInfo, , E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument encountered. Ignored.");
+
+ AddToSyncLocationRequestInfoList(*pSyncLocRequestInfo);
+
+ pArgs->RemoveAt(0);
+ }
+ break;
+
+ case REQ_ID_GET_APP_ACCESSIBILITY:
+ {
+ SysLog(NID_LOC, "REQ_ID_GET_APP_ACCESSIBILITY");
+ SysTryReturnVoidResult(NID_LOC, pArgs, E_INVALID_ARG, "[E_INVALID_ARG] Null argument encountered. Ignored.");
+
+ Boolean* pEnabled = static_cast< Boolean* >(pArgs->GetAt(0));
+ Monitor* pMonitor = static_cast< Monitor* >(pArgs->GetAt(1));
+ SysAssertf(pEnabled != null && pMonitor != null, "Invalid request has been made on the location manager.");
+ if (pMonitor != null)
+ {
+ pMonitor->Enter();
+ if (pEnabled != null)
+ {
+ pEnabled->value = GetAppAccessibility();
+ }
+ pMonitor->Notify();
+ pMonitor->Exit();
+ }
+ pArgs->RemoveAt(1);
+ pArgs->RemoveAt(0);
+ }
+ break;
+
+ case REQ_ID_GET_LAST_LOCATION:
+ {
+ SysLog(NID_LOC, "REQ_ID_GET_LAST_LOCATION");
+ SysTryReturnVoidResult(NID_LOC, pArgs, E_INVALID_ARG, "[E_INVALID_ARG] Null argument encountered. Ignored.");
+
+ Location* pLocation = static_cast< Location* >(pArgs->GetAt(0));
+ Monitor* pMonitor = static_cast< Monitor* >(pArgs->GetAt(1));
+ SysAssertf(pLocation != null && pMonitor != null, "Invalid request has been made on the location manager.");
+ if (pMonitor != null)
+ {
+ pMonitor->Enter();
+ if (pLocation != null)
+ {
+ *pLocation = GetRecentLocationAvailable();
+ }
+ pMonitor->Notify();
+ pMonitor->Exit();
+ }
+ pArgs->RemoveAt(1);
+ pArgs->RemoveAt(0);
+ }
+ break;
+ }
+
+ if (pArgs)
+ {
+ pArgs->RemoveAll(true);
+ delete pArgs;
+ }
+
+ return;
+
+CATCH:
+ pArgs->RemoveAll(true);
+ delete pArgs;
+}
+
+void
+_LocationManager::OnTimerExpired(Tizen::Base::Runtime::Timer& timer)
+{
+ const int MAX_VALID_TIME_DIFFERENCE = 2000;
+
+ if (__pLocUpdateTimer->Equals(timer))
+ {
+ __timerTicks++;
+ SysLog(NID_LOC, "LocationManager update timer expired. Timer Tick value is (%d).", __timerTicks);
+ result r = E_SUCCESS;
+ double altitude = 0.0;
+ double latitude = 0.0;
+ double longitude = 0.0;
+ time_t timestamp;
+
+ int res = -1;
+ int satellitesInViewCount = 0;
+ int satellitesInUseCount = 0;
+ time_t timestampSatellite = 0;
+ String satInfo = L"";
+ long long timeDiff = 0;
+
+ switch (__locMethodRequested)
+ {
+ case LOC_METHOD_REQUESTED_GPS:
+ res = location_manager_get_position(__gpsHandler, &altitude, &latitude, &longitude, &timestamp);
+ SysTryLog(NID_LOC, res == 0, "[E_SYSTEM] Failed to obtain the GPS location information");
+
+ if (res == 0)
+ {
+ r = SetLocationInformation(latitude, longitude, altitude, timestamp, LOCATIONS_METHOD_GPS);
+ if (r != E_SUCCESS)
+ {
+ SysLog(NID_LOC, "Failed to set the location information");
+ }
+
+ res = gps_status_get_satellite(__gpsHandler, &satellitesInUseCount, &satellitesInViewCount, &timestampSatellite);
+
+ timeDiff = abs(timestamp - timestampSatellite);
+ timeDiff = timeDiff * 1000;
+ SysLog(NID_LOC, "Result (%d), Satellites in Use (%d), Satellites in View (%d), Time stamp (%ld), Time Difference (Loc and Sat) (%ld)",
+ res, satellitesInUseCount, satellitesInViewCount, timestampSatellite, timeDiff);
+ if (res == 0 && timeDiff <= MAX_VALID_TIME_DIFFERENCE)
+ {
+ res = gps_status_foreach_satellites_in_view(__gpsHandler, SatelliteInfoUpdated, &satInfo);
+ }
+ SysLog(NID_LOC, "Result of get satellite is (%d) and satelliteInfo string representation is (%ls)", res, satInfo.GetPointer());
+
+ _LocationImpl::GetInstance(*__pCurrentLocation.get())->SetExtraInfo(L"satellite", satInfo);
+ }
+ else
+ {
+ SendUserEvent(REQ_ID_RESTART_LOC_UPDATES, null);
+ return;
+ }
+ break;
+
+ case LOC_METHOD_REQUESTED_WPS:
+ res = location_manager_get_position(__wpsHandler, &altitude, &latitude, &longitude, &timestamp);
+ SysTryLog(NID_LOC, res == 0, "[E_SYSTEM] Failed to obtain the WPS location information");
+ if (res == 0)
+ {
+ r = SetLocationInformation(latitude, longitude, altitude, timestamp, LOCATIONS_METHOD_WPS);
+ if (r != E_SUCCESS)
+ {
+ SysLog(NID_LOC, "Failed to set the location information");
+ }
+ }
+ else
+ {
+ SendUserEvent(REQ_ID_RESTART_LOC_UPDATES, null);
+ return;
+ }
+ break;
+
+ case LOC_METHOD_REQUESTED_CPS:
+ res = location_manager_get_position(__cpsHandler, &altitude, &latitude, &longitude, &timestamp);
+ SysTryLog(NID_LOC, res == 0, "[E_SYSTEM] Failed to obtain the CPS location information");
+ if (res == 0)
+ {
+ r = SetLocationInformation(latitude, longitude, altitude, timestamp, LOCATIONS_METHOD_CPS);
+ if (r != E_SUCCESS)
+ {
+ SysLog(NID_LOC, "Failed to set the location information");
+ }
+ }
+ else
+ {
+ SendUserEvent(REQ_ID_RESTART_LOC_UPDATES, null);
+ return;
+ }
+ break;
+
+ case LOC_METHOD_REQUESTED_ALL:
+ if (__nativeCPSServiceState == LOCATIONS_SERVICE_ENABLED)
+ {
+ res = location_manager_get_position(__cpsHandler, &altitude, &latitude, &longitude, &timestamp);
+ SysTryLog(NID_LOC, res == 0, "[E_SYSTEM] Failed to obtain the CPS location information");
+ if (res == 0)
+ {
+ r = SetLocationInformation(latitude, longitude, altitude, timestamp, LOCATIONS_METHOD_CPS);
+ if (r != E_SUCCESS)
+ {
+ SysLog(NID_LOC, "Failed to set the location information");
+ }
+ }
+ }
+ else
+ {
+ SysLog(NID_LOC, "CPS Location not available at the Native side.");
+ }
+
+ if (__nativeWPSServiceState == LOCATIONS_SERVICE_ENABLED)
+ {
+ res = location_manager_get_position(__wpsHandler, &altitude, &latitude, &longitude, &timestamp);
+ SysTryLog(NID_LOC, res == 0, "[E_SYSTEM] Failed to obtain the WPS location information");
+ if (res == 0)
+ {
+ r = SetLocationInformation(latitude, longitude, altitude, timestamp, LOCATIONS_METHOD_WPS);
+ if (r != E_SUCCESS)
+ {
+ SysLog(NID_LOC, "Failed to set the location information");
+ }
+ }
+ }
+ else
+ {
+ SysLog(NID_LOC, "WPS Location not available at the Native side.");
+ }
+
+ if (__nativeGPSServiceState == LOCATIONS_SERVICE_ENABLED)
+ {
+ res = location_manager_get_position(__gpsHandler, &altitude, &latitude, &longitude, &timestamp);
+ SysTryLog(NID_LOC, res == 0, "[E_SYSTEM] Failed to obtain the GPS location information");
+ if (res == 0)
+ {
+ r = SetLocationInformation(latitude, longitude, altitude, timestamp, LOCATIONS_METHOD_GPS);
+ if (r != E_SUCCESS)
+ {
+ SysLog(NID_LOC, "Failed to set the location information");
+ }
+
+ res = gps_status_get_satellite(__gpsHandler, &satellitesInUseCount, &satellitesInViewCount, &timestampSatellite);
+
+ timeDiff = abs(timestamp - timestampSatellite);
+ timeDiff = timeDiff * 1000;
+ SysLog(NID_LOC, "Result (%d), Satellites in Use (%d), Satellites in View (%d), Time stamp (%ld), Time Difference (Loc and Sat) (%ld)",
+ res, satellitesInUseCount, satellitesInViewCount, timestampSatellite, timeDiff);
+ if (res == 0 && timeDiff <= MAX_VALID_TIME_DIFFERENCE)
+ {
+ res = gps_status_foreach_satellites_in_view(__gpsHandler, SatelliteInfoUpdated, &satInfo);
+ }
+ SysLog(NID_LOC, "Result of get satellite is (%d) and satelliteInfo string representation is (%ls)", res, satInfo.GetPointer());
+
+ _LocationImpl::GetInstance(*__pCurrentLocation.get())->SetExtraInfo(L"satellite", satInfo);
+ }
+ }
+ else
+ {
+ SysLog(NID_LOC, "GPS Location not available at the Native side.");
+ }
+ break;
+
+ case LOC_METHOD_REQUESTED_NONE:
+ // follow through
+ default:
+ SysLog(NID_LOC, "Timer expired when no location update is called.");
+ return;
+ }
+
+ __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;
+}
+
+bool
+_LocationManager::SatelliteInfoUpdated(unsigned int azimuth, unsigned int elevation, unsigned int prn, int snr, bool is_active, void* user_data)
+{
+
+ if (user_data == null)
+ {
+ SysLog(NID_LOC, "User data Null. Return.");
+ return true;
+ }
+
+ String* pSatInfo = static_cast< String* >(user_data);
+
+ SysLog(NID_LOC, "GPS Position Satellite Info: SatID (%d), Used (%d), Elevation (%d), Azimuth (%d), Snr (%d).", prn, is_active, elevation, azimuth, snr);
+
+ pSatInfo->Append(static_cast< int >(prn));
+ pSatInfo->Append(", ");
+ pSatInfo->Append(static_cast< int >(elevation));
+ pSatInfo->Append(", ");
+ pSatInfo->Append(static_cast< int >(azimuth));
+ pSatInfo->Append(", ");
+ pSatInfo->Append(snr);
+ pSatInfo->Append(", ");
+ pSatInfo->Append(is_active);
+ pSatInfo->Append("; ");
+
+ return true;
+}
+
+void
+_LocationManager::GpsServiceUpdateCallback(location_service_state_e state, void* user_data)
+{
+ SysLog(NID_LOC, "Updated State is (%d).", state);
+ if (user_data == null)
+ {
+ SysLog(NID_LOC, "User data is null. Return");
+ return;
+ }
+
+ _LocationManager* pThis = static_cast< _LocationManager* >(user_data);
+ pThis->__nativeGPSServiceState = state;
+}
+
+void
+_LocationManager::WpsServiceUpdateCallback(location_service_state_e state, void* user_data)
+{
+ SysLog(NID_LOC, "Updated State is (%d).", state);
+ if (user_data == null)
+ {
+ SysLog(NID_LOC, "User data is null. Return");
+ return;
+ }
+
+ _LocationManager* pThis = static_cast< _LocationManager* >(user_data);
+ pThis->__nativeWPSServiceState = state;
+}
+
+void
+_LocationManager::CpsServiceUpdateCallback(location_service_state_e state, void* user_data)
+{
+ SysLog(NID_LOC, "Updated State is (%d).", state);
+ if (user_data == null)
+ {
+ SysLog(NID_LOC, "User data is null. Return");
+ return;
+ }
+
+ _LocationManager* pThis = static_cast< _LocationManager* >(user_data);
+ pThis->__nativeCPSServiceState = state;
+}
+
+void
+_LocationManager::InitLocationManager(void)
+{
+ SysLog(NID_LOC, "Creating the first location manager instance.");
+
+ 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));
+
+ r = pLocMgr->Start();
+ SysTryReturnVoidResult(NID_LOC, r == E_SUCCESS, r, "[%s] Falied to start the Location Manager. Propagating.", GetErrorMessage(r));
+
+ __pUniqueInstance = pLocMgr.release();
+
+ std::atexit(DestroyLocationManager);
+}
+
+void
+_LocationManager::DestroyLocationManager(void)
+{
+ delete __pUniqueInstance;
+}
+
+Location
+_LocationManager::GetLastKnownLocation(location_method_e nativeLocMethod)
+{
+ String locationMethod;
+ location_manager_h nativeHandle = null;
+ switch (nativeLocMethod)
+ {
+ case LOCATIONS_METHOD_GPS:
+ nativeHandle = __gpsHandler;
+ locationMethod = L"gps";
+ break;
+ case LOCATIONS_METHOD_WPS:
+ nativeHandle = __wpsHandler;
+ locationMethod = L"network";
+ break;
+ case LOCATIONS_METHOD_CPS:
+ nativeHandle = __cpsHandler;
+ locationMethod = L"network";
+ break;
+ default:
+ break;
+ }
+ SysLog(NID_LOC, "Last location requested(method: %x, handle: %x).", nativeLocMethod, nativeHandle);
+
+ Location location = _LocationImpl::GetLocationInstance();
+ if (nativeHandle != null)
+ {
+ _LocationImpl* pLocationImpl = _LocationImpl::GetInstance(location);
+
+ double altitude = Tizen::Locations::NaN;
+ double latitude = Tizen::Locations::NaN;
+ double longitude = Tizen::Locations::NaN;
+ time_t timestampPosition = 0;
+
+ 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);
+ SysLog(NID_LOC, "Last position(latitude: %lf, longitude: %lf, altitude: %lf, timestamp: %lld",
+ latitude, longitude, altitude, timestampPosition);
+
+ Coordinates coord;
+ coord.Set(latitude, longitude, altitude);
+ pLocationImpl->SetCoordinates(coord);
+
+ double horAcc = Tizen::Locations::NaN;
+ double verAcc = Tizen::Locations::NaN;
+ location_accuracy_level_e level;
+ res = location_manager_get_last_accuracy(nativeHandle, &level, &horAcc, &verAcc);
+ if (res == 0)
+ {
+ SysLog(NID_LOC, "Last accuracy(horAcc: %lf, vAcc: %lf, level: %x)", horAcc, verAcc, level);
+ pLocationImpl->SetHorizontalAccuracy(horAcc);
+ pLocationImpl->SetVerticalAccuracy(verAcc);
+ }
+
+ double climb = Tizen::Locations::NaN;
+ double direction = Tizen::Locations::NaN;
+ double speed = Tizen::Locations::NaN;
+ time_t timestampVelocity = 0;
+ res = location_manager_get_last_velocity(nativeHandle, &climb, &direction, &speed, &timestampVelocity);
+ if (res == 0)
+ {
+ SysLog(NID_LOC, "Last velocity(climb: %lf, direction: %lf, speed: %x, timestamp: %lld)",
+ climb, direction, speed, timestampVelocity);
+ pLocationImpl->SetCourse(direction);
+ pLocationImpl->SetSpeed(speed);
+ }
+
+ if (nativeLocMethod == LOCATIONS_METHOD_GPS)
+ {
+ int satUsedCount = 0;
+ int satViewCount = 0;
+ time_t timestampSatellite = 0;
+ String satInfo = L"";
+ res = gps_status_get_last_satellite(nativeHandle, &satUsedCount, &satViewCount, &timestampSatellite);
+ if (res == 0)
+ {
+ 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: %lld, timeDiff: %ld)",
+ res, satUsedCount, satViewCount, timestampSatellite, timeDiff);
+
+ SysLog(NID_LOC, "Last satellite(info: %ls)", satInfo.GetPointer());
+ pLocationImpl->SetExtraInfo(L"satellite", satInfo);
+ }
+ }
+
+ pLocationImpl->SetTimestamp(((long long)timestampPosition) * 1000); // in milliseconds
+ pLocationImpl->SetValidity(true);
+ pLocationImpl->SetExtraInfo(L"location_method", locationMethod);
+ }
+
+ ClearLastResult();
+ return location;
+
+CATCH:
+ return location;
+}
+
+bool
+_LocationManager::GetAppAccessibility(void)
+{
+ int res = 0;
+ static bool appRegistered = false;
+ if (!appRegistered)
+ {
+ static const char COMMAND_REGISTER_APP[] = "ADD_APPLIST";
+ if (location_manager_send_command(COMMAND_REGISTER_APP) == LOCATIONS_ERROR_NONE)
+ {
+#ifdef _OSP_EMUL_
+ static const char COMMAND_ENABLE_APP[] = "ACCESSIBILITY:1";
+ res = location_manager_send_command(COMMAND_ENABLE_APP);
+ SysTryReturn(NID_LOC, res == 0, false, E_SYSTEM,
+ "[%s] Failed to register the application.", GetErrorMessage(E_SYSTEM));
+#endif
+ appRegistered = true;
+ }
+ }
+
+ location_accessibility_state_e accessState;
+ res = location_manager_get_accessibility_state(&accessState);
+ SysTryReturn(NID_LOC, res == 0, false, E_SYSTEM,
+ "[%s] Failed to get the application location setting.", GetErrorMessage(E_SYSTEM));
+
+ return (accessState == LOCATIONS_ACCESS_STATE_ALLOWED) ? true : false;
+}
+
+Location
+_LocationManager::GetRecentLocationAvailable(void)
+{
+ long long gpsTimestamp = 0;
+ long long wpsTimestamp = 0;
+ long long cpsTimestamp = 0;
+
+ Location lastGpsLocation = GetLastKnownLocation(LOCATIONS_METHOD_GPS);
+ if (lastGpsLocation.IsValid())
+ {
+ gpsTimestamp = _LocationImpl::GetInstance(lastGpsLocation)->GetTimestampInMs();
+ }
+
+ Location lastWpsLocation = GetLastKnownLocation(LOCATIONS_METHOD_WPS);
+ if (lastWpsLocation.IsValid())
+ {
+ wpsTimestamp = _LocationImpl::GetInstance(lastWpsLocation)->GetTimestampInMs();
+ }
+
+ Location lastCpsLocation = GetLastKnownLocation(LOCATIONS_METHOD_CPS);
+ if (lastCpsLocation.IsValid())
+ {
+ cpsTimestamp = _LocationImpl::GetInstance(lastCpsLocation)->GetTimestampInMs();
+ }
+
+ SysLog(NID_LOC, "Compare timestamp(gps: %lld, wps: %lld, cps: %lld) for recent location.",
+ gpsTimestamp, wpsTimestamp, cpsTimestamp);
+
+ if (gpsTimestamp >= wpsTimestamp && gpsTimestamp >= cpsTimestamp)
+ {
+ return lastGpsLocation;
+ }
+ else if (wpsTimestamp > gpsTimestamp && wpsTimestamp > cpsTimestamp)
+ {
+ return lastWpsLocation;
+ }
+ else
+ {
+ return lastCpsLocation;
+ }
+}
+}}
diff --git a/src/FLoc_LocationManager.h b/src/FLoc_LocationManager.h
new file mode 100644
index 0000000..531eabb
--- /dev/null
+++ b/src/FLoc_LocationManager.h
@@ -0,0 +1,308 @@
+//
+// 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_LocationManager.h
+ * @brief This is the header file for the %_LocationManager class.
+ *
+ * This header file contains the declarations of the %_LocationManager class methods.
+ */
+
+#ifndef _FLOC_INTERNAL_LOCATION_MANAGER_H_
+#define _FLOC_INTERNAL_LOCATION_MANAGER_H_
+
+#include <unique_ptr.h>
+#include <location/locations.h>
+#include <FBaseColAllElementsDeleter.h>
+#include <FBaseRtEventDrivenThread.h>
+#include <FLocLocation.h>
+#include "FLoc_ILocationManagerListener.h"
+#include "FLoc_Types.h"
+
+namespace Tizen { namespace Locations
+{
+
+class _LocationMonitor;
+class _LocationRequestInfo;
+class _SyncLocationRequestInfo;
+
+class _LocationManager
+ : public Tizen::Base::Runtime::EventDrivenThread
+ , public Tizen::Base::Runtime::ITimerEventListener
+{
+public:
+ // This method adds the location request into the list of requests and requests for location updates from native location provider.
+ //
+ // @since 2.0
+ //
+ result StartLocationUpdates(LocationAccuracy accuracy, int interval, _ILocationManagerListener* pListener, RequestId& reqId);
+
+ // This method removes the location request wrt to the reqId provided. If the list entries is zero, then stops the native location provider.
+ //
+ // @since 2.0
+ //
+ result StopLocationUpdates(RequestId reqId);
+
+ // This method initiates the synchronous location retrieval. The location monitor instance provided is used to intimate back the location.
+ //
+ // @since 2.0
+ //
+ result RegisterLocationMonitor(_LocationMonitor* pLocationMonitor);
+
+ // This method returns the stored location.
+ //
+ // @since 2.0
+ //
+ 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 gets the location setting information of this particular application.
+ //
+ // @since 2.0
+ //
+ bool IsAppEnabled(void);
+
+ // This method returns the single instance of the location maanger.
+ //
+ // @since 2.0
+ //
+ static _LocationManager* GetInstance(void);
+
+private:
+ // This default constructor is intentionally declared as private to implement the Singleton semantic.
+ //
+ // @since 2.0
+ //
+ _LocationManager(void);
+
+ // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
+ //
+ // @since 2.0
+ //
+ _LocationManager(const _LocationManager& value);
+
+ // This destructor is intentionally declared as private to implement the Singleton semantic.
+ //
+ // @since 2.0
+ //
+ ~_LocationManager(void);
+
+ // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
+ //
+ // @since 2.0
+ //
+ _LocationManager& operator =(const _LocationManager& rhs);
+
+ // The method adds the _LocationRequestInfo instance to the array list.
+ //
+ // @since 2.0
+ //
+ void AddToLocRequestInfoList(const _LocationRequestInfo* pLocRequestInfo);
+
+ // The method removes the _LocationRequestInfo instance corresponding to a reqId from the array list.
+ //
+ // @since 2.0
+ //
+ void RemoveFromLocRequestInfoList(RequestId reqId);
+
+ // The method adds the _SyncLocationRequestInfo instance to the array list.
+ //
+ // @since 2.0
+ //
+ void AddToSyncLocationRequestInfoList(_SyncLocationRequestInfo& syncLocRequestInfo);
+
+ // The method removes the _SyncLocationRequestInfo instance from the list.
+ //
+ // @since 2.0
+ //
+ void RemoveSyncLocRetrievalRequest(_SyncLocationRequestInfo& syncLocRequestInfo);
+
+ // The method restarts all (GPS, WPS and CPS) the native location providers.
+ //
+ // @since 2.0
+ //
+ void RestartLocationUpdates(void);
+
+ // The method restarts the update timer after calculating the GCD of the timeout values requested by each location provider.
+ //
+ // @since 2.0
+ //
+ void RestartUpdateTimer(void);
+
+ // The method is called everytime the sync retrieval timer is expired.
+ //
+ // @since 2.0
+ //
+ void HandleSyncRetrievalTimerExpiry(_SyncLocationRequestInfo& syncLocRequestInfo);
+
+ // The method is called everytime the Async update timer is expired to set the location information.
+ //
+ // @since 2.0
+ //
+ result SetLocationInformation(double latitude, double longitude, double altitude, time_t timestamp, location_method_e locMethod);
+
+ // The method is called to send back the callbacks in case of async location updates.
+ //
+ // @since 2.0
+ //
+ void SendLocationCallbacks(void);
+
+ // This method resets the member variables.
+ //
+ // @since 2.0
+ //
+ void Reset(void);
+
+ // 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.
+ //
+ // @since 2.0
+ //
+ Location GetLastKnownLocation(location_method_e nativeLocMethod);
+
+ // @see @ref Tizen::Base::Runtime::EventDrivenThread::OnStart()
+ //
+ // @since 2.0
+ //
+ virtual bool OnStart(void);
+
+ // @see @ref Tizen::Base::Runtime::EventDrivenThread::OnStop()
+ //
+ // @since 2.0
+ //
+ virtual void OnStop(void);
+
+ // @see @ref Tizen::Base::Runtime::EventDrivenThread::OnUserEventReceivedN()
+ //
+ // @since 2.0
+ //
+ virtual void OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs);
+
+ // @see @ref Tizen::Base::Runtime::ITimerEventListener::OnTimerExpired()
+ //
+ // @since 2.0
+ //
+ virtual void OnTimerExpired(Tizen::Base::Runtime::Timer& timer);
+
+ // This callback is recieved from native location manager for satellite information.
+ //
+ // @since 2.0
+ //
+ static bool SatelliteInfoUpdated(unsigned int azimuth, unsigned int elevation, unsigned int prn, int snr, bool is_active, void* user_data);
+
+ // This method is called by the native location provider when the service state of GPS method is changed.
+ //
+ // @since 2.0
+ //
+ static void GpsServiceUpdateCallback(location_service_state_e state, void* user_data);
+
+ // This method is called by the native location provider when the service state of WPS method is changed.
+ //
+ // @since 2.0
+ //
+ static void WpsServiceUpdateCallback(location_service_state_e state, void* user_data);
+
+ // This method is called by the native location provider when the service state of CPS method is changed.
+ //
+ // @since 2.0
+ //
+ static void CpsServiceUpdateCallback(location_service_state_e state, void* user_data);
+
+ // This method initializes the single instance of the location manager.
+ //
+ // @since 2.0
+ //
+ static void InitLocationManager(void);
+
+ // This method is called when the location manager thread is destroyed.
+ //
+ // @since 2.0
+ //
+ static void DestroyLocationManager(void);
+
+ // This method gets app's accessibility from native side, adding the app into the location
+ // setting, if it is not registerd.
+ //
+ // @since 2.0
+ //
+ static bool GetAppAccessibility(void);
+
+ // This method returns the most recent location among available last known locations.
+ //
+ // @since 2.0
+ //
+ Location GetRecentLocationAvailable(void);
+
+private:
+ const static RequestId REQ_ID_START_LOC_UPDATES = 1;
+ const static RequestId REQ_ID_STOP_LOC_UPDATES = 2;
+ const static RequestId REQ_ID_RESTART_LOC_UPDATES = 3;
+ const static RequestId REQ_ID_SUSTAIN_GPS = 4;
+ const static RequestId REQ_ID_SUSTAIN_WPS = 5;
+ const static RequestId REQ_ID_SUSTAIN_CPS = 6;
+ const static RequestId REQ_ID_SYNC_LOC_RETRIEVAL = 7;
+ const static RequestId REQ_ID_GET_APP_ACCESSIBILITY = 8;
+ const static RequestId REQ_ID_GET_LAST_LOCATION = 9;
+
+ enum _LocationMethodRequested
+ {
+ LOC_METHOD_REQUESTED_NONE,
+ LOC_METHOD_REQUESTED_GPS,
+ LOC_METHOD_REQUESTED_WPS,
+ LOC_METHOD_REQUESTED_CPS,
+ LOC_METHOD_REQUESTED_ALL,
+ }
+ __locMethodRequested;
+
+ enum _LocationManagerState
+ {
+ LOC_MGR_STATE_IDLE,
+ LOC_MGR_STATE_FAST_SENSING,
+ LOC_MGR_STATE_FAST_SENSING_SETTLED
+ }
+ __locationMgrState;
+
+ LocationAccuracy __minRequestedAccuracy;
+ location_service_state_e __nativeGPSServiceState;
+ location_service_state_e __nativeWPSServiceState;
+ location_service_state_e __nativeCPSServiceState;
+ int __timerInterval;
+ int __timerTicks;
+ location_manager_h __gpsHandler;
+ location_manager_h __wpsHandler;
+ location_manager_h __cpsHandler;
+ std::unique_ptr< Tizen::Locations::Location > __pCurrentLocation;
+ 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::Mutex > __pLocMgrMutex;
+ std::unique_ptr< Tizen::Base::Runtime::Timer > __pLocUpdateTimer;
+ static _LocationManager* __pUniqueInstance;
+
+ friend class std::default_delete< _LocationManager >;
+}; // class _LocationManager
+}} // Tizen::Locations
+#endif // _FLOC_INTERNAL_LOCATION_MANAGER_H_
diff --git a/src/FLoc_LocationMonitor.cpp b/src/FLoc_LocationMonitor.cpp
new file mode 100644
index 0000000..921abfd
--- /dev/null
+++ b/src/FLoc_LocationMonitor.cpp
@@ -0,0 +1,116 @@
+//
+// 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_LocationMonitor.cpp
+ * @brief This is the implementation file for the %_LocationMonitor class.
+ *
+ * This implementation file contains the definitions of the %_LocationMonitor class methods.
+ */
+
+#include <FBaseSysLog.h>
+#include "FLoc_LocationMonitor.h"
+
+using namespace Tizen::Base::Runtime;
+using namespace std;
+
+namespace Tizen { namespace Locations
+{
+
+_LocationMonitor::_LocationMonitor(void)
+ : __pMonitor(null)
+ , __pLocation(null)
+{
+}
+
+_LocationMonitor::~_LocationMonitor(void)
+{
+ delete __pLocation;
+}
+
+result
+_LocationMonitor::Construct(int timeout, LocationAccuracy accuracy)
+{
+ unique_ptr< Tizen::Base::Runtime::Monitor > pMonitor(new (std::nothrow) Monitor());
+ SysTryReturn(NID_LOC, pMonitor, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ result r = pMonitor->Construct();
+ SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Error from Monitor::Construct(). Propagating.", GetErrorMessage(r));
+
+ __pMonitor = std::move(pMonitor);
+
+ __timeout = timeout;
+ __accuracy = accuracy;
+
+ return r;
+}
+
+result
+_LocationMonitor::Enter(void)
+{
+ return __pMonitor->Enter();
+}
+
+result
+_LocationMonitor::Wait(void)
+{
+ return __pMonitor->Wait();
+}
+
+result
+_LocationMonitor::Notify(void)
+{
+ return __pMonitor->Notify();
+}
+
+result
+_LocationMonitor::Exit(void)
+{
+ return __pMonitor->Exit();
+}
+
+Location*
+_LocationMonitor::GetLocationN(void)
+{
+ Location* pLocation = __pLocation;
+ __pLocation = null;
+ return pLocation;
+}
+
+void
+_LocationMonitor::SetLocation(Tizen::Locations::Location* pLocation)
+{
+ if (__pLocation != null)
+ {
+ delete __pLocation;
+ }
+ __pLocation = pLocation;
+}
+
+int
+_LocationMonitor::GetTimeout(void) const
+{
+ return __timeout;
+}
+
+LocationAccuracy
+_LocationMonitor::GetAccuracy(void) const
+{
+ return __accuracy;
+}
+
+}}
diff --git a/src/FLoc_LocationMonitor.h b/src/FLoc_LocationMonitor.h
new file mode 100644
index 0000000..3342ed9
--- /dev/null
+++ b/src/FLoc_LocationMonitor.h
@@ -0,0 +1,75 @@
+//
+// 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_LocationMonitor.h
+ * @brief This is the header file for the %_LocationMonitor class.
+ *
+ * This header file contains the declarations of the %_LocationMonitor class methods.
+ */
+
+#ifndef _FLOC_INTERNAL_LOCATION_MONITOR_H_
+#define _FLOC_INTERNAL_LOCATION_MONITOR_H_
+
+#include <unique_ptr.h>
+#include <FBaseRtMonitor.h>
+#include <FLocLocation.h>
+#include <FLocTypes.h>
+
+namespace Tizen { namespace Locations
+{
+
+class _LocationMonitor
+{
+public:
+ _LocationMonitor(void);
+
+ ~_LocationMonitor(void);
+
+ result Construct(int timeout, LocationAccuracy accuracy);
+
+ result Enter(void);
+
+ result Wait(void);
+
+ result Notify(void);
+
+ result Exit(void);
+
+ Location* GetLocationN(void);
+
+ void SetLocation(Tizen::Locations::Location* pLocation);
+
+ int GetTimeout(void) const;
+
+ LocationAccuracy GetAccuracy(void) const;
+
+private:
+ _LocationMonitor(const _LocationMonitor& value);
+
+ _LocationMonitor& operator =(const _LocationMonitor& rhs);
+
+private:
+ int __timeout;
+ LocationAccuracy __accuracy;
+ std::unique_ptr< Tizen::Base::Runtime::Monitor > __pMonitor;
+ Location* __pLocation;
+}; // class _LocationMonitor
+
+}} // Tizen::Locations
+
+#endif // _FLOC_INTERNAL_LOCATION_MONITOR_H_
diff --git a/src/FLoc_LocationProviderImpl.cpp b/src/FLoc_LocationProviderImpl.cpp
new file mode 100644
index 0000000..02a1229
--- /dev/null
+++ b/src/FLoc_LocationProviderImpl.cpp
@@ -0,0 +1,923 @@
+//
+// 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_LocationProviderImpl.cpp
+ * @brief This is the implementation file for the %_LocationProviderImpl class.
+ *
+ * This implementation file contains the definitions of the %_LocationProviderImpl class methods.
+ */
+
+#include <unique_ptr.h>
+#include <FApp_AppManagerImpl.h>
+#include <FAppApp.h>
+#include <FAppTypes.h>
+#include <FAppUiApp.h>
+#include <FBaseColArrayList.h>
+#include <FBaseDouble.h>
+#include <FBaseRtEvent.h>
+#include <FBaseRtTimer.h>
+#include <FBaseSysLog.h>
+#include <FLocLocationCriteria.h>
+#include <FLocCoordinates.h>
+#include <FLocILocationProviderListener.h>
+#include <FLocLocation.h>
+#include <FLocTypes.h>
+#include <FSysPowerManager.h>
+#include <FSysSystemTime.h>
+#include <FSys_SettingInfoImpl.h>
+#include "FLoc_LocationImpl.h"
+#include "FLoc_LocationManager.h"
+#include "FLoc_LocationMonitor.h"
+#include "FLoc_LocationProviderImpl.h"
+#include "FLoc_MathUtils.h"
+#include "FLoc_Types.h"
+
+using namespace Tizen::App;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+using namespace Tizen::Base::Runtime;
+using namespace Tizen::Base::Utility;
+using namespace Tizen::System;
+using namespace std;
+
+namespace Tizen { namespace Locations
+{
+
+_LocationProviderImpl::_LocationProviderImpl(void)
+ : Tizen::Base::Runtime::_Event()
+ , __firstLocationUpdate(true)
+ , __regionMonitoringActive(false)
+ , __awakeEnabled(false)
+ , __updateInterval(0)
+ , __locationUpdateType(_LOCATION_UPDATE_TYPE_NONE)
+ , __locationUpdateStatus(LOC_SVC_STATUS_IDLE)
+ , __regionMonitorStatus(LOC_SVC_STATUS_IDLE)
+ , __lastLocationAccuracy(LOC_ACCURACY_INVALID)
+ , __reqId(-1)
+ , __regionReqId(-1)
+ , __distanceThreshold(0.0)
+ , __pLocationListener(null)
+ , __pLocationManager(null)
+ , __pLastLocation(null)
+ , __pRegionList(null)
+{
+}
+
+_LocationProviderImpl::~_LocationProviderImpl(void)
+{
+ UiApp* pAppInstance = Tizen::App::UiApp::GetInstance();
+ if (pAppInstance)
+ {
+ _AppManagerImpl* pAppManager = _AppManagerImpl::GetInstance();
+ if (pAppManager)
+ {
+ pAppManager->RemoveActiveAppEventListener(*this);
+ }
+ }
+
+ StopLocationUpdates();
+ RemoveAllMonitoringRegions();
+}
+
+result
+_LocationProviderImpl::Construct(const LocationCriteria& criteria, ILocationProviderListener& listener)
+{
+ result r = E_SUCCESS;
+ _LocationManager* pLocationManager = null;
+
+ 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());
+ SysTryReturn(NID_LOC, pRegionList != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ r = pRegionList->Construct();
+ SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to construct the list. Propagating.", GetErrorMessage(r));
+
+ UiApp* pAppInstance = Tizen::App::UiApp::GetInstance();
+ if (pAppInstance != null)
+ {
+ _AppManagerImpl* pAppManager = _AppManagerImpl::GetInstance();
+ SysTryReturn(NID_LOC, pAppManager, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] System error occured.");
+
+ r = pAppManager->AddActiveAppEventListener(*this);
+ SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Error occured during adding the event listener to app manager. Propagating.", GetErrorMessage(r));
+ }
+
+ std::unique_ptr< Tizen::Locations::Location > pLocation(_LocationImpl::GetLocationInstanceN());
+ SysTryReturn(NID_LOC, pLocation != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ _Event::Initialize();
+ _Event::AddListener(*this);
+
+ __pRegionList = std::move(pRegionList);
+ __pLastLocation = std::move(pLocation);
+ __criteria = criteria;
+ __pLocationListener = &listener;
+ __pLocationManager = pLocationManager;
+
+ SysLog(NID_LOC, "Location provider constructed with the accuracy (%x).", criteria.GetAccuracy());
+
+ return E_SUCCESS;
+}
+
+result
+_LocationProviderImpl::StartLocationUpdatesByInterval(int interval)
+{
+ bool userConsent = GetUserPrivilege();
+ SysTryReturn(NID_LOC, userConsent, E_USER_NOT_CONSENTED, E_USER_NOT_CONSENTED, "[E_USER_NOT_CONSENTED] The user has disabled the required settings.");
+
+ SysTryReturn(NID_LOC, interval >= 1, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The interval(%d) should be greater than or equal to 1", interval);
+
+ if (__locationUpdateType == _LOCATION_UPDATE_TYPE_INTERVAL && __updateInterval == interval)
+ {
+ return E_SUCCESS;
+ }
+ else if (__locationUpdateType == _LOCATION_UPDATE_TYPE_DISTANCE || __locationUpdateType == _LOCATION_UPDATE_TYPE_INTERVAL)
+ {
+ __pLocationManager->StopLocationUpdates(__reqId);
+ __locationUpdateStatus = LOC_SVC_STATUS_IDLE;
+ }
+
+ const double INVALID_DISTANCE_THRESHOLD = 0.0;
+ return StartLocationUpdates(_LOCATION_UPDATE_TYPE_INTERVAL, interval, INVALID_DISTANCE_THRESHOLD);
+}
+
+result
+_LocationProviderImpl::StartLocationUpdatesByDistance(double distance)
+{
+ bool userConsent = GetUserPrivilege();
+ SysTryReturn(NID_LOC, userConsent, E_USER_NOT_CONSENTED, E_USER_NOT_CONSENTED, "[E_USER_NOT_CONSENTED] The user has disabled the required settings.");
+
+ SysTryReturn(NID_LOC, distance > 0.0, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The distance(%lf) should be greater than 0.0", distance);
+
+ SysTryReturn(NID_LOC, Double::IsNaN(distance) == false, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The distance is NaN.");
+
+ if (__locationUpdateType == _LOCATION_UPDATE_TYPE_DISTANCE && (Double::Compare(__distanceThreshold, distance) == 0))
+ {
+ return E_SUCCESS;
+ }
+ else if (__locationUpdateType == _LOCATION_UPDATE_TYPE_DISTANCE || __locationUpdateType == _LOCATION_UPDATE_TYPE_INTERVAL)
+ {
+ __pLocationManager->StopLocationUpdates(__reqId);
+ __locationUpdateStatus = LOC_SVC_STATUS_IDLE;
+ }
+
+ const int INVALID_INTERVAL = 0;
+ return StartLocationUpdates(_LOCATION_UPDATE_TYPE_DISTANCE, INVALID_INTERVAL, distance);
+}
+
+result
+_LocationProviderImpl::StopLocationUpdates(void)
+{
+ SysLog(NID_LOC, "Stopping the location updates for the request ID (%ld)", __reqId);
+
+ SysTryReturn(NID_LOC, __locationUpdateType != _LOCATION_UPDATE_TYPE_NONE, E_INVALID_OPERATION, E_INVALID_OPERATION, "[E_INVALID_OPERATION] Location update has not been requested.");
+
+ result r = __pLocationManager->StopLocationUpdates(__reqId);
+
+ ResetLocationUpdates();
+
+ return r;
+}
+
+void
+_LocationProviderImpl::KeepLocationUpdateAwake(bool enable)
+{
+ if (__awakeEnabled == enable)
+ {
+ return;
+ }
+ __awakeEnabled = enable;
+
+ UiApp* appInstance = Tizen::App::UiApp::GetInstance();
+ if (appInstance == null) // This is service APP. So should be handled now.
+ {
+ SysLog(NID_LOC, "Handling the request awake mode(%d) for the service application.", enable);
+ if (enable == true)
+ {
+ if (__locationUpdateType != _LOCATION_UPDATE_TYPE_NONE && __locationUpdateStatus == LOC_SVC_STATUS_PAUSED)
+ {
+ SysLog(NID_LOC, "Requesting to start the location updates as the update type is (%x)", __locationUpdateType);
+ __locationUpdateStatus = LOC_SVC_STATUS_NOT_FIXED;
+ __pLocationManager->StartLocationUpdates(__criteria.GetAccuracy(), __updateInterval, this, __reqId);
+
+ NotifyServiceStatus(_LOC_PRV_EVENT_SEND_LOC_SVC_CB, __locationUpdateStatus);
+ }
+ }
+ else
+ {
+ if (__locationUpdateType != _LOCATION_UPDATE_TYPE_NONE && (__locationUpdateStatus == LOC_SVC_STATUS_RUNNING || __locationUpdateStatus == LOC_SVC_STATUS_NOT_FIXED))
+ {
+ SysLog(NID_LOC, "Requesting to stop the location updates as the update type is (%x)", __locationUpdateType);
+ __locationUpdateStatus = LOC_SVC_STATUS_PAUSED;
+ __pLocationManager->StopLocationUpdates(__reqId);
+
+ NotifyServiceStatus(_LOC_PRV_EVENT_SEND_LOC_SVC_CB, __locationUpdateStatus);
+ }
+ }
+ }
+}
+
+result
+_LocationProviderImpl::AddMonitoringRegion(const Coordinates& regionCenter, double radius, RegionId& regionId)
+{
+ bool userConsent = GetUserPrivilege();
+ SysTryReturn(NID_LOC, userConsent, E_USER_NOT_CONSENTED, E_USER_NOT_CONSENTED, "[E_USER_NOT_CONSENTED] The user has disabled the required settings.");
+
+ SysTryReturn(NID_LOC, radius >= 50.0 && radius <= 100000.00, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The radius is not within the specified limits.");
+
+ SysTryReturn(NID_LOC, (!Double::IsNaN(radius) && !Double::IsNaN(regionCenter.GetLatitude()) && !Double::IsNaN(regionCenter.GetLongitude())),
+ E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] One of the value is NaN.");
+
+ SysLog(NID_LOC, "Requested to add the monitoring region with center (Latitude: %lf, Longitude %lf) and radius (%lf).", regionCenter.GetLatitude(), regionCenter.GetLongitude(), radius);
+
+ const int DEAULT_REGION_MONITOR_INTERVAL = 5;
+ static int nextRegionId = 0;
+ result r = E_SUCCESS;
+
+ std::unique_ptr< _RegionInfo > pRegionInfo(new (std::nothrow) _RegionInfo(regionCenter, radius, nextRegionId));
+ SysTryReturn(NID_LOC, pRegionInfo != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ r = __pRegionList->Add(*pRegionInfo.get());
+ SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to add the Region info into the list. Propogated.", GetErrorMessage(r));
+
+ pRegionInfo.release();
+ regionId = nextRegionId;
+ nextRegionId++;
+
+ if (__regionMonitoringActive == true)
+ {
+ return E_SUCCESS;
+ }
+
+ r = __pLocationManager->StartLocationUpdates(__criteria.GetAccuracy(), DEAULT_REGION_MONITOR_INTERVAL, this, __regionReqId);
+ SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to start the location updates. Propogating.", GetErrorMessage(r));
+
+ __regionMonitoringActive = true;
+ __regionMonitorStatus = LOC_SVC_STATUS_NOT_FIXED;
+ NotifyServiceStatus(_LOC_PRV_EVENT_SEND_MONITOR_SVC_CB, __regionMonitorStatus);
+
+ return E_SUCCESS;
+}
+
+result
+_LocationProviderImpl::RemoveMonitoringRegion(RegionId regionId)
+{
+ int count = __pRegionList->GetCount();
+ result r = E_SUCCESS;
+ bool isIdValid = false;
+
+ SysLog(NID_LOC, "Total regions currently monitored is (%d).", count);
+
+ for (int i = 0; i < count; i++)
+ {
+ _RegionInfo* pRegionInfo = static_cast< _RegionInfo* >(__pRegionList->GetAt(i));
+ if (regionId == pRegionInfo->GetRegionId())
+ {
+ __pRegionList->RemoveAt(i, true);
+ isIdValid = true;
+ break;
+ }
+ }
+
+ SysTryReturn(NID_LOC, isIdValid == true, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The region ID is invalid.");
+
+ if (__pRegionList->GetCount() == 0)
+ {
+ __regionMonitoringActive = false;
+ __regionMonitorStatus = LOC_SVC_STATUS_IDLE;
+ if (__locationUpdateStatus == LOC_SVC_STATUS_IDLE) // As we are using the same variable for both region monitoring and location updates, this set is required here.
+ {
+ __lastLocationAccuracy = LOC_ACCURACY_INVALID;
+ }
+ r = __pLocationManager->StopLocationUpdates(__regionReqId);
+ SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] All regions are removed but failed to stop the location updates. Propagating.", GetErrorMessage(r));
+ }
+
+ return E_SUCCESS;
+}
+
+void
+_LocationProviderImpl::RemoveAllMonitoringRegions(void)
+{
+ result r = E_SUCCESS;
+
+ __pRegionList->RemoveAll(true);
+
+ if (__regionMonitoringActive == true)
+ {
+ __regionMonitoringActive = false;
+ __regionMonitorStatus = LOC_SVC_STATUS_IDLE;
+ if (__locationUpdateStatus == LOC_SVC_STATUS_IDLE) // As we are using the same variable for both region monitoring and location updates, this set is required here.
+ {
+ __lastLocationAccuracy = LOC_ACCURACY_INVALID;
+ }
+ r = __pLocationManager->StopLocationUpdates(__regionReqId);
+ SysTryReturnVoidResult(NID_LOC, r == E_SUCCESS, r, "[%s] All regions are removed but failed to stop the location updates. Ignored.", GetErrorMessage(r));
+ }
+
+ return;
+}
+
+LocationServiceStatus
+_LocationProviderImpl::GetLocationUpdateStatus(void) const
+{
+ return __locationUpdateStatus;
+}
+
+LocationServiceStatus
+_LocationProviderImpl::GetRegionMonitoringStatus(void) const
+{
+ return __regionMonitorStatus;
+}
+
+LocationAccuracy
+_LocationProviderImpl::GetCurrentAccuracy(void) const
+{
+ return __lastLocationAccuracy;
+}
+
+Location
+_LocationProviderImpl::GetLocation(const LocationCriteria& criteria)
+{
+ Location retLocation(_LocationImpl::GetLocationInstance());
+
+ bool userConsent = GetUserPrivilege();
+ SysTryReturn(NID_LOC, userConsent, retLocation, E_USER_NOT_CONSENTED, "[E_USER_NOT_CONSENTED] The user has disabled the required settings.");
+
+ Location* pLocation = null;
+ const int MAX_TIMEOUT = 30;
+ result r = E_SUCCESS;
+ _LocationManager* pLocationManager = null;
+
+ SysLog(NID_LOC, "Requesting for single location with criteria (%x).", criteria.GetAccuracy());
+
+ std::unique_ptr< _LocationMonitor > pLocMonitor(new (std::nothrow) _LocationMonitor());
+ SysTryCatch(NID_LOC, pLocMonitor, , E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ r = pLocMonitor->Construct(MAX_TIMEOUT, criteria.GetAccuracy());
+ SysTryCatch(NID_LOC, r == E_SUCCESS, , r, "[%s] Failed to construct the Location Monitor.", GetErrorMessage(r));
+
+ pLocationManager = _LocationManager::GetInstance();
+ SysTryCatch(NID_LOC, pLocationManager, , r, "[%s] Failed to get the location manager instance.", GetErrorMessage(r));
+
+ r = pLocationManager->RegisterLocationMonitor(pLocMonitor.get());
+ SysTryCatch(NID_LOC, r == E_SUCCESS, , r, "[%s] Failed to register the location monitor.", GetErrorMessage(r));
+
+ r = pLocMonitor->Wait();
+
+ if (!IsFailed(r))
+ {
+ pLocation = pLocMonitor->GetLocationN();
+ }
+
+ if (pLocation)
+ {
+ retLocation = *pLocation;
+ }
+ else
+ {
+ SetLastResult(E_LOCATION_UNAVAILABLE);
+ }
+
+ delete pLocation;
+
+ return retLocation;
+
+CATCH:
+ return retLocation;
+}
+
+Location
+_LocationProviderImpl::GetLastKnownLocation(void)
+{
+ Location retLocation(_LocationImpl::GetLocationInstance());
+
+ bool userConsent = GetUserPrivilege();
+ SysTryReturn(NID_LOC, userConsent, retLocation, E_USER_NOT_CONSENTED, "[E_USER_NOT_CONSENTED] The user has disabled the required settings.");
+
+ _LocationManager* pLocationManager = _LocationManager::GetInstance();
+ SysTryReturn(NID_LOC, pLocationManager, retLocation, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ retLocation = pLocationManager->GetLastKnownLocation();
+
+ if (!retLocation.IsValid())
+ {
+ SetLastResult(E_LOCATION_UNAVAILABLE);
+ }
+ else
+ {
+ ClearLastResult();
+ }
+
+ return retLocation;
+}
+
+// Private members
+
+void
+_LocationProviderImpl::OnLocationUpdated(RequestId reqId, const Tizen::Locations::Location& location)
+{
+ SysLog(NID_LOC, "Location is updated from Location Manager for the request ID (%ld).", reqId);
+
+ std::unique_ptr< Location > pLocation(new (std::nothrow) Location(location));
+ SysTryReturnVoidResult(NID_LOC, pLocation, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ 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_LOC);
+ pLocProviderEventArg->SetLocation(pLocation.get());
+ pLocProviderEventArg->SetRequestId(reqId);
+ pLocation.release();
+
+ 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.");
+ bool isNew = false;
+ LocationAccuracy currentAccuracy = LOC_ACCURACY_INVALID;
+ long long lastLocationTime = 0;
+
+ Location* pLocation = &location;
+ _LocationImpl* pLocationImpl = _LocationImpl::GetInstance(*pLocation);
+ if (__pLastLocation)
+ {
+ lastLocationTime = _LocationImpl::GetInstance(*__pLastLocation.get())->GetTimestampInMs();
+ }
+
+ long long timeDifference = abs(pLocationImpl->GetTimestampInMs() - lastLocationTime);
+ SysLog(NID_LOC, "Time difference between last location timestamp (%lld) and current location timestamp (%lld) is (%lld).", lastLocationTime, pLocationImpl->GetTimestampInMs(), timeDifference);
+ if (timeDifference > 0)
+ {
+ isNew = true;
+ currentAccuracy = __pLocationManager->GetAccuracyLevel(pLocation->GetHorizontalAccuracy());
+ }
+
+ if (currentAccuracy != __lastLocationAccuracy)
+ {
+ SysLog(NID_LOC, "Notify the accuracy change.");
+ __lastLocationAccuracy = currentAccuracy;
+ __pLocationListener->OnAccuracyChanged(currentAccuracy);
+ }
+
+ if (reqId == __reqId)
+ {
+ HandleLocationUpdate(location, isNew);
+ }
+ else if (reqId == __regionReqId)
+ {
+ HandleRegionMonitoring(location, isNew);
+ }
+
+ delete pLocation;
+}
+
+void
+_LocationProviderImpl::OnLocationUpdateStatusChanged(Tizen::Locations::LocationServiceStatus locSvcStatus)
+{
+ __pLocationListener->OnLocationUpdateStatusChanged(locSvcStatus);
+}
+
+void
+_LocationProviderImpl::OnRegionMonitoringStatusChanged(Tizen::Locations::LocationServiceStatus locSvcStatus)
+{
+ __pLocationListener->OnRegionMonitoringStatusChanged(locSvcStatus);
+}
+
+void
+_LocationProviderImpl::OnActiveAppChanged(const Tizen::App::AppId& appId)
+{
+ Tizen::App::App* pApp = Tizen::App::App::GetInstance();
+ Tizen::App::AppId currentAppId = pApp->GetAppId();
+
+ SysLog(NID_LOC, "Active App ID is (%ls) and the current app Id is (%ls)", appId.GetPointer(), currentAppId.GetPointer());
+
+ if (currentAppId == appId)
+ {
+ SysLog(NID_LOC, "Application is active.");
+
+ if (__locationUpdateStatus == LOC_SVC_STATUS_PAUSED)
+ {
+ SysLog(NID_LOC, "Start the location updates as the location update status is PAUSED.");
+ __pLocationManager->StartLocationUpdates(__criteria.GetAccuracy(), __updateInterval, this, __reqId);
+ __locationUpdateStatus = LOC_SVC_STATUS_NOT_FIXED;
+ __pLocationListener->OnLocationUpdateStatusChanged(__locationUpdateStatus);
+ }
+ }
+ else
+ {
+ SysLog(NID_LOC, "Application is not active.");
+ if (__awakeEnabled == false && (__locationUpdateStatus == LOC_SVC_STATUS_RUNNING || __locationUpdateStatus == LOC_SVC_STATUS_NOT_FIXED))
+ {
+ SysLog(NID_LOC, "Stop the location updates as application is not active with awake mode as (%d) and location update state as (%x).", __awakeEnabled, __locationUpdateStatus);
+ __pLocationManager->StopLocationUpdates(__reqId);
+ __locationUpdateStatus = LOC_SVC_STATUS_PAUSED;
+ __pLocationListener->OnLocationUpdateStatusChanged(__locationUpdateStatus);
+ }
+ }
+}
+
+result
+_LocationProviderImpl::StartLocationUpdates(LocationUpdateType updateType, int interval, double distance)
+{
+ result r = E_SUCCESS;
+ const int CHECKING_INTERVAL = 10;
+
+ if (updateType == _LOCATION_UPDATE_TYPE_INTERVAL)
+ {
+ __updateInterval = interval;
+ }
+ else if (updateType == _LOCATION_UPDATE_TYPE_DISTANCE)
+ {
+ __updateInterval = CHECKING_INTERVAL;
+ __distanceThreshold = distance;
+ }
+
+ __locationUpdateType = updateType;
+
+ if (__awakeEnabled == true)
+ {
+ r = __pLocationManager->StartLocationUpdates(__criteria.GetAccuracy(), __updateInterval, this, __reqId);
+ SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to start the Native location updates.", GetErrorMessage(r));
+ __locationUpdateStatus = LOC_SVC_STATUS_NOT_FIXED;
+ }
+ else
+ {
+ UiApp* pAppInstance = Tizen::App::UiApp::GetInstance();
+ if (pAppInstance == null)
+ {
+ __locationUpdateStatus = LOC_SVC_STATUS_PAUSED;
+ }
+ else
+ {
+ AppUiState appUiState = pAppInstance->GetAppUiState();
+ if (appUiState == APP_UI_STATE_FOREGROUND || appUiState == APP_UI_STATE_PARTIAL_BACKGROUND)
+ {
+ r = __pLocationManager->StartLocationUpdates(__criteria.GetAccuracy(), __updateInterval, this, __reqId);
+ SysTryCatch(NID_LOC, r == E_SUCCESS, , r, "[%s] Failed to start the location updates. Propagating.", GetErrorMessage(r));
+ __locationUpdateStatus = LOC_SVC_STATUS_NOT_FIXED;
+ }
+ else
+ {
+ __locationUpdateStatus = LOC_SVC_STATUS_PAUSED;
+ }
+ }
+ }
+
+ SysLog(NID_LOC, "Update type is (%x). The request Id is (%ld) and the update status is (%x).", __locationUpdateType, __reqId, __locationUpdateStatus);
+ NotifyServiceStatus(_LOC_PRV_EVENT_SEND_LOC_SVC_CB, __locationUpdateStatus);
+
+ return E_SUCCESS;
+
+CATCH:
+ __locationUpdateType = _LOCATION_UPDATE_TYPE_NONE;
+ return r;
+}
+
+bool
+_LocationProviderImpl::CheckDistanceThreshold(const Location& oldPosition, const Location& newPosition)
+{
+ double displacement = 0.0;
+ const Coordinates coordOld = oldPosition.GetCoordinates();
+ const Coordinates coordNew = newPosition.GetCoordinates();
+
+ if (__firstLocationUpdate)
+ {
+ SysLog(NID_LOC, "First location update. So send true.");
+ __firstLocationUpdate = false;
+ return true;
+ }
+
+ displacement = coordOld.GetDistanceTo(coordNew);
+ SysLog(NID_LOC, "Displacement is (%lf)", displacement);
+ return ((displacement > __distanceThreshold) ? true : false);
+}
+
+void
+_LocationProviderImpl::ResetLocationUpdates(void)
+{
+ __firstLocationUpdate = true;
+ __reqId = -1;
+ __lastLocationAccuracy = LOC_ACCURACY_INVALID;
+ __locationUpdateType = _LOCATION_UPDATE_TYPE_NONE;
+ __locationUpdateStatus = LOC_SVC_STATUS_IDLE;
+ __updateInterval = 0;
+ __distanceThreshold = 0.0;
+}
+
+void
+_LocationProviderImpl::FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg)
+{
+ _ILocProviderEventListener* pLocProviderEventListener = dynamic_cast< _ILocProviderEventListener* >(&listener);
+ SysTryReturnVoidResult(NID_LOC, pLocProviderEventListener, E_SYSTEM, "[E_INVALID_ARG] The listener is null.");
+
+ IEventArg* pArg = const_cast< IEventArg* >(&arg);
+ _LocProviderEventArg* pEventArg = dynamic_cast< _LocProviderEventArg* >(pArg);
+ SysTryReturnVoidResult(NID_LOC, pEventArg, E_SYSTEM, "[E_INVALID_ARG] Event argument is null.");
+
+ _LocProviderEventType eventType = pEventArg->GetEventType();
+ switch (eventType)
+ {
+ case _LOC_PRV_EVENT_SEND_LOC:
+ pLocProviderEventListener->OnLocationEventReceivedN(pEventArg->GetRequestId(), *pEventArg->GetLocationN());
+ break;
+
+ case _LOC_PRV_EVENT_SEND_LOC_SVC_CB:
+ pLocProviderEventListener->OnLocationUpdateStatusChanged(pEventArg->GetLocServiceStatus());
+ break;
+
+ case _LOC_PRV_EVENT_SEND_MONITOR_SVC_CB:
+ pLocProviderEventListener->OnRegionMonitoringStatusChanged(pEventArg->GetLocServiceStatus());
+ break;
+ }
+}
+
+void
+_LocationProviderImpl::HandleLocationUpdate(Tizen::Locations::Location& location, bool isNew)
+{
+ LocationServiceStatus newLocationUpdateStatus = __locationUpdateStatus;
+
+ if (isNew)
+ {
+ if (__locationUpdateType != _LOCATION_UPDATE_TYPE_NONE && __locationUpdateStatus != LOC_SVC_STATUS_PAUSED)
+ {
+ newLocationUpdateStatus = LOC_SVC_STATUS_RUNNING;
+ }
+ }
+ else if (_LocationImpl::GetInstance(location)->IsDenied())
+ {
+ SysLog(NID_LOC, "User consent not available.");
+ if (__locationUpdateType != _LOCATION_UPDATE_TYPE_NONE && __locationUpdateStatus != LOC_SVC_STATUS_PAUSED)
+ {
+ newLocationUpdateStatus = LOC_SVC_STATUS_DENIED;
+ }
+ }
+ else
+ {
+ SysLog(NID_LOC, "Invalid Location Update.");
+ if (__locationUpdateType != _LOCATION_UPDATE_TYPE_NONE && __locationUpdateStatus != LOC_SVC_STATUS_PAUSED)
+ {
+ newLocationUpdateStatus = LOC_SVC_STATUS_NOT_FIXED;
+ }
+ }
+
+ if (newLocationUpdateStatus != __locationUpdateStatus)
+ {
+ SysLog(NID_LOC, "Location Update Satus changed to (%x). Notify the status.", newLocationUpdateStatus);
+ __locationUpdateStatus = newLocationUpdateStatus;
+ __pLocationListener->OnLocationUpdateStatusChanged(__locationUpdateStatus);
+ }
+
+ if (newLocationUpdateStatus == LOC_SVC_STATUS_RUNNING)
+ {
+ if (__locationUpdateType == _LOCATION_UPDATE_TYPE_DISTANCE)
+ {
+ if (CheckDistanceThreshold(*__pLastLocation.get(), location) == true)
+ {
+ SysLog(NID_LOC, "Location displacement exceeds the distance threshold (%lf). Notify the location.", __distanceThreshold);
+ __pLocationListener->OnLocationUpdated(location);
+ *__pLastLocation.get() = location;
+ }
+ }
+ else if (__locationUpdateType == _LOCATION_UPDATE_TYPE_INTERVAL)
+ {
+ SysLog(NID_LOC, "Location time interval expired. Notify the location.");
+ __pLocationListener->OnLocationUpdated(location);
+ *__pLastLocation.get() = location;
+ }
+ }
+}
+
+void
+_LocationProviderImpl::HandleRegionMonitoring(Tizen::Locations::Location& location, bool isNew)
+{
+ LocationServiceStatus newRegionMonitorStatus = __regionMonitorStatus;
+
+ if (isNew)
+ {
+ newRegionMonitorStatus = LOC_SVC_STATUS_RUNNING;
+ }
+ else if (_LocationImpl::GetInstance(location)->IsDenied())
+ {
+ newRegionMonitorStatus = LOC_SVC_STATUS_DENIED;
+ }
+ else
+ {
+ newRegionMonitorStatus = LOC_SVC_STATUS_NOT_FIXED;
+ }
+
+ if (newRegionMonitorStatus != __regionMonitorStatus)
+ {
+ SysLog(NID_LOC, "Region Monitoring Satus changed to (%x). Notify the status.", newRegionMonitorStatus);
+ __regionMonitorStatus = newRegionMonitorStatus;
+ __pLocationListener->OnRegionMonitoringStatusChanged(__regionMonitorStatus);
+ }
+
+ if (newRegionMonitorStatus == LOC_SVC_STATUS_RUNNING)
+ {
+ NotifyRegionCrossedStatus(location);
+ *__pLastLocation.get() = location;
+ }
+}
+
+void
+_LocationProviderImpl::NotifyRegionCrossedStatus(const Tizen::Locations::Location& location)
+{
+ int count = __pRegionList->GetCount();
+
+ SysLog(NID_LOC, "Number of regions currently monitored is (%d)", count);
+
+ for (int i = 0; i < count; i++)
+ {
+ _RegionInfo* pRegionInfo = static_cast< _RegionInfo* >(__pRegionList->GetAt(i));
+
+ if (pRegionInfo)
+ {
+ Coordinates regionCoordinate = pRegionInfo->GetCoordinate();
+ _RegionState currentState = REGION_STATE_UNKNOWN;
+ _RegionState previousState = pRegionInfo->GetPreviousValidState();
+ bool notifyStateChange = false;
+
+ currentState = GetRegionCurrentState(*pRegionInfo, location);
+ SysLog(NID_LOC, "Current Region state is (%d) and Previous Region state is (%d)", currentState, previousState);
+
+ if (currentState != REGION_STATE_UNKNOWN && previousState != currentState)
+ {
+ notifyStateChange = true;
+ pRegionInfo->SetValidPreviousState(currentState);
+ }
+
+ if ((pRegionInfo->GetRegionState() == REGION_STATE_INSIDE || pRegionInfo->GetRegionState() == REGION_STATE_UNKNOWN) && currentState == REGION_STATE_OUTSIDE)
+ {
+ if (notifyStateChange)
+ {
+ SysLog(NID_LOC, "Notify the boundary crossed event as previous valid region state is INSIDE and current state is OUTSIDE.");
+ __pLocationListener->OnRegionLeft(pRegionInfo->GetRegionId());
+ }
+ }
+ else if ((pRegionInfo->GetRegionState() == REGION_STATE_OUTSIDE || pRegionInfo->GetRegionState() == REGION_STATE_UNKNOWN) && currentState == REGION_STATE_INSIDE)
+ {
+ if (notifyStateChange)
+ {
+ SysLog(NID_LOC, "Notify the boundary crossed event as previous valid region state is OUTSIDE and current state is INSIDE.");
+ __pLocationListener->OnRegionEntered(pRegionInfo->GetRegionId());
+ }
+ }
+ pRegionInfo->SetRegionState(currentState);
+ }
+ }
+}
+
+_RegionState
+_LocationProviderImpl::GetRegionCurrentState(const _RegionInfo& region, const Location& location)
+{
+ TryReturn(location.GetHorizontalAccuracy() >= 0.0, REGION_STATE_UNKNOWN, "Location received with invalid accuracy");
+
+ SysLog(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());
+ SysLog(NID_LOC, "[RegionID %d] Location Information is (Latitude: %lf, Longitude: %lf, Horizontal accuracy:%lf", region.GetRegionId(), location.GetCoordinates().GetLatitude(),
+ location.GetCoordinates().GetLongitude(), location.GetHorizontalAccuracy());
+
+ _RegionState regionState = REGION_STATE_UNKNOWN;
+
+ double distanceBtwCenters = region.GetCoordinate().GetDistanceTo(location.GetCoordinates());
+ double regionRadius = region.GetRadius();
+ double locationRadius = location.GetHorizontalAccuracy();
+
+ SysLog(NID_LOC, "[RegionID %d] The distance between centers is (%lf)", region.GetRegionId(), distanceBtwCenters);
+
+ if (distanceBtwCenters >= (regionRadius + locationRadius))
+ {
+ regionState = REGION_STATE_OUTSIDE;
+ }
+ else if (distanceBtwCenters < regionRadius && Double::Compare(locationRadius, 0.0) == 0)
+ {
+ SysLog(NID_LOC, "[RegionID %d] Location Radius is 0 and distance < regionRadius", region.GetRegionId());
+ regionState = REGION_STATE_INSIDE;
+ }
+ else
+ {
+ double radiusThreshold = (1 / Math::Sqrt(2)) * locationRadius;
+
+ if (regionRadius < radiusThreshold)
+ {
+ SysLog(NID_LOC, "[RegionID %d] Region circle is less than 50 percent area of the location circle.", region.GetRegionId());
+ regionState = (distanceBtwCenters >= locationRadius) ? REGION_STATE_OUTSIDE : REGION_STATE_UNKNOWN;
+
+ return regionState;
+ }
+ else
+ {
+ double overlapRegion = _MathUtils::CalculateOverlapRegion(region, location);
+ double upperThreshold = 0;
+ double lowerThreshold = 0;
+ double occupancy = 0;
+
+ SysLog(NID_LOC, "[RegionID %d] OverlapRegion is (%lf)", region.GetRegionId(), overlapRegion);
+
+ if (regionRadius >= locationRadius)
+ {
+ // Calculate occupancy % with the location circle
+ SysLog(NID_LOC, "[RegionID %d] Region radius is bigger.", region.GetRegionId());
+ occupancy = (overlapRegion / (Math::GetPi() * locationRadius * locationRadius)) * 100;
+
+ upperThreshold = 60;
+ lowerThreshold = 40;
+ }
+ else if (regionRadius >= radiusThreshold)
+ {
+ SysLog(NID_LOC, "[RegionID %d] The ratio of Region radius to location radius is between 0.707 and 1.", region.GetRegionId());
+ double thresholdValue = -136.51 * (regionRadius / locationRadius) + 146.51; // This equation varies the threshold value from 10 (for R/r = 1) to 50 (for R/r = 0.707)
+
+ SysLog(NID_LOC, "[RegionID %d] Threshold value is %lf.", region.GetRegionId(), thresholdValue);
+
+ occupancy = (overlapRegion / (Math::GetPi() * locationRadius * locationRadius)) * 100;
+
+ upperThreshold = 50 + thresholdValue;
+ lowerThreshold = 50 - thresholdValue;
+ }
+
+ // Decide the state with as per the inner and outer thresholds
+ SysLog(NID_LOC, "[RegionID %d] Occupancy is (%lf), Upper threshold is (%lf) and lower threshold is (%lf).", region.GetRegionId(), occupancy, upperThreshold, lowerThreshold);
+ regionState = (occupancy >= upperThreshold) ? REGION_STATE_INSIDE : ((occupancy <= lowerThreshold) ? REGION_STATE_OUTSIDE : REGION_STATE_UNKNOWN);
+ }
+ }
+
+ SysLog(NID_LOC, "[RegionID %d] Returning region state as (%d).", region.GetRegionId(), regionState);
+ return regionState;
+}
+
+void
+_LocationProviderImpl::NotifyServiceStatus(_LocProviderEventType eventType, LocationServiceStatus svcStatus)
+{
+ std::unique_ptr< _LocProviderEventArg > pLocProviderEventArg(new (std::nothrow) _LocProviderEventArg());
+ if (pLocProviderEventArg)
+ {
+ pLocProviderEventArg->SetEventType(eventType);
+ pLocProviderEventArg->SetLocServiceStatus(svcStatus);
+
+ result r = _Event::FireAsync(*pLocProviderEventArg.get());
+ SysTryReturnVoidResult(NID_LOC, r == E_SUCCESS, r, "[%s] Failed to fire the event.", GetErrorMessage(r));
+
+ pLocProviderEventArg.release();
+ }
+
+ return;
+}
+
+bool
+_LocationProviderImpl::GetUserPrivilege(void)
+{
+ _LocationManager* pLocMgr = _LocationManager::GetInstance();
+ SysTryReturn(NID_LOC, pLocMgr, false, E_SYSTEM, "[E_SYSTEM] Failed to get the location manager instance.");
+
+ bool appSettingEnabled = pLocMgr->IsAppEnabled();
+ if (appSettingEnabled == false)
+ {
+ return false;
+ }
+
+ bool hasPrivilege = false;
+ result gps = E_SUCCESS;
+ result wps = E_SUCCESS;
+
+ bool gpsEnabled = true;
+ bool wpsEnabled = true;
+
+ gps = _SettingInfoImpl::GetValue(L"http://tizen.org/setting/location.gps", gpsEnabled);
+ wps = _SettingInfoImpl::GetValue(L"http://tizen.org/setting/location.wps", wpsEnabled);
+
+ hasPrivilege = gpsEnabled | wpsEnabled;
+
+ if (gps != E_SUCCESS || wps != E_SUCCESS || hasPrivilege == false)
+ {
+ return false;
+ }
+
+ return true;
+}
+}}
diff --git a/src/FLoc_LocationProviderImpl.h b/src/FLoc_LocationProviderImpl.h
new file mode 100644
index 0000000..3b78e53
--- /dev/null
+++ b/src/FLoc_LocationProviderImpl.h
@@ -0,0 +1,255 @@
+//
+// 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_LocationProviderImpl.h
+ * @brief This is the header file for the %_LocationProviderImpl class.
+ *
+ * This header file contains the declarations of the %_LocationProviderImpl class.
+ */
+
+#ifndef _FLOC_INTERNAL_LOCATION_PROVIDER_IMPL_H_
+#define _FLOC_INTERNAL_LOCATION_PROVIDER_IMPL_H_
+
+#include <unique_ptr.h>
+#include <FAppIActiveAppEventListener.h>
+#include <FBaseColAllElementsDeleter.h>
+#include <FBaseRtTimer.h>
+#include <FBaseRtIEventListener.h>
+#include <FLocLocationCriteria.h>
+#include <FBaseRt_Event.h>
+#include "FLoc_ILocationManagerListener.h"
+#include "FLoc_ILocProviderEventListener.h"
+#include "FLoc_LocProviderEventArg.h"
+#include "FLoc_RegionInfo.h"
+
+namespace Tizen { namespace Locations
+{
+
+class Coordinates;
+class _LocationManager;
+class _LocProviderEventArg;
+
+enum LocationUpdateType
+{
+ _LOCATION_UPDATE_TYPE_NONE,
+ _LOCATION_UPDATE_TYPE_INTERVAL,
+ _LOCATION_UPDATE_TYPE_DISTANCE
+};
+
+class _LocationProviderImpl
+ : public Tizen::Base::Runtime::_Event
+ , public Tizen::Locations::_ILocationManagerListener
+ , public Tizen::Locations::_ILocProviderEventListener
+ , public Tizen::App::IActiveAppEventListener
+{
+public:
+ /**
+ * This is the default constructor of this class.
+ *
+ * @since 2.0
+ */
+ _LocationProviderImpl(void);
+
+ /**
+ * This is the destructor of this class
+ *
+ * @since 2.0
+ */
+ virtual ~_LocationProviderImpl(void);
+
+ /**
+ * @see @ref Tizen::Locations::LocationProvider::Construct()
+ */
+ result Construct(const LocationCriteria& criteria, ILocationProviderListener& listener);
+
+ /**
+ * @see @ref Tizen::Locations::LocationProvider::StartLocationUpdates()
+ */
+ result StartLocationUpdatesByInterval(int interval);
+
+ /**
+ * @see @ref Tizen::Locations::LocationProvider::StartLocationUpdates()
+ */
+ result StartLocationUpdatesByDistance(double distance);
+
+ /**
+ * @see @ref Tizen::Locations::LocationProvider::StopLocationUdpates()
+ */
+ result StopLocationUpdates(void);
+
+ /**
+ * @see @ref Tizen::Locations::LocationProvider::KeepLocationUpdateAwake()
+ */
+ void KeepLocationUpdateAwake(bool enable);
+
+ /**
+ * @see @ref Tizen::Locations::LocationProvider::AddRegionMonitoring()
+ */
+ result AddMonitoringRegion(const Tizen::Locations::Coordinates& regionCenter, double radius, RegionId& regionId);
+
+ /**
+ * @see @ref Tizen::Locations::LocationProvider::RemoveRegionMonitoring()
+ */
+ result RemoveMonitoringRegion(int regionId);
+
+ /**
+ * @see @ref Tizen::Locations::LocationProvider::RemoveAllRegionMonitoring()
+ */
+ void RemoveAllMonitoringRegions(void);
+
+ /**
+ * @see @ref Tizen::Locations::LocationProvider::GetLocationUpdateStatus()
+ */
+ LocationServiceStatus GetLocationUpdateStatus(void) const;
+
+ /**
+ * @see @ref Tizen::Locations::LocationProvider::GetRegionMonitoringStatus()
+ */
+ LocationServiceStatus GetRegionMonitoringStatus(void) const;
+
+ /**
+ * @see @ref Tizen::Locations::LocationProvider::GetCurrentAccuracy()
+ */
+ LocationAccuracy GetCurrentAccuracy(void) const;
+
+ /**
+ * @see @ref Tizen::Locations::LocationProvider::GetLocation()
+ */
+ static Location GetLocation(const LocationCriteria& criteria);
+
+ /**
+ * @see @ref Tizen::Locations::LocationProvider::GetLocation()
+ */
+ static Location GetLastKnownLocation(void);
+
+private:
+ // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
+ //
+ // @since 2.0
+ //
+ _LocationProviderImpl(const _LocationProviderImpl& rhs);
+
+ // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
+ //
+ // @since 2.0
+ //
+ _LocationProviderImpl& operator =(const _LocationProviderImpl& rhs);
+
+ /**
+ * @see @ref Tizen::Locations::_ILocationManagerListener::OnLocationUpdated()
+ */
+ virtual void OnLocationUpdated(RequestId reqId, const Tizen::Locations::Location& location);
+
+ /**
+ * @see @ref Tizen::Locations::_ILocProviderEventListener::OnLocationEventReceivedN()
+ */
+ virtual void OnLocationEventReceivedN(RequestId reqId, Tizen::Locations::Location& location);
+
+ /**
+ * @see @ref Tizen::Locations::_ILocProviderEventListener::OnLocationUpdateStatusChanged()
+ */
+ virtual void OnLocationUpdateStatusChanged(Tizen::Locations::LocationServiceStatus locSvcStatus);
+
+ /**
+ * @see @ref Tizen::Locations::_ILocProviderEventListener::OnRegionMonitoringStatusChanged()
+ */
+ virtual void OnRegionMonitoringStatusChanged(Tizen::Locations::LocationServiceStatus locSvcStatus);
+
+ /**
+ * @see @ref Tizen::App::IActiveAppEventListener::OnActiveAppChanged()
+ */
+ virtual void OnActiveAppChanged(const Tizen::App::AppId& appId);
+
+ // This method requests the location update to the Location Manager.
+ //
+ // @since 2.0
+ //
+ result StartLocationUpdates(LocationUpdateType updateType, int interval, double distance);
+
+ // This method is used to check if the new position is at a certain distance from the original position.
+ //
+ // @since 2.0
+ //
+ bool CheckDistanceThreshold(const Tizen::Locations::Location& oldPosition, const Tizen::Locations::Location& newPosition);
+
+ // This method is used to reset the member variables.
+ //
+ // @since 2.0
+ //
+ void ResetLocationUpdates(void);
+
+ // @see @ref Tizen::Base::Runtime::Event::FireImpl()
+ //
+ // @since 2.0
+ //
+ virtual void FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg);
+
+ // This method is handles the location udpates.
+ //
+ // @since 2.0
+ //
+ void HandleLocationUpdate(Tizen::Locations::Location& location, bool isLocationValid);
+
+ // This method handles the region monitoring.
+ //
+ // @since 2.0
+ //
+ void HandleRegionMonitoring(Tizen::Locations::Location& location, bool isLocationValid);
+
+ // This method sends the callbacks to the applications regarding the Region events.
+ // @since 2.0
+ //
+ void NotifyRegionCrossedStatus(const Tizen::Locations::Location& location);
+
+ // This method finds the region status of a particular region w.r.t the given location.
+ // @since 2.0
+ //
+ _RegionState GetRegionCurrentState(const _RegionInfo& region, const Location& location);
+
+ // This method sends the service status update callback to the application.
+ // @since 2.0
+ //
+ void NotifyServiceStatus(_LocProviderEventType eventType, LocationServiceStatus svcStatus);
+
+ // This method is returns the bool value depicting the privilege details depending on the location settings.
+ //
+ // @since 2.0
+ //
+ static bool GetUserPrivilege(void);
+
+private:
+ bool __firstLocationUpdate;
+ bool __regionMonitoringActive;
+ bool __awakeEnabled;
+ int __updateInterval;
+ LocationUpdateType __locationUpdateType;
+ LocationServiceStatus __locationUpdateStatus;
+ LocationServiceStatus __regionMonitorStatus;
+ LocationAccuracy __lastLocationAccuracy;
+ RequestId __reqId;
+ RequestId __regionReqId;
+ double __distanceThreshold;
+ LocationCriteria __criteria;
+ ILocationProviderListener* __pLocationListener;
+ _LocationManager* __pLocationManager;
+ std::unique_ptr< Tizen::Locations::Location > __pLastLocation;
+ std::unique_ptr< Tizen::Base::Collection::ArrayList, Tizen::Base::Collection::AllElementsDeleter > __pRegionList;
+}; // _LocationProviderImpl
+}} // Tizen::Locations
+
+#endif // _FLOC_INTERNAL_LOCATION_PROVIDER_IMPL_H_
diff --git a/src/FLoc_LocationRequestInfo.h b/src/FLoc_LocationRequestInfo.h
new file mode 100644
index 0000000..de3602c
--- /dev/null
+++ b/src/FLoc_LocationRequestInfo.h
@@ -0,0 +1,83 @@
+//
+// 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_LocationRequestInfo.h
+ * @brief This is the header file for the %_LocationRequestInfo class.
+ *
+ * This header file contains the declarations of the %_LocationRequestInfo class member variables.
+ */
+
+#ifndef _FLOC_INTERNAL_LOCATION_REQUEST_INFO_H_
+#define _FLOC_INTERNAL_LOCATION_REQUEST_INFO_H_
+
+#include <FBaseObject.h>
+#include <FLocTypes.h>
+
+namespace Tizen { namespace Locations
+{
+
+class _ILocationManagerListener;
+
+class _LocationRequestInfo
+ : public Tizen::Base::Object
+{
+public:
+ _LocationRequestInfo(LocationAccuracy accuracy, int interval, _ILocationManagerListener* pListener, RequestId reqId)
+ : Tizen::Base::Object()
+ , __interval(interval)
+ , __reqId(reqId)
+ , __accuracy(accuracy)
+ , __pListener(pListener)
+ {
+ }
+
+ ~_LocationRequestInfo(void)
+ {
+ }
+
+ _LocationRequestInfo(const _LocationRequestInfo& rhs)
+ : Tizen::Base::Object()
+ , __interval(rhs.__interval)
+ , __reqId(rhs.__reqId)
+ , __accuracy(rhs.__accuracy)
+ , __pListener(rhs.__pListener)
+ {
+ }
+
+ LocationAccuracy GetAccuracy(void) const {return __accuracy;}
+
+ int GetInterval(void) const {return __interval;}
+
+ _ILocationManagerListener* GetListener(void) const {return __pListener;}
+
+ RequestId GetRequestId(void) const {return __reqId;}
+
+private:
+ _LocationRequestInfo(void);
+
+ _LocationRequestInfo& operator =(const _LocationRequestInfo& rhs);
+
+private:
+ int __interval;
+ RequestId __reqId;
+ LocationAccuracy __accuracy;
+ _ILocationManagerListener* __pListener;
+}; //_LocationRequestInfo
+}} //Tizen::Locations
+
+#endif // _FLOC_INTERNAL_LOCATION_REQUEST_INFO_H_
diff --git a/src/FLoc_MathUtils.cpp b/src/FLoc_MathUtils.cpp
new file mode 100644
index 0000000..25c2b6a
--- /dev/null
+++ b/src/FLoc_MathUtils.cpp
@@ -0,0 +1,73 @@
+//
+// 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_MathUtils.cpp
+ * @brief This is the implementation file for _MathUtils class.
+ *
+ * This file contains implementation of _MathUtils class.
+ */
+
+#include <math.h>
+#include <FBaseSysLog.h>
+#include <FBaseUtilMath.h>
+#include <FLocLocation.h>
+#include "FLoc_MathUtils.h"
+#include "FLoc_RegionInfo.h"
+
+using namespace Tizen::Base::Utility;
+
+
+namespace Tizen { namespace Locations
+{
+
+const double _MathUtils::PI = M_PI;
+const double _MathUtils::PI2 = 2.0 * _MathUtils::PI;
+const double _MathUtils::DEG2RAD = _MathUtils::PI / 180.0;
+const double _MathUtils::RAD2DEG = 180.0 / _MathUtils::PI;
+const double _MathUtils::HALFPI = 1.5707963267948966;
+const double _MathUtils::CENTRE_LATITUDE = 0.0;
+
+double
+_MathUtils::CalculateOverlapRegion(const _RegionInfo& region, const Location& location)
+{
+ double overlapArea = 0;
+ double distanceBtwCenters = region.GetCoordinate().GetDistanceTo(location.GetCoordinates());
+ double regionRadius = region.GetRadius();
+ double locationRadius = location.GetHorizontalAccuracy();
+
+ double distanceBtwCentersSqr = distanceBtwCenters * distanceBtwCenters;
+ double regionRadiusSqr = regionRadius * regionRadius;
+ double locationRadiusSqr = locationRadius * locationRadius;
+
+ // The circles are overlapping
+ if (distanceBtwCenters <= Math::Abs(regionRadius - locationRadius))
+ {
+ overlapArea = locationRadius > regionRadius ? Math::GetPi() * regionRadiusSqr : Math::GetPi() * locationRadiusSqr;
+ }
+ else
+ {
+ double theta = Math::Acos((regionRadiusSqr + distanceBtwCentersSqr - locationRadiusSqr) / (2 * regionRadius * distanceBtwCenters));
+ double phi = Math::Acos((locationRadiusSqr + distanceBtwCentersSqr - regionRadiusSqr) / (2 * locationRadius * distanceBtwCenters));
+
+ overlapArea = regionRadiusSqr * (theta - Math::Sin(theta) * Math::Cos(theta)) + locationRadiusSqr * (phi - Math::Sin(phi) * Math::Cos(phi));
+ }
+
+ return overlapArea;
+}
+
+} } // Tizen::Locations
diff --git a/src/FLoc_MathUtils.h b/src/FLoc_MathUtils.h
new file mode 100644
index 0000000..082de85
--- /dev/null
+++ b/src/FLoc_MathUtils.h
@@ -0,0 +1,65 @@
+//
+// 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_MathUtils.h
+ * @brief This is the header file for the _MathUtils class.
+ *
+ * This header file contains declaration of the _MathUtils class.
+ *
+ */
+
+#ifndef _FLOC_INTERNAL_MATH_UTILS_H_
+#define _FLOC_INTERNAL_MATH_UTILS_H_
+
+namespace Tizen { namespace Locations
+{
+
+// forward declaration
+class Location;
+class _RegionInfo;
+
+/**
+ * @class _MathUtils
+ * @since 2.0
+ *
+ * This class provides fundamental constants and operations for helping mathematical calculation.
+ */
+class _MathUtils
+{
+public:
+ // This method calculates the overlapped area between a region circle and the location uncertainty circle with horizontal accuracy as the radius.
+ // @since 2.0
+ //
+ static double CalculateOverlapRegion(const _RegionInfo& region, const Location& location);
+
+public:
+ static const double PI;
+ static const double PI2;
+ static const double DEG2RAD;
+ static const double RAD2DEG;
+ static const double HALFPI;
+ static const double CENTRE_LATITUDE;
+
+private:
+ _MathUtils(void);
+}; // class _MathUtils
+
+} } // Tizen::Locations
+
+#endif // _FLOC_INTERNAL_MATH_UTILS_H_
diff --git a/src/FLoc_RegionInfo.h b/src/FLoc_RegionInfo.h
new file mode 100644
index 0000000..654acbd
--- /dev/null
+++ b/src/FLoc_RegionInfo.h
@@ -0,0 +1,86 @@
+//
+// 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_RegionInfo.h
+ * @brief This is the header file for the %_RegionInfo class.
+ *
+ * This header file contains the declarations of the %_RegionInfo class member variables.
+ */
+
+#ifndef _FLOC_INTERNAL_REGION_INFO_H_
+#define _FLOC_INTERNAL_REGION_INFO_H_
+
+#include <FBaseObject.h>
+#include <FLocCoordinates.h>
+#include <FLocTypes.h>
+#include "FLoc_Types.h"
+
+namespace Tizen { namespace Locations
+{
+
+class _RegionInfo
+ : public Tizen::Base::Object
+{
+public:
+ _RegionInfo(Coordinates coordinate, double radius, RegionId regionId)
+ : Tizen::Base::Object()
+ , __coordinate(coordinate)
+ , __radius(radius)
+ , __regionId(regionId)
+ , __state(REGION_STATE_UNKNOWN)
+ , __preValidState(REGION_STATE_UNKNOWN)
+ , __requestedAccuracy(LOC_ACCURACY_INVALID)
+ , __timerValue(0)
+ {
+ }
+
+ ~_RegionInfo()
+ {
+ }
+
+ Coordinates GetCoordinate(void) const {return __coordinate;}
+
+ double GetRadius(void) const {return __radius;}
+
+ RegionId GetRegionId(void) const {return __regionId;}
+
+ _RegionState GetRegionState(void) const {return __state;}
+
+ void SetRegionState(_RegionState state) {__state = state;}
+
+ _RegionState GetPreviousValidState(void) const {return __preValidState;}
+
+ void SetValidPreviousState(_RegionState prevState) {__preValidState = prevState;}
+
+private:
+ _RegionInfo(const _RegionInfo& rhs);
+
+ _RegionInfo& operator =(const _RegionInfo& rhs);
+
+private:
+ Coordinates __coordinate;
+ double __radius;
+ RegionId __regionId;
+ _RegionState __state;
+ _RegionState __preValidState;
+ LocationAccuracy __requestedAccuracy;
+ int __timerValue;
+}; //_RegionInfo
+}} //Tizen::Locations
+
+#endif // _FLOC_INTERNAL_REGION_INFO_H_
diff --git a/src/FLoc_SyncLocationRequestInfo.h b/src/FLoc_SyncLocationRequestInfo.h
new file mode 100644
index 0000000..0b22c78
--- /dev/null
+++ b/src/FLoc_SyncLocationRequestInfo.h
@@ -0,0 +1,117 @@
+//
+// 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_SyncLocationRequestInfo.h
+ * @brief This is the header file for the %_SyncLocationRequestInfo class.
+ *
+ * This header file contains the declarations of the %_SyncLocationRequestInfo class member variables.
+ */
+
+#ifndef _FLOC_INTERNAL_SYNC_LOCATION_REQUEST_INFO_H_
+#define _FLOC_INTERNAL_SYNC_LOCATION_REQUEST_INFO_H_
+
+#include <new>
+#include <unique_ptr.h>
+#include <FBaseObject.h>
+#include <FBaseRtTimer.h>
+#include <FBaseRtITimerEventListener.h>
+#include <FLocTypes.h>
+#include <FSysSystemTime.h>
+
+namespace Tizen { namespace Locations
+{
+class _LocationMonitor;
+class _LocationManager;
+
+class _SyncLocationRequestInfo
+ : public Tizen::Base::Object
+{
+public:
+ _SyncLocationRequestInfo(_LocationMonitor* pLocMonitor, RequestId reqId)
+ : Tizen::Base::Object()
+ , __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;}
+
+ bool IsInTime(const Tizen::Base::DateTime& timestamp)
+ {
+ return (timestamp > __requestTime) ? true : false;
+ }
+
+ bool IsAccuracySatisfying(LocationAccuracy accuracy)
+ {
+ if (accuracy == LOC_ACCURACY_INVALID)
+ {
+ return false;
+ }
+ else
+ {
+ return (accuracy <= __pLocMonitor->GetAccuracy()) ? true : false;
+ }
+ }
+
+private:
+ _SyncLocationRequestInfo(void);
+
+ _SyncLocationRequestInfo& operator =(const _SyncLocationRequestInfo& rhs);
+
+private:
+ Tizen::Base::DateTime __requestTime;
+ _LocationMonitor* __pLocMonitor;
+ std::unique_ptr< Tizen::Base::Runtime::Timer > __pTimer;
+ RequestId __reqId;
+ int __tickCount;
+}; //_SyncLocationRequestInfo
+}} //Tizen::Locations
+#endif // _FLOC_INTERNAL_SYNC_LOCATION_REQUEST_INFO_H_
diff --git a/src/FLoc_Types.h b/src/FLoc_Types.h
new file mode 100644
index 0000000..b2e4067
--- /dev/null
+++ b/src/FLoc_Types.h
@@ -0,0 +1,54 @@
+//
+// 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_Types.h
+* @brief This is the header file for the constants used internally in Locations module.
+*
+*/
+
+#ifndef _FLOC_INTERNAL_TYPES_H_
+#define _FLOC_INTERNAL_TYPES_H_
+
+#include <FBaseUtilMath.h>
+
+using namespace Tizen::Base::Utility;
+
+namespace Tizen { namespace Locations
+{
+
+enum _RegionState
+{
+ REGION_STATE_UNKNOWN,
+ REGION_STATE_INSIDE,
+ REGION_STATE_OUTSIDE,
+};
+
+static const double MAX_LATITUDE = 90.0;
+static const double MIN_LATITUDE = -90.0;
+static const double MAX_LONGITUDE = 180.0;
+static const double MIN_LONGITUDE = -180.0;
+
+const int ACCURACY_FINEST = 5;
+const int ACCURACY_TEN_MTRS = 10;
+const int ACCURACY_HUNDRED_MTRS = 100;
+const int ACCURACY_ONE_KILOMETER = 1000;
+const int ACCURACY_ANY = 10000;
+
+const double NaN = Math::Acos(2);
+} } // Tizen::Locations
+#endif // _FLOC_INTERNAL_TYPES_H_