From: saerome.kim Date: Wed, 10 Jan 2018 01:18:13 +0000 (+0900) Subject: fn-manager : Enable/Disable MOT agent when fn-manager initialization/deinitialization X-Git-Tag: submit/tizen/20190131.065036~264 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=992e6ff2700afdc2cee4e46c5fe56e6aebeef140;p=platform%2Fcore%2Fapi%2Fmulti-device-group.git fn-manager : Enable/Disable MOT agent when fn-manager initialization/deinitialization Signed-off-by: saerome.kim --- diff --git a/src/fn-manager/include/comp_mot_agent.h b/src/fn-manager/include/comp_mot_agent.h index bcbd760..514bc46 100644 --- a/src/fn-manager/include/comp_mot_agent.h +++ b/src/fn-manager/include/comp_mot_agent.h @@ -20,9 +20,10 @@ #ifndef __COMP_MOT_AGENT_H__ #define __COMP_MOT_AGENT_H__ - typedef void *agent_handle_h; + int agent_dbus_start(); +int agent_dbus_stop(); - int agent_dbus_start(agent_handle_h handle); -int agent_dbus_stop(agent_handle_h handle); +int agent_enable(); +int agent_disable(); #endif /* __COMP_MOT_AGENT_H__ */ \ No newline at end of file diff --git a/src/fn-manager/src/comp_mot_agent.c b/src/fn-manager/src/comp_mot_agent.c index eefe4b0..f392c3f 100644 --- a/src/fn-manager/src/comp_mot_agent.c +++ b/src/fn-manager/src/comp_mot_agent.c @@ -37,24 +37,70 @@ #define AGENT_DBUS_PROXY_TIMEOUT ((9.5 + 2) * 1000) /**< default timeout for GDBus */ -struct agent_handle { +struct agent_s { GDBusProxy *gproxy_agent_service; gpointer dbus_connection; GCancellable *ca; GList *dbus_sub_ids; }; -typedef struct agent_handle *agent_handle_h; +struct agent_s agent; -static int _close_gdbus_call(agent_handle_h handle) +int agent_enable() { - struct agent_handle *h = handle; + GVariant *variant = NULL; + int result = FN_ERROR_NONE; + GError *error = NULL; + + if (NULL == agent.dbus_connection || NULL == agent.gproxy_agent_service) { + LOG_ERR("I/O error"); + return FN_ERROR_IO_ERROR; + } - if (NULL == h) - return FN_ERROR_INVALID_PARAMETER; + variant = g_dbus_connection_call_sync(agent.dbus_connection, + AGENT_ENABLER_NAME, AGENT_ENABLER_OBJ_PATH, AGENT_ENABLER_INTERFACE, + "enable", NULL, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); + if (variant) { + g_variant_get(variant, "(i)", &result); + LOG_DEBUG("MOT Agent Enabled status 0x%x", result); + } else if (error) { + LOGE("Failed DBus call [%s]", error->message); + g_error_free(error); + return FN_ERROR_IO_ERROR; + } + + return result; +} +int agent_disable() +{ + GVariant *variant = NULL; + int result = FN_ERROR_NONE; + GError *error = NULL; + + if (NULL == agent.dbus_connection || NULL == agent.gproxy_agent_service) { + LOG_ERR("I/O error"); + return FN_ERROR_IO_ERROR; + } + + variant = g_dbus_connection_call_sync(agent.dbus_connection, + AGENT_ENABLER_NAME, AGENT_ENABLER_OBJ_PATH, AGENT_ENABLER_INTERFACE, + "disable", NULL, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); + if (variant) { + g_variant_get(variant, "(i)", &result); + LOG_DEBUG("MOT Agent Disabled status 0x%x", result); + } else if (error) { + LOGE("Failed DBus call [%s]", error->message); + g_error_free(error); + return FN_ERROR_IO_ERROR; + } + return result; +} + +static int _close_gdbus_call() +{ /* CHECK: is connection ref count required? */ - g_object_unref(h->dbus_connection); - h->dbus_connection = NULL; + g_object_unref(agent.dbus_connection); + agent.dbus_connection = NULL; return FN_ERROR_NONE; } @@ -62,33 +108,28 @@ static int _close_gdbus_call(agent_handle_h handle) static void _dbus_name_owner_notify(GObject *object, GParamSpec *pspec, gpointer *userdata) { - /* LCOV_EXCL_START */ GDBusProxy *proxy = G_DBUS_PROXY(object); gchar *name_owner = g_dbus_proxy_get_name_owner(proxy); - agent_handle_h handle = (agent_handle_h)userdata; + struct agent_s* handle = (struct agent_s*)userdata; LOG_DEBUG("Name owner notify [%s]", name_owner); if (NULL == name_owner) - _close_gdbus_call(handle); + _close_gdbus_call( ); g_free(name_owner); } -static int _create_gdbus_call(agent_handle_h handle) +static int _create_gdbus_call() { int id; GError *error = NULL; - struct agent_handle *h = handle; - if (NULL == h) - return FN_ERROR_INVALID_PARAMETER; - - if (h->dbus_connection != NULL) + if (agent.dbus_connection != NULL) return FN_ERROR_ALREADY_IN_PROGRESS; - h->dbus_connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); - if (NULL == h->dbus_connection) { + agent.dbus_connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); + if (NULL == agent.dbus_connection) { if (error != NULL) { LOG_ERR("Failed to connect to the D-BUS daemon [%s]", error->message); g_error_free(error); @@ -96,34 +137,28 @@ static int _create_gdbus_call(agent_handle_h handle) return FN_ERROR_IO_ERROR; } - id = g_signal_connect(h->dbus_connection, "notify::g-name-owner", - G_CALLBACK(_dbus_name_owner_notify), h); + id = g_signal_connect(agent.dbus_connection, "notify::g-name-owner", + G_CALLBACK(_dbus_name_owner_notify), &agent); if (0 == id) { LOGE("g_signal_connect() Fail"); - g_object_unref(h->dbus_connection); - h->dbus_connection = NULL; + g_object_unref(agent.dbus_connection); + agent.dbus_connection = NULL; return FN_ERROR_IO_ERROR; } return FN_ERROR_NONE; } -static GDBusProxy *_get_proxy_service(agent_handle_h handle) +static GDBusProxy *_get_proxy_service() { GDBusProxy *proxy = NULL; - struct agent_handle *h = handle; - - if (NULL == h) { - LOG_ERR("Agenet Handle is NULL"); - return NULL; - } - if (NULL == h->gproxy_agent_service) { - proxy = g_dbus_proxy_new_sync(h->dbus_connection, G_DBUS_PROXY_FLAGS_NONE, NULL, + if (NULL == agent.gproxy_agent_service) { + proxy = g_dbus_proxy_new_sync(agent.dbus_connection, G_DBUS_PROXY_FLAGS_NONE, NULL, AGENT_SERVER_NAME, AGENT_OBJECT_PATH, AGENT_SERVICE_INTERFACE, NULL, NULL); } else - proxy = h->gproxy_agent_service; + proxy = agent.gproxy_agent_service; return proxy; } @@ -132,7 +167,7 @@ static void _agent_signal_handler(GDBusConnection *connection, const gchar *sender_name, const gchar *object_path, const gchar *interface_name, const gchar *signal_name, GVariant *parameters, gpointer userdata) { - struct agent_handle *h = userdata; + struct agent_s *h = userdata; if (NULL == h) { LOG_ERR("user_data is null"); @@ -147,13 +182,10 @@ static void _agent_signal_handler(GDBusConnection *connection, LOG_DEBUG("Result : %d", result); } } -static int _subscribe_event(agent_handle_h handle) +static int _subscribe_event() { unsigned int id; - struct agent_handle *h = handle; - - if (NULL == h) - return FN_ERROR_INVALID_PARAMETER; + struct agent_s *h = &agent; /* subowner_enabled */ id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, AGENT_SERVER_NAME, @@ -227,7 +259,7 @@ static int _subscribe_event(agent_handle_h handle) static void _on_unsubscribe_ids(gpointer data, gpointer userdata) { unsigned int id = GPOINTER_TO_UINT(data); - struct agent_handle *h = (struct agent_handle*)userdata; + struct agent_s *h = (struct agent_s*)userdata; if (NULL == h) { LOG_ERR("Invaild parameter"); return; @@ -235,68 +267,56 @@ static void _on_unsubscribe_ids(gpointer data, gpointer userdata) LOG_DEBUG("[Signal unsubscribe] : %d", id); g_dbus_connection_signal_unsubscribe(h->dbus_connection, id); } -static void _unsubscribe_event(agent_handle_h handle) +static void _unsubscribe_event() { - struct agent_handle *h = handle; - if (NULL == h) { - LOG_ERR("Invaild parameter"); - } - g_list_foreach(h->dbus_sub_ids, _on_unsubscribe_ids, h); - g_list_free(h->dbus_sub_ids); - h->dbus_sub_ids = NULL; + g_list_foreach(agent.dbus_sub_ids, _on_unsubscribe_ids, &agent); + g_list_free(agent.dbus_sub_ids); + agent.dbus_sub_ids = NULL; } -int agent_dbus_start(agent_handle_h handle) +int agent_dbus_start( ) { int ret = FN_ERROR_NONE; - struct agent_handle *h = handle; - - if (NULL == h) - return FN_ERROR_INVALID_PARAMETER; - ret = _create_gdbus_call(handle); + ret = _create_gdbus_call(); if (FN_ERROR_NONE != ret) return ret; - h->ca = g_cancellable_new(); + agent.ca = g_cancellable_new(); /* Create all proxies here */ - h->gproxy_agent_service = _get_proxy_service(h); - if (NULL == h->gproxy_agent_service) { + agent.gproxy_agent_service = _get_proxy_service(); + if (NULL == agent.gproxy_agent_service) { LOG_ERR("Couldn't get _get_proxy_service"); return FN_ERROR_IO_ERROR; } g_dbus_proxy_set_default_timeout( - G_DBUS_PROXY(h->gproxy_agent_service), AGENT_DBUS_PROXY_TIMEOUT); + G_DBUS_PROXY(agent.gproxy_agent_service), AGENT_DBUS_PROXY_TIMEOUT); /* Subscribe events */ - _subscribe_event(h); + _subscribe_event(); return FN_ERROR_NONE; } -int agent_dbus_stop(agent_handle_h handle) +int agent_dbus_stop() { int ret = FN_ERROR_NONE; - struct agent_handle *h = handle; - - if (NULL == h) - return FN_ERROR_INVALID_PARAMETER; - _unsubscribe_event(h); + _unsubscribe_event(); /* Unref all proxies here */ - if (h->gproxy_agent_service) { - g_object_unref(h->gproxy_agent_service); - h->gproxy_agent_service = NULL; + if (agent.gproxy_agent_service) { + g_object_unref(agent.gproxy_agent_service); + agent.gproxy_agent_service = NULL; } - g_cancellable_cancel(h->ca); - g_object_unref(h->ca); - h->ca = NULL; + g_cancellable_cancel(agent.ca); + g_object_unref(agent.ca); + agent.ca = NULL; - ret = _close_gdbus_call(h); + ret = _close_gdbus_call(); return ret; } diff --git a/src/fn-manager/src/fn_manager.c b/src/fn-manager/src/fn_manager.c index 4024488..ddccfdb 100644 --- a/src/fn-manager/src/fn_manager.c +++ b/src/fn-manager/src/fn_manager.c @@ -1,4 +1,5 @@ #include +#include int main(int argc, char *argv[]) { @@ -38,6 +39,12 @@ int main(int argc, char *argv[]) } //7. operation mgr initialize + ret = agent_dbus_start(); + if (ret != FN_ERROR_NONE) { + LOG_ERR("MOT agent interface initialize failed : %s", fn_log_get_error_string(ret)); + goto EXIT; + } + agent_enable(); //8. g main loop run fn_context_t *fn_ctx = fn_context_get_context(); @@ -46,6 +53,11 @@ int main(int argc, char *argv[]) EXIT: //9. deinitialize phase + agent_disable(); + ret = agent_dbus_stop(); + if (ret != FN_ERROR_NONE) + LOG_ERR("MOT agent interface deinitialize failed : %s", fn_log_get_error_string(ret)); + ret = fn_group_deinitialize(); if (ret != FN_ERROR_NONE) LOG_ERR("FN group deinitialize failed : %s", fn_log_get_error_string(ret));