#include <arsmessages.h>
Collaboration diagram for Ars::MessageServer:
Public Member Functions | |
virtual | ~MessageServer (void) |
void | RegisterMessageClient (MessageClient *pClient, const Message::EMessageType eMessageType) |
void | DeregisterMessageClient (MessageClient *pClient, const Message::EMessageType eMessageType) |
void | DeregisterMessageClient (MessageClient *pClient) |
void | ProcessMessage (void) |
Takes the next message in the queue and dispatches it to any registered clients in priority order. | |
void | QueueMessage (Message *msg, const int aLine, const std::string aFile, void *aFrom) |
void | LaunchMessage (Message *msg) |
Sends immediately a message - do not put it in queue. | |
const bool | IsRegistered (const Message::EMessageType &type, const MessageClient *target) |
Static Public Member Functions | |
MessageServer & | Instance (void) |
The single valid instance of the message server, or create one if it doesn't already exist. | |
Protected Member Functions | |
MessageServer (void) | |
The CMessageServer class cannot be directly instantiated, it must be access through Instance(). | |
Protected Attributes | |
std::map< Message::EMessageType, std::vector< std::pair< MessageClient *, bool > > > | messageClients |
A map of all the registered clients. | |
Static Protected Attributes | |
MessageServer * | instance = 0 |
A pointer to the single instande of the message server. | |
Private Member Functions | |
void | HandleTillRoot (Message &msg) |
Friends | |
class | Form |
CMessageServer is a singeton (only one instance of it is allowed to exist at any time) Clients must register to get messages sent to them
Definition at line 242 of file arsmessages.h.
|
The CMessageServer class cannot be directly instantiated, it must be access through Instance().
Definition at line 113 of file arsmessage.cpp.
00114 { 00115 } |
|
Definition at line 118 of file arsmessage.cpp. References messageClients.
00119 { 00120 while( !empty() ) 00121 { 00122 delete front(); 00123 pop_front(); 00124 } 00125 messageClients.clear(); 00126 clear(); 00127 } |
|
Deregister a client for all message types
Definition at line 165 of file arsmessage.cpp. References DeregisterMessageClient(), and messageClients.
00166 { 00167 for( std::map<Message::EMessageType,std::vector< std::pair<MessageClient *, bool> > >::iterator it = messageClients.begin() ; it != messageClients.end() ; ++it ) 00168 if( it->first != Message::DEREG_CHILD ) 00169 DeregisterMessageClient( pClient , it->first ); 00170 } |
|
Deregister a client for a certain message type
Definition at line 151 of file arsmessage.cpp. References messageClients. Referenced by DeregisterMessageClient().
00152 { 00153 std::map<Message::EMessageType,std::vector< std::pair<MessageClient *, bool> > >::iterator at = messageClients.find( eMessageType ); 00154 if( at != messageClients.end() ) 00155 { 00156 for( std::vector< std::pair<MessageClient *, bool> >::iterator it = at->second.begin() ; it != at->second.end() ; ++it ) 00157 if( it->first == pClient ) 00158 { 00159 it->second = false; 00160 break; 00161 } 00162 } 00163 } |
|
Definition at line 207 of file arsmessage.cpp. References Ars::Message::Destination(), Ars::Window::GetParent(), Ars::MessageClient::HandleMessage(), IsRegistered(), Ars::Message::MessageType(), and Ars::Message::SetTarget(). Referenced by LaunchMessage(), and ProcessMessage().
00208 { 00209 bool stopLoop = false; 00210 00211 while( !stopLoop ) 00212 { 00213 if( IsRegistered( msg.MessageType() , msg.Destination() ) ) 00214 stopLoop = msg.Destination()->HandleMessage( msg ); 00215 00216 if( !stopLoop ) 00217 { 00218 Window *wnd = dynamic_cast<Window *>( msg.Destination() ); 00219 00220 if( wnd && wnd->GetParent() ) 00221 msg.SetTarget( wnd->GetParent() ); 00222 else 00223 stopLoop = true; 00224 } 00225 } 00226 } |
|
The single valid instance of the message server, or create one if it doesn't already exist.
Definition at line 130 of file arsmessage.cpp. References instance.
00131 { 00132 if( !instance ) 00133 instance = new MessageServer; 00134 00135 return *instance; 00136 } |
|
Definition at line 228 of file arsmessage.cpp. References messageClients. Referenced by HandleTillRoot().
00229 { 00230 std::map<Message::EMessageType,std::vector< std::pair<MessageClient *, bool> > >::iterator at = messageClients.find( type ); 00231 if( at != messageClients.end() ) 00232 for( std::vector< std::pair<MessageClient *, bool> >::iterator it = at->second.begin() ; it != at->second.end() ; ++it ) 00233 if( it->first == target ) 00234 return it->second; 00235 return false; 00236 } |
|
Sends immediately a message - do not put it in queue.
Definition at line 246 of file arsmessage.cpp. References Ars::Message::Destination(), HandleTillRoot(), messageClients, and Ars::Message::MessageType().
00247 { 00248 if( msg->Destination() != 0 ) 00249 HandleTillRoot( *msg ); 00250 else 00251 { 00252 std::map<Message::EMessageType,std::vector< std::pair<MessageClient *, bool> > >::iterator at = messageClients.find( msg->MessageType() ); 00253 std::vector< std::pair<MessageClient *, bool> > tmp = at->second; 00254 00255 for( std::vector< std::pair<MessageClient *, bool> >::iterator it = tmp.begin() ; it != tmp.end() ; ++it ) 00256 if( it->second ) 00257 it->first->HandleMessage( *msg ); 00258 } 00259 delete msg; 00260 } |
|
Takes the next message in the queue and dispatches it to any registered clients in priority order. Broadcast to all if no specific targets.... Definition at line 172 of file arsmessage.cpp. References Ars::Message::Destination(), HandleTillRoot(), messageClients, and Ars::Message::MessageType().
00173 { 00174 if( !empty() ) 00175 { 00176 Message *msg2 = front(); 00177 Message &msg = *msg2; 00178 pop_front(); 00179 std::map<Message::EMessageType,std::vector< std::pair<MessageClient *, bool> > >::iterator at = messageClients.find( msg.MessageType() ); 00181 if( at != messageClients.end() ) 00182 { 00183 if( msg.Destination() == 0 ) 00184 { 00185 std::vector< std::pair<MessageClient *, bool> > tmp = at->second; 00186 for( std::vector< std::pair<MessageClient *, bool> >::iterator it = tmp.begin() ; it != tmp.end() ; ++it ) 00187 if( it->second && it->first->HandleMessage( msg ) ) 00188 break; 00189 } 00190 else 00191 HandleTillRoot( msg ); 00192 } 00193 delete msg2; 00194 } 00195 00196 for( std::map<Message::EMessageType,std::vector< std::pair<MessageClient *, bool> > >::iterator at = messageClients.begin() ; at != messageClients.end() ; ++at ) 00197 for( std::vector< std::pair<MessageClient *, bool> >::iterator it = at->second.begin() ; it != at->second.end() ; ) 00198 if( !it->second ) 00199 { 00200 at->second.erase( it ); 00201 it = at->second.begin(); 00202 } 00203 else 00204 ++it; 00205 } |
|
Adds a message to the message queue
Definition at line 238 of file arsmessage.cpp. References Ars::Message::file, Ars::Message::from, and Ars::Message::line.
00239 { 00240 msg->file = aFile; 00241 msg->line = aLine; 00242 msg->from = aFrom; 00243 push_back( msg ); 00244 } |
|
Register a client to recieve messages
Definition at line 139 of file arsmessage.cpp. References messageClients.
00140 { 00141 std::map<Message::EMessageType,std::vector< std::pair<MessageClient *, bool> > >::iterator at = messageClients.find( eMessageType ); 00142 if( at == messageClients.end() ) 00143 { 00144 std::vector< std::pair<MessageClient *, bool> > tmp; 00145 at = messageClients.insert( std::make_pair( eMessageType , tmp ) ).first; 00146 } 00147 at->second.push_back( std::make_pair( pClient , true ) ); 00148 } |
|
Definition at line 245 of file arsmessages.h. |
|
A pointer to the single instande of the message server.
Definition at line 111 of file arsmessage.cpp. Referenced by Instance(). |
|
A map of all the registered clients.
Definition at line 248 of file arsmessages.h. Referenced by DeregisterMessageClient(), IsRegistered(), LaunchMessage(), ProcessMessage(), RegisterMessageClient(), and ~MessageServer(). |