Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

MessagerAgent.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004 Ivo Danihelka (ivo@danihelka.net)
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or
00007  * (at your option) any later version.
00008  */
00009 #include "MessagerAgent.h"
00010 
00011 #include "Log.h"
00012 #include "BaseMsg.h"
00013 #include "BaseListener.h"
00014 #include "NameException.h"
00015 
00016 #include <memory> // for auto_ptr
00017 
00018 //-----------------------------------------------------------------
00019 /**
00020  * Remember listener under his name.
00021  * NOTE: listeners may be added before own_init()
00022  *
00023  * @param listener listener, borowed pointer
00024  */
00025     void
00026 MessagerAgent::addListener(BaseListener *listener)
00027 {
00028     m_listeners[listener->getName()] = listener;
00029 }
00030 //-----------------------------------------------------------------
00031 /**
00032  * Forget listener.
00033  * @param listenerName listener name
00034  */
00035     void
00036 MessagerAgent::removeListener(const std::string &listenerName)
00037 {
00038     m_listeners.erase(listenerName);
00039 }
00040 //-----------------------------------------------------------------
00041 /**
00042  * Forward message to her destination.
00043  * @param msg message, will be deleted
00044  * @throws NameException when listener cannot be found
00045  */
00046 void
00047 MessagerAgent::forwardNewMsg(BaseMsg *msg)
00048 {
00049     std::auto_ptr<BaseMsg> sure_delete(msg);
00050 
00051     const std::string &listenerName = msg->getListenerName();
00052     LOG_DEBUG(ExInfo("received new message")
00053             .addInfo("msg", msg->toString()));
00054 
00055     t_listeners::iterator it = m_listeners.find(listenerName);
00056     if (m_listeners.end() == it) {
00057         throw NameException(ExInfo("cannot find listener")
00058                 .addInfo("name", listenerName));
00059     }
00060 
00061     msg->sendActual(it->second);
00062 }
00063 
00064 

Generated on Wed Jun 1 09:54:31 2005 for Fish Fillets - Next Generation by  doxygen 1.4.2