1 /* 2 * Copyright 2015, Axel Dörfler, axeld@pinc-software.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef NETWORK_WATCHER_H 6 #define NETWORK_WATCHER_H 7 8 9 #include <Handler.h> 10 #include <ObjectList.h> 11 12 13 class NetworkListener { 14 public: 15 virtual ~NetworkListener(); 16 17 virtual void NetworkAvailabilityChanged(bool available) = 0; 18 }; 19 20 21 class NetworkWatcher : public BHandler { 22 public: 23 NetworkWatcher(); 24 virtual ~NetworkWatcher(); 25 26 void AddListener(NetworkListener* listener); 27 void RemoveListener(NetworkListener* listener); 28 int32 CountListeners() const; 29 30 virtual void MessageReceived(BMessage* message); 31 32 static void Register(NetworkListener* listener); 33 static void Unregister(NetworkListener* listener); 34 35 static bool NetworkAvailable(bool immediate); 36 37 protected: 38 void UpdateAvailability(); 39 40 protected: 41 BObjectList<NetworkListener> 42 fListeners; 43 bool fAvailable; 44 }; 45 46 47 #endif // NETWORK_WATCHER_H 48