Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

MessageManager Class Reference

Gets all messages and distributes them to the handlers. More...

#include <manager.h>

Collaboration diagram for MessageManager:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ~MessageManager ()

Static Public Member Functions

void init ()
 Initialize the message manger.

void cleanup ()
 Cleanup message manager.

void PostMessage (const Message &m)
 Send a message to all the handlers.

void DoExitOnFatal (bool yes_no)
 Select whether the manager should exit on a fatal message or not.

void SelectMessageTypes (MessageHandler *hdl, Message::Type mask)
 Called by a message handler do set which sorts of messages it wants to receive.

bool IsRequestedType (Message::Type t)
 Check if passed message type is requested by any handler.

void RegisterHandler (MessageHandler *hdl)
 Internal registration function of message handlers called by their destructor.

void UnregisterHandler (MessageHandler *hdl)
 Internal unregistration function of message handlers called by their destructor.


Private Member Functions

bool _IsRequestedType (Message::Type t) const
 Check if passed message type is requested by any handler.

void _PostMessage (const Message &m)
 Internally used to post a message to all the clients.

void _RecomputeMTMask ()
 Internally used to recompute the global message type mask.

void _SelectMessageTypes (MessageHandler *hdl, Message::Type t)
 Internally used to select the message types for this handler.

void _RegisterHandler (MessageHandler *hdl)
 Internally used method for message handler registration.

void _UnregisterHandler (MessageHandler *hdl)
 Internally used method for message handler de-registration.

 MessageManager (const MessageManager &)
 Do use this class directly; just its static members.

void operator= (const MessageManager &)
 MessageManager ()
 Do use this class directly; just its static members.


Private Attributes

LinkedList< MessageHandlerhdl_list
 List of all message handler classes currently registered.

RecursiveMutex main_mutex
AtomicInt type_mask
bool exit_on_fatal
 Exit after having delivered a fatal message?


Static Private Attributes

MessageManagermanager = NULL
 Static message manager; created by init().


Detailed Description

Gets all messages and distributes them to the handlers.

Author:
Wolfgang Wieser ] wwieser (a) gmx <*> de [
This class is the main message manager class; it receives all messages created via error/warning/debug function calls. The class is designed to exist exactly once; normally generated from within the main thread during startup.

Note:
All user interface methods are actually static; never create an object of this type in your application (constructors are private).
Of course, this class is NOT C++-safe.

Definition at line 67 of file manager.h.


Constructor & Destructor Documentation

MessageManager::MessageManager const MessageManager  )  [private]
 

Do use this class directly; just its static members.

MessageManager::MessageManager  )  [private]
 

Do use this class directly; just its static members.

Definition at line 129 of file manager.cc.

References Assert, CritAssert, exit_on_fatal, manager, and type_mask.

Referenced by init().

MessageManager::~MessageManager  ) 
 

Definition at line 145 of file manager.cc.

References _UnregisterHandler(), Assert, LinkedList< MessageHandler >::first(), hdl_list, LinkedList< MessageHandler >::IsEmpty(), RecursiveMutex::lock(), main_mutex, manager, and RecursiveMutex::unlock().


Member Function Documentation

bool MessageManager::_IsRequestedType Message::Type  t  )  const [inline, private]
 

Check if passed message type is requested by any handler.

Definition at line 92 of file manager.h.

References type_mask, and AtomicInt::val().

Referenced by _PostMessage(), and IsRequestedType().

void MessageManager::_PostMessage const Message m  )  [private]
 

Internally used to post a message to all the clients.

Definition at line 26 of file manager.cc.

References _IsRequestedType(), exit_on_fatal, LinkedList< MessageHandler >::first(), MessageHandler::HandleMessage(), hdl_list, RecursiveMutex::lock(), main_mutex, Message::MatchesTypeMask(), MessageHandler::mtmask, LinkedListBase< MessageHandler >::next, Message::type(), and RecursiveMutex::unlock().

Referenced by PostMessage().

void MessageManager::_RecomputeMTMask  )  [private]
 

Internally used to recompute the global message type mask.

Definition at line 63 of file manager.cc.

References LinkedList< MessageHandler >::first(), hdl_list, MessageHandler::mtmask, LinkedListBase< MessageHandler >::next, AtomicInt::set(), and type_mask.

Referenced by _SelectMessageTypes(), and _UnregisterHandler().

void MessageManager::_RegisterHandler MessageHandler hdl  )  [private]
 

Internally used method for message handler registration.

Definition at line 93 of file manager.cc.

References LinkedList< MessageHandler >::append(), hdl_list, RecursiveMutex::lock(), main_mutex, MessageHandler::mtmask, and RecursiveMutex::unlock().

Referenced by RegisterHandler().

