From: Marcin Masternak Date: Fri, 5 Aug 2016 16:35:58 +0000 (+0200) Subject: [my-place] Internal API. X-Git-Tag: accepted/tizen/common/20160907.154906^2~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f30414516b15c90b31c4853bbd5598727d87e892;p=platform%2Fcore%2Fapi%2Fcontext.git [my-place] Internal API. Change-Id: I3d510bb26fb386191b6970f2ba94c1b653865d87 Signed-off-by: Marcin Masternak --- diff --git a/include/context_places_internal.h b/include/context_places_internal.h new file mode 100644 index 0000000..cd34c77 --- /dev/null +++ b/include/context_places_internal.h @@ -0,0 +1,389 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * 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_CONTEXT_PLACES_H__ +#define __TIZEN_CONTEXT_PLACES_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @brief Enumeration for place category. + * @since_tizen 3.0 + */ +typedef enum { + CONTEXT_PLACES_CATEG_ID_NONE = 0, + CONTEXT_PLACES_CATEG_ID_HOME = 1, + CONTEXT_PLACES_CATEG_ID_WORK = 2, + CONTEXT_PLACES_CATEG_ID_OTHER = 3 +} context_places_categ_id_e; + +/** + * @brief Enumeration for errors. + * @since_tizen 3.0 + */ +typedef enum { + CONTEXT_PLACES_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ + CONTEXT_PLACES_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ + CONTEXT_PLACES_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */ + CONTEXT_PLACES_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< Not supported */ + CONTEXT_PLACES_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Memory allocation failed */ + CONTEXT_PLACES_ERROR_NO_DATA = TIZEN_ERROR_NO_DATA, /**< No Data */ + CONTEXT_PLACES_ERROR_OUT_OF_RANGE = (TIZEN_ERROR_CONTEXT | 0x03), /**< Out of range */ + CONTEXT_PLACES_ERROR_OPERATION_FAILED = (TIZEN_ERROR_CONTEXT | 0x04), /**< Operation failed */ +} context_places_error_e; + +/** + * @brief Places list handle. It contains one or multiple records. + * @since_tizen 3.0 + */ +typedef struct _context_places_list_handle_s* context_places_list_h; + +/** + * @brief Place handle. + * @since_tizen 3.0 + */ +typedef struct _context_places_place_handle_s* context_places_place_h; + +/** + * @brief Place Wifi AP's list handle. It contains one or multiple records. + * @since_tizen 3.0 + */ +typedef struct _context_places_wifi_ap_list_handle_s* context_places_wifi_ap_list_h; + +/** + * @brief Reads detected/recognized user places list. + * @since_tizen 3.0 + * + * @remarks The @c list must be released using context_places_list_destroy(). \n + * %http://tizen.org/privilege/location is needed to retrieve data. + * + * @param[out] list Places data retrieved. This should be freed after use + * + * @return 0 on success, otherwise a negative error value + * @retval #CONTEXT_PLACES_ERROR_NONE Successful + * @retval #CONTEXT_PLACES_ERROR_OPERATION_FAILED Operation failed + * @retval #CONTEXT_PLACES_ERROR_OUT_OF_MEMORY Out of memory + * @retval #CONTEXT_PLACES_ERROR_NO_DATA Requested data does not exist + * + * @post context_places_list_destroy() + */ +int context_places_get_list(context_places_list_h* list); + +/** + * @brief Retrieves the number of records in a list. + * @since_tizen 3.0 + * + * @param[in] list The places data list handle + * @param[out] count The count of the data list + * + * @return 0 on success, otherwise a negative error value + * @retval #CONTEXT_PLACES_ERROR_NONE Successful + * @retval #CONTEXT_PLACES_ERROR_OPERATION_FAILED Operation failed + * + * @pre context_places_get_list() + * @see context_places_list_move_first() + * @see context_places_list_move_next() + */ +int context_places_list_get_count(context_places_list_h list, int* count); + +/** + * @brief Retrieves the current record from the places list. + * @details The default current record is the first record. + * @since_tizen 3.0 + * @remarks The @c record must be released using context_places_record_destroy(). + * + * @param[in] list The context places list handle + * @param[out] record Places data record retrieved + * + * @return 0 on success, otherwise a negative error value + * @retval #CONTEXT_PLACES_ERROR_NONE Successful + * @retval #CONTEXT_PLACES_ERROR_OPERATION_FAILED Operation failed + * + * @pre context_places_get_list() + * @post context_places_record_destroy() + */ +int context_places_list_get_current(context_places_list_h list, context_places_place_h* record); + +/** + * @brief Moves a places data list to the first position. + * @since_tizen 3.0 + * + * @param[in] list The context places list handle + * + * @return 0 on success, otherwise a negative error value + * @retval #CONTEXT_PLACES_ERROR_NONE Successful + * + * @pre context_places_get_list() + * @see context_places_list_get_count() + * @see context_places_list_move_next() + */ +int context_places_list_move_first(context_places_list_h list); + +/** + * @brief Moves a places data list to the next position. + * @since_tizen 3.0 + * + * @param[in] list The context places list handle + * + * @return 0 on success, otherwise a negative error value + * @retval #CONTEXT_PLACES_ERROR_NONE Successful + * @retval #CONTEXT_PLACES_ERROR_NO_DATA Requested data does not exist + * + * @pre context_places_get_list() + * @see context_places_list_get_count() + * @see context_places_list_move_first() + */ +int context_places_list_move_next(context_places_list_h list); + +/** + * @brief Destroys a places list handle and release all its resources. + * @since_tizen 3.0 + * + * @param[in] list The context places data handle + * + * @return 0 on success, otherwise a negative error value + * @retval #CONTEXT_PLACES_ERROR_NONE Successful + * + * @pre context_places_get_list() + */ +int context_places_list_destroy(context_places_list_h list); + +/** + * @brief Gets place category and its confidence. + * @since_tizen 3.0 + * + * @param[in] place Place handle + * @param[out] value Place category value + * @param[out] confidence Place category confidence + * + * @return 0 on success, otherwise a negative error value + * @retval #CONTEXT_PLACES_ERROR_NONE Successful + * + * @pre context_places_list_get_current() + */ +int context_places_place_get_category(context_places_place_h place, context_places_categ_id_e* value, double* confidence); + +/** + * @brief Gets a place name. + * @since_tizen 3.0 + * + * @param[in] place Place handle + * @param[out] name Place name + * + * @return 0 on success, otherwise a negative error value + * @retval #CONTEXT_PLACES_ERROR_NONE Successful + * + * @pre context_places_list_get_current() + */ +int context_places_place_get_name(context_places_place_h place, char** name); + +/** + * @brief Gets place location. + * @since_tizen 3.0 + * + * @param[in] place Place handle + * @param[out] latitude Place location latitude + * @param[out] longitude Place location longitude + * @param[out] accuracy Place location accuracy + * + * @return 0 on success, otherwise a negative error value + * @retval #CONTEXT_PLACES_ERROR_NONE Successful + * + * @pre context_places_list_get_current() + */ +int context_places_place_get_location(context_places_place_h place, double* latitude, double* longitude, double* accuracy); + +/** + * @brief Gets place creation/detection timestamp. + * @since_tizen 3.0 + * + * @param[in] place Place handle + * @param[out] timestamp Place creation timestamp + * + * @return 0 on success, otherwise a negative error value + * @retval #CONTEXT_PLACES_ERROR_NONE Successful + * + * @pre context_places_list_get_current() + */ +int context_places_place_get_creation_date(context_places_place_h place, time_t* timestamp); + +/** + * @brief Destroys a place handle and releases all its resources. + * @since_tizen 3.0 + * + * @param[in] place Place handle + * + * @return 0 on success, otherwise a negative error value + * @retval #CONTEXT_PLACES_ERROR_NONE Successful + * + * @pre context_places_list_get_current() + */ +int context_places_place_destroy(context_places_place_h place); + +/** + * @brief Reads place Wifi AP's list. + * @since_tizen 3.0 + * + * @remarks The @c list must be released using context_places_wifi_ap_list_destroy(). + * + * @param[int] place Place handle + * @param[out] list Place Wifi AP's list. This should be freed after use + * + * @return 0 on success, otherwise a negative error value + * @retval #CONTEXT_PLACES_ERROR_NONE Successful + * @retval #CONTEXT_PLACES_ERROR_NO_DATA Requested data does not exist + * + * @pre context_places_list_get_current() + * @post context_places_wifi_ap_list_destroy() + */ +int context_places_place_get_wifi_ap_list(context_places_place_h place, context_places_wifi_ap_list_h* list); + +/** + * @brief Retrieves the number of records in a list. + * @since_tizen 3.0 + * + * @param[in] list Place Wifi AP's list handle + * @param[out] count The count of the data list + * + * @return 0 on success, otherwise a negative error value + * @retval #CONTEXT_PLACES_ERROR_NONE Successful + * @retval #CONTEXT_PLACES_ERROR_OPERATION_FAILED Operation failed + * + * @pre context_places_place_get_wifi_ap_list() + * @see context_places_wifi_ap_list_move_first() + * @see context_places_wifi_ap_list_move_next() + */ +int context_places_wifi_ap_list_get_count(context_places_wifi_ap_list_h list, int* count); + +/** + * @brief Retrieves the current record from the places list. + * @details The default current record is the first record. + * @since_tizen 3.0 + * + * @param[in] list Wifi AP's list handle + * @param[out] bssid Wifi AP MAC address + * @param[out] essid Wifi AP network name + * + * @return 0 on success, otherwise a negative error value + * @retval #CONTEXT_PLACES_ERROR_NONE Successful + * @retval #CONTEXT_PLACES_ERROR_OPERATION_FAILED Operation failed + * @retval #CONTEXT_PLACES_ERROR_NO_DATA Requested data does not exist + * + * @pre context_places_place_get_wifi_ap_list() + * @see context_places_wifi_ap_list_move_first() + * @see context_places_wifi_ap_list_move_next() + */ +int context_places_wifi_ap_list_get_current(context_places_wifi_ap_list_h list, char** bssid, char** essid); + +/** + * @brief Moves a Place Wifi AP's list to the first position. + * @since_tizen 3.0 + * + * @param[in] list Wifi AP's list handle + * + * @return 0 on success, otherwise a negative error value + * @retval #CONTEXT_PLACES_ERROR_NONE Successful + * + * @pre context_places_place_get_wifi_ap_list() + * @see context_places_wifi_ap_list_get_count() + * @see context_places_wifi_ap_list_move_next() + */ +int context_places_wifi_ap_list_move_first(context_places_wifi_ap_list_h list); + +/** + * @brief Moves a Place Wifi AP's list to the next position. + * @since_tizen 3.0 + * + * @param[in] list Wifi AP's list handle + * + * @return 0 on success, otherwise a negative error value + * @retval #CONTEXT_PLACES_ERROR_NONE Successful + * @retval #CONTEXT_PLACES_ERROR_NO_DATA Requested data does not exist + * + * @pre context_places_place_get_wifi_ap_list() + * @see context_places_wifi_ap_list_get_count() + * @see context_places_wifi_ap_list_move_first() + */ +int context_places_wifi_ap_list_move_next(context_places_wifi_ap_list_h list); + +/** + * @brief Destroys a Wifi AP's list handle and release all its resources. + * @since_tizen 3.0 + * + * @param[in] list Wifi AP's list handle + * + * @return 0 on success, otherwise a negative error value + * @retval #CONTEXT_PLACES_ERROR_NONE Successful + * + * @pre context_places_place_get_wifi_ap_list() + */ +int context_places_wifi_ap_list_destroy(context_places_wifi_ap_list_h list); + +/** + * @brief Returns information if context places engine is supported by the system. + * @since_tizen 3.0 + * + * @param[out] supported context places support + * + * @return 0 on success, otherwise a negative error value + * @retval #CONTEXT_PLACES_ERROR_NONE Successful + * @retval #CONTEXT_PLACES_ERROR_OPERATION_FAILED Failed + */ +int context_places_is_supported(bool *supported); + +/** + * @brief Sets user consent/permission for the operation of the context places engine, + * resulting in the start and stop of the engine. + * @since_tizen 3.0 + * + * @param[in] consent User consent + * + * @return 0 on success, otherwise a negative error value + * @retval #CONTEXT_PLACES_ERROR_NONE Successful + * @retval #CONTEXT_PLACES_ERROR_OPERATION_FAILED Failed + * + * @pre context_places_is_supported() + */ +int context_places_consent(bool consent); + +/** + * @brief Checks if the user give consent/permission to the context places operation. + * This means also the engine state (run/off). + * @since_tizen 3.0 + * + * @param[out] consented User consent + * + * @return 0 on success, otherwise a negative error value + * @retval #CONTEXT_PLACES_ERROR_NONE Successful + * @retval #CONTEXT_PLACES_ERROR_OPERATION_FAILED Failed + * + * @pre context_places_is_supported() + */ +int context_places_is_consented(bool *consented); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +/** +* @} +*/ + +#endif /* __TIZEN_CONTEXT_PLACES_H__ */ diff --git a/src/context_places.cpp b/src/context_places.cpp new file mode 100644 index 0000000..bd18058 --- /dev/null +++ b/src/context_places.cpp @@ -0,0 +1,482 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * 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 +#include +#include +#include +#include +#include "DBusClient.h" + +/* XXX: temporary !!!!! Example JSON output: +--------------------------------------------------------------------------------------- +{ + "PlacesList":[ + { + "CategId":1, + "CategConfidence":"0.555000007152557", + "Name":"Home", + "Location":{"Latitude":"10.9443311","Longitude":"50.8550422","Accuracy":"-1"}, + "WifiAPs": + { + "WifiAPs":[ + { + "Mac":"00:1f:f3:5b:2b:1f", + "Network":"first network" + }, + { + "Mac":"13:34:56:78:9a:ba", + "Network":"third network" + }, + { + "Mac":"15:34:56:78:9a:ba", + "Network":"second network" + } + ] + }, + "CreateDate":12132567 + }, + { + "CategId":2, + "CategConfidence":"0.666000008583069", + "Name":"Work", + "Location": + { + "Latitude":"10.9623333", + "Longitude":"50.8430444", + "Accuracy":"100" + }, + "WifiAPs": + { + "WifiAPs":[ + { + "Mac":"12:34:56:78:9a:ba", + "Network":"fourth network" + } + ] + }, + "CreateDate":12132889 + }, + { + "CategId":3, + "CategConfidence":"0.77700001001358", + "Name":"Other", + "CreateDate":12132777 + } + ] +} +--------------------------------------------------------------------------------------- +*/ + +struct _context_places_list_handle_s { + ctx::Json jList; + int current; + _context_places_list_handle_s() + { + current = 0; + } +}; + +struct _context_places_place_handle_s { + ctx::Json jPlace; +}; + +struct _context_places_wifi_ap_list_handle_s { + ctx::Json jList; + int current; + _context_places_wifi_ap_list_handle_s() + { + current = 0; + } +}; + +SO_EXPORT int context_places_get_list(context_places_list_h* list) +{ + ASSERT_NOT_NULL(list); + *list = NULL; + + ctx::Json option; + option.set(NULL, PLACE_DETECTION_REQUEST, PLACE_DETECTION_REQUEST_LIST); + + int req_id; + ctx::Json tmp_list; + ctx::DBusClient dbusClient; + + int error = dbusClient.readSync(PLACE_DETECTION_SUBJECT, option, &req_id, &tmp_list); + IF_FAIL_RETURN_TAG( + error == ERR_NONE, + error, + _E, + "Getting list failed"); + + _J("Read response", tmp_list); + + IF_FAIL_RETURN_TAG( + tmp_list.getSize(NULL, PLACE_DATA_READ) > 0, + CONTEXT_PLACES_ERROR_NO_DATA, + _D, + "No data"); + + *list = new(std::nothrow) _context_places_list_handle_s(); + ASSERT_ALLOC(*list); + (*list)->jList = tmp_list; + (*list)->current = 0; + + return CONTEXT_PLACES_ERROR_NONE; +} + +SO_EXPORT int context_places_list_get_count(context_places_list_h list, int* count) +{ + ASSERT_NOT_NULL(list && count); + *count = 0; + + int result = list->jList.getSize(NULL, PLACE_DATA_READ); + IF_FAIL_RETURN(result > 0, CONTEXT_PLACES_ERROR_OPERATION_FAILED); + + *count = result; + + return CONTEXT_PLACES_ERROR_NONE; +} + +SO_EXPORT int context_places_list_get_current(context_places_list_h list, context_places_place_h* record) +{ + ASSERT_NOT_NULL(list && record); + *record = NULL; + + ctx::Json tmp_record; + int error = list->jList.getAt(NULL, PLACE_DATA_READ, list->current, &tmp_record); + IF_FAIL_RETURN_TAG( + error, + CONTEXT_PLACES_ERROR_OPERATION_FAILED, + _E, + "Place record load failed"); + + *record = new(std::nothrow) _context_places_place_handle_s(); + ASSERT_ALLOC(*record); + (*record)->jPlace = tmp_record; + + return CONTEXT_PLACES_ERROR_NONE; +} + +SO_EXPORT int context_places_list_move_first(context_places_list_h list) +{ + ASSERT_NOT_NULL(list); + + list->current = 0; + + return CONTEXT_PLACES_ERROR_NONE; +} + +SO_EXPORT int context_places_list_move_next(context_places_list_h list) +{ + ASSERT_NOT_NULL(list); + + IF_FAIL_RETURN_TAG( + list->current+1 < list->jList.getSize(NULL, PLACE_DATA_READ), + CONTEXT_PLACES_ERROR_NO_DATA, + _D, + "End of list"); + + list->current++; + + return CONTEXT_PLACES_ERROR_NONE; +} + +SO_EXPORT int context_places_list_destroy(context_places_list_h list) +{ + ASSERT_NOT_NULL(list); + + delete list; + + return CONTEXT_PLACES_ERROR_NONE; +} + +SO_EXPORT int context_places_place_get_category(context_places_place_h place, context_places_categ_id_e* value, double* confidence) +{ + ASSERT_NOT_NULL(place && value && confidence); + + int categId; + IF_FAIL_RETURN_TAG( + place->jPlace.get(NULL, PLACE_CATEG_ID, &categId), + CONTEXT_PLACES_ERROR_NO_DATA, + _E, + "Parameter empty"); + + double categConfidence; + IF_FAIL_RETURN_TAG( + place->jPlace.get(NULL, PLACE_CATEG_CONFIDENCE, &categConfidence), + CONTEXT_PLACES_ERROR_NO_DATA, + _E, + "Parameter empty"); + + *value = static_cast(categId); + *confidence = categConfidence; + + return CONTEXT_PLACES_ERROR_NONE; +} + +SO_EXPORT int context_places_place_get_name(context_places_place_h place, char** name) +{ + ASSERT_NOT_NULL(place && name); + + std::string str; + IF_FAIL_RETURN_TAG( + place->jPlace.get(NULL, PLACE_NAME, &str), + CONTEXT_PLACES_ERROR_NO_DATA, + _E, + "Parameter empty"); + + *name = g_strdup(str.c_str()); + ASSERT_ALLOC(*name); + + return CONTEXT_PLACES_ERROR_NONE; +} + +SO_EXPORT int context_places_place_get_location(context_places_place_h place, double* latitude, double* longitude, double* accuracy) +{ + ASSERT_NOT_NULL(place && latitude && longitude && accuracy); + + ctx::Json locationJson; + IF_FAIL_RETURN_TAG( + place->jPlace.get(NULL, PLACE_LOCATION, &locationJson), + CONTEXT_PLACES_ERROR_NO_DATA, + _E, + "Parameter empty"); + + double lat; + IF_FAIL_RETURN_TAG( + locationJson.get(NULL, PLACE_LOCATION_LATITUDE, &lat), + CONTEXT_PLACES_ERROR_NO_DATA, + _E, + "Parameter empty"); + + double lon; + IF_FAIL_RETURN_TAG( + locationJson.get(NULL, PLACE_LOCATION_LONGITUDE, &lon), + CONTEXT_PLACES_ERROR_NO_DATA, + _E, + "Parameter empty"); + + double acc; + IF_FAIL_RETURN_TAG( + locationJson.get(NULL, PLACE_LOCATION_ACCURACY, &acc), + CONTEXT_PLACES_ERROR_NO_DATA, + _E, + "Parameter empty"); + + *latitude = lat; + *longitude = lon; + *accuracy = acc; + + return CONTEXT_PLACES_ERROR_NONE; +} + +SO_EXPORT int context_places_place_get_creation_date(context_places_place_h place, time_t* timestamp) +{ + ASSERT_NOT_NULL(place && timestamp); + + int64_t tmp_timestamp; + IF_FAIL_RETURN_TAG( + place->jPlace.get(NULL, PLACE_CREATE_DATE, &tmp_timestamp), + CONTEXT_PLACES_ERROR_NO_DATA, + _E, + "Parameter empty"); + + *timestamp = static_cast(tmp_timestamp); + + return CONTEXT_PLACES_ERROR_NONE; +} + +SO_EXPORT int context_places_place_destroy(context_places_place_h place) +{ + ASSERT_NOT_NULL(place); + + delete place; + + return CONTEXT_PLACES_ERROR_NONE; +} + +SO_EXPORT int context_places_place_get_wifi_ap_list(context_places_place_h place, context_places_wifi_ap_list_h* list) +{ + ASSERT_NOT_NULL(place && list); + *list = NULL; + + ctx::Json tmp_list; + IF_FAIL_RETURN_TAG( + place->jPlace.get(NULL, PLACE_WIFI_APS, &tmp_list), + CONTEXT_PLACES_ERROR_NO_DATA, + _E, + "No data"); + + IF_FAIL_RETURN_TAG( + tmp_list.getSize(NULL, PLACE_WIFI_APS) > 0, + CONTEXT_PLACES_ERROR_NO_DATA, + _D, + "No data"); + + *list = new(std::nothrow) _context_places_wifi_ap_list_handle_s(); + ASSERT_ALLOC(*list); + (*list)->jList = tmp_list; + (*list)->current = 0; + + return CONTEXT_PLACES_ERROR_NONE; +} + +SO_EXPORT int context_places_wifi_ap_list_get_count(context_places_wifi_ap_list_h list, int* count) +{ + ASSERT_NOT_NULL(list && count); + *count = 0; + + int result = list->jList.getSize(NULL, PLACE_WIFI_APS); + IF_FAIL_RETURN(result > 0, CONTEXT_PLACES_ERROR_OPERATION_FAILED); + + *count = result; + + return CONTEXT_PLACES_ERROR_NONE; +} + +SO_EXPORT int context_places_wifi_ap_list_get_current(context_places_wifi_ap_list_h list, char** bssid, char** essid) +{ + ASSERT_NOT_NULL(list && bssid && essid); + + ctx::Json wifiAPJson; + IF_FAIL_RETURN_TAG( + list->jList.getAt(NULL, PLACE_WIFI_APS, list->current, &wifiAPJson), + CONTEXT_PLACES_ERROR_OPERATION_FAILED, + _E, + "Place Wifi AP load failed"); + + std::string bssid_str; + IF_FAIL_RETURN_TAG( + wifiAPJson.get(NULL, PLACE_WIFI_AP_MAC, &bssid_str), + CONTEXT_PLACES_ERROR_NO_DATA, + _E, + "Parameter empty"); + + std::string essid_str; + IF_FAIL_RETURN_TAG( + wifiAPJson.get(NULL, PLACE_WIFI_AP_NETWORK_NAME, &essid_str), + CONTEXT_PLACES_ERROR_NO_DATA, + _E, + "Parameter empty"); + + *bssid = g_strdup(bssid_str.c_str()); + ASSERT_ALLOC(*bssid); + + *essid = g_strdup(essid_str.c_str()); + ASSERT_ALLOC(*essid); + + return CONTEXT_PLACES_ERROR_NONE; +} + +SO_EXPORT int context_places_wifi_ap_list_move_first(context_places_wifi_ap_list_h list) +{ + ASSERT_NOT_NULL(list); + + list->current = 0; + + return CONTEXT_PLACES_ERROR_NONE; +} + +SO_EXPORT int context_places_wifi_ap_list_move_next(context_places_wifi_ap_list_h list) +{ + ASSERT_NOT_NULL(list); + + IF_FAIL_RETURN_TAG( + list->current+1 < list->jList.getSize(NULL, PLACE_WIFI_APS), + CONTEXT_PLACES_ERROR_NO_DATA, + _D, + "End of list"); + + list->current++; + + return CONTEXT_PLACES_ERROR_NONE; +} + +SO_EXPORT int context_places_wifi_ap_list_destroy(context_places_wifi_ap_list_h list) +{ + ASSERT_NOT_NULL(list); + + delete list; + + return CONTEXT_PLACES_ERROR_NONE; +} + +SO_EXPORT int context_places_is_supported(bool *supported) +{ + ctx::DBusClient dbusClient; + int error = dbusClient.isSupported(PLACE_DETECTION_SUBJECT); + if (error == ERR_NONE) { + *supported = true; + } else if (error == ERR_NOT_SUPPORTED) { + *supported = false; + } else { + *supported = false; + _E("Getting supported value failed"); + return CONTEXT_PLACES_ERROR_OPERATION_FAILED; + } + _D(""); + return CONTEXT_PLACES_ERROR_NONE; +} + +SO_EXPORT int context_places_consent(bool consent) +{ + _D(""); + ctx::Json option; + option.set(NULL, PLACE_DETECTION_REQUEST_CONSENT, consent ? MYPLACE_SETTING_VALUE_TRUE : MYPLACE_SETTING_VALUE_FALSE); + ctx::DBusClient dbusClient; + int error = dbusClient.write(PLACE_DETECTION_SUBJECT, option); + IF_FAIL_RETURN_TAG( + error == ERR_NONE, + CONTEXT_PLACES_ERROR_OPERATION_FAILED, + _E, + "Setting consent value failed"); + + return CONTEXT_PLACES_ERROR_NONE; +} + +SO_EXPORT int context_places_is_consented(bool *consented) +{ + _D(""); + ctx::Json option; + option.set(NULL, PLACE_DETECTION_REQUEST, PLACE_DETECTION_REQUEST_CONSENT); + int req_id; + ctx::Json tmp_cons; + ctx::DBusClient dbusClient; + int ret = dbusClient.readSync(PLACE_DETECTION_SUBJECT, option, &req_id, &tmp_cons); + IF_FAIL_RETURN_TAG( + ret == ERR_NONE, + CONTEXT_PLACES_ERROR_OPERATION_FAILED, + _E, + "Getting consent value failed"); + + std::string value; + IF_FAIL_RETURN_TAG( + tmp_cons.get(NULL, PLACE_DETECTION_REQUEST_CONSENT, &value), + CONTEXT_PLACES_ERROR_OPERATION_FAILED, + _E, + "Getting consent value failed"); + if (value == MYPLACE_SETTING_VALUE_TRUE) { + *consented = true; + } else if (value == MYPLACE_SETTING_VALUE_FALSE) { + *consented = false; + } else { + _E("Invalid %s value = '%s'", PLACE_DETECTION_REQUEST_CONSENT, value.c_str()); + return CONTEXT_PLACES_ERROR_OPERATION_FAILED; + } + + return CONTEXT_PLACES_ERROR_NONE; +}