utils::Listeners Class Reference

#include <listeners.h>

Collaboration diagram for utils::Listeners:
Collaboration graph
[legend]

Data Structures

struct  ListenerData

Public Member Functions

 Listeners (void)
 ~Listeners (void)
unsigned long add_listener (const PluginEvent event_type, EventFunc callback, void *user_data)
bool remove_listener (unsigned long handler_id)
 Remove listener.
void broadcast (IPluginUnknown *sender, const PluginEvent event_type, const PluginEventAttrs *plugin_data)
 Broadcast.
 Listeners (void)
 ~Listeners (void)
unsigned long add_listener (const PluginEvent event_type, EventFunc callback, void *user_data)
bool remove_listener (unsigned long handler_id)
 Remove listener.
void broadcast (IPluginUnknown *sender, const PluginEvent event_type, const PluginEventAttrs *plugin_data)
 Broadcast.
 Listeners (void)
 ~Listeners (void)
unsigned long add_listener (const PluginEvent event_type, EventFunc callback, void *user_data)
bool remove_listener (unsigned long handler_id)
 Remove listener.
void broadcast (IPluginUnknown *sender, const PluginEvent event_type, const PluginEventAttrs *plugin_data)
 Broadcast.

Detailed Description

Implement a event listener container. This class enables user to manage listeners for every PluginEvent type. The handler_id will never be zero, so listener can use zero as a special flag.

Definition at line 42 of file images/plugin_impl/listeners.h.


Constructor & Destructor Documentation

utils::Listeners::Listeners ( void   ) 

Definition at line 32 of file images/plugin_impl/listeners.cpp.

00033 : handler_id(0)
00034 {
00035 }

utils::Listeners::~Listeners ( void   ) 

Definition at line 37 of file images/plugin_impl/listeners.cpp.

00038 {
00039 }

utils::Listeners::Listeners ( void   ) 
utils::Listeners::~Listeners ( void   ) 
utils::Listeners::Listeners ( void   ) 
utils::Listeners::~Listeners ( void   ) 

Member Function Documentation

unsigned long utils::Listeners::add_listener ( const PluginEvent  event_type,
EventFunc  callback,
void *  user_data 
)

Add listener. Repeated adding same callback function is allowed. So this function always returns the new added handler id.

unsigned long utils::Listeners::add_listener ( const PluginEvent  event_type,
EventFunc  callback,
void *  user_data 
)

Add listener. Repeated adding same callback function is allowed. So this function always returns the new added handler id.

unsigned long utils::Listeners::add_listener ( const PluginEvent  event_type,
EventFunc  callback,
void *  user_data 
)

Add listener. Repeated adding same callback function is allowed. So this function always returns the new added handler id.

Definition at line 44 of file images/plugin_impl/listeners.cpp.

References data.

00047 {
00048     ++handler_id;
00049     ListenerData * data = new ListenerData;
00050     data->callback = callback;
00051     data->user_data = user_data;
00052     data->handler_id = handler_id;
00053     listeners[event_type].push_back(data);
00054     return handler_id;
00055 }

void utils::Listeners::broadcast ( IPluginUnknown sender,
const PluginEvent  event_type,
const PluginEventAttrs plugin_data 
)

Broadcast.

void utils::Listeners::broadcast ( IPluginUnknown sender,
const PluginEvent  event_type,
const PluginEventAttrs plugin_data 
)

Broadcast.

void utils::Listeners::broadcast ( IPluginUnknown sender,
const PluginEvent  event_type,
const PluginEventAttrs plugin_data 
)

Broadcast.

Definition at line 74 of file images/plugin_impl/listeners.cpp.

00077 {
00078     broadcast_to_vector(listeners[event_type], sender, 
00079                         event_type, plugin_data);
00080 }

bool utils::Listeners::remove_listener ( unsigned long  handler_id  ) 

Remove listener.

bool utils::Listeners::remove_listener ( unsigned long  handler_id  ) 

Remove listener.

bool utils::Listeners::remove_listener ( unsigned long  handler_id  ) 

Remove listener.

Definition at line 58 of file images/plugin_impl/listeners.cpp.

00059 {
00060     // Have to search the whole map.
00061     ListenerMapIter begin = listeners.begin();
00062     ListenerMapIter end   = listeners.end();
00063     for(ListenerMapIter it = begin; it != end; ++it)
00064     {
00065         if (remove_from_vector(handler_id, it->second))
00066         {
00067             return true;
00068         }
00069     }
00070     return false;
00071 }


The documentation for this class was generated from the following files:
Generated by  doxygen 1.6.2-20100208