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 
148  bool Update(
149  coral::model::StepID stepID,
150  std::chrono::milliseconds timeout);
151 
166  const coral::model::ScalarValue& Value(const coral::model::Variable& variable)
167  const;
168 
169 private:
171  ValueQueue;
172 
173  // A hash function for Variable objects, so we can put them in a
174  // std::unordered_map (below)
175  struct VariableHash
176  {
177  std::size_t operator()(const coral::model::Variable& v) const
178  {
179  return static_cast<std::size_t>((v.Slave() << 16) + v.ID());
180  }
181  };
182 
183  coral::model::StepID m_currentStepID;
186 };
187 
188 
189 }} // namespace
190 #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.