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
*/
47
BlackBoardMessageManager::BlackBoardMessageManager
(
BlackBoardNotifier
*notifier)
48
{
49
__im = NULL;
50
__notifier = notifier;
51
}
52
53
54
/** Destructor */
55
BlackBoardMessageManager::~BlackBoardMessageManager
()
56
{
57
}
58
59
60
void
61
BlackBoardMessageManager::transmit
(
Message
*message)
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
}
71
}
catch
(
BlackBoardNoWritingInstanceException
&e) {
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
fawkes::Message::sender_thread_name
const char * sender_thread_name() const
Get sender of message.
Definition:
message.cpp:335
fawkes::Message::interface
Interface * interface() const
Get transmitting interface.
Definition:
message.cpp:368
fawkes::Message
Base class for all messages passed through interfaces in Fawkes BlackBoard.
Definition:
message.h:44
fawkes
Fawkes library namespace.
fawkes::Interface::id
const char * id() const
Get identifier of interface.
Definition:
interface.cpp:661
fawkes::BlackBoardNotifier
BlackBoard notifier.
Definition:
notifier.h:43
fawkes::NullPointerException
A NULL pointer was supplied where not allowed.
Definition:
software.h:34
fawkes::Interface::msgq_append
void msgq_append(Message *message)
Enqueue message.
Definition:
interface.cpp:976
fawkes::Interface
Base class for all Fawkes BlackBoard interfaces.
Definition:
interface.h:79
fawkes::BlackBoardNoWritingInstanceException
Thrown if no writer interface is alive.
Definition:
exceptions.h:145
fawkes::BlackBoardMessageManager::BlackBoardMessageManager
BlackBoardMessageManager(BlackBoardNotifier *notifier)
Constructor.
Definition:
message_manager.cpp:47
fawkes::Interface::type
const char * type() const
Get type of interface.
Definition:
interface.cpp:651
fawkes::LibLogger::log_warn
static void log_warn(const char *component, const char *format,...)
Log warning message.
Definition:
liblogger.cpp:162
fawkes::Message::recipient
unsigned int recipient() const
Get recipient memory serial.
Definition:
message.cpp:275
fawkes::BlackBoardNotifier::notify_of_message_received
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
fawkes::BlackBoardMessageManager::~BlackBoardMessageManager
~BlackBoardMessageManager()
Destructor.
Definition:
message_manager.cpp:55
fawkes::BlackBoardMessageManager::transmit
virtual void transmit(Message *message)
Transmit message.
Definition:
message_manager.cpp:61
fawkes::BlackBoardInterfaceManager
BlackBoard interface manager.
Definition:
interface_manager.h:47
src
libs
blackboard
internal
message_manager.cpp
Generated by
1.8.13