PInterfaceMonitor Class Reference

#include <psockbun.h>

Inheritance diagram for PInterfaceMonitor:

PProcessStartup PObject List of all members.

Public Types

enum  { DefaultRefreshInterval = 60000 }
typedef PIPSocket::InterfaceEntry InterfaceEntry

Public Member Functions

 PInterfaceMonitor (unsigned refreshInterval=DefaultRefreshInterval, bool runMonitorThread=true)
virtual ~PInterfaceMonitor ()
void SetRefreshInterval (unsigned refresh)
 Change the refresh interval.
void SetRunMonitorThread (bool runMonitorThread)
 Change whether the monitor thread should run.
void Start ()
void Stop ()
 Stop monitoring network interfaces.
PStringArray GetInterfaces (bool includeLoopBack=false, const PIPSocket::Address &destination=PIPSocket::GetDefaultIpAny())
bool IsValidBindingForDestination (const PIPSocket::Address &binding, const PIPSocket::Address &destination)
bool GetInterfaceInfo (const PString &iface, InterfaceEntry &info)
void SetInterfaceFilter (PInterfaceFilter *filter)
bool HasInterfaceFilter () const
virtual void RefreshInterfaceList ()
void OnRemoveNatMethod (const PNatMethod *natMethod)

Static Public Member Functions

static PInterfaceMonitorGetInstance ()
 Return the singleton interface for the network monitor.
static bool IsMatchingInterface (const PString &iface, const InterfaceEntry &entry)

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 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
PSyncPoint m_signalUpdate
bool m_threadRunning
PInterfaceFilterm_interfaceFilter

Friends

class PInterfaceMonitorClient

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

typedef PIPSocket::InterfaceEntry PInterfaceMonitor::InterfaceEntry

typedef PSmartPtr<PInterfaceMonitorClient> PInterfaceMonitor::ClientPtr [protected]

typedef std::list<PInterfaceMonitorClient *> PInterfaceMonitor::ClientList_T [protected]


Member Enumeration Documentation

anonymous enum

Enumerator:
DefaultRefreshInterval 


Constructor & Destructor Documentation

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

virtual PInterfaceMonitor::~PInterfaceMonitor (  )  [virtual]


Member Function Documentation

static PInterfaceMonitor& PInterfaceMonitor::GetInstance (  )  [static]

Return the singleton interface for the network monitor.

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.

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:
destination  Flag for if loopback is to included in list

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.

bool PInterfaceMonitor::GetInterfaceInfo ( const PString iface,
InterfaceEntry info 
)

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:
info  Interface desciptor name Information on the interface

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:
entry  Interface descriptor Interface entry

void PInterfaceMonitor::SetInterfaceFilter ( PInterfaceFilter filter  ) 

Sets the monitor's interface filter. Note that the monitor instance handles deletion of the filter.

bool PInterfaceMonitor::HasInterfaceFilter (  )  const [inline]

virtual void PInterfaceMonitor::RefreshInterfaceList (  )  [virtual]

void PInterfaceMonitor::OnRemoveNatMethod ( const PNatMethod natMethod  ) 

virtual void PInterfaceMonitor::OnShutdown (  )  [protected, virtual]

Reimplemented from PProcessStartup.

void PInterfaceMonitor::UpdateThreadMain (  )  [protected]

void PInterfaceMonitor::AddClient ( PInterfaceMonitorClient  )  [protected]

void PInterfaceMonitor::RemoveClient ( PInterfaceMonitorClient  )  [protected]

virtual void PInterfaceMonitor::OnInterfacesChanged ( const PIPSocket::InterfaceTable &  addedInterfaces,
const PIPSocket::InterfaceTable &  removedInterfaces 
) [protected, virtual]


Friends And Related Function Documentation

friend class PInterfaceMonitorClient [friend]


Member Data Documentation

ClientList_T PInterfaceMonitor::m_clients [protected]

PMutex PInterfaceMonitor::m_clientsMutex [protected]

PIPSocket::InterfaceTable PInterfaceMonitor::m_interfaces [protected]

PMutex PInterfaceMonitor::m_interfacesMutex [protected]

bool PInterfaceMonitor::m_runMonitorThread [protected]

PTimeInterval PInterfaceMonitor::m_refreshInterval [protected]

PMutex PInterfaceMonitor::m_threadMutex [protected]

PThread* PInterfaceMonitor::m_updateThread [protected]

PSyncPoint PInterfaceMonitor::m_signalUpdate [protected]

bool PInterfaceMonitor::m_threadRunning [protected]

PInterfaceFilter* PInterfaceMonitor::m_interfaceFilter [protected]


The documentation for this class was generated from the following file:
Generated on Mon Feb 23 01:57:56 2009 for PTLib by  doxygen 1.5.1