coral
A C++ library for distributed co-simulation
Public Member Functions | List of all members
coral::provider::SlaveProvider Class Reference

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...
 

Detailed Description

A slave provider that runs in a background thread.

Constructor & Destructor Documentation

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.

Parameters
[in]slaveProviderIDA string which is used to uniquely identify the slave provider. Expect trouble if two slave providers have the same ID.
[in]slaveTypesThe slave types offered by the slave provider.
[in]networkInterfaceThe name or IP address (in dot-decimal format) of the network interface that should be used, or "*" for all available interfaces.
[in]discoveryPortThe UDP port used by others to discover this slave provider.
[in]exceptionHandlerA 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.

Member Function Documentation

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.


The documentation for this class was generated from the following file: