PTLib
Version 2.18.8
|
This class is a singleton that will monitor the network interfaces on a machine and update a list aof clients on any changes to the number or addresses of the interfaces. More...
#include <psockbun.h>
Classes | |
struct | InterfaceChange |
Information on the interface change. More... | |
Public Types | |
enum | { DefaultRefreshInterval = 60000 } |
enum | { DefaultPriority = 50 } |
typedef PIPSocket::InterfaceEntry | InterfaceEntry |
typedef PNotifierTemplate < InterfaceChange > | Notifier |
Type for disposition notifiers. More... | |
![]() | |
enum | Comparison { LessThan = -1, EqualTo = 0, GreaterThan = 1 } |
Result of the comparison operation performed by the Compare() function. More... | |
Public Member Functions | |
PInterfaceMonitor (unsigned refreshInterval=DefaultRefreshInterval, bool runMonitorThread=true) | |
virtual | ~PInterfaceMonitor () |
PFACTORY_GET_SINGLETON (PProcessStartupFactory, PInterfaceMonitor) | |
Return the singleton interface for the network monitor. More... | |
void | SetRefreshInterval (unsigned refresh) |
Change the refresh interval. More... | |
void | SetRunMonitorThread (bool runMonitorThread) |
Change whether the monitor thread should run. More... | |
void | Start () |
Start monitoring network interfaces. More... | |
void | Stop () |
Stop monitoring network interfaces. More... | |
PStringArray | GetInterfaces (bool includeLoopBack=false, const PIPSocket::Address &destination=PIPSocket::GetDefaultIpAny()) |
Get an array of all current interface descriptors, possibly including the loopback (127.0.0.1) interface. More... | |
bool | IsValidBindingForDestination (const PIPSocket::Address &binding, const PIPSocket::Address &destination) |
Returns whether destination is reachable through binding or not. More... | |
bool | GetInterfaceInfo (const PString &iface, InterfaceEntry &info) const |
Return information about an active interface given the descriptor string. More... | |
void | AddNotifier (const Notifier ¬ifier, unsigned priority=DefaultPriority) |
Add a notifier for interface changes. More... | |
void | RemoveNotifier (const Notifier ¬ifier) |
void | SetInterfaceFilter (PInterfaceFilter *filter) |
Sets the monitor's interface filter. More... | |
bool | HasInterfaceFilter () const |
![]() | |
virtual void | OnStartup () |
![]() | |
__inline unsigned | GetTraceContextIdentifier () const |
Get PTRACE context identifier. More... | |
__inline void | SetTraceContextIdentifier (unsigned id) |
__inline void | SetTraceContextIdentifier (const PObject &obj) |
__inline void | SetTraceContextIdentifier (const PObject *obj) |
__inline void | CopyTraceContextIdentifier (PObject &obj) const |
__inline void | CopyTraceContextIdentifier (PObject *obj) const |
virtual | ~PObject () |
__inline const char * | GetClass () const |
__inline bool | IsClass (const char *name) const |
__inline const PObject * | PTraceObjectInstance () const |
virtual PObject * | Clone () const |
Create a copy of the class on the heap. More... | |
template<class CLS > | |
CLS * | CloneAs () const |
As for Clone() but converts to specified type. More... | |
virtual PINDEX | HashFunction () const |
This function yields a hash value required by the PDictionary class. More... | |
virtual Comparison | Compare (const PObject &obj) const |
Compare the two objects and return their relative rank. More... | |
virtual Comparison | CompareObjectMemoryDirect (const PObject &obj) const |
Determine the byte wise comparison of two objects. More... | |
bool | operator== (const PObject &obj) const |
Compare the two objects. More... | |
bool | operator!= (const PObject &obj) const |
Compare the two objects. More... | |
bool | operator< (const PObject &obj) const |
Compare the two objects. More... | |
bool | operator> (const PObject &obj) const |
Compare the two objects. More... | |
bool | operator<= (const PObject &obj) const |
Compare the two objects. More... | |
bool | operator>= (const PObject &obj) const |
Compare the two objects. More... | |
virtual void | PrintOn (ostream &strm) const |
Output the contents of the object to the stream. More... | |
virtual void | ReadFrom (istream &strm) |
Input the contents of the object from the stream. More... | |
Static Public Member Functions | |
static bool | IsMatchingInterface (const PString &iface, const InterfaceEntry &entry) |
Returns whether the descriptor string equals the interface entry. More... | |
![]() | |
static __inline void | CopyTraceContextIdentifier (PObject &to, const PObject &from) |
static __inline void | CopyTraceContextIdentifier (PObject &to, const PObject *from) |
static __inline void | CopyTraceContextIdentifier (PObject *to, const PObject &from) |
static __inline void | CopyTraceContextIdentifier (PObject *to, const PObject *from) |
static __inline const char * | Class () |
static __inline const PObject * | PTraceObjectInstance (const char *) |
static __inline const PObject * | PTraceObjectInstance (const PObject *obj) |
template<typename T > | |
static Comparison | Compare2 (T v1, T v2) |
Compare two types, returning Comparison type. More... | |
static Comparison | InternalCompareObjectMemoryDirect (const PObject *obj1, const PObject *obj2, PINDEX size) |
Internal function caled from CompareObjectMemoryDirect() More... | |
Protected Types | |
typedef std::multimap < unsigned, Notifier > | Notifiers |
Protected Member Functions | |
virtual void | OnShutdown () |
void | UpdateThreadMain () |
virtual void | RefreshInterfaceList () |
virtual void | OnInterfacesChanged (const PIPSocket::InterfaceTable &addedInterfaces, const PIPSocket::InterfaceTable &removedInterfaces) |
PDECLARE_MUTEX (m_notifiersMutex) | |
PDECLARE_MUTEX (m_interfacesMutex) | |
PDECLARE_MUTEX (m_threadMutex) | |
![]() | |
PObject () | |
Constructor for PObject, made protected so cannot ever create one on its own. More... | |
Protected Attributes | |
Notifiers | m_notifiers |
PIPSocket::InterfaceTable | m_interfaces |
bool | m_runMonitorThread |
PTimeInterval | m_refreshInterval |
PThread * | m_updateThread |
PInterfaceFilter * | m_interfaceFilter |
PIPSocket::RouteTableDetector * | m_changedDetector |
![]() | |
unsigned | m_traceContextIdentifier |
This class is a singleton that will monitor the network interfaces on a machine and update a list aof clients on any changes to the number or addresses of the interfaces.
A user may override this singleton by creating a derived class and making a static instance of it before any monitor client classes are created. This would typically be done in the users main program.
Type for disposition notifiers.
|
protected |
PInterfaceMonitor::PInterfaceMonitor | ( | unsigned | refreshInterval = DefaultRefreshInterval , |
bool | runMonitorThread = true |
||
) |
|
virtual |
void PInterfaceMonitor::AddNotifier | ( | const Notifier & | notifier, |
unsigned | priority = DefaultPriority |
||
) |
Add a notifier for interface changes.
notifier | Notifier to be called by interface monitor |
priority | Priority for notification |
bool PInterfaceMonitor::GetInterfaceInfo | ( | const PString & | iface, |
InterfaceEntry & | info | ||
) | const |
Return information about an active interface given the descriptor string.
Note that when searchin the descriptor may be a partial match e.g. "10.0.1.11" or "%eth0" may be used.
iface | Interface desciptor name |
info | Information on the interface |
PStringArray PInterfaceMonitor::GetInterfaces | ( | bool | includeLoopBack = false , |
const PIPSocket::Address & | destination = PIPSocket::GetDefaultIpAny() |
||
) |
Get an array of all current interface descriptors, possibly including the loopback (127.0.0.1) interface.
Note the names are of the form ipname, eg "10.0.1.11%3Com 3C90x Ethernet Adapter" or "192.168.0.10%eth0"
includeLoopBack | Flag for if loopback is to included in list |
destination | Optional destination for selecting specific interface |
|
inline |
References m_interfaceFilter.
|
static |
Returns whether the descriptor string equals the interface entry.
Note that when searching the descriptor may be a partial match e.g. "10.0.1.11" or "%eth0" may be used.
iface | Interface descriptor |
entry | Interface entry |
bool PInterfaceMonitor::IsValidBindingForDestination | ( | const PIPSocket::Address & | binding, |
const PIPSocket::Address & | destination | ||
) |
Returns whether destination is reachable through binding or not.
The default behaviour returns true unless there is an interface filter installed an the filter does not return binding
among it's interfaces.
binding | Interface binding to test |
destination | Destination to test against the binding |
|
protectedvirtual |
|
protectedvirtual |
Reimplemented from PProcessStartup.
|
protected |
|
protected |
|
protected |
PInterfaceMonitor::PFACTORY_GET_SINGLETON | ( | PProcessStartupFactory | , |
PInterfaceMonitor | |||
) |
Return the singleton interface for the network monitor.
|
protectedvirtual |
void PInterfaceMonitor::RemoveNotifier | ( | const Notifier & | notifier | ) |
notifier | Notifier to be called by interface monitor |
void PInterfaceMonitor::SetInterfaceFilter | ( | PInterfaceFilter * | filter | ) |
Sets the monitor's interface filter.
Note that the monitor instance handles deletion of the filter.
void PInterfaceMonitor::SetRefreshInterval | ( | unsigned | refresh | ) |
Change the refresh interval.
void PInterfaceMonitor::SetRunMonitorThread | ( | bool | runMonitorThread | ) |
Change whether the monitor thread should run.
void PInterfaceMonitor::Start | ( | ) |
Start monitoring network interfaces.
If the monitoring thread is already running, then this will cause an refresh of the interface list as soon as possible. Note that this will happen asynchronously.
void PInterfaceMonitor::Stop | ( | ) |
Stop monitoring network interfaces.
|
protected |
|
protected |
|
protected |
Referenced by HasInterfaceFilter().
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |