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/internal/message_manager.h>
25 #include <blackboard/internal/interface_manager.h>
26 #include <blackboard/internal/notifier.h>
27 #include <blackboard/exceptions.h>
28 
29 #include <interface/message.h>
30 #include <interface/interface.h>
31 
32 #include <core/exceptions/software.h>
33 #include <logging/liblogger.h>
34 
35 namespace fawkes {
36 
37 /** @class BlackBoardMessageManager <blackboard/internal/message_manager.h>
38  * BlackBoard message manager.
39  * Transmits messages from reading interface instances to the writer instance
40  * if the interface, if there is any.
41  * @author Tim Niemueller
42  */
43 
44 /** Constructor.
45  * @param notifier BlackBoard notifier to all for events
46  */
48 {
49  __im = NULL;
50  __notifier = notifier;
51 }
52 
53 
54 /** Destructor */
56 {
57 }
58 
59 
60 void
62 {
63  if ( __im == NULL ) {
64  throw NullPointerException("InterfaceManager has not been set for MessageManager");
65  }
66  try {
67  Interface *writer = __im->writer_for_mem_serial(message->recipient());
68  if (__notifier->notify_of_message_received(writer, message)) {
69  writer->msgq_append(message);
70  }
72  Interface *iface = message->interface();
73  LibLogger::log_warn("BlackBoardMessageManager", "Cannot transmit message from sender %s "
74  "via interface %s (type %s), no writing "
75  "instance exists!",
76  message->sender_thread_name(),
77  (iface != NULL) ? iface->id() : "Unknown",
78  (iface != NULL) ? iface->type() : "unknown");
79  throw;
80  }
81 }
82 
83 
84 /** Set interface manager.
85  * @param im interface manager
86  */
87 void
88 BlackBoardMessageManager::set_interface_manager(BlackBoardInterfaceManager *im)
89 {
90  __im = im;
91 }
92 
93 } // end namespace fawkes
const char * sender_thread_name() const
Get sender of message.
Definition: message.cpp:335
Interface * interface() const
Get transmitting interface.
Definition: message.cpp:368
Base class for all messages passed through interfaces in Fawkes BlackBoard.
Definition: message.h:44
Fawkes library namespace.
const char * id() const
Get identifier of interface.
Definition: interface.cpp:661
BlackBoard notifier.
Definition: notifier.h:43
A NULL pointer was supplied where not allowed.
Definition: software.h:34
void msgq_append(Message *message)
Enqueue message.
Definition: interface.cpp:976
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:79
Thrown if no writer interface is alive.
Definition: exceptions.h:145
BlackBoardMessageManager(BlackBoardNotifier *notifier)
Constructor.
const char * type() const
Get type of interface.
Definition: interface.cpp:651
static void log_warn(const char *component, const char *format,...)
Log warning message.
Definition: liblogger.cpp:162
unsigned int recipient() const
Get recipient memory serial.
Definition: message.cpp:275
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:714
virtual void transmit(Message *message)
Transmit message.
BlackBoard interface manager.