Yate
RefObject Class Reference

#include <yateclass.h>

Inheritance diagram for RefObject:
GenObject AnalogLine Array ChanAssist IAXFrame IAXInfoElement IAXMetaTrunkFrame IAXTransaction IAXTrunkInfo ISDNFrame MGCPEndpoint MGCPMessage MGCPTransaction RadioInterface SIPMessage SIPParty SIPSequence SIPTransaction SS7Route SS7TCAPTransaction SccpLocalSubsystem SccpRemote SccpSubsystem ScriptCode ScriptContext SignallingCall SignallingCircuit SignallingComponent SignallingMessage SocketRef SubsystemStatusTest CallEndpoint ClientAccount ClientContact ClientResource DataEndpoint DataNode DurationUpdate JBEvent JBStream JBStreamSetList JGSession JGSessionContent MessageHook MessagePostHook RefStorage XmlElementOut

Public Member Functions

 RefObject ()
 
virtual ~RefObject ()
 
virtual void * getObject (const String &name) const
 
virtual bool alive () const
 
bool ref ()
 
bool deref ()
 
int refcount () const
 
virtual void destruct ()
 
- Public Member Functions inherited from GenObject
 GenObject ()
 
virtual ~GenObject ()
 
virtual const StringtoString () const
 
virtual const StringtraceId () const
 
NamedCountergetObjCounter () const
 
NamedCountersetObjCounter (NamedCounter *counter)
 

Static Public Member Functions

static bool alive (const RefObject *obj)
 
static bool efficientIncDec ()
 
- Static Public Member Functions inherited from GenObject
static void * getObject (const String &name, const GenObject *obj)
 
static bool getObjCounting ()
 
static void setObjCounting (bool enable)
 
static NamedCountergetObjCounter (const String &name, bool create=true)
 
static ObjListgetObjCounters ()
 

Protected Member Functions

virtual void zeroRefs ()
 
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()

RefObject ( )

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

Referenced by alive(), ClientChannel::clientData(), ScriptContext::refObj(), and ClientChannel::setClientData().

◆ ~RefObject()

virtual ~RefObject ( )
virtual

Destructor.

Member Function Documentation

◆ alive() [1/2]

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.

◆ alive() [2/2]

static bool alive ( const RefObject * obj)
inlinestatic

Check if a refcounted object is still alive

Parameters
objPointer to the object to check
Returns
True if the pointer is not null and the object is referenced

References refcount(), and RefObject().

◆ deref()

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

◆ destroyed()

virtual void destroyed ( )
protectedvirtual

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 AnalogLine, AnalogLineGroup, GTT, IAXFullFrame, IAXTransaction, ISDNQ921, ISDNQ921Passive, ISDNQ931, ISDNQ931Monitor, MGCPTransaction, SCCPUser, SignallingCircuitGroup, SignallingComponent, SIPTransaction, SS7ISUP, SS7Layer4, SS7M2PA, SS7MTP2, SS7MTP3, SS7Router, SS7SCCP, TCAPUser, CallEndpoint, ClientAccount, ClientChannel, ClientContact, DataConsumer, DataEndpoint, DataSource, DurationUpdate, JBClientStream, JBServerStream, JBStream, JBStreamSetList, JGSession, MucRoom, and ThreadedSource.

Referenced by ISDNQ931::destroyed(), and ISDNQ931Monitor::destroyed().

◆ destruct()

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.

◆ efficientIncDec()

static bool efficientIncDec ( )
static

Check if reference counter manipulations are efficient on this platform. If platform does not support atomic operations a mutex pool is used.

Returns
True if refcount uses atomic integer operations

◆ getObject()

virtual void * getObject ( const String & name) const
virtual

Get a pointer to a derived class given that class name

Parameters
nameName of the class we are asking for
Returns
Pointer to the requested class or NULL if this object doesn't implement it

Reimplemented from GenObject.

Reimplemented in Array, ISDNQ931Call, ISDNQ931CallMonitor, ISDNQ931Message, ScriptContext, SocketRef, SS7ISUPCall, CallEndpoint, Channel, DataConsumer, DataEndpoint, DataSource, DataTranslator, and JBStream.

Referenced by SocketRef::getObject().

◆ ref()

◆ refcount()

int refcount ( ) const
inline

Get the current value of the reference counter

Returns
The value of the reference counter

Referenced by alive().

◆ resurrect()

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 ;-)

◆ zeroRefs()

virtual void zeroRefs ( )
protectedvirtual

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.


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