From: hj kim Date: Fri, 31 Jan 2020 01:58:53 +0000 (+0900) Subject: Unify duplicated code regarding launching miracast server X-Git-Tag: submit/tizen/20200205.015006~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=62c1d39a042f78615feeef1027051e59ad3f9ab3;p=platform%2Fcore%2Fapi%2Fscreen-mirroring.git Unify duplicated code regarding launching miracast server Change-Id: Id32724e44ef64a04b356c48d0e4ffb7924c7ee43 --- diff --git a/include/scmirroring_private.h b/include/scmirroring_private.h index af9f8b5..1c39331 100644 --- a/include/scmirroring_private.h +++ b/include/scmirroring_private.h @@ -300,6 +300,7 @@ int _scmirroring_src_send_set_multisink(int sock, scmirroring_multisink_e multis int _scmirroring_src_send_set_coupling_mode(int sock, scmirroring_coupling_mode_e coupling_mode); int _scmirroring_src_send_set_direct_streaming(int sock, scmirroring_direct_streaming_e direct_streaming, const char *filesrc); int _scmirroring_src_send_switch_transport(int sock, scmirroring_av_transport_e av_transport); +int _scmirroring_server_launch(const char *server_name); #ifdef __cplusplus diff --git a/src/scmirroring_primary_sink.c b/src/scmirroring_primary_sink.c index 5b0f3fe..fc01989 100644 --- a/src/scmirroring_primary_sink.c +++ b/src/scmirroring_primary_sink.c @@ -14,7 +14,7 @@ * limitations under the License. */ #include -#include +#include #include #include #include @@ -430,80 +430,6 @@ static gboolean __scmirroring_primary_src_callback_call(gpointer data) return FALSE; } -static int __miracast_server_launch(scmirroring_primary_sink_s *scmirroring) -{ - int ret = SCMIRRORING_ERROR_NONE; - GDBusProxy *proxy = NULL; - GVariant *reg = NULL; - GDBusConnection *conn = NULL; - GError *error = NULL; - -#if !GLIB_CHECK_VERSION(2, 35, 0) - g_type_init(); -#endif - - scmirroring_debug("-----------socket connect failed it means server is not yet started------------"); - scmirroring_debug("going to start miracast server"); - - conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); - if (error) { - scmirroring_error("Failed to get dbus connection: %s", error->message); - g_error_free(error); - return SCMIRRORING_ERROR_INVALID_OPERATION; - } - - gchar *name = NULL; - gchar *if_name = NULL; - gchar *obj_path = NULL; - - if (scmirroring->server_name) { - name = g_strdup_printf("org.tizen.%s.server", scmirroring->server_name); - if_name = g_strdup_printf("org.tizen.%s.server", scmirroring->server_name); - obj_path = g_strdup_printf("/org/tizen/%s/server", scmirroring->server_name); - } else { - name = g_strdup("org.tizen.scmirroring.server"); - if_name = g_strdup("org.tizen.scmirroring.server"); - obj_path = g_strdup("/org/tizen/scmirroring/server"); - } - - scmirroring_debug("Server Name : %s", name); - - proxy = g_dbus_proxy_new_sync(conn, - G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS, - NULL, - name, - obj_path, - if_name, - NULL, - &error); - g_free(name); - g_free(if_name); - g_free(obj_path); - g_object_unref(conn); - if (proxy == NULL) { - scmirroring_error("g_dbus_proxy_new_sync failed : %s", error->message); - g_error_free(error); - return SCMIRRORING_ERROR_INVALID_OPERATION; - } - - reg = g_dbus_proxy_call_sync(proxy, "launch_method", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); - g_object_unref(proxy); - - if (reg) { - g_variant_unref(reg); - reg = NULL; - } - if (error) { - scmirroring_error("g_dbus_proxy_call_sync failed : %s", error->message); - g_error_free(error); - return SCMIRRORING_ERROR_INVALID_OPERATION; - } - - scmirroring_debug("Miracast server is launched successfully"); - - return ret; -} - /* * Application - miracast server message * 1. Response Message from miracast server @@ -920,10 +846,10 @@ try: if (connect(_scmirroring->sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) { /* Once failed to connect, try to launch miracast server */ if (retry == 0) { - ret = __miracast_server_launch(_scmirroring); + ret = _scmirroring_server_launch(_scmirroring->server_name); if (ret != SCMIRRORING_ERROR_NONE) { SCMIRRORING_SAFE_G_FREE(_scmirroring->sock_path); - scmirroring_error("__miracast_server_launch error : %d", ret); + scmirroring_error("_scmirroring_server_launch error : %d", ret); return ret; } retry++; diff --git a/src/scmirroring_src.c b/src/scmirroring_src.c index dc3e5ff..803f8e1 100644 --- a/src/scmirroring_src.c +++ b/src/scmirroring_src.c @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include #include #include #include @@ -68,80 +68,6 @@ static gboolean __scmirroring_src_callback_call(gpointer data) return FALSE; } -static int __miracast_server_launch(scmirroring_src_s *scmirroring) -{ - int ret = SCMIRRORING_ERROR_NONE; - GDBusProxy *proxy = NULL; - GVariant *reg = NULL; - GDBusConnection *conn = NULL; - GError *error = NULL; - -#if !GLIB_CHECK_VERSION(2, 35, 0) - g_type_init(); -#endif - - scmirroring_debug("-----------socket connect failed it means server is not yet started------------"); - scmirroring_debug("going to start miracast server"); - - conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); - if (error) { - scmirroring_error("Failed to get dbus connection: %s", error->message); - g_error_free(error); - return SCMIRRORING_ERROR_INVALID_OPERATION; - } - - gchar *name = NULL; - gchar *if_name = NULL; - gchar *obj_path = NULL; - - if (scmirroring->server_name) { - name = g_strdup_printf("org.tizen.%s.server", scmirroring->server_name); - if_name = g_strdup_printf("org.tizen.%s.server", scmirroring->server_name); - obj_path = g_strdup_printf("/org/tizen/%s/server", scmirroring->server_name); - } else { - name = g_strdup("org.tizen.scmirroring.server"); - if_name = g_strdup("org.tizen.scmirroring.server"); - obj_path = g_strdup("/org/tizen/scmirroring/server"); - } - - scmirroring_debug("Server Name : %s", name); - - proxy = g_dbus_proxy_new_sync(conn, - G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS, - NULL, - name, - obj_path, - if_name, - NULL, - &error); - g_free(name); - g_free(if_name); - g_free(obj_path); - g_object_unref(conn); - if (proxy == NULL) { - scmirroring_error("g_dbus_proxy_new_sync failed : %s", error->message); - g_error_free(error); - return SCMIRRORING_ERROR_INVALID_OPERATION; - } - - reg = g_dbus_proxy_call_sync(proxy, "launch_method", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); - g_object_unref(proxy); - - if (reg) { - g_variant_unref(reg); - reg = NULL; - } - if (error) { - scmirroring_error("g_dbus_proxy_call_sync failed : %s", error->message); - g_error_free(error); - return SCMIRRORING_ERROR_INVALID_OPERATION; - } - - scmirroring_debug("Miracast server is launched successfully"); - - return ret; -} - /* * Application - miracast server message * 1. Response Message from miracast server @@ -570,10 +496,10 @@ try: if (connect(_scmirroring->sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) { /* Once failed to connect, try to launch miracast server */ if (retry == 0) { - ret = __miracast_server_launch(_scmirroring); + ret = _scmirroring_server_launch(_scmirroring->server_name); if (ret != SCMIRRORING_ERROR_NONE) { SCMIRRORING_SAFE_G_FREE(_scmirroring->sock_path); - scmirroring_error("__miracast_server_launch error : %d", ret); + scmirroring_error("_scmirroring_server_launch error : %d", ret); return ret; } retry++; diff --git a/src/scmirroring_util.c b/src/scmirroring_util.c index 91aa36f..1a5a8cc 100644 --- a/src/scmirroring_util.c +++ b/src/scmirroring_util.c @@ -16,6 +16,7 @@ #include #include +#include #include scmirroring_error_e _scmirroring_error_convert(const char *func, int error) @@ -501,3 +502,78 @@ int _scmirroring_src_send_switch_transport(int sock, scmirroring_av_transport_e return ret; } + +int _scmirroring_server_launch(const char *server_name) +{ + int ret = SCMIRRORING_ERROR_NONE; + GDBusProxy *proxy = NULL; + GVariant *reg = NULL; + GDBusConnection *conn = NULL; + GError *error = NULL; + +#if !GLIB_CHECK_VERSION(2, 35, 0) + g_type_init(); +#endif + + scmirroring_debug("-----------socket connect failed it means server is not yet started------------"); + scmirroring_debug("going to start miracast server"); + + conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); + if (error) { + scmirroring_error("Failed to get dbus connection: %s", error->message); + g_error_free(error); + return SCMIRRORING_ERROR_INVALID_OPERATION; + } + + gchar *name = NULL; + gchar *if_name = NULL; + gchar *obj_path = NULL; + + if (server_name) { + name = g_strdup_printf("org.tizen.%s.server", server_name); + if_name = g_strdup_printf("org.tizen.%s.server", server_name); + obj_path = g_strdup_printf("/org/tizen/%s/server", server_name); + } else { + name = g_strdup("org.tizen.scmirroring.server"); + if_name = g_strdup("org.tizen.scmirroring.server"); + obj_path = g_strdup("/org/tizen/scmirroring/server"); + } + + scmirroring_debug("Server Name : %s", name); + + proxy = g_dbus_proxy_new_sync(conn, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS, + NULL, + name, + obj_path, + if_name, + NULL, + &error); + g_free(name); + g_free(if_name); + g_free(obj_path); + g_object_unref(conn); + if (proxy == NULL) { + scmirroring_error("g_dbus_proxy_new_sync failed : %s", error->message); + g_error_free(error); + return SCMIRRORING_ERROR_INVALID_OPERATION; + } + + reg = g_dbus_proxy_call_sync(proxy, "launch_method", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); + g_object_unref(proxy); + + if (reg) { + g_variant_unref(reg); + reg = NULL; + } + if (error) { + scmirroring_error("g_dbus_proxy_call_sync failed : %s", error->message); + g_error_free(error); + return SCMIRRORING_ERROR_INVALID_OPERATION; + } + + scmirroring_debug("Miracast server is launched successfully"); + + return ret; +} +