Move load wpa_supplicant plugin function to utils 49/164949/1 submit/tizen/20171228.053515
authorJiung <jiung.yu@samsung.com>
Fri, 22 Dec 2017 03:01:41 +0000 (12:01 +0900)
committerJiung <jiung.yu@samsung.com>
Fri, 22 Dec 2017 03:01:52 +0000 (12:01 +0900)
Change-Id: Ib9465da56df3961d4c9f4684312c8fb73d5f50b3
Signed-off-by: Yu jiung <jiung.yu@samsung.com>
include/wifi-direct-util.h
packaging/wifi-direct-manager.spec
src/wifi-direct-dbus.c
src/wifi-direct-main.c
src/wifi-direct-manager.c
src/wifi-direct-util.c

index 50a4f4a..2269900 100644 (file)
@@ -53,6 +53,12 @@ extern "C" {
 #if !(__GNUC__ <= 4 && __GNUC_MINOR__ < 8)
 int wfd_util_get_current_time(unsigned long *cur_time);
 #endif
+
+void *wfd_util_plugin_init(wfd_manager_s *manager);
+int wfd_util_plugin_deinit(wfd_manager_s *manager);
+void *wfd_util_prd_plugin_init(wfd_manager_s *manager);
+int wfd_util_prd_plugin_deinit(wfd_manager_s *manager);
+
 gboolean wfd_util_execute_file(const char *file_path,  char *const args[], char *const envs[]);
 int wfd_util_freq_to_channel(int freq);
 int wfd_util_channel_to_freq(int channel);
index ab286ad..b7fd10c 100644 (file)
@@ -6,7 +6,7 @@
 
 Name:          wifi-direct-manager
 Summary:       Wi-Fi Direct manger
-Version:       1.2.260
+Version:       1.2.261
 Release:       1
 Group:      Network & Connectivity/Wireless
 License:    Apache-2.0
@@ -26,12 +26,17 @@ BuildRequires:  pkgconfig(capi-system-info)
 BuildRequires: pkgconfig(capi-appfw-application)
 BuildRequires:  pkgconfig(libsystemd-login)
 BuildRequires:  pkgconfig(libtzplatform-config)
+%if 0%{?gtests:1}
+BuildRequires: pkgconfig(gmock)
+%endif
 BuildRequires: cmake
 
 Requires:      net-tools
 
 Requires: toybox-symlinks-dhcpd
 Requires: toybox-symlinks-dhcp
+Requires(post): /sbin/ldconfig
+Requires(postun): /sbin/ldconfig
 
 %description
 Manager for handling wifi-direct functionalities
@@ -113,6 +118,12 @@ cp -a %{SOURCE3} .
 export CFLAGS="$CFLAGS -DTIZEN_DEBUG_ENABLE"
 export CXXFLAGS="$CXXFLAGS -DTIZEN_DEBUG_ENABLE"
 export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE"
+%if 0%{?gcov:1}
+export CFLAGS+=" -fprofile-arcs -ftest-coverage"
+export CXXFLAGS+=" -fprofile-arcs -ftest-coverage"
+export FFLAGS+=" -fprofile-arcs -ftest-coverage"
+export LDFLAGS+=" -lgcov"
+%endif
 
 %ifarch %{arm}
 export ARCH=arm
@@ -126,7 +137,7 @@ export ARCH=i586
 
 %endif
 
-cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DARCHITECTURE=$ARCH \
+%cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DARCHITECTURE=$ARCH \
 %if ! 0%{?model_build_feature_network_tethering_disable}
        -DTIZEN_TETHERING_ENABLE=0 \
 %endif
@@ -140,7 +151,9 @@ cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DARCHITECTURE=$ARCH \
        -DTZ_SYS_RO_ETC=%{TZ_SYS_RO_ETC} \
        -DTZ_SYS_VAR=%{TZ_SYS_VAR} \
        -DTZ_SYS_ETC=%{TZ_SYS_ETC} \
-       -DTZ_SYS_RUN=%{TZ_SYS_RUN}
+       -DTZ_SYS_RUN=%{TZ_SYS_RUN} \
+       -DBUILD_GTESTS=%{?gtests:1}%{!?gtests:0} \
+       -DBUILD_GCOV=%{?gcov:1}%{!?gcov:0}
 
 make %{?_smp_mflags}
 
@@ -260,6 +273,9 @@ mv -f %{_sysconfdir}/wifi-direct/wifi-direct-manager.conf.tv %{_sysconfdir}/wifi
 %endif
 %attr(755,-,-) %{_sbindir}/p2p_supp.sh
 %attr(755,-,-) %{_bindir}/wfd-manager
+%if 0%{?gtests:1}
+       %{_bindir}/gtest*
+%endif
 
 %files -n wifi-direct-plugin-wpasupplicant
 %manifest wifi-direct-plugin-wpasupplicant.manifest
index d7a869c..aa69958 100644 (file)
@@ -827,7 +827,6 @@ gboolean wfd_manager_dbus_init(void)
                return FALSE;
        }
 
