void NMListener::run() { NMDevice *dev = nm_client_get_device_by_iface(nm, "wlan0"); context = g_main_context_default(); //context = g_main_context_new(); loop = g_main_loop_new(context, false); //g_main_context_invoke(context, initialize_in_context, status); g_signal_connect_swapped(nm, "notify::" NM_CLIENT_WIRELESS_ENABLED, G_CALLBACK(handle_wireless_enabled), wifiStatus); g_signal_connect_swapped(dev, "notify::" NM_DEVICE_STATE, G_CALLBACK(handle_wireless_connected), wifiStatus); g_signal_connect_swapped(NM_DEVICE_WIFI(dev), "notify::" NM_DEVICE_WIFI_ACTIVE_ACCESS_POINT, G_CALLBACK(handle_active_access_point), wifiStatus); g_signal_connect_swapped(NM_DEVICE_WIFI(dev), "access-point-added", G_CALLBACK(handle_changed_access_points), wifiStatus); g_signal_connect_swapped(NM_DEVICE_WIFI(dev), "access-point-removed", G_CALLBACK(handle_changed_access_points), wifiStatus); while (!threadShouldExit()) { { const MessageManagerLock mmLock; bool dispatched = g_main_context_iteration(context, false); } wait(LIBNM_ITERATION_PERIOD); } g_main_loop_unref(loop); g_main_context_unref(context); }
NMClient* WifiStatusNM::connectToNetworkManager() { if (!nmclient || !NM_IS_CLIENT(nmclient)) nmclient = nm_client_new(); if (!nmclient || !NM_IS_CLIENT(nmclient)) DBG("WifiStatusNM: failed to connect to nmclient over dbus"); if (!nmdevice || !NM_IS_DEVICE(nmdevice)) nmdevice = nm_client_get_device_by_iface(nmclient, "wlan0"); if (!nmdevice || !NM_IS_DEVICE(nmdevice)) DBG("WifiStatusNM: failed to connect to nmdevice wlan0 over dbus"); return nmclient; }
bool ActivateConnectionService::activate_connection_cb(ActivateConnection::Request& request, ActivateConnection::Response& response) { const NetworkConnections::ConstPtr connections = m_latest_connections; if (!connections) //haven't yet received any connection data return false; NMDevice * device = nm_client_get_device_by_iface(m_client, request.device_iface.c_str()); if (device == NULL) { ROS_WARN("Could not find device: '%s'", request.device_iface.c_str()); response.message = "Could not find device: '"; response.message += request.device_iface; response.message += "'"; return true; } //get the connection info for this active connection const char* path = NULL; std::vector<NetworkConnection>::const_iterator itr = connections->list.begin(); for (; itr != connections->list.end(); ++itr) { if (itr->name == request.connection_name) { path = itr->path.c_str(); break; } } NMConnection * connection = NULL; if (path != NULL) connection = NM_CONNECTION(nm_remote_settings_get_connection_by_path(m_remote_settings, path)); if (connection == NULL) { ROS_WARN( "Could not find connection: '%s'", request.connection_name.c_str()); response.message = "Could not find connection: '"; response.message += request.connection_name; response.message += "'"; return true; } ROS_INFO( "Activiting Connection: '%s' on %s", request.connection_name.c_str(), request.device_iface.c_str()); nm_client_activate_connection(m_client, connection, device, NULL, NULL, NULL); return true; }