diff --git a/.gitignore b/.gitignore index 8d5694f..7afadea 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ include/cpp_core/version.h build/ .cache/ - +compile_commands.json diff --git a/CMakeLists.txt b/CMakeLists.txt index 6fabd8e..ffee20c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,64 +1,111 @@ -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.30) -project(cpp-core - VERSION 0.1.0 - DESCRIPTION "Cross-platform helper library shared by cpp-linux-bindings and cpp-windows-bindings" - LANGUAGES CXX) +# Export compile commands to root directory +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # --------------------------------------------------------------------------- -# Version information - can be overridden by parent project +# Version information from Git tags +# Version is determined automatically from Git tags and cannot be overridden # --------------------------------------------------------------------------- -foreach(_part IN ITEMS MAJOR MINOR PATCH) - if(NOT DEFINED CPP_CORE_VERSION_${_part} OR CPP_CORE_VERSION_${_part} STREQUAL "") - set(CPP_CORE_VERSION_${_part} ${PROJECT_VERSION_${_part}}) - endif() -endforeach() +include(${CMAKE_CURRENT_LIST_DIR}/cmake/get_version_from_git.cmake) + +# Get version from Git tags +get_version_from_git() +set(CPP_CORE_VERSION_MAJOR ${VERSION_MAJOR} CACHE STRING "Major version number" FORCE) +set(CPP_CORE_VERSION_MINOR ${VERSION_MINOR} CACHE STRING "Minor version number" FORCE) +set(CPP_CORE_VERSION_PATCH ${VERSION_PATCH} CACHE STRING "Patch version number" FORCE) +set(CPP_CORE_VERSION_STRING ${VERSION_STRING} CACHE STRING "Full version string" FORCE) + +# Set PROJECT_VERSION for CMake package config (only MAJOR.MINOR.PATCH, no suffix) +set(PROJECT_VERSION "${CPP_CORE_VERSION_MAJOR}.${CPP_CORE_VERSION_MINOR}.${CPP_CORE_VERSION_PATCH}") + +project( + cpp-core + VERSION ${PROJECT_VERSION} + DESCRIPTION "Cross-platform helper library shared by cpp-linux-bindings and cpp-windows-bindings" + LANGUAGES CXX +) configure_file( - ${CMAKE_CURRENT_SOURCE_DIR}/include/cpp_core/version.h.in - ${CMAKE_CURRENT_SOURCE_DIR}/include/cpp_core/version.h - @ONLY) + ${CMAKE_CURRENT_SOURCE_DIR}/include/cpp_core/version.h.in + ${CMAKE_CURRENT_SOURCE_DIR}/include/cpp_core/version.h + @ONLY +) # Header-only library -------------------------------------------------------- add_library(cpp_core INTERFACE) add_library(cpp_core::cpp_core ALIAS cpp_core) # Public include directories -target_include_directories(cpp_core INTERFACE +target_include_directories( + cpp_core + INTERFACE $ - $) + $ +) + +# Set C++ standard +set(CMAKE_CXX_STANDARD 23) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) # Require C++23 target_compile_features(cpp_core INTERFACE cxx_std_23) +# Enable C++23 module support +set(CMAKE_CXX_MODULE_STD 23) +set(CMAKE_CXX_MODULE_EXTENSIONS OFF) + # Install rules -------------------------------------------------------------- include(GNUInstallDirs) -install(TARGETS cpp_core - EXPORT cpp_coreTargets) +install( + TARGETS cpp_core + EXPORT cpp_coreTargets +) -install(DIRECTORY include/ - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) +install( + DIRECTORY include/ + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} +) # CMake package configuration ------------------------------------------------ include(CMakePackageConfigHelpers) write_basic_package_version_file( - ${CMAKE_CURRENT_BINARY_DIR}/cpp_coreConfigVersion.cmake - VERSION ${PROJECT_VERSION} - COMPATIBILITY SameMajorVersion) + ${CMAKE_CURRENT_BINARY_DIR}/cpp_coreConfigVersion.cmake + VERSION ${PROJECT_VERSION} + COMPATIBILITY SameMajorVersion + ) configure_package_config_file( - ${CMAKE_CURRENT_LIST_DIR}/cmake/cpp_core_config.cmake.in - ${CMAKE_CURRENT_BINARY_DIR}/cpp_coreConfig.cmake - INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cpp_core) + ${CMAKE_CURRENT_LIST_DIR}/cmake/cpp_core_config.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/cpp_coreConfig.cmake + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cpp_core +) -install(EXPORT cpp_coreTargets - FILE cpp_coreTargets.cmake - NAMESPACE cpp_core:: - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cpp_core) +install( + EXPORT cpp_coreTargets + FILE cpp_coreTargets.cmake + NAMESPACE cpp_core:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cpp_core +) -install(FILES +install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/cpp_coreConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/cpp_coreConfigVersion.cmake - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cpp_core) + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cpp_core +) + +if(CMAKE_EXPORT_COMPILE_COMMANDS AND EXISTS "${CMAKE_BINARY_DIR}/compile_commands.json") + add_custom_target( + copy-compile-commands + ALL + ${CMAKE_COMMAND} -E copy_if_different + ${CMAKE_BINARY_DIR}/compile_commands.json + ${CMAKE_SOURCE_DIR}/compile_commands.json + DEPENDS ${CMAKE_BINARY_DIR}/compile_commands.json + COMMENT "Copying compile_commands.json to project root" + ) +endif() diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 0000000..0c9fa5c --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,82 @@ +{ + "version": 3, + "cmakeMinimumRequired": { + "major": 3, + "minor": 30, + "patch": 0 + }, + "configurePresets": [ + { + "name": "gcc", + "displayName": "GCC (g++)", + "description": "Build using GCC compiler", + "generator": "Ninja", + "binaryDir": "${sourceDir}/build/gcc", + "toolchainFile": "${sourceDir}/cmake/gcc-toolchain.cmake", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + }, + { + "name": "clang", + "displayName": "Clang (clang++)", + "description": "Build using Clang compiler", + "generator": "Ninja", + "binaryDir": "${sourceDir}/build/clang", + "toolchainFile": "${sourceDir}/cmake/clang-toolchain.cmake", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + }, + { + "name": "msvc", + "displayName": "MSVC", + "description": "Build using MSVC compiler", + "generator": "Visual Studio 17 2022", + "binaryDir": "${sourceDir}/build/msvc", + "toolchainFile": "${sourceDir}/cmake/msvc-toolchain.cmake", + "architecture": { + "value": "x64", + "strategy": "external" + } + } + ], + "buildPresets": [ + { + "name": "gcc-debug", + "displayName": "GCC Debug", + "configurePreset": "gcc", + "configuration": "Debug" + }, + { + "name": "gcc-release", + "displayName": "GCC Release", + "configurePreset": "gcc", + "configuration": "Release" + }, + { + "name": "clang-debug", + "displayName": "Clang Debug", + "configurePreset": "clang", + "configuration": "Debug" + }, + { + "name": "clang-release", + "displayName": "Clang Release", + "configurePreset": "clang", + "configuration": "Release" + }, + { + "name": "msvc-debug", + "displayName": "MSVC Debug", + "configurePreset": "msvc", + "configuration": "Debug" + }, + { + "name": "msvc-release", + "displayName": "MSVC Release", + "configurePreset": "msvc", + "configuration": "Release" + } + ] +} diff --git a/README.md b/README.md index 067d997..0333f95 100644 --- a/README.md +++ b/README.md @@ -1,81 +1,76 @@ # C++ Core -Header-only C++ helper library that provides small, cross-platform utilities and a centrally maintained **Version** struct shared by the *cpp-bindings-linux*, *cpp-bindings-windows* and *cpp-bindings-macos* repositories. +Header-only API definition library for cross-platform serial communication. Defines the **API contract** and **version information** shared by all platform-specific binding implementations. -> [!NOTE] +> [!IMPORTANT] > -> This repository contains **headers only**. To obtain a working native library (SO / DLL / dylib) build one of the platform-specific projects instead: -> - [C++ bindings (Windows)](https://github.com/Serial-IO/cpp-bindings-windows) -> - [C++ bindings (Linux)](https://github.com/Serial-IO/cpp-bindings-linux) -> -> These repositories compile *cpp-core* for you and provide the ready-to-use shared library. +> **API definitions only** (headers). For implementations and ready-to-use shared libraries: +> - [cpp-bindings-windows](https://github.com/Serial-IO/cpp-bindings-windows) - Windows (DLL) +> - [cpp-bindings-linux](https://github.com/Serial-IO/cpp-bindings-linux) - Linux (SO) +> - [cpp-bindings-macos](https://github.com/Serial-IO/cpp-bindings-macos) - macOS (dylib) -## Documentation +## Features -* [Overview](docs/overview.md): Architecture, Build & Quick Start. -* C++23, zero runtime dependencies -* Delivered as an INTERFACE target `cpp_core::cpp_core` -* Fetchable via [CPM.cmake](https://github.com/cpm-cmake/CPM.cmake) or regular `find_package` +* **C++23** header-only API definitions +* **Cross-platform serial I/O API** (POSIX/Windows compatible) +* **Centralized version information** from Git tags (`cpp_core::kVersion`) +* **Status codes** enum for error handling +* **C-compatible API** for FFI bindings (Rust, Python, Deno, etc.) ## Requirements -* CMake ≥ 3.14 +* CMake ≥ 3.30 * A C++23 compatible compiler (GCC 13+, Clang 16+, MSVC 2022+) +* Git (for automatic version detection) -## Quick Start +## Version Information -1. Add *cpp-core* with CPM.cmake (recommended way) +The version is **automatically extracted from Git tags** during CMake configuration and cannot be overridden: -```cmake -# Set the project version once via **cache variables** – -# ensures the values end up in cpp-core regardless of when CPM configures. -set(CPP_CORE_VERSION_MAJOR 1 CACHE STRING "") -set(CPP_CORE_VERSION_MINOR 0 CACHE STRING "") -set(CPP_CORE_VERSION_PATCH 3 CACHE STRING "") +* **With Git tag** (e.g., `v1.2.3`): Version is `1.2.3` (or `1.2.3-dirty` if working tree has uncommitted changes) +* **Without Git tag**: Version is `0.0.0` (or `0.0.0-dirty` if working tree has uncommitted changes) -CPMAddPackage( - NAME cpp_core - GITHUB_REPOSITORY Serial-IO/cpp-core # Fork / Upstream - GIT_TAG main # or e.g. v0.1.0 -) - -add_executable(my_app src/main.cpp) -target_link_libraries(my_app PRIVATE cpp_core::cpp_core) -``` - -> Why cache variables? -> They guarantee the values exist **before** the `CPMAddPackage()` call. If the variables are set later (or via -> `OPTIONS ... "CPP_CORE_VERSION_MAJOR=${FOO}"`) and `FOO` is empty at that moment, *cpp-core* falls back to its default version (0.1.0). - -2. Use in code +All binding repositories that include this repository will use the same version information, ensuring consistency across platforms. ```cpp #include -#include -int main() { - constexpr auto v = cpp_core::VERSION; // {1,4,0} -} +constexpr auto v = cpp_core::kVersion; // v.major, v.minor, v.patch ``` -## Alternative: add_subdirectory +## Usage in Binding Repositories -If you include the source code directly as a sub-repository, simply do: +Binding repositories typically include this repository as a dependency: ```cmake -add_subdirectory(externals/cpp-core) -# the same version variables can be set before the call +CPMAddPackage( + NAME cpp_core + GITHUB_REPOSITORY Serial-IO/cpp-core + GIT_TAG v1.2.3 # Version tag determines the API version +) + +target_link_libraries(my_binding_library PRIVATE cpp_core::cpp_core) ``` -## Using the package with `find_package` +The binding implementation then uses the API definitions: -After running `cmake --install` (or `make install`) you can locate the package system-wide: +```cpp +#include +#include -```cmake -find_package(cpp_core REQUIRED) -add_executable(my_app src/main.cpp) -target_link_libraries(my_app PRIVATE cpp_core::cpp_core) +// Implement platform-specific functions matching the API +intptr_t serialOpen( + void *port, + int baudrate, + int data_bits, + int parity, + int stop_bits, + ErrorCallbackT error_callback +) { + // Platform-specific implementation (Windows/Linux/macOS) +} ``` ## License -`Apache-2.0` Check [LICENSE](https://github.com/Serial-IO/cpp-core/blob/main/LICENSE) for more details. + +`Apache-2.0` - Check [LICENSE](LICENSE) for more details. diff --git a/cmake/clang-toolchain.cmake b/cmake/clang-toolchain.cmake new file mode 100644 index 0000000..72d8016 --- /dev/null +++ b/cmake/clang-toolchain.cmake @@ -0,0 +1,12 @@ +# Clang Toolchain file for cpp-core +# Usage: cmake -DCMAKE_TOOLCHAIN_FILE=cmake/clang-toolchain.cmake .. + +# Set the C++ compiler +set(CMAKE_CXX_COMPILER "clang++") +set(CMAKE_C_COMPILER "clang") + +# Compiler-specific flags +set(CMAKE_CXX_FLAGS_INIT "-Wall -Wextra -Wpedantic") +set(CMAKE_CXX_FLAGS_DEBUG_INIT "-g -O0") +set(CMAKE_CXX_FLAGS_RELEASE_INIT "-O3 -DNDEBUG") + diff --git a/cmake/cpp_core_config.cmake.in b/cmake/cpp_core_config.cmake.in index 65434e4..be99792 100644 --- a/cmake/cpp_core_config.cmake.in +++ b/cmake/cpp_core_config.cmake.in @@ -2,4 +2,10 @@ include("${CMAKE_CURRENT_LIST_DIR}/cpp_coreTargets.cmake") +# Set version variables for parent projects +set(CPP_CORE_VERSION_MAJOR @CPP_CORE_VERSION_MAJOR@) +set(CPP_CORE_VERSION_MINOR @CPP_CORE_VERSION_MINOR@) +set(CPP_CORE_VERSION_PATCH @CPP_CORE_VERSION_PATCH@) +set(CPP_CORE_VERSION_STRING "@CPP_CORE_VERSION_STRING@") + check_required_components(cpp_core) diff --git a/cmake/gcc-toolchain.cmake b/cmake/gcc-toolchain.cmake new file mode 100644 index 0000000..6f16511 --- /dev/null +++ b/cmake/gcc-toolchain.cmake @@ -0,0 +1,11 @@ +# GCC Toolchain file for cpp-core +# Usage: cmake -DCMAKE_TOOLCHAIN_FILE=cmake/gcc-toolchain.cmake .. + +# Set the C++ compiler +set(CMAKE_CXX_COMPILER "g++") +set(CMAKE_C_COMPILER "gcc") + +# Compiler-specific flags +set(CMAKE_CXX_FLAGS_INIT "-Wall -Wextra -Wpedantic") +set(CMAKE_CXX_FLAGS_DEBUG_INIT "-g -O0") +set(CMAKE_CXX_FLAGS_RELEASE_INIT "-O3 -DNDEBUG") diff --git a/cmake/get_version_from_git.cmake b/cmake/get_version_from_git.cmake new file mode 100644 index 0000000..5a71921 --- /dev/null +++ b/cmake/get_version_from_git.cmake @@ -0,0 +1,76 @@ +# Function to get version from Git tags +# If a tag exists (e.g., v1.2.3 or 1.2.3), use it (with -dirty suffix if working tree is dirty) +# If no tag exists, use 0.0.0 (with -dirty suffix if working tree is dirty) + +function(get_version_from_git) + # Check if we're in a git repository + find_package(Git QUIET) + if(NOT Git_FOUND) + set(VERSION_MAJOR 0 PARENT_SCOPE) + set(VERSION_MINOR 0 PARENT_SCOPE) + set(VERSION_PATCH 0 PARENT_SCOPE) + set(VERSION_STRING "0.0.0-dev-no-git" PARENT_SCOPE) + return() + endif() + + # Get the latest tag + execute_process( + COMMAND ${GIT_EXECUTABLE} describe --tags --abbrev=0 + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_VARIABLE GIT_TAG + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET + ) + + # Check if working tree is dirty + execute_process( + COMMAND ${GIT_EXECUTABLE} diff --quiet --exit-code + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + RESULT_VARIABLE GIT_DIRTY_RESULT + ERROR_QUIET + ) + + # Get short commit hash + + if(GIT_TAG) + # Extract version from tag (remove 'v' prefix if present) + string(REGEX REPLACE "^v([0-9]+)\\..*" "\\1" VERSION_MAJOR "${GIT_TAG}") + string(REGEX REPLACE "^v?[0-9]+\\.([0-9]+)\\..*" "\\1" VERSION_MINOR "${GIT_TAG}") + string(REGEX REPLACE "^v?[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${GIT_TAG}") + + # If regex didn't match, try simpler pattern + if(NOT VERSION_MAJOR MATCHES "^[0-9]+$") + string(REGEX REPLACE "^v?([0-9]+)" "\\1" VERSION_MAJOR "${GIT_TAG}") + endif() + if(NOT VERSION_MINOR MATCHES "^[0-9]+$") + set(VERSION_MINOR "0") + endif() + if(NOT VERSION_PATCH MATCHES "^[0-9]+$") + set(VERSION_PATCH "0") + endif() + + # Check if dirty - if dirty, mark the version with -dirty suffix + if(GIT_DIRTY_RESULT) + set(VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}-dirty") + else() + set(VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}") + endif() + else() + # No tag found, use 0.0.0 (with -dirty if dirty) + set(VERSION_MAJOR "0") + set(VERSION_MINOR "0") + set(VERSION_PATCH "0") + if(GIT_DIRTY_RESULT) + set(VERSION_STRING "0.0.0-dirty") + else() + set(VERSION_STRING "0.0.0") + endif() + endif() + + # Return values to parent scope + set(VERSION_MAJOR ${VERSION_MAJOR} PARENT_SCOPE) + set(VERSION_MINOR ${VERSION_MINOR} PARENT_SCOPE) + set(VERSION_PATCH ${VERSION_PATCH} PARENT_SCOPE) + set(VERSION_STRING ${VERSION_STRING} PARENT_SCOPE) +endfunction() + diff --git a/cmake/msvc-toolchain.cmake b/cmake/msvc-toolchain.cmake new file mode 100644 index 0000000..0691dce --- /dev/null +++ b/cmake/msvc-toolchain.cmake @@ -0,0 +1,18 @@ +# MSVC Toolchain file for cpp-core +# Usage: cmake -DCMAKE_TOOLCHAIN_FILE=cmake/msvc-toolchain.cmake .. + +# Set the C++ compiler +set(CMAKE_CXX_COMPILER "cl") +set(CMAKE_C_COMPILER "cl") + +# MSVC-specific flags +# /W4 = Enable all warnings +# /permissive- = Conformance mode +# /Zc:__cplusplus = Enable updated __cplusplus macro +# /std:c++latest = Use latest C++ standard (C++23) +set(CMAKE_CXX_FLAGS_INIT "/W4 /permissive- /Zc:__cplusplus /std:c++latest") +set(CMAKE_CXX_FLAGS_DEBUG_INIT "/Zi /Od /MDd") +set(CMAKE_CXX_FLAGS_RELEASE_INIT "/O2 /DNDEBUG /MD") + +# MSVC-specific definitions +add_compile_definitions(_CRT_SECURE_NO_WARNINGS) diff --git a/docs/overview.md b/docs/overview.md deleted file mode 100644 index d69985c..0000000 --- a/docs/overview.md +++ /dev/null @@ -1,117 +0,0 @@ -# cpp-core – Library Overview - -Welcome to **cpp-core**, a header-only, cross-platform C++23 helper library that bundles utilities frequently needed in systems programming and embedded scenarios. Besides multiple compile-time helpers it exposes a fully-featured **C API for serial communication**, making the library consumable from virtually any language (Rust, Python, Deno, …). - -> ⚠️ **Looking for a ready-to-use shared library?** Build one of the platform bindings instead of cpp-core itself: -> • Windows → [cpp-bindings-windows](https://github.com/Serial-IO/cpp-bindings-windows) -> • Linux → [cpp-bindings-linux](https://github.com/Serial-IO/cpp-bindings-linux) - -> Looking for the raw function list? See the [C API reference](api_reference.md). -> -> Want to call the library from TypeScript? Jump straight to the [Deno FFI guide](deno_ffi.md). - ---- - -## What ships with cpp-core? - -| Area | Header | Highlights | -|------|--------|------------| -| Versioning | `cpp_core/version.h` | Compile-time `constexpr` version struct, filled during the build. -| Helpers | `cpp_core/helpers.h` | Collection of lightweight, header-only helper templates. -| Serial I/O | `cpp_core/serial.h` | Cross-platform serial helper built on the POSIX/Win32 APIs (see [C API reference](api_reference.md)). -| Error Codes| `cpp_core/status_codes.h` | Unified negative error codes shared across languages and bindings. - -All headers live in the `include/` tree and are directly usable after installation. - ---- - -## Directory structure - -``` -cpp-core/ -├── cmake/ # CMake helper modules -├── docs/ # You are here 📚 -├── include/ -│ └── cpp_core/ # Public headers (header-only!) -└── test/ # Unit tests (if enabled) -``` - ---- - -## Building the library - -### 1. Fetch & configure - -```bash -# clone -$ git clone https://github.com/Serial-IO/cpp-core.git -$ cd cpp-core - -# create an out-of-tree build directory -$ cmake -B build -DCMAKE_BUILD_TYPE=Release -``` - -### 2. Build & install (header-only) - -```bash -$ cmake --build build --target install -``` - -`install` copies the headers (and *optionally* a shared library, see below) to your default prefix (`/usr/local`, `Program Files/`, …). - -### 3. Building a shared library for FFI consumers - -Deno, Python and other FFI users expect a shared library (`*.so`, `*.dll`, `*.dylib`). Enable it like so: - -```bash -# add the switch – all code remains header-only for C++ callers -$ cmake -B build-shared -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Release -$ cmake --build build-shared --config Release - -# resulting artifact (Linux) -$ ls build-shared -libcpp_core.so # rename or copy as needed, e.g. to libserial.so -``` - -> **Tip**: keep the header files close to your FFI project so you can re-generate bindings easily. - ---- - -## Minimal C example - -```c -#include -#include - -int main() { - intptr_t h = serialOpen("/dev/ttyUSB0", 115200, 8, 0, 0); - if (h <= 0) { - fprintf(stderr, "open failed: %ld\n", (long)h); - return 1; - } - - const char msg[] = "hello\n"; - serialWriteLine(h, msg, sizeof msg - 1, 1000); - - char buf[64]; - int n = serialReadLine(h, buf, sizeof buf, 1000); - fwrite(buf, 1, n, stdout); - - serialClose(h); -} -``` - -For a deep dive into every parameter head over to the [C API reference](api_reference.md). - ---- - -## Going further - -* **Deno, Node, Python & Rust**: see the dedicated [Deno FFI guide](deno_ffi.md) which includes a complete TypeScript example and hints for other languages. -* **Questions / issues** – open a ticket on GitHub; contributions are welcome! - ---- - -## License - -cpp-core is licensed under the terms of the Apache-2.0 license. See [LICENSE](../LICENSE) for details. diff --git a/include/cpp_core.h b/include/cpp_core.h index 59edc64..1f50732 100644 --- a/include/cpp_core.h +++ b/include/cpp_core.h @@ -13,7 +13,6 @@ */ #include "cpp_core/error_callback.h" -#include "cpp_core/interface/sequential.h" #include "cpp_core/serial.h" #include "cpp_core/status_codes.h" #include "cpp_core/version.h" diff --git a/include/cpp_core/interface/sequential.h b/include/cpp_core/interface/sequential.h deleted file mode 100644 index e4731c6..0000000 --- a/include/cpp_core/interface/sequential.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -// Sequential wrappers -#include "sequential/serial_abort_read_sequential.h" -#include "sequential/serial_abort_write_sequential.h" -#include "sequential/serial_clear_buffer_in_sequential.h" -#include "sequential/serial_clear_buffer_out_sequential.h" -#include "sequential/serial_close_sequential.h" -#include "sequential/serial_drain_sequential.h" -#include "sequential/serial_in_bytes_total_sequential.h" -#include "sequential/serial_in_bytes_waiting_sequential.h" -#include "sequential/serial_out_bytes_total_sequential.h" -#include "sequential/serial_out_bytes_waiting_sequential.h" -#include "sequential/serial_read_line_sequential.h" -#include "sequential/serial_read_sequential.h" -#include "sequential/serial_read_until_sequence_sequential.h" -#include "sequential/serial_read_until_sequential.h" -#include "sequential/serial_write_sequential.h" diff --git a/include/cpp_core/interface/sequential/serial_abort_read_sequential.h b/include/cpp_core/interface/sequential/serial_abort_read_sequential.h deleted file mode 100644 index b9dd5a1..0000000 --- a/include/cpp_core/interface/sequential/serial_abort_read_sequential.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#include "../../error_callback.h" -#include "../../internal/sequential/call.h" -#include "../serial_abort_read.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - - /** - * @copydoc serialAbortRead - * @note Sequential variant: guarantees execution in the exact order the calls were made across threads. - */ - inline MODULE_API auto serialAbortReadSequential( - int64_t handle, - ErrorCallbackT error_callback = nullptr - ) -> int - { - return cpp_core::internal::sequential::call(handle, [=] { return serialAbortRead(handle, error_callback); }); - } - -#ifdef __cplusplus -} -#endif diff --git a/include/cpp_core/interface/sequential/serial_abort_write_sequential.h b/include/cpp_core/interface/sequential/serial_abort_write_sequential.h deleted file mode 100644 index c7e42cc..0000000 --- a/include/cpp_core/interface/sequential/serial_abort_write_sequential.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#include "../../error_callback.h" -#include "../../internal/sequential/call.h" -#include "../serial_abort_write.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - - /** - * @copydoc serialAbortWrite - * @note Sequential variant: guarantees execution in the exact order the calls were made across threads. - */ - inline MODULE_API auto serialAbortWriteSequential( - int64_t handle, - ErrorCallbackT error_callback = nullptr - ) -> int - { - return cpp_core::internal::sequential::call(handle, [=] { return serialAbortWrite(handle, error_callback); }); - } - -#ifdef __cplusplus -} -#endif diff --git a/include/cpp_core/interface/sequential/serial_clear_buffer_in_sequential.h b/include/cpp_core/interface/sequential/serial_clear_buffer_in_sequential.h deleted file mode 100644 index 6288caa..0000000 --- a/include/cpp_core/interface/sequential/serial_clear_buffer_in_sequential.h +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once - -#include "../../error_callback.h" -#include "../../internal/sequential/call.h" -#include "../serial_clear_buffer_in.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - - /** - * @copydoc serialClearBufferIn - * @note Sequential variant: guarantees execution in the exact order the calls were made across threads. - */ - inline MODULE_API auto serialClearBufferInSequential( - int64_t handle, - ErrorCallbackT error_callback = nullptr - ) -> int - { - return cpp_core::internal::sequential::call(handle, [=] { - return serialClearBufferIn(handle, error_callback); - }); - } - -#ifdef __cplusplus -} -#endif diff --git a/include/cpp_core/interface/sequential/serial_clear_buffer_out_sequential.h b/include/cpp_core/interface/sequential/serial_clear_buffer_out_sequential.h deleted file mode 100644 index 3d58d98..0000000 --- a/include/cpp_core/interface/sequential/serial_clear_buffer_out_sequential.h +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once - -#include "../../error_callback.h" -#include "../../internal/sequential/call.h" -#include "../serial_clear_buffer_out.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - - /** - * @copydoc serialClearBufferOut - * @note Sequential variant: guarantees execution in the exact order the calls were made across threads. - */ - inline MODULE_API auto serialClearBufferOutSequential( - int64_t handle, - ErrorCallbackT error_callback = nullptr - ) -> int - { - return cpp_core::internal::sequential::call(handle, [=] { - return serialClearBufferOut(handle, error_callback); - }); - } - -#ifdef __cplusplus -} -#endif diff --git a/include/cpp_core/interface/sequential/serial_close_sequential.h b/include/cpp_core/interface/sequential/serial_close_sequential.h deleted file mode 100644 index 7c9aa0a..0000000 --- a/include/cpp_core/interface/sequential/serial_close_sequential.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#include "../../error_callback.h" -#include "../../internal/sequential/call.h" -#include "../serial_close.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - - /** - * @copydoc serialClose - * @note Sequential variant: guarantees execution in the exact order the calls were made across threads. - */ - inline MODULE_API auto serialCloseSequential( - int64_t handle, - ErrorCallbackT error_callback = nullptr - ) -> int - { - return cpp_core::internal::sequential::call(handle, [=] { return serialClose(handle, error_callback); }); - } - -#ifdef __cplusplus -} -#endif diff --git a/include/cpp_core/interface/sequential/serial_drain_sequential.h b/include/cpp_core/interface/sequential/serial_drain_sequential.h deleted file mode 100644 index 5216b39..0000000 --- a/include/cpp_core/interface/sequential/serial_drain_sequential.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#include "../../error_callback.h" -#include "../../internal/sequential/call.h" -#include "../serial_drain.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - - /** - * @copydoc serialDrain - * @note Sequential variant: guarantees execution in the exact order the calls were made across threads. - */ - inline MODULE_API auto serialDrainSequential( - int64_t handle, - ErrorCallbackT error_callback = nullptr - ) -> int - { - return cpp_core::internal::sequential::call(handle, [=] { return serialDrain(handle, error_callback); }); - } - -#ifdef __cplusplus -} -#endif diff --git a/include/cpp_core/interface/sequential/serial_in_bytes_total_sequential.h b/include/cpp_core/interface/sequential/serial_in_bytes_total_sequential.h deleted file mode 100644 index 9f40ac7..0000000 --- a/include/cpp_core/interface/sequential/serial_in_bytes_total_sequential.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#include "../../error_callback.h" -#include "../../internal/sequential/call.h" -#include "../serial_in_bytes_total.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - - /** - * @copydoc serialInBytesTotal - * @note Sequential variant: guarantees execution in the exact order the calls were made across threads. - */ - inline MODULE_API auto serialInBytesTotalSequential( - int64_t handle, - ErrorCallbackT error_callback = nullptr - ) -> int64_t - { - return cpp_core::internal::sequential::call(handle, [=] { return serialInBytesTotal(handle, error_callback); }); - } - -#ifdef __cplusplus -} -#endif diff --git a/include/cpp_core/interface/sequential/serial_in_bytes_waiting_sequential.h b/include/cpp_core/interface/sequential/serial_in_bytes_waiting_sequential.h deleted file mode 100644 index eb5ee6b..0000000 --- a/include/cpp_core/interface/sequential/serial_in_bytes_waiting_sequential.h +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once - -#include "../../error_callback.h" -#include "../../internal/sequential/call.h" -#include "../serial_in_bytes_waiting.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - - /** - * @copydoc serialInBytesWaiting - * @note Sequential variant: guarantees execution in the exact order the calls were made across threads. - */ - inline MODULE_API auto serialInBytesWaitingSequential( - int64_t handle, - ErrorCallbackT error_callback = nullptr - ) -> int - { - return cpp_core::internal::sequential::call(handle, [=] { - return serialInBytesWaiting(handle, error_callback); - }); - } - -#ifdef __cplusplus -} -#endif diff --git a/include/cpp_core/interface/sequential/serial_out_bytes_total_sequential.h b/include/cpp_core/interface/sequential/serial_out_bytes_total_sequential.h deleted file mode 100644 index 6528871..0000000 --- a/include/cpp_core/interface/sequential/serial_out_bytes_total_sequential.h +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once - -#include "../../error_callback.h" -#include "../../internal/sequential/call.h" -#include "../serial_out_bytes_total.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - - /** - * @copydoc serialOutBytesTotal - * @note Sequential variant: guarantees execution in the exact order the calls were made across threads. - */ - inline MODULE_API auto serialOutBytesTotalSequential( - int64_t handle, - ErrorCallbackT error_callback = nullptr - ) -> int64_t - { - return cpp_core::internal::sequential::call(handle, [=] { - return serialOutBytesTotal(handle, error_callback); - }); - } - -#ifdef __cplusplus -} -#endif diff --git a/include/cpp_core/interface/sequential/serial_out_bytes_waiting_sequential.h b/include/cpp_core/interface/sequential/serial_out_bytes_waiting_sequential.h deleted file mode 100644 index 82abef2..0000000 --- a/include/cpp_core/interface/sequential/serial_out_bytes_waiting_sequential.h +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once - -#include "../../error_callback.h" -#include "../../internal/sequential/call.h" -#include "../serial_out_bytes_waiting.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - - /** - * @copydoc serialOutBytesWaiting - * @note Sequential variant: guarantees execution in the exact order the calls were made across threads. - */ - inline MODULE_API auto serialOutBytesWaitingSequential( - int64_t handle, - ErrorCallbackT error_callback = nullptr - ) -> int - { - return cpp_core::internal::sequential::call(handle, [=] { - return serialOutBytesWaiting(handle, error_callback); - }); - } - -#ifdef __cplusplus -} -#endif diff --git a/include/cpp_core/interface/sequential/serial_read_line_sequential.h b/include/cpp_core/interface/sequential/serial_read_line_sequential.h deleted file mode 100644 index dae9685..0000000 --- a/include/cpp_core/interface/sequential/serial_read_line_sequential.h +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#include "../../error_callback.h" -#include "../../internal/sequential/call.h" -#include "../serial_read_line.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - - /** - * @copydoc serialReadLine - * @note Sequential variant: guarantees execution in the exact order the calls were made across threads. - */ - inline MODULE_API auto serialReadLineSequential( - int64_t handle, - void *buffer, - int buffer_size, - int timeout_ms, - int multiplier, - ErrorCallbackT error_callback = nullptr - ) -> int - { - return cpp_core::internal::sequential::call(handle, [=] { - return serialReadLine(handle, buffer, buffer_size, timeout_ms, multiplier, error_callback); - }); - } - -#ifdef __cplusplus -} -#endif diff --git a/include/cpp_core/interface/sequential/serial_read_sequential.h b/include/cpp_core/interface/sequential/serial_read_sequential.h deleted file mode 100644 index 88ca226..0000000 --- a/include/cpp_core/interface/sequential/serial_read_sequential.h +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#include "../../error_callback.h" -#include "../../internal/sequential/call.h" -#include "../serial_read.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - - /** - * @copydoc serialRead - * @note Sequential variant: guarantees execution in the exact order the calls were made across threads. - */ - inline MODULE_API auto serialReadSequential( - int64_t handle, - void *buffer, - int buffer_size, - int timeout_ms, - int multiplier, - ErrorCallbackT error_callback = nullptr - ) -> int - { - return cpp_core::internal::sequential::call(handle, [=] { - return serialRead(handle, buffer, buffer_size, timeout_ms, multiplier, error_callback); - }); - } - -#ifdef __cplusplus -} -#endif diff --git a/include/cpp_core/interface/sequential/serial_read_until_sequence_sequential.h b/include/cpp_core/interface/sequential/serial_read_until_sequence_sequential.h deleted file mode 100644 index cdcc6d4..0000000 --- a/include/cpp_core/interface/sequential/serial_read_until_sequence_sequential.h +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once - -#include "../../error_callback.h" -#include "../../internal/sequential/call.h" -#include "../serial_read_until_sequence.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - - /** - * @copydoc serialReadUntilSequence - * @note Sequential variant: guarantees execution in the exact order the calls were made across threads. - */ - inline MODULE_API auto serialReadUntilSequenceSequential( - int64_t handle, - void *buffer, - int buffer_size, - int timeout_ms, - int multiplier, - void *sequence, - ErrorCallbackT error_callback = nullptr - ) -> int - { - return cpp_core::internal::sequential::call(handle, [=] { - return serialReadUntilSequence( - handle, buffer, buffer_size, timeout_ms, multiplier, sequence, error_callback - ); - }); - } - -#ifdef __cplusplus -} -#endif diff --git a/include/cpp_core/interface/sequential/serial_read_until_sequential.h b/include/cpp_core/interface/sequential/serial_read_until_sequential.h deleted file mode 100644 index 1b1780f..0000000 --- a/include/cpp_core/interface/sequential/serial_read_until_sequential.h +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#include "../../error_callback.h" -#include "../../internal/sequential/call.h" -#include "../serial_read_until.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - - /** - * @copydoc serialReadUntil - * @note Sequential variant: guarantees execution in the exact order the calls were made across threads. - */ - inline MODULE_API auto serialReadUntilSequential( - int64_t handle, - void *buffer, - int buffer_size, - int timeout_ms, - int multiplier, - void *until_char, - ErrorCallbackT error_callback = nullptr - ) -> int - { - return cpp_core::internal::sequential::call(handle, [=] { - return serialReadUntil(handle, buffer, buffer_size, timeout_ms, multiplier, until_char, error_callback); - }); - } - -#ifdef __cplusplus -} -#endif diff --git a/include/cpp_core/interface/sequential/serial_write_sequential.h b/include/cpp_core/interface/sequential/serial_write_sequential.h deleted file mode 100644 index be82826..0000000 --- a/include/cpp_core/interface/sequential/serial_write_sequential.h +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#include "../../error_callback.h" -#include "../../internal/sequential/call.h" -#include "../serial_write.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - - /** - * @copydoc serialWrite - * @note Sequential variant: guarantees execution in the exact order the calls were made across threads. - */ - inline MODULE_API auto serialWriteSequential( - int64_t handle, - const void *buffer, - int buffer_size, - int timeout_ms, - int multiplier, - ErrorCallbackT error_callback = nullptr - ) -> int - { - return cpp_core::internal::sequential::call(handle, [=] { - return serialWrite(handle, buffer, buffer_size, timeout_ms, multiplier, error_callback); - }); - } - -#ifdef __cplusplus -} -#endif diff --git a/include/cpp_core/interface/serial_get_ports_info.h b/include/cpp_core/interface/serial_list_ports.h similarity index 96% rename from include/cpp_core/interface/serial_get_ports_info.h rename to include/cpp_core/interface/serial_list_ports.h index 665f981..0a5d34a 100644 --- a/include/cpp_core/interface/serial_get_ports_info.h +++ b/include/cpp_core/interface/serial_list_ports.h @@ -17,7 +17,7 @@ extern "C" * @param error_callback [optional] Callback to invoke on error. Defined in error_callback.h. Default is `nullptr`. * @return Number of ports found or a negative error code from ::cpp_core::StatusCodes on error. */ - MODULE_API auto serialGetPortsInfo( + MODULE_API auto serialListPorts( void (*callback_fn)( const char *port, const char *path, diff --git a/include/cpp_core/internal/sequential/call.h b/include/cpp_core/internal/sequential/call.h deleted file mode 100644 index 3404f58..0000000 --- a/include/cpp_core/internal/sequential/call.h +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#include "execute_in_queue.h" -#include "state_for_handle.h" -#include -#include - -namespace cpp_core::internal::sequential -{ -/** - * @brief Executes the given callable in the sequential dispatch queue associated with the specified handle. - * - * This helper forwards the callable to executeInQueue() together with the - * DispatchState that belongs to @p handle, thereby ensuring that all calls - * targeting the same handle are processed strictly sequentially. - * - * @tparam FunctionT Type of the invocable object. - * @param handle Handle identifying the sequential queue. - * @param function Callable object to execute. Can return any type (including void). - * @return Whatever @p function returns. - */ -template -auto call( - int64_t handle, - FunctionT &&function -) -> decltype(function()) -{ - return executeInQueue( - ::cpp_core::internal::sequential::internal::stateForHandle(handle), std::forward(function) - ); -} -} // namespace cpp_core::internal::sequential diff --git a/include/cpp_core/internal/sequential/dispatch_state.h b/include/cpp_core/internal/sequential/dispatch_state.h deleted file mode 100644 index 0436427..0000000 --- a/include/cpp_core/internal/sequential/dispatch_state.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include - -namespace cpp_core::internal::sequential -{ -/** - * @brief Holds the queue and synchronisation primitives used by the sequential dispatch system. - */ -struct DispatchState -{ - // Mutex protecting queue + condition_variable. - std::mutex mutex; - - // Condition variable to wake the worker thread when new jobs arrive. - std::condition_variable condition_variable; - - // FIFO containing packaged thunks (jobs). - std::queue> queue; - - // Indicates if the worker thread is already launched. - std::once_flag worker_started; -}; -} // namespace cpp_core::internal::sequential diff --git a/include/cpp_core/internal/sequential/ensure_worker_running.h b/include/cpp_core/internal/sequential/ensure_worker_running.h deleted file mode 100644 index d82aea7..0000000 --- a/include/cpp_core/internal/sequential/ensure_worker_running.h +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include "dispatch_state.h" -#include "worker_loop.h" -#include -#include - -namespace cpp_core::internal::sequential -{ -/** - * @brief Starts the worker thread for @p state if it is not already running. - * - * The worker thread executes workerLoop() on the given DispatchState. A - * call_once flag inside the state guarantees that the thread is only created - * the first time this function is invoked. - * - * @param state DispatchState whose queue should be processed by the worker. - */ -inline void ensureWorkerRunning(DispatchState &state) -{ - std::call_once(state.worker_started, [&state] { std::thread([&state] { workerLoop(state); }).detach(); }); -} -} // namespace cpp_core::internal::sequential diff --git a/include/cpp_core/internal/sequential/execute_in_queue.h b/include/cpp_core/internal/sequential/execute_in_queue.h deleted file mode 100644 index 19e9a03..0000000 --- a/include/cpp_core/internal/sequential/execute_in_queue.h +++ /dev/null @@ -1,53 +0,0 @@ -#pragma once - -#include "dispatch_state.h" -#include "ensure_worker_running.h" -#include -#include -#include -#include -#include - -namespace cpp_core::internal::sequential -{ -/** - * @brief Queues the given callable in @p state and returns its result. - * - * The function first makes sure a worker thread is active via - * ensureWorkerRunning(). It then enqueues the callable and blocks until the - * callable has completed, forwarding the return value (if any). - * - * @tparam FunctionT Type of the callable object. - * @param state DispatchState that owns the queue and synchronisation primitives. - * @param function Callable object to execute. Can return any type. - * @return Result produced by @p function or void if it returns void. - */ -template -auto executeInQueue( - DispatchState &state, - FunctionT &&function -) -> decltype(function()) -{ - using FunctionReturnT = decltype(function()); - - auto task_ptr = std::make_shared>(std::forward(function)); - auto future = task_ptr->get_future(); - - ensureWorkerRunning(state); - - { - std::lock_guard lock(state.mutex); - state.queue.emplace([task_ptr]() { (*task_ptr)(); }); - } - state.condition_variable.notify_one(); - - if constexpr (std::is_void_v) - { - future.get(); - } - else - { - return future.get(); - } -} -} // namespace cpp_core::internal::sequential diff --git a/include/cpp_core/internal/sequential/handle_states.h b/include/cpp_core/internal/sequential/handle_states.h deleted file mode 100644 index 0741a4e..0000000 --- a/include/cpp_core/internal/sequential/handle_states.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include "dispatch_state.h" -#include -#include -#include - -namespace cpp_core::internal::sequential::internal -{ -/** - * @brief Gives access to the global handle -> DispatchState map. - * - * The map is lazily initialised on first access and is intended to be - * protected by handleStatesMutex(). - * - * @return Reference to the singleton unordered_map storing all DispatchStates. - */ -inline auto handleStates() -> std::unordered_map< - int64_t, - cpp_core::internal::sequential::DispatchState> & -{ - static std::unordered_map instance; - return instance; -} -} // namespace cpp_core::internal::sequential::internal diff --git a/include/cpp_core/internal/sequential/handle_states_mutex.h b/include/cpp_core/internal/sequential/handle_states_mutex.h deleted file mode 100644 index 5d2b6a8..0000000 --- a/include/cpp_core/internal/sequential/handle_states_mutex.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include - -namespace cpp_core::internal::sequential::internal -{ -/** - * @brief Returns the mutex guarding access to handleStates(). - * - * @return Reference to the singleton std::mutex. - */ -inline auto handleStatesMutex() -> std::mutex & -{ - static std::mutex instance; - return instance; -} -} // namespace cpp_core::internal::sequential::internal diff --git a/include/cpp_core/internal/sequential/state_for_handle.h b/include/cpp_core/internal/sequential/state_for_handle.h deleted file mode 100644 index c0e62cb..0000000 --- a/include/cpp_core/internal/sequential/state_for_handle.h +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include "handle_states.h" -#include "handle_states_mutex.h" -#include -#include - -namespace cpp_core::internal::sequential::internal -{ -/** - * @brief Retrieves the DispatchState associated with the specified handle. - * - * The global map is protected by a mutex to make this operation thread-safe. - * - * @param handle Identifier of the sequential dispatch queue. - * @return Reference to the corresponding DispatchState object. - */ -inline auto stateForHandle(int64_t handle) -> cpp_core::internal::sequential::DispatchState & -{ - std::lock_guard lock(handleStatesMutex()); - return handleStates()[handle]; -} -} // namespace cpp_core::internal::sequential::internal diff --git a/include/cpp_core/internal/sequential/worker_loop.h b/include/cpp_core/internal/sequential/worker_loop.h deleted file mode 100644 index 6961ae6..0000000 --- a/include/cpp_core/internal/sequential/worker_loop.h +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include "dispatch_state.h" -#include -#include -#include -#include - -namespace cpp_core::internal::sequential -{ -/** - * @brief Blocking loop that continuously processes jobs from @p state. - * - * Intended to run on a background thread created by ensureWorkerRunning(). - * The loop waits on a condition variable until a job is available, executes - * it and then repeats indefinitely. - * - * @param state DispatchState providing the job queue and synchronisation primitives. - */ -inline void workerLoop(DispatchState &state) -{ - for (;;) - { - std::function job; - { - std::unique_lock lock(state.mutex); - state.condition_variable.wait(lock, [&state] { return !state.queue.empty(); }); - job = std::move(state.queue.front()); - state.queue.pop(); - } - job(); - } -} -} // namespace cpp_core::internal::sequential diff --git a/include/cpp_core/serial.h b/include/cpp_core/serial.h index e7e142a..c8bc160 100644 --- a/include/cpp_core/serial.h +++ b/include/cpp_core/serial.h @@ -11,9 +11,9 @@ #include "interface/serial_clear_buffer_out.h" #include "interface/serial_close.h" #include "interface/serial_drain.h" -#include "interface/serial_get_ports_info.h" #include "interface/serial_in_bytes_total.h" #include "interface/serial_in_bytes_waiting.h" +#include "interface/serial_list_ports.h" #include "interface/serial_open.h" #include "interface/serial_out_bytes_total.h" #include "interface/serial_out_bytes_waiting.h" diff --git a/include/cpp_core/version.h.in b/include/cpp_core/version.h.in index 4b398fc..ac76ee0 100644 --- a/include/cpp_core/version.h.in +++ b/include/cpp_core/version.h.in @@ -10,8 +10,11 @@ struct Version unsigned int patch; }; -// Generated at configure time. Parent project can override the numbers via -// -DCPP_CORE_VERSION_XXX=... or CPM OPTIONS -inline constexpr Version kVersion{@CPP_CORE_VERSION_MAJOR@U, @CPP_CORE_VERSION_MINOR@U, @CPP_CORE_VERSION_PATCH@U}; +// Generated at configure time from Git tags (or dirty build version if no tag). +// Version is determined automatically from Git tags and cannot be overridden. +inline constexpr Version kVersion +{ + @CPP_CORE_VERSION_MAJOR@U, @CPP_CORE_VERSION_MINOR@U, @CPP_CORE_VERSION_PATCH@U +}; } // namespace cpp_core