-
        g_owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
                                    WFD_MANAGER_SERVICE,
                                    G_BUS_NAME_OWNER_FLAGS_NONE,
index 67cbbd6..556bbf7 100644 (file)
@@ -25,6 +25,7 @@
  * @version     0.1
  */
 #include <glib.h>
+#include <glib-object.h>
 
 #include <wifi-direct.h>
 
@@ -32,6 +33,8 @@
 #include "wifi-direct-log.h"
 #include "wifi-direct-oem.h"
 #include "wifi-direct-manager.h"
+#include "wifi-direct-dbus.h"
+#include "wifi-direct-util.h"
 
 
 int main(int argc, char *argv[])
@@ -61,6 +64,36 @@ int main(int argc, char *argv[])
                return -1;
        }
 
+       /**
+        * wfd_manager_plugin initialization
+        */
+       manager->plugin_handle = wfd_util_plugin_init(manager);
+       if (!manager->plugin_handle) {
+               WDS_LOGE("Failed to initialize plugin");
+               wfd_manager_unload(manager);
+               __WDS_LOG_FUNC_EXIT__;
+               return -1;
+       }
+       WDS_LOGD("Succeeded to load plugin");
+#if defined TIZEN_ENABLE_PRD
+       /**
+        * wfd_manager_prd_plugin initialization
+        */
+       manager->prd_plugin_handle = wfd_prd_util_plugin_init(manager);
+       if (!manager->prd_plugin_handle)
+               WDS_LOGW("Failed to initialize prd plugin");
+       else
+               WDS_LOGD("Succeeded to load plugin");
+#endif /* TIZEN_ENABLE_PRD */
+
+       if (!wfd_manager_dbus_init()) {
+               WDS_LOGE("Failed to DBus");
+               wfd_util_plugin_deinit(manager);
+               wfd_manager_unload();
+               __WDS_LOG_FUNC_EXIT__;
+               return -1;
+       }
+
        main_loop = g_main_loop_new(NULL, FALSE);
        if (main_loop == NULL) {
                WDS_LOGE("Failed to create GMainLoop structure");
@@ -70,6 +103,17 @@ int main(int argc, char *argv[])
        manager->main_loop = main_loop;
        g_main_loop_run(main_loop);
 
+       wfd_manager_dbus_unregister_nameowner_signal();
+
+       wfd_manager_dbus_unregister();
+       wfd_manager_dbus_deinit();
+
+#if defined TIZEN_ENABLE_PRD
+       wfd_util_prd_plugin_deinit(manager);
+#endif /* TIZEN_ENABLE_PRD */
+
+       wfd_util_plugin_deinit(manager);
+
        wfd_manager_unload();
 
        __WDS_LOG_FUNC_EXIT__;
index 0d9d6ea..fdd1fc7 100644 (file)
@@ -27,8 +27,6 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-#include <dlfcn.h>
-#include <sys/utsname.h>
 #include <time.h>
 #include <errno.h>
 #include <string.h>
@@ -1779,175 +1777,6 @@ int wfd_manager_deinit(wfd_manager_s *manager)
        return 0;
 }
 
