summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJinkun Jang <jinkun.jang@samsung.com>2013-03-13 01:45:58 +0900
committerJinkun Jang <jinkun.jang@samsung.com>2013-03-13 01:45:58 +0900
commit0c4363b425e20b6141145c45e0c83d88936e67cb (patch)
treeef3d3865dffeaf128232523da23b064a20b46ce8
parent6fefcfb3259ce0088331bcb92224dfecd29fe898 (diff)
downloadlocation-manager-0c4363b425e20b6141145c45e0c83d88936e67cb.tar.gz
location-manager-0c4363b425e20b6141145c45e0c83d88936e67cb.tar.bz2
location-manager-0c4363b425e20b6141145c45e0c83d88936e67cb.zip
Tizen 2.1 base
-rw-r--r--AUTHORS1
-rwxr-xr-xCMakeLists.txt98
-rw-r--r--LICENSE206
-rw-r--r--capi-location-manager.manifest5
-rw-r--r--capi-location-manager.pc.in15
-rw-r--r--include/location_bounds.h255
-rw-r--r--include/location_preference.h391
-rw-r--r--include/locations.h725
-rwxr-xr-xinclude/locations_private.h87
-rwxr-xr-xpackaging/capi-location-manager.spec56
-rwxr-xr-xsrc/location_bounds.c315
-rwxr-xr-xsrc/location_preference.c514
-rwxr-xr-xsrc/locations.c1017
-rw-r--r--test/CMakeLists.txt19
-rw-r--r--test/location_test.c339
15 files changed, 4043 insertions, 0 deletions
diff --git a/AUTHORS b/AUTHORS
new file mode 100644
index 0000000..111161d
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1 @@
+Kangho Hur <kanho.hur@samsung.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100755
index 0000000..4174b65
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,98 @@
+
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+SET(fw_name "capi-location-manager")
+
+PROJECT(${fw_name})
+
+SET(CMAKE_INSTALL_PREFIX /usr)
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+
+SET(INC_DIR include)
+INCLUDE_DIRECTORIES(${INC_DIR})
+
+SET(dependents "dlog location capi-base-common")
+SET(pc_dependents "capi-base-common")
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(${fw_name} REQUIRED ${dependents})
+FOREACH(flag ${${fw_name}_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall -Werror")
+SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
+
+IF("${ARCH}" STREQUAL "arm")
+ ADD_DEFINITIONS("-DTARGET")
+ENDIF("${ARCH}" STREQUAL "arm")
+
+ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
+ADD_DEFINITIONS("-DTIZEN_DEBUG")
+
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=/usr/lib")
+
+aux_source_directory(src SOURCES)
+ADD_LIBRARY(${fw_name} SHARED ${SOURCES})
+
+SET_TARGET_PROPERTIES(${fw_name}
+ PROPERTIES
+ VERSION ${FULLVER}
+ SOVERSION ${MAJORVER}
+ CLEAN_DIRECT_OUTPUT 1
+)
+
+TARGET_LINK_LIBRARIES(${fw_name} ${${fw_name}_LDFLAGS})
+
+INSTALL(TARGETS ${fw_name} DESTINATION lib)
+INSTALL(
+ DIRECTORY ${INC_DIR}/ DESTINATION include/location
+ FILES_MATCHING
+ PATTERN "*_private.h" EXCLUDE
+ PATTERN "${INC_DIR}/*.h"
+ )
+
+SET(PC_NAME ${fw_name})
+SET(PC_REQUIRED ${pc_dependents})
+SET(PC_LDFLAGS -l${fw_name})
+SET(PC_CFLAGS -I\${includedir}/location)
+
+CONFIGURE_FILE(
+ ${fw_name}.pc.in
+ ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc
+ @ONLY
+)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc DESTINATION lib/pkgconfig)
+
+ADD_SUBDIRECTORY(test)
+
+IF(UNIX)
+
+ADD_CUSTOM_TARGET (distclean @echo cleaning for source distribution)
+ADD_CUSTOM_COMMAND(
+ DEPENDS clean
+ COMMENT "distribution clean"
+ COMMAND find
+ ARGS .
+ -not -name config.cmake -and \(
+ -name tester.c -or
+ -name Testing -or
+ -name CMakeFiles -or
+ -name cmake.depends -or
+ -name cmake.check_depends -or
+ -name CMakeCache.txt -or
+ -name cmake.check_cache -or
+ -name *.cmake -or
+ -name Makefile -or
+ -name core -or
+ -name core.* -or
+ -name gmon.out -or
+ -name install_manifest.txt -or
+ -name *.pc -or
+ -name *~ \)
+ | grep -v TC | xargs rm -rf
+ TARGET distclean
+ VERBATIM
+)
+
+ENDIF(UNIX)
+
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..bbe9d02
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,206 @@
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+ 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/capi-location-manager.manifest b/capi-location-manager.manifest
new file mode 100644
index 0000000..97e8c31
--- /dev/null
+++ b/capi-location-manager.manifest
@@ -0,0 +1,5 @@
+<manifest>
+ <request>
+ <domain name="_"/>
+ </request>
+</manifest>
diff --git a/capi-location-manager.pc.in b/capi-location-manager.pc.in
new file mode 100644
index 0000000..150e613
--- /dev/null
+++ b/capi-location-manager.pc.in
@@ -0,0 +1,15 @@
+
+# Package Information for pkg-config
+
+prefix=@PREFIX@
+exec_prefix=/usr
+libdir=/usr/lib
+includedir=/usr/include/location
+
+Name: @PC_NAME@
+Description: @PACKAGE_DESCRIPTION@
+Version: @VERSION@
+Requires: @PC_REQUIRED@
+Libs: -L${libdir} @PC_LDFLAGS@
+Cflags: -I${includedir}
+
diff --git a/include/location_bounds.h b/include/location_bounds.h
new file mode 100644
index 0000000..64f846e
--- /dev/null
+++ b/include/location_bounds.h
@@ -0,0 +1,255 @@
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* 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.
+*/
+
+#ifndef __TIZEN_LOCATION_BOUNDS_H__
+#define __TIZEN_LOCATION_BOUNDS_H__
+
+#include <tizen_type.h>
+#include <tizen_error.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define LOCATION_BOUNDS_ERROR_CLASS TIZEN_ERROR_LOCATION_CLASS | 0x20
+
+/**
+ * @addtogroup CAPI_LOCATION_BOUNDS_MODULE
+ * @{
+ */
+
+/**
+ * @brief Represents a coordinates with latitude and longitude.
+ */
+typedef struct
+{
+ double latitude; /**< The latitude [-90.0 ~ 90.0] (degrees) */
+ double longitude; /**< The longitude [-180.0 ~ 180.0] (degrees) */
+} location_coords_s;
+
+/**
+ * @brief Enumerations of error code for Location manager.
+ */
+typedef enum
+{
+ LOCATION_BOUNDS_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
+ LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
+ LOCATION_BOUNDS_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
+ LOCATION_BOUNDS_ERROR_INCORRECT_TYPE = LOCATION_BOUNDS_ERROR_CLASS | 0x01, /**< Incorrect bounds type for a given call */
+ LOCATION_BOUNDS_ERROR_IS_ADDED = LOCATION_BOUNDS_ERROR_CLASS | 0x02, /**< Cannot remove bounds handle from location manager */
+} location_bound_error_e;
+
+/**
+ * @brief Location boundary type.
+ */
+typedef enum
+{
+ LOCATION_BOUNDS_RECT = 1, /**< Rectangular geographical area type. */
+ LOCATION_BOUNDS_CIRCLE, /**< Circle geographical area type.. */
+ LOCATION_BOUNDS_POLYGON, /**< Polygon geographical area type.. */
+} location_bounds_type_e;
+
+/**
+ * @brief Enumerations of the boundary state.
+ */
+typedef enum
+{
+ LOCATIONS_BOUNDARY_IN, /**< Boundary In (Zone In) */
+ LOCATIONS_BOUNDARY_OUT /**< Boundary Out (Zone Out) */
+} location_boundary_state_e;
+
+/**
+ * @brief The location boundary handle.
+ */
+typedef struct location_bounds_s *location_bounds_h;
+
+/**
+ * @brief Gets called iteratively to notify you of coordinates of polygon.
+ * @param[in] coords The coordinates
+ * @param[in] user_data The user data passed from the foreach function
+ * @return @c true to continue with the next iteration of the loop, \n @c false to break out of the loop
+ * @pre location_bounds_foreach_polygon_coords() will invoke this callback.
+ * @see location_bounds_foreach_polygon_coords()
+ */
+typedef bool (*polygon_coords_cb)(location_coords_s coords, void *user_data);
+
+/**
+ * @brief Called when the given boundary is entered or exited.
+ * @param[in] state The boundary state
+ * @pre location_manager_start() will invoke this callback if you register this callback using location_bounds_set_state_changed_cb()
+ * @see #location_boundary_state_e
+ * @see location_manager_start()
+ * @see location_bounds_set_state_changed_cb()
+ */
+typedef void (*location_bounds_state_changed_cb)(location_boundary_state_e state, void *user_data);
+
+/**
+ * @brief Creates a rect type of new location bounds.
+ * @remarks @a bounds must be released location_bounds_destroy() by you.
+ * @param[in] top_left The top left position
+ * @param[in] bottom_right The bottom right position
+ * @param[out] bounds A location bounds handle to be newly created on success
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATION_BOUNDS_ERROR_NONE Successful
+ * @retval #LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #LOCATION_BOUNDS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see location_bounds_get_rect_coords()
+ * @see location_bounds_destroy()
+ */
+int location_bounds_create_rect(location_coords_s top_left, location_coords_s bottom_right, location_bounds_h* bounds);
+
+/**
+ * @brief Creates a circle type of new location bounds.
+ * @remarks @a bounds must be released location_bounds_destroy() by you.
+ * @param[in] center The center position
+ * @param[in] radius The radius of a circle (meters)
+ * @param[out] bounds A location bounds handle to be newly created on success
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATION_BOUNDS_ERROR_NONE Successful
+ * @retval #LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #LOCATION_BOUNDS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see location_bounds_get_circle_coords()
+ * @see location_bounds_destroy()
+ */
+int location_bounds_create_circle(location_coords_s center, double radius, location_bounds_h* bounds);
+
+/**
+ * @brief Creates a polygon type of new location bounds.
+ * @remarks @a bounds must be released location_bounds_destroy() by you.
+ * @remarks @a length sholud be over than 3 to represent polygon.
+ * @param[in] coords_list The list of coordinates
+ * @param[in] length The length of the coordinates list
+ * @param[out] bounds A location bounds handle to be newly created on success
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATION_BOUNDS_ERROR_NONE Successful
+ * @retval #LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #LOCATION_BOUNDS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see location_bounds_foreach_polygon_coords()
+ * @see location_bounds_destroy()
+ */
+int location_bounds_create_polygon(location_coords_s* coords_list, int length, location_bounds_h* bounds);
+
+/**
+ * @brief Check if the bounds contains the specified coordinates.
+ * @param[in] bounds The location bounds handle
+ * @param[in] coords The coordinates
+ * @param[out] contained The result indicating whether the boundary contains the specified coordinate (@c true = contained, @c false = not contained )
+ * @return @c true if the bouns contains the specified coordinates. \n else @c false
+ * @see location_bounds_create_rect()
+ * @see location_bounds_create_circle()
+ * @see location_bounds_create_polygon()
+ */
+bool location_bounds_contains_coordinates(location_bounds_h bounds, location_coords_s coords);
+
+/**
+ * @brief Get the type of location bounds.
+ * @param[in] bounds The location bounds handle
+ * @param[out] type The type of location bounds
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATION_BOUNDS_ERROR_NONE Successful
+ * @retval #LOCATION_BOUNDS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see location_bounds_create_rect()
+ * @see location_bounds_create_circle()
+ * @see location_bounds_create_polygon()
+ */
+int location_bounds_get_type(location_bounds_h bounds, location_bounds_type_e *type);
+
+/**
+ * @brief Get the center position and radius of circle bounds.
+ * @param[in] bounds The location bounds handle
+ * @param[out] top_left The top left position
+ * @param[out] bottom_right The bottom right position
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATION_BOUNDS_ERROR_NONE Successful
+ * @retval #LOCATION_BOUNDS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #LOCATION_BOUNDS_ERROR_INCORRECT_TYPE Incorrect bounds type
+ * @see location_bounds_create_rect()
+ */
+int location_bounds_get_rect_coords(location_bounds_h bounds, location_coords_s *top_left, location_coords_s *bottom_right);
+
+/**
+ * @brief Get the center position and radius of circle bounds.
+ * @param[in] bounds The location bounds handle
+ * @param[out] center The center position of circle
+ * @param[radius] center The radius of circle
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATION_BOUNDS_ERROR_NONE Successful
+ * @retval #LOCATION_BOUNDS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #LOCATION_BOUNDS_ERROR_INCORRECT_TYPE Incorrect bounds type
+ * @see location_bounds_create_circle()
+ */
+int location_bounds_get_circle_coords(location_bounds_h bounds, location_coords_s *center, double *radius);
+
+/**
+ * @brief Get the coordinates of polygon.
+ * @param[in] bounds The location bounds handle
+ * @param[in] callback The geocoder get positions callback function
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATION_BOUNDS_ERROR_NONE Successful
+ * @retval #LOCATION_BOUNDS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #LOCATION_BOUNDS_ERROR_INCORRECT_TYPE Incorrect bounds type
+ * @post It invokes polygon_coords_cb() to get coordinates of polygon.
+ * @see polygon_coords_cb()
+ * @see location_bounds_create_polygon()
+ */
+int location_bounds_foreach_polygon_coords(location_bounds_h bounds, polygon_coords_cb callback, void *user_data);
+
+/**
+ * @brief Releases the location bounds.
+ * @param[in] bounds The location bounds handle
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATION_BOUNDS_ERROR_NONE Successful
+ * @retval #LOCATION_BOUNDS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see location_bounds_create_rect()
+ * @see location_bounds_create_circle()
+ * @see location_bounds_create_polygon()
+*/
+int location_bounds_destroy(location_bounds_h bounds);
+
+/**
+ * @brief Registers a callback function to be invoked when boundary area is entered or exited.
+ * @param[in] bounds The location bounds handle
+ * @param[in] callback The callback function to register
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATION_BOUNDS_ERROR_NONE Successful
+ * @retval #LOCATION_BOUNDS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @post location_bounds_state_changed_cb() will be invoked
+ * @see location_bounds_unset_state_changed_cb()
+ * @see location_bounds_state_changed_cb()
+ */
+int location_bounds_set_state_changed_cb(location_bounds_h bounds, location_bounds_state_changed_cb callback, void* user_data);
+
+/**
+ * @brief Unregisters the callback function.
+ * @param[in] bounds The location bounds handle
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATION_BOUNDS_ERROR_NONE Successful
+ * @retval #LOCATION_BOUNDS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see location_bounds_set_state_changed_cb()
+ */
+int location_bounds_unset_state_changed_cb(location_bounds_h bounds);
+
+/**
+ * @}
+ */
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_LOCATION_BOUNDS_H__ */
+
diff --git a/include/location_preference.h b/include/location_preference.h
new file mode 100644
index 0000000..3cbaa11
--- /dev/null
+++ b/include/location_preference.h
@@ -0,0 +1,391 @@
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* 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.
+*/
+
+#ifndef __TIZEN_LOCATION_LOCATION_PREFERENCE_H__
+#define __TIZEN_LOCATION_LOCATION_PREFERENCE_H__
+
+#include <tizen_type.h>
+#include <tizen_error.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/**
+ * @addtogroup CAPI_LOCATION_PREF_MODULE
+ * @{
+ */
+
+/**
+ * @brief The handle of location service
+ */
+typedef void* location_service_h;
+
+
+/**
+ * @brief Gets a handle of location service from x
+ */
+#define GET_LOCATION_SERVICE(x) (location_service_h)(x)
+
+
+/**
+ * @brief Enumerations of error code for Location Preference
+ */
+typedef enum
+{
+ LOCATION_PREFERENCE_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
+ LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
+ LOCATION_PREFERENCE_ERROR_RESULT_NOT_FOUND = TIZEN_ERROR_LOCATION_CLASS|0x0101, /**< Result not found */
+ LOCATION_PREFERENCE_ERROR_NETWORK_FAILED = TIZEN_ERROR_LOCATION_CLASS|0x0102, /**< Network unavailable */
+ LOCATION_PREFERENCE_ERROR_INVALID_KEY = TIZEN_ERROR_LOCATION_CLASS | 0x0103, /**< Invalid key */
+} location_preference_error_e;
+
+/**
+ * @brief Enumerations of distance unit
+ */
+typedef enum
+{
+ LOCATION_PREFERENCE_DISTANCE_UNIT_M = 0, /**< Meter */
+ LOCATION_PREFERENCE_DISTANCE_UNIT_KM = 1, /**< Kilometer */
+ LOCATION_PREFERENCE_DISTANCE_UNIT_FT = 2, /**< Feet */
+ LOCATION_PREFERENCE_DISTANCE_UNIT_YD = 3, /**< Mile */
+ LOCATION_PREFERENCE_DISTANCE_UNIT_MI = 4, /**< Mile */
+} location_preference_distance_unit_e;
+
+/**
+ * @brief Called repeatedly when you get the available property keys.
+ * @param[in] key The property key of location preference
+ * @param[in] user_data The user data passed from foreach function
+ * @pre location_preference_foreach_available_property_keys() will invoke this callback.
+ * @return @c true to continue with the next iteration of the loop, \n @c false to break out of the loop
+ * @see location_preference_foreach_available_property_keys()
+ */
+typedef bool (*location_preference_available_property_key_cb)(const char* key, void* user_data);
+
+/**
+ * @brief Called repeatedly when you get the available property values.
+ * @param[in] value The property value of location preference
+ * @param[in] user_data The user data passed from foreach function
+ * @pre location_preference_foreach_available_property_values() will invoke this callback.
+ * @return @c true to continue with the next iteration of the loop, \n @c false to break out of the loop
+ * @see location_preference_foreach_available_property_values()
+ */
+typedef bool (*location_preference_available_property_value_cb)(const char* value, void* user_data);
+
+/**
+ * @brief Called repeatedly when you get the available languages.
+ * @param[in] language The language of location preference
+ * @param[in] user_data The user data passed from foreach function
+ * @pre location_preference_foreach_available_languages() will invoke this callback.
+ * @return @c true to continue with the next iteration of the loop, \n @c false to break out of the loop
+ * @see location_preference_foreach_available_languages()
+ */
+typedef bool (*location_preference_available_language_cb)(const char* language, void* user_data);
+
+/**
+ * @brief Called repeatedly when you get the available country code.
+ * @param[in] country_code The country code of location preference
+ * @param[in] user_data The user data passed from foreach function
+ * @pre location_preference_foreach_available_country_code() will invoke this callback.
+ * @return @c true to continue with the next iteration of the loop, \n @c false to break out of the loop
+ * @see location_preference_foreach_available_country_code()
+ */
+typedef bool (*location_preference_available_country_code_cb)(const char* country_code, void* user_data);
+
+/**
+ * @brief Called repeatedly when you get the properties that was set in location preference.
+ * @param[in] key The property key of location preference
+ * @param[in] value The property value of location preference
+ * @param[in] user_data The user data passed from foreach function
+ * @pre location_preference_foreach_properties() will invoke this callback.
+ * @return @c true to continue with the next iteration of the loop, \n @c false to break out of the loop
+ * @see location_preference_foreach_properties()
+ */
+typedef bool (*location_preference_property_cb)(const char* key, const char* value, void* user_data);
+
+/**
+ * @brief Called repeatedly to get each supported providers.
+ * @param[in] provider The supported provider name
+ * @param[in] user_data The user data passed from the foreach function
+ * @return @c true to continue with the next iteration of the loop, \n @c false to break outsp of the loop.
+ * @pre location_preference_foreach_supported_provider() will invoke this callback.
+ * @see location_preference_foreach_supported_provider()
+ */
+typedef bool (*location_preference_supported_provider_cb)(const char* provider, void *user_data);
+
+/**
+ * @brief Retrieves the available property keys of location preference.
+ * @param[in] location_service The memory pointer of location service handle.
+ * It must be converted into location_service_h by GET_LOCATION_SERVICE().
+ * @param[in] callback The callback function to be invoked
+ * @param[in] user_data The user data passed to the callback function
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATION_PREFERENCE_ERROR_NONE Successful
+ * @retval #LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #LOCATION_PREFERENCE_ERROR_NETWORK_FAILED Network unavailable
+ * @retval #LOCATION_PREFERENCE_ERROR_RESULT_NOT_FOUND Result not found
+ * @post location_preference_available_property_key_cb() will be invoked.
+ * @see GET_LOCATION_SERVICE()
+ * @see location_preference_available_property_key_cb()
+ * @see location_preference_foreach_available_property_values()
+ */
+int location_preference_foreach_available_property_keys(location_service_h service, location_preference_available_property_key_cb callback, void* user_data);
+
+/**
+ * @brief Retrieves the available property values of location preference.
+ * @param[in] location_service The memory pointer of location service handle.
+ * It must be converted into location_service_h by GET_LOCATION_SERVICE().
+ * @param[in] key The property of location preference
+ * @param[in] callback The callback function to be invoked
+ * @param[in] user_data The user data passed to the callback function
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATION_PREFERENCE_ERROR_NONE Successful
+ * @retval #LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #LOCATION_PREFERENCE_ERROR_INVALID_KEY Invalid key
+ * @retval #LOCATION_PREFERENCE_ERROR_RESULT_NOT_FOUND Result not found
+ * @post location_preference_available_property_value_cb() will be invoked.
+ * @see GET_LOCATION_SERVICE()
+ * @see location_preference_available_property_value_cb()
+ * @see location_preference_foreach_available_property_keys()
+ */
+int location_preference_foreach_available_property_values(location_service_h service, const char* key, location_preference_available_property_value_cb callback, void* user_data);
+
+/**
+ * @brief Retrieves the available languages of location preference.
+ * @param[in] location_service The memory pointer of location service handle.
+ * It must be converted into location_service_h by GET_LOCATION_SERVICE().
+ * @param[in] callback The callback function to be invoked
+ * @param[in] user_data The user data passed to the callback function
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATION_PREFERENCE_ERROR_NONE Successful
+ * @retval #LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #LOCATION_PREFERENCE_ERROR_NETWORK_FAILED Network unavailable
+ * @retval #LOCATION_PREFERENCE_ERROR_RESULT_NOT_FOUND Result not found
+ * @post location_preference_available_language_cb() will be invoked.
+ * @see GET_LOCATION_SERVICE()
+ * @see location_preference_available_language_cb()
+ */
+int location_preference_foreach_available_languages(location_service_h service, location_preference_available_language_cb callback, void* user_data);
+
+/**
+ * @brief Retrieves the available country code of location preference.
+ * @param[in] location_service The memory pointer of location service handle.
+ * It must be converted into location_service_h by GET_LOCATION_SERVICE().
+ * @param[in] callback The callback function to be invoked
+ * @param[in] user_data The user data passed to the callback function
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATION_PREFERENCE_ERROR_NONE Successful
+ * @retval #LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #LOCATION_PREFERENCE_ERROR_NETWORK_FAILED Network unavailable
+ * @retval #LOCATION_PREFERENCE_ERROR_RESULT_NOT_FOUND Result not found
+ * @post location_preference_available_country_code_cb() will be invoked.
+ * @see GET_LOCATION_SERVICE()
+ * @see location_preference_available_country_code_cb()
+ */
+int location_preference_foreach_available_country_code(location_service_h service, location_preference_available_country_code_cb callback, void* user_data);
+
+/**
+ * @brief Gets the location preference that was set in location preference.
+ * @param[in] location_service The memory pointer of location service handle.
+ * It must be converted into location_service_h by GET_LOCATION_SERVICE().
+ * @param[in] key The property of location preference
+ * @param[in] callback The callback function to be invoked
+ * @param[in] user_data The user data passed to the callback function
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATION_PREFERENCE_ERROR_NONE Successful
+ * @retval #LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see GET_LOCATION_SERVICE()
+ */
+int location_preference_foreach_properties(location_service_h service, location_preference_property_cb callback, void* user_data);
+
+/**
+ * @brief Sets the location preference value.
+ * @param[in] location_service The memory pointer of location service handle.
+ * It must be converted into location_service_h by GET_LOCATION_SERVICE().
+ * @param[in] property The property of location preference
+ * @param[in] value The value of location preference
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATION_PREFERENCE_ERROR_NONE Successful
+ * @retval #LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see GET_LOCATION_SERVICE()
+ * @see location_preference_foreach_available_property_keys()
+ * @see location_preference_foreach_available_property_values()
+ * @see location_preference_get()
+ */
+int location_preference_set(location_service_h service, const char* key, const char* value);
+
+/**
+ * @brief Gets the location preference value.
+ * @param[in] location_service The memory pointer of location service handle.
+ * It must be converted into location_service_h by GET_LOCATION_SERVICE().
+ * @param[in] property The property of location preference
+ * @param[out] value The value of location preference
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATION_PREFERENCE_ERROR_NONE Successful
+ * @retval #LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #LOCATION_PREFERENCE_ERROR_INVALID_KEY Invalid key
+ * @see GET_LOCATION_SERVICE()
+ * @see location_preference_foreach_available_property_keys()
+ * @see location_preference_set()
+ */
+int location_preference_get(location_service_h service, const char* key, char** value);
+
+__attribute__ ((deprecated)) int location_preference_get_provider_name(location_service_h service, char** provider);
+
+/**
+ * @brief Sets the provider of location service.
+ * @param[in] location_service The memory pointer of location service handle.
+ * It must be converted into location_service_h by GET_LOCATION_SERVICE().
+ * @param[in] provider The provider name of location service
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATION_PREFERENCE_ERROR_NONE Successful
+ * @retval #LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see GET_LOCATION_SERVICE()
+ * @see location_preference_get_provider()
+ */
+int location_preference_set_provider(location_service_h service, char* provider);
+
+/**
+ * @brief Gets the provider of location service.
+ * @remarks The @a provider must be released with free() by you.
+ * @param[in] location_service The memory pointer of location service handle.
+ * It must be converted into location_service_h by GET_LOCATION_SERVICE().
+ * @param[out] provider The provider name of location service
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATION_PREFERENCE_ERROR_NONE Successful
+ * @retval #LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see GET_LOCATION_SERVICE()
+ * @see location_preference_set_provider()
+ */
+int location_preference_get_provider(location_service_h service, char** provider);
+
+/**
+ * @brief Gets the default provider of location service.
+ * @remarks The @a provider must be released with free() by you.
+ * @param[in] location_service The memory pointer of location service handle.
+ * It must be converted into location_service_h by GET_LOCATION_SERVICE().
+ * @param[out] provider The default provider name of location service
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATION_PREFERENCE_ERROR_NONE Successful
+ * @retval #LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see GET_LOCATION_SERVICE()
+ */
+int location_preference_get_default_provider(location_service_h service, char** provider);
+
+/**
+ * @brief Gets the provider of location service.
+ * @param[in] location_service The memory pointer of location service handle.
+ * It must be converted into location_service_h by GET_LOCATION_SERVICE().
+ * @param[in] callback The callback function to be invoked
+ * @param[in] user_data The user data passed to the callback function
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATION_PREFERENCE_ERROR_NONE Successful
+ * @retval #LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @post This function invokes location_preference_supported_provider_cb() to get all supported providers.
+ * @see GET_LOCATION_SERVICE()
+ * @see location_preference_set_provider()
+ */
+int location_preference_foreach_supported_provider(location_service_h service, location_preference_supported_provider_cb callback , void *user_data);
+
+/**
+ * @brief Gets the distance unit of location service.
+ * @param[in] location_service The memory pointer of location service handle.
+ * It must be converted into location_service_h by GET_LOCATION_SERVICE().
+ * @param[out] unit The distance unit
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATION_PREFERENCE_ERROR_NONE Successful
+ * @retval #LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #LOCATION_PREFERENCE_ERROR_RESULT_NOT_FOUND Result not found
+ * @see GET_LOCATION_SERVICE()
+ * @see location_preference_set_distance_unit()
+ */
+int location_preference_get_distance_unit(location_service_h service, location_preference_distance_unit_e* unit);
+
+/**
+ * @brief Sets the distance unit of location service.
+ * @param[in] location_service The memory pointer of location service handle.
+ * It must be converted into location_service_h by GET_LOCATION_SERVICE().
+ * @param[in] unit The distance unit
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATION_PREFERENCE_ERROR_NONE Successful
+ * @retval #LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see GET_LOCATION_SERVICE()
+ * @see location_preference_get_distance_unit()
+ */
+int location_preference_set_distance_unit(location_service_h service, location_preference_distance_unit_e unit);
+
+/**
+ * @brief Gets the language of location service.
+ * @param[in] location_service The memory pointer of location service handle.
+ * It must be converted into location_service_h by GET_LOCATION_SERVICE().
+ * @param[out] language The language
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATION_PREFERENCE_ERROR_NONE Successful
+ * @retval #LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see GET_LOCATION_SERVICE()
+ * @see location_preference_set_language()
+ */
+int location_preference_get_language(location_service_h service, char** language);
+
+/**
+ * @brief Sets the language of location service.
+ * @param[in] location_service The memory pointer of location service handle.
+ * It must be converted into location_service_h by GET_LOCATION_SERVICE().
+ * @param[in] language The language
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATION_PREFERENCE_ERROR_NONE Successful
+ * @retval #LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see GET_LOCATION_SERVICE()
+ * @see location_preference_get_language()
+ */
+int location_preference_set_language(location_service_h service, const char* language);
+
+/**
+ * @brief Sets the country code.
+ * @param[in] location_service The memory pointer of location service handle.
+ * It must be converted into location_service_h by GET_LOCATION_SERVICE().
+ * @param[in] country_code The country code
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATION_PREFERENCE_ERROR_NONE Successful
+ * @retval #LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see GET_LOCATION_SERVICE()
+ * @see location_preference_get_country_code()
+ */
+int location_preference_set_country_code(location_service_h service, const char* country_code);
+
+/**
+ * @brief Gets the country code.
+ * @param[in] location_service The memory pointer of location service handle.
+ * It must be converted into location_service_h by GET_LOCATION_SERVICE().
+ * @param[out] country_code The country code
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATION_PREFERENCE_ERROR_NONE Successful
+ * @retval #LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see GET_LOCATION_SERVICE()
+ * @see location_preference_set_country_code()
+ */
+int location_preference_get_country_code(location_service_h service, char** country_code);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_LOCATION_LOCATION_PREFERENCE_H__ */
diff --git a/include/locations.h b/include/locations.h
new file mode 100644
index 0000000..e1121fa
--- /dev/null
+++ b/include/locations.h
@@ -0,0 +1,725 @@
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* 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.
+*/
+
+#ifndef __TIZEN_LOCATION_LOCATIONS_H__
+#define __TIZEN_LOCATION_LOCATIONS_H__
+
+#include <tizen_type.h>
+#include <tizen_error.h>
+#include <location_bounds.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @addtogroup CAPI_LOCATION_MANAGER_MODULE
+ * @{
+ */
+
+/**
+ * @brief Enumerations of error code for Location manager.
+ */
+typedef enum
+{
+ LOCATIONS_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
+ LOCATIONS_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
+ LOCATIONS_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
+ LOCATIONS_ERROR_INCORRECT_METHOD = TIZEN_ERROR_LOCATION_CLASS | 0x01, /**< Location manager contains incorrect method for a given call */
+ LOCATIONS_ERROR_NETWORK_FAILED = TIZEN_ERROR_LOCATION_CLASS | 0x02, /**< Network unavailable */
+ LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE = TIZEN_ERROR_LOCATION_CLASS | 0x03, /**< Location service is not available */
+ LOCATIONS_ERROR_GPS_SETTING_OFF = TIZEN_ERROR_LOCATION_CLASS | 0x04, /**< GPS/WPS setting is not enabled */
+ LOCATIONS_ERROR_SECURITY_RESTRICTED = TIZEN_ERROR_LOCATION_CLASS | 0x05, /**< Restricted by security system policy */
+ LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED = TIZEN_ERROR_LOCATION_CLASS | 0x06, /**< Location service accessibility is not allowed */
+} location_error_e;
+
+/**
+ * @brief Location method type.
+ */
+typedef enum
+{
+ LOCATIONS_METHOD_NONE=-1, /**< Undefined method. */
+ LOCATIONS_METHOD_HYBRID, /**< This method selects the best method available at the moment. */
+ LOCATIONS_METHOD_GPS, /**< This method uses Global Positioning System. */
+ LOCATIONS_METHOD_WPS, /**< This method uses Wifi Positioning System. */
+ LOCATIONS_METHOD_CPS /**< This method uses Cellular Positioning System. */
+} location_method_e;
+
+/**
+ * @brief Approximate accuracy level of given information.
+ */
+typedef enum
+{
+ LOCATIONS_ACCURACY_NONE=0, /**< Invalid data. */
+ LOCATIONS_ACCURACY_COUNTRY, /**< Country accuracy level. */
+ LOCATIONS_ACCURACY_REGION, /**< Regional accuracy level. */
+ LOCATIONS_ACCURACY_LOCALITY, /**< Local accuracy level. */
+ LOCATIONS_ACCURACY_POSTALCODE, /**< Postal accuracy level. */
+ LOCATIONS_ACCURACY_STREET, /**< Street accuracy level. */
+ LOCATIONS_ACCURACY_DETAILED, /**< Detailed accuracy level. */
+} location_accuracy_level_e;
+
+/**
+ * @brief Enumerations of the state of the location service.
+ */
+typedef enum
+{
+ LOCATIONS_SERVICE_DISABLED, /**< Service is disabled */
+ LOCATIONS_SERVICE_ENABLED /**< Service is enabled */
+} location_service_state_e;
+
+/**
+ * @brief Enumerations of the location service accessibility state.
+ */
+typedef enum
+{
+ LOCATIONS_ACCESS_STATE_NONE, /**< Not determined yet */
+ LOCATIONS_ACCESS_STATE_DENIED, /**< Access denied */
+ LOCATIONS_ACCESS_STATE_ALLOWED, /**< Access authorized */
+} location_accessibility_state_e;
+
+/**
+ * @brief The location manager handle.
+ */
+typedef struct location_manager_s *location_manager_h;
+
+/**
+ * @}
+ */
+/*
+ * Location Manager
+*/
+/**
+ * @addtogroup CAPI_LOCATION_MANAGER_MODULE
+ * @{
+ */
+/**
+ * @brief Called at defined interval with updated position information.
+ * @param[in] latitude The updated latitude [-90.0 ~ 90.0] (degrees)
+ * @param[in] longitude The updated longitude [-180.0 ~ 180.0] (degrees)
+ * @param[in] altitude The updated altitude (meters)
+ * @param[in] timestamp The timestamp (time when measurement took place or 0 if invalid)
+ * @param[in] user_data The user data passed from the call registration function
+ * @pre location_manager_start() will invoke this callback if you register this callback using location_manager_set_position_updated_cb()
+ * @see location_manager_start()
+ * @see location_manager_set_position_updated_cb()
+ */
+typedef void(*location_position_updated_cb)(double latitude, double longitude, double altitude, time_t timestamp, void *user_data);
+
+/**
+ * @brief Called at defined interval with updated velocity information.
+ * @param[in] speed The updated speed (km/h)
+ * @param[in] direction The updated direction (in degrees from the north)
+ * @param[in] climb The updated climb (km/h)
+ * @param[in] timestamp The timestamp (time when measurement took place or 0 if invalid)
+ * @param[in] user_data The user data passed from the callback registration function
+ * @pre location_manager_start() will invoke this callback if you register this callback using location_manager_set_velocity_updated_cb()
+ * @see location_manager_start()
+ * @see location_manager_set_velocity_updated_cb()
+ */
+typedef void(*location_velocity_updated_cb)(double speed, double direction, double climb, time_t timestamp, void *user_data);
+
+/**
+ * @brief Called when the state of location service is changed from enabled to disabled or vice versa.
+ * @param[in] state The service state
+ * @param[in] user_data The user data passed from the callback registration function
+ * @pre Either location_manager_start() or location_manager_stop() will invoke this callback if you register this callback using location_manager_set_service_state_changed_cb()
+ * @see location_manager_start()
+ * @see location_manager_stop()
+ * @see location_manager_set_service_state_changed_cb()
+ * @see #location_service_state_e
+ */
+typedef void(*location_service_state_changed_cb)(location_service_state_e state, void *user_data);
+
+/**
+ * @brief Called when the user defined zones are entered or exited.
+ * @param[in] state The boundary state
+ * @param[in] latitude The updated latitude [-90.0 ~ 90.0] (degrees)
+ * @param[in] longitude The updated longitude [-180.0 ~ 180.0] (degrees)
+ * @param[in] altitude The updated altitude (meters)
+ * @param[in] timestamp The timestamp (time when measurement took place or 0 if invalid)
+ * @param[in] user_data The user data passed from the callback registration function
+ * @pre location_manager_start() will invoke this callback if you register this callback using location_manager_set_zone_changed_cb()
+ * @see #location_boundary_state_e
+ * @see location_manager_start()
+ * @see location_manager_set_zone_changed_cb()
+ */
+typedef void(*location_zone_changed_cb)(location_boundary_state_e state, double latitude, double longitude, double altitude, time_t timestamp, void *user_data);
+
+/**
+ * @brief Gets called iteratively to notify you of location bounds.
+ * @param[in] bounds The location bounds handle
+ * @param[in] user_data The user data passed from the callback registration function
+ * @pre location_manager_foreach_boundary() will invoke this callback.
+ * @see location_manager_foreach_boundary()
+ */
+typedef bool(*location_bounds_cb)(location_bounds_h bounds, void *user_data);
+
+/**
+ * @brief Checks whether the given location method is avaliable or not.
+ * @param[in] method The location method to be checked
+ * @return @c true if the specified location method is supported, \n else @c false
+ * @see location_manager_create()
+ * @see location_manager_get_method()
+ */
+bool location_manager_is_supported_method(location_method_e method);
+
+
+/**
+ * @brief Creates a new location manager.
+ * @remarks @a manager must be released location_manager_destroy() by you.
+ * @param[in] method The location method
+ * @param[out] manager A location manager handle to be newly created on success
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATIONS_ERROR_NONE Successful
+ * @retval #LOCATIONS_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE Service not available
+ * @see location_manager_destroy()
+ */
+int location_manager_create(location_method_e method, location_manager_h* manager);
+
+/**
+ * @brief Releases the location manager.
+ * @param[in] manager The location manager handle
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATIONS_ERROR_NONE Successful
+ * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see location_manager_create()
+*/
+int location_manager_destroy(location_manager_h manager);
+
+/**
+ * @brief Starts the location service.
+ *
+ * @remarks There is no limit on number of location managers for which this function was called.
+ *
+ * Calling this function invokes a location service event. When the location service is enabled, the service state change callback
+ * (set using #location_manager_set_service_state_changed_cb()) notifies the user with #LOCATIONS_SERVICE_ENABLED as
+ * the first argument, and the service starts. \n
+
+ * Started service is a requirement for calling these functions:
+ *
+ * location_manager_get_position(), location_manager_get_velocity(), location_manager_get_accuracy(),
+ * gps_status_get_nmea(), gps_status_get_satellite_count_in_view(), gps_status_foreach_satellites_in_view(), gps_status_get_active_satellite_count().
+ *
+ * Once you stop the service, using #location_manager_stop(), you can no longer call the functions listed above.
+ *
+ * Starting and stopping the service is in the scope of the given location manager only (if there's more than one manager,
+ * starting and stopping should be executed for each of them separately).
+ *
+ * @param[in] manager The location manager handle
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATIONS_ERROR_NONE Successful
+ * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE Service not available
+ * @retval #LOCATIONS_ERROR_NETWORK_FAILED Network failed
+ * @retval #LOCATIONS_ERROR_GPS_SETTING_OFF GPS is not enabled
+ * @post It invokes location_position_updated_cb(), location_velocity_updated_cb(), location_zone_changed_cb(), and location_service_state_changed_cb().
+ * @see location_manager_stop()
+ * @see location_manager_get_position()
+ * @see location_manager_get_velocity()
+ * @see location_manager_get_accuracy()
+ * @see location_manager_set_service_state_changed_cb()
+ * @see location_manager_set_position_updated_cb()
+ * @see location_position_updated_cb()
+ * @see location_manager_set_velocity_updated_cb()
+ * @see location_velocity_updated_cb()
+ * @see location_manager_set_zone_changed_cb()
+ * @see location_zone_changed_cb()
+ */
+int location_manager_start(location_manager_h manager);
+
+/**
+ * @brief Stops the location service.
+ * @remarks This function initiates the process of stopping the service. When the process is finished, callback set using
+ * #location_manager_set_service_state_changed_cb() will be called, with #LOCATIONS_SERVICE_DISABLED as first argument.
+ * When that happens, the service is stopped and the user is notified.
+ *
+ * You can stop and start the location manager as needed.
+ *
+ * @param[in] manager The location manager handle
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATIONS_ERROR_NONE Successful
+ * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE Service not available
+ * @retval #LOCATIONS_ERROR_NETWORK_FAILED Network failed
+ * @see location_manager_start()
+ * @see location_manager_set_service_state_changed_cb()
+ * @see location_service_state_changed_cb()
+ */
+int location_manager_stop(location_manager_h manager);
+
+/**
+ * @brief Adds a bounds for a given location manager.
+ * @param[in] manager The location manager handle
+ * @param[in] bounds The location bounds handle
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATIONS_ERROR_NONE Successful
+ * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #LOCATIONS_ERROR_OUT_OF_MEMORY Out of memory
+ * @post It invokes location_manager_set_zone_changed_cb() when a boundary is entered or exited, if you set a callback with location_manager_set_zone_changed_cb().
+ * @see location_manager_remove_boundary()
+ * @see location_manager_set_zone_changed_cb()
+ * @see location_manager_is_boundary_contains_coordinate()
+ */
+int location_manager_add_boundary(location_manager_h manager, const location_bounds_h bounds);
+
+/**
+ * @brief Deletes a bounds for a given location manager.
+ * @param[in] manager The location manager handle
+ * @param[in] bounds The location bounds handle
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATIONS_ERROR_NONE Successful
+ * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #LOCATIONS_ERROR_OUT_OF_MEMORY Out of memory
+ * @see location_manager_add_boundary()
+ */
+int location_manager_remove_boundary(location_manager_h manager, const location_bounds_h bounds);
+
+/**
+ * @brief Retrieves all location bounds by invoking a specific callback for each locatoin bounds
+ * @param[in] manager The location manager handle
+ * @param[in] callback The iteration callback
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATIONS_ERROR_NONE Successful
+ * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @post location_bounds_cb() will be invoked
+ * @see location_manager_add_boundary()
+ * @see location_manager_remove_boundary()
+ * @see location_bounds_cb()
+ */
+int location_manager_foreach_boundary(location_manager_h manager, location_bounds_cb callback, void *user_data);
+
+/**
+ * @brief Gets the given location manager's method.
+ *
+ * @param[in] manager The location manager handle
+ * @param[out] method The location method
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATIONS_ERROR_NONE Successful
+ * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see location_manager_create()
+ */
+int location_manager_get_method(location_manager_h manager, location_method_e *method);
+
+/**
+ * @brief Gets the current position information.
+ * @details
+ * The result is current altitude, latitude, and longitude, with a measurement timestamp.
+ *
+ * If @a altitude is negative, only altitude and latitude are available (fix status is 2D).
+ * If @a altitude is positive, fix status is 3D and returned altitude value is the result of measurement.
+ *
+ * @param[in] manager The location manager handle
+ * @param[out] altitude The current altitude (meters)
+ * @param[out] latitude The current latitude [-90.0 ~ 90.0] (degrees)
+ * @param[out] longitude The current longitude [-180.0 ~ 180.0] (degrees)
+ * @param[out] timestamp The timestamp (time when measurement took place or 0 if valid)
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATIONS_ERROR_NONE Successful
+ * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid argument
+ * @retval #LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE Service not available
+ * @retval #LOCATIONS_ERROR_GPS_SETTING_OFF GPS is not enabled
+ * @pre The location service state must be #LOCATIONS_SERVICE_ENABLED with location_manager_start()
+ */
+int location_manager_get_position(location_manager_h manager, double *altitude, double *latitude, double *longitude, time_t *timestamp);
+
+/**
+ * @brief Gets the current velocity information.
+ * @details
+ * The result is current climb, direction, and speed, with a measurement timestamp.
+ *
+ * @param[in] manager The location manager handle
+ * @param[out] climb The climb (km/h)
+ * @param[out] direction The direction, degrees from the north
+ * @param[out] speed The speed (km/h)
+ * @param[out] timestamp The timestamp (time when measurement took place or 0 if invalid)
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATIONS_ERROR_NONE Successful
+ * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid argument
+ * @retval #LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE Service not available
+ * @retval #LOCATIONS_ERROR_GPS_SETTING_OFF GPS is not enabled
+ * @pre The location service state must be #LOCATIONS_SERVICE_ENABLED with location_manager_start()
+ */
+int location_manager_get_velocity(location_manager_h manager, double *climb, double *direction, double *speed, time_t *timestamp);
+
+/**
+ * @brief Gets the current accuracy information.
+ * @param[in] manager The location manager handle
+ * @param[out] level The accuracy level
+ * @param[out] horizontal The horizontal accuracy (meters)
+ * @param[out] vertical The vertical accuracy (meters)
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATIONS_ERROR_NONE Successful
+ * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid argument
+ * @retval #LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE Service not available
+ * @retval #LOCATIONS_ERROR_GPS_SETTING_OFF GPS is not enabled
+ * @pre The location service state must be #LOCATIONS_SERVICE_ENABLED with location_manager_start()
+ */
+int location_manager_get_accuracy(location_manager_h manager, location_accuracy_level_e *level, double *horizontal, double *vertical);
+
+/**
+ * @brief Gets the last position information which is recorded.
+ * @details The @a altitude, @a latitude, @a longitude, and @c timestamp values should be 0, if there is no record of any previous position information.
+ * @details If @a altitude is negative, only altitude and latitude are available (fix status is 2D).
+ * @details If @a altitude is positive, fix status is 3D and returned altitude value is the result of measurement.
+ * @param[in] manager The location manager handle
+ * @param[out] altitude The last altitude (meters)
+ * @param[out] latitude The last latitude [-90.0 ~ 90.0] (degrees)
+ * @param[out] longitude The last longitude [-180.0 ~ 180.0] (degrees)
+ * @param[out] timestamp The timestamp (time when measurement took place or 0 if invalid)
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATIONS_ERROR_NONE Successful
+ * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid argument
+ * @pre The location manager handle must be created by location_manager_create()
+ */
+int location_manager_get_last_position(location_manager_h manager, double *altitude, double *latitude, double *longitude, time_t *timestamp);
+
+/**
+ * @brief Gets the last velocity information which is recorded.
+ * @details
+ * The @a climb, @a direction and @a speed values should be 0, if there is no record of any previous velocity information.
+ *
+ * @param[in] manager The location manager handle
+ * @param[out] climb The last climb (km/h)
+ * @param[out] direction The last direction, degrees from the north
+ * @param[out] speed The last speed (km/h)
+ * @param[out] timestamp The timestamp (time when measurement took place or 0 if invalid)
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATIONS_ERROR_NONE Successful
+ * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid argument
+ * @pre The location manager handle must be created by location_manager_create()
+ */
+int location_manager_get_last_velocity(location_manager_h manager, double *climb, double *direction, double *speed, time_t *timestamp);
+
+/**
+ * @brief Gets the last accuracy information which is recorded.
+ * @param[in] manager The location manager handle
+ * @param[out] level The last accuracy level
+ * @param[out] horizontal The last horizontal accuracy (meters)
+ * @param[out] vertical The last vertical accuracy (meters)
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATIONS_ERROR_NONE Successful
+ * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid argument
+ * @pre The location manager handle must be created by location_manager_create()
+ */
+int location_manager_get_last_accuracy(location_manager_h manager, location_accuracy_level_e *level, double *horizontal, double *vertical);
+
+/**
+ * @brief Gets the current application's location accessibility status.
+ * @param[in] manager The location manager handle
+ * @param[out] state The current location service accessibility status.
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATIONS_ERROR_NONE Successful
+ * @retval #LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE Service not available
+ * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid argument
+ */
+int location_manager_get_accessibility_state(location_accessibility_state_e* state);
+
+/**
+ * @brief Registers a callback function to be invoked at defined interval with updated position information.
+ *
+ * @param[in] manager The location manager handle
+ * @param[in] callback The callback function to register
+ * @param[in] interval The interval [1 ~ 120] (seconds)
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATIONS_ERROR_NONE Successful
+ * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @post location_position_updated_cb() will be invoked
+ * @see location_manager_unset_position_updated_cb()
+ * @see location_position_updated_cb()
+ */
+int location_manager_set_position_updated_cb(location_manager_h manager, location_position_updated_cb callback, int interval, void *user_data);
+
+/**
+ * @brief Unregisters the callback function.
+ *
+ * @param[in] manager The location manager handle
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATIONS_ERROR_NONE Successful
+ * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see location_manager_set_position_updated_cb()
+ */
+int location_manager_unset_position_updated_cb(location_manager_h manager);
+
+/**
+ * @brief Registers a callback function to be invoked at defined interval with updated velocity information.
+ *
+ * @param[in] manager The location manager handle
+ * @param[in] callback The callback function to register
+ * @param[in] interval The interval [1 ~ 120] (seconds)
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATIONS_ERROR_NONE Successful
+ * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @post location_velocity_updated_cb() will be invoked
+ * @see location_manager_unset_velocity_updated_cb()
+ * @see location_velocity_updated_cb()
+ */
+int location_manager_set_velocity_updated_cb(location_manager_h manager, location_velocity_updated_cb callback, int interval, void *user_data);
+
+/**
+ * @brief Unregisters the callback function.
+ *
+ * @param[in] manager The location manager handle
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATIONS_ERROR_NONE Successful
+ * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see location_manager_set_velocity_updated_cb()
+ */
+int location_manager_unset_velocity_updated_cb(location_manager_h manager);
+
+/**
+ * @brief Registers a callback function to be invoked when the location service state is changed.
+ *
+ * @param[in] manager The location manager handle
+ * @param[in] callback The callback function to register
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATIONS_ERROR_NONE Successful
+ * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @post location_service_state_changed_cb() will be invoked
+ * @see location_manager_unset_service_state_changed_cb()
+ * @see location_service_state_changed_cb()
+ * @see location_manager_start()
+ * @see location_manager_stop()
+ * @see #location_service_state_e
+*/
+int location_manager_set_service_state_changed_cb(location_manager_h manager, location_service_state_changed_cb callback, void *user_data);
+
+/**
+ * @brief Unregisters the callback function.
+ * @param[in] manager The location manager handle
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATIONS_ERROR_NONE Successful
+ * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see location_manager_set_service_state_changed_cb()
+ */
+int location_manager_unset_service_state_changed_cb(location_manager_h manager);
+
+/**
+ * @brief Registers a callback function to be invoked when the previously set boundary area is entered or left.
+ *
+ * @param[in] manager The location manager handle
+ * @param[in] callback The callback function to register
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATIONS_ERROR_NONE Successful
+ * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @pre Either location_manager_set_boundary_rect() or location_manager_set_boundary_circle() is called before.
+ * @post location_zone_changed_cb() will be invoked
+ * @see location_manager_unset_zone_changed_cb()
+ * @see location_zone_changed_cb()
+ */
+int location_manager_set_zone_changed_cb(location_manager_h manager, location_zone_changed_cb callback, void *user_data);
+
+/**
+ * @brief Unregisters the callback function.
+ * @param[in] manager The location manager handle
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATIONS_ERROR_NONE Successful
+ * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see location_manager_set_zone_changed_cb()
+ */
+int location_manager_unset_zone_changed_cb(location_manager_h manager);
+
+/**
+ * @brief Gets the distance in meters between two locations.
+ * @param[in] start_latitude The starting latitude [-90.0 ~ 90.0] (degrees)
+ * @param[in] start_longitude The starting longitude [-180.0 ~ 180.0] (degrees)
+ * @param[in] end_latitude The ending latitude [-90.0 ~ 90.0] (degrees)
+ * @param[in] end_longitude The ending longitude [-180.0 ~ 180.0] (degrees)
+ * @param[out] distance The distance between two locations (meters)
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATIONS_ERROR_NONE Successful
+ * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid argument
+ */
+int location_manager_get_distance(double start_latitude, double start_longitude, double end_latitude, double end_longitude, double *distance);
+
+/**
+ * @brief Sends command to the server.
+ * @param[in] cmd The command string to be sent
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATIONS_ERROR_NONE Successful
+ * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int location_manager_send_command(const char *cmd);
+
+/**
+ * @}
+ */
+
+/*
+ * GPS Status & Satellites
+ */
+
+/**
+ * @addtogroup CAPI_LOCATION_GPS_STATUS_MODULE
+ * @{
+ */
+
+/**
+ * @brief Called once for each satellite in range.
+ * @param[in] azimuth The azimuth of the satellite (degrees)
+ * @param[in] elevation The elevation of the satellite (meters)
+ * @param[in] prn The PRN of the satellite
+ * @param[in] snr The SNR of the satellite [dB]
+ * @param[in] is_active The flag signaling if satellite is in use
+ * @param[in] user_data The user data passed from the foreach function
+ * @return @c true to continue with the next iteration of the loop, \n @c false to break out of the loop
+ * @pre gps_status_foreach_satellites_in_view() will invoke this callback.
+ * @pre gps_status_foreach_last_satellites_in_view() will invoke this callback.
+ * @see gps_status_foreach_satellites_in_view()
+ */
+typedef bool(*gps_status_get_satellites_cb)(unsigned int azimuth, unsigned int elevation, unsigned int prn, int snr, bool is_active, void *user_data);
+
+/**
+ * @brief Called at defined interval with updated satellite information.
+ * @param[out] num_of_active The last number of active satellites
+ * @param[out] num_of_inview The last number of satellites in view
+ * @param[out] timestamp The last timestamp (time when last measurement took place or 0 if invalid)
+ * @param[in] user_data The user data passed from the call registration function
+ * @pre location_manager_start() will invoke this callback if you register this callback using location_manager_set_position_updated_cb()
+ * @see location_manager_start()
+ * @see location_manager_set_position_updated_cb()
+ */
+typedef void(*gps_status_satellite_updated_cb)(int num_of_active, int num_of_inview, time_t timestamp, void *user_data);
+
+/**
+ * @brief Gets the GPS NMEA data.
+ * @remarks This call is valid only for location managers with #LOCATIONS_METHOD_GPS method.\n
+ * @a nmea must be released with @c free() by you.
+ * @param[in] manager The location manager handle
+ * @param[out] nmea The NMEA data
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATIONS_ERROR_NONE Successful
+ * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid argument
+ * @retval #LOCATIONS_ERROR_INCORRECT_METHOD Incorrect method
+ * @retval #LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE Service not available
+ * @retval #LOCATIONS_ERROR_OUT_OF_MEMORY Out of memory
+ * @pre The location service state must be #LOCATIONS_SERVICE_ENABLED with location_manager_start()
+ * @see location_manager_start()
+ */
+int gps_status_get_nmea(location_manager_h manager, char **nmea);
+
+/**
+ * @brief Gets the information of satellites.
+ * @remarks This call is valid only for location managers with #LOCATIONS_METHOD_GPS method.
+ * @param[in] manager The location manager handle
+ * @param[out] num_of_active The number of active satellites
+ * @param[out] num_of_inview The number of satellites in view
+ * @param[out] timestamp The timestamp (time when measurement took place or 0 if invalid)
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATIONS_ERROR_NONE Successful
+ * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid argument
+ * @retval #LOCATIONS_ERROR_INCORRECT_METHOD Incorrect method
+ * @retval #LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE Service not available
+ * @pre The location service state must be #LOCATIONS_SERVICE_ENABLED with location_manager_start()
+ * @see gps_status_foreach_satellites_in_view()
+ */
+int gps_status_get_satellite(location_manager_h manager, int *num_of_active, int *num_of_inview, time_t *timestamp);
+
+/**
+ * @brief Registers a callback function to be invoked at defined interval with updated satellite information.
+ *
+ * @param[in] manager The location manager handle
+ * @param[in] callback The callback function to register
+ * @param[in] interval The interval [1 ~ 120] (seconds)
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATIONS_ERROR_NONE Successful
+ * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @post gps_status_satellite_updated_cb() will be invoked
+ * @see gps_status_unset_satellite_updated_cb()
+ * @see gps_status_satellite_updated_cb()
+ */
+int gps_status_set_satellite_updated_cb(location_manager_h manager, gps_status_satellite_updated_cb callback, int interval, void *user_data);
+
+/**
+ * @brief Unregisters the callback function.
+ *
+ * @param[in] manager The location manager handle
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATIONS_ERROR_NONE Successful
+ * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see gps_status_set_satellite_updated_cb()
+ */
+int gps_status_unset_satellite_updated_cb(location_manager_h manager);
+
+/**
+ * @brief Invokes the callback function for each satellite.
+ * @remarks This function is valid only for location managers with the #LOCATIONS_METHOD_GPS method.
+ * @param[in] manager The location manager handle
+ * @param[in] callback The iteration callback function
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATIONS_ERROR_NONE Successful
+ * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid argument
+ * @retval #LOCATIONS_ERROR_INCORRECT_METHOD Incorrect method
+ * @retval #LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE Service not available
+ * @pre The location service state must be #LOCATIONS_SERVICE_ENABLED with location_manager_start()
+ * @post It invokes gps_status_get_satellites_cb().
+ * @see gps_status_get_satellite()
+ * @see gps_status_get_satellites_cb()
+ */
+int gps_status_foreach_satellites_in_view (location_manager_h manager, gps_status_get_satellites_cb callback, void *user_data);
+
+/**
+ * @brief Gets the last information of satellites.
+ * @remarks This call is valid only for location managers with #LOCATIONS_METHOD_GPS method.
+ * @param[in] manager The location manager handle
+ * @param[out] num_of_active The last number of active satellites
+ * @param[out] num_of_inview The last number of satellites in view
+ * @param[out] timestamp The last timestamp (time when last measurement took place or 0 if invalid)
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATIONS_ERROR_NONE Successful
+ * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid argument
+ * @retval #LOCATIONS_ERROR_INCORRECT_METHOD Incorrect method
+ * @retval #LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE Service not available
+ * @pre The location service state must be #LOCATIONS_SERVICE_ENABLED with location_manager_start()
+ * @see gps_status_foreach_satellites_in_view()
+ */
+int gps_status_get_last_satellite(location_manager_h manager, int *num_of_active, int *num_of_inview, time_t *timestamp);
+
+/**
+ * @brief Invokes the callback function for each last satellite which is recorded.
+ * @remarks This function is valid only for location managers with the #LOCATIONS_METHOD_GPS method.
+ * @param[in] manager The location manager handle
+ * @param[in] callback The iteration callback function
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #LOCATIONS_ERROR_NONE Successful
+ * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid argument
+ * @retval #LOCATIONS_ERROR_INCORRECT_METHOD Incorrect method
+ * @retval #LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE Service not available
+ * @pre The location service state must be #LOCATIONS_SERVICE_ENABLED with location_manager_start()
+ * @post It invokes gps_status_get_satellites_cb().
+ * @see gps_status_get_last_satellite()
+ * @see gps_status_get_satellites_cb()
+ */
+int gps_status_foreach_last_satellites_in_view(location_manager_h manager, gps_status_get_satellites_cb callback, void *user_data);
+
+/**
+ * @}
+ */
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_LOCATION_LOCATIONS_H__ */
diff --git a/include/locations_private.h b/include/locations_private.h
new file mode 100755
index 0000000..6c78ffc
--- /dev/null
+++ b/include/locations_private.h
@@ -0,0 +1,87 @@
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* 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.
+*/
+
+#ifndef __TIZEN_LOCATION_LOCATIONS_PRIVATE_H__
+#define __TIZEN_LOCATION_LOCATIONS_PRIVATE_H__
+
+#include <location/location.h>
+#include <locations.h>
+#include <dlog.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+#define LOG_TAG "CAPI_LOCATION_MANAGER"
+
+/*
+* Internal Macros
+*/
+#define LOCATIONS_LOGD(fmt,args...) LOGD(fmt, ##args)
+#define LOCATIONS_LOGW(fmt,args...) LOGW(fmt, ##args)
+#define LOCATIONS_LOGI(fmt,args...) LOGI(fmt, ##args)
+#define LOCATIONS_LOGE(fmt,args...) LOGE(fmt, ##args)
+
+#define LOCATIONS_CHECK_CONDITION(condition, error, msg) \
+ do { \
+ if (condition) { \
+ } else { \
+ LOCATIONS_LOGE("%s(0x%08x)", msg, error); \
+ return error; \
+ } \
+ } while (0)
+
+
+#define LOCATIONS_PRINT_ERROR_CODE(error, msg) \
+ do { \
+ LOCATIONS_LOGE("%s(0x%08x)", msg, error); \
+ return error; \
+ } while (0)
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef enum {
+ _LOCATIONS_EVENT_TYPE_SERVICE_STATE,
+ _LOCATIONS_EVENT_TYPE_POSITION,
+ _LOCATIONS_EVENT_TYPE_VELOCITY,
+ _LOCATIONS_EVENT_TYPE_BOUNDARY,
+ _LOCATIONS_EVENT_TYPE_SATELLITE,
+ _LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS,
+ _LOCATIONS_EVENT_TYPE_NUM
+}_location_event_e;
+
+typedef struct _location_manager_s {
+ LocationObject* object;
+ const void* user_cb[_LOCATIONS_EVENT_TYPE_NUM];
+ void* user_data[_LOCATIONS_EVENT_TYPE_NUM];
+ location_method_e method;
+ bool is_continue_foreach_bounds;
+ GList *bounds_list;
+} location_manager_s;
+
+typedef struct _location_bounds_s {
+ LocationBoundary* boundary;
+ const void* user_cb;
+ void* user_data;
+ bool is_added;
+} location_bounds_s;
+#ifdef __cplusplus
+}
+#endif
+
+#endif //__TIZEN_LOCATION_LOCATIONS_PRIVATE_H__
diff --git a/packaging/capi-location-manager.spec b/packaging/capi-location-manager.spec
new file mode 100755
index 0000000..bfb0ac1
--- /dev/null
+++ b/packaging/capi-location-manager.spec
@@ -0,0 +1,56 @@
+#sbs-git:slp/api/location-manager capi-location-manager 0.1.0 d1ee09a32e8bc0e9ed48ece37c641a7393c086c5
+Name: capi-location-manager
+Summary: A Location Manager library in Tizen Native API
+Version: 0.1.7
+Release: 1
+Group: System/Libraries
+License: Apache Licensc, Version 2.0
+Source0: %{name}-%{version}.tar.gz
+BuildRequires: cmake
+BuildRequires: pkgconfig(dlog)
+BuildRequires: pkgconfig(location)
+BuildRequires: pkgconfig(capi-base-common)
+Requires(post): /sbin/ldconfig
+Requires(postun): /sbin/ldconfig
+
+%description
+
+
+%package devel
+Summary: A Location Manager library in Tizen Native API (Development)
+Group: TO_BE/FILLED_IN
+Requires: %{name} = %{version}-%{release}
+
+%description devel
+
+
+
+%prep
+%setup -q
+
+
+%build
+MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
+cmake . -DCMAKE_INSTALL_PREFIX=/usr -DFULLVER=%{version} -DMAJORVER=${MAJORVER}
+
+make %{?jobs:-j%jobs}
+
+%install
+rm -rf %{buildroot}
+%make_install
+
+%post -p /sbin/ldconfig
+
+%postun -p /sbin/ldconfig
+
+
+%files
+%manifest capi-location-manager.manifest
+%{_libdir}/libcapi-location-manager.so.*
+
+%files devel
+%{_includedir}/location/*.h
+%{_libdir}/pkgconfig/*.pc
+%{_libdir}/libcapi-location-manager.so
+
+
diff --git a/src/location_bounds.c b/src/location_bounds.c
new file mode 100755
index 0000000..9626964
--- /dev/null
+++ b/src/location_bounds.c
@@ -0,0 +1,315 @@
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <location_bounds.h>
+#include <locations_private.h>
+
+
+#define LOCATIONS_NULL_ARG_CHECK(arg) \
+ LOCATIONS_CHECK_CONDITION((arg != NULL),LOCATION_BOUNDS_ERROR_INVALID_PARAMETER,"LOCATION_BOUNDS_ERROR_INVALID_PARAMETER") \
+
+static void __free_position_list(gpointer data)
+{
+ if (data == NULL)
+ return;
+
+ LocationPosition *position = (LocationPosition *) data;
+ location_position_free(position);
+}
+
+static location_bounds_type_e __convert_bounds_type(LocationBoundaryType type)
+{
+ location_bounds_type_e ret;
+ switch (type) {
+ case LOCATION_BOUNDARY_CIRCLE:
+ ret = LOCATION_BOUNDS_CIRCLE;
+ break;
+ case LOCATION_BOUNDARY_POLYGON:
+ ret = LOCATION_BOUNDS_POLYGON;
+ break;
+ case LOCATION_BOUNDARY_NONE:
+ case LOCATION_BOUNDARY_RECT:
+ default:
+ ret = LOCATION_BOUNDS_RECT;
+ break;
+ }
+ return ret;
+}
+
+int location_bounds_create_rect(location_coords_s top_left, location_coords_s bottom_right, location_bounds_h * bounds)
+{
+ LOCATIONS_NULL_ARG_CHECK(bounds);
+ LOCATIONS_CHECK_CONDITION(top_left.latitude>=-90 && top_left.latitude<=90,LOCATION_BOUNDS_ERROR_INVALID_PARAMETER,"LOCATION_BOUNDS_ERROR_INVALID_PARAMETER");
+ LOCATIONS_CHECK_CONDITION(top_left.longitude>=-180 && top_left.longitude<=180,LOCATION_BOUNDS_ERROR_INVALID_PARAMETER, "LOCATION_BOUNDS_ERROR_INVALID_PARAMETER");
+ LOCATIONS_CHECK_CONDITION(bottom_right.latitude>=-90 && bottom_right.latitude<=90,LOCATION_BOUNDS_ERROR_INVALID_PARAMETER, "LOCATION_BOUNDS_ERROR_INVALID_PARAMETER");
+ LOCATIONS_CHECK_CONDITION(bottom_right.longitude>=-180 && bottom_right.longitude<=180,LOCATION_BOUNDS_ERROR_INVALID_PARAMETER, "LOCATION_BOUNDS_ERROR_INVALID_PARAMETER");
+
+ LocationPosition *lt = location_position_new(0, top_left.latitude, top_left.longitude, 0, LOCATION_STATUS_2D_FIX);
+ if (lt == NULL) {
+ LOCATIONS_LOGE("LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY(0x%08x) : fail to location_position_new", LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY);
+ return LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY;
+ }
+
+ LocationPosition *rb = location_position_new(0, bottom_right.latitude, bottom_right.longitude, 0, LOCATION_STATUS_2D_FIX);
+ if (rb == NULL) {
+ LOCATIONS_LOGE("LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY(0x%08x) : fail to location_position_new", LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY);
+ location_position_free(lt);
+ return LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY;
+ }
+
+ location_bounds_s *handle = (location_bounds_s *) malloc(sizeof(location_bounds_s));
+ if (handle == NULL) {
+ LOCATIONS_LOGE("OUT_OF_MEMORY(0x%08x)", LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY);
+ location_position_free(rb);
+ location_position_free(lt);
+ return LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY;
+ }
+ memset(handle, 0, sizeof(location_bounds_s));
+
+ handle->is_added = FALSE;
+ handle->boundary = location_boundary_new_for_rect(lt, rb);
+ location_position_free(rb);
+ location_position_free(lt);
+ if (handle->boundary == NULL) {
+ LOCATIONS_LOGE("LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY(0x%08x) : fail to location_boundary_new_for_rect", LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY);
+ free(handle);
+ return LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY;
+ }
+ handle->user_cb = NULL;
+ handle->user_data = NULL;
+
+ *bounds = (location_bounds_h) handle;
+ return LOCATION_BOUNDS_ERROR_NONE;
+}
+
+int location_bounds_create_circle(location_coords_s center, double radius, location_bounds_h * bounds)
+{
+ LOCATIONS_NULL_ARG_CHECK(bounds);
+ LOCATIONS_CHECK_CONDITION(radius>=0,LOCATION_BOUNDS_ERROR_INVALID_PARAMETER,"LOCATION_BOUNDS_ERROR_INVALID_PARAMETER");
+ LOCATIONS_CHECK_CONDITION(center.latitude>=-90 && center.latitude<=90,LOCATION_BOUNDS_ERROR_INVALID_PARAMETER,"LOCATION_BOUNDS_ERROR_INVALID_PARAMETER");
+ LOCATIONS_CHECK_CONDITION(center.longitude>=-180 && center.longitude<=180,LOCATION_BOUNDS_ERROR_INVALID_PARAMETER, "LOCATION_BOUNDS_ERROR_INVALID_PARAMETER");
+
+ LocationPosition *ct = location_position_new(0, center.latitude, center.longitude, 0, LOCATION_STATUS_2D_FIX);
+ if (ct == NULL) {
+ LOCATIONS_LOGE("LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY(0x%08x) : fail to location_position_new", LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY);
+ return LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY;
+ }
+
+ location_bounds_s *handle = (location_bounds_s *) malloc(sizeof(location_bounds_s));
+ if (handle == NULL) {
+ LOCATIONS_LOGE("OUT_OF_MEMORY(0x%08x)", LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY);
+ location_position_free(ct);
+ return LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY;
+ }
+ memset(handle, 0, sizeof(location_bounds_s));
+
+ handle->is_added = FALSE;
+ handle->boundary = location_boundary_new_for_circle(ct, radius);
+ location_position_free(ct);
+ if (handle->boundary == NULL) {
+ LOCATIONS_LOGE("LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY(0x%08x) : fail to location_boundary_new_for_circle", LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY);
+ free(handle);
+ return LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY;
+ }
+ handle->user_cb = NULL;
+ handle->user_data = NULL;
+
+ *bounds = (location_bounds_h) handle;
+ return LOCATION_BOUNDS_ERROR_NONE;
+}
+
+int location_bounds_create_polygon(location_coords_s * coords_list, int length, location_bounds_h * bounds)
+{
+ LOCATIONS_NULL_ARG_CHECK(coords_list);
+ LOCATIONS_NULL_ARG_CHECK(bounds);
+ LOCATIONS_CHECK_CONDITION(length>=3, LOCATION_BOUNDS_ERROR_INVALID_PARAMETER, "LOCATION_BOUNDS_ERROR_INVALID_PARAMETER");
+
+ int i;
+ GList *position_list = NULL;
+ LocationPosition *position = NULL;
+ bool isValid;
+
+ for (i = 0; i < length; i++) {
+ if (coords_list[i].latitude < -90 || coords_list[i].latitude > 90 || coords_list[i].longitude < -180 || coords_list[i].longitude > 180) {
+ LOCATIONS_LOGE("LOCATION_BOUNDS_ERROR_INVALID_PARAMETER(0x%08x)", LOCATION_BOUNDS_ERROR_INVALID_PARAMETER);
+ isValid = FALSE;
+ break;
+ }
+ position = location_position_new(0, coords_list[i].latitude, coords_list[i].longitude, 0.0, LOCATION_STATUS_2D_FIX);
+ position_list = g_list_append(position_list, position);
+ location_position_free(position);
+ isValid = TRUE;
+ }
+
+ if (!isValid) {
+ g_list_free_full(position_list, (GDestroyNotify) __free_position_list);
+ return LOCATION_BOUNDS_ERROR_INVALID_PARAMETER;
+ }
+
+ if (position_list == NULL) {
+ LOCATIONS_LOGE("LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY(0x%08x) : fail to location_position_new", LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY);
+ g_list_free_full(position_list, (GDestroyNotify) __free_position_list);
+ return LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY;
+ }
+
+ location_bounds_s *handle = (location_bounds_s *) malloc(sizeof(location_bounds_s));
+ if (handle == NULL) {
+ LOCATIONS_LOGE("OUT_OF_MEMORY(0x%08x)", LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY);
+ return LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY;
+ }
+ memset(handle, 0, sizeof(location_bounds_s));
+
+ handle->is_added = FALSE;
+ handle->boundary = location_boundary_new_for_polygon(position_list);
+ if (handle->boundary == NULL) {
+ LOCATIONS_LOGE("LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY(0x%08x) : fail to location_boundary_new_for_polygon", LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY);
+ free(handle);
+ return LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY;
+ }
+ handle->user_cb = NULL;
+ handle->user_data = NULL;
+
+ *bounds = (location_bounds_h) handle;
+ return LOCATION_BOUNDS_ERROR_NONE;
+}
+
+bool location_bounds_contains_coordinates(location_bounds_h bounds, location_coords_s coords)
+{
+ if (!bounds)
+ return FALSE;
+
+ if (coords.latitude < -90 || coords.latitude > 90 || coords.longitude < -180 || coords.longitude > 180)
+ return FALSE;
+
+ LocationPosition *pos = location_position_new(0, coords.latitude, coords.longitude, 0, LOCATION_STATUS_2D_FIX);
+ if (pos == NULL) {
+ LOCATIONS_LOGE("LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY(0x%08x) : fail to location_position_new", LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY);
+ return FALSE;
+ }
+ location_bounds_s *handle = (location_bounds_s *) bounds;
+ gboolean is_inside = location_boundary_if_inside(handle->boundary, pos);
+ location_position_free(pos);
+ bool result = is_inside ? TRUE : FALSE;
+ return result;
+}
+
+int location_bounds_get_type(location_bounds_h bounds, location_bounds_type_e * type)
+{
+ LOCATIONS_NULL_ARG_CHECK(bounds);
+ LOCATIONS_NULL_ARG_CHECK(type);
+ location_bounds_s *handle = (location_bounds_s *) bounds;
+ *type = __convert_bounds_type(handle->boundary->type);
+ return LOCATION_BOUNDS_ERROR_NONE;
+}
+
+int location_bounds_get_rect_coords(location_bounds_h bounds, location_coords_s * top_left, location_coords_s * bottom_right)
+{
+ LOCATIONS_NULL_ARG_CHECK(bounds);
+ LOCATIONS_NULL_ARG_CHECK(top_left);
+ LOCATIONS_NULL_ARG_CHECK(bottom_right);
+ location_bounds_s *handle = (location_bounds_s *) bounds;
+ if (__convert_bounds_type(handle->boundary->type) != LOCATION_BOUNDS_RECT) {
+ LOCATIONS_LOGE("LOCATION_BOUNDS_ERROR_INCORRECT_TYPE(0x%08x)", LOCATION_BOUNDS_ERROR_INCORRECT_TYPE);
+ return LOCATION_BOUNDS_ERROR_INCORRECT_TYPE;
+ }
+
+ top_left->latitude = handle->boundary->rect.left_top->latitude;
+ top_left->longitude = handle->boundary->rect.left_top->longitude;
+ bottom_right->latitude = handle->boundary->rect.right_bottom->latitude;
+ bottom_right->longitude = handle->boundary->rect.right_bottom->longitude;
+ return LOCATION_BOUNDS_ERROR_NONE;
+}
+
+int location_bounds_get_circle_coords(location_bounds_h bounds, location_coords_s * center, double *radius)
+{
+ LOCATIONS_NULL_ARG_CHECK(bounds);
+ LOCATIONS_NULL_ARG_CHECK(center);
+ LOCATIONS_NULL_ARG_CHECK(radius);
+ location_bounds_s *handle = (location_bounds_s *) bounds;
+ if (__convert_bounds_type(handle->boundary->type) != LOCATION_BOUNDS_CIRCLE) {
+ LOCATIONS_LOGE("LOCATION_BOUNDS_ERROR_INCORRECT_TYPE(0x%08x)", LOCATION_BOUNDS_ERROR_INCORRECT_TYPE);
+ return LOCATION_BOUNDS_ERROR_INCORRECT_TYPE;
+ }
+
+ center->latitude = handle->boundary->circle.center->latitude;
+ center->longitude = handle->boundary->circle.center->longitude;
+ *radius = handle->boundary->circle.radius;
+ return LOCATION_BOUNDS_ERROR_NONE;
+}
+
+int location_bounds_foreach_polygon_coords(location_bounds_h bounds, polygon_coords_cb callback, void *user_data)
+{
+ LOCATIONS_NULL_ARG_CHECK(bounds);
+ LOCATIONS_NULL_ARG_CHECK(callback);
+ location_bounds_s *handle = (location_bounds_s *) bounds;
+ if (__convert_bounds_type(handle->boundary->type) != LOCATION_BOUNDS_POLYGON) {
+ LOCATIONS_LOGE("LOCATION_BOUNDS_ERROR_INCORRECT_TYPE(0x%08x)", LOCATION_BOUNDS_ERROR_INCORRECT_TYPE);
+ return LOCATION_BOUNDS_ERROR_INCORRECT_TYPE;
+ }
+
+ GList *list = handle->boundary->polygon.position_list;
+ while (list) {
+ LocationPosition *pos = list->data;
+ location_coords_s coords;
+ coords.latitude = pos->latitude;
+ coords.longitude = pos->longitude;
+
+ if (callback(coords, user_data) != TRUE) {
+ LOCATIONS_LOGI("User quit the loop ");
+ break;
+ }
+ list = g_list_next(list);
+ }
+ return LOCATION_BOUNDS_ERROR_NONE;
+}
+
+int location_bounds_destroy(location_bounds_h bounds)
+{
+ LOCATIONS_NULL_ARG_CHECK(bounds);
+ location_bounds_s *handle = (location_bounds_s *) bounds;
+ if (handle->is_added) {
+ LOCATIONS_LOGE("LOCATION_BOUNDS_ERROR_IS_ADDED(0x%08x)", LOCATION_BOUNDS_ERROR_IS_ADDED);
+ return LOCATION_BOUNDS_ERROR_IS_ADDED;
+ }
+ location_boundary_free(handle->boundary);
+ handle->user_cb = NULL;
+ handle->user_data = NULL;
+ free(handle);
+ LOCATIONS_LOGE("");
+ return LOCATION_BOUNDS_ERROR_NONE;
+}
+
+int location_bounds_set_state_changed_cb(location_bounds_h bounds, location_bounds_state_changed_cb callback, void *user_data)
+{
+ LOCATIONS_NULL_ARG_CHECK(bounds);
+ LOCATIONS_NULL_ARG_CHECK(callback);
+ location_bounds_s *handle = (location_bounds_s *) bounds;
+ handle->user_cb = callback;
+ handle->user_data = user_data;
+ return LOCATION_BOUNDS_ERROR_NONE;
+}
+
+int location_bounds_unset_state_changed_cb(location_bounds_h bounds)
+{
+ LOCATIONS_NULL_ARG_CHECK(bounds);
+ location_bounds_s *handle = (location_bounds_s *) bounds;
+ handle->user_cb = NULL;
+ handle->user_data = NULL;
+ return LOCATION_BOUNDS_ERROR_NONE;
+}
diff --git a/src/location_preference.c b/src/location_preference.c
new file mode 100755
index 0000000..f313af3
--- /dev/null
+++ b/src/location_preference.c
@@ -0,0 +1,514 @@
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* 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 <location_preference.h>
+#include <location-map-service.h>
+#include <stdlib.h>
+#include <string.h>
+#include <locations_private.h>
+
+#define LOCATION_PREFERENCE_NULL_ARG_CHECK(arg) \
+ LOCATIONS_CHECK_CONDITION((arg != NULL), LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER, "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER")
+
+#define LOCATION_PREFERENCE_GET_LOCATION_OBJECT(service) *((LocationMapObject**)service)
+
+/*
+* Internal Implementation
+*/
+
+static int __convert_error_code(int code)
+{
+ int ret = LOCATION_PREFERENCE_ERROR_NONE;
+ char* msg = "LOCATION_PREFERENCE_ERROR_NONE";
+ switch(code)
+ {
+ case LOCATION_ERROR_NONE:
+ ret = LOCATION_PREFERENCE_ERROR_NONE;
+ msg = "LOCATION_PREFERENCE_ERROR_NONE";
+ break;
+ case LOCATION_ERROR_NETWORK_NOT_CONNECTED:
+ ret = LOCATION_PREFERENCE_ERROR_NETWORK_FAILED;
+ msg = "LOCATION_PREFERENCE_ERROR_NETWORK_FAILED";
+ break;
+ case LOCATION_ERROR_PARAMETER:
+ ret = LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER;
+ msg = "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER";
+ break;
+ case LOCATION_ERROR_NOT_AVAILABLE:
+ msg = "LOCATION_PREFERENCE_ERROR_RESULT_NOT_FOUND";
+ ret = LOCATION_PREFERENCE_ERROR_RESULT_NOT_FOUND;
+ }
+ LOCATIONS_LOGE("%s(0x%08x)", msg, ret);
+ return ret;
+}
+
+
+/*
+ * Public Implementation
+ */
+int location_preference_foreach_available_property_keys(location_service_h service, location_preference_available_property_key_cb callback, void* user_data)
+{
+ LocationMapObject* object = NULL;
+ GList* keys = NULL;
+ char* key = NULL;
+ int ret = 0;
+
+ LOCATION_PREFERENCE_NULL_ARG_CHECK(service);
+ LOCATION_PREFERENCE_NULL_ARG_CHECK(callback);
+
+ object = LOCATION_PREFERENCE_GET_LOCATION_OBJECT(service);
+ ret = location_map_get_provider_capability_key(object, MAP_SERVICE_PREF_PROPERTY, &keys);
+ if(ret != LOCATION_ERROR_NONE)
+ {
+ return __convert_error_code(ret);
+ }
+ else
+ {
+ while(keys) {
+ key = keys->data;
+ if(!callback(key, user_data))
+ break;
+ keys = keys->next;
+ }
+
+ return LOCATION_PREFERENCE_ERROR_NONE;
+ }
+}
+
+int location_preference_foreach_available_property_values(location_service_h service, const char* key, location_preference_available_property_value_cb callback, void* user_data)
+{
+ LOCATION_PREFERENCE_NULL_ARG_CHECK(service);
+ LOCATION_PREFERENCE_NULL_ARG_CHECK(key);
+ LOCATION_PREFERENCE_NULL_ARG_CHECK(callback);
+ return LOCATION_PREFERENCE_ERROR_RESULT_NOT_FOUND;
+}
+
+int location_preference_foreach_available_languages(location_service_h service, location_preference_available_language_cb callback, void* user_data)
+{
+ LocationMapObject* object = NULL;
+ GList* keys = NULL;
+ char* key = NULL;
+ int ret = 0;
+
+ LOCATION_PREFERENCE_NULL_ARG_CHECK(service);
+ LOCATION_PREFERENCE_NULL_ARG_CHECK(callback);
+
+ object = LOCATION_PREFERENCE_GET_LOCATION_OBJECT(service);
+ ret = location_map_get_provider_capability_key(object, MAP_SERVICE_PREF_LANGUAGE, &keys);
+ if(ret != LOCATION_ERROR_NONE)
+ {
+ return __convert_error_code(ret);
+ }
+ else
+ {
+ while(keys) {
+ key = keys->data;
+ if(!callback(key, user_data))
+ break;
+ keys = keys->next;
+ }
+
+ return LOCATION_PREFERENCE_ERROR_NONE;
+ }
+}
+
+int location_preference_foreach_available_country_codes(location_service_h service, location_preference_available_country_code_cb callback, void* user_data)
+{
+ LocationMapObject* object = NULL;
+ GList* keys = NULL;
+ char* key = NULL;
+ int ret = 0;
+
+ LOCATION_PREFERENCE_NULL_ARG_CHECK(service);
+ LOCATION_PREFERENCE_NULL_ARG_CHECK(callback);
+
+ object = LOCATION_PREFERENCE_GET_LOCATION_OBJECT(service);
+ ret = location_map_get_provider_capability_key(object, MAP_SERVICE_PREF_COUNTRY, &keys);
+ if(ret != LOCATION_ERROR_NONE)
+ {
+ return __convert_error_code(ret);
+ }
+ else
+ {
+ while(keys) {
+ key = keys->data;
+ if(!callback(key, user_data))
+ break;
+ keys = keys->next;
+ }
+ }
+
+ return LOCATION_PREFERENCE_ERROR_NONE;
+}
+
+int location_preference_foreach_properties(location_service_h service, location_preference_property_cb callback, void* user_data)
+{
+ LocationMapPref* pref = NULL;
+ LocationMapObject* object = NULL;
+ GList* keys = NULL;
+ char* key = NULL;
+ char* value = NULL;
+
+ LOCATION_PREFERENCE_NULL_ARG_CHECK(service);
+ LOCATION_PREFERENCE_NULL_ARG_CHECK(callback);
+
+ object = LOCATION_PREFERENCE_GET_LOCATION_OBJECT(service);
+ pref = location_map_get_service_pref(object);
+ LOCATIONS_CHECK_CONDITION(pref != NULL, LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER, "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER");
+
+ keys = location_map_pref_get_property_key(pref);
+ while(keys) {
+ key = keys->data;
+ value = (char*)location_map_pref_get_property(pref, key);
+ if(!callback(key, value, user_data))
+ break;
+ keys = keys->next;
+ }
+
+ location_map_pref_free(pref);
+ return LOCATION_PREFERENCE_ERROR_NONE;
+}
+
+int location_preference_set(location_service_h service, const char* key, const char* value)
+{
+ LocationMapPref* pref = NULL;
+ LocationMapObject* object = NULL;
+
+ LOCATION_PREFERENCE_NULL_ARG_CHECK(service);
+ LOCATION_PREFERENCE_NULL_ARG_CHECK(key);
+ LOCATION_PREFERENCE_NULL_ARG_CHECK(value);
+
+ object = LOCATION_PREFERENCE_GET_LOCATION_OBJECT(service);
+ pref = location_map_get_service_pref(object);
+ LOCATIONS_CHECK_CONDITION(pref != NULL, LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER, "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER");
+
+ location_map_pref_set_property(pref, (gconstpointer)key, (gconstpointer)value);
+ location_map_set_service_pref(object, pref);
+ location_map_pref_free(pref);
+
+ return LOCATION_PREFERENCE_ERROR_NONE;
+}
+
+int location_preference_get(location_service_h service, const char* key, char** value)
+{
+ LocationMapPref* pref = NULL;
+ LocationMapObject* object = NULL;
+ char* ret = NULL;
+
+ LOCATION_PREFERENCE_NULL_ARG_CHECK(service);
+ LOCATION_PREFERENCE_NULL_ARG_CHECK(key);
+ LOCATION_PREFERENCE_NULL_ARG_CHECK(value);
+
+ object = LOCATION_PREFERENCE_GET_LOCATION_OBJECT(service);
+ pref = location_map_get_service_pref(object);
+ LOCATIONS_CHECK_CONDITION(pref != NULL, LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER, "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER");
+
+ ret = (char*)location_map_pref_get_property(pref, (gconstpointer)key);
+ if(ret != NULL)
+ {
+ *value = strdup(ret);
+ location_map_pref_free(pref);
+ }
+ else
+ {
+ *value = NULL;
+ location_map_pref_free(pref);
+ LOCATIONS_PRINT_ERROR_CODE(LOCATION_PREFERENCE_ERROR_INVALID_KEY, "LOCATION_PREFERENCE_ERROR_INVALID_KEY");
+ }
+
+ return LOCATION_PREFERENCE_ERROR_NONE;
+}
+
+int location_preference_set_provider(location_service_h service, char* provider)
+{
+ LOCATION_PREFERENCE_NULL_ARG_CHECK(service);
+ LOCATION_PREFERENCE_NULL_ARG_CHECK(provider);
+
+ LocationMapObject *object = NULL;
+ LocationMapPref *pref = NULL;
+ gboolean ret = FALSE;
+
+ object = LOCATION_PREFERENCE_GET_LOCATION_OBJECT(service);
+ pref = location_map_get_service_pref(object);
+ LOCATIONS_CHECK_CONDITION(pref != NULL, LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER, "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER");
+
+ ret = location_map_pref_set_provider_name(pref, provider);
+ if (!ret) {
+ location_map_pref_free(pref);
+ LOCATIONS_CHECK_CONDITION(pref != NULL, LOCATION_PREFERENCE_ERROR_INVALID_KEY, "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER");
+ }
+ ret = location_map_set_service_pref(object, pref);
+ if (!ret) {
+ location_map_pref_free(pref);
+ LOCATIONS_CHECK_CONDITION(pref != NULL, LOCATION_PREFERENCE_ERROR_INVALID_KEY, "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER");
+ }
+
+ location_map_pref_free(pref);
+ return LOCATION_PREFERENCE_ERROR_NONE;
+}
+
+int location_preference_get_provider(location_service_h service, char** provider)
+{
+ LOCATION_PREFERENCE_NULL_ARG_CHECK(service);
+ LOCATION_PREFERENCE_NULL_ARG_CHECK(provider);
+
+ LocationMapObject *object = NULL;
+ LocationMapPref *pref = NULL;
+ gchar* current_provider = NULL;
+
+ object = LOCATION_PREFERENCE_GET_LOCATION_OBJECT(service);
+ pref = location_map_get_service_pref(object);
+ LOCATIONS_CHECK_CONDITION(pref != NULL, LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER, "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER");
+
+ current_provider = location_map_pref_get_provider_name(pref);
+ if (!current_provider) {
+ location_map_pref_free(pref);
+ LOCATIONS_CHECK_CONDITION(pref != NULL, LOCATION_PREFERENCE_ERROR_INVALID_KEY, "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER");
+ }
+
+ *provider = g_strdup (current_provider);
+ location_map_pref_free(pref);
+
+ return LOCATION_PREFERENCE_ERROR_NONE;
+}
+
+int location_preference_get_default_provider(location_service_h service, char** provider)
+{
+ LOCATION_PREFERENCE_NULL_ARG_CHECK(service);
+ LOCATION_PREFERENCE_NULL_ARG_CHECK(provider);
+
+ LocationMapObject *object = NULL;
+ gchar *current_provider = NULL;
+ object = LOCATION_PREFERENCE_GET_LOCATION_OBJECT(service);
+ current_provider = location_map_get_default_provider(object);
+ LOCATIONS_CHECK_CONDITION(current_provider != NULL, LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER, "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER");
+
+ *provider = g_strdup(current_provider);
+ g_free(current_provider);
+
+ return LOCATION_PREFERENCE_ERROR_NONE;
+}
+
+int location_preference_foreach_supported_provider(location_service_h service, location_preference_supported_provider_cb callback , void *user_data)
+{
+ LOCATION_PREFERENCE_NULL_ARG_CHECK(service);
+ LOCATION_PREFERENCE_NULL_ARG_CHECK(callback);
+
+ LocationMapObject *object = NULL;
+ GList *providers = NULL;
+ gchar *provider = NULL;
+
+ object = LOCATION_PREFERENCE_GET_LOCATION_OBJECT(service);
+ providers = location_map_get_supported_providers(object);
+ LOCATIONS_CHECK_CONDITION(providers != NULL, LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER, "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER");
+ while(providers) {
+ provider = providers->data;
+ if(!callback(provider, user_data))
+ break;
+ providers = providers->next;
+ }
+
+ return LOCATION_PREFERENCE_ERROR_NONE;
+}
+
+int location_preference_get_provider_name(location_service_h service, char** provider)
+{
+ LocationMapPref* pref = NULL;
+ LocationMapObject* object = NULL;
+ char* ret = NULL;
+
+ LOCATION_PREFERENCE_NULL_ARG_CHECK(service);
+ LOCATION_PREFERENCE_NULL_ARG_CHECK(provider);
+
+ object = LOCATION_PREFERENCE_GET_LOCATION_OBJECT(service);
+ pref = location_map_get_service_pref(object);
+ LOCATIONS_CHECK_CONDITION(pref != NULL, LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER, "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER");
+
+ ret = location_map_pref_get_provider_name(pref);
+ if(ret != NULL)
+ *provider = strdup(ret);
+ else
+ *provider = NULL;
+
+ location_map_pref_free(pref);
+ return LOCATION_PREFERENCE_ERROR_NONE;
+}
+
+int location_preference_get_distance_unit(location_service_h service, location_preference_distance_unit_e* unit)
+{
+ LocationMapPref* pref = NULL;
+ LocationMapObject* object = NULL;
+ char* ret = NULL;
+
+ LOCATION_PREFERENCE_NULL_ARG_CHECK(service);
+ LOCATION_PREFERENCE_NULL_ARG_CHECK(unit);
+
+ object = LOCATION_PREFERENCE_GET_LOCATION_OBJECT(service);
+ pref = location_map_get_service_pref(object);
+ LOCATIONS_CHECK_CONDITION(pref != NULL, LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER, "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER");
+
+ ret = location_map_pref_get_distance_unit(pref);
+ if(ret != NULL)
+ {
+ switch(ret[0]) {
+ case 'F' :
+ *unit = LOCATION_PREFERENCE_DISTANCE_UNIT_FT;
+ break;
+ case 'K' :
+ *unit = LOCATION_PREFERENCE_DISTANCE_UNIT_KM;
+ break;
+ case 'Y' :
+ *unit = LOCATION_PREFERENCE_DISTANCE_UNIT_YD;
+ break;
+ case 'M' :
+ if(ret[1] == 'I')
+ *unit = LOCATION_PREFERENCE_DISTANCE_UNIT_MI;
+ else
+ *unit = LOCATION_PREFERENCE_DISTANCE_UNIT_M;
+ break;
+ }
+ location_map_pref_free(pref);
+ return LOCATION_PREFERENCE_ERROR_NONE;
+ }
+ else
+ {
+ location_map_pref_free(pref);
+ LOCATIONS_PRINT_ERROR_CODE(LOCATION_PREFERENCE_ERROR_RESULT_NOT_FOUND, "LOCATION_PREFERENCE_ERROR_RESULT_NOT_FOUND");
+ }
+}
+
+int location_preference_set_distance_unit(location_service_h service, location_preference_distance_unit_e unit)
+{
+ LocationMapPref* pref = NULL;
+ LocationMapObject* object = NULL;
+ char* distance = NULL;
+
+ LOCATION_PREFERENCE_NULL_ARG_CHECK(service);
+ switch(unit) {
+ case LOCATION_PREFERENCE_DISTANCE_UNIT_FT :
+ distance = "FT";
+ break;
+ case LOCATION_PREFERENCE_DISTANCE_UNIT_KM :
+ distance = "KM";
+ break;
+ case LOCATION_PREFERENCE_DISTANCE_UNIT_YD :
+ distance = "YD";
+ break;
+ case LOCATION_PREFERENCE_DISTANCE_UNIT_MI :
+ distance = "MI";
+ break;
+ case LOCATION_PREFERENCE_DISTANCE_UNIT_M :
+ distance = "M";
+ break;
+ default :
+ LOCATIONS_PRINT_ERROR_CODE(LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER, "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER");
+ }
+
+ object = LOCATION_PREFERENCE_GET_LOCATION_OBJECT(service);
+ pref = location_map_get_service_pref(object);
+ LOCATIONS_CHECK_CONDITION(pref != NULL, LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER, "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER");
+
+ location_map_pref_set_distance_unit(pref, distance);
+ location_map_set_service_pref(object, pref);
+ location_map_pref_free(pref);
+
+ return LOCATION_PREFERENCE_ERROR_NONE;
+}
+
+int location_preference_get_language(location_service_h service, char** language)
+{
+ LocationMapPref* pref = NULL;
+ LocationMapObject* object = NULL;
+ char* ret = NULL;
+
+ LOCATION_PREFERENCE_NULL_ARG_CHECK(service);
+ LOCATION_PREFERENCE_NULL_ARG_CHECK(language);
+
+ object = LOCATION_PREFERENCE_GET_LOCATION_OBJECT(service);
+ pref = location_map_get_service_pref(object);
+ LOCATIONS_CHECK_CONDITION(pref != NULL, LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER, "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER");
+
+ ret = location_map_pref_get_language(pref);
+ if(ret != NULL)
+ *language = strdup(ret);
+ else
+ *language = NULL;
+
+ location_map_pref_free(pref);
+ return LOCATION_PREFERENCE_ERROR_NONE;
+}
+
+int location_preference_set_language(location_service_h service, const char* language)
+{
+ LocationMapPref* pref = NULL;
+ LocationMapObject* object = NULL;
+
+ LOCATION_PREFERENCE_NULL_ARG_CHECK(service);
+ LOCATION_PREFERENCE_NULL_ARG_CHECK(language);
+
+ object = LOCATION_PREFERENCE_GET_LOCATION_OBJECT(service);
+ pref = location_map_get_service_pref(object);
+ LOCATIONS_CHECK_CONDITION(pref != NULL, LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER, "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER");
+
+ location_map_pref_set_language(pref, language);
+ location_map_set_service_pref(object, pref);
+ location_map_pref_free(pref);
+
+ return LOCATION_PREFERENCE_ERROR_NONE;
+}
+
+
+int location_preference_get_country_code(location_service_h service, char** country_code)
+{
+ LocationMapPref* pref = NULL;
+ LocationMapObject* object = NULL;
+ char* ret = NULL;
+
+ LOCATION_PREFERENCE_NULL_ARG_CHECK(service);
+ LOCATION_PREFERENCE_NULL_ARG_CHECK(country_code);
+
+ object = LOCATION_PREFERENCE_GET_LOCATION_OBJECT(service);
+ pref = location_map_get_service_pref(object);
+ LOCATIONS_CHECK_CONDITION(pref != NULL, LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER, "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER");
+
+ ret = location_map_pref_get_country(pref);
+ if(ret != NULL)
+ *country_code = strdup(ret);
+ else
+ *country_code = NULL;
+
+ location_map_pref_free(pref);
+ return LOCATION_PREFERENCE_ERROR_NONE;
+}
+
+int location_preference_set_country_code(location_service_h service, const char* country_code)
+{
+ LocationMapPref* pref = NULL;
+ LocationMapObject* object = NULL;
+
+ LOCATION_PREFERENCE_NULL_ARG_CHECK(service);
+ LOCATION_PREFERENCE_NULL_ARG_CHECK(country_code);
+
+ object = LOCATION_PREFERENCE_GET_LOCATION_OBJECT(service);
+ pref = location_map_get_service_pref(object);
+ LOCATIONS_CHECK_CONDITION(pref != NULL, LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER, "LOCATION_PREFERENCE_ERROR_INVALID_PARAMETER");
+
+ location_map_pref_set_country(pref, country_code);
+ location_map_set_service_pref(object, pref);
+ location_map_pref_free(pref);
+
+ return LOCATION_PREFERENCE_ERROR_NONE;
+}
diff --git a/src/locations.c b/src/locations.c
new file mode 100755
index 0000000..33e58b8
--- /dev/null
+++ b/src/locations.c
@@ -0,0 +1,1017 @@
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <locations_private.h>
+#include <location_bounds.h>
+
+
+#define LOCATIONS_NULL_ARG_CHECK(arg) \
+ LOCATIONS_CHECK_CONDITION((arg != NULL),LOCATIONS_ERROR_INVALID_PARAMETER,"LOCATIONS_ERROR_INVALID_PARAMETER") \
+
+/*
+* Internal Implementation
+*/
+
+static int __convert_error_code(int code)
+{
+ int ret;
+ char *msg = "LOCATIONS_ERROR_NONE";
+ switch (code) {
+ case LOCATION_ERROR_NONE:
+ ret = LOCATIONS_ERROR_NONE;
+ msg = "LOCATIONS_ERROR_NONE";
+ break;
+ case LOCATION_ERROR_NETWORK_FAILED:
+ case LOCATION_ERROR_NETWORK_NOT_CONNECTED:
+ ret = LOCATIONS_ERROR_NETWORK_FAILED;
+ msg = "LOCATIONS_ERROR_NETWORK_FAILED";
+ break;
+ case LOCATION_ERROR_NOT_ALLOWED:
+ ret = LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
+ msg = "LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED";
+ break;
+ case LOCATION_ERROR_SETTING_OFF:
+ ret = LOCATIONS_ERROR_GPS_SETTING_OFF;
+ msg = "LOCATIONS_ERROR_GPS_SETTING_OFF";
+ break;
+ case LOCATION_ERROR_SECURITY_DENIED:
+ ret = LOCATIONS_ERROR_SECURITY_RESTRICTED;
+ msg = "LOCATIONS_ERROR_SECURITY_RESTRICTED";
+ break;
+ case LOCATION_ERROR_NOT_AVAILABLE:
+ case LOCATION_ERROR_CONFIGURATION:
+ case LOCATION_ERROR_PARAMETER:
+ case LOCATION_ERROR_UNKNOWN:
+ default:
+ msg = "LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE";
+ ret = LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
+ }
+ LOCATIONS_LOGE("%s(0x%08x) : core fw error(0x%x)", msg, ret, code);
+ return ret;
+}
+
+static void __cb_service_updated(GObject * self, guint type, gpointer data, gpointer accuracy, gpointer userdata)
+{
+ LOCATIONS_LOGI("Callback function has been invoked. ");
+ location_manager_s *handle = (location_manager_s *) userdata;
+ if (type == VELOCITY_UPDATED && handle->user_cb[_LOCATIONS_EVENT_TYPE_VELOCITY]) {
+ LocationVelocity *vel = (LocationVelocity *) data;
+ LOCATIONS_LOGI("Current velocity: timestamp : %d, speed: %f, direction : %f, climb : %f",
+ vel->timestamp, vel->speed, vel->direction, vel->climb);
+ ((location_velocity_updated_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_VELOCITY]) (vel->speed, vel->direction,
+ vel->climb, vel->timestamp,
+ handle->user_data
+ [_LOCATIONS_EVENT_TYPE_VELOCITY]);
+ }
+ else if (type == POSITION_UPDATED && handle->user_cb[_LOCATIONS_EVENT_TYPE_POSITION]) {
+ LocationPosition *pos = (LocationPosition *) data;
+ LOCATIONS_LOGI("Current position: timestamp : %d, latitude : %f, altitude: %f, longitude: %f",
+ pos->timestamp, pos->latitude, pos->altitude, pos->longitude);
+ ((location_position_updated_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_POSITION]) (pos->latitude, pos->longitude,
+ pos->altitude, pos->timestamp,
+ handle->user_data
+ [_LOCATIONS_EVENT_TYPE_POSITION]);
+ }
+ else if (type == SATELLITE_UPDATED && handle->user_cb[_LOCATIONS_EVENT_TYPE_SATELLITE]) {
+ LocationSatellite *sat = (LocationSatellite *)data;
+ LOCATIONS_LOGI("Current satellite information: timestamp : %d, number of active : %d, number of inview : %d",
+ sat->timestamp, sat->num_of_sat_used, sat->num_of_sat_inview);
+ ((gps_status_satellite_updated_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_SATELLITE]) (sat->num_of_sat_used, sat->num_of_sat_inview,
+ sat->timestamp, handle->user_data[_LOCATIONS_EVENT_TYPE_SATELLITE]);
+ }
+}
+
+static void __cb_service_enabled(GObject * self, guint status, gpointer userdata)
+{
+ LOCATIONS_LOGI("Callback function has been invoked. ");
+ location_manager_s *handle = (location_manager_s *) userdata;
+ if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]) {
+ ((location_service_state_changed_cb)
+ handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]) (LOCATIONS_SERVICE_ENABLED,
+ handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]);
+ }
+}
+
+static void __cb_service_disabled(GObject * self, guint status, gpointer userdata)
+{
+ LOCATIONS_LOGI("Callback function has been invoked. ");
+ location_manager_s *handle = (location_manager_s *) userdata;
+ if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])
+ ((location_service_state_changed_cb)
+ handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]) (LOCATIONS_SERVICE_DISABLED,
+ handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]);
+}
+
+static int __compare_position (gconstpointer a, gconstpointer b)
+{
+ if(location_position_equal((LocationPosition*) a, (LocationPosition *)b) == TRUE) {
+ return 0;
+ }
+
+ return -1;
+}
+
+static int __boundary_compare(LocationBoundary * bound1, LocationBoundary * bound2)
+{
+ int ret = -1;
+
+ if (bound1->type == bound2->type) {
+ switch (bound1->type) {
+ case LOCATION_BOUNDARY_CIRCLE:
+ if (location_position_equal(bound1->circle.center, bound2->circle.center) && bound1->circle.radius == bound2->circle.radius) {
+ ret = 0;
+ }
+ break;
+ case LOCATION_BOUNDARY_RECT:
+ if (location_position_equal(bound1->rect.left_top, bound2->rect.left_top) && location_position_equal(bound1->rect.right_bottom, bound2->rect.right_bottom)) {
+ ret = 0;
+ }
+ break;
+ case LOCATION_BOUNDARY_POLYGON: {
+ GList *boundary1_next = NULL;
+ GList *boundary2_start = NULL, *boundary2_prev = NULL, *boundary2_next = NULL;
+ if (g_list_length(bound1->polygon.position_list) != g_list_length(bound2->polygon.position_list)) {
+ return -1;
+ }
+
+ boundary2_start = g_list_find_custom(bound2->polygon.position_list, g_list_nth_data(bound1->polygon.position_list, 0), (GCompareFunc) __compare_position);
+ if (boundary2_start == NULL) return -1;
+
+ boundary2_prev = g_list_previous(boundary2_start);
+ boundary2_next = g_list_next(boundary2_start);
+
+ if (boundary2_prev == NULL) boundary2_prev = g_list_last(bound2->polygon.position_list);
+ if (boundary2_next == NULL) boundary2_next = g_list_first(bound2->polygon.position_list);
+
+ boundary1_next = g_list_next(bound1->polygon.position_list);
+ if (location_position_equal((LocationPosition*)boundary1_next->data, (LocationPosition*)boundary2_prev->data) == TRUE) {
+ boundary1_next = g_list_next(boundary1_next);
+ while (boundary1_next) {
+ boundary2_prev = g_list_previous(boundary2_prev);
+ if (boundary2_prev == NULL) boundary2_prev = g_list_last(bound2->polygon.position_list);
+ if (location_position_equal((LocationPosition*)boundary1_next->data, (LocationPosition*) boundary2_prev->data) == FALSE) {
+ return -1;
+ }
+ boundary1_next = g_list_next(boundary1_next);
+ }
+ ret = 0;
+ } else if (location_position_equal((LocationPosition*)boundary1_next->data, (LocationPosition*)boundary2_next->data) == TRUE) {
+ boundary1_next = g_list_next(boundary1_next);
+ while(boundary1_next) {
+ boundary2_next = g_list_next(boundary2_next);
+ if (boundary2_next == NULL) boundary2_next = g_list_first(bound2->polygon.position_list);
+ if (location_position_equal((LocationPosition*)boundary1_next->data, (LocationPosition*) boundary2_next->data) == FALSE) {
+ return -1;
+ }
+ boundary1_next = g_list_next(boundary1_next);
+ }
+ ret = 0;
+ } else {
+ return -1;
+ }
+ break;
+ }
+ default:
+ break;
+ }
+ }
+ return ret;
+}
+
+static void __cb_zone_in(GObject * self, gpointer boundary, gpointer position, gpointer accuracy, gpointer userdata)
+{
+ LOCATIONS_LOGI("Callback function has been invoked.");
+ location_manager_s *handle = (location_manager_s *) userdata;
+ if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY]) {
+ LocationPosition *pos = (LocationPosition *) position;
+ ((location_zone_changed_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY]) (LOCATIONS_BOUNDARY_IN,
+ pos->latitude, pos->longitude,
+ pos->altitude, pos->timestamp,
+ handle->user_data
+ [_LOCATIONS_EVENT_TYPE_BOUNDARY]);
+ }
+
+ location_bounds_s *bounds;
+ GList *bounds_list = g_list_first(handle->bounds_list);
+ while (bounds_list) {
+ bounds = (location_bounds_s *)bounds_list->data;
+ if (__boundary_compare(boundary, bounds->boundary) == 0) {
+ LOCATIONS_LOGI("Find zone in boundary");
+ ((location_bounds_state_changed_cb) bounds->user_cb) (LOCATIONS_BOUNDARY_IN, bounds->user_data);
+ break;
+ }
+ bounds_list = g_list_next(bounds_list);
+ }
+}
+
+static void __cb_zone_out(GObject * self, gpointer boundary, gpointer position, gpointer accuracy, gpointer userdata)
+{
+ LOCATIONS_LOGI("Callback function has been invoked.");
+ location_manager_s *handle = (location_manager_s *) userdata;
+ if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY]) {
+ LocationPosition *pos = (LocationPosition *) position;
+ ((location_zone_changed_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY]) (LOCATIONS_BOUNDARY_OUT,
+ pos->latitude, pos->longitude,
+ pos->altitude, pos->timestamp,
+ handle->user_data
+ [_LOCATIONS_EVENT_TYPE_BOUNDARY]);
+ }
+
+ location_bounds_s *bounds;
+ GList *bounds_list = g_list_first(handle->bounds_list);
+ while (bounds_list) {
+ bounds = (location_bounds_s *)bounds_list->data;
+ if (__boundary_compare(boundary, bounds->boundary) == 0) {
+ LOCATIONS_LOGI("Find zone out boundary");
+ ((location_bounds_state_changed_cb) bounds->user_cb) (LOCATIONS_BOUNDARY_OUT, bounds->user_data);
+ break;
+ }
+ bounds_list = g_list_next(bounds_list);
+ }
+}
+
+static int __set_callback(_location_event_e type, location_manager_h manager, void *callback, void *user_data)
+{
+ LOCATIONS_NULL_ARG_CHECK(manager);
+ LOCATIONS_NULL_ARG_CHECK(callback);
+ location_manager_s *handle = (location_manager_s *) manager;
+ handle->user_cb[type] = callback;
+ handle->user_data[type] = user_data;
+ LOCATIONS_LOGI("event type : %d. ", type);
+ return LOCATIONS_ERROR_NONE;
+}
+
+static int __unset_callback(_location_event_e type, location_manager_h manager)
+{
+ LOCATIONS_NULL_ARG_CHECK(manager);
+ location_manager_s *handle = (location_manager_s *) manager;
+ handle->user_cb[type] = NULL;
+ handle->user_data[type] = NULL;
+ LOCATIONS_LOGI("event type : %d. ", type);
+ return LOCATIONS_ERROR_NONE;
+}
+
+static void __foreach_boundary(LocationBoundary * boundary, void *user_data)
+{
+ location_manager_s *handle = (location_manager_s *) user_data;
+
+ if (handle != NULL && boundary != NULL) {
+ int ret = -1;
+ location_bounds_h bounds;
+ if (boundary->type == LOCATION_BOUNDARY_CIRCLE) {
+ location_coords_s center;
+ center.latitude = boundary->circle.center->latitude;
+ center.longitude = boundary->circle.center->longitude;
+ ret = location_bounds_create_circle(center, boundary->circle.radius, &bounds);
+ } else if (boundary->type == LOCATION_BOUNDARY_RECT) {
+ location_coords_s left_top;
+ location_coords_s right_bottom;
+ left_top.latitude = boundary->rect.left_top->latitude;
+ left_top.longitude = boundary->rect.left_top->longitude;
+ right_bottom.latitude = boundary->rect.right_bottom->latitude;
+ right_bottom.longitude = boundary->rect.right_bottom->longitude;
+ ret = location_bounds_create_rect(left_top, right_bottom, &bounds);
+ } else if (boundary->type == LOCATION_BOUNDARY_POLYGON) {
+ GList *list = boundary->polygon.position_list;
+ int size = g_list_length(list);
+ if (size > 0) {
+ location_coords_s coords[size];
+ int cnt = 0;
+ while (list) {
+ LocationPosition *pos = list->data;
+ coords[cnt].latitude = pos->latitude;
+ coords[cnt].longitude = pos->longitude;
+ list = g_list_next(list);
+ cnt++;
+ }
+ ret = location_bounds_create_polygon(coords, size, &bounds);
+ }
+ } else {
+ LOCATIONS_LOGI("Invalid boundary type : %d", boundary->type);
+ }
+
+ if (ret != LOCATIONS_ERROR_NONE) {
+ LOCATIONS_LOGI("Failed to create location_bounds : (0x%08x) ", ret);
+ } else {
+ if (handle->is_continue_foreach_bounds) {
+ handle->is_continue_foreach_bounds =
+ ((location_bounds_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS]) (bounds,
+ handle->
+ user_data
+ [_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS]);
+ }
+ location_bounds_destroy(bounds);
+ }
+ } else {
+ LOCATIONS_LOGI("__foreach_boundary() has been failed");
+ }
+}
+
+/////////////////////////////////////////
+// Location Manager
+////////////////////////////////////////
+
+/*
+* Public Implementation
+*/
+
+bool location_manager_is_supported_method(location_method_e method)
+{
+ LocationMethod _method = LOCATION_METHOD_NONE;
+ switch (method) {
+ case LOCATIONS_METHOD_HYBRID:
+ _method = LOCATION_METHOD_HYBRID;
+ break;
+ case LOCATIONS_METHOD_GPS:
+ _method = LOCATION_METHOD_GPS;
+ break;
+ case LOCATIONS_METHOD_WPS:
+ _method = LOCATION_METHOD_WPS;
+ break;
+ case LOCATIONS_METHOD_CPS:
+ _method = LOCATION_METHOD_CPS;
+ break;
+ default:
+ _method = LOCATION_METHOD_NONE;
+ break;
+ }
+ return location_is_supported_method(_method);
+}
+
+int location_manager_create(location_method_e method, location_manager_h * manager)
+{
+ LOCATIONS_NULL_ARG_CHECK(manager);
+ if (location_init() != LOCATION_ERROR_NONE)
+ return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
+
+ LocationMethod _method = LOCATION_METHOD_NONE;
+ switch (method) {
+ case LOCATIONS_METHOD_HYBRID:
+ _method = LOCATION_METHOD_HYBRID;
+ break;
+ case LOCATIONS_METHOD_GPS:
+ _method = LOCATION_METHOD_GPS;
+ break;
+ case LOCATIONS_METHOD_WPS:
+ _method = LOCATION_METHOD_WPS;
+ break;
+ case LOCATIONS_METHOD_CPS:
+ _method = LOCATION_METHOD_CPS;
+ break;
+ case LOCATIONS_METHOD_NONE:
+ return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
+ default:
+ {
+ LOCATIONS_LOGE("LOCATIONS_ERROR_INVALID_PARAMETER(0x%08x) : Out of range (location_method_e) - method : %d ",
+ LOCATIONS_ERROR_INVALID_PARAMETER, method);
+ return LOCATIONS_ERROR_INVALID_PARAMETER;
+ }
+ }
+
+ location_manager_s *handle = (location_manager_s *) malloc(sizeof(location_manager_s));
+ if (handle == NULL) {
+ LOCATIONS_LOGE("OUT_OF_MEMORY(0x%08x)", LOCATIONS_ERROR_OUT_OF_MEMORY);
+ return LOCATIONS_ERROR_OUT_OF_MEMORY;
+ }
+
+ memset(handle, 0, sizeof(location_manager_s));
+
+ handle->object = location_new(_method);
+ if (handle->object == NULL) {
+ LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : fail to location_new",
+ LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
+ free(handle);
+ return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
+ }
+ handle->method = method;
+ handle->is_continue_foreach_bounds = TRUE;
+ handle->bounds_list = NULL;
+ *manager = (location_manager_h) handle;
+ return LOCATIONS_ERROR_NONE;
+}
+
+int location_manager_destroy(location_manager_h manager)
+{
+ LOCATIONS_NULL_ARG_CHECK(manager);
+ location_manager_s *handle = (location_manager_s *) manager;
+
+ int ret = location_free(handle->object);
+ if (ret != LOCATIONS_ERROR_NONE) {
+ return __convert_error_code(ret);
+ }
+ free(handle);
+ return LOCATIONS_ERROR_NONE;
+}
+
+int location_manager_start(location_manager_h manager)
+{
+ LOCATIONS_NULL_ARG_CHECK(manager);
+ location_manager_s *handle = (location_manager_s *) manager;
+
+ g_signal_connect(handle->object, "service-enabled", G_CALLBACK(__cb_service_enabled), handle);
+ g_signal_connect(handle->object, "service-disabled", G_CALLBACK(__cb_service_disabled), handle);
+ g_signal_connect(handle->object, "service-updated", G_CALLBACK(__cb_service_updated), handle);
+ g_signal_connect(handle->object, "zone-in", G_CALLBACK(__cb_zone_in), handle);
+ g_signal_connect(handle->object, "zone-out", G_CALLBACK(__cb_zone_out), handle);
+
+ int ret = location_start(handle->object);
+ if (ret != LOCATION_ERROR_NONE) {
+ return __convert_error_code(ret);
+ }
+ return LOCATIONS_ERROR_NONE;
+}
+
+int location_manager_stop(location_manager_h manager)
+{
+ LOCATIONS_NULL_ARG_CHECK(manager);
+ location_manager_s *handle = (location_manager_s *) manager;
+
+ int ret = location_stop(handle->object);
+ if (ret != LOCATION_ERROR_NONE) {
+ return __convert_error_code(ret);
+ }
+ return LOCATIONS_ERROR_NONE;
+}
+
+int location_manager_add_boundary(location_manager_h manager, location_bounds_h bounds)
+{
+ LOCATIONS_NULL_ARG_CHECK(manager);
+ LOCATIONS_NULL_ARG_CHECK(bounds);
+
+ location_manager_s *handle = (location_manager_s *) manager;
+ location_bounds_s *bound_handle = (location_bounds_s *) bounds;
+ int ret = location_boundary_add(handle->object, bound_handle->boundary);
+ if (ret != LOCATION_ERROR_NONE) {
+ return __convert_error_code(ret);
+ }
+ bound_handle->is_added = TRUE;
+ handle->bounds_list = g_list_append(handle->bounds_list, bound_handle);
+ return LOCATIONS_ERROR_NONE;
+}
+
+int location_manager_remove_boundary(location_manager_h manager, location_bounds_h bounds)
+{
+ LOCATIONS_NULL_ARG_CHECK(manager);
+ LOCATIONS_NULL_ARG_CHECK(bounds);
+
+ location_manager_s *handle = (location_manager_s *) manager;
+ location_bounds_s *bound_handle = (location_bounds_s *) bounds;
+ int ret = location_boundary_remove(handle->object, bound_handle->boundary);
+ if (ret != LOCATION_ERROR_NONE) {
+ return __convert_error_code(ret);
+ }
+ handle->bounds_list = g_list_remove(handle->bounds_list, bound_handle);
+ bound_handle->is_added = FALSE;
+ return LOCATIONS_ERROR_NONE;
+}
+
+int location_manager_foreach_boundary(location_manager_h manager, location_bounds_cb callback, void *user_data)
+{
+ LOCATIONS_NULL_ARG_CHECK(manager);
+ LOCATIONS_NULL_ARG_CHECK(callback);
+
+ location_manager_s *handle = (location_manager_s *) manager;
+ handle->user_cb[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS] = callback;
+ handle->user_data[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS] = user_data;
+ handle->is_continue_foreach_bounds = TRUE;
+ int ret = location_boundary_foreach(handle->object, __foreach_boundary, handle);
+ if (ret != LOCATION_ERROR_NONE) {
+ return __convert_error_code(ret);
+ }
+ return LOCATIONS_ERROR_NONE;
+}
+
+int location_manager_get_method(location_manager_h manager, location_method_e * method)
+{
+ LOCATIONS_NULL_ARG_CHECK(manager);
+ LOCATIONS_NULL_ARG_CHECK(method);
+ location_manager_s *handle = (location_manager_s *) manager;
+ LocationMethod _method = LOCATION_METHOD_NONE;
+ g_object_get(handle->object, "method", &_method, NULL);
+ switch (_method) {
+ case LOCATION_METHOD_NONE:
+ *method = LOCATIONS_METHOD_NONE;
+ break;
+ case LOCATION_METHOD_HYBRID:
+ *method = LOCATIONS_METHOD_HYBRID;
+ break;
+ case LOCATION_METHOD_GPS:
+ *method = LOCATIONS_METHOD_GPS;
+ break;
+ case LOCATION_METHOD_WPS:
+ *method = LOCATIONS_METHOD_WPS;
+ break;
+ case LOCATION_METHOD_CPS:
+ *method = LOCATIONS_METHOD_CPS;
+ break;
+ default:
+ {
+ LOCATIONS_LOGE("LOCATIONS_ERROR_INVALID_PARAMETER(0x%08x) : Out of range (location_method_e) - method : %d ",
+ LOCATIONS_ERROR_INVALID_PARAMETER, method);
+ return LOCATIONS_ERROR_INVALID_PARAMETER;
+ }
+ }
+ //*method = handle->method;
+ return LOCATIONS_ERROR_NONE;
+}
+
+int location_manager_get_position(location_manager_h manager, double *altitude, double *latitude, double *longitude,
+ time_t * timestamp)
+{
+ LOCATIONS_NULL_ARG_CHECK(manager);
+ LOCATIONS_NULL_ARG_CHECK(altitude);
+ LOCATIONS_NULL_ARG_CHECK(latitude);
+ LOCATIONS_NULL_ARG_CHECK(longitude);
+ LOCATIONS_NULL_ARG_CHECK(timestamp);
+
+ location_manager_s *handle = (location_manager_s *) manager;
+ int ret;
+ LocationPosition *pos = NULL;
+ LocationAccuracy *acc = NULL;
+ ret = location_get_position(handle->object, &pos, &acc);
+ if (ret != LOCATION_ERROR_NONE) {
+ return __convert_error_code(ret);
+ }
+
+ if (pos->status == LOCATION_STATUS_NO_FIX) {
+ *altitude = -1;
+ *latitude = -1;
+ *longitude = -1;
+ } else {
+ if (pos->status == LOCATION_STATUS_3D_FIX) {
+ *altitude = pos->altitude;
+ } else {
+ *altitude = -1;
+ }
+ *latitude = pos->latitude;
+ *longitude = pos->longitude;
+ }
+ *timestamp = pos->timestamp;
+ location_position_free(pos);
+ location_accuracy_free(acc);
+ return LOCATIONS_ERROR_NONE;
+}
+
+int location_manager_get_velocity(location_manager_h manager, double *climb, double *direction, double *speed, time_t * timestamp)
+{
+ LOCATIONS_NULL_ARG_CHECK(manager);
+ LOCATIONS_NULL_ARG_CHECK(climb);
+ LOCATIONS_NULL_ARG_CHECK(direction);
+ LOCATIONS_NULL_ARG_CHECK(speed);
+ LOCATIONS_NULL_ARG_CHECK(timestamp);
+
+ location_manager_s *handle = (location_manager_s *) manager;
+ int ret;
+ LocationVelocity *vel = NULL;
+ LocationAccuracy *acc = NULL;
+ ret = location_get_velocity(handle->object, &vel, &acc);
+ if (ret != LOCATION_ERROR_NONE) {
+ return __convert_error_code(ret);
+ }
+
+ *climb = vel->climb;
+ *direction = vel->direction;
+ *speed = vel->speed;
+ *timestamp = vel->timestamp;
+ location_velocity_free(vel);
+ location_accuracy_free(acc);
+ return LOCATIONS_ERROR_NONE;
+}
+
+int location_manager_get_accuracy(location_manager_h manager, location_accuracy_level_e * level, double *horizontal,
+ double *vertical)
+{
+ LOCATIONS_NULL_ARG_CHECK(manager);
+ LOCATIONS_NULL_ARG_CHECK(level);
+ LOCATIONS_NULL_ARG_CHECK(horizontal);
+ LOCATIONS_NULL_ARG_CHECK(vertical);
+ location_manager_s *handle = (location_manager_s *) manager;
+
+ int ret;
+ LocationPosition *pos = NULL;
+ LocationAccuracy *acc = NULL;
+ ret = location_get_position(handle->object, &pos, &acc);
+ if (ret != LOCATION_ERROR_NONE) {
+ return __convert_error_code(ret);
+ }
+
+ if (acc == NULL) {
+ return __convert_error_code(LOCATION_ERROR_NOT_AVAILABLE);
+ }
+
+ *level = acc->level;
+ *horizontal = acc->horizontal_accuracy;
+ *vertical = acc->vertical_accuracy;
+ location_position_free(pos);
+ location_accuracy_free(acc);
+ return LOCATIONS_ERROR_NONE;
+}
+
+int location_manager_get_last_position(location_manager_h manager, double *altitude, double *latitude, double *longitude,
+ time_t * timestamp)
+{
+ LOCATIONS_NULL_ARG_CHECK(manager);
+ LOCATIONS_NULL_ARG_CHECK(altitude);
+ LOCATIONS_NULL_ARG_CHECK(latitude);
+ LOCATIONS_NULL_ARG_CHECK(longitude);
+ LOCATIONS_NULL_ARG_CHECK(timestamp);
+
+ location_manager_s *handle = (location_manager_s *) manager;
+
+ int ret;
+ LocationPosition *last_pos = NULL;
+ LocationAccuracy *last_acc = NULL;
+ ret = location_get_last_position(handle->object, &last_pos, &last_acc);
+ if (ret != LOCATION_ERROR_NONE) {
+ return __convert_error_code(ret);
+ }
+
+ if (last_pos->status == LOCATION_STATUS_NO_FIX) {
+ *altitude = -1;
+ *latitude = -1;
+ *longitude = -1;
+ } else {
+ if (last_pos->status == LOCATION_STATUS_3D_FIX) {
+ *altitude = last_pos->altitude;
+ } else {
+ *altitude = -1;
+ }
+ *latitude = last_pos->latitude;
+ *longitude = last_pos->longitude;
+ }
+ *timestamp = last_pos->timestamp;
+ location_position_free(last_pos);
+ location_accuracy_free(last_acc);
+ return LOCATIONS_ERROR_NONE;
+}
+
+int location_manager_get_last_velocity(location_manager_h manager, double *climb, double *direction, double *speed, time_t * timestamp)
+{
+ LOCATIONS_NULL_ARG_CHECK(manager);
+ LOCATIONS_NULL_ARG_CHECK(climb);
+ LOCATIONS_NULL_ARG_CHECK(direction);
+ LOCATIONS_NULL_ARG_CHECK(speed);
+ LOCATIONS_NULL_ARG_CHECK(timestamp);
+
+ location_manager_s *handle = (location_manager_s *) manager;
+
+ int ret;
+ LocationVelocity *last_vel = NULL;
+ LocationAccuracy *last_acc = NULL;
+ ret = location_get_last_velocity(handle->object, &last_vel, &last_acc);
+ if (ret != LOCATION_ERROR_NONE) {
+ return __convert_error_code(ret);
+ }
+
+ *climb = last_vel->climb;
+ *direction = last_vel->direction;
+ *speed = last_vel->speed;
+ *timestamp = last_vel->timestamp;
+ location_velocity_free(last_vel);
+ location_accuracy_free(last_acc);
+ return LOCATIONS_ERROR_NONE;
+}
+
+int location_manager_get_last_accuracy(location_manager_h manager, location_accuracy_level_e * level, double *horizontal,
+ double *vertical)
+{
+ LOCATIONS_NULL_ARG_CHECK(manager);
+ LOCATIONS_NULL_ARG_CHECK(level);
+ LOCATIONS_NULL_ARG_CHECK(horizontal);
+ LOCATIONS_NULL_ARG_CHECK(vertical);
+ location_manager_s *handle = (location_manager_s *) manager;
+
+ int ret;
+ LocationPosition *last_pos = NULL;
+ LocationAccuracy *last_acc = NULL;
+ ret = location_get_last_position(handle->object, &last_pos, &last_acc);
+ if (ret != LOCATION_ERROR_NONE) {
+ return __convert_error_code(ret);
+ }
+
+ *level = last_acc->level;
+ *horizontal = last_acc->horizontal_accuracy;
+ *vertical = last_acc->vertical_accuracy;
+ location_position_free(last_pos);
+ location_accuracy_free(last_acc);
+ return LOCATIONS_ERROR_NONE;
+}
+
+int location_manager_get_accessibility_state(location_accessibility_state_e* state)
+{
+ LOCATIONS_NULL_ARG_CHECK(state);
+
+ int ret = LOCATION_ERROR_NONE;
+ LocationAccessState auth = LOCATION_ACCESS_NONE;
+ ret = location_get_accessibility_state (&auth);
+ if (ret != LOCATION_ERROR_NONE) {
+ *state = LOCATIONS_ACCESS_STATE_NONE;
+ return __convert_error_code(ret);
+ }
+
+ switch (auth) {
+ case LOCATION_ACCESS_DENIED:
+ *state = LOCATIONS_ACCESS_STATE_DENIED;
+ break;
+ case LOCATION_ACCESS_ALLOWED:
+ *state = LOCATIONS_ACCESS_STATE_ALLOWED;
+ break;
+ case LOCATION_ACCESS_NONE:
+ default:
+ *state = LOCATIONS_ACCESS_STATE_NONE;
+ break;
+ }
+
+ return LOCATIONS_ERROR_NONE;
+}
+
+int location_manager_set_position_updated_cb(location_manager_h manager, location_position_updated_cb callback, int interval, void *user_data)
+{
+ LOCATIONS_CHECK_CONDITION(interval >= 1
+ && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
+ LOCATIONS_NULL_ARG_CHECK(manager);
+ location_manager_s *handle = (location_manager_s *) manager;
+ g_object_set(handle->object, "pos-interval", interval, NULL);
+ return __set_callback(_LOCATIONS_EVENT_TYPE_POSITION, manager, callback, user_data);
+}
+
+int location_manager_unset_position_updated_cb(location_manager_h manager)
+{
+ return __unset_callback(_LOCATIONS_EVENT_TYPE_POSITION, manager);
+}
+
+int location_manager_set_velocity_updated_cb(location_manager_h manager, location_velocity_updated_cb callback, int interval, void *user_data)
+{
+ LOCATIONS_CHECK_CONDITION(interval >= 1
+ && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
+ LOCATIONS_NULL_ARG_CHECK(manager);
+ location_manager_s *handle = (location_manager_s *) manager;
+ g_object_set(handle->object, "vel-interval", interval, NULL);
+ return __set_callback(_LOCATIONS_EVENT_TYPE_VELOCITY, manager, callback, user_data);
+}
+
+int location_manager_unset_velocity_updated_cb(location_manager_h manager)
+{
+ return __unset_callback(_LOCATIONS_EVENT_TYPE_VELOCITY, manager);
+}
+
+int location_manager_set_service_state_changed_cb(location_manager_h manager, location_service_state_changed_cb callback,
+ void *user_data)
+{
+ return __set_callback(_LOCATIONS_EVENT_TYPE_SERVICE_STATE, manager, callback, user_data);
+}
+
+int location_manager_unset_service_state_changed_cb(location_manager_h manager)
+{
+ return __unset_callback(_LOCATIONS_EVENT_TYPE_SERVICE_STATE, manager);
+}
+
+int location_manager_set_zone_changed_cb(location_manager_h manager, location_zone_changed_cb callback, void *user_data)
+{
+ return __set_callback(_LOCATIONS_EVENT_TYPE_BOUNDARY, manager, callback, user_data);
+}
+
+int location_manager_unset_zone_changed_cb(location_manager_h manager)
+{
+ return __unset_callback(_LOCATIONS_EVENT_TYPE_BOUNDARY, manager);
+}
+
+int location_manager_get_distance(double start_latitude, double start_longitude, double end_latitude, double end_longitude, double *distance)
+{
+ LOCATIONS_NULL_ARG_CHECK(distance);
+ LOCATIONS_CHECK_CONDITION(start_latitude>=-90 && start_latitude<=90,LOCATIONS_ERROR_INVALID_PARAMETER,"LOCATIONS_ERROR_INVALID_PARAMETER");
+ LOCATIONS_CHECK_CONDITION(start_longitude>=-180 && start_longitude<=180,LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
+ LOCATIONS_CHECK_CONDITION(end_latitude>=-90 && end_latitude<=90,LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
+ LOCATIONS_CHECK_CONDITION(end_longitude>=-180 && end_longitude<=180,LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
+
+ int ret = LOCATION_ERROR_NONE;
+ ulong u_distance;
+
+ LocationPosition *start = location_position_new (0, start_latitude, start_longitude, 0, LOCATION_STATUS_2D_FIX);
+ LocationPosition *end = location_position_new (0, end_latitude, end_longitude, 0, LOCATION_STATUS_2D_FIX);
+
+ ret = location_get_distance (start, end, &u_distance);
+ if (ret != LOCATION_ERROR_NONE) {
+ return __convert_error_code(ret);
+ }
+
+ *distance = (double)u_distance;
+
+ return LOCATIONS_ERROR_NONE;
+}
+
+int location_manager_send_command(const char *cmd)
+{
+ LOCATIONS_NULL_ARG_CHECK(cmd);
+
+ int ret;
+ ret = location_send_command(cmd);
+ if (ret != LOCATION_ERROR_NONE) {
+ return __convert_error_code(ret);
+ }
+
+ return LOCATIONS_ERROR_NONE;
+}
+
+/////////////////////////////////////////
+// GPS Status & Satellites
+////////////////////////////////////////
+
+int gps_status_get_nmea(location_manager_h manager, char **nmea)
+{
+ LOCATIONS_NULL_ARG_CHECK(manager);
+ LOCATIONS_NULL_ARG_CHECK(nmea);
+ location_manager_s *handle = (location_manager_s *) manager;
+
+ if (handle->method == LOCATIONS_METHOD_HYBRID) {
+ LocationMethod _method = LOCATION_METHOD_NONE;
+ g_object_get(handle->object, "method", &_method, NULL);
+ if (_method != LOCATION_METHOD_GPS) {
+ LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d",
+ LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
+ return LOCATIONS_ERROR_INCORRECT_METHOD;
+ }
+ } else if (handle->method != LOCATIONS_METHOD_GPS) {
+ LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d",
+ LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
+ return LOCATIONS_ERROR_INCORRECT_METHOD;
+ }
+ gchar *nmea_data = NULL;
+ g_object_get(handle->object, "nmea", &nmea_data, NULL);
+ if (nmea_data == NULL) {
+ LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : nmea data is NULL ",
+ LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
+ return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
+ }
+ *nmea = NULL;
+ *nmea = strdup(nmea_data);
+ if (*nmea == NULL) {
+ LOCATIONS_LOGE("LOCATIONS_ERROR_OUT_OF_MEMORY(0x%08x) : fail to strdup ",
+ LOCATIONS_ERROR_OUT_OF_MEMORY);
+ return LOCATIONS_ERROR_OUT_OF_MEMORY;
+ }
+ g_free(nmea_data);
+ return LOCATIONS_ERROR_NONE;
+}
+
+int gps_status_get_satellite(location_manager_h manager, int *num_of_active, int *num_of_inview, time_t *timestamp)
+{
+ LOCATIONS_NULL_ARG_CHECK(manager);
+ LOCATIONS_NULL_ARG_CHECK(num_of_active);
+ LOCATIONS_NULL_ARG_CHECK(num_of_inview);
+ LOCATIONS_NULL_ARG_CHECK(timestamp);
+ location_manager_s *handle = (location_manager_s *) manager;
+ LocationSatellite *sat = NULL;
+ int ret = location_get_satellite (handle->object, &sat);
+ if (ret != LOCATION_ERROR_NONE || sat == NULL) {
+ if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
+ LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d",
+ LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
+ return LOCATIONS_ERROR_INCORRECT_METHOD;
+ }
+
+ LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ",
+ LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
+ return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
+ }
+
+ *num_of_active = sat->num_of_sat_used;
+ *num_of_inview = sat->num_of_sat_inview;
+ *timestamp = sat->timestamp;
+ location_satellite_free(sat);
+ sat = NULL;
+ return LOCATIONS_ERROR_NONE;
+}
+
+int gps_status_set_satellite_updated_cb(location_manager_h manager, gps_status_satellite_updated_cb callback, int interval, void *user_data)
+{
+ LOCATIONS_CHECK_CONDITION(interval >= 1
+ && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
+ LOCATIONS_NULL_ARG_CHECK(manager);
+ location_manager_s *handle = (location_manager_s *) manager;
+ g_object_set(handle->object, "sat-interval", interval, NULL);
+ return __set_callback(_LOCATIONS_EVENT_TYPE_SATELLITE, manager, callback, user_data);
+}
+
+int gps_status_unset_satellite_updated_cb(location_manager_h manager)
+{
+ return __unset_callback(_LOCATIONS_EVENT_TYPE_SATELLITE, manager);
+}
+
+
+int gps_status_foreach_satellites_in_view(location_manager_h manager, gps_status_get_satellites_cb callback, void *user_data)
+{
+ LOCATIONS_NULL_ARG_CHECK(manager);
+ LOCATIONS_NULL_ARG_CHECK(callback);
+ location_manager_s *handle = (location_manager_s *) manager;
+ LocationSatellite *sat = NULL;
+ int ret = location_get_satellite (handle->object, &sat);
+ if (ret != LOCATION_ERROR_NONE || sat == NULL) {
+ if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
+ LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d",
+ LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
+ return LOCATIONS_ERROR_INCORRECT_METHOD;
+ }
+
+ LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ",
+ LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
+ return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
+ }
+
+ int i;
+ for (i = 0; i < sat->num_of_sat_inview; i++) {
+ guint prn;
+ gboolean used;
+ guint elevation;
+ guint azimuth;
+ gint snr;
+ location_satellite_get_satellite_details(sat, i, &prn, &used, &elevation, &azimuth, &snr);
+ if (callback(azimuth, elevation, prn, snr, used, user_data) != TRUE)
+ break;
+ }
+ location_satellite_free(sat);
+ sat = NULL;
+ return LOCATIONS_ERROR_NONE;
+}
+
+int gps_status_get_last_satellite(location_manager_h manager, int *num_of_active, int *num_of_inview, time_t *timestamp)
+{
+ LOCATIONS_NULL_ARG_CHECK(manager);
+ LOCATIONS_NULL_ARG_CHECK(num_of_active);
+ LOCATIONS_NULL_ARG_CHECK(num_of_inview);
+ LOCATIONS_NULL_ARG_CHECK(timestamp);
+ location_manager_s *handle = (location_manager_s *) manager;
+ int ret = LOCATION_ERROR_NONE;
+ LocationSatellite *last_sat = NULL;
+ ret = location_get_last_satellite(handle->object, &last_sat);
+ if (ret != LOCATION_ERROR_NONE || last_sat == NULL) {
+ if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
+ LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d",
+ LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
+ return LOCATIONS_ERROR_INCORRECT_METHOD;
+ }
+
+ LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ",
+ LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
+ return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
+ }
+
+ *num_of_active = last_sat->num_of_sat_used;
+ *num_of_inview = last_sat->num_of_sat_inview;
+ *timestamp = last_sat->timestamp;
+ location_satellite_free(last_sat);
+ return LOCATIONS_ERROR_NONE;
+}
+
+int gps_status_foreach_last_satellites_in_view(location_manager_h manager, gps_status_get_satellites_cb callback,
+ void *user_data)
+{
+ LOCATIONS_NULL_ARG_CHECK(manager);
+ LOCATIONS_NULL_ARG_CHECK(callback);
+ location_manager_s *handle = (location_manager_s *) manager;
+ int ret;
+ LocationSatellite *last_sat = NULL;
+ ret = location_get_last_satellite(handle->object, &last_sat);
+ if (ret != LOCATION_ERROR_NONE || last_sat == NULL) {
+ if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
+ LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d",
+ LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
+ return LOCATIONS_ERROR_INCORRECT_METHOD;
+ }
+
+ LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ",
+ LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
+ return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
+ }
+
+ int i;
+ for (i = 0; i < last_sat->num_of_sat_inview; i++) {
+ guint prn;
+ gboolean used;
+ guint elevation;
+ guint azimuth;
+ gint snr;
+ location_satellite_get_satellite_details(last_sat, i, &prn, &used, &elevation, &azimuth, &snr);
+ if (callback(azimuth, elevation, prn, snr, used, user_data) != TRUE) {
+ break;
+ }
+ }
+ location_satellite_free(last_sat);
+ return LOCATIONS_ERROR_NONE;
+}
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
new file mode 100644
index 0000000..afc523f
--- /dev/null
+++ b/test/CMakeLists.txt
@@ -0,0 +1,19 @@
+
+SET(fw_test "${fw_name}-test")
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(${fw_test} REQUIRED )
+FOREACH(flag ${${fw_test}_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall -Werror")
+
+aux_source_directory(. sources)
+FOREACH(src ${sources})
+ GET_FILENAME_COMPONENT(src_name ${src} NAME_WE)
+ MESSAGE("${src_name}")
+ ADD_EXECUTABLE(${src_name} ${src})
+ TARGET_LINK_LIBRARIES(${src_name} ${fw_name} ${${fw_test}_LDFLAGS})
+ENDFOREACH()
+
diff --git a/test/location_test.c b/test/location_test.c
new file mode 100644
index 0000000..841e1a5
--- /dev/null
+++ b/test/location_test.c
@@ -0,0 +1,339 @@
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <glib.h>
+#include <locations.h>
+#include <location_bounds.h>
+
+location_manager_h manager;
+
+void zone_event_cb(location_boundary_state_e state, double latitude, double longitude, double altitude, time_t timestamp,
+ void *user_data)
+{
+ if (state == LOCATIONS_BOUNDARY_IN) {
+ printf("Entering zone\n");
+ } else // state == LOCATIONS_BOUNDARY_OUT
+ {
+ printf("Leaving zone\n");
+ }
+
+ printf("Latitude: %lf, longitude: %lf, altitude: %lf\n", latitude, longitude, altitude);
+
+ printf("Time: %s\n", ctime(&timestamp));
+}
+
+static bool satellites_foreach_cb(unsigned int azimuth, unsigned int elevation, unsigned int prn, int snr, bool is_in_use,
+ void *user_data)
+{
+ printf("[Satellite information] azimuth : %d, elevation : %d, prn :%d, snr : %d, used: %d\n", azimuth, elevation, prn,
+ snr, is_in_use);
+ return true;
+}
+
+static bool last_satellites_foreach_cb(unsigned int azimuth, unsigned int elevation, unsigned int prn, int snr, bool is_in_use,
+ void *user_data)
+{
+ printf("[Last Satellite information] azimuth : %d, elevation : %d, prn :%d, snr : %d, used: %d\n", azimuth, elevation,
+ prn, snr, is_in_use);
+ return true;
+}
+
+static void _state_change_cb(location_service_state_e state, void *user_data)
+{
+ fprintf(stderr, "--------------------------state change %d---------\n", state);
+ location_manager_h lm = (location_manager_h) user_data;
+ if (state == LOCATIONS_SERVICE_ENABLED) {
+ int ret;
+ double altitude;
+ double latitude;
+ double longitude;
+ time_t timestamp;
+ ret = location_manager_get_position(lm, &altitude, &latitude, &longitude, &timestamp);
+ if (ret != LOCATIONS_ERROR_NONE) {
+ printf(" Fail : location_manager_get_position ---> %d \n", ret);
+ } else {
+ printf("[%ld] alt: %g, lat %g, long %g\n", timestamp, altitude, latitude, longitude);
+ }
+
+ location_accuracy_level_e level;
+ double horizontal;
+ double vertical;
+ ret = location_manager_get_accuracy(lm, &level, &horizontal, &vertical);
+ if (ret != LOCATIONS_ERROR_NONE) {
+ printf(" Fail : location_manager_get_accuracy ---> %d \n", ret);
+ } else {
+ printf("Level : %d, horizontal: %g, vertical %g\n", level, horizontal, vertical);
+ }
+
+ char *nmea;
+ ret = gps_status_get_nmea(lm, &nmea);
+ if (ret != LOCATIONS_ERROR_NONE) {
+ printf(" Fail : gps_status_get_nmea ---> %d \n", ret);
+ } else {
+ printf("NMEA : %s\n", nmea);
+ free(nmea);
+ }
+
+ int num_of_view, num_of_active;
+ ret = gps_status_get_satellite(lm, &num_of_active, &num_of_view, &timestamp);
+ if (ret != LOCATIONS_ERROR_NONE) {
+ printf(" Fail : gps_status_get_satellite_count_in_view ---> %d \n", ret);
+ } else {
+ printf("[%ld] Satellite number of active : %d, in view : %d\n", timestamp, num_of_active, num_of_view);
+ }
+
+ ret = gps_status_foreach_satellites_in_view(lm, satellites_foreach_cb, user_data);
+ if (ret != LOCATIONS_ERROR_NONE) {
+ printf(" Fail : gps_status_foreach_satellites_in_view ---> %d \n", ret);
+ }
+ }
+}
+
+static bool __poly_coords_cb(location_coords_s coords, void *user_data)
+{
+ printf("location_bounds_foreach_rect_coords(latitude : %lf, longitude: %lf) \n", coords.latitude, coords.longitude);
+ return TRUE;
+}
+
+static bool __location_bounds_cb(location_bounds_h bounds, void *user_data)
+{
+ if (bounds == NULL)
+ printf("bounds ==NULL\n");
+ else {
+ location_bounds_type_e type;
+ location_bounds_get_type(bounds, &type);
+ if (type == LOCATION_BOUNDS_CIRCLE) {
+ location_coords_s center;
+ double radius;
+ location_bounds_get_circle_coords(bounds, &center, &radius);
+ printf("location_bounds_get_circle_coords(center : %lf, %lf, radius : %lf) \n", center.latitude,
+ center.longitude, radius);
+
+ } else if (type == LOCATION_BOUNDS_RECT) {
+ location_coords_s left_top;
+ location_coords_s right_bottom;
+ location_bounds_get_rect_coords(bounds, &left_top, &right_bottom);
+ printf("location_bounds_get_rect_coords(left_top : %lf, %lf - right_bottom : %lf, %lf) \n",
+ left_top.latitude, left_top.longitude, right_bottom.latitude, right_bottom.longitude);
+ } else if (type == LOCATION_BOUNDS_POLYGON) {
+ location_bounds_foreach_polygon_coords(bounds, __poly_coords_cb, NULL);
+ }
+ }
+ return TRUE;
+}
+
+void location_bounds_test()
+{
+ int ret;
+ location_coords_s center;
+ center.latitude = 37.258;
+ center.longitude = 127.056;
+ double radius = 30;
+ location_bounds_h bounds_circle;
+ ret = location_bounds_create_circle(center, radius, &bounds_circle);
+ if (ret != LOCATION_BOUNDS_ERROR_NONE) {
+ printf("location_bounds_create_circle() failed\n");
+ } else
+ printf("Bounds(circle) has been created successfully.\n");
+
+ ret = location_manager_add_boundary(manager, bounds_circle);
+ if (ret != LOCATIONS_ERROR_NONE) {
+ printf("Setting boundary failed\n");
+ } else
+ printf("Boundary set\n");
+
+ location_coords_s center2;
+ double radius2;
+ ret = location_bounds_get_circle_coords(bounds_circle, &center2, &radius2);
+ if (ret != LOCATIONS_ERROR_NONE) {
+ printf("location_bounds_get_circle_coords() failed\n");
+ } else
+ printf("location_bounds_get_circle_coords(center : %lf, %lf, radius : %lf) \n", center2.latitude,
+ center2.longitude, radius2);
+
+ //Add the rect bounds
+ location_coords_s left_top;
+ left_top.latitude = 30;
+ left_top.longitude = 30;
+
+ location_coords_s right_bottom;
+ right_bottom.latitude = 10;
+ right_bottom.longitude = 50;
+
+ location_bounds_h bounds_rect;
+ ret = location_bounds_create_rect(left_top, right_bottom, &bounds_rect);
+ if (ret != LOCATION_BOUNDS_ERROR_NONE) {
+ printf("location_bounds_create_rect() failed\n");
+ } else
+ printf("Bounds(rect) has been created successfully.\n");
+
+ ret = location_manager_add_boundary(manager, bounds_rect);
+ if (ret != LOCATIONS_ERROR_NONE) {
+ printf("Setting boundary failed\n");
+ } else
+ printf("Boundary set\n");
+
+ location_coords_s left_top2;
+ location_coords_s right_bottom2;
+
+ ret = location_bounds_get_rect_coords(bounds_rect, &left_top2, &right_bottom2);
+ if (ret != LOCATIONS_ERROR_NONE) {
+ printf("location_bounds_get_rect_coords() failed\n");
+ } else
+ printf("location_bounds_get_rect_coords(left_top : %lf, %lf - right_bottom : %lf, %lf) \n", left_top2.latitude,
+ left_top2.longitude, right_bottom2.latitude, right_bottom2.longitude);
+
+ //Add the polygon bounds
+
+ int poly_size = 3;
+ location_coords_s coord_list[poly_size];
+
+ coord_list[0].latitude = 10;
+ coord_list[0].longitude = 10;
+ coord_list[1].latitude = 20;
+ coord_list[1].longitude = 20;
+ coord_list[2].latitude = 30;
+ coord_list[2].longitude = 30;
+
+ location_bounds_h bounds_poly;
+ ret = location_bounds_create_polygon(coord_list, poly_size, &bounds_poly);
+ if (ret != LOCATION_BOUNDS_ERROR_NONE) {
+ printf("location_bounds_create_polygon() failed\n");
+ } else
+ printf("Bounds(polygon) has been created successfully.\n");
+
+ ret = location_manager_add_boundary(manager, bounds_poly);
+ if (ret != LOCATIONS_ERROR_NONE) {
+ printf("Setting boundary failed\n");
+ } else
+ printf("Boundary set\n");
+
+ ret = location_bounds_foreach_polygon_coords(bounds_poly, __poly_coords_cb, NULL);
+ if (ret != LOCATIONS_ERROR_NONE) {
+ printf("location_bounds_get_rect_coords() failed\n");
+ }
+
+ location_coords_s test_coords;
+ test_coords.latitude = 12;
+ test_coords.longitude = 12;
+
+ if (location_bounds_contains_coordinates(bounds_poly, test_coords))
+ printf("location_bounds_contains_coordinates() retrun TRUE \n");
+ else
+ printf("location_bounds_contains_coordinates() retrun FALSE \n");
+
+ //print current bounds
+ ret = location_manager_foreach_boundary(manager, __location_bounds_cb, (void *)manager);
+ if (ret != LOCATIONS_ERROR_NONE) {
+ printf("location_manager_foreach_boundary() failed\n");
+ }
+
+}
+
+void location_get_last_information_test()
+{
+ int ret;
+ double altitude, latitude, longitude;
+ double climb, direction, speed;
+ double horizontal, vertical;
+ location_accuracy_level_e level;
+ time_t timestamp;
+ int num_of_inview, num_of_active;
+
+ ret = location_manager_get_last_position(manager, &altitude, &latitude, &longitude, &timestamp);
+ if (ret != LOCATIONS_ERROR_NONE) {
+ printf(" Fail : location_manager_get_last_position ---> %d \n", ret);
+ } else {
+ printf("[%ld] alt: %g, lat: %g, long: %g\n", timestamp, altitude, latitude, longitude);
+ }
+
+ ret = location_manager_get_last_velocity(manager, &climb, &direction, &speed, &timestamp);
+ if (ret != LOCATIONS_ERROR_NONE) {
+ printf(" Fail : location_manager_get_last_velocity ---> %d \n", ret);
+ } else {
+ printf("climb: %f, direction: %f, speed: %f\n", climb, direction, speed);
+ }
+
+ ret = location_manager_get_last_accuracy(manager, &level, &horizontal, &vertical);
+ if (ret != LOCATIONS_ERROR_NONE) {
+ printf(" Fail : location_manager_get_last_accuracy ---> %d \n", ret);
+ } else {
+ printf("Level : %d, horizontal: %g, vertical : %g\n", level, horizontal, vertical);
+ }
+
+ ret = gps_status_get_last_satellite(manager, &num_of_active, &num_of_inview, &timestamp);
+ if (ret != LOCATIONS_ERROR_NONE) {
+ printf(" Fail : gps_status_get_last_satellite_count_in_view ---> %d \n", ret);
+ } else {
+ printf("[%ld] Satellite number of active : %d, in view : %d\n", timestamp, num_of_active, num_of_inview);
+ }
+
+ ret = gps_status_foreach_last_satellites_in_view(manager, last_satellites_foreach_cb, NULL);
+ if (ret != LOCATIONS_ERROR_NONE) {
+ printf(" Fail : gps_status_foreach_last_satellites_in_view ---> %d \n", ret);
+ }
+}
+
+int location_test()
+{
+ int ret;
+ ret = location_manager_create(LOCATIONS_METHOD_GPS, &manager);
+ printf("create : %d\n", ret);
+
+ location_bounds_test();
+ location_get_last_information_test();
+
+ //set zone changed callback
+ ret = location_manager_set_zone_changed_cb(manager, zone_event_cb, (void *)manager);
+ printf("set zone callback : %d\n", ret);
+
+ ret = location_manager_set_service_state_changed_cb(manager, _state_change_cb, (void *)manager);
+ printf("set state callback : %d\n", ret);
+
+ ret = location_manager_start(manager);
+ printf("start : %d\n", ret);
+ return 1;
+}
+
+static GMainLoop *g_mainloop = NULL;
+
+static gboolean exit_program(gpointer data)
+{
+ if (manager == NULL) {
+ printf("manager == NULL \n");
+ } else {
+ int ret = location_manager_stop(manager);
+ printf("stop : %d\n", ret);
+ ret = location_manager_destroy(manager);
+ printf("destroy : %d\n", ret);
+ }
+ g_main_loop_quit(g_mainloop);
+ printf("Quit g_main_loop\n");
+ return FALSE;
+}
+
+int main(int argc, char **argv)
+{
+ g_setenv("PKG_NAME", "com.samsung.location-test", 1);
+ g_mainloop = g_main_loop_new(NULL, 0);
+ location_test();
+ g_timeout_add_seconds(90, exit_program, NULL);
+ g_main_loop_run(g_mainloop);
+ return 0;
+}