class EngineProtoWrapper

Overview

Abstract class defining an interface to interact with an Engine with data exchange via protobuf messages. More…

#include <engine_proto_wrapper.h>

class EngineProtoWrapper {
public:
    // typedefs

    typedef std::timed_mutex mutex_t;
    typedef std::unique_lock<EngineProtoWrapper::mutex_t> lock_t;

    // construction

    EngineProtoWrapper();

    EngineProtoWrapper(
        const std::string& engineName,
        const std::string& protobufPluginsPath,
        const nlohmann::json& protobufPlugins
    );

    // methods

    void registerDataPack(
        const std::string& datapackName,
        ProtoDataPackController* interface
    );

    unsigned getNumRegisteredDataPacks();
    std::vector<std::string> getNamesRegisteredDataPacks();
    const std::string& getEngineName();
    virtual bool initRunFlag() const = 0;
    virtual bool shutdownFlag() const = 0;
    virtual void initialize(const nlohmann::json& data) = 0;
    virtual void reset() = 0;
    virtual void shutdown() = 0;
    virtual SimulationTime runLoopStep(const SimulationTime timeStep) = 0;
    void setDataPacks(const EngineGrpc::SetDataPacksRequest& data);
    void setDataPack(const EngineGrpc::DataPackMessage& dataPack);
    std::unique_ptr<gpb::Message> unpackFromAny(const gpb::Any& data);

    virtual void getDataPacks(
        const EngineGrpc::GetDataPacksRequest& request,
        EngineGrpc::GetDataPacksReply* reply
    );

    bool getDataPack(const std::string& name, EngineGrpc::DataPackMessage* dpMsg);

    void setDataPackMessageData(
        gpb::Message* data,
        EngineGrpc::DataPackMessage* dpMsg
    );
};

// direct descendants

class NRPGazeboCommunicationController;

Detailed Documentation

Abstract class defining an interface to interact with an Engine with data exchange via protobuf messages.

Derived classes are responsible for implementing simulation initialization, shutdown and run step methods.

Construction

EngineProtoWrapper()

No dummy wrappers, only those with name.

EngineProtoWrapper(
    const std::string& engineName,
    const std::string& protobufPluginsPath,
    const nlohmann::json& protobufPlugins
)

Constructor.

Parameters:

engineName

Name of the simulation engine

Methods

void registerDataPack(
    const std::string& datapackName,
    ProtoDataPackController* interface
)

Registers a datapack controller with the given name in the engine.

Parameters:

datapackName

Name of the datapack to be registered

datapackController

Pointer to the datapack controller object that’s supposed to be registered in the engine

std::vector<std::string> getNamesRegisteredDataPacks()

Get the names of registered datapacks.

const std::string& getEngineName()

Get the Engine name.

virtual bool initRunFlag() const = 0

Indicates if the simulation was initialized and is running.

virtual bool shutdownFlag() const = 0

Indicates if shutdown was requested by the client.

virtual void initialize(const nlohmann::json& data) = 0

Initializes the simulation.

Parameters:

data

Simulation configuration data

datapackLock

???

virtual void reset() = 0

Resets the simulation.

virtual void shutdown() = 0

Shutdowns the simulation.

virtual SimulationTime runLoopStep(const SimulationTime timeStep) = 0

Runs a single simulation loop step.

Parameters:

timeStep

Time step by which the simulation should be advanced

Returns:

Engine time after running the step