Check already powered during Wi-Fi enable/disable
[framework/connectivity/net-config.git] / src / main.c
1 /*
2  * Network Configuration Module
3  *
4  * Copyright (c) 2012-2013 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 #include <unistd.h>
21
22 #include "log.h"
23 #include "wifi.h"
24 #include "util.h"
25 #include "emulator.h"
26 #include "netdbus.h"
27 #include "network-clock.h"
28 #include "network-state.h"
29 #include "network-statistics.h"
30 #include "signal-handler.h"
31 #include "wifi-agent.h"
32
33 static GMainLoop *main_loop = NULL;
34
35 int main(int argc, char* argv[])
36 {
37         DBusGConnection *connection;
38
39         DBG("Network Configuration Module");
40
41         if (daemon(0, 0) != 0)
42                 DBG("Cannot start daemon");
43
44         netconfig_set_wifi_mac_address();
45
46         g_type_init();
47
48         main_loop = g_main_loop_new(NULL, FALSE);
49
50         connection = netconfig_setup_dbus();
51         if (connection == NULL)
52                 return -1;
53
54         if (netconfig_network_state_create_and_init(connection) == NULL)
55                 return -1;
56
57         netconfig_register_signal();
58
59         /* Registering the agent for exchanging security credentials */
60         netconfig_agent_register();
61
62         if (netconfig_wifi_create_and_init(connection) == NULL)
63                 return -1;
64
65         if (netconfig_network_statistics_create_and_init(connection) == NULL)
66                 return -1;
67
68         /* If its environment uses Emulator, network configuration is set by emulator default */
69         netconfig_emulator_test_and_start();
70
71         g_main_loop_run(main_loop);
72
73         netconfig_deregister_signal();
74         netconfig_wifi_state_notifier_cleanup();
75
76         /* Unregistering the agent */
77         netconfig_agent_unregister();
78
79         return 0;
80 }