char *key;
} mc_ipc_listener_s;
-/* This checks if service daemon is running */
-static int __make_service_connection(mc_priv_type_e priv_type)
-{
- int ret = MEDIA_CONTROLLER_ERROR_NONE;
- char *app_id = NULL;
-
- ret = _mc_util_get_own_name(&app_id);
- mc_retvm_if(ret != MEDIA_CONTROLLER_ERROR_NONE, ret, "Failed to _mc_util_get_own_name[%d]", ret);
-
- ret = _mc_ipc_send_message_to_server(MC_MSG_SERVER_CONNECTION, priv_type, app_id);
-
- MC_SAFE_FREE(app_id);
-
- return ret;
-}
-
static char *__make_key_for_map(const char *main_key, const char *sub_key)
{
mc_retvm_if(!main_key, NULL, "Invalid main_key");
return g_strdup_printf("%s.%s", main_key, sub_key);
}
-static gint __find_listener_by_key(gconstpointer data, gconstpointer user_data)
+static gint __find_dbus_listener_by_key(gconstpointer data, gconstpointer user_data)
{
mc_ipc_listener_s *listener = (mc_ipc_listener_s *)data;
char *key = (char *)user_data;
return (!listener || g_strcmp0(listener->key, key)) ? 1 : 0;
}
-static void __mc_ipc_signal_cb(GDBusConnection *connection,
+static void __dbus_signal_cb(GDBusConnection *connection,
const gchar *sender_name,
const gchar *object_path,
const gchar *interface_name,
request_id = NULL;
key = __make_key_for_map(interface_name, signal_name);
- found_item = g_list_find_custom(*listener_list, key, __find_listener_by_key);
+ found_item = g_list_find_custom(*listener_list, key, __find_dbus_listener_by_key);
if (found_item && found_item->data) {
listener = found_item->data;
mc_secure_debug("Received : [%s] (req_id = %s) from %s.%s", message, request_id, interface_name, signal_name);
MC_SAFE_FREE(key);
}
-static void __mc_destroy_listener(gpointer data)
+static void __free_dbus_listener(gpointer data)
{
mc_ipc_listener_s *listener = (mc_ipc_listener_s *)data;
if (!listener)
MC_SAFE_FREE(listener);
}
-static gboolean _mc_ipc_is_listener_duplicated(GList *listener_list, const char *key)
+static gboolean __is_duplicated_dbus_listener(GList *listener_list, const char *key)
{
GList *found_item = NULL;
mc_retvm_if(!MC_STRING_VALID(key), TRUE, "Invalid Key");
- found_item = g_list_find_custom(listener_list, key, __find_listener_by_key);
+ found_item = g_list_find_custom(listener_list, key, __find_dbus_listener_by_key);
mc_retvm_if(found_item, TRUE, "listener[%s] is duplicated ", key);
return FALSE;
}
+static int __dbus_send_message(GDBusConnection *connection, const char *dbus_name, const char *interface_name, const char *signal_name, const char *message, const char *request_id)
+{
+ GError *error = NULL;
+ gboolean emmiting = TRUE;
+
+ mc_retvm_if(connection == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "connection is NULL");
+ mc_retvm_if(!MC_STRING_VALID(signal_name), MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid signal_name");
+ mc_retvm_if(!MC_STRING_VALID(message), MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid message");
+
+ mc_secure_debug("emit signal - interface_name [%s], signal_name [%s]", interface_name, signal_name);
+
+ emmiting = g_dbus_connection_emit_signal(
+ connection,
+ dbus_name,
+ MC_DBUS_PATH,
+ interface_name,
+ signal_name,
+ g_variant_new("(ss)", request_id, message),
+ &error);
+ if (!emmiting) {
+ mc_error("g_dbus_connection_emit_signal failed : %s", error ? error->message : "none");
+ if (error)
+ g_error_free(error);
+ return MEDIA_CONTROLLER_ERROR_INVALID_OPERATION;
+ }
+
+ return MEDIA_CONTROLLER_ERROR_NONE;
+}
+
int _mc_ipc_get_dbus_connection(GDBusConnection **connection, int *dref_count)
{
GError *error = NULL;
key = __make_key_for_map(interface_name, signal_name);
mc_retvm_if(key == NULL, MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "fail to get key");
- if (_mc_ipc_is_listener_duplicated(*listener_list, key)) {
+ if (__is_duplicated_dbus_listener(*listener_list, key)) {
mc_error("listener is duplicated");
MC_SAFE_G_FREE(key);
return MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER;
}
- mc_ipc_listener_s *listener = (mc_ipc_listener_s *)calloc(1, sizeof(__dbus_listener_s));
+ mc_ipc_listener_s *listener = (mc_ipc_listener_s *)calloc(1, sizeof(mc_ipc_listener_s));
if (listener == NULL) {
mc_error("Error memroy allocation");
MC_SAFE_G_FREE(key);
MC_DBUS_PATH,
NULL,
G_DBUS_SIGNAL_FLAGS_NONE,
- (GDBusSignalCallback)__mc_ipc_signal_cb,
+ (GDBusSignalCallback)__dbus_signal_cb,
(gpointer)listener_list,
NULL);
key = __make_key_for_map(interface_name, signal_name);
mc_retvm_if(!key, MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "fail to get key");
- found_item = g_list_find_custom(*listener_list, (gconstpointer)key, __find_listener_by_key);
+ found_item = g_list_find_custom(*listener_list, (gconstpointer)key, __find_dbus_listener_by_key);
if (found_item) {
(*listener_list) = g_list_remove_link(*listener_list, found_item);
- __mc_destroy_listener(found_item->data);
+ __free_dbus_listener(found_item->data);
g_list_free(found_item);
}
{
mc_retvm_if(listener_list == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "listener_list is NULL");
- g_list_free_full(*listener_list, __mc_destroy_listener);
+ g_list_free_full(*listener_list, __free_dbus_listener);
*listener_list = NULL;
return MEDIA_CONTROLLER_ERROR_NONE;
return MEDIA_CONTROLLER_ERROR_NONE;
}
-static int __send_message(GDBusConnection *connection, const char *dbus_name, const char *interface_name, const char *signal_name, const char *message, const char *request_id)
-{
- GError *error = NULL;
-
- mc_retvm_if(connection == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "connection is NULL");
- mc_retvm_if(!MC_STRING_VALID(signal_name), MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid signal_name");
- mc_retvm_if(!MC_STRING_VALID(message), MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid message");
-
- mc_secure_debug("emit signal - interface_name [%s], signal_name [%s]", interface_name, signal_name);
-
- gboolean emmiting = g_dbus_connection_emit_signal(
- connection,
- dbus_name,
- MC_DBUS_PATH,
- interface_name,
- signal_name,
- g_variant_new("(ss)", request_id, message),
- &error);
- if (!emmiting) {
- mc_error("g_dbus_connection_emit_signal failed : %s", error ? error->message : "none");
- if (error) {
- mc_error("Error in g_dbus_connection_emit_signal");
- g_error_free(error);
- }
- return MEDIA_CONTROLLER_ERROR_INVALID_OPERATION;
- }
-
- return MEDIA_CONTROLLER_ERROR_NONE;
-}
-
int _mc_ipc_send_message(GDBusConnection *connection, const char *dbus_name, const char *interface_name, const char *signal_name, const char *message, char **request_id)
{
const char *req_id = DEFAULT_REQ_ID;
mc_secure_debug("req_id[%s]", req_id);
}
- return __send_message(connection, dbus_name, interface_name, signal_name, message, req_id);
+ return __dbus_send_message(connection, dbus_name, interface_name, signal_name, message, req_id);
}
int _mc_ipc_send_reply(GDBusConnection *connection, const char *dbus_name, const char *interface_name, const char *signal_name, const char *message, const char *request_id)
{
- return __send_message(connection, dbus_name, interface_name, signal_name, message, request_id);
+ return __dbus_send_message(connection, dbus_name, interface_name, signal_name, message, request_id);
+}
+
+/* This checks if service daemon is running */
+static int __make_service_connection(mc_priv_type_e priv_type)
+{
+ int ret = MEDIA_CONTROLLER_ERROR_NONE;
+ char *app_id = NULL;
+
+ ret = _mc_util_get_own_name(&app_id);
+ mc_retvm_if(ret != MEDIA_CONTROLLER_ERROR_NONE, ret, "Failed to _mc_util_get_own_name[%d]", ret);
+
+ ret = _mc_ipc_send_message_to_server(MC_MSG_SERVER_CONNECTION, priv_type, app_id);
+
+ MC_SAFE_FREE(app_id);
+
+ return ret;
}
int _mc_ipc_send_message_to_server(mc_msg_type_e msg_type, mc_priv_type_e priv_type, const char *request_msg)