NRP Server class, responsible for handling simulation control requests coming from the client application or script. More...
#include <nrp_core_server.h>
Public Types | |
enum | RequestType { RequestType::None, RequestType::Initialize, RequestType::RunLoop, RequestType::RunUntilTimeout, RequestType::StopLoop, RequestType::Reset, RequestType::Shutdown } |
enum with possible request types to be processed by SimulationManager More... | |
Public Member Functions | |
NrpCoreServer (const std::string &address, std::shared_ptr< SimulationManager > &&manager) | |
Constructor. Spawns an instance of gRPC server with given address. More... | |
void | runServerLoop () |
Enters server loop in which requests are processed sequentially. More... | |
void | stopServerLoop () |
Stops server loop. More... | |
NRP Server class, responsible for handling simulation control requests coming from the client application or script.
The class has two roles:
The class is an instance of gRPC Service, which means that it will have a pool of worker threads. Every request coming from the client will be handled by a separate thread from the pool. The natural approach to request handling would be to call proper methods of the SimulationManager directly from the callbacks (for example, SimulationManager::initFTILoop() from NrpCoreServer::init()). This proved to cause problems with certain python libraries, like OpenCV, that may be used in the transceiver functions. The problem seems to arise from the fact, that the python code was executed in a worker thread, and not in the thread that spawned the python interpreter (the main thread of NRP Core). The solution is to create a producer-consumer relation between the NRP Server threads and the main thread. The NRP Server relays (produces) the requests to the main thread, which consumes them and returns a status back to the NRP Server.
|
strong |
enum with possible request types to be processed by SimulationManager
Enumerator | |
---|---|
None | |
Initialize | |
RunLoop | |
RunUntilTimeout | |
StopLoop | |
Reset | |
Shutdown |
NrpCoreServer::NrpCoreServer | ( | const std::string & | address, |
std::shared_ptr< SimulationManager > && | manager | ||
) |
Constructor. Spawns an instance of gRPC server with given address.
address | Address of the gRPC server |
manager | SimulationManager which actually perform actions from requests |
void NrpCoreServer::runServerLoop | ( | ) |
Enters server loop in which requests are processed sequentially.
void NrpCoreServer::stopServerLoop | ( | ) |
Stops server loop.