PTLib  Version 2.10.11
PInterfaceMonitor Class Reference

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>

Inheritance diagram for PInterfaceMonitor:
PProcessStartup PObject

Public Types

enum  { DefaultRefreshInterval = 60000 }
 
typedef PIPSocket::InterfaceEntry InterfaceEntry
 
- Public Types inherited from PObject
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 SetInterfaceFilter (PInterfaceFilter *filter)
 Sets the monitor's interface filter. More...
 
bool HasInterfaceFilter () const
 
virtual void RefreshInterfaceList ()
 
void OnRemoveNatMethod (const PNatMethod *natMethod)
 
- Public Member Functions inherited from PProcessStartup
virtual void OnStartup ()
 
- Public Member Functions inherited from PObject
virtual ~PObject ()
 
virtual PObjectClone () const
 Create a copy of the class on the heap. 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 const char * GetClass (unsigned ancestor=0) const
 Get the current dynamic type of the object instance. More...
 
PBoolean IsClass (const char *cls) const
 
virtual PBoolean InternalIsDescendant (const char *clsName) const
 Determine if the dynamic type of the current instance is a descendent of the specified class. 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 Public Member Functions inherited from PObject
static Comparison InternalCompareObjectMemoryDirect (const PObject *obj1, const PObject *obj2, PINDEX size)
 Internal function caled from CompareObjectMemoryDirect() More...
 
static const char * Class ()
 Get the name of the class as a C string. More...
 

Protected Types

typedef PSmartPtr< PInterfaceMonitorClientClientPtr
 
typedef std::list< PInterfaceMonitorClient * > ClientList_T
 

Protected Member Functions

virtual void OnShutdown ()
 
void UpdateThreadMain ()
 
void AddClient (PInterfaceMonitorClient *)
 
void RemoveClient (PInterfaceMonitorClient *)
 
virtual void OnInterfacesChanged (const PIPSocket::InterfaceTable &addedInterfaces, const PIPSocket::InterfaceTable &removedInterfaces)
 
- Protected Member Functions inherited from PObject
 PObject ()
 Constructor for PObject, made protected so cannot ever create one on its own. More...
 

Protected Attributes

ClientList_T m_clients
 
PMutex m_clientsMutex
 
PIPSocket::InterfaceTable m_interfaces
 
PMutex m_interfacesMutex
 
bool m_runMonitorThread
 
PTimeInterval m_refreshInterval
 
PMutex m_threadMutex
 
PThreadm_updateThread
 
PInterfaceFilterm_interfaceFilter
 
PIPSocket::RouteTableDetectorm_changedDetector
 

Detailed Description

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.

Member Typedef Documentation

§ ClientList_T

§ ClientPtr

§ InterfaceEntry

Member Enumeration Documentation

§ anonymous enum

anonymous enum
Enumerator
DefaultRefreshInterval 

Constructor & Destructor Documentation

§ PInterfaceMonitor()

PInterfaceMonitor::PInterfaceMonitor ( unsigned  refreshInterval = DefaultRefreshInterval,
bool  runMonitorThread = true 
)

§ ~PInterfaceMonitor()

virtual PInterfaceMonitor::~PInterfaceMonitor ( )
virtual

Member Function Documentation

§ AddClient()

void PInterfaceMonitor::AddClient ( PInterfaceMonitorClient )
protected

Referenced by HasInterfaceFilter().

§ GetInterfaceInfo()

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.

Parameters
ifaceInterface desciptor name
infoInformation on the interface

§ GetInterfaces()

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"

Parameters
includeLoopBackFlag for if loopback is to included in list
destinationOptional destination for selecting specific interface

§ HasInterfaceFilter()

bool PInterfaceMonitor::HasInterfaceFilter ( ) const
inline

§ IsMatchingInterface()

static bool PInterfaceMonitor::IsMatchingInterface ( const PString iface,
const InterfaceEntry entry 
)
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.

Parameters
ifaceInterface descriptor
entryInterface entry

§ IsValidBindingForDestination()

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.

Parameters
bindingInterface binding to test
destinationDestination to test against the binding

§ OnInterfacesChanged()

virtual void PInterfaceMonitor::OnInterfacesChanged ( const PIPSocket::InterfaceTable &  addedInterfaces,
const PIPSocket::InterfaceTable &  removedInterfaces 
)
protectedvirtual

Referenced by HasInterfaceFilter().

§ OnRemoveNatMethod()

void PInterfaceMonitor::OnRemoveNatMethod ( const PNatMethod natMethod)

§ OnShutdown()

virtual void PInterfaceMonitor::OnShutdown ( )
protectedvirtual

Reimplemented from PProcessStartup.

Referenced by HasInterfaceFilter().

§ PFACTORY_GET_SINGLETON()

PInterfaceMonitor::PFACTORY_GET_SINGLETON ( PProcessStartupFactory  ,
PInterfaceMonitor   
)

Return the singleton interface for the network monitor.

§ RefreshInterfaceList()

virtual void PInterfaceMonitor::RefreshInterfaceList ( )
virtual

Referenced by HasInterfaceFilter().

§ RemoveClient()

void PInterfaceMonitor::RemoveClient ( PInterfaceMonitorClient )
protected

Referenced by HasInterfaceFilter().

§ SetInterfaceFilter()

void PInterfaceMonitor::SetInterfaceFilter ( PInterfaceFilter filter)

Sets the monitor's interface filter.

Note that the monitor instance handles deletion of the filter.

§ SetRefreshInterval()

void PInterfaceMonitor::SetRefreshInterval ( unsigned  refresh)

Change the refresh interval.

§ SetRunMonitorThread()

void PInterfaceMonitor::SetRunMonitorThread ( bool  runMonitorThread)

Change whether the monitor thread should run.

§ Start()

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.

§ Stop()

void PInterfaceMonitor::Stop ( )

Stop monitoring network interfaces.

§ UpdateThreadMain()

void PInterfaceMonitor::UpdateThreadMain ( )
protected

Referenced by HasInterfaceFilter().

Member Data Documentation

§ m_changedDetector

PIPSocket::RouteTableDetector* PInterfaceMonitor::m_changedDetector
protected

§ m_clients

ClientList_T PInterfaceMonitor::m_clients
protected

§ m_clientsMutex

PMutex PInterfaceMonitor::m_clientsMutex
protected

§ m_interfaceFilter

PInterfaceFilter* PInterfaceMonitor::m_interfaceFilter
protected

Referenced by HasInterfaceFilter().

§ m_interfaces

PIPSocket::InterfaceTable PInterfaceMonitor::m_interfaces
protected

§ m_interfacesMutex

PMutex PInterfaceMonitor::m_interfacesMutex
protected

§ m_refreshInterval

PTimeInterval PInterfaceMonitor::m_refreshInterval
protected

§ m_runMonitorThread

bool PInterfaceMonitor::m_runMonitorThread
protected

§ m_threadMutex

PMutex PInterfaceMonitor::m_threadMutex
protected

§ m_updateThread

PThread* PInterfaceMonitor::m_updateThread
protected

The documentation for this class was generated from the following file: