Rename and relocate the functions for dbus & socket IPC 69/227269/3 accepted/tizen/unified/20200315.214713 submit/tizen/20200313.030919
authorjiyong.min <jiyong.min@samsung.com>
Wed, 11 Mar 2020 04:50:47 +0000 (13:50 +0900)
committerjiyong.min <jiyong.min@samsung.com>
Thu, 12 Mar 2020 00:40:21 +0000 (09:40 +0900)
  - dbus IPC functions
    all functions except socket IPC functions

  - socket IPC functions
    __make_service_connection
    _mc_ipc_send_message_to_server
    _mc_ipc_service_connection

Change-Id: I7cf1ccb706fa1151a0da963ca338304ff3935451

src/media_controller_ipc.c

index c4fe3e1..945a119 100644 (file)
@@ -32,22 +32,6 @@ typedef struct {
        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");
@@ -56,7 +40,7 @@ static char *__make_key_for_map(const char *main_key, const char *sub_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;
@@ -64,7 +48,7 @@ static gint __find_listener_by_key(gconstpointer data, gconstpointer 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,
@@ -90,7 +74,7 @@ static void __mc_ipc_signal_cb(GDBusConnection *connection,
                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);
@@ -102,7 +86,7 @@ static void __mc_ipc_signal_cb(GDBusConnection *connection,
        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)
@@ -113,18 +97,47 @@ static void __mc_destroy_listener(gpointer data)
        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;
@@ -184,14 +197,14 @@ int _mc_ipc_register_listener(GList **listener_list, GDBusConnection *connection
        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);
@@ -210,7 +223,7 @@ int _mc_ipc_register_listener(GList **listener_list, GDBusConnection *connection
                                MC_DBUS_PATH,
                                NULL,
                                G_DBUS_SIGNAL_FLAGS_NONE,
-                               (GDBusSignalCallback)__mc_ipc_signal_cb,
+                               (GDBusSignalCallback)__dbus_signal_cb,
                                (gpointer)listener_list,
                                NULL);
 
@@ -240,10 +253,10 @@ int _mc_ipc_unregister_listener(GList **listener_list, const char *interface_nam
        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);
        }
 
@@ -258,7 +271,7 @@ int _mc_ipc_unregister_all_listener(GList **listener_list)
 {
        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;
@@ -283,36 +296,6 @@ int _mc_ipc_unregister_filter_listener(GList **listener_list, const char *server
        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;
@@ -324,12 +307,28 @@ int _mc_ipc_send_message(GDBusConnection *connection, const char *dbus_name, con
                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)