diff options
author | Genie Kim <daejins.kim@samsung.com> | 2013-05-09 23:17:13 +0900 |
---|---|---|
committer | Genie Kim <daejins.kim@samsung.com> | 2013-05-09 23:24:54 +0900 |
commit | c185ca2a93846452978cf9dd3ff2a35847b8b0d4 (patch) | |
tree | 62cb25de43a219332b5c5fffba8d23ab136674c7 | |
parent | 8ce8597f3f6a930c319cdbe81c670b24f53f581d (diff) | |
download | geocoder-tizen_2.1.tar.gz geocoder-tizen_2.1.tar.bz2 geocoder-tizen_2.1.zip |
sync PRIVATE and RSA for tizen2.1submit/tizen_2.2/20130714.143824submit/tizen_2.2/20130714.135117submit/tizen_2.1/20130514.0519282.2_releasetizen_2.1
Change-Id: I22dd75823fc979a2f807cb3b31c5ac2ec1c2645c
-rwxr-xr-x | CMakeLists.txt | 3 | ||||
-rw-r--r-- | include/geocoder.h | 240 | ||||
-rw-r--r-- | include/geocoder_private.h | 39 | ||||
-rwxr-xr-x | packaging/capi-location-geocoder.spec | 4 | ||||
-rw-r--r-- | src/geocoder.c | 248 | ||||
-rwxr-xr-x | test/geocoder_test.c | 47 |
6 files changed, 507 insertions, 74 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index de90ae5..af76580 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,7 +18,7 @@ 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 "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fvisibility=hidden -fPIC -Wall -Werror") SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") IF("${ARCH}" STREQUAL "arm") @@ -26,6 +26,7 @@ IF("${ARCH}" STREQUAL "arm") ENDIF("${ARCH}" STREQUAL "arm") ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") +ADD_DEFINITIONS("-DEXPORT_API=__attribute__((visibility(\"default\")))") ADD_DEFINITIONS("-DTIZEN_DEBUG") SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=/usr/lib") diff --git a/include/geocoder.h b/include/geocoder.h index 701d828..d418e77 100644 --- a/include/geocoder.h +++ b/include/geocoder.h @@ -1,18 +1,18 @@ /* -* 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. -*/ + * Copyright (c) 2011-2013 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_GEOCODER_H__ #define __TIZEN_LOCATION_GEOCODER_H__ @@ -34,6 +34,7 @@ extern "C" { * @brief The geocoder handle */ typedef struct geocoder_s *geocoder_h; +typedef struct geocoder_preference_s *geocoder_preference_h; /** @@ -48,6 +49,7 @@ typedef enum GEOCODER_ERROR_NETWORK_FAILED = TIZEN_ERROR_LOCATION_CLASS | 0x02, /**< Network unavailable*/ GEOCODER_ERROR_SERVICE_NOT_AVAILABLE = TIZEN_ERROR_LOCATION_CLASS | 0x03, /**< Service unavailable */ GEOCODER_ERROR_NOT_FOUND = TIZEN_ERROR_LOCATION_CLASS | 0x04, /**< Result not found */ + GEOCODER_ERROR_INVALID_KEY = TIZEN_ERROR_LOCATION_CLASS | 0x05, /**< Invalid key */ } geocoder_error_e; /** @@ -81,6 +83,15 @@ typedef bool(*geocoder_get_position_cb)(geocoder_error_e result, double latitude typedef void (*geocoder_get_address_cb)(geocoder_error_e result, const char *building_number, const char *postal_code, const char *street, const char *city, const char *district, const char *state, const char *country_code, void *user_data); /** + * @brief Called once for each available keys + * @remarks @a key is valid only in this function. + * @param [in] key The key string + * @param [in] uesr_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. + */ +typedef bool (*geocoder_preference_available_key_cb)(const char *key , void *user_data); + +/** * @brief Creates a new geocoder handle. * @details * A geocoder handle can be used to change position information to address information and vice versa. @@ -144,6 +155,207 @@ int geocoder_get_address_from_position(geocoder_h geocoder, double latitude, dou int geocoder_foreach_positions_from_address(geocoder_h geocoder, const char *address, geocoder_get_position_cb callback, void *user_data); /** + * @brief Called once for each position information converted from the given address information. + * @param[in] result The result of request + * @param[in] request_id The id of request + * @param[in] index The current index of request + * @param[in] total_count The total number of request + * @param[in] latitude The latitude [-90.0 ~ 90.0] (degrees) + * @param[in] longitude The longitude [-180.0 ~ 180.0] (degrees) + * @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 geocoder_geocode() will invoke this callback. + * @see geocoder_geocode() + */ +typedef void (*geocoder_get_geocode_cb)(geocoder_error_e result, int request_id, int index, int total_count, double latitude, double longitude, void *user_data); + +/** + * @brief Called when the address information has converted from position information. + * @remarks You should not free all string values. + * @param[in] result The result of request + * @param[in] request_id The id of request + * @param[in] index The current index of request + * @param[in] total_count The total number of request + * @param[in] building_number The building number + * @param[in] postal_code The postal delivery code + * @param[in] street The full street name + * @param[in] city The city name + * @param[in] district The municipal district name + * @param[in] state The state or province region of a nation + * @param[in] country_code The country code + * @param[in] country The country + * @param[in] county The county + * @param[in] text The description + * @param[in] user_data The user data passed from the foreach function + * @pre geocoder_reverse_geocode() will invoke this callback. + * @see geocoder_reverse_geocode() + */ +typedef void (*geocoder_get_reverse_geocode_cb)(geocoder_error_e result, int request_id, int index, int total_count, const char *building_number, const char *postal_code, const char *street, const char *city, const char *district, const char *state, const char *country_code, const char *country, const char *county, const char *text, void *user_data); + +/** + * @brief Gets the positions for a given address, asynchronously. + * @details This function gets positions for a given free-formed address string. + * @remarks This function requires network access. + * @param[in] geocoder The geocoder handle + * @param[in] address The free-formed address + * @param[in] callback The geocoder get positions callback function + * @param[in] user_data The user data to be passed to the callback function + * @param[out] request_id The id of request + * @return 0 on success, otherwise a negative error value. + * @retval #GEOCODER_ERROR_NONE Successful + * @retval #GEOCODER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #GEOCODER_ERROR_NETWORK_FAILED Network connection failed + * @retval #GEOCODER_ERROR_SERVICE_NOT_AVAILABLE Service not available + * @post It invokes geocoder_get_geocode_cb() to get changes in position. + * @see geocoder_get_geocode_cb() + * @see geocoder_reverse_geocode() + */ +int geocoder_geocode(geocoder_h geocoder, const char *address, geocoder_get_geocode_cb callback, void *user_data, int *request_id); + +/** + * @brief Gets the address for a given position, asynchronously. + * @remarks This function requires network access. + * @param[in] geocoder The geocoder handle + * @param[in] latitude The latitude [-90.0 ~ 90.0] (degrees) + * @param[in] longitude The longitude [-180.0 ~ 180.0] (degrees) + * @param[in] callback The callback which will receive address information + * @param[in] user_data The user data to be passed to the callback function + * @param[out] request_id The id of request + * @return 0 on success, otherwise a negative error value. + * @retval #GEOCODER_ERROR_NONE Successful + * @retval #GEOCODER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #GEOCODER_ERROR_NETWORK_FAILED Network connection failed + * @retval #GEOCODER_ERROR_SERVICE_NOT_AVAILABLE Service not available + * @post This function invokes geocoder_get_reverse_geocode_cb(). + * @see geocoder_get_reverse_geocode_cb() + * @see geocoder_geocode() + */ +int geocoder_reverse_geocode(geocoder_h geocoder, double latitude, double longitude, geocoder_get_reverse_geocode_cb callback, void *user_data, int *request_id); + +/** + * @brief Cancels the reuqest. + * @remarks This function requires network access. + * @param[in] geocoder The geocoder handle + * @param[in] request_id The id of request + * @return 0 on success, otherwise a negative error value. + * @retval #GEOCODER_ERROR_NONE Successful + * @retval #GEOCODER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #GEOCODER_ERROR_NETWORK_FAILED Network connection failed + * @retval #GEOCODER_ERROR_SERVICE_NOT_AVAILABLE Service not available + * @see geocoder_reverse_geocode() + * @see geocoder_geocode() + */ +int geocoder_cancel(geocoder_h geocoder, int request_id); + + +/** + * @brief Creates a new geocoder preference handle. + * @remarks @a preference must be released geocoder_preference_destroy() by you. + * @param[out] preference A handle of a new geocoder preference handle on success + * @return 0 on success, otherwise a negative error value. + * @retval #GEOCODER_ERROR_NONE Successful + * @retval #GEOCODER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #GEOCODER_ERROR_NETWORK_FAILED Network connection failed + * @retval #GEOCODER_ERROR_SERVICE_NOT_AVAILABLE Service not available + * @see geocoder_preference_destroy() + */ +int geocoder_preference_create (geocoder_preference_h *preference); + +/** + * @brief Destroys the geocoder preference handle and releases all its resources. + * @param[in] preference The geocoder preference handle to destroy + * @return 0 on success, otherwise a negative error value. + * @retval #GEOCODER_ERROR_NONE Successful + * @retval #GEOCODER_ERROR_INVALID_PARAMETER Invalid parameter + * @see geocoder_preference_create() + */ +int geocoder_preference_destroy (geocoder_preference_h preference); + +/** + * @brief Gets the preference value + * @remarks @a value must be released @c free() by you. + * @param[in] preference The geocoder preference handle + * @param[in] key The key of preference + * @param[out] value The preference value + * @return 0 on success, otherwise a negative error value. + * @retval #GEOCODER_ERROR_NONE Successful + * @retval #GEOCODER_ERROR_INVALID_PARAMETER Invalid parameter + * @see geocoder_preference_set() + */ +int geocoder_preference_get(geocoder_preference_h preference, const char *key, char **value); + +/** + * @brief Sets the preference value + * @param[in] preference The geocoder preference handle + * @param[in] key The key of preference + * @param[in] value The preference value to set, could be NULL if want to remove value + * @return 0 on success, otherwise a negative error value. + * @retval #GEOCODER_ERROR_NONE Successful + * @retval #GEOCODER_ERROR_INVALID_PARAMETER Invalid parameter + * @see geocoder_preference_get() + */ +int geocoder_preference_set(geocoder_preference_h preference, const char *key, const char *value); + +/** + * @brief Gets the number of maximum result + * @param[in] preference The geocoder preference handle + * @param[out] max_result The number of maximum result + * @return 0 on success, otherwise a negative error value. + * @retval #GEOCODER_ERROR_NONE Successful + * @retval #GEOCODER_ERROR_INVALID_PARAMETER Invalid parameter + * @see geocoder_preference_set_max_result() + */ +int geocoder_preference_get_max_result(geocoder_preference_h preference, int *max_result); + +/** + * @brief Sets the number of maximum result + * @param[in] preference The geocoder preference handle + * @param[in] max_result The number of maximum result + * @return 0 on success, otherwise a negative error value. + * @retval #GEOCODER_ERROR_NONE Successful + * @retval #GEOCODER_ERROR_INVALID_PARAMETER Invalid parameter + * @see geocoder_preference_get_max_result() + */ +int geocoder_preference_set_max_result(geocoder_preference_h preference, int max_result); + +/** + * @brief Retrieves all available preference keys + * @param[in] preference The geocoder preference handle + * @param[in] key The key of preference + * @param[out] value The preference value + * @return 0 on success, otherwise a negative error value. + * @retval #GEOCODER_ERROR_NONE Successful + * @retval #GEOCODER_ERROR_INVALID_PARAMETER Invalid parameter + * @see geocoder_preference_set() + * @see geocoder_preference_get() + */ +int geocoder_preference_foreach_available_keys(geocoder_h geocoder, geocoder_preference_available_key_cb callback , void * user_data); + +/** + * @brief Gets the geocoder preference + * @param[in] geocoder The geocoder handle + * @param[out] preference The geocoder preference handle + * @return 0 on success, otherwise a negative error value. + * @retval #GEOCODER_ERROR_NONE Successful + * @retval #GEOCODER_ERROR_INVALID_PARAMETER Invalid parameter + * @see geocoder_service_set_preference() + */ +int geocoder_service_get_preference(geocoder_h geocoder, geocoder_preference_h *preference); + +/** + * @brief Sets the geocoder preference + * @param[in] geocoder The geocoder handle + * @param[in] preference The geocoder preference handle + * @return 0 on success, otherwise a negative error value. + * @retval #GEOCODER_ERROR_NONE Successful + * @retval #GEOCODER_ERROR_INVALID_PARAMETER Invalid parameter + * @see geocoder_service_get_preference() + */ +int geocoder_service_set_preference(geocoder_h geocoder, geocoder_preference_h preference); + + + +/** * @} */ diff --git a/include/geocoder_private.h b/include/geocoder_private.h index cc41787..72eb732 100644 --- a/include/geocoder_private.h +++ b/include/geocoder_private.h @@ -1,18 +1,18 @@ /* -* 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. -*/ + * Copyright (c) 2011-2013 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_GEOCODER_PRIVATE_H__ #define __TIZEN_LOCATION_GEOCODER_PRIVATE_H__ @@ -47,6 +47,12 @@ #define GEOCODER_NULL_ARG_CHECK(arg) \ GEOCODER_CHECK_CONDITION(arg != NULL,GEOCODER_ERROR_INVALID_PARAMETER,"GEOCODER_ERROR_INVALID_PARAMETER") +#define GEOCODER_PRINT_ERROR_CODE_RETURN(code) \ + do{ \ + GEOCODER_LOGE("%s(0x%08x)", #code, code); \ + return code; \ + } while (0) + #ifdef __cplusplus extern "C" { #endif @@ -60,8 +66,13 @@ typedef enum { typedef struct _geocoder_s{ LocationMapObject* object; + geocoder_preference_h preference; } geocoder_s; +typedef struct _geocoder_preference_s{ + LocationGeocodePreference *pref; +} geocoder_preference_s; + #ifdef __cplusplus } #endif diff --git a/packaging/capi-location-geocoder.spec b/packaging/capi-location-geocoder.spec index d5658b2..30cb36c 100755 --- a/packaging/capi-location-geocoder.spec +++ b/packaging/capi-location-geocoder.spec @@ -1,6 +1,6 @@ Name: capi-location-geocoder Summary: A Geocoder library in Tizen Native API -Version: 0.1.1 +Version: 0.1.2 Release: 1 Group: System/Libraries License: Apache License, Version 2.0 @@ -30,7 +30,7 @@ Requires: %{name} = %{version}-%{release} %build MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` -cmake . -DCMAKE_INSTALL_PREFIX=/usr -DFULLVER=%{version} -DMAJORVER=${MAJORVER} +%cmake . -DFULLVER=%{version} -DMAJORVER=${MAJORVER} make %{?jobs:-j%jobs} diff --git a/src/geocoder.c b/src/geocoder.c index e0e5c03..e4e07ee 100644 --- a/src/geocoder.c +++ b/src/geocoder.c @@ -1,23 +1,24 @@ /* -* 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. -*/ + * Copyright (c) 2011-2013 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 <geocoder_private.h> +#include <location-geocode.h> /* * Internal Implementation @@ -33,6 +34,18 @@ typedef struct { geocoder_get_position_cb callback; }__pos_callback_data; +typedef struct { + int request_id; + void *data; + geocoder_get_geocode_cb callback; +}__geocode_callback_data; + +typedef struct { + int request_id; + void *data; + geocoder_get_reverse_geocode_cb callback; +}__reverse_geocode_callback_data; + static int __convert_error_code(int code) { int ret; @@ -121,7 +134,7 @@ static void __cb_position_from_address (LocationError error, GList *position_lis /* * Public Implementation */ -int geocoder_create(geocoder_h* geocoder) +EXPORT_API int geocoder_create(geocoder_h* geocoder) { GEOCODER_NULL_ARG_CHECK(geocoder); if(location_init()!=LOCATION_ERROR_NONE) @@ -139,6 +152,10 @@ int geocoder_create(geocoder_h* geocoder) memset(handle, 0 , sizeof(geocoder_s)); + if( GEOCODER_ERROR_NONE != geocoder_preference_create(&handle->preference ) ){ + free(handle); + GEOCODER_PRINT_ERROR_CODE_RETURN(GEOCODER_ERROR_OUT_OF_MEMORY); + } handle->object = location_map_new(NULL); if(handle->object == NULL) { @@ -151,7 +168,7 @@ int geocoder_create(geocoder_h* geocoder) return GEOCODER_ERROR_NONE; } -int geocoder_destroy(geocoder_h geocoder) +EXPORT_API int geocoder_destroy(geocoder_h geocoder) { GEOCODER_NULL_ARG_CHECK(geocoder); geocoder_s *handle = (geocoder_s*)geocoder; @@ -165,8 +182,9 @@ int geocoder_destroy(geocoder_h geocoder) return GEOCODER_ERROR_NONE; } -int geocoder_get_address_from_position(geocoder_h geocoder, double latitude, double longitude, geocoder_get_address_cb callback, void *user_data) +EXPORT_API int geocoder_get_address_from_position(geocoder_h geocoder, double latitude, double longitude, geocoder_get_address_cb callback, void *user_data) { + unsigned int reqid;//Need to check whether we need to change the parameter of the API. GEOCODER_NULL_ARG_CHECK(geocoder); GEOCODER_NULL_ARG_CHECK(callback); GEOCODER_CHECK_CONDITION(latitude>=-90 && latitude<=90 ,GEOCODER_ERROR_INVALID_PARAMETER,"GEOCODER_ERROR_INVALID_PARAMETER"); @@ -186,7 +204,7 @@ int geocoder_get_address_from_position(geocoder_h geocoder, double latitude, dou calldata->callback = callback; calldata->data = user_data; - ret = location_map_get_address_from_position_async(handle->object, pos, __cb_address_from_position, calldata); + ret = location_map_get_address_from_position_async(handle->object, pos, __cb_address_from_position, calldata,&reqid); location_position_free(pos); if( ret != LOCATION_ERROR_NONE) { @@ -196,13 +214,15 @@ int geocoder_get_address_from_position(geocoder_h geocoder, double latitude, dou return GEOCODER_ERROR_NONE; } -int geocoder_foreach_positions_from_address(geocoder_h geocoder,const char* address, geocoder_get_position_cb callback, void *user_data) +EXPORT_API int geocoder_foreach_positions_from_address(geocoder_h geocoder,const char* address, geocoder_get_position_cb callback, void *user_data) { + unsigned int reqid;//Need to check whether we need to change the parameter of the API. + int ret; GEOCODER_NULL_ARG_CHECK(geocoder); GEOCODER_NULL_ARG_CHECK(address); GEOCODER_NULL_ARG_CHECK(callback); - geocoder_s *handle = (geocoder_s*)geocoder; + geocoder_s *handle = (geocoder_s*)geocoder; char* addr_str = g_strdup(address); __pos_callback_data * calldata = (__pos_callback_data *)malloc(sizeof(__pos_callback_data)); @@ -214,8 +234,7 @@ int geocoder_foreach_positions_from_address(geocoder_h geocoder,const char* add calldata->callback = callback; calldata->data = user_data; - int ret; - ret = location_map_get_position_from_freeformed_address_async(handle->object, addr_str,__cb_position_from_address, calldata); + ret = location_map_get_position_from_freeformed_address_async(handle->object, addr_str, (LocationGeocodePreference *)handle->preference, __cb_position_from_address, calldata,&reqid); g_free(addr_str); if( ret != LOCATION_ERROR_NONE) { @@ -223,3 +242,188 @@ int geocoder_foreach_positions_from_address(geocoder_h geocoder,const char* add } return GEOCODER_ERROR_NONE; } + +EXPORT_API int +geocoder_geocode(geocoder_h geocoder, const char *address, geocoder_get_geocode_cb callback, void *user_data, int *request_id) +{ + GEOCODER_NULL_ARG_CHECK(geocoder); + GEOCODER_NULL_ARG_CHECK(callback); + + unsigned int reqid; + int ret; + geocoder_s *handle = (geocoder_s*)geocoder; + + __geocode_callback_data * calldata = (__geocode_callback_data *)malloc(sizeof(__geocode_callback_data)); + if( calldata == NULL) + GEOCODER_PRINT_ERROR_CODE_RETURN(GEOCODER_ERROR_OUT_OF_MEMORY); + + calldata->callback = callback; + calldata->data = user_data; + + ret = location_map_get_position_from_freeformed_address_async(handle->object , address, (LocationGeocodePreference *)handle->preference, __cb_position_from_address, calldata, &reqid); + + if( ret != 0 ){ + free(calldata); + return __convert_error_code(ret); + } + + if( request_id ) + *request_id = reqid; + return GEOCODER_ERROR_NONE; +} + +EXPORT_API int geocoder_reverse_geocode(geocoder_h geocoder, double latitude, double longitude, geocoder_get_reverse_geocode_cb callback, void *user_data, int *request_id) +{ + GEOCODER_NULL_ARG_CHECK(geocoder); + GEOCODER_NULL_ARG_CHECK(callback); + GEOCODER_CHECK_CONDITION(latitude>=-90 && latitude<=90 ,GEOCODER_ERROR_INVALID_PARAMETER,"GEOCODER_ERROR_INVALID_PARAMETER"); + GEOCODER_CHECK_CONDITION(longitude>=-180 && longitude<=180,GEOCODER_ERROR_INVALID_PARAMETER,"GEOCODER_ERROR_INVALID_PARAMETER"); + + + unsigned int reqid; + int ret; + geocoder_s *handle = (geocoder_s*)geocoder; + + LocationPosition *pos = NULL; + pos = location_position_new (0, latitude, longitude, 0, LOCATION_STATUS_2D_FIX); + + __reverse_geocode_callback_data * calldata = (__reverse_geocode_callback_data *)malloc(sizeof(__reverse_geocode_callback_data)); + if( calldata == NULL) + GEOCODER_PRINT_ERROR_CODE_RETURN(GEOCODER_ERROR_OUT_OF_MEMORY); + + calldata->callback = callback; + calldata->data = user_data; + + ret = location_map_get_address_from_position_async(handle->object,pos ,__cb_address_from_position, calldata, &reqid); + + location_position_free(pos); + if( ret != 0 ){ + free(calldata); + return __convert_error_code(ret); + } + + if( request_id ) + *request_id = reqid; + return GEOCODER_ERROR_NONE; +} + +EXPORT_API int geocoder_cancel(geocoder_h geocoder, int request_id) +{ + GEOCODER_NULL_ARG_CHECK(geocoder); + + geocoder_s *handle = (geocoder_s*)geocoder; + return __convert_error_code(location_map_cancel_geocode_request(handle->object, request_id)); + +} + +EXPORT_API int geocoder_preference_create (geocoder_preference_h *preference) +{ + GEOCODER_NULL_ARG_CHECK(preference); + LocationGeocodePreference *pref; + pref = location_geocode_pref_new(); + if( pref == NULL) + GEOCODER_PRINT_ERROR_CODE_RETURN(GEOCODER_ERROR_OUT_OF_MEMORY); + *preference = (geocoder_preference_h)pref; + + return GEOCODER_ERROR_NONE; +} + +EXPORT_API int geocoder_preference_destroy (geocoder_preference_h preference) +{ + GEOCODER_NULL_ARG_CHECK(preference); + location_geocode_pref_free((LocationGeocodePreference*)preference); + return GEOCODER_ERROR_NONE; +} + +EXPORT_API int geocoder_preference_get(geocoder_preference_h preference, const char *key, char **value) +{ + GEOCODER_NULL_ARG_CHECK(preference); + GEOCODER_NULL_ARG_CHECK(key); + GEOCODER_NULL_ARG_CHECK(value); + char *v = (char*)location_geocode_pref_get_property((LocationGeocodePreference*)preference, key); + if( v == NULL ) + GEOCODER_PRINT_ERROR_CODE_RETURN(GEOCODER_ERROR_INVALID_KEY); + *value = strdup(v); + return GEOCODER_ERROR_NONE; +} + +EXPORT_API int geocoder_preference_set(geocoder_preference_h preference, const char *key, const char *value) +{ + GEOCODER_NULL_ARG_CHECK(preference); + GEOCODER_NULL_ARG_CHECK(key); + + int ret = location_geocode_pref_set_property((LocationGeocodePreference*)preference,key, value); + if( !ret ) + GEOCODER_PRINT_ERROR_CODE_RETURN(GEOCODER_ERROR_INVALID_KEY); + return GEOCODER_ERROR_NONE; +} + +EXPORT_API int geocoder_preference_get_max_result(geocoder_preference_h preference, int *max_result) +{ + GEOCODER_NULL_ARG_CHECK(preference); + GEOCODER_NULL_ARG_CHECK(max_result); + int ret = location_geocode_pref_get_max_result((LocationGeocodePreference*)preference ); + if( ret == 0 ) + GEOCODER_PRINT_ERROR_CODE_RETURN(GEOCODER_ERROR_INVALID_PARAMETER); + *max_result = ret; + return GEOCODER_ERROR_NONE; +} + +EXPORT_API int geocoder_preference_set_max_result(geocoder_preference_h preference, int max_result) +{ + GEOCODER_NULL_ARG_CHECK(preference); + GEOCODER_CHECK_CONDITION(max_result >= 0 , GEOCODER_ERROR_INVALID_PARAMETER, "max count value is negative"); + int ret = location_geocode_pref_set_max_result((LocationGeocodePreference*)preference, max_result); + if( !ret ) + GEOCODER_PRINT_ERROR_CODE_RETURN(GEOCODER_ERROR_INVALID_PARAMETER); + return GEOCODER_ERROR_NONE; +} + +EXPORT_API int geocoder_preference_foreach_available_keys(geocoder_h geocoder, geocoder_preference_available_key_cb callback , void * user_data) +{ + GEOCODER_NULL_ARG_CHECK(geocoder); + GEOCODER_NULL_ARG_CHECK(callback); + + geocoder_s *handle = (geocoder_s*)geocoder; + + GList *keys=NULL; + location_map_get_provider_capability_key(handle->object, MAP_SERVICE_GEOCODE_PREF_PROPERTY, &keys); + if( keys == NULL ) + return GEOCODER_ERROR_NOT_FOUND; + + while(keys){ + char *key = keys->data; + if( !callback(key,user_data) ) + break; + keys = keys->next; + } + g_list_free_full (keys, g_free); + return GEOCODER_ERROR_SERVICE_NOT_AVAILABLE; +} + +EXPORT_API int geocoder_service_get_preference(geocoder_h geocoder, geocoder_preference_h *preference) +{ + GEOCODER_NULL_ARG_CHECK(geocoder); + GEOCODER_NULL_ARG_CHECK(preference); + geocoder_s *handle = (geocoder_s*)geocoder; + + if( handle->preference == NULL ){ + geocoder_preference_create(&handle->preference ); + } + *preference = (geocoder_preference_h)location_geocode_pref_copy((LocationGeocodePreference*)handle->preference); + return GEOCODER_ERROR_SERVICE_NOT_AVAILABLE; +} + +EXPORT_API int geocoder_service_set_preference(geocoder_h geocoder, geocoder_preference_h preference) +{ + GEOCODER_NULL_ARG_CHECK(geocoder); + GEOCODER_NULL_ARG_CHECK(preference); + + geocoder_s *handle = (geocoder_s*)geocoder; + + if( handle->preference ){ + geocoder_preference_destroy(handle->preference); + handle->preference = (geocoder_preference_h)location_geocode_pref_copy((LocationGeocodePreference*)preference); + } + return GEOCODER_ERROR_SERVICE_NOT_AVAILABLE; +} diff --git a/test/geocoder_test.c b/test/geocoder_test.c index 12c21a6..5f73854 100755 --- a/test/geocoder_test.c +++ b/test/geocoder_test.c @@ -1,24 +1,24 @@ /* -* 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. -*/ + * Copyright (c) 2011-2013 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 <geocoder.h> +#include <geocoder.h> geocoder_h geocoder; @@ -36,13 +36,12 @@ static bool get_pos_cb(geocoder_error_e result, double latitude, double longitu int geocoder_test() { int ret; - if (geocoder ==NULL) + geocoder_preference_h pref; + int maxcnt; + ret = geocoder_create(&geocoder); + if (ret != GEOCODER_ERROR_NONE || geocoder == NULL) { - ret = geocoder_create(&geocoder); - if(ret != GEOCODER_ERROR_NONE) - { - printf ("geocoder_create return error : %d=n", ret); - } + printf ("geocoder_create return error : %d\n", ret); } ret = geocoder_get_address_from_position(geocoder,37.258,127.056,get_addr_cb, NULL); @@ -50,6 +49,12 @@ int geocoder_test() { printf ("geocoder_get_address_from_position return error : %d\n", ret); } + geocoder_preference_create(&pref); + geocoder_preference_set_max_result(pref, 3); + geocoder_preference_get_max_result(pref, &maxcnt); + printf ("max cnt value set %d \n",maxcnt); + geocoder_service_set_preference(geocoder, pref); + geocoder_preference_destroy(pref); return 1; } |