Fawkes API Fawkes Development Version
message_manager.cpp
1
2/***************************************************************************
3 * message_manager.cpp - BlackBoard message manager
4 *
5 * Created: Fri Oct 06 11:36:24 2006
6 * Copyright 2006-2007 Tim Niemueller [www.niemueller.de]
7 *
8 ****************************************************************************/
9
10/* This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version. A runtime exception applies to
14 * this software (see LICENSE.GPL_WRE file mentioned below for details).
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Library General Public License for more details.
20 *
21 * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22 */
23
24#include <blackboard/exceptions.h>
25#include <blackboard/internal/interface_manager.h>
26#include <blackboard/internal/message_manager.h>
27#include <blackboard/internal/notifier.h>
28#include <core/exceptions/software.h>
29#include <interface/interface.h>
30#include <interface/message.h>
31#include <logging/liblogger.h>
32
33namespace fawkes {
34
35/** @class BlackBoardMessageManager <blackboard/internal/message_manager.h>
36 * BlackBoard message manager.
37 * Transmits messages from reading interface instances to the writer instance
38 * if the interface, if there is any.
39 * @author Tim Niemueller
40 */
41
42/** Constructor.
43 * @param notifier BlackBoard notifier to all for events
44 */
46{
47 im_ = NULL;
48 notifier_ = notifier;
49}
50
51/** Destructor */
53{
54}
55
56void
58{
59 if (im_ == NULL) {
60 throw NullPointerException("InterfaceManager has not been set for MessageManager");
61 }
62 try {
63 Interface *writer = im_->writer_for_mem_serial(message->recipient());
64 if (notifier_->notify_of_message_received(writer, message)) {
65 writer->msgq_append(message);
66 }
68 Interface *iface = message->interface();
69 LibLogger::log_warn("BlackBoardMessageManager",
70 "Cannot transmit message from sender %s "
71 "via interface %s (type %s), no writing "
72 "instance exists!",
73 message->sender_thread_name(),
74 (iface != NULL) ? iface->id() : "Unknown",
75 (iface != NULL) ? iface->type() : "unknown");
76 throw;
77 }
78}
79
80/** Set interface manager.
81 * @param im interface manager
82 */
83void
84BlackBoardMessageManager::set_interface_manager(BlackBoardInterfaceManager *im)
85{
86 im_ = im;
87}
88
89} // end namespace fawkes
BlackBoard interface manager.
virtual void transmit(Message *message)
Transmit message.
BlackBoardMessageManager(BlackBoardNotifier *notifier)
Constructor.
Thrown if no writer interface is alive.
Definition: exceptions.h:151
BlackBoard notifier.
Definition: notifier.h:44
bool notify_of_message_received(const Interface *interface, Message *message)
Notify of message received Notify all subscribers of the given interface of an incoming message This ...
Definition: notifier.cpp:744
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:80
const char * type() const
Get type of interface.
Definition: interface.cpp:652
void msgq_append(Message *message)
Enqueue message.
Definition: interface.cpp:986
const char * id() const
Get identifier of interface.
Definition: interface.cpp:661
static void log_warn(const char *component, const char *format,...)
Log warning message.
Definition: liblogger.cpp:156
Base class for all messages passed through interfaces in Fawkes BlackBoard.
Definition: message.h:44
unsigned int recipient() const
Get recipient memory serial.
Definition: message.cpp:271
Interface * interface() const
Get transmitting interface.
Definition: message.cpp:372
const char * sender_thread_name() const
Get sender of message.
Definition: message.cpp:327
A NULL pointer was supplied where not allowed.
Definition: software.h:32
Fawkes library namespace.