class NrpCoreServer¶
Overview¶
NRP Server class, responsible for handling simulation control requests coming from the client application or script. More…
#include <nrp_core_server.h> class NrpCoreServer: public Service { public: // enums enum RequestType; // construction NrpCoreServer( const std::string& address, std::shared_ptr<SimulationManager>&& manager ); // methods void runServerLoop(); void stopServerLoop(); };
Detailed Documentation¶
NRP Server class, responsible for handling simulation control requests coming from the client application or script.
The class has two roles:
receive simulation control requests from the client application
relay received requests to the main thread of NRP Core and wait for response
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.
Construction¶
NrpCoreServer( const std::string& address, std::shared_ptr<SimulationManager>&& manager )
Constructor. Spawns an instance of gRPC server with given address.
Parameters:
address |
Address of the gRPC server |
manager |
SimulationManager which actually perform actions from requests |
Methods¶
void runServerLoop()
Enters server loop in which requests are processed sequentially.
void stopServerLoop()
Stops server loop.