message_manager.h
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2011, Southwest Research Institute
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  * * Neither the name of the Southwest Research Institute, nor the names
16  * of its contributors may be used to endorse or promote products derived
17  * from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef MESSAGE_MANAGER_H
33 #define MESSAGE_MANAGER_H
34 
35 #ifndef FLATHEADERS
41 #else
42 #include "smpl_msg_connection.h"
43 #include "message_handler.h"
44 #include "ping_handler.h"
45 #include "comms_fault_handler.h"
47 #endif
48 
49 
50 namespace industrial
51 {
52 namespace message_manager
53 {
54 
58 //* MessageManager
75 {
76 
77 public:
78 
83 
88 
99 
114 
119  void spinOnce();
120 
124  void spin();
125 
134  bool add(industrial::message_handler::MessageHandler* handler, bool allow_replace = false);
135 
141  unsigned int getNumHandlers()
142  {
143  return this->num_handlers_;
144  }
145 
151  unsigned int getMaxNumHandlers()
152  {
153  return this->MAX_NUM_HANDLERS;
154  }
155 
156 
163  {
164  return this->comms_hndlr_;
165  }
166 
173  {
174  this->comms_hndlr_ = handler;
175  }
176 
177 
178 private:
179 
186  static const unsigned int MAX_NUM_HANDLERS = 64;
187 
192 
197 
202 
208 
213 
217  unsigned int num_handlers_;
218 
227 
235  int getHandlerIdx(int msg_type);
236 
243  {
244  return this->def_comms_hndlr_;
245  }
252  {
253  return this->ping_hndlr_;
254  }
255  ;
256 
263  {
264  this->connection_ = connection;
265  }
266  ;
267 
274  {
275  return this->connection_;
276  }
277  ;
278 
284  void setNumHandlers(unsigned int num_handlers)
285  {
286  this->num_handlers_ = num_handlers;
287  }
288  ;
289 
290 };
291 
292 } // namespace industrial
293 } // namespace message_manager
294 
295 #endif //MESSAGE_MANAGER
industrial::message_manager::MessageManager::getPingHandler
industrial::ping_handler::PingHandler & getPingHandler()
Gets ping handler.
Definition: message_manager.h:251
industrial::message_manager::MessageManager::connection_
industrial::smpl_msg_connection::SmplMsgConnection * connection_
Reference to reply connection (called if incoming message requires a reply)
Definition: message_manager.h:196
industrial::message_manager::MessageManager::MessageManager
MessageManager()
Constructor.
Definition: message_manager.cpp:65
industrial::message_manager::MessageManager::add
bool add(industrial::message_handler::MessageHandler *handler, bool allow_replace=false)
Adds a message handler to the manager.
Definition: message_manager.cpp:206
industrial::message_manager::MessageManager::getCommsFaultHandler
industrial::comms_fault_handler::CommsFaultHandler * getCommsFaultHandler()
Gets communications fault handler.
Definition: message_manager.h:162
industrial::message_handler::MessageHandler
Interface definition for message handlers. The interface defines the callback function that should ex...
Definition: message_handler.h:61
industrial::message_manager::MessageManager::num_handlers_
unsigned int num_handlers_
Number of handlers.
Definition: message_manager.h:217
industrial
Definition: byte_array.h:45
industrial::message_manager::MessageManager::~MessageManager
~MessageManager()
Destructor.
Definition: message_manager.cpp:75
industrial::message_manager::MessageManager::MAX_NUM_HANDLERS
static const unsigned int MAX_NUM_HANDLERS
Maximum number of handlers.
Definition: message_manager.h:186
industrial::message_manager::MessageManager::ping_hndlr_
industrial::ping_handler::PingHandler ping_hndlr_
Internal ping handle (by default every message manager can handle pings)
Definition: message_manager.h:201
industrial::message_manager::MessageManager::getHandler
industrial::message_handler::MessageHandler * getHandler(int msg_type)
Gets message handler for specific message type.
Definition: message_manager.cpp:249
industrial::message_manager::MessageManager::setConnection
void setConnection(industrial::smpl_msg_connection::SmplMsgConnection *connection)
Sets connection manager.
Definition: message_manager.h:262
message_handler.h
industrial::message_manager::MessageManager::def_comms_hndlr_
industrial::simple_comms_fault_handler::SimpleCommsFaultHandler def_comms_hndlr_
Internal default comms handler (this is used if a communications fault handler is not specified as pa...
Definition: message_manager.h:207
industrial::message_manager::MessageManager::getDefaultCommsFaultHandler
industrial::simple_comms_fault_handler::SimpleCommsFaultHandler & getDefaultCommsFaultHandler()
Gets default communications fault handler.
Definition: message_manager.h:242
industrial::message_manager::MessageManager::comms_hndlr_
industrial::comms_fault_handler::CommsFaultHandler * comms_hndlr_
Reference to comms handler.
Definition: message_manager.h:212
ping_handler.h
industrial::simple_comms_fault_handler::SimpleCommsFaultHandler
Default implementation of comms fault handler. This class attempts to reconnect if the connection is ...
Definition: simple_comms_fault_handler.h:57
industrial::message_manager::MessageManager::spin
void spin()
Perform a indefinite execution of the message manager.
Definition: message_manager.cpp:188
industrial::message_manager::MessageManager::getConnection
industrial::smpl_msg_connection::SmplMsgConnection * getConnection()
Gets connection for manager.
Definition: message_manager.h:273
industrial::message_manager::MessageManager::setNumHandlers
void setNumHandlers(unsigned int num_handlers)
Sets message type that callback expects.
Definition: message_manager.h:284
industrial::smpl_msg_connection::SmplMsgConnection
Defines an interface and common methods for sending simple messages (see simple_message)....
Definition: smpl_msg_connection.h:61
industrial::message_manager::MessageManager
The message manager handles communications for a simple server.
Definition: message_manager.h:74
industrial::message_manager::MessageManager::init
bool init(industrial::smpl_msg_connection::SmplMsgConnection *connection)
Class initializer.
Definition: message_manager.cpp:80
comms_fault_handler.h
industrial::message_manager::MessageManager::getHandlerIdx
int getHandlerIdx(int msg_type)
Gets index of message handler for specific message type.
Definition: message_manager.cpp:259
industrial::message_manager::MessageManager::getMaxNumHandlers
unsigned int getMaxNumHandlers()
Gets maximumn number of handlers.
Definition: message_manager.h:151
industrial::message_manager::MessageManager::setCommsFaultHandler
void setCommsFaultHandler(industrial::comms_fault_handler::CommsFaultHandler *handler)
Gets communications fault handler.
Definition: message_manager.h:172
industrial::message_manager::MessageManager::spinOnce
void spinOnce()
Perform an single execution of the message manager (a single receive and send (if required)
Definition: message_manager.cpp:136
industrial::comms_fault_handler::CommsFaultHandler
Interface definition for communications fault handler. Defines the type of communcations faults that ...
Definition: comms_fault_handler.h:46
simple_comms_fault_handler.h
industrial::message_manager::MessageManager::handlers_
industrial::message_handler::MessageHandler * handlers_[MAX_NUM_HANDLERS]
buffer of handlers
Definition: message_manager.h:191
industrial::message_manager::MessageManager::getNumHandlers
unsigned int getNumHandlers()
Gets number of handlers.
Definition: message_manager.h:141
industrial::ping_handler::PingHandler
Message handler that handles ping messages.
Definition: ping_handler.h:60
smpl_msg_connection.h


simple_message
Author(s): Shaun Edwards
autogenerated on Wed Mar 2 2022 00:24:53