From: kj7.sung Date: Tue, 2 Feb 2016 06:47:33 +0000 (+0900) Subject: [ACR-517] Alternative routes APIs X-Git-Tag: submit/tizen/20160308.085901^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1d7df888c4deeaa5f4554de3b84fb09e6ca6504e;p=platform%2Fcore%2Fapi%2Fmaps-service.git [ACR-517] Alternative routes APIs 2. Modify place list APIs Change-Id: I4b57a702a56dccbe5366b2e4c49f700c6478e321 Signed-off-by: kj7.sung --- diff --git a/include/maps_address.h b/include/maps_address.h index 3279158..37bae9a 100755 --- a/include/maps_address.h +++ b/include/maps_address.h @@ -585,7 +585,6 @@ int maps_address_list_foreach(maps_address_list_h address_list, maps_address_cb * @since_tizen 3.0 * * @param[in] address_list The address list handle - * @param[in] maps_address_h The address handle * @return 0 on success, otherwise a negative error value * @retval #MAPS_ERROR_NONE Successful * @retval #MAPS_ERROR_INVALID_PARAMETER Invalid parameter diff --git a/include/maps_extra_types.h b/include/maps_extra_types.h index a709d0e..7fc70d2 100755 --- a/include/maps_extra_types.h +++ b/include/maps_extra_types.h @@ -201,6 +201,8 @@ typedef bool(*maps_item_list_foreach_cb) (int index, int total, void *data, * @details This function delivers items of a specified list via * maps_item_list_foreach_cb() callback. * @since_tizen 2.4 + * @remarks This function clones the list values during maps_item_list_foreach() procedure. + * \n maps_item_list_foreach_noclone() is useful to reduce the memory consumption. * * @param[in] list The handle of list * @param[in] clone_func The function for cloning the list values @@ -219,6 +221,7 @@ typedef bool(*maps_item_list_foreach_cb) (int index, int total, void *data, * * @see maps_item_list_foreach_cb() * @see maps_item_list_append() + * @see maps_item_list_foreach_noclone() * @see maps_service_create() */ int maps_item_list_foreach(maps_item_list_h list, @@ -270,6 +273,48 @@ typedef int (*maps_item_list_free_cb) (void *data); int maps_item_list_remove_all(maps_item_list_h list, maps_item_list_free_cb free_func); +/** + * @brief Called once for each item while iterating through the given list. + * @details This function is called once for each item of the given list while + * the list is being iterated during the maps_item_list_foreach_noclone() procedure. + * @since_tizen 3.0 + * + * @param[in] index The current index of item + * @param[in] data The pointer to the list item + * @param[in] user_data The user data passed from maps_item_list_foreach_noclone() + * @return @c true to continue with the next iteration of the loop, \n @c false to break out of the loop + * + * @pre maps_item_list_foreach_noclone() will invoke this callback. + * + * @see maps_item_list_foreach_noclone() + */ +typedef bool(*maps_item_list_foreach_noclone_cb) (int index, void *data, void *user_data); + +/** + * @brief Gets the items of the specified list. + * @details This function delivers items of a specified list via maps_item_list_foreach_noclone_cb() callback. + * @since_tizen 3.0 + * @remarks This function is useful while adding to the list an item of arbitrary type without cloning it. + * \n maps_item_list_foreach() is useful when cloning the value is required while adding to the list. + * + * @param[in] list The handle of list + * @param[in] callback The callback to be invoked for delivering each list item + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value + * @retval #MAPS_ERROR_NONE Successful + * @retval #MAPS_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MAPS_ERROR_NOT_FOUND Result not found + * + * @pre @a list is created using maps_item_list_create(). + * @post This function invokes maps_item_list_foreach_noclone_cb() to deliver list items. + * + * @see maps_item_list_foreach_noclone_cb() + * @see maps_item_list_append() + * @see maps_item_list_foreach() + * @see maps_service_create() + */ +int maps_item_list_foreach_noclone(maps_item_list_h list, maps_item_list_foreach_noclone_cb callback, void *user_data); + /** * @} */ diff --git a/include/maps_place.h b/include/maps_place.h index 8976d32..6ab5668 100644 --- a/include/maps_place.h +++ b/include/maps_place.h @@ -64,6 +64,7 @@ typedef void *maps_place_h; * @since_tizen 3.0 * * @see maps_place_list_foreach() + * @see maps_place_list_destroy() */ typedef void *maps_place_list_h; @@ -259,11 +260,8 @@ typedef bool(*maps_place_reviews_cb) (int index, int total, * @brief Called when requesting the list of Place. * @details This callback is invoked while iterating through the list of Place. * @since_tizen 3.0 - * @remarks @a place is valid only in this function and must be released using - * maps_place_destroy(). * * @param[in] index The current index of review - * @param[in] total The total amount of reviews * @param[in] place The place handle * @param[in] uesr_data The user data passed from the maps_place_list_foreach() * @return @c true to continue with the next iteration of the loop, @@ -280,7 +278,7 @@ typedef bool(*maps_place_reviews_cb) (int index, int total, * @see maps_place_get_rating() * @see maps_place_foreach_category() */ -typedef bool(*maps_place_cb) (int index, int total, maps_place_h place, void *user_data); +typedef bool(*maps_place_cb) (int index, maps_place_h place, void *user_data); /*----------------------------------------------------------------------------*/ @@ -632,6 +630,7 @@ int maps_place_get_related_link(const maps_place_image_h place, * @details This function retrieves all places. * @since_tizen 3.0 * @remarks The places will be delivered via maps_place_cb(). + * \n @a place_list must be released using maps_place_list_destroy(). * * @param[in] place_list The place list handle * @param[in] callback The callback function to invoke @@ -645,9 +644,22 @@ int maps_place_get_related_link(const maps_place_image_h place, * @post This function invokes maps_place_cb() repeatedly to retrieve each place. * * @see maps_place_cb() + * @see maps_place_list_destroy() + */ +int maps_place_list_foreach(const maps_place_list_h place_list, maps_place_cb callback, void *user_data); + +/** + * @brief Frees all of the memory used by a place list. + * @since_tizen 3.0 + * + * @param[in] place_list The place list handle + * @return 0 on success, otherwise a negative error value + * @retval #MAPS_ERROR_NONE Successful + * @retval #MAPS_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see maps_place_list_foreach() */ -int maps_place_list_foreach(const maps_place_list_h place_list, - maps_place_cb callback, void *user_data); +int maps_place_list_destroy(maps_place_list_h place_list); #ifdef __cplusplus } diff --git a/include/maps_place_plugin.h b/include/maps_place_plugin.h index 93ae1a8..160daba 100644 --- a/include/maps_place_plugin.h +++ b/include/maps_place_plugin.h @@ -361,6 +361,20 @@ int maps_place_set_supplier_link(maps_place_h place, int maps_place_set_related_link(maps_place_h place, const maps_place_link_object_h related); +/** + * @brief Creates a place list having a set of places. + * @since_tizen 3.0 + * + * @param[out] place_list The place list handle + * @return 0 on success, otherwise a negative error value + * @retval #MAPS_ERROR_NONE Successful + * @retval #MAPS_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MAPS_ERROR_OUT_OF_MEMORY Out of memory + * + * @see maps_place_list_destroy() + */ +int maps_place_list_create(maps_place_list_h *place_list); + #ifdef __cplusplus } #endif diff --git a/include/maps_preference.h b/include/maps_preference.h index c5bddab..d5880d2 100644 --- a/include/maps_preference.h +++ b/include/maps_preference.h @@ -497,6 +497,19 @@ int maps_preference_get_route_feature_weight(const maps_preference_h int maps_preference_get_route_feature(const maps_preference_h preference, maps_route_feature_e *feature); +/** + * @brief Gets the enable status of alternative routes. + * @details This function retrieves the enable status of alternative route. + * @since_tizen 3.0 + * + * @param[in] preference The preference handle + * @param[out] enable The enable status + * @return 0 on success, otherwise a negative error value + * @retval #MAPS_ERROR_NONE Successful + * @retval #MAPS_ERROR_INVALID_PARAMETER Invalid parameter + */ +int maps_preference_get_route_alternatives_enabled(const maps_preference_h preference, bool *enable); + /** * @brief Gets the maps preference value by key. * @details This function gets the maps preference value by key. @@ -695,6 +708,24 @@ int maps_preference_set_route_feature_weight(maps_preference_h preference, int maps_preference_set_route_feature(maps_preference_h preference, const maps_route_feature_e feature); +/** + * @brief Sets the enable status of alternative routes. + * @details This function sets the alternative routes status. + * @since_tizen 3.0 + * + * @param[in] preference The preference handle + * @param[in] enable The value to set + * @return 0 on success, otherwise a negative error value + * @retval #MAPS_ERROR_NONE Successful + * @retval #MAPS_ERROR_INVALID_PARAMETER Invalid parameter + * + * @pre @a preference is created using maps_preference_create(). + * + * @see maps_preference_create() + * @see maps_preference_get_route_alternatives_enabled() + */ +int maps_preference_set_route_alternatives_enabled(maps_preference_h preference, bool enable); + /** * @brief Sets the preference value by key. * @details This function sets the preference value assigned with a specified diff --git a/include/maps_service.h b/include/maps_service.h index b8b440d..4a21edf 100644 --- a/include/maps_service.h +++ b/include/maps_service.h @@ -925,7 +925,8 @@ typedef bool(*maps_service_search_place_cb) (maps_error_e error, * from the specified coordinates. * \n If search is failed, the value of @a total is 0 and @a place_list is NULL * @since_tizen 3.0 - * @remarks This error code will be reported. \n + * @remarks The parameter @a place_list must be released using maps_place_list_destroy(). + * \n This error code will be reported. \n * #MAPS_ERROR_NONE \n * #MAPS_ERROR_OUT_OF_MEMORY \n * #MAPS_ERROR_INVALID_PARAMETER \n @@ -933,6 +934,7 @@ typedef bool(*maps_service_search_place_cb) (maps_error_e error, * * @param[in] error The result of request * @param[in] request_id The request id + * @param[in] total The total number of results * @param[in] place_list The resulting Place list data * @param[in] uesr_data The user data passed from maps_service_search_place_list() * @@ -942,7 +944,7 @@ typedef bool(*maps_service_search_place_cb) (maps_error_e error, * @see maps_place_list_foreach() */ typedef void(*maps_service_search_place_list_cb) (maps_error_e error, - int request_id, maps_place_list_h place_list, void *user_data); + int request_id, int total, maps_place_list_h place_list, void *user_data); /** * @brief Called for Place datail information of Place Search request @@ -950,7 +952,8 @@ typedef void(*maps_service_search_place_list_cb) (maps_error_e error, * obtained from the specified uri. * \n If search is failed, @a place is NULL * @since_tizen 3.0 - * @remarks This error code will be reported. \n + * @remarks The parameter @a place must be released using maps_place_destroy(). + * \n This error code will be reported. \n * #MAPS_ERROR_NONE \n * #MAPS_ERROR_OUT_OF_MEMORY \n * #MAPS_ERROR_INVALID_PARAMETER \n diff --git a/src/api/maps_extra_types.cpp b/src/api/maps_extra_types.cpp index 95d9b24..a9dd480 100755 --- a/src/api/maps_extra_types.cpp +++ b/src/api/maps_extra_types.cpp @@ -94,6 +94,27 @@ EXPORT_API int maps_item_list_foreach(maps_item_list_h list, return MAPS_ERROR_NONE; } +EXPORT_API int maps_item_list_foreach_noclone(maps_item_list_h list, maps_item_list_foreach_noclone_cb callback, void *user_data) +{ + if (!list || !callback) + return MAPS_ERROR_INVALID_PARAMETER; + maps_item_list_s *l = (maps_item_list_s *) list; + + if (!l->l) + return MAPS_ERROR_NOT_FOUND; + + GList *head = g_list_first(l->l); + int index = 0; + while (head) { + void *data = head->data; + head = head->next; + if (!callback(index++, data, user_data)) + break; + } + + return MAPS_ERROR_NONE; +} + EXPORT_API int maps_item_list_remove_all(maps_item_list_h list, maps_item_list_free_cb free_func) { diff --git a/src/api/maps_place.cpp b/src/api/maps_place.cpp index 495a45a..a554b99 100755 --- a/src/api/maps_place.cpp +++ b/src/api/maps_place.cpp @@ -821,5 +821,28 @@ EXPORT_API int maps_place_list_foreach(const maps_place_list_h place_list, if (!place_list || !callback) return MAPS_ERROR_INVALID_PARAMETER; - return maps_item_list_foreach((maps_item_list_h) place_list, maps_place_clone, callback, user_data); + return maps_item_list_foreach_noclone((maps_item_list_h) place_list, callback, user_data); } + +EXPORT_API int maps_place_list_create(maps_place_list_h *place_list) +{ + if (!place_list) + return MAPS_ERROR_INVALID_PARAMETER; + + return maps_item_list_create(place_list); +} + +EXPORT_API int maps_place_list_destroy(maps_place_list_h place_list) +{ + if (!place_list) + return MAPS_ERROR_INVALID_PARAMETER; + + int error = MAPS_ERROR_NONE; + + error = maps_item_list_remove_all(place_list, maps_place_destroy); + if (error != MAPS_ERROR_NONE) + return error; + + return maps_item_list_destroy(place_list); +} + diff --git a/src/api/maps_preference.cpp b/src/api/maps_preference.cpp index 7a253bf..b0f2558 100755 --- a/src/api/maps_preference.cpp +++ b/src/api/maps_preference.cpp @@ -20,6 +20,8 @@ #include "maps_preference.h" #include +const int _DEFAULT_ALTERNATIVES_SIZE = 2; + typedef struct _callback_data { maps_preference_properties_cb callback; @@ -53,7 +55,8 @@ static bool __isnamed_preference(const char *key) g_str_hash("MAPS_PREFERENCE_ROUTE_OPTIMIZATION"), g_str_hash("MAPS_PREFERENCE_ROUTE_TRANSPORT_MODE"), g_str_hash("MAPS_PREFERENCE_ROUTE_FEATURE_WEIGHT"), - g_str_hash("MAPS_PREFERENCE_ROUTE_FEATURE") + g_str_hash("MAPS_PREFERENCE_ROUTE_FEATURE"), + g_str_hash("MAPS_PREFERENCE_ROUTE_ALTERNATIVES") }; const int size = sizeof(names) / sizeof(names[0]); @@ -95,18 +98,19 @@ EXPORT_API int maps_preference_create(maps_preference_h *preference) return error; do { - error = maps_item_hashtable_set_int(*preference, - "MAPS_PREFERENCE_DISTANCE_UNIT", MAPS_DISTANCE_UNIT_M); + error = maps_item_hashtable_set_int(*preference, "MAPS_PREFERENCE_DISTANCE_UNIT", MAPS_DISTANCE_UNIT_M); + if (error != MAPS_ERROR_NONE) + break; + + error = maps_item_hashtable_set_string(*preference, "MAPS_PREFERENCE_LANGUAGE", "en-US"); if (error != MAPS_ERROR_NONE) break; - error = maps_item_hashtable_set_string(*preference, - "MAPS_PREFERENCE_LANGUAGE", "en-US"); + error = maps_item_hashtable_set_int(*preference, "MAPS_PREFERENCE_MAX_RESULTS", 25); if (error != MAPS_ERROR_NONE) break; - error = maps_item_hashtable_set_int(*preference, - "MAPS_PREFERENCE_MAX_RESULTS", 25); + error = maps_item_hashtable_set_int(*preference, "MAPS_PREFERENCE_ROUTE_ALTERNATIVES", 0); if (error != MAPS_ERROR_NONE) break; @@ -216,6 +220,21 @@ EXPORT_API int maps_preference_get_route_feature(const maps_preference_h "MAPS_PREFERENCE_ROUTE_FEATURE", (int *) feature); } +EXPORT_API int maps_preference_get_route_alternatives_enabled(const maps_preference_h preference, bool *enable) +{ + if (!preference) + return MAPS_ERROR_INVALID_PARAMETER; + + int alternatives; + int error = maps_item_hashtable_get_int(preference, "MAPS_PREFERENCE_ROUTE_ALTERNATIVES", &alternatives); + if (error != MAPS_ERROR_NONE) + return error; + + *enable = (alternatives == _DEFAULT_ALTERNATIVES_SIZE) ? true :false; + + return MAPS_ERROR_NONE; +} + EXPORT_API int maps_preference_get(const maps_preference_h preference, const char *key, char **value) { @@ -333,6 +352,18 @@ EXPORT_API int maps_preference_set_route_feature(maps_preference_h preference, "MAPS_PREFERENCE_ROUTE_FEATURE", feature); } +EXPORT_API int maps_preference_set_route_alternatives_enabled(maps_preference_h preference, bool enable) +{ + if (!preference) + return MAPS_ERROR_INVALID_PARAMETER; + + int alternatives = 0; + if (enable) + alternatives = _DEFAULT_ALTERNATIVES_SIZE; + + return maps_item_hashtable_set_int(preference, "MAPS_PREFERENCE_ROUTE_ALTERNATIVES", alternatives); +} + EXPORT_API int maps_preference_set_property(maps_preference_h preference, const char *key, const char *value) { diff --git a/src/session/commands.cpp b/src/session/commands.cpp index 4171930..0a95858 100755 --- a/src/session/commands.cpp +++ b/src/session/commands.cpp @@ -960,7 +960,7 @@ int session::command_search_place_list::run() if (handler) { /* Run the plugin interface function */ error = func(boundary, filter, preference, - command_search_place_list_handler::foreach_place_around_cb, handler, + command_search_place_list_handler::foreach_place_list_cb, handler, &handler->plg_req_id); pr.update(my_req_id, handler); @@ -994,8 +994,9 @@ session::command_search_place_list_handler::command_search_place_list_handler( { } -void session::command_search_place_list_handler::foreach_place_around_cb(maps_error_e error, +void session::command_search_place_list_handler::foreach_place_list_cb(maps_error_e error, int request_id, + int total, maps_place_list_h place_list, void *user_data) { @@ -1008,7 +1009,7 @@ void session::command_search_place_list_handler::foreach_place_around_cb(maps_er } /* Send data to user */ - handler->callback(error, handler->user_req_id, place_list, handler->user_data); + handler->callback(error, handler->user_req_id, total, place_list, handler->user_data); pending_request pr(handler->plugin()); pr.remove(handler->user_req_id); diff --git a/src/session/commands.h b/src/session/commands.h index 6293d6d..dbb27de 100644 --- a/src/session/commands.h +++ b/src/session/commands.h @@ -556,8 +556,8 @@ namespace session { return *this; } private: - static void foreach_place_around_cb(maps_error_e error, int request_id, - maps_place_list_h place, void *user_data); + static void foreach_place_list_cb(maps_error_e error, int request_id, + int total, maps_place_list_h place, void *user_data); friend class command_search_place_list; };