[ACR-517] Alternative routes APIs 97/58597/10
authorkj7.sung <kj7.sung@samsung.com>
Tue, 2 Feb 2016 06:47:33 +0000 (15:47 +0900)
committerkj7.sung <kj7.sung@samsung.com>
Mon, 7 Mar 2016 09:15:43 +0000 (18:15 +0900)
2. Modify place list APIs

Change-Id: I4b57a702a56dccbe5366b2e4c49f700c6478e321
Signed-off-by: kj7.sung <kj7.sung@samsung.com>
include/maps_address.h
include/maps_extra_types.h
include/maps_place.h
include/maps_place_plugin.h
include/maps_preference.h
include/maps_service.h
src/api/maps_extra_types.cpp
src/api/maps_place.cpp
src/api/maps_preference.cpp
src/session/commands.cpp
src/session/commands.h

index 3279158e2bd2d8628fc5b582733b28754337f39f..37bae9aab2c7ecccd49e500e161a60991e0dbcff 100755 (executable)
@@ -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
index a709d0e8cc5e07aa73bbdd8dbae50b858ed30b65..7fc70d26fec120794d668c2320eb5a86450bf7a8 100755 (executable)
@@ -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);
+
 /**
  * @}
  */
index 8976d3244c3a728764a076189c38152a7017d683..6ab5668aa8864a14dd80926d1a49705a574cc7fc 100644 (file)
@@ -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
 }
index 93ae1a81a9b0d9ac8af6702515dbfe010d7c52ca..160dabac3d20c91f17efb07df029a54e35046541 100644 (file)
@@ -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
index c5bddab48f0c802aa5e6a141d2fd18f679ac3bb5..d5880d2c46ee6c17f9b993a7c2f7386b83dbf5d4 100644 (file)
@@ -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
index b8b440ddca570b52fd028e00a915fa8d9126c2c0..4a21edf4ea0e6fe685b628aa187e78e7f578d1c8 100644 (file)
@@ -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
index 95d9b249509feeee2d63d968510ed937ec20667a..a9dd48064b53e77338d4aa6bbba0b70f899f8f43 100755 (executable)
@@ -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)
 {
index 495a45ab292ef892a960306af5d3ac753386de25..a554b993f7fd2dff0b7bc77d719490d4448271a4 100755 (executable)
@@ -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);
+}
+
index 7a253bf076abc0f7bdb65bebe7def5fe34db8099..b0f2558c82af37205ac430d58b06c2e5fd3d3215 100755 (executable)
@@ -20,6 +20,8 @@
 #include "maps_preference.h"
 #include <glib.h>
 
+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)
 {
index 41719303ed0547d6453a138201bb871de9ec145c..0a95858b0ac3c9f05b5f4be085a7c08f047edda3 100755 (executable)
@@ -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);
index 6293d6d3901a73bb9544abd7ae3a1d3f0dfe2cd1..dbb27de0604a9cb5593942462bee7a2b9d14abd9 100644 (file)
@@ -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;
        };