-static void *wfd_plugin_init(wfd_manager_s *manager)
-{
-       __WDS_LOG_FUNC_ENTER__;
-       void *handle;
-       struct utsname kernel_info;
-       int res;
-       char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
-
-       if (!manager) {
-               WDS_LOGE("Invalid parameter");
-               __WDS_LOG_FUNC_EXIT__;
-               return NULL;
-       }
-
-       res = uname(&kernel_info);
-       if (res) {
-               WDS_LOGE("Failed to detect target type");
-               __WDS_LOG_FUNC_EXIT__;
-               return NULL;
-       }
-       WDS_LOGD("Node name [%s], HW ID [%s]", kernel_info.nodename, kernel_info.machine);
-
-       errno = 0;
-
-#if defined(TIZEN_ARCH_64)
-       handle = dlopen(SUPPL_PLUGIN_64BIT_PATH, RTLD_NOW);
-#else
-       handle = dlopen(SUPPL_PLUGIN_PATH, RTLD_NOW);
-#endif
-       if (!handle) {
-               WDS_LOGE("Failed to open shared object. [%s]", dlerror());
-               __WDS_LOG_FUNC_EXIT__;
-               return NULL;
-       }
-
-       errno = 0;
-       int (*plugin_load)(wfd_oem_ops_s **ops) = NULL;
-       plugin_load = (int (*)(wfd_oem_ops_s **ops)) dlsym(handle, "wfd_plugin_load");
-       if (!plugin_load) {
-               strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
-               WDS_LOGE("Failed to load symbol. Error = [%s]", error_buf);
-               dlclose(handle);
-               __WDS_LOG_FUNC_EXIT__;
-               return NULL;
-       }
-
-       wfd_oem_ops_s *temp_ops;
-       (*plugin_load)(&temp_ops);
-       manager->oem_ops = temp_ops;
-
-       res = wfd_oem_init(temp_ops);
-       if (res < 0) {
-               WDS_LOGE("Failed to initialize OEM");
-               dlclose(handle);
-               __WDS_LOG_FUNC_EXIT__;
-               return NULL;
-       }
-
-       /* Configure the plugin here,
-        * using config file parameters */
-       res = wfd_oem_configure(manager->oem_ops, manager->wfd_oem_conf);
-       if (res < 0) {
-               WDS_LOGE("Failed to configure OEM");
-               dlclose(handle);
-               __WDS_LOG_FUNC_EXIT__;
-               return NULL;
-       }
-
-       WDS_LOGD("Succeeded to initialize OEM");
-
-       __WDS_LOG_FUNC_EXIT__;
-       return handle;
-}
-
-static int wfd_plugin_deinit(wfd_manager_s *manager)
-{
-       __WDS_LOG_FUNC_ENTER__;
-
-       if (!manager || !manager->plugin_handle) {
-               WDS_LOGE("Invalid parameter");
-               __WDS_LOG_FUNC_EXIT__;
-               return -1;
-       }
-
-       dlclose(manager->plugin_handle);
-       manager->plugin_handle = NULL;
-
-       __WDS_LOG_FUNC_EXIT__;
-       return 0;
-}
-
-#if defined TIZEN_ENABLE_PRD
-static void *wfd_prd_plugin_init(wfd_manager_s *manager)
-{
-       __WDS_LOG_FUNC_ENTER__;
-       void *handle;
-       struct utsname kernel_info;
-       int res;
-
-       if (!manager) {
-               WDS_LOGE("Invalid parameter");
-               __WDS_LOG_FUNC_EXIT__;
-               return NULL;
-       }
-
-       res = uname(&kernel_info);
-       if (res) {
-               WDS_LOGE("Failed to detect target type");
-               __WDS_LOG_FUNC_EXIT__;
-               return NULL;
-       }
-       WDS_LOGD("Node name [%s], HW ID [%s]", kernel_info.nodename, kernel_info.machine);
-
-       errno = 0;
-
-#if defined(TIZEN_ARCH_64)
-       handle = dlopen(SUPPL_PRD_PLUGIN_64BIT_PATH, RTLD_NOW);
-#else
-       handle = dlopen(SUPPL_PRD_PLUGIN_PATH, RTLD_NOW);
-#endif
-       if (!handle) {
-               WDS_LOGE("Failed to open shared object. [%s]", dlerror());
-               __WDS_LOG_FUNC_EXIT__;
-               return NULL;
-       }
-
-       errno = 0;
-       int (*plugin_load)(wfd_oem_ops_s **ops) = NULL;
-       plugin_load = (int (*)(wfd_oem_ops_s **ops)) dlsym(handle, "wfd_prd_plugin_load");
-       if (!plugin_load) {
-               WDS_LOGE("Failed to load symbol. Error = [%s]", strerror(errno));
-               dlclose(handle);
-               __WDS_LOG_FUNC_EXIT__;
-               return NULL;
-       }
-
-       (*plugin_load)((wfd_oem_ops_s **)&manager->oem_ops);
-
-       res = wfd_oem_prd_init((wfd_oem_ops_s *)manager->oem_ops);
-       if (res < 0) {
-               WDS_LOGE("Failed to initialize PRD OEM");
-               dlclose(handle);
-               __WDS_LOG_FUNC_EXIT__;
-               return NULL;
-       }
-       WDS_LOGD("Succeeded to initialize PRD OEM");
-
-       __WDS_LOG_FUNC_EXIT__;
-       return handle;
-}
-
-static int wfd_prd_plugin_deinit(wfd_manager_s *manager)
-{
-       __WDS_LOG_FUNC_ENTER__;
-
-       if (!manager || !manager->prd_plugin_handle) {
-               WDS_LOGE("Invalid parameter");
-               __WDS_LOG_FUNC_EXIT__;
-               return -1;
-       }
-
-       dlclose(manager->prd_plugin_handle);
-       manager->prd_plugin_handle = NULL;
-
-       __WDS_LOG_FUNC_EXIT__;
-       return 0;
-}
-#endif /* TIZEN_ENABLE_PRD */
-
 int wfd_manager_load()
 {
        __WDS_LOG_FUNC_ENTER__;
@@ -1966,18 +1795,6 @@ int wfd_manager_load()
        }
        WDS_LOGD("Succeeded to initialize manager");
 
