coral
A C++ library for distributed co-simulation
slave_provider_comm.hpp
Go to the documentation of this file.
1 
10 #ifndef CORAL_BUS_SP_INFO_CLIENT_HPP
11 #define CORAL_BUS_SP_INFO_CLIENT_HPP
12 
13 #include <chrono>
14 #include <cstdint>
15 #include <functional>
16 #include <memory>
17 #include <string>
18 #include <system_error>
19 
20 #include "coral/config.h"
21 #include "coral/model.hpp"
22 #include "coral/net.hpp"
23 #include "coral/net/reactor.hpp"
24 #include "coral/net/reqrep.hpp"
25 
26 
27 namespace coral
28 {
29 namespace bus
30 {
31 
32 
37 {
38 public:
50  coral::net::Reactor& reactor,
51  const coral::net::ip::Endpoint& endpoint);
52 
54  ~SlaveProviderClient() CORAL_NOEXCEPT;
55 
57  SlaveProviderClient& operator=(const SlaveProviderClient&) = delete;
58 
60  SlaveProviderClient(SlaveProviderClient&&) CORAL_NOEXCEPT;
61 
63  SlaveProviderClient& operator=(SlaveProviderClient&&) CORAL_NOEXCEPT;
64 
66  typedef std::function<void(
67  const std::error_code& error,
68  const coral::model::SlaveTypeDescription* slaveTypes,
69  std::size_t slaveTypeCount)>
71 
81  void GetSlaveTypes(
82  GetSlaveTypesHandler onComplete,
84 
86  typedef std::function<void(
87  const std::error_code& ec,
88  const coral::net::SlaveLocator& slaveLocator,
89  const std::string& errorMessage)>
91 
106  void InstantiateSlave(
107  const std::string& slaveTypeUUID,
108  std::chrono::milliseconds instantiationTimeout,
109  InstantiateSlaveHandler onComplete,
111 
112 private:
113  class Private;
114  std::unique_ptr<Private> m_private;
115 };
116 
117 
123 {
124 public:
126  virtual int GetSlaveTypeCount() const CORAL_NOEXCEPT = 0;
127 
129  virtual coral::model::SlaveTypeDescription GetSlaveType(int index) const = 0;
130 
133  const std::string& slaveTypeUUID,
134  std::chrono::milliseconds timeout) = 0;
135 
136  virtual ~SlaveProviderOps() CORAL_NOEXCEPT { }
137 };
138 
139 
152  std::shared_ptr<SlaveProviderOps> slaveProvider);
153 
154 
155 }} // namespace
156 #endif // header guard
void InstantiateSlave(const std::string &slaveTypeUUID, std::chrono::milliseconds instantiationTimeout, InstantiateSlaveHandler onComplete, std::chrono::milliseconds requestTimeout=std::chrono::milliseconds(0))
Requests the instantiation of a slave.
std::function< void(const std::error_code &error, const coral::model::SlaveTypeDescription *slaveTypes, std::size_t slaveTypeCount)> GetSlaveTypesHandler
Completion handler type for GetSlaveTypes().
Definition: slave_provider_comm.hpp:70
Contains the coral::net::Reactor class and related functionality.
Main module header for coral::net.
STL class.
void GetSlaveTypes(GetSlaveTypesHandler onComplete, std::chrono::milliseconds timeout)
Requests a list of slave types provided.
STL class.
An interface for the services offered by a slave provider, for use with MakeSlaveProviderServer().
Definition: slave_provider_comm.hpp:122
SlaveProviderClient(coral::net::Reactor &reactor, const coral::net::ip::Endpoint &endpoint)
Constructor.
A description of a slave type.
Definition: model.hpp:148
An object which identifies an endpoint for Internet communication as a combination of an address and ...
Definition: net.hpp:209
Definition: variable_io.hpp:28
void MakeSlaveProviderServer(coral::net::reqrep::Server &server, std::shared_ptr< SlaveProviderOps > slaveProvider)
Creates a server to be used by slave providers to handle incoming requests from a SlaveProviderClient...
Module header for coral::net::reqrep.
~SlaveProviderClient() CORAL_NOEXCEPT
Destructor.
A class for communicating with a single slave provider.
Definition: slave_provider_comm.hpp:36
A generic server class for simple request-reply protocols.
Definition: reqrep.hpp:325
An implementation of the reactor pattern.
Definition: reactor.hpp:41
Class which represents the network location(s) of a slave.
Definition: net.hpp:292
Main module header for coral::model.
std::function< void(const std::error_code &ec, const coral::net::SlaveLocator &slaveLocator, const std::string &errorMessage)> InstantiateSlaveHandler
Completion handler type for InstantiateSlave().
Definition: slave_provider_comm.hpp:90