void MessageManager::_SelectMessageTypes MessageHandler hdl,
Message::Type  t
[private]
 

Internally used to select the message types for this handler.

Definition at line 77 of file manager.cc.

References _RecomputeMTMask(), RecursiveMutex::lock(), main_mutex, MessageHandler::mtmask, and RecursiveMutex::unlock().

Referenced by SelectMessageTypes().

void MessageManager::_UnregisterHandler MessageHandler hdl  )  [private]
 

Internally used method for message handler de-registration.

Definition at line 103 of file manager.cc.

References _RecomputeMTMask(), LinkedList< MessageHandler >::dequeue(), hdl_list, RecursiveMutex::lock(), main_mutex, and RecursiveMutex::unlock().

Referenced by UnregisterHandler(), and ~MessageManager().

void MessageManager::cleanup  )  [static]
 

Cleanup message manager.

The opposite of init().

Definition at line 121 of file manager.cc.

References manager.

Referenced by main().

void MessageManager::DoExitOnFatal bool  yes_no  )  [inline, static]
 

Select whether the manager should exit on a fatal message or not.

By default, the manager will do exit(2) after having delivered a fatal message.

Definition at line 151 of file manager.h.

References exit_on_fatal, and manager.

void MessageManager::init  )  [static]
 

Initialize the message manger.

In order to use the message reporting routines, you must first initialize the message manager using MessageManager::init(), normally from the main thread.

Note:
Make sure this function is called exactly once.

Definition at line 114 of file manager.cc.

References MessageManager().

Referenced by main().

bool MessageManager::IsRequestedType Message::Type  t  )  [inline, static]
 

Check if passed message type is requested by any handler.

Definition at line 163 of file manager.h.

References _IsRequestedType(), and manager.

Referenced by _Debug(), Error(), Fatal(), and Warning().

void MessageManager::operator= const MessageManager  )  [private]
 

void MessageManager::PostMessage const Message m  )  [inline, static]
 

Send a message to all the handlers.

Normally, this is not meant to be called directly but via the provided message formatting functions like Warning(), Error(), Fatal(), Debug().

Definition at line 141 of file manager.h.

References _PostMessage(), and manager.

Referenced by _vaMessage().

void MessageManager::RegisterHandler MessageHandler hdl  )  [inline, static]
 

Internal registration function of message handlers called by their destructor.

For internal use only.

Definition at line 170 of file manager.h.

References _RegisterHandler(), and manager.

Referenced by MessageHandler::MessageHandler().

void MessageManager::SelectMessageTypes MessageHandler hdl,
Message::Type  mask
[inline, static]
 

Called by a message handler do set which sorts of messages it wants to receive.

For internal use only.

Definition at line 158 of file manager.h.

References _SelectMessageTypes(), and manager.

Referenced by MessageHandler::SelectMessageTypes().

void MessageManager::UnregisterHandler MessageHandler hdl  )  [inline, static]
 

Internal unregistration function of message handlers called by their destructor.

For internal use only.

Definition at line 177 of file manager.h.

References _UnregisterHandler(), and manager.

Referenced by MessageHandler::~MessageHandler().


Member Data Documentation

bool MessageManager::exit_on_fatal [private]
 

Exit after having delivered a fatal message?

Definition at line 89 of file manager.h.

Referenced by _PostMessage(), DoExitOnFatal(), and MessageManager().

LinkedList<MessageHandler> MessageManager::hdl_list [private]
 

List of all message handler classes currently registered.

Definition at line 78 of file manager.h.

Referenced by _PostMessage(), _RecomputeMTMask(), _RegisterHandler(), _UnregisterHandler(), and ~MessageManager().

RecursiveMutex MessageManager::main_mutex [private]
 

Mutex to protect the message handler list and the delivery process:

Definition at line 81 of file manager.h.

Referenced by _PostMessage(), _RegisterHandler(), _SelectMessageTypes(), _UnregisterHandler(), and ~MessageManager().

MessageManager * MessageManager::manager = NULL [static, private]
 

Static message manager; created by init().

Definition at line 23 of file manager.cc.

Referenced by cleanup(), DoExitOnFatal(), IsRequestedType(), MessageManager(), PostMessage(), RegisterHandler(), SelectMessageTypes(), UnregisterHandler(), and ~MessageManager().

AtomicInt MessageManager::type_mask [private]
 

Bitfield of the message types requested by any message handler. This is actually a Message::Type, but we need the atomic type here. (There is an assertion to check for the size in manager.cc.)

Definition at line 86 of file manager.h.

Referenced by _IsRequestedType(), _RecomputeMTMask(), and MessageManager().


The documentation for this class was generated from the following files:
Generated on Sat Feb 19 22:35:30 2005 for Ray by doxygen 1.3.5