From a02249fad9bea7d0a6a71153a21894999d35a83f Mon Sep 17 00:00:00 2001 From: "jiyong.min" Date: Wed, 30 Jan 2019 11:05:59 +0900 Subject: [PATCH] Add to notify the updated server_name and server_states to clients Change-Id: I4200d24402c3797ddd252e5d7175208d55ac76ab --- svc/media_controller_svc.c | 58 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 3 deletions(-) diff --git a/svc/media_controller_svc.c b/svc/media_controller_svc.c index 2810ff5..0226dde 100644 --- a/svc/media_controller_svc.c +++ b/svc/media_controller_svc.c @@ -445,6 +445,54 @@ static int _mc_service_get_data(GList **connected_list, mc_comm_msg_s *request_m } } +static int __mc_notify_server_updated(const char *server_name, mc_server_state_e state) +{ + char *message = NULL; + GDBusConnection *bus = NULL; + GError *error = NULL; + gboolean emmiting = FALSE; + + mc_secure_error("[No-error] __mc_notify_server_updated [%s:%d]", server_name, state); + + mc_retvm_if(server_name == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "server_name is null!"); + + bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); + if (!bus) { + mc_secure_error("Failed to get gdbus connection : %s", error ? error->message : "none"); + g_error_free(error); + return MEDIA_CONTROLLER_ERROR_INVALID_OPERATION; + } + + message = g_strdup_printf("%s%s%d", server_name, MC_STRING_DELIMITER, state); + if (message == NULL) { + mc_secure_error("Error in message generation"); + g_object_unref(bus); + return MEDIA_CONTROLLER_ERROR_OUT_OF_MEMORY; + } + + /* Send the signal */ + emmiting = g_dbus_connection_emit_signal( + bus, + NULL, + MC_DBUS_PATH, + MC_DBUS_UPDATE_INTERFACE, + MC_DBUS_SIGNAL_NAME_SERVER_STATE, + g_variant_new("(ss)", (const gchar *)"DEF_REQ_ID", message), + &error); + if (!emmiting) { + mc_secure_error("Failed to emit gdbus signal : %s", error ? error->message : "none"); + g_error_free(error); + g_object_unref(bus); + MC_SAFE_G_FREE(message); + return MEDIA_CONTROLLER_ERROR_INVALID_OPERATION; + } + + g_object_unref(bus); + MC_SAFE_G_FREE(message); + + return MEDIA_CONTROLLER_ERROR_NONE; +} + static int _mc_service_app_dead_handler(int pid, void *data) { mc_service_t *_service_data = (mc_service_t *)data; @@ -466,9 +514,13 @@ static int _mc_service_app_dead_handler(int pid, void *data) if (app_data->pid == pid) { mc_secure_debug("app_dead(appid) : %s", app_data->app_id); - /* TODO: Delete application from database and - * send notifiaction to deactivation message via dbus - */ + /* TODO: Delete application from database */ + + /* Sends notification for deactivated server via dbus */ + if (app_data->priv_type == MC_PRIV_TYPE_SERVER) { + if (MEDIA_CONTROLLER_ERROR_NONE != __mc_notify_server_updated(app_data->app_id, MC_SERVER_STATE_DEACTIVATE)) + mc_secure_error("Fail to notify deactivated server"); + } if (MEDIA_CONTROLLER_ERROR_NONE == __mc_list_remove_item(&_service_data->connected, i)) { g_connection_cnt--; -- 2.7.4