PSafeCollection Class Reference

This class defines a thread-safe collection of objects. More...

#include <safecoll.h>

Inheritance diagram for PSafeCollection:

PObject PSafeColl< Coll, Base > PSafeColl< PArray< Base >, Base > PSafeColl< PList< Base >, Base > PSafeColl< PSortedList< Base >, Base > PSafeDictionaryBase< Coll, Key, Base > PSafeDictionaryBase< PDictionary< Key, Base >, Key, Base > PSafeArray< Base > PSafeList< Base > PSafeSortedList< Base > PSafeDictionary< Key, Base > List of all members.

Operations

virtual void RemoveAll (PBoolean synchronous=false)
 Remove all objects in collection.
void AllowDeleteObjects (PBoolean yes=true)
 Disallow the automatic delete any objects that have been removed.
void DisallowDeleteObjects ()
 Disallow the automatic delete any objects that have been removed.
virtual PBoolean DeleteObjectsToBeRemoved ()
 Delete any objects that have been removed.
virtual void DeleteObject (PObject *object) const
 Delete an objects that has been removed.
virtual void SetAutoDeleteObjects ()
 Start a timer to automatically call DeleteObjectsToBeRemoved().
PINDEX GetSize () const
 Get the current size of the collection.
PBoolean IsEmpty () const
 Determine if the collection is empty.
const PMutexGetMutex () const
 Get the mutex for the collection.
virtual PBoolean SafeRemove (PSafeObject *obj)
 Remove an object to the collection.
virtual PBoolean SafeRemoveAt (PINDEX idx)
 Remove an object to the collection.

Public Member Functions

Construction
 PSafeCollection (PCollection *collection)
 Create a thread safe collection of objects.
 ~PSafeCollection ()
 Destroy the thread safe collection.

Protected Member Functions

void CopySafeCollection (PCollection *other)
void CopySafeDictionary (PAbstractDictionary *other)
void SafeRemoveObject (PSafeObject *obj)
 PDECLARE_NOTIFIER (PTimer, PSafeCollection, DeleteObjectsTimeout)

Protected Attributes

PCollectioncollection
PMutex collectionMutex
bool deleteObjects
PList< PSafeObjecttoBeRemoved
PMutex removalMutex
PTimer deleteObjectsTimer

Detailed Description

This class defines a thread-safe collection of objects.

This class is a wrapper around a standard PCollection class which allows only safe, mutexed, access to the collection.

This is part of a set of classes to solve the general problem of a collection (eg a PList or PDictionary) of objects that needs to be a made thread safe. Any thread can add, read, write or remove an object with both the object and the database of objects itself kept thread safe.

See the PSafeObject class for more details. Especially in regard to enumeration of collections.


Constructor & Destructor Documentation

PSafeCollection::PSafeCollection ( PCollection collection  ) 

Create a thread safe collection of objects.

Note the collection is automatically deleted on destruction.

Parameters:
collection  Actual collection of objects

PSafeCollection::~PSafeCollection (  ) 

Destroy the thread safe collection.

The will delete the collection object provided in the constructor.


Member Function Documentation

void PSafeCollection::AllowDeleteObjects ( PBoolean  yes = true  )  [inline]

Disallow the automatic delete any objects that have been removed.

Objects are simply removed from the collection and not marked for deletion using PSafeObject::SafeRemove() and DeleteObject().

Parameters:
yes  New value for flag for deleting objects

void PSafeCollection::CopySafeCollection ( PCollection other  )  [protected]

void PSafeCollection::CopySafeDictionary ( PAbstractDictionary other  )  [protected]

virtual void PSafeCollection::DeleteObject ( PObject object  )  const [virtual]

Delete an objects that has been removed.

virtual PBoolean PSafeCollection::DeleteObjectsToBeRemoved (  )  [virtual]

Delete any objects that have been removed.

Returns true if all objects in the collection have been removed and their pending deletions carried out.

void PSafeCollection::DisallowDeleteObjects (  )  [inline]

Disallow the automatic delete any objects that have been removed.

Objects are simply removed from the collection and not marked for deletion using PSafeObject::SafeRemove() and DeleteObject().

const PMutex& PSafeCollection::GetMutex (  )  const [inline]

Get the mutex for the collection.

PINDEX PSafeCollection::GetSize (  )  const

Get the current size of the collection.

Note that usefulness of this function is limited as it is merely an instantaneous snapshot of the state of the collection.

PBoolean PSafeCollection::IsEmpty (  )  const [inline]

Determine if the collection is empty.

Note that usefulness of this function is limited as it is merely an instantaneous snapshot of the state of the collection.

PSafeCollection::PDECLARE_NOTIFIER ( PTimer  ,
PSafeCollection  ,
DeleteObjectsTimeout   
) [protected]

virtual void PSafeCollection::RemoveAll ( PBoolean  synchronous = false  )  [virtual]

Remove all objects in collection.

Parameters:
synchronous  Wait till objects are deleted before returning

virtual PBoolean PSafeCollection::SafeRemove ( PSafeObject obj  )  [protected, virtual]

Remove an object to the collection.

This function removes the object from the collection itself, but does not actually delete the object. It simply moves the object to a list of objects to be garbage collected at a later time.

As for Append() full mutual exclusion locking on the collection itself is maintained.

Parameters:
obj  Object to remove from collection

virtual PBoolean PSafeCollection::SafeRemoveAt ( PINDEX  idx  )  [protected, virtual]

Remove an object to the collection.

This function removes the object from the collection itself, but does not actually delete the object. It simply moves the object to a list of objects to be garbage collected at a later time.

As for Append() full mutual exclusion locking on the collection itself is maintained.

Parameters:
idx  Object index to remove

void PSafeCollection::SafeRemoveObject ( PSafeObject obj  )  [protected]

virtual void PSafeCollection::SetAutoDeleteObjects (  )  [virtual]

Start a timer to automatically call DeleteObjectsToBeRemoved().


Member Data Documentation

PCollection* PSafeCollection::collection [protected]

PMutex PSafeCollection::collectionMutex [mutable, protected]

bool PSafeCollection::deleteObjects [protected]

PTimer PSafeCollection::deleteObjectsTimer [protected]

PMutex PSafeCollection::removalMutex [protected]

PList<PSafeObject> PSafeCollection::toBeRemoved [protected]


The documentation for this class was generated from the following file:
Generated on Fri Oct 14 01:44:12 2011 for PTLib by  doxygen 1.4.7