-       /**
-        * wfd_manager_plugin initialization
-        */
-       g_manager->plugin_handle = wfd_plugin_init(g_manager);
-       if (!g_manager->plugin_handle) {
-               WDS_LOGE("Failed to initialize plugin");
-               wfd_manager_deinit(g_manager);
-               __WDS_LOG_FUNC_EXIT__;
-               return -1;
-       }
-       WDS_LOGD("Succeeded to load plugin");
-
        if (wfd_manager_iface_init() != 0) {
                WDS_LOGE("Failed to initialize iface");
                wfd_manager_deinit(g_manager);
@@ -1985,24 +1802,6 @@ int wfd_manager_load()
                return -1;
        }
        WDS_LOGD("Succeeded to load iface");
-#if defined TIZEN_ENABLE_PRD
-       /**
-        * wfd_manager_prd_plugin initialization
-        */
-       g_manager->prd_plugin_handle = wfd_prd_plugin_init(g_manager);
-       if (!g_manager->prd_plugin_handle)
-               WDS_LOGW("Failed to initialize prd plugin");
-       else
-               WDS_LOGD("Succeeded to load plugin");
-#endif /* TIZEN_ENABLE_PRD */
-
-       if (!wfd_manager_dbus_init()) {
-               WDS_LOGE("Failed to DBus");
-               wfd_plugin_deinit(g_manager);
-               wfd_manager_deinit(g_manager);
-               __WDS_LOG_FUNC_EXIT__;
-               return -1;
-       }
 
        __WDS_LOG_FUNC_EXIT__;
        return 0;
