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::comms_fault_handler::CommsFaultHandler * getCommsFaultHandler()
Gets communications fault handler.
Interface definition for communications fault handler. Defines the type of communcations faults that ...
Interface definition for message handlers. The interface defines the callback function that should ex...
industrial::message_handler::MessageHandler * getHandler(int msg_type)
Gets message handler for specific message type.
Defines an interface and common methods for sending simple messages (see simple_message). This interface makes a bare minimum of assumptions:
void setConnection(industrial::smpl_msg_connection::SmplMsgConnection *connection)
Sets connection manager.
industrial::simple_comms_fault_handler::SimpleCommsFaultHandler & getDefaultCommsFaultHandler()
Gets default communications fault handler.
industrial::message_handler::MessageHandler * handlers_[MAX_NUM_HANDLERS]
buffer of handlers
unsigned int getNumHandlers()
Gets number of handlers.
void spinOnce()
Perform an single execution of the message manager (a single receive and send (if required) ...
void spin()
Perform a indefinite execution of the message manager.
bool add(industrial::message_handler::MessageHandler *handler, bool allow_replace=false)
Adds a message handler to the manager.
Message handler that handles ping messages.
Definition: ping_handler.h:60
The message manager handles communications for a simple server.
unsigned int num_handlers_
Number of handlers.
Default implementation of comms fault handler. This class attempts to reconnect if the connection is ...
industrial::smpl_msg_connection::SmplMsgConnection * getConnection()
Gets connection for manager.
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...
void setNumHandlers(unsigned int num_handlers)
Sets message type that callback expects.
industrial::ping_handler::PingHandler ping_hndlr_
Internal ping handle (by default every message manager can handle pings)
static const unsigned int MAX_NUM_HANDLERS
Maximum number of handlers.
int getHandlerIdx(int msg_type)
Gets index of message handler for specific message type.
unsigned int getMaxNumHandlers()
Gets maximumn number of handlers.
industrial::smpl_msg_connection::SmplMsgConnection * connection_
Reference to reply connection (called if incoming message requires a reply)
void setCommsFaultHandler(industrial::comms_fault_handler::CommsFaultHandler *handler)
Gets communications fault handler.
bool init(industrial::smpl_msg_connection::SmplMsgConnection *connection)
Class initializer.
industrial::comms_fault_handler::CommsFaultHandler * comms_hndlr_
Reference to comms handler.
industrial::ping_handler::PingHandler & getPingHandler()
Gets ping handler.


simple_message
Author(s): Shaun Edwards
autogenerated on Mon Feb 28 2022 22:34:36