coral
A C++ library for distributed co-simulation
slave_control_messenger.hpp
Go to the documentation of this file.
1 
15 #ifndef CORAL_BUS_SLAVE_CONTROL_MESSENGER_HPP
16 #define CORAL_BUS_SLAVE_CONTROL_MESSENGER_HPP
17 
18 #include <chrono>
19 #include <functional>
20 #include <memory>
21 #include <system_error>
22 #include <vector>
23 
24 #include "boost/noncopyable.hpp"
25 
26 #include "coral/config.h"
27 
29 #include "coral/net/reactor.hpp"
30 #include "coral/model.hpp"
31 #include "coral/net.hpp"
32 
33 
34 namespace coral
35 {
36 namespace bus
37 {
38 
39 
42 {
44  SLAVE_CONNECTED, // For internal use
49 };
50 
51 
52 // Internal types, intentionally left undefined and undocumented.
53 class PendingSlaveControlConnectionPrivate;
54 struct SlaveControlConnectionPrivate;
55 
56 
64 {
65 public:
70  ~PendingSlaveControlConnection() CORAL_NOEXCEPT;
71 
80  void Close();
81 
89  operator bool() const CORAL_NOEXCEPT;
90 
91 private:
93 };
94 
95 
103 {
104 public:
106  SlaveControlConnection() CORAL_NOEXCEPT;
107 
108  // For internal use.
109  explicit SlaveControlConnection(
111 
114 
116  SlaveControlConnection& operator=(SlaveControlConnection&&) CORAL_NOEXCEPT;
117 
118  ~SlaveControlConnection() CORAL_NOEXCEPT;
119 
124  operator bool() const CORAL_NOEXCEPT;
125 
126  // For internal use.
127  SlaveControlConnectionPrivate& Private();
128 
129 private:
131 };
132 
133 
141 class ISlaveControlMessenger : boost::noncopyable
142 {
143 public:
149 
158  virtual ~ISlaveControlMessenger() CORAL_NOEXCEPT { }
159 
164  virtual SlaveState State() const CORAL_NOEXCEPT = 0;
165 
179  virtual void Close() = 0;
180 
181 
185 
226  virtual void GetDescription(
228  GetDescriptionHandler onComplete) = 0;
229 
230 
232  typedef VoidHandler SetVariablesHandler;
233 
275  virtual void SetVariables(
278  SetVariablesHandler onComplete) = 0;
279 
280 
282  typedef VoidHandler SetPeersHandler;
283 
325  virtual void SetPeers(
328  SetPeersHandler onComplete) = 0;
329 
330 
332  typedef VoidHandler ResendVarsHandler;
333 
371  virtual void ResendVars(
373  ResendVarsHandler onComplete) = 0;
374 
375 
377  typedef VoidHandler StepHandler;
378 
419  virtual void Step(
420  coral::model::StepID stepID,
421  coral::model::TimePoint currentT,
424  StepHandler onComplete) = 0;
425 
426 
428  typedef VoidHandler AcceptStepHandler;
429 
463  virtual void AcceptStep(
465  AcceptStepHandler onComplete) = 0;
466 
480  virtual void Terminate() = 0;
481 };
482 
483 
487 
488 
555  coral::net::Reactor& reactor,
556  const coral::net::SlaveLocator& slaveLocator,
557  int maxAttempts,
559  ConnectToSlaveHandler onComplete);
560 
561 
565 
615  SlaveControlConnection connection,
616  coral::model::SlaveID slaveID,
617  const std::string& slaveName,
618  const SlaveSetup& setup,
620 
621 
622 }} // namespace
623 #endif // header guard
PendingSlaveControlConnection ConnectToSlave(coral::net::Reactor &reactor, const coral::net::SlaveLocator &slaveLocator, int maxAttempts, std::chrono::milliseconds timeout, ConnectToSlaveHandler onComplete)
Initiates a master&#39;s connection to a slave.
Slave is currently performing some action.
Definition: slave_control_messenger.hpp:48
Defines the coral::bus::SlaveSetup class.
VoidHandler SetVariablesHandler
Completion handler type for SetVariables()
Definition: slave_control_messenger.hpp:232
std::function< void(const std::error_code &, const coral::model::SlaveDescription &)> GetDescriptionHandler
Completion handler type for GetDescription()
Definition: slave_control_messenger.hpp:184
VoidHandler StepHandler
Completion handler type for Step()
Definition: slave_control_messenger.hpp:377
Contains the coral::net::Reactor class and related functionality.
A handle for a pending connection to a slave.
Definition: slave_control_messenger.hpp:63
std::unique_ptr< ISlaveControlMessenger > MakeSlaveControlMessenger(SlaveControlConnection connection, coral::model::SlaveID slaveID, const std::string &slaveName, const SlaveSetup &setup, MakeSlaveControlMessengerHandler onComplete)
Returns an object which handles communication with a slave after the connection has been established...
Main module header for coral::net.
Slave has performed a step and published its variables.
Definition: slave_control_messenger.hpp:46
std::function< void(const std::error_code &)> VoidHandler
Basic completion handler type without any arguments aside from an error code.
Definition: slave_control_messenger.hpp:148
Configuration data which is sent to each slave as they are added to the simulation.
Definition: slave_setup.hpp:27
std::function< void(const std::error_code &)> MakeSlaveControlMessengerHandler
Completion handler type for MakeSlaveControlMessenger()
Definition: slave_control_messenger.hpp:564
A handle for an established connection to a slave.
Definition: slave_control_messenger.hpp:102
STL class.
Definition: variable_io.hpp:28
std::function< void(const std::error_code &, SlaveControlConnection)> ConnectToSlaveHandler
Completion handler type for ConnectToSlave()
Definition: slave_control_messenger.hpp:486
VoidHandler AcceptStepHandler
Completion handler type for AcceptStep()
Definition: slave_control_messenger.hpp:428
SlaveState
The various states a slave may be in.
Definition: slave_control_messenger.hpp:41
Slave failed to perform a time step.
Definition: slave_control_messenger.hpp:47
double TimeDuration
The type used to specify (simulation) time durations.
Definition: model.hpp:56
VoidHandler ResendVarsHandler
Completion handler type for ResendVars()
Definition: slave_control_messenger.hpp:332
An interface for classes that implement various versions of the master/slave communication protocol...
Definition: slave_control_messenger.hpp:141
void Close()
Aborts the connection attempt and calls the completion handler with an error code.
An implementation of the reactor pattern.
Definition: reactor.hpp:41
Slave is ready.
Definition: slave_control_messenger.hpp:45
virtual ~ISlaveControlMessenger() CORAL_NOEXCEPT
Destructor.
Definition: slave_control_messenger.hpp:158
Class which represents the network location(s) of a slave.
Definition: net.hpp:292
Main module header for coral::model.
Slave is not yet connected.
Definition: slave_control_messenger.hpp:43
VoidHandler SetPeersHandler
Completion handler type for SetPeers()
Definition: slave_control_messenger.hpp:282
double TimePoint
The type used to specify (simulation) time points.
Definition: model.hpp:42