Fawkes API Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * message_manager.cpp - BlackBoard message manager 00004 * 00005 * Created: Fri Oct 06 11:36:24 2006 00006 * Copyright 2006-2007 Tim Niemueller [www.niemueller.de] 00007 * 00008 ****************************************************************************/ 00009 00010 /* This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. A runtime exception applies to 00014 * this software (see LICENSE.GPL_WRE file mentioned below for details). 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Library General Public License for more details. 00020 * 00021 * Read the full text in the LICENSE.GPL_WRE file in the doc directory. 00022 */ 00023 00024 #include <blackboard/internal/message_manager.h> 00025 #include <blackboard/internal/interface_manager.h> 00026 #include <blackboard/internal/notifier.h> 00027 #include <blackboard/exceptions.h> 00028 00029 #include <interface/message.h> 00030 #include <interface/interface.h> 00031 00032 #include <core/exceptions/software.h> 00033 #include <utils/logging/liblogger.h> 00034 00035 namespace fawkes { 00036 00037 /** @class BlackBoardMessageManager <blackboard/internal/message_manager.h> 00038 * BlackBoard message manager. 00039 * Transmits messages from reading interface instances to the writer instance 00040 * if the interface, if there is any. 00041 * @author Tim Niemueller 00042 */ 00043 00044 /** Constructor. 00045 * @param notifier BlackBoard notifier to all for events 00046 */ 00047 BlackBoardMessageManager::BlackBoardMessageManager(BlackBoardNotifier *notifier) 00048 { 00049 __im = NULL; 00050 __notifier = notifier; 00051 } 00052 00053 00054 /** Destructor */ 00055 BlackBoardMessageManager::~BlackBoardMessageManager() 00056 { 00057 } 00058 00059 00060 void 00061 BlackBoardMessageManager::transmit(Message *message) 00062 { 00063 if ( __im == NULL ) { 00064 throw NullPointerException("InterfaceManager has not been set for MessageManager"); 00065 } 00066 try { 00067 Interface *writer = __im->writer_for_mem_serial(message->recipient()); 00068 if (__notifier->notify_of_message_received(writer, message)) { 00069 message->ref(); 00070 writer->msgq_append(message); 00071 } 00072 } catch (BlackBoardNoWritingInstanceException &e) { 00073 Interface *iface = message->interface(); 00074 LibLogger::log_warn("BlackBoardMessageManager", "Cannot transmit message from sender %s " 00075 "via interface %s (type %s), no writing " 00076 "instance exists!", 00077 message->sender_thread_name(), 00078 (iface != NULL) ? iface->id() : "Unknown", 00079 (iface != NULL) ? iface->type() : "unknown"); 00080 throw; 00081 } 00082 } 00083 00084 00085 /** Set interface manager. 00086 * @param im interface manager 00087 */ 00088 void 00089 BlackBoardMessageManager::set_interface_manager(BlackBoardInterfaceManager *im) 00090 { 00091 __im = im; 00092 } 00093 00094 } // end namespace fawkes