template class EngineGrpcClient

Overview

#include <engine_grpc_client.h>

template <class ENGINE, const char* SCHEMA>
class EngineGrpcClient: public EngineClient {
public:
    // construction

    EngineGrpcClient(
        nlohmann::json& config,
        ProcessLauncherInterface::unique_ptr&& launcher
    );

    // methods

    virtual pid_t launchEngine();
    void connectToServer();
    void sendInitializeCommand(const nlohmann::json& data);
    void sendResetCommand();
    void sendShutdownCommand(const nlohmann::json& data);
    virtual SimulationTime runLoopStepCallback(const SimulationTime timeStep);
    virtual datapacks_vector_t getDataPacksFromEngine(const datapack_identifiers_set_t& datapackIdentifiers);
    virtual void sendDataPacksToEngine(const datapacks_set_t& dataPacks);
    virtual const std::vector<std::string> engineProcStartParams() const;
    std::string tryBind(const std::string& address);
    void validateServerAddress();
    const std::string serverAddress() const;
};

// direct descendants

class GazeboEngineGrpcNRPClient;
class PythonEngineGRPCNRPClient;

Inherited Members

public:
    // typedefs

    typedef std::shared_ptr<T> shared_ptr;
    typedef std::shared_ptr<const T> const_shared_ptr;
    typedef std::unique_ptr<T> unique_ptr;
    typedef std::unique_ptr<const T> const_unique_ptr;
    typedef ENGINE engine_t;

    // classes

    template <const char* ENGINE_TYPE>
    class EngineLauncher;

    // methods

    virtual const std::string engineName() const = 0;
    virtual const nlohmann::json& engineConfig() const = 0;
    virtual nlohmann::json& engineConfig() = 0;
    virtual const std::vector<std::string> engineProcStartParams() const = 0;
    virtual pid_t launchEngine();
    virtual void initialize() = 0;
    virtual void reset() = 0;
    virtual void shutdown() = 0;
    virtual SimulationTime getEngineTimestep() const = 0;
    virtual SimulationTime getEngineTime() const = 0;
    virtual const std::string engineSchema() const = 0;
    virtual void runLoopStepAsync(SimulationTime timeStep) = 0;
    virtual void runLoopStepAsyncGet(SimulationTime timeOut) = 0;
    virtual void sendDataPacksToEngine(const datapacks_set_t& dataPacks) = 0;
    virtual datapacks_vector_t getDataPacksFromEngine(const datapack_identifiers_set_t& datapackIdentifiers) = 0;
    virtual const std::string engineName() const;
    virtual SimulationTime getEngineTimestep() const;
    virtual const nlohmann::json& engineConfig() const;
    virtual nlohmann::json& engineConfig();
    virtual const std::string engineSchema() const;
    virtual SimulationTime getEngineTime() const;
    virtual void runLoopStepAsync(SimulationTime timeStep);
    virtual void runLoopStepAsyncGet(SimulationTime timeOut);

Detailed Documentation

Methods

virtual pid_t launchEngine()

Launch the engine.

Returns:

Returns engine process ID on success, throws on failure

virtual SimulationTime runLoopStepCallback(const SimulationTime timeStep)

Executes a single loop step.

This function is going to be called by runLoopStep using std::async. It will be executed by a worker thread, which allows for runLoopStepFunction from multiple engines to run simultaneously.

Parameters:

timeStep

A time step by which the simulation should be advanced

Returns:

Engine time after loop step execution

virtual datapacks_vector_t getDataPacksFromEngine(const datapack_identifiers_set_t& datapackIdentifiers)

Gets requested datapacks from engine.

Parameters:

datapackNames

All requested datapack ids

Throws

on error

Returns:

Returns all requested datapacks

virtual void sendDataPacksToEngine(const datapacks_set_t& dataPacks)

Sends datapacks to engine.

Parameters:

datapacksArray

Array of datapacks that will be send to the engine

Throws

on error

Returns:

Returns SUCCESS if all datapacks could be handles, ERROR otherwise

virtual const std::vector<std::string> engineProcStartParams() const

Get all Engine Process Startup parameters.

void validateServerAddress()

Validates if server address is already in use.

const std::string serverAddress() const

Returns the address used by the gRPC server.