From 3c4bfee243562baee1e4ae7c8fff9063699f0da9 Mon Sep 17 00:00:00 2001 From: "kj7.sung" Date: Thu, 19 Nov 2015 12:21:31 +0900 Subject: [PATCH] [ACR-443] Added multi_reverse_geocode API Change-Id: Ie37423cf45dcc39e390cb3b1585c3b812b422ca1 Signed-off-by: kj7.sung --- include/maps_plugin.h | 41 ++++++++++++++ include/maps_preference.h | 4 -- include/maps_service.h | 86 +++++++++++++++++++++++++++- packaging/capi-maps-service.spec | 2 +- src/api/maps_service.cpp | 27 ++++++++- src/plugin/empty_module.cpp | 9 +++ src/plugin/module.cpp | 5 ++ src/plugin/module.h | 5 ++ src/session/commands.cpp | 111 +++++++++++++++++++++++++++++++++++++ src/session/commands.h | 72 ++++++++++++++++++++++++ test/dummy_plugin/dummy_plugin.cpp | 1 + 11 files changed, 356 insertions(+), 7 deletions(-) diff --git a/include/maps_plugin.h b/include/maps_plugin.h index dfef0d5..ae61174 100755 --- a/include/maps_plugin.h +++ b/include/maps_plugin.h @@ -413,6 +413,47 @@ int maps_plugin_reverse_geocode(double latitude, double longitude, maps_service_reverse_geocode_cb callback, void *user_data, int *request_id); +/** + * @brief Gets the address list for a given position coordinates list. + * @details This function obtains structured address information for a given + * position coordinates. + * @since_tizen 3.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/mapservice + * @remarks This function requires network access. + * \n To cancel the request use maps_plugin_cancel_request(). + * \n To check if Maps Provider is capable of Reverse Geocoding and which + * Reverse Geocode preferences are supported see the lists of capacities and + * preferences above. + * + * @param[in] geocode_list The position coordinates list + * @param[in] preference The set of preferences for processing Reverse Geocode + * @param[in] callback The callback which will receive address informations + * @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 #MAPS_ERROR_NONE Successful + * @retval #MAPS_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MAPS_ERROR_NETWORK_UNREACHABLE Network connection failed + * @retval #MAPS_ERROR_SERVICE_NOT_AVAILABLE Service not available + * @retval #MAPS_ERROR_PERMISSION_DENIED Permission Denied + * @retval #MAPS_ERROR_NOT_SUPPORTED Not supported + * @retval #MAPS_ERROR_CONNECTION_TIME_OUT Timeout error, no answer + * @retval #MAPS_ERROR_INVALID_OPERATION Operation is not valid + * @retval #MAPS_ERROR_NOT_FOUND Result not found + * @retval #MAPS_ERROR_KEY_NOT_AVAILABLE Invalid key + * @retval #MAPS_ERROR_UNKNOWN Unknown error + * + * @post This function invokes maps_service_multi_reverse_geocode_cb(). + * + * @see maps_service_multi_reverse_geocode_cb() + * @see maps_plugin_cancel_request() + */ +int maps_plugin_multi_reverse_geocode(const maps_coordinates_list_h geocode_list, + const maps_preference_h preference, maps_service_multi_reverse_geocode_cb callback, + void *user_data, int *request_id); + + /*----------------------------------------------------------------------------*/ /* * Place diff --git a/include/maps_preference.h b/include/maps_preference.h index fe16a51..c5bddab 100644 --- a/include/maps_preference.h +++ b/include/maps_preference.h @@ -34,10 +34,6 @@ extern "C" { * @{ * @brief This provides enumerations of Maps API preferences -* - - - - - - - - - - - - - -* -* Preference key names -* -------------------- * * The Preferences are organized as a key-value table where available Preference * keys are following strings: diff --git a/include/maps_service.h b/include/maps_service.h index e262465..088e7cf 100644 --- a/include/maps_service.h +++ b/include/maps_service.h @@ -85,8 +85,10 @@ typedef enum _maps_service_e { MAPS_SERVICE_SEARCH_ROUTE_WAYPOINTS, /**< Indicates that maps_service_search_route_waypoints() service is allowed */ - MAPS_SERVICE_CANCEL_REQUEST /**< Indicates that + MAPS_SERVICE_CANCEL_REQUEST, /**< Indicates that maps_service_cancel_request() service is allowed */ + MAPS_SERVICE_MULTI_REVERSE_GEOCODE /**< Indicates that + maps_service_multi_reverse_geocode() service is allowed (Since 3.0)*/ } maps_service_e; /** @@ -775,6 +777,88 @@ int maps_service_reverse_geocode(const maps_service_h maps, double latitude, maps_service_reverse_geocode_cb callback, void *user_data, int *request_id); + +/** + * @brief Called when responsed the request of multi reverse geocoding. + * @details The Maps Service invokes this callback once when gets the response + * from map service provider. + * \n The value of @a total is same with requested coordinates list size. + * Even though one of address is not provided valid address handle is retrieved. + * @since_tizen 3.0 + * @remarks You can get the respective address information of @a address_list + * using maps_address_list_foreach(). + * + * @param[in] result The result of request + * @param[in] request_id The id of request + * @param[in] total The total number of results + * @param[in] address_list The converted address list from the + * requested coordinates list + * @param[in] user_data The user data pointer passed from + * maps_service_multi_reverse_geocode() + * @return @c true to continue with the next iteration of the loop, \n @c + * false to break out of the loop + * + * @pre maps_service_multi_reverse_geocode() will invoke this callback. + * + * @see maps_service_multi_reverse_geocode() + * @see maps_address_list_foreach() + * @see maps_service_cancel_request() + */ +typedef bool (*maps_service_multi_reverse_geocode_cb) (maps_error_e result, + int request_id, + int total, + maps_address_list_h address_list, + void *user_data); + +/** + * @brief Gets the address list for a given position coordinates list. + * \n The request is asynchronous. + * @details This function obtains structured address information. + * @since_tizen 3.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/mapservice \n + * %http://tizen.org/privilege/internet \n + * %http://tizen.org/privilege/network.get + * @remarks %http://tizen.org/privilege/internet is needed to access internet. + * \n To cancel the request use maps_service_cancel_request(). + * \n To check if Maps Provider is capable of Multi Reverse Geocoding use + * maps_service_provider_is_service_supported() with + * #MAPS_SERVICE_MULTI_REVERSE_GEOCODE passed as @a service parameter. + * + * @param[in] maps The Maps Service handle + * @param[in] coordinates_list The coordinates list [2 ~ 100] (a set of coordinates) + * @param[in] preference The set of preferences for processing Reverse + * Geocode + * @param[in] callback The callback which will retrieve address list + * @param[in] user_data The user data pointer to be passed to the + * callback + * @param[out] request_id The id of request + * @return 0 on success, otherwise a negative error value + * @retval #MAPS_ERROR_NONE Successful + * @retval #MAPS_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MAPS_ERROR_NETWORK_UNREACHABLE Network connection failed + * @retval #MAPS_ERROR_SERVICE_NOT_AVAILABLE Service not available + * @retval #MAPS_ERROR_PERMISSION_DENIED Permission Denied + * @retval #MAPS_ERROR_NOT_SUPPORTED Not supported + * @retval #MAPS_ERROR_CONNECTION_TIME_OUT Timeout error, no answer + * @retval #MAPS_ERROR_INVALID_OPERATION Operation is not valid + * @retval #MAPS_ERROR_NOT_FOUND Result not found + * @retval #MAPS_ERROR_KEY_NOT_AVAILABLE Invalid key + * @retval #MAPS_ERROR_UNKNOWN Unknown error + * + * @pre Call maps_service_create() to create Maps Service and obtain its handle. + * @post This function invokes maps_service_multi_reverse_geocode_cb(). + * + * @see maps_service_multi_reverse_geocode_cb() + * @see maps_service_cancel_request() + * @see maps_service_reverse_geocode() + * @see maps_service_provider_is_service_supported() + */ +int maps_service_multi_reverse_geocode(const maps_service_h maps, + maps_coordinates_list_h coordinates_list, + const maps_preference_h preference, + maps_service_multi_reverse_geocode_cb callback, + void *user_data, int *request_id); /** * @} */ diff --git a/packaging/capi-maps-service.spec b/packaging/capi-maps-service.spec index 5525619..d3c2b16 100644 --- a/packaging/capi-maps-service.spec +++ b/packaging/capi-maps-service.spec @@ -1,6 +1,6 @@ Name: capi-maps-service Summary: Tizen Maps Service API -Version: 0.5.0 +Version: 0.5.1 Release: 1 Group: Location/API License: Apache-2.0 diff --git a/src/api/maps_service.cpp b/src/api/maps_service.cpp index 98bff4e..12afd5b 100755 --- a/src/api/maps_service.cpp +++ b/src/api/maps_service.cpp @@ -244,7 +244,7 @@ EXPORT_API int maps_service_provider_is_service_supported(const maps_service_h if (!maps || !supported) return MAPS_ERROR_INVALID_PARAMETER; if ((service < MAPS_SERVICE_GEOCODE) - || (service > MAPS_SERVICE_CANCEL_REQUEST)) + || (service > MAPS_SERVICE_MULTI_REVERSE_GEOCODE)) return MAPS_ERROR_INVALID_PARAMETER; const plugin::plugin_s *p = __extract_plugin(maps); if (!p) @@ -578,3 +578,28 @@ EXPORT_API int maps_service_cancel_request(const maps_service_h maps, return q()->push(new session::command_cancel_request(maps, request_id)); } + +/*----------------------------------------------------------------------------*/ +/* */ +/* Multi geocoder */ + +EXPORT_API int maps_service_multi_reverse_geocode(const maps_service_h maps, + const maps_coordinates_list_h coordinates_list, const maps_preference_h preference, + maps_service_multi_reverse_geocode_cb callback, void *user_data, int *request_id) +{ + if (!maps) + return MAPS_ERROR_INVALID_PARAMETER; + + if (!__maps_provider_supported(maps, MAPS_SERVICE_MULTI_REVERSE_GEOCODE)) + return MAPS_ERROR_NOT_SUPPORTED; + + if (!coordinates_list || !callback || !request_id) + return MAPS_ERROR_INVALID_PARAMETER; + + if (!__has_maps_service_privilege()) + return MAPS_ERROR_PERMISSION_DENIED; + + return q()->push(new session::command_multi_reverse_geocode(maps, + coordinates_list, preference, callback, user_data, request_id)); +} + diff --git a/src/plugin/empty_module.cpp b/src/plugin/empty_module.cpp index 4683be6..d995cf3 100755 --- a/src/plugin/empty_module.cpp +++ b/src/plugin/empty_module.cpp @@ -107,6 +107,14 @@ int maps_plugin_reverse_geocode_empty(double latitude, double longitude, return 0; } +int maps_plugin_multi_reverse_geocode_empty(const maps_coordinates_list_h maps_list, + const maps_preference_h preference, + maps_service_multi_reverse_geocode_cb callback, + void *user_data, int *request_id) +{ + return 0; +} + /* Place */ int maps_plugin_search_place_empty(const maps_coordinates_h position, int distance, @@ -185,6 +193,7 @@ plugin::interface_s empty_interface = { maps_plugin_geocode_inside_area_empty, maps_plugin_geocode_by_structured_address_empty, maps_plugin_reverse_geocode_empty, + maps_plugin_multi_reverse_geocode_empty, /* Place */ maps_plugin_search_place_empty, diff --git a/src/plugin/module.cpp b/src/plugin/module.cpp index 01a4103..830065c 100755 --- a/src/plugin/module.cpp +++ b/src/plugin/module.cpp @@ -154,6 +154,9 @@ maps_plugin_h plugin::binary_extractor::init(const provider_info &info) new_plugin->interface.maps_plugin_reverse_geocode = (maps_plugin_reverse_geocode_f) gmod_find_sym(plugin, "maps_plugin_reverse_geocode"); + new_plugin->interface.maps_plugin_multi_reverse_geocode = + (maps_plugin_multi_reverse_geocode_f) + gmod_find_sym(plugin, "maps_plugin_multi_reverse_geocode"); /* Place */ new_plugin->interface.maps_plugin_search_place = @@ -446,6 +449,8 @@ void plugin::binary_extractor::trace_dbg(const plugin_s *plugin) const itf->maps_plugin_geocode_by_structured_address); MAPS_LOGD("maps_plugin_reverse_geocode:\t\t%p", itf->maps_plugin_reverse_geocode); + MAPS_LOGD("maps_plugin_multi_reverse_geocode:\t%p", + itf->maps_plugin_multi_reverse_geocode); MAPS_LOGD("maps_plugin_search_place:\t\t%p", itf->maps_plugin_search_place); diff --git a/src/plugin/module.h b/src/plugin/module.h index aff3a19..e0deb45 100644 --- a/src/plugin/module.h +++ b/src/plugin/module.h @@ -68,6 +68,10 @@ typedef int (*maps_plugin_reverse_geocode_f) (double latitude, double longitude, maps_service_reverse_geocode_cb callback, void *user_data, int *request_id); +typedef int (*maps_plugin_multi_reverse_geocode_f) (const maps_coordinates_list_h maps_list, + const maps_preference_h preference, + maps_service_multi_reverse_geocode_cb callback, + void *user_data, int *request_id); /* Place */ typedef int (*maps_plugin_search_place_f) (const maps_coordinates_h position, @@ -144,6 +148,7 @@ namespace plugin { maps_plugin_geocode_by_structured_address_f maps_plugin_geocode_by_structured_address; maps_plugin_reverse_geocode_f maps_plugin_reverse_geocode; + maps_plugin_multi_reverse_geocode_f maps_plugin_multi_reverse_geocode; /* Place */ maps_plugin_search_place_f maps_plugin_search_place; diff --git a/src/session/commands.cpp b/src/session/commands.cpp index 81d49ae..1e38c35 100755 --- a/src/session/commands.cpp +++ b/src/session/commands.cpp @@ -440,6 +440,117 @@ void session::command_reverse_geocode_handler::foreach_reverse_geocode_cb( } /*----------------------------------------------------------------------------*/ +/*typedef int (*maps_plugin_multi_reverse_geocode_f) (maps_service_h maps, +* maps_coordinates_list_h maps_list, maps_preference_h preference, +* maps_service_multi_reverse_geocode_cb callback, void * user_data, int *request_id) */ +session::command_multi_reverse_geocode::command_multi_reverse_geocode( + maps_service_h ms, const maps_coordinates_list_h list, const maps_item_hashtable_h pref, + maps_service_multi_reverse_geocode_cb cb, void *ud, int *request_id) + : command(ms) + , maps_list(NULL) + , preference(NULL) + , callback(cb) + , user_data(ud) + , error(0) +{ + *request_id = command::command_request_id++; + my_req_id = *request_id; + + int list_size = 0; + maps_coordinates_list_get_length(list, &list_size); + if (list_size < 2 || list_size > 100) + error = MAPS_ERROR_INVALID_PARAMETER; + + if (pref && (maps_item_hashtable_clone(pref, &preference) != MAPS_ERROR_NONE)) + error = MAPS_ERROR_INVALID_PARAMETER; + + maps_list = list; +} + +session::command_multi_reverse_geocode::~command_multi_reverse_geocode() +{ + maps_item_hashtable_destroy(preference); +} + +int session::command_multi_reverse_geocode::run() +{ + if (error != MAPS_ERROR_NONE) + return error; + + pending_request pr(plugin()); + + /* Get the plugin interface function */ + maps_plugin_multi_reverse_geocode_f func = + interface()->maps_plugin_multi_reverse_geocode; + + command_multi_reverse_geocode_handler *handler = NULL; + if (func) { + /* No need to create the handler when the function is NULL */ + pr.add(my_req_id); + handler = new command_multi_reverse_geocode_handler(plugin(), callback, user_data, my_req_id); + + if (handler) { + /* Run the plugin interface function */ + error = func(maps_list, preference, + command_multi_reverse_geocode_handler::foreach_multi_reverse_geocode_cb, + handler, &handler->plg_req_id); + + pr.update(my_req_id, handler); + + MAPS_LOGD("session::command_multi_reverse_geocode::run: %d", my_req_id); + } + else { + error = MAPS_ERROR_OUT_OF_MEMORY; + } + } + else { + /* Plugin Function is NULL: use default empty function */ + /* + func = plugin::get_empty_interface(). + maps_plugin_multi_reverse_geocode; + */ + MAPS_LOGE("MAPS_ERROR_NOT_SUPPORTED: Can't get any plugin"); + error = MAPS_ERROR_NOT_SUPPORTED; + } + + const int ret = error; + destroy(); + return ret; +} + +session::command_multi_reverse_geocode_handler::command_multi_reverse_geocode_handler( + plugin::plugin_s *p, maps_service_multi_reverse_geocode_cb cb, void *ud, int urid) + : command_handler(p, ud, urid) + , callback(cb) +{ +} + +bool session::command_multi_reverse_geocode_handler::foreach_multi_reverse_geocode_cb( + maps_error_e error, int request_id, int total, maps_coordinates_list_h address_list, void *user_data) +{ + command_multi_reverse_geocode_handler *handler = + (command_multi_reverse_geocode_handler *) user_data; + + if (request_id != handler->plg_req_id) { + MAPS_LOGE("\n\nERROR! Incorrect request id [%d] come from the plugin; expected [%d]\n\n", + request_id, handler->plg_req_id); + } + + /* Make a user's copy of result data */ + maps_coordinates_list_h cloned_result = NULL; + cloned_result = address_list; + + /* Send data to user */ + const bool b = handler->callback(error, handler->user_req_id, total, cloned_result, handler->user_data); + /*if(index>=(total-1)) */ + + pending_request pr(handler->plugin()); + pr.remove(handler->user_req_id); + + return b; +} + +/*----------------------------------------------------------------------------*/ /*typedef int (*maps_plugin_search_place_f)(maps_service_h maps, * maps_coordinates_h position, int distance, maps_item_hashtable_h preference, * maps_place_filter_h filter, maps_service_search_place_cb callback, diff --git a/src/session/commands.h b/src/session/commands.h index bf3425b..9ade36a 100644 --- a/src/session/commands.h +++ b/src/session/commands.h @@ -254,6 +254,78 @@ namespace session }; /*----------------------------------------------------------------------------*/ + /*typedef int (*maps_plugin_multi_reverse_geocode_f)(maps_service_h maps, + * maps_maps_h maps_list, maps_preference_h preference, + * maps_service_multi_reverse_geocode_cb callback, void *user_data, * int *request_id); */ + class command_multi_reverse_geocode : public command + { + public: + const string address; + maps_coordinates_list_h maps_list; + maps_item_hashtable_h preference; + maps_service_multi_reverse_geocode_cb callback; + void *user_data; + int error; + public: + command_multi_reverse_geocode(maps_service_h ms, + const maps_coordinates_list_h maps_list, + const maps_item_hashtable_h preference, + maps_service_multi_reverse_geocode_cb callback, + void *user_data, int *request_id); + virtual ~command_multi_reverse_geocode(); + private: + command_multi_reverse_geocode() : command(NULL) + { + } + command_multi_reverse_geocode(const command_multi_reverse_geocode &src) + : command(NULL) + { + } + command_multi_reverse_geocode& operator=( + const command_multi_reverse_geocode &src) + { + return *this; + } + private: + virtual int run(); + }; + + class command_multi_reverse_geocode_handler : public command_handler + { + maps_service_multi_reverse_geocode_cb callback; + public: + command_multi_reverse_geocode_handler(plugin::plugin_s *plugin, + maps_service_multi_reverse_geocode_cb callback, + void *user_data, + int user_req_id); + virtual ~command_multi_reverse_geocode_handler() + { + }; + private: + command_multi_reverse_geocode_handler() + : command_handler(NULL, NULL, 0) + { + } + command_multi_reverse_geocode_handler( + command_multi_reverse_geocode_handler &src) + : command_handler(NULL, NULL, 0) + { + } + command_multi_reverse_geocode_handler &operator=( + const command_multi_reverse_geocode_handler &src) + { + return *this; + } + private: + static bool foreach_multi_reverse_geocode_cb(maps_error_e result, + int request_id, + int total, + maps_coordinates_list_h address_list, + void *user_data); + friend class command_multi_reverse_geocode; + }; + +/*----------------------------------------------------------------------------*/ /*typedef int (*maps_plugin_search_place_f)(maps_service_h maps, * maps_coordinates_h position, int distance, * maps_item_hashtable_h preference, maps_place_filter_h filter, diff --git a/test/dummy_plugin/dummy_plugin.cpp b/test/dummy_plugin/dummy_plugin.cpp index 55d9865..cb02848 100644 --- a/test/dummy_plugin/dummy_plugin.cpp +++ b/test/dummy_plugin/dummy_plugin.cpp @@ -92,6 +92,7 @@ EXPORT_API int maps_plugin_is_service_supported(maps_service_e service, case MAPS_SERVICE_SEARCH_ROUTE: case MAPS_SERVICE_SEARCH_ROUTE_WAYPOINTS: case MAPS_SERVICE_CANCEL_REQUEST: + case MAPS_SERVICE_MULTI_REVERSE_GEOCODE: *supported = true; return MAPS_ERROR_NONE; default: -- 2.7.4