_wifi_data_s wifi_data = { 0, };
int rv = 0;
- sa_error_e ret = SA_ERROR_UNKNOWN;
+ sa_error_e ret = SA_ERROR_NONE;
wifi_manager_h wifi_h = NULL;
_D("__wifi_connect_main (ssid=%s, pw=%s)", info->ssid, info->password);
}
context = g_main_context_new();
- g_main_context_push_thread_default(context); // should be.. to get mainloop message in thread
- gmain_loop = g_main_loop_new(context, FALSE);
-
- rv = wifi_manager_initialize(&wifi_h);
-
- if (rv == WIFI_MANAGER_ERROR_NONE) {
- // fill the token data
- wifi_data.ssid = info->ssid;
- wifi_data.password = info->password;
- wifi_data.loop = gmain_loop;
- wifi_data.wifi_h = wifi_h;
-
- rv = wifi_manager_set_device_state_changed_cb(wifi_h, __wifi_state_changed_cb, (void *)&wifi_data);
- rv = wifi_manager_activate(wifi_h, __wifi_activate_cb, NULL);
- if (rv == WIFI_MANAGER_ERROR_ALREADY_EXISTS) {
- _D("wifi_manager_active alreay exists");
- wifi_manager_scan(wifi_h, __wifi_scan_finished_cb, (void *)&wifi_data);
- } else if (rv != WIFI_MANAGER_ERROR_NONE) {
- _E("wifi_manager_activated failed.[%s]", __print_wifi_error(rv));
- return SA_ERROR_UNKNOWN;
- }
- } else {
- _E("Wifi init failed [%s]", __print_wifi_error(rv));
- return SA_ERROR_UNKNOWN;
- }
- g_main_loop_run(gmain_loop);
+ if (context != NULL) {
+ g_main_context_push_thread_default(context); // should be.. to get mainloop message in thread
+ gmain_loop = g_main_loop_new(context, FALSE);
- gmain_loop = NULL;
+ if (gmain_loop != NULL) {
+ rv = wifi_manager_initialize(&wifi_h);
- wifi_manager_unset_scan_state_changed_cb(wifi_h);
- wifi_manager_unset_connection_state_changed_cb(wifi_h);
+ if (rv == WIFI_MANAGER_ERROR_NONE) {
+ // fill the token data
+ wifi_data.ssid = info->ssid;
+ wifi_data.password = info->password;
+ wifi_data.loop = gmain_loop;
+ wifi_data.wifi_h = wifi_h;
+
+ rv = wifi_manager_set_device_state_changed_cb(wifi_h, __wifi_state_changed_cb, (void *)&wifi_data);
+ if (rv == WIFI_MANAGER_ERROR_NONE) {
+ rv = wifi_manager_activate(wifi_h, __wifi_activate_cb, NULL);
+ if (rv == WIFI_MANAGER_ERROR_ALREADY_EXISTS) {
+ _D("wifi_manager_active alreay exists");
+ wifi_manager_scan(wifi_h, __wifi_scan_finished_cb, (void *)&wifi_data);
+ } else if (rv != WIFI_MANAGER_ERROR_NONE) {
+ _E("wifi_manager_activated failed.[%s]", __print_wifi_error(rv));
+ ret = SA_ERROR_UNKNOWN;
+ }
+ } else {
+ ret = SA_ERROR_UNKNOWN;
+ _E("wifi_manager_set_device_state_changed_cb error");
+ }
+ } else {
+ ret = SA_ERROR_UNKNOWN;
+ _E("Wifi init failed [%s]", __print_wifi_error(rv));
+ }
- rv = wifi_manager_deinitialize(wifi_h);
+ if (ret == SA_ERROR_NONE)
+ g_main_loop_run(gmain_loop);
- if (rv != WIFI_MANAGER_ERROR_NONE) {
- _D("Fail to deinitialize.");
- ret = SA_ERROR_UNKNOWN;
+ g_main_loop_unref(gmain_loop);
+ g_main_context_unref(context);
+
+ if (wifi_h != NULL) {
+ wifi_manager_unset_scan_state_changed_cb(wifi_h);
+ wifi_manager_unset_connection_state_changed_cb(wifi_h);
+ }
+
+ gmain_loop = NULL;
+ context = NULL;
+
+ if (wifi_h != NULL) {
+ rv = wifi_manager_deinitialize(wifi_h);
+ if (rv != WIFI_MANAGER_ERROR_NONE) {
+ _D("Fail to deinitialize.");
+ ret = SA_ERROR_UNKNOWN;
+ }
+ }
+ } else {
+ g_main_context_unref(context);
+ _E("Fail to create g_main_loop");
+ }
+ } else {
+ _E("Fail to create g_main_context");
}
_D("__wifi_connect_main completed.");
if (info->wifi != NULL) {
if ((info->wifi->enabled == TRUE) && !sa_inputfile_get_completion_flag(SA_FILE_CONFIG_WIFI)) {
retWifi = __wifi_connect_main(info->wifi);
+
_D("return wifi [%d]", retWifi);
} else {
_D("wifi enabled flag is false");