Remove the DhcpcdWi instance if the wpa_supplicant connection is lost.
authorRoy Marples <roy@marples.name>
Fri, 12 Sep 2014 11:58:08 +0000 (11:58 +0000)
committerRoy Marples <roy@marples.name>
Fri, 12 Sep 2014 11:58:08 +0000 (11:58 +0000)
src/dhcpcd-qt/dhcpcd-qt.cpp
src/dhcpcd-qt/dhcpcd-qt.h
src/dhcpcd-qt/dhcpcd-wi.cpp
src/libdhcpcd/wpa.c

index 57c278e5cbfd4326ffe6c4b559da12981b148347..5e88aa7c4c14809add88332d6023685c3bb4f0e7 100644 (file)
@@ -69,6 +69,7 @@ DhcpcdQt::DhcpcdQt()
        dhcpcd_set_status_callback(con, dhcpcd_status_cb, this);
        dhcpcd_set_if_callback(con, dhcpcd_if_cb, this);
        dhcpcd_wpa_set_scan_callback(con, dhcpcd_wpa_scan_cb, this);
+       dhcpcd_wpa_set_status_callback(con, dhcpcd_wpa_status_cb, this);
        tryOpen();
 }
 
@@ -317,6 +318,29 @@ void DhcpcdQt::dhcpcd_wpa_scan_cb(DHCPCD_WPA *wpa, void *d)
        dhcpcdQt->scanCallback(wpa);
 }
 
+void DhcpcdQt::wpaStatusCallback(DHCPCD_WPA *wpa, const char *status)
+{
+       DHCPCD_IF *i;
+
+       i = dhcpcd_wpa_if(wpa);
+       qDebug("%s: WPA status %s", i->ifname, status);
+       if (strcmp(status, "down") == 0) {
+               DhcpcdWi *wi = findWi(wpa);
+               if (wi) {
+                       wis->removeOne(wi);
+                       delete wi;
+               }
+       }
+}
+
+void DhcpcdQt::dhcpcd_wpa_status_cb(DHCPCD_WPA *wpa, const char *status,
+    void *d)
+{
+       DhcpcdQt *dhcpcdQt = (DhcpcdQt *)d;
+
+       dhcpcdQt->wpaStatusCallback(wpa, status);
+}
+
 void DhcpcdQt::tryOpen() {
        int fd = dhcpcd_open(con);
        static int last_error;
index a6c70e7d9dd518dd2aef8ca18d956b02d0592f95..efa1bf03c3db5385c77881dfdaf5574f320320f2 100644 (file)
@@ -66,6 +66,9 @@ public:
 
        static void dhcpcd_wpa_scan_cb(DHCPCD_WPA *wpa, void *d);
        void scanCallback(DHCPCD_WPA *wpa);
+       static void dhcpcd_wpa_status_cb(DHCPCD_WPA *wpa, const char *status,
+           void *d);
+       void wpaStatusCallback(DHCPCD_WPA *wpa, const char *status);
 
        static QIcon getIcon(QString category, QString name);
 
index 5aa46638e60c0f50230dde3df7cceb510d675ea9..b8f2c547ed9439b0ae629441007ede124affbf5d 100644 (file)
@@ -58,8 +58,14 @@ DhcpcdWi::DhcpcdWi(DhcpcdQt *parent, DHCPCD_WPA *wpa)
 DhcpcdWi::~DhcpcdWi()
 {
 
+       if (menu) {
+               delete menu;
+               menu = NULL;
+       }
+
        dhcpcd_wi_scans_free(scans);
-       if (notifier != NULL)
+
+       if (notifier)
                delete notifier;
 }
 
index 472b2659d2d9b3fb3c235c031c1b2652954cc992..354dd4176e3a613f75f83276e7db802f1d97ca2a 100644 (file)
@@ -629,6 +629,16 @@ dhcpcd_wpa_set_scan_callback(DHCPCD_CONNECTION *con,
        con->wi_scanresults_context = context;
 }
 
+
+void dhcpcd_wpa_set_status_callback(DHCPCD_CONNECTION * con,
+    void (*cb)(DHCPCD_WPA *, const char *, void *), void *context)
+{
+
+       assert(con);
+       con->wpa_status_cb = cb;
+       con->wpa_status_context = context;
+}
+
 void
 dhcpcd_wpa_dispatch(DHCPCD_WPA *wpa)
 {