RefObject Class Reference

#include <yateclass.h>

Inheritance diagram for RefObject:
GenObject AnalogLine Array CallEndpoint ChanAssist ClientAccount ClientContact ClientResource DataEndpoint DataNode DurationUpdate IAXFrame IAXInfoElement IAXMetaTrunkFrame IAXTransaction ISDNFrame JBEvent JBStream JGSession JGSessionContent JIDFeature JIDIdentity JIDResource MGCPEndpoint MGCPMessage MGCPTransaction SignallingCall SignallingCircuit SignallingComponent SignallingMessage SIPMessage SIPParty SIPTransaction SS7Route XMLElementOut XMPPServerInfo XMPPUser XMPPUserRoster

List of all members.

Public Member Functions

 RefObject ()
virtual ~RefObject ()
virtual bool alive () const
bool ref ()
bool deref ()
int refcount () const
virtual void destruct ()

Static Public Member Functions

static MutexrefMutex ()

Protected Member Functions

virtual void zeroRefs ()
virtual bool zeroRefsTest ()
bool refInternal ()
bool resurrect ()
virtual void destroyed ()

Detailed Description

A reference counted object. Whenever using multiple inheritance you should inherit this class virtually.


Constructor & Destructor Documentation

RefObject (  )  [inline]

The constructor initializes the reference counter to 1! Use deref() to destruct the object when safe

virtual ~RefObject (  )  [virtual]

Destructor.


Member Function Documentation

virtual bool alive (  )  const [virtual]

Check if the object is still referenced and safe to access. Note that you should not trust this result unless the object is locked by other means.

Returns:
True if the object is referenced and safe to access

Reimplemented from GenObject.

bool deref (  ) 

Decrements the reference counter, destroys the object if it reaches zero

 // Deref this object, return quickly if the object was deleted
 if (deref()) return;
 
Returns:
True if the object may have been deleted, false if it still exists and is safe to access
virtual void destroyed (  )  [protected, virtual]

Pre-destruction notification, called just before the object is deleted. Unlike in the destructor it is safe to call virtual methods here. Reimplementing this method allows to perform any object cleanups.

Reimplemented in DataConsumer, DataSource, ThreadedSource, DataEndpoint, CallEndpoint, ClientChannel, ClientAccount, ClientContact, DurationUpdate, JBStream, JGSession, MGCPTransaction, SignallingComponent, SignallingCircuitGroup, AnalogLine, AnalogLineGroup, SS7MTP2, SS7MTP3, SS7ISUP, ISDNQ921, ISDNQ921Passive, ISDNQ931, ISDNQ931Monitor, and SIPTransaction.

virtual void destruct (  )  [virtual]

Refcounted objects should just have the counter decremented. That will destroy them only when the refcount reaches zero.

Reimplemented from GenObject.

bool ref (  ) 

Increments the reference counter if not already zero

Returns:
True if the object was successfully referenced and is safe to access

Referenced by AnalogLineEvent::AnalogLineEvent().

int refcount (  )  const [inline]

Get the current value of the reference counter

Returns:
The value of the reference counter
bool refInternal (  )  [protected]

Increments the reference counter if not already zero without locking the mutex. The caller must make sure to hold the refMutex() locked.

Returns:
True if the object was successfully referenced
static Mutex& refMutex (  )  [static]

Retrieve the mutex that protects ref() and deref() for all objects

Returns:
Reference to the global mutex used for all counter operations
bool resurrect (  )  [protected]

Bring the object back alive by setting the reference counter to one. Note that it works only if the counter was zero previously

Returns:
True if the object was resurrected - its name may be Lazarus ;-)
virtual void zeroRefs (  )  [protected, virtual]

This method is called when the reference count reaches zero after unlocking the mutex if the call to zeroRefsTest() returned true. The default behaviour is to delete the object.

Reimplemented in Channel.

virtual bool zeroRefsTest (  )  [protected, virtual]

This method is called when the reference count reaches zero just before calling zeroRefs() with the non-recursive mutex still locked. Extra care must be taken to prevent deadlocks, normally the code should only change some variables and return. The default implementation just returns true.

Returns:
True to call zeroRefs() after releasing the mutex

The documentation for this class was generated from the following file:
Generated on Thu Apr 8 18:22:35 2010 for Yate by  doxygen 1.6.3