coral
A C++ library for distributed co-simulation
|
A slave provider that runs in a background thread. More...
#include "coral/provider/provider.hpp"
Public Member Functions | |
SlaveProvider (const std::string &slaveProviderID, std::vector< std::unique_ptr< SlaveCreator >> &&slaveTypes, const coral::net::ip::Address &networkInterface, coral::net::ip::Port discoveryPort, std::function< void(std::exception_ptr)> exceptionHandler=nullptr) | |
Creates a background thread and runs a slave provider in it. More... | |
~SlaveProvider () CORAL_NOEXCEPT | |
Destructs the SlaveProvider object; requires that Stop() has been called first. More... | |
void | Stop () |
Stops the slave provider. More... | |
A slave provider that runs in a background thread.
coral::provider::SlaveProvider::SlaveProvider | ( | const std::string & | slaveProviderID, |
std::vector< std::unique_ptr< SlaveCreator >> && | slaveTypes, | ||
const coral::net::ip::Address & | networkInterface, | ||
coral::net::ip::Port | discoveryPort, | ||
std::function< void(std::exception_ptr)> | exceptionHandler = nullptr |
||
) |
Creates a background thread and runs a slave provider in it.
[in] | slaveProviderID | A string which is used to uniquely identify the slave provider. Expect trouble if two slave providers have the same ID. |
[in] | slaveTypes | The slave types offered by the slave provider. |
[in] | networkInterface | The name or IP address (in dot-decimal format) of the network interface that should be used, or "*" for all available interfaces. |
[in] | discoveryPort | The UDP port used by others to discover this slave provider. |
[in] | exceptionHandler | A function that will be called if an exception is thrown in the background thread. If no handler is provided, or if the handler itself throws, std::terminate() will be called. If the handler returns without throwing, the background thread will simply terminate. (In this case, it is still necessary to call Stop() in the foreground thread before the SlaveProvider object is destroyed.) Note that the exception handler will be called in the background thread, so care should be taken not to implement it in a thread-unsafe manner. |
coral::provider::SlaveProvider::~SlaveProvider | ( | ) |
Destructs the SlaveProvider object; requires that Stop() has been called first.
If the background thread has not been terminated with Stop() when the destructor runs, std::terminate() is called.
void coral::provider::SlaveProvider::Stop | ( | ) |
Stops the slave provider.
This will send a signal to the background thread that triggers a shutdown of the slave provider. The function blocks until the background thread has terminated.