Fawkes API  Fawkes Development Version
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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  message->ref();
70  writer->msgq_append(message);
71  }
73  Interface *iface = message->interface();
74  LibLogger::log_warn("BlackBoardMessageManager", "Cannot transmit message from sender %s "
75  "via interface %s (type %s), no writing "
76  "instance exists!",
77  message->sender_thread_name(),
78  (iface != NULL) ? iface->id() : "Unknown",
79  (iface != NULL) ? iface->type() : "unknown");
80  throw;
81  }
82 }
83 
84 
85 /** Set interface manager.
86  * @param im interface manager
87  */
88 void
89 BlackBoardMessageManager::set_interface_manager(BlackBoardInterfaceManager *im)
90 {
91  __im = im;
92 }
93 
94 } // end namespace fawkes