#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;
}
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);
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;
}
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");
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,
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;
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;
}