PTLib  Version 2.18.8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PMonitoredSocketBundle Class Reference

This concrete class bundles a set of UDP sockets which are dynamically adjusted as interfaces are added and removed from the system. More...

#include <psockbun.h>

Inheritance diagram for PMonitoredSocketBundle:
Collaboration diagram for PMonitoredSocketBundle:

Public Member Functions

 PMonitoredSocketBundle (const PString &fixedInterface, unsigned ipVersion, bool reuseAddrP_NAT_PARAM(PNatMethods *natMethods=NULL))
 
 ~PMonitoredSocketBundle ()
 
virtual 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...
 
virtual PBoolean Open (WORD port)
 Open the socket(s) using the specified port. More...
 
virtual PBoolean Close ()
 Close all socket(s) More...
 
virtual bool SetQoS (const PIPSocket::QoS &qos)
 Set the quality of service for sockets. More...
 
virtual PBoolean GetAddress (const PString &iface, PIPSocket::Address &address, WORD &port, PBoolean usingNAT) const
 Get the local address for the given interface. More...
 
virtual void WriteToBundle (BundleParams &param)
 Write to the remote address/port using the socket(s) available. More...
 
virtual void ReadFromBundle (BundleParams &param)
 Read fram a remote address/port using the socket(s) available. More...
 
- Public Member Functions inherited from PMonitoredSockets
PBoolean IsOpen () const
 Indicate if the socket(s) are open and ready for reads/writes. More...
 
WORD GetPort () const
 Return the local port number being used by the socket(s) More...
 
virtual bool GetInterfaceInfo (const PString &iface, InterfaceEntry &info) const
 Return information about an active interface given the descriptor string. More...
 
- Public Member Functions inherited from PSafeObject
 PSafeObject ()
 Create a thread safe object. More...
 
 PSafeObject (const PSafeObject &other)
 
 PSafeObject (PSafeObject *indirectLock)
 
 PSafeObject (PReadWriteMutex &mutex)
 
 ~PSafeObject ()
 
PBoolean SafeReference ()
 Increment the reference count for object. More...
 
PBoolean SafeDereference ()
 Decrement the reference count for object. More...
 
__inline bool LockReadOnly () const
 Lock the object for Read Only access. More...
 
__inline bool LockReadOnly (const PDebugLocation &location) const
 
__inline void UnlockReadOnly () const
 Release the read only lock on an object. More...
 
__inline void UnlockReadOnly (const PDebugLocation &location) const
 
__inline bool LockReadWrite () const
 Lock the object for Read/Write access. More...
 
__inline bool LockReadWrite (const PDebugLocation &location) const
 
__inline void UnlockReadWrite () const
 Release the read/write lock on an object. More...
 
__inline void UnlockReadWrite (const PDebugLocation &location) const
 
void SafeRemove ()
 Set the removed flag. More...
 
unsigned IsSafelyBeingRemoved () const
 Indicate the object is being safely removed. More...
 
PBoolean SafelyCanBeDeleted () const
 Determine if the object can be safely deleted. More...
 
virtual bool GarbageCollection ()
 Do any garbage collection that may be required by the object so that it may be finally deleted. More...
 
unsigned GetSafeReferenceCount () const
 Get count of references to this object. More...
 
- Public Member Functions inherited from PObject
__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 PObjectPTraceObjectInstance () const
 
virtual PObjectClone () 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...
 

Protected Types

typedef std::map< std::string,
SocketInfo
SocketInfoMap_T
 

Protected Member Functions

 PDECLARE_InterfaceNotifier (PMonitoredSocketBundle, OnInterfaceChange)
 
void OpenSocket (const PString &iface)
 
void CloseSocket (SocketInfoMap_T::iterator iterSocket)
 
- Protected Member Functions inherited from PMonitoredSockets
 PMonitoredSockets (bool reuseAddrP_NAT_PARAM(PNatMethods *natMethods))
 
bool CreateSocket (SocketInfo &info, const PIPSocket::Address &binding)
 
bool DestroySocket (SocketInfo &info)
 
bool GetSocketAddress (const SocketInfo &info, PIPSocket::Address &address, WORD &port, bool usingNAT) const
 
void ReadFromSocketList (PSocket::SelectList &readers, PUDPSocket *&socket, BundleParams &param)
 
- Protected Member Functions inherited from PObject
 PObject ()
 Constructor for PObject, made protected so cannot ever create one on its own. More...
 

Protected Attributes

PInterfaceMonitor::Notifier m_onInterfaceChange
 
SocketInfoMap_T m_socketInfoMap
 
