[DA patch]Add timeout configuration
[platform/core/connectivity/wifi-direct-manager.git] / src / wifi-direct-main.c
1 /*
2  * Network Configuration Module
3  *
4  * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 /**
21  * This file implements wifi direct manager main functions.
22  *
23  * @file        wifi-direct-main.c
24  * @author      Jiung Yu (jiung.yu@samsung.com)
25  * @version     0.1
26  */
27 #include <glib.h>
28 #include <glib-object.h>
29
30 #include <wifi-direct.h>
31
32 #include "wifi-direct-ipc.h"
33 #include "wifi-direct-log.h"
34 #include "wifi-direct-oem.h"
35 #include "wifi-direct-manager.h"
36 #include "wifi-direct-dbus.h"
37 #include "wifi-direct-util.h"
38
39
40 int main(int argc, char *argv[])
41 {
42         __WDS_LOG_FUNC_ENTER__;//LCOV_EXCL_LINE
43         GMainLoop *main_loop = NULL;
44         wfd_manager_s *manager = NULL;
45
46 #if !GLIB_CHECK_VERSION(2, 32, 0)
47         if (!g_thread_supported())
48                 g_thread_init(NULL);
49 #endif
50
51 #if !GLIB_CHECK_VERSION(2, 36, 0)
52         g_type_init();
53 #endif
54
55         if (wfd_manager_load() < 0) {
56                 WDS_LOGE("Failed to initialize wifi-direct manager");
57                 __WDS_LOG_FUNC_EXIT__;//LCOV_EXCL_LINE
58                 return -1;
59         }
60         manager = wfd_get_manager();
61         if (!manager) {
62                 WDS_LOGE("Failed to initialize wifi-direct manager");
63                 __WDS_LOG_FUNC_EXIT__;//LCOV_EXCL_LINE
64                 return -1;
65         }
66
67         /**
68          * wfd_manager_plugin initialization
69          */
70         manager->plugin_handle = wfd_util_plugin_init(manager);
71         if (!manager->plugin_handle) {
72                 WDS_LOGE("Failed to initialize plugin");
73                 wfd_manager_unload(manager);
74                 __WDS_LOG_FUNC_EXIT__;//LCOV_EXCL_LINE
75                 return -1;
76         }
77         WDS_LOGD("Succeeded to load plugin");
78 #if defined TIZEN_ENABLE_PRD
79         /**
80          * wfd_manager_prd_plugin initialization
81          */
82         manager->prd_plugin_handle = wfd_prd_util_plugin_init(manager);
83         if (!manager->prd_plugin_handle)
84                 WDS_LOGW("Failed to initialize prd plugin");
85         else
86                 WDS_LOGD("Succeeded to load plugin");
87 #endif /* TIZEN_ENABLE_PRD */
88
89         if (!wfd_manager_dbus_init()) {
90                 WDS_LOGE("Failed to DBus");
91                 wfd_util_plugin_deinit(manager);
92                 wfd_manager_unload();
93                 __WDS_LOG_FUNC_EXIT__;//LCOV_EXCL_LINE
94                 return -1;
95         }
96
97         main_loop = g_main_loop_new(NULL, FALSE);
98         if (main_loop == NULL) {
99                 WDS_LOGE("Failed to create GMainLoop structure");
100                 __WDS_LOG_FUNC_EXIT__;//LCOV_EXCL_LINE
101                 return -1;
102         }
103         manager->main_loop = main_loop;
104         g_main_loop_run(main_loop);
105
106         wfd_manager_dbus_unregister_nameowner_signal();
107
108         wfd_manager_dbus_unregister();
109         wfd_manager_dbus_deinit();
110
111 #if defined TIZEN_ENABLE_PRD
112         wfd_util_prd_plugin_deinit(manager);
113 #endif /* TIZEN_ENABLE_PRD */
114
115         wfd_util_plugin_deinit(manager);
116
117         wfd_manager_unload();
118
119         __WDS_LOG_FUNC_EXIT__;//LCOV_EXCL_LINE
120         return 0;
121 }