[haiku-commits] Change in haiku[master]: NetworkStatus: do not show non-present interfaces

  • From: Gerrit <review@xxxxxxxxxxxxxxxxxxx>
  • To: waddlesplash <waddlesplash@xxxxxxxxx>, haiku-commits@xxxxxxxxxxxxx
  • Date: Mon, 13 Jun 2022 08:17:38 +0000

From Javier Steinaker <jsteinaker@xxxxxxxxx>:

Javier Steinaker has uploaded this change for review. ( 
https://review.haiku-os.org/c/haiku/+/5378 ;)


Change subject: NetworkStatus: do not show non-present interfaces
......................................................................

NetworkStatus: do not show non-present interfaces
---
M src/apps/networkstatus/NetworkStatusView.cpp
1 file changed, 17 insertions(+), 0 deletions(-)



  git pull ssh://git.haiku-os.org:22/haiku refs/changes/78/5378/1

diff --git a/src/apps/networkstatus/NetworkStatusView.cpp 
b/src/apps/networkstatus/NetworkStatusView.cpp
index 84aaae7..9e736ff 100644
--- a/src/apps/networkstatus/NetworkStatusView.cpp
+++ b/src/apps/networkstatus/NetworkStatusView.cpp
@@ -13,6 +13,7 @@
 #include "NetworkStatusView.h"

 #include <algorithm>
+#include <list>
 #include <set>
 #include <vector>

@@ -519,9 +520,12 @@
        BNetworkRoster& roster = BNetworkRoster::Default();
        BNetworkInterface interface;
        uint32 cookie = 0;
+       std::list<BString> currentInterfaces;

        while (roster.GetNextInterface(&cookie, interface) == B_OK) {
                if ((interface.Flags() & IFF_LOOPBACK) == 0) {
+                       // Make a list of the current interfaces, needed later
+                       currentInterfaces.push_front((BString)interface.Name());
                        int32 oldStatus = kStatusUnknown;
                        if (fInterfaceStatuses.find(interface.Name())
                                != fInterfaceStatuses.end()) {
@@ -550,6 +554,19 @@
                        fInterfaceStatuses[interface.Name()] = status;
                }
        }
+
+       /* Check every element in fInterfaceStatuses against our current 
interface
+       /* list. If it's not there, then the interface is not present anymore 
and
+       /* should be removed from fInterfaceStatuses.*/
+       auto it = fInterfaceStatuses.begin();
+       while (it != fInterfaceStatuses.end()) {
+               if (std::find(currentInterfaces.begin(),
+                               currentInterfaces.end(), it->first) == 
currentInterfaces.end()) {
+                       it = fInterfaceStatuses.erase(it);
+               } else {
+                       ++it;
+               }
+       }
 }



--
To view, visit https://review.haiku-os.org/c/haiku/+/5378
To unsubscribe, or for help writing mail filters, visit 
https://review.haiku-os.org/settings

Gerrit-Project: haiku
Gerrit-Branch: master
Gerrit-Change-Id: I65d536f42957f244464d05b2d902d9a09988e8cc
Gerrit-Change-Number: 5378
Gerrit-PatchSet: 1
Gerrit-Owner: Javier Steinaker <jsteinaker@xxxxxxxxx>
Gerrit-MessageType: newchange

Other related posts: