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 | |
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
-rw-r--r-- | CMakeLists.txt | 4 | ||||
-rw-r--r-- | geofence-dbus.pc.in | 2 | ||||
-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 | ||||
-rw-r--r-- | introspection/geofence.xml | 56 | ||||
-rw-r--r-- | packaging/geofence-dbus.spec | 9 | ||||
-rw-r--r-- | server/include/geofence_dbus_server.h | 113 | ||||
-rw-r--r-- | server/include/geofence_dbus_server_priv.h | 2 | ||||
-rw-r--r-- | server/src/geofence_dbus_server.c | 499 |
10 files changed, 590 insertions, 799 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index c465b9d..1d4b4dd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,12 +3,11 @@ PROJECT(geofence-dbus C) SET(PREFIX ${CMAKE_INSTALL_PREFIX}) SET(EXEC_PREFIX "\${prefix}") -SET(LIBDIR ${LIBDIR}) SET(INCLUDEDIR "\${prefix}/include") # Set required packages INCLUDE(FindPkgConfig) -pkg_check_modules(pkgs REQUIRED glib-2.0 gio-2.0 gthread-2.0 dlog gobject-2.0 gio-unix-2.0 capi-appfw-app-manager capi-appfw-package-manager pkgmgr-info) +pkg_check_modules(pkgs REQUIRED glib-2.0 gio-2.0 gthread-2.0 dlog gobject-2.0 gio-unix-2.0) FOREACH(flag ${pkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") @@ -23,7 +22,6 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-parameter -Wno-missing-field-ini ADD_DEFINITIONS("-DFEATURE_DLOG_DEBUG") ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") -ADD_DEFINITIONS("-DLIBDIR=\"${LIBDIR}\"") ADD_DEFINITIONS(" -DEXPORT_API=\"__attribute__((visibility(\\\"default\\\")))\" ") IF ( ENABLE_DOCOMO_LOCATION ) diff --git a/geofence-dbus.pc.in b/geofence-dbus.pc.in index 6dd5102..b8453c4 100644 --- a/geofence-dbus.pc.in +++ b/geofence-dbus.pc.in @@ -1,6 +1,6 @@ prefix=@PREFIX@ exec_prefix=${prefix} -libdir=${exec_prefix}/lib +libdir=@LIBDIR@ includedir=${prefix}/include Name: GEOFENCE dbus Library 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; diff --git a/introspection/geofence.xml b/introspection/geofence.xml index 2f61278..391f37e 100644 --- a/introspection/geofence.xml +++ b/introspection/geofence.xml @@ -12,28 +12,21 @@ <arg direction="in" type="s" name="ssid"/> <arg direction="out" type="i" name="fence_id"/> </method> - <method name="AddPlace"> - <arg direction="in" type="s" name="app_id"/> - <arg direction="in" type="s" name="place_name"/> - <arg direction="out" type="i" name="place_id"/> - </method> - <method name="EnableGeofence"> + <method name="DeleteGeofence"> <arg direction="in" type="i" name="fence_id"/> <arg direction="in" type="s" name="app_id"/> - <arg direction="in" type="b" name="enable"/> </method> - <method name="UpdatePlace"> + <method name="GetGeofences"> <arg direction="in" type="i" name="place_id"/> <arg direction="in" type="s" name="app_id"/> - <arg direction="in" type="s" name="place_name"/> + <arg direction="out" type="i" name="fence_count"/> + <arg direction="out" type="i" name="error_code"/> + <arg direction="out" type="aa{sv}" name="geofence_info"/> </method> - <method name="DeleteGeofence"> + <method name="EnableGeofence"> <arg direction="in" type="i" name="fence_id"/> <arg direction="in" type="s" name="app_id"/> - </method> - <method name="DeletePlace"> - <arg direction="in" type="i" name="place_id"/> - <arg direction="in" type="s" name="app_id"/> + <arg direction="in" type="b" name="enable"/> </method> <method name="StartGeofence"> <arg direction="in" type="i" name="fence_id"/> @@ -43,31 +36,40 @@ <arg direction="in" type="i" name="fence_id"/> <arg direction="in" type="s" name="app_id"/> </method> - <method name="GetPlaceName"> + <signal name="GeofenceInout"> + <arg direction="out" type="s" name="app_id"/> + <arg direction="out" type="i" name="fence_id"/> + <arg direction="out" type="i" name="access_type"/> + <arg direction="out" type="i" name="fence_state"/> + </signal> + + <!-- Place Management --> + <method name="AddPlace"> + <arg direction="in" type="s" name="app_id"/> + <arg direction="in" type="s" name="place_name"/> + <arg direction="out" type="i" name="place_id"/> + </method> + <method name="UpdatePlace"> <arg direction="in" type="i" name="place_id"/> <arg direction="in" type="s" name="app_id"/> - <arg direction="out" type="i" name="error_code"/> - <arg direction="out" type="s" name="place_name"/> + <arg direction="in" type="s" name="place_name"/> </method> - <method name="GetList"> + <method name="DeletePlace"> + <arg direction="in" type="i" name="place_id"/> + <arg direction="in" type="s" name="app_id"/> + </method> + <method name="GetPlaceName"> <arg direction="in" type="i" name="place_id"/> <arg direction="in" type="s" name="app_id"/> - <arg direction="out" type="i" name="fence_count"/> <arg direction="out" type="i" name="error_code"/> - <arg direction="out" type="aa{sv}" name="geofence_info"/> + <arg direction="out" type="s" name="place_name"/> </method> - <method name="GetPlaceList"> + <method name="GetPlaces"> <arg direction="in" type="s" name="app_id"/> <arg direction="out" type="i" name="place_count"/> <arg direction="out" type="i" name="error_code"/> <arg direction="out" type="aa{sv}" name="place_info"/> </method> - <signal name="GeofenceInout"> - <arg direction="out" type="s" name="app_id"/> - <arg direction="out" type="i" name="fence_id"/> - <arg direction="out" type="i" name="access_type"/> - <arg direction="out" type="i" name="fence_state"/> - </signal> <signal name="GeofenceEvent"> <arg direction="out" type="i" name="place_id"/> <arg direction="out" type="i" name="fence_id"/> diff --git a/packaging/geofence-dbus.spec b/packaging/geofence-dbus.spec index b44c2ea..7022abb 100644 --- a/packaging/geofence-dbus.spec +++ b/packaging/geofence-dbus.spec @@ -1,6 +1,6 @@ Name: geofence-dbus Summary: Dbus interface for Geofence service -Version: 0.2.2 +Version: 0.3.0 Release: 1 Group: Location/Libraries License: Apache-2.0 @@ -16,14 +16,9 @@ BuildRequires: cmake BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(gobject-2.0) BuildRequires: pkgconfig(dlog) -#BuildRequires: pkgconfig(security-server) BuildRequires: pkgconfig(gio-2.0) BuildRequires: pkgconfig(gio-unix-2.0) -BuildRequires: pkgconfig(capi-appfw-app-manager) -BuildRequires: pkgconfig(capi-appfw-package-manager) -BuildRequires: pkgconfig(pkgmgr-info) -BuildRequires: python -BuildRequires: python-xml +BuildRequires: pkgconfig(capi-base-common) %description Geofence dbus interface diff --git a/server/include/geofence_dbus_server.h b/server/include/geofence_dbus_server.h index 1d532c6..7448c2e 100644 --- a/server/include/geofence_dbus_server.h +++ b/server/include/geofence_dbus_server.h @@ -24,84 +24,93 @@ __BEGIN_DECLS #include <gio/gio.h> +typedef enum { + GEOFENCE_DBUS_SERVER_ERROR_NONE = 0x0, + GEOFENCE_DBUS_SERVER_ERROR_UNKNOWN, + GEOFENCE_DBUS_SERVER_ERROR_PARAMETER, + GEOFENCE_DBUS_SERVER_ERROR_MEMORY, + GEOFENCE_DBUS_SERVER_ERROR_CONNECTION, + GEOFENCE_DBUS_SERVER_ERROR_STATUS, + GEOFENCE_DBUS_SERVER_ERROR_DBUS_CALL, + GEOFENCE_DBUS_SERVER_ERROR_NO_RESULT, +} geofence_dbus_server_error_e; + + +typedef void *geofence_dbus_server_h; + + +#if SUPPORT_MULTI_CLIENT /** * @brief Callback for setting the options */ -typedef void (*GeofenceDbusSetOptionsCB) (GVariant * options, gpointer userdata); +typedef void (*GeofenceDbusSetOptionsCB)(GVariant *options, gpointer userdata); +#endif /** * @brief Callback for shutting down the Dbus */ -typedef void (*GeofenceDbusShutdownCB) (gpointer userdata, gboolean *shutdown_arr); +typedef void (*GeofenceDbusShutdownCB)(gpointer userdata, gboolean shutdown_arr); + /* for geofence callbacks */ /** * @brief Callback for adding the fence */ -typedef gint (*GeofenceAddGeofenceCB) (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); +typedef gint(*GeofenceAddGeofenceCB)(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); /** -* @brief Callback for adding the place +* @brief Callback for deleting the geofence */ -typedef gint (*GeofenceAddPlaceCB) (const gchar * app_id, const gchar * place_name, gpointer userdata); +typedef void (*GeofenceDeleteGeofenceCB)(gint fence_id, const gchar *app_id, gpointer userdata); /** -* @brief Callback for enabling the geofence +* @brief Callback for getting the fence list */ -typedef void (*GeofenceEnableGeofenceCB) (gint fence_id, const gchar *app_id, gboolean enable, gpointer userdata); +typedef GVariant *(*GeofenceGetGeofencesCB)(int place_id, const gchar *app_id, int *fence_cnt, int *error_code, gpointer userdata); /** -* @brief Callback for updating the place +* @brief Callback for enabling the geofence */ -typedef void (*GeofenceUpdatePlaceCB) (gint place_id, const gchar *app_id, const gchar *place_name, gpointer userdata); +typedef void (*GeofenceEnableGeofenceCB)(gint fence_id, const gchar *app_id, gboolean enable, gpointer userdata); + /** -* @brief Callback for deleting the geofence +* @brief Callback for Starting the Geofence service */ -typedef void (*GeofenceDeleteGeofenceCB) (gint fence_id, const gchar *app_id, gpointer userdata); +typedef void (*GeofenceStartGeofenceCB)(gint fence_id, const gchar *app_id, gpointer userdata); /** -* @brief Callback for deleting the place +* @brief Callback for Stopping the Geofence service */ -typedef void (*GeofenceDeletePlaceCB) (gint place_id, const gchar *app_id, gpointer userdata); +typedef void (*GeofenceStopGeofenceCB)(gint fence_id, const gchar *app_id, gpointer userdata); + + +/* for place callbacks */ /** -* @brief Callback for Starting the Geofence service +* @brief Callback for adding the place */ -typedef void (*GeofenceStartGeofenceCB) (gint fence_id, const gchar *app_id, gpointer userdata); +typedef gint(*GeofenceAddPlaceCB)(const gchar *app_id, const gchar *place_name, gpointer userdata); /** -* @brief Callback for Stopping the Geofence service +* @brief Callback for deleting the place */ -typedef void (*GeofenceStopGeofenceCB) (gint fence_id, const gchar *app_id, gpointer userdata); +typedef void (*GeofenceDeletePlaceCB)(gint place_id, const gchar *app_id, gpointer userdata); /** -* @brief Callback for getting the place name +* @brief Callback for updating the place */ -typedef void (*GeofenceGetPlaceNameGeofenceCB) (int place_id, const gchar *app_id, char **place_name, int *error_code, gpointer userdata); +typedef void (*GeofenceUpdatePlaceCB)(gint place_id, const gchar *app_id, const gchar *place_name, gpointer userdata); /** -* @brief Callback for getting the fence list +* @brief Callback for getting the place name */ -typedef GVariant * (*GeofenceGetlistGeofenceCB) (int place_id, const gchar *app_id, int *fenceCnt, int *error_code, gpointer userdata); +typedef void (*GeofenceGetPlaceNameCB)(int place_id, const gchar *app_id, char **place_name, int *error_code, gpointer userdata); /** * @brief Callback for getting the place list */ -typedef GVariant * (*GeofenceGetPlaceListGeofenceCB) (const gchar *app_id, int *fenceCnt, int *error_code, gpointer userdata); - -typedef enum { - GEOFENCE_DBUS_SERVER_ERROR_NONE = 0x0, - GEOFENCE_DBUS_SERVER_ERROR_UNKNOWN, - GEOFENCE_DBUS_SERVER_ERROR_PARAMETER, - GEOFENCE_DBUS_SERVER_ERROR_MEMORY, - GEOFENCE_DBUS_SERVER_ERROR_CONNECTION, - GEOFENCE_DBUS_SERVER_ERROR_STATUS, - GEOFENCE_DBUS_SERVER_ERROR_DBUS_CALL, - GEOFENCE_DBUS_SERVER_ERROR_NO_RESULT, -} geofence_dbus_server_error_e; - -typedef void *geofence_dbus_server_h; +typedef GVariant *(*GeofenceGetPlacesCB)(const gchar *app_id, int *fence_cnt, int *error_code, gpointer userdata); /** * @brief API to send the geofence status to the application @@ -109,32 +118,46 @@ typedef void *geofence_dbus_server_h; * @param[in] app_id - The application to which the status needs to be sent * @param[in] fence_state - The state of the fence whether in/out * @return int -* @retval GEOFENCE_DBUS_SERVER_ERROR_NONE +* @retval GEOFENCE_DBUS_SERVER_ERROR_NONE */ int geofence_dbus_server_send_geofence_inout_changed(geofence_dbus_server_h geofence_dbus_server, const gchar *app_id, gint fence_id, gint access_type, gint fence_state); int geofence_dbus_server_send_geofence_event_changed(geofence_dbus_server_h geofence_dbus_server, gint place_id, gint fence_id, gint access_type, const gchar *app_id, gint error, gint state); +typedef struct { +#if SUPPORT_MULTI_CLIENT + /* size_t size; */ + GeofenceDbusSetOptionsCB set_options_cb; +#endif + GeofenceDbusShutdownCB shutdown_cb; + + GeofenceAddGeofenceCB add_geofence_cb; + GeofenceDeleteGeofenceCB delete_geofence_cb; + GeofenceGetGeofencesCB get_geofences_cb; + GeofenceEnableGeofenceCB enable_geofence_cb; + GeofenceStartGeofenceCB start_geofence_cb; + GeofenceStopGeofenceCB stop_geofence_cb; + + GeofenceAddPlaceCB add_place_cb; + GeofenceUpdatePlaceCB update_place_cb; + GeofenceDeletePlaceCB delete_place_cb; + GeofenceGetPlaceNameCB get_place_name_cb; + GeofenceGetPlacesCB get_places_cb; +} geofence_dbus_callback_s; + /** * @brief API to create the server * @param[in] service_name - Name of the service for which the server has to be created * @param[in] service_path - Path for the service -* @param[in] name - Server name -* @param[in] description - Description about the server * @param[in] geofence_dbus_server - Dbus server pointer -* @param[in] add_geofence_cb - Callback for add geofence funtionality -* @param[in] enable_geofence_cb - Callback for enable geofence functionality -* @param[in] delete_fence_cb - Callback for delete geofence funtionality -* @param[in] getlist_fence_cb - Callback for getlist functionality -* @param[in] start_geofence_cb - Callback for start geofence functionality -* @param[in] stop_geofence_cb - Callback for stopping the geofence functionality +* @param[in] geofence_dbus_callback - Callback for all dbus interface * @param[in] userdata - Userdata if any which will come back in the callbacks * return int * retval GEOFENCE_DBUS_SERVER_ERROR_NONE if success GEOFENCE_DBUS_SERVER_ERROR_MEMORY if failure */ -int geofence_dbus_server_create(char *service_name, char *service_path, char *name, char *description, geofence_dbus_server_h *geofence_dbus_server, GeofenceAddGeofenceCB add_geofence_cb, GeofenceAddPlaceCB add_place_cb, GeofenceEnableGeofenceCB enable_geofence_cb, GeofenceUpdatePlaceCB update_place_cb, GeofenceDeleteGeofenceCB delete_fence_cb, GeofenceDeletePlaceCB delete_place_cb, GeofenceGetPlaceNameGeofenceCB getplacename_fence_cb, GeofenceGetlistGeofenceCB getlist_fence_cb, GeofenceGetPlaceListGeofenceCB getplacelist_fence_cb, GeofenceStartGeofenceCB start_geofence_cb, GeofenceStopGeofenceCB stop_geofence_cb, gpointer userdata); +int geofence_dbus_server_create(geofence_dbus_server_h *geofence_dbus_server, geofence_dbus_callback_s *geofence_dbus_callback, gpointer userdata); /** * @brief API to destroy the dbus server which was created diff --git a/server/include/geofence_dbus_server_priv.h b/server/include/geofence_dbus_server_priv.h index 5623e9f..00851cc 100644 --- a/server/include/geofence_dbus_server_priv.h +++ b/server/include/geofence_dbus_server_priv.h @@ -40,5 +40,5 @@ __BEGIN_DECLS #define GEOFENCE_DBUS_SERVER_LOGE(fmt, args...) #define GEOFENCE_DBUS_SERVER_SECLOG(fmt, args...) #endif - __END_DECLS +__END_DECLS #endif /*__GEOFENCE_DBUS_SERVER_PRIV_H__*/ diff --git a/server/src/geofence_dbus_server.c b/server/src/geofence_dbus_server.c index 254d00b..3e86c03 100644 --- a/server/src/geofence_dbus_server.c +++ b/server/src/geofence_dbus_server.c @@ -20,20 +20,35 @@ #include "geofence_dbus_server.h" #include "geofence_dbus_server_priv.h" + +#define GEOFENCE_SERVICE_NAME "org.tizen.lbs.Providers.GeofenceServer" +#define GEOFENCE_SERVICE_PATH "/org/tizen/lbs/Providers/GeofenceServer" + +typedef struct _geofence_dbus_signal_s { + guint add_geofence_h; + guint delete_geofence_h; + guint get_geofences_h; + guint enable_geofence_h; + guint start_geofence_h; + guint stop_geofence_h; + + guint add_place_h; + guint update_place_h; + guint delete_place_h; + guint get_place_name_h; + guint get_places_h; +} geofence_dbus_signal_s; + typedef struct _geofence_dbus_server_s { /* Geofence Dbus Server info */ gchar *service_name; gchar *prev_owner; gchar *service_path; - gchar *name; - gchar *description; - GHashTable *connections; gint status; GDBusObjectManagerServer *manager; SLocObjectSkeleton *obj_skeleton; - GeofenceDbusSetOptionsCB set_options_cb; - GeofenceDbusShutdownCB shutdown_cb; - gpointer userdata; /* used for save GpsManager */ + GHashTable *connections; + gpointer userdata; guint owner_changed_id; guint owner_id; guint get_providerinfo_h; @@ -42,41 +57,10 @@ typedef struct _geofence_dbus_server_s { guint add_reference_h; guint remove_reference_h; - /* for geofence */ - guint add_geofence_h; - guint add_place_h; - guint enable_geofence_h; - guint update_place_h; - guint delete_geofence_h; - guint delete_place_h; - guint start_geofence_h; - guint stop_geofence_h; - guint getplacename_geofence_h; - guint getlist_geofence_h; - guint getplacelist_geofence_h; - - gint geofence_status; - GeofenceAddGeofenceCB add_geofence_cb; - GeofenceAddPlaceCB add_place_cb; - GeofenceEnableGeofenceCB enable_geofence_cb; - GeofenceUpdatePlaceCB update_place_cb; - GeofenceDeleteGeofenceCB delete_geofence_cb; - GeofenceDeletePlaceCB delete_place_cb; - GeofenceGetPlaceNameGeofenceCB getplacename_geofence_cb; - GeofenceGetlistGeofenceCB getlist_geofence_cb; - GeofenceGetPlaceListGeofenceCB getplacelist_geofence_cb; - GeofenceStartGeofenceCB start_geofence_cb; - GeofenceStopGeofenceCB stop_geofence_cb; + geofence_dbus_signal_s *dbus_signal; + geofence_dbus_callback_s *dbus_callback; } geofence_dbus_server_s; -typedef enum { - GEOFENCE_DBUS_SERVER_METHOD_GPS = 0, - GEOFENCE_DBUS_SERVER_METHOD_NPS, - GEOFENCE_DBUS_SERVER_METHOD_AGPS, - GEOFENCE_DBUS_SERVER_METHOD_GEOFENCE, - GEOFENCE_DBUS_SERVER_METHOD_SIZE, -} geofence_dbus_server_method_e; - static gboolean geofence_dbus_setup_geofence_interface(SLocObjectSkeleton *object, geofence_dbus_server_s *ctx) { GEOFENCE_DBUS_SERVER_LOGD("geofence_dbus_setup_geofence_interface"); @@ -91,160 +75,138 @@ static gboolean geofence_dbus_setup_geofence_interface(SLocObjectSkeleton *objec return TRUE; } -static gboolean geofence_find_method(gpointer key, gpointer value, gpointer user_data) -{ - int *ip = (int *)user_data; - int *arr = (int *)value; - int method = *ip; - - GEOFENCE_DBUS_SERVER_LOGD("[%s] geofence_find_method method:%d, count:%d", (char *)key, method, arr[method]); - - return (arr[method] > 0) ? TRUE : FALSE; -} - /* * For geofence methods */ static gboolean on_add_geofence(SLocGeofence *geofence, GDBusMethodInvocation *invocation, 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 user_data) { - GEOFENCE_DBUS_SERVER_LOGD("on_add_geofence"); + GEOFENCE_DBUS_SERVER_LOGD("ENTER >>>"); /* call geofence-server's callback, add_geofence_cb */ geofence_dbus_server_s *ctx = (geofence_dbus_server_s *)user_data; - if (!ctx) - return FALSE; - gint fence_id = 0; - if (ctx->add_geofence_cb) { - fence_id = ctx->add_geofence_cb(app_id, place_id, geofence_type, latitude, longitude, radius, address, bssid, ssid, ctx->userdata); + if (!ctx) return FALSE; + + gint fence_id = -1; + if (ctx->dbus_callback && ctx->dbus_callback->add_geofence_cb) { + fence_id = ctx->dbus_callback->add_geofence_cb(app_id, place_id, geofence_type, latitude, longitude, radius, address, bssid, ssid, ctx->userdata); GEOFENCE_DBUS_SERVER_LOGD("add_geofence_cb called"); } + GEOFENCE_DBUS_SERVER_LOGD("fence_id: %d", fence_id); sloc_geofence_complete_add_geofence(geofence, invocation, fence_id); return TRUE; } -static gboolean on_add_place(SLocGeofence *geofence, GDBusMethodInvocation *invocation, const gchar *app_id, const gchar *place_name, gpointer user_data) +static gboolean on_delete_geofence(SLocGeofence *geofence, GDBusMethodInvocation *invocation, gint fence_id, const gchar *app_id, gpointer user_data) { - GEOFENCE_DBUS_SERVER_LOGD("on_add_place"); + GEOFENCE_DBUS_SERVER_LOGD("on_delete_geofence"); - /* call geofence-server's callback, add_place_cb */ + /* call geofence-server's callback, delete_geofence_cb */ geofence_dbus_server_s *ctx = (geofence_dbus_server_s *)user_data; - if (!ctx) - return FALSE; - gint place_id = 0; - if (ctx->add_geofence_cb) { - place_id = ctx->add_place_cb(app_id, place_name, ctx->userdata); - GEOFENCE_DBUS_SERVER_LOGD("add_place_cb called"); + if (!ctx) return FALSE; + + if (ctx->dbus_callback && ctx->dbus_callback->delete_geofence_cb) { + ctx->dbus_callback->delete_geofence_cb(fence_id, app_id, ctx->userdata); + GEOFENCE_DBUS_SERVER_LOGD("delete_geofence_cb called"); } - sloc_geofence_complete_add_place(geofence, invocation, place_id); + sloc_geofence_complete_delete_geofence(geofence, invocation); return TRUE; } -static gboolean on_enable_geofence(SLocGeofence *geofence, GDBusMethodInvocation *invocation, gint fence_id, const gchar *app_id, gboolean enable, gpointer user_data) +static gboolean on_get_geofences(SLocGeofence *geofence, GDBusMethodInvocation *invocation, gint place_id, const gchar *app_id, gpointer user_data) { - GEOFENCE_DBUS_SERVER_LOGD("on_enable_geofence"); + GEOFENCE_DBUS_SERVER_LOGD("ENTER >>>"); + /* call geofence-server's callback, getlist_geofence_cb */ geofence_dbus_server_s *ctx = (geofence_dbus_server_s *)user_data; - if (!ctx) - return FALSE; + if (!ctx) return FALSE; - /* call geofence-server's callback, enable_geofence_cb */ - if (ctx->enable_geofence_cb) { - ctx->enable_geofence_cb(fence_id, app_id, enable, ctx->userdata); - GEOFENCE_DBUS_SERVER_LOGD("enable_geofence_cb called"); + GVariant *geofence_info = NULL; + gint fence_cnt = 0; + gint error_code = -1; + + if (ctx->dbus_callback && ctx->dbus_callback->get_geofences_cb) { + geofence_info = ctx->dbus_callback->get_geofences_cb(place_id, app_id, &fence_cnt, &error_code, ctx->userdata); + GEOFENCE_DBUS_SERVER_LOGD("getlist_geofence_cb called"); } - sloc_geofence_complete_enable_geofence(geofence, invocation); + sloc_geofence_complete_get_geofences(geofence, invocation, fence_cnt, error_code, geofence_info); return TRUE; } -static gboolean on_update_place(SLocGeofence *geofence, GDBusMethodInvocation *invocation, gint place_id, const gchar *app_id, const gchar *place_name, gpointer user_data) +static gboolean on_enable_geofence(SLocGeofence *geofence, GDBusMethodInvocation *invocation, gint fence_id, const gchar *app_id, gboolean enable, gpointer user_data) { - GEOFENCE_DBUS_SERVER_LOGD("on_update_place"); + GEOFENCE_DBUS_SERVER_LOGD("on_enable_geofence"); - /* call geofence-server's callback, update_place_cb */ geofence_dbus_server_s *ctx = (geofence_dbus_server_s *)user_data; - if (!ctx) - return FALSE; - if (ctx->update_place_cb) { - ctx->update_place_cb(place_id, app_id, place_name, ctx->userdata); - GEOFENCE_DBUS_SERVER_LOGD("update_place_cb called"); + if (!ctx) return FALSE; + + /* call geofence-server's callback, enable_geofence_cb */ + if (ctx->dbus_callback && ctx->dbus_callback->enable_geofence_cb) { + ctx->dbus_callback->enable_geofence_cb(fence_id, app_id, enable, ctx->userdata); + GEOFENCE_DBUS_SERVER_LOGD("enable_geofence_cb called"); } - sloc_geofence_complete_update_place(geofence, invocation); + sloc_geofence_complete_enable_geofence(geofence, invocation); return TRUE; } -static gboolean on_getplacename_geofence(SLocGeofence *geofence, GDBusMethodInvocation *invocation, gint place_id, const gchar *app_id, gpointer user_data) +static gboolean on_start_geofence(SLocGeofence *geofence, GDBusMethodInvocation *invocation, gint fence_id, const gchar *app_id, gpointer user_data) { - GEOFENCE_DBUS_SERVER_LOGD("on_getplacename_geofence"); + GEOFENCE_DBUS_SERVER_LOGD("on_start_geofence"); - /* call geofence-server's callback, getplacename_geofence_cb */ geofence_dbus_server_s *ctx = (geofence_dbus_server_s *)user_data; - if (!ctx) { - return FALSE; - } - char *place_name = NULL; - gint error_code = -1; - if (ctx->getplacename_geofence_cb) { - ctx->getplacename_geofence_cb(place_id, app_id, &place_name, &error_code, ctx->userdata); - GEOFENCE_DBUS_SERVER_LOGD("getlist_geofence_cb called"); + if (!ctx) return FALSE; + /* call geofence-server's callback, start_geofence_cb */ + if (ctx->dbus_callback && ctx->dbus_callback->start_geofence_cb) { + ctx->dbus_callback->start_geofence_cb(fence_id, app_id, ctx->userdata); + GEOFENCE_DBUS_SERVER_LOGD("start_geofence_cb called"); } - sloc_geofence_complete_get_place_name(geofence, invocation, error_code, place_name); - if (place_name) - g_free(place_name); /*This has to be freed as it has been allocated by the server DB side*/ + sloc_geofence_complete_start_geofence(geofence, invocation); return TRUE; } -static gboolean on_getlist_geofence(SLocGeofence *geofence, GDBusMethodInvocation *invocation, gint place_id, const gchar *app_id, gpointer user_data) +static gboolean on_stop_geofence(SLocGeofence *geofence, GDBusMethodInvocation *invocation, gint fence_id, const gchar *app_id, gpointer user_data) { - GEOFENCE_DBUS_SERVER_LOGD("on_getlist_geofence"); + GEOFENCE_DBUS_SERVER_LOGD("on_stop_geofence"); - /* call geofence-server's callback, getlist_geofence_cb */ geofence_dbus_server_s *ctx = (geofence_dbus_server_s *)user_data; - if (!ctx) - return FALSE; - - GVariant *geofence_info = NULL; - gint fence_cnt = 0; - gint error_code = -1; - if (ctx->getlist_geofence_cb) { - geofence_info = ctx->getlist_geofence_cb(place_id, app_id, &fence_cnt, &error_code, ctx->userdata); - GEOFENCE_DBUS_SERVER_LOGD("getlist_geofence_cb called"); + if (!ctx) return FALSE; + /* call geofence-server's callback, stop_geofence_cb */ + if (ctx->dbus_callback && ctx->dbus_callback->stop_geofence_cb) { + ctx->dbus_callback->stop_geofence_cb(fence_id, app_id, ctx->userdata); + GEOFENCE_DBUS_SERVER_LOGD("stop_geofence_cb called"); } - sloc_geofence_complete_get_list(geofence, invocation, fence_cnt, error_code, geofence_info); + sloc_geofence_complete_stop_geofence(geofence, invocation); return TRUE; } -static gboolean on_getplacelist_geofence(SLocGeofence *geofence, GDBusMethodInvocation *invocation, const gchar *app_id, gpointer user_data) +static gboolean on_add_place(SLocGeofence *geofence, GDBusMethodInvocation *invocation, const gchar *app_id, const gchar *place_name, gpointer user_data) { - GEOFENCE_DBUS_SERVER_LOGD("on_getplacelist_geofence"); + GEOFENCE_DBUS_SERVER_LOGD("on_add_place"); - /* call geofence-server's callback, getplacelist_geofence_cb */ + /* call geofence-server's callback, add_place_cb */ geofence_dbus_server_s *ctx = (geofence_dbus_server_s *)user_data; - if (!ctx) - return FALSE; - GVariant *place_info = NULL; - gint place_cnt = 0; - gint error_code = -1; - if (ctx->getplacelist_geofence_cb) { - place_info = ctx->getplacelist_geofence_cb(app_id, &place_cnt, &error_code, ctx->userdata); - GEOFENCE_DBUS_SERVER_LOGD("getplacelist_geofence_cb called"); + if (!ctx) return FALSE; + gint place_id = -1; + if (ctx->dbus_callback && ctx->dbus_callback->add_place_cb) { + place_id = ctx->dbus_callback->add_place_cb(app_id, place_name, ctx->userdata); + GEOFENCE_DBUS_SERVER_LOGD("add_place_cb called"); } - sloc_geofence_complete_get_place_list(geofence, invocation, place_cnt, error_code, place_info); + sloc_geofence_complete_add_place(geofence, invocation, place_id); return TRUE; } -static gboolean on_delete_geofence(SLocGeofence *geofence, GDBusMethodInvocation *invocation, gint fence_id, const gchar *app_id, gpointer user_data) +static gboolean on_update_place(SLocGeofence *geofence, GDBusMethodInvocation *invocation, gint place_id, const gchar *app_id, const gchar *place_name, gpointer user_data) { - GEOFENCE_DBUS_SERVER_LOGD("on_delete_geofence"); + GEOFENCE_DBUS_SERVER_LOGD("on_update_place"); - /* call geofence-server's callback, delete_geofence_cb */ + /* call geofence-server's callback, update_place_cb */ geofence_dbus_server_s *ctx = (geofence_dbus_server_s *)user_data; - if (!ctx) - return FALSE; - if (ctx->delete_geofence_cb) { - ctx->delete_geofence_cb(fence_id, app_id, ctx->userdata); - GEOFENCE_DBUS_SERVER_LOGD("delete_geofence_cb called"); + if (!ctx) return FALSE; + + if (ctx->dbus_callback && ctx->dbus_callback->update_place_cb) { + ctx->dbus_callback->update_place_cb(place_id, app_id, place_name, ctx->userdata); + GEOFENCE_DBUS_SERVER_LOGD("update_place_cb called"); } - sloc_geofence_complete_delete_geofence(geofence, invocation); + sloc_geofence_complete_update_place(geofence, invocation); return TRUE; } @@ -254,48 +216,56 @@ static gboolean on_delete_place(SLocGeofence *geofence, GDBusMethodInvocation *i /* call geofence-server's callback, delete_place_cb */ geofence_dbus_server_s *ctx = (geofence_dbus_server_s *)user_data; - if (!ctx) - return FALSE; - if (ctx->delete_place_cb) { - ctx->delete_place_cb(place_id, app_id, ctx->userdata); + if (!ctx) return FALSE; + + if (ctx->dbus_callback && ctx->dbus_callback->delete_place_cb) { + ctx->dbus_callback->delete_place_cb(place_id, app_id, ctx->userdata); GEOFENCE_DBUS_SERVER_LOGD("delete_place_cb called"); } sloc_geofence_complete_delete_place(geofence, invocation); return TRUE; } -static gboolean on_start_geofence(SLocGeofence *geofence, GDBusMethodInvocation *invocation, gint fence_id, const gchar *app_id, gpointer user_data) +static gboolean on_get_place_name(SLocGeofence *geofence, GDBusMethodInvocation *invocation, gint place_id, const gchar *app_id, gpointer user_data) { - GEOFENCE_DBUS_SERVER_LOGD("on_start_geofence"); + GEOFENCE_DBUS_SERVER_LOGD("on_getplacename_geofence"); + /* call geofence-server's callback, getplacename_geofence_cb */ geofence_dbus_server_s *ctx = (geofence_dbus_server_s *)user_data; - if (!ctx) - return FALSE; - /* call geofence-server's callback, start_geofence_cb */ - if (ctx->start_geofence_cb) { - ctx->start_geofence_cb(fence_id, app_id, ctx->userdata); - GEOFENCE_DBUS_SERVER_LOGD("start_geofence_cb called"); + if (!ctx) return FALSE; + + char *place_name = NULL; + gint error_code = -1; + if (ctx->dbus_callback && ctx->dbus_callback->add_place_cb) { + ctx->dbus_callback->get_place_name_cb(place_id, app_id, &place_name, &error_code, ctx->userdata); + GEOFENCE_DBUS_SERVER_LOGD("getlist_geofence_cb called"); } - sloc_geofence_complete_start_geofence(geofence, invocation); + sloc_geofence_complete_get_place_name(geofence, invocation, error_code, place_name); + if (place_name) + g_free(place_name); /*This has to be freed as it has been allocated by the server DB side*/ return TRUE; } -static gboolean on_stop_geofence(SLocGeofence *geofence, GDBusMethodInvocation *invocation, gint fence_id, const gchar *app_id, gpointer user_data) +static gboolean on_get_places(SLocGeofence *geofence, GDBusMethodInvocation *invocation, const gchar *app_id, gpointer user_data) { - GEOFENCE_DBUS_SERVER_LOGD("on_stop_geofence"); + GEOFENCE_DBUS_SERVER_LOGD("ENTER >>>"); + /* call geofence-server's callback, getplacelist_geofence_cb */ geofence_dbus_server_s *ctx = (geofence_dbus_server_s *)user_data; - if (!ctx) - return FALSE; - /* call geofence-server's callback, stop_geofence_cb */ - if (ctx->stop_geofence_cb) { - ctx->stop_geofence_cb(fence_id, app_id, ctx->userdata); - GEOFENCE_DBUS_SERVER_LOGD("stop_geofence_cb called"); + if (!ctx) return FALSE; + + GVariant *place_info = NULL; + gint place_cnt = 0; + gint error_code = -1; + if (ctx->dbus_callback && ctx->dbus_callback->add_place_cb) { + place_info = ctx->dbus_callback->get_places_cb(app_id, &place_cnt, &error_code, ctx->userdata); + GEOFENCE_DBUS_SERVER_LOGD("get_places_cb called"); } - sloc_geofence_complete_stop_geofence(geofence, invocation); + sloc_geofence_complete_get_places(geofence, invocation, place_cnt, error_code, place_info); return TRUE; } +/*#if SUPPORT_MULTI_CLIENT */ static gboolean geofence_remove_client_by_force(const char *client, void *data) { GEOFENCE_DBUS_SERVER_LOGD("remove client by force for client [%s]", client); @@ -312,37 +282,25 @@ static gboolean geofence_remove_client_by_force(const char *client, void *data) GEOFENCE_DBUS_SERVER_LOGE("g_hash_table_remove is Fail"); } - int index = 0; - gboolean *shutdown_arr = (gboolean *)g_malloc0_n(GEOFENCE_DBUS_SERVER_METHOD_SIZE, sizeof(gboolean)); - if (shutdown_arr == NULL) { - GEOFENCE_DBUS_SERVER_LOGD("malloc fail for geofence_remove_client_by_force"); - return FALSE; - } +#if SUPPORT_MULTI_CLIENT + gboolean shutdown_arr = FALSE; if (g_hash_table_size(ctx->connections) == 0) { - GEOFENCE_DBUS_SERVER_SECLOG("Hash table size is zero, Now shutdown provider[%s]", ctx->name); - - for (; index < GEOFENCE_DBUS_SERVER_METHOD_SIZE; index++) - shutdown_arr[index] = TRUE; + GEOFENCE_DBUS_SERVER_SECLOG("Hash table size is zero, Now shutdown provider[%s]", ctx->prev_owner); + shutdown_arr = TRUE; } else { GEOFENCE_DBUS_SERVER_SECLOG("Hash table size is not zero"); - - for (; index < GEOFENCE_DBUS_SERVER_METHOD_SIZE; index++) { - if (g_hash_table_find(ctx->connections, (GHRFunc) geofence_find_method, &index) == NULL) { - shutdown_arr[index] = TRUE; - continue; - } - } } if (ctx->shutdown_cb) { ctx->shutdown_cb(ctx->userdata, shutdown_arr); - GEOFENCE_DBUS_SERVER_LOGD("shutdown_cb called.. gps:%d, nps:%d", shutdown_arr[GEOFENCE_DBUS_SERVER_METHOD_GPS], shutdown_arr[GEOFENCE_DBUS_SERVER_METHOD_NPS]); + GEOFENCE_DBUS_SERVER_LOGD("shutdown_cb called..[%d]", shutdown_arr); } +#endif GEOFENCE_DBUS_SERVER_LOGD("###### A client[%s] is abnormally shut down ########", client); - g_free(shutdown_arr); + return TRUE; } @@ -382,12 +340,12 @@ static void on_name_owner_changed(GDBusConnection *connection, const gchar *send g_hash_table_foreach(handle->connections, (GHFunc) geofence_scan_sender, handle); } } +/*#endif */ static void on_bus_acquired(GDBusConnection *conn, const gchar *name, gpointer user_data) { geofence_dbus_server_s *ctx = (geofence_dbus_server_s *)user_data; - if (!ctx) - return; + g_return_if_fail(ctx); gchar *path = NULL; SLocGeofence *geofence = NULL; @@ -412,34 +370,47 @@ static void on_bus_acquired(GDBusConnection *conn, const gchar *name, gpointer u /* register callback for each methods for geofence */ geofence = sloc_object_get_geofence(SLOC_OBJECT(ctx->obj_skeleton)); } - if (geofence == NULL) + if (geofence == NULL) { + GEOFENCE_DBUS_SERVER_LOGE("Can't create geofence object"); return; + } + + geofence_dbus_callback_s *dbus_callback = ctx->dbus_callback; + geofence_dbus_signal_s *dbus_signal = g_new0(geofence_dbus_signal_s, 1); + g_return_val_if_fail(dbus_signal, GEOFENCE_DBUS_SERVER_ERROR_MEMORY); + + if (dbus_callback->add_geofence_cb) + dbus_signal->add_geofence_h = g_signal_connect(geofence, "handle-add-geofence", G_CALLBACK(on_add_geofence), ctx); + if (dbus_callback->delete_geofence_cb) + dbus_signal->delete_geofence_h = g_signal_connect(geofence, "handle-delete-geofence", G_CALLBACK(on_delete_geofence), ctx); + if (dbus_callback->get_geofences_cb) + dbus_signal->get_geofences_h = g_signal_connect(geofence, "handle-get-geofences", G_CALLBACK(on_get_geofences), ctx); + if (dbus_callback->enable_geofence_cb) + dbus_signal->enable_geofence_h = g_signal_connect(geofence, "handle-enable-geofence", G_CALLBACK(on_enable_geofence), ctx); + if (dbus_callback->start_geofence_cb) + dbus_signal->start_geofence_h = g_signal_connect(geofence, "handle-start-geofence", G_CALLBACK(on_start_geofence), ctx); + if (dbus_callback->stop_geofence_cb) + dbus_signal->stop_geofence_h = g_signal_connect(geofence, "handle-stop-geofence", G_CALLBACK(on_stop_geofence), ctx); + + if (dbus_callback->add_place_cb) + dbus_signal->add_place_h = g_signal_connect(geofence, "handle-add-place", G_CALLBACK(on_add_place), ctx); + if (dbus_callback->update_place_cb) + dbus_signal->update_place_h = g_signal_connect(geofence, "handle-update-place", G_CALLBACK(on_update_place), ctx); + if (dbus_callback->delete_place_cb) + dbus_signal->delete_place_h = g_signal_connect(geofence, "handle-delete-place", G_CALLBACK(on_delete_place), ctx); + if (dbus_callback->get_place_name_cb) + dbus_signal->get_place_name_h = g_signal_connect(geofence, "handle-get-place-name", G_CALLBACK(on_get_place_name), ctx); + if (dbus_callback->get_places_cb) + dbus_signal->get_places_h = g_signal_connect(geofence, "handle-get-places", G_CALLBACK(on_get_places), ctx); + + ctx->dbus_signal = dbus_signal; - if (ctx->add_geofence_cb) - ctx->add_geofence_h = g_signal_connect(geofence, "handle-add-geofence", G_CALLBACK(on_add_geofence), ctx); /* user_data */ - if (ctx->add_place_cb) - ctx->add_place_h = g_signal_connect(geofence, "handle-add-place", G_CALLBACK(on_add_place), ctx); /* user_data */ - if (ctx->enable_geofence_cb) - ctx->enable_geofence_h = g_signal_connect(geofence, "handle-enable-geofence", G_CALLBACK(on_enable_geofence), ctx); /* user_data */ - if (ctx->update_place_cb) - ctx->update_place_h = g_signal_connect(geofence, "handle-update-place", G_CALLBACK(on_update_place), ctx); /* user_data */ - if (ctx->delete_geofence_cb) - ctx->delete_geofence_h = g_signal_connect(geofence, "handle-delete-geofence", G_CALLBACK(on_delete_geofence), ctx); /* user_data */ - if (ctx->delete_place_cb) - ctx->delete_place_h = g_signal_connect(geofence, "handle-delete-place", G_CALLBACK(on_delete_place), ctx); /* user_data */ - if (ctx->start_geofence_cb) - ctx->start_geofence_h = g_signal_connect(geofence, "handle-start-geofence", G_CALLBACK(on_start_geofence), ctx); /* user_data */ - if (ctx->stop_geofence_cb) - ctx->stop_geofence_h = g_signal_connect(geofence, "handle-stop-geofence", G_CALLBACK(on_stop_geofence), ctx); /* user_data */ - if (ctx->getplacename_geofence_cb) - ctx->getplacename_geofence_h = g_signal_connect(geofence, "handle-get-place-name", G_CALLBACK(on_getplacename_geofence), ctx); - if (ctx->getlist_geofence_cb) - ctx->getlist_geofence_h = g_signal_connect(geofence, "handle-get-list", G_CALLBACK(on_getlist_geofence), ctx); /*user_data */ - if (ctx->getplacelist_geofence_cb) - ctx->getplacelist_geofence_h = g_signal_connect(geofence, "handle-get-place-list", G_CALLBACK(on_getplacelist_geofence), ctx); g_object_unref(geofence); + /*#if SUPPORT_MULTI_CLIENT //TODO: We need it? */ ctx->owner_changed_id = g_dbus_connection_signal_subscribe(conn, "org.freedesktop.DBus", "org.freedesktop.DBus", "NameOwnerChanged", "/org/freedesktop/DBus", NULL, G_DBUS_SIGNAL_FLAGS_NONE, on_name_owner_changed, ctx, NULL); + /*#endif */ + g_dbus_object_manager_server_set_connection(ctx->manager, conn); GEOFENCE_DBUS_SERVER_LOGD("done to acquire the dbus"); } @@ -456,7 +427,7 @@ static void on_name_lost(GDBusConnection *connection, const gchar *name, gpointe EXPORT_API int geofence_dbus_server_send_geofence_inout_changed(geofence_dbus_server_h geofence_dbus_server, const gchar *app_id, gint fence_id, gint access_type, gint fence_state) { - GEOFENCE_DBUS_SERVER_LOGD("geofence_dbus_server_send_geofence_inout_changed"); + GEOFENCE_DBUS_SERVER_LOGD("ENTER >>>"); g_return_val_if_fail(geofence_dbus_server, GEOFENCE_DBUS_SERVER_ERROR_PARAMETER); geofence_dbus_server_s *handle = (geofence_dbus_server_s *)geofence_dbus_server; @@ -474,7 +445,7 @@ EXPORT_API int geofence_dbus_server_send_geofence_inout_changed(geofence_dbus_se EXPORT_API int geofence_dbus_server_send_geofence_event_changed(geofence_dbus_server_h geofence_dbus_server, gint place_id, gint fence_id, gint access_type, const gchar *app_id, gint error, gint state) { - GEOFENCE_DBUS_SERVER_LOGD("geofence_dbus_server_send_geofence_event_changed"); + GEOFENCE_DBUS_SERVER_LOGD("ENTER >>>"); g_return_val_if_fail(geofence_dbus_server, GEOFENCE_DBUS_SERVER_ERROR_PARAMETER); geofence_dbus_server_s *handle = (geofence_dbus_server_s *)geofence_dbus_server; g_return_val_if_fail(handle->obj_skeleton, GEOFENCE_DBUS_SERVER_ERROR_PARAMETER); @@ -489,100 +460,80 @@ EXPORT_API int geofence_dbus_server_send_geofence_event_changed(geofence_dbus_se return GEOFENCE_DBUS_SERVER_ERROR_NONE; } -static void _glib_log(const gchar *log_domain, GLogLevelFlags log_level, const gchar *msg, gpointer user_data) +/* Because of this, geofence-server's handler doesn't work. */ +#if 0 +static void __glib_log(const gchar *log_domain, GLogLevelFlags log_level, const gchar *msg, gpointer user_data) { geofence_dbus_server_s *server = (geofence_dbus_server_s *)user_data; if (server != NULL) GEOFENCE_DBUS_SERVER_LOGD("server->manager (%p)", server->manager); GEOFENCE_DBUS_SERVER_LOGE("GLIB[%d] : %s", log_level, msg); } +#endif -EXPORT_API int geofence_dbus_server_create(char *service_name, char *service_path, char *name, char *description, geofence_dbus_server_h *geofence_dbus_server, GeofenceAddGeofenceCB add_geofence_cb, GeofenceAddPlaceCB add_place_cb, GeofenceEnableGeofenceCB enable_geofence_cb, GeofenceUpdatePlaceCB update_place_cb, GeofenceDeleteGeofenceCB delete_geofence_cb, GeofenceDeletePlaceCB delete_place_cb, GeofenceGetPlaceNameGeofenceCB getplacename_geofence_cb, GeofenceGetlistGeofenceCB getlist_geofence_cb, GeofenceGetPlaceListGeofenceCB getplacelist_geofence_cb, GeofenceStartGeofenceCB start_geofence_cb, GeofenceStopGeofenceCB stop_geofence_cb, gpointer userdata) +EXPORT_API int geofence_dbus_server_create(geofence_dbus_server_h *geofence_dbus_server, geofence_dbus_callback_s *geofence_dbus_callback, gpointer userdata) { GEOFENCE_DBUS_SERVER_LOGD("geofence_dbus_server_create"); - g_return_val_if_fail(service_name, GEOFENCE_DBUS_SERVER_ERROR_PARAMETER); - g_return_val_if_fail(service_path, GEOFENCE_DBUS_SERVER_ERROR_PARAMETER); g_return_val_if_fail(geofence_dbus_server, GEOFENCE_DBUS_SERVER_ERROR_PARAMETER); + g_return_val_if_fail(geofence_dbus_callback, GEOFENCE_DBUS_SERVER_ERROR_PARAMETER); int ret = GEOFENCE_DBUS_SERVER_ERROR_NONE; geofence_dbus_server_s *server = g_new0(geofence_dbus_server_s, 1); g_return_val_if_fail(server, GEOFENCE_DBUS_SERVER_ERROR_MEMORY); - g_log_set_default_handler(_glib_log, server); + /* g_log_set_default_handler(__glib_log, server); */ - server->service_name = g_strdup(service_name); - server->service_path = g_strdup(service_path); + server->service_name = g_strdup(GEOFENCE_SERVICE_NAME); + server->service_path = g_strdup(GEOFENCE_SERVICE_PATH); server->manager = g_dbus_object_manager_server_new(server->service_path); - - if (name) - server->name = g_strdup(name); - if (description) - server->description = g_strdup(description); - server->connections = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); server->userdata = userdata; - /* add gefence callbacks */ - server->add_geofence_cb = add_geofence_cb; - server->add_place_cb = add_place_cb; - server->enable_geofence_cb = enable_geofence_cb; - server->update_place_cb = update_place_cb; - server->delete_geofence_cb = delete_geofence_cb; - server->delete_place_cb = delete_place_cb; - server->getplacename_geofence_cb = getplacename_geofence_cb; - server->getlist_geofence_cb = getlist_geofence_cb; - server->getplacelist_geofence_cb = getplacelist_geofence_cb; - server->start_geofence_cb = start_geofence_cb; - server->stop_geofence_cb = stop_geofence_cb; - - server->owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM, service_name, G_BUS_NAME_OWNER_FLAGS_REPLACE, on_bus_acquired, on_name_acquired, on_name_lost, server, NULL); + /* set gefence callbacks */ + server->dbus_callback = geofence_dbus_callback; + + server->owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM, server->service_name, G_BUS_NAME_OWNER_FLAGS_REPLACE, on_bus_acquired, on_name_acquired, on_name_lost, server, NULL); GEOFENCE_DBUS_SERVER_LOGD("g_bus_own_name id=[%d]", server->owner_id); - *geofence_dbus_server = (geofence_dbus_server_h *) server; + *geofence_dbus_server = (geofence_dbus_server_s *) server; return ret; } - EXPORT_API int geofence_dbus_server_destroy(geofence_dbus_server_h geofence_dbus_server) { GEOFENCE_DBUS_SERVER_LOGD("geofence_dbus_server_destroy"); g_return_val_if_fail(geofence_dbus_server, GEOFENCE_DBUS_SERVER_ERROR_PARAMETER); - geofence_dbus_server_s *handle = (geofence_dbus_server_s *)geofence_dbus_server; + geofence_dbus_server_s *server = (geofence_dbus_server_s *)geofence_dbus_server; int ret = GEOFENCE_DBUS_SERVER_ERROR_NONE; - g_bus_unown_name(handle->owner_id); - if (handle->prev_owner) { - g_free(handle->prev_owner); - handle->prev_owner = NULL; + g_bus_unown_name(server->owner_id); + if (server->prev_owner) { + g_free(server->prev_owner); + server->prev_owner = NULL; } /* disconnect geofence callbacks */ SLocGeofence *geofence = NULL; - geofence = sloc_object_get_geofence(SLOC_OBJECT(handle->obj_skeleton)); + geofence = sloc_object_get_geofence(SLOC_OBJECT(server->obj_skeleton)); g_return_val_if_fail(geofence, GEOFENCE_DBUS_SERVER_ERROR_PARAMETER); + geofence_dbus_signal_s *handle = server->dbus_signal; + g_return_val_if_fail(handle, GEOFENCE_DBUS_SERVER_ERROR_PARAMETER); + if (handle->add_geofence_h) { g_signal_handler_disconnect(geofence, handle->add_geofence_h); handle->add_geofence_h = 0; } - if (handle->add_place_h) { - g_signal_handler_disconnect(geofence, handle->add_place_h); - handle->add_place_h = 0; - } - if (handle->enable_geofence_h) { - g_signal_handler_disconnect(geofence, handle->enable_geofence_h); - handle->enable_geofence_h = 0; - } - if (handle->update_place_h) { - g_signal_handler_disconnect(geofence, handle->update_place_h); - handle->update_place_h = 0; - } if (handle->delete_geofence_h) { g_signal_handler_disconnect(geofence, handle->delete_geofence_h); handle->delete_geofence_h = 0; } - if (handle->delete_place_h) { - g_signal_handler_disconnect(geofence, handle->delete_place_h); - handle->delete_place_h = 0; + if (handle->get_geofences_h) { + g_signal_handler_disconnect(geofence, handle->get_geofences_h); + handle->get_geofences_h = 0; + } + if (handle->enable_geofence_h) { + g_signal_handler_disconnect(geofence, handle->enable_geofence_h); + handle->enable_geofence_h = 0; } if (handle->start_geofence_h) { g_signal_handler_disconnect(geofence, handle->start_geofence_h); @@ -592,31 +543,45 @@ EXPORT_API int geofence_dbus_server_destroy(geofence_dbus_server_h geofence_dbus g_signal_handler_disconnect(geofence, handle->stop_geofence_h); handle->stop_geofence_h = 0; } - if (handle->getplacename_geofence_h) { - g_signal_handler_disconnect(geofence, handle->getplacename_geofence_h); - handle->getplacename_geofence_h = 0; + + if (handle->add_place_h) { + g_signal_handler_disconnect(geofence, handle->add_place_h); + handle->add_place_h = 0; + } + if (handle->update_place_h) { + g_signal_handler_disconnect(geofence, handle->update_place_h); + handle->update_place_h = 0; + } + if (handle->delete_place_h) { + g_signal_handler_disconnect(geofence, handle->delete_place_h); + handle->delete_place_h = 0; } - if (handle->getlist_geofence_h) { - g_signal_handler_disconnect(geofence, handle->getlist_geofence_h); - handle->getlist_geofence_h = 0; + if (handle->get_place_name_h) { + g_signal_handler_disconnect(geofence, handle->get_place_name_h); + handle->get_place_name_h = 0; } - if (handle->getplacelist_geofence_h) { - g_signal_handler_disconnect(geofence, handle->getplacelist_geofence_h); - handle->getplacelist_geofence_h = 0; + if (handle->get_places_h) { + g_signal_handler_disconnect(geofence, handle->get_places_h); + handle->get_places_h = 0; } + g_free(handle); g_object_unref(geofence); - if (handle->manager) { - if (handle->owner_changed_id) { - g_dbus_connection_signal_unsubscribe(g_dbus_object_manager_server_get_connection(handle->manager), handle->owner_changed_id); - handle->owner_changed_id = 0; + if (server->manager) { + if (server->owner_changed_id) { + g_dbus_connection_signal_unsubscribe(g_dbus_object_manager_server_get_connection(server->manager), server->owner_changed_id); + server->owner_changed_id = 0; } - g_object_unref(handle->manager); - handle->manager = NULL; + g_object_unref(server->manager); + server->manager = NULL; } - g_hash_table_destroy(handle->connections); - g_free(handle); + g_hash_table_destroy(server->connections); + + g_free(server->service_name); + g_free(server->service_path); + + g_free(server); return ret; } |