coral
A C++ library for distributed co-simulation
variable_io.hpp
Go to the documentation of this file.
1 
11 #ifndef CORAL_BUS_VARIABLE_IO_HPP_INCLUDED
12 #define CORAL_BUS_VARIABLE_IO_HPP_INCLUDED
13 
14 #include <chrono>
15 #include <memory>
16 #include <queue>
17 #include <string>
18 #include <unordered_map>
19 
20 #include "coral/model.hpp"
21 #include "coral/net.hpp"
22 
23 
24 // Forward declaration to avoid dependency on ZMQ headers
25 namespace zmq { class socket_t; }
26 
27 
28 namespace coral
29 {
30 namespace bus
31 {
32 
33 
36 {
37 public:
44 
55  void Bind(const coral::net::Endpoint& endpoint);
56 
65  coral::net::Endpoint BoundEndpoint() const;
66 
83  void Publish(
84  coral::model::StepID stepID,
85  coral::model::SlaveID slaveID,
86  coral::model::VariableID variableID,
88 
89 private:
91 };
92 
93 
96 {
97 public:
104 
118  void Connect(
119  const coral::net::Endpoint* endpoints,
120  std::size_t endpointsSize);
121 
127  void Subscribe(const coral::model::Variable& variable);
128 
134  void Unsubscribe(const coral::model::Variable& variable);
135 
147  bool Update(
148  coral::model::StepID stepID,
149  std::chrono::milliseconds timeout);
150 
165  const coral::model::ScalarValue& Value(const coral::model::Variable& variable)
166  const;
167 
168 private:
170  ValueQueue;
171 
172  // A hash function for Variable objects, so we can put them in a
173  // std::unordered_map (below)
174  struct VariableHash
175  {
176  std::size_t operator()(const coral::model::Variable& v) const
177  {
178  return static_cast<std::size_t>((v.Slave() << 16) + v.ID());
179  }
180  };
181 
182  coral::model::StepID m_currentStepID;
185 };
186 
187 
188 }} // namespace
189 #endif // header guard
An object that identifies a variable in a simulation, and which consists of a slave ID and a variable...
Definition: model.hpp:270
Main module header for coral::net.
boost::variant< double, int, bool, std::string > ScalarValue
An algebraic type that can hold values of all supported data types.
Definition: model.hpp:259
A class which handles subscriptions to and receiving of variable values.
Definition: variable_io.hpp:95
A protocol/transport independent endpoint address specification.
Definition: net.hpp:34
Definition: variable_io.hpp:28
A class which handles publishing of variable values on the network.
Definition: variable_io.hpp:35
STL class.
Definition: variable_io.hpp:25
Main module header for coral::model.