Notification Center. More...

#include <rnotificationcenter.h>

Public Member Functions

 RNotificationCenter (void)
 
hNotification GetNotificationHandle (const RCString &name)
 
RCString GetNotificationName (hNotification handle) const
 
void InsertObserver (tNotificationHandler handler, RObject *observer, const hNotification handle=0, RObject *object=0)
 
void InsertObserver (tNotificationHandler handler, RObject *observer, const RCString &name=RCString::Null, RObject *object=0)
 
void PostNotification (const RNotification &notification)
 
template<class T >
void PostNotification (const hNotification handle, T data)
 
template<class T >
void PostNotification (const RCString &name, T data)
 
void PostNotification (const hNotification handle)
 
void PostNotification (const RCString &name)
 
void DeleteObserver (RObject *observer)
 
void DeleteObserver (RObject *observer, const hNotification handle, RObject *object)
 
void DeleteObserver (RObject *observer, const RCString &name, RObject *object)
 
 ~RNotificationCenter (void)
 

Private Member Functions

void DeleteObject (RObject *obj)
 

Private Attributes

Intern * Data
 

Detailed Description

Notification Center.

The RNotificationCenter class provides a representation for a notification center that dispatch notifications send by objects.

class MyObject : public RObject
{
public:
MyObject(const RString& name) : RObject(name)
{
InsertObserver(HANDLER(MyObject::Handle),"Example");
}
virtual RCString GetClassName(void) const {return("MyObject");}
void Handle(const RNotification& notification)
{
cout<<"From "<<notification.GetName()<<" : "<<GetData<long>(msg)<<endl;
}
};
int main(int argc, char *argv[])
{
MyObject Obj1("Object 1");
MyObject Obj2("Object 2");
}

Constructor & Destructor Documentation

RNotificationCenter ( void  )

Constructor of a notification center.

~RNotificationCenter ( void  )

Destruct the notification center.

Member Function Documentation

hNotification GetNotificationHandle ( const RCString name)

Get a handle for a given notification.

Parameters
nameName of the notification.
Returns
Handle.
RCString GetNotificationName ( hNotification  handle) const

Get the name of a notification.

Parameters
handleHandle of the notification.
void InsertObserver ( tNotificationHandler  handler,
RObject observer,
const hNotification  handle = 0,
RObject object = 0 
)

Add an observer, eventually for a particular object and/or a particular notification.

Parameters
handlerMethod that should handle the notification.
observerObserver of the notification.
handleHandle of the notification.
objectObject which notifications must be handle. Several possibilities exists:
  1. handle is not null, but object is. The handler catches a particular notification for any object.
  2. handle is null, but object isn't. The handler catches every notification for a particular object.
  3. handle and object are null. The handler catches every notification of every object.
Warning
The same combination of (handler,observer,handle,object) can be inserted multiple times.
void InsertObserver ( tNotificationHandler  handler,
RObject observer,
const RCString name = RCString::Null,
RObject object = 0 
)

Add an observer, eventually for a particular object and/or a particular notification.

Parameters
handlerMethod that should handle the notification.
observerObserver of the notification.
nameName of the notification to handle.
objectObject which notifications must be handle. Several possibilities exists:
  1. name is not null, but object is. The handler catches a particular notification for any object.
  2. name is null, but object isn't. The handler catches every notification for a particular object.
  3. name and object are null. The handler catches every notification of every object.
Warning
The same combination of (handler,observer,name,object) can be inserted multiple times.
void PostNotification ( const RNotification notification)

Post a notification.

Parameters
notificationNotification.
void PostNotification ( const hNotification  handle,
data 
)

Post a notification.

Template Parameters
TClass of the data to the send with the notification.
Parameters
handleHandle of the notification.
dataData associated to the notification.
void PostNotification ( const RCString name,
data 
)

Post a notification.

Template Parameters
TClass of the data to the send with the notification.
Parameters
nameName of the notification.
dataData associated to the notification.
void PostNotification ( const hNotification  handle)

Post a notification without any data.

Parameters
handleHandle of the notification.
void PostNotification ( const RCString name)

Post a notification without any data.

Parameters
nameName of the notification.
void DeleteObserver ( RObject observer)

Delete a given observer.

Parameters
observerObserver to delete.
void DeleteObserver ( RObject observer,
const hNotification  handle,
RObject object 
)

Delete a given handler of a given observer.

Parameters
observerObserver of the handle.
handleHandle of the notification.
objectObject which notifications must be handle. Several possibilities exists:
  1. handle is not null, but object is. All handlers defined for the particular notification are deleted.
  2. handle is null, but object isn't. All handlers defined for the object are deleted.
  3. handle and object are null. All default handlers are deleted.
void DeleteObserver ( RObject observer,
const RCString name,
RObject object 
)

Delete a given handler of a given observer.

Parameters
observerObserver of the handle.
nameName of the notification to handle.
objectObject which notifications must be handle. Several possibilities exists:
  1. name is not null, but object is. All handlers defined for the particular notification are deleted.
  2. name is null, but object isn't. All handlers defined for the object are deleted.
  3. name and object are null. All default handlers are deleted.
void DeleteObject ( RObject obj)
private

An object is deleted. It must be removed from the observer and no other objects can observed it anymore.

Parameters
obj

Field Documentation

Intern* Data
private