Program Listing for File common.h

Return to documentation for file (api/include/pntos/plugins/common.h)

#pragma once

#include <pntos/annotations.h>
#include <pntos/memory.h>
#include <pntos/stdbool.h>

#include <pntos/stdint.h>
#include <stddef.h>

#include <pntos/aspn.h>
#include <pntos/type_enum.h>

#ifdef __cplusplus
extern "C" {
#endif

PNTOS_ASSUME_NONNULL_BEGIN

#define PNTOS_PLUGIN_API_VERSION 2

typedef struct PntosMessage {
    PntosManagedMemory* memory;
    AspnBase* wrapped_message;
    char* source_identifier;
} PntosMessage;

typedef struct PntosMessageArray {

    PntosManagedMemory* memory;

    PntosMessage* PNTOS_NULLABLE* data;

    size_t num_messages;

} PntosMessageArray;

typedef struct PntosString {
    PntosManagedMemory* memory;
    char* data;
} PntosString;

typedef struct PntosByteArray {
    PntosManagedMemory* memory;
    unsigned char* data;

    size_t num_bytes;
} PntosByteArray;

typedef struct PntosStringArray {
    PntosManagedMemory* memory;
    char** data;

    size_t num_strings;
} PntosStringArray;
typedef struct PntosIntArray {
    PntosManagedMemory* memory;
    int64_t* data;
    size_t num_ints;

} PntosIntArray;
typedef struct PntosDoubleArray {
    PntosManagedMemory* memory;
    double* data;
    size_t num_doubles;

} PntosDoubleArray;

typedef struct PntosMatrix {
    PntosManagedMemory* memory;
    size_t rows;
    size_t cols;
    double* data;
} PntosMatrix;

typedef enum PntosEstimateWithCovarianceType {

    PNTOS_EWC_GENERIC,
    PNTOS_EWC_ATTITUDE_QUAT
} PntosEstimateWithCovarianceType;

typedef struct PntosEstimateWithCovariance {
    PntosManagedMemory* memory;

    PntosEstimateWithCovarianceType type;

    size_t length;

    double* estimate;

    double* covariance;
} PntosEstimateWithCovariance;

typedef struct PntosMessageTypeArray {
    PntosManagedMemory* memory;
    PntosMessageType* data;
    size_t num_types;
} PntosMessageTypeArray;

typedef enum PntosPluginTypes {
    PNTOS_UNDEFINED_PLUGIN,
    PNTOS_CONTROLLER_PLUGIN,
    PNTOS_FUSION_PLUGIN,
    PNTOS_FUSION_STRATEGY_PLUGIN,
    PNTOS_PLATFORM_INTEGRATION_PLUGIN,
    PNTOS_INITIALIZATION_PLUGIN,
    PNTOS_DATABASE_PLUGIN,
    PNTOS_TRANSPORT_PLUGIN,
    PNTOS_UI_PLUGIN,
    PNTOS_ORCHESTRATION_PLUGIN,
    PNTOS_ORCHESTRATION_STRATEGY_PLUGIN,
    PNTOS_REGISTRY_PLUGIN,
    PNTOS_INERTIAL_PLUGIN,
    PNTOS_STATE_MODELING_PLUGIN,
    PNTOS_LOGGING_PLUGIN,
    PNTOS_UTILITY_PLUGIN,
    PNTOS_PREPROCESSOR_PLUGIN,
    PNTOS_NUM_PLUGIN_TYPES
} PntosPluginTypes;

typedef enum PntosFusionType {
    PNTOS_FUSION_STANDARD_MODEL,
    PNTOS_FUSION_SAMPLED_MODEL,
    PNTOS_FUSION_TIME_DELAYED_MODEL,
    PNTOS_FUSION_STANDARD_COMPILED_MODEL
} PntosFusionType;

typedef enum PntosLoggingLevel {
    PNTOS_LOG_LEVEL_ERROR,
    PNTOS_LOG_LEVEL_WARN,
    PNTOS_LOG_LEVEL_INFO,
    PNTOS_LOG_LEVEL_DEBUG
} PntosLoggingLevel;

typedef enum PntosKeyValueStoreDataFormat {
    PNTOS_KV_STORE_INI,
    PNTOS_KV_STORE_UNSPECIFIED
} PntosKeyValueStoreDataFormat;

typedef enum PntosKeyValueStoreType {
    /*
     * Indicates a string in the PntosKeyValueStore.
     * Maps to C type: PntosString
     */
    PNTOS_KV_STORE_TYPE_STR,
    /*
     * Indicates an array of strings in the PntosKeyValueStore.
     * Maps to C type: PntosStringArray
     */
    PNTOS_KV_STORE_TYPE_STR_ARRAY,
    /*
     * Indicates an integer in the PntosKeyValueStore.
     * Maps to C type: int64_t
     */
    PNTOS_KV_STORE_TYPE_INT,
    /*
     * Indicates a boolean in the PntosKeyValueStore.
     * Maps to C type: bool
     */
    PNTOS_KV_STORE_TYPE_BOOL,
    /*
     * Indicates a double in the PntosKeyValueStore.
     * Maps to C type: double
     */
    PNTOS_KV_STORE_TYPE_DOUBLE,
    /*
     * Indicates an array of doubles in the PntosKeyValueStore.
     * Maps to C type: PntosDoubleArray
     */
    PNTOS_KV_STORE_TYPE_DOUBLE_ARRAY,
    /*
     * Indicates a message in the PntosKeyValueStore.
     * Maps to C type: PntosMessage
     */
    PNTOS_KV_STORE_TYPE_MESSAGE,
    /*
     * Indicates a raw value in the PntosKeyValueStore.
     * Maps to C type: PntosByteArray
     */
    PNTOS_KV_STORE_TYPE_RAW,
    /*
     * Indicates that the requested key does not exist, and therefore has no
     * type associated with it.
     */
    PNTOS_KV_STORE_KEY_DNE
} PntosKeyValueStoreType;

/* TODO: Note error conditions and what happens with type mismatches between set/get. */
typedef struct PntosKeyValueStore {
    PntosManagedMemory* memory;

    PntosStringArray* PNTOS_NULLABLE (*get_key_array)(struct PntosKeyValueStore* self);
    bool (*has_key)(struct PntosKeyValueStore* self, char* key);
    PntosKeyValueStoreType (*PNTOS_NULLABLE get_type)(struct PntosKeyValueStore* self, char* key);
    PntosString* PNTOS_NULLABLE (*get_str)(struct PntosKeyValueStore* self, char* key);
    PntosStringArray* PNTOS_NULLABLE (*get_str_array)(struct PntosKeyValueStore* self, char* key);
    int64_t (*get_int)(struct PntosKeyValueStore* self, char* key);
    bool (*get_bool)(struct PntosKeyValueStore* self, char* key);
    double (*get_double)(struct PntosKeyValueStore* self, char* key);
    PntosDoubleArray* PNTOS_NULLABLE (*get_double_array)(struct PntosKeyValueStore* self,
                                                         char* key);
    PntosMessage* PNTOS_NULLABLE (*get_message)(struct PntosKeyValueStore* self, char* key);
    void (*set_str)(struct PntosKeyValueStore* self, char* key, char* value);
    void (*set_str_array)(struct PntosKeyValueStore* self,
                          char* key,
                          char** values,
                          size_t num_values);
    void (*set_int)(struct PntosKeyValueStore* self, char* key, int64_t value);
    void (*set_bool)(struct PntosKeyValueStore* self, char* key, bool value);
    void (*set_double)(struct PntosKeyValueStore* self, char* key, double value);
    void (*set_double_array)(struct PntosKeyValueStore* self,
                             char* key,
                             double* values,
                             size_t num_values);
    void (*set_message)(struct PntosKeyValueStore* self,
                        char* key,
                        PntosMessage* PNTOS_NULLABLE message);
    bool (*remove_key)(struct PntosKeyValueStore* self, char* key);

    PntosKeyValueStoreDataFormat data_format;
    void (*set_raw)(struct PntosKeyValueStore* self,
                    char* PNTOS_NULLABLE key,
                    unsigned char* bytes,
                    size_t num_bytes);
    PntosByteArray* PNTOS_NULLABLE (*get_raw)(struct PntosKeyValueStore* self,
                                              char* PNTOS_NULLABLE key);
    void (*batch_end)(struct PntosKeyValueStore* self);
    void (*batch_restart)(struct PntosKeyValueStore* self);
    bool (*request_notify)(struct PntosKeyValueStore* self,
                           char* PNTOS_NULLABLE key,
                           void* PNTOS_NULLABLE receiver,
                           void (*callback)(void* PNTOS_NULLABLE receiver,
                                            char* modified_group,
                                            char** modified_keys,
                                            size_t num_modified_keys,
                                            struct PntosKeyValueStore* modified_values));

    bool (*remove_notify)(struct PntosKeyValueStore* self,
                          char* PNTOS_NULLABLE key,
                          void* PNTOS_NULLABLE receiver,
                          void (*callback)(void* PNTOS_NULLABLE receiver,
                                           char* modified_group,
                                           char** modified_keys,
                                           size_t num_modified_keys,
                                           struct PntosKeyValueStore* modified_values));

    bool (*set_permanent)(struct PntosKeyValueStore* self, bool permanent);

} PntosKeyValueStore;

typedef struct PntosRegistry {
    PntosManagedMemory* memory;

    PntosKeyValueStore* (*batch_start)(struct PntosRegistry* self, char* group);
    PntosStringArray* PNTOS_NULLABLE (*get_group_array)(struct PntosRegistry* self);

    bool (*has_group)(struct PntosRegistry* self, char* group);

    bool (*request_notify_new_group)(struct PntosRegistry* self,
                                     void* receiver,
                                     void (*callback)(void* receiver, char* new_group));

} PntosRegistry;

typedef struct PntosMediator {
    PntosManagedMemory* memory;

    PntosStringArray* (*get_filter_description_list)(struct PntosMediator* self);

    PntosMessageArray* PNTOS_NULLABLE (*request_solutions)(struct PntosMediator* self,
                                                           AspnTypeTimestamp* solution_times,
                                                           size_t num_solution_times,
                                                           char* PNTOS_NULLABLE filter_description);

    void (*process_pntos_message)(struct PntosMediator* self, PntosMessage* message);
    void (*broadcast_aspn_message)(struct PntosMediator* self,
                                   PntosMessage* message,
                                   char* PNTOS_NULLABLE transport,
                                   char* PNTOS_NULLABLE destination_identifier);
    void (*log_message)(struct PntosMediator* self, PntosLoggingLevel level, char* message);

    void (*log_message_fmt)(struct PntosMediator* self, PntosLoggingLevel level, char* fmt, ...);

    PntosRegistry* registry;
} PntosMediator;

typedef struct PntosCommonPlugin {
    PntosManagedMemory* memory;
    void (*init_plugin)(struct PntosCommonPlugin* self,
                        char* PNTOS_NULLABLE plugin_resources_location,
                        PntosMediator* PNTOS_NULLABLE mediator);

    void (*shutdown_plugin)(struct PntosCommonPlugin* self);

    PntosPluginTypes plugin_type;
    char* identifier;
} PntosCommonPlugin;

typedef struct PntosPluginArray {
    PntosManagedMemory* memory;
    PntosCommonPlugin** plugins;
    size_t num_plugins;

} PntosPluginArray;


PNTOS_ASSUME_NONNULL_END

#ifdef __cplusplus
}
#endif