Skip to content

Commit

Permalink
jstore: initial commit
Browse files Browse the repository at this point in the history
JSON configuration and state serialization and introspection library.
  • Loading branch information
DavidLeeds authored and dleeds-cpi committed Sep 26, 2024
0 parents commit 7b6ab90
Show file tree
Hide file tree
Showing 18 changed files with 4,115 additions and 0 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false

matrix:
os: [ubuntu-latest]
build_type: [Release, Debug]
cpp_compiler: [g++, clang]
dbus_support: [OFF, ON]

steps:
- uses: actions/checkout@v4

- name: Set reusable strings
# Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file.
id: strings
shell: bash
run: echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"

- name: Configure CMake
# Configure CMake in a 'build' subdirectory.
run: >
cmake
-B ${{ steps.strings.outputs.build-output-dir }}
-S ${{ github.workspace }}
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-DCMAKE_CXX_STANDARD=20
-DJSTORE_BUILD_JSON=ON
-DJSTORE_BUILD_DBUS=ON
-DJSTORE_BUILD_TESTS=ON
-DJSTORE_BUILD_EXAMPLES=ON
-DJSTORE_BUILD_EXAMPLES=ON
-DJSTORE_ENABLE_DBUS=${{ matrix.dbus_support }}
- name: Build
# Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}

- name: Test
working-directory: ${{ steps.strings.outputs.build-output-dir }}
# Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
run: dbus-run-session ctest --output-on-failure --build-config ${{ matrix.build_type }}
32 changes: 32 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Prerequisites
*.d

# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app
71 changes: 71 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# -------------------------------
# JSON Configuration Storage library
# -------------------------------

cmake_minimum_required(VERSION 3.16)
project(
jstore
VERSION 1.0.0
LANGUAGES CXX
)

# -------------------------------
# Project Options
# -------------------------------

option(JSTORE_BUILD_JSON "Fetch the nlohmann_json library, instead of searching for it in the system" OFF)
option(JSTORE_BUILD_DBUS "Fetch the sdbus-c++ library, instead of searching for it in the system" OFF)
option(JSTORE_BUILD_TESTS "Build tests" OFF)
option(JSTORE_BUILD_EXAMPLES "Build examples" OFF)
option(JSTORE_ENABLE_DBUS "Enable remote access to the data model via D-Bus (sdbus-c++ library)" OFF)

# -------------------------------
# Setup Compiler
# -------------------------------

# Set compiler options
if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 20)
endif()
set(CMAKE_CXX_EXTENSIONS OFF)

# -------------------------------
# Resolve library dependencies
# -------------------------------

add_subdirectory(thirdparty)

# -------------------------------
# Build Library
# -------------------------------

add_library(jstore INTERFACE)
target_compile_features(jstore INTERFACE cxx_std_20)
target_include_directories(jstore INTERFACE include)
target_link_libraries(jstore INTERFACE nlohmann_json::nlohmann_json fmt::fmt visit_struct::visit_struct)

# Optional D-Bus integration using sdbus-c++ library
if(JSTORE_ENABLE_DBUS)
target_compile_definitions(jstore INTERFACE JSTORE_SDBUSCPP=1)
target_link_libraries(jstore INTERFACE SDBusCpp::sdbus-c++)
else()
target_compile_definitions(jstore INTERFACE JSTORE_SDBUSCPP=0)
endif()

# -------------------------------
# Build Unit Tests
# -------------------------------

if(JSTORE_BUILD_TESTS)
message(STATUS "jstore: building with tests")
enable_testing()
add_subdirectory(tests)
endif()

# -------------------------------
# Build Examples
# -------------------------------

if(JSTORE_BUILD_EXAMPLES)
# add_subdirectory(examples)
endif()
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 David Leeds

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# jstore
C++ '20 library for serialization and persistent storage of application configuration and state

[![CI](https://github.com/DavidLeeds/jstore/actions/workflows/ci.yml/badge.svg)](https://github.com/DavidLeeds/jstore/actions/workflows/ci.yml)
27 changes: 27 additions & 0 deletions dbus/JStore.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">

<node>

<interface name="io.davidleeds.JStore">
<method name="Get">
<arg type="s" name="Path" direction="in" />
<arg type="s" name="ValueJson" direction="out" />
</method>

<method name="GetAll">
<!-- dict{path, JSON encoded value} -->
<arg type="a{ss}" name="ValuesJson" direction="out" />
</method>

<method name="Set">
<arg type="s" name="Path" direction="in" />
<arg type="s" name="ValueJson" direction="in" />
</method>

<signal name="ValuesChanged">
<arg type="a{ss}" name="Values" />
</signal>
</interface>

</node>
Loading

0 comments on commit 7b6ab90

Please sign in to comment.