diff options
author | jomui <jongmun.woo@samsung.com> | 2015-07-29 19:02:27 +0900 |
---|---|---|
committer | jomui <jongmun.woo@samsung.com> | 2015-07-29 19:03:03 +0900 |
commit | 5af8f5161212ad7fa0812d928eb684e5d821760c (patch) | |
tree | 0daddf607f45b501ad2eea062b736f0bbc142f72 /geofence | |
parent | 0851a7d94a6df955b89bf9e68414b05ad0ab2524 (diff) | |
download | geofence-dbus-5af8f5161212ad7fa0812d928eb684e5d821760c.tar.gz geofence-dbus-5af8f5161212ad7fa0812d928eb684e5d821760c.tar.bz2 geofence-dbus-5af8f5161212ad7fa0812d928eb684e5d821760c.zip |
sync with tizen_2.4submit/tizen/20150810.082148submit/tizen/20150810.015449accepted/tizen/wearable/20150810.102058accepted/tizen/tv/20150810.101908accepted/tizen/mobile/20150810.101721
Signed-off-by: jomui <jongmun.woo@samsung.com>
Change-Id: I08fd2e26eef6596973bbf78e9c13e408dfb4bc04
Diffstat (limited to 'geofence')
-rw-r--r-- | geofence/include/geofence_client.h | 87 | ||||
-rw-r--r-- | geofence/include/geofence_client_priv.h | 2 | ||||
-rw-r--r-- | geofence/src/geofence_client.c | 615 |
3 files changed, 256 insertions, 448 deletions
diff --git a/geofence/include/geofence_client.h b/geofence/include/geofence_client.h index a5f85a5..2d73956 100644 --- a/geofence/include/geofence_client.h +++ b/geofence/include/geofence_client.h @@ -22,38 +22,40 @@ __BEGIN_DECLS #include <gio/gio.h> +#include <tizen_error.h> + typedef enum { - GEOFENCE_STATUS_CB = 0x01, - GEOFENCE_INOUT_CB = GEOFENCE_STATUS_CB << 0x01, + GEOFENCE_STATUS_CB = 0x01, + GEOFENCE_INOUT_CB = GEOFENCE_STATUS_CB << 0x01, } geofence_client_callback_e; typedef enum { - GEOFENCE_CLIENT_ERROR_NONE = 0x0, - GEOFENCE_CLIENT_ERROR_UNKNOWN, - GEOFENCE_CLIENT_ERROR_PARAMETER, - GEOFENCE_CLIENT_ERROR_MEMORY, - GEOFENCE_CLIENT_ERROR_CONNECTION, - GEOFENCE_CLIENT_ERROR_STATUS, - GEOFENCE_CLIENT_ERROR_DBUS_CALL, - GEOFENCE_CLIENT_ERROR_NO_RESULT, - GEOFENCE_CLIENT_ACCESS_DENIED + GEOFENCE_CLIENT_ERROR_NONE = 0x0, + GEOFENCE_CLIENT_ERROR_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, + GEOFENCE_CLIENT_ERROR_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, + GEOFENCE_CLIENT_ACCESS_DENIED = TIZEN_ERROR_PERMISSION_DENIED, + GEOFENCE_CLIENT_ERROR_CONNECTION = TIZEN_ERROR_GEOFENCE_MANAGER | 0x01, + GEOFENCE_CLIENT_ERROR_DBUS_CALL = TIZEN_ERROR_GEOFENCE_MANAGER | 0x06, } geofence_client_error_e; typedef void *geofence_client_dbus_h; /** -* @brief Callback registered by the client to get the callback for the geofence in/out status +* @brief Callback registered by the client to get the callback for the geofence in/out status */ -typedef void (*geofence_client_cb) (const char *sig, GVariant *param, void *user_data); +typedef void (*geofence_client_cb)(const char *sig, GVariant *param, void *user_data); +#if 0 /** -* @brief Callback registered by the client to get the callback for the geofence event status +* @brief Callback registered by the client to get the callback for the geofence event status */ -typedef void (*geofence_client_event_cb) (const char *sig, GVariant *param, void *user_data); +typedef void (*geofence_client_event_cb)(const char *sig, GVariant *param, void *user_data); +#endif /** * @brief API to add the geofence. This will call the server API. * @param[in] geofence_client - Client dbus handle +* @param[in] app_id - Caller's application ID * @param[in] latitude - latitude value if is a geopoint geofence * @param[in] longitude - longitude value if it is a geopint geofence * @param[in] radius - radius value if it is a geopoint geofence @@ -62,28 +64,22 @@ typedef void (*geofence_client_event_cb) (const char *sig, GVariant *param, void * @retval returns the fence-id of the geofence added * @see geo_client_delete_geofence */ -int geo_client_add_geofence(geofence_client_dbus_h geofence_client, gint place_id, gint geofence_type, gdouble latitude, gdouble longitude, gint radius, const gchar *address, const gchar *bssid, const gchar *ssid); +int geo_client_add_geofence(geofence_client_dbus_h geofence_client, gchar *app_id, gint place_id, gint geofence_type, gdouble latitude, gdouble longitude, gint radius, const gchar *address, const gchar *bssid, const gchar *ssid); /** * @brief API to add the place. This will call the server API * @param[in] geofence_client - Client dbus handle +* @param[in] app_id - Caller's application ID * @param[in] place_name - Name of the place * retval returns the place_id of the place added * @see geo_client_delete_place */ -int geo_client_add_place(geofence_client_dbus_h geofence_client, const gchar *place_name); - -/** -* @brief API to enable the geofence. This will call the server API -* @param[in] geofence_client - Client dbus handle -* @param[in] fence_id - Unique id of the fence -* @param[in] bEnable - enable flag for geofence -*/ -int geo_client_enable_service(geofence_client_dbus_h geofence_client, gint geofence_id, gboolean bEnable); +int geo_client_add_place(geofence_client_dbus_h geofence_client, gchar *appid, const gchar *place_name); /** * @brief API to update the place. This will call the server API * @param[in] geofence_client - Client dbus handle +* @param[in] app_id - Caller's application ID * @param[in] place_id - Unique id of the place * @param[in] place_name - Name of the place[may be a new value] * @return int @@ -91,29 +87,31 @@ int geo_client_enable_service(geofence_client_dbus_h geofence_client, gint geofe GEOFENCE_CLIENT_ERROR_DBUS_CALL if failure * @see geo_client_add_place */ -int geo_client_update_place(geofence_client_dbus_h geofence_client, gint place_id, const gchar *place_name); +int geo_client_update_place(geofence_client_dbus_h geofence_client, gchar *app_id, gint place_id, const gchar *place_name); /** * @brief API to delete the geofence from the server * @param[in] geofence_client - Client dbus handle +* @param[in] app_id - Caller's application ID * @param[in] fence-id - Fence ID of the fence which needs to be deleted * @return int * @retval GEOFENCE_CLIENT_ERROR_NONE if success GEOFENCE_CLIENT_ERROR_DBUS_CALL if failure * @see geo_client_add_geofence */ -int geo_client_delete_geofence(geofence_client_dbus_h geofence_client, gint fence_id); +int geo_client_delete_geofence(geofence_client_dbus_h geofence_client, gchar *app_id, gint fence_id); /** * @brief API to delete the place from the server * @param[in] geofence_client - Client dbus handle +* @param[in] app_id - Caller's application ID * @param[in] place_id - Place ID of the place which needs to be deleted * @return int * @retval GEOFENCE_CLIENT_ERROR_NONE if success GEOFENCE_CLIENT_ERROR_DBUS_CALL if failure * @see geo_client_add_place */ -int geo_client_delete_place(geofence_client_dbus_h geofence_client, gint place_id); +int geo_client_delete_place(geofence_client_dbus_h geofence_client, gchar *app_id, gint place_id); /** * @brief API to get the place name @@ -124,11 +122,12 @@ int geo_client_delete_place(geofence_client_dbus_h geofence_client, gint place_i * @return GEOFENCE_CLIENT_ERROR_NONE if success GEOFENCE_CLIENT_ERROR_DBUS_CALL if failure */ -int geo_client_get_place_name(geofence_client_dbus_h geofence_client, gint place_id, char **placeName, int *errorCode); +int geo_client_get_place_name(geofence_client_dbus_h geofence_client, gchar *app_id, gint place_id, gchar **place_name, gint *error_code); /** * @brief API to get the fence list * @param[in] geofence_client - Client dbus handle +* @param[in] app_id - Caller's application ID * @param[in] place_id - ID of the place whose list has to be retrived * @param[out] iter - iterator for the array of fences * @param[out] fenceCnt - total count of the fence @@ -137,11 +136,12 @@ int geo_client_get_place_name(geofence_client_dbus_h geofence_client, gint place * @retval GEOFENCE_CLIENT_ERROR_NONE if success GEOFENCE_CLIENT_ERROR_DBUS_CALL if failure */ -int geo_client_get_list(geofence_client_dbus_h geofence_client, int place_id, GVariantIter **iter, gint *fenceCnt, int *errorCode); +int geo_client_get_geofences(geofence_client_dbus_h geofence_client, gchar *app_id, gint place_id, GVariantIter **iter, gint *fence_cnt, gint *error_code); /** * @brief API to get the place list * @param[in] geofence_client - Client dbus handle +* @param[in] app_id - Caller's application ID * @param[out] iter - iterator for the array of fences * @param[out] placeCnt - total count of the fence * @param[out] errorCode - error code for the API @@ -149,34 +149,43 @@ int geo_client_get_list(geofence_client_dbus_h geofence_client, int place_id, GV * @retval GEOFENCE_CLIENT_ERROR_NONE if success GEOFENCE_CLIENT_ERROR_DBUS_CALL if failure */ -int geo_client_get_place_list(geofence_client_dbus_h geofence_client, GVariantIter **iter, gint *fenceCnt, int *errorCode); +int geo_client_get_places(geofence_client_dbus_h geofence_client, gchar *app_id, GVariantIter **iter, gint *fence_cnt, int *error_code); + +/** +* @brief API to enable the geofence. This will call the server API +* @param[in] geofence_client - Client dbus handle +* @param[in] app_id - Caller's application ID +* @param[in] fence_id - Unique id of the fence +* @param[in] bEnable - enable flag for geofence +*/ +int geo_client_enable_geofence(geofence_client_dbus_h geofence_client, gchar *app_id, gint geofence_id, gboolean onoff); /** * @brief API to start the geofence service on a particular geofence +* @param[in] app_id - Caller's application ID * @param[in] geofence_client - Client dbus handle * @param[in] fence-id - Fence ID of the fence for which geofence service should be started * @return int * @retval GEOFENCE_CLIENT_ERROR_NONE if success GEOFENCE_CLIENT_ERROR_DBUS_CALL if failure -* @see geo_client_stop_geofence +* @see geo_client_stop_geofence */ -int geo_client_start_geofence(geofence_client_dbus_h geofence_client, gint fence_id); +int geo_client_start_geofence(geofence_client_dbus_h geofence_client, gchar *app_id, gint fence_id); /** * @brief API to stop the geofence service on a particular geofence * @param[in] geofence_client - Client dbus handle +* @param[in] app_id - Caller's application ID * @param[in] fence-id - Fence ID of the fence for which geofence service should be stopped * @return int * @retval GEOFENCE_CLIENT_ERROR_NONE if success GEOFENCE_CLIENT_ERROR_DBUS_CALL if failure -* @see geo_client_start_geofence +* @see geo_client_start_geofence */ -int geo_client_stop_geofence(geofence_client_dbus_h geofence_client, gint fence_id); +int geo_client_stop_geofence(geofence_client_dbus_h geofence_client, gchar *app_id, gint fence_id); /** * @brief API to start the client and make a subscription to the server -* @param[in] service_name - Name of the service required by the client -* @param[in] service_path - Path of the service for dbus connection * @param[in] geofence_client - Client dbus handle * @param[in] callback - callback registered by the client * @param[in] user_data - Data that has to come back in the callback @@ -186,7 +195,7 @@ int geo_client_stop_geofence(geofence_client_dbus_h geofence_client, gint fence_ GEOFENCE_CLIENT_ERROR_DBUS_CALL - if failure * @see geo_client_stop */ -int geo_client_start(char *service_name, char *service_path, geofence_client_dbus_h *geofence_client, geofence_client_cb callback, geofence_client_event_cb evt_callback, void *user_data); +int geo_client_start(geofence_client_dbus_h geofence_client, geofence_client_cb callback, void *user_data); /** * @brief API to stop the client and remove the subscription to the server @@ -197,7 +206,7 @@ int geo_client_start(char *service_name, char *service_path, geofence_client_dbu GEOFENCE_CLIENT_ERROR_DBUS_CALL - if failure * @see geo_client_start */ -int geo_client_stop(geofence_client_dbus_h *geofence_client); +int geo_client_stop(geofence_client_dbus_h geofence_client); /** * @brief API to create the connection with the server diff --git a/geofence/include/geofence_client_priv.h b/geofence/include/geofence_client_priv.h index ec0b7b2..9b6eb68 100644 --- a/geofence/include/geofence_client_priv.h +++ b/geofence/include/geofence_client_priv.h @@ -40,5 +40,5 @@ __BEGIN_DECLS #define GEOFENCE_CLIENT_LOGE(fmt, args...) #define GEOFENCE_CLIENT_SECLOG(fmt, args...) #endif - __END_DECLS +__END_DECLS #endif /* __GEOFENCE_CLIENT_PRIV_H__ */ diff --git a/geofence/src/geofence_client.c b/geofence/src/geofence_client.c index 30f6203..a37ea4f 100644 --- a/geofence/src/geofence_client.c +++ b/geofence/src/geofence_client.c @@ -14,25 +14,28 @@ */ #include <stdio.h> -#include <app_manager.h> #include "geofence_client.h" #include "geofence_client_priv.h" +#define GEOFENCE_SERVICE_NAME "org.tizen.lbs.Providers.GeofenceServer" +#define GEOFENCE_SERVICE_PATH "/org/tizen/lbs/Providers/GeofenceServer" +#define GEOFENCE_INTERFACE_NAME "org.tizen.lbs.Geofence" + + typedef struct _geofence_client_dbus_s { GDBusConnection *conn; gchar *service_name; gchar *service_path; + gchar *signal_path; int geofence_evt_id; int geofence_evt_status_id; - int geofence_id; geofence_client_cb user_cb; - geofence_client_event_cb user_event_cb; void *user_data; } geofence_client_dbus_s; static void __geofence_signal_callback(GDBusConnection *conn, const gchar *name, const gchar *path, const gchar *interface, const gchar *sig, GVariant *param, gpointer user_data) { - GEOFENCE_CLIENT_SECLOG("name : %s, path : %s, interface : %s, sig : %s, handle[%p]", name, path, interface, sig, user_data); + GEOFENCE_CLIENT_SECLOG("name: %s, path: %s, interface: %s, sig: %s, handle[%p]", name, path, interface, sig, user_data); geofence_client_dbus_s *handle = (geofence_client_dbus_s *) user_data; if (handle == NULL) { GEOFENCE_CLIENT_LOGD("Invalid handle"); @@ -42,37 +45,21 @@ static void __geofence_signal_callback(GDBusConnection *conn, const gchar *name, handle->user_cb(sig, param, handle->user_data); } -EXPORT_API int geo_client_add_geofence(geofence_client_dbus_h geofence_client, gint place_id, gint geofence_type, gdouble latitude, gdouble longitude, gint radius, const gchar *address, const gchar *bssid, const gchar *ssid) +EXPORT_API int geo_client_add_geofence(geofence_client_dbus_h geofence_client, gchar *app_id, gint place_id, gint geofence_type, gdouble latitude, gdouble longitude, gint radius, const gchar *address, const gchar *bssid, const gchar *ssid) { - /* add fence interface between App & geofence-server */ - GEOFENCE_CLIENT_LOGD("geo_client_add_fence"); - g_return_val_if_fail(geofence_client, 0); - geofence_client_dbus_s *handle = (geofence_client_dbus_s *)geofence_client; + GEOFENCE_CLIENT_LOGD("ENTER >>>"); + g_return_val_if_fail(geofence_client, GEOFENCE_CLIENT_ERROR_PARAMETER); + geofence_client_dbus_s *handle = (geofence_client_dbus_s *)geofence_client; GVariant *reg = NULL; GError *error = NULL; GDBusProxy *proxy = NULL; - gchar *app_id = NULL; - gint fence_id = -1; - pid_t pid = 0; - - GEOFENCE_CLIENT_LOGI("Getting the app id in client"); - pid = getpid(); - int ret = app_manager_get_app_id(pid, &app_id); - - if (ret != APP_MANAGER_ERROR_NONE) - GEOFENCE_CLIENT_LOGE("Fail to get app_id from module_geofence_server. Err[%d]", ret); - - GEOFENCE_CLIENT_LOGI("APP ID is : %s", app_id); - gchar *signal_path = NULL; - signal_path = g_strdup_printf("%s/%s", handle->service_path, "SAMSUNG"); - GEOFENCE_CLIENT_SECLOG("GEOFENCE signal subscribe Object Path [%s]", signal_path); - - proxy = g_dbus_proxy_new_sync(handle->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, handle->service_name, signal_path, "org.tizen.lbs.Geofence", NULL, &error); - g_free(signal_path); + int fence_id = -1; + proxy = g_dbus_proxy_new_sync(handle->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, handle->service_name, handle->signal_path, GEOFENCE_INTERFACE_NAME, NULL, &error); if (proxy) { - GEOFENCE_CLIENT_LOGD(" proxy exited !"); + GEOFENCE_CLIENT_LOGD("proxy: %p", proxy); + reg = g_dbus_proxy_call_sync(proxy, "AddGeofence", g_variant_new("(siiddisss)", app_id, place_id, geofence_type, latitude, longitude, radius, address, bssid, ssid), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (reg) { g_variant_get(reg, "(i)", &fence_id); @@ -86,403 +73,242 @@ EXPORT_API int geo_client_add_geofence(geofence_client_dbus_h geofence_client, g } g_object_unref(proxy); } else { - GEOFENCE_CLIENT_LOGD(" proxy NOT exited !"); if (error) { GEOFENCE_CLIENT_LOGE("Fail to get proxy Error[%s]", error->message); g_error_free(error); } - } - if (app_id) - g_free(app_id); + } + GEOFENCE_CLIENT_LOGD("fence_id: %d", fence_id); return fence_id; } -EXPORT_API int geo_client_add_place(geofence_client_dbus_h geofence_client, const gchar *place_name) +EXPORT_API int geo_client_delete_geofence(geofence_client_dbus_h geofence_client, gchar *app_id, gint fence_id) { - /* add fence interface between App & geofence-server */ - GEOFENCE_CLIENT_LOGD("geo_client_add_place"); - g_return_val_if_fail(geofence_client, 0); - geofence_client_dbus_s *handle = (geofence_client_dbus_s *)geofence_client; + GEOFENCE_CLIENT_LOGD("ENTER >>>"); + g_return_val_if_fail(geofence_client, GEOFENCE_CLIENT_ERROR_PARAMETER); - GVariant *reg = NULL; + geofence_client_dbus_s *handle = (geofence_client_dbus_s *) geofence_client; GError *error = NULL; GDBusProxy *proxy = NULL; - gchar *app_id = NULL; - int place_id = -1; - pid_t pid = 0; - - GEOFENCE_CLIENT_LOGI("Getting the app id in client"); - pid = getpid(); - int ret = app_manager_get_app_id(pid, &app_id); - - if (ret != APP_MANAGER_ERROR_NONE) - GEOFENCE_CLIENT_LOGE("Fail to get app_id from module_geofence_server. Err[%d]", ret); - - GEOFENCE_CLIENT_LOGI("APP ID is : %s", app_id); - gchar *signal_path = NULL; - signal_path = g_strdup_printf("%s/%s", handle->service_path, "SAMSUNG"); - GEOFENCE_CLIENT_SECLOG("GEOFENCE signal subscribe Object Path [%s]", signal_path); - - proxy = g_dbus_proxy_new_sync(handle->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, handle->service_name, signal_path, "org.tizen.lbs.Geofence", NULL, &error); - g_free(signal_path); + int ret = GEOFENCE_CLIENT_ERROR_NONE; + proxy = g_dbus_proxy_new_sync(handle->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, handle->service_name, handle->signal_path, GEOFENCE_INTERFACE_NAME, NULL, &error); if (proxy) { - GEOFENCE_CLIENT_LOGD(" proxy exited !"); - reg = g_dbus_proxy_call_sync(proxy, "AddPlace", g_variant_new("(ss)", app_id, place_name), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); - if (reg) { - g_variant_get(reg, "(i)", &place_id); - g_variant_unref(reg); - reg = NULL; - } else { - if (error) { - GEOFENCE_CLIENT_LOGE("Fail to add place Error[%s]", error->message); - g_error_free(error); - } - } - g_object_unref(proxy); + g_dbus_proxy_call(proxy, "DeleteGeofence", g_variant_new("(is)", fence_id, app_id), G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, &error); } else { - GEOFENCE_CLIENT_LOGD(" proxy NOT exited !"); if (error) { GEOFENCE_CLIENT_LOGE("Fail to get proxy Error[%s]", error->message); g_error_free(error); + ret = GEOFENCE_CLIENT_ERROR_DBUS_CALL; } } - if (app_id) - g_free(app_id); - return place_id; + return ret; } -EXPORT_API int geo_client_update_place(geofence_client_dbus_h geofence_client, gint place_id, const gchar *place_name) +EXPORT_API int geo_client_get_geofences(geofence_client_dbus_h geofence_client, gchar *app_id, gint place_id, GVariantIter **iter, gint *fence_cnt, gint *error_code) { - GEOFENCE_CLIENT_LOGD("geo_client_update_place"); - g_return_val_if_fail(geofence_client, 0); + GEOFENCE_CLIENT_LOGD("ENTER >>>"); + g_return_val_if_fail(geofence_client, GEOFENCE_CLIENT_ERROR_PARAMETER); + geofence_client_dbus_s *handle = (geofence_client_dbus_s *)geofence_client; + GVariant *reg = NULL; GError *error = NULL; GDBusProxy *proxy = NULL; - gchar *app_id = NULL; - pid_t pid = 0; - - GEOFENCE_CLIENT_LOGI("Getting the app id in client"); - pid = getpid(); - int ret = app_manager_get_app_id(pid, &app_id); - if (ret != APP_MANAGER_ERROR_NONE) - GEOFENCE_CLIENT_LOGE("Fail to get app_id from module_geofence_server. Err[%d]", ret); - GEOFENCE_CLIENT_LOGI("APP ID is : %s", app_id); - - ret = GEOFENCE_CLIENT_ERROR_NONE; - gchar *signal_path = NULL; - signal_path = g_strdup_printf("%s/%s", handle->service_path, "SAMSUNG"); - GEOFENCE_CLIENT_SECLOG("GEOFENCE signal subscribe Object Path [%s]", signal_path); - - proxy = g_dbus_proxy_new_sync(handle->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, handle->service_name, signal_path, "org.tizen.lbs.Geofence", NULL, &error); - g_free(signal_path); + int ret = GEOFENCE_CLIENT_ERROR_NONE; + GVariantIter *iterator; + int new_error_code = 0; + int new_fence_cnt = 0; + proxy = g_dbus_proxy_new_sync(handle->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, handle->service_name, handle->signal_path, GEOFENCE_INTERFACE_NAME, NULL, &error); if (proxy) { - GEOFENCE_CLIENT_LOGD(" proxy exited !"); - g_dbus_proxy_call(proxy, "UpdatePlace", g_variant_new("(iss)", place_id, app_id, place_name), G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, &error); + GEOFENCE_CLIENT_LOGD("proxy: %p", proxy); + + reg = g_dbus_proxy_call_sync(proxy, "GetGeofences", g_variant_new("(is)", place_id, app_id), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); + if (reg) { + g_variant_get(reg, "(iiaa{sv})", &new_fence_cnt, &new_error_code, &iterator); + *error_code = new_error_code; + *fence_cnt = new_fence_cnt; + if (iterator == NULL) + GEOFENCE_CLIENT_LOGE("Iterator is null"); + *iter = iterator; + g_variant_unref(reg); + } else { + if (error) { + GEOFENCE_CLIENT_LOGE("Fail to get the list Error[%s]", error->message); + g_error_free(error); + ret = GEOFENCE_CLIENT_ERROR_DBUS_CALL; + } + } + g_object_unref(proxy); } else { - GEOFENCE_CLIENT_LOGD(" proxy NOT exited !"); if (error) { GEOFENCE_CLIENT_LOGE("Fail to get proxy Error[%s]", error->message); g_error_free(error); ret = GEOFENCE_CLIENT_ERROR_DBUS_CALL; } } - if (app_id) - g_free(app_id); return ret; } -EXPORT_API int geo_client_delete_geofence(geofence_client_dbus_h geofence_client, gint fence_id) +EXPORT_API int geo_client_enable_geofence(geofence_client_dbus_h geofence_client, gchar *app_id, gint geofence_id, gboolean onoff) { - GEOFENCE_CLIENT_LOGD("geo_client_delete_geofence"); + GEOFENCE_CLIENT_LOGD("ENTER >>>"); g_return_val_if_fail(geofence_client, GEOFENCE_CLIENT_ERROR_PARAMETER); - geofence_client_dbus_s *handle = (geofence_client_dbus_s *) geofence_client; + geofence_client_dbus_s *handle = (geofence_client_dbus_s *)geofence_client; GError *error = NULL; GDBusProxy *proxy = NULL; - gchar *app_id = NULL; int ret = GEOFENCE_CLIENT_ERROR_NONE; - pid_t pid = 0; - - GEOFENCE_CLIENT_LOGI("Getting the app id in client"); - pid = getpid(); - ret = app_manager_get_app_id(pid, &app_id); - - if (ret != APP_MANAGER_ERROR_NONE) - GEOFENCE_CLIENT_LOGE("Fail to get app_id from module_geofence_server. Err[%d]", ret); - - GEOFENCE_CLIENT_LOGI("APP ID is : %s", app_id); - - gchar *signal_path = NULL; - signal_path = g_strdup_printf("%s/%s", handle->service_path, "SAMSUNG"); - GEOFENCE_CLIENT_SECLOG("GEOFENCE signal subscribe Object Path [%s]", signal_path); - - proxy = g_dbus_proxy_new_sync(handle->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, handle->service_name, signal_path, "org.tizen.lbs.Geofence", NULL, &error); - g_free(signal_path); + proxy = g_dbus_proxy_new_sync(handle->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, handle->service_name, handle->signal_path, GEOFENCE_INTERFACE_NAME, NULL, &error); if (proxy) { - g_dbus_proxy_call(proxy, "DeleteGeofence", g_variant_new("(is)", fence_id, app_id), G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, &error); + g_dbus_proxy_call(proxy, "EnableGeofence", g_variant_new("(isb)", geofence_id, app_id, onoff), G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, &error); } else { - GEOFENCE_CLIENT_LOGD(" proxy NOT exited !"); if (error) { GEOFENCE_CLIENT_LOGE("Fail to get proxy Error[%s]", error->message); g_error_free(error); ret = GEOFENCE_CLIENT_ERROR_DBUS_CALL; } } - if (app_id) - g_free(app_id); return ret; } -EXPORT_API int geo_client_delete_place(geofence_client_dbus_h geofence_client, gint place_id) +EXPORT_API int geo_client_start_geofence(geofence_client_dbus_h geofence_client, gchar *app_id, gint geofence_id) { - GEOFENCE_CLIENT_LOGD("geo_client_delete_place"); + GEOFENCE_CLIENT_LOGD("ENTER >>>"); g_return_val_if_fail(geofence_client, GEOFENCE_CLIENT_ERROR_PARAMETER); - geofence_client_dbus_s *handle = (geofence_client_dbus_s *)geofence_client; + geofence_client_dbus_s *handle = (geofence_client_dbus_s *)geofence_client; GError *error = NULL; GDBusProxy *proxy = NULL; - gchar *app_id = NULL; int ret = GEOFENCE_CLIENT_ERROR_NONE; - pid_t pid = 0; - - GEOFENCE_CLIENT_LOGI("Getting the app id in client"); - pid = getpid(); - ret = app_manager_get_app_id(pid, &app_id); - if (ret != APP_MANAGER_ERROR_NONE) - GEOFENCE_CLIENT_LOGE("Fail to get app_id from module_geofence_server. Err[%d]", ret); + GEOFENCE_CLIENT_LOGD("handle->conn: %p, geofence_id", handle->conn, geofence_id); - GEOFENCE_CLIENT_LOGI("APP ID is : %s", app_id); - - gchar *signal_path = NULL; - signal_path = g_strdup_printf("%s/%s", handle->service_path, "SAMSUNG"); - GEOFENCE_CLIENT_SECLOG("GEOFENCE signal subscribe Object Path [%s]", signal_path); - - proxy = g_dbus_proxy_new_sync(handle->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, handle->service_name, signal_path, "org.tizen.lbs.Geofence", NULL, &error); - g_free(signal_path); + proxy = g_dbus_proxy_new_sync(handle->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, handle->service_name, handle->signal_path, GEOFENCE_INTERFACE_NAME, NULL, &error); if (proxy) { - g_dbus_proxy_call(proxy, "DeletePlace", g_variant_new("(is)", place_id, app_id), G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, &error); + g_dbus_proxy_call(proxy, "StartGeofence", g_variant_new("(is)", geofence_id, app_id), G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, &error); } else { - GEOFENCE_CLIENT_LOGD(" proxy NOT exited !"); if (error) { GEOFENCE_CLIENT_LOGE("Fail to get proxy Error[%s]", error->message); g_error_free(error); ret = GEOFENCE_CLIENT_ERROR_DBUS_CALL; } } - if (app_id) - g_free(app_id); - return ret; } -EXPORT_API int geo_client_enable_service(geofence_client_dbus_h geofence_client, gint geofence_id, gboolean bEnable) +EXPORT_API int geo_client_stop_geofence(geofence_client_dbus_h geofence_client, gchar *app_id, gint geofence_id) { - GEOFENCE_CLIENT_LOGD("geo_client_enable_geofence, id(%d)", geofence_id); + GEOFENCE_CLIENT_LOGD("ENTER >>>"); g_return_val_if_fail(geofence_client, GEOFENCE_CLIENT_ERROR_PARAMETER); geofence_client_dbus_s *handle = (geofence_client_dbus_s *)geofence_client; - + int ret = GEOFENCE_CLIENT_ERROR_NONE; GError *error = NULL; GDBusProxy *proxy = NULL; - gchar *app_id = NULL; - int ret = GEOFENCE_CLIENT_ERROR_NONE; - gchar *signal_path = NULL; - pid_t pid = 0; - gboolean enable = bEnable; - - GEOFENCE_CLIENT_LOGI("Getting the app id in client"); - pid = getpid(); - ret = app_manager_get_app_id(pid, &app_id); - - if (ret != APP_MANAGER_ERROR_NONE) - GEOFENCE_CLIENT_LOGE("Fail to get app_id from module_geofence_server. Err[%d]", ret); - - GEOFENCE_CLIENT_LOGI("APP ID is : %s", app_id); - - signal_path = g_strdup_printf("%s/%s", handle->service_path, "SAMSUNG"); - GEOFENCE_CLIENT_SECLOG("GEOFENCE signal subscribe Object Path [%s]", signal_path); - - GEOFENCE_CLIENT_LOGD("handle->user_cb : %x", handle->user_cb); - /* Start geofence */ - proxy = g_dbus_proxy_new_sync(handle->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, handle->service_name, signal_path, "org.tizen.lbs.Geofence", NULL, &error); - g_free(signal_path); + GEOFENCE_CLIENT_LOGD("handle->conn: %p", handle->conn); + proxy = g_dbus_proxy_new_sync(handle->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, handle->service_name, handle->signal_path, GEOFENCE_INTERFACE_NAME, NULL, &error); if (proxy) { - g_dbus_proxy_call(proxy, "EnableGeofence", g_variant_new("(isb)", geofence_id, app_id, enable), G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, &error); + g_dbus_proxy_call(proxy, "StopGeofence", g_variant_new("(is)", geofence_id, app_id), G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, &error); } else { - GEOFENCE_CLIENT_LOGD(" proxy NOT exited !"); if (error) { GEOFENCE_CLIENT_LOGE("Fail to get proxy Error[%s]", error->message); g_error_free(error); ret = GEOFENCE_CLIENT_ERROR_DBUS_CALL; } } - if (app_id) - g_free(app_id); return ret; } -EXPORT_API int geo_client_start_geofence(geofence_client_dbus_h geofence_client, int geofence_id) +EXPORT_API int geo_client_add_place(geofence_client_dbus_h geofence_client, gchar *app_id, const gchar *place_name) { - GEOFENCE_CLIENT_LOGD("geo_client_start_geofence, id(%d)", geofence_id); + /* add fence interface between App & geofence-server */ + GEOFENCE_CLIENT_LOGD("ENTER >>>"); g_return_val_if_fail(geofence_client, GEOFENCE_CLIENT_ERROR_PARAMETER); geofence_client_dbus_s *handle = (geofence_client_dbus_s *)geofence_client; - + GVariant *reg = NULL; GError *error = NULL; GDBusProxy *proxy = NULL; - gchar *app_id = NULL; - int ret = GEOFENCE_CLIENT_ERROR_NONE; - gchar *signal_path = NULL; - pid_t pid = 0; - - GEOFENCE_CLIENT_LOGI("Getting the app id in client"); - pid = getpid(); - ret = app_manager_get_app_id(pid, &app_id); - - if (ret != APP_MANAGER_ERROR_NONE) - GEOFENCE_CLIENT_LOGE("Fail to get app_id from module_geofence_server. Err[%d]", ret); - - GEOFENCE_CLIENT_LOGI("APP ID is : %s", app_id); - - signal_path = g_strdup_printf("%s/%s", handle->service_path, "SAMSUNG"); - GEOFENCE_CLIENT_SECLOG("GEOFENCE signal subscribe Object Path [%s]", signal_path); - - GEOFENCE_CLIENT_LOGD("handle->user_cb : %x", handle->user_cb); + int place_id = -1; - /* Start geofence */ - proxy = g_dbus_proxy_new_sync(handle->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, handle->service_name, signal_path, "org.tizen.lbs.Geofence", NULL, &error); - g_free(signal_path); + GEOFENCE_CLIENT_LOGI("APP ID: %s", app_id); + proxy = g_dbus_proxy_new_sync(handle->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, handle->service_name, handle->signal_path, GEOFENCE_INTERFACE_NAME, NULL, &error); if (proxy) { - g_dbus_proxy_call(proxy, "StartGeofence", g_variant_new("(is)", geofence_id, app_id), G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, &error); + GEOFENCE_CLIENT_LOGD("proxy: %p", proxy); + reg = g_dbus_proxy_call_sync(proxy, "AddPlace", g_variant_new("(ss)", app_id, place_name), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); + if (reg) { + g_variant_get(reg, "(i)", &place_id); + g_variant_unref(reg); + reg = NULL; + } else { + if (error) { + GEOFENCE_CLIENT_LOGE("Fail to add place Error[%s]", error->message); + g_error_free(error); + } + } + g_object_unref(proxy); } else { - GEOFENCE_CLIENT_LOGD(" proxy NOT exited !"); if (error) { GEOFENCE_CLIENT_LOGE("Fail to get proxy Error[%s]", error->message); g_error_free(error); - ret = GEOFENCE_CLIENT_ERROR_DBUS_CALL; } } - if (app_id) - g_free(app_id); - return ret; + GEOFENCE_CLIENT_LOGD("place_id: %d", place_id); + + return place_id; } -EXPORT_API int geo_client_stop_geofence(geofence_client_dbus_h geofence_client, int geofence_id) +EXPORT_API int geo_client_update_place(geofence_client_dbus_h geofence_client, gchar *app_id, gint place_id, const gchar *place_name) { - GEOFENCE_CLIENT_LOGD("geo_client_stop_geofence"); + GEOFENCE_CLIENT_LOGD("ENTER >>>"); + g_return_val_if_fail(geofence_client, GEOFENCE_CLIENT_ERROR_PARAMETER); geofence_client_dbus_s *handle = (geofence_client_dbus_s *)geofence_client; - g_return_val_if_fail(handle, GEOFENCE_CLIENT_ERROR_PARAMETER); - - int ret = GEOFENCE_CLIENT_ERROR_NONE; GError *error = NULL; - gchar *app_id = NULL; - pid_t pid = 0; - - GEOFENCE_CLIENT_LOGI("Getting the app id in client"); - pid = getpid(); - ret = app_manager_get_app_id(pid, &app_id); - - if (ret != APP_MANAGER_ERROR_NONE) - GEOFENCE_CLIENT_LOGE("Fail to get app_id from module_geofence_server. Err[%d]", ret); - - GEOFENCE_CLIENT_LOGI("APP ID is : %s", app_id); - GEOFENCE_CLIENT_LOGD("handle->user_cb : %x", handle->user_cb); - - gchar *signal_path = NULL; - signal_path = g_strdup_printf("%s/%s", handle->service_path, "SAMSUNG"); - GEOFENCE_CLIENT_SECLOG("GEOFENCE signal subscribe Object Path [%s]", signal_path); - - /* Stop*/ GDBusProxy *proxy = NULL; - GEOFENCE_CLIENT_LOGD("handle->conn: %p", handle->conn); - proxy = g_dbus_proxy_new_sync(handle->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, handle->service_name, signal_path, "org.tizen.lbs.Geofence", NULL, &error); - g_free(signal_path); + int ret = GEOFENCE_CLIENT_ERROR_NONE; + proxy = g_dbus_proxy_new_sync(handle->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, handle->service_name, handle->signal_path, GEOFENCE_INTERFACE_NAME, NULL, &error); if (proxy) { - g_dbus_proxy_call(proxy, "StopGeofence", g_variant_new("(is)", geofence_id, app_id), G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, &error); + g_dbus_proxy_call(proxy, "UpdatePlace", g_variant_new("(iss)", place_id, app_id, place_name), G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, &error); } else { - GEOFENCE_CLIENT_LOGD(" proxy NOT exited !"); if (error) { GEOFENCE_CLIENT_LOGE("Fail to get proxy Error[%s]", error->message); g_error_free(error); ret = GEOFENCE_CLIENT_ERROR_DBUS_CALL; } } - if (app_id) - g_free(app_id); return ret; } -EXPORT_API int geo_client_get_place_name(geofence_client_dbus_h geofence_client, int place_id, char **placeName, int *errorCode) +EXPORT_API int geo_client_delete_place(geofence_client_dbus_h geofence_client, gchar *app_id, gint place_id) { - GEOFENCE_CLIENT_LOGD("geo_client_get_place_name"); + GEOFENCE_CLIENT_LOGD("ENTER >>>"); g_return_val_if_fail(geofence_client, GEOFENCE_CLIENT_ERROR_PARAMETER); geofence_client_dbus_s *handle = (geofence_client_dbus_s *)geofence_client; - - GVariant *reg = NULL; GError *error = NULL; GDBusProxy *proxy = NULL; - gchar *app_id = NULL; int ret = GEOFENCE_CLIENT_ERROR_NONE; - gchar *signal_path = NULL; - pid_t pid = 0; - char *place_name = NULL; - int error_code = -1; - - GEOFENCE_CLIENT_LOGI("Getting the app id in client"); - pid = getpid(); - ret = app_manager_get_app_id(pid, &app_id); - - if (ret != APP_MANAGER_ERROR_NONE) - GEOFENCE_CLIENT_LOGE("Fail to get app_id from module_geofence_server. Err[%d]", ret); - - GEOFENCE_CLIENT_LOGI("APP ID is : %s", app_id); - - signal_path = g_strdup_printf("%s/%s", handle->service_path, "SAMSUNG"); - GEOFENCE_CLIENT_SECLOG("GEOFENCE signal subscribe Object Path [%s]", signal_path); - - GEOFENCE_CLIENT_LOGD("handle->user_cb : %x", handle->user_cb); - /* Start geofence */ - proxy = g_dbus_proxy_new_sync(handle->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, handle->service_name, signal_path, "org.tizen.lbs.Geofence", NULL, &error); - g_free(signal_path); + proxy = g_dbus_proxy_new_sync(handle->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, handle->service_name, handle->signal_path, GEOFENCE_INTERFACE_NAME, NULL, &error); if (proxy) { - reg = g_dbus_proxy_call_sync(proxy, "GetPlaceName", g_variant_new("(is)", place_id, app_id), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); - if (reg) { - g_variant_get(reg, "(is)", &error_code, &place_name); - *errorCode = error_code; - *placeName = strdup(place_name); - if (place_name) - g_free(place_name); - g_variant_unref(reg); - } else { - if (error) { - GEOFENCE_CLIENT_LOGE("Fail to get the place name Error[%s]", error->message); - g_error_free(error); - ret = GEOFENCE_CLIENT_ERROR_DBUS_CALL; - } - } - g_object_unref(proxy); + g_dbus_proxy_call(proxy, "DeletePlace", g_variant_new("(is)", place_id, app_id), G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, &error); } else { - GEOFENCE_CLIENT_LOGD(" proxy NOT exited !"); if (error) { GEOFENCE_CLIENT_LOGE("Fail to get proxy Error[%s]", error->message); g_error_free(error); @@ -490,120 +316,75 @@ EXPORT_API int geo_client_get_place_name(geofence_client_dbus_h geofence_client, } } - if (app_id) - g_free(app_id); - return ret; } -EXPORT_API int geo_client_get_list(geofence_client_dbus_h geofence_client, int place_id, GVariantIter **iter, int *fenceCnt, int *errorCode) +EXPORT_API int geo_client_get_place_name(geofence_client_dbus_h geofence_client, gchar *app_id, gint place_id, gchar **place_name, gint *error_code) { - GEOFENCE_CLIENT_LOGD("geo_client_get_list"); + GEOFENCE_CLIENT_LOGD("ENTER >>>"); g_return_val_if_fail(geofence_client, GEOFENCE_CLIENT_ERROR_PARAMETER); geofence_client_dbus_s *handle = (geofence_client_dbus_s *)geofence_client; - GVariant *reg = NULL; GError *error = NULL; GDBusProxy *proxy = NULL; - gchar *app_id = NULL; int ret = GEOFENCE_CLIENT_ERROR_NONE; - gchar *signal_path = NULL; - pid_t pid = 0; - GVariantIter *iterator; - int error_code = -1; - int fence_cnt = 1; - - GEOFENCE_CLIENT_LOGI("Getting the app id in client"); - pid = getpid(); - ret = app_manager_get_app_id(pid, &app_id); - - if (ret != APP_MANAGER_ERROR_NONE) - GEOFENCE_CLIENT_LOGE("Fail to get app_id from module_geofence_server. Err[%d]", ret); - - GEOFENCE_CLIENT_LOGI("APP ID is : %s", app_id); - - signal_path = g_strdup_printf("%s/%s", handle->service_path, "SAMSUNG"); - GEOFENCE_CLIENT_SECLOG("GEOFENCE signal subscribe Object Path [%s]", signal_path); - - GEOFENCE_CLIENT_LOGD("handle->user_cb : %x", handle->user_cb); - - /* Start geofence */ - proxy = g_dbus_proxy_new_sync(handle->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, handle->service_name, signal_path, "org.tizen.lbs.Geofence", NULL, &error); - g_free(signal_path); + char *new_place_name = NULL; + int new_error_code = 0; + proxy = g_dbus_proxy_new_sync(handle->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, handle->service_name, handle->signal_path, GEOFENCE_INTERFACE_NAME, NULL, &error); if (proxy) { - reg = g_dbus_proxy_call_sync(proxy, "GetList", g_variant_new("(is)", place_id, app_id), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); + reg = g_dbus_proxy_call_sync(proxy, "GetPlaceName", g_variant_new("(is)", place_id, app_id), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (reg) { - g_variant_get(reg, "(iiaa{sv})", &fence_cnt, &error_code, &iterator); - *fenceCnt = fence_cnt; - *errorCode = error_code; - if (iterator == NULL) - GEOFENCE_CLIENT_LOGE("Iterator is null"); - *iter = iterator; + g_variant_get(reg, "(is)", &new_error_code, &new_place_name); + *error_code = new_error_code; + *place_name = g_strdup(new_place_name); + g_free(new_place_name); g_variant_unref(reg); } else { if (error) { - GEOFENCE_CLIENT_LOGE("Fail to get the list Error[%s]", error->message); + GEOFENCE_CLIENT_LOGE("Fail to get the place name Error[%s]", error->message); g_error_free(error); ret = GEOFENCE_CLIENT_ERROR_DBUS_CALL; } } g_object_unref(proxy); } else { - GEOFENCE_CLIENT_LOGD(" proxy NOT exited !"); if (error) { GEOFENCE_CLIENT_LOGE("Fail to get proxy Error[%s]", error->message); g_error_free(error); ret = GEOFENCE_CLIENT_ERROR_DBUS_CALL; } } - if (app_id) - g_free(app_id); return ret; } -EXPORT_API int geo_client_get_place_list(geofence_client_dbus_h geofence_client, GVariantIter **iter, int *placeCnt, int *errorCode) +EXPORT_API int geo_client_get_places(geofence_client_dbus_h geofence_client, gchar *app_id, GVariantIter **iter, gint *place_cnt, gint *error_code) { - GEOFENCE_CLIENT_LOGD("geo_client_get_place_list"); + GEOFENCE_CLIENT_LOGD("ENTER >>>"); g_return_val_if_fail(geofence_client, GEOFENCE_CLIENT_ERROR_PARAMETER); geofence_client_dbus_s *handle = (geofence_client_dbus_s *)geofence_client; - GVariant *reg = NULL; GError *error = NULL; GDBusProxy *proxy = NULL; - gchar *app_id = NULL; + int ret = GEOFENCE_CLIENT_ERROR_NONE; - gchar *signal_path = NULL; - pid_t pid = 0; GVariantIter *iterator; - int error_code = -1; - int place_cnt = 0; + int new_error_code = 0; + int new_place_cnt = 0; - GEOFENCE_CLIENT_LOGI("Getting the app id in client"); - pid = getpid(); - ret = app_manager_get_app_id(pid, &app_id); - if (ret != APP_MANAGER_ERROR_NONE) - GEOFENCE_CLIENT_LOGE("Fail to get app_id from module_geofence_server. Err[%d]", ret); - - GEOFENCE_CLIENT_LOGI("APP ID is : %s", app_id); - - signal_path = g_strdup_printf("%s/%s", handle->service_path, "SAMSUNG"); - GEOFENCE_CLIENT_SECLOG("GEOFENCE signal subscribe Object Path [%s]", signal_path); - - GEOFENCE_CLIENT_LOGD("handle->user_cb : %x", handle->user_cb); + GEOFENCE_CLIENT_LOGD("handle->conn: %p", handle->conn); + GEOFENCE_CLIENT_LOGI("APP ID: %s", app_id); - /* Start geofence */ - proxy = g_dbus_proxy_new_sync(handle->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, handle->service_name, signal_path, "org.tizen.lbs.Geofence", NULL, &error); - g_free(signal_path); + proxy = g_dbus_proxy_new_sync(handle->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, handle->service_name, handle->signal_path, GEOFENCE_INTERFACE_NAME, NULL, &error); if (proxy) { - reg = g_dbus_proxy_call_sync(proxy, "GetPlaceList", g_variant_new("(s)", app_id), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); + reg = g_dbus_proxy_call_sync(proxy, "GetPlaces", g_variant_new("(s)", app_id), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (reg) { - g_variant_get(reg, "(iiaa{sv})", &place_cnt, &error_code, &iterator); - *placeCnt = place_cnt; - *errorCode = error_code; + g_variant_get(reg, "(iiaa{sv})", &new_place_cnt, &new_error_code, &iterator); + *place_cnt = new_place_cnt; + *error_code = new_error_code; if (iterator == NULL) GEOFENCE_CLIENT_LOGE("Iterator is null"); *iter = iterator; @@ -617,85 +398,57 @@ EXPORT_API int geo_client_get_place_list(geofence_client_dbus_h geofence_client, } g_object_unref(proxy); } else { - GEOFENCE_CLIENT_LOGD(" proxy NOT exited !"); if (error) { GEOFENCE_CLIENT_LOGE("Fail to get proxy Error[%s]", error->message); g_error_free(error); ret = GEOFENCE_CLIENT_ERROR_DBUS_CALL; } } - if (app_id) - g_free(app_id); return ret; } -static void geo_client_signal_unsubcribe(geofence_client_dbus_h geofence_client) +EXPORT_API int geo_client_start(geofence_client_dbus_h geofence_client, geofence_client_cb callback, void *user_data) { - GEOFENCE_CLIENT_LOGD("geo_client_signal_unsubcribe"); - - geofence_client_dbus_s *handle = (geofence_client_dbus_s *)geofence_client; - if (handle == NULL) { - GEOFENCE_CLIENT_LOGE("Invalid handle"); - return; - } - if (handle->conn == NULL) { - GEOFENCE_CLIENT_LOGE("Invalid dbus_connection"); - return; - } - if (handle->geofence_evt_id) { - g_dbus_connection_signal_unsubscribe(handle->conn, handle->geofence_evt_id); - handle->geofence_evt_id = 0; - } - if (handle->geofence_evt_status_id) { - g_dbus_connection_signal_unsubscribe(handle->conn, handle->geofence_evt_status_id); - handle->geofence_evt_status_id = 0; - } -} - -EXPORT_API int geo_client_start(char *service_name, char *service_path, geofence_client_dbus_h *geofence_client, geofence_client_cb callback, geofence_client_event_cb evt_callback, void *user_data) -{ - GEOFENCE_CLIENT_LOGD("geo_client_start"); + GEOFENCE_CLIENT_LOGD("ENTER >>>"); g_return_val_if_fail(geofence_client, GEOFENCE_CLIENT_ERROR_PARAMETER); geofence_client_dbus_s *handle = (geofence_client_dbus_s *)geofence_client; - - GVariant *param = NULL; - GVariantBuilder *builder = NULL; gchar *signal_path = NULL; - handle->service_name = g_strdup(service_name); - handle->service_path = g_strdup(service_path); - - signal_path = g_strdup_printf("%s/%s", handle->service_path, "SAMSUNG"); - GEOFENCE_CLIENT_LOGD("Geofence signal subscribe Object Path [%s]", signal_path); + handle->service_name = g_strdup(GEOFENCE_SERVICE_NAME); + handle->service_path = g_strdup(GEOFENCE_SERVICE_PATH); + handle->signal_path = g_strdup_printf("%s/%s", handle->service_path, "SAMSUNG"); + GEOFENCE_CLIENT_LOGD("Object Path [%s]", handle->signal_path); if (callback) { handle->user_cb = callback; handle->user_data = user_data; - handle->geofence_evt_id = g_dbus_connection_signal_subscribe(handle->conn, handle->service_name, "org.tizen.lbs.Geofence", "GeofenceInout", signal_path, NULL, G_DBUS_SIGNAL_FLAGS_NONE, __geofence_signal_callback, handle, NULL); + handle->geofence_evt_id = g_dbus_connection_signal_subscribe(handle->conn, handle->service_name, GEOFENCE_INTERFACE_NAME, "GeofenceInout", handle->signal_path, NULL, G_DBUS_SIGNAL_FLAGS_NONE, __geofence_signal_callback, handle, NULL); if (handle->geofence_evt_id) { - GEOFENCE_CLIENT_LOGD("Listening Geofence Changed"); + GEOFENCE_CLIENT_LOGD("Listening GeofenceInout"); } else { - GEOFENCE_CLIENT_LOGD("Fail to listen Geofence Changed"); + GEOFENCE_CLIENT_LOGD("Fail to listen GeofenceInout"); } - } - if (callback) { - handle->user_event_cb = evt_callback; - handle->user_data = user_data; - handle->geofence_evt_status_id = g_dbus_connection_signal_subscribe(handle->conn, handle->service_name, "org.tizen.lbs.Geofence", "GeofenceEvent", signal_path, NULL, G_DBUS_SIGNAL_FLAGS_NONE, __geofence_signal_callback, handle, NULL); + + handle->geofence_evt_status_id = g_dbus_connection_signal_subscribe(handle->conn, handle->service_name, GEOFENCE_INTERFACE_NAME, "GeofenceEvent", handle->signal_path, NULL, G_DBUS_SIGNAL_FLAGS_NONE, __geofence_signal_callback, handle, NULL); if (handle->geofence_evt_status_id) { - GEOFENCE_CLIENT_LOGD("Listening Geofence event changed"); + GEOFENCE_CLIENT_LOGD("Listening Geofence event"); } else { - GEOFENCE_CLIENT_LOGD("Fail to listen Geofence event changed"); + GEOFENCE_CLIENT_LOGD("Fail to listen Geofence event"); return GEOFENCE_CLIENT_ERROR_DBUS_CALL; } } g_free(signal_path); - /* Start */ + +#if SUPPORT_MULTI_CLIENT + GVariant *param = NULL; + GVariantBuilder *builder = NULL; + + GEOFENCE_CLIENT_LOGD("START: CMD-START"); builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); g_variant_builder_add(builder, "{sv}", "CMD", g_variant_new_string("START")); @@ -703,20 +456,47 @@ EXPORT_API int geo_client_start(char *service_name, char *service_path, geofence param = g_variant_ref_sink(g_variant_new("(@a{sv})", g_variant_builder_end(builder))); g_variant_unref(param); +#endif return GEOFENCE_CLIENT_ERROR_NONE; } -EXPORT_API int geo_client_stop(geofence_client_dbus_h *geofence_client) +static void __geo_client_signal_unsubcribe(geofence_client_dbus_h geofence_client) +{ + GEOFENCE_CLIENT_LOGD("ENTER >>>"); + + geofence_client_dbus_s *handle = (geofence_client_dbus_s *)geofence_client; + if (handle == NULL) { + GEOFENCE_CLIENT_LOGE("Invalid handle"); + return; + } + if (handle->conn == NULL) { + GEOFENCE_CLIENT_LOGE("Invalid dbus_connection"); + return; + } + if (handle->geofence_evt_id) { + g_dbus_connection_signal_unsubscribe(handle->conn, handle->geofence_evt_id); + handle->geofence_evt_id = 0; + } + if (handle->geofence_evt_status_id) { + g_dbus_connection_signal_unsubscribe(handle->conn, handle->geofence_evt_status_id); + handle->geofence_evt_status_id = 0; + } +} + +EXPORT_API int geo_client_stop(geofence_client_dbus_h geofence_client) { - GEOFENCE_CLIENT_LOGD("geo_client_stop"); + GEOFENCE_CLIENT_LOGD("ENTER >>>"); geofence_client_dbus_s *handle = (geofence_client_dbus_s *)geofence_client;; g_return_val_if_fail(handle, GEOFENCE_CLIENT_ERROR_PARAMETER); + __geo_client_signal_unsubcribe(handle); + +#if SUPPORT_MULTI_CLIENT GVariant *param = NULL; GVariantBuilder *builder = NULL; - geo_client_signal_unsubcribe(handle); + /* Stop*/ GEOFENCE_CLIENT_LOGD("STOP: CMD-STOP"); builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); @@ -725,23 +505,43 @@ EXPORT_API int geo_client_stop(geofence_client_dbus_h *geofence_client) g_variant_unref(param); +#endif + return GEOFENCE_CLIENT_ERROR_NONE; } static int __geofence_client_create_connection(geofence_client_dbus_s *client) { - GEOFENCE_CLIENT_LOGD("__geofence_client_create_connection"); + GEOFENCE_CLIENT_LOGD("ENTER >>>"); + g_return_val_if_fail(client, GEOFENCE_CLIENT_ERROR_PARAMETER); GError *error = NULL; +#if 0 client->conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); +#endif + + char *bus_addr = NULL; + bus_addr = g_dbus_address_get_for_bus_sync(G_BUS_TYPE_SYSTEM, NULL, &error); + if (!bus_addr) { + GEOFENCE_CLIENT_LOGD("Fail to get addr of bus."); + return GEOFENCE_CLIENT_ERROR_CONNECTION; + } + + GEOFENCE_CLIENT_LOGD("bus_addr: %s", bus_addr); + + client->conn = g_dbus_connection_new_for_address_sync(bus_addr, + G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT | + G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION, + NULL, NULL, &error); + g_free(bus_addr); + if (!client->conn) { if (error && error->message) { GEOFENCE_CLIENT_LOGD("Fail to get GBus. ErrCode[%d], Msg[%s]", error->code, error->message); g_error_free(error); error = NULL; } - GEOFENCE_CLIENT_LOGD("Fail to get addr of bus."); return GEOFENCE_CLIENT_ERROR_CONNECTION; } GEOFENCE_CLIENT_LOGD("client->conn: %p", client->conn); @@ -749,24 +549,24 @@ static int __geofence_client_create_connection(geofence_client_dbus_s *client) return GEOFENCE_CLIENT_ERROR_NONE; } -static void _glib_log(const gchar *log_domain, GLogLevelFlags log_level, const gchar *msg, gpointer user_data) +static void __glib_log(const gchar *log_domain, GLogLevelFlags log_level, const gchar *msg, gpointer user_data) { geofence_client_dbus_s *client = (geofence_client_dbus_s *)user_data; if (client != NULL) { GEOFENCE_CLIENT_LOGD("client->conn: %p", client->conn); } - GEOFENCE_CLIENT_LOGE("GLIB[%d] : %s", log_level, msg); + GEOFENCE_CLIENT_LOGE("GLIB[%d]: %s", log_level, msg); } /* The reason why we seperate this from start is to support IPC for db operation between a server and a client.*/ EXPORT_API int geo_client_create(geofence_client_dbus_h *geofence_client) { - GEOFENCE_CLIENT_LOGD("geo_client_create"); + GEOFENCE_CLIENT_LOGD("ENTER >>>"); int ret = GEOFENCE_CLIENT_ERROR_NONE; geofence_client_dbus_s *client = g_new0(geofence_client_dbus_s, 1); g_return_val_if_fail(client, GEOFENCE_CLIENT_ERROR_MEMORY); - g_log_set_default_handler(_glib_log, client); + g_log_set_default_handler(__glib_log, client); ret = __geofence_client_create_connection(client); if (ret != GEOFENCE_CLIENT_ERROR_NONE) { @@ -780,7 +580,7 @@ EXPORT_API int geo_client_create(geofence_client_dbus_h *geofence_client) EXPORT_API int geo_client_destroy(geofence_client_dbus_h geofence_client) { - GEOFENCE_CLIENT_LOGD("geo_client_destroy"); + GEOFENCE_CLIENT_LOGD("ENTER >>>"); g_return_val_if_fail(geofence_client, GEOFENCE_CLIENT_ERROR_PARAMETER); geofence_client_dbus_s *handle = (geofence_client_dbus_s *)geofence_client; @@ -789,10 +589,9 @@ EXPORT_API int geo_client_destroy(geofence_client_dbus_h geofence_client) g_object_unref(handle->conn); handle->conn = NULL; } - if (handle->service_path) - g_free(handle->service_path); - if (handle->service_name) - g_free(handle->service_name); + g_free(handle->service_path); + g_free(handle->service_name); + g_free(handle->signal_path); g_free(handle); return GEOFENCE_CLIENT_ERROR_NONE; |