PCaselessString m_fixedInterface
 
unsigned m_ipVersion
 
- Protected Attributes inherited from PMonitoredSockets
WORD m_localPort
 
bool m_reuseAddress
 
bool m_opened
 
PUDPSocket m_interfaceAddedSignal
 
PIPSocket::QoS m_qos
 
- Protected Attributes inherited from PObject
unsigned m_traceContextIdentifier
 

Additional Inherited Members

- Public Types inherited from PMonitoredSockets
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...
 
- Static Public Member Functions inherited from PMonitoredSockets
static PMonitoredSocketsCreate (const PString &iface, bool reuseAddr=falseP_NAT_PARAM(PNatMethods *natMethods=NULL))
 Create a new monitored socket instance based on the interface descriptor. More...
 
- Static Public Member Functions inherited from PObject
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 PObjectPTraceObjectInstance (const char *)
 
static __inline const PObjectPTraceObjectInstance (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...
 

Detailed Description

This concrete class bundles a set of UDP sockets which are dynamically adjusted as interfaces are added and removed from the system.

Member Typedef Documentation

typedef std::map<std::string, SocketInfo> PMonitoredSocketBundle::SocketInfoMap_T
protected

Constructor & Destructor Documentation

PMonitoredSocketBundle::PMonitoredSocketBundle ( const PString fixedInterface,
unsigned  ipVersion,
bool   reuseAddrP_NAT_PARAMPNatMethods *natMethods=NULL 
)
Parameters
fixedInterfaceInterface name for bundle, "" is all interfaces
ipVersionVersion of IP to listen
reuseAddrP_NAT_PARAMFlag for sharing socket/exclusve use NAT method to use to create sockets.
PMonitoredSocketBundle::~PMonitoredSocketBundle ( )

Member Function Documentation

virtual PBoolean PMonitoredSocketBundle::Close ( )
virtual

Close all socket(s)

Implements PMonitoredSockets.

void PMonitoredSocketBundle::CloseSocket ( SocketInfoMap_T::iterator  iterSocket)
protected
virtual PBoolean PMonitoredSocketBundle::GetAddress ( const PString iface,
PIPSocket::Address address,
WORD &  port,
PBoolean  usingNAT 
) const
virtual

Get the local address for the given interface.

Parameters
ifaceInterface to get address for
addressAddress of interface
portPort listening on
usingNATRequire NAT address/port

Implements PMonitoredSockets.

virtual PStringArray PMonitoredSocketBundle::GetInterfaces ( bool  includeLoopBack = false,
const PIPSocket::Address destination = PIPSocket::GetDefaultIpAny() 
)
virtual

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". If destination is not 'any' and a filter is set, filters the interface list before returning it.

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

Reimplemented from PMonitoredSockets.

virtual PBoolean PMonitoredSocketBundle::Open ( WORD  port)
virtual

Open the socket(s) using the specified port.

If port is zero then a system allocated port is used. In this case and when multiple interfaces are supported, all sockets use the same dynamic port value.

Returns true if all sockets are opened.

Implements PMonitoredSockets.

void PMonitoredSocketBundle::OpenSocket ( const PString iface)
protected
PMonitoredSocketBundle::PDECLARE_InterfaceNotifier ( PMonitoredSocketBundle  ,
OnInterfaceChange   
)
protected
virtual void PMonitoredSocketBundle::ReadFromBundle ( BundleParams param)
virtual

Read fram a remote address/port using the socket(s) available.

If the iface parameter is empty, then the first data received on any socket(s) is used, and the iface parameter is set to the name of that interface. Otherwise the iface parameter indicates the specific interface socket to read the data from.

Parameters
paramInfo on data to read

Implements PMonitoredSockets.

virtual bool PMonitoredSocketBundle::SetQoS ( const PIPSocket::QoS qos)
virtual

Set the quality of service for sockets.

Implements PMonitoredSockets.

virtual void PMonitoredSocketBundle::WriteToBundle ( BundleParams param)
virtual

Write to the remote address/port using the socket(s) available.

If the iface parameter is empty, then the data is written to all socket(s). Otherwise the iface parameter indicates the specific interface socket to write the data to.

Parameters
paramInfo on data to write

Implements PMonitoredSockets.

Member Data Documentation

PCaselessString PMonitoredSocketBundle::m_fixedInterface
protected
unsigned PMonitoredSocketBundle::m_ipVersion
protected
PInterfaceMonitor::Notifier PMonitoredSocketBundle::m_onInterfaceChange
protected
SocketInfoMap_T PMonitoredSocketBundle::m_socketInfoMap
protected

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