Skip to content
Merged
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
11 changes: 7 additions & 4 deletions .github/workflows/python-bindings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ jobs:
- name: "Build and Install Python package"
run: |
mkdir -p /tmp/capio_cl_jsons
cp tests/jsons/*.json /tmp/capio_cl_jsons
mkdir -p /tmp/capio_cl_tomls
cp -r tests/jsons/* /tmp/capio_cl_jsons
cp -r tests/tomls/* /tmp/capio_cl_tomls
. ./venv/bin/activate
pip install .

Expand Down Expand Up @@ -128,7 +130,9 @@ jobs:
python3 -m pip install -r build-requirements.txt

mkdir -p /tmp/capio_cl_jsons
cp tests/jsons/*.json /tmp/capio_cl_jsons
mkdir -p /tmp/capio_cl_tomls
cp -r tests/jsons/* /tmp/capio_cl_jsons
cp -r tests/tomls/* /tmp/capio_cl_tomls

python3 -m build \
-Ccmake.define.ENABLE_COVERAGE=OFF \
Expand All @@ -137,6 +141,5 @@ jobs:

pip install dist/*.whl
python3 -m pip install -r test-requirements.txt

echo "✅ Running unit tests"

pytest -v tests/python/test_* | tee pytest-riscv.log
59 changes: 44 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ add_compile_options(-Wall -Wextra -Wpedantic)
# External projects
#####################################

FetchContent_Declare(
tomlplusplus
GIT_REPOSITORY https://github.com/marzer/tomlplusplus.git
GIT_TAG v3.4.0
)

FetchContent_Declare(
jsoncons
GIT_REPOSITORY https://github.com/danielaparker/jsoncons.git
Expand All @@ -55,7 +61,7 @@ set(JSONCONS_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(JSONCONS_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(JSONCONS_BUILD_FUZZERS OFF CACHE BOOL "" FORCE)

FetchContent_MakeAvailable(jsoncons)
FetchContent_MakeAvailable(jsoncons tomlplusplus)

if (BUILD_PYTHON_BINDINGS)
FetchContent_Declare(
Expand All @@ -82,22 +88,33 @@ file(WRITE ${OUTPUT_HEADER} "// Bundled CAPIO-CL encoded JSON schemas\n")
file(APPEND ${OUTPUT_HEADER} "#pragma once\n\n")

foreach (SCHEMA_FILE ${SCHEMA_FILES})
get_filename_component(SCHEMA_NAME ${SCHEMA_FILE} NAME_WE)
get_filename_component(SCHEMA_BASENAME ${SCHEMA_FILE} NAME)
message(STATUS "Bundling CAPIO-CL schema: ${SCHEMA_BASENAME}")

execute_process(
COMMAND bash -c "echo 'constexpr char schema_${SCHEMA_NAME}[] = R\"(' && cat ${SCHEMA_BASENAME} && echo ')\";'"
COMMAND bash -c "echo ${SCHEMA_BASENAME} | sed 's/\\.json$//'"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/schema
OUTPUT_VARIABLE SCHEMA_NAME_RAW
OUTPUT_STRIP_TRAILING_WHITESPACE
)

string(REPLACE "." "_" SCHEMA_NAME "${SCHEMA_NAME_RAW}")

execute_process(
COMMAND bash -c
"echo \"// CAPIO-CL version: ${SCHEMA_NAME_RAW}\" && \
echo \"constexpr char schema_${SCHEMA_NAME}[] = R\\\"(\" && \
cat \"${SCHEMA_BASENAME}\" && \
echo \")\\\";\""
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/schema
OUTPUT_VARIABLE HEXDATA
RESULT_VARIABLE RES
)

if (NOT RES EQUAL 0)
message(FATAL_ERROR "Failed bundling for ${SCHEMA_FILE}: Error code is ${RES}")
message(FATAL_ERROR "Failed to bundle ${SCHEMA_BASENAME}: exit ${RES}")
endif ()


file(APPEND ${OUTPUT_HEADER} "// CAPIO-CL version: ${SCHEMA_NAME}\n")
file(APPEND ${OUTPUT_HEADER} "${HEXDATA}\n\n")
endforeach ()

Expand All @@ -117,10 +134,11 @@ target_include_directories(libcapio_cl PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src
${jsoncons_SOURCE_DIR}/include
${CAPIOCL_JSON_SCHEMAS_DIRECTORY}
${TOMLPLUSPLUS_SOURCE_DIR}/include
)

# jsoncons is header-only, no linking required
target_link_libraries(libcapio_cl PUBLIC)
target_link_libraries(libcapio_cl PRIVATE tomlplusplus::tomlplusplus)

#####################################
# Install rules
Expand Down Expand Up @@ -189,8 +207,24 @@ if (CAPIO_CL_BUILD_TESTS)
add_custom_command(
TARGET CAPIO_CL_tests PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory "/tmp/capio_cl_jsons"
COMMAND ${CMAKE_COMMAND} -E copy_directory ${TEST_JSON_DIR} "/tmp/capio_cl_jsons"
COMMENT "Copying JSON test files to build directory"
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${TEST_JSON_DIR}"
"/tmp/capio_cl_jsons"
COMMENT "Copying JSON test files with full directory structure"
)

#####################################
# Copy TOMLS test files
#####################################
set(TEST_TOMLS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/tests/tomls")

add_custom_command(
TARGET CAPIO_CL_tests PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory "/tmp/capio_cl_tomls"
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${TEST_TOMLS_DIR}"
"/tmp/capio_cl_tomls"
COMMENT "Copying TOMLS test files with full directory structure"
)

#####################################
Expand All @@ -200,13 +234,8 @@ if (CAPIO_CL_BUILD_TESTS)
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

install(DIRECTORY ${TEST_JSON_DIR}
DESTINATION ${CMAKE_INSTALL_BINDIR}/jsons
FILES_MATCHING PATTERN "*.json"
)

#####################################
# Targget to execute tests
# Target to execute tests
#####################################
add_custom_target(run_tests
DEPENDS CAPIO_CL_tests
Expand Down
19 changes: 9 additions & 10 deletions capiocl.hpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
#ifndef CAPIO_CL_CAPIOCL_HPP
#define CAPIO_CL_CAPIOCL_HPP

#include <climits>
#include <cstring>
#include <filesystem>
#include <iostream>
#include <jsoncons/basic_json.hpp>
#include <jsoncons_ext/jsonschema/jsonschema.hpp>
#include <string>
#include <thread>
#include <unistd.h>
#include <unordered_map>
#include <vector>

/// @brief Namespace containing all the CAPIO-CL related code
namespace capiocl {
Expand Down Expand Up @@ -76,7 +67,9 @@ inline std::string sanitize(const std::string &input) {
/// @brief Available versions of CAPIO-CL language
struct CAPIO_CL_VERSION final {
/// @brief Release 1.0 of CAPIO-CL
static constexpr char V1[] = "1.0";
static constexpr char V1[] = "1.0";
/// @brief Release 1.1 of CAPIO-CL
static constexpr char V1_1[] = "1.1";
};

namespace serializer {
Expand All @@ -92,6 +85,12 @@ class MonitorException;
namespace engine {
class Engine;
}

namespace configuration {
class CapioClConfiguration;
class CapioClConfigurationException;
struct defaults;
} // namespace configuration
} // namespace capiocl

#endif // CAPIO_CL_CAPIOCL_HPP
16 changes: 9 additions & 7 deletions doxygen/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -943,12 +943,14 @@ WARN_LOGFILE =
# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
# Note: If this tag is empty the current directory is searched.

INPUT = .README.md \
../src \
../include \
../capiocl.hpp \
semantics.md \
syntax_v1.md
INPUT = .README.md \
../src \
../include \
../capiocl.hpp \
semantics.md \
syntax_v1.md \
syntax_v1_1.md \
configuration.md

# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
Expand Down Expand Up @@ -2425,7 +2427,7 @@ INCLUDE_PATH =
# used.
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.

INCLUDE_FILE_PATTERNS =
INCLUDE_FILE_PATTERNS = *.md

# The PREDEFINED tag can be used to specify one or more macro names that are
# defined before the preprocessor is started (similar to the -D option of e.g.
Expand Down
69 changes: 69 additions & 0 deletions doxygen/configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Runtime Configuration for **CAPIO-CL**

CAPIO-CL supports **runtime configuration** through a user-provided **TOML** configuration file.
This allows you to customize various aspects of the library without recompiling it.

A configuration file can be loaded into a running CAPIO-CL instance by calling:

capiocl::Engine engine;
engine.load("path/to/config.toml");

If no configuration file is provided, CAPIO-CL falls back to its built-in defaults.

---

## TOML Configuration Structure

The configuration file uses a structured namespace under the top-level table `monitor.mcast`.

Available configuration parameters:

| Key | Type | Default | Description |
|----------------------------------|----------|----------------|----------------------------------------------------------------------------------------------|
| `monitor.mcast.commit.ip` | string | `224.224.224.1` | Multicast IP address used for commit messages |
| `monitor.mcast.commit.port` | integer | `12345` | UDP port for commit messages |
| `monitor.mcast.delay_ms` | integer | `300` | Artificial delay (in milliseconds) inserted before sending multicast messages. Useful for debugging or simulating slower networks. |
| `monitor.mcast.homenode.ip` | string | `224.224.224.2` | IP address of the home node for monitoring operations |
| `monitor.mcast.homenode.port` | integer | `12345` | Port associated with the home node monitoring endpoint |

---

## Example configuration file

Below is a complete example of a `config.toml` file:

# Example CAPIO-CL TOML configuration

[monitor.mcast]

# Multicast settings for commit messages
commit.ip = "224.224.224.1"
commit.port = 12345

# Delay (in milliseconds)
delay_ms = 300

# Home node information
homenode.ip = "224.224.224.2"
homenode.port = 12345

---

## How CAPIO-CL Uses These Settings

### `commit.ip` and `commit.port`
These fields define where CAPIO-CL sends **commit broadcast messages**.
Commit messages are used for consistency coordination across distributed nodes.

### `delay_ms`
A small configurable delay may help with:

- debugging message-ordering issues,
- testing high-latency environments,
- reproducing specific timing-related behavior.

A value of `0` means no delay.

### `homenode.ip` and `homenode.port`
These define the **central monitoring endpoint** (the “home node”).
CAPIO-CL uses this endpoint to coordinate monitoring metadata and cluster-wide communication.
Loading
Loading