Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions CMLibStorage.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
SET(STORAGE_LIST DEP)

SET(STORAGE_LIST_DEP "https://github.com/bacpack-system/package-tracker.git")
SET(STORAGE_LIST_DEP_REVISION "v0.0.0" CACHE STRING "" FORCE)
SET(STORAGE_LIST_DEP "https://github.com/bacpack-system/package-tracker.git")
34 changes: 21 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.25 FATAL_ERROR)
PROJECT(ModuleGateway)

SET(BRINGAUTO_MODULE_GATEWAY_VERSION 1.4.0)

SET(BRINGAUTO_MODULE_GATEWAY_MINIMUM_LOGGER_VERBOSITY "DEBUG" CACHE STRING "Minimum logger verbosity level for module-gateway")
SET_PROPERTY(CACHE BRINGAUTO_MODULE_GATEWAY_MINIMUM_LOGGER_VERBOSITY PROPERTY STRINGS "DEBUG" "INFO" "WARNING" "ERROR" "CRITICAL")

OPTION(BRINGAUTO_TESTS "Enable tests" OFF)
OPTION(BRINGAUTO_PACKAGE "Package creation" OFF)
OPTION(BRINGAUTO_INSTALL "Enable install" OFF)
OPTION(BRINGAUTO_SYSTEM_DEP "Enable system dependencies" OFF)
OPTION(BRINGAUTO_SAMPLES "Enable build of sample app, not used in project" OFF)
OPTION(BRINGAUTO_GET_PACKAGES_ONLY "Only download packages for this project" OFF)

FIND_PACKAGE(CMLIB COMPONENTS CMCONF REQUIRED)
CMCONF_INIT_SYSTEM(FLEET_PROTOCOL)

FIND_PACKAGE(CMLIB
COMPONENTS CMDEF CMUTIL STORAGE
REQUIRED
)

SET(BRINGAUTO_MODULE_GATEWAY_VERSION 1.3.5)

SET(BRINGAUTO_MODULE_GATEWAY_MINIMUM_LOGGER_VERBOSITY "DEBUG" CACHE STRING "Minimum logger verbosity level for module-gateway")
SET_PROPERTY(CACHE BRINGAUTO_MODULE_GATEWAY_MINIMUM_LOGGER_VERBOSITY PROPERTY STRINGS "DEBUG" "INFO" "WARNING" "ERROR" "CRITICAL")

CMDEF_COMPILE_DEFINITIONS(
ALL
"MODULE_GATEWAY_VERSION=\"${BRINGAUTO_MODULE_GATEWAY_VERSION}\""
"BRINGAUTO_MODULE_GATEWAY_MINIMUM_LOGGER_VERBOSITY=\"${BRINGAUTO_MODULE_GATEWAY_MINIMUM_LOGGER_VERBOSITY}\""
)
SET(CMAKE_INSTALL_RPATH "$ORIGIN/../${CMDEF_LIBRARY_INSTALL_DIR}")
SET(CMAKE_CXX_STANDARD 20)
SET(CMAKE_CXX_STANDARD 23)

INCLUDE(CheckPIESupported)
CHECK_PIE_SUPPORTED()
SET(CMAKE_POSITION_INDEPENDENT_CODE ON)

OPTION(BRINGAUTO_TESTS "Disable tests" OFF)
OPTION(BRINGAUTO_PACKAGE "Package creation" OFF)
OPTION(BRINGAUTO_INSTALL "Disable install" OFF)
OPTION(BRINGAUTO_SYSTEM_DEP "Enable system dependencies" OFF)
OPTION(BRINGAUTO_SAMPLES "Enable build of sample app, not used in project" OFF)
OPTION(BRINGAUTO_GET_PACKAGES_ONLY "Only download packages for this project" OFF)

IF(BRINGAUTO_PACKAGE)
IF(NOT BRINGAUTO_INSTALL)
SET(BRINGAUTO_INSTALL ON CACHE BOOL "Forced install due to BRINGAUTO_PACKAGE=ON" FORCE)
Expand All @@ -55,6 +58,9 @@ FIND_PACKAGE(eclipse-paho-mqtt-c REQUIRED)
FIND_PACKAGE(libbringauto_logger 2.0.0 REQUIRED)
FIND_PACKAGE(fleet-protocol-interface 2.0.0 REQUIRED)
FIND_PACKAGE(ZLIB 1.2.11 REQUIRED)
FIND_PACKAGE(fleet-protocol-cxx-helpers-static 1.2.0 REQUIRED)
FIND_PACKAGE(aeron 1.48.6 REQUIRED)
FIND_PACKAGE(async-function-execution-shared 1.0.0 REQUIRED)

