class FunctionManager

Overview

Manages all types of Python functions that can be run as part of NRP Core. More…

#include <function_manager.h>

class FunctionManager {
public:
    // typedefs

    typedef std::multimap<std::string, FunctionData> function_datas_t;
    typedef std::pair<FunctionManager::function_datas_t::iterator, FunctionManager::function_datas_t::iterator> linked_functions_t;
    typedef std::tuple<bool, datapacks_vector_t> status_function_results_t;

    // construction

    FunctionManager();
    FunctionManager(const boost::python::dict& tfGlobals);

    // methods

    datapack_identifiers_set_t getRequestedDataPackIDs() const;
    DataPackPassingPolicy getDataPackPassingPolicy() const;
    void setDataPackPassingPolicy(DataPackPassingPolicy method);
    void setSimulationTime(SimulationTime simulationTime);
    const SimulationTime& getSimulationTime() const;
    void setSimulationIteration(unsigned long simulationIteration);
    unsigned long getSimulationIteration() const;

    void loadDataPackFunction(
        const std::string& dataPackFunctionName,
        const std::string& dataPackFunctionFilename
    );

    void loadStatusFunction(
        const std::string& statusFunctionName,
        const std::string& statusFunctionFilename
    );

    datapacks_vector_t executePreprocessingFunctions(
        const std::string& engineName,
        datapacks_set_t dataPacks
    );

    datapacks_vector_t executeTransceiverFunctions(
        const std::string& engineName,
        datapacks_set_t dataPacks
    );

    status_function_results_t executeStatusFunction(datapacks_set_t dataPacks);
};

Detailed Documentation

Manages all types of Python functions that can be run as part of NRP Core.

This class is responsible for loading and running all Python functions that are supported by NRP Core. The following function types are supported:

  • Preprocessing Functions

  • Transceiver Functions

  • Status Functions Preprocessing and Transceiver Functions will be also refered to as DataPack (Processing) Functions, to distinguish them from Status Functions, which have a slightly different purpose.

Methods

datapack_identifiers_set_t getRequestedDataPackIDs() const

Get DataPack IDs requested by TFs.

Returns:

void setSimulationTime(SimulationTime simulationTime)

Sets simulation time that will be accessible by all Python Functions.

Parameters:

simulationTime

Current simulation time from the simulation manager

const SimulationTime& getSimulationTime() const

Returns simulation time stored by the manager.

void setSimulationIteration(unsigned long simulationIteration)

Sets simulation iteration that will be accessible by all Python Functions.

Parameters:

simulationIteration

Current simulation iteration from the simulation manager

unsigned long getSimulationIteration() const

Returns simulation iteration number stored by the manager.

void loadDataPackFunction(
    const std::string& dataPackFunctionName,
    const std::string& dataPackFunctionFilename
)

Loads given DataPack Processing Function.

The function runs python code from the given file, executes all decorators found in the function definition, and stores the function with some metadata for future use.

DataPack Processing Functions are Transceiver Functions and Preprocessing Functions.

Parameters:

dataPackFunctionName

Name of the function, used as function’s ID. The name doesn’t have to match the actual name of the python function.

dataPackFunctionFilename

Name of the file where the function is located.

void loadStatusFunction(
    const std::string& statusFunctionName,
    const std::string& statusFunctionFilename
)

Loads given status funtion.

The function runs python code from the given file, executes all decorators found in the definition of the function, and stores the function with some metadata for future use.

Parameters:

statusFunctionName

Name of the function, used as function’s ID. The name doesn’t have to match the actual name of the python function.

statusFunctionFilename

Name of the file where the function is located.

datapacks_vector_t executePreprocessingFunctions(
    const std::string& engineName,
    datapacks_set_t dataPacks
)

Executes all Preprocessing Functions linked to an engine.

Parameters:

engineName

Name of engine

Returns:

Returns results of executed Preprocessing Functions

datapacks_vector_t executeTransceiverFunctions(
    const std::string& engineName,
    datapacks_set_t dataPacks
)

Executes all Transceiver Functions linked to an engine.

Parameters:

engineName

Name of engine

Returns:

Returns results of executed Preprocessing Functions

status_function_results_t executeStatusFunction(datapacks_set_t dataPacks)

Executes Status Function registered loaded by the manager.

This method will run the Status Function that was loaded using loadStatusFunction method.

Returns:

Results of the Status Function execution as JSON object