From 69c977ca4e4d3ce2569cb16828cd9800266116c8 Mon Sep 17 00:00:00 2001 From: Jongmun Woo Date: Mon, 28 Mar 2016 04:39:42 -0700 Subject: [PATCH 01/16] Revert "fix for permission deny of cynara" This reverts commit 0e94dece884b395b199ab658ec7cf307811e69d5. Change-Id: I6f517932abe805f2f7dcbf0fa86bb8be9399ab66 --- module/module_geofence_server.c | 45 ++++++++++++++++------------------------- 1 file changed, 17 insertions(+), 28 deletions(-) diff --git a/module/module_geofence_server.c b/module/module_geofence_server.c index 67678a2..0011ec9 100644 --- a/module/module_geofence_server.c +++ b/module/module_geofence_server.c @@ -53,14 +53,11 @@ EXPORT_API int add_geopoint(void *handle, int place_id, double latitude, double GeofenceManagerData *geofence_manager = (GeofenceManagerData *)handle; g_return_val_if_fail(geofence_manager, GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER); int new_fence_id = -1; - int error_code = GEOFENCE_MANAGER_ERROR_NONE; - new_fence_id = geo_client_add_geofence(geofence_manager->geofence_client, geofence_manager->app_id, place_id, GEOFENCE_TYPE_GEOPOINT, latitude, longitude, radius, address, "", "", &error_code); + new_fence_id = geo_client_add_geofence(geofence_manager->geofence_client, geofence_manager->app_id, place_id, GEOFENCE_TYPE_GEOPOINT, latitude, longitude, radius, address, "", ""); *fence_id = new_fence_id; - if (error_code != GEOFENCE_MANAGER_ERROR_NONE) - return error_code; - else if (new_fence_id == -1) + if (new_fence_id == -1) return GEOFENCE_CLIENT_ERROR_DBUS_CALL; return GEOFENCE_MANAGER_ERROR_NONE; @@ -72,14 +69,11 @@ EXPORT_API int add_bssid(void *handle, int place_id, const char *bssid, const ch GeofenceManagerData *geofence_manager = (GeofenceManagerData *)handle; g_return_val_if_fail(geofence_manager, GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER); int new_fence_id = -1; - int error_code = GEOFENCE_MANAGER_ERROR_NONE; - new_fence_id = geo_client_add_geofence(geofence_manager->geofence_client, geofence_manager->app_id, place_id, type, -1, -1, -1, "", bssid, ssid, &error_code); + new_fence_id = geo_client_add_geofence(geofence_manager->geofence_client, geofence_manager->app_id, place_id, type, -1, -1, -1, "", bssid, ssid); *fence_id = new_fence_id; - if (error_code != GEOFENCE_MANAGER_ERROR_NONE) - return error_code; - else if (new_fence_id == -1) + if (new_fence_id == -1) return GEOFENCE_CLIENT_ERROR_DBUS_CALL; return GEOFENCE_MANAGER_ERROR_NONE; @@ -91,14 +85,11 @@ EXPORT_API int add_place(void *handle, const char *place_name, int *place_id) GeofenceManagerData *geofence_manager = (GeofenceManagerData *)handle; g_return_val_if_fail(geofence_manager, GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER); int new_place_id = -1; - int error_code = GEOFENCE_MANAGER_ERROR_NONE; - new_place_id = geo_client_add_place(geofence_manager->geofence_client, geofence_manager->app_id, place_name, &error_code); + new_place_id = geo_client_add_place(geofence_manager->geofence_client, geofence_manager->app_id, place_name); *place_id = new_place_id; - if (error_code != GEOFENCE_MANAGER_ERROR_NONE) - return error_code; - else if (new_place_id == -1) + if (new_place_id == -1) return GEOFENCE_CLIENT_ERROR_DBUS_CALL; return GEOFENCE_MANAGER_ERROR_NONE; @@ -112,7 +103,7 @@ EXPORT_API int update_place(void *handle, int place_id, const char *place_name) int ret = geo_client_update_place(geofence_manager->geofence_client, geofence_manager->app_id, place_id, place_name); if (ret != GEOFENCE_CLIENT_ERROR_NONE) - return ret; + return GEOFENCE_CLIENT_ERROR_DBUS_CALL; return GEOFENCE_MANAGER_ERROR_NONE; } @@ -125,7 +116,7 @@ EXPORT_API int remove_geofence(void *handle, int fence_id) int ret = geo_client_delete_geofence(geofence_manager->geofence_client, geofence_manager->app_id, fence_id); if (ret != GEOFENCE_CLIENT_ERROR_NONE) - return ret; + return GEOFENCE_CLIENT_ERROR_DBUS_CALL; return GEOFENCE_MANAGER_ERROR_NONE; } @@ -138,7 +129,7 @@ EXPORT_API int remove_place(void *handle, int place_id) int ret = geo_client_delete_place(geofence_manager->geofence_client, geofence_manager->app_id, place_id); if (ret != GEOFENCE_CLIENT_ERROR_NONE) - return ret; + return GEOFENCE_CLIENT_ERROR_DBUS_CALL; return GEOFENCE_MANAGER_ERROR_NONE; } @@ -231,7 +222,7 @@ EXPORT_API int get_place_name(void *handle, int place_id, char **place_name) int error_code = GEOFENCE_MANAGER_ERROR_NONE; int ret = geo_client_get_place_name(geofence_manager->geofence_client, geofence_manager->app_id, place_id, place_name, &error_code); if (ret != GEOFENCE_CLIENT_ERROR_NONE) - return ret; + return GEOFENCE_CLIENT_ERROR_DBUS_CALL; return error_code; } @@ -256,10 +247,10 @@ EXPORT_API int get_geofences(void *handle, int place_id, int *fence_amount, int int error_code = GEOFENCE_MANAGER_ERROR_NONE; int ret = geo_client_get_geofences(geofence_manager->geofence_client, geofence_manager->app_id, place_id, &iter, &fence_cnt, &error_code); - if (ret != GEOFENCE_MANAGER_ERROR_NONE) - return ret; - else if (error_code != GEOFENCE_MANAGER_ERROR_NONE) + if (error_code != GEOFENCE_MANAGER_ERROR_NONE) return error_code; + else if (ret != GEOFENCE_MANAGER_ERROR_NONE) + return GEOFENCE_CLIENT_ERROR_DBUS_CALL; *fence_amount = fence_cnt; MOD_LOGD("Total fence count : %d", *fence_amount); @@ -319,12 +310,10 @@ EXPORT_API int get_places(void *handle, int *place_amount, int **place_ids, plac gchar *key; GVariant *value; int place_cnt = 0; - int error_code = GEOFENCE_MANAGER_ERROR_NONE; + int error_code = -1; /*Call the geofence_client api here....*/ - int ret = geo_client_get_places(geofence_manager->geofence_client, geofence_manager->app_id, &iter, &place_cnt, &error_code); - if (ret != GEOFENCE_MANAGER_ERROR_NONE) - return ret; + geo_client_get_places(geofence_manager->geofence_client, geofence_manager->app_id, &iter, &place_cnt, &error_code); if (error_code != GEOFENCE_MANAGER_ERROR_NONE) return error_code; @@ -385,7 +374,7 @@ EXPORT_API int start_geofence(void *handle, int fence_id) ret = geo_client_start_geofence(geofence_manager->geofence_client, geofence_manager->app_id, fence_id); if (ret != GEOFENCE_MANAGER_ERROR_NONE) { MOD_LOGE("Fail to start geofence_client_h. Error[%d]", ret); - return ret; + return GEOFENCE_CLIENT_ERROR_DBUS_CALL; } return GEOFENCE_MANAGER_ERROR_NONE; @@ -403,7 +392,7 @@ EXPORT_API int stop_geofence(void *handle, int fence_id) ret = geo_client_stop_geofence(geofence_manager->geofence_client, geofence_manager->app_id, fence_id); if (ret != GEOFENCE_MANAGER_ERROR_NONE) { MOD_LOGE("Fail to stop. Error[%d]", ret); - return ret; + return GEOFENCE_CLIENT_ERROR_DBUS_CALL; } return GEOFENCE_MANAGER_ERROR_NONE; -- 2.7.4 From bbd99845d0b0eb60eeb659fc21d96cfd462eb4dd Mon Sep 17 00:00:00 2001 From: "jongmun.woo" Date: Fri, 25 Mar 2016 16:44:29 +0900 Subject: [PATCH 02/16] fix svace warnings Signed-off-by: jongmun.woo Change-Id: Ifd16a4bba331f2d50e90ad4df87a2e579db0173a --- geofence-server/src/geofence_server.c | 19 +++++++++++++++++-- geofence-server/src/geofence_server_bluetooth.c | 3 ++- geofence-server/src/geofence_server_db.c | 3 +++ geofence-server/src/geofence_server_wifi.c | 3 ++- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/geofence-server/src/geofence_server.c b/geofence-server/src/geofence_server.c index 61f3562..49f8a36 100644 --- a/geofence-server/src/geofence_server.c +++ b/geofence-server/src/geofence_server.c @@ -148,7 +148,7 @@ static void bt_le_scan_result_cb(int result, bt_adapter_le_device_scan_result_in int ret = BT_ERROR_NONE; GeofenceServer *geofence_server = (GeofenceServer *) user_data; LOGI_GEOFENCE("Current addresses: %s", geofence_server->ble_info); - LOGI_GEOFENCE("Received address: %s", info->remote_address); + if (info == NULL) { LOGI_GEOFENCE("Stopping scan as there is no BLE addresses found"); ret = bt_adapter_le_stop_scan(); @@ -156,6 +156,8 @@ static void bt_le_scan_result_cb(int result, bt_adapter_le_device_scan_result_in LOGE_GEOFENCE("Unable to stop the BLE scan, error: %d", ret); return; } + LOGI_GEOFENCE("Received address: %s", info->remote_address); + /* Retrieve the information about the AP */ if (!g_ascii_strcasecmp(geofence_server->ble_info, "")) { g_stpcpy(geofence_server->ble_info, info->remote_address); @@ -210,6 +212,10 @@ void bt_le_scan_result_display_cb(int result, bt_adapter_le_device_scan_result_i ble_proximity_mode = BLE_INFO_NONE; fence_id = GPOINTER_TO_INT(tracking_list->data); GeofenceItemData *item_data = __get_item_by_fence_id(fence_id, geofence_server); + if (item_data == NULL) { + LOGD_GEOFENCE("Invalid item_data"); + return; + } if (item_data->common_info.type == GEOFENCE_TYPE_GEOPOINT) { vconf_get_int(VCONFKEY_LOCATION_NETWORK_ENABLED, &wps_state); vconf_get_int(VCONFKEY_LOCATION_ENABLED, &gps_state); @@ -1584,6 +1590,7 @@ static int dbus_add_fence_cb(const gchar *app_id, if (geocoordinate_info == NULL) { LOGI_GEOFENCE("Fail to set geocoordinate_info for GPS because of malloc fail"); __emit_fence_event(geofence_server, place_id, -1, ACCESS_TYPE_UNKNOWN, app_id, GEOFENCE_SERVER_ERROR_OUT_OF_MEMORY, GEOFENCE_MANAGE_FENCE_ADDED); + g_free(item_data); return -1; } geocoordinate_info->latitude = latitude; @@ -1603,6 +1610,8 @@ static int dbus_add_fence_cb(const gchar *app_id, if (ret != FENCE_ERR_NONE) LOGI_GEOFENCE("Fail to delete fence_id[%d] from common table", fence_id); __emit_fence_event(geofence_server, place_id, -1, ACCESS_TYPE_UNKNOWN, app_id, GEOFENCE_SERVER_ERROR_DATABASE, GEOFENCE_MANAGE_FENCE_ADDED); + g_free(geocoordinate_info); + g_free(item_data); return -1; } item_data->priv = (void *) geocoordinate_info; @@ -1615,6 +1624,7 @@ static int dbus_add_fence_cb(const gchar *app_id, if (wifi_info == NULL) { LOGI_GEOFENCE("Fail to set bssid_info for wifi because of malloc fail"); __emit_fence_event(geofence_server, place_id, -1, ACCESS_TYPE_UNKNOWN, app_id, GEOFENCE_SERVER_ERROR_OUT_OF_MEMORY, GEOFENCE_MANAGE_FENCE_ADDED); + g_free(item_data); return -1; } g_strlcpy(wifi_info->bssid, bssid, WLAN_BSSID_LEN); @@ -1628,6 +1638,8 @@ static int dbus_add_fence_cb(const gchar *app_id, if (ret != FENCE_ERR_NONE) LOGI_GEOFENCE("Fail to delete fence_id[%d] from common table", fence_id); __emit_fence_event(geofence_server, place_id, -1, ACCESS_TYPE_UNKNOWN, app_id, GEOFENCE_SERVER_ERROR_DATABASE, GEOFENCE_MANAGE_FENCE_ADDED); + g_free(wifi_info); + g_free(item_data); return -1; } item_data->priv = (void *) wifi_info; @@ -1639,6 +1651,7 @@ static int dbus_add_fence_cb(const gchar *app_id, if (bt_info == NULL) { LOGI_GEOFENCE("Fail to set bssid_info for BT because of malloc fail"); __emit_fence_event(geofence_server, place_id, -1, ACCESS_TYPE_UNKNOWN, app_id, GEOFENCE_SERVER_ERROR_OUT_OF_MEMORY, GEOFENCE_MANAGE_FENCE_ADDED); + g_free(item_data); return -1; } bt_info->enabled = TRUE; @@ -1653,6 +1666,8 @@ static int dbus_add_fence_cb(const gchar *app_id, if (ret != FENCE_ERR_NONE) LOGI_GEOFENCE("Fail to delete fence_id[%d] from common table", fence_id); __emit_fence_event(geofence_server, place_id, -1, ACCESS_TYPE_UNKNOWN, app_id, GEOFENCE_SERVER_ERROR_DATABASE, GEOFENCE_MANAGE_FENCE_ADDED); + g_free(bt_info); + g_free(item_data); return -1; } item_data->priv = (void *) bt_info; @@ -2419,7 +2434,7 @@ static void __activity_cb(activity_type_e type, const activity_data_h data, doub { FUNC_ENTRANCE_SERVER GeofenceServer *geofence_server = (GeofenceServer *)user_data; - activity_accuracy_e accuracy; + activity_accuracy_e accuracy = ACTIVITY_ACCURACY_LOW; int result = ACTIVITY_ERROR_NONE; if (error != ACTIVITY_ERROR_NONE) { diff --git a/geofence-server/src/geofence_server_bluetooth.c b/geofence-server/src/geofence_server_bluetooth.c index ab79233..130f55c 100644 --- a/geofence-server/src/geofence_server_bluetooth.c +++ b/geofence-server/src/geofence_server_bluetooth.c @@ -50,7 +50,6 @@ static void bt_le_scan_result_cb(int result, bt_adapter_le_device_scan_result_in int ret = BT_ERROR_NONE; GeofenceServer *geofence_server = (GeofenceServer *) user_data; LOGI_GEOFENCE("Current addresses: %s", geofence_server->ble_info); - LOGI_GEOFENCE("Received address: %s", info->remote_address); if (info == NULL) { LOGI_GEOFENCE("Stopping scan as there is no BLE address found"); @@ -59,6 +58,8 @@ static void bt_le_scan_result_cb(int result, bt_adapter_le_device_scan_result_in LOGE_GEOFENCE("Unable to stop the BLE scan, error: %d", ret); return; } + LOGI_GEOFENCE("Received address: %s", info->remote_address); + if (!g_ascii_strcasecmp(geofence_server->ble_info, "")) { g_stpcpy(geofence_server->ble_info, info->remote_address); } else if (!__check_for_match(geofence_server->ble_info, info->remote_address)) { /* If duplicate does not exist */ diff --git a/geofence-server/src/geofence_server_db.c b/geofence-server/src/geofence_server_db.c index 5d11e96..1ef3378 100755 --- a/geofence-server/src/geofence_server_db.c +++ b/geofence-server/src/geofence_server_db.c @@ -788,6 +788,8 @@ int geofence_manager_set_place_info(place_info_s *place_info, int *place_id) ret = sqlite3_prepare_v2(db_info_s.handle, query, -1, &state, &tail); if (ret != SQLITE_OK) { LOGI_GEOFENCE("Error: %s", sqlite3_errmsg(db_info_s.handle)); + g_free(place_name); + g_free(appid); sqlite3_free(query); return FENCE_ERR_PREPARE; } @@ -845,6 +847,7 @@ int geofence_manager_set_common_info(fence_common_info_s *fence_info, int *fence ret = sqlite3_prepare_v2(db_info_s.handle, query, -1, &state, &tail); if (ret != SQLITE_OK) { LOGI_GEOFENCE("Error: %s", sqlite3_errmsg(db_info_s.handle)); + g_free(appid); sqlite3_free(query); return FENCE_ERR_PREPARE; } diff --git a/geofence-server/src/geofence_server_wifi.c b/geofence-server/src/geofence_server_wifi.c index 6587333..82463ed 100644 --- a/geofence-server/src/geofence_server_wifi.c +++ b/geofence-server/src/geofence_server_wifi.c @@ -70,7 +70,6 @@ static void bt_le_scan_result_cb(int result, bt_adapter_le_device_scan_result_in int ret = BT_ERROR_NONE; GeofenceServer *geofence_server = (GeofenceServer *) user_data; LOGI_GEOFENCE("Current addresses: %s", geofence_server->ble_info); - LOGI_GEOFENCE("Received address: %s", info->remote_address); if (info == NULL) { LOGI_GEOFENCE("Stopping scan as there is no BLE address found"); @@ -79,6 +78,8 @@ static void bt_le_scan_result_cb(int result, bt_adapter_le_device_scan_result_in LOGE_GEOFENCE("Unable to stop the BLE scan, error: %d", ret); return; } + LOGI_GEOFENCE("Received address: %s", info->remote_address); + if (!g_ascii_strcasecmp(geofence_server->ble_info, "")) { g_stpcpy(geofence_server->ble_info, info->remote_address); } else if (!__check_for_match(geofence_server->ble_info, info->remote_address)) { /* If duplicate does not exist */ -- 2.7.4 From e9c55fcffb33a75891cb0e854111ef6e0f4d93f4 Mon Sep 17 00:00:00 2001 From: "jongmun.woo" Date: Mon, 28 Mar 2016 20:55:26 +0900 Subject: [PATCH 03/16] 1.fix for permission deny of cynara 2.modify as Coding convention 3.fix svace issues Signed-off-by: jongmun.woo Change-Id: I56f3338ee9289a87f5162128a2dacbfe208e817f --- geofence-server/src/geofence_server.c | 319 +++++++++++------------- geofence-server/src/geofence_server_alarm.c | 6 +- geofence-server/src/geofence_server_bluetooth.c | 14 +- geofence-server/src/geofence_server_db.c | 145 ++++------- geofence-server/src/geofence_server_wifi.c | 3 +- geofence-server/src/server.c | 30 +-- module/module_geofence_server.c | 64 +++-- packaging/geofence-server.spec | 2 +- 8 files changed, 245 insertions(+), 338 deletions(-) diff --git a/geofence-server/src/geofence_server.c b/geofence-server/src/geofence_server.c index 49f8a36..de4cc3f 100644 --- a/geofence-server/src/geofence_server.c +++ b/geofence-server/src/geofence_server.c @@ -75,9 +75,8 @@ static bool __is_support_wps() const char *wps_feature = "http://tizen.org/feature/location.wps"; bool is_wps_supported = false; system_info_get_platform_bool(wps_feature, &is_wps_supported); - if (is_wps_supported == true) { + if (is_wps_supported == true) location_manager_is_enabled_method(LOCATIONS_METHOD_WPS, &is_wps_supported); - } return is_wps_supported; } @@ -85,38 +84,38 @@ static bool __is_support_wps() static const char *__convert_wifi_error_to_string(wifi_error_e err_type) { switch (err_type) { - case WIFI_ERROR_NONE: - return "NONE"; - case WIFI_ERROR_INVALID_PARAMETER: - return "INVALID_PARAMETER"; - case WIFI_ERROR_OUT_OF_MEMORY: - return "OUT_OF_MEMORY"; - case WIFI_ERROR_INVALID_OPERATION: - return "INVALID_OPERATION"; - case WIFI_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED: - return "ADDRESS_FAMILY_NOT_SUPPORTED"; - case WIFI_ERROR_OPERATION_FAILED: - return "OPERATION_FAILED"; - case WIFI_ERROR_NO_CONNECTION: - return "NO_CONNECTION"; - case WIFI_ERROR_NOW_IN_PROGRESS: - return "NOW_IN_PROGRESS"; - case WIFI_ERROR_ALREADY_EXISTS: - return "ALREADY_EXISTS"; - case WIFI_ERROR_OPERATION_ABORTED: - return "OPERATION_ABORTED"; - case WIFI_ERROR_DHCP_FAILED: - return "DHCP_FAILED"; - case WIFI_ERROR_INVALID_KEY: - return "INVALID_KEY"; - case WIFI_ERROR_NO_REPLY: - return "NO_REPLY"; - case WIFI_ERROR_SECURITY_RESTRICTED: - return "SECURITY_RESTRICTED"; - case WIFI_ERROR_PERMISSION_DENIED: - return "PERMISSION_DENIED"; - default: - return "NOT Defined"; + case WIFI_ERROR_NONE: + return "NONE"; + case WIFI_ERROR_INVALID_PARAMETER: + return "INVALID_PARAMETER"; + case WIFI_ERROR_OUT_OF_MEMORY: + return "OUT_OF_MEMORY"; + case WIFI_ERROR_INVALID_OPERATION: + return "INVALID_OPERATION"; + case WIFI_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED: + return "ADDRESS_FAMILY_NOT_SUPPORTED"; + case WIFI_ERROR_OPERATION_FAILED: + return "OPERATION_FAILED"; + case WIFI_ERROR_NO_CONNECTION: + return "NO_CONNECTION"; + case WIFI_ERROR_NOW_IN_PROGRESS: + return "NOW_IN_PROGRESS"; + case WIFI_ERROR_ALREADY_EXISTS: + return "ALREADY_EXISTS"; + case WIFI_ERROR_OPERATION_ABORTED: + return "OPERATION_ABORTED"; + case WIFI_ERROR_DHCP_FAILED: + return "DHCP_FAILED"; + case WIFI_ERROR_INVALID_KEY: + return "INVALID_KEY"; + case WIFI_ERROR_NO_REPLY: + return "NO_REPLY"; + case WIFI_ERROR_SECURITY_RESTRICTED: + return "SECURITY_RESTRICTED"; + case WIFI_ERROR_PERMISSION_DENIED: + return "PERMISSION_DENIED"; + default: + return "NOT Defined"; } } @@ -266,9 +265,9 @@ void device_display_changed_cb(device_callback_e type, void *value, void *user_d LOGD_GEOFENCE("Scanning for BLE and read DB"); g_stpcpy(geofence_server->ble_info, ""); ret = bt_adapter_le_start_scan(bt_le_scan_result_display_cb, geofence_server); - if (ret != BT_ERROR_NONE) { + if (ret != BT_ERROR_NONE) LOGE_GEOFENCE("Fail to start ble scan. %d", ret); - } + } } else if (state == DISPLAY_STATE_SCREEN_DIM) LOGI_GEOFENCE("State: DIM"); @@ -306,9 +305,9 @@ static int __emit_fence_inout(GeofenceServer *geofence_server, int fence_id, geo /*LOGD_GEOFENCE("FENCE_IN to be set, current state: %d", item_data->common_info.status);*/ if (item_data->common_info.status != GEOFENCE_FENCE_STATE_IN) { geofence_dbus_server_send_geofence_inout_changed(geofence_server->geofence_dbus_server, item_data->common_info.appid, fence_id, item_data->common_info.access_type, GEOFENCE_EMIT_STATE_IN); - if (item_data->client_status == GEOFENCE_CLIENT_STATUS_START) { + if (item_data->client_status == GEOFENCE_CLIENT_STATUS_START) item_data->client_status = GEOFENCE_CLIENT_STATUS_RUNNING; - } + LOGD_GEOFENCE("%d : FENCE_IN", fence_id); #ifdef TIZEN_ENGINEER_MODE GEOFENCE_PRINT_LOG("FENCE_IN"); @@ -322,9 +321,9 @@ static int __emit_fence_inout(GeofenceServer *geofence_server, int fence_id, geo if (item_data->common_info.status != GEOFENCE_FENCE_STATE_OUT) { geofence_dbus_server_send_geofence_inout_changed(geofence_server->geofence_dbus_server, item_data->common_info.appid, fence_id, item_data->common_info.access_type, GEOFENCE_EMIT_STATE_OUT); __emit_fence_proximity(geofence_server, fence_id, GEOFENCE_PROXIMITY_UNCERTAIN); - if (item_data->client_status == GEOFENCE_CLIENT_STATUS_START) { + if (item_data->client_status == GEOFENCE_CLIENT_STATUS_START) item_data->client_status = GEOFENCE_CLIENT_STATUS_RUNNING; - } + LOGD_GEOFENCE("%d : FENCE_OUT", fence_id); #ifdef TIZEN_ENGINEER_MODE GEOFENCE_PRINT_LOG("FENCE_OUT"); @@ -347,11 +346,11 @@ static int __emit_fence_proximity(GeofenceServer *geofence_server, int fence_id, geofence_proximity_provider_e provider = GEOFENCE_PROXIMITY_PROVIDER_LOCATION; GeofenceItemData *item_data = __get_item_by_fence_id(fence_id, geofence_server); if (item_data) { - if (item_data->common_info.type == GEOFENCE_TYPE_WIFI) { + if (item_data->common_info.type == GEOFENCE_TYPE_WIFI) provider = GEOFENCE_PROXIMITY_PROVIDER_WIFI; - } else if (item_data->common_info.type == GEOFENCE_TYPE_BT) { + else if (item_data->common_info.type == GEOFENCE_TYPE_BT) provider = GEOFENCE_PROXIMITY_PROVIDER_BLUETOOTH; - } + geofence_dbus_server_send_geofence_proximity_changed(geofence_server->geofence_dbus_server, item_data->common_info.appid, fence_id, item_data->common_info.access_type, state, provider); item_data->common_info.proximity_status = state; } else { @@ -367,13 +366,13 @@ static void __check_proximity_for_fence(double distance, int fence_id, int radiu int ret = BT_ERROR_NONE; geofence_proximity_state_e state = GEOFENCE_PROXIMITY_UNCERTAIN; GeofenceServer *geofence_server = (GeofenceServer *) user_data; - if (distance <= 50.0) { + if (distance <= 50.0) state = GEOFENCE_PROXIMITY_IMMEDIATE; - } else if (distance > 50.0 && distance <= 100.0) { + else if (distance > 50.0 && distance <= 100.0) state = GEOFENCE_PROXIMITY_NEAR; - } else if (distance > 100.0 && distance <= radius) { + else if (distance > 100.0 && distance <= radius) state = GEOFENCE_PROXIMITY_FAR; - } + if (current_state != state) { LOGD_GEOFENCE("PROXIMITY ALERTING for fence: %d, alert: %d, distance: %f", fence_id, state, distance); __emit_fence_proximity(geofence_server, fence_id, state); @@ -382,9 +381,8 @@ static void __check_proximity_for_fence(double distance, int fence_id, int radiu LOGD_GEOFENCE("Scanning for BLE and storing in DB"); g_stpcpy(geofence_server->ble_info, ""); ret = bt_adapter_le_start_scan(bt_le_scan_result_cb, geofence_server); - if (ret != BT_ERROR_NONE) { + if (ret != BT_ERROR_NONE) LOGE_GEOFENCE("Fail to start ble scan. %d", ret); - } } else if (current_state == GEOFENCE_PROXIMITY_IMMEDIATE) { /* Stopping the scan if state changes */ ret = bt_adapter_le_stop_scan(); if (ret != BT_ERROR_NONE) @@ -421,9 +419,8 @@ static void __check_inout_by_gps(double latitude, double longitude, int fence_id __check_proximity_for_fence(distance, item_data->common_info.fence_id, geocoordinate_info->radius, item_data->common_info.proximity_status, geofence_server); /*}*/ - if (__emit_fence_inout(geofence_server, item_data->common_info.fence_id, status) == 0 && status == GEOFENCE_FENCE_STATE_IN) { + if (__emit_fence_inout(geofence_server, item_data->common_info.fence_id, status) == 0 && status == GEOFENCE_FENCE_STATE_IN) LOGD_GEOFENCE("Disable timer"); - } } static void __stop_gps_alarms(void *user_data) @@ -570,21 +567,18 @@ static void __stop_gps_positioning(gpointer userdata) int ret = 0; if (geofence_server->loc_gps_started == TRUE) { ret = location_manager_stop(geofence_server->loc_gps_manager); - if (ret != LOCATIONS_ERROR_NONE) { + if (ret != LOCATIONS_ERROR_NONE) return; - } geofence_server->loc_gps_started = FALSE; ret = location_manager_unset_position_updated_cb(geofence_server->loc_gps_manager); - if (ret != LOCATIONS_ERROR_NONE) { + if (ret != LOCATIONS_ERROR_NONE) return; - } } if (geofence_server->loc_gps_manager != NULL) { ret = location_manager_destroy(geofence_server->loc_gps_manager); - if (ret != LOCATIONS_ERROR_NONE) { + if (ret != LOCATIONS_ERROR_NONE) return; - } geofence_server->loc_gps_manager = NULL; } } @@ -634,7 +628,7 @@ static void __process_best_location(GeofenceServer *geofence_server) int gpsdiff = 0; int wpsdiff = 0; - + /* Check if any of the fix is null just return. It doesn't make sense to compare if only one fix is available*/ if (geofence_server->gps_fix_info == NULL || geofence_server->wps_fix_info == NULL) return; @@ -685,9 +679,9 @@ static void __geofence_standalone_gps_position_changed_cb(double latitude, doubl int ret = LOCATIONS_ERROR_NONE; /* Allocate memory for the location_info structure */ - if (geofence_server->gps_fix_info == NULL) { + if (geofence_server->gps_fix_info == NULL) geofence_server->gps_fix_info = (location_fix_info_s *)g_malloc(sizeof(location_fix_info_s)); - } + /* Store the location information in the structure for future use*/ if (geofence_server->gps_fix_info != NULL) { geofence_server->gps_fix_info->latitude = latitude; @@ -784,9 +778,8 @@ static void __geofence_gps_position_changed_cb(double latitude, double longitude } /* Allocate memory for the location_info structure */ - if (geofence_server->gps_fix_info == NULL) { + if (geofence_server->gps_fix_info == NULL) geofence_server->gps_fix_info = (location_fix_info_s *)g_malloc(sizeof(location_fix_info_s)); - } /* Store the location information in the structure for future use*/ if (geofence_server->gps_fix_info != NULL) { @@ -802,7 +795,7 @@ static void __geofence_gps_position_changed_cb(double latitude, double longitude } else { LOGD_GEOFENCE("Invalid GPS fix data"); return; - } + } geofence_server->last_loc_time = timestamp; if (geofence_server->wps_fix_info && __get_time_diff(geofence_server->wps_fix_info->timestamp) <= 20 && geofence_server->gps_fix_info->accuracy <= 50.0) { @@ -848,9 +841,8 @@ static void __geofence_wps_position_changed_cb(double latitude, double longitude int interval = 0; /* Allocate memory for the location_info structure */ - if (geofence_server->wps_fix_info == NULL) { + if (geofence_server->wps_fix_info == NULL) geofence_server->wps_fix_info = (location_fix_info_s *)g_malloc(sizeof(location_fix_info_s)); - } /*Remove the timeout callback that might be running when requesting for fix.*/ if (geofence_server->wps_timeout_alarm_id != -1) { /*LOGI_GEOFENCE("Removing the timeout alarm from restart gps");*/ @@ -883,18 +875,17 @@ static void __geofence_wps_position_changed_cb(double latitude, double longitude return;/* There is no valid fence with this fence id. So return*/ geocoordinate_info_s *geocoordinate_info = (geocoordinate_info_s *)item_data->priv; - + double interval_dist = (min_distance - geocoordinate_info->radius) - geofence_server->wps_fix_info->accuracy; LOGI_GEOFENCE("Distance for interval: %f", interval_dist); - if (interval_dist < 15000) { + if (interval_dist < 15000) interval = interval_dist/25; /*secs*/ /*Assuming 90 km/hr of speed - So 25 mtrs covered in 1 sec*/ - } else if (interval_dist >= 15000 && interval_dist < 18000) { + else if (interval_dist >= 15000 && interval_dist < 18000) interval = 10 * 60; /* 10 mins */ - } else if (interval_dist >= 18000 && interval_dist < 20000) { + else if (interval_dist >= 18000 && interval_dist < 20000) interval = 12 * 60; /* 12 mins */ - } else if (interval_dist >= 20000) { + else if (interval_dist >= 20000) interval = 15 * 60; /*15 mins*/ - } if (interval < 15) interval = 15; /*15 sec */ @@ -992,11 +983,10 @@ void bt_adapter_device_discovery_state_cb(int result, bt_adapter_device_discover tracking_fences = g_list_next(tracking_fences); item_data = __get_item_by_fence_id(tracking_fence_id, geofence_server); if (item_data && item_data->common_info.type == GEOFENCE_TYPE_BT) { - if (item_data->is_bt_status_in == true) { + if (item_data->is_bt_status_in == true) __emit_fence_inout(geofence_server, item_data->common_info.fence_id, GEOFENCE_FENCE_STATE_IN); - } else { + else __emit_fence_inout(geofence_server, item_data->common_info.fence_id, GEOFENCE_FENCE_STATE_OUT); - } item_data->is_bt_status_in = false; } } @@ -1006,9 +996,8 @@ void bt_adapter_device_discovery_state_cb(int result, bt_adapter_device_discover LOGI_GEOFENCE("rssi: %d is_bonded: %d", discovery_info->rssi, discovery_info->is_bonded); if (geofence_server->running_bt_cnt > 0) { - for (i = 0; i < discovery_info->service_count; i++) { + for (i = 0; i < discovery_info->service_count; i++) LOGI_GEOFENCE("uuid: %s", discovery_info->service_uuid[i]); - } LOGI_GEOFENCE("Tracking list is being checked for the BT geofence"); __check_tracking_list(discovery_info->remote_address, geofence_server, GEOFENCE_TYPE_BT); } @@ -1043,9 +1032,8 @@ static void geofence_network_evt_cb(net_event_info_t *event_cb, void *user_data) } if (gps_state == 1) { ret = __start_gps_positioning(geofence_server, __geofence_standalone_gps_position_changed_cb); - if (ret != FENCE_ERR_NONE) { + if (ret != FENCE_ERR_NONE) LOGE_GEOFENCE("Fail to start standalone gps positioning. Error[%d]", ret); - } } } else { if (__isDataConnected() == true) {/*&& wps_state == 1) {*/ @@ -1056,9 +1044,8 @@ static void geofence_network_evt_cb(net_event_info_t *event_cb, void *user_data) __stop_gps_alarms(geofence_server); /**** Start the WPS as mobile data is connected and wifi and wps are on *******/ ret = __start_wps_positioning(geofence_server, __geofence_wps_position_changed_cb); - if (ret != FENCE_ERR_NONE) { + if (ret != FENCE_ERR_NONE) LOGE_GEOFENCE("Fail to start wps positioning. Error[%d]", ret); - } } } } @@ -1074,11 +1061,10 @@ static void geofence_network_evt_cb(net_event_info_t *event_cb, void *user_data) if (geofence_server->loc_gps_started_by_wps == false && geofence_server->loc_gps_started == true) { __stop_gps_positioning(geofence_server); /*GPS should be stopped only if it is running standalone*/ __stop_gps_alarms(geofence_server); - } + } ret = __start_wps_positioning(geofence_server, __geofence_wps_position_changed_cb); - if (ret != FENCE_ERR_NONE) { + if (ret != FENCE_ERR_NONE) LOGE_GEOFENCE("Fail to start wps positioning. Error[%d]", ret); - } } break; case NET_EVENT_CLOSE_IND: @@ -1093,9 +1079,8 @@ static void geofence_network_evt_cb(net_event_info_t *event_cb, void *user_data) geofence_server->loc_gps_started_by_wps = false; } ret = __start_gps_positioning(geofence_server, __geofence_standalone_gps_position_changed_cb); - if (ret != FENCE_ERR_NONE) { + if (ret != FENCE_ERR_NONE) LOGE_GEOFENCE("Fail to start standalone gps positioning. Error[%d]", ret); - } } break; default: @@ -1112,11 +1097,10 @@ static int __gps_timeout_cb(alarm_id_t alarm_id, void *user_data) geofence_server->gps_timeout_alarm_id = -1; /*resetting the alarm id*/ /*Stop the gps for sometime when there is no fix*/ __stop_gps_positioning(geofence_server); - if (geofence_server->loc_gps_started_by_wps == FALSE) { + if (geofence_server->loc_gps_started_by_wps == FALSE) geofence_server->gps_alarm_id = _geofence_add_alarm(1 * 60, __gps_alarm_cb, geofence_server); - } else { + else geofence_server->loc_gps_started_by_wps = FALSE; - } return 0; } @@ -1134,14 +1118,12 @@ static int __gps_alarm_cb(alarm_id_t alarm_id, void *user_data) } if (geofence_server->loc_gps_started_by_wps == true) { ret = __start_gps_positioning(geofence_server, __geofence_gps_position_changed_cb); - if (ret != FENCE_ERR_NONE) { + if (ret != FENCE_ERR_NONE) LOGE_GEOFENCE("Fail to start gps positioning. Error[%d]", ret); - } } else { ret = __start_gps_positioning(geofence_server, __geofence_standalone_gps_position_changed_cb); - if (ret != FENCE_ERR_NONE) { + if (ret != FENCE_ERR_NONE) LOGE_GEOFENCE("Fail to start standalone gps positioning. Error[%d]", ret); - } } return 0; } @@ -1178,20 +1160,17 @@ static int __wps_alarm_cb(alarm_id_t alarm_id, void *user_data) } if (__is_support_wps() == true && __isWifiOn() == true && __isDataConnected() == true) { ret = __start_wps_positioning(geofence_server, __geofence_wps_position_changed_cb); - if (ret != FENCE_ERR_NONE) { + if (ret != FENCE_ERR_NONE) LOGE_GEOFENCE("Fail to start wps positioning. Error[%d]", ret); - } } else { ret = __start_gps_positioning(geofence_server, __geofence_standalone_gps_position_changed_cb); - if (ret != FENCE_ERR_NONE) { + if (ret != FENCE_ERR_NONE) LOGE_GEOFENCE("Fail to start standalone gps positioning. Error[%d]", ret); - } } return 0; } -static void gps_setting_changed_cb(location_method_e method, bool enable, - void *user_data) +static void gps_setting_changed_cb(location_method_e method, bool enable, void *user_data) { FUNC_ENTRANCE_SERVER; GeofenceServer *geofence_server = (GeofenceServer *) user_data; @@ -1254,9 +1233,8 @@ static void gps_setting_changed_cb(location_method_e method, bool enable, } } } - if (geofence_server->loc_gps_started_by_wps == true) { + if (geofence_server->loc_gps_started_by_wps == true) geofence_server->loc_gps_started_by_wps = false; /*So that WPS will use GPS if needed in its next fix(wps fix)*/ - } } else if (enable == true && geofence_server->running_geopoint_cnt > 0) { if (method == LOCATIONS_METHOD_GPS) { geofence_server->loc_gps_started_by_wps = false; /* So that WPS will use GPS if needed in its next fix(wps fix) */ @@ -1292,9 +1270,8 @@ static void __free_geofence_list(gpointer userdata) GList *tmp_fence_list = g_list_first(geofence_server->geofence_list); while (tmp_fence_list) { GeofenceItemData *tmp_data = (GeofenceItemData *)tmp_fence_list->data; - if (tmp_data) { + if (tmp_data) g_free(tmp_data); - } tmp_fence_list = g_list_next(tmp_fence_list); } geofence_server->geofence_list = NULL; @@ -1382,11 +1359,10 @@ static void __stop_geofence_service(gint fence_id, const gchar *app_id, gpointer ret = __check_fence_permission(fence_id, app_id); if (ret != 1) { LOGE("Permission denied or DB error occured while accessing the fence[%d]", fence_id); - if (ret == 0) { + if (ret == 0) __emit_fence_event(geofence_server, place_id, fence_id, ACCESS_TYPE_UNKNOWN, app_id, GEOFENCE_SERVER_ERROR_GEOFENCE_ACCESS_DENIED, GEOFENCE_MANAGE_FENCE_STOPPED); - } else { + else __emit_fence_event(geofence_server, place_id, fence_id, ACCESS_TYPE_UNKNOWN, app_id, GEOFENCE_SERVER_ERROR_DATABASE, GEOFENCE_MANAGE_FENCE_STOPPED); - } return; } ret = geofence_manager_get_running_status(fence_id, &tracking_status); @@ -1442,10 +1418,6 @@ static void __stop_geofence_service(gint fence_id, const gchar *app_id, gpointer } else if (item_data->common_info.type == GEOFENCE_TYPE_BT) { geofence_server->running_bt_cnt--; LOGI_GEOFENCE("Removed bt fence: %d from tracking list", fence_id); - - if (geofence_server->running_bt_cnt <= 0) { - /*May be unsetting the cb for bt discovery can be done here*/ - } } else if (item_data->common_info.type == GEOFENCE_TYPE_WIFI) { /*NOTHING NEED TO BE DONE HERE EXCEPT DECREMENTING THE COUNT*/ geofence_server->running_wifi_cnt--; @@ -1483,8 +1455,8 @@ static bool __isWifiOn(void) { int network_state = -1; vconf_get_int(VCONFKEY_WIFI_STATE, &network_state); - if (network_state == 0) - return false; + if (network_state == 0) + return false; return true; } @@ -1507,8 +1479,8 @@ static bool __isDataConnected(void) if (network_state == VCONFKEY_NETWORK_CELLULAR_ON) { rv = vconf_get_int(VCONFKEY_DNET_STATE, &data_state); if (data_state == VCONFKEY_DNET_NORMAL_CONNECTED) { - LOGI_GEOFENCE("USING MOBILE DATA"); - isDataConnected = true; + LOGI_GEOFENCE("USING MOBILE DATA"); + isDataConnected = true; } } } @@ -1517,13 +1489,13 @@ static bool __isDataConnected(void) } static int dbus_add_fence_cb(const gchar *app_id, - gint place_id, - gint geofence_type, - gdouble latitude, - gdouble longitude, - gint radius, - const gchar *address, - const gchar *bssid, const gchar *ssid, gpointer userdata) + gint place_id, + gint geofence_type, + gdouble latitude, + gdouble longitude, + gint radius, + const gchar *address, + const gchar *bssid, const gchar *ssid, gpointer userdata) { FUNC_ENTRANCE_SERVER; GeofenceServer *geofence_server = (GeofenceServer *) userdata; @@ -1546,11 +1518,10 @@ static int dbus_add_fence_cb(const gchar *app_id, ret = __check_place_permission(place_id, app_id); if (ret != 1) { LOGE("Unable to add the fence. Permission denied or DB error occured while accessing the place[%d]", place_id); - if (ret == 0) { + if (ret == 0) __emit_fence_event(geofence_server, place_id, fence_id, ACCESS_TYPE_UNKNOWN, app_id, GEOFENCE_SERVER_ERROR_GEOFENCE_ACCESS_DENIED, GEOFENCE_MANAGE_FENCE_ADDED); - } else { + else __emit_fence_event(geofence_server, place_id, fence_id, ACCESS_TYPE_UNKNOWN, app_id, GEOFENCE_SERVER_ERROR_DATABASE, GEOFENCE_MANAGE_FENCE_ADDED); - } return -1; } /* create GeofenceItemData item, and append it into geofence_list*/ @@ -1565,11 +1536,10 @@ static int dbus_add_fence_cb(const gchar *app_id, item_data->client_status = GEOFENCE_CLIENT_STATUS_NONE; item_data->common_info.type = geofence_type; /*fences added by myplaces application are public fences by default*/ - if (!g_strcmp0(app_id, MYPLACES_APPID)) { + if (!g_strcmp0(app_id, MYPLACES_APPID)) item_data->common_info.access_type = ACCESS_TYPE_PUBLIC; - } else { + else item_data->common_info.access_type = ACCESS_TYPE_PRIVATE; - } item_data->common_info.enable = 1; item_data->common_info.status = GEOFENCE_FENCE_STATE_UNCERTAIN; item_data->common_info.proximity_status = GEOFENCE_PROXIMITY_UNCERTAIN; @@ -1595,11 +1565,10 @@ static int dbus_add_fence_cb(const gchar *app_id, } geocoordinate_info->latitude = latitude; geocoordinate_info->longitude = longitude; - if (radius < GEOFENCE_DEFAULT_RADIUS) { + if (radius < GEOFENCE_DEFAULT_RADIUS) geocoordinate_info->radius = GEOFENCE_DEFAULT_RADIUS; - } else { + else geocoordinate_info->radius = radius; - } g_strlcpy(geocoordinate_info->address, address, ADDRESS_LEN); /*Geopoint information is saved in the DB*/ @@ -1673,11 +1642,10 @@ static int dbus_add_fence_cb(const gchar *app_id, item_data->priv = (void *) bt_info; } /*Adding the data to the geofence_list which contains the added geofences list information*/ - if (geofence_server->geofence_list == NULL) { + if (geofence_server->geofence_list == NULL) geofence_server->geofence_list = g_list_append(geofence_server->geofence_list, item_data); - } else { + else geofence_server->geofence_list = g_list_insert_before(geofence_server->geofence_list, next_item_ptr, item_data); - } /*This code is just for testing purpose. It will be removed after the development phase - Karthik*/ int temp_cnt = 0; GList *temp_list = g_list_first(geofence_server->geofence_list); @@ -1695,8 +1663,7 @@ static int dbus_add_fence_cb(const gchar *app_id, return fence_id; } -static int dbus_add_place_cb(const gchar *app_id, - const gchar *place_name, gpointer userdata) +static int dbus_add_place_cb(const gchar *app_id, const gchar *place_name, gpointer userdata) { FUNC_ENTRANCE_SERVER; int place_id = -1; @@ -1923,11 +1890,10 @@ static void dbus_get_place_name_cb(gint place_id, const gchar *app_id, char **pl ret = __check_place_permission(place_id, app_id); if (ret != 1) { LOGE("Unable to get the place name. Permission denied or DB error occured while accessing the place[%d]", place_id); - if (ret == 0) { + if (ret == 0) *error_code = GEOFENCE_SERVER_ERROR_PLACE_ACCESS_DENIED; - } else { + else *error_code = GEOFENCE_SERVER_ERROR_DATABASE; - } return; } ret = geofence_manager_get_place_name(place_id, place_name); @@ -1938,8 +1904,7 @@ static void dbus_get_place_name_cb(gint place_id, const gchar *app_id, char **pl *error_code = GEOFENCE_SERVER_ERROR_NONE; } -static void dbus_remove_place_cb(gint place_id, const gchar *app_id, - gpointer userdata) +static void dbus_remove_place_cb(gint place_id, const gchar *app_id, gpointer userdata) { FUNC_ENTRANCE_SERVER; g_return_if_fail(userdata); @@ -2114,8 +2079,7 @@ static void dbus_start_geofence_cb(gint fence_id, const gchar *app_id, gpointer return; } if (enable == 0) { - LOGI_GEOFENCE("Error - Fence[%d] is not enabled", - fence_id); + LOGI_GEOFENCE("Error - Fence[%d] is not enabled", fence_id); __emit_fence_event(geofence_server, place_id, fence_id, ACCESS_TYPE_UNKNOWN, app_id, GEOFENCE_SERVER_ERROR_GEOFENCE_ACCESS_DENIED, GEOFENCE_MANAGE_FENCE_STARTED); return; } @@ -2230,9 +2194,8 @@ static void dbus_start_geofence_cb(gint fence_id, const gchar *app_id, gpointer LOGI_GEOFENCE("Wifi is on..."); geofence_server->running_wifi_cnt++; /*Incrementing the counter for wifi fence*/ - if (item_data->priv != NULL) { + if (item_data->priv != NULL) wifi_info = (bssid_info_s *) item_data->priv; - } rv = wifi_get_connected_ap(&ap_h); if (rv != WIFI_ERROR_NONE) { LOGI_GEOFENCE("Fail/not connected to get the connected AP: [%s] , geofence will be added to the fence list", __convert_wifi_error_to_string(rv)); @@ -2263,17 +2226,15 @@ static void dbus_start_geofence_cb(gint fence_id, const gchar *app_id, gpointer status_to_be_emitted = GEOFENCE_FENCE_STATE_OUT; } } else { - LOGI_GEOFENCE("Invalid fence_type[%d]", - item_data->common_info.type); + LOGI_GEOFENCE("Invalid fence_type[%d]", item_data->common_info.type); return; } /*Adding the fence to the tracking list*/ LOGI_GEOFENCE("Add to tracklist: Fence id: %d", fence_id); - if (geofence_server->tracking_list == NULL) { + if (geofence_server->tracking_list == NULL) geofence_server->tracking_list = g_list_append(geofence_server->tracking_list, GINT_TO_POINTER(fence_id)); - } else { + else geofence_server->tracking_list = g_list_insert_before(geofence_server->tracking_list, next_item_ptr, GINT_TO_POINTER(fence_id)); - } LOGI_GEOFENCE("Added fence id: Fence id: %d", fence_id); __emit_fence_event(geofence_server, place_id, fence_id, access_type, app_id, GEOFENCE_SERVER_ERROR_NONE, GEOFENCE_MANAGE_FENCE_STARTED); @@ -2531,32 +2492,32 @@ static GVariant *dbus_get_geofences_cb(int place_id, const gchar *app_id, int *f LOGI_GEOFENCE("fence_id: %d, place_id: %d, latitude: %f, longitude: %f, radius: %d", item->fence_id, item->param.place_id, item->param.latitude, item->param.longitude, item->param.radius); switch (item->param.type) { - case GEOFENCE_TYPE_GEOPOINT: { - g_variant_builder_add(&b, "{sv}", "place_id", g_variant_new_int32(item->param.place_id)); - g_variant_builder_add(&b, "{sv}", "geofence_type", g_variant_new_int32(item->param.type)); - g_variant_builder_add(&b, "{sv}", "latitude", g_variant_new_double(item->param.latitude)); - g_variant_builder_add(&b, "{sv}", "longitude", g_variant_new_double(item->param.longitude)); - g_variant_builder_add(&b, "{sv}", "radius", g_variant_new_int32(item->param.radius)); - g_variant_builder_add(&b, "{sv}", "address", g_variant_new_string(item->param.address)); - g_variant_builder_add(&b, "{sv}", "bssid", g_variant_new_string("NA")); - g_variant_builder_add(&b, "{sv}", "ssid", g_variant_new_string("NA")); - } - break; - case GEOFENCE_TYPE_WIFI: - case GEOFENCE_TYPE_BT: { - g_variant_builder_add(&b, "{sv}", "place_id", g_variant_new_int32(item->param.place_id)); - g_variant_builder_add(&b, "{sv}", "geofence_type", g_variant_new_int32(item->param.type)); - g_variant_builder_add(&b, "{sv}", "latitude", g_variant_new_double(0.0)); - g_variant_builder_add(&b, "{sv}", "longitude", g_variant_new_double(0.0)); - g_variant_builder_add(&b, "{sv}", "radius", g_variant_new_int32(0.0)); - g_variant_builder_add(&b, "{sv}", "address", g_variant_new_string("NA")); - g_variant_builder_add(&b, "{sv}", "bssid", g_variant_new_string(item->param.bssid)); - g_variant_builder_add(&b, "{sv}", "ssid", g_variant_new_string(item->param.ssid)); - } - break; - default: - LOGI_GEOFENCE("Unsupported type: [%d]", item->param.type); - break; + case GEOFENCE_TYPE_GEOPOINT: { + g_variant_builder_add(&b, "{sv}", "place_id", g_variant_new_int32(item->param.place_id)); + g_variant_builder_add(&b, "{sv}", "geofence_type", g_variant_new_int32(item->param.type)); + g_variant_builder_add(&b, "{sv}", "latitude", g_variant_new_double(item->param.latitude)); + g_variant_builder_add(&b, "{sv}", "longitude", g_variant_new_double(item->param.longitude)); + g_variant_builder_add(&b, "{sv}", "radius", g_variant_new_int32(item->param.radius)); + g_variant_builder_add(&b, "{sv}", "address", g_variant_new_string(item->param.address)); + g_variant_builder_add(&b, "{sv}", "bssid", g_variant_new_string("NA")); + g_variant_builder_add(&b, "{sv}", "ssid", g_variant_new_string("NA")); + } + break; + case GEOFENCE_TYPE_WIFI: + case GEOFENCE_TYPE_BT: { + g_variant_builder_add(&b, "{sv}", "place_id", g_variant_new_int32(item->param.place_id)); + g_variant_builder_add(&b, "{sv}", "geofence_type", g_variant_new_int32(item->param.type)); + g_variant_builder_add(&b, "{sv}", "latitude", g_variant_new_double(0.0)); + g_variant_builder_add(&b, "{sv}", "longitude", g_variant_new_double(0.0)); + g_variant_builder_add(&b, "{sv}", "radius", g_variant_new_int32(0.0)); + g_variant_builder_add(&b, "{sv}", "address", g_variant_new_string("NA")); + g_variant_builder_add(&b, "{sv}", "bssid", g_variant_new_string(item->param.bssid)); + g_variant_builder_add(&b, "{sv}", "ssid", g_variant_new_string(item->param.ssid)); + } + break; + default: + LOGI_GEOFENCE("Unsupported type: [%d]", item->param.type); + break; } /* Close container*/ @@ -2681,9 +2642,8 @@ static void __init_geofencemanager(GeofenceServer *geofence_server) geofence_server->activity_in_vehicle_h = NULL; /*Initializing the DB to store the fence informations*/ - if (geofence_manager_db_init() != FENCE_ERR_NONE) { + if (geofence_manager_db_init() != FENCE_ERR_NONE) LOGI_GEOFENCE("Error initalizing the DB"); - } /*Adding default places in the DB*/ int place_id = DEFAULT_PLACE_HOME; int count = -1; @@ -2691,13 +2651,12 @@ static void __init_geofencemanager(GeofenceServer *geofence_server) while (place_id <= DEFAULT_PLACE_CAR) { if (geofence_manager_get_place_count_by_placeid(place_id, &count) == FENCE_ERR_NONE) { if (count == 0) { - if (place_id == DEFAULT_PLACE_HOME) { + if (place_id == DEFAULT_PLACE_HOME) __add_default_place("Home"); - } else if (place_id == DEFAULT_PLACE_OFFICE) { + else if (place_id == DEFAULT_PLACE_OFFICE) __add_default_place("Office"); - } else if (place_id == DEFAULT_PLACE_CAR) { + else if (place_id == DEFAULT_PLACE_CAR) __add_default_place("Car"); - } } } else { LOGI_GEOFENCE("Error adding the default place: %d", place_id); diff --git a/geofence-server/src/geofence_server_alarm.c b/geofence-server/src/geofence_server_alarm.c index 9fb86c9..587aa39 100644 --- a/geofence-server/src/geofence_server_alarm.c +++ b/geofence-server/src/geofence_server_alarm.c @@ -27,9 +27,8 @@ int _geofence_add_alarm(int interval, alarm_cb_t alarm_cb, void *userdata) alarm_id_t alarm_id = -1; ret = alarmmgr_add_alarm_withcb(ALARM_TYPE_DEFAULT, interval, 0, alarm_cb, geofence_server, &alarm_id); - if (ret != ALARMMGR_RESULT_SUCCESS) { + if (ret != ALARMMGR_RESULT_SUCCESS) LOGE_GEOFENCE("Fail to alarmmgr_add_alarm_withcb : %d", ret); - } LOGD_GEOFENCE("alarm_id : %d", alarm_id); return alarm_id; @@ -40,9 +39,8 @@ int _geofence_remove_alarm(alarm_id_t alarm_id) FUNC_ENTRANCE_SERVER; int ret = 0; ret = alarmmgr_remove_alarm(alarm_id); - if (ret != ALARMMGR_RESULT_SUCCESS) { + if (ret != ALARMMGR_RESULT_SUCCESS) LOGE_GEOFENCE("Fail to alarmmgr_remove_alarm : %d", ret); - } return -1; } diff --git a/geofence-server/src/geofence_server_bluetooth.c b/geofence-server/src/geofence_server_bluetooth.c index 130f55c..ccb689a 100644 --- a/geofence-server/src/geofence_server_bluetooth.c +++ b/geofence-server/src/geofence_server_bluetooth.c @@ -102,9 +102,8 @@ static void emit_bt_geofence_proximity_changed(GeofenceServer *geofence_server, LOGD_GEOFENCE("BT Fence. Scanning for BLE and storing in DB"); g_stpcpy(geofence_server->ble_info, ""); ret = bt_adapter_le_start_scan(bt_le_scan_result_cb, geofence_server); - if (ret != BT_ERROR_NONE) { + if (ret != BT_ERROR_NONE) LOGE_GEOFENCE("Fail to start ble scan. %d", ret); - } } item_data->common_info.proximity_status = fence_proximity_status; } @@ -117,22 +116,21 @@ static void emit_bt_geofence_proximity_changed(GeofenceServer *geofence_server, static void emit_bt_geofence_inout_changed(GeofenceServer *geofence_server, GeofenceItemData *item_data, int fence_status) { FUNC_ENTRANCE_SERVER - char *app_id = (char *)g_malloc0(sizeof(char) * APP_ID_LEN); + char *app_id = (char *)g_malloc0(sizeof(char) *APP_ID_LEN); g_strlcpy(app_id, item_data->common_info.appid, APP_ID_LEN); if (app_id == NULL) { LOGD_GEOFENCE("get app_id failed. fence_id [%d]", item_data->common_info.fence_id); return; } - if (fence_status == GEOFENCE_FENCE_STATE_IN) { + if (fence_status == GEOFENCE_FENCE_STATE_IN) geofence_dbus_server_send_geofence_inout_changed(geofence_server->geofence_dbus_server, app_id, item_data->common_info.fence_id, item_data->common_info.access_type, GEOFENCE_EMIT_STATE_IN); - } else if (fence_status == GEOFENCE_FENCE_STATE_OUT) { + else if (fence_status == GEOFENCE_FENCE_STATE_OUT) geofence_dbus_server_send_geofence_inout_changed(geofence_server->geofence_dbus_server, app_id, item_data->common_info.fence_id, item_data->common_info.access_type, GEOFENCE_EMIT_STATE_OUT); - } - if (item_data->client_status == GEOFENCE_CLIENT_STATUS_START) { + if (item_data->client_status == GEOFENCE_CLIENT_STATUS_START) item_data->client_status = GEOFENCE_CLIENT_STATUS_RUNNING; - } + if (app_id) free(app_id); } diff --git a/geofence-server/src/geofence_server_db.c b/geofence-server/src/geofence_server_db.c index 1ef3378..fabe33c 100755 --- a/geofence-server/src/geofence_server_db.c +++ b/geofence-server/src/geofence_server_db.c @@ -55,10 +55,10 @@ const char *col_radius = "r"; #endif typedef enum { - FENCE_MAIN_TABLE = 0, /*GeoFence */ - FENCE_GEOCOORDINATE_TAB, /*FenceGeocoordinate */ - FENCE_GEOPOINT_WIFI_TABLE, /*FenceCurrentLocation */ - FENCE_BSSID_TABLE /*FenceBluetoothBssid */ + FENCE_MAIN_TABLE = 0, /*GeoFence */ + FENCE_GEOCOORDINATE_TAB, /*FenceGeocoordinate */ + FENCE_GEOPOINT_WIFI_TABLE, /*FenceCurrentLocation */ + FENCE_BSSID_TABLE /*FenceBluetoothBssid */ } fence_table_type_e; static struct { @@ -196,9 +196,8 @@ static inline int __geofence_manager_db_create_places_table(void) return FENCE_ERR_SQLITE_FAIL; } - if (sqlite3_changes(db_info_s.handle) == 0) { + if (sqlite3_changes(db_info_s.handle) == 0) LOGI_GEOFENCE("No changes to DB"); - } sqlite3_free(ddl); return FENCE_ERR_NONE; } @@ -217,9 +216,8 @@ static inline int __geofence_manager_db_create_geofence_table(void) return FENCE_ERR_SQLITE_FAIL; } - if (sqlite3_changes(db_info_s.handle) == 0) { + if (sqlite3_changes(db_info_s.handle) == 0) LOGI_GEOFENCE("No changes to DB"); - } sqlite3_free(ddl); return FENCE_ERR_NONE; } @@ -238,9 +236,8 @@ static inline int __geofence_manager_db_create_geocoordinate_table(void) return FENCE_ERR_SQLITE_FAIL; } - if (sqlite3_changes(db_info_s.handle) == 0) { + if (sqlite3_changes(db_info_s.handle) == 0) LOGI_GEOFENCE("No changes to DB"); - } sqlite3_free(ddl); return FENCE_ERR_NONE; } @@ -259,9 +256,8 @@ static inline int __geofence_manager_db_create_wifi_data_table(void) return FENCE_ERR_SQLITE_FAIL; } - if (sqlite3_changes(db_info_s.handle) == 0) { + if (sqlite3_changes(db_info_s.handle) == 0) LOGI_GEOFENCE("No changes to DB"); - } sqlite3_free(ddl); return FENCE_ERR_NONE; } @@ -333,7 +329,7 @@ static int __geofence_manager_db_get_count_by_fence_id_and_bssid(int fence_id, c return FENCE_ERR_NONE; } -static int __geofence_manager_db_insert_bssid_info(const int fence_id, const char *bssid_info, const char *ssid) +static int __geofence_manager_db_insert_bssid_info(const int fence_id, char *bssid_info, const char *ssid) { FUNC_ENTRANCE_SERVER; g_return_val_if_fail(fence_id, FENCE_ERR_INVALID_PARAMETER); @@ -343,14 +339,11 @@ static int __geofence_manager_db_insert_bssid_info(const int fence_id, const cha int index = 0; int count = -1; const char *tail; - char *bssid = NULL; char *query = sqlite3_mprintf("INSERT INTO %Q(fence_id, bssid, ssid) VALUES (?, ?, ?)", menu_table[FENCE_BSSID_TABLE]); - bssid = (char *)g_malloc0(sizeof(char) * WLAN_BSSID_LEN); - g_strlcpy(bssid, bssid_info, WLAN_BSSID_LEN); - LOGI_GEOFENCE("fence_id[%d], bssid[%s], ssid[%s]", fence_id, bssid, ssid); + LOGI_GEOFENCE("fence_id[%d], bssid[%s], ssid[%s]", fence_id, bssid_info, ssid); - ret = __geofence_manager_db_get_count_by_fence_id_and_bssid(fence_id, bssid, FENCE_BSSID_TABLE, &count); + ret = __geofence_manager_db_get_count_by_fence_id_and_bssid(fence_id, bssid_info, FENCE_BSSID_TABLE, &count); if (ret != FENCE_ERR_NONE) { LOGI_GEOFENCE("__geofence_manager_db_get_count_by_fence_id_and_bssid() failed. ERROR(%d)", ret); sqlite3_free(query); @@ -371,7 +364,7 @@ static int __geofence_manager_db_insert_bssid_info(const int fence_id, const cha ret = sqlite3_bind_int(state, ++index, fence_id); SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state); - ret = sqlite3_bind_text(state, ++index, bssid, -1, SQLITE_STATIC); + ret = sqlite3_bind_text(state, ++index, bssid_info, -1, SQLITE_STATIC); SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state); ret = sqlite3_bind_text(state, ++index, ssid, -1, SQLITE_STATIC); @@ -381,7 +374,6 @@ static int __geofence_manager_db_insert_bssid_info(const int fence_id, const cha if (ret != SQLITE_DONE) { LOGI_GEOFENCE("sqlite3_step Error[%d] : %s", ret, sqlite3_errmsg(db_info_s.handle)); sqlite3_finalize(state); - g_free(bssid); sqlite3_free(query); return FENCE_ERR_SQLITE_FAIL; } @@ -389,7 +381,6 @@ static int __geofence_manager_db_insert_bssid_info(const int fence_id, const cha sqlite3_reset(state); sqlite3_clear_bindings(state); sqlite3_finalize(state); - g_free(bssid); sqlite3_free(query); LOGI_GEOFENCE("fence_id[%d], bssid[%s], ssid[%s] inserted db table [%s] successfully.", fence_id, bssid_info, ssid, menu_table[FENCE_BSSID_TABLE]); @@ -408,15 +399,13 @@ static int __geofence_manager_db_insert_wifi_data_info(gpointer data, gpointer u int index = 0; int count = -1; const char *tail; - char *bssid = NULL; + wifi_info = (wifi_info_s *) data; - bssid = (char *)g_malloc0(sizeof(char) * WLAN_BSSID_LEN); - g_strlcpy(bssid, wifi_info->bssid, WLAN_BSSID_LEN); LOGI_GEOFENCE("fence_id[%d] bssid[%s]", *fence_id, wifi_info->bssid); char *query = sqlite3_mprintf("INSERT INTO FenceGeopointWifi(fence_id, bssid) VALUES (?, ?)"); - ret = __geofence_manager_db_get_count_by_fence_id_and_bssid(*fence_id, bssid, FENCE_GEOPOINT_WIFI_TABLE, &count); + ret = __geofence_manager_db_get_count_by_fence_id_and_bssid(*fence_id, wifi_info->bssid, FENCE_GEOPOINT_WIFI_TABLE, &count); if (count > 0) { LOGI_GEOFENCE("count = %d", count); sqlite3_free(query); @@ -433,14 +422,13 @@ static int __geofence_manager_db_insert_wifi_data_info(gpointer data, gpointer u ret = sqlite3_bind_int(state, ++index, *fence_id); SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state); - ret = sqlite3_bind_text(state, ++index, bssid, -1, SQLITE_STATIC); + ret = sqlite3_bind_text(state, ++index, wifi_info->bssid, -1, SQLITE_STATIC); SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state); ret = sqlite3_step(state); if (ret != SQLITE_DONE) { LOGI_GEOFENCE("sqlite3_step Error[%d] : %s", ret, sqlite3_errmsg(db_info_s.handle)); sqlite3_finalize(state); - g_free(bssid); sqlite3_free(query); return FENCE_ERR_SQLITE_FAIL; } @@ -448,7 +436,6 @@ static int __geofence_manager_db_insert_wifi_data_info(gpointer data, gpointer u sqlite3_reset(state); sqlite3_clear_bindings(state); sqlite3_finalize(state); - g_free(bssid); sqlite3_free(query); return FENCE_ERR_NONE; @@ -628,14 +615,12 @@ void __geofence_manager_generate_password(char *password) int ret = 0; ret = bt_adapter_get_address(&bt_address); - if (ret != BT_ERROR_NONE) { + if (ret != BT_ERROR_NONE) LOGD_GEOFENCE("bt address get fail %d", ret); - } ret = wifi_get_mac_address(&wifi_address); - if (ret != WIFI_ERROR_NONE) { + if (ret != WIFI_ERROR_NONE) LOGD_GEOFENCE("wifi address get fail %d", ret); - } if (bt_address) { token = strtok_r(bt_address, ":", &save_token); @@ -693,13 +678,13 @@ static int __check_db_file() { int fd = -1; - fd = open(GEOFENCE_DB_FILE, O_RDONLY); - if (fd < 0) { - LOGW_GEOFENCE("DB file(%s) is not exist.", GEOFENCE_DB_FILE); - return -1; - } - close(fd); - return 0; + fd = open(GEOFENCE_DB_FILE, O_RDONLY); + if (fd < 0) { + LOGW_GEOFENCE("DB file(%s) is not exist.", GEOFENCE_DB_FILE); + return -1; + } + close(fd); + return 0; } /** @@ -776,40 +761,29 @@ int geofence_manager_set_place_info(place_info_s *place_info, int *place_id) int ret = SQLITE_OK; int index = 0; const char *tail; - char *appid = NULL; - char *place_name = NULL; char *query = sqlite3_mprintf("INSERT INTO Places (access_type, place_name, app_id) VALUES (?, ?, ?)"); - place_name = (char *)g_malloc0(sizeof(char) * PLACE_NAME_LEN); - g_strlcpy(place_name, place_info->place_name, PLACE_NAME_LEN); - appid = (char *)g_malloc0(sizeof(char) * APP_ID_LEN); - g_strlcpy(appid, place_info->appid, APP_ID_LEN); - ret = sqlite3_prepare_v2(db_info_s.handle, query, -1, &state, &tail); if (ret != SQLITE_OK) { LOGI_GEOFENCE("Error: %s", sqlite3_errmsg(db_info_s.handle)); - g_free(place_name); - g_free(appid); sqlite3_free(query); return FENCE_ERR_PREPARE; } - LOGD_GEOFENCE("appid[%s] access_type[%d] place_name[%s]", appid, place_info->access_type, place_info->place_name); + LOGD_GEOFENCE("appid[%s] access_type[%d] place_name[%s]", place_info->appid, place_info->access_type, place_info->place_name); ret = sqlite3_bind_int(state, ++index, place_info->access_type); SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state); - ret = sqlite3_bind_text(state, ++index, place_name, -1, SQLITE_STATIC); + ret = sqlite3_bind_text(state, ++index, place_info->place_name, -1, SQLITE_STATIC); SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state); - ret = sqlite3_bind_text(state, ++index, appid, -1, SQLITE_STATIC); + ret = sqlite3_bind_text(state, ++index, place_info->appid, -1, SQLITE_STATIC); SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state); ret = sqlite3_step(state); if (ret != SQLITE_DONE) { LOGI_GEOFENCE("sqlite3_step Error[%d] : %s", ret, sqlite3_errmsg(db_info_s.handle)); sqlite3_finalize(state); - g_free(place_name); - g_free(appid); sqlite3_free(query); return FENCE_ERR_SQLITE_FAIL; } @@ -818,8 +792,6 @@ int geofence_manager_set_place_info(place_info_s *place_info, int *place_id) sqlite3_reset(state); sqlite3_clear_bindings(state); sqlite3_finalize(state); - g_free(place_name); - g_free(appid); sqlite3_free(query); if (*place_id < 1) { @@ -839,20 +811,16 @@ int geofence_manager_set_common_info(fence_common_info_s *fence_info, int *fence int ret = SQLITE_OK; int index = 0; const char *tail; - char *appid = NULL; char *query = sqlite3_mprintf("INSERT INTO GeoFence (place_id, enable, app_id, geofence_type, access_type, running_status) VALUES (?, ?, ?, ?, ?, ?)"); - appid = (char *)g_malloc0(sizeof(char) * APP_ID_LEN); - g_strlcpy(appid, fence_info->appid, APP_ID_LEN); ret = sqlite3_prepare_v2(db_info_s.handle, query, -1, &state, &tail); if (ret != SQLITE_OK) { LOGI_GEOFENCE("Error: %s", sqlite3_errmsg(db_info_s.handle)); - g_free(appid); sqlite3_free(query); return FENCE_ERR_PREPARE; } - LOGD_GEOFENCE("place_id[%d], enable[%d], appid[%s] geofence_type[%d] access_type[%d] running_status[%d]", fence_info->place_id, fence_info->enable, appid, fence_info->running_status, fence_info->type, fence_info->access_type, fence_info->place_id); + LOGD_GEOFENCE("place_id[%d], enable[%d], appid[%s] geofence_type[%d] access_type[%d] running_status[%d]", fence_info->place_id, fence_info->enable, fence_info->appid, fence_info->running_status, fence_info->type, fence_info->access_type, fence_info->place_id); ret = sqlite3_bind_int(state, ++index, fence_info->place_id); SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state); @@ -860,7 +828,7 @@ int geofence_manager_set_common_info(fence_common_info_s *fence_info, int *fence ret = sqlite3_bind_int(state, ++index, fence_info->enable); SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state); - ret = sqlite3_bind_text(state, ++index, appid, -1, SQLITE_STATIC); + ret = sqlite3_bind_text(state, ++index, fence_info->appid, -1, SQLITE_STATIC); SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state); ret = sqlite3_bind_int(state, ++index, fence_info->type); @@ -876,7 +844,6 @@ int geofence_manager_set_common_info(fence_common_info_s *fence_info, int *fence if (ret != SQLITE_DONE) { LOGI_GEOFENCE("sqlite3_step Error[%d] : %s", ret, sqlite3_errmsg(db_info_s.handle)); sqlite3_finalize(state); - g_free(appid); sqlite3_free(query); return FENCE_ERR_SQLITE_FAIL; } @@ -885,7 +852,6 @@ int geofence_manager_set_common_info(fence_common_info_s *fence_info, int *fence sqlite3_reset(state); sqlite3_clear_bindings(state); sqlite3_finalize(state); - g_free(appid); sqlite3_free(query); if (*fence_id < 1) { @@ -1101,18 +1067,12 @@ int geofence_manager_update_place_info(int place_id, const char *place_info_name sqlite3_stmt *state = NULL; const char *tail; int ret = SQLITE_OK; - char *place_name = NULL; - - place_name = (char *)g_malloc0(sizeof(char) * PLACE_NAME_LEN); - g_strlcpy(place_name, place_info_name, PLACE_NAME_LEN); - - char *query = sqlite3_mprintf("UPDATE Places SET place_name = %Q where place_id = %d", place_name, place_id); + char *query = sqlite3_mprintf("UPDATE Places SET place_name = %Q where place_id = %d", place_info_name, place_id); ret = sqlite3_prepare_v2(db_info_s.handle, query, -1, &state, &tail); if (ret != SQLITE_OK) { LOGI_GEOFENCE("Error: %s", sqlite3_errmsg(db_info_s.handle)); sqlite3_free(query); - g_free(place_name); return FENCE_ERR_PREPARE; } @@ -1120,13 +1080,11 @@ int geofence_manager_update_place_info(int place_id, const char *place_info_name if (ret != SQLITE_DONE) { LOGI_GEOFENCE("sqlite3_step Error[%d] : %s", ret, sqlite3_errmsg(db_info_s.handle)); sqlite3_finalize(state); - g_free(place_name); sqlite3_free(query); return FENCE_ERR_SQLITE_FAIL; } sqlite3_finalize(state); - g_free(place_name); sqlite3_free(query); LOGI_GEOFENCE("place_id: %d has been successfully updated.", place_id); return FENCE_ERR_NONE; @@ -1268,25 +1226,22 @@ int geofence_manager_get_geocoordinate_info(int fence_id, geocoordinate_info_s * data_name = (char *) sqlite3_column_text(state, ++index); - if (!data_name || !strlen(data_name)) { + if (!data_name || !strlen(data_name)) LOGI_GEOFENCE("ERROR: data_name is NULL!!!"); - } else { + else (*geocoordinate_info)->latitude = atof(data_name); - } data_name = (char *) sqlite3_column_text(state, ++index); - if (!data_name || !strlen(data_name)) { + if (!data_name || !strlen(data_name)) LOGI_GEOFENCE("ERROR: data_name is NULL!!!"); - } else { + else (*geocoordinate_info)->longitude = atof(data_name); - } data_name = (char *) sqlite3_column_text(state, ++index); - if (!data_name || !strlen(data_name)) { + if (!data_name || !strlen(data_name)) LOGI_GEOFENCE("ERROR: data_name is NULL!!!"); - } else { + else (*geocoordinate_info)->radius = atof(data_name); - } g_strlcpy((*geocoordinate_info)->address, (char *) sqlite3_column_text(state, ++index), ADDRESS_LEN); @@ -1407,11 +1362,10 @@ int geofence_manager_get_place_info(int place_id, place_info_s **place_info) g_return_val_if_fail(*place_info, FENCE_ERR_INVALID_PARAMETER); data_name = (char *)sqlite3_column_text(state, ++index); - if (!data_name || !strlen(data_name)) { + if (!data_name || !strlen(data_name)) LOGI_GEOFENCE("ERROR: data_name is NULL!!!"); - } else { + else (*place_info)->access_type = atof(data_name); - } g_strlcpy((*place_info)->place_name, (char *)sqlite3_column_text(state, ++index), PLACE_NAME_LEN); g_strlcpy((*place_info)->appid, (char *)sqlite3_column_text(state, ++index), APP_ID_LEN); @@ -1706,11 +1660,10 @@ int geofence_manager_get_place_name(int place_id, char **name) } tmp = (char *) sqlite3_column_text(state, 0); - if (!tmp || !strlen(tmp)) { + if (!tmp || !strlen(tmp)) LOGI_GEOFENCE("ERROR: name is NULL!!!"); - } else { + else *name = g_strdup(tmp); - } sqlite3_finalize(state); sqlite3_free(query); @@ -1787,11 +1740,10 @@ int geofence_manager_get_appid_from_places(int place_id, char **appid) } id = (char *) sqlite3_column_text(state, 0); - if (!id || !strlen(id)) { + if (!id || !strlen(id)) LOGI_GEOFENCE("ERROR: appid is NULL!!!"); - } else { + else *appid = g_strdup(id); - } sqlite3_finalize(state); sqlite3_free(query); @@ -1866,11 +1818,10 @@ int geofence_manager_get_appid_from_geofence(int fence_id, char **appid) } id = (char *) sqlite3_column_text(state, 0); - if (!id || !strlen(id)) { + if (!id || !strlen(id)) LOGI_GEOFENCE("ERROR: appid is NULL!!!"); - } else { + else *appid = g_strdup(id); - } sqlite3_finalize(state); sqlite3_free(query); @@ -1946,11 +1897,10 @@ int geofence_manager_get_ble_info_from_geofence(int fence_id, char **ble_info) } info = (char *) sqlite3_column_text(state, 0); - if (!info || !strlen(info)) { + if (!info || !strlen(info)) LOGI_GEOFENCE("ERROR: ble info is NULL!!!"); - } else { + else *ble_info = g_strdup(info); - } sqlite3_finalize(state); sqlite3_free(query); @@ -2415,9 +2365,8 @@ int geofence_manager_close_db(void) FUNC_ENTRANCE_SERVER; int ret = SQLITE_OK; - if (db_info_s.handle == NULL) { + if (db_info_s.handle == NULL) return FENCE_ERR_NONE; - } ret = db_util_close(db_info_s.handle); if (ret != SQLITE_OK) { diff --git a/geofence-server/src/geofence_server_wifi.c b/geofence-server/src/geofence_server_wifi.c index 82463ed..3217474 100644 --- a/geofence-server/src/geofence_server_wifi.c +++ b/geofence-server/src/geofence_server_wifi.c @@ -122,9 +122,8 @@ static void emit_wifi_geofence_proximity_changed(GeofenceServer *geofence_server LOGD_GEOFENCE("WIFI Fence. Scanning for BLE and storing in DB"); g_stpcpy(geofence_server->ble_info, ""); ret = bt_adapter_le_start_scan(bt_le_scan_result_cb, geofence_server); - if (ret != BT_ERROR_NONE) { + if (ret != BT_ERROR_NONE) LOGE_GEOFENCE("Fail to start ble scan. %d", ret); - } } else if (item_data->common_info.proximity_status == GEOFENCE_PROXIMITY_IMMEDIATE) { /* Stopping the scan if state changes from imm to somethingelse */ ret = bt_adapter_le_stop_scan(); if (ret != BT_ERROR_NONE) diff --git a/geofence-server/src/server.c b/geofence-server/src/server.c index 8202b57..b114669 100644 --- a/geofence-server/src/server.c +++ b/geofence-server/src/server.c @@ -339,44 +339,38 @@ int _geofence_deinitialize_geofence_server() /* to denit geofence engine staff...*/ /* unset bluetooth device connection state changed state event callback*/ - if (bt_device_unset_connection_state_changed_cb() != BT_ERROR_NONE) { + if (bt_device_unset_connection_state_changed_cb() != BT_ERROR_NONE) LOGD_GEOFENCE("bt_device_unset_connection_state_changed_cb() failed.\n"); - } else { + else LOGD_GEOFENCE("bt_device_unset_connection_state_changed_cb() success.\n"); - } /* unset bluetooth adapter changed state event callback*/ - if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) LOGD_GEOFENCE("bt_adapter_unset_state_changed_cb() failed.\n"); - } else { + else LOGD_GEOFENCE("bt_adapter_unset_state_changed_cb() success.\n"); - } /* deinit bluetooth api*/ - if (bt_deinitialize() != BT_ERROR_NONE) { + if (bt_deinitialize() != BT_ERROR_NONE) LOGD_GEOFENCE("bt_deinitialize() failed.\n"); - } else { + else LOGD_GEOFENCE("bt_deinitialize() success.\n"); - } /*unset the callbacks related to wifi*/ - if (wifi_unset_connection_state_changed_cb() != WIFI_ERROR_NONE) { + if (wifi_unset_connection_state_changed_cb() != WIFI_ERROR_NONE) LOGD_GEOFENCE("wifi_unset_connection_state_changed_cb() failed.\n"); - } else { + else LOGD_GEOFENCE("wifi_unset_connection_state_changed_cb() success.\n"); - } - if (wifi_deinitialize() != WIFI_ERROR_NONE) { + if (wifi_deinitialize() != WIFI_ERROR_NONE) LOGD_GEOFENCE("wifi_deinitialize() failed.\n"); - } else { + else LOGD_GEOFENCE("wifi_deinitialize() success.\n"); - } - if (location_manager_unset_setting_changed_cb(LOCATIONS_METHOD_GPS) != LOCATIONS_ERROR_NONE) { + if (location_manager_unset_setting_changed_cb(LOCATIONS_METHOD_GPS) != LOCATIONS_ERROR_NONE) LOGD_GEOFENCE("GPS unsetting failed\n"); - } else { + else LOGD_GEOFENCE("GPS unsetting success\n"); - } #if USE_TAPI __deinitialize_geofence_data(); #endif diff --git a/module/module_geofence_server.c b/module/module_geofence_server.c index 0011ec9..fc1783f 100644 --- a/module/module_geofence_server.c +++ b/module/module_geofence_server.c @@ -33,9 +33,9 @@ #define MYPLACES_APP_ID "org.tizen.myplace" typedef enum { - ACCESS_TYPE_PRIVATE = 1, - ACCESS_TYPE_PUBLIC, - ACCESS_TYPE_UNKNOWN, + ACCESS_TYPE_PRIVATE = 1, + ACCESS_TYPE_PUBLIC, + ACCESS_TYPE_UNKNOWN, } access_type_e; typedef struct { @@ -53,11 +53,14 @@ EXPORT_API int add_geopoint(void *handle, int place_id, double latitude, double GeofenceManagerData *geofence_manager = (GeofenceManagerData *)handle; g_return_val_if_fail(geofence_manager, GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER); int new_fence_id = -1; + int error_code = GEOFENCE_MANAGER_ERROR_NONE; - new_fence_id = geo_client_add_geofence(geofence_manager->geofence_client, geofence_manager->app_id, place_id, GEOFENCE_TYPE_GEOPOINT, latitude, longitude, radius, address, "", ""); + new_fence_id = geo_client_add_geofence(geofence_manager->geofence_client, geofence_manager->app_id, place_id, GEOFENCE_TYPE_GEOPOINT, latitude, longitude, radius, address, "", "", &error_code); *fence_id = new_fence_id; - if (new_fence_id == -1) + if (error_code != GEOFENCE_MANAGER_ERROR_NONE) + return error_code; + else if (new_fence_id == -1) return GEOFENCE_CLIENT_ERROR_DBUS_CALL; return GEOFENCE_MANAGER_ERROR_NONE; @@ -69,11 +72,14 @@ EXPORT_API int add_bssid(void *handle, int place_id, const char *bssid, const ch GeofenceManagerData *geofence_manager = (GeofenceManagerData *)handle; g_return_val_if_fail(geofence_manager, GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER); int new_fence_id = -1; + int error_code = GEOFENCE_MANAGER_ERROR_NONE; - new_fence_id = geo_client_add_geofence(geofence_manager->geofence_client, geofence_manager->app_id, place_id, type, -1, -1, -1, "", bssid, ssid); + new_fence_id = geo_client_add_geofence(geofence_manager->geofence_client, geofence_manager->app_id, place_id, type, -1, -1, -1, "", bssid, ssid, &error_code); *fence_id = new_fence_id; - if (new_fence_id == -1) + if (error_code != GEOFENCE_MANAGER_ERROR_NONE) + return error_code; + else if (new_fence_id == -1) return GEOFENCE_CLIENT_ERROR_DBUS_CALL; return GEOFENCE_MANAGER_ERROR_NONE; @@ -85,11 +91,14 @@ EXPORT_API int add_place(void *handle, const char *place_name, int *place_id) GeofenceManagerData *geofence_manager = (GeofenceManagerData *)handle; g_return_val_if_fail(geofence_manager, GEOFENCE_MANAGER_ERROR_INVALID_PARAMETER); int new_place_id = -1; + int error_code = GEOFENCE_MANAGER_ERROR_NONE; - new_place_id = geo_client_add_place(geofence_manager->geofence_client, geofence_manager->app_id, place_name); + new_place_id = geo_client_add_place(geofence_manager->geofence_client, geofence_manager->app_id, place_name, &error_code); *place_id = new_place_id; - if (new_place_id == -1) + if (error_code != GEOFENCE_MANAGER_ERROR_NONE) + return error_code; + else if (new_place_id == -1) return GEOFENCE_CLIENT_ERROR_DBUS_CALL; return GEOFENCE_MANAGER_ERROR_NONE; @@ -103,7 +112,7 @@ EXPORT_API int update_place(void *handle, int place_id, const char *place_name) int ret = geo_client_update_place(geofence_manager->geofence_client, geofence_manager->app_id, place_id, place_name); if (ret != GEOFENCE_CLIENT_ERROR_NONE) - return GEOFENCE_CLIENT_ERROR_DBUS_CALL; + return ret; return GEOFENCE_MANAGER_ERROR_NONE; } @@ -116,7 +125,7 @@ EXPORT_API int remove_geofence(void *handle, int fence_id) int ret = geo_client_delete_geofence(geofence_manager->geofence_client, geofence_manager->app_id, fence_id); if (ret != GEOFENCE_CLIENT_ERROR_NONE) - return GEOFENCE_CLIENT_ERROR_DBUS_CALL; + return ret; return GEOFENCE_MANAGER_ERROR_NONE; } @@ -129,7 +138,7 @@ EXPORT_API int remove_place(void *handle, int place_id) int ret = geo_client_delete_place(geofence_manager->geofence_client, geofence_manager->app_id, place_id); if (ret != GEOFENCE_CLIENT_ERROR_NONE) - return GEOFENCE_CLIENT_ERROR_DBUS_CALL; + return ret; return GEOFENCE_MANAGER_ERROR_NONE; } @@ -222,7 +231,7 @@ EXPORT_API int get_place_name(void *handle, int place_id, char **place_name) int error_code = GEOFENCE_MANAGER_ERROR_NONE; int ret = geo_client_get_place_name(geofence_manager->geofence_client, geofence_manager->app_id, place_id, place_name, &error_code); if (ret != GEOFENCE_CLIENT_ERROR_NONE) - return GEOFENCE_CLIENT_ERROR_DBUS_CALL; + return ret; return error_code; } @@ -247,15 +256,15 @@ EXPORT_API int get_geofences(void *handle, int place_id, int *fence_amount, int int error_code = GEOFENCE_MANAGER_ERROR_NONE; int ret = geo_client_get_geofences(geofence_manager->geofence_client, geofence_manager->app_id, place_id, &iter, &fence_cnt, &error_code); - if (error_code != GEOFENCE_MANAGER_ERROR_NONE) + if (ret != GEOFENCE_MANAGER_ERROR_NONE) + return ret; + else if (error_code != GEOFENCE_MANAGER_ERROR_NONE) return error_code; - else if (ret != GEOFENCE_MANAGER_ERROR_NONE) - return GEOFENCE_CLIENT_ERROR_DBUS_CALL; *fence_amount = fence_cnt; MOD_LOGD("Total fence count : %d", *fence_amount); - int *fence_id_array = (int *) g_slice_alloc0(sizeof(int) * fence_cnt); - geofence_s *p = (geofence_s *) g_slice_alloc0(sizeof(geofence_s) * fence_cnt); + int *fence_id_array = (int *) g_slice_alloc0(sizeof(int) *fence_cnt); + geofence_s *p = (geofence_s *) g_slice_alloc0(sizeof(geofence_s) *fence_cnt); while (g_variant_iter_next(iter, "a{sv}", &iter_row)) { while (g_variant_iter_loop(iter_row, "{sv}", &key, &value)) { @@ -310,28 +319,29 @@ EXPORT_API int get_places(void *handle, int *place_amount, int **place_ids, plac gchar *key; GVariant *value; int place_cnt = 0; - int error_code = -1; + int error_code = GEOFENCE_MANAGER_ERROR_NONE; /*Call the geofence_client api here....*/ - geo_client_get_places(geofence_manager->geofence_client, geofence_manager->app_id, &iter, &place_cnt, &error_code); + int ret = geo_client_get_places(geofence_manager->geofence_client, geofence_manager->app_id, &iter, &place_cnt, &error_code); + if (ret != GEOFENCE_MANAGER_ERROR_NONE) + return ret; if (error_code != GEOFENCE_MANAGER_ERROR_NONE) return error_code; *place_amount = place_cnt; MOD_LOGI("Total place count : %d", *place_amount); - int *place_id_array = (int *)g_slice_alloc0(sizeof(int) * place_cnt); - place_s *p = (place_s *)g_slice_alloc0(sizeof(place_s) * place_cnt); + int *place_id_array = (int *)g_slice_alloc0(sizeof(int) *place_cnt); + place_s *p = (place_s *)g_slice_alloc0(sizeof(place_s) *place_cnt); if (iter == NULL) MOD_LOGI("Iterator is null"); while (g_variant_iter_next(iter, "a{sv}", &iter_row)) { while (g_variant_iter_loop(iter_row, "{sv}", &key, &value)) { - if (!g_strcmp0(key, "place_id")) { + if (!g_strcmp0(key, "place_id")) place_id_array[index] = g_variant_get_int32(value); - } else if (!g_strcmp0(key, "place_name")) { + else if (!g_strcmp0(key, "place_name")) g_strlcpy(p[index].place_name, g_variant_get_string(value, NULL), PLACE_NAME_LEN); - } } MOD_LOGI("place_id: %d, place_name: %s", place_id_array[index], p[index].place_name); index++; @@ -374,7 +384,7 @@ EXPORT_API int start_geofence(void *handle, int fence_id) ret = geo_client_start_geofence(geofence_manager->geofence_client, geofence_manager->app_id, fence_id); if (ret != GEOFENCE_MANAGER_ERROR_NONE) { MOD_LOGE("Fail to start geofence_client_h. Error[%d]", ret); - return GEOFENCE_CLIENT_ERROR_DBUS_CALL; + return ret; } return GEOFENCE_MANAGER_ERROR_NONE; @@ -392,7 +402,7 @@ EXPORT_API int stop_geofence(void *handle, int fence_id) ret = geo_client_stop_geofence(geofence_manager->geofence_client, geofence_manager->app_id, fence_id); if (ret != GEOFENCE_MANAGER_ERROR_NONE) { MOD_LOGE("Fail to stop. Error[%d]", ret); - return GEOFENCE_CLIENT_ERROR_DBUS_CALL; + return ret; } return GEOFENCE_MANAGER_ERROR_NONE; diff --git a/packaging/geofence-server.spec b/packaging/geofence-server.spec index 8d5b9a9..3855e92 100644 --- a/packaging/geofence-server.spec +++ b/packaging/geofence-server.spec @@ -1,6 +1,6 @@ Name: geofence-server Summary: Geofence Server for Tizen -Version: 0.4.3 +Version: 0.4.4 Release: 1 Group: Location/Service License: Apache-2.0 -- 2.7.4 From 2bc3d1996b02fe348828c70f219c29b871a8149f Mon Sep 17 00:00:00 2001 From: "kj7.sung" Date: Tue, 3 May 2016 16:19:09 +0900 Subject: [PATCH 04/16] Fixed Svace issues Change-Id: I0b34b7d7cde872a84243b7599166d59851593f93 Signed-off-by: kj7.sung --- module/module_geofence_server.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/module/module_geofence_server.c b/module/module_geofence_server.c index fc1783f..0a1cc92 100644 --- a/module/module_geofence_server.c +++ b/module/module_geofence_server.c @@ -347,9 +347,11 @@ EXPORT_API int get_places(void *handle, int *place_amount, int **place_ids, plac index++; g_variant_iter_free(iter_row); } - g_variant_iter_free(iter); - *params = (place_s *)p; + if (iter != NULL) + g_variant_iter_free(iter); + + *params = (place_s *)p; *place_ids = place_id_array; return GEOFENCE_MANAGER_ERROR_NONE; -- 2.7.4 From 360a271e1344d728063748c301a16340c2dfd5a9 Mon Sep 17 00:00:00 2001 From: chanywa Date: Wed, 15 Jun 2016 21:35:20 +0900 Subject: [PATCH 05/16] fixed memory leaks Change-Id: I741797ff81811664ca71a4208fda3e83f5ed1e14 --- geofence-server/src/geofence_server.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/geofence-server/src/geofence_server.c b/geofence-server/src/geofence_server.c index de4cc3f..c5e68c1 100644 --- a/geofence-server/src/geofence_server.c +++ b/geofence-server/src/geofence_server.c @@ -1689,10 +1689,11 @@ static int dbus_add_place_cb(const gchar *app_id, const gchar *place_name, gpoin if (ret != FENCE_ERR_NONE) { LOGI_GEOFENCE("Unable to add the place due to DB error"); __emit_fence_event(geofence_server, -1, -1, ACCESS_TYPE_UNKNOWN, app_id, GEOFENCE_SERVER_ERROR_DATABASE, GEOFENCE_MANAGE_PLACE_ADDED); + g_free(place_info); return -1; } __emit_fence_event(geofence_server, place_id, -1, place_info->access_type, app_id, GEOFENCE_SERVER_ERROR_NONE, GEOFENCE_MANAGE_PLACE_ADDED); - + g_free(place_info); return place_id; } @@ -2608,6 +2609,7 @@ static void __add_default_place(char *place_name) int ret = geofence_manager_set_place_info(place_info, &place_id); if (ret != FENCE_ERR_NONE) LOGI_GEOFENCE("Unable to add the default places due to DB error"); + g_free(place_info); } static void __init_geofencemanager(GeofenceServer *geofence_server) -- 2.7.4 From 1237eaaf7fdfe7d23c5914bc0e0b3d49164769ef Mon Sep 17 00:00:00 2001 From: jomui Date: Fri, 17 Jun 2016 16:12:34 +0900 Subject: [PATCH 06/16] fix memory leak Signed-off-by: jomui Change-Id: Id9ff7c35fe00d7c1caee127189bf44ab6418de0f --- geofence-server/src/geofence_server.c | 40 +++++++++++++++++++------------- geofence-server/src/geofence_server_db.c | 2 +- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/geofence-server/src/geofence_server.c b/geofence-server/src/geofence_server.c index c5e68c1..9b4d66d 100644 --- a/geofence-server/src/geofence_server.c +++ b/geofence-server/src/geofence_server.c @@ -1757,16 +1757,16 @@ static void dbus_update_place_cb(gint place_id, const gchar *app_id, const gchar return; } - place_info_s *place_info = (place_info_s *) g_malloc0(sizeof(place_info_s)); - if (place_info == NULL) { - LOGI_GEOFENCE("malloc fail for place id[%d]", place_id); - __emit_fence_event(geofence_server, place_id, -1, ACCESS_TYPE_UNKNOWN, app_id, GEOFENCE_SERVER_ERROR_OUT_OF_MEMORY, GEOFENCE_MANAGE_PLACE_UPDATED); - return; - } + place_info_s *place_info = NULL; ret = geofence_manager_get_place_info(place_id, &place_info); - if (ret != FENCE_ERR_NONE) { - LOGI_GEOFENCE("Place_id does not exist or DB error in getting the place info for place_id[%d].", place_id); - __emit_fence_event(geofence_server, place_id, -1, ACCESS_TYPE_UNKNOWN, app_id, GEOFENCE_SERVER_ERROR_ID_NOT_EXIST, GEOFENCE_MANAGE_PLACE_UPDATED); + if (ret != FENCE_ERR_NONE || place_info == NULL) { + if (ret == FENCE_ERR_INTERNAL) { + LOGI_GEOFENCE("malloc fail for place id[%d]", place_id); + __emit_fence_event(geofence_server, place_id, -1, ACCESS_TYPE_UNKNOWN, app_id, GEOFENCE_SERVER_ERROR_OUT_OF_MEMORY, GEOFENCE_MANAGE_PLACE_UPDATED); + } else { + LOGI_GEOFENCE("Place_id does not exist or DB error in getting the place info for place_id[%d].", place_id); + __emit_fence_event(geofence_server, place_id, -1, ACCESS_TYPE_UNKNOWN, app_id, GEOFENCE_SERVER_ERROR_ID_NOT_EXIST, GEOFENCE_MANAGE_PLACE_UPDATED); + } g_free(place_info); return; } @@ -1929,12 +1929,16 @@ static void dbus_remove_place_cb(gint place_id, const gchar *app_id, gpointer us return; } - place_info_s *place_info = - (place_info_s *) g_malloc0(sizeof(place_info_s)); + place_info_s *place_info = NULL; ret = geofence_manager_get_place_info(place_id, &place_info); - if (ret != FENCE_ERR_NONE) { - LOGI_GEOFENCE("Place_id does not exist or DB error in getting the place info for place_id[%d].", place_id); - __emit_fence_event(geofence_server, place_id, -1, ACCESS_TYPE_UNKNOWN, app_id, GEOFENCE_SERVER_ERROR_ID_NOT_EXIST, GEOFENCE_MANAGE_PLACE_REMOVED); + if (ret != FENCE_ERR_NONE || place_info == NULL) { + if (ret == FENCE_ERR_INTERNAL) { + LOGI_GEOFENCE("malloc fail for place id[%d]", place_id); + __emit_fence_event(geofence_server, place_id, -1, ACCESS_TYPE_UNKNOWN, app_id, GEOFENCE_SERVER_ERROR_OUT_OF_MEMORY, GEOFENCE_MANAGE_PLACE_REMOVED); + } else { + LOGI_GEOFENCE("Place_id does not exist or DB error in getting the place info for place_id[%d].", place_id); + __emit_fence_event(geofence_server, place_id, -1, ACCESS_TYPE_UNKNOWN, app_id, GEOFENCE_SERVER_ERROR_ID_NOT_EXIST, GEOFENCE_MANAGE_PLACE_REMOVED); + } g_free(place_info); return; } @@ -2434,12 +2438,16 @@ static GVariant *dbus_get_geofences_cb(int place_id, const gchar *app_id, int *f ret = geofence_manager_get_fence_list_from_db(&count, &fence_list, -1); } else { ret = geofence_manager_get_place_info(place_id, &place_info); - if (ret != FENCE_ERR_NONE) { + if (ret != FENCE_ERR_NONE || place_info == NULL) { LOGE("Error getting the place info for place_id[%d]", place_id); /* Send ZERO data gvariant*/ - *errorCode = GEOFENCE_SERVER_ERROR_DATABASE; + if (ret == FENCE_ERR_INTERNAL) + *errorCode = GEOFENCE_SERVER_ERROR_OUT_OF_MEMORY; + else + *errorCode = GEOFENCE_SERVER_ERROR_DATABASE; *fenceCnt = fence_cnt; g_variant_builder_init(&b, G_VARIANT_TYPE("aa{sv}")); + g_free(place_info); return g_variant_builder_end(&b); } if ((place_info != NULL) && (place_info->access_type == ACCESS_TYPE_PRIVATE)) { diff --git a/geofence-server/src/geofence_server_db.c b/geofence-server/src/geofence_server_db.c index fabe33c..26273be 100755 --- a/geofence-server/src/geofence_server_db.c +++ b/geofence-server/src/geofence_server_db.c @@ -1359,7 +1359,7 @@ int geofence_manager_get_place_info(int place_id, place_info_s **place_info) return FENCE_ERR_SQLITE_FAIL; } *place_info = (place_info_s *)g_malloc0(sizeof(place_info_s)); - g_return_val_if_fail(*place_info, FENCE_ERR_INVALID_PARAMETER); + g_return_val_if_fail(*place_info, FENCE_ERR_INTERNAL); data_name = (char *)sqlite3_column_text(state, ++index); if (!data_name || !strlen(data_name)) -- 2.7.4 From d9eccda1618626a95fbaf90136b417b537a3967c Mon Sep 17 00:00:00 2001 From: chanywa Date: Fri, 15 Jul 2016 17:48:48 +0900 Subject: [PATCH 07/16] fixed a SVACE issue Change-Id: Ieb3847b2b1e8deb696dbafa1e830c904cd66ca4b --- geofence-server/src/geofence_server.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/geofence-server/src/geofence_server.c b/geofence-server/src/geofence_server.c index 9b4d66d..9b33a97 100644 --- a/geofence-server/src/geofence_server.c +++ b/geofence-server/src/geofence_server.c @@ -842,7 +842,7 @@ static void __geofence_wps_position_changed_cb(double latitude, double longitude /* Allocate memory for the location_info structure */ if (geofence_server->wps_fix_info == NULL) - geofence_server->wps_fix_info = (location_fix_info_s *)g_malloc(sizeof(location_fix_info_s)); + geofence_server->wps_fix_info = (location_fix_info_s *)g_malloc0(sizeof(location_fix_info_s)); /*Remove the timeout callback that might be running when requesting for fix.*/ if (geofence_server->wps_timeout_alarm_id != -1) { /*LOGI_GEOFENCE("Removing the timeout alarm from restart gps");*/ -- 2.7.4 From 7e2c135b772eac67642da2c92a12e98e1a17d26f Mon Sep 17 00:00:00 2001 From: jomui Date: Tue, 6 Sep 2016 10:59:10 +0900 Subject: [PATCH 08/16] upgrade script Signed-off-by: jomui Change-Id: I880537d0b7252d59954fa5654e48918ccee8c930 --- packaging/geofence-server.spec | 7 ++++++- scripts/geofence-server_upgrade.sh | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 scripts/geofence-server_upgrade.sh diff --git a/packaging/geofence-server.spec b/packaging/geofence-server.spec index 3855e92..728ef7b 100644 --- a/packaging/geofence-server.spec +++ b/packaging/geofence-server.spec @@ -11,6 +11,8 @@ Source1: geofence-server.service ExcludeArch: %{arm} %ix86 x86_64 %endif +%define upgrade_script_path /usr/share/upgrade/scripts/ + Requires(post): sqlite Requires(post): lbs-server BuildRequires: cmake @@ -60,6 +62,9 @@ make %{?jobs:-j%jobs} rm -rf %{buildroot} %make_install +mkdir -p %{buildroot}%{upgrade_script_path} +cp -f scripts/geofence-server_upgrade.sh %{buildroot}%{upgrade_script_path} + #service for systemd is not installed to support only DBus auto activation #mkdir -p %{buildroot}%{_unitdir_user}/default.target.wants #install -m 644 %{SOURCE1} %{buildroot}%{_unitdir_user}/geofence-server.service @@ -76,9 +81,9 @@ rm -rf %{buildroot} %manifest geofence-server.manifest %defattr(-,root,root,-) /usr/bin/geofence-server - /usr/share/dbus-1/services/org.tizen.lbs.Providers.GeofenceServer.service %config %{_sysconfdir}/dbus-1/session.d/geofence-server.conf +%{upgrade_script_path}/geofence-server_upgrade.sh #service for systemd is not installed to support only DBus auto activation #%{_unitdir_user}/geofence-server.service diff --git a/scripts/geofence-server_upgrade.sh b/scripts/geofence-server_upgrade.sh new file mode 100644 index 0000000..fb359b0 --- /dev/null +++ b/scripts/geofence-server_upgrade.sh @@ -0,0 +1,21 @@ +#!/bin/sh +PATH=/bin:/usr/bin:/sbin:/usr/sbin + +#------------------------------------------------# +# geofence-server patch for upgrade (2.4 -> 3.0) # +#------------------------------------------------# + +# Macro +DB_DIR_24=/opt/usr/dbspace/ +DB_DIR_30=/opt/usr/home/owner/.applications/dbspace/ +DB_FILE=.geofence-server.db + +# move DB +mv $DB_DIR_24$DB_FILE $DB_DIR_30 +mv $DB_DIR_24$DB_FILE-journal $DB_DIR_30 + +#set Permission +chown owner:users $DB_DIR_30$DB_FILE +chown owner:users $DB_DIR_30$DB_FILE-journal + +exit 0 -- 2.7.4 From 4dfe998fde1a7dcf47c0d76ab46f73774e525037 Mon Sep 17 00:00:00 2001 From: MyungJoo Ham Date: Fri, 9 Sep 2016 01:48:34 +0000 Subject: [PATCH 09/16] Remove unnecessary profile dependencies from build spec If TV profile does not need geofence-dbus, update meta-tv.git so that it does not include geofence-dbus. If it does not include geofence-dbus already, this if profile expression is a dead code. Change-Id: I4a4a2d0ea588cf2eec18b22852a7c21ac236c528 Signed-off-by: MyungJoo Ham --- packaging/geofence-server.spec | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packaging/geofence-server.spec b/packaging/geofence-server.spec index 728ef7b..c385ca8 100644 --- a/packaging/geofence-server.spec +++ b/packaging/geofence-server.spec @@ -7,10 +7,6 @@ License: Apache-2.0 Source0: %{name}-%{version}.tar.gz Source1: geofence-server.service -%if "%{?profile}" == "tv" -ExcludeArch: %{arm} %ix86 x86_64 -%endif - %define upgrade_script_path /usr/share/upgrade/scripts/ Requires(post): sqlite -- 2.7.4 From 8de1f3f754920205d8205d307df5c2e63ce55131 Mon Sep 17 00:00:00 2001 From: jomui Date: Fri, 2 Dec 2016 18:02:30 +0900 Subject: [PATCH 10/16] fixed SVACE 2.2 issues Signed-off-by: jomui Change-Id: Ibebe3807b07bccbb2697935c4392a50966610fa4 --- geofence-server/src/geofence_server.c | 5 ++++- geofence-server/src/geofence_server_wifi.c | 8 +++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/geofence-server/src/geofence_server.c b/geofence-server/src/geofence_server.c index 9b33a97..88fbf87 100644 --- a/geofence-server/src/geofence_server.c +++ b/geofence-server/src/geofence_server.c @@ -2215,7 +2215,7 @@ static void dbus_start_geofence_cb(gint fence_id, const gchar *app_id, gpointer } else { bssidlen = strlen(ap_bssid); LOGI_GEOFENCE("Connected AP: %s, %d\n", ap_bssid, bssidlen); - if (g_strcmp0(wifi_info->bssid, ap_bssid) == 0) { + if (g_strcmp0(wifi_info->bssid, ap_bssid) == 0) { status_to_be_emitted = GEOFENCE_FENCE_STATE_IN; geofence_server->connectedTrackingWifiFenceId = fence_id; } else { @@ -2223,6 +2223,9 @@ static void dbus_start_geofence_cb(gint fence_id, const gchar *app_id, gpointer } } + if (ap_bssid != NULL) + free(ap_bssid); + ap_bssid = NULL; } } else { LOGI_GEOFENCE("Wifi is not switched on..."); diff --git a/geofence-server/src/geofence_server_wifi.c b/geofence-server/src/geofence_server_wifi.c index 3217474..13fc92f 100644 --- a/geofence-server/src/geofence_server_wifi.c +++ b/geofence-server/src/geofence_server_wifi.c @@ -165,6 +165,9 @@ void wifi_rssi_level_changed(wifi_rssi_level_e rssi_level, void *user_data) state = GEOFENCE_PROXIMITY_FAR; emit_wifi_geofence_proximity_changed(geofence_server, geofence_server->connectedTrackingWifiFenceId, state); } + if (bssid != NULL) + free(bssid); + bssid = NULL; } } @@ -203,7 +206,7 @@ void wifi_device_state_changed(wifi_device_state_e state, void *user_data) LOGD_GEOFENCE("exit"); } -void __geofence_check_wifi_matched_bssid(wifi_connection_state_e state, char *bssid, void *user_data) +void __geofence_check_wifi_matched_bssid(wifi_connection_state_e state, char *bssid, void *user_data) { LOGD_GEOFENCE("Comparing the matching bssids"); GeofenceServer *geofence_server = (GeofenceServer *)user_data; @@ -263,4 +266,7 @@ void wifi_conn_state_changed(wifi_connection_state_e state, wifi_ap_h ap, void * LOGD_GEOFENCE("Wifi disconnected with [%s].", ap_bssid); __geofence_check_wifi_matched_bssid(state, ap_bssid, user_data); } + if (ap_bssid != NULL) + free(ap_bssid); + ap_bssid = NULL; } -- 2.7.4 From 2328a0d26512585c854887a8e855e69295f0bf8c Mon Sep 17 00:00:00 2001 From: chanywa Date: Sat, 3 Dec 2016 17:05:08 +0900 Subject: [PATCH 11/16] rename update script file Change-Id: I7bc7f3267f1d5e25ff0fd128ba44fef07389e844 --- packaging/geofence-server.spec | 6 +++--- scripts/{geofence-server_upgrade.sh => 500.geofence-server.sh} | 0 2 files changed, 3 insertions(+), 3 deletions(-) rename scripts/{geofence-server_upgrade.sh => 500.geofence-server.sh} (100%) diff --git a/packaging/geofence-server.spec b/packaging/geofence-server.spec index c385ca8..302063a 100644 --- a/packaging/geofence-server.spec +++ b/packaging/geofence-server.spec @@ -1,6 +1,6 @@ Name: geofence-server Summary: Geofence Server for Tizen -Version: 0.4.4 +Version: 0.4.5 Release: 1 Group: Location/Service License: Apache-2.0 @@ -59,7 +59,7 @@ rm -rf %{buildroot} %make_install mkdir -p %{buildroot}%{upgrade_script_path} -cp -f scripts/geofence-server_upgrade.sh %{buildroot}%{upgrade_script_path} +cp -f scripts/500.%{name}.sh %{buildroot}%{upgrade_script_path} #service for systemd is not installed to support only DBus auto activation #mkdir -p %{buildroot}%{_unitdir_user}/default.target.wants @@ -79,7 +79,7 @@ rm -rf %{buildroot} /usr/bin/geofence-server /usr/share/dbus-1/services/org.tizen.lbs.Providers.GeofenceServer.service %config %{_sysconfdir}/dbus-1/session.d/geofence-server.conf -%{upgrade_script_path}/geofence-server_upgrade.sh +%{upgrade_script_path}/500.%{name}.sh #service for systemd is not installed to support only DBus auto activation #%{_unitdir_user}/geofence-server.service diff --git a/scripts/geofence-server_upgrade.sh b/scripts/500.geofence-server.sh similarity index 100% rename from scripts/geofence-server_upgrade.sh rename to scripts/500.geofence-server.sh -- 2.7.4 From 450e23497c0a717ffc47acc84f73ed09a089d6cf Mon Sep 17 00:00:00 2001 From: jomui Date: Wed, 7 Dec 2016 14:02:26 +0900 Subject: [PATCH 12/16] set default fence state Signed-off-by: jomui Change-Id: I2b139261ba9f0b1216d62c0099ac24d2c7523f71 --- geofence-server/src/geofence_server.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/geofence-server/src/geofence_server.c b/geofence-server/src/geofence_server.c index 88fbf87..7f94948 100644 --- a/geofence-server/src/geofence_server.c +++ b/geofence-server/src/geofence_server.c @@ -2112,7 +2112,7 @@ static void dbus_start_geofence_cb(gint fence_id, const gchar *app_id, gpointer item_data->client_status = GEOFENCE_CLIENT_STATUS_START; if (item_data->common_info.type == GEOFENCE_TYPE_GEOPOINT) { - + status_to_be_emitted = GEOFENCE_FENCE_STATE_OUT; if (__is_support_wps() == true && __isDataConnected() == true && __isWifiOn() == true) { ret = __start_wps_positioning(geofence_server, __geofence_wps_position_changed_cb); if (ret != FENCE_ERR_NONE) { -- 2.7.4 From af4972bdf7246af7887c755c87b53cb013aff315 Mon Sep 17 00:00:00 2001 From: jomui Date: Wed, 1 Feb 2017 15:30:02 +0900 Subject: [PATCH 13/16] change tab to space Signed-off-by: jomui Change-Id: Iccea64f98112ed17607a4ea3320b456d83d9c41d --- geofence-server/src/geofence_server.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/geofence-server/src/geofence_server.c b/geofence-server/src/geofence_server.c index 7f94948..77eba2c 100644 --- a/geofence-server/src/geofence_server.c +++ b/geofence-server/src/geofence_server.c @@ -304,7 +304,7 @@ static int __emit_fence_inout(GeofenceServer *geofence_server, int fence_id, geo if (state == GEOFENCE_FENCE_STATE_IN) { /*LOGD_GEOFENCE("FENCE_IN to be set, current state: %d", item_data->common_info.status);*/ if (item_data->common_info.status != GEOFENCE_FENCE_STATE_IN) { - geofence_dbus_server_send_geofence_inout_changed(geofence_server->geofence_dbus_server, item_data->common_info.appid, fence_id, item_data->common_info.access_type, GEOFENCE_EMIT_STATE_IN); + geofence_dbus_server_send_geofence_inout_changed(geofence_server->geofence_dbus_server, item_data->common_info.appid, fence_id, item_data->common_info.access_type, GEOFENCE_EMIT_STATE_IN); if (item_data->client_status == GEOFENCE_CLIENT_STATUS_START) item_data->client_status = GEOFENCE_CLIENT_STATUS_RUNNING; -- 2.7.4 From e6f06724ae4778fcc2cf5250a82a9eba35b9c653 Mon Sep 17 00:00:00 2001 From: jomui Date: Fri, 17 Mar 2017 10:16:57 +0900 Subject: [PATCH 14/16] add license file in spec Signed-off-by: jomui Change-Id: I14bfcf443746d81be9a1e05676304ddb75754a59 --- packaging/geofence-server.spec | 1 + 1 file changed, 1 insertion(+) diff --git a/packaging/geofence-server.spec b/packaging/geofence-server.spec index 302063a..781c821 100644 --- a/packaging/geofence-server.spec +++ b/packaging/geofence-server.spec @@ -75,6 +75,7 @@ rm -rf %{buildroot} %files %manifest geofence-server.manifest +%license LICENSE %defattr(-,root,root,-) /usr/bin/geofence-server /usr/share/dbus-1/services/org.tizen.lbs.Providers.GeofenceServer.service -- 2.7.4 From 55f095fd967a162f500c256eff76134a45b4cd85 Mon Sep 17 00:00:00 2001 From: jomui Date: Tue, 28 Mar 2017 09:58:11 +0900 Subject: [PATCH 15/16] add license macro Signed-off-by: jomui Change-Id: If01d516518bda50901a668a85da017bf0009e60b --- packaging/geofence-server.spec | 1 + 1 file changed, 1 insertion(+) diff --git a/packaging/geofence-server.spec b/packaging/geofence-server.spec index 781c821..ee27058 100644 --- a/packaging/geofence-server.spec +++ b/packaging/geofence-server.spec @@ -103,4 +103,5 @@ Geofence Server for Tizen %files -n location-geofence-server %manifest location-geofence-server.manifest +%license LICENSE %{_libdir}/geofence/module/libgeofence.so* -- 2.7.4 From 786fc1bacea5591ae0a4984dfd7ce7b52016e3d5 Mon Sep 17 00:00:00 2001 From: jomui Date: Wed, 12 Apr 2017 10:08:11 +0900 Subject: [PATCH 16/16] fixed for deprecate WIFI API Signed-off-by: jomui Change-Id: I1a6a7a8d0fd69ec6f84ac85ac0c6303636f32da1 --- CMakeLists.txt | 2 +- geofence-server/src/geofence_server.c | 87 ++++++++++++++----------- geofence-server/src/geofence_server.h | 8 +-- geofence-server/src/geofence_server_bluetooth.c | 4 +- geofence-server/src/geofence_server_db.c | 6 +- geofence-server/src/geofence_server_private.h | 2 + geofence-server/src/geofence_server_wifi.c | 44 ++++++------- geofence-server/src/geofence_server_wifi.h | 6 +- geofence-server/src/server.c | 74 +++++++++++---------- geofence-server/src/server.h | 4 +- packaging/geofence-server.spec | 4 +- 11 files changed, 127 insertions(+), 114 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a416dfa..6600afd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ SET(BIN_DIR "${PREFIX}/bin") #Dependencies SET(common_dp "glib-2.0 geofence-dbus dlog gio-2.0 capi-appfw-app-manager") -SET(server_dp "${common_dp} network vconf vconf-internal-keys capi-system-info gthread-2.0 gio-unix-2.0 sqlite3 db-util alarm-service deviced capi-location-manager capi-network-bluetooth capi-network-wifi libcore-context-manager capi-system-device libtzplatform-config") +SET(server_dp "${common_dp} network vconf vconf-internal-keys capi-system-info gthread-2.0 gio-unix-2.0 sqlite3 db-util alarm-service deviced capi-location-manager capi-network-bluetooth capi-network-wifi-manager libcore-context-manager capi-system-device libtzplatform-config") SET(module_dp "${common_dp} gmodule-2.0 capi-geofence-manager") # Set required packages diff --git a/geofence-server/src/geofence_server.c b/geofence-server/src/geofence_server.c index 77eba2c..de56328 100644 --- a/geofence-server/src/geofence_server.c +++ b/geofence-server/src/geofence_server.c @@ -35,7 +35,7 @@ #include "geofence_server_alarm.h" #include "geofence_server_internal.h" #include "geofence_server_bluetooth.h" -#include +#include #include #include @@ -81,39 +81,43 @@ static bool __is_support_wps() return is_wps_supported; } -static const char *__convert_wifi_error_to_string(wifi_error_e err_type) +static const char *__convert_wifi_error_to_string(wifi_manager_error_e err_type) { switch (err_type) { - case WIFI_ERROR_NONE: + case WIFI_MANAGER_ERROR_NONE: return "NONE"; - case WIFI_ERROR_INVALID_PARAMETER: + case WIFI_MANAGER_ERROR_INVALID_PARAMETER: return "INVALID_PARAMETER"; - case WIFI_ERROR_OUT_OF_MEMORY: + case WIFI_MANAGER_ERROR_OUT_OF_MEMORY: return "OUT_OF_MEMORY"; - case WIFI_ERROR_INVALID_OPERATION: + case WIFI_MANAGER_ERROR_INVALID_OPERATION: return "INVALID_OPERATION"; - case WIFI_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED: + case WIFI_MANAGER_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED: return "ADDRESS_FAMILY_NOT_SUPPORTED"; - case WIFI_ERROR_OPERATION_FAILED: + case WIFI_MANAGER_ERROR_OPERATION_FAILED: return "OPERATION_FAILED"; - case WIFI_ERROR_NO_CONNECTION: + case WIFI_MANAGER_ERROR_NO_CONNECTION: return "NO_CONNECTION"; - case WIFI_ERROR_NOW_IN_PROGRESS: + case WIFI_MANAGER_ERROR_NOW_IN_PROGRESS: return "NOW_IN_PROGRESS"; - case WIFI_ERROR_ALREADY_EXISTS: + case WIFI_MANAGER_ERROR_ALREADY_EXISTS: return "ALREADY_EXISTS"; - case WIFI_ERROR_OPERATION_ABORTED: + case WIFI_MANAGER_ERROR_OPERATION_ABORTED: return "OPERATION_ABORTED"; - case WIFI_ERROR_DHCP_FAILED: + case WIFI_MANAGER_ERROR_DHCP_FAILED: return "DHCP_FAILED"; - case WIFI_ERROR_INVALID_KEY: + case WIFI_MANAGER_ERROR_INVALID_KEY: return "INVALID_KEY"; - case WIFI_ERROR_NO_REPLY: + case WIFI_MANAGER_ERROR_NO_REPLY: return "NO_REPLY"; - case WIFI_ERROR_SECURITY_RESTRICTED: + case WIFI_MANAGER_ERROR_SECURITY_RESTRICTED: return "SECURITY_RESTRICTED"; - case WIFI_ERROR_PERMISSION_DENIED: + case WIFI_MANAGER_ERROR_ALREADY_INITIALIZED: + return "ALREADY_INITIALIZED"; + case WIFI_MANAGER_ERROR_PERMISSION_DENIED: return "PERMISSION_DENIED"; + case WIFI_MANAGER_ERROR_NOT_SUPPORTED: + return "NOT_SUPPORTED"; default: return "NOT Defined"; } @@ -1281,7 +1285,7 @@ static void __free_geofence_list(gpointer userdata) static int __check_fence_permission(int fence_id, const char *app_id) { access_type_e access_type = ACCESS_TYPE_PUBLIC; - char *appid; + char *appid = NULL; int ret = FENCE_ERR_NONE; ret = geofence_manager_get_access_type(fence_id, -1, &access_type); if (ret != FENCE_ERR_NONE) { @@ -1295,17 +1299,19 @@ static int __check_fence_permission(int fence_id, const char *app_id) return -1; } if (g_strcmp0(appid, app_id)) { - LOGE("Not authorized to access this private fence[%d]", fence_id); + LOGE("Not authorized to access this private fence[%d]", fence_id); + g_free(appid); return 0; } } + g_free(appid); return 1; } static int __check_place_permission(int place_id, const char *app_id) { access_type_e access_type = ACCESS_TYPE_PUBLIC; - char *appid; + char *appid = NULL; int ret = FENCE_ERR_NONE; ret = geofence_manager_get_access_type(-1, place_id, &access_type); if (ret != FENCE_ERR_NONE) { @@ -1319,10 +1325,12 @@ static int __check_place_permission(int place_id, const char *app_id) return -1; } if (g_strcmp0(appid, app_id)) { - LOGE("Not authorized to access this private place[%d]", place_id); + LOGE("Not authorized to access this private place[%d]", place_id); + g_free(appid); return 0; } } + g_free(appid); return 1; } @@ -1572,7 +1580,7 @@ static int dbus_add_fence_cb(const gchar *app_id, g_strlcpy(geocoordinate_info->address, address, ADDRESS_LEN); /*Geopoint information is saved in the DB*/ - ret = geofence_manager_set_geocoordinate_info(fence_id, geocoordinate_info); + ret = geofence_manager_set_geocoordinate_info(fence_id, geocoordinate_info); if (ret != FENCE_ERR_NONE) { LOGI_GEOFENCE("Fail to set geocoordinate_info"); ret = geofence_manager_delete_fence_info(fence_id); @@ -1796,7 +1804,7 @@ static void dbus_remove_fence_cb(gint fence_id, const gchar *app_id, gpointer us g_return_if_fail(geofence_server); int ret = FENCE_ERR_NONE; int place_id = -1; - char *app_id_db; + char *app_id_db = NULL; access_type_e access_type = ACCESS_TYPE_UNKNOWN; /*//////////Required to be sent in the event callback////////////////--*/ @@ -2187,9 +2195,9 @@ static void dbus_start_geofence_cb(gint fence_id, const gchar *app_id, gpointer } } else if (item_data->common_info.type == GEOFENCE_TYPE_WIFI) { LOGI_GEOFENCE("fence_type [GEOFENCE_TYPE_WIFI]"); - wifi_error_e rv = WIFI_ERROR_NONE; + wifi_manager_error_e rv = WIFI_MANAGER_ERROR_NONE; int nWifiState; - wifi_ap_h ap_h; + wifi_manager_ap_h ap_h; char *ap_bssid = NULL; int bssidlen; bssid_info_s *wifi_info = NULL; @@ -2201,16 +2209,16 @@ static void dbus_start_geofence_cb(gint fence_id, const gchar *app_id, gpointer if (item_data->priv != NULL) wifi_info = (bssid_info_s *) item_data->priv; - rv = wifi_get_connected_ap(&ap_h); - if (rv != WIFI_ERROR_NONE) { + rv = wifi_manager_get_connected_ap(geofence_server->wifi_h, &ap_h); + if (rv != WIFI_MANAGER_ERROR_NONE) { LOGI_GEOFENCE("Fail/not connected to get the connected AP: [%s] , geofence will be added to the fence list", __convert_wifi_error_to_string(rv)); - if (rv == WIFI_ERROR_NO_CONNECTION) { + if (rv == WIFI_MANAGER_ERROR_NO_CONNECTION) { LOGI_GEOFENCE("Not connected to any AP"); status_to_be_emitted = GEOFENCE_FENCE_STATE_OUT; } } else { - rv = wifi_ap_get_bssid(ap_h, &ap_bssid); - if (rv != WIFI_ERROR_NONE) { + rv = wifi_manager_ap_get_bssid(ap_h, &ap_bssid); + if (rv != WIFI_MANAGER_ERROR_NONE) { LOGI_GEOFENCE("Fail to get the bssid: [%d]\n", __convert_wifi_error_to_string(rv)); } else { bssidlen = strlen(ap_bssid); @@ -2456,16 +2464,14 @@ static GVariant *dbus_get_geofences_cb(int place_id, const gchar *app_id, int *f if ((place_info != NULL) && (place_info->access_type == ACCESS_TYPE_PRIVATE)) { if (g_strcmp0(app_id, place_info->appid) != 0) { LOGI_GEOFENCE("Not authorized to access this private place[%d]", place_id); - if (place_info) - g_free(place_info); + g_free(place_info); /* Send ZERO data gvariant*/ *errorCode = GEOFENCE_SERVER_ERROR_PLACE_ACCESS_DENIED; *fenceCnt = fence_cnt; g_variant_builder_init(&b, G_VARIANT_TYPE("aa{sv}")); return g_variant_builder_end(&b); } - if (place_info) - g_free(place_info); + g_free(place_info); } ret = geofence_manager_get_fence_list_from_db(&count, &fence_list, place_id); } @@ -2654,6 +2660,8 @@ static void __init_geofencemanager(GeofenceServer *geofence_server) geofence_server->activity_run_h = NULL; geofence_server->activity_in_vehicle_h = NULL; + geofence_server->wifi_h = NULL; + /*Initializing the DB to store the fence informations*/ if (geofence_manager_db_init() != FENCE_ERR_NONE) LOGI_GEOFENCE("Error initalizing the DB"); @@ -2716,10 +2724,9 @@ int __copy_geofence_to_item_data(int fence_id, GeofenceItemData *item_data) if (FENCE_ERR_NONE != geofence_manager_get_enable_status(fence_id, &item_data->common_info.enable)) return FENCE_ERR_SQLITE_FAIL; - if (FENCE_ERR_NONE != geofence_manager_get_appid_from_geofence(fence_id, &app_id)) { - g_free(app_id); + if (FENCE_ERR_NONE != geofence_manager_get_appid_from_geofence(fence_id, &app_id)) return FENCE_ERR_SQLITE_FAIL; - } else { + else { g_strlcpy(item_data->common_info.appid, app_id, APP_ID_LEN); g_free(app_id); } @@ -2779,6 +2786,10 @@ static void __add_left_fences(gpointer user_data) * } */ GeofenceItemData *item_data = (GeofenceItemData *)g_malloc0(sizeof(GeofenceItemData)); + if (item_data == NULL) { + LOGI_GEOFENCE("Unable to add the fence because of malloc fail"); + return; + } if (FENCE_ERR_NONE != __copy_geofence_to_item_data(fence_id, item_data)) { g_free(item_data); return; @@ -2871,7 +2882,7 @@ int main(int argc, char **argv) LOGD_GEOFENCE("GEOFENCE_manager deamon Stop...."); /*This call goes to server.c and deregisters all the callbacks w.r.t bt and wifi*/ - _geofence_deinitialize_geofence_server(); + _geofence_deinitialize_geofence_server(geofenceserver); #ifdef TIZEN_ENGINEER_MODE _deinit_log(); diff --git a/geofence-server/src/geofence_server.h b/geofence-server/src/geofence_server.h index 0d5d635..19a3044 100644 --- a/geofence-server/src/geofence_server.h +++ b/geofence-server/src/geofence_server.h @@ -24,7 +24,7 @@ #include #include -#include +#include #include #include #include @@ -71,7 +71,7 @@ typedef void (*geofence_device_display_changed_cb)(device_callback_e type, void * @Param[in] user_data The user data to be returned * @see None. */ -typedef void (*geofence_wifi_conn_state_changed_cb)(wifi_connection_state_e state, wifi_ap_h ap, void *user_data); +typedef void (*geofence_wifi_conn_state_changed_cb)(wifi_manager_connection_state_e state, wifi_manager_ap_h ap, void *user_data); /** * @brief Wifi device status change callback @@ -80,7 +80,7 @@ typedef void (*geofence_wifi_conn_state_changed_cb)(wifi_connection_state_e stat * @Param[in] user_data The user data to be returned * @see None. */ -typedef void (*geofence_wifi_device_state_changed_cb)(wifi_device_state_e state, void *user_data); +typedef void (*geofence_wifi_device_state_changed_cb)(wifi_manager_device_state_e state, void *user_data); /** * @brief Network scan status change callback @@ -121,7 +121,7 @@ typedef void (*geofence_gps_setting_changed_cb)(location_method_e method, bool e * @see wifi_set_rssi_level_changed_cb() * @see wifi_unset_rssi_level_changed_cb() */ -typedef void(*geofence_wifi_rssi_level_changed_cb)(wifi_rssi_level_e rssi_level, void *user_data); +typedef void(*geofence_wifi_rssi_level_changed_cb)(wifi_manager_rssi_level_e rssi_level, void *user_data); /** * Geofence callback structure. diff --git a/geofence-server/src/geofence_server_bluetooth.c b/geofence-server/src/geofence_server_bluetooth.c index ccb689a..30dbf51 100644 --- a/geofence-server/src/geofence_server_bluetooth.c +++ b/geofence-server/src/geofence_server_bluetooth.c @@ -107,9 +107,7 @@ static void emit_bt_geofence_proximity_changed(GeofenceServer *geofence_server, } item_data->common_info.proximity_status = fence_proximity_status; } - - if (app_id) - free(app_id); + g_free(app_id); } diff --git a/geofence-server/src/geofence_server_db.c b/geofence-server/src/geofence_server_db.c index 26273be..8c85238 100755 --- a/geofence-server/src/geofence_server_db.c +++ b/geofence-server/src/geofence_server_db.c @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #include #include @@ -618,8 +618,8 @@ void __geofence_manager_generate_password(char *password) if (ret != BT_ERROR_NONE) LOGD_GEOFENCE("bt address get fail %d", ret); - ret = wifi_get_mac_address(&wifi_address); - if (ret != WIFI_ERROR_NONE) + ret = wifi_manager_get_mac_address(&wifi_address); + if (ret != WIFI_MANAGER_ERROR_NONE) LOGD_GEOFENCE("wifi address get fail %d", ret); if (bt_address) { diff --git a/geofence-server/src/geofence_server_private.h b/geofence-server/src/geofence_server_private.h index 729054b..e34b023 100644 --- a/geofence-server/src/geofence_server_private.h +++ b/geofence-server/src/geofence_server_private.h @@ -181,6 +181,8 @@ typedef struct { activity_h activity_walk_h; activity_h activity_run_h; activity_h activity_in_vehicle_h; + + wifi_manager_h wifi_h; } GeofenceServer; #ifdef __cplusplus diff --git a/geofence-server/src/geofence_server_wifi.c b/geofence-server/src/geofence_server_wifi.c index 13fc92f..5001594 100644 --- a/geofence-server/src/geofence_server_wifi.c +++ b/geofence-server/src/geofence_server_wifi.c @@ -54,8 +54,7 @@ static void emit_wifi_geofence_inout_changed(GeofenceServer *geofence_server, in item_data->common_info.status = GEOFENCE_FENCE_STATE_OUT; } } - if (app_id) - free(app_id); + g_free(app_id); } static bool __check_for_match(char *str1, char *str2) @@ -132,34 +131,33 @@ static void emit_wifi_geofence_proximity_changed(GeofenceServer *geofence_server } item_data->common_info.proximity_status = fence_proximity_status; } - if (app_id) - free(app_id); + g_free(app_id); } -void wifi_rssi_level_changed(wifi_rssi_level_e rssi_level, void *user_data) +void wifi_rssi_level_changed(wifi_manager_rssi_level_e rssi_level, void *user_data) { FUNC_ENTRANCE_SERVER GeofenceServer *geofence_server = (GeofenceServer *) user_data; g_return_if_fail(geofence_server); - wifi_ap_h ap_h; + wifi_manager_ap_h ap_h; char *bssid = NULL; geofence_proximity_state_e state = GEOFENCE_PROXIMITY_UNCERTAIN; - wifi_error_e rv = WIFI_ERROR_NONE; + wifi_manager_error_e rv = WIFI_MANAGER_ERROR_NONE; LOGI_GEOFENCE("running cnt: %d, connected id: %d", geofence_server->running_wifi_cnt, geofence_server->connectedTrackingWifiFenceId); if (geofence_server->running_wifi_cnt > 0 && geofence_server->connectedTrackingWifiFenceId != -1) { - rv = wifi_get_connected_ap(&ap_h); - if (rv != WIFI_ERROR_NONE) { + rv = wifi_manager_get_connected_ap(geofence_server->wifi_h, &ap_h); + if (rv != WIFI_MANAGER_ERROR_NONE) { LOGE_GEOFENCE("Fail to get the connected AP: Error - %d", rv); return; } - rv = wifi_ap_get_bssid(ap_h, &bssid); - if (rv != WIFI_ERROR_NONE) { + rv = wifi_manager_ap_get_bssid(ap_h, &bssid); + if (rv != WIFI_MANAGER_ERROR_NONE) { LOGI_GEOFENCE("Fail to get the bssid: [%d]", rv); } else { /*Emit the proximity alert here using mConnectedFenceId*/ - if (rssi_level == WIFI_RSSI_LEVEL_4) + if (rssi_level == WIFI_MANAGER_RSSI_LEVEL_4) state = GEOFENCE_PROXIMITY_IMMEDIATE; - else if (rssi_level == WIFI_RSSI_LEVEL_3) + else if (rssi_level == WIFI_MANAGER_RSSI_LEVEL_3) state = GEOFENCE_PROXIMITY_NEAR; else state = GEOFENCE_PROXIMITY_FAR; @@ -171,7 +169,7 @@ void wifi_rssi_level_changed(wifi_rssi_level_e rssi_level, void *user_data) } } -void wifi_device_state_changed(wifi_device_state_e state, void *user_data) +void wifi_device_state_changed(wifi_manager_device_state_e state, void *user_data) { FUNC_ENTRANCE_SERVER GeofenceServer *geofence_server = (GeofenceServer *) user_data; @@ -196,7 +194,7 @@ void wifi_device_state_changed(wifi_device_state_e state, void *user_data) if (fence_type != GEOFENCE_TYPE_WIFI) continue; - if (state == WIFI_DEVICE_STATE_DEACTIVATED) { + if (state == WIFI_MANAGER_DEVICE_STATE_DEACTIVATED) { LOGD_GEOFENCE("Emitted to fence_id [%d] GEOFENCE_FENCE_STATE_OUT", fence_id); emit_wifi_geofence_inout_changed(geofence_server, fence_id, GEOFENCE_FENCE_STATE_OUT); emit_wifi_geofence_proximity_changed(geofence_server, fence_id, GEOFENCE_PROXIMITY_UNCERTAIN); @@ -206,7 +204,7 @@ void wifi_device_state_changed(wifi_device_state_e state, void *user_data) LOGD_GEOFENCE("exit"); } -void __geofence_check_wifi_matched_bssid(wifi_connection_state_e state, char *bssid, void *user_data) +void __geofence_check_wifi_matched_bssid(wifi_manager_connection_state_e state, char *bssid, void *user_data) { LOGD_GEOFENCE("Comparing the matching bssids"); GeofenceServer *geofence_server = (GeofenceServer *)user_data; @@ -230,10 +228,10 @@ void __geofence_check_wifi_matched_bssid(wifi_connection_state_e state, char *bs } if (!g_ascii_strcasecmp(bssid_info->bssid, bssid) || !g_ascii_strcasecmp(g_strdelimit(bssid_info->bssid, "-", ':'), bssid)) { LOGI_GEOFENCE("Matched wifi fence: fence_id = %d, bssid = %s", tracking_fence_id, bssid_info->bssid); - if (state == WIFI_CONNECTION_STATE_CONNECTED) { + if (state == WIFI_MANAGER_CONNECTION_STATE_CONNECTED) { emit_wifi_geofence_inout_changed(geofence_server, tracking_fence_id, GEOFENCE_FENCE_STATE_IN); geofence_server->connectedTrackingWifiFenceId = tracking_fence_id; - } else if (state == WIFI_CONNECTION_STATE_DISCONNECTED) { + } else if (state == WIFI_MANAGER_CONNECTION_STATE_DISCONNECTED) { emit_wifi_geofence_inout_changed(geofence_server, tracking_fence_id, GEOFENCE_FENCE_STATE_OUT); emit_wifi_geofence_proximity_changed(geofence_server, tracking_fence_id, GEOFENCE_PROXIMITY_UNCERTAIN); geofence_server->connectedTrackingWifiFenceId = -1; @@ -245,24 +243,24 @@ void __geofence_check_wifi_matched_bssid(wifi_connection_state_e state, char *bs } -void wifi_conn_state_changed(wifi_connection_state_e state, wifi_ap_h ap, void *user_data) +void wifi_conn_state_changed(wifi_manager_connection_state_e state, wifi_manager_ap_h ap, void *user_data) { LOGD_GEOFENCE("wifi_conn_state_changed"); GeofenceServer *geofence_server = (GeofenceServer *)user_data; char *ap_bssid = NULL; int rv = 0; g_return_if_fail(geofence_server); - rv = wifi_ap_get_bssid(ap, &ap_bssid); + rv = wifi_manager_ap_get_bssid(ap, &ap_bssid); - if (rv != WIFI_ERROR_NONE) { + if (rv != WIFI_MANAGER_ERROR_NONE) { LOGD_GEOFENCE("Failed to get the bssid"); return; } - if (state == WIFI_CONNECTION_STATE_CONNECTED) { + if (state == WIFI_MANAGER_CONNECTION_STATE_CONNECTED) { LOGD_GEOFENCE("Wifi connected to [%s].", ap_bssid); __geofence_check_wifi_matched_bssid(state, ap_bssid, user_data); - } else if (state == WIFI_CONNECTION_STATE_DISCONNECTED) { + } else if (state == WIFI_MANAGER_CONNECTION_STATE_DISCONNECTED) { LOGD_GEOFENCE("Wifi disconnected with [%s].", ap_bssid); __geofence_check_wifi_matched_bssid(state, ap_bssid, user_data); } diff --git a/geofence-server/src/geofence_server_wifi.h b/geofence-server/src/geofence_server_wifi.h index 3932ab7..3c390d8 100644 --- a/geofence-server/src/geofence_server_wifi.h +++ b/geofence-server/src/geofence_server_wifi.h @@ -54,7 +54,7 @@ gboolean geofence_get_enable_wifi_state(gpointer data); * @Param[in] user_data The user data * @see None. */ -void wifi_conn_state_changed(wifi_connection_state_e state, wifi_ap_h ap, void *user_data); +void wifi_conn_state_changed(wifi_manager_connection_state_e state, wifi_manager_ap_h ap, void *user_data); /** * @brief Wifi device status change @@ -62,7 +62,7 @@ void wifi_conn_state_changed(wifi_connection_state_e state, wifi_ap_h ap, void * * @Param[in] user_data The user data * @see None. */ -void wifi_device_state_changed(wifi_device_state_e state, void *user_data); +void wifi_device_state_changed(wifi_manager_device_state_e state, void *user_data); /** * @brief Wifi AP rssi level change @@ -70,5 +70,5 @@ void wifi_device_state_changed(wifi_device_state_e state, void *user_data); * @Param[in] user_data The user data * @see None. **/ -void wifi_rssi_level_changed(wifi_rssi_level_e rssi_level, void *user_data); +void wifi_rssi_level_changed(wifi_manager_rssi_level_e rssi_level, void *user_data); #endif /* GEOFENCE_MANAGER_WIFI_H_ */ diff --git a/geofence-server/src/server.c b/geofence-server/src/server.c index b114669..66dc4fc 100644 --- a/geofence-server/src/server.c +++ b/geofence-server/src/server.c @@ -58,7 +58,7 @@ #include "geofence_server_private.h" /* for bluetooth-geofence*/ #include -#include +#include #include #define TIZEN_ENGINEER_MODE @@ -162,7 +162,7 @@ static void __geofence_bt_adapter_device_discovery_state_changed_cb(int result, LOGD_GEOFENCE("exit"); } -static void __geofence_wifi_device_connection_state_changed_cb(wifi_connection_state_e state, wifi_ap_h ap, void *user_data) +static void __geofence_wifi_device_connection_state_changed_cb(wifi_manager_connection_state_e state, wifi_manager_ap_h ap, void *user_data) { LOGD_GEOFENCE("__geofence_wifi_device_connection_state_changed_cb()"); @@ -175,7 +175,7 @@ static void __geofence_wifi_device_connection_state_changed_cb(wifi_connection_s } } -static void __geofence_wifi_device_state_changed_cb(wifi_device_state_e state, void *user_data) +static void __geofence_wifi_device_state_changed_cb(wifi_manager_device_state_e state, void *user_data) { LOGD_GEOFENCE("__geofence_wifi_device_state_changed_cb()"); @@ -188,7 +188,7 @@ static void __geofence_wifi_device_state_changed_cb(wifi_device_state_e state, v } } -static void __geofence_wifi_rssi_level_changed_cb(wifi_rssi_level_e rssi_level, void *user_data) +static void __geofence_wifi_rssi_level_changed_cb(wifi_manager_rssi_level_e rssi_level, void *user_data) { LOGD_GEOFENCE("__geofence_wifi_rssi_level_changed_cb()"); GeofenceServer *geofence_server = (GeofenceServer *)user_data; @@ -269,9 +269,9 @@ int _geofence_initialize_geofence_server(GeofenceServer *geofence_server) if (BT_ERROR_NONE != ret) LOGE_GEOFENCE("Failed to set the callback for discovery"); - ret = wifi_initialize(); - if (WIFI_ERROR_NONE != ret) { - LOGD_GEOFENCE("wifi_initialize() failed(%d).", ret); + ret = wifi_manager_initialize(&(geofence_server->wifi_h)); + if (WIFI_MANAGER_ERROR_NONE != ret) { + LOGD_GEOFENCE("wifi_manager_initialize() failed(%d).", ret); return -1; } @@ -282,37 +282,40 @@ int _geofence_initialize_geofence_server(GeofenceServer *geofence_server) LOGD_GEOFENCE("net_register_client() succeeded"); } - ret = wifi_set_connection_state_changed_cb(__geofence_wifi_device_connection_state_changed_cb, geofence_server); - if (WIFI_ERROR_NONE != ret) { - LOGD_GEOFENCE("wifi_set_connection_state_changed_cb() failed(%d).", ret); - ret = wifi_deinitialize(); - if (ret != WIFI_ERROR_NONE) - LOGD_GEOFENCE("wifi_deinitialize() failed(%d).", ret); + ret = wifi_manager_set_connection_state_changed_cb(geofence_server->wifi_h, __geofence_wifi_device_connection_state_changed_cb, geofence_server); + if (WIFI_MANAGER_ERROR_NONE != ret) { + LOGD_GEOFENCE("wifi_manager_set_connection_state_changed_cb() failed(%d).", ret); + ret = wifi_manager_deinitialize(geofence_server->wifi_h); + if (ret != WIFI_MANAGER_ERROR_NONE) + LOGD_GEOFENCE("wifi_manager_deinitialize() failed(%d).", ret); + geofence_server->wifi_h = NULL; return -1; } else { - LOGD_GEOFENCE("wifi_set_connection_state_changed_cb() success.", ret); + LOGD_GEOFENCE("wifi_manager_set_connection_state_changed_cb() success.", ret); } - ret = wifi_set_device_state_changed_cb(__geofence_wifi_device_state_changed_cb, geofence_server); - if (WIFI_ERROR_NONE != ret) { - LOGD_GEOFENCE("wifi_set_device_state_changed_cb() failed(%d).", ret); - ret = wifi_deinitialize(); - if (ret != WIFI_ERROR_NONE) - LOGD_GEOFENCE("wifi_deinitialize() failed(%d).", ret); + ret = wifi_manager_set_device_state_changed_cb(geofence_server->wifi_h, __geofence_wifi_device_state_changed_cb, geofence_server); + if (WIFI_MANAGER_ERROR_NONE != ret) { + LOGD_GEOFENCE("wifi_manager_set_device_state_changed_cb() failed(%d).", ret); + ret = wifi_manager_deinitialize(geofence_server->wifi_h); + if (ret != WIFI_MANAGER_ERROR_NONE) + LOGD_GEOFENCE("wifi_manager_deinitialize() failed(%d).", ret); + geofence_server->wifi_h = NULL; return -1; } else { - LOGD_GEOFENCE("wifi_set_device_state_changed_cb() success.", ret); + LOGD_GEOFENCE("wifi_manager_set_device_state_changed_cb() success.", ret); } - ret = wifi_set_rssi_level_changed_cb(__geofence_wifi_rssi_level_changed_cb, geofence_server); - if (WIFI_ERROR_NONE != ret) { - LOGD_GEOFENCE("wifi_set_rssi_level_changed_cb() failed(%d).", ret); - ret = wifi_deinitialize(); - if (ret != WIFI_ERROR_NONE) - LOGD_GEOFENCE("wifi_deinitialize() failed(%d).", ret); + ret = wifi_manager_set_rssi_level_changed_cb(geofence_server->wifi_h, __geofence_wifi_rssi_level_changed_cb, geofence_server); + if (WIFI_MANAGER_ERROR_NONE != ret) { + LOGD_GEOFENCE("wifi_manager_set_rssi_level_changed_cb() failed(%d).", ret); + ret = wifi_manager_deinitialize(geofence_server->wifi_h); + if (ret != WIFI_MANAGER_ERROR_NONE) + LOGD_GEOFENCE("wifi_manager_deinitialize() failed(%d).", ret); + geofence_server->wifi_h = NULL; return -1; } else { - LOGD_GEOFENCE("wifi_set_rssi_level_changed_cb() success.", ret); + LOGD_GEOFENCE("wifi_manager_set_rssi_level_changed_cb() success.", ret); } /*Set the callback for location*/ @@ -334,7 +337,7 @@ int _geofence_initialize_geofence_server(GeofenceServer *geofence_server) return 0; } -int _geofence_deinitialize_geofence_server() +int _geofence_deinitialize_geofence_server(GeofenceServer *geofence_server) { /* to denit geofence engine staff...*/ @@ -357,15 +360,16 @@ int _geofence_deinitialize_geofence_server() LOGD_GEOFENCE("bt_deinitialize() success.\n"); /*unset the callbacks related to wifi*/ - if (wifi_unset_connection_state_changed_cb() != WIFI_ERROR_NONE) - LOGD_GEOFENCE("wifi_unset_connection_state_changed_cb() failed.\n"); + if (wifi_manager_unset_connection_state_changed_cb(geofence_server->wifi_h) != WIFI_MANAGER_ERROR_NONE) + LOGD_GEOFENCE("wifi_manager_unset_connection_state_changed_cb() failed.\n"); else - LOGD_GEOFENCE("wifi_unset_connection_state_changed_cb() success.\n"); + LOGD_GEOFENCE("wifi_manager_unset_connection_state_changed_cb() success.\n"); - if (wifi_deinitialize() != WIFI_ERROR_NONE) - LOGD_GEOFENCE("wifi_deinitialize() failed.\n"); + if (wifi_manager_deinitialize(geofence_server->wifi_h) != WIFI_MANAGER_ERROR_NONE) + LOGD_GEOFENCE("wifi_manager_deinitialize() failed.\n"); else - LOGD_GEOFENCE("wifi_deinitialize() success.\n"); + LOGD_GEOFENCE("wifi_manager_deinitialize() success.\n"); + geofence_server->wifi_h = NULL; if (location_manager_unset_setting_changed_cb(LOCATIONS_METHOD_GPS) != LOCATIONS_ERROR_NONE) LOGD_GEOFENCE("GPS unsetting failed\n"); diff --git a/geofence-server/src/server.h b/geofence-server/src/server.h index 154db89..8788c7a 100644 --- a/geofence-server/src/server.h +++ b/geofence-server/src/server.h @@ -25,7 +25,7 @@ #include "geofence_server.h" #include "geofence_server_private.h" #include -#include +#include typedef enum { GEOFENCE_STATE_AVAILABLE, @@ -47,7 +47,7 @@ int _geofence_initialize_geofence_server(GeofenceServer *geofence_server); * @retval 0 if success * @see none */ -int _geofence_deinitialize_geofence_server(); +int _geofence_deinitialize_geofence_server(GeofenceServer *geofence_server); /** * @brief Registers the update callbacks diff --git a/packaging/geofence-server.spec b/packaging/geofence-server.spec index ee27058..72309b8 100644 --- a/packaging/geofence-server.spec +++ b/packaging/geofence-server.spec @@ -1,6 +1,6 @@ Name: geofence-server Summary: Geofence Server for Tizen -Version: 0.4.5 +Version: 0.4.6 Release: 1 Group: Location/Service License: Apache-2.0 @@ -27,7 +27,7 @@ BuildRequires: pkgconfig(vconf-internal-keys) BuildRequires: pkgconfig(capi-system-info) BuildRequires: pkgconfig(capi-appfw-app-manager) BuildRequires: pkgconfig(capi-location-manager) -BuildRequires: pkgconfig(capi-network-wifi) +BuildRequires: pkgconfig(capi-network-wifi-manager) BuildRequires: pkgconfig(capi-network-bluetooth) BuildRequires: pkgconfig(libcore-context-manager) BuildRequires: pkgconfig(capi-system-device) -- 2.7.4