FILE(GLOB_RECURSE source_files "source/*")
ADD_LIBRARY(module-gateway-lib STATIC "${source_files}")
Expand All @@ -72,6 +78,8 @@ TARGET_LINK_LIBRARIES(module-gateway-lib PUBLIC
eclipse-paho-mqtt-c::paho-mqtt3as
PahoMqttCpp::paho-mqttpp3
ZLIB::ZLIB
fleet-protocol-cxx-helpers-static::fleet-protocol-cxx-helpers-static
async-function-execution-shared::async-function-execution-shared
${CMAKE_DL_LIBS}
)

Expand Down
19 changes: 13 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,18 @@ connection is broken and as soon as the connection is up, then error aggregated
- [cmlib](https://github.com/cmakelib/cmakelib)

- [protobuf](https://github.com/protocolbuffers/protobuf/tree/main/src) >= v3.21.12
- [cxxopts](https://github.com/jarro2783/cxxopts) >= v3.0.0
- [boost](https://github.com/boostorg/boost) >= v1.74.0
- [nlohmann-json](https://github.com/nlohmann/json) >= v3.2.0
- [ba-logger](https://github.com/bringauto/ba-logger) >= v1.2.0
- g++ >= 10 or other compiler with c++20 support
- [cxxopts](https://github.com/jarro2783/cxxopts) >= v3.1.1
- [boost](https://github.com/boostorg/boost) >= v1.86.0
- [nlohmann-json](https://github.com/nlohmann/json) >= v3.10.5/
- [pahomqtt](https://github.com/eclipse-paho/paho.mqtt.c) >= v1.3.9
- [pahomqttcpp](https://github.com/eclipse-paho/paho.mqtt.cpp) >= v1.3.2
- [zlib](https://github.com/madler/zlib) >= v1.2.11
- [ba-logger](https://github.com/bringauto/ba-logger) >= v2.0.0
- [fleet-protocol-interface](https://github.com/bringauto/fleet-protocol) >= v2.0.0
- [fleet-protocol-cpp](https://github.com/bringauto/fleet-protocol-cpp) >= v1.2.0
- [aeron](https://github.com/aeron-io/aeron) >= v1.48.6
- [async-function-execution](https://github.com/bringauto/async-function-execution) >= 0.1.0
- g++ >= 10 or other compiler with c++23 support

## Build
```
Expand All @@ -50,7 +57,7 @@ make

### Arguments

* required arguments:
* Required arguments:
* `-c <string> | --config-path=<string>`path to json configuration file ([Configs Readme](./configs/README.md))
* All arguments:
* `-h | --help` print help
Expand Down
6 changes: 4 additions & 2 deletions cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ BA_PACKAGE_LIBRARY(fleet-protocol-interface v2.0.0 NO_DEBUG ON)
BA_PACKAGE_LIBRARY(nlohmann-json v3.10.5 NO_DEBUG ON)
BA_PACKAGE_LIBRARY(cxxopts v3.1.1 NO_DEBUG ON)
BA_PACKAGE_LIBRARY(boost v1.86.0)
BA_PACKAGE_LIBRARY(ba-logger v2.0.0
)
BA_PACKAGE_LIBRARY(ba-logger v2.0.0)
BA_PACKAGE_LIBRARY(pahomqttc v1.3.9)
BA_PACKAGE_LIBRARY(pahomqttcpp v1.3.2)
BA_PACKAGE_LIBRARY(zlib v1.2.11 OUTPUT_PATH_VAR ZLIB_DIR)
BA_PACKAGE_LIBRARY(fleet-protocol-cpp v1.2.0)
BA_PACKAGE_LIBRARY(aeron v1.48.6)
BA_PACKAGE_LIBRARY(async-function-execution v1.0.0)

IF (BRINGAUTO_TESTS)
BA_PACKAGE_LIBRARY(gtest v1.12.1)
Expand Down
6 changes: 3 additions & 3 deletions include/bringauto/external_client/ErrorAggregator.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <bringauto/modules/ModuleManagerLibraryHandler.hpp>
#include <bringauto/modules/IModuleManagerLibraryHandler.hpp>
#include <bringauto/structures/DeviceIdentification.hpp>

#include <filesystem>
Expand All @@ -25,7 +25,7 @@ class ErrorAggregator {
* @return OK if initialization was successful
* @return NOT_OK if an error occurred
*/
int init_error_aggregator(const std::shared_ptr <modules::ModuleManagerLibraryHandler> &library);
int init_error_aggregator(const std::shared_ptr <modules::IModuleManagerLibraryHandler> &library);

/**
* @short Clean up.
Expand Down Expand Up @@ -111,7 +111,7 @@ class ErrorAggregator {
modules::Buffer lastStatus {};
};

std::shared_ptr <modules::ModuleManagerLibraryHandler> module_ {};
std::shared_ptr <modules::IModuleManagerLibraryHandler> module_ {};

/**
* @brief Map of devices states, key is device identification converted to string
Expand Down
4 changes: 3 additions & 1 deletion include/bringauto/modules/Buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

namespace bringauto::modules {

class IModuleManagerLibraryHandler;

/**
* @brief Buffer structure used to simplify buffer management. The reason for this class is to provide
* a way to manage buffer memory in a safe way and make it easier to pass buffers between objects.
Expand All @@ -18,7 +20,7 @@ namespace bringauto::modules {
*/
struct Buffer final {

friend class ModuleManagerLibraryHandler;
friend class IModuleManagerLibraryHandler;

Buffer() = default;
Buffer(const Buffer& buff) = default;
Expand Down
126 changes: 126 additions & 0 deletions include/bringauto/modules/IModuleManagerLibraryHandler.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#pragma once

#include <bringauto/modules/Buffer.hpp>

#include <filesystem>
#include <functional>



namespace bringauto::modules {

/**
* @brief Class used to load and handle library created by module maintainer
*/
class IModuleManagerLibraryHandler {
public:
IModuleManagerLibraryHandler() = default;

virtual ~IModuleManagerLibraryHandler() = default;

/**
* @brief Load library created by a module maintainer
*
* @param path path to the library
*/
virtual void loadLibrary(const std::filesystem::path &path) = 0;

/**
* @brief Get the module number
*
* @return module number
*/
virtual int getModuleNumber() = 0;

/**
* @brief Check if device type is supported by the module
*
* @param device_type device type to check
* @return OK if supported, NOT_OK otherwise
*/
virtual int isDeviceTypeSupported(unsigned int device_type) = 0;

/**
* @brief Evaluate the condition for aggregating a new status into the current status
*
* @param current_status current aggregated status
* @param new_status newly received status
* @param device_type device type
* @return OK if the new status should be aggregated, NOT_OK otherwise
*/
virtual int sendStatusCondition(const Buffer &current_status, const Buffer &new_status, unsigned int device_type) = 0;

/**
* @brief After executing the respective module function, an error might be thrown when allocating the buffer.
*
* @see fleet-protocol/lib/module_maintainer/module_gateway/include/module_manager.h
*/
virtual int generateCommand(Buffer &generated_command, const Buffer &new_status,
const Buffer &current_status, const Buffer &current_command,
unsigned int device_type) = 0;

/**
* @brief After executing the respective module function, an error might be thrown when allocating the buffer.
*
* @see fleet-protocol/lib/module_maintainer/module_gateway/include/module_manager.h
*/
virtual int aggregateStatus(Buffer &aggregated_status, const Buffer &current_status,
const Buffer &new_status, unsigned int device_type) = 0;

/**
* @brief After executing the respective module function, an error might be thrown when allocating the buffer.
*
* @see fleet-protocol/lib/module_maintainer/module_gateway/include/module_manager.h
*/
virtual int aggregateError(Buffer &error_message, const Buffer &current_error_message, const Buffer &status,
unsigned int device_type) = 0;

/**
* @brief After executing the respective module function, an error might be thrown when allocating the buffer.
*
* @see fleet-protocol/lib/module_maintainer/module_gateway/include/module_manager.h
*/
virtual int generateFirstCommand(Buffer &default_command, unsigned int device_type) = 0;

/**
* @brief Check if the status data is valid
*
* @param status status buffer to validate
* @param device_type device type
* @return OK if valid, NOT_OK otherwise
*/
virtual int statusDataValid(const Buffer &status, unsigned int device_type) = 0;

/**
* @brief Check if the command data is valid
*
* @param command command buffer to validate
* @param device_type device type
* @return OK if valid, NOT_OK otherwise
*/
virtual int commandDataValid(const Buffer &command, unsigned int device_type) = 0;

/**
* @brief Constructs a buffer with the given size
*
* @param size size of the buffer
* @return a new Buffer object
*/
Buffer constructBuffer(std::size_t size = 0);

protected:

std::function<void(struct buffer*)> deallocate_ {};

virtual int allocate(struct buffer* buffer_pointer, size_t size_in_bytes) const = 0;

/**
* @brief Constructs a buffer by taking ownership of the given raw C buffer
*
* @param buffer raw C buffer whose memory ownership is transferred
* @return a new Buffer object
*/
Buffer constructBufferByTakeOwnership(struct ::buffer& buffer);
};

}
Loading