@@ -2010,18 +1809,10 @@ int wfd_manager_load()
 void wfd_manager_unload()
 {
        __WDS_LOG_FUNC_ENTER__;
-       wfd_manager_dbus_unregister_nameowner_signal();
-
-       wfd_manager_dbus_unregister();
-       wfd_manager_dbus_deinit();
-
-#if defined TIZEN_ENABLE_PRD
-       wfd_prd_plugin_deinit(g_manager);
-#endif /* TIZEN_ENABLE_PRD */
 
        wfd_manager_iface_deinit();
-       wfd_plugin_deinit(g_manager);
        wfd_manager_deinit(g_manager);
+
        __WDS_LOG_FUNC_EXIT__;
        return;
 }
index 829b7be..b8541e1 100644 (file)
@@ -39,6 +39,8 @@
 #include <fcntl.h>
 #include <time.h>
 #include <errno.h>
+#include <dlfcn.h>
+#include <sys/utsname.h>
 
 #include <glib.h>
 
@@ -230,6 +232,175 @@ static void __unload_wfd_config(GKeyFile *key_file, struct key_value *conf_key_v
        return;
 }
 
+void *wfd_util_plugin_init(wfd_manager_s *manager)
+{
+       __WDS_LOG_FUNC_ENTER__;
+       void *handle;
+       struct utsname kernel_info;
+       int res;
+       char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
+
+       if (!manager) {
+               WDS_LOGE("Invalid parameter");
+               __WDS_LOG_FUNC_EXIT__;
+               return NULL;
+       }
+
+       res = uname(&kernel_info);
+       if (res) {
+               WDS_LOGE("Failed to detect target type");
+               __WDS_LOG_FUNC_EXIT__;
+               return NULL;
+       }
+       WDS_LOGD("Node name [%s], HW ID [%s]", kernel_info.nodename, kernel_info.machine);
+
+       errno = 0;
+
+#if defined(TIZEN_ARCH_64)
+       handle = dlopen(SUPPL_PLUGIN_64BIT_PATH, RTLD_NOW);
+#else
+       handle = dlopen(SUPPL_PLUGIN_PATH, RTLD_NOW);
+#endif
+       if (!handle) {
+               WDS_LOGE("Failed to open shared object. [%s]", dlerror());
+               __WDS_LOG_FUNC_EXIT__;
+               return NULL;
+       }
+
+       errno = 0;
+       int (*plugin_load)(wfd_oem_ops_s **ops) = NULL;
+       plugin_load = (int (*)(wfd_oem_ops_s **ops)) dlsym(handle, "wfd_plugin_load");
+       if (!plugin_load) {
+               strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
+               WDS_LOGE("Failed to load symbol. Error = [%s]", error_buf);
+               dlclose(handle);
+               __WDS_LOG_FUNC_EXIT__;
+               return NULL;
+       }
+
+       wfd_oem_ops_s *temp_ops;
+       (*plugin_load)(&temp_ops);
+       manager->oem_ops = temp_ops;
+
+       res = wfd_oem_init(temp_ops);
+       if (res < 0) {
+               WDS_LOGE("Failed to initialize OEM");
+               dlclose(handle);
+               __WDS_LOG_FUNC_EXIT__;
+               return NULL;
+       }
+
+       /* Configure the plugin here,
+        * using config file parameters */
+       res = wfd_oem_configure(manager->oem_ops, manager->wfd_oem_conf);
+       if (res < 0) {
+               WDS_LOGE("Failed to configure OEM");
+               dlclose(handle);
+               __WDS_LOG_FUNC_EXIT__;
+               return NULL;
+       }
+
+       WDS_LOGD("Succeeded to initialize OEM");
+
+       __WDS_LOG_FUNC_EXIT__;
+       return handle;
+}
+
+int wfd_util_plugin_deinit(wfd_manager_s *manager)
+{
+       __WDS_LOG_FUNC_ENTER__;
+
+       if (!manager || !manager->plugin_handle) {
+               WDS_LOGE("Invalid parameter");
+               __WDS_LOG_FUNC_EXIT__;
+               return -1;
+       }
+
+       dlclose(manager->plugin_handle);
+       manager->plugin_handle = NULL;
+
+       __WDS_LOG_FUNC_EXIT__;
+       return 0;
+}
+
+#if defined TIZEN_ENABLE_PRD
+void *wfd_util_prd_plugin_init(wfd_manager_s *manager)
+{
+       __WDS_LOG_FUNC_ENTER__;
+       void *handle;
+       struct utsname kernel_info;
+       int res;
+
+       if (!manager) {
+               WDS_LOGE("Invalid parameter");
+               __WDS_LOG_FUNC_EXIT__;
+               return NULL;
+       }
+
+       res = uname(&kernel_info);
+       if (res) {
+               WDS_LOGE("Failed to detect target type");
+               __WDS_LOG_FUNC_EXIT__;
+               return NULL;
+       }
+       WDS_LOGD("Node name [%s], HW ID [%s]", kernel_info.nodename, kernel_info.machine);
+
+       errno = 0;
+
+#if defined(TIZEN_ARCH_64)
+       handle = dlopen(SUPPL_PRD_PLUGIN_64BIT_PATH, RTLD_NOW);
+#else
+       handle = dlopen(SUPPL_PRD_PLUGIN_PATH, RTLD_NOW);
+#endif
+       if (!handle) {
+               WDS_LOGE("Failed to open shared object. [%s]", dlerror());
+               __WDS_LOG_FUNC_EXIT__;
+               return NULL;
+       }
+
+       errno = 0;
+       int (*plugin_load)(wfd_oem_ops_s **ops) = NULL;
+       plugin_load = (int (*)(wfd_oem_ops_s **ops)) dlsym(handle, "wfd_prd_plugin_load");
+       if (!plugin_load) {
+               WDS_LOGE("Failed to load symbol. Error = [%s]", strerror(errno));
+               dlclose(handle);
+               __WDS_LOG_FUNC_EXIT__;
+               return NULL;
+       }
+
+       (*plugin_load)((wfd_oem_ops_s **)&manager->oem_ops);
+
+       res = wfd_oem_prd_init((wfd_oem_ops_s *)manager->oem_ops);
+       if (res < 0) {
+               WDS_LOGE("Failed to initialize PRD OEM");
+               dlclose(handle);
+               __WDS_LOG_FUNC_EXIT__;
+               return NULL;
+       }
+       WDS_LOGD("Succeeded to initialize PRD OEM");
+
+       __WDS_LOG_FUNC_EXIT__;
+       return handle;
+}
+
+int wfd_util_prd_plugin_deinit(wfd_manager_s *manager)
+{
+       __WDS_LOG_FUNC_ENTER__;
+
+       if (!manager || !manager->prd_plugin_handle) {
+               WDS_LOGE("Invalid parameter");
+               __WDS_LOG_FUNC_EXIT__;
+               return -1;
+       }
+
+       dlclose(manager->prd_plugin_handle);
+       manager->prd_plugin_handle = NULL;
+
+       __WDS_LOG_FUNC_EXIT__;
+       return 0;
+}
+#endif /* TIZEN_ENABLE_PRD */
+
 void wfd_util_load_wfd_conf(wfd_manager_s * manager)
 {
        __WDS_LOG_FUNC_ENTER__;