diff --git a/.docker/Dockerfile b/.docker/Dockerfile index df8ef0a9f18f5754eae33686e832bd88f37da9de..9695b6f80950698ca7a587ed2c649c8f10b43549 100644 --- a/.docker/Dockerfile +++ b/.docker/Dockerfile @@ -1,24 +1,33 @@ -FROM debian:bullseye +FROM debian:bookworm RUN apt-get update RUN apt-get install -y cmake -RUN apt-get install -y lcov +# iwyu is not a strict dependency here, but in the cppinttests. +RUN apt-get install -y lcov iwyu RUN apt-get install -y doxygen graphviz -RUN apt-get install -y clang-format-11 clang-tidy-11 -RUN apt-get install -y python3-pip -RUN apt-get install -y git -RUN apt-get install -y curl - -RUN apt-get install -y openjdk-11-jdk-headless - +RUN apt-get install -y clang-format-16 clang-tidy-16 +RUN apt-get install -y python3-pip python3-venv +RUN apt-get install -y git +RUN apt-get install -y curl zip unzip tar +RUN apt-get install -y perl pkg-config +RUN apt-get install -y openjdk-17-jdk-headless WORKDIR / +RUN python3 -m venv ./venv +RUN . ./venv/bin/activate COPY doc/requirements.txt doc-requirements.txt -RUN pip3 install -r doc-requirements.txt +RUN ./venv/bin/pip install -r doc-requirements.txt COPY requirements.txt build-requirements.txt -RUN pip3 install -r build-requirements.txt +RUN ./venv/bin/pip install -r build-requirements.txt +RUN ./venv/bin/conan profile detect + +ENV PATH=/venv/bin:$PATH COPY . /libcaosdb/ WORKDIR /libcaosdb RUN git rev-parse HEAD > libcaosdb_commit RUN rm -rf .git + +# build dependencies +RUN /venv/bin/conan install /libcaosdb --build=missing -s build_type=Debug +RUN /venv/bin/conan install /libcaosdb --build=missing -s build_type=Release diff --git a/.gitignore b/.gitignore index 7ddf9b7e3c77a0cc492c738c47b5a97a6b7e7997..82ee632624bd0b2aa8876df6435b72046a2f7db3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ # General build/ -include/libcaosdbConfig.h +include/liblinkaheadConfig.h .* # CMake @@ -154,3 +154,6 @@ conanbuildinfo.cmake conanbuildinfo.txt conaninfo.txt graph_info.json + +# vcpkg +vcpkg_installed \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9e4b424b096beac09b2c130ab0fe041f56196d8b..f200853328d4da817249e4fbebd9540e53256c31 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -78,23 +78,31 @@ code_style: tags: [ docker ] stage: test script: - - clang-format-11 --dry-run --verbose --Werror $(find test/ src/ include/ -type f -iname "*.cpp" -o -iname "*.h" -o -iname "*.h.in") + - clang-format-16 --dry-run --verbose --Werror $(find test/ src/ include/ -type f -iname "*.cpp" -o -iname "*.h" -o -iname "*.h.in") + allow_failure: true + + +# build with vcpkg +build_vcpkg: + tags: [ docker ] + stage: test + script: + - cd vcpkg && git fetch origin 5d3798ac7388ca66c169773e46103b14077b76a4 && cd .. + - make vcpkg-build-release allow_failure: true # unit tests with gtest -test: +test-debug: + tags: [ docker ] + stage: test + script: + - make test-debug + +test-release: tags: [ docker ] stage: test script: - - mkdir build - - cd build - - VERSION="$(conan inspect --raw version ..)" - - conan install -s "compiler.libcxx=libstdc++11" --build=missing -o build_acm=True .. "caosdb/$VERSION@_/_" - - cmake -DCMAKE_BUILD_TYPE=Debug .. - - cmake --build . -j - - cmake --build . -j --target unit_test_coverage - - cmake --build . -j --target cxxcaosdbcli - # - cmake --build . -j --target ccaosdbcli # Disabled until it compiles again. + - make test-release trigger_prepare: # Calculate the branch name @@ -173,49 +181,49 @@ trigger_inttest: branch: $CPPINT_REF strategy: depend -# After the cppinttest have been successful, also start tests for Octave... -trigger_octavelib: - stage: deploy - needs: [ trigger_prepare, trigger_inttest ] - inherit: - variables: - # List the variables that shall be inherited, which also means they will override any equally - # named varibles in child pipelines. - - TRIGGERED_BY_REPO - - TRIGGERED_BY_REF - - TRIGGERED_BY_HASH - - CPPLIB_REGISTRY_IMAGE - variables: - # dotenv variables must be set again here. - F_BRANCH: $F_BRANCH - trigger: - project: caosdb/src/caosdb-octavelib - branch: $OCTAVELIB_REF - # It's ok if octave fails in case of features that might already be - # implemented in proto, server, and cpplib, but not yet in Octave. - allow_failure: true - -# ... and for Julia. -trigger_julialib: - stage: deploy - needs: [ trigger_prepare, trigger_inttest ] - inherit: - variables: - # List the variables that shall be inherited, which also means they will override any equally - # named varibles in child pipelines. - - TRIGGERED_BY_REPO - - TRIGGERED_BY_REF - - TRIGGERED_BY_HASH - - CPPLIB_REGISTRY_IMAGE - variables: - # dotenv variables must be set again here. - F_BRANCH: $F_BRANCH - trigger: - project: caosdb/src/caosdb-julialib - branch: $JULIALIB_REF - # It's ok if julia fails in case of features that might already be - # implemented in proto, server, and cpplib, but not yet in Julia. - allow_failure: true +# # After the cppinttest have been successful, also start tests for Octave... +# trigger_octavelib: +# stage: deploy +# needs: [ trigger_prepare, trigger_inttest ] +# inherit: +# variables: +# # List the variables that shall be inherited, which also means they will override any equally +# # named varibles in child pipelines. +# - TRIGGERED_BY_REPO +# - TRIGGERED_BY_REF +# - TRIGGERED_BY_HASH +# - CPPLIB_REGISTRY_IMAGE +# variables: +# # dotenv variables must be set again here. +# F_BRANCH: $F_BRANCH +# trigger: +# project: caosdb/src/caosdb-octavelib +# branch: $OCTAVELIB_REF +# # It's ok if octave fails in case of features that might already be +# # implemented in proto, server, and cpplib, but not yet in Octave. +# allow_failure: true + +# # ... and for Julia. +# trigger_julialib: +# stage: deploy +# needs: [ trigger_prepare, trigger_inttest ] +# inherit: +# variables: +# # List the variables that shall be inherited, which also means they will override any equally +# # named varibles in child pipelines. +# - TRIGGERED_BY_REPO +# - TRIGGERED_BY_REF +# - TRIGGERED_BY_HASH +# - CPPLIB_REGISTRY_IMAGE +# variables: +# # dotenv variables must be set again here. +# F_BRANCH: $F_BRANCH +# trigger: +# project: caosdb/src/caosdb-julialib +# branch: $JULIALIB_REF +# # It's ok if julia fails in case of features that might already be +# # implemented in proto, server, and cpplib, but not yet in Julia. +# allow_failure: true # Build the sphinx documentation and make it ready for deployment by Gitlab Pages # Special job for serving a static website. See https://docs.gitlab.com/ee/ci/yaml/README.html#pages @@ -224,7 +232,7 @@ trigger_julialib: stage: deploy script: - make doc - - cp -r build/doc/sphinx_out ./public + - cp -r build/Release/doc/sphinx_out ./public test_pages: <<: *pages_prepare diff --git a/.gitlab/merge_request_templates/Default.md b/.gitlab/merge_request_templates/Default.md index 35c6d01c5904289b77fc7f1de9419ef91a1510e9..3629e0ca3695000863d8c254516f64bf59a7bf60 100644 --- a/.gitlab/merge_request_templates/Default.md +++ b/.gitlab/merge_request_templates/Default.md @@ -28,6 +28,7 @@ guidelines](https://gitlab.com/caosdb/caosdb/-/blob/dev/REVIEW_GUIDELINES.md) - [ ] Up-to-date CHANGELOG.md (or not necessary) - [ ] Up-to-date JSON schema (or not necessary) - [ ] Appropriate user and developer documentation (or not necessary) + - Update / write published documentation (`make doc`). - How do I use the software? Assume "stupid" users. - How do I develop or debug the software? Assume novice developers. - [ ] Annotations in code (Gitlab comments) @@ -41,7 +42,8 @@ guidelines](https://gitlab.com/caosdb/caosdb/-/blob/dev/REVIEW_GUIDELINES.md) - [ ] I understand the intent of this MR - [ ] All automated tests pass - [ ] Up-to-date CHANGELOG.md (or not necessary) -- [ ] Appropriate user and developer documentation (or not necessary) +- [ ] Appropriate user and developer documentation (or not necessary), also in published + documentation. - [ ] The test environment setup works and the intended behavior is reproducible in the test environment - [ ] In-code documentation and comments are up-to-date. diff --git a/.gitmodules b/.gitmodules index 80d822f671b09d8a0eaf0e4bbb4104ae6c587905..f937552d4b116474da1258942473e4dc95edd12c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "proto"] path = proto url = ../caosdb-proto.git +[submodule "vcpkg"] + path = vcpkg + url = https://github.com/microsoft/vcpkg diff --git a/CMakeLists.txt b/CMakeLists.txt index 51f80e9066a803f0b711e2536a600f88087a77bc..618c6dd586165e4fd74f188bd7b7751656f9704c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,10 @@ # -# This file is a part of the CaosDB Project. +# This file is a part of the LinkAhead Project. # # Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> -# Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> +# Copyright (C) 2024 Joscha Schmiedt <joscha@schmiedt.dev> +# Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> +# # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -20,20 +22,20 @@ cmake_minimum_required(VERSION 3.13) -set(libcaosdb_VERSION 0.2.2) -set(libcaosdb_COMPATIBLE_SERVER_VERSION_MAJOR 0) -set(libcaosdb_COMPATIBLE_SERVER_VERSION_MINOR 9) -set(libcaosdb_COMPATIBLE_SERVER_VERSION_PATCH 0) -set(libcaosdb_COMPATIBLE_SERVER_VERSION_PRE_RELEASE "") +set(liblinkahead_VERSION 0.3.0) +set(liblinkahead_COMPATIBLE_SERVER_VERSION_MAJOR 0) +set(liblinkahead_COMPATIBLE_SERVER_VERSION_MINOR 9) +set(liblinkahead_COMPATIBLE_SERVER_VERSION_PATCH 0) +set(liblinkahead_COMPATIBLE_SERVER_VERSION_PRE_RELEASE "") -project(libcaosdb - VERSION ${libcaosdb_VERSION} - DESCRIPTION "C and C++ client libraries for CaosDB" +project(liblinkahead + VERSION ${liblinkahead_VERSION} + DESCRIPTION "C and C++ client libraries for LinkAhead" LANGUAGES CXX C) set(CMAKE_C_STANDARD 11) set(CMAKE_CXX_STANDARD 17) - +set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(CMAKE_C_EXTENSIONS OFF) set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) @@ -44,31 +46,16 @@ set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) IF (WIN32) set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) -ENDIF() + add_compile_definitions(_CRT_SECURE_NO_WARNINGS) # suppress warnings for fopen, strcpy, etc. +endif() + IF (BUILD_ACM) message(STATUS "BUILD_ACM") add_compile_definitions("BUILD_ACM") ENDIF() -########################################### -### DEPENDENCY MANAGEMENT with CONAN -########################################### message(STATUS "Build directory ${CMAKE_BINARY_DIR}") -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup() - -# fix grpc - remove unsecure (no-op ssl implementations) -string(REGEX REPLACE "grpc\\+?\\+?_unsecure" "" CONAN_LIBS_GRPC - "${CONAN_LIBS_GRPC}") -string(REGEX REPLACE "grpc\\+?\\+?_unsecure" "" CONAN_PKG_LIBS_GRPC - "${CONAN_PKG_LIBS_GRPC}") -string(REGEX REPLACE "grpc\\+?\\+?_unsecure" "" CONAN_LIBS - "${CONAN_LIBS}") -string(REGEX REPLACE "grpc\\+?\\+?_unsecure" "" CONAN_PKG_LIBS - "${CONAN_PKG_LIBS}") - -message(STATUS "CONAN_LIBS: ${CONAN_LIBS}") ########################################### ### GENERAL SETUP of SOURCES @@ -82,6 +69,8 @@ add_subdirectory(doc) ### CODE GENERATION (WITH GRPC) #################################################################### +find_package(protobuf CONFIG REQUIRED) + # Protobuf/Grpc source files set(PROTO_FILES ${PROJECT_SOURCE_DIR}/proto/proto/caosdb/info/v1/main.proto @@ -96,12 +85,11 @@ ENDIF() set(PROTO_PATH ${PROJECT_SOURCE_DIR}/proto/proto) +set(_PROTOBUF_PROTOC ${Protobuf_PROTOC_EXECUTABLE}) # compiler binaries IF (WIN32) - set(_PROTOBUF_PROTOC "${CMAKE_BINARY_DIR}/build_tools/protoc.exe") set(_GRPC_CPP_PLUGIN_EXECUTABLE "${CMAKE_BINARY_DIR}/build_tools/grpc_cpp_plugin.exe") ELSE() - set(_PROTOBUF_PROTOC "${CMAKE_BINARY_DIR}/build_tools/protoc") set(_GRPC_CPP_PLUGIN_EXECUTABLE "${CMAKE_BINARY_DIR}/build_tools/grpc_cpp_plugin") ENDIF() @@ -147,94 +135,105 @@ add_custom_command( ${PROTO_FILES} DEPENDS ${PROTO_FILES}) +# add generated files to include path +include_directories(${CMAKE_CURRENT_BINARY_DIR}/include) + ############################################################################### ### Set up main targets -### * [caosdb_grpc] - only in Debug builds. Otherwise this library is compiled -### into caosdb libraray -### * caosdb (links to caosdb_grpc) - The main library. -### * cxxcaosdbcli - A C++ test client. -### * ccaosdb - A C-Wrapper of the C++ caosdb library. -### * ccaosdbcli - A plain C test client. +### * linkahead - The main library including the protobuf and grpc generated files. +### * cxxlinkaheadcli - A C++ test client. +### * clinkahead - A C-Wrapper of the C++ linkahead library. +### * clinkaheadcli - A plain C test client. ############################################################################### -if("${CMAKE_BUILD_TYPE}" MATCHES "Debug") - add_library(caosdb_grpc SHARED ${GRPC_GENERATED}) - add_library(caosdb SHARED ${libcaosdb_INCL} ${libcaosdb_SRC}) - target_link_libraries(caosdb caosdb_grpc) - set(LIBCAOSDB caosdb caosdb_grpc) - - target_include_directories(caosdb_grpc PUBLIC - $<BUILD_INTERFACE:${libcaosdb_SOURCE_DIR}/include> - $<BUILD_INTERFACE:${libcaosdb_BINARY_DIR}/include> - - $<INSTALL_INTERFACE:include> - ) - target_include_directories(caosdb_grpc SYSTEM PUBLIC - ${CONAN_INCLUDE_DIRS} - ) -else() - add_library(caosdb - SHARED ${libcaosdb_INCL} ${libcaosdb_SRC} ${GRPC_GENERATED}) - set(LIBCAOSDB caosdb) -endif() -target_link_libraries(caosdb - ${CONAN_LIBS} - stdc++fs +find_package(gRPC CONFIG REQUIRED) + +# boost +find_package(Boost REQUIRED COMPONENTS json filesystem log thread system log_setup) +# find_package(Boost REQUIRED COMPONENTS filesystem ) +# find_package(Boost REQUIRED COMPONENTS log ) +# find_package(Boost REQUIRED COMPONENTS thread ) +# find_package(Boost REQUIRED COMPONENTS system ) + +# Boost settings +set(Boost_USE_STATIC_LIBS ON) # only find static libs +set(Boost_USE_DEBUG_LIBS OFF) # ignore debug libs and +set(Boost_USE_RELEASE_LIBS ON) # only find release libs +set(Boost_USE_MULTITHREADED ON) +set(Boost_USE_STATIC_RUNTIME ON) # link Boost Static libraries + + +find_package(GTest REQUIRED) + +# print include directories for debugging +message(DEBUG "CMAKE_INCLUDE_PATH: ${CMAKE_INCLUDE_PATH}") +message(DEBUG "PROTOBUF_INCLUDE_DIRS: ${PROTOBUF_INCLUDE_DIRS}") +message(DEBUG "gRPC_INCLUDE_DIRS: ${gRPC_INCLUDE_DIRS}") +message(DEBUG "Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}") +message(DEBUG "GTest_INCLUDE_DIRS: ${GTest_INCLUDE_DIRS}") +message(DEBUG "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}") +message(DEBUG "liblinkahead_SOURCE_DIR: ${liblinkahead_SOURCE_DIR}") +message(DEBUG "liblinkahead_BINARY_DIR: ${liblinkahead_BINARY_DIR}") + +# libcaosdb_grpc +# -------------- +add_library(caosdb_grpc STATIC ${GRPC_GENERATED}) +target_link_libraries(caosdb_grpc + gRPC::grpc gRPC::grpc++ protobuf::libprotobuf ) -target_include_directories(caosdb PUBLIC - $<BUILD_INTERFACE:${libcaosdb_SOURCE_DIR}/include> - $<BUILD_INTERFACE:${libcaosdb_BINARY_DIR}/include> - $<BUILD_INTERFACE:${libcaosdb_SOURCE_DIR}/src> - $<INSTALL_INTERFACE:include> + +# liblinkahead +# --------- +add_library(linkahead SHARED + ${liblinkahead_INCL} ${liblinkahead_SRC}) +target_link_libraries(linkahead PUBLIC + caosdb_grpc gRPC::grpc gRPC::grpc++ protobuf::libprotobuf ${Boost_LIBRARIES} ) -target_include_directories(caosdb SYSTEM PUBLIC - ${CONAN_INCLUDE_DIRS} +set(liblinkahead linkahead) + +target_include_directories(linkahead PUBLIC + $<BUILD_INTERFACE:${liblinkahead_SOURCE_DIR}/include> + $<BUILD_INTERFACE:${liblinkahead_BINARY_DIR}/include> + $<BUILD_INTERFACE:${liblinkahead_SOURCE_DIR}/src> + $<INSTALL_INTERFACE:include> ) -add_library(ccaosdb SHARED src/ccaosdb.cpp) -target_link_libraries(ccaosdb - ${CONAN_LIBS} - ${LIBCAOSDB} - stdc++fs +# libclinkahead +# ---------- +add_library(clinkahead SHARED src/clinkahead.cpp) +target_link_libraries(clinkahead PUBLIC + linkahead caosdb_grpc gRPC::grpc gRPC::grpc++ protobuf::libprotobuf ${Boost_LIBRARIES} ) -target_include_directories(ccaosdb PUBLIC - $<BUILD_INTERFACE:${libcaosdb_SOURCE_DIR}/include> - $<BUILD_INTERFACE:${libcaosdb_BINARY_DIR}/include> +target_include_directories(clinkahead PUBLIC + $<BUILD_INTERFACE:${liblinkahead_SOURCE_DIR}/include> + $<BUILD_INTERFACE:${liblinkahead_BINARY_DIR}/include> $<INSTALL_INTERFACE:include> ) -target_include_directories(ccaosdb SYSTEM PUBLIC - ${CONAN_INCLUDE_DIRS} -) -add_executable(ccaosdbcli EXCLUDE_FROM_ALL src/ccaosdbcli.c) -target_include_directories(ccaosdbcli PUBLIC - $<BUILD_INTERFACE:${libcaosdb_SOURCE_DIR}/include> - $<BUILD_INTERFACE:${libcaosdb_BINARY_DIR}/include> +# clinkaheadcli +# ---------- +add_executable(clinkaheadcli EXCLUDE_FROM_ALL src/clinkaheadcli.c) +target_include_directories(clinkaheadcli PUBLIC + $<BUILD_INTERFACE:${liblinkahead_SOURCE_DIR}/include> + $<BUILD_INTERFACE:${liblinkahead_BINARY_DIR}/include> $<INSTALL_INTERFACE:include> ) -target_include_directories(ccaosdbcli SYSTEM PUBLIC - ${CONAN_INCLUDE_DIRS} -) - -target_link_libraries(ccaosdbcli - ${CONAN_LIBS} - ${LIBCAOSDB} - ccaosdb +target_link_libraries(clinkaheadcli PRIVATE + caosdb_grpc clinkahead + gRPC::grpc protobuf::libprotobuf ${Boost_LIBRARIES} ) -add_executable(cxxcaosdbcli EXCLUDE_FROM_ALL src/cxxcaosdbcli.cpp) -target_include_directories(cxxcaosdbcli PUBLIC - $<BUILD_INTERFACE:${libcaosdb_SOURCE_DIR}/include> - $<BUILD_INTERFACE:${libcaosdb_BINARY_DIR}/include> +# cxxlinkaheadcli +# ------------ +add_executable(cxxlinkaheadcli EXCLUDE_FROM_ALL src/cxxlinkaheadcli.cpp) +target_include_directories(cxxlinkaheadcli PUBLIC + $<BUILD_INTERFACE:${liblinkahead_SOURCE_DIR}/include> + $<BUILD_INTERFACE:${liblinkahead_BINARY_DIR}/include> $<INSTALL_INTERFACE:include> ) -target_include_directories(cxxcaosdbcli SYSTEM PUBLIC - ${CONAN_INCLUDE_DIRS} -) -target_link_libraries(cxxcaosdbcli - ${LIBCAOSDB} - ${CONAN_LIBS} +target_link_libraries(cxxlinkaheadcli PRIVATE + linkahead caosdb_grpc gRPC::grpc++ protobuf::libprotobuf ${Boost_LIBRARIES} ) @@ -288,19 +287,19 @@ if(_LINTING) add_compiler_flag("-Werror") message(STATUS "PEDANTIC_CMAKE_CXX_FLAGS: [${PEDANTIC_CMAKE_CXX_FLAGS}]") - set(TARGET_CAOSDB_COMPILE_FLAGS "${TARGET_CAOSDB_COMPILE_FLAGS} ${PEDANTIC_CMAKE_CXX_FLAGS}") - set(TARGET_CCAOSDB_COMPILE_FLAGS "${TARGET_CCAOSDB_COMPILE_FLAGS} ${PEDANTIC_CMAKE_C_FLAGS}") - set(TARGET_CXXCAOSDBCLI_COMPILE_FLAGS "${TARGET_CXXCAOSDBCLI_COMPILE_FLAGS} ${PEDANTIC_CMAKE_CXX_FLAGS}") - set(TARGET_CCAOSDBCLI_COMPILE_FLAGS "${TARGET_CCAOSDBCLI_COMPILE_FLAGS} ${PEDANTIC_CMAKE_C_FLAGS}") - - set_target_properties(caosdb PROPERTIES - COMPILE_FLAGS "${TARGET_CAOSDB_COMPILE_FLAGS}") - set_target_properties(ccaosdb PROPERTIES - COMPILE_FLAGS "${TARGET_CCAOSDB_COMPILE_FLAGS}") - set_target_properties(cxxcaosdbcli PROPERTIES - COMPILE_FLAGS "${TARGET_CXXCAOSDBCLI_COMPILE_FLAGS}") - set_target_properties(ccaosdbcli PROPERTIES - COMPILE_FLAGS "${TARGET_CCAOSDBCLI_COMPILE_FLAGS}") + set(TARGET_LINKAHEAD_COMPILE_FLAGS "${TARGET_LINKAHEAD_COMPILE_FLAGS} ${PEDANTIC_CMAKE_CXX_FLAGS}") + set(TARGET_CLINKAHEAD_COMPILE_FLAGS "${TARGET_CLINKAHEAD_COMPILE_FLAGS} ${PEDANTIC_CMAKE_C_FLAGS}") + set(TARGET_CXXLINKAHEADCLI_COMPILE_FLAGS "${TARGET_CXXLINKAHEADCLI_COMPILE_FLAGS} ${PEDANTIC_CMAKE_CXX_FLAGS}") + set(TARGET_CLINKAHEADCLI_COMPILE_FLAGS "${TARGET_CLINKAHEADCLI_COMPILE_FLAGS} ${PEDANTIC_CMAKE_C_FLAGS}") + + set_target_properties(linkahead PROPERTIES + COMPILE_FLAGS "${TARGET_LINKAHEAD_COMPILE_FLAGS}") + set_target_properties(clinkahead PROPERTIES + COMPILE_FLAGS "${TARGET_CLINKAHEAD_COMPILE_FLAGS}") + set_target_properties(cxxlinkaheadcli PROPERTIES + COMPILE_FLAGS "${TARGET_CXXLINKAHEADCLI_COMPILE_FLAGS}") + set_target_properties(clinkaheadcli PROPERTIES + COMPILE_FLAGS "${TARGET_CLINKAHEADCLI_COMPILE_FLAGS}") find_program(iwyu NAMES include-what-you-use iwyu @@ -312,28 +311,28 @@ if(_LINTING) set(_CMAKE_CXX_INCLUDE_WHAT_YOU_USE ${iwyu} "-Xiwyu" "--cxx17ns" "-Xiwyu" "--no_fwd_decls") - set_target_properties(caosdb PROPERTIES + set_target_properties(linkahead PROPERTIES CXX_INCLUDE_WHAT_YOU_USE "${_CMAKE_CXX_INCLUDE_WHAT_YOU_USE}" ) - set_target_properties(cxxcaosdbcli PROPERTIES + set_target_properties(cxxlinkaheadcli PROPERTIES CXX_INCLUDE_WHAT_YOU_USE "${_CMAKE_CXX_INCLUDE_WHAT_YOU_USE}" ) - set_target_properties(ccaosdbcli PROPERTIES + set_target_properties(clinkaheadcli PROPERTIES C_INCLUDE_WHAT_YOU_USE "${_CMAKE_CXX_INCLUDE_WHAT_YOU_USE}" ) endif() - find_program(clang_tidy NAMES clang-tidy clang-tidy-11) + find_program(clang_tidy NAMES clang-tidy clang-tidy-16) if(NOT clang_tidy) message(WARNING "clang-tidy: Not found") else() message(STATUS "clang-tidy: ${clang_tidy}") set(_CMAKE_CXX_CLANG_TIDY_CHECKS - "--checks=*,-fuchsia-*,-llvmlibc-*,-readability-convert-member-functions-to-static,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-hicpp-no-array-decay,-llvm-else-after-return,-readability-else-after-return,-modernize-use-trailing-return-type,-bugprone-branch-clone,-altera-*") + "--checks=*,-fuchsia-*,-llvmlibc-*,-readability-convert-member-functions-to-static,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-hicpp-no-array-decay,-llvm-else-after-return,-readability-else-after-return,-modernize-use-trailing-return-type,-bugprone-branch-clone,-altera-*,-misc-include-cleaner,-readability-identifier-*,-llvm-include-order,-misc-const-correctness") set(_CMAKE_C_CLANG_TIDY_CHECKS "${_CMAKE_CXX_CLANG_TIDY_CHECKS}") set(_CMAKE_CXX_CLANG_TIDY "${clang_tidy}" - "--header-filter=caosdb/.*[^\(\.pb\.h\)]$" - "--warnings-as-errors=*") + "--header-filter=caosdb/.*[^\(\.pb\.h\)]$") + # "--warnings-as-errors=*") set(_CMAKE_C_CLANG_TIDY "${_CMAKE_CXX_CLANG_TIDY}") option(AUTO_FIX_LINTING "Append --fix option to clang-tidy" OFF) if(AUTO_FIX_LINTING) @@ -341,16 +340,16 @@ if(_LINTING) endif() message(STATUS "Using clang-tidy with '${_CMAKE_CXX_CLANG_TIDY};${_CMAKE_CXX_CLANG_TIDY_CHECKS}'") - set_target_properties(caosdb PROPERTIES + set_target_properties(linkahead PROPERTIES CXX_CLANG_TIDY "${_CMAKE_CXX_CLANG_TIDY};${_CMAKE_CXX_CLANG_TIDY_CHECKS}" ) - set_target_properties(cxxcaosdbcli PROPERTIES + set_target_properties(cxxlinkaheadcli PROPERTIES CXX_CLANG_TIDY "${_CMAKE_CXX_CLANG_TIDY};${_CMAKE_CXX_CLANG_TIDY_CHECKS}" ) - set_target_properties(ccaosdb PROPERTIES + set_target_properties(clinkahead PROPERTIES C_CLANG_TIDY "${_CMAKE_C_CLANG_TIDY};${_CMAKE_C_CLANG_TIDY_CHECKS}" ) - set_target_properties(ccaosdbcli PROPERTIES + set_target_properties(clinkaheadcli PROPERTIES C_CLANG_TIDY "${_CMAKE_C_CLANG_TIDY};${_CMAKE_C_CLANG_TIDY_CHECKS}" ) endif() @@ -361,47 +360,53 @@ endif() ### UNIT TEST ####################################################### -if("${CMAKE_BUILD_TYPE}" MATCHES "Debug") +#if("${CMAKE_BUILD_TYPE}" MATCHES "Debug") enable_testing() add_subdirectory(test) -endif() +#endif() -############################################### -############ INSTALLATION ##################### -############################################### +# ############################################### +# ############ INSTALLATION ##################### +# ############################################### -set(libcaosdb_INCLUDE_DEST "include/caosdb") -set(libcaosdb_LIB_DEST "lib") +set(liblinkahead_INCLUDE_DEST "include/linkahead") +set(liblinkahead_LIB_DEST "lib") + +if (WIN32) + set(CMAKE_INSTALL_PREFIX "$ENV{APPDATA}/LinkAhead") +else() + set(CMAKE_INSTALL_PREFIX "$ENV{HOME}/.local/") +endif() -set(CMAKE_INSTALL_PREFIX "$ENV{HOME}/.local/") install( # targets to install - TARGETS ${LIBCAOSDB} ccaosdb + TARGETS linkahead clinkahead caosdb_grpc # name of the CMake "export group" containing the targets we want to install - EXPORT caosdbTargets + EXPORT linkaheadTargets # Dynamic, static library and include destination locations after running # "make install" - LIBRARY DESTINATION ${libcaosdb_LIB_DEST} - ARCHIVE DESTINATION ${libcaosdb_LIB_DEST} - INCLUDES DESTINATION ${libcaosdb_INCLUDE_DEST} + LIBRARY DESTINATION ${liblinkahead_LIB_DEST} + ARCHIVE DESTINATION ${liblinkahead_LIB_DEST} + RUNTIME DESTINATION ${liblinkahead_LIB_DEST} # This line ensures DLLs are copied on Windows + INCLUDES DESTINATION ${liblinkahead_INCLUDE_DEST} ) -set(libcaosdb_CMAKE_DEST "${libcaosdb_LIB_DEST}/cmake/caosdb") +set(liblinkahead_CMAKE_DEST "${liblinkahead_LIB_DEST}/cmake/linkahead") install( # The export we want to save (matches name defined above containing the # install targets) - EXPORT caosdbTargets + EXPORT linkaheadTargets # CMake file in which to store the export's information - FILE caosdbTargets.cmake + FILE linkaheadTargets.cmake # Namespace prepends all targets in the export (when we import later, we - # will use caosdb::caosdb) - NAMESPACE caosdb:: + # will use linkahead::linkahead) + NAMESPACE linkahead:: # where to place the resulting file (here, we're putting it with the library) - DESTINATION ${libcaosdb_CMAKE_DEST} + DESTINATION ${liblinkahead_CMAKE_DEST} ) -install(FILES ${libcaosdb_INCL} ${PROJECT_SOURCE_DIR}/include/ccaosdb.h DESTINATION ${libcaosdb_INCLUDE_DEST}) +install(FILES ${liblinkahead_INCL} ${PROJECT_SOURCE_DIR}/include/clinkahead.h DESTINATION ${liblinkahead_INCLUDE_DEST}) foreach(i RANGE "${len_proto_files}") list(GET PROTO_FILES ${i} next_proto_file) @@ -421,35 +426,35 @@ foreach(i RANGE "${len_proto_files}") set(next_grpc_hdr "${CMAKE_CURRENT_BINARY_DIR}/include/caosdb/${next_proto_module}/main.grpc.pb.h") install(FILES ${next_proto_hdr} ${next_grpc_hdr} DESTINATION - ${libcaosdb_INCLUDE_DEST}/${next_proto_module}) + ${liblinkahead_INCLUDE_DEST}/${next_proto_module}) endforeach() -install(FILES ${PROJECT_SOURCE_DIR}/caosdbConfig.cmake - DESTINATION ${libcaosdb_CMAKE_DEST}) +install(FILES ${PROJECT_SOURCE_DIR}/linkaheadConfig.cmake + DESTINATION ${liblinkahead_CMAKE_DEST}) -#set_property(TARGET caosdb PROPERTY VERSION ${libcaosdb_VERSION}) +#set_property(TARGET caosdb PROPERTY VERSION ${liblinkahead_VERSION}) include(CMakePackageConfigHelpers) write_basic_package_version_file( - "${PROJECT_SOURCE_DIR}/caosdbConfigVersion.cmake" - VERSION ${libcaosdb_VERSION} + "${PROJECT_SOURCE_DIR}/linkaheadConfigVersion.cmake" + VERSION ${liblinkahead_VERSION} COMPATIBILITY AnyNewerVersion ) -install(FILES ${PROJECT_SOURCE_DIR}/caosdbConfigVersion.cmake - DESTINATION ${libcaosdb_CMAKE_DEST}) +install(FILES ${PROJECT_SOURCE_DIR}/linkaheadConfigVersion.cmake + DESTINATION ${liblinkahead_CMAKE_DEST}) ####################################################### ### code formatting with clang-format ####################################################### option(AUTOFORMATTING "call clang-format at configure time" ON) if(AUTOFORMATTING AND NOT SKIP_LINTING) - find_program(clang_format NAMES clang-format-11 clang-format) + find_program(clang_format NAMES clang-format-16 clang-format) file(GLOB format_test_sources test/*.cpp test/*.h test/*.h.in) - execute_process(COMMAND ${clang_format} -i --verbose ${libcaosdb_INCL} - ${libcaosdb_SRC} ${libcaosdb_TEST_SRC} - ${PROJECT_SOURCE_DIR}/src/cxxcaosdbcli.cpp - ${PROJECT_SOURCE_DIR}/src/ccaosdbcli.c - ${PROJECT_SOURCE_DIR}/src/ccaosdb.cpp - ${PROJECT_SOURCE_DIR}/include/ccaosdb.h + execute_process(COMMAND ${clang_format} -i --verbose ${liblinkahead_INCL} + ${liblinkahead_SRC} ${liblinkahead_TEST_SRC} + ${PROJECT_SOURCE_DIR}/src/cxxlinkaheadcli.cpp + ${PROJECT_SOURCE_DIR}/src/clinkaheadcli.c + ${PROJECT_SOURCE_DIR}/src/clinkahead.cpp + ${PROJECT_SOURCE_DIR}/include/clinkahead.h ${format_test_sources} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}) endif() diff --git a/CMakeSettings.json b/CMakeSettings.json new file mode 100644 index 0000000000000000000000000000000000000000..09da9d3ea26bd9563e1f4c89bee60f09fc16ad7a --- /dev/null +++ b/CMakeSettings.json @@ -0,0 +1,27 @@ +{ + "configurations": [ + { + "name": "x64-Debug", + "generator": "Ninja", + "configurationType": "Debug", + "inheritEnvironments": [ "msvc_x64_x64" ], + "buildRoot": "${projectDir}\\build", + "installRoot": "${projectDir}\\out\\install\\${name}", + "cmakeCommandArgs": "", + "buildCommandArgs": "", + "ctestCommandArgs": "" + }, + { + "name": "x64-Release", + "generator": "Ninja", + "configurationType": "RelWithDebInfo", + "buildRoot": "${projectDir}\\build", + "installRoot": "${projectDir}\\out\\install\\${name}", + "cmakeCommandArgs": "", + "buildCommandArgs": "", + "ctestCommandArgs": "", + "inheritEnvironments": [ "msvc_x64_x64" ], + "variables": [] + } + ] +} \ No newline at end of file diff --git a/HUMANS.md b/HUMANS.md index 3104ed33f893da734c04d97b694bc2c1126ac519..95ce3cffda358d2b07885556d8591dbdec298104 100644 --- a/HUMANS.md +++ b/HUMANS.md @@ -1,3 +1,6 @@ # Active Contributors * Timm Fitschen <t.fitschen@indiscale.com> +* Daniel Hornung <d.hornung@indiscale.com> +* Joscha Schmiedt <joscha@schmiedt.dev> +* Florian Spreckelsen <f.spreckelsen@indiscale.com> diff --git a/Makefile b/Makefile index 4be361a56cb09fa5359d5ef03ccff3064b2e4e3d..707209ca54adf20506752c74eb8cfa57f9bfefce 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ # ** header v3.0 -# This file is a part of the CaosDB Project. +# This file is a part of the LinkAhead Project. # # Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> # Copyright (C) 2021 Daniel Hornung <d.hornung@indiscale.com> @@ -22,7 +22,7 @@ # This Makefile is a wrapper for several other scripts. -CLANG_FORMAT ?= clang-format-11 +CLANG_FORMAT ?= clang-format-16 CONAN_SETTINGS = "compiler.libcxx=libstdc++11" # OS specific handling, with code by Ken Jackson and oHo, @@ -45,20 +45,30 @@ endif help: @echo "Targets:" @echo " style - auto-format the source files." - @echo " conan-install - Install locally with Conan." - @echo -e " conan-create - Create conan binary package in the local conan\n"\ + @echo " conan-install-deps - Install dependencies locally with Conan." + @echo -e " conan-create - Create Conan binary package in the local conan\n"\ " repostory." + @echo " conan - Install dependencies, then build and install package." + @echo " doc - Generate documentation." + @echo " conan-debug - Install dependencies and create Conan binary package in Debug mode." + @echo " conan-build - Build the Conan package." + @echo " conan-build-debug - Build the Conan package in Debug mode." + @echo " vcpkg-install - Install dependencies with Vcpkg." + @echo " vcpkg-build-release - Build the project with Vcpkg in Release mode." + @echo " test-debug - Install dependencies, build the project in Debug mode, and run the tests." + @echo " test-release - Install dependencies, build the project in Release mode, and run the tests." + @echo " clean - Remove build directory." style: $(CLANG_FORMAT) -i --verbose \ $$(find test/ src/ include/ -type f -iname "*.cpp" -o -iname "*.h" -o -iname "*.h.in") .PHONY: style -conan-install: - conan install . -s $(CONAN_SETTINGS) || \ +conan-install-deps: + conan install . -s $(CONAN_SETTINGS) -s build_type=Release || \ (echo "'conan install' failed, trying to build from sources..."; \ - conan install . -s $(CONAN_SETTINGS) --build=missing) -.PHONY: conan-install + conan install . -s $(CONAN_SETTINGS) -s build_type=Release --build=missing) +.PHONY: conan-install-deps conan-install-debug: conan install . -s $(CONAN_SETTINGS) -s build_type=Debug || \ @@ -67,22 +77,66 @@ conan-install-debug: .PHONY: conan-install-debug conan-create: - conan create -s $(CONAN_SETTINGS) -o caosdb:build_acm=True . "caosdb/$$(conan inspect --raw version .)@_/_" + conan create -s $(CONAN_SETTINGS) -o linkahead/*:build_acm=True . .PHONY: conan-create conan-create-debug: - conan create -s $(CONAN_SETTINGS) -s build_type=Debug -o caosdb:build_acm=True . "caosdb/$$(conan inspect --raw version .)@_/_" + conan create -s $(CONAN_SETTINGS) -s build_type=Debug -o linkahead/*:build_acm=True . .PHONY: conan-create-debug -conan: conan-install conan-create +conan: conan-install-deps conan-create .PHONY: conan -doc: - mkdir -p build && cd build && conan install .. --build=missing -s $(CONAN_SETTINGS) \ - && cmake .. && cmake --build . --target doc-sphinx \ - && echo "The documentation starts at build/doc/sphinx_out/index.html ." +doc: conan-install-deps + @doxygen --version || ( echo "Doxygen not found. Please install Doxygen first." ; exit 1 ) + cd build/Release\ + && cmake -S ../.. -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE="generators/conan_toolchain.cmake" -DCMAKE_POLICY_DEFAULT_CMP0091="NEW" -DCMAKE_BUILD_TYPE="Release" \ + && cmake --build . --target doc-sphinx \ + && echo "The documentation starts at build/Release/doc/sphinx_out/index.html ." .PHONY: doc conan-debug: conan-install-debug conan-create-debug .PHONY: conan-debug + +conan-build: + conan build . -s $(CONAN_SETTINGS) -s build_type=Release +.PHONY: conan-build + +conan-build-debug: + @command -v lcov || (echo "Could not find 'lcov', exiting."; exit 1) + @command -v clang-tidy || command -v clang-tidy-16 || \ + (echo "Could not find 'clang-tidy'(-16), exiting."; exit 1) + conan build . -s $(CONAN_SETTINGS) -s build_type=Debug +.PHONY: conan-build-debug + +vcpkg-install: + ./vcpkg/bootstrap-vcpkg.sh -disableMetrics\ + &&vcpkg/vcpkg install +.PHONY: vcpkg-install + +vcpkg-build-release: vcpkg-install + mkdir -p build/build_tools\ + && cp vcpkg_installed/x64-linux/tools/grpc/grpc_cpp_plugin build/build_tools\ + && cd build\ + && cmake -S .. -B . -DCMAKE_TOOLCHAIN_FILE=../vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-linux-release -DCMAKE_BUILD_TYPE=Release\ + && cmake --build . +.PHONY: vcpkg-build-release + +ctest-debug: + cd build/Debug && ctest +.PHONY: ctest-debug + +ctest-release: + cd build/Release && ctest +.PHONY: ctest-release + +test-debug: conan-install-debug conan-build-debug ctest-debug +.PHONY: test-debug + +test-release: conan-install-deps conan-build ctest-release +.PHONY: test-release + +clean: + rm -rf build +.PHONY: clean diff --git a/README.md b/README.md index 4750574a04da7d170c16858ddfcb82f789237150..1402eab396f70d08a22189d88a2134a81f3e4131 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# libcaosdb +# liblinkahead ## Welcome @@ -7,7 +7,7 @@ for LinkAhead and a part of the LinkAhead project. ## Setup -Please read the installation notes [online](https://docs.indiscale.com/caosdb-cpplib/Install_develop.html) or [in the source repository](doc/Install_develop.md) for instructions +Please read the installation notes [online](https://docs.indiscale.com/caosdb-cpplib/Install_develop.html) or [in the source repository](doc/Install_develop.rst) for instructions on how to build, use and develop this code. ## Further Reading @@ -39,7 +39,7 @@ Conduct](https://gitlab.com/linkahead/linkahead/-/blob/main/CODE_OF_CONDUCT.md). ## License -* Copyright (C) 2022 Indiscale GmbH <info@indiscale.com> +* Copyright (C) 2022-2024 Indiscale GmbH <info@indiscale.com> All files in this repository are licensed under a [GNU Affero General Public License](LICENSE.md) (version 3 or later). diff --git a/RELEASE_GUIDELINES.md b/RELEASE_GUIDELINES.md index 8260a985b5146a0a8332ce1b8213eec6b3d0d325..fe287b6f9a8421af8a28efe6181b1b9d087ef0cf 100644 --- a/RELEASE_GUIDELINES.md +++ b/RELEASE_GUIDELINES.md @@ -1,7 +1,7 @@ -# Release Guidelines for the CaosDB Python Client Library +# Release Guidelines for the LinkAhead C++ Client Library This document specifies release guidelines in addition to the generel release -guidelines of the CaosDB Project +guidelines of the LinkAhead Project ([RELEASE_GUIDELINES.md](https://gitlab.com/caosdb/caosdb/blob/dev/RELEASE_GUIDELINES.md)) ## General Prerequisites @@ -24,8 +24,8 @@ guidelines of the CaosDB Project 4. Update version numbers: 1. In [CMakeLists.txt](./CMakeLists.txt): Check the version variables and make sure that the compatible caosdb-server version is set correctly. - 2. In `conanfile.py`: Update the `version` variable. - 3. In `caosdb-cppinttest/conanfile.py`: Update the version + 2. In `conanfile.py` and `vcpkg.json`: Update the `version` variable. + 3. In `linkahead-cppinttest/conanfile.py`: Update the version 5. Merge the release branch into the main branch. diff --git a/caosdbConfig.cmake b/caosdbConfig.cmake deleted file mode 100644 index f54465446c4b6102d2644b51f518104b11608359..0000000000000000000000000000000000000000 --- a/caosdbConfig.cmake +++ /dev/null @@ -1,11 +0,0 @@ -get_filename_component(CAOSDB_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) - -include(CMakeFindDependencyMacro) - -find_dependency(Threads REQUIRED) -find_dependency(Protobuf CONFIG REQUIRED) -find_dependency(gRPC CONFIG REQUIRED) - -if(NOT TARGET caosdb::caosdb) - include("${CAOSDB_CMAKE_DIR}/caosdbTargets.cmake") -endif() diff --git a/conanfile.py b/conanfile.py index e86f49da94e88aba9cee145e45c1045230d24bc5..304c9a7b85c9ee214aae6f567bc05bdbbf0e8f55 100644 --- a/conanfile.py +++ b/conanfile.py @@ -1,14 +1,18 @@ -from conans import ConanFile, CMake, tools +import os +from conan import ConanFile +from conan.tools.cmake import CMake, cmake_layout, CMakeDeps, CMakeToolchain +from conan.tools.files import copy +from conan.errors import ConanInvalidConfiguration -class CaosdbConan(ConanFile): - name = "caosdb" - version = "0.2.2" +class LinkAheadConan(ConanFile): + name = "linkahead" + version = "0.3.0" license = "AGPL-3.0-or-later" author = "Timm C. Fitschen <t.fitschen@indiscale.com>" url = "https://gitlab.indiscale.com/caosdb/src/caosdb-cpplib.git" - description = "C++ library for the CaosDB project" - topics = ("data management", "caosdb") + description = "C++ library for the LinkAhead project" + topics = ("data management", "linkahead", "caosdb") settings = "os", "compiler", "build_type", "arch" options = { "shared": [True, False], @@ -20,48 +24,97 @@ class CaosdbConan(ConanFile): "fPIC": True, "build_acm": False, } - generators = "cmake" - requires = [ - ("grpc/1.48.0"), - ] - build_requires = [ - ("boost/1.78.0"), - ("gtest/1.11.0"), - ] + exports = ("*.cmake", "*CMakeLists.txt", "*.in", "*.h", "*.proto", "*.c", "*.cpp", "*.rst", "*.md", - ) - exports_sources = "src", "doc", "include", "test", "cmake", "proto" + ) + + exports_sources = "CMakeLists.txt", "src/*", "doc/*", "include/*", "test/*", "cmake/*", "proto/*", "*.cmake" + + def build_requirements(self): + self.tool_requires("protobuf/3.21.12") + self.tool_requires("cmake/[>=3.13]") + self.tool_requires("boost/1.80.0") + self.test_requires("gtest/1.11.0") + + def requirements(self): + self.requires("grpc/1.48.4", transitive_headers=True, transitive_libs=True) + self.requires("protobuf/3.21.12", transitive_headers=True, transitive_libs=True) + self.requires("boost/1.80.0", transitive_headers=True, transitive_libs=True) + + def test_requirements(self): + self.test_requires("gtest/1.11.0") def config_options(self): if self.settings.os == "Windows": - del self.options.fPIC + self.options.rm_safe("fPIC") self.options["boost"].without_python = True + self.options["boost"].without_test = True self.options["boost"].filesystem_version = "3" - # def source(self): - # self.run("git clone https://gitlab.indiscale.com/caosdb/src/caosdb-cpplib.git") - # self.run("cd caosdb-cpplib && git submodule update --init") + def generate(self): + + tc = CMakeToolchain(self) + if self.options.build_acm: + tc.cache_variables["BUILD_ACM"] = "ON" + tc.generate() + + cmake = CMakeDeps(self) + cmake.generate() - def imports(self): - self.copy("protoc*", "build_tools", "bin") - self.copy("grpc_cpp_plugin*", "build_tools", "bin") + for dep in self.dependencies.values(): + dst = self.build_folder + "/build_tools" + src = dep.cpp_info.bindirs[0] + copied = copy(self, pattern="protoc*", dst=dst, src=src) + copy(self, pattern="grpc_cpp_plugin*", dst=dst, src=src) + + def layout(self): + cmake_layout(self, src_folder=".") def build(self): cmake = CMake(self) - if self.options.build_acm: - cmake.definitions["BUILD_ACM"] = "On" - cmake.configure(source_folder="") + cmake.configure() cmake.build() def package(self): - self.copy("*.h", dst="include", src="include") - self.copy("*.dll", dst="bin", keep_path=False) - self.copy("*.so", dst="lib", keep_path=False) - self.copy("*.dylib", dst="lib", keep_path=False) - self.copy("*.a", dst="lib", keep_path=False) + cmake = CMake(self) + cmake.install() + + print(copy(self, pattern="*.h", + src=os.path.join(self.build_folder, "include"), + dst=os.path.join(self.package_folder, "include"))) + print(copy(self, pattern="*.h", + dst=os.path.join(self.package_folder, "include"), + src=os.path.join(self.source_folder, "include"))) + copy(self, pattern="*.h", + dst=os.path.join(self.package_folder, "include"), + src=os.path.join(self.source_folder, "include")) + copy(self, pattern="*.dll", src=os.path.join(self.build_folder, "bin"), + dst=os.path.join(self.package_folder, "bin"), keep_path=False) + copy(self, pattern="*.so", src=os.path.join(self.build_folder, "bin"), + dst=os.path.join(self.package_folder, "lib"), keep_path=False) + copy(self, pattern="*.dylib", src=os.path.join(self.build_folder, "bin"), + dst=os.path.join(self.package_folder, "lib"), keep_path=False) + copy(self, pattern="*.a", src=os.path.join(self.build_folder, "bin"), + dst=os.path.join(self.package_folder, "lib"), keep_path=False) def package_info(self): - self.cpp_info.libs = ["caosdb", "ccaosdb"] + self.cpp_info.libs = ["linkahead::linkahead", "linkahead::clinkahead", "linkahead::caosdb_grpc" ] + self.cpp_info.requires = ["boost::headers", "grpc::grpc", "protobuf::protobuf"] + self.cpp_info.bindirs = ["build/Release", "build/Debug"] + self.cpp_info.includedirs = ["include", "build/include"] + self.cpp_info.components["linkahead::linkahead"].libs = ["linkahead"] + self.cpp_info.components["linkahead::linkahead"].set_property("cmake_target_name", "linkahead") + + self.cpp_info.components["linkahead::clinkahead"].libs = ["clinkahead"] + self.cpp_info.components["linkahead::clinkahead"].set_property("cmake_target_name", "clinkahead") + + self.cpp_info.components["linkahead::caosdb_grpc"].libs = ["caosdb_grpc"] + self.cpp_info.components["linkahead::caosdb_grpc"].set_property("cmake_target_name", "caosdb_grpc") + + + def validate(self): + if self.settings.os not in ("Linux", "Windows"): + raise ConanInvalidConfiguration(f"{self.settings.os} is currently not supported") diff --git a/doc/CHANGELOG.md b/doc/CHANGELOG.md index aba1ff29bbaa11f977598baf4b588b9686790212..10389b44d3868f4abc6c061a864140856795e2b7 100644 --- a/doc/CHANGELOG.md +++ b/doc/CHANGELOG.md @@ -5,14 +5,44 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [0.2.2] - 2023-06-15 ## +## [0.3.0] - 2024-11-15 +(Joscha Schmiedt) + +### Added + +- `Connection::ListUsers` method +- Added experimental support for compilation with vcpkg. + +### Changed + +- Renamed the project to linkahead-cpplib +- Updated dependency versions (Boost, gRPC) +- Updated Python dependencies for Conan 2 and support Python 3.12. +- Updated C++ package manager Conan to 2.5.0 including migration of conanfile.py + +### Deprecated + +### Removed + +### Fixed + +- Values can now hold empty vectors and do not silently convert them into a scalar. +- [indiscale#34](https://gitlab.indiscale.com/caosdb/src/caosdb-cpplib/-/issues/34) + Building shared libraries on Windows. + +### Security + +### Documentation + + +## [0.2.2] - 2023-06-15 (Timm Fitschen) ### Added * Support for `SELECT` queries. -## [0.2.1] - 2022-09-22 ## +## [0.2.1] - 2022-09-22 (Daniel Hornung) ### Changed ### diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index e2bebee45ccb7a709387dfe275c00d90e8296c6c..962c0d44a8cdb0f827e35ee064666f0fb014d4ce 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -1,8 +1,8 @@ # -# This file is a part of the CaosDB Project. +# This file is a part of the LinkAhead Project. # # Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> -# Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> +# Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -23,7 +23,7 @@ find_package(Doxygen) if (DOXYGEN_FOUND) string(REPLACE ";" " " DOXYGEN_INPUT - "${libcaosdb_INCL} ${PROJECT_INCLUDE_DIR}/ccaosdb.h") + "${liblinkahead_INCL} ${PROJECT_INCLUDE_DIR}/clinkahead.h") configure_file(Doxyfile.in Doxyfile) @@ -43,10 +43,10 @@ if (DOXYGEN_FOUND) configure_file(cppapi/index.rst.in cppapi/index.rst) # create rst pages for every header file - list(LENGTH libcaosdb_INCL len_header_files) + list(LENGTH liblinkahead_INCL len_header_files) math(EXPR len_header_files "${len_header_files} - 1") foreach (i RANGE "${len_header_files}") - list(GET libcaosdb_INCL ${i} HEADER_FILE) + list(GET liblinkahead_INCL ${i} HEADER_FILE) string(REPLACE "${PROJECT_INCLUDE_DIR}/" "" @@ -58,7 +58,7 @@ if (DOXYGEN_FOUND) HEADER_FILE_NAME ${HEADER_FILE_NAME}) string(REPLACE - "caosdb/" + "linkahead/" "" DOC_FILE_NAME ${HEADER_FILE_NAME}) @@ -69,11 +69,11 @@ if (DOXYGEN_FOUND) # create (plain) C docs configure_file(capi/index.rst.in capi/index.rst) - set(HEADER_FILE_NAME ccaosdb.h) - set(HEADER_FILE ccaosdb.h) + set(HEADER_FILE_NAME clinkahead.h) + set(HEADER_FILE clinkahead.h) configure_file( header_file.rst.in - capi/_ccaosdb.rst) + capi/_clinkahead.rst) add_custom_target(doc-sphinx COMMAND ${SPHINX_CMD} diff --git a/doc/DEPENDENCIES.md b/doc/DEPENDENCIES.md index eb31b5cef190c48300f1166630b920228ad23202..543d02c00d535589103d9d7c39dea708b8846914 100644 --- a/doc/DEPENDENCIES.md +++ b/doc/DEPENDENCIES.md @@ -11,7 +11,7 @@ Exact versions of some packages here are listed in `requirements.txt`. ## Compiling ## ``` ->=conan-1.54.0 (e.g. with `pip install conan`) +>=conan-2.5.0 (e.g. with `pip install conan`) >=cmake-3.13 >=gcc-10.2.0 | >=clang-11 ``` @@ -32,7 +32,7 @@ python packages from the `doc/requirements.txt` file ## Build and run tests ## ``` ->=clang-tidy-11 +clang-tidy-16 >=gtest-1.10.0 ``` @@ -40,11 +40,11 @@ python packages from the `doc/requirements.txt` file ``` >=gcc-10.2.0 ->=lcov-1.15 +>=lcov-1.16 ``` ## Formatting ## ``` ->=clang-formatting-11 +>=clang-format-16 ``` diff --git a/doc/Examples.rst b/doc/Examples.rst index 1bf62f31a05bccd9e168be22a1c2d12d6873f325..32c52b032062a2cb7d5a8e85df94412d8ab5039b 100644 --- a/doc/Examples.rst +++ b/doc/Examples.rst @@ -2,18 +2,18 @@ Examples ======== -Connect to a CaosDB server +Connect to a LinkAhead server -------------------------- -See also the hints on how to :doc:`get started<Install_develop>`, and set-up of libcaosdb. In order -to connect to a CaosDB server with libcaosdb you first have to configure the connection via a +See also the hints on how to :doc:`get started<Install_develop>`, and set-up of liblinkahead. In order +to connect to a LinkAhead server with liblinkahead you first have to configure the connection via a configuration file as explained in the :ref:`"Client Configuration" section <Client Configuration>`. Once the configuration is set up, connecting to the server is as easy as .. code:: cpp const auto &connection = - caosdb::connection::ConnectionManager::GetDefaultConnection(); + linkahead::connection::ConnectionManager::GetDefaultConnection(); You can print the full version of the server that you are connected to (and therby test the connection) via: @@ -32,19 +32,19 @@ therby test the connection) via: Retrieve a Record ----------------- -With libcaosdb you can create a transaction +With liblinkahead you can create a transaction object, fill it with sub-requests, execute it, and retrieve the result(s) . This is handy when you want to have several requests in the same transaction. However, most of the time, e.g., when retrieving one or multiple -Records, this is not necessary. libcaosdb provides helper functions so +Records, this is not necessary. liblinkahead provides helper functions so you don’t have to worry about transactions and their executions. Assume you want to retrieve an Entity with id=123. This is done via .. code:: cpp const auto &connection = - caosdb::connection::ConnectionManager::GetDefaultConnection(); + linkahead::connection::ConnectionManager::GetDefaultConnection(); auto transaction(connection->CreateTransaction()); @@ -57,9 +57,9 @@ you want to retrieve an Entity with id=123. This is done via const auto &entity = result_set.at(0) -You can then use the getter methods like :cpp:any:`GetId<caosdb::entity::Entity::GetId>`, -:cpp:any:`GetParents<caosdb::entity::Entity::GetParents>`, or -:cpp:any:`GetProperties`<caosdb::entity::Entity::GetProperties>` to get the name, the parents, or +You can then use the getter methods like :cpp:any:`GetId<linkahead::entity::Entity::GetId>`, +:cpp:any:`GetParents<linkahead::entity::Entity::GetParents>`, or +:cpp:any:`GetProperties`<linkahead::entity::Entity::GetProperties>` to get the name, the parents, or the properties of the retrieved entity. Retrieving multiple entities works in the same way. Type @@ -78,7 +78,7 @@ transaction manually. This is done by .. code:: cpp const auto &connection = - caosdb::connection::ConnectionManager::GetDefaultConnection(); + linkahead::connection::ConnectionManager::GetDefaultConnection(); auto transaction(connection->CreateTransaction()); transaction->RetrieveById("1231"); @@ -86,7 +86,7 @@ transaction manually. This is done by auto status = transaction->Execute(); A result set can be obtained via -:cpp:any:`GetResultSet`<caosdb::transaction::Transaction::GetResultSet>` which contains the +:cpp:any:`GetResultSet`<linkahead::transaction::Transaction::GetResultSet>` which contains the resulting entities and can, e.g., be checked for length. Execute queries @@ -98,12 +98,12 @@ ids. FIND and SELECT queries ~~~~~~~~~~~~~~~~~~~~~~~ -In general, entities can be found using CaosDB’s query language like +In general, entities can be found using LinkAhead’s query language like .. code:: cpp const auto &connection = - caosdb::connection::ConnectionManager::GetDefaultConnection(); + linkahead::connection::ConnectionManager::GetDefaultConnection(); auto query_transaction(connection->CreateTransaction()); query_transaction->Query("FIND ENTITY WITH id = 1222"); @@ -119,7 +119,7 @@ inspected as above. :: SELECT queries haven't been implemented in the C++ client yet and - thus cannot be executed from libcaosdb right now. SELECT queries + thus cannot be executed from liblinkahead right now. SELECT queries will be added in a future release. COUNT queries @@ -129,12 +129,12 @@ COUNT queries are different from FIND or SELECT queries in two ways. Firstly, they do not return entities but a single number which is why, secondly, they do not have a result set that could be returned. The result of the count is -obtained using the :cpp:any:`GetCountResult<caosdb::transaction::Transaction::GetCountResult>` function: +obtained using the :cpp:any:`GetCountResult<linkahead::transaction::Transaction::GetCountResult>` function: .. code:: cpp const auto &connection = - caosdb::connection::ConnectionManager::GetDefaultConnection(); + linkahead::connection::ConnectionManager::GetDefaultConnection(); auto query_transaction(connection->CreateTransaction()); query_transaction->Query("COUNT RECORD person WITH NAME LIKE '*Baggins'"); @@ -151,7 +151,7 @@ task is added to a transaction and the transaction is executed. .. code:: cpp const auto &connection = - caosdb::connection::ConnectionManager::GetDefaultConnection(); + linkahead::connection::ConnectionManager::GetDefaultConnection(); // ######## INSERT ######## @@ -210,7 +210,7 @@ Up- and Download a file .. code:: cpp const auto &connection = - caosdb::connection::ConnectionManager::GetDefaultConnection(); + linkahead::connection::ConnectionManager::GetDefaultConnection(); Entity file; file.SetRole(Role::FILE); diff --git a/doc/FEATURES.md b/doc/FEATURES.md index 770574833a4fd9dcfd777f9aae4d1f2060ddf541..905481bd4771929ae6c333fa9a5c4d2d8d267dda 100644 --- a/doc/FEATURES.md +++ b/doc/FEATURES.md @@ -1,7 +1,7 @@ # Features -This library provides a client for communication with a CaosDB server over the -CaosDB GRPC-APIs. The client supports +This library provides a client for communication with a LinkAhead server over the +LinkAhead GRPC-APIs. The client supports * Transaction of entities and file transmission. * Authentication via Username/Password. @@ -11,18 +11,18 @@ CaosDB GRPC-APIs. The client supports * File-based configuration. The core is written in C++ and makes heavy use of object-oriented patterns. It -results in a c++ library -- libcaosdb. +results in a c++ library -- liblinkahead. For using the library in a plain C context, a thin wrapper is included --- libccaosdb. It wrapps the C++ classes into structs and the member methods +-- libclinkahead. It wrapps the C++ classes into structs and the member methods into functions which operate on the wrapped C++ instances. Minimal testing executables in C++ and C are included as well, but they only serve as just that -- minimal testing. -## CaosDB Entitiy API +## LinkAhead Entitiy API -This library implements a subset of the CaosDB Entitiy API (caosdb.entity.v1) +This library implements a subset of the LinkAhead Entitiy API (caosdb.entity.v1) as a client. Current limitations: The implementation does not support mixing retrievals with @@ -32,12 +32,12 @@ write-transactions. Support for `FIND`, `SELECT` and `COUNT` queries. -## CaosDB Info API +## LinkAhead Info API -This library implements the CaosDB Info API (caosdb.info.v1) as a client +This library implements the LinkAhead Info API (caosdb.info.v1) as a client without limitations. -## CaosDB ACM (Access Control Management) API +## LinkAhead ACM (Access Control Management) API This library implements small parts of the experimental ACM API (caosdb.acm.v1alpha1) as a client. @@ -46,7 +46,7 @@ This library implements small parts of the experimental ACM API Currently, the library should not be considered thread-safe. -The `caosdb::transaction::Transaction` class is designed with an with an +The `linkahead::transaction::Transaction` class is designed with an with an interface ready for concurrent and asyncronous transactions. While it is possible to execute transactions in non-blocking mode and call `GetStatus` concurrently, it is not possible to use any of the non-const methods of the diff --git a/doc/Install_develop.rst b/doc/Install_develop.rst index 5a102626bbf26bd9089677eb0d61db6f60c6ae17..255fd2f66d47ae86a9daa5ff120b66e6f3ca38c6 100644 --- a/doc/Install_develop.rst +++ b/doc/Install_develop.rst @@ -1,16 +1,16 @@ -How to use and develop libcaosdb +How to use and develop liblinkahead ================================ Dependencies ------------ -- See the `dependencies <DEPENDENCIES.md>`__ file, install with ``pip install -r requiremens.txt``. +- See the `dependencies <DEPENDENCIES.md>`__ file, install with ``pip install -r requirements.txt``. Build ----- -Building with ``make`` -~~~~~~~~~~~~~~~~~~~~~~ +Building with ``make`` and Conan +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Make sure that the dependencies (see above) are fulfilled. On systems which have ``make`` installed, type this in your command line terminal: @@ -19,50 +19,79 @@ which have ``make`` installed, type this in your command line terminal: make conan -Manual build -~~~~~~~~~~~~ +Manual build with Conan +~~~~~~~~~~~~~~~~~~~~~~~ We use `cmake <https://cmake.org>`__ as build tool, with Conan as package manager. The compiler must support the C++17 standard. 1. clone/update the subrepo ``git submodule update --init proto`` -2. ``mkdir build && cd build`` -3. ``conan install .. -s "compiler.libcxx=libstdc++11"`` -4. ``cmake -B . ..`` +2. ``conan install . -s build_type=Release --build=missing`` +3. ``cd build/Release`` +4. ``cmake -S ../.. -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=generators/conan_toolchain.cmake -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_BUILD_TYPE=Release`` 5. ``cmake --build .`` -You may also want to install libcaosdb system-wide to +You may also want to install liblinkahead system-wide to ``CMAKE_INSTALL_PREFIX/lib`` by 1. ``cmake --install .`` The default install prefix is ``~/.local``. It can be set by adding ``-DCMAKE_INSTALL_PREFIX=/path/to/install/prefix`` to the first cmake -command (3.). +command (4.). .. Note:: - The C++ CaosDB library links against other libraries which are installed by Conan. So if you want + The C++ LinkAhead library links against other libraries which are installed by Conan. So if you want to switch to newer versions of those libraries (possible reasons may be security releases or bug fixes), it is not sufficient to update your system libraries, but you have to update your Conan - content and then rebuild libcaosdb. + content and then rebuild liblinkahead. -If you want to build or install libcaosdb without the use of Conan, feel -free to rewrite the CMakeLists.txt as needed. The CaosDB project is open +If you want to build or install liblinkahead without the use of Conan, feel +free to rewrite the CMakeLists.txt as needed. The LinkAhead project is open to merge requests which support multiple ways of installation. -How to build on MacOS -~~~~~~~~~~~~~~~~~~~~~ +Optional: Building with ``vcpkg`` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Next to Conan, you also have the option to use the vcpkg package manager to install the +dependencies (`vcpkg.json`). Note, however, *vcpkg is not fully supported and tested*. It's +included as a submodule in the project. To install the dependencies, run the following +commands: + +.. code:: console + + ./vcpkg/bootstrap-vcpkg.<sh/bat> -disableMetrics + vcpkg/vcpkg install + + +Copy the ``grpc-cpp-plugin`` to the build directory (TODO: This should ideally be done automatically by CMake): + +.. code:: console + + mkdir -p build/build_tools + cp vcpkg_installed/<os>/tools/grpc/grpc_cpp_plugin build/build_tools + +Then compile the project with CMake by including the vcpkg toolchain file: + +.. code:: console + + cd build + cmake -S .. -B . -DCMAKE_TOOLCHAIN_FILE=../vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-linux -DCMAKE_BUILD_TYPE=Release + cmake --build . + +Alternatively, on Linux, you can use the provided `Makefile` targets + +.. code:: console + + make vcpkg-build-release -If you use apple-clang as the compiler: Instead of the above conan -command (2.) use -1. ``conan install .. -s "compiler.cppstd=17"`` -and continue as you would when building on a Linux system. You may have -to add ``build/lib/`` (or, alternatively after installation, -``CMAKE_INSTALL_PREFIX/lib``) to your ``DYLD_LIBRARY_PATH`` -environmental variable. +How to build on MacOS +~~~~~~~~~~~~~~~~~~~~~ + +... is currently untested. Problems and solutions ^^^^^^^^^^^^^^^^^^^^^^ @@ -77,32 +106,36 @@ How to build on Windows ~~~~~~~~~~~~~~~~~~~~~~~ We use `Visual Studio -2019 <https://visualstudio.microsoft.com/de/vs/features/cplusplus/>`__ +2022 <https://visualstudio.microsoft.com/de/vs/features/cplusplus/>`__ as compiler. We use `cmake <https://cmake.org/download/>`__ as build -tool. +tool, which can be installed together with Visual Studio. + +1. Install Python and create a virtual environment with the dependencies in + `requirements.txt`. +2. In a PowerShell, activate the environment and run the following commands from the + repository root: +3. ``conan profile detect --force`` (and check the output) +3. ``make.ps1 conan-install`` +4. ``make.ps1 build`` + +You'll find the shared libraries and cli clients in ``.\build\Release\``. To run the tests, +use ``make.ps1 test``. As a shortcut to run all steps, use ``make.ps1 all``. -1. clone/update the subrepo ``git submodule update --init proto`` -2. ``mkdir build`` -3. ``cd build`` -4. ``conan install .. -g visual_studio -s arch=x86_64 -s build_type=Release -s compiler.toolset=v142 -s compiler.version=16 -s compiler.runtime=MD --build=missing --update`` -5. ``cmake -B . ..`` -6. open ``libcaosdb.sln`` with Visual Studio, change the buildtype to - ``Release`` and build the project. (You can open Tools/Command - Line/Developer Command Prompt and execute - ``msbuild libcaosdb.sln /property:Configuration=Release``) - -Known problems -^^^^^^^^^^^^^^ - -- Linking dynamic libraries currently fails on Windows. So probably - other CaosDB libraries which make use of libcaosdb also will not - build. This is a known bug and we hope to fix this in the next - release. See - `#34 <https://gitlab.indiscale.com/caosdb/src/caosdb-cpplib/-/issues/34>`__ Troubleshooting ~~~~~~~~~~~~~~~ +ERROR: The default build profile '~/.conan2/profiles/default' doesn't exist +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Follow the instructions and run + +.. code:: console + + conan profile detect + +Check the output and adjust settings if necessary. + Warning: WARNING: GCC OLD ABI COMPATIBILITY ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -142,27 +175,47 @@ to, e.g., ``std::string_view`` being unavailable, try specifying the cpp standard manually by ``conan install .. [other options] -s "compiler.cppstd=17"``. +Problems with symlinks on Windows +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +If you're experiencing problems with symlinks, e.g., errors like `` +\linkahead-cpplib\test_package\test_info.cpp(1,1): error C2059: syntax +error '.'`` when running ``conan create`` on Windows you might need to +activate the Windows Development Mode and adjust yor git config to +allow symlinks as described in `this Stackoverflow post +<https://stackoverflow.com/questions/5917249/git-symbolic-links-in-windows/59761201#59761201>`_. Without +development mode and the proper git configuration, windows treats +symlinks as text files instead of links. + Client Configuration -------------------- You can use a json file for the configuration of the client. See -``test/test_data/test_caosdb_client.json`` for an example. You may use -``caosdb-client-configuration-schema.json`` to validate your schema. +``test/test_data/test_linkahead_client.json`` for an example. You may use +``linkahead-client-configuration-schema.json`` to validate your schema. Typically, you will need to provide the path to your SSL certificate. The client will load the configuration file from the first existing file in the following locations (precedence from highest to lowest): -1. A file specified by the environment variable - ``$CAOSDB_CLIENT_CONFIGURATION``. -2. ``$PWD/caosdb_client.json`` -3. ``$PWD/caosdb-client.json`` -4. ``$PWD/.caosdb_client.json`` -5. ``$PWD/.caosdb-client.json`` -6. ``$HOME/caosdb_client.json`` -7. ``$HOME/caosdb-client.json`` -8. ``$HOME/.caosdb_client.json`` -9. ``$HOME/.caosdb-client.json`` +1. A file specified by the environment variable ``$LINKAHEAD_CLIENT_CONFIGURATION``. +2. ``$PWD/linkahead_client.json`` +3. ``$PWD/linkahead-client.json`` +4. ``$PWD/.linkahead_client.json`` +5. ``$PWD/.linkahead-client.json`` +6. ``$HOME/linkahead_client.json`` +7. ``$HOME/linkahead-client.json`` +8. ``$HOME/.linkahead_client.json`` +9. ``$HOME/.linkahead-client.json`` +10. A file specified by the environment variable ``$CAOSDB_CLIENT_CONFIGURATION``. +11. ``$PWD/caosdb_client.json`` +12. ``$PWD/caosdb-client.json`` +13. ``$PWD/.caosdb_client.json`` +14. ``$PWD/.caosdb-client.json`` +15. ``$HOME/caosdb_client.json`` +16. ``$HOME/caosdb-client.json`` +17. ``$HOME/.caosdb_client.json`` +18. ``$HOME/.caosdb-client.json`` Develop ------- @@ -175,25 +228,26 @@ Unit tests Build ^^^^^ -For the tests there is a slightly different setup required (with option -``-D CMAKE_BUILD_TYPE=Debug``) +For the tests the build type has to be Debug. As a shorthand you can run ``make +test``. If you want to build manually, follow these steps: -1. ``mkdir build && cd build/`` -2. ``conan install ..`` (with gcc, append - ``-s "compiler.libcxx=libstdc++11"``, with apple-clang, append - ``-s compiler.cppstd=17``) -3. ``cmake -B . -D CMAKE_BUILD_TYPE=Debug ..`` +1. ``conan install . -s build_type=Debug --build=missing`` +2. ``cd build/Debug`` +3. ``cmake -S ../.. -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=generators/conan_toolchain.cmake -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_BUILD_TYPE=Debug`` - If your clang-format version is too old, formatting, linting etc. can be skipped: ``cmake -B . -D CMAKE_BUILD_TYPE=Debug -D SKIP_LINTING=ON ..`` - Depending on the clang version it may be necessary to also add ``-DCMAKE_CXX_FLAGS="-Wno-unused-parameter"`` -4. ``cmake --build .`` +5. ``cmake --build . `` + - If this fails with ``Error running '': No such file or directory``, you may want to try + CMake's ``-D SKIP_LINTING=ON``. (See previous step.) Run ^^^ -In the build directory, run ``ctest`` +In the build directory, run ``ctest``. For more verbose output of a single test: +``ctest -R test_value.test_list -V`` Framework ^^^^^^^^^ diff --git a/doc/capi/index.rst.in b/doc/capi/index.rst.in index 71c78372ceebba9d03d77fcefe2d33b01ae1d757..1848f93bcd9e3b57844bab8e84347a828f6d8c18 100644 --- a/doc/capi/index.rst.in +++ b/doc/capi/index.rst.in @@ -1,9 +1,9 @@ .. # - # This file is a part of the CaosDB Project. + # This file is a part of the LinkAhead Project. # # Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - # Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + # Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -32,12 +32,12 @@ .. note:: - When working with libcaosdb's C API keep the following in mind: + When working with liblinkahead's C API keep the following in mind: Delete all objects (transactions, entities, properties, parents, ...) that you created using a - call to ``caosdb_..._create_...`` or released using ``caosdb_..._release_...`` and only those. + call to ``linkahead_..._create_...`` or released using ``linkahead_..._release_...`` and only those. - Specifically, any objects set by a ``caosdb_..._get_...`` function are managed by another owning + Specifically, any objects set by a ``linkahead_..._get_...`` function are managed by another owning object (e.g., a connection object is managed by the connection manager) and thus should not be deleted manually. diff --git a/doc/cppapi/index.rst.in b/doc/cppapi/index.rst.in index 67e96fa6014ad1de0da6bec4b33ca5a40b2a6e80..85d0fe522dce202bdc0423d9cf6202f4a70ecde9 100644 --- a/doc/cppapi/index.rst.in +++ b/doc/cppapi/index.rst.in @@ -1,9 +1,9 @@ .. # - # This file is a part of the CaosDB Project. + # This file is a part of the LinkAhead Project. # # Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - # Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + # Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -25,7 +25,7 @@ C++ API ========= -This is the C++ library for connecting to CaosDB. If you are interested in code examples, please +This is the C++ library for connecting to LinkAhead. If you are interested in code examples, please refer to the corresponding :doc:`documentation section<examples.rst>`. diff --git a/doc/header_file.rst.in b/doc/header_file.rst.in index 03b7674d901e7f7fef2ab934d2a43769cf1d67d8..16e455bdf07e88505a2ad4910a073f09d875ab2e 100644 --- a/doc/header_file.rst.in +++ b/doc/header_file.rst.in @@ -1,9 +1,9 @@ .. # - # This file is a part of the CaosDB Project. + # This file is a part of the LinkAhead Project. # # Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - # Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + # Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -29,4 +29,4 @@ :hidden: .. doxygenfile:: @HEADER_FILE@ - :project: libcaosdb + :project: liblinkahead diff --git a/doc/index.rst.in b/doc/index.rst.in index b6fdaaf592f8fe4e36008a509204a10d23d3e320..cae148092ccc12ae8aae07bd0d15a8755c160dc3 100644 --- a/doc/index.rst.in +++ b/doc/index.rst.in @@ -1,9 +1,9 @@ .. # - # This file is a part of the CaosDB Project. + # This file is a part of the LinkAhead Project. # # Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - # Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + # Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as diff --git a/doc/requirements.txt b/doc/requirements.txt index 458d5d584d3a8020543e287c651b521e0479b713..2a508b715a81bec87be01b179009b570f0730b04 100644 --- a/doc/requirements.txt +++ b/doc/requirements.txt @@ -9,7 +9,7 @@ idna==2.10 imagesize==1.2.0 Jinja2==2.11.3 MarkupSafe==1.1.1 -packaging==20.9 +packaging==24.1 Pygments==2.9.0 pyparsing==2.4.7 pytz==2021.1 diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 31f0e81d6a8fc8e55a6005b86d7160c834a2dfd7..7a951bdacc7889b288004de4091eff638d561b7a 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -1,8 +1,8 @@ # -# This file is a part of the CaosDB Project. +# This file is a part of the LinkAhead Project. # # Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> -# Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> +# Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -19,47 +19,47 @@ # # add all header files to this list -set(libcaosdb_INCL - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/authentication.h - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/certificate_provider.h - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/configuration.h - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/connection.h - ${CMAKE_CURRENT_BINARY_DIR}/caosdb/constants.h - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/data_type.h - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/entity.h - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/exceptions.h - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/file_descriptor.h - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/handler_interface.h - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/info.h - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/log_level.h - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/logging.h - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/message_code.h - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/protobuf_helper.h - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/result_table.h - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/result_set.h - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/status_code.h - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/transaction.h - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/transaction_handler.h - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/transaction_status.h - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/unary_rpc_handler.h - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/utility.h - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/value.h - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/file_transmission/register_file_upload_handler.h - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/file_transmission/upload_request_handler.h - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/file_transmission/download_request_handler.h - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/file_transmission/file_writer.h - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/file_transmission/file_reader.h - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/file_transmission/file_error.h +set(liblinkahead_INCL + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/authentication.h + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/certificate_provider.h + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/configuration.h + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/connection.h + ${CMAKE_CURRENT_BINARY_DIR}/linkahead/constants.h + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/data_type.h + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/entity.h + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/exceptions.h + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/file_descriptor.h + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/handler_interface.h + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/info.h + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/log_level.h + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/logging.h + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/message_code.h + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/protobuf_helper.h + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/result_table.h + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/result_set.h + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/status_code.h + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/transaction.h + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/transaction_handler.h + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/transaction_status.h + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/unary_rpc_handler.h + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/utility.h + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/value.h + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/file_transmission/register_file_upload_handler.h + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/file_transmission/upload_request_handler.h + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/file_transmission/download_request_handler.h + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/file_transmission/file_writer.h + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/file_transmission/file_reader.h + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/file_transmission/file_error.h ) IF(BUILD_ACM) - list(APPEND libcaosdb_INCL - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/acm/user.h + list(APPEND liblinkahead_INCL + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/acm/user.h ) ENDIF() # pass variable to parent scope -set(libcaosdb_INCL ${libcaosdb_INCL} PARENT_SCOPE) +set(liblinkahead_INCL ${liblinkahead_INCL} PARENT_SCOPE) # initialize constants -configure_file(caosdb/constants.h.in caosdb/constants.h) +configure_file(linkahead/constants.h.in linkahead/constants.h) diff --git a/include/ccaosdb.h b/include/ccaosdb.h deleted file mode 100644 index 48d0da757351508ed194e52635670d0c24e53164..0000000000000000000000000000000000000000 --- a/include/ccaosdb.h +++ /dev/null @@ -1,501 +0,0 @@ -/* - * This file is a part of the CaosDB Project. - * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 Florian Spreckelsen <f.spreckelsen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> - * - * This program is free software: you can redistribute it and/or - * modify it under the terms of the GNU Affero General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public - * License along with this program. If not, see - * <https://www.gnu.org/licenses/>. - * - */ - -#ifndef CCAOSDB_H -#define CCAOSDB_H -#ifdef __cplusplus -#include <cstdint> // for int64_t -extern "C" { -#else -#include <stdint.h> // for int64_t -#include <stdbool.h> // for bool -#endif - -/** - * Return the constant caosdb::LIBCAOSDB_VERSION_MAJOR. - */ -int caosdb_constants_LIBCAOSDB_VERSION_MAJOR(); -/** - * Return the constant caosdb::LIBCAOSDB_VERSION_MINOR - */ -int caosdb_constants_LIBCAOSDB_VERSION_MINOR(); -/** - * Return the constant caosdb::LIBCAOSDB_VERSION_PATCH. - */ -int caosdb_constants_LIBCAOSDB_VERSION_PATCH(); -/** - * Return the constant caosdb::COMPATIBLE_SERVER_VERSION_MAJOR. - */ -int caosdb_constants_COMPATIBLE_SERVER_VERSION_MAJOR(); -/** - * Return the constant caosdb::COMPATIBLE_SERVER_VERSION_MINOR. - */ -int caosdb_constants_COMPATIBLE_SERVER_VERSION_MINOR(); -/** - * Return the constant caosdb::COMPATIBLE_SERVER_VERSION_PATCH. - */ -int caosdb_constants_COMPATIBLE_SERVER_VERSION_PATCH(); -/** - * Return the constant caosdb::COMPATIBLE_SERVER_VERSION_PRE_RELEASE. - */ -const char *caosdb_constants_COMPATIBLE_SERVER_VERSION_PRE_RELEASE(); - -/** - * Return the status code reserved for errors in clients wrapping this - * interface. - */ -int caosdb_status_code_OTHER_CLIENT_ERROR(); - -/** - * A wrapper of the C++ Connection class. - * - * We use a wrapper for future extensibility and in order to have a minimal - * capability for type checking in C even though the C++ class - * Connection is opaque in C. - */ -typedef struct caosdb_connection_connection { - void *wrapped_connection; - bool _deletable; -} caosdb_connection_connection; - -/** - * A wrapper of the C++ ConnectionConfiguration class. - * - * We use a wrapper for future extensibility and in order to have a minimal - * capability for type checking in C even though the C++ class - * Connection is opaque in C. - */ -typedef struct caosdb_connection_connection_configuration { - void *wrapped_connection_configuration; - bool _deletable; -} caosdb_connection_connection_configuration; - -/** - * A wrapper of the C++ VersionInfo class. - * - * We use a wrapper for future extensibility and in order to have a minimal - * capability for type checking in C even though the C++ class - * Connection is opaque in C. - */ -typedef struct caosdb_info_version_info { - int major; - int minor; - int patch; - const char *pre_release; - const char *build; -} caosdb_info_version_info; - -typedef struct caosdb_connection_certificate_provider { - void *wrapped_certificate_provider; - bool _deletable; -} caosdb_connection_certificate_provider; - -typedef struct caosdb_authentication_authenticator { - void *wrapped_authenticator; - bool _deletable; -} caosdb_authentication_authenticator; - -/** - * Return the environment variable of the given name. - * - * If the environment variable is not set, return the fallback instead. - */ -const char *caosdb_utility_get_env_fallback(const char *name, const char *fallback); - -/** - * Return a description of the status code. - */ -const char *caosdb_get_status_description(int code); - -/** - * Create a pem-file certificate provider. - * - * Use the destructor function - * `caosdb_connection_delete_certificate_provider` to free the wrapped - * provider. - * - * EXPERT USE ONLY. Memory management with this function is a bit tricky. - * Only use it when you know what you are doing. - */ -int caosdb_connection_create_pem_file_certificate_provider( - caosdb_connection_certificate_provider *out, const char *path); - -/** - * Destructor function for a certificate provider. - * - * EXPERT USE ONLY. Only use it when you know what you are doing. - */ -int caosdb_connection_delete_certificate_provider(caosdb_connection_certificate_provider *provider); - -/** - * Create a tls-secured connection configuration. - * - * The configuration is needed to instantiate a connection. - * - * Use the destructor function - * `caosdb_connection_delete_connection_configuration` to free the wrapped - * configuration. - * - * EXPERT USE ONLY. Memory management with this function is a bit tricky. - * Only use it when you know what you are doing. - */ -int caosdb_connection_create_tls_connection_configuration( - caosdb_connection_connection_configuration *out, const char *host, const int port, - caosdb_authentication_authenticator *authenticator, - caosdb_connection_certificate_provider *provider); - -/** - * Create a tls-secured connection configuration. - * - * The configuration is needed to instantiate a connection. - * - * Use `caosdb_connection_create_tls_connection_configuration` for a - * tls-secured connection which also supports authentication. - * - * Use the destructor function - * `caosdb_connection_delete_connection_configuration` to free the wrapped - * configuration. - * - * EXPERT USE ONLY. Memory management with this function is a bit tricky. - * Only use it when you know what you are doing. - */ -int caosdb_connection_create_insecure_connection_configuration( - caosdb_connection_connection_configuration *out, const char *host, const int port); - -/** - * Destructor function for the caosdb_connection_connection_configuration - * struct. - * - * EXPERT USE ONLY. Only use it when you know what you are doing. - */ -int caosdb_connection_delete_connection_configuration( - caosdb_connection_connection_configuration *configuration); - -/** - * Add a public certificate of a trusted certificate authority to an - * existing, tls-enabled connection configuration. - * - * @param cacert path to a pem-file. - */ -int caosdb_connection_configuration_add_cacert( - caosdb_connection_connection_configuration *configuration, const char *cacert); - -/** - * Create a plain password authenticator. - * - * Use the destructor function - * `caosdb_authentication_delete_authenticator` to free the wrapped - * authenticator. - * - * EXPERT USE ONLY. Memory management with this function is a bit tricky. - * Only use it when you know what you are doing. - */ -int caosdb_authentication_create_plain_password_authenticator( - caosdb_authentication_authenticator *out, const char *username, const char *password); - -/** - * Destructor function for the caosdb_authentication_authenticator struct. - * - * EXPERT USE ONLY. Only use it when you know what you are doing. - */ -int caosdb_authentication_delete_authenticator(caosdb_authentication_authenticator *authenticator); - -/** - * Create a connection instance. - * - * The connection is needed to create transactions and to initiate any other - * interaction with a CaosDB server. - * - * Use the destructor function - * `caosdb_connection_delete_connection` to free the wrapped - * connection. - * - * EXPERT USE ONLY. Memory management with this function is a bit tricky. - * Only use it when you know what you are doing. - */ -int caosdb_connection_create_connection( - caosdb_connection_connection *out, - const caosdb_connection_connection_configuration *configuration); - -/** - * Destructor function for the caosdb_connection_connection struct. - * - * EXPERT USE ONLY. Only use it when you know what you are doing. - */ -int caosdb_connection_delete_connection(caosdb_connection_connection *connection); - -/** - * Request the version of the server. - */ -int caosdb_connection_get_version_info(caosdb_info_version_info *out, - const caosdb_connection_connection *connection); - -/** - * Get the default connection from the ConnectionManager. - * - * The default connection is to be specified in a configuration file. - */ -int caosdb_connection_connection_manager_get_default_connection(caosdb_connection_connection *out); - -/** - * Get a named connection from the ConnectionManager. - * - * The named connection is to be specified in a configuration file. - */ -int caosdb_connection_connection_manager_get_connection(caosdb_connection_connection *out, - const char *name); - -/**************************************************************************** - * ENTITY STUFF AND TRANSACTIONS - ****************************************************************************/ - -typedef struct caosdb_transaction_transaction { - void *wrapped_transaction; - bool _deletable; -} caosdb_transaction_transaction; - -/** - * Create a transaction on an existing connection. - * - * This transaction has to be deleted manually by - * caosdb_transaction_delete_transaction() later on. - */ -int caosdb_connection_connection_create_transaction(caosdb_connection_connection *connection, - caosdb_transaction_transaction *out); -int caosdb_transaction_delete_transaction(caosdb_transaction_transaction *transaction); -int caosdb_transaction_transaction_retrieve_by_id(caosdb_transaction_transaction *transaction, - const char *id); -int caosdb_transaction_transaction_retrieve_and_download_file_by_id( - caosdb_transaction_transaction *transaction, const char *id, const char *path); -int caosdb_transaction_transaction_retrieve_by_ids(caosdb_transaction_transaction *transaction, - const char *ids[], int length); -int caosdb_transaction_transaction_query(caosdb_transaction_transaction *transaction, - const char *query); -int caosdb_transaction_transaction_execute(caosdb_transaction_transaction *transaction); -// TODO(fspreck) execute_asynchronously may be added as a separate -// function once we actually support asynchronous execution. - -typedef struct caosdb_transaction_result_set { - void *wrapped_result_set; - bool _deletable; -} caosdb_transaction_result_set; - -typedef struct caosdb_entity_entity { - void *wrapped_entity; - bool _deletable; -} caosdb_entity_entity; - -int caosdb_transaction_transaction_get_result_set(caosdb_transaction_transaction *transaction, - caosdb_transaction_result_set *out); -/** - * Release the result set from the transaction. - * - * The transactions is spoiled after this action and should not be used anymore. - * - * Note: The result_set has to be deleted via caosdb_transaction_delete_result_set. - * - * EXPERT USE ONLY. Only use it when you know what you are doing. - */ -int caosdb_transaction_transaction_release_result_set(caosdb_transaction_transaction *transaction, - caosdb_transaction_result_set *out); -/** - * Release the entity from the result set. - * - * Each entity (each index) can be released once. The result set is spoiled - * after this action and should not be used for anything else anymore. - * - * Note: The result_set has to be deleted via caosdb_entity_delete_entity. - * - * EXPERT USE ONLY. Only use it when you know what you are doing. - */ -int caosdb_transaction_result_set_release_at(caosdb_transaction_result_set *result_set, - caosdb_entity_entity *entity, int index); -/** - * Destructor for caosdb_transaction_result_set. - * - * EXPERT USE ONLY. Only use it when you know what you are doing. - */ -int caosdb_transaction_delete_result_set(caosdb_transaction_result_set *result_set); - -int caosdb_transaction_transaction_get_count_result(caosdb_transaction_transaction *transaction, - long *out); - -int caosdb_transaction_result_set_at(caosdb_transaction_result_set *result_set, - caosdb_entity_entity *entity, int index); -int caosdb_transaction_result_set_size(caosdb_transaction_result_set *result_set, int *out); - -int caosdb_transaction_transaction_insert_entity(caosdb_transaction_transaction *transaction, - caosdb_entity_entity *entity); -int caosdb_transaction_transaction_update_entity(caosdb_transaction_transaction *transaction, - caosdb_entity_entity *entity); -int caosdb_transaction_transaction_delete_by_id(caosdb_transaction_transaction *transaction, - const char *id); - -typedef struct caosdb_entity_property { - void *wrapped_property; - bool _deletable; -} caosdb_entity_property; - -typedef struct caosdb_entity_parent { - void *wrapped_parent; - bool _deletable; -} caosdb_entity_parent; - -typedef struct caosdb_entity_message { - void *wrapped_message; - bool _deletable; -} caosdb_entity_message; - -typedef struct caosdb_entity_value { - void *wrapped_value; - bool _deletable; -} caosdb_entity_value; - -typedef struct caosdb_entity_datatype { - void *wrapped_datatype; - bool _deletable; -} caosdb_entity_datatype; - -// GETTERS FOR EVERYTHING -int caosdb_entity_entity_get_id(caosdb_entity_entity *entity, char **out); -int caosdb_entity_entity_get_role(caosdb_entity_entity *entity, char **out); -int caosdb_entity_entity_get_name(caosdb_entity_entity *entity, char **out); -int caosdb_entity_entity_get_description(caosdb_entity_entity *entity, char **out); -int caosdb_entity_entity_get_local_path(caosdb_entity_entity *entity, char **out); -int caosdb_entity_entity_get_datatype(caosdb_entity_entity *entity, caosdb_entity_datatype *out); -int caosdb_entity_entity_get_unit(caosdb_entity_entity *entity, char **out); -int caosdb_entity_entity_get_value(caosdb_entity_entity *entity, caosdb_entity_value *out); -int caosdb_entity_entity_get_version_id(caosdb_entity_entity *entity, char **out); -int caosdb_entity_entity_get_errors_size(caosdb_entity_entity *entity, int *out); -int caosdb_entity_entity_get_error(caosdb_entity_entity *entity, caosdb_entity_message *out, - int index); -int caosdb_entity_entity_get_warnings_size(caosdb_entity_entity *entity, int *out); -int caosdb_entity_entity_get_warning(caosdb_entity_entity *entity, caosdb_entity_message *out, - int index); -int caosdb_entity_entity_get_infos_size(caosdb_entity_entity *entity, int *out); -int caosdb_entity_entity_get_info(caosdb_entity_entity *entity, caosdb_entity_message *out, - int index); -int caosdb_entity_entity_get_properties_size(caosdb_entity_entity *entity, int *out); -int caosdb_entity_entity_get_property(caosdb_entity_entity *entity, caosdb_entity_property *out, - int index); -int caosdb_entity_entity_get_parents_size(caosdb_entity_entity *entity, int *out); -int caosdb_entity_entity_get_parent(caosdb_entity_entity *entity, caosdb_entity_parent *out, - int index); - -int caosdb_entity_property_get_id(caosdb_entity_property *property, char **out); -int caosdb_entity_property_get_name(caosdb_entity_property *property, char **out); -int caosdb_entity_property_get_description(caosdb_entity_property *property, char **out); -int caosdb_entity_property_get_importance(caosdb_entity_property *property, char **out); -int caosdb_entity_property_get_datatype(caosdb_entity_property *property, - caosdb_entity_datatype *out); -int caosdb_entity_property_get_unit(caosdb_entity_property *property, char **out); -int caosdb_entity_property_get_value(caosdb_entity_property *property, caosdb_entity_value *out); -int caosdb_entity_parent_get_id(caosdb_entity_parent *parent, char **out); -int caosdb_entity_parent_get_name(caosdb_entity_parent *parent, char **out); -int caosdb_entity_parent_get_description(caosdb_entity_parent *parent, char **out); - -int caosdb_entity_message_get_code(caosdb_entity_message *message, int *out); -int caosdb_entity_message_get_description(caosdb_entity_message *message, char **out); - -int caosdb_entity_datatype_is_undefined(caosdb_entity_datatype *datatype, bool *out); -int caosdb_entity_datatype_is_atomic(caosdb_entity_datatype *datatype, bool *out); -int caosdb_entity_datatype_is_reference(caosdb_entity_datatype *datatype, bool *out); -int caosdb_entity_datatype_is_list_of_atomic(caosdb_entity_datatype *datatype, bool *out); -int caosdb_entity_datatype_is_list_of_reference(caosdb_entity_datatype *datatype, bool *out); -int caosdb_entity_datatype_get_datatype_name(caosdb_entity_datatype *datatype, char **out); - -int caosdb_entity_value_is_null(caosdb_entity_value *value, bool *out); -int caosdb_entity_value_is_string(caosdb_entity_value *value, bool *out); -int caosdb_entity_value_is_double(caosdb_entity_value *value, bool *out); -int caosdb_entity_value_is_integer(caosdb_entity_value *value, bool *out); -int caosdb_entity_value_is_bool(caosdb_entity_value *value, bool *out); -int caosdb_entity_value_is_vector(caosdb_entity_value *value, bool *out); -int caosdb_entity_value_get_as_string(caosdb_entity_value *value, char **out); -int caosdb_entity_value_get_as_double(caosdb_entity_value *value, double *out); -int caosdb_entity_value_get_as_integer(caosdb_entity_value *value, int64_t *out); -int caosdb_entity_value_get_as_bool(caosdb_entity_value *value, bool *out); -int caosdb_entity_value_get_as_vector_size(caosdb_entity_value *value, int *out); -int caosdb_entity_value_get_as_vector_at(caosdb_entity_value *value, caosdb_entity_value *out, - const int index); - -// CONSTRUCTORS AND DESTRUCTORS -int caosdb_entity_create_entity(caosdb_entity_entity *out); -int caosdb_entity_delete_entity(caosdb_entity_entity *out); -int caosdb_entity_create_property(caosdb_entity_property *out); -int caosdb_entity_delete_property(caosdb_entity_property *out); -int caosdb_entity_create_parent(caosdb_entity_parent *out); -int caosdb_entity_delete_parent(caosdb_entity_parent *out); - -// DATATYPE CONSTRUCTORS for atomic and reference datatypes and lists thereof -int caosdb_entity_create_atomic_datatype(caosdb_entity_datatype *out, const char *name); -int caosdb_entity_create_reference_datatype(caosdb_entity_datatype *out, const char *name); -int caosdb_entity_create_atomic_list_datatype(caosdb_entity_datatype *out, const char *name); -int caosdb_entity_create_reference_list_datatype(caosdb_entity_datatype *out, const char *name); -int caosdb_entity_delete_datatype(caosdb_entity_datatype *out); - -// VALUE CONSTRUCTORS (resolve overloaded constructors) -int caosdb_entity_create_int_value(caosdb_entity_value *out, const int64_t value); -int caosdb_entity_create_string_value(caosdb_entity_value *out, const char *value); -int caosdb_entity_create_double_value(caosdb_entity_value *out, const double value); -int caosdb_entity_create_bool_value(caosdb_entity_value *out, const bool value); -int caosdb_entity_create_int_vector_value(caosdb_entity_value *out, const int64_t *value, - const int length); -int caosdb_entity_create_string_vector_value(caosdb_entity_value *out, const char **value, - const int length); -int caosdb_entity_create_double_vector_value(caosdb_entity_value *out, const double *value, - const int length); -int caosdb_entity_create_bool_vector_value(caosdb_entity_value *out, const bool *value, - const int length); -int caosdb_entity_delete_value(caosdb_entity_value *out); - -// SETTERS FOR EVERYTHING THAT MAY BE SET -int caosdb_entity_entity_set_role(caosdb_entity_entity *entity, const char *role); -int caosdb_entity_entity_set_name(caosdb_entity_entity *entity, const char *name); -int caosdb_entity_entity_set_description(caosdb_entity_entity *entity, const char *description); -int caosdb_entity_entity_set_local_path(caosdb_entity_entity *entity, const char *name); -int caosdb_entity_entity_set_file_path(caosdb_entity_entity *entity, const char *name); -int caosdb_entity_entity_set_datatype(caosdb_entity_entity *entity, - caosdb_entity_datatype *datatype); -int caosdb_entity_entity_set_unit(caosdb_entity_entity *entity, const char *unit); -int caosdb_entity_entity_set_value(caosdb_entity_entity *entity, caosdb_entity_value *value); - -int caosdb_entity_entity_append_parent(caosdb_entity_entity *entity, caosdb_entity_parent *parent); -int caosdb_entity_entity_remove_parent(caosdb_entity_entity *entity, int index); -int caosdb_entity_entity_append_property(caosdb_entity_entity *entity, - caosdb_entity_property *property); -int caosdb_entity_entity_remove_property(caosdb_entity_entity *entity, int index); - -int caosdb_entity_property_set_id(caosdb_entity_property *property, const char *id); -int caosdb_entity_property_set_name(caosdb_entity_property *property, const char *name); -int caosdb_entity_property_set_datatype(caosdb_entity_property *property, - caosdb_entity_datatype *datatype); -int caosdb_entity_property_set_importance(caosdb_entity_property *property, const char *importance); -int caosdb_entity_property_set_unit(caosdb_entity_property *property, const char *unit); -int caosdb_entity_property_set_value(caosdb_entity_property *property, caosdb_entity_value *value); - -int caosdb_entity_parent_set_id(caosdb_entity_parent *parent, const char *id); -int caosdb_entity_parent_set_name(caosdb_entity_parent *parent, const char *name); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/include/clinkahead.h b/include/clinkahead.h new file mode 100644 index 0000000000000000000000000000000000000000..5f50f593fae7445ed2def525b873f31c325f7a7b --- /dev/null +++ b/include/clinkahead.h @@ -0,0 +1,512 @@ +/* + * This file is a part of the LinkAhead Project. + * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> + * Copyright (C) 2021 Florian Spreckelsen <f.spreckelsen@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this program. If not, see + * <https://www.gnu.org/licenses/>. + * + */ + +#ifndef CLINKAHEAD_H +#define CLINKAHEAD_H +#ifdef __cplusplus +#include <cstdint> // for int64_t +extern "C" { +#else +#include <stdint.h> // for int64_t +#include <stdbool.h> // for bool +#endif + +/** + * Return the constant linkahead::LIBLINKAHEAD_VERSION_MAJOR. + */ +int linkahead_constants_LIBLINKAHEAD_VERSION_MAJOR(); +/** + * Return the constant linkahead::LIBLINKAHEAD_VERSION_MINOR + */ +int linkahead_constants_LIBLINKAHEAD_VERSION_MINOR(); +/** + * Return the constant linkahead::LIBLINKAHEAD_VERSION_PATCH. + */ +int linkahead_constants_LIBLINKAHEAD_VERSION_PATCH(); +/** + * Return the constant linkahead::COMPATIBLE_SERVER_VERSION_MAJOR. + */ +int linkahead_constants_COMPATIBLE_SERVER_VERSION_MAJOR(); +/** + * Return the constant linkahead::COMPATIBLE_SERVER_VERSION_MINOR. + */ +int linkahead_constants_COMPATIBLE_SERVER_VERSION_MINOR(); +/** + * Return the constant linkahead::COMPATIBLE_SERVER_VERSION_PATCH. + */ +int linkahead_constants_COMPATIBLE_SERVER_VERSION_PATCH(); +/** + * Return the constant linkahead::COMPATIBLE_SERVER_VERSION_PRE_RELEASE. + */ +const char *linkahead_constants_COMPATIBLE_SERVER_VERSION_PRE_RELEASE(); + +/** + * Return the status code reserved for errors in clients wrapping this + * interface. + */ +int linkahead_status_code_OTHER_CLIENT_ERROR(); + +/** + * A wrapper of the C++ Connection class. + * + * We use a wrapper for future extensibility and in order to have a minimal + * capability for type checking in C even though the C++ class + * Connection is opaque in C. + */ +typedef struct linkahead_connection_connection { + void *wrapped_connection; + bool _deletable; +} linkahead_connection_connection; + +/** + * A wrapper of the C++ ConnectionConfiguration class. + * + * We use a wrapper for future extensibility and in order to have a minimal + * capability for type checking in C even though the C++ class + * Connection is opaque in C. + */ +typedef struct linkahead_connection_connection_configuration { + void *wrapped_connection_configuration; + bool _deletable; +} linkahead_connection_connection_configuration; + +/** + * A wrapper of the C++ VersionInfo class. + * + * We use a wrapper for future extensibility and in order to have a minimal + * capability for type checking in C even though the C++ class + * Connection is opaque in C. + */ +typedef struct linkahead_info_version_info { + int major; + int minor; + int patch; + const char *pre_release; + const char *build; +} linkahead_info_version_info; + +typedef struct linkahead_connection_certificate_provider { + void *wrapped_certificate_provider; + bool _deletable; +} linkahead_connection_certificate_provider; + +typedef struct linkahead_authentication_authenticator { + void *wrapped_authenticator; + bool _deletable; +} linkahead_authentication_authenticator; + +/** + * Return the environment variable of the given name. + * + * If the environment variable is not set, return the fallback instead. + */ +const char *linkahead_utility_get_env_fallback(const char *name, const char *fallback); + +/** + * Return a description of the status code. + */ +const char *linkahead_get_status_description(int code); + +/** + * Create a pem-file certificate provider. + * + * Use the destructor function + * `linkahead_connection_delete_certificate_provider` to free the wrapped + * provider. + * + * EXPERT USE ONLY. Memory management with this function is a bit tricky. + * Only use it when you know what you are doing. + */ +int linkahead_connection_create_pem_file_certificate_provider( + linkahead_connection_certificate_provider *out, const char *path); + +/** + * Destructor function for a certificate provider. + * + * EXPERT USE ONLY. Only use it when you know what you are doing. + */ +int linkahead_connection_delete_certificate_provider( + linkahead_connection_certificate_provider *provider); + +/** + * Create a tls-secured connection configuration. + * + * The configuration is needed to instantiate a connection. + * + * Use the destructor function + * `linkahead_connection_delete_connection_configuration` to free the wrapped + * configuration. + * + * EXPERT USE ONLY. Memory management with this function is a bit tricky. + * Only use it when you know what you are doing. + */ +int linkahead_connection_create_tls_connection_configuration( + linkahead_connection_connection_configuration *out, const char *host, const int port, + linkahead_authentication_authenticator *authenticator, + linkahead_connection_certificate_provider *provider); + +/** + * Create a tls-secured connection configuration. + * + * The configuration is needed to instantiate a connection. + * + * Use `linkahead_connection_create_tls_connection_configuration` for a + * tls-secured connection which also supports authentication. + * + * Use the destructor function + * `linkahead_connection_delete_connection_configuration` to free the wrapped + * configuration. + * + * EXPERT USE ONLY. Memory management with this function is a bit tricky. + * Only use it when you know what you are doing. + */ +int linkahead_connection_create_insecure_connection_configuration( + linkahead_connection_connection_configuration *out, const char *host, const int port); + +/** + * Destructor function for the linkahead_connection_connection_configuration + * struct. + * + * EXPERT USE ONLY. Only use it when you know what you are doing. + */ +int linkahead_connection_delete_connection_configuration( + linkahead_connection_connection_configuration *configuration); + +/** + * Add a public certificate of a trusted certificate authority to an + * existing, tls-enabled connection configuration. + * + * @param cacert path to a pem-file. + */ +int linkahead_connection_configuration_add_cacert( + linkahead_connection_connection_configuration *configuration, const char *cacert); + +/** + * Create a plain password authenticator. + * + * Use the destructor function + * `linkahead_authentication_delete_authenticator` to free the wrapped + * authenticator. + * + * EXPERT USE ONLY. Memory management with this function is a bit tricky. + * Only use it when you know what you are doing. + */ +int linkahead_authentication_create_plain_password_authenticator( + linkahead_authentication_authenticator *out, const char *username, const char *password); + +/** + * Destructor function for the linkahead_authentication_authenticator struct. + * + * EXPERT USE ONLY. Only use it when you know what you are doing. + */ +int linkahead_authentication_delete_authenticator( + linkahead_authentication_authenticator *authenticator); + +/** + * Create a connection instance. + * + * The connection is needed to create transactions and to initiate any other + * interaction with a LinkAhead server. + * + * Use the destructor function + * `linkahead_connection_delete_connection` to free the wrapped + * connection. + * + * EXPERT USE ONLY. Memory management with this function is a bit tricky. + * Only use it when you know what you are doing. + */ +int linkahead_connection_create_connection( + linkahead_connection_connection *out, + const linkahead_connection_connection_configuration *configuration); + +/** + * Destructor function for the linkahead_connection_connection struct. + * + * EXPERT USE ONLY. Only use it when you know what you are doing. + */ +int linkahead_connection_delete_connection(linkahead_connection_connection *connection); + +/** + * Request the version of the server. + */ +int linkahead_connection_get_version_info(linkahead_info_version_info *out, + const linkahead_connection_connection *connection); + +/** + * Get the default connection from the ConnectionManager. + * + * The default connection is to be specified in a configuration file. + */ +int linkahead_connection_connection_manager_get_default_connection( + linkahead_connection_connection *out); + +/** + * Get a named connection from the ConnectionManager. + * + * The named connection is to be specified in a configuration file. + */ +int linkahead_connection_connection_manager_get_connection(linkahead_connection_connection *out, + const char *name); + +/**************************************************************************** + * ENTITY STUFF AND TRANSACTIONS + ****************************************************************************/ + +typedef struct linkahead_transaction_transaction { + void *wrapped_transaction; + bool _deletable; +} linkahead_transaction_transaction; + +/** + * Create a transaction on an existing connection. + * + * This transaction has to be deleted manually by + * linkahead_transaction_delete_transaction() later on. + */ +int linkahead_connection_connection_create_transaction(linkahead_connection_connection *connection, + linkahead_transaction_transaction *out); +int linkahead_transaction_delete_transaction(linkahead_transaction_transaction *transaction); +int linkahead_transaction_transaction_retrieve_by_id(linkahead_transaction_transaction *transaction, + const char *id); +int linkahead_transaction_transaction_retrieve_and_download_file_by_id( + linkahead_transaction_transaction *transaction, const char *id, const char *path); +int linkahead_transaction_transaction_retrieve_by_ids( + linkahead_transaction_transaction *transaction, const char *ids[], int length); +int linkahead_transaction_transaction_query(linkahead_transaction_transaction *transaction, + const char *query); +int linkahead_transaction_transaction_execute(linkahead_transaction_transaction *transaction); +// TODO(fspreck) execute_asynchronously may be added as a separate +// function once we actually support asynchronous execution. + +typedef struct linkahead_transaction_result_set { + void *wrapped_result_set; + bool _deletable; +} linkahead_transaction_result_set; + +typedef struct linkahead_entity_entity { + void *wrapped_entity; + bool _deletable; +} linkahead_entity_entity; + +int linkahead_transaction_transaction_get_result_set(linkahead_transaction_transaction *transaction, + linkahead_transaction_result_set *out); +/** + * Release the result set from the transaction. + * + * The transactions is spoiled after this action and should not be used anymore. + * + * Note: The result_set has to be deleted via linkahead_transaction_delete_result_set. + * + * EXPERT USE ONLY. Only use it when you know what you are doing. + */ +int linkahead_transaction_transaction_release_result_set( + linkahead_transaction_transaction *transaction, linkahead_transaction_result_set *out); +/** + * Release the entity from the result set. + * + * Each entity (each index) can be released once. The result set is spoiled + * after this action and should not be used for anything else anymore. + * + * Note: The result_set has to be deleted via dentity_delete_entity. + * + * EXPERT USE ONLY. Only use it when you know what you are doing. + */ +int linkahead_transaction_result_set_release_at(linkahead_transaction_result_set *result_set, + linkahead_entity_entity *entity, int index); +/** + * Destructor for linkahead_transaction_result_set. + * + * EXPERT USE ONLY. Only use it when you know what you are doing. + */ +int linkahead_transaction_delete_result_set(linkahead_transaction_result_set *result_set); + +int linkahead_transaction_transaction_get_count_result( + linkahead_transaction_transaction *transaction, long *out); + +int linkahead_transaction_result_set_at(linkahead_transaction_result_set *result_set, + linkahead_entity_entity *entity, int index); +int linkahead_transaction_result_set_size(linkahead_transaction_result_set *result_set, int *out); + +int linkahead_transaction_transaction_insert_entity(linkahead_transaction_transaction *transaction, + linkahead_entity_entity *entity); +int linkahead_transaction_transaction_update_entity(linkahead_transaction_transaction *transaction, + linkahead_entity_entity *entity); +int linkahead_transaction_transaction_delete_by_id(linkahead_transaction_transaction *transaction, + const char *id); + +typedef struct linkahead_entity_property { + void *wrapped_property; + bool _deletable; +} linkahead_entity_property; + +typedef struct linkahead_entity_parent { + void *wrapped_parent; + bool _deletable; +} linkahead_entity_parent; + +typedef struct linkahead_entity_message { + void *wrapped_message; + bool _deletable; +} linkahead_entity_message; + +typedef struct linkahead_entity_value { + void *wrapped_value; + bool _deletable; +} linkahead_entity_value; + +typedef struct linkahead_entity_datatype { + void *wrapped_datatype; + bool _deletable; +} linkahead_entity_datatype; + +// GETTERS FOR EVERYTHING +int linkahead_entity_entity_get_id(linkahead_entity_entity *entity, char **out); +int linkahead_entity_entity_get_role(linkahead_entity_entity *entity, char **out); +int linkahead_entity_entity_get_name(linkahead_entity_entity *entity, char **out); +int linkahead_entity_entity_get_description(linkahead_entity_entity *entity, char **out); +int linkahead_entity_entity_get_local_path(linkahead_entity_entity *entity, char **out); +int linkahead_entity_entity_get_datatype(linkahead_entity_entity *entity, + linkahead_entity_datatype *out); +int linkahead_entity_entity_get_unit(linkahead_entity_entity *entity, char **out); +int linkahead_entity_entity_get_value(linkahead_entity_entity *entity, linkahead_entity_value *out); +int linkahead_entity_entity_get_version_id(linkahead_entity_entity *entity, char **out); +int linkahead_entity_entity_get_errors_size(linkahead_entity_entity *entity, int *out); +int linkahead_entity_entity_get_error(linkahead_entity_entity *entity, + linkahead_entity_message *out, int index); +int linkahead_entity_entity_get_warnings_size(linkahead_entity_entity *entity, int *out); +int linkahead_entity_entity_get_warning(linkahead_entity_entity *entity, + linkahead_entity_message *out, int index); +int linkahead_entity_entity_get_infos_size(linkahead_entity_entity *entity, int *out); +int linkahead_entity_entity_get_info(linkahead_entity_entity *entity, linkahead_entity_message *out, + int index); +int linkahead_entity_entity_get_properties_size(linkahead_entity_entity *entity, int *out); +int linkahead_entity_entity_get_property(linkahead_entity_entity *entity, + linkahead_entity_property *out, int index); +int linkahead_entity_entity_get_parents_size(linkahead_entity_entity *entity, int *out); +int linkahead_entity_entity_get_parent(linkahead_entity_entity *entity, + linkahead_entity_parent *out, int index); + +int linkahead_entity_property_get_id(linkahead_entity_property *property, char **out); +int linkahead_entity_property_get_name(linkahead_entity_property *property, char **out); +int linkahead_entity_property_get_description(linkahead_entity_property *property, char **out); +int linkahead_entity_property_get_importance(linkahead_entity_property *property, char **out); +int linkahead_entity_property_get_datatype(linkahead_entity_property *property, + linkahead_entity_datatype *out); +int linkahead_entity_property_get_unit(linkahead_entity_property *property, char **out); +int linkahead_entity_property_get_value(linkahead_entity_property *property, + linkahead_entity_value *out); +int linkahead_entity_parent_get_id(linkahead_entity_parent *parent, char **out); +int linkahead_entity_parent_get_name(linkahead_entity_parent *parent, char **out); +int linkahead_entity_parent_get_description(linkahead_entity_parent *parent, char **out); + +int linkahead_entity_message_get_code(linkahead_entity_message *message, int *out); +int linkahead_entity_message_get_description(linkahead_entity_message *message, char **out); + +int linkahead_entity_datatype_is_undefined(linkahead_entity_datatype *datatype, bool *out); +int linkahead_entity_datatype_is_atomic(linkahead_entity_datatype *datatype, bool *out); +int linkahead_entity_datatype_is_reference(linkahead_entity_datatype *datatype, bool *out); +int linkahead_entity_datatype_is_list_of_atomic(linkahead_entity_datatype *datatype, bool *out); +int linkahead_entity_datatype_is_list_of_reference(linkahead_entity_datatype *datatype, bool *out); +int linkahead_entity_datatype_get_datatype_name(linkahead_entity_datatype *datatype, char **out); + +int linkahead_entity_value_is_null(linkahead_entity_value *value, bool *out); +int linkahead_entity_value_is_string(linkahead_entity_value *value, bool *out); +int linkahead_entity_value_is_double(linkahead_entity_value *value, bool *out); +int linkahead_entity_value_is_integer(linkahead_entity_value *value, bool *out); +int linkahead_entity_value_is_bool(linkahead_entity_value *value, bool *out); +int linkahead_entity_value_is_vector(linkahead_entity_value *value, bool *out); +int linkahead_entity_value_get_as_string(linkahead_entity_value *value, char **out); +int linkahead_entity_value_get_as_double(linkahead_entity_value *value, double *out); +int linkahead_entity_value_get_as_integer(linkahead_entity_value *value, int64_t *out); +int linkahead_entity_value_get_as_bool(linkahead_entity_value *value, bool *out); +int linkahead_entity_value_get_as_vector_size(linkahead_entity_value *value, int *out); +int linkahead_entity_value_get_as_vector_at(linkahead_entity_value *value, + linkahead_entity_value *out, const int index); + +// CONSTRUCTORS AND DESTRUCTORS +int linkahead_entity_create_entity(linkahead_entity_entity *out); +int linkahead_entity_delete_entity(linkahead_entity_entity *out); +int linkahead_entity_create_property(linkahead_entity_property *out); +int linkahead_entity_delete_property(linkahead_entity_property *out); +int linkahead_entity_create_parent(linkahead_entity_parent *out); +int linkahead_entity_delete_parent(linkahead_entity_parent *out); + +// DATATYPE CONSTRUCTORS for atomic and reference datatypes and lists thereof +int linkahead_entity_create_atomic_datatype(linkahead_entity_datatype *out, const char *name); +int linkahead_entity_create_reference_datatype(linkahead_entity_datatype *out, const char *name); +int linkahead_entity_create_atomic_list_datatype(linkahead_entity_datatype *out, const char *name); +int linkahead_entity_create_reference_list_datatype(linkahead_entity_datatype *out, + const char *name); +int linkahead_entity_delete_datatype(linkahead_entity_datatype *out); + +// VALUE CONSTRUCTORS (resolve overloaded constructors) +int linkahead_entity_create_int_value(linkahead_entity_value *out, const int64_t value); +int linkahead_entity_create_string_value(linkahead_entity_value *out, const char *value); +int linkahead_entity_create_double_value(linkahead_entity_value *out, const double value); +int linkahead_entity_create_bool_value(linkahead_entity_value *out, const bool value); +int linkahead_entity_create_int_vector_value(linkahead_entity_value *out, const int64_t *value, + const int length); +int linkahead_entity_create_string_vector_value(linkahead_entity_value *out, const char **value, + const int length); +int linkahead_entity_create_double_vector_value(linkahead_entity_value *out, const double *value, + const int length); +int linkahead_entity_create_bool_vector_value(linkahead_entity_value *out, const bool *value, + const int length); +int linkahead_entity_delete_value(linkahead_entity_value *out); + +// SETTERS FOR EVERYTHING THAT MAY BE SET +int linkahead_entity_entity_set_role(linkahead_entity_entity *entity, const char *role); +int linkahead_entity_entity_set_name(linkahead_entity_entity *entity, const char *name); +int linkahead_entity_entity_set_description(linkahead_entity_entity *entity, + const char *description); +int linkahead_entity_entity_set_local_path(linkahead_entity_entity *entity, const char *name); +int linkahead_entity_entity_set_file_path(linkahead_entity_entity *entity, const char *name); +int linkahead_entity_entity_set_datatype(linkahead_entity_entity *entity, + linkahead_entity_datatype *datatype); +int linkahead_entity_entity_set_unit(linkahead_entity_entity *entity, const char *unit); +int linkahead_entity_entity_set_value(linkahead_entity_entity *entity, + linkahead_entity_value *value); + +int linkahead_entity_entity_append_parent(linkahead_entity_entity *entity, + linkahead_entity_parent *parent); +int linkahead_entity_entity_remove_parent(linkahead_entity_entity *entity, int index); +int linkahead_entity_entity_append_property(linkahead_entity_entity *entity, + linkahead_entity_property *property); +int linkahead_entity_entity_remove_property(linkahead_entity_entity *entity, int index); + +int linkahead_entity_property_set_id(linkahead_entity_property *property, const char *id); +int linkahead_entity_property_set_name(linkahead_entity_property *property, const char *name); +int linkahead_entity_property_set_datatype(linkahead_entity_property *property, + linkahead_entity_datatype *datatype); +int linkahead_entity_property_set_importance(linkahead_entity_property *property, + const char *importance); +int linkahead_entity_property_set_unit(linkahead_entity_property *property, const char *unit); +int linkahead_entity_property_set_value(linkahead_entity_property *property, + linkahead_entity_value *value); + +int linkahead_entity_parent_set_id(linkahead_entity_parent *parent, const char *id); +int linkahead_entity_parent_set_name(linkahead_entity_parent *parent, const char *name); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/include/caosdb/acm/user.h b/include/linkahead/acm/user.h similarity index 90% rename from include/caosdb/acm/user.h rename to include/linkahead/acm/user.h index 9c1ae91ec9451c7d7a33b4b209646676fa2d7eb0..9a9943ab978ad4dbf72e1cb1b705e8642e6f06aa 100644 --- a/include/caosdb/acm/user.h +++ b/include/linkahead/acm/user.h @@ -1,5 +1,5 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * * Copyright (C) 2022 Timm Fitschen <t.fitschen@indiscale.com> * Copyright (C) 2022 IndiScale GmbH <info@indiscale.com> @@ -21,24 +21,24 @@ /** * @brief Users, together with roles, and permissions are a fundamental concept - * of the access controll management of CaosDB. + * of the access controll management of LinkAhead. * - * @file caosdb/acm/user.h + * @file linkahead/acm/user.h * @author Timm Fitchen * @date 2022-06-29 */ #ifdef BUILD_ACM -#ifndef CAOSDB_ACM_USER_H -#define CAOSDB_ACM_USER_H +#ifndef LINKAHEAD_ACM_USER_H +#define LINKAHEAD_ACM_USER_H #include <memory> // for unique_ptr #include <string> // for string -namespace caosdb::connection { +namespace linkahead::connection { class Connection; } -namespace caosdb::acm { +namespace linkahead::acm { /** * The UserImpl class is the delegate of the User class. It hides the @@ -120,7 +120,7 @@ public: */ auto SetPassword(const std::string &password) -> void; - friend class caosdb::connection::Connection; + friend class linkahead::connection::Connection; private: /** @@ -133,6 +133,6 @@ private: std::unique_ptr<UserImpl> wrapped; }; -} // namespace caosdb::acm +} // namespace linkahead::acm #endif #endif diff --git a/include/caosdb/authentication.h b/include/linkahead/authentication.h similarity index 83% rename from include/caosdb/authentication.h rename to include/linkahead/authentication.h index 2e117265d71f660888d6fd76d5fe3a3f898cac95..2770bcfdda5fbef96e8005f9e723a3f84358e333 100644 --- a/include/caosdb/authentication.h +++ b/include/linkahead/authentication.h @@ -1,8 +1,8 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -19,31 +19,31 @@ * */ -#ifndef CAOSDB_AUTHENTICATION_H -#define CAOSDB_AUTHENTICATION_H +#ifndef LINKAHEAD_AUTHENTICATION_H +#define LINKAHEAD_AUTHENTICATION_H /** - * @file caosdb/authentication.h + * @file linkahead/authentication.h * @author Timm Fitschen * @date 2021-06-28 * @brief Configuration and setup of the client authentication. */ -#include "caosdb/utility.h" // for base64_encode #include <grpcpp/security/auth_context.h> // for AuthContext -#include <grpcpp/security/credentials.h> // for CallCredentials +#include <grpcpp/security/credentials.h> // for CallCredentials, MetadataC... +#include <grpcpp/support/config.h> // for string #include <grpcpp/support/interceptor.h> // for Status -#include <grpcpp/support/status.h> // for Status #include <grpcpp/support/string_ref.h> // for string_ref #include <map> // for multimap #include <memory> // for shared_ptr -#include <string> // for string +#include <string> // for string, basic_string +#include "linkahead/utility.h" // for base64_encode -namespace caosdb { +namespace linkahead { namespace authentication { -using caosdb::utility::base64_encode; using grpc::AuthContext; using grpc::MetadataCredentialsPlugin; using grpc::Status; using grpc::string_ref; +using linkahead::utility::base64_encode; /** * @brief Abstract base class for authenticators. @@ -83,5 +83,5 @@ public: [[nodiscard]] auto GetCallCredentials() const -> std::shared_ptr<grpc::CallCredentials> override; }; } // namespace authentication -} // namespace caosdb +} // namespace linkahead #endif diff --git a/include/caosdb/certificate_provider.h b/include/linkahead/certificate_provider.h similarity index 84% rename from include/caosdb/certificate_provider.h rename to include/linkahead/certificate_provider.h index a2cb5b5a1e407d93f3aa0ac774c26aac5ff31f83..468500aeb66eabdff9a8ce94a772197114b5dd0d 100644 --- a/include/caosdb/certificate_provider.h +++ b/include/linkahead/certificate_provider.h @@ -1,8 +1,8 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -19,11 +19,11 @@ * */ -#ifndef CAOSDB_CERTIFICATE_PROVIDER_H -#define CAOSDB_CERTIFICATE_PROVIDER_H +#ifndef LINKAHEAD_CERTIFICATE_PROVIDER_H +#define LINKAHEAD_CERTIFICATE_PROVIDER_H #include <filesystem> // for path -namespace caosdb::configuration { +namespace linkahead::configuration { using std::filesystem::path; class CertificateProvider { @@ -49,5 +49,5 @@ public: explicit PemCertificateProvider(std::string certificate_provider); [[nodiscard]] auto GetCertificatePem() const -> std::string override; }; -} // namespace caosdb::configuration +} // namespace linkahead::configuration #endif diff --git a/include/caosdb/configuration.h b/include/linkahead/configuration.h similarity index 78% rename from include/caosdb/configuration.h rename to include/linkahead/configuration.h index 053888672ab3e1649a060553264fe8d26fda9907..bdb87fd3f8133485649af3561fb065455f7a993f 100644 --- a/include/caosdb/configuration.h +++ b/include/linkahead/configuration.h @@ -1,8 +1,8 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -19,36 +19,36 @@ * */ -#ifndef CAOSDB_CONFIGURATION_H -#define CAOSDB_CONFIGURATION_H - -#include "caosdb/authentication.h" // for Authenticator, PlainPassw... -#include "caosdb/certificate_provider.h" // for CertificateProvider, path -#include "caosdb/exceptions.h" // for ConfigurationError -#include "caosdb/utility.h" // for load_json_file -#include <google/protobuf/arena.h> // for Arena -#include <google/protobuf/extension_set.h> // for Arena -#include <grpcpp/security/credentials.h> // for ChannelCredentials -#include <filesystem> // for path, exists -#include <iosfwd> // for ostream -#include <memory> // for shared_ptr, unique_ptr -#include <string> // for string - -namespace caosdb::configuration { -using caosdb::authentication::Authenticator; -using caosdb::authentication::PlainPasswordAuthenticator; -using caosdb::exceptions::ConfigurationError; -using caosdb::utility::JsonValue; -using caosdb::utility::load_json_file; +#ifndef LINKAHEAD_CONFIGURATION_H +#define LINKAHEAD_CONFIGURATION_H + +#include "linkahead/authentication.h" // for Authenticator, PlainPassw... +#include "linkahead/certificate_provider.h" // for CertificateProvider, path +#include "linkahead/exceptions.h" // for ConfigurationError +#include "linkahead/utility.h" // for load_json_file +#include <google/protobuf/arena.h> // for Arena +#include <google/protobuf/extension_set.h> // for Arena +#include <grpcpp/security/credentials.h> // for ChannelCredentials +#include <filesystem> // for path, exists +#include <iosfwd> // for ostream +#include <memory> // for shared_ptr, unique_ptr +#include <string> // for string + +namespace linkahead::configuration { using google::protobuf::Arena; using grpc::ChannelCredentials; +using linkahead::authentication::Authenticator; +using linkahead::authentication::PlainPasswordAuthenticator; +using linkahead::exceptions::ConfigurationError; +using linkahead::utility::JsonValue; +using linkahead::utility::load_json_file; using std::filesystem::exists; using std::filesystem::path; -const std::string logger_name = "caosdb::configuration"; +const std::string logger_name = "linkahead::configuration"; /** - * @brief Configuration of the CaosDB connection. + * @brief Configuration of the LinkAhead connection. */ class ConnectionConfiguration { private: @@ -103,10 +103,7 @@ public: */ class ConfigurationManager { public: - static ConfigurationManager &GetInstance() { - static ConfigurationManager instance; - return instance; - }; + static ConfigurationManager &GetInstance(); /** * See mReset. @@ -156,8 +153,9 @@ public: private: Arena arena; JsonValue json_configuration; + static ConfigurationManager mInstance; - inline ConfigurationManager() + inline ConfigurationManager() noexcept : json_configuration(nullptr){ // InitializeDefaults(); }; @@ -166,7 +164,7 @@ private: * Initialize this ConfigurationManager with the defaults. * * Currently, this means, that the ConfigurationManager attempts to load the - * first existing file from the LIBCAOSDB_CONFIGURATION_FILES_PRECEDENCE list + * first existing file from the LIBLINKAHEAD_CONFIGURATION_FILES_PRECEDENCE list * of file locations. */ auto InitializeDefaults() -> int; @@ -206,5 +204,5 @@ private: auto mGetDefaultConnectionName() const -> std::string; }; -} // namespace caosdb::configuration +} // namespace linkahead::configuration #endif diff --git a/include/caosdb/connection.h b/include/linkahead/connection.h similarity index 84% rename from include/caosdb/connection.h rename to include/linkahead/connection.h index d0414f2e84f81fe9e86a50f2e6411788cf0befeb..1f47a421cc123688051a45514fcffaf94179d9c7 100644 --- a/include/caosdb/connection.h +++ b/include/linkahead/connection.h @@ -1,8 +1,8 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -19,48 +19,51 @@ * */ -#ifndef CAOSDB_CONNECTION_H -#define CAOSDB_CONNECTION_H +#ifndef LINKAHEAD_CONNECTION_H +#define LINKAHEAD_CONNECTION_H /** - * @file caosdb/connection.h + * @file linkahead/connection.h * @author Timm Fitschen * @date 2021-05-18 * @brief Configuration and setup of the connection. */ #ifdef BUILD_ACM -#include "caosdb/acm/user.h" // for User +#include "linkahead/acm/user.h" // for User #include "caosdb/acm/v1alpha1/main.grpc.pb.h" // for AccessControlMan... #endif -#include "caosdb/authentication.h" // for Authenticator -#include "caosdb/configuration.h" // for ConnectionConfigura... +#include "linkahead/authentication.h" // for Authenticator +#include "linkahead/configuration.h" // for ConnectionConfigura... #include "caosdb/entity/v1/main.grpc.pb.h" // for EntityTransactionSe... -#include "caosdb/info.h" // for VersionInfo +#include "linkahead/info.h" // for VersionInfo #include "caosdb/info/v1/main.grpc.pb.h" // for GeneralInfoService:... -#include "caosdb/transaction.h" // for Transaction -#include "caosdb/transaction_status.h" // for TransactionStatus +#include "linkahead/transaction.h" // for Transaction +#include "linkahead/transaction_status.h" // for TransactionStatus #include <filesystem> // for path #include <grpcpp/channel.h> // for Channel #include <map> // for map #include <memory> // for shared_ptr, unique_ptr #include <string> // for string, basic_string +#ifdef BUILD_ACM +#include <vector> // for vector +#endif -namespace caosdb::connection { +namespace linkahead::connection { #ifdef BUILD_ACM -using caosdb::acm::User; using caosdb::acm::v1alpha1::AccessControlManagementService; +using linkahead::acm::User; #endif -using caosdb::authentication::Authenticator; -using caosdb::configuration::ConnectionConfiguration; using caosdb::entity::v1::EntityTransactionService; using caosdb::entity::v1::FileTransmissionService; -using caosdb::info::VersionInfo; using caosdb::info::v1::GeneralInfoService; -using caosdb::transaction::Transaction; -using caosdb::transaction::TransactionStatus; +using linkahead::authentication::Authenticator; +using linkahead::configuration::ConnectionConfiguration; +using linkahead::info::VersionInfo; +using linkahead::transaction::Transaction; +using linkahead::transaction::TransactionStatus; using std::filesystem::path; /** - * @brief A reusable connection to a CaosDBServer. + * @brief A reusable connection to a LinkAheadServer. */ class Connection { public: @@ -122,6 +125,11 @@ public: // TODO(tf) find a way to deal with this: // NOLINTNEXTLINE(bugprone-easily-swappable-parameters) auto DeleteSingleUser(const std::string &realm, const std::string &name) const -> void; + + /** + * List known users. + */ + auto ListUsers() const -> std::vector<User>; #endif private: @@ -162,7 +170,10 @@ class ConnectionManager { private: mutable std::map<std::string, std::shared_ptr<Connection>> connections; mutable std::string default_connection_name; - inline ConnectionManager(){}; + + static ConnectionManager mInstance; + + ConnectionManager() = default; auto mHasConnection(const std::string &name) const -> bool; @@ -176,10 +187,7 @@ private: } public: - static ConnectionManager &GetInstance() { - static ConnectionManager instance; - return instance; - }; + static ConnectionManager &GetInstance(); inline static auto HasConnection(const std::string &name) -> bool { return ConnectionManager::GetInstance().mHasConnection(name); @@ -202,5 +210,5 @@ public: void operator=(ConnectionManager const &) = delete; }; -} // namespace caosdb::connection +} // namespace linkahead::connection #endif diff --git a/include/caosdb/constants.h.in b/include/linkahead/constants.h.in similarity index 51% rename from include/caosdb/constants.h.in rename to include/linkahead/constants.h.in index 2661806d63a23b419da44de664f087b3c95c9a87..b47ab22213e01da96e0e8d7525591892c65d420d 100644 --- a/include/caosdb/constants.h.in +++ b/include/linkahead/constants.h.in @@ -1,9 +1,9 @@ /* * - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -20,27 +20,36 @@ * */ -#ifndef CAOSDB_CONSTANTS_H -#define CAOSDB_CONSTANTS_H +#ifndef LINKAHEAD_CONSTANTS_H +#define LINKAHEAD_CONSTANTS_H #ifndef __GNUC__ #define __attribute__(x) #endif #ifdef __cplusplus -namespace caosdb { +namespace linkahead { #endif // clang-format off -static const int LIBCAOSDB_VERSION_MAJOR = @libcaosdb_VERSION_MAJOR@; -static const int LIBCAOSDB_VERSION_MINOR = @libcaosdb_VERSION_MINOR@; -static const int LIBCAOSDB_VERSION_PATCH = @libcaosdb_VERSION_PATCH@; -static const int COMPATIBLE_SERVER_VERSION_MAJOR = @libcaosdb_COMPATIBLE_SERVER_VERSION_MAJOR@; -static const int COMPATIBLE_SERVER_VERSION_MINOR = @libcaosdb_COMPATIBLE_SERVER_VERSION_MINOR@; -static const int COMPATIBLE_SERVER_VERSION_PATCH = @libcaosdb_COMPATIBLE_SERVER_VERSION_PATCH@; -__attribute__((unused)) static const char* COMPATIBLE_SERVER_VERSION_PRE_RELEASE = "@libcaosdb_COMPATIBLE_SERVER_VERSION_PRE_RELEASE@"; +static const int LIBLINKAHEAD_VERSION_MAJOR = @liblinkahead_VERSION_MAJOR@; +static const int LIBLINKAHEAD_VERSION_MINOR = @liblinkahead_VERSION_MINOR@; +static const int LIBLINKAHEAD_VERSION_PATCH = @liblinkahead_VERSION_PATCH@; +static const int COMPATIBLE_SERVER_VERSION_MAJOR = @liblinkahead_COMPATIBLE_SERVER_VERSION_MAJOR@; +static const int COMPATIBLE_SERVER_VERSION_MINOR = @liblinkahead_COMPATIBLE_SERVER_VERSION_MINOR@; +static const int COMPATIBLE_SERVER_VERSION_PATCH = @liblinkahead_COMPATIBLE_SERVER_VERSION_PATCH@; +__attribute__((unused)) static const char* COMPATIBLE_SERVER_VERSION_PRE_RELEASE = "@liblinkahead_COMPATIBLE_SERVER_VERSION_PRE_RELEASE@"; /** * Precedence of configuration files from highest to lowest. */ -__attribute__((unused)) static const char* LIBCAOSDB_CONFIGURATION_FILES_PRECEDENCE[] = { +__attribute__((unused)) static const char* LIBLINKAHEAD_CONFIGURATION_FILES_PRECEDENCE[] = { + "$LINKAHEAD_CLIENT_CONFIGURATION", + "linkahead_client.json", + "linkahead-client.json", + ".linkahead_client.json", + ".linkahead-client.json", + "$HOME/linkahead_client.json", + "$HOME/linkahead-client.json", + "$HOME/.linkahead_client.json", + "$HOME/.linkahead-client.json", "$CAOSDB_CLIENT_CONFIGURATION", "caosdb_client.json", "caosdb-client.json", @@ -53,6 +62,6 @@ __attribute__((unused)) static const char* LIBCAOSDB_CONFIGURATION_FILES_PRECEDE }; // clang-format on #ifdef __cplusplus -} // namespace caosdb +} // namespace linkahead #endif #endif diff --git a/include/caosdb/data_type.h b/include/linkahead/data_type.h similarity index 94% rename from include/caosdb/data_type.h rename to include/linkahead/data_type.h index 11909c012e3105ed29185637b3f32801f1613ccf..950c84c1cf413cb9a6538b8a57947a8d1a1ad184 100644 --- a/include/caosdb/data_type.h +++ b/include/linkahead/data_type.h @@ -1,8 +1,8 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -26,21 +26,21 @@ * obtained with GetName(). */ -#ifndef CAOSDB_DATA_TYPE_H -#define CAOSDB_DATA_TYPE_H -#include "caosdb/protobuf_helper.h" // for ProtoMessageWrapper -#include "caosdb/entity/v1/main.pb.h" // for RepeatedPtrField, Message -#include <memory> // for unique_ptr -#include <string> // for string -namespace caosdb::entity { +#ifndef LINKAHEAD_DATA_TYPE_H +#define LINKAHEAD_DATA_TYPE_H +#include "linkahead/protobuf_helper.h" // for ProtoMessageWrapper +#include "caosdb/entity/v1/main.pb.h" // for RepeatedPtrField, Message +#include <memory> // for unique_ptr +#include <string> // for string +namespace linkahead::entity { using ProtoAtomicDataType = caosdb::entity::v1::AtomicDataType; using ProtoDataType = caosdb::entity::v1::DataType; using ProtoListDataType = caosdb::entity::v1::ListDataType; using ProtoReferenceDataType = caosdb::entity::v1::ReferenceDataType; using DataTypeCase = caosdb::entity::v1::DataType::DataTypeCase; using ListDataTypeCase = caosdb::entity::v1::ListDataType::ListDataTypeCase; -using caosdb::utility::ProtoMessageWrapper; -using caosdb::utility::ScalarProtoMessageWrapper; +using linkahead::utility::ProtoMessageWrapper; +using linkahead::utility::ScalarProtoMessageWrapper; class Entity; class Property; @@ -283,6 +283,6 @@ protected: mutable std::unique_ptr<ListDataType> list_data_type; }; -} // namespace caosdb::entity +} // namespace linkahead::entity #endif diff --git a/include/caosdb/entity.h b/include/linkahead/entity.h similarity index 91% rename from include/caosdb/entity.h rename to include/linkahead/entity.h index 23b6e2f612a52e85df9eb2682b6cac11fd594063..fd08014634a1a650b6fd3c4cac3e64a6e39e8890 100644 --- a/include/caosdb/entity.h +++ b/include/linkahead/entity.h @@ -1,9 +1,9 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> * Copyright (C) 2021 Florian Spreckelsen <f.spreckelsen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -22,34 +22,34 @@ /** * @brief Anything entity-related. - * @file caosdb/entity.h + * @file linkahead/entity.h * @author Timm Fitchen * @date 2021-07-07 */ -#ifndef CAOSDB_ENTITY_H -#define CAOSDB_ENTITY_H - -#include "caosdb/data_type.h" // for DataType -#include "caosdb/entity/v1/main.pb.h" // for RepeatedPtrField -#include "caosdb/file_descriptor.h" // for FileDescriptor -#include "caosdb/logging.h" // for CAOSDB_LOG_WARN -#include "caosdb/message_code.h" // for get_message_code -#include "caosdb/protobuf_helper.h" // for get_arena -#include "caosdb/status_code.h" // for StatusCode -#include "caosdb/value.h" // for Value -#include <cstdint> // for int64_t -#include <filesystem> // for path -#include <google/protobuf/arena.h> // for Arena -#include <google/protobuf/message.h> // for RepeatedPtrField -#include <iterator> // for iterator, output_iterato... -#include <map> // for map -#include <stdexcept> // for out_of_range -#include <string> // for string, basic... -#include <utility> // for move -#include <vector> // for vector +#ifndef LINKAHEAD_ENTITY_H +#define LINKAHEAD_ENTITY_H + +#include <google/protobuf/message.h> // for RepeatedPtrField +#include <cstdint> // for int64_t +#include <filesystem> // for path, exists, is_directory +#include <iosfwd> // for ptrdiff_t +#include <iterator> // for output_iterator_tag +#include <map> // for map +#include <stdexcept> // for out_of_range +#include <string> // for string, basic_string, operator== +#include <utility> // for move, pair +#include <vector> // for vector +#include "caosdb/entity/v1/main.pb.h" // for Entity, EntityRole, Property +#include "linkahead/data_type.h" // for DataType, AtomicDataType +#include "linkahead/file_descriptor.h" // for FileDescriptor +#include "linkahead/logging.h" // for LoggerOutputStream, LINKAHEAD... +#include "linkahead/message_code.h" // for get_message_code, MessageCode +#include "linkahead/protobuf_helper.h" // for ScalarProtoMessageWrapper +#include "linkahead/status_code.h" // for StatusCode +#include "linkahead/value.h" // for Value, AbstractValue, Arena // IWYU pragma: no_include "net/proto2/public/repeated_field.h" -namespace caosdb::entity { +namespace linkahead::entity { using caosdb::entity::v1::IdResponse; using std::filesystem::exists; using std::filesystem::is_directory; @@ -61,15 +61,15 @@ using ProtoValue = caosdb::entity::v1::Value; using ProtoDataType = caosdb::entity::v1::DataType; using caosdb::entity::v1::EntityRole; using ProtoImportance = caosdb::entity::v1::Importance; -using caosdb::StatusCode; using caosdb::entity::v1::EntityResponse; using caosdb::entity::v1::FileTransmissionId; -using caosdb::utility::get_arena; -using caosdb::utility::ProtoMessageWrapper; using ::google::protobuf::RepeatedPtrField; using google::protobuf::RepeatedPtrField; +using linkahead::StatusCode; +using linkahead::utility::get_arena; +using linkahead::utility::ProtoMessageWrapper; -static const std::string logger_name = "caosdb::entity"; +static const std::string logger_name = "linkahead::entity"; /** * The property importance. @@ -165,7 +165,7 @@ public: } std::string result("[\n"); for (int i = 0; i < this->size();) { - CAOSDB_DEBUG_MESSAGE_STRING(this->wrapped->at(i), next); + LINKAHEAD_DEBUG_MESSAGE_STRING(this->wrapped->at(i), next); result += next; if (++i < this->size()) { result.replace(result.size() - 1, 1, ",\n"); @@ -242,8 +242,14 @@ protected: mutable std::map<int, T> cache; private: - class iterator : public std::iterator<std::output_iterator_tag, T> { + class iterator { public: + using iterator_category = std::output_iterator_tag; + using value_type = T; + using difference_type = std::ptrdiff_t; + using pointer = T *; + using reference = T &; + explicit iterator(const RepeatedPtrFieldWrapper<T, P> *instance, int index = 0); // TODO(henrik) add unit tests auto operator*() const -> T &; @@ -496,16 +502,16 @@ public: */ inline Property(const Property &other) : Property(ProtoMessageWrapper<ProtoProperty>::CopyProtoMessage(other.wrapped)) { - CAOSDB_LOG_TRACE(logger_name) << "Property::Property(const Property &) " - << "- Copy constructor"; + LINKAHEAD_LOG_TRACE(logger_name) << "Property::Property(const Property &) " + << "- Copy constructor"; }; /** * Move constructor. */ inline Property(Property &&other) : Property(other.wrapped) { - CAOSDB_LOG_TRACE(logger_name) << "Property::Property(Property &&) " - << "- Move constructor"; + LINKAHEAD_LOG_TRACE(logger_name) << "Property::Property(Property &&) " + << "- Move constructor"; other.wrapped = nullptr; other.data_type.wrapped = nullptr; other.value.wrapped = nullptr; @@ -606,8 +612,8 @@ public: * Copy assignment operator. */ auto operator=(const Property &other) -> Property & { - CAOSDB_LOG_TRACE(logger_name) << "Property::operator=(const Property &) " - << "- Copy assignment operator"; + LINKAHEAD_LOG_TRACE(logger_name) << "Property::operator=(const Property &) " + << "- Copy assignment operator"; this->wrapped->CopyFrom(*other.wrapped); this->value.wrapped = (this->wrapped->has_value() ? this->wrapped->mutable_value() @@ -622,8 +628,8 @@ public: * Move assignment operator. */ auto operator=(Property &&other) -> Property & { - CAOSDB_LOG_TRACE(logger_name) << "Property::operator=(Property &&) " - << "- Move assignment operator"; + LINKAHEAD_LOG_TRACE(logger_name) << "Property::operator=(Property &&) " + << "- Move assignment operator"; this->wrapped = other.wrapped; other.wrapped = nullptr; this->value = std::move(other.value); @@ -669,7 +675,7 @@ private: // class Entity /////////////////////////////////////////////////////////////// /** - * Entity is the central and basic data object of CaosDB. + * Entity is the central and basic data object of LinkAhead. * * This class is a wrapper of the Entity class auto-generated by protobuf * (henceforth "ProtoEntity"). @@ -874,21 +880,21 @@ public: inline auto SetLocalPath(const std::filesystem::path &local_path) noexcept -> StatusCode { if (GetRole() != Role::FILE) { - CAOSDB_LOG_WARN(logger_name) << "Entity::SetLocalPath failed. This is not a file entity."; + LINKAHEAD_LOG_WARN(logger_name) << "Entity::SetLocalPath failed. This is not a file entity."; return StatusCode::NOT_A_FILE_ENTITY; } if (!exists(local_path)) { - CAOSDB_LOG_WARN(logger_name) + LINKAHEAD_LOG_WARN(logger_name) << "Entity::SetLocalPath failed. This file does not exists: " << local_path.string(); return StatusCode::FILE_DOES_NOT_EXIST_LOCALLY; } if (is_directory(local_path)) { - CAOSDB_LOG_WARN(logger_name) + LINKAHEAD_LOG_WARN(logger_name) << "Entity::SetLocalPath failed. This file is a directory: " << local_path.string(); return StatusCode::PATH_IS_A_DIRECTORY; } - CAOSDB_LOG_TRACE(logger_name) << "Entity::SetLocalPath(" << local_path.string() << ");"; + LINKAHEAD_LOG_TRACE(logger_name) << "Entity::SetLocalPath(" << local_path.string() << ");"; this->file_descriptor.local_path = local_path; return StatusCode::SUCCESS; } @@ -925,5 +931,5 @@ private: DataType data_type; }; -} // namespace caosdb::entity +} // namespace linkahead::entity #endif diff --git a/include/caosdb/exceptions.h b/include/linkahead/exceptions.h similarity index 87% rename from include/caosdb/exceptions.h rename to include/linkahead/exceptions.h index 415d0722580e1199f014358f524caf75f9d68b32..2fad1e194e34d623f50470d6302a38050d214b1e 100644 --- a/include/caosdb/exceptions.h +++ b/include/linkahead/exceptions.h @@ -1,8 +1,8 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -19,18 +19,18 @@ * */ -#ifndef CAOSDB_EXCEPTIONS_H -#define CAOSDB_EXCEPTIONS_H -#include "caosdb/status_code.h" +#ifndef LINKAHEAD_EXCEPTIONS_H +#define LINKAHEAD_EXCEPTIONS_H +#include "linkahead/status_code.h" #include <stdexcept> #include <string> -namespace caosdb::exceptions { -using caosdb::StatusCode; +namespace linkahead::exceptions { +using linkahead::StatusCode; using std::runtime_error; /** - * @brief Generic exception class of the caosdb client library. + * @brief Generic exception class of the linkahead client library. */ class Exception : public runtime_error { public: @@ -52,7 +52,7 @@ public: }; /** - * @brief The connection to the CaosDB server is down. + * @brief The connection to the LinkAhead server is down. */ class ConnectionError : public Exception { public: @@ -109,5 +109,5 @@ public: : Exception(StatusCode::CONNECTION_CONFIGURATION_ERROR, what_arg) {} }; -} // namespace caosdb::exceptions +} // namespace linkahead::exceptions #endif diff --git a/include/caosdb/file_descriptor.h b/include/linkahead/file_descriptor.h similarity index 83% rename from include/caosdb/file_descriptor.h rename to include/linkahead/file_descriptor.h index c6d6784c6cc73632dfdd871720c241a59ab03079..84a1fd1560fb228eab03ee1e68c558719c8fca99 100644 --- a/include/caosdb/file_descriptor.h +++ b/include/linkahead/file_descriptor.h @@ -1,5 +1,5 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * * Copyright (C) 2022 Timm Fitschen <t.fitschen@indiscale.com> * Copyright (C) 2022 IndiScale GmbH <info@indiscale.com> @@ -21,18 +21,18 @@ /** * @brief File descriptors are used to represent directories, links and files - * of the caosdb file system and their meta data. - * @file caosdb/entity.h + * of the linkahead file system and their meta data. + * @file linkahead/entity.h * @author Timm Fitchen * @date 2022-01-21 */ -#ifndef CAOSDB_FILE_DESCRIPTOR_H -#define CAOSDB_FILE_DESCRIPTOR_H +#ifndef LINKAHEAD_FILE_DESCRIPTOR_H +#define LINKAHEAD_FILE_DESCRIPTOR_H #include "caosdb/entity/v1/main.pb.h" // for RepeatedPtrField #include <filesystem> // for path -namespace caosdb::entity { +namespace linkahead::entity { using ProtoFileDescriptor = caosdb::entity::v1::FileDescriptor; using caosdb::entity::v1::FileTransmissionId; @@ -42,5 +42,5 @@ struct FileDescriptor { std::filesystem::path local_path; }; -} // namespace caosdb::entity +} // namespace linkahead::entity #endif diff --git a/include/caosdb/file_transmission/download_request_handler.h b/include/linkahead/file_transmission/download_request_handler.h similarity index 73% rename from include/caosdb/file_transmission/download_request_handler.h rename to include/linkahead/file_transmission/download_request_handler.h index 9c82b232bed9e0b702c38eeeeb762899a3071528..8419a0e3ab110a8fd0da272d3dbda16dc58cb52b 100644 --- a/include/caosdb/file_transmission/download_request_handler.h +++ b/include/linkahead/file_transmission/download_request_handler.h @@ -1,7 +1,7 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -46,28 +46,29 @@ * > FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * > DEALINGS IN THE SOFTWARE. */ -#ifndef CAOSDB_FILE_TRANSMISSION_DOWNLOAD_REQUEST_HANDLER_H -#define CAOSDB_FILE_TRANSMISSION_DOWNLOAD_REQUEST_HANDLER_H - -#include "caosdb/file_descriptor.h" // for FileDescriptor -#include "caosdb/entity/v1/main.grpc.pb.h" // for FileTransmissionS... -#include "caosdb/entity/v1/main.pb.h" // for FileDownloadResponse -#include "caosdb/file_transmission/file_writer.h" // for FileWriter -#include "caosdb/handler_interface.h" // for HandlerTag, Handl... -#include <cstdint> // for uint64_t -#include <grpcpp/client_context.h> // for ClientContext -#include <grpcpp/completion_queue.h> // for CompletionQueue -#include <grpcpp/support/async_stream.h> // for ClientAsyncReader -#include <grpcpp/support/status.h> // for Status -#include <memory> // for unique_ptr - -namespace caosdb::transaction { -using caosdb::entity::FileDescriptor; +#ifndef LINKAHEAD_FILE_TRANSMISSION_DOWNLOAD_REQUEST_HANDLER_H +#define LINKAHEAD_FILE_TRANSMISSION_DOWNLOAD_REQUEST_HANDLER_H + +#include <grpcpp/client_context.h> // for ClientContext +#include <grpcpp/completion_queue.h> // for CompletionQueue +#include <grpcpp/support/async_stream.h> // for ClientAsyncReader +#include <grpcpp/support/interceptor.h> // for InterceptionHoo... +#include <grpcpp/support/status.h> // for Status +#include <cstdint> // for uint64_t +#include <memory> // for unique_ptr +#include "caosdb/entity/v1/main.grpc.pb.h" // for FileTransmissio... +#include "caosdb/entity/v1/main.pb.h" // for FileDownloadRes... +#include "linkahead/file_descriptor.h" // for FileDescriptor +#include "linkahead/file_transmission/file_writer.h" // for FileWriter +#include "linkahead/handler_interface.h" // for HandlerTag, Han... + +namespace linkahead::transaction { using caosdb::entity::v1::FileDownloadRequest; using caosdb::entity::v1::FileDownloadResponse; using caosdb::entity::v1::FileTransmissionService; -using caosdb::transaction::HandlerInterface; -using caosdb::transaction::HandlerTag; +using linkahead::entity::FileDescriptor; +using linkahead::transaction::HandlerInterface; +using linkahead::transaction::HandlerTag; /* * Handler for the download request of a single file @@ -123,6 +124,6 @@ protected: uint64_t bytesReceived_; }; -} // namespace caosdb::transaction +} // namespace linkahead::transaction #endif diff --git a/include/caosdb/file_transmission/file_error.h b/include/linkahead/file_transmission/file_error.h similarity index 89% rename from include/caosdb/file_transmission/file_error.h rename to include/linkahead/file_transmission/file_error.h index ae057be3ba47f894f8fdbc22adb6e6d56accdafd..d3f32833986e6f9def1cd94ad442ea349eb6c8d5 100644 --- a/include/caosdb/file_transmission/file_error.h +++ b/include/linkahead/file_transmission/file_error.h @@ -1,7 +1,7 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -46,19 +46,19 @@ * > FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * > DEALINGS IN THE SOFTWARE. */ -#ifndef CAOSDB_FILE_TRANSMISSION_FILE_ERROR_H -#define CAOSDB_FILE_TRANSMISSION_FILE_ERROR_H +#ifndef LINKAHEAD_FILE_TRANSMISSION_FILE_ERROR_H +#define LINKAHEAD_FILE_TRANSMISSION_FILE_ERROR_H #include <stdexcept> #include <string> -namespace caosdb::transaction { +namespace linkahead::transaction { class FileIOError : public std::runtime_error { public: FileIOError(const std::string &message) : std::runtime_error(message) {} }; -} // namespace caosdb::transaction +} // namespace linkahead::transaction #endif diff --git a/include/caosdb/file_transmission/file_reader.h b/include/linkahead/file_transmission/file_reader.h similarity index 91% rename from include/caosdb/file_transmission/file_reader.h rename to include/linkahead/file_transmission/file_reader.h index 380b6a838b77e9f80f91f93c84eb0b0f888de2e0..510983a3b0cf44911d902152d3ad58b6884be3b7 100644 --- a/include/caosdb/file_transmission/file_reader.h +++ b/include/linkahead/file_transmission/file_reader.h @@ -1,7 +1,7 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -46,8 +46,8 @@ * > FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * > DEALINGS IN THE SOFTWARE. */ -#ifndef CAOSDB_FILE_TRANSMISSION_FILE_READER_H -#define CAOSDB_FILE_TRANSMISSION_FILE_READER_H +#ifndef LINKAHEAD_FILE_TRANSMISSION_FILE_READER_H +#define LINKAHEAD_FILE_TRANSMISSION_FILE_READER_H #include <cstddef> // for size_t #include <cstdint> // for uint64_t @@ -55,7 +55,7 @@ #include <fstream> // for ifstream #include <string> // for string -namespace caosdb::transaction { +namespace linkahead::transaction { using std::ifstream; using std::filesystem::exists; using std::filesystem::path; @@ -84,6 +84,6 @@ private: uint64_t size_; }; -} // namespace caosdb::transaction +} // namespace linkahead::transaction #endif diff --git a/include/caosdb/file_transmission/file_writer.h b/include/linkahead/file_transmission/file_writer.h similarity index 90% rename from include/caosdb/file_transmission/file_writer.h rename to include/linkahead/file_transmission/file_writer.h index 165178b1e3b44f9d3208220d1422af1bb61d0833..8e913b1710cfd5b636a10edea1a7d70a527256d3 100644 --- a/include/caosdb/file_transmission/file_writer.h +++ b/include/linkahead/file_transmission/file_writer.h @@ -1,7 +1,7 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -46,14 +46,14 @@ * > FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * > DEALINGS IN THE SOFTWARE. */ -#ifndef CAOSDB_FILE_TRANSMISSION_FILE_WRITER_H -#define CAOSDB_FILE_TRANSMISSION_FILE_WRITER_H +#ifndef LINKAHEAD_FILE_TRANSMISSION_FILE_WRITER_H +#define LINKAHEAD_FILE_TRANSMISSION_FILE_WRITER_H #include <filesystem> // for path #include <fstream> // for ofstream #include <string> // for string -namespace caosdb::transaction { +namespace linkahead::transaction { class FileWriter final { public: @@ -76,6 +76,6 @@ private: std::filesystem::path filename_; }; -} // namespace caosdb::transaction +} // namespace linkahead::transaction #endif diff --git a/include/caosdb/file_transmission/register_file_upload_handler.h b/include/linkahead/file_transmission/register_file_upload_handler.h similarity index 86% rename from include/caosdb/file_transmission/register_file_upload_handler.h rename to include/linkahead/file_transmission/register_file_upload_handler.h index 37cc6cf6ae83aa23781cc65924cefba83be22627..40f25d45c01c5058cbb6638c37634fbcad311e29 100644 --- a/include/caosdb/file_transmission/register_file_upload_handler.h +++ b/include/linkahead/file_transmission/register_file_upload_handler.h @@ -1,7 +1,7 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -46,18 +46,18 @@ * > FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * > DEALINGS IN THE SOFTWARE. */ -#ifndef CAOSDB_FILE_TRANSMISSION_REGISTER_FILE_UPLOAD_H -#define CAOSDB_FILE_TRANSMISSION_REGISTER_FILE_UPLOAD_H +#ifndef LINKAHEAD_FILE_TRANSMISSION_REGISTER_FILE_UPLOAD_H +#define LINKAHEAD_FILE_TRANSMISSION_REGISTER_FILE_UPLOAD_H -#include "caosdb/entity/v1/main.grpc.pb.h" // for FileTransmissionS... -#include "caosdb/entity/v1/main.pb.h" // for FileDownloadResponse -#include "caosdb/handler_interface.h" // for HandlerTag, Handl... -#include "caosdb/unary_rpc_handler.h" // for UnaryRpcHandler +#include "caosdb/entity/v1/main.pb.h" // for FileTransmissionS... +#include "caosdb/entity/v1/main.grpc.pb.h" // for FileDownloadResponse +#include "linkahead/handler_interface.h" // for HandlerTag, Handl... +#include "linkahead/unary_rpc_handler.h" // for UnaryRpcHandler #include <grpcpp/completion_queue.h> // for CompletionQueue #include <grpcpp/support/async_unary_call.h> // for ClientAsyncResponseReader #include <memory> // for unique_ptr -namespace caosdb::transaction { +namespace linkahead::transaction { using caosdb::entity::v1::FileTransmissionService; using caosdb::entity::v1::RegisterFileUploadRequest; @@ -90,6 +90,6 @@ protected: RegisterFileUploadResponse *response_; }; -} // namespace caosdb::transaction +} // namespace linkahead::transaction #endif diff --git a/include/caosdb/file_transmission/upload_request_handler.h b/include/linkahead/file_transmission/upload_request_handler.h similarity index 74% rename from include/caosdb/file_transmission/upload_request_handler.h rename to include/linkahead/file_transmission/upload_request_handler.h index f9d6aab9abf1800ab7e5ebece6f2f7011f86cca0..7218152364265b988b90249519beb226e8228421 100644 --- a/include/caosdb/file_transmission/upload_request_handler.h +++ b/include/linkahead/file_transmission/upload_request_handler.h @@ -1,7 +1,7 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -46,28 +46,28 @@ * > FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * > DEALINGS IN THE SOFTWARE. */ -#ifndef CAOSDB_FILE_TRANSMISSION_UPLOAD_REQUEST_HANDLER_H -#define CAOSDB_FILE_TRANSMISSION_UPLOAD_REQUEST_HANDLER_H - -#include "caosdb/entity/v1/main.grpc.pb.h" // for FileTransmissionS... -#include "caosdb/entity/v1/main.pb.h" // for FileUploadRequest -#include "caosdb/file_descriptor.h" // for FileDescriptor -#include "caosdb/file_transmission/file_reader.h" // for FileReader -#include "caosdb/handler_interface.h" // for HandlerTag, Handl... -#include <cstdint> // for uint64_t -#include <grpcpp/client_context.h> // for ClientContext -#include <grpcpp/completion_queue.h> // for CompletionQueue -#include <grpcpp/support/async_stream.h> // for ClientAsyncReader -#include <grpcpp/support/status.h> // for Status -#include <memory> // for unique_ptr - -namespace caosdb::transaction { -using caosdb::entity::FileDescriptor; +#ifndef LINKAHEAD_FILE_TRANSMISSION_UPLOAD_REQUEST_HANDLER_H +#define LINKAHEAD_FILE_TRANSMISSION_UPLOAD_REQUEST_HANDLER_H + +#include "caosdb/entity/v1/main.pb.h" // for FileTransmissionS... +#include "caosdb/entity/v1/main.grpc.pb.h" // for FileTransmissionS... +#include "linkahead/file_descriptor.h" // for FileDescriptor +#include "linkahead/file_transmission/file_reader.h" // for FileReader +#include "linkahead/handler_interface.h" // for HandlerTag, Handl... +#include <cstdint> // for uint64_t +#include <grpcpp/client_context.h> // for ClientContext +#include <grpcpp/completion_queue.h> // for CompletionQueue +#include <grpcpp/support/async_stream.h> // for ClientAsyncReader +#include <grpcpp/support/status.h> // for Status +#include <memory> // for unique_ptr + +namespace linkahead::transaction { using caosdb::entity::v1::FileTransmissionService; using caosdb::entity::v1::FileUploadRequest; using caosdb::entity::v1::FileUploadResponse; -using caosdb::transaction::HandlerInterface; -using caosdb::transaction::HandlerTag; +using linkahead::entity::FileDescriptor; +using linkahead::transaction::HandlerInterface; +using linkahead::transaction::HandlerTag; class UploadRequestHandler final : public HandlerInterface { public: @@ -121,6 +121,6 @@ protected: uint64_t bytesToSend_; }; -} // namespace caosdb::transaction +} // namespace linkahead::transaction #endif diff --git a/include/caosdb/handler_interface.h b/include/linkahead/handler_interface.h similarity index 88% rename from include/caosdb/handler_interface.h rename to include/linkahead/handler_interface.h index f5d77f86c35fe60edbd088afd235ed7ba633c69c..3ac97d04ddc356f97aca5febabeb512417cccbb4 100644 --- a/include/caosdb/handler_interface.h +++ b/include/linkahead/handler_interface.h @@ -1,7 +1,7 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -46,16 +46,16 @@ * > FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * > DEALINGS IN THE SOFTWARE. */ -#ifndef CAOSDB_HANDLER_INTERFACE_H -#define CAOSDB_HANDLER_INTERFACE_H +#ifndef LINKAHEAD_HANDLER_INTERFACE_H +#define LINKAHEAD_HANDLER_INTERFACE_H -#include "caosdb/transaction_status.h" // for TransactionStatus +#include "linkahead/transaction_status.h" // for TransactionStatus #include <memory> #include <string> -namespace caosdb::transaction { +namespace linkahead::transaction { -const static std::string logger_name = "caosdb::transaction"; +const static std::string logger_name = "linkahead::transaction"; /* * Baseclass for UnaryRpcHandler, DownloadRequestHandler and * UploadRequestHandler @@ -91,6 +91,6 @@ protected: using HandlerPtr = std::unique_ptr<HandlerInterface>; using HandlerTag = HandlerPtr *; -} // namespace caosdb::transaction +} // namespace linkahead::transaction #endif diff --git a/include/caosdb/info.h b/include/linkahead/info.h similarity index 83% rename from include/caosdb/info.h rename to include/linkahead/info.h index 0c4132f770d7bd68f10a74743246c0c037364f01..237564a7a6f61f01dd2de073542a13465911a585 100644 --- a/include/caosdb/info.h +++ b/include/linkahead/info.h @@ -1,8 +1,8 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -19,19 +19,19 @@ * */ -#ifndef CAOSDB_INFO_H -#define CAOSDB_INFO_H +#ifndef LINKAHEAD_INFO_H +#define LINKAHEAD_INFO_H /** - * @file caosdb/info.h + * @file linkahead/info.h * @author Timm Fitschen * @date 2021-07-02 - * @brief General information about the CaosDBServer. + * @brief General information about the LinkAheadServer. */ #include "caosdb/info/v1/main.pb.h" // for VersionInfo #include <cstdint> // for uint32_t #include <string> // for string -namespace caosdb::info { +namespace linkahead::info { using ProtoVersionInfo = caosdb::info::v1::VersionInfo; @@ -49,8 +49,8 @@ public: * Wrapp a Protobuf VersionInfo object. * * Don't instantiate this version info class. The constructor is only public - * for simpler testing. Create a CaosDBConnection and use - * CaosDBConnection::GetVersionInfo() instead to get the version of the + * for simpler testing. Create a LinkAheadConnection and use + * LinkAheadConnection::GetVersionInfo() instead to get the version of the * server behind the given connection. */ explicit inline VersionInfo(ProtoVersionInfo *info) : info(info){}; @@ -67,5 +67,5 @@ private: std::unique_ptr<ProtoVersionInfo> info; }; -} // namespace caosdb::info +} // namespace linkahead::info #endif diff --git a/include/caosdb/log_level.h b/include/linkahead/log_level.h similarity index 57% rename from include/caosdb/log_level.h rename to include/linkahead/log_level.h index c2fcb9b1181dcb86f91dfaf9a4ddecba3ea417cb..82c63a8f4b024ac8a1edfdc1e973cf08cdc47531 100644 --- a/include/caosdb/log_level.h +++ b/include/linkahead/log_level.h @@ -1,8 +1,8 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -19,20 +19,20 @@ * */ -#ifndef CAOSDB_LOG_LEVEL_H -#define CAOSDB_LOG_LEVEL_H +#ifndef LINKAHEAD_LOG_LEVEL_H +#define LINKAHEAD_LOG_LEVEL_H -#define CAOSDB_LOG_LEVEL_OFF 1000000 -#define CAOSDB_LOG_LEVEL_FATAL 700 -#define CAOSDB_LOG_LEVEL_ERROR 600 -#define CAOSDB_LOG_LEVEL_WARN 500 -#define CAOSDB_LOG_LEVEL_INFO 400 -#define CAOSDB_LOG_LEVEL_DEBUG 300 -#define CAOSDB_LOG_LEVEL_TRACE 200 -#define CAOSDB_LOG_LEVEL_ALL 0 +#define LINKAHEAD_LOG_LEVEL_OFF 1000000 +#define LINKAHEAD_LOG_LEVEL_FATAL 700 +#define LINKAHEAD_LOG_LEVEL_ERROR 600 +#define LINKAHEAD_LOG_LEVEL_WARN 500 +#define LINKAHEAD_LOG_LEVEL_INFO 400 +#define LINKAHEAD_LOG_LEVEL_DEBUG 300 +#define LINKAHEAD_LOG_LEVEL_TRACE 200 +#define LINKAHEAD_LOG_LEVEL_ALL 0 -#ifndef CAOSDB_DEFAULT_LOG_LEVEL -#define CAOSDB_DEFAULT_LOG_LEVEL CAOSDB_LOG_LEVEL_ERROR +#ifndef LINKAHEAD_DEFAULT_LOG_LEVEL +#define LINKAHEAD_DEFAULT_LOG_LEVEL LINKAHEAD_LOG_LEVEL_ERROR #endif #endif diff --git a/include/caosdb/logging.h b/include/linkahead/logging.h similarity index 70% rename from include/caosdb/logging.h rename to include/linkahead/logging.h index 3fda8e83ac5c164728b2cd156292d22952b70130..3b70c1a203178e383d8ba286749427c8fb811158 100644 --- a/include/caosdb/logging.h +++ b/include/linkahead/logging.h @@ -1,6 +1,6 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * * Copyright (C) 2021-2022 Timm Fitschen <t.fitschen@indiscale.com> * Copyright (C) 2021-2022 IndiScale GmbH <info@indiscale.com> @@ -20,19 +20,20 @@ * */ -#ifndef CAOSDB_LOGGING_H -#define CAOSDB_LOGGING_H +#ifndef LINKAHEAD_LOGGING_H +#define LINKAHEAD_LOGGING_H -#include "caosdb/log_level.h" // for CAOSDB_LOG_... -#include <cstdint> // for uint64_t -#include <iosfwd> // for streamsize -#include <memory> // for shared_ptr -#include <string> // for string -#include <vector> // for vector +#include "linkahead/log_level.h" // for LINKAHEAD_LOG_... +#include <cstdint> // for uint64_t +#include <iosfwd> // for streamsize +#include <memory> // for shared_ptr +#include <string> // for string +#include <vector> // for vector +#include <filesystem> // for path -namespace caosdb::logging { +namespace linkahead::logging { -const std::string logger_name = "caosdb::logging"; +const std::string logger_name = "linkahead::logging"; class LoggerOutputStream { public: @@ -46,6 +47,9 @@ public: auto operator<<(const char *msg) -> LoggerOutputStream &; auto operator<<(const std::string &msg) -> LoggerOutputStream &; auto operator<<(void *msg) -> LoggerOutputStream &; + auto operator<<(std::filesystem::path *path) -> LoggerOutputStream &; + auto operator<<(const std::filesystem::path &path) -> LoggerOutputStream &; + static auto get(const std::string &channel, int level) -> LoggerOutputStream { return LoggerOutputStream(channel, level); } @@ -60,17 +64,17 @@ private: * * Please Use the macro * - * CAOSDB_LOG_TRACE_ENTER_AND_LEAVE(logger_name, function_name); + * LINKAHEAD_LOG_TRACE_ENTER_AND_LEAVE(logger_name, function_name); */ class TraceEnterLeaveLogger { public: inline TraceEnterLeaveLogger(const std::string &channel, const std::string &function_name) : channel(channel), function_name(function_name) { - caosdb::logging::LoggerOutputStream::get(this->channel, CAOSDB_LOG_LEVEL_TRACE) + linkahead::logging::LoggerOutputStream::get(this->channel, LINKAHEAD_LOG_LEVEL_TRACE) << "Enter " << this->function_name; } inline ~TraceEnterLeaveLogger() { - caosdb::logging::LoggerOutputStream::get(this->channel, CAOSDB_LOG_LEVEL_TRACE) + linkahead::logging::LoggerOutputStream::get(this->channel, LINKAHEAD_LOG_LEVEL_TRACE) << "Leave " << this->function_name; } @@ -199,49 +203,50 @@ private: /** * Convenience function for the C interface. */ -void caosdb_log_fatal(const char *channel, const char *msg); +void linkahead_log_fatal(const char *channel, const char *msg); /** * Convenience function for the C interface. */ -void caosdb_log_error(const char *channel, const char *msg); +void linkahead_log_error(const char *channel, const char *msg); /** * Convenience function for the C interface. */ -void caosdb_log_warn(const char *channel, const char *msg); +void linkahead_log_warn(const char *channel, const char *msg); /** * Convenience function for the C interface. */ -void caosdb_log_info(const char *channel, const char *msg); +void linkahead_log_info(const char *channel, const char *msg); /** * Convenience function for the C interface. */ -void caosdb_log_debug(const char *channel, const char *msg); +void linkahead_log_debug(const char *channel, const char *msg); /** * Convenience function for the C interface. */ -void caosdb_log_trace(const char *channel, const char *msg); - -} // namespace caosdb::logging - -#define CAOSDB_LOG_FATAL(Channel) \ - caosdb::logging::LoggerOutputStream::get(Channel, CAOSDB_LOG_LEVEL_FATAL) -#define CAOSDB_LOG_ERROR(Channel) \ - caosdb::logging::LoggerOutputStream::get(Channel, CAOSDB_LOG_LEVEL_ERROR) -#define CAOSDB_LOG_WARN(Channel) \ - caosdb::logging::LoggerOutputStream::get(Channel, CAOSDB_LOG_LEVEL_WARN) -#define CAOSDB_LOG_INFO(Channel) \ - caosdb::logging::LoggerOutputStream::get(Channel, CAOSDB_LOG_LEVEL_INFO) -#define CAOSDB_LOG_DEBUG(Channel) \ - caosdb::logging::LoggerOutputStream::get(Channel, CAOSDB_LOG_LEVEL_DEBUG) -#define CAOSDB_LOG_TRACE(Channel) \ - caosdb::logging::LoggerOutputStream::get(Channel, CAOSDB_LOG_LEVEL_TRACE) - -#define CAOSDB_LOG_TRACE_ENTER_AND_LEAVE(Channel, FunctionName) \ - const caosdb::logging::TraceEnterLeaveLogger trace_enter_leave_logger(Channel, FunctionName); - -#define CAOSDB_LOG_ERROR_AND_RETURN_STATUS(Channel, StatusCode, Message) \ - CAOSDB_LOG_ERROR(Channel) << "StatusCode (" << StatusCode << ") " \ - << caosdb::get_status_description(StatusCode) << ": " << Message; \ +void linkahead_log_trace(const char *channel, const char *msg); + +} // namespace linkahead::logging + +#define LINKAHEAD_LOG_FATAL(Channel) \ + linkahead::logging::LoggerOutputStream::get(Channel, LINKAHEAD_LOG_LEVEL_FATAL) +#define LINKAHEAD_LOG_ERROR(Channel) \ + linkahead::logging::LoggerOutputStream::get(Channel, LINKAHEAD_LOG_LEVEL_ERROR) +#define LINKAHEAD_LOG_WARN(Channel) \ + linkahead::logging::LoggerOutputStream::get(Channel, LINKAHEAD_LOG_LEVEL_WARN) +#define LINKAHEAD_LOG_INFO(Channel) \ + linkahead::logging::LoggerOutputStream::get(Channel, LINKAHEAD_LOG_LEVEL_INFO) +#define LINKAHEAD_LOG_DEBUG(Channel) \ + linkahead::logging::LoggerOutputStream::get(Channel, LINKAHEAD_LOG_LEVEL_DEBUG) +#define LINKAHEAD_LOG_TRACE(Channel) \ + linkahead::logging::LoggerOutputStream::get(Channel, LINKAHEAD_LOG_LEVEL_TRACE) + +#define LINKAHEAD_LOG_TRACE_ENTER_AND_LEAVE(Channel, FunctionName) \ + const linkahead::logging::TraceEnterLeaveLogger trace_enter_leave_logger(Channel, FunctionName); + +#define LINKAHEAD_LOG_ERROR_AND_RETURN_STATUS(Channel, StatusCode, Message) \ + LINKAHEAD_LOG_ERROR(Channel) << "StatusCode (" << StatusCode << ") " \ + << linkahead::get_status_description(StatusCode) << ": " \ + << Message; \ return StatusCode; #endif diff --git a/include/caosdb/message_code.h b/include/linkahead/message_code.h similarity index 96% rename from include/caosdb/message_code.h rename to include/linkahead/message_code.h index ce539c188eabfa0d20762eac9fbe1083185286ea..0103d40b6cbddbc1a5ed2d6f843bc9efa781c9b7 100644 --- a/include/caosdb/message_code.h +++ b/include/linkahead/message_code.h @@ -1,8 +1,8 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -19,15 +19,15 @@ * */ -#ifndef CAOSDB_MESSAGE_CODE_H -#define CAOSDB_MESSAGE_CODE_H +#ifndef LINKAHEAD_MESSAGE_CODE_H +#define LINKAHEAD_MESSAGE_CODE_H #include "caosdb/entity/v1/main.pb.h" // for Entity, RepeatedField /** * MessageCodes for entity messages. * - * In contrast to the status codes, the message codes are part of the CaosDB + * In contrast to the status codes, the message codes are part of the LinkAhead * API. Messages (and their codes) represent the state of the entities in a * transaction or the server. * @@ -36,7 +36,7 @@ * https://gitlab.indiscale.com/caosdb/src/caosdb-proto. */ -namespace caosdb::entity { +namespace linkahead::entity { #define _MAP_MESSAGE_CODE(name) name = caosdb::entity::v1::MessageCode::MESSAGE_CODE_##name @@ -174,5 +174,5 @@ enum MessageCode { return MessageCode::UNKNOWN; } -} // namespace caosdb::entity +} // namespace linkahead::entity #endif diff --git a/include/caosdb/protobuf_helper.h b/include/linkahead/protobuf_helper.h similarity index 90% rename from include/caosdb/protobuf_helper.h rename to include/linkahead/protobuf_helper.h index ef4cb8383eb384cd058a3f210c9d27f99b199658..3df96fd3eb9157aa1049e862670c6343d6c1b560 100644 --- a/include/caosdb/protobuf_helper.h +++ b/include/linkahead/protobuf_helper.h @@ -1,8 +1,8 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -19,15 +19,15 @@ * */ -#ifndef CAOSDB_PROTOBUF_HELPER_H -#define CAOSDB_PROTOBUF_HELPER_H +#ifndef LINKAHEAD_PROTOBUF_HELPER_H +#define LINKAHEAD_PROTOBUF_HELPER_H // IWYU pragma: no_include <google/protobuf/extension_set.h> #include <google/protobuf/arena.h> // for Arena #include <google/protobuf/util/json_util.h> // for JsonOptions, MessageToJs... #include <string> // for string -#define CAOSDB_DEBUG_MESSAGE_STRING(message, out) \ +#define LINKAHEAD_DEBUG_MESSAGE_STRING(message, out) \ std::string out; \ { \ google::protobuf::util::JsonOptions options; \ @@ -35,7 +35,7 @@ google::protobuf::util::MessageToJsonString(message, &out, options); \ } -namespace caosdb::utility { +namespace linkahead::utility { using google::protobuf::Arena; @@ -104,10 +104,10 @@ public: if (this->wrapped == nullptr) { return "{}\n"; } - CAOSDB_DEBUG_MESSAGE_STRING(*this->wrapped, out) + LINKAHEAD_DEBUG_MESSAGE_STRING(*this->wrapped, out) return out; } }; -} // namespace caosdb::utility +} // namespace linkahead::utility #endif diff --git a/include/caosdb/result_set.h b/include/linkahead/result_set.h similarity index 79% rename from include/caosdb/result_set.h rename to include/linkahead/result_set.h index 2ce70e67e770a93e86512c564954ea57d10046eb..d8181fd0c4fe686d529afe7f075f126c20beb1f2 100644 --- a/include/caosdb/result_set.h +++ b/include/linkahead/result_set.h @@ -1,5 +1,5 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * * Copyright (C) 2022 Timm Fitschen <t.fitschen@indiscale.com> * Copyright (C) 2022 IndiScale GmbH <info@indiscale.com> @@ -18,19 +18,19 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ -#ifndef CAOSDB_RESULT_SET_H -#define CAOSDB_RESULT_SET_H +#ifndef LINKAHEAD_RESULT_SET_H +#define LINKAHEAD_RESULT_SET_H -#include "caosdb/entity.h" // for Entity, FileDe... -#include <algorithm> // for max -#include <iterator> // for iterator, next -#include <memory> // for unique_ptr -#include <utility> // for move -#include <vector> // for vector +#include <iosfwd> // for ptrdiff_t +#include <iterator> // for output_iterator_tag +#include <memory> // for unique_ptr, make_unique +#include <utility> // for move +#include <vector> // for vector +#include "linkahead/entity.h" // for Entity // IWYU pragma: no_include <ext/alloc_traits.h> -namespace caosdb::transaction { -using caosdb::entity::Entity; +namespace linkahead::transaction { +using linkahead::entity::Entity; /** * Abstract base class for the results of a Transaction. @@ -40,7 +40,7 @@ class ResultSet { public: virtual ~ResultSet() = default; - [[nodiscard]] virtual auto size() const noexcept -> int = 0; + [[nodiscard]] virtual auto size() const noexcept -> size_t = 0; [[nodiscard]] virtual auto at(const int index) const -> const Entity & = 0; [[nodiscard]] virtual auto mutable_at(int index) const -> Entity * = 0; /** @@ -56,8 +56,14 @@ public: auto end() const -> iterator; private: - class iterator : public std::iterator<std::output_iterator_tag, Entity> { + class iterator { public: + using iterator_category = std::output_iterator_tag; + using value_type = Entity; + using difference_type = std::ptrdiff_t; + using pointer = Entity *; + using reference = Entity &; + explicit iterator(const ResultSet *result_set, int index = 0); auto operator*() const -> const Entity &; auto operator++() -> iterator &; @@ -85,7 +91,7 @@ public: virtual ~AbstractMultiResultSet() = default; inline explicit AbstractMultiResultSet(std::vector<std::unique_ptr<Entity>> result_set) : items(std::move(result_set)) {} - [[nodiscard]] inline auto size() const noexcept -> int override { return this->items.size(); } + [[nodiscard]] inline auto size() const noexcept -> size_t override { return this->items.size(); } [[nodiscard]] inline auto at(const int index) const -> const Entity & override { return *(this->items.at(index)); } @@ -121,5 +127,5 @@ public: explicit MultiResultSet(std::vector<std::unique_ptr<Entity>> result_set); }; -} // namespace caosdb::transaction +} // namespace linkahead::transaction #endif diff --git a/include/caosdb/result_table.h b/include/linkahead/result_table.h similarity index 76% rename from include/caosdb/result_table.h rename to include/linkahead/result_table.h index 6795e27e5b60a680c1700d9fa98bcdd50b059474..c6a122973391f491b121bf75bb179c63d955407c 100644 --- a/include/caosdb/result_table.h +++ b/include/linkahead/result_table.h @@ -1,5 +1,5 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * * Copyright (C) 2022 Timm Fitschen <t.fitschen@indiscale.com> * Copyright (C) 2022 IndiScale GmbH <info@indiscale.com> @@ -18,16 +18,17 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ -#ifndef CAOSDB_RESULT_TABLE_H -#define CAOSDB_RESULT_TABLE_H +#ifndef LINKAHEAD_RESULT_TABLE_H +#define LINKAHEAD_RESULT_TABLE_H -#include "caosdb/value.h" // for Value -#include <iterator> // for iterator, next -#include <memory> // for unique_ptr -#include <string> // for string +#include <iosfwd> // for ptrdiff_t +#include <iterator> // for output_iterator_tag +#include <memory> // for unique_ptr +#include <string> // for string +#include "linkahead/value.h" // for Value -namespace caosdb::transaction { -using caosdb::entity::Value; +namespace linkahead::transaction { +using linkahead::entity::Value; class ResultTableImpl; @@ -82,8 +83,14 @@ public: friend class ResultTableImpl; private: - class HeaderIterator : std::iterator<std::output_iterator_tag, ResultTableColumn> { + class HeaderIterator { public: + using iterator_category = std::output_iterator_tag; + using value_type = ResultTableColumn; + using difference_type = std::ptrdiff_t; + using pointer = ResultTableColumn *; + using reference = ResultTableColumn &; + explicit HeaderIterator(const ResultTable *result_table, int index = 0); HeaderIterator(const HeaderIterator &other); auto operator*() const -> const ResultTableColumn &; @@ -99,8 +106,14 @@ private: const ResultTable *result_table; }; - class RowIterator : std::iterator<std::output_iterator_tag, ResultTableRow> { + class RowIterator { public: + using iterator_category = std::output_iterator_tag; + using value_type = linkahead::transaction::ResultTableRow; + using difference_type = std::ptrdiff_t; + using pointer = value_type *; + using reference = value_type &; + explicit RowIterator(const ResultTable *result_table, int index = 0); RowIterator(const RowIterator &other); auto operator*() const -> const ResultTableRow &; @@ -120,5 +133,5 @@ private: std::unique_ptr<ResultTableImpl> delegate; }; -} // namespace caosdb::transaction +} // namespace linkahead::transaction #endif diff --git a/include/caosdb/status_code.h b/include/linkahead/status_code.h similarity index 93% rename from include/caosdb/status_code.h rename to include/linkahead/status_code.h index 41dad5bddd918ac5cc42e577798676bcf8b6bea4..4dc5f80e1d94e0bf8c737effb4507175108c04b4 100644 --- a/include/caosdb/status_code.h +++ b/include/linkahead/status_code.h @@ -1,8 +1,8 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -19,13 +19,13 @@ * */ -#ifndef CAOSDB_STATUS_CODE_H -#define CAOSDB_STATUS_CODE_H +#ifndef LINKAHEAD_STATUS_CODE_H +#define LINKAHEAD_STATUS_CODE_H #include <grpcpp/impl/codegen/status_code_enum.h> // for StatusCode #include <string> // for string -namespace caosdb { +namespace linkahead { /** * StatusCodes represent the status of this client, it's connections, @@ -82,5 +82,5 @@ enum StatusCode { auto get_status_description(int code) -> const std::string &; -} // namespace caosdb +} // namespace linkahead #endif diff --git a/include/caosdb/transaction.h b/include/linkahead/transaction.h similarity index 90% rename from include/caosdb/transaction.h rename to include/linkahead/transaction.h index b1d3bee8f740b1bcbb62c5f8fe924a937cbdf36c..84e7829edf61a071328e7e7824367a00c2cee9c8 100644 --- a/include/caosdb/transaction.h +++ b/include/linkahead/transaction.h @@ -1,8 +1,8 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -18,32 +18,30 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ -#ifndef CAOSDB_TRANSACTION_H -#define CAOSDB_TRANSACTION_H - -#include "caosdb/entity.h" // for Entity, FileDe... -#include "caosdb/entity/v1/main.grpc.pb.h" // for EntityTransact... -#include "caosdb/entity/v1/main.pb.h" // for MultiTransacti... -#include "caosdb/file_descriptor.h" // for FileDescriptor -#include "caosdb/handler_interface.h" // for HandlerInterface -#include "caosdb/transaction_handler.h" // for EntityTransactionHandler -#include "caosdb/logging.h" // for CAOSDB_LOG_ERR... -#include "caosdb/protobuf_helper.h" // for get_arena -#include "caosdb/status_code.h" // for StatusCode -#include "caosdb/result_set.h" // for ResultSet -#include "caosdb/result_table.h" // for ResultTable -#include "caosdb/transaction_status.h" // for StatusCode -#include "caosdb/value.h" // for Value -#include <future> // for async, future -#include <google/protobuf/arena.h> // for Arena -#include <google/protobuf/util/json_util.h> // for MessageToJsonS... +#ifndef LINKAHEAD_TRANSACTION_H +#define LINKAHEAD_TRANSACTION_H + +#include <google/protobuf/util/json_util.h> // for JsonPrintOptions, Messag... #include <grpcpp/completion_queue.h> // for CompletionQueue -#include <iterator> // for iterator, next +#include <future> // for future +#include <iterator> // for next #include <map> // for map -#include <memory> // for unique_ptr +#include <memory> // for unique_ptr, shared_ptr #include <mutex> // for mutex -#include <string> // for string +#include <string> // for string, basic_string #include <vector> // for vector +#include "caosdb/entity/v1/main.grpc.pb.h" // for EntityTransactionService +#include "caosdb/entity/v1/main.pb.h" // for MultiTransactionRequest +#include "linkahead/entity.h" // for Entity +#include "linkahead/file_descriptor.h" // for FileDescriptor +#include "linkahead/handler_interface.h" // for logger_name, HandlerInte... +#include "linkahead/logging.h" // for LINKAHEAD_LOG_ERROR_AND_... +#include "linkahead/protobuf_helper.h" // for get_arena +#include "linkahead/result_set.h" // for MultiResultSet, ResultSet +#include "linkahead/result_table.h" // for ResultTable +#include "linkahead/status_code.h" // for StatusCode +#include "linkahead/transaction_status.h" // for StatusCode, TransactionS... +#include "linkahead/value.h" // for Value /** * Do all necessary checks and assure that another retrieval (by id or by @@ -63,7 +61,7 @@ case TransactionType::MIXED_READ_AND_WRITE: \ break; \ default: \ - CAOSDB_LOG_ERROR_AND_RETURN_STATUS( \ + LINKAHEAD_LOG_ERROR_AND_RETURN_STATUS( \ logger_name, StatusCode::TRANSACTION_TYPE_ERROR, \ "You cannot add a retrieval to this transaction because it has the " \ "wrong TransactionType.") \ @@ -76,7 +74,7 @@ #define ASSERT_CAN_ADD_QUERY \ ASSERT_CAN_ADD_RETRIEVAL \ if (this->has_query) { \ - CAOSDB_LOG_ERROR_AND_RETURN_STATUS( \ + LINKAHEAD_LOG_ERROR_AND_RETURN_STATUS( \ logger_name, StatusCode::UNSUPPORTED_FEATURE, \ "Currently the number of queries which can be processed in a single " \ "transaction is limitted to one."); \ @@ -99,7 +97,7 @@ case TransactionType::MIXED_READ_AND_WRITE: \ break; \ default: \ - CAOSDB_LOG_ERROR_AND_RETURN_STATUS( \ + LINKAHEAD_LOG_ERROR_AND_RETURN_STATUS( \ logger_name, StatusCode::TRANSACTION_TYPE_ERROR, \ "You cannot add a deletion to this transaction because it has the " \ "wrong TransactionType.") \ @@ -122,7 +120,7 @@ case TransactionType::MIXED_READ_AND_WRITE: \ break; \ default: \ - CAOSDB_LOG_ERROR_AND_RETURN_STATUS( \ + LINKAHEAD_LOG_ERROR_AND_RETURN_STATUS( \ logger_name, StatusCode::TRANSACTION_TYPE_ERROR, \ "You cannot add an insertion to this transaction because it has the " \ "wrong TransactionType.") \ @@ -145,13 +143,13 @@ case TransactionType::MIXED_READ_AND_WRITE: \ break; \ default: \ - CAOSDB_LOG_ERROR_AND_RETURN_STATUS( \ + LINKAHEAD_LOG_ERROR_AND_RETURN_STATUS( \ logger_name, StatusCode::TRANSACTION_TYPE_ERROR, \ "You cannot add an update to this transaction because it has the " \ "wrong TransactionType.") \ } \ if (!entity->HasId()) { \ - CAOSDB_LOG_ERROR_AND_RETURN_STATUS( \ + LINKAHEAD_LOG_ERROR_AND_RETURN_STATUS( \ logger_name, StatusCode::ORIGINAL_ENTITY_MISSING_ID, \ "You cannot update this entity without any id. Probably you did not " \ "retrieve it first? Entity updates should always start with the " \ @@ -163,10 +161,7 @@ * @author Timm Fitschen * @date 2021-08-05 */ -namespace caosdb::transaction { -using caosdb::entity::Entity; -using caosdb::entity::FileDescriptor; -using caosdb::entity::Value; +namespace linkahead::transaction { using caosdb::entity::v1::EntityResponse; using caosdb::entity::v1::EntityTransactionService; using caosdb::entity::v1::FileDownloadRequest; @@ -180,16 +175,19 @@ using caosdb::entity::v1::MultiTransactionRequest; using caosdb::entity::v1::MultiTransactionResponse; using caosdb::entity::v1::RegisterFileUploadRequest; using caosdb::entity::v1::RegisterFileUploadResponse; -using caosdb::transaction::TransactionStatus; +using linkahead::entity::Entity; +using linkahead::entity::FileDescriptor; +using linkahead::entity::Value; +using linkahead::transaction::TransactionStatus; using RetrieveResponse = caosdb::entity::v1::RetrieveResponse; using TransactionResponseCase = caosdb::entity::v1::TransactionResponse::TransactionResponseCase; -using caosdb::utility::get_arena; using google::protobuf::Arena; +using linkahead::utility::get_arena; class Transaction; /** - * @brief Create a transaction via `CaosDBConnection.createTransaction()` + * @brief Create a transaction via `LinkAheadConnection.createTransaction()` */ class Transaction { public: @@ -317,7 +315,7 @@ public: */ [[nodiscard]] inline auto GetResultSet() const noexcept -> const ResultSet & { if (this->GetStatus().GetCode() < 0) { - CAOSDB_LOG_ERROR(logger_name) + LINKAHEAD_LOG_ERROR(logger_name) << "GetResultSet was called before the transaction has terminated. This is a programming " "error of the code which uses the transaction."; // TODO(tf) This is a really bad SegFault factory. When the transaction @@ -325,7 +323,7 @@ public: // created here will be deleted and any client of the return ResultSet // will have a SegFault. } else if (this->GetStatus().GetCode() == StatusCode::SPOILED) { - CAOSDB_LOG_ERROR(logger_name) + LINKAHEAD_LOG_ERROR(logger_name) << "GetResultSet was called on a \"spoiled\" transaction. That means " "that the result set has already been released via " "ReleaseResultSet(). This is a programming error of the code which " @@ -339,11 +337,11 @@ public: */ [[nodiscard]] inline auto GetResultTable() const noexcept -> const ResultTable & { if (this->GetStatus().GetCode() < 0) { - CAOSDB_LOG_ERROR(logger_name) + LINKAHEAD_LOG_ERROR(logger_name) << "GetResultTable was called before the transaction has terminated. This is a programming " "error of the code which uses the transaction."; } else if (this->GetStatus().GetCode() == StatusCode::SPOILED) { - CAOSDB_LOG_ERROR(logger_name) + LINKAHEAD_LOG_ERROR(logger_name) << "GetResultTable was called on a \"spoiled\" transaction. That means " "that the result table has already been released via " "ReleaseResultTable(). This is a programming error of the code which " @@ -439,7 +437,7 @@ protected: * Return the Arena where this transaction may create Message instances. * * Currently, this implementation is only a call to - * caosdb::utility::get_arena(), but in the future we might want to have a + * linkahead::utility::get_arena(), but in the future we might want to have a * smarter memory management. */ inline auto GetArena() const -> Arena * { return get_arena(); } @@ -496,5 +494,5 @@ inline auto Transaction::RetrieveById(InputIterator begin, InputIterator end) no return this->status.GetCode(); } -} // namespace caosdb::transaction +} // namespace linkahead::transaction #endif diff --git a/include/caosdb/transaction_handler.h b/include/linkahead/transaction_handler.h similarity index 80% rename from include/caosdb/transaction_handler.h rename to include/linkahead/transaction_handler.h index 3f9fc811a2137d9b8c8d0205c15704179a1c3554..eb22c1447858b89d55a22f8b36b5162fa7998e66 100644 --- a/include/caosdb/transaction_handler.h +++ b/include/linkahead/transaction_handler.h @@ -1,13 +1,13 @@ #pragma once -#include "caosdb/entity/v1/main.grpc.pb.h" // for FileTransmissionS... -#include "caosdb/entity/v1/main.pb.h" // for FileDownloadResponse -#include "caosdb/handler_interface.h" // for HandlerTag -#include "caosdb/unary_rpc_handler.h" // for HandlerTag, Handl... +#include "caosdb/entity/v1/main.pb.h" // for FileTransmissionS... +#include "caosdb/entity/v1/main.grpc.pb.h" // for FileDownloadResponse +#include "linkahead/handler_interface.h" // for HandlerTag +#include "linkahead/unary_rpc_handler.h" // for HandlerTag, Handl... #include <grpcpp/completion_queue.h> // for CompletionQueue #include <grpcpp/support/async_unary_call.h> // for ClientAsyncResponseReader #include <memory> // for unique_ptr -namespace caosdb::transaction { +namespace linkahead::transaction { using caosdb::entity::v1::EntityTransactionService; using caosdb::entity::v1::MultiTransactionRequest; @@ -39,4 +39,4 @@ protected: MultiTransactionResponse *response_; }; -} // namespace caosdb::transaction +} // namespace linkahead::transaction diff --git a/include/caosdb/transaction_status.h b/include/linkahead/transaction_status.h similarity index 73% rename from include/caosdb/transaction_status.h rename to include/linkahead/transaction_status.h index d46f3911aa17fbf518fd43b91e3568e4e4740c2f..6ef62a95c8484d02d60ca08636bead78d3c96544 100644 --- a/include/caosdb/transaction_status.h +++ b/include/linkahead/transaction_status.h @@ -1,8 +1,8 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -19,30 +19,30 @@ * */ -#ifndef CAOSDB_TRANSACTION_STATUS_H -#define CAOSDB_TRANSACTION_STATUS_H +#ifndef LINKAHEAD_TRANSACTION_STATUS_H +#define LINKAHEAD_TRANSACTION_STATUS_H -#include "caosdb/status_code.h" -#include "caosdb/exceptions.h" +#include "linkahead/status_code.h" +#include "linkahead/exceptions.h" #include <memory> // for shared_ptr, unique_ptr #include <string> // for string -namespace caosdb::transaction { -using caosdb::StatusCode; -using caosdb::exceptions::AuthenticationError; -using caosdb::exceptions::ConnectionError; -using caosdb::exceptions::Exception; -using caosdb::exceptions::TransactionError; -using caosdb::exceptions::TransactionStatusError; -using caosdb::exceptions::TransactionTypeError; +namespace linkahead::transaction { +using linkahead::StatusCode; +using linkahead::exceptions::AuthenticationError; +using linkahead::exceptions::ConnectionError; +using linkahead::exceptions::Exception; +using linkahead::exceptions::TransactionError; +using linkahead::exceptions::TransactionStatusError; +using linkahead::exceptions::TransactionTypeError; /** * Define static factory method in the TransactionStatus class. */ -#define CAOSDB_TRANSACTION_STATUS_DEFAULT_FACTORY(_StatusName, _StatusCode) \ +#define LINKAHEAD_TRANSACTION_STATUS_DEFAULT_FACTORY(_StatusName, _StatusCode) \ inline static auto _StatusName()->const TransactionStatus & { \ static const TransactionStatus instance(_StatusCode, \ - caosdb::get_status_description(_StatusCode)); \ + linkahead::get_status_description(_StatusCode)); \ return instance; \ } @@ -62,7 +62,7 @@ public: * This status means that the transaction has not been executed yet and the * transaction does not contain any sub-transactions yet. */ - CAOSDB_TRANSACTION_STATUS_DEFAULT_FACTORY(INITIAL, StatusCode::INITIAL) + LINKAHEAD_TRANSACTION_STATUS_DEFAULT_FACTORY(INITIAL, StatusCode::INITIAL) /** * Factory for a GO_ON status. * @@ -71,7 +71,7 @@ public: * * However, it also can be executed right now. */ - CAOSDB_TRANSACTION_STATUS_DEFAULT_FACTORY(GO_ON, StatusCode::GO_ON) + LINKAHEAD_TRANSACTION_STATUS_DEFAULT_FACTORY(GO_ON, StatusCode::GO_ON) /** * Factory for a READY status. * @@ -79,26 +79,26 @@ public: * ready to be executed and it is not possible anymore to add further * sub-transactions. */ - CAOSDB_TRANSACTION_STATUS_DEFAULT_FACTORY(READY, StatusCode::READY) + LINKAHEAD_TRANSACTION_STATUS_DEFAULT_FACTORY(READY, StatusCode::READY) /** * Factory for an EXECUTING status. * * This status means that the transaction is currently being executed. */ - CAOSDB_TRANSACTION_STATUS_DEFAULT_FACTORY(EXECUTING, StatusCode::EXECUTING) + LINKAHEAD_TRANSACTION_STATUS_DEFAULT_FACTORY(EXECUTING, StatusCode::EXECUTING) /** * Factory for a SUCCESS status. * * This status means that the transaction has been executed successfully. */ - CAOSDB_TRANSACTION_STATUS_DEFAULT_FACTORY(SUCCESS, StatusCode::SUCCESS) + LINKAHEAD_TRANSACTION_STATUS_DEFAULT_FACTORY(SUCCESS, StatusCode::SUCCESS) /** * Factory for a CANCELLED status. * * This status means that the transaction has been canceled and should not be * used anymore. */ - CAOSDB_TRANSACTION_STATUS_DEFAULT_FACTORY(CANCELLED, StatusCode::CANCELLED) + LINKAHEAD_TRANSACTION_STATUS_DEFAULT_FACTORY(CANCELLED, StatusCode::CANCELLED) /** * Factory for a CONNECTION_ERROR status. * @@ -106,20 +106,21 @@ public: * possibly due to misconfiguration of the client, errors in the network or * because the server is down. */ - CAOSDB_TRANSACTION_STATUS_DEFAULT_FACTORY(CONNECTION_ERROR, StatusCode::CONNECTION_ERROR) + LINKAHEAD_TRANSACTION_STATUS_DEFAULT_FACTORY(CONNECTION_ERROR, StatusCode::CONNECTION_ERROR) /** * Factory for an AUTHENTICATION_ERROR status. * * This status means that the RPC layer reported an authentication error. */ - CAOSDB_TRANSACTION_STATUS_DEFAULT_FACTORY(AUTHENTICATION_ERROR, StatusCode::AUTHENTICATION_ERROR) + LINKAHEAD_TRANSACTION_STATUS_DEFAULT_FACTORY(AUTHENTICATION_ERROR, + StatusCode::AUTHENTICATION_ERROR) /** * Another factory for an TRANSACTION_ERROR Status with a detailed * description. */ inline static auto AUTHENTICATION_ERROR(const std::string &details) -> const TransactionStatus { return TransactionStatus(StatusCode::AUTHENTICATION_ERROR, - caosdb::get_status_description(StatusCode::AUTHENTICATION_ERROR) + + linkahead::get_status_description(StatusCode::AUTHENTICATION_ERROR) + " Original error: " + details); } /** @@ -128,22 +129,23 @@ public: * This status means that the transaction failed during the upload of the * file blobs of file entities. */ - CAOSDB_TRANSACTION_STATUS_DEFAULT_FACTORY(FILE_UPLOAD_ERROR, StatusCode::FILE_UPLOAD_ERROR); + LINKAHEAD_TRANSACTION_STATUS_DEFAULT_FACTORY(FILE_UPLOAD_ERROR, StatusCode::FILE_UPLOAD_ERROR); /** * Factory for a FILE_DOWN_ERROR status. * * This status means that the transaction failed during the download of the * file blobs of file entities. */ - CAOSDB_TRANSACTION_STATUS_DEFAULT_FACTORY(FILE_DOWNLOAD_ERROR, StatusCode::FILE_DOWNLOAD_ERROR); + LINKAHEAD_TRANSACTION_STATUS_DEFAULT_FACTORY(FILE_DOWNLOAD_ERROR, + StatusCode::FILE_DOWNLOAD_ERROR); /** * Factory for a TRANSACTION_ERROR status. * * This status means that the transaction failed due to errors thrown by the * server. */ - CAOSDB_TRANSACTION_STATUS_DEFAULT_FACTORY(TRANSACTION_ERROR, - StatusCode::GENERIC_TRANSACTION_ERROR) + LINKAHEAD_TRANSACTION_STATUS_DEFAULT_FACTORY(TRANSACTION_ERROR, + StatusCode::GENERIC_TRANSACTION_ERROR) /** * Factory for a SPOILED status. * @@ -151,15 +153,16 @@ public: * GetResultSet() will not return the actual results of the transaction * anymore. */ - CAOSDB_TRANSACTION_STATUS_DEFAULT_FACTORY(SPOILED, StatusCode::SPOILED); + LINKAHEAD_TRANSACTION_STATUS_DEFAULT_FACTORY(SPOILED, StatusCode::SPOILED); /** * Another factory for a TRANSACTION_ERROR status with a detailed * description. */ inline static auto TRANSACTION_ERROR(const std::string &details) -> const TransactionStatus { - return TransactionStatus(StatusCode::GENERIC_TRANSACTION_ERROR, - caosdb::get_status_description(StatusCode::GENERIC_TRANSACTION_ERROR) + - " Original error: " + details); + return TransactionStatus( + StatusCode::GENERIC_TRANSACTION_ERROR, + linkahead::get_status_description(StatusCode::GENERIC_TRANSACTION_ERROR) + + " Original error: " + details); } /** * Factory for a RPC_ERROR with a detailed description. @@ -171,7 +174,7 @@ public: // RPC_ERROR states with different error codes (which stem from GRPC) here // in the future. return TransactionStatus(StatusCode::GENERIC_RPC_ERROR, - caosdb::get_status_description(StatusCode::GENERIC_RPC_ERROR) + + linkahead::get_status_description(StatusCode::GENERIC_RPC_ERROR) + " Original error: " + details); } @@ -183,7 +186,7 @@ public: */ inline static auto GENERIC_ERROR(const std::string &details) { return TransactionStatus(StatusCode::GENERIC_ERROR, - caosdb::get_status_description(StatusCode::GENERIC_ERROR) + + linkahead::get_status_description(StatusCode::GENERIC_ERROR) + "Original error: " + details); } @@ -254,5 +257,5 @@ private: std::string description; }; -} // namespace caosdb::transaction +} // namespace linkahead::transaction #endif diff --git a/include/caosdb/unary_rpc_handler.h b/include/linkahead/unary_rpc_handler.h similarity index 83% rename from include/caosdb/unary_rpc_handler.h rename to include/linkahead/unary_rpc_handler.h index 06b9457ceae715b4319739f46d810d7a892612d7..4122c3f918ac0df97660f752b8539f4d5236ad83 100644 --- a/include/caosdb/unary_rpc_handler.h +++ b/include/linkahead/unary_rpc_handler.h @@ -1,7 +1,7 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -46,16 +46,16 @@ * > FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * > DEALINGS IN THE SOFTWARE. */ -#ifndef CAOSDB_UNARY_RPC_HANDLER_H -#define CAOSDB_UNARY_RPC_HANDLER_H +#ifndef LINKAHEAD_UNARY_RPC_HANDLER_H +#define LINKAHEAD_UNARY_RPC_HANDLER_H -#include "caosdb/handler_interface.h" // for HandlerTag, Handl... -#include "caosdb/transaction_status.h" // for TransactionStatus -#include <grpcpp/client_context.h> // for ClientContext -#include <grpcpp/completion_queue.h> // for CompletionQueue -#include <grpcpp/support/status.h> // for Status +#include "linkahead/handler_interface.h" // for HandlerTag, Handl... +#include "linkahead/transaction_status.h" // for TransactionStatus +#include <grpcpp/client_context.h> // for ClientContext +#include <grpcpp/completion_queue.h> // for CompletionQueue +#include <grpcpp/support/status.h> // for Status -namespace caosdb::transaction { +namespace linkahead::transaction { class UnaryRpcHandler : public HandlerInterface { public: @@ -85,6 +85,6 @@ protected: grpc::Status status_; }; -} // namespace caosdb::transaction +} // namespace linkahead::transaction #endif diff --git a/include/caosdb/utility.h b/include/linkahead/utility.h similarity index 71% rename from include/caosdb/utility.h rename to include/linkahead/utility.h index 13e3dfeb99dc5415a733d5b6dcea852705b1662d..1b739d7e9f0a919df2501c6e8a0fb981407447be 100644 --- a/include/caosdb/utility.h +++ b/include/linkahead/utility.h @@ -1,8 +1,8 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -19,50 +19,53 @@ * */ -#ifndef CAOSDB_UTILS_H -#define CAOSDB_UTILS_H -#include "caosdb/data_type.h" // for AtomicDataType -#include "caosdb/entity.h" // for Importance, Role -#include <cstdlib> // for getenv -#include <filesystem> // for path -#include <fstream> // for basic_istream<>::__ist... -#include <memory> // for shared_ptr -#include <string> // for string, operator+, cha... - -namespace caosdb::utility { +#ifndef LINKAHEAD_UTILS_H +#define LINKAHEAD_UTILS_H +#include "linkahead/data_type.h" // for AtomicDataType +#include "linkahead/entity.h" // for Importance, Role +#include <cstdlib> // for getenv +#include <filesystem> // for path +#include <fstream> // for basic_istream<>::__ist... +#include <memory> // for shared_ptr +#include <string> // for string, operator+, cha... + +namespace linkahead::utility { using std::ifstream; using std::filesystem::exists; using std::filesystem::path; /** - * @brief Get the name of the enum value. May be useful for higher-order CaosDB clients. + * @brief Get the name of the enum value. May be useful for higher-order LinkAhead clients. */ template <typename Enum> auto getEnumNameFromValue(Enum v) -> std::string; // Forward declaration of specializations template <> -auto getEnumNameFromValue<caosdb::entity::AtomicDataType>(caosdb::entity::AtomicDataType v) +auto getEnumNameFromValue<linkahead::entity::AtomicDataType>(linkahead::entity::AtomicDataType v) -> std::string; template <> -auto getEnumNameFromValue<caosdb::entity::Importance>(caosdb::entity::Importance v) -> std::string; -template <> auto getEnumNameFromValue<caosdb::entity::Role>(caosdb::entity::Role v) -> std::string; +auto getEnumNameFromValue<linkahead::entity::Importance>(linkahead::entity::Importance v) + -> std::string; +template <> +auto getEnumNameFromValue<linkahead::entity::Role>(linkahead::entity::Role v) -> std::string; /** * @brief Get the enum value from a string. * - * @detail May be useful for higher-order CaosDB clients and only makes sense if specialized. + * @detail May be useful for higher-order LinkAhead clients and only makes sense if specialized. */ template <typename Enum> auto getEnumValueFromName(const std::string &name) -> Enum; // Forward declaration of specializations template <> -auto getEnumValueFromName<caosdb::entity::AtomicDataType>(const std::string &name) - -> caosdb::entity::AtomicDataType; +auto getEnumValueFromName<linkahead::entity::AtomicDataType>(const std::string &name) + -> linkahead::entity::AtomicDataType; template <> -auto getEnumValueFromName<caosdb::entity::Importance>(const std::string &name) - -> caosdb::entity::Importance; +auto getEnumValueFromName<linkahead::entity::Importance>(const std::string &name) + -> linkahead::entity::Importance; template <> -auto getEnumValueFromName<caosdb::entity::Role>(const std::string &name) -> caosdb::entity::Role; +auto getEnumValueFromName<linkahead::entity::Role>(const std::string &name) + -> linkahead::entity::Role; /** * @brief Read a text file into a string and return the file's content. @@ -172,10 +175,14 @@ auto load_json_file(const path &json_file) -> JsonValue; auto base64_encode(const std::string &plain) -> std::string; inline auto get_home_directory() -> const path { +#if defined(_WIN32) + const auto *const home = getenv("USERPROFILE"); +#else const auto *const home = getenv("HOME"); - // TODO(tf) Add windowsy way of determining the home directory +#endif + return home; } -} // namespace caosdb::utility +} // namespace linkahead::utility #endif diff --git a/include/caosdb/value.h b/include/linkahead/value.h similarity index 90% rename from include/caosdb/value.h rename to include/linkahead/value.h index cffb11162b9ed8b83508316c155f1fca46be2714..78407a3f418a44e26d8f6ee50e751437e072bae2 100644 --- a/include/caosdb/value.h +++ b/include/linkahead/value.h @@ -1,8 +1,8 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -19,16 +19,16 @@ * */ -#ifndef CAOSDB_VALUE_H -#define CAOSDB_VALUE_H -#include "caosdb/protobuf_helper.h" // for ProtoMessageWrapper -#include "caosdb/entity/v1/main.pb.h" // for RepeatedPtrField, Message -#include <cstdint> // for int64_t -#include <google/protobuf/arena.h> // for Arena -#include <memory> // for unique_ptr -#include <string> // for string, operator== -#include <utility> // for move -#include <vector> // for vector +#ifndef LINKAHEAD_VALUE_H +#define LINKAHEAD_VALUE_H +#include "linkahead/protobuf_helper.h" // for ProtoMessageWrapper +#include "caosdb/entity/v1/main.pb.h" // for RepeatedPtrField, Message +#include <cstdint> // for int64_t +#include <google/protobuf/arena.h> // for Arena +#include <memory> // for unique_ptr +#include <string> // for string, operator== +#include <utility> // for move +#include <vector> // for vector #define LIST_VALUE_CONSTRUCTOR(TYPE, SETTER) \ explicit inline Value(const std::vector<TYPE> &values) \ @@ -36,13 +36,17 @@ for (const auto &value : values) { \ this->wrapped->mutable_list_values()->add_values()->SETTER(value); \ } \ + if (values.empty()) { \ + this->wrapped->mutable_list_values()->add_values()->set_special_value( \ + ProtoSpecialValue::SPECIAL_VALUE_UNSPECIFIED); \ + } \ } -namespace caosdb::entity { -using caosdb::utility::get_arena; -using caosdb::utility::ProtoMessageWrapper; -using caosdb::utility::ScalarProtoMessageWrapper; +namespace linkahead::entity { using google::protobuf::Arena; +using linkahead::utility::get_arena; +using linkahead::utility::ProtoMessageWrapper; +using linkahead::utility::ScalarProtoMessageWrapper; using ProtoSpecialValue = caosdb::entity::v1::SpecialValue; using ProtoValue = caosdb::entity::v1::Value; using ProtoScalarValue = caosdb::entity::v1::ScalarValue; @@ -62,7 +66,7 @@ public: */ virtual ~AbstractValue() = 0; /** - * Return true iff the value is a NULL value (NULL in the CaosDB sense). + * Return true iff the value is a NULL value (NULL in the LinkAhead sense). */ [[nodiscard]] virtual auto IsNull() const noexcept -> bool = 0; /** @@ -385,7 +389,9 @@ public: return !IsNull() && this->wrapped->value_case() == ValueCase::kListValues; } [[nodiscard]] inline auto GetAsVector() const noexcept -> const std::vector<ScalarValue> & { - if (!IsVector()) { + if (!IsVector() || (this->wrapped->list_values().values(0).has_special_value() && + this->wrapped->list_values().values(0).special_value() == + ProtoSpecialValue::SPECIAL_VALUE_UNSPECIFIED)) { // create empty list static std::vector<ScalarValue> empty_values; return empty_values; @@ -435,6 +441,6 @@ private: mutable std::unique_ptr<std::vector<ScalarValue>> collection_values; }; -} // namespace caosdb::entity +} // namespace linkahead::entity #endif diff --git a/caosdb-client-configuration-schema.json b/linkahead-client-configuration-schema.json similarity index 96% rename from caosdb-client-configuration-schema.json rename to linkahead-client-configuration-schema.json index ff1967f639400d26bd33714691f416f10c841cae..d7aa7cbd9d8b4448ad8d11c7ebabbb0598080c10 100644 --- a/caosdb-client-configuration-schema.json +++ b/linkahead-client-configuration-schema.json @@ -1,7 +1,7 @@ { "$schema": "http://json-schema.org/draft-07/schema#", - "title": "CaosDB Client Configuration", - "description": "Configuration of the connection, logging, and other things of a CaosDB client.", + "title": "LinkAhead Client Configuration", + "description": "Configuration of the connection, logging, and other things of a LinkAhead client.", "type": "object", "additionalProperties": false, "properties": { @@ -117,11 +117,11 @@ "type": "string", "description": "Domain name or ip address of the server host.", "default": "localhost", - "examples": ["localhost", "caosdb.example.com", "192.168.0.123"] + "examples": ["localhost", "linkahead.example.com", "192.168.0.123"] }, "port": { "type": "integer", - "description": "Ip port of the grpc end-point of the CaosDB server.", + "description": "Ip port of the grpc end-point of the LinkAhead server.", "mininum": 1, "default": 8443, "maximum": 65535 diff --git a/linkaheadConfig.cmake b/linkaheadConfig.cmake new file mode 100644 index 0000000000000000000000000000000000000000..50f4d45613d02ee1df742c313831e56b9b6d1499 --- /dev/null +++ b/linkaheadConfig.cmake @@ -0,0 +1,11 @@ +get_filename_component(LINKAHEAD_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) + +include(CMakeFindDependencyMacro) + +find_dependency(Threads REQUIRED) +find_dependency(Protobuf CONFIG REQUIRED) +find_dependency(gRPC CONFIG REQUIRED) + +if(NOT TARGET linkahead::linkahead) + include("${LINKAHEAD_CMAKE_DIR}/linkaheadTargets.cmake") +endif() diff --git a/make.ps1 b/make.ps1 new file mode 100644 index 0000000000000000000000000000000000000000..5bbadaf9aba2a89d66e65ec234d0bc9627d66cbb --- /dev/null +++ b/make.ps1 @@ -0,0 +1,93 @@ +param ( + [string]$target +) + +$buildType = "Release" +$cppStd=17 + +function Install-Conan { + Write-Output "Installing Release dependencies with Conan..." + # check if conan is available + if (-not (Get-Command conan -ErrorAction SilentlyContinue)) { + Write-Output "Conan is not available. Please install Conan or activate the Conan environment venv" + exit 1 + } + conan install . --build=missing -s build_type=$buildType -s compiler.cppstd=$cppStd + cmake --preset conan-default +} + +function Invoke-Build { + Write-Output "Building the project..." + # check if msbuild is available + if (-not (Get-Command msbuild -ErrorAction SilentlyContinue)) { + Write-Output "msbuild is not available. Please install Visual Studio or open the Developer PowerShell." + exit 1 + } + # check if conan install was run + if (-not (Test-Path .\build\liblinkahead.sln)) { + Write-Output "Please run conan-install first." + exit 1 + } + msbuild .\build\liblinkahead.sln /property:Configuration=$buildType +} + +function Invoke-Tests { + Write-Output "Running tests..." + # check if build was run before + if (-not (Test-Path .\build\Release\linkahead.dll)) { + Write-Output "Please build the project first." + exit 1 + } + Set-Location .\build\ + ctest + Set-Location ..\ +} + +function Invoke-Create { + Write-Output "Creating Conan package..." + conan create . +} + +# check if vswhere is available +if (-not (Test-Path "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe")) { + Write-Output "vswhere is not available. Please install Visual Studio" + exit 1 +} + +# locate the latest Visual Studio installation +$currentPath = Get-Location +$installPath = &"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -latest -products * -requires Microsoft.Component.MSBuild -property installationPath +Import-Module (Join-Path $installPath "Common7\Tools\Microsoft.VisualStudio.DevShell.dll") +Enter-VsDevShell -VsInstallPath $installPath +Set-Location $currentPath + + +# Windows is with Release only for now + +switch ($target) { + "build" { + Invoke-Build + } + "test" { + Invoke-Tests + } + "conan-install" { + Install-Conan + } + "conan-create" { + Invoke-Create + } + "clean"{ + Write-Output "Cleaning the project..." + Remove-Item -Recurse -Force .\build\* + } + "all" { + Install-Conan + Invoke-Build + Invoke-Tests + Invoke-Create + } + default { + Write-Output "Usage: .\make.ps1 [all|conan-install|conan-create|build|test|clean]" + } +} diff --git a/requirements.txt b/requirements.txt index b0410ad5624768205f16743a17bef2d9e34ead66..beee199161c222749b8c113e78d52069cfdff852 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,22 +1,17 @@ -bottle==0.12.23 -certifi==2022.9.24 -charset-normalizer==2.1.1 +certifi==2024.6.2 +charset-normalizer==3.3.2 colorama==0.4.6 -conan==1.61.0 -distro==1.7.0 -fasteners==0.18 -future==0.18.2 -idna==3.4 -Jinja2==3.1.2 -MarkupSafe==2.1.1 -node-semver==0.6.1 +packaging==24.1 +setuptools==71.0.4 +conan==2.5.0 +distro==1.8.0 +fasteners==0.19 +idna==3.7 +Jinja2==3.1.4 +MarkupSafe==2.1.5 patch-ng==1.17.4 -pluginbase==1.0.1 -Pygments==2.13.0 -PyJWT==2.6.0 -python-dateutil==2.8.2 -PyYAML==6.0 -requests==2.28.1 +python-dateutil==2.9.0.post0 +PyYAML==6.0.1 +requests==2.32.3 six==1.16.0 -tqdm==4.64.1 -urllib3==1.26.12 +urllib3==1.26.18 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 939a85ba1f0492a6d985d4f873f2560adb22f039..cdc2fa4189fdc11fbcb4565893ccf441153ed71a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,8 +1,8 @@ # -# This file is a part of the CaosDB Project. +# This file is a part of the LinkAhead Project. # # Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> -# Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> +# Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -20,33 +20,33 @@ # add all source files to this list -set(libcaosdb_SRC - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/authentication.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/entity.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/logging.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/connection.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/configuration.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/protobuf_helper.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/result_set.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/result_table.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/result_table_impl.h - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/transaction.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/transaction_handler.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/utility.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/unary_rpc_handler.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/file_transmission/register_file_upload_handler.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/file_transmission/upload_request_handler.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/file_transmission/download_request_handler.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/file_transmission/file_writer.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/file_transmission/file_reader.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/status_code_description.cpp +set(liblinkahead_SRC + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/authentication.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/entity.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/logging.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/connection.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/configuration.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/protobuf_helper.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/result_set.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/result_table.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/result_table_impl.h + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/transaction.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/transaction_handler.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/utility.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/unary_rpc_handler.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/file_transmission/register_file_upload_handler.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/file_transmission/upload_request_handler.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/file_transmission/download_request_handler.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/file_transmission/file_writer.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/file_transmission/file_reader.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/status_code_description.cpp ) IF(BUILD_ACM) - list(APPEND libcaosdb_SRC - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/acm/user.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/caosdb/acm/user_impl.h + list(APPEND liblinkahead_SRC + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/acm/user.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/linkahead/acm/user_impl.h ) ENDIF() # pass variable to parent scope -set(libcaosdb_SRC ${libcaosdb_SRC} PARENT_SCOPE) +set(liblinkahead_SRC ${liblinkahead_SRC} PARENT_SCOPE) diff --git a/src/ccaosdbcli.c b/src/ccaosdbcli.c deleted file mode 100644 index e3ce7dea431441b5ef6f827f02f8741681f631c2..0000000000000000000000000000000000000000 --- a/src/ccaosdbcli.c +++ /dev/null @@ -1,28 +0,0 @@ -#include "caosdb/constants.h" // for LIBCAOSDB_VERSION_MAJOR, LIBCAOSDB_VER... -#include "ccaosdb.h" // for caosdb_info_version_info, caosdb_conne... -#include <stdio.h> // for printf - -int main(void) { - int status = 0; // last function return value - printf("CaosDB C client (libcaosdb %d.%d.%d)\nWe don't miss the H of caos.\n\n", - LIBCAOSDB_VERSION_MAJOR, LIBCAOSDB_VERSION_MINOR, LIBCAOSDB_VERSION_PATCH); - - caosdb_connection_connection connection; - status = caosdb_connection_connection_manager_get_default_connection(&connection); - if (status != 0) { - printf("An error occured: ERROR %d - %s\n", status, caosdb_get_status_description(status)); - return status; - } - - caosdb_info_version_info version_info; - status = caosdb_connection_get_version_info(&version_info, &connection); - if (status != 0) { - printf("An error occured: ERROR %d - %s\n", status, caosdb_get_status_description(status)); - return status; - } - - printf("Server version: %d.%d.%d-%s-%s\n", version_info.major, version_info.minor, - version_info.patch, version_info.pre_release, version_info.build); - - return 0; -} diff --git a/src/ccaosdb.cpp b/src/clinkahead.cpp similarity index 51% rename from src/ccaosdb.cpp rename to src/clinkahead.cpp index ae1a728f62b7cdfb293eb347d1a1966b86bfd3b2..624fbf567d0a514b95e3a689e3e4c679cb69f2f7 100644 --- a/src/ccaosdb.cpp +++ b/src/clinkahead.cpp @@ -1,8 +1,8 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> * Copyright (C) 2021 Florian Spreckelsen <f.spreckelsen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License @@ -19,15 +19,15 @@ * <https://www.gnu.org/licenses/>. * */ -#include "ccaosdb.h" -#include "caosdb/connection.h" -#include "caosdb/constants.h" -#include "caosdb/data_type.h" // for DataType, AtomicDat... -#include "caosdb/entity.h" -#include "caosdb/value.h" -#include "caosdb/utility.h" -#include "caosdb/status_code.h" -#include "caosdb/logging.h" +#include "clinkahead.h" +#include "linkahead/connection.h" +#include "linkahead/constants.h" +#include "linkahead/data_type.h" // for DataType, AtomicDat... +#include "linkahead/entity.h" +#include "linkahead/value.h" +#include "linkahead/utility.h" +#include "linkahead/status_code.h" +#include "linkahead/logging.h" #include <cassert> #include <cstring> #include <exception> @@ -38,25 +38,28 @@ extern "C" { -#define CCAOSDB_LOGGER_NAME "ccaosdb" +#define CLINKAHEAD_LOGGER_NAME "clinkahead" -#define WRAPPED_ENTITY_CAST(name) static_cast<caosdb::entity::Entity *>(name->wrapped_entity) +#define WRAPPED_ENTITY_CAST(name) static_cast<linkahead::entity::Entity *>(name->wrapped_entity) -#define WRAPPED_PROPERTY_CAST(name) static_cast<caosdb::entity::Property *>(name->wrapped_property) +#define WRAPPED_PROPERTY_CAST(name) \ + static_cast<linkahead::entity::Property *>(name->wrapped_property) -#define WRAPPED_PARENT_CAST(name) static_cast<caosdb::entity::Parent *>(name->wrapped_parent) +#define WRAPPED_PARENT_CAST(name) static_cast<linkahead::entity::Parent *>(name->wrapped_parent) -#define WRAPPED_MESSAGE_CAST(name) static_cast<caosdb::entity::Message *>(name->wrapped_message) +#define WRAPPED_MESSAGE_CAST(name) static_cast<linkahead::entity::Message *>(name->wrapped_message) -#define WRAPPED_DATATYPE_CAST(name) static_cast<caosdb::entity::DataType *>(name->wrapped_datatype) +#define WRAPPED_DATATYPE_CAST(name) \ + static_cast<linkahead::entity::DataType *>(name->wrapped_datatype) -#define WRAPPED_VALUE_CAST(name) static_cast<caosdb::entity::AbstractValue *>(name->wrapped_value) +#define WRAPPED_VALUE_CAST(name) \ + static_cast<linkahead::entity::AbstractValue *>(name->wrapped_value) #define ENUM_NAME_FROM_VALUE(arg, etype) \ - caosdb::utility::getEnumNameFromValue<caosdb::entity::etype>(arg) + linkahead::utility::getEnumNameFromValue<linkahead::entity::etype>(arg) #define ENUM_VALUE_FROM_NAME(arg, etype) \ - caosdb::utility::getEnumValueFromName<caosdb::entity::etype>(arg) + linkahead::utility::getEnumValueFromName<linkahead::entity::etype>(arg) /* * Macro for wrapping every function into a try-catch clause. If an exception @@ -64,26 +67,26 @@ extern "C" { */ #define ERROR_RETURN_CODE(code, fun, body) \ fun { \ - CAOSDB_LOG_TRACE(CCAOSDB_LOGGER_NAME) << "Enter " << #fun; \ + LINKAHEAD_LOG_TRACE(CLINKAHEAD_LOGGER_NAME) << "Enter " << #fun; \ try { \ body \ } catch (const std::exception &exc) { \ - caosdb::logging::caosdb_log_fatal(CCAOSDB_LOGGER_NAME, exc.what()); \ - return caosdb::StatusCode::code; \ + linkahead::logging::linkahead_log_fatal(CLINKAHEAD_LOGGER_NAME, exc.what()); \ + return linkahead::StatusCode::code; \ } \ } /** * Macro for entity getters */ -#define CAOSDB_ENTITY_GET(element, GetFunction) \ +#define LINKAHEAD_ENTITY_GET(element, GetFunction) \ ERROR_RETURN_CODE( \ GENERIC_ERROR, \ - int caosdb_entity_entity_get_##element(caosdb_entity_entity *entity, char **out), { \ + int linkahead_entity_entity_get_##element(linkahead_entity_entity *entity, char **out), { \ auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity); \ auto *tmp = (char *)malloc(sizeof(char) * wrapped_entity->GetFunction.length() + 1); \ strcpy(tmp, wrapped_entity->GetFunction.c_str()); \ - delete[] * out; \ + delete[] *out; \ *out = tmp; \ return 0; \ }) @@ -91,10 +94,11 @@ extern "C" { /** * Macro for entity setters */ -#define CAOSDB_ENTITY_SET(element, value, body_part) \ +#define LINKAHEAD_ENTITY_SET(element, value, body_part) \ ERROR_RETURN_CODE( \ GENERIC_ERROR, \ - int caosdb_entity_entity_set_##element(caosdb_entity_entity *entity, const char *value), { \ + int linkahead_entity_entity_set_##element(linkahead_entity_entity *entity, const char *value), \ + { \ auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity); \ body_part return 0; \ }) @@ -102,14 +106,15 @@ extern "C" { /** * Macro for property getters */ -#define CAOSDB_PROPERTY_GET(element, GetFunction) \ +#define LINKAHEAD_PROPERTY_GET(element, GetFunction) \ ERROR_RETURN_CODE( \ GENERIC_ERROR, \ - int caosdb_entity_property_get_##element(caosdb_entity_property *property, char **out), { \ + int linkahead_entity_property_get_##element(linkahead_entity_property *property, char **out), \ + { \ auto *wrapped_property = WRAPPED_PROPERTY_CAST(property); \ auto *tmp = (char *)malloc(sizeof(char) * wrapped_property->GetFunction.length() + 1); \ strcpy(tmp, wrapped_property->GetFunction.c_str()); \ - delete[] * out; \ + delete[] *out; \ *out = tmp; \ return 0; \ }) @@ -117,26 +122,26 @@ extern "C" { /** * Macro for property setters */ -#define CAOSDB_PROPERTY_SET(element, value, body_part) \ - ERROR_RETURN_CODE( \ - GENERIC_ERROR, \ - int caosdb_entity_property_set_##element(caosdb_entity_property *property, const char *value), \ - { \ - auto *wrapped_property = WRAPPED_PROPERTY_CAST(property); \ - body_part return 0; \ - }) +#define LINKAHEAD_PROPERTY_SET(element, value, body_part) \ + ERROR_RETURN_CODE(GENERIC_ERROR, \ + int linkahead_entity_property_set_##element( \ + linkahead_entity_property *property, const char *value), \ + { \ + auto *wrapped_property = WRAPPED_PROPERTY_CAST(property); \ + body_part return 0; \ + }) /** * Macro for parent getters */ -#define CAOSDB_PARENT_GET(element, GetFunction) \ +#define LINKAHEAD_PARENT_GET(element, GetFunction) \ ERROR_RETURN_CODE( \ GENERIC_ERROR, \ - int caosdb_entity_parent_get_##element(caosdb_entity_parent *parent, char **out), { \ + int linkahead_entity_parent_get_##element(linkahead_entity_parent *parent, char **out), { \ auto *wrapped_parent = WRAPPED_PARENT_CAST(parent); \ auto *tmp = (char *)malloc(sizeof(char) * wrapped_parent->GetFunction.length() + 1); \ strcpy(tmp, wrapped_parent->GetFunction.c_str()); \ - delete[] * out; \ + delete[] *out; \ *out = tmp; \ return 0; \ }) @@ -144,10 +149,11 @@ extern "C" { /** * Macro for parent setters */ -#define CAOSDB_PARENT_SET(element, value, body_part) \ +#define LINKAHEAD_PARENT_SET(element, value, body_part) \ ERROR_RETURN_CODE( \ GENERIC_ERROR, \ - int caosdb_entity_parent_set_##element(caosdb_entity_parent *parent, const char *value), { \ + int linkahead_entity_parent_set_##element(linkahead_entity_parent *parent, const char *value), \ + { \ auto *wrapped_parent = WRAPPED_PARENT_CAST(parent); \ body_part return 0; \ }) @@ -157,8 +163,8 @@ extern "C" { */ #define CREATE_VALUE(fname, arg) \ ERROR_RETURN_CODE(GENERIC_ERROR, \ - int caosdb_entity_create_##fname(caosdb_entity_value *out, arg), { \ - out->wrapped_value = new caosdb::entity::Value(value); \ + int linkahead_entity_create_##fname(linkahead_entity_value *out, arg), { \ + out->wrapped_value = new linkahead::entity::Value(value); \ out->_deletable = true; \ return 0; \ }) @@ -168,12 +174,12 @@ extern "C" { #define CREATE_VECTOR_VALUE(fname, type, arg, assign) \ ERROR_RETURN_CODE( \ GENERIC_ERROR, \ - int caosdb_entity_create_##fname(caosdb_entity_value *out, arg, const int length), { \ + int linkahead_entity_create_##fname(linkahead_entity_value *out, arg, const int length), { \ std::vector<type> value_vec; \ for (int i = 0; i < length; i++) { \ value_vec.push_back(assign); \ } \ - out->wrapped_value = new caosdb::entity::Value(value_vec); \ + out->wrapped_value = new linkahead::entity::Value(value_vec); \ out->_deletable = true; \ return 0; \ }) @@ -182,72 +188,80 @@ extern "C" { * Macro for value is-a functions */ #define VALUE_IS(fname, isfunction) \ - ERROR_RETURN_CODE(GENERIC_ERROR, \ - int caosdb_entity_value_is_##fname(caosdb_entity_value *value, bool *out), { \ - auto *wrapped_value = WRAPPED_VALUE_CAST(value); \ - *out = wrapped_value->isfunction(); \ - return 0; \ - }) + ERROR_RETURN_CODE( \ + GENERIC_ERROR, \ + int linkahead_entity_value_is_##fname(linkahead_entity_value *value, bool *out), { \ + auto *wrapped_value = WRAPPED_VALUE_CAST(value); \ + *out = wrapped_value->isfunction(); \ + return 0; \ + }) /** * Macro for some value getters */ #define VALUE_GET_AS(fname, getfunction, arg) \ ERROR_RETURN_CODE(GENERIC_ERROR, \ - int caosdb_entity_value_get_as_##fname(caosdb_entity_value *value, arg), { \ + int linkahead_entity_value_get_as_##fname(linkahead_entity_value *value, arg), \ + { \ auto *wrapped_value = WRAPPED_VALUE_CAST(value); \ *out = wrapped_value->getfunction(); \ return 0; \ }) -int caosdb_constants_LIBCAOSDB_VERSION_MAJOR() { return caosdb::LIBCAOSDB_VERSION_MAJOR; } +int linkahead_constants_LIBLINKAHEAD_VERSION_MAJOR() { + return linkahead::LIBLINKAHEAD_VERSION_MAJOR; +} -int caosdb_constants_LIBCAOSDB_VERSION_MINOR() { return caosdb::LIBCAOSDB_VERSION_MINOR; } +int linkahead_constants_LIBLINKAHEAD_VERSION_MINOR() { + return linkahead::LIBLINKAHEAD_VERSION_MINOR; +} -int caosdb_constants_LIBCAOSDB_VERSION_PATCH() { return caosdb::LIBCAOSDB_VERSION_PATCH; } +int linkahead_constants_LIBLINKAHEAD_VERSION_PATCH() { + return linkahead::LIBLINKAHEAD_VERSION_PATCH; +} -int caosdb_constants_COMPATIBLE_SERVER_VERSION_MAJOR() { - return caosdb::COMPATIBLE_SERVER_VERSION_MAJOR; +int linkahead_constants_COMPATIBLE_SERVER_VERSION_MAJOR() { + return linkahead::COMPATIBLE_SERVER_VERSION_MAJOR; } -int caosdb_constants_COMPATIBLE_SERVER_VERSION_MINOR() { - return caosdb::COMPATIBLE_SERVER_VERSION_MINOR; +int linkahead_constants_COMPATIBLE_SERVER_VERSION_MINOR() { + return linkahead::COMPATIBLE_SERVER_VERSION_MINOR; } -int caosdb_constants_COMPATIBLE_SERVER_VERSION_PATCH() { - return caosdb::COMPATIBLE_SERVER_VERSION_PATCH; +int linkahead_constants_COMPATIBLE_SERVER_VERSION_PATCH() { + return linkahead::COMPATIBLE_SERVER_VERSION_PATCH; } -const char *caosdb_constants_COMPATIBLE_SERVER_VERSION_PRE_RELEASE() { - return caosdb::COMPATIBLE_SERVER_VERSION_PRE_RELEASE; +const char *linkahead_constants_COMPATIBLE_SERVER_VERSION_PRE_RELEASE() { + return linkahead::COMPATIBLE_SERVER_VERSION_PRE_RELEASE; } -int caosdb_status_code_OTHER_CLIENT_ERROR() { return caosdb::StatusCode::OTHER_CLIENT_ERROR; } +int linkahead_status_code_OTHER_CLIENT_ERROR() { return linkahead::StatusCode::OTHER_CLIENT_ERROR; } -const char *caosdb_utility_get_env_fallback(const char *name, const char *fallback) { - return caosdb::utility::get_env_fallback(name, fallback); +const char *linkahead_utility_get_env_fallback(const char *name, const char *fallback) { + return linkahead::utility::get_env_fallback(name, fallback); } -const char *caosdb_get_status_description(int code) { - return caosdb::get_status_description(code).c_str(); +const char *linkahead_get_status_description(int code) { + return linkahead::get_status_description(code).c_str(); } ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_connection_create_pem_file_certificate_provider( - caosdb_connection_certificate_provider *out, const char *path), + int linkahead_connection_create_pem_file_certificate_provider( + linkahead_connection_certificate_provider *out, const char *path), { out->wrapped_certificate_provider = - new caosdb::configuration::PemFileCertificateProvider(std::string(path)); + new linkahead::configuration::PemFileCertificateProvider(std::string(path)); out->_deletable = true; return 0; }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_connection_delete_certificate_provider( - caosdb_connection_certificate_provider *provider), + int linkahead_connection_delete_certificate_provider( + linkahead_connection_certificate_provider *provider), { if (provider->_deletable && provider->wrapped_certificate_provider) { - delete static_cast<caosdb::configuration::CertificateProvider *>( + delete static_cast<linkahead::configuration::CertificateProvider *>( provider->wrapped_certificate_provider); } provider->wrapped_certificate_provider = nullptr; @@ -256,23 +270,23 @@ ERROR_RETURN_CODE(GENERIC_ERROR, }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_authentication_create_plain_password_authenticator( - caosdb_authentication_authenticator *out, const char *username, + int linkahead_authentication_create_plain_password_authenticator( + linkahead_authentication_authenticator *out, const char *username, const char *password), { out->wrapped_authenticator = - new caosdb::authentication::PlainPasswordAuthenticator(std::string(username), - std::string(password)); + new linkahead::authentication::PlainPasswordAuthenticator( + std::string(username), std::string(password)); out->_deletable = true; return 0; }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_authentication_delete_authenticator( - caosdb_authentication_authenticator *authenticator), + int linkahead_authentication_delete_authenticator( + linkahead_authentication_authenticator *authenticator), { if (authenticator->_deletable && authenticator->wrapped_authenticator) { - delete static_cast<caosdb::authentication::Authenticator *>( + delete static_cast<linkahead::authentication::Authenticator *>( authenticator->wrapped_authenticator); } authenticator->wrapped_authenticator = nullptr; @@ -282,55 +296,57 @@ ERROR_RETURN_CODE(GENERIC_ERROR, ERROR_RETURN_CODE( GENERIC_ERROR, - int caosdb_connection_create_tls_connection_configuration( - caosdb_connection_connection_configuration *out, const char *host, const int port, - caosdb_authentication_authenticator *authenticator, - caosdb_connection_certificate_provider *provider), + int linkahead_connection_create_tls_connection_configuration( + linkahead_connection_connection_configuration *out, const char *host, const int port, + linkahead_authentication_authenticator *authenticator, + linkahead_connection_certificate_provider *provider), { auto host_str = std::string(host); if (authenticator != nullptr && provider != nullptr) { - auto wrapped_provider = static_cast<caosdb::configuration::CertificateProvider *>( + auto wrapped_provider = static_cast<linkahead::configuration::CertificateProvider *>( provider->wrapped_certificate_provider); - auto wrapped_authenticator = - static_cast<caosdb::authentication::Authenticator *>(authenticator->wrapped_authenticator); - out->wrapped_connection_configuration = new caosdb::configuration::TlsConnectionConfiguration( - host_str, port, *wrapped_provider, *wrapped_authenticator); + auto wrapped_authenticator = static_cast<linkahead::authentication::Authenticator *>( + authenticator->wrapped_authenticator); + out->wrapped_connection_configuration = + new linkahead::configuration::TlsConnectionConfiguration(host_str, port, *wrapped_provider, + *wrapped_authenticator); } else if (authenticator != nullptr) { - auto wrapped_authenticator = - static_cast<caosdb::authentication::Authenticator *>(authenticator->wrapped_authenticator); - out->wrapped_connection_configuration = new caosdb::configuration::TlsConnectionConfiguration( - host_str, port, *wrapped_authenticator); + auto wrapped_authenticator = static_cast<linkahead::authentication::Authenticator *>( + authenticator->wrapped_authenticator); + out->wrapped_connection_configuration = + new linkahead::configuration::TlsConnectionConfiguration(host_str, port, + *wrapped_authenticator); } else if (provider != nullptr) { - auto wrapped_provider = static_cast<caosdb::configuration::CertificateProvider *>( + auto wrapped_provider = static_cast<linkahead::configuration::CertificateProvider *>( provider->wrapped_certificate_provider); out->wrapped_connection_configuration = - new caosdb::configuration::TlsConnectionConfiguration(host_str, port, *wrapped_provider); + new linkahead::configuration::TlsConnectionConfiguration(host_str, port, *wrapped_provider); } else { out->wrapped_connection_configuration = - new caosdb::configuration::TlsConnectionConfiguration(host_str, port); + new linkahead::configuration::TlsConnectionConfiguration(host_str, port); } out->_deletable = true; return 0; }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_connection_create_insecure_connection_configuration( - caosdb_connection_connection_configuration *out, const char *host, + int linkahead_connection_create_insecure_connection_configuration( + linkahead_connection_connection_configuration *out, const char *host, const int port), { out->wrapped_connection_configuration = - new caosdb::configuration::InsecureConnectionConfiguration(host, port); + new linkahead::configuration::InsecureConnectionConfiguration(host, port); out->_deletable = true; return 0; }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_connection_delete_connection_configuration( - caosdb_connection_connection_configuration *configuration), + int linkahead_connection_delete_connection_configuration( + linkahead_connection_connection_configuration *configuration), { if (configuration->_deletable && configuration->wrapped_connection_configuration) { - delete static_cast<caosdb::configuration::ConnectionConfiguration *>( + delete static_cast<linkahead::configuration::ConnectionConfiguration *>( configuration->wrapped_connection_configuration); } configuration->wrapped_connection_configuration = nullptr; @@ -339,37 +355,36 @@ ERROR_RETURN_CODE(GENERIC_ERROR, }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_connection_create_connection( - caosdb_connection_connection *out, - const caosdb_connection_connection_configuration *configuration), + int linkahead_connection_create_connection( + linkahead_connection_connection *out, + const linkahead_connection_connection_configuration *configuration), { - caosdb::configuration::ConnectionConfiguration *config = - static_cast<caosdb::configuration::ConnectionConfiguration *>( + linkahead::configuration::ConnectionConfiguration *config = + static_cast<linkahead::configuration::ConnectionConfiguration *>( configuration->wrapped_connection_configuration); - out->wrapped_connection = new caosdb::connection::Connection(*config); + out->wrapped_connection = new linkahead::connection::Connection(*config); out->_deletable = true; return 0; }) -ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_connection_delete_connection(caosdb_connection_connection *connection), - { - if (connection->_deletable && connection->wrapped_connection) { - delete static_cast<caosdb::connection::Connection *>( - connection->wrapped_connection); - } - connection->wrapped_connection = nullptr; - connection->_deletable = false; - return 0; - }) +ERROR_RETURN_CODE( + GENERIC_ERROR, + int linkahead_connection_delete_connection(linkahead_connection_connection *connection), { + if (connection->_deletable && connection->wrapped_connection) { + delete static_cast<linkahead::connection::Connection *>(connection->wrapped_connection); + } + connection->wrapped_connection = nullptr; + connection->_deletable = false; + return 0; + }) ERROR_RETURN_CODE( GENERIC_ERROR, - int caosdb_connection_get_version_info(caosdb_info_version_info *out, - const caosdb_connection_connection *connection), + int linkahead_connection_get_version_info(linkahead_info_version_info *out, + const linkahead_connection_connection *connection), { auto *wrapped_connection = - static_cast<caosdb::connection::Connection *>(connection->wrapped_connection); + static_cast<linkahead::connection::Connection *>(connection->wrapped_connection); auto status = wrapped_connection->RetrieveVersionInfoNoExceptions(); if (status.IsError()) { @@ -395,36 +410,38 @@ ERROR_RETURN_CODE( }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_connection_connection_manager_get_default_connection( - caosdb_connection_connection *out), + int linkahead_connection_connection_manager_get_default_connection( + linkahead_connection_connection *out), { out->wrapped_connection = - caosdb::connection::ConnectionManager::GetDefaultConnection().get(); + linkahead::connection::ConnectionManager::GetDefaultConnection().get(); out->_deletable = false; return 0; }) -ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_connection_connection_manager_get_connection( - caosdb_connection_connection *out, const char *name), - { - out->wrapped_connection = - caosdb::connection::ConnectionManager::GetConnection(std::string(name)).get(); - // managed by the connection manager now, so not - // to be deleted manually - out->_deletable = false; - return 0; - }) +ERROR_RETURN_CODE( + GENERIC_ERROR, + int linkahead_connection_connection_manager_get_connection(linkahead_connection_connection *out, + const char *name), + { + out->wrapped_connection = + linkahead::connection::ConnectionManager::GetConnection(std::string(name)).get(); + // managed by the connection manager now, so not + // to be deleted manually + out->_deletable = false; + return 0; + }) /**************************************************************************** * ENTITY STUFF AND TRANSACTIONS ****************************************************************************/ ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_connection_connection_create_transaction( - caosdb_connection_connection *connection, caosdb_transaction_transaction *out), + int linkahead_connection_connection_create_transaction( + linkahead_connection_connection *connection, + linkahead_transaction_transaction *out), { - auto *wrapped_connection = - static_cast<caosdb::connection::Connection *>(connection->wrapped_connection); + auto *wrapped_connection = static_cast<linkahead::connection::Connection *>( + connection->wrapped_connection); out->wrapped_transaction = wrapped_connection->CreateTransaction().release(); out->_deletable = true; return 0; @@ -432,9 +449,9 @@ ERROR_RETURN_CODE(GENERIC_ERROR, ERROR_RETURN_CODE( GENERIC_ERROR, - int caosdb_transaction_delete_transaction(caosdb_transaction_transaction *transaction), { + int linkahead_transaction_delete_transaction(linkahead_transaction_transaction *transaction), { if (transaction->_deletable && transaction->wrapped_transaction) { - delete static_cast<caosdb::transaction::Transaction *>(transaction->wrapped_transaction); + delete static_cast<linkahead::transaction::Transaction *>(transaction->wrapped_transaction); } transaction->wrapped_transaction = nullptr; transaction->_deletable = false; @@ -442,71 +459,73 @@ ERROR_RETURN_CODE( }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_transaction_transaction_retrieve_by_id( - caosdb_transaction_transaction *transaction, const char *id), + int linkahead_transaction_transaction_retrieve_by_id( + linkahead_transaction_transaction *transaction, const char *id), { - auto *wrapped_transaction = static_cast<caosdb::transaction::Transaction *>( + auto *wrapped_transaction = static_cast<linkahead::transaction::Transaction *>( transaction->wrapped_transaction); return wrapped_transaction->RetrieveById(std::string(id)); }) -ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_transaction_transaction_retrieve_and_download_file_by_id( - caosdb_transaction_transaction *transaction, const char *id, const char *path), - { - auto *wrapped_transaction = static_cast<caosdb::transaction::Transaction *>( - transaction->wrapped_transaction); - return wrapped_transaction->RetrieveAndDownloadFileById(std::string(id), - std::string(path)); - }) +ERROR_RETURN_CODE( + GENERIC_ERROR, + int linkahead_transaction_transaction_retrieve_and_download_file_by_id( + linkahead_transaction_transaction *transaction, const char *id, const char *path), + { + auto *wrapped_transaction = + static_cast<linkahead::transaction::Transaction *>(transaction->wrapped_transaction); + return wrapped_transaction->RetrieveAndDownloadFileById(std::string(id), std::string(path)); + }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_transaction_transaction_retrieve_by_ids( - caosdb_transaction_transaction *transaction, const char *ids[], int length), + int linkahead_transaction_transaction_retrieve_by_ids( + linkahead_transaction_transaction *transaction, const char *ids[], int length), { - auto *wrapped_transaction = static_cast<caosdb::transaction::Transaction *>( + auto *wrapped_transaction = static_cast<linkahead::transaction::Transaction *>( transaction->wrapped_transaction); return wrapped_transaction->RetrieveById(ids, ids + length); }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_transaction_transaction_query( - caosdb_transaction_transaction *transaction, const char *query), + int linkahead_transaction_transaction_query( + linkahead_transaction_transaction *transaction, const char *query), { - auto *wrapped_transaction = static_cast<caosdb::transaction::Transaction *>( + auto *wrapped_transaction = static_cast<linkahead::transaction::Transaction *>( transaction->wrapped_transaction); return wrapped_transaction->Query(std::string(query)); }) -ERROR_RETURN_CODE( - GENERIC_ERROR, - int caosdb_transaction_transaction_insert_entity(caosdb_transaction_transaction *transaction, - caosdb_entity_entity *entity), - { - auto *wrapped_transaction = - static_cast<caosdb::transaction::Transaction *>(transaction->wrapped_transaction); - auto *wrapped_entity = static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); +ERROR_RETURN_CODE(GENERIC_ERROR, + int linkahead_transaction_transaction_insert_entity( + linkahead_transaction_transaction *transaction, + linkahead_entity_entity *entity), + { + auto *wrapped_transaction = static_cast<linkahead::transaction::Transaction *>( + transaction->wrapped_transaction); + auto *wrapped_entity = + static_cast<linkahead::entity::Entity *>(entity->wrapped_entity); - return wrapped_transaction->InsertEntity(wrapped_entity); - }) + return wrapped_transaction->InsertEntity(wrapped_entity); + }) -ERROR_RETURN_CODE( - GENERIC_ERROR, - int caosdb_transaction_transaction_update_entity(caosdb_transaction_transaction *transaction, - caosdb_entity_entity *entity), - { - auto *wrapped_transaction = - static_cast<caosdb::transaction::Transaction *>(transaction->wrapped_transaction); - auto *wrapped_entity = static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); +ERROR_RETURN_CODE(GENERIC_ERROR, + int linkahead_transaction_transaction_update_entity( + linkahead_transaction_transaction *transaction, + linkahead_entity_entity *entity), + { + auto *wrapped_transaction = static_cast<linkahead::transaction::Transaction *>( + transaction->wrapped_transaction); + auto *wrapped_entity = + static_cast<linkahead::entity::Entity *>(entity->wrapped_entity); - return wrapped_transaction->UpdateEntity(wrapped_entity); - }) + return wrapped_transaction->UpdateEntity(wrapped_entity); + }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_transaction_transaction_delete_by_id( - caosdb_transaction_transaction *transaction, const char *id), + int linkahead_transaction_transaction_delete_by_id( + linkahead_transaction_transaction *transaction, const char *id), { - auto *wrapped_transaction = static_cast<caosdb::transaction::Transaction *>( + auto *wrapped_transaction = static_cast<linkahead::transaction::Transaction *>( transaction->wrapped_transaction); return wrapped_transaction->DeleteById(std::string(id)); @@ -514,44 +533,44 @@ ERROR_RETURN_CODE(GENERIC_ERROR, ERROR_RETURN_CODE( GENERIC_ERROR, - int caosdb_transaction_transaction_execute(caosdb_transaction_transaction *transaction), { + int linkahead_transaction_transaction_execute(linkahead_transaction_transaction *transaction), { auto *wrapped_transaction = - static_cast<caosdb::transaction::Transaction *>(transaction->wrapped_transaction); + static_cast<linkahead::transaction::Transaction *>(transaction->wrapped_transaction); wrapped_transaction->ExecuteAsynchronously(); auto status = wrapped_transaction->WaitForIt(); return status.GetCode(); }) -ERROR_RETURN_CODE( - GENERIC_ERROR, - int caosdb_transaction_transaction_get_result_set(caosdb_transaction_transaction *transaction, - caosdb_transaction_result_set *out), - { - auto *wrapped_transaction = - static_cast<caosdb::transaction::Transaction *>(transaction->wrapped_transaction); - out->wrapped_result_set = (void *)(&(wrapped_transaction->GetResultSet())); - out->_deletable = false; - return 0; - }) +ERROR_RETURN_CODE(GENERIC_ERROR, + int linkahead_transaction_transaction_get_result_set( + linkahead_transaction_transaction *transaction, + linkahead_transaction_result_set *out), + { + auto *wrapped_transaction = static_cast<linkahead::transaction::Transaction *>( + transaction->wrapped_transaction); + out->wrapped_result_set = (void *)(&(wrapped_transaction->GetResultSet())); + out->_deletable = false; + return 0; + }) -ERROR_RETURN_CODE( - GENERIC_ERROR, - int caosdb_transaction_transaction_release_result_set(caosdb_transaction_transaction *transaction, - caosdb_transaction_result_set *out), - { - auto *wrapped_transaction = - static_cast<caosdb::transaction::Transaction *>(transaction->wrapped_transaction); - out->wrapped_result_set = (void *)(wrapped_transaction->ReleaseResultSet()); - // out is the owner now, that are the semantics of ReleaseResultSet - out->_deletable = true; - return 0; - }) +ERROR_RETURN_CODE(GENERIC_ERROR, + int linkahead_transaction_transaction_release_result_set( + linkahead_transaction_transaction *transaction, + linkahead_transaction_result_set *out), + { + auto *wrapped_transaction = static_cast<linkahead::transaction::Transaction *>( + transaction->wrapped_transaction); + out->wrapped_result_set = (void *)(wrapped_transaction->ReleaseResultSet()); + // out is the owner now, that are the semantics of ReleaseResultSet + out->_deletable = true; + return 0; + }) ERROR_RETURN_CODE( GENERIC_ERROR, - int caosdb_transaction_delete_result_set(caosdb_transaction_result_set *result_set), { + int linkahead_transaction_delete_result_set(linkahead_transaction_result_set *result_set), { if (result_set->_deletable && result_set->wrapped_result_set) { - delete static_cast<caosdb::entity::Entity *>(result_set->wrapped_result_set); + delete static_cast<linkahead::entity::Entity *>(result_set->wrapped_result_set); } result_set->wrapped_result_set = nullptr; result_set->_deletable = false; @@ -559,89 +578,92 @@ ERROR_RETURN_CODE( }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_transaction_transaction_get_count_result( - caosdb_transaction_transaction *transaction, long *out), + int linkahead_transaction_transaction_get_count_result( + linkahead_transaction_transaction *transaction, long *out), { - auto *wrapped_transaction = static_cast<caosdb::transaction::Transaction *>( + auto *wrapped_transaction = static_cast<linkahead::transaction::Transaction *>( transaction->wrapped_transaction); long cr(wrapped_transaction->GetCountResult()); *out = cr; return 0; }) -ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_transaction_result_set_at(caosdb_transaction_result_set *result_set, - caosdb_entity_entity *entity, int index), - { - auto *wrapped_result_set = static_cast<caosdb::transaction::MultiResultSet *>( - result_set->wrapped_result_set); - entity->wrapped_entity = wrapped_result_set->mutable_at(index); - return 0; - }) +ERROR_RETURN_CODE( + GENERIC_ERROR, + int linkahead_transaction_result_set_at(linkahead_transaction_result_set *result_set, + linkahead_entity_entity *entity, int index), + { + auto *wrapped_result_set = + static_cast<linkahead::transaction::MultiResultSet *>(result_set->wrapped_result_set); + entity->wrapped_entity = wrapped_result_set->mutable_at(index); + return 0; + }) ERROR_RETURN_CODE( GENERIC_ERROR, - int caosdb_transaction_result_set_release_at(caosdb_transaction_result_set *result_set, - caosdb_entity_entity *entity, int index), + int linkahead_transaction_result_set_release_at(linkahead_transaction_result_set *result_set, + linkahead_entity_entity *entity, int index), { auto *wrapped_result_set = - static_cast<caosdb::transaction::MultiResultSet *>(result_set->wrapped_result_set); + static_cast<linkahead::transaction::MultiResultSet *>(result_set->wrapped_result_set); entity->wrapped_entity = wrapped_result_set->release_at(index); // entity is the owner now. That are the semantics of release_at. entity->_deletable = true; return 0; }) -ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_transaction_result_set_size(caosdb_transaction_result_set *result_set, - int *out), - { - auto *wrapped_result_set = static_cast<caosdb::transaction::MultiResultSet *>( - result_set->wrapped_result_set); - int size(wrapped_result_set->size()); - *out = size; - return 0; - }) +ERROR_RETURN_CODE( + GENERIC_ERROR, + int linkahead_transaction_result_set_size(linkahead_transaction_result_set *result_set, int *out), + { + auto *wrapped_result_set = + static_cast<linkahead::transaction::MultiResultSet *>(result_set->wrapped_result_set); + int size(wrapped_result_set->size()); + *out = size; + return 0; + }) -ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_create_entity(caosdb_entity_entity *out), { - out->wrapped_entity = new caosdb::entity::Entity(); +ERROR_RETURN_CODE(GENERIC_ERROR, int linkahead_entity_create_entity(linkahead_entity_entity *out), { + out->wrapped_entity = new linkahead::entity::Entity(); out->_deletable = true; return 0; }) -ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_delete_entity(caosdb_entity_entity *out), { +ERROR_RETURN_CODE(GENERIC_ERROR, int linkahead_entity_delete_entity(linkahead_entity_entity *out), { if (out->_deletable && out->wrapped_entity) { - delete static_cast<caosdb::entity::Entity *>(out->wrapped_entity); + delete static_cast<linkahead::entity::Entity *>(out->wrapped_entity); } out->wrapped_entity = nullptr; out->_deletable = false; return 0; }) -ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_create_property(caosdb_entity_property *out), { - out->wrapped_property = new caosdb::entity::Property(); - out->_deletable = true; - return 0; -}) +ERROR_RETURN_CODE(GENERIC_ERROR, + int linkahead_entity_create_property(linkahead_entity_property *out), { + out->wrapped_property = new linkahead::entity::Property(); + out->_deletable = true; + return 0; + }) -ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_delete_property(caosdb_entity_property *out), { - if (out->_deletable && out->wrapped_property) { - delete static_cast<caosdb::entity::Property *>(out->wrapped_property); - } - out->wrapped_property = nullptr; - out->_deletable = false; - return 0; -}) +ERROR_RETURN_CODE(GENERIC_ERROR, + int linkahead_entity_delete_property(linkahead_entity_property *out), { + if (out->_deletable && out->wrapped_property) { + delete static_cast<linkahead::entity::Property *>(out->wrapped_property); + } + out->wrapped_property = nullptr; + out->_deletable = false; + return 0; + }) -ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_create_parent(caosdb_entity_parent *out), { - out->wrapped_parent = new caosdb::entity::Parent(); +ERROR_RETURN_CODE(GENERIC_ERROR, int linkahead_entity_create_parent(linkahead_entity_parent *out), { + out->wrapped_parent = new linkahead::entity::Parent(); out->_deletable = true; return 0; }) -ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_delete_parent(caosdb_entity_parent *out), { +ERROR_RETURN_CODE(GENERIC_ERROR, int linkahead_entity_delete_parent(linkahead_entity_parent *out), { if (out->_deletable && out->wrapped_parent) { - delete static_cast<caosdb::entity::Parent *>(out->wrapped_parent); + delete static_cast<linkahead::entity::Parent *>(out->wrapped_parent); } out->wrapped_parent = nullptr; out->_deletable = false; @@ -649,60 +671,61 @@ ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_delete_parent(caosdb_entity_p }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_create_atomic_datatype(caosdb_entity_datatype *out, - const char *name), + int linkahead_entity_create_atomic_datatype(linkahead_entity_datatype *out, + const char *name), { try { auto enum_value = ENUM_VALUE_FROM_NAME(std::string(name), AtomicDataType); - out->wrapped_datatype = new caosdb::entity::DataType(enum_value); + out->wrapped_datatype = new linkahead::entity::DataType(enum_value); out->_deletable = true; return 0; } catch (const std::out_of_range &exc) { - caosdb::logging::caosdb_log_fatal(CCAOSDB_LOGGER_NAME, exc.what()); - return caosdb::StatusCode::ENUM_MAPPING_ERROR; + linkahead::logging::linkahead_log_fatal(CLINKAHEAD_LOGGER_NAME, exc.what()); + return linkahead::StatusCode::ENUM_MAPPING_ERROR; } }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_create_reference_datatype(caosdb_entity_datatype *out, - const char *name), + int linkahead_entity_create_reference_datatype(linkahead_entity_datatype *out, + const char *name), { - out->wrapped_datatype = new caosdb::entity::DataType(std::string(name)); + out->wrapped_datatype = new linkahead::entity::DataType(std::string(name)); out->_deletable = true; return 0; }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_create_atomic_list_datatype(caosdb_entity_datatype *out, - const char *name), + int linkahead_entity_create_atomic_list_datatype(linkahead_entity_datatype *out, + const char *name), { try { auto enum_value = ENUM_VALUE_FROM_NAME(std::string(name), AtomicDataType); - out->wrapped_datatype = - new caosdb::entity::DataType(caosdb::entity::DataType::ListOf(enum_value)); + out->wrapped_datatype = new linkahead::entity::DataType( + linkahead::entity::DataType::ListOf(enum_value)); out->_deletable = true; return 0; } catch (const std::out_of_range &exc) { - caosdb::logging::caosdb_log_fatal(CCAOSDB_LOGGER_NAME, exc.what()); - return caosdb::StatusCode::ENUM_MAPPING_ERROR; + linkahead::logging::linkahead_log_fatal(CLINKAHEAD_LOGGER_NAME, exc.what()); + return linkahead::StatusCode::ENUM_MAPPING_ERROR; } }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_create_reference_list_datatype(caosdb_entity_datatype *out, - const char *name), + int linkahead_entity_create_reference_list_datatype( + linkahead_entity_datatype *out, const char *name), { - out->wrapped_datatype = new caosdb::entity::DataType( - caosdb::entity::DataType::ListOf(std::string(name))); + out->wrapped_datatype = new linkahead::entity::DataType( + linkahead::entity::DataType::ListOf(std::string(name))); out->_deletable = true; return 0; }) -ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_delete_datatype(caosdb_entity_datatype *out), { - if (out->_deletable && out->wrapped_datatype) { - delete WRAPPED_DATATYPE_CAST(out); - } - out->wrapped_datatype = nullptr; - out->_deletable = false; - return 0; -}) +ERROR_RETURN_CODE(GENERIC_ERROR, + int linkahead_entity_delete_datatype(linkahead_entity_datatype *out), { + if (out->_deletable && out->wrapped_datatype) { + delete WRAPPED_DATATYPE_CAST(out); + } + out->wrapped_datatype = nullptr; + out->_deletable = false; + return 0; + }) CREATE_VALUE(int_value, const int64_t value) CREATE_VALUE(string_value, const char *value) @@ -713,7 +736,7 @@ CREATE_VECTOR_VALUE(string_vector_value, std::string, const char **value, std::s CREATE_VECTOR_VALUE(double_vector_value, double, const double *value, value[i]) CREATE_VECTOR_VALUE(bool_vector_value, bool, const bool *value, value[i]) -ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_delete_value(caosdb_entity_value *out), { +ERROR_RETURN_CODE(GENERIC_ERROR, int linkahead_entity_delete_value(linkahead_entity_value *out), { if (out->_deletable && out->wrapped_value) { delete WRAPPED_VALUE_CAST(out); } @@ -722,34 +745,36 @@ ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_delete_value(caosdb_entity_va return 0; }) -CAOSDB_ENTITY_GET(id, GetId()) +LINKAHEAD_ENTITY_GET(id, GetId()) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_entity_get_role(caosdb_entity_entity *entity, char **out), { + int linkahead_entity_entity_get_role(linkahead_entity_entity *entity, char **out), + { auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity); std::string role_str = ENUM_NAME_FROM_VALUE(wrapped_entity->GetRole(), Role); auto *tmp = (char *)malloc(sizeof(char) * role_str.length() + 1); strcpy(tmp, role_str.c_str()); - delete[] * out; + delete[] *out; *out = tmp; return 0; }) -CAOSDB_ENTITY_GET(name, GetName()) +LINKAHEAD_ENTITY_GET(name, GetName()) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_entity_get_local_path(caosdb_entity_entity *entity, char **out), + int linkahead_entity_entity_get_local_path(linkahead_entity_entity *entity, + char **out), { auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity); auto path = wrapped_entity->GetLocalPath().string(); auto *tmp = (char *)(malloc(sizeof(char) * path.length() + 1)); strcpy(tmp, path.c_str()); - delete[] * out; + delete[] *out; *out = tmp; return 0; }) -// CAOSDB_ENTITY_GET(file_path, GetFilePath()) TODO(henrik) -CAOSDB_ENTITY_GET(description, GetDescription()) +// LINKAHEAD_ENTITY_GET(file_path, GetFilePath()) TODO(henrik) +LINKAHEAD_ENTITY_GET(description, GetDescription()) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_entity_get_datatype(caosdb_entity_entity *entity, - caosdb_entity_datatype *out), + int linkahead_entity_entity_get_datatype(linkahead_entity_entity *entity, + linkahead_entity_datatype *out), { auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity); out->wrapped_datatype = (void *)(&(wrapped_entity->GetDataType())); @@ -757,8 +782,8 @@ ERROR_RETURN_CODE(GENERIC_ERROR, return 0; }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_entity_get_value(caosdb_entity_entity *entity, - caosdb_entity_value *out), + int linkahead_entity_entity_get_value(linkahead_entity_entity *entity, + linkahead_entity_value *out), { auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity); out->wrapped_value = (void *)(&(wrapped_entity->GetValue())); @@ -766,134 +791,139 @@ ERROR_RETURN_CODE(GENERIC_ERROR, return 0; }) -CAOSDB_ENTITY_GET(unit, GetUnit()) -CAOSDB_ENTITY_GET(version_id, GetVersionId()) +LINKAHEAD_ENTITY_GET(unit, GetUnit()) +LINKAHEAD_ENTITY_GET(version_id, GetVersionId()) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_entity_get_errors_size(caosdb_entity_entity *entity, int *out), + int linkahead_entity_entity_get_errors_size(linkahead_entity_entity *entity, + int *out), { auto *wrapped_entity = - static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); + static_cast<linkahead::entity::Entity *>(entity->wrapped_entity); *out = wrapped_entity->GetErrors().size(); return 0; }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_entity_get_error(caosdb_entity_entity *entity, - caosdb_entity_message *out, int index), + int linkahead_entity_entity_get_error(linkahead_entity_entity *entity, + linkahead_entity_message *out, int index), { auto *wrapped_entity = - static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); + static_cast<linkahead::entity::Entity *>(entity->wrapped_entity); out->wrapped_message = wrapped_entity->GetErrors().mutable_at(index); out->_deletable = false; return 0; }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_entity_get_warnings_size(caosdb_entity_entity *entity, - int *out), + int linkahead_entity_entity_get_warnings_size(linkahead_entity_entity *entity, + int *out), { auto *wrapped_entity = - static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); + static_cast<linkahead::entity::Entity *>(entity->wrapped_entity); *out = wrapped_entity->GetWarnings().size(); return 0; }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_entity_get_warning(caosdb_entity_entity *entity, - caosdb_entity_message *out, int index), + int linkahead_entity_entity_get_warning(linkahead_entity_entity *entity, + linkahead_entity_message *out, int index), { auto *wrapped_entity = - static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); + static_cast<linkahead::entity::Entity *>(entity->wrapped_entity); out->wrapped_message = wrapped_entity->GetWarnings().mutable_at(index); out->_deletable = false; return 0; }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_entity_get_infos_size(caosdb_entity_entity *entity, int *out), { + int linkahead_entity_entity_get_infos_size(linkahead_entity_entity *entity, + int *out), + { auto *wrapped_entity = - static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); + static_cast<linkahead::entity::Entity *>(entity->wrapped_entity); *out = wrapped_entity->GetInfos().size(); return 0; }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_entity_get_info(caosdb_entity_entity *entity, - caosdb_entity_message *out, int index), + int linkahead_entity_entity_get_info(linkahead_entity_entity *entity, + linkahead_entity_message *out, int index), { auto *wrapped_entity = - static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); + static_cast<linkahead::entity::Entity *>(entity->wrapped_entity); out->wrapped_message = wrapped_entity->GetInfos().mutable_at(index); out->_deletable = false; return 0; }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_entity_get_properties_size(caosdb_entity_entity *entity, - int *out), + int linkahead_entity_entity_get_properties_size(linkahead_entity_entity *entity, + int *out), { auto *wrapped_entity = - static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); + static_cast<linkahead::entity::Entity *>(entity->wrapped_entity); *out = wrapped_entity->GetProperties().size(); return 0; }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_entity_get_property(caosdb_entity_entity *entity, - caosdb_entity_property *out, int index), + int linkahead_entity_entity_get_property(linkahead_entity_entity *entity, + linkahead_entity_property *out, + int index), { auto *wrapped_entity = - static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); + static_cast<linkahead::entity::Entity *>(entity->wrapped_entity); out->wrapped_property = wrapped_entity->GetProperties().mutable_at(index); out->_deletable = false; return 0; }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_entity_get_parents_size(caosdb_entity_entity *entity, int *out), + int linkahead_entity_entity_get_parents_size(linkahead_entity_entity *entity, + int *out), { auto *wrapped_entity = - static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); + static_cast<linkahead::entity::Entity *>(entity->wrapped_entity); *out = wrapped_entity->GetParents().size(); return 0; }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_entity_get_parent(caosdb_entity_entity *entity, - caosdb_entity_parent *out, int index), + int linkahead_entity_entity_get_parent(linkahead_entity_entity *entity, + linkahead_entity_parent *out, int index), { auto *wrapped_entity = - static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); + static_cast<linkahead::entity::Entity *>(entity->wrapped_entity); out->wrapped_parent = wrapped_entity->GetParents().mutable_at(index); out->_deletable = false; return 0; }) -CAOSDB_PARENT_GET(id, GetId()) -CAOSDB_PARENT_GET(name, GetName()) -CAOSDB_PARENT_GET(description, GetDescription()) +LINKAHEAD_PARENT_GET(id, GetId()) +LINKAHEAD_PARENT_GET(name, GetName()) +LINKAHEAD_PARENT_GET(description, GetDescription()) -CAOSDB_PROPERTY_GET(id, GetId()) -CAOSDB_PROPERTY_GET(name, GetName()) -CAOSDB_PROPERTY_GET(description, GetDescription()) +LINKAHEAD_PROPERTY_GET(id, GetId()) +LINKAHEAD_PROPERTY_GET(name, GetName()) +LINKAHEAD_PROPERTY_GET(description, GetDescription()) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_property_get_importance(caosdb_entity_property *property, - char **out), + int linkahead_entity_property_get_importance(linkahead_entity_property *property, + char **out), { auto *wrapped_property = WRAPPED_PROPERTY_CAST(property); std::string importance_str = ENUM_NAME_FROM_VALUE(wrapped_property->GetImportance(), Importance); char *tmp = (char *)malloc(sizeof(char) * importance_str.length() + 1); strcpy(tmp, importance_str.c_str()); - delete[] * out; + delete[] *out; *out = tmp; return 0; }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_property_get_datatype(caosdb_entity_property *property, - caosdb_entity_datatype *out), + int linkahead_entity_property_get_datatype(linkahead_entity_property *property, + linkahead_entity_datatype *out), { auto *wrapped_property = WRAPPED_PROPERTY_CAST(property); out->wrapped_datatype = (void *)(&(wrapped_property->GetDataType())); @@ -901,74 +931,76 @@ ERROR_RETURN_CODE(GENERIC_ERROR, return 0; }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_property_get_value(caosdb_entity_property *property, - caosdb_entity_value *out), + int linkahead_entity_property_get_value(linkahead_entity_property *property, + linkahead_entity_value *out), { auto *wrapped_property = WRAPPED_PROPERTY_CAST(property); out->wrapped_value = (void *)(&(wrapped_property->GetValue())); out->_deletable = false; return 0; }) -CAOSDB_PROPERTY_GET(unit, GetUnit()) +LINKAHEAD_PROPERTY_GET(unit, GetUnit()) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_message_get_code(caosdb_entity_message *message, int *out), { + int linkahead_entity_message_get_code(linkahead_entity_message *message, + int *out), + { auto *wrapped_message = - static_cast<caosdb::entity::Message *>(message->wrapped_message); + static_cast<linkahead::entity::Message *>(message->wrapped_message); *out = wrapped_message->GetCode(); return 0; }) ERROR_RETURN_CODE( GENERIC_ERROR, - int caosdb_entity_message_get_description(caosdb_entity_message *message, char **out), { - auto *wrapped_message = static_cast<caosdb::entity::Message *>(message->wrapped_message); + int linkahead_entity_message_get_description(linkahead_entity_message *message, char **out), { + auto *wrapped_message = static_cast<linkahead::entity::Message *>(message->wrapped_message); auto *tmp = (char *)malloc(sizeof(char) * wrapped_message->GetDescription().length() + 1); strcpy(tmp, wrapped_message->GetDescription().c_str()); - delete[] * out; + delete[] *out; *out = tmp; return 0; }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_datatype_is_undefined(caosdb_entity_datatype *datatype, - bool *out), + int linkahead_entity_datatype_is_undefined(linkahead_entity_datatype *datatype, + bool *out), { auto *wrapped_datatype = WRAPPED_DATATYPE_CAST(datatype); *out = wrapped_datatype->IsUndefined(); return 0; }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_datatype_is_atomic(caosdb_entity_datatype *datatype, bool *out), + int linkahead_entity_datatype_is_atomic(linkahead_entity_datatype *datatype, + bool *out), { auto *wrapped_datatype = WRAPPED_DATATYPE_CAST(datatype); *out = wrapped_datatype->IsAtomic(); return 0; }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_datatype_is_reference(caosdb_entity_datatype *datatype, - bool *out), + int linkahead_entity_datatype_is_reference(linkahead_entity_datatype *datatype, + bool *out), { auto *wrapped_datatype = WRAPPED_DATATYPE_CAST(datatype); *out = wrapped_datatype->IsReference(); return 0; }) +ERROR_RETURN_CODE( + GENERIC_ERROR, + int linkahead_entity_datatype_is_list_of_atomic(linkahead_entity_datatype *datatype, bool *out), { + auto *wrapped_datatype = WRAPPED_DATATYPE_CAST(datatype); + if (wrapped_datatype->IsList()) { + const auto &list_datatype = wrapped_datatype->GetAsList(); + *out = list_datatype.IsListOfAtomic(); + } else { + *out = false; + } + return 0; + }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_datatype_is_list_of_atomic(caosdb_entity_datatype *datatype, - bool *out), - { - auto *wrapped_datatype = WRAPPED_DATATYPE_CAST(datatype); - if (wrapped_datatype->IsList()) { - const auto &list_datatype = wrapped_datatype->GetAsList(); - *out = list_datatype.IsListOfAtomic(); - } else { - *out = false; - } - return 0; - }) -ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_datatype_is_list_of_reference(caosdb_entity_datatype *datatype, - bool *out), + int linkahead_entity_datatype_is_list_of_reference( + linkahead_entity_datatype *datatype, bool *out), { auto *wrapped_datatype = WRAPPED_DATATYPE_CAST(datatype); if (wrapped_datatype->IsList()) { @@ -981,7 +1013,8 @@ ERROR_RETURN_CODE(GENERIC_ERROR, }) ERROR_RETURN_CODE( GENERIC_ERROR, - int caosdb_entity_datatype_get_datatype_name(caosdb_entity_datatype *datatype, char **out), { + int linkahead_entity_datatype_get_datatype_name(linkahead_entity_datatype *datatype, char **out), + { auto *wrapped_datatype = WRAPPED_DATATYPE_CAST(datatype); std::string datatype_name; if (wrapped_datatype->IsList()) { @@ -1000,7 +1033,7 @@ ERROR_RETURN_CODE( } char *tmp = (char *)malloc(sizeof(char) * datatype_name.length() + 1); strcpy(tmp, datatype_name.c_str()); - delete[] * out; + delete[] *out; *out = tmp; return 0; }) @@ -1013,12 +1046,14 @@ VALUE_IS(bool, IsBool) VALUE_IS(vector, IsVector) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_value_get_as_string(caosdb_entity_value *value, char **out), { + int linkahead_entity_value_get_as_string(linkahead_entity_value *value, + char **out), + { auto *wrapped_value = WRAPPED_VALUE_CAST(value); auto *tmp = (char *)malloc(sizeof(char) * wrapped_value->GetAsString().length() + 1); strcpy(tmp, wrapped_value->GetAsString().c_str()); - delete[] * out; + delete[] *out; *out = tmp; return 0; }) @@ -1027,9 +1062,9 @@ VALUE_GET_AS(integer, GetAsInt64, int64_t *out) VALUE_GET_AS(bool, GetAsBool, bool *out) VALUE_GET_AS(vector_size, GetAsVector().size, int *out) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_value_get_as_vector_at(caosdb_entity_value *value, - caosdb_entity_value *out, - const int index), + int linkahead_entity_value_get_as_vector_at(linkahead_entity_value *value, + linkahead_entity_value *out, + const int index), { auto *wrapped_value = WRAPPED_VALUE_CAST(value); out->wrapped_value = (void *)(&(wrapped_value->GetAsVector().at(index))); @@ -1037,7 +1072,8 @@ ERROR_RETURN_CODE(GENERIC_ERROR, return 0; }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_entity_set_role(caosdb_entity_entity *entity, const char *role), + int linkahead_entity_entity_set_role(linkahead_entity_entity *entity, + const char *role), { auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity); try { @@ -1045,20 +1081,20 @@ ERROR_RETURN_CODE(GENERIC_ERROR, wrapped_entity->SetRole(enum_value); return 0; } catch (const std::out_of_range &exc) { - caosdb::logging::caosdb_log_fatal(CCAOSDB_LOGGER_NAME, exc.what()); - return caosdb::StatusCode::ENUM_MAPPING_ERROR; + linkahead::logging::linkahead_log_fatal(CLINKAHEAD_LOGGER_NAME, exc.what()); + return linkahead::StatusCode::ENUM_MAPPING_ERROR; } }) -CAOSDB_ENTITY_SET(name, name, wrapped_entity->SetName(std::string(name));) -CAOSDB_ENTITY_SET(local_path, local_path, - return wrapped_entity->SetLocalPath(std::filesystem::path(local_path));) -CAOSDB_ENTITY_SET(file_path, file_path, wrapped_entity->SetFilePath(std::string(file_path));) -CAOSDB_ENTITY_SET(description, description, - wrapped_entity->SetDescription(std::string(description));) -CAOSDB_ENTITY_SET(unit, unit, wrapped_entity->SetUnit(std::string(unit));) +LINKAHEAD_ENTITY_SET(name, name, wrapped_entity->SetName(std::string(name));) +LINKAHEAD_ENTITY_SET(local_path, local_path, + return wrapped_entity->SetLocalPath(std::filesystem::path(local_path));) +LINKAHEAD_ENTITY_SET(file_path, file_path, wrapped_entity->SetFilePath(std::string(file_path));) +LINKAHEAD_ENTITY_SET(description, description, + wrapped_entity->SetDescription(std::string(description));) +LINKAHEAD_ENTITY_SET(unit, unit, wrapped_entity->SetUnit(std::string(unit));) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_entity_set_datatype(caosdb_entity_entity *entity, - caosdb_entity_datatype *datatype), + int linkahead_entity_entity_set_datatype(linkahead_entity_entity *entity, + linkahead_entity_datatype *datatype), { auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity); auto *wrapped_datatype = WRAPPED_DATATYPE_CAST(datatype); @@ -1066,8 +1102,8 @@ ERROR_RETURN_CODE(GENERIC_ERROR, return wrapped_entity->SetDataType(*wrapped_datatype); }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_entity_set_value(caosdb_entity_entity *entity, - caosdb_entity_value *value), + int linkahead_entity_entity_set_value(linkahead_entity_entity *entity, + linkahead_entity_value *value), { auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity); auto *wrapped_value = WRAPPED_VALUE_CAST(value); @@ -1076,53 +1112,56 @@ ERROR_RETURN_CODE(GENERIC_ERROR, }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_entity_append_parent(caosdb_entity_entity *entity, - caosdb_entity_parent *parent), + int linkahead_entity_entity_append_parent(linkahead_entity_entity *entity, + linkahead_entity_parent *parent), { auto *wrapped_entity = - static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); + static_cast<linkahead::entity::Entity *>(entity->wrapped_entity); auto *wrapped_parent = - static_cast<caosdb::entity::Parent *>(parent->wrapped_parent); + static_cast<linkahead::entity::Parent *>(parent->wrapped_parent); wrapped_entity->AppendParent(*wrapped_parent); return 0; }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_entity_remove_parent(caosdb_entity_entity *entity, int index), { + int linkahead_entity_entity_remove_parent(linkahead_entity_entity *entity, + int index), + { auto *wrapped_entity = - static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); + static_cast<linkahead::entity::Entity *>(entity->wrapped_entity); wrapped_entity->RemoveParent(index); return 0; }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_entity_append_property(caosdb_entity_entity *entity, - caosdb_entity_property *property), + int linkahead_entity_entity_append_property(linkahead_entity_entity *entity, + linkahead_entity_property *property), { auto *wrapped_entity = - static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); + static_cast<linkahead::entity::Entity *>(entity->wrapped_entity); auto *wrapped_property = - static_cast<caosdb::entity::Property *>(property->wrapped_property); + static_cast<linkahead::entity::Property *>(property->wrapped_property); wrapped_entity->AppendProperty(*wrapped_property); return 0; }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_entity_remove_property(caosdb_entity_entity *entity, int index), + int linkahead_entity_entity_remove_property(linkahead_entity_entity *entity, + int index), { auto *wrapped_entity = - static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); + static_cast<linkahead::entity::Entity *>(entity->wrapped_entity); wrapped_entity->RemoveProperty(index); return 0; }) -CAOSDB_PARENT_SET(id, id, wrapped_parent->SetId(std::string(id));) -CAOSDB_PARENT_SET(name, name, wrapped_parent->SetName(std::string(name));) +LINKAHEAD_PARENT_SET(id, id, wrapped_parent->SetId(std::string(id));) +LINKAHEAD_PARENT_SET(name, name, wrapped_parent->SetName(std::string(name));) -CAOSDB_PROPERTY_SET(name, name, wrapped_property->SetName(std::string(name));) -CAOSDB_PROPERTY_SET(id, id, wrapped_property->SetId(std::string(id));) +LINKAHEAD_PROPERTY_SET(name, name, wrapped_property->SetName(std::string(name));) +LINKAHEAD_PROPERTY_SET(id, id, wrapped_property->SetId(std::string(id));) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_property_set_datatype(caosdb_entity_property *property, - caosdb_entity_datatype *datatype), + int linkahead_entity_property_set_datatype(linkahead_entity_property *property, + linkahead_entity_datatype *datatype), { auto *wrapped_property = WRAPPED_PROPERTY_CAST(property); auto *wrapped_datatype = WRAPPED_DATATYPE_CAST(datatype); @@ -1130,8 +1169,8 @@ ERROR_RETURN_CODE(GENERIC_ERROR, return wrapped_property->SetDataType(*wrapped_datatype); }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_property_set_value(caosdb_entity_property *property, - caosdb_entity_value *value), + int linkahead_entity_property_set_value(linkahead_entity_property *property, + linkahead_entity_value *value), { auto *wrapped_property = WRAPPED_PROPERTY_CAST(property); auto *wrapped_value = WRAPPED_VALUE_CAST(value); @@ -1140,8 +1179,8 @@ ERROR_RETURN_CODE(GENERIC_ERROR, }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_property_set_importance(caosdb_entity_property *property, - const char *importance), + int linkahead_entity_property_set_importance(linkahead_entity_property *property, + const char *importance), { auto *wrapped_property = WRAPPED_PROPERTY_CAST(property); try { @@ -1149,10 +1188,10 @@ ERROR_RETURN_CODE(GENERIC_ERROR, wrapped_property->SetImportance(enum_value); return 0; } catch (const std::out_of_range &exc) { - caosdb::logging::caosdb_log_fatal(CCAOSDB_LOGGER_NAME, exc.what()); - return caosdb::StatusCode::ENUM_MAPPING_ERROR; + linkahead::logging::linkahead_log_fatal(CLINKAHEAD_LOGGER_NAME, exc.what()); + return linkahead::StatusCode::ENUM_MAPPING_ERROR; } }) -CAOSDB_PROPERTY_SET(unit, unit, wrapped_property->SetUnit(std::string(unit));) +LINKAHEAD_PROPERTY_SET(unit, unit, wrapped_property->SetUnit(std::string(unit));) } diff --git a/src/clinkaheadcli.c b/src/clinkaheadcli.c new file mode 100644 index 0000000000000000000000000000000000000000..34ea16c4add6f030a49d9a177cbd4becb0eacd3e --- /dev/null +++ b/src/clinkaheadcli.c @@ -0,0 +1,28 @@ +#include "linkahead/constants.h" // for LIBLINKAHEAD_VERSION_MAJOR, LIBLINKAHEAD_VER... +#include "clinkahead.h" // for linkahead_info_version_info, linkahead_conne... +#include <stdio.h> // for printf + +int main(void) { + int status = 0; // last function return value + printf("LinkAhead C client (liblinkahead %d.%d.%d)\n\n", LIBLINKAHEAD_VERSION_MAJOR, + LIBLINKAHEAD_VERSION_MINOR, LIBLINKAHEAD_VERSION_PATCH); + + linkahead_connection_connection connection; + status = linkahead_connection_connection_manager_get_default_connection(&connection); + if (status != 0) { + printf("An error occured: ERROR %d - %s\n", status, linkahead_get_status_description(status)); + return status; + } + + linkahead_info_version_info version_info; + status = linkahead_connection_get_version_info(&version_info, &connection); + if (status != 0) { + printf("An error occured: ERROR %d - %s\n", status, linkahead_get_status_description(status)); + return status; + } + + printf("Server version: %d.%d.%d-%s-%s\n", version_info.major, version_info.minor, + version_info.patch, version_info.pre_release, version_info.build); + + return 0; +} diff --git a/src/cxxcaosdbcli.cpp b/src/cxxlinkaheadcli.cpp similarity index 52% rename from src/cxxcaosdbcli.cpp rename to src/cxxlinkaheadcli.cpp index e6e5cee66e6c90ab7719434d7667cd6ad20ccbb8..3626d96835d6447d60e8df3a53370099b3eabe8d 100644 --- a/src/cxxcaosdbcli.cpp +++ b/src/cxxlinkaheadcli.cpp @@ -1,9 +1,9 @@ /* * - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -20,16 +20,16 @@ * */ -// A simple caosdb client -#include "caosdb/connection.h" // for Connection, ConnectionManager -#include "caosdb/constants.h" // for LIBCAOSDB_VERSION_MINOR, LIBCAOSDB_V... -#include "caosdb/entity.h" // for Entity -#include "caosdb/exceptions.h" // for ConfigurationError -#include "caosdb/info.h" // for VersionInfo -#include "caosdb/logging.h" // for CAOSDB_LOG_TRACE -#include "caosdb/transaction.h" // for Transaction, ResultSet -#include "caosdb/transaction_status.h" // for TransactionSt... -#include <boost/log/core/record.hpp> // for record +// A simple linkahead client +#include "linkahead/connection.h" // for Connection, ConnectionManager +#include "linkahead/constants.h" // for LIBLINKAHEAD_VERSION_MINOR, LIBLINKAHEAD_V... +#include "linkahead/entity.h" // for Entity +#include "linkahead/exceptions.h" // for ConfigurationError +#include "linkahead/info.h" // for VersionInfo +#include "linkahead/logging.h" // for LINKAHEAD_LOG_TRACE +#include "linkahead/transaction.h" // for Transaction, ResultSet +#include "linkahead/transaction_status.h" // for TransactionSt... +#include <boost/log/core/record.hpp> // for record #include <boost/log/detail/attachable_sstream_buf.hpp> // for basic_ostring... #include <boost/log/sources/record_ostream.hpp> // for operator<< #include <boost/preprocessor/seq/limits/enum_256.hpp> // for BOOST_PP_SEQ_... @@ -39,60 +39,67 @@ #include <memory> // for unique_ptr, allocator, __shared_ptr_... #include <string> // for operator<<, char_traits -const auto logger_name = "libcaosdb"; +const auto logger_name = "liblinkahead"; auto main() -> int { - std::cout << "CaosDB C++ client (libcaosdb " << caosdb::LIBCAOSDB_VERSION_MINOR << "." - << caosdb::LIBCAOSDB_VERSION_MINOR << "." << caosdb::LIBCAOSDB_VERSION_PATCH << ")\n" - << "We don't miss the H of caos.\n" - << std::endl; + std::cout << "LinkAhead C++ client (liblinkahead " << linkahead::LIBLINKAHEAD_VERSION_MAJOR << "." + << linkahead::LIBLINKAHEAD_VERSION_MINOR << "." << linkahead::LIBLINKAHEAD_VERSION_PATCH + << ")\n"; try { - const auto &connection = caosdb::connection::ConnectionManager::GetDefaultConnection(); + const auto &connection = linkahead::connection::ConnectionManager::GetDefaultConnection(); - connection->RetrieveVersionInfoNoExceptions(); + auto status = connection->RetrieveVersionInfoNoExceptions(); + if (status.GetCode() == linkahead::CONNECTION_ERROR) { + const auto connection_config = + linkahead::configuration::ConfigurationManager::GetDefaultConnectionConfiguration(); + std::cout << "ConnectionError: Cannot connect to " << connection_config->GetHost() << ":" + << connection_config->GetPort() << '\n'; + + return 1; + } // get version info of the server const auto &v_info = connection->GetVersionInfo(); std::cout << "Server Version: " << v_info->GetMajor() << "." << v_info->GetMinor() << "." << v_info->GetPatch() << "-" << v_info->GetPreRelease() << "-" << v_info->GetBuild() - << std::endl; + << '\n'; // retrieve an entity auto transaction(connection->CreateTransaction()); transaction->RetrieveById("21"); transaction->ExecuteAsynchronously(); auto t_stat = transaction->WaitForIt(); - CAOSDB_LOG_INFO(logger_name) << "status: " << t_stat.GetCode() << " // " - << t_stat.GetDescription(); + LINKAHEAD_LOG_INFO(logger_name) + << "status: " << t_stat.GetCode() << " // " << t_stat.GetDescription(); const auto &result_set = transaction->GetResultSet(); for (const auto &entity : result_set) { - std::cout << entity.ToString() << std::endl; + std::cout << entity.ToString() << '\n'; } // execute a query std::string query("FIND Property \"Prop *\""); - std::cout << "Trying to execute a query:\n" << query << std::endl; + std::cout << "Trying to execute a query:\n" << query << '\n'; auto q_transaction(connection->CreateTransaction()); q_transaction->Query(query); q_transaction->ExecuteAsynchronously(); t_stat = q_transaction->WaitForIt(); - CAOSDB_LOG_INFO(logger_name) << "status: " << t_stat.GetCode() << " // " - << t_stat.GetDescription(); + LINKAHEAD_LOG_INFO(logger_name) + << "status: " << t_stat.GetCode() << " // " << t_stat.GetDescription(); const auto &result_set_2 = q_transaction->GetResultSet(); for (const auto &entity : result_set_2) { - std::cout << entity.ToString() << std::endl; + std::cout << entity.ToString() << '\n'; } return 0; - } catch (const caosdb::exceptions::ConfigurationError &exc) { - std::cout << "ConfigurationError: " << exc.what() << std::endl; + } catch (const linkahead::exceptions::ConfigurationError &exc) { + std::cout << "ConfigurationError: " << exc.what() << '\n'; return exc.GetCode(); } catch (const std::exception &exc) { - std::cout << "Exception: " << exc.what() << std::endl; + std::cout << "Exception: " << exc.what() << '\n'; return 1; } catch (...) { - std::cout << "Some other exception." << std::endl; + std::cout << "Some other exception." << '\n'; return 2; } } diff --git a/src/caosdb/acm/user.cpp b/src/linkahead/acm/user.cpp similarity index 91% rename from src/caosdb/acm/user.cpp rename to src/linkahead/acm/user.cpp index 2988287997c723c35bdd1f470572c4dc5797879f..39c88f1501a13f55d2f3a81e0a6f37f7ef679c1b 100644 --- a/src/caosdb/acm/user.cpp +++ b/src/linkahead/acm/user.cpp @@ -1,5 +1,5 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * * Copyright (C) 2022 Timm Fitschen <t.fitschen@indiscale.com> * Copyright (C) 2022 IndiScale GmbH <info@indiscale.com> @@ -18,14 +18,14 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ -#include "caosdb/acm/user.h" -#include "caosdb/acm/user_impl.h" // for UserImpl +#include "linkahead/acm/user.h" +#include "linkahead/acm/user_impl.h" // for UserImpl #include "caosdb/acm/v1alpha1/main.pb.h" // for ProtoUser -#include "caosdb/protobuf_helper.h" // for ProtoMessageWrapper +#include "linkahead/protobuf_helper.h" // for ProtoMessageWrapper #include <utility> // for move -namespace caosdb::acm { -using caosdb::utility::ScalarProtoMessageWrapper; +namespace linkahead::acm { +using linkahead::utility::ScalarProtoMessageWrapper; using ProtoUser = caosdb::acm::v1alpha1::User; UserImpl::UserImpl() = default; @@ -113,4 +113,4 @@ auto User::SetPassword(const std::string &password) -> void { auto User::ToString() const -> std::string { return this->wrapped->ToString(); } -} // namespace caosdb::acm +} // namespace linkahead::acm diff --git a/src/caosdb/acm/user_impl.h b/src/linkahead/acm/user_impl.h similarity index 84% rename from src/caosdb/acm/user_impl.h rename to src/linkahead/acm/user_impl.h index ea2e0da6738942f922d158f3adfa03d81c0c862a..3ba072f0f4fa6052c3d8028fe68327a2eafefda0 100644 --- a/src/caosdb/acm/user_impl.h +++ b/src/linkahead/acm/user_impl.h @@ -1,5 +1,5 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * * Copyright (C) 2022 Timm Fitschen <t.fitschen@indiscale.com> * Copyright (C) 2022 IndiScale GmbH <info@indiscale.com> @@ -18,14 +18,14 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ -#include "caosdb/acm/user.h" +#include "linkahead/acm/user.h" #include "caosdb/acm/v1alpha1/main.pb.h" // for ProtoUser -#include "caosdb/protobuf_helper.h" // for ProtoMessageWrapper +#include "linkahead/protobuf_helper.h" // for ProtoMessageWrapper #include <memory> // for unique_ptr #include <utility> // for move -namespace caosdb::acm { -using caosdb::utility::ScalarProtoMessageWrapper; +namespace linkahead::acm { +using linkahead::utility::ScalarProtoMessageWrapper; using ProtoUser = caosdb::acm::v1alpha1::User; /** @@ -49,10 +49,10 @@ public: UserImpl(ProtoUser *user); friend class User; - friend class caosdb::connection::Connection; + friend class linkahead::connection::Connection; private: std::string password; }; -} // namespace caosdb::acm +} // namespace linkahead::acm diff --git a/src/caosdb/authentication.cpp b/src/linkahead/authentication.cpp similarity index 71% rename from src/caosdb/authentication.cpp rename to src/linkahead/authentication.cpp index 7faa8619b4153c8ff3c03549369b7d976a62e035..bebe747e32018e99a63b68337852016b38292e1c 100644 --- a/src/caosdb/authentication.cpp +++ b/src/linkahead/authentication.cpp @@ -1,8 +1,8 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -18,19 +18,22 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ -#include "caosdb/authentication.h" -#include <grpcpp/security/credentials.h> // for MetadataCredentialsPlugin -#include <map> // for multimap -#include <memory> // for allocator, shared_ptr -#include <string> // for basic_string, operator+ -#include <utility> // for pair, move, make_pair +#include "linkahead/authentication.h" +#include <grpcpp/security/auth_context.h> // for AuthContext +#include <grpcpp/security/credentials.h> // for MetadataCredentialsPlugin +#include <grpcpp/support/status.h> // for Status +#include <map> // for multimap +#include <memory> // for allocator, shared_ptr, uni... +#include <string> // for basic_string, operator+ +#include <utility> // for pair, move, make_pair +#include "linkahead/utility.h" // for base64_encode -namespace caosdb::authentication { -using caosdb::utility::base64_encode; +namespace linkahead::authentication { using grpc::AuthContext; using grpc::MetadataCredentialsPlugin; using grpc::Status; using grpc::string_ref; +using linkahead::utility::base64_encode; MetadataCredentialsPluginImpl::MetadataCredentialsPluginImpl(std::string key, std::string value) : key(std::move(key)), value(std::move(value)) {} @@ -58,4 +61,4 @@ auto PlainPasswordAuthenticator::GetCallCredentials() const return call_creds; } -} // namespace caosdb::authentication +} // namespace linkahead::authentication diff --git a/src/caosdb/configuration.cpp b/src/linkahead/configuration.cpp similarity index 78% rename from src/caosdb/configuration.cpp rename to src/linkahead/configuration.cpp index e1ffb23b3b1a2db5ecea79588c237bb36e79b1e1..377c8241e7b72619e3898994dabdb013dc47fca0 100644 --- a/src/caosdb/configuration.cpp +++ b/src/linkahead/configuration.cpp @@ -1,8 +1,8 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -18,32 +18,31 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ -#include "caosdb/configuration.h" -#include "caosdb/authentication.h" // for Authenticator -#include "caosdb/connection.h" // for ConnectionManager -#include "caosdb/constants.h" // for LIBCAOSDB_CONF... -#include "caosdb/exceptions.h" // for ConfigurationE... -#include "caosdb/log_level.h" // for CAOSDB_DEFAULT... -#include "caosdb/logging.h" // for SinkConfiguration, Loggin... -#include "caosdb/status_code.h" // for StatusCode -#include "caosdb/utility.h" // for get_home_direc... -#include <boost/json/impl/object.hpp> // for object::at -#include <boost/json/object.hpp> // for object, objec... -#include <boost/json/string.hpp> // for string -#include <boost/json/string_view.hpp> // for string_view -#include <boost/json/value.hpp> // for value, key_va... -#include <boost/json/value_ref.hpp> // for object -#include <cassert> // for assert -#include <cstdlib> // for getenv -#include <cstring> // for strcmp -#include <exception> // IWYU pragma: keep -// IWYU pragma: no_include <bits/exception.h> -#include <grpcpp/security/credentials.h> // for SslCredentials +#include "linkahead/configuration.h" +#include <grpcpp/security/credentials.h> // for SslCredentialsOptions, SslC... +#include <boost/json/impl/object.hpp> // for object::at, object::empty +#include <boost/json/object.hpp> // for object +#include <boost/json/string.hpp> // for string +#include <boost/json/value.hpp> // for value +#include <boost/json/value_ref.hpp> // for object +#include <cassert> // for assert +#include <cstdlib> // for getenv +#include <cstring> // for strcmp +#include <exception> // for exception #include <iterator> // for next #include <map> // for map +#include <ostream> // for basic_ios, basic_ostream #include <stdexcept> // for out_of_range -#include <string> // for string, operator+ -#include <utility> // for move +#include <string> // for basic_string, operator+ +#include <utility> // for pair, move +#include "linkahead/authentication.h" // for Authenticator, PlainPasswor... +#include "linkahead/connection.h" // for ConnectionManager +#include "linkahead/constants.h" // for LIBLINKAHEAD_CONFIGURATION_... +#include "linkahead/exceptions.h" // for ConfigurationError, Exception +#include "linkahead/log_level.h" // for LINKAHEAD_LOG_LEVEL_OFF +#include "linkahead/logging.h" // for FileSinkConfiguration, Cons... +#include "linkahead/status_code.h" // for StatusCode +#include "linkahead/utility.h" // for JsonValue, get_home_directory // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define WRAPPED_JSON_CONFIGURATION(obj) \ @@ -52,41 +51,44 @@ // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define GET_CONNECTIONS \ if (!this->json_configuration.wrapped) { \ - throw ConfigurationError("This CaosDB client has not been configured."); \ + throw ConfigurationError("This LinkAhead client has not been configured."); \ } \ assert(WRAPPED_JSON_CONFIGURATION(this)->is_object()); \ const auto &configuration = WRAPPED_JSON_CONFIGURATION(this)->as_object(); \ if (!configuration.contains("connections")) { \ - throw ConfigurationError("This CaosDB client hasn't any configured connections."); \ + throw ConfigurationError("This LinkAhead client hasn't any configured connections."); \ } \ const auto &connections_value = configuration.at("connections"); \ if (connections_value.is_null()) { \ - throw ConfigurationError("This CaosDB client hasn't any configured connections."); \ + throw ConfigurationError("This LinkAhead client hasn't any configured connections."); \ } \ assert(connections_value.is_object()); \ const auto &connections = connections_value.as_object(); \ if (connections.empty()) { \ - throw ConfigurationError("This CaosDB client hasn't any configured connections."); \ + throw ConfigurationError("This LinkAhead client hasn't any configured connections."); \ } -namespace caosdb::configuration { +namespace linkahead::configuration { + +ConfigurationManager ConfigurationManager::mInstance; + using boost::json::object; using boost::json::value; -using caosdb::authentication::Authenticator; -using caosdb::authentication::PlainPasswordAuthenticator; -using caosdb::connection::ConnectionManager; -using caosdb::exceptions::ConfigurationError; -using caosdb::logging::ConsoleSinkConfiguration; -using caosdb::logging::FileSinkConfiguration; -using caosdb::logging::LoggingConfiguration; -using caosdb::logging::SinkConfiguration; -using caosdb::logging::SyslogSinkConfiguration; -using caosdb::utility::get_home_directory; -using caosdb::utility::load_json_file; -using caosdb::utility::load_string_file; using grpc::InsecureChannelCredentials; using grpc::SslCredentials; using grpc::SslCredentialsOptions; +using linkahead::authentication::Authenticator; +using linkahead::authentication::PlainPasswordAuthenticator; +using linkahead::connection::ConnectionManager; +using linkahead::exceptions::ConfigurationError; +using linkahead::logging::ConsoleSinkConfiguration; +using linkahead::logging::FileSinkConfiguration; +using linkahead::logging::LoggingConfiguration; +using linkahead::logging::SinkConfiguration; +using linkahead::logging::SyslogSinkConfiguration; +using linkahead::utility::get_home_directory; +using linkahead::utility::load_json_file; +using linkahead::utility::load_string_file; using std::filesystem::exists; using std::filesystem::path; @@ -274,19 +276,19 @@ auto CreateConnectionConfiguration(const object &from) -> std::unique_ptr<Connec } auto CreateConsoleSinkConfiguration(const object & /*from*/, const std::string &name, int level) - -> std::shared_ptr<caosdb::logging::SinkConfiguration> { + -> std::shared_ptr<linkahead::logging::SinkConfiguration> { auto result = std::make_shared<ConsoleSinkConfiguration>(name, level); return result; } auto CreateSyslogSinkConfiguration(const object & /*from*/, const std::string &name, int level) - -> std::shared_ptr<caosdb::logging::SinkConfiguration> { + -> std::shared_ptr<linkahead::logging::SinkConfiguration> { auto result = std::make_shared<SyslogSinkConfiguration>(name, level); return result; } auto CreateFileSinkConfiguration(const object &from, const std::string &name, int level) - -> std::shared_ptr<caosdb::logging::SinkConfiguration> { + -> std::shared_ptr<linkahead::logging::SinkConfiguration> { auto result = std::make_shared<FileSinkConfiguration>(name, level); if (from.contains("directory")) { result->SetDirectory(from.at("directory").as_string().c_str()); @@ -296,11 +298,11 @@ auto CreateFileSinkConfiguration(const object &from, const std::string &name, in auto ConvertLogLevel(const std::string &string_level) -> int { static std::map<std::string, int> log_level_names = { - {"", CAOSDB_DEFAULT_LOG_LEVEL}, {"off", CAOSDB_LOG_LEVEL_OFF}, - {"fatal", CAOSDB_LOG_LEVEL_FATAL}, {"error", CAOSDB_LOG_LEVEL_ERROR}, - {"warn", CAOSDB_LOG_LEVEL_WARN}, {"info", CAOSDB_LOG_LEVEL_INFO}, - {"debug", CAOSDB_LOG_LEVEL_DEBUG}, {"trace", CAOSDB_LOG_LEVEL_TRACE}, - {"all", CAOSDB_LOG_LEVEL_ALL}}; + {"", LINKAHEAD_DEFAULT_LOG_LEVEL}, {"off", LINKAHEAD_LOG_LEVEL_OFF}, + {"fatal", LINKAHEAD_LOG_LEVEL_FATAL}, {"error", LINKAHEAD_LOG_LEVEL_ERROR}, + {"warn", LINKAHEAD_LOG_LEVEL_WARN}, {"info", LINKAHEAD_LOG_LEVEL_INFO}, + {"debug", LINKAHEAD_LOG_LEVEL_DEBUG}, {"trace", LINKAHEAD_LOG_LEVEL_TRACE}, + {"all", LINKAHEAD_LOG_LEVEL_ALL}}; try { return log_level_names.at(string_level); } catch (const std::out_of_range &exc) { @@ -309,7 +311,7 @@ auto ConvertLogLevel(const std::string &string_level) -> int { } auto CreateSinkConfiguration(const object &from, const std::string &name, int default_level) - -> std::shared_ptr<caosdb::logging::SinkConfiguration> { + -> std::shared_ptr<linkahead::logging::SinkConfiguration> { assert(from.contains("destination")); const auto &destination = std::string(from.at("destination").as_string().c_str()); @@ -333,7 +335,7 @@ auto CreateLoggingConfiguration(const object &from) -> LoggingConfiguration { int default_level = ConvertLogLevel(default_level_str); auto result = LoggingConfiguration(default_level); - if (default_level == CAOSDB_LOG_LEVEL_OFF) { + if (default_level == LINKAHEAD_LOG_LEVEL_OFF) { return result; } @@ -343,7 +345,7 @@ auto CreateLoggingConfiguration(const object &from) -> LoggingConfiguration { const auto *elem = sinks.begin(); while (elem != sinks.end()) { - result.AddSink(CreateSinkConfiguration(elem->value().as_object(), elem->key().to_string(), + result.AddSink(CreateSinkConfiguration(elem->value().as_object(), std::string(elem->key()), default_level)); elem = std::next(elem); } @@ -358,11 +360,11 @@ auto ConfigurationManager::mReset() noexcept -> int { mClear(); InitializeDefaults(); return StatusCode::SUCCESS; - } catch (const caosdb::exceptions::Exception &exc) { + } catch (const linkahead::exceptions::Exception &exc) { return exc.GetCode(); } catch (const std::exception &exc) { - CAOSDB_LOG_ERROR(logger_name) << "Unknown error during the reset of the ConfigurationManager: " - << exc.what(); + LINKAHEAD_LOG_ERROR(logger_name) + << "Unknown error during the reset of the ConfigurationManager: " << exc.what(); return StatusCode::CONFIGURATION_ERROR; } } @@ -372,18 +374,18 @@ auto ConfigurationManager::mClear() noexcept -> int { json_configuration.Reset(); ConnectionManager::Reset(); return StatusCode::SUCCESS; - } catch (const caosdb::exceptions::Exception &exc) { + } catch (const linkahead::exceptions::Exception &exc) { return exc.GetCode(); } catch (const std::exception &exc) { - CAOSDB_LOG_ERROR(logger_name) << "Unknown error during the reset of the ConfigurationManager: " - << exc.what(); + LINKAHEAD_LOG_ERROR(logger_name) + << "Unknown error during the reset of the ConfigurationManager: " << exc.what(); return StatusCode::CONFIGURATION_ERROR; } } auto ConfigurationManager::mLoadSingleJSONConfiguration(const path &json_file) -> void { if (json_configuration.wrapped) { - throw ConfigurationError("This CaosDB client has already been configured."); + throw ConfigurationError("This LinkAhead client has already been configured."); } if (!exists(json_file)) { throw ConfigurationError("Configuration file does not exist."); @@ -419,21 +421,24 @@ auto ConfigurationManager::mGetDefaultConnectionName() const -> std::string { } if (connections.size() == 1) { // return the key of the first and only sub-element of connections. - return connections.begin()->key().to_string(); + return std::string(connections.begin()->key()); } throw ConfigurationError("Could not determine the default connection."); } +ConfigurationManager &ConfigurationManager::GetInstance() { return mInstance; } + // TODO(tf) This has apparently a cognitive complexity of 34>25 (threshold). auto ConfigurationManager::InitializeDefaults() -> int { // NOLINT // find the configuration file... std::unique_ptr<path> configuration_file_path; - for (const char *const &configuration_file : caosdb::LIBCAOSDB_CONFIGURATION_FILES_PRECEDENCE) { - if (strcmp(configuration_file, "$CAOSDB_CLIENT_CONFIGURATION") == 0) { + for (const char *const &configuration_file : + linkahead::LIBLINKAHEAD_CONFIGURATION_FILES_PRECEDENCE) { + if (strcmp(configuration_file, "$LINKAHEAD_CLIENT_CONFIGURATION") == 0) { // user specified a file via the environment variable // TODO(tf) make this thread-secure (concurrency-mt-unsafe) - const auto *from_env_var = getenv("CAOSDB_CLIENT_CONFIGURATION"); // NOLINT + const auto *from_env_var = getenv("LINKAHEAD_CLIENT_CONFIGURATION"); // NOLINT if (from_env_var != nullptr) { configuration_file_path = std::make_unique<path>(from_env_var); if (exists(*configuration_file_path)) { @@ -441,7 +446,7 @@ auto ConfigurationManager::InitializeDefaults() -> int { // NOLINT } else { configuration_file_path = nullptr; // TODO(tf) log warning: "Configuration file under - // $CAOSDB_CLIENT_CONFIGURATION does not exist. + // $LINKAHEAD_CLIENT_CONFIGURATION does not exist. } } } else { @@ -478,14 +483,14 @@ auto ConfigurationManager::InitializeDefaults() -> int { // NOLINT logging::initialize_logging(logging_configuration); } else { logging::initialize_logging_defaults(); - CAOSDB_LOG_INFO(logger_name) << "No logging configuration has been found. " - "We are using the default configuration"; + LINKAHEAD_LOG_INFO(logger_name) << "No logging configuration has been found. " + "We are using the default configuration"; } if (configuration_file_path != nullptr && this->json_configuration.wrapped && WRAPPED_JSON_CONFIGURATION(this)->is_object()) { - CAOSDB_LOG_INFO(logger_name) << "Loaded configuration from " << *(configuration_file_path) - << "."; + LINKAHEAD_LOG_INFO(logger_name) + << "Loaded configuration from " << *(configuration_file_path) << "."; } return 0; @@ -493,4 +498,4 @@ auto ConfigurationManager::InitializeDefaults() -> int { // NOLINT const int IS_INITIALIZED = ConfigurationManager::Reset(); -} // namespace caosdb::configuration +} // namespace linkahead::configuration diff --git a/src/caosdb/connection.cpp b/src/linkahead/connection.cpp similarity index 74% rename from src/caosdb/connection.cpp rename to src/linkahead/connection.cpp index 4c77c5254c1300e908622882cd01d29d7b0aab65..717f7d96b5bffdb3e9b96d23d1ff731b920ad3b2 100644 --- a/src/caosdb/connection.cpp +++ b/src/linkahead/connection.cpp @@ -1,6 +1,6 @@ /* * - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * * Copyright (C) 2021-2022 Timm Fitschen <t.fitschen@indiscale.com> * Copyright (C) 2021-2022 IndiScale GmbH <info@indiscale.com> @@ -19,46 +19,56 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ -#include "caosdb/connection.h" +#include "linkahead/connection.h" #ifdef BUILD_ACM -#include "caosdb/acm/user_impl.h" // for UserImpl +#include "linkahead/acm/user_impl.h" // for UserImpl #include "caosdb/acm/v1alpha1/main.grpc.pb.h" // for AccessControlMan... #include "caosdb/acm/v1alpha1/main.pb.h" // for CreateSingleUser... #endif -#include "caosdb/configuration.h" // for ConnectionConfigur... -#include "caosdb/exceptions.h" // for ConfigurationError -#include "caosdb/info.h" // for VersionInfo -#include "caosdb/info/v1/main.grpc.pb.h" // for GeneralInfoService -#include "caosdb/info/v1/main.pb.h" // for GetVersionInfoRequest -#include "caosdb/transaction.h" // for Transaction -#include "caosdb/transaction_status.h" // for TransactionStatus -#include <grpcpp/client_context.h> // for ClientContext -#include <grpcpp/create_channel.h> // for CreateChannel -#include <grpcpp/support/status.h> // for Status -#include <string> // for string, operator+ +#include "linkahead/configuration.h" // for ConnectionConfigur... +#include "linkahead/exceptions.h" // for ConfigurationError +#include "linkahead/info.h" // for VersionInfo +#include "caosdb/info/v1/main.grpc.pb.h" // for GeneralInfoService +#include "caosdb/info/v1/main.pb.h" // for GetVersionInfoRequest +#include "linkahead/transaction.h" // for Transaction +#include "linkahead/transaction_status.h" // for TransactionStatus +#include <grpcpp/client_context.h> // for ClientContext +#include <grpcpp/create_channel.h> // for CreateChannel +#include <grpcpp/support/status.h> // for Status +#include <string> // for string, operator+ +#include <memory> // for make_shared +#ifdef BUILD_ACM +#include <vector> // for vector +#endif // IWYU pragma: no_include "net/proto2/public/repeated_field.h" -namespace caosdb::connection { +namespace linkahead::connection { #ifdef BUILD_ACM -using caosdb::acm::UserImpl; using caosdb::acm::v1alpha1::AccessControlManagementService; using caosdb::acm::v1alpha1::CreateSingleUserRequest; using caosdb::acm::v1alpha1::CreateSingleUserResponse; using caosdb::acm::v1alpha1::DeleteSingleUserRequest; using caosdb::acm::v1alpha1::DeleteSingleUserResponse; +using caosdb::acm::v1alpha1::ListUsersRequest; +using caosdb::acm::v1alpha1::ListUsersResponse; using caosdb::acm::v1alpha1::RetrieveSingleUserRequest; using caosdb::acm::v1alpha1::RetrieveSingleUserResponse; +using linkahead::acm::UserImpl; #endif -using caosdb::configuration::ConfigurationManager; -using caosdb::configuration::ConnectionConfiguration; using caosdb::entity::v1::EntityTransactionService; using caosdb::entity::v1::FileTransmissionService; -using caosdb::info::VersionInfo; using caosdb::info::v1::GeneralInfoService; using caosdb::info::v1::GetVersionInfoRequest; using caosdb::info::v1::GetVersionInfoResponse; -using caosdb::transaction::Transaction; -using caosdb::transaction::TransactionStatus; +using linkahead::configuration::ConfigurationManager; +using linkahead::configuration::ConnectionConfiguration; +using linkahead::info::VersionInfo; +using linkahead::transaction::Transaction; +using linkahead::transaction::TransactionStatus; + +ConnectionManager ConnectionManager::mInstance; + +ConnectionManager &ConnectionManager::GetInstance() { return mInstance; } Connection::Connection(const ConnectionConfiguration &configuration) { const std::string target = @@ -204,6 +214,37 @@ auto Connection::CreateSingleUser(const User &user) const -> void { } status.ThrowExceptionIfError(); } + +auto Connection::ListUsers() const -> std::vector<User> { + ListUsersRequest request; + ListUsersResponse response; + grpc::ClientContext context; + const grpc::Status grpc_status = + this->access_controll_management_service->ListUsers(&context, request, &response); + auto status = TransactionStatus::SUCCESS(); + if (!grpc_status.ok()) { + switch (grpc_status.error_code()) { + case grpc::StatusCode::UNAUTHENTICATED: + status = TransactionStatus::AUTHENTICATION_ERROR(grpc_status.error_message()); + break; + case grpc::StatusCode::UNAVAILABLE: + status = TransactionStatus::CONNECTION_ERROR(); + break; + default: + auto error_message = grpc_status.error_message(); + status = TransactionStatus::RPC_ERROR(std::to_string(grpc_status.error_code()) + " - " + + error_message); + } + } + status.ThrowExceptionIfError(); + + std::vector<User> results; + for (auto &user : *(response.mutable_users())) { + results.push_back(User(std::make_unique<UserImpl>(&user))); + } + + return results; +} #endif auto ConnectionManager::mHasConnection(const std::string &name) const -> bool { @@ -217,9 +258,9 @@ auto ConnectionManager::mGetConnection(const std::string &name) const try { auto connection = ConfigurationManager::GetConnectionConfiguration(name); connections[name] = std::make_shared<Connection>(*connection.release()); - } catch (const caosdb::exceptions::ConfigurationError &exc) { - throw caosdb::exceptions::ConnectionConfigurationError("Error with the connection named '" + - name + "': " + exc.what()); + } catch (const linkahead::exceptions::ConfigurationError &exc) { + throw linkahead::exceptions::ConnectionConfigurationError( + "Error with the connection named '" + name + "': " + exc.what()); } } return this->connections.at(name); @@ -236,4 +277,4 @@ auto ConnectionManager::mGetDefaultConnection() const -> const std::shared_ptr<C return connections.at(default_connection_name); } -} // namespace caosdb::connection +} // namespace linkahead::connection diff --git a/src/caosdb/entity.cpp b/src/linkahead/entity.cpp similarity index 93% rename from src/caosdb/entity.cpp rename to src/linkahead/entity.cpp index 568cc5d97c38c8af0bf8fd632d93cb9b9bc4b2f1..b4230444d6f2c0b8281e4e70e0b50220d64247ed 100644 --- a/src/caosdb/entity.cpp +++ b/src/linkahead/entity.cpp @@ -1,9 +1,9 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> * Copyright (C) 2021 Florian Spreckelsen <f.spreckelsen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -19,14 +19,16 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ -#include "caosdb/entity.h" -#include "caosdb/data_type.h" // for DataType -#include "caosdb/entity/v1/main.pb.h" // for Messages -#include "caosdb/protobuf_helper.h" // for get_arena -#include "caosdb/value.h" // for Value -#include <google/protobuf/arena.h> // for Arena - -namespace caosdb::entity { +#include "linkahead/entity.h" +#include "linkahead/data_type.h" // for DataType +#include "caosdb/entity/v1/main.pb.h" // for Messages +#include "linkahead/protobuf_helper.h" // for get_arena +#include "linkahead/status_code.h" // for StatusCode +#include <google/protobuf/arena.h> // for Arena +#include <string> // for string +#include <vector> // for vector + +namespace linkahead::entity { using ProtoParent = caosdb::entity::v1::Parent; using ProtoProperty = caosdb::entity::v1::Property; using ProtoEntity = caosdb::entity::v1::Entity; @@ -34,8 +36,8 @@ using ProtoImportance = caosdb::entity::v1::Importance; using caosdb::entity::v1::EntityRole; using ProtoMessage = caosdb::entity::v1::Message; using ProtoFileDescriptor = caosdb::entity::v1::FileDescriptor; -using caosdb::utility::get_arena; using google::protobuf::Arena; +using linkahead::utility::get_arena; // Parent ///////////////////////////////////////////////////////////////////// @@ -270,4 +272,4 @@ auto Entity::SetFilePath(const std::string &path) -> void { this->wrapped->mutable_file_descriptor()->set_path(path); } -} // namespace caosdb::entity +} // namespace linkahead::entity diff --git a/src/caosdb/file_transmission/download_request_handler.cpp b/src/linkahead/file_transmission/download_request_handler.cpp similarity index 66% rename from src/caosdb/file_transmission/download_request_handler.cpp rename to src/linkahead/file_transmission/download_request_handler.cpp index 1b0764fa2039b7d4c37ba09fdc03cedf4959736a..ae1e9cb88199ccdf366c28b69622865e8b640c46 100644 --- a/src/caosdb/file_transmission/download_request_handler.cpp +++ b/src/linkahead/file_transmission/download_request_handler.cpp @@ -1,5 +1,5 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * Copyright (C) 2021-2022 Timm Fitschen <t.fitschen@indiscale.com> * Copyright (C) 2021-2022 IndiScale GmbH <info@indiscale.com> * @@ -46,27 +46,26 @@ * > FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * > DEALINGS IN THE SOFTWARE. */ -#include "caosdb/file_transmission/download_request_handler.h" -#include "caosdb/logging.h" // for CAOSDB_LOG_TRACE -#include "caosdb/protobuf_helper.h" // for get_arena -#include "caosdb/status_code.h" // for GENERIC_RPC_E... -#include "caosdb/transaction_status.h" // for TransactionStatus -#include <exception> // IWYU pragma: keep -#include <filesystem> // for operator<<, path -#include <google/protobuf/arena.h> // for Arena -#include <grpcpp/client_context.h> // for ClientContext -#include <grpcpp/completion_queue.h> // for CompletionQueue -#include <grpcpp/support/async_stream.h> // for ClientAsyncReader -#include <grpcpp/support/status.h> // for Status -#include <stdexcept> // for runtime_error -#include <string> // for string, opera... -#include <utility> // for move +#include "linkahead/file_transmission/download_request_handler.h" +#include <google/protobuf/arena.h> // for Arena +#include <grpcpp/client_context.h> // for ClientContext +#include <grpcpp/completion_queue.h> // for CompletionQueue +#include <grpcpp/support/async_stream.h> // for ClientAsyncReader +#include <grpcpp/support/status.h> // for Status, StatusCode +#include <exception> // for exception +#include <stdexcept> // for runtime_error +#include <string> // for basic_string, operator+ +#include <utility> // for move +#include "linkahead/logging.h" // for LoggerOutputStream, LINKAH... +#include "linkahead/protobuf_helper.h" // for get_arena +#include "linkahead/status_code.h" // for get_status_description +#include "linkahead/transaction_status.h" // for TransactionStatus // IWYU pragma: no_include <bits/exception.h> // -namespace caosdb::transaction { -using caosdb::StatusCode; -using caosdb::utility::get_arena; +namespace linkahead::transaction { using google::protobuf::Arena; +using linkahead::StatusCode; +using linkahead::utility::get_arena; DownloadRequestHandler::DownloadRequestHandler(HandlerTag tag, FileTransmissionService::Stub *stub, grpc::CompletionQueue *cq, @@ -96,11 +95,11 @@ bool DownloadRequestHandler::OnNext(bool ok) { return true; } catch (std::exception &e) { - CAOSDB_LOG_ERROR(logger_name) << "DownloadRequestHandler caught an exception: " << e.what(); + LINKAHEAD_LOG_ERROR(logger_name) << "DownloadRequestHandler caught an exception: " << e.what(); transaction_status = TransactionStatus::GENERIC_ERROR(e.what()); state_ = CallState::CallComplete; } catch (...) { - CAOSDB_LOG_ERROR(logger_name) << "Transaction error: unknown exception caught"; + LINKAHEAD_LOG_ERROR(logger_name) << "Transaction error: unknown exception caught"; transaction_status = TransactionStatus::GENERIC_ERROR("DownloadRequestHandler caught an unknown exception"); state_ = CallState::CallComplete; @@ -121,9 +120,9 @@ void DownloadRequestHandler::Cancel() { } void DownloadRequestHandler::handleNewCallState() { - CAOSDB_LOG_TRACE(logger_name) << "Enter DownloadRequestHandler::handleNewCallState. local_path = " - << file_descriptor_.local_path - << ", download_id = " << file_descriptor_.file_transmission_id; + LINKAHEAD_LOG_TRACE(logger_name) + << "Enter DownloadRequestHandler::handleNewCallState. local_path = " + << file_descriptor_.local_path << ", download_id = " << file_descriptor_.file_transmission_id; fileWriter_ = std::make_unique<FileWriter>(file_descriptor_.local_path); auto *tid = request_->mutable_file_transmission_id(); @@ -134,22 +133,22 @@ void DownloadRequestHandler::handleNewCallState() { transaction_status = TransactionStatus::EXECUTING(); state_ = CallState::SendingRequest; rpc_->StartCall(tag_); - CAOSDB_LOG_TRACE(logger_name) << "Leave DownloadRequestHandler::handleNewCallState"; + LINKAHEAD_LOG_TRACE(logger_name) << "Leave DownloadRequestHandler::handleNewCallState"; } void DownloadRequestHandler::handleSendingRequestState() { - CAOSDB_LOG_TRACE(logger_name) << "Enter DownloadRequestHandler::handleSendingRequestState"; + LINKAHEAD_LOG_TRACE(logger_name) << "Enter DownloadRequestHandler::handleSendingRequestState"; state_ = CallState::ReceivingFile; rpc_->Read(response_, tag_); - CAOSDB_LOG_TRACE(logger_name) << "Leave DownloadRequestHandler::handleSendingRequestState"; + LINKAHEAD_LOG_TRACE(logger_name) << "Leave DownloadRequestHandler::handleSendingRequestState"; } void DownloadRequestHandler::handleReceivingFileState() { - CAOSDB_LOG_TRACE(logger_name) << "Enter DownloadRequestHandler::handleReceivingFileState"; + LINKAHEAD_LOG_TRACE(logger_name) << "Enter DownloadRequestHandler::handleReceivingFileState"; if (response_->has_chunk()) { const auto &chunkData = response_->chunk().data(); if (chunkData.empty()) { - CAOSDB_LOG_DEBUG(logger_name) << "Received an empty FileChunk, ignoring"; + LINKAHEAD_LOG_DEBUG(logger_name) << "Received an empty FileChunk, ignoring"; } else { fileWriter_->write(chunkData); bytesReceived_ += chunkData.size(); @@ -161,30 +160,30 @@ void DownloadRequestHandler::handleReceivingFileState() { } else { throw std::runtime_error("File chunk expected"); } - CAOSDB_LOG_TRACE(logger_name) << "Leave DownloadRequestHandler::handleReceivingFileState"; + LINKAHEAD_LOG_TRACE(logger_name) << "Leave DownloadRequestHandler::handleReceivingFileState"; } void DownloadRequestHandler::handleCallCompleteState() { - CAOSDB_LOG_TRACE(logger_name) << "Enter DownloadRequestHandler::handleCallCompleteState"; + LINKAHEAD_LOG_TRACE(logger_name) << "Enter DownloadRequestHandler::handleCallCompleteState"; switch (status_.error_code()) { case grpc::OK: { - CAOSDB_LOG_INFO(logger_name) << "DownloadRequestHandler finished successfully (" - << file_descriptor_.local_path << "): Download complete, " - << bytesReceived_ << " bytes received."; + LINKAHEAD_LOG_INFO(logger_name) + << "DownloadRequestHandler finished successfully (" << file_descriptor_.local_path + << "): Download complete, " << bytesReceived_ << " bytes received."; } break; default: { auto code(static_cast<StatusCode>(status_.error_code())); std::string description(get_status_description(code) + " Original message: " + status_.error_message()); transaction_status = TransactionStatus(code, description); - CAOSDB_LOG_ERROR(logger_name) << "DownloadRequestHandler finished with an error (" - << file_descriptor_.local_path << "): Download aborted with code " - << code << " - " << description; + LINKAHEAD_LOG_ERROR(logger_name) + << "DownloadRequestHandler finished with an error (" << file_descriptor_.local_path + << "): Download aborted with code " << code << " - " << description; } break; } - CAOSDB_LOG_TRACE(logger_name) << "Leave DownloadRequestHandler::handleCallCompleteState"; + LINKAHEAD_LOG_TRACE(logger_name) << "Leave DownloadRequestHandler::handleCallCompleteState"; } -} // namespace caosdb::transaction +} // namespace linkahead::transaction diff --git a/src/caosdb/file_transmission/file_reader.cpp b/src/linkahead/file_transmission/file_reader.cpp similarity index 87% rename from src/caosdb/file_transmission/file_reader.cpp rename to src/linkahead/file_transmission/file_reader.cpp index 3f82b8c8c775d38f2a75e2a995ce7cfa8bb7cceb..d2d39b5a9afb9b4edc3755a1ea0ed569ec569b3e 100644 --- a/src/caosdb/file_transmission/file_reader.cpp +++ b/src/linkahead/file_transmission/file_reader.cpp @@ -1,7 +1,7 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -46,12 +46,12 @@ * > FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * > DEALINGS IN THE SOFTWARE. */ -#include "caosdb/file_transmission/file_reader.h" -#include "caosdb/file_transmission/file_error.h" // for FileIOError -#include <filesystem> // for path -#include <utility> // for move +#include "linkahead/file_transmission/file_reader.h" +#include "linkahead/file_transmission/file_error.h" // for FileIOError +#include <filesystem> // for path +#include <utility> // for move -namespace caosdb::transaction { +namespace linkahead::transaction { FileReader::FileReader(std::filesystem::path filename) : filename_(std::move(filename)), size_(0) { this->openFile(); @@ -88,4 +88,4 @@ std::size_t FileReader::read(std::string &buffer) { return bytesRead; } -} // namespace caosdb::transaction +} // namespace linkahead::transaction diff --git a/src/caosdb/file_transmission/file_writer.cpp b/src/linkahead/file_transmission/file_writer.cpp similarity index 86% rename from src/caosdb/file_transmission/file_writer.cpp rename to src/linkahead/file_transmission/file_writer.cpp index 0f0161fbcafe1df7f6ffa271dcce8af9cc10fe82..e6030c05352e977d031d88b491d6ebfdd5686075 100644 --- a/src/caosdb/file_transmission/file_writer.cpp +++ b/src/linkahead/file_transmission/file_writer.cpp @@ -1,7 +1,7 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -46,12 +46,12 @@ * > FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * > DEALINGS IN THE SOFTWARE. */ -#include "caosdb/file_transmission/file_writer.h" -#include "caosdb/file_transmission/file_error.h" // for FileIOError -#include <filesystem> // for path -#include <utility> // for move +#include "linkahead/file_transmission/file_writer.h" +#include "linkahead/file_transmission/file_error.h" // for FileIOError +#include <filesystem> // for path +#include <utility> // for move -namespace caosdb::transaction { +namespace linkahead::transaction { FileWriter::FileWriter(std::filesystem::path filename) : filename_(std::move(filename)) { this->openFile(); @@ -74,4 +74,4 @@ void FileWriter::write(const std::string &buffer) { } } -} // namespace caosdb::transaction +} // namespace linkahead::transaction diff --git a/src/caosdb/file_transmission/register_file_upload_handler.cpp b/src/linkahead/file_transmission/register_file_upload_handler.cpp similarity index 85% rename from src/caosdb/file_transmission/register_file_upload_handler.cpp rename to src/linkahead/file_transmission/register_file_upload_handler.cpp index 3a47715c75eb797120e1a0116c37743ef6d2b92a..a17a77c8a2c96a2fe9c365c0ef687879abb4d917 100644 --- a/src/caosdb/file_transmission/register_file_upload_handler.cpp +++ b/src/linkahead/file_transmission/register_file_upload_handler.cpp @@ -1,7 +1,7 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -46,10 +46,10 @@ * > FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * > DEALINGS IN THE SOFTWARE. */ -#include "caosdb/file_transmission/register_file_upload_handler.h" -#include "caosdb/logging.h" // for CAOSDB_LOG_TRACE +#include "linkahead/file_transmission/register_file_upload_handler.h" +#include "linkahead/logging.h" // for LINKAHEAD_LOG_TRACE -namespace caosdb::transaction { +namespace linkahead::transaction { RegisterFileUploadHandler::~RegisterFileUploadHandler() = default; @@ -62,7 +62,7 @@ RegisterFileUploadHandler::RegisterFileUploadHandler(HandlerTag tag, response_(response) {} void RegisterFileUploadHandler::handleNewCallState() { - CAOSDB_LOG_TRACE(logger_name) << "Enter RegisterFileUploadHandler::handleNewCallState."; + LINKAHEAD_LOG_TRACE(logger_name) << "Enter RegisterFileUploadHandler::handleNewCallState."; rpc_ = stub_->PrepareAsyncRegisterFileUpload(&call_context, *request_, completion_queue); @@ -70,7 +70,7 @@ void RegisterFileUploadHandler::handleNewCallState() { rpc_->StartCall(); rpc_->Finish(response_, &status_, tag_); - CAOSDB_LOG_TRACE(logger_name) << "Leave RegisterFileUploadHandler::handleNewCallState"; + LINKAHEAD_LOG_TRACE(logger_name) << "Leave RegisterFileUploadHandler::handleNewCallState"; } -} // namespace caosdb::transaction +} // namespace linkahead::transaction diff --git a/src/caosdb/file_transmission/upload_request_handler.cpp b/src/linkahead/file_transmission/upload_request_handler.cpp similarity index 82% rename from src/caosdb/file_transmission/upload_request_handler.cpp rename to src/linkahead/file_transmission/upload_request_handler.cpp index 57bd224dfe53a57ecb706d74dc1438e143dac641..4ed652782fa641ec8e4b0de882b579495cacc08d 100644 --- a/src/caosdb/file_transmission/upload_request_handler.cpp +++ b/src/linkahead/file_transmission/upload_request_handler.cpp @@ -1,5 +1,5 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * Copyright (C) 2021-2022 Timm Fitschen <t.fitschen@indiscale.com> * Copyright (C) 2021-2022 IndiScale GmbH <info@indiscale.com> * @@ -46,11 +46,11 @@ * > FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * > DEALINGS IN THE SOFTWARE. */ -#include "caosdb/file_transmission/upload_request_handler.h" -#include "caosdb/logging.h" // for CAOSDB_LOG_ERROR -#include "caosdb/protobuf_helper.h" // for get_arena -#include "caosdb/status_code.h" // for GENERIC_RPC_E... -#include "caosdb/transaction_status.h" // for TransactionStatus +#include "linkahead/file_transmission/upload_request_handler.h" +#include "linkahead/logging.h" // for LINKAHEAD_LOG_ERROR +#include "linkahead/protobuf_helper.h" // for get_arena +#include "linkahead/status_code.h" // for GENERIC_RPC_E... +#include "linkahead/transaction_status.h" // for TransactionStatus #include <algorithm> // for min #include <cstdint> // for uint64_t #include <exception> // IWYU pragma: keep @@ -61,10 +61,10 @@ #include <utility> // for move // IWYU pragma: no_include <bits/exception.h> -namespace caosdb::transaction { -using caosdb::StatusCode; -using caosdb::utility::get_arena; +namespace linkahead::transaction { using google::protobuf::Arena; +using linkahead::StatusCode; +using linkahead::utility::get_arena; UploadRequestHandler::UploadRequestHandler(HandlerTag tag, FileTransmissionService::Stub *stub, grpc::CompletionQueue *cq, @@ -95,11 +95,11 @@ bool UploadRequestHandler::OnNext(bool ok) { return true; } catch (std::exception &e) { - CAOSDB_LOG_ERROR(logger_name) << "UploadRequestHandler caught an exception: " << e.what(); + LINKAHEAD_LOG_ERROR(logger_name) << "UploadRequestHandler caught an exception: " << e.what(); transaction_status = TransactionStatus::GENERIC_ERROR(e.what()); state_ = CallState::CallComplete; } catch (...) { - CAOSDB_LOG_ERROR(logger_name) << "Transaction error: unknown exception caught"; + LINKAHEAD_LOG_ERROR(logger_name) << "Transaction error: unknown exception caught"; transaction_status = TransactionStatus::GENERIC_ERROR("UploadRequestHandler caught an unknown exception"); state_ = CallState::CallComplete; @@ -174,27 +174,27 @@ void UploadRequestHandler::handleExpectingResponseState() { } void UploadRequestHandler::handleCallCompleteState() { - CAOSDB_LOG_TRACE(logger_name) << "Enter UploadRequestHandler::handleCallCompleteState"; + LINKAHEAD_LOG_TRACE(logger_name) << "Enter UploadRequestHandler::handleCallCompleteState"; switch (status_.error_code()) { case grpc::OK: { auto bytesSent = fileReader_ != nullptr ? fileReader_->fileSize() : 0; - CAOSDB_LOG_INFO(logger_name) << "UploadRequestHandler finished successfully (" - << file_descriptor_.local_path << "): upload complete, " - << bytesSent << " bytes sent"; + LINKAHEAD_LOG_INFO(logger_name) + << "UploadRequestHandler finished successfully (" << file_descriptor_.local_path + << "): upload complete, " << bytesSent << " bytes sent"; } break; default: { auto code(static_cast<StatusCode>(status_.error_code())); std::string description(get_status_description(code) + " Original message: " + status_.error_message()); transaction_status = TransactionStatus(code, description); - CAOSDB_LOG_ERROR(logger_name) << "UploadRequestHandler finished with an error (" - << file_descriptor_.local_path << "): Upload aborted with code " - << code << " - " << description; + LINKAHEAD_LOG_ERROR(logger_name) + << "UploadRequestHandler finished with an error (" << file_descriptor_.local_path + << "): Upload aborted with code " << code << " - " << description; } break; } - CAOSDB_LOG_TRACE(logger_name) << "Leave UploadRequestHandler::handleCallCompleteState"; + LINKAHEAD_LOG_TRACE(logger_name) << "Leave UploadRequestHandler::handleCallCompleteState"; } -} // namespace caosdb::transaction +} // namespace linkahead::transaction diff --git a/src/caosdb/info.cpp b/src/linkahead/info.cpp similarity index 100% rename from src/caosdb/info.cpp rename to src/linkahead/info.cpp diff --git a/src/caosdb/logging.cpp b/src/linkahead/logging.cpp similarity index 68% rename from src/caosdb/logging.cpp rename to src/linkahead/logging.cpp index ecc34d668971eaa22cd7ff727d8f54c84c2f3bdc..a3060697b521fc35169a8b8ec19acbb08f249540 100644 --- a/src/caosdb/logging.cpp +++ b/src/linkahead/logging.cpp @@ -1,8 +1,8 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -18,14 +18,12 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ -#include "caosdb/logging.h" -#include "caosdb/log_level.h" +#include "linkahead/logging.h" #include <boost/core/swap.hpp> // for swap #include <boost/iterator/iterator_facade.hpp> #include <boost/log/attributes/clock.hpp> #include <boost/log/core/core.hpp> // for core #include <boost/log/core/record.hpp> -#include <boost/log/detail/attachable_sstream_buf.hpp> #include <boost/log/sources/record_ostream.hpp> #include <boost/log/sources/severity_channel_logger.hpp> #include <boost/log/utility/setup/from_settings.hpp> @@ -35,17 +33,18 @@ #include <boost/preprocessor/seq/limits/enum_256.hpp> #include <boost/preprocessor/seq/limits/size_256.hpp> #include <boost/property_tree/detail/exception_implementation.hpp> -#include <boost/smart_ptr/intrusive_ptr.hpp> +#include <boost/property_tree/detail/ptree_implementation.hpp> #include <boost/smart_ptr/intrusive_ref_counter.hpp> #include <boost/smart_ptr/shared_ptr.hpp> -#include <cstdint> // for uint64_t +#include <cstdint> +#include <filesystem> // for path #include <memory> -#include <sstream> #include <string> #include <utility> // for move #include <vector> +#include "linkahead/log_level.h" -namespace caosdb::logging { +namespace linkahead::logging { using boost_logger_class = boost::log::sources::severity_channel_logger_mt<int, std::string>; class logger { @@ -64,59 +63,71 @@ LoggerOutputStream::LoggerOutputStream(std::string channel, int level) : channel(std::move(channel)), level(level) {} auto LoggerOutputStream::operator<<(std::ostream &(*f)(std::ostream &)) -> LoggerOutputStream & { - BOOST_LOG_CHANNEL_SEV(caosdb::logging::logger::get(), this->channel, this->level) << f; + BOOST_LOG_CHANNEL_SEV(linkahead::logging::logger::get(), this->channel, this->level) << f; return *this; } auto LoggerOutputStream::operator<<(bool msg) -> LoggerOutputStream & { - BOOST_LOG_CHANNEL_SEV(caosdb::logging::logger::get(), this->channel, this->level) << msg; + BOOST_LOG_CHANNEL_SEV(linkahead::logging::logger::get(), this->channel, this->level) << msg; return *this; } auto LoggerOutputStream::operator<<(std::streambuf *msg) -> LoggerOutputStream & { - BOOST_LOG_CHANNEL_SEV(caosdb::logging::logger::get(), channel, this->level) << msg; + BOOST_LOG_CHANNEL_SEV(linkahead::logging::logger::get(), channel, this->level) << msg; return *this; } auto LoggerOutputStream::operator<<(int msg) -> LoggerOutputStream & { - BOOST_LOG_CHANNEL_SEV(caosdb::logging::logger::get(), channel, this->level) << msg; + BOOST_LOG_CHANNEL_SEV(linkahead::logging::logger::get(), channel, this->level) << msg; return *this; } auto LoggerOutputStream::operator<<(int64_t msg) -> LoggerOutputStream & { - BOOST_LOG_CHANNEL_SEV(caosdb::logging::logger::get(), channel, this->level) << msg; + BOOST_LOG_CHANNEL_SEV(linkahead::logging::logger::get(), channel, this->level) << msg; return *this; } auto LoggerOutputStream::operator<<(uint64_t msg) -> LoggerOutputStream & { - BOOST_LOG_CHANNEL_SEV(caosdb::logging::logger::get(), channel, this->level) << msg; + BOOST_LOG_CHANNEL_SEV(linkahead::logging::logger::get(), channel, this->level) << msg; return *this; } auto LoggerOutputStream::operator<<(const char *msg) -> LoggerOutputStream & { - BOOST_LOG_CHANNEL_SEV(caosdb::logging::logger::get(), channel, this->level) << msg; + BOOST_LOG_CHANNEL_SEV(linkahead::logging::logger::get(), channel, this->level) << msg; return *this; } auto LoggerOutputStream::operator<<(const std::string &msg) -> LoggerOutputStream & { - BOOST_LOG_CHANNEL_SEV(caosdb::logging::logger::get(), channel, this->level) << msg; + BOOST_LOG_CHANNEL_SEV(linkahead::logging::logger::get(), channel, this->level) << msg; return *this; } auto LoggerOutputStream::operator<<(void *msg) -> LoggerOutputStream & { - BOOST_LOG_CHANNEL_SEV(caosdb::logging::logger::get(), channel, this->level) << msg; + BOOST_LOG_CHANNEL_SEV(linkahead::logging::logger::get(), channel, this->level) << msg; return *this; } +auto LoggerOutputStream::operator<<(std::filesystem::path *path) -> LoggerOutputStream & { + BOOST_LOG_CHANNEL_SEV(linkahead::logging::logger::get(), channel, this->level) << path->string(); + + return *this; +} + +LoggerOutputStream &LoggerOutputStream::operator<<(const std::filesystem::path &path) { + + BOOST_LOG_CHANNEL_SEV(linkahead::logging::logger::get(), channel, this->level) << path.string(); + return *this; +} + LoggingConfiguration::LoggingConfiguration(int level) : LevelConfiguration(level) {} auto LoggingConfiguration::AddSink(const std::shared_ptr<SinkConfiguration> &sink) -> void { @@ -134,7 +145,7 @@ SinkConfiguration::SinkConfiguration(std::string name, int level) [[nodiscard]] auto SinkConfiguration::GetName() const -> const std::string & { return this->name; } auto SinkConfiguration::Configure(void *settings) const -> void { - CAOSDB_LOG_TRACE(logger_name) << "Enter SinkConfiguration::Configure(*settings)"; + LINKAHEAD_LOG_TRACE(logger_name) << "Enter SinkConfiguration::Configure(*settings)"; auto sink = "Sinks." + GetName(); auto *boost_settings = static_cast<boost::log::settings *>(settings); (*boost_settings)[sink]["Destination"] = GetDestination(); @@ -147,12 +158,12 @@ ConsoleSinkConfiguration::ConsoleSinkConfiguration(const std::string &name, int : SinkConfiguration(name, level) {} [[nodiscard]] auto ConsoleSinkConfiguration::GetDestination() const -> const std::string & { - CAOSDB_LOG_TRACE(logger_name) << "Enter ConsoleSinkConfiguration::GetDestination()"; + LINKAHEAD_LOG_TRACE(logger_name) << "Enter ConsoleSinkConfiguration::GetDestination()"; return this->destination; } auto ConsoleSinkConfiguration::Configure(void *settings) const -> void { - CAOSDB_LOG_TRACE(logger_name) << "Enter ConsoleSinkConfiguration::Configure(*settings)"; + LINKAHEAD_LOG_TRACE(logger_name) << "Enter ConsoleSinkConfiguration::Configure(*settings)"; sink_configuration::Configure(settings); } @@ -160,7 +171,7 @@ FileSinkConfiguration::FileSinkConfiguration(const std::string &name, int level) : SinkConfiguration(name, level) {} [[nodiscard]] auto FileSinkConfiguration::GetDestination() const -> const std::string & { - CAOSDB_LOG_TRACE(logger_name) << "Enter FileSinkConfiguration::GetDestination()"; + LINKAHEAD_LOG_TRACE(logger_name) << "Enter FileSinkConfiguration::GetDestination()"; return this->destination; } @@ -169,7 +180,7 @@ auto FileSinkConfiguration::SetDirectory(const std::string &directory) -> void { } auto FileSinkConfiguration::Configure(void *settings) const -> void { - CAOSDB_LOG_TRACE(logger_name) << "Enter FileSinkConfiguration::Configure(*settings)"; + LINKAHEAD_LOG_TRACE(logger_name) << "Enter FileSinkConfiguration::Configure(*settings)"; sink_configuration::Configure(settings); auto *boost_settings = static_cast<boost::log::settings *>(settings); (*boost_settings)["Sink." + GetName() + ".Target"] = this->directory; @@ -194,7 +205,7 @@ auto initialize_logging_defaults() -> int { // now set everything up const static std::vector<std::shared_ptr<SinkConfiguration>> default_sinks = { - std::make_shared<ConsoleSinkConfiguration>("DEFAULT_SINK_1", CAOSDB_DEFAULT_LOG_LEVEL)}; + std::make_shared<ConsoleSinkConfiguration>("DEFAULT_SINK_1", LINKAHEAD_DEFAULT_LOG_LEVEL)}; boost::log::settings default_settings; @@ -207,7 +218,7 @@ auto initialize_logging_defaults() -> int { boost::log::init_from_settings(default_settings); core->add_global_attribute("TimeStamp", boost::log::attributes::local_clock()); - CAOSDB_LOG_DEBUG(logger_name) << "Initialized default settings."; + LINKAHEAD_LOG_DEBUG(logger_name) << "Initialized default settings."; return 0; } @@ -222,7 +233,7 @@ auto initialize_logging(const LoggingConfiguration &configuration) -> void { core->set_logging_enabled(false); } - if (configuration.GetLevel() == CAOSDB_LOG_LEVEL_OFF) { + if (configuration.GetLevel() == LINKAHEAD_LOG_LEVEL_OFF) { // it is off return; } @@ -237,31 +248,31 @@ auto initialize_logging(const LoggingConfiguration &configuration) -> void { boost::log::init_from_settings(new_settings); - CAOSDB_LOG_DEBUG(logger_name) << "Initialized logging with custom settings."; + LINKAHEAD_LOG_DEBUG(logger_name) << "Initialized logging with custom settings."; } -void caosdb_log_fatal(const char *channel, const char *msg) { - LoggerOutputStream::get(channel, CAOSDB_LOG_LEVEL_FATAL) << msg; +void linkahead_log_fatal(const char *channel, const char *msg) { + LoggerOutputStream::get(channel, LINKAHEAD_LOG_LEVEL_FATAL) << msg; } -void caosdb_log_error(const char *channel, const char *msg) { - LoggerOutputStream::get(channel, CAOSDB_LOG_LEVEL_ERROR) << msg; +void linkahead_log_error(const char *channel, const char *msg) { + LoggerOutputStream::get(channel, LINKAHEAD_LOG_LEVEL_ERROR) << msg; } -void caosdb_log_warn(const char *channel, const char *msg) { - LoggerOutputStream::get(channel, CAOSDB_LOG_LEVEL_WARN) << msg; +void linkahead_log_warn(const char *channel, const char *msg) { + LoggerOutputStream::get(channel, LINKAHEAD_LOG_LEVEL_WARN) << msg; } -void caosdb_log_info(const char *channel, const char *msg) { - LoggerOutputStream::get(channel, CAOSDB_LOG_LEVEL_INFO) << msg; +void linkahead_log_info(const char *channel, const char *msg) { + LoggerOutputStream::get(channel, LINKAHEAD_LOG_LEVEL_INFO) << msg; } -void caosdb_log_debug(const char *channel, const char *msg) { - LoggerOutputStream::get(channel, CAOSDB_LOG_LEVEL_DEBUG) << msg; +void linkahead_log_debug(const char *channel, const char *msg) { + LoggerOutputStream::get(channel, LINKAHEAD_LOG_LEVEL_DEBUG) << msg; } -void caosdb_log_trace(const char *channel, const char *msg) { - LoggerOutputStream::get(channel, CAOSDB_LOG_LEVEL_TRACE) << msg; +void linkahead_log_trace(const char *channel, const char *msg) { + LoggerOutputStream::get(channel, LINKAHEAD_LOG_LEVEL_TRACE) << msg; } -} // namespace caosdb::logging +} // namespace linkahead::logging diff --git a/src/caosdb/protobuf_helper.cpp b/src/linkahead/protobuf_helper.cpp similarity index 71% rename from src/caosdb/protobuf_helper.cpp rename to src/linkahead/protobuf_helper.cpp index 2b5847687d4926324cbbd5d4f49caca4131dc951..287fa5f4dfe83e5d0559b656cf38178e1e224a84 100644 --- a/src/caosdb/protobuf_helper.cpp +++ b/src/linkahead/protobuf_helper.cpp @@ -1,8 +1,8 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -18,16 +18,16 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ -#include "caosdb/protobuf_helper.h" -#include "caosdb/configuration.h" +#include "linkahead/protobuf_helper.h" +#include "linkahead/configuration.h" #include <google/protobuf/arena.h> // for Arena -namespace caosdb::utility { +namespace linkahead::utility { using google::protobuf::Arena; -auto get_arena() -> Arena * { return caosdb::configuration::ConfigurationManager::GetArena(); } +auto get_arena() -> Arena * { return linkahead::configuration::ConfigurationManager::GetArena(); } auto reset_arena() -> void { get_arena()->Reset(); } -} // namespace caosdb::utility +} // namespace linkahead::utility diff --git a/src/caosdb/result_set.cpp b/src/linkahead/result_set.cpp similarity index 85% rename from src/caosdb/result_set.cpp rename to src/linkahead/result_set.cpp index a4172a836d4e8bb9ed5e568439556ebace53c4e4..2517e61d98ea5e852205db17d137cf6dfb9b596e 100644 --- a/src/caosdb/result_set.cpp +++ b/src/linkahead/result_set.cpp @@ -1,5 +1,5 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * Copyright (C) 2021-2022 Timm Fitschen <t.fitschen@indiscale.com> * Copyright (C) 2021-2022 IndiScale GmbH <info@indiscale.com> * @@ -17,11 +17,12 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ -#include "caosdb/result_set.h" // for ResultSet -#include <memory> // for unique_ptr -#include <utility> // for move, pair +#include "linkahead/result_set.h" // for ResultSet +#include <memory> // for unique_ptr +#include <utility> // for move, pair +#include <vector> -namespace caosdb::transaction { +namespace linkahead::transaction { ResultSet::iterator::iterator(const ResultSet *result_set_param, int index) : current_index(index), result_set(result_set_param) {} @@ -52,4 +53,4 @@ auto ResultSet::end() const -> ResultSet::iterator { return ResultSet::iterator( MultiResultSet::MultiResultSet(std::vector<std::unique_ptr<Entity>> result_set) : AbstractMultiResultSet(std::move(result_set)) {} -} // namespace caosdb::transaction +} // namespace linkahead::transaction diff --git a/src/caosdb/result_table.cpp b/src/linkahead/result_table.cpp similarity index 83% rename from src/caosdb/result_table.cpp rename to src/linkahead/result_table.cpp index f7d5c3e3564fdad9b7f9755c77c6ddce37d3c25f..65283e3bd51d3614db6216146bea317ab96501ff 100644 --- a/src/caosdb/result_table.cpp +++ b/src/linkahead/result_table.cpp @@ -1,6 +1,6 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * Copyright (C) 2021-2022 Timm Fitschen <t.fitschen@indiscale.com> * Copyright (C) 2021-2022 IndiScale GmbH <info@indiscale.com> * @@ -18,26 +18,24 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ -#include "caosdb/result_table.h" // for ResultTable, ResultTab... -#include "caosdb/entity/v1/main.pb.h" // for SelectQueryResult, Sel... -#include "caosdb/protobuf_helper.h" // for ScalarProtoMessageWrapper -#include "caosdb/result_table_impl.h" // for ResultTableImpl, Resul... -#include "caosdb/value.h" // for Value -#include <algorithm> // for max -#include <google/protobuf/repeated_field.h> // IWYU pragma: keep for RepeatedPtrField -#include <memory> // for unique_ptr -#include <string> // for string, operator== -#include <utility> // for move -#include <vector> // for vector +#include "linkahead/result_table.h" +#include <memory> // for unique_ptr +#include <string> // for string, operator==, basic_s... +#include <utility> // for move +#include <vector> // for vector +#include "caosdb/entity/v1/main.pb.h" // for SelectQueryResult, SelectQu... +#include "linkahead/protobuf_helper.h" // for ScalarProtoMessageWrapper +#include "linkahead/result_table_impl.h" // for ResultTableImpl, ResultTabl... +#include "linkahead/value.h" // for Value // IWYU pragma: no_include "net/proto2/public/repeated_field.h" -namespace caosdb::transaction { -using caosdb::entity::Value; +namespace linkahead::transaction { +using linkahead::entity::Value; using ProtoSelectQueryResult = caosdb::entity::v1::SelectQueryResult; using ProtoSelectQueryHeader = caosdb::entity::v1::SelectQueryHeader; using ProtoSelectQueryColumn = caosdb::entity::v1::SelectQueryColumn; using ProtoSelectQueryRow = caosdb::entity::v1::SelectQueryRow; -using caosdb::utility::ScalarProtoMessageWrapper; +using linkahead::utility::ScalarProtoMessageWrapper; ResultTableRowImpl::ResultTableRowImpl(ProtoSelectQueryResult *table, int row) : header(*table->mutable_header()), row(*table->mutable_data_rows(row)) {} @@ -106,8 +104,7 @@ auto ResultTable::GetRows() const noexcept -> RowIterator { return RowIterator(t ResultTable::RowIterator::RowIterator(const ResultTable *result_table_param, int index) : current_index(index), result_table(result_table_param) {} -ResultTable::RowIterator::RowIterator(const RowIterator &other) - : current_index(other.current_index), result_table(other.result_table) {} +ResultTable::RowIterator::RowIterator(const RowIterator &other) = default; auto ResultTable::RowIterator::size() const noexcept -> int { return this->result_table->delegate->wrapped->data_rows_size(); @@ -145,8 +142,7 @@ auto ResultTable::GetHeader() const noexcept -> HeaderIterator { return HeaderIt ResultTable::HeaderIterator::HeaderIterator(const ResultTable *result_table_param, int index) : current_index(index), result_table(result_table_param) {} -ResultTable::HeaderIterator::HeaderIterator(const HeaderIterator &other) - : current_index(other.current_index), result_table(other.result_table) {} +ResultTable::HeaderIterator::HeaderIterator(const HeaderIterator &other) = default; auto ResultTable::HeaderIterator::size() const noexcept -> int { return this->result_table->delegate->wrapped->header().columns_size(); @@ -179,4 +175,4 @@ auto ResultTable::HeaderIterator::end() const -> HeaderIterator { return HeaderIterator(this->result_table, size()); } -} // namespace caosdb::transaction +} // namespace linkahead::transaction diff --git a/src/caosdb/result_table_impl.h b/src/linkahead/result_table_impl.h similarity index 54% rename from src/caosdb/result_table_impl.h rename to src/linkahead/result_table_impl.h index 3450a68cf7ae0638d42d3ea1c79fd9d181a3eaab..62d7fa1c67c4d9b9ec2d0ce2c6e6cb6856701040 100644 --- a/src/caosdb/result_table_impl.h +++ b/src/linkahead/result_table_impl.h @@ -1,5 +1,5 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * Copyright (C) 2021-2022 Timm Fitschen <t.fitschen@indiscale.com> * Copyright (C) 2021-2022 IndiScale GmbH <info@indiscale.com> * @@ -17,38 +17,38 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ -#ifndef CAOSDB_RESULT_TABLE_IMPL_H -#define CAOSDB_RESULT_TABLE_IMPL_H +#ifndef LINKAHEAD_RESULT_TABLE_IMPL_H +#define LINKAHEAD_RESULT_TABLE_IMPL_H -#include "caosdb/transaction.h" -#include "caosdb/entity/v1/main.grpc.pb.h" // for EntityTransac... -#include "caosdb/entity/v1/main.pb.h" // for TransactionRe... -#include "caosdb/file_transmission/download_request_handler.h" // Download... -#include "caosdb/file_transmission/file_reader.h" // for path -#include "caosdb/file_transmission/register_file_upload_handler.h" // for RegisterFileUploadHandler -#include "caosdb/file_transmission/upload_request_handler.h" // Upload... -#include "caosdb/logging.h" // for CAOSDB_LOG_FATAL -#include "caosdb/protobuf_helper.h" // for ProtoMessageWrapper -#include "caosdb/status_code.h" // for StatusCode -#include "caosdb/transaction_handler.h" // for EntityTransactionHandler -#include <algorithm> // for max -#include <filesystem> // for operator<<, path -#include <future> // for async, future -#include <google/protobuf/arena.h> // for Arena -#include <grpc/grpc.h> // for gpr_timespec -#include <map> // for map, operator!= -#include <memory> // for unique_ptr -#include <random> // for mt19937, rand... -#include <system_error> // for std::system_error -#include <utility> // for move, pair +#include "linkahead/transaction.h" +#include "caosdb/entity/v1/main.pb.h" // for EntityTransac... +#include "caosdb/entity/v1/main.pb.h" // for TransactionRe... +#include "linkahead/file_transmission/download_request_handler.h" // Download... +#include "linkahead/file_transmission/file_reader.h" // for path +#include "linkahead/file_transmission/register_file_upload_handler.h" // for RegisterFileUploadHandler +#include "linkahead/file_transmission/upload_request_handler.h" // Upload... +#include "linkahead/logging.h" // for LINKAHEAD_LOG_FATAL +#include "linkahead/protobuf_helper.h" // for ProtoMessageWrapper +#include "linkahead/status_code.h" // for StatusCode +#include "linkahead/transaction_handler.h" // for EntityTransactionHandler +#include <algorithm> // for max +#include <filesystem> // for operator<<, path +#include <future> // for async, future +#include <google/protobuf/arena.h> // for Arena +#include <grpc/grpc.h> // for gpr_timespec +#include <map> // for map, operator!= +#include <memory> // for unique_ptr +#include <random> // for mt19937, rand... +#include <system_error> // for std::system_error +#include <utility> // for move, pair -namespace caosdb::transaction { -using caosdb::entity::Value; +namespace linkahead::transaction { +using linkahead::entity::Value; using ProtoSelectQueryResult = caosdb::entity::v1::SelectQueryResult; using ProtoSelectQueryHeader = caosdb::entity::v1::SelectQueryHeader; using ProtoSelectQueryColumn = caosdb::entity::v1::SelectQueryColumn; using ProtoSelectQueryRow = caosdb::entity::v1::SelectQueryRow; -using caosdb::utility::ScalarProtoMessageWrapper; +using linkahead::utility::ScalarProtoMessageWrapper; class ResultTableRowImpl { explicit ResultTableRowImpl(ProtoSelectQueryResult *table, int row); @@ -80,5 +80,5 @@ class ResultTableImpl : public ScalarProtoMessageWrapper<ProtoSelectQueryResult> -> std::unique_ptr<ResultTable>; }; -} // namespace caosdb::transaction +} // namespace linkahead::transaction #endif diff --git a/src/caosdb/status_code_description.cpp b/src/linkahead/status_code_description.cpp similarity index 95% rename from src/caosdb/status_code_description.cpp rename to src/linkahead/status_code_description.cpp index d1f651257bc1a682870ffb52650a42c4d16ec642..7183c38a362566347e52361a909825696fcbd1ea 100644 --- a/src/caosdb/status_code_description.cpp +++ b/src/linkahead/status_code_description.cpp @@ -1,7 +1,7 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -18,12 +18,13 @@ * */ -#include "caosdb/status_code.h" // for StatusCode, ABORTED, ALREADY_EXISTS -#include <map> // for allocator, map -#include <stdexcept> // for out_of_range -#include <string> // for string, basic_string +#include <map> // for map +#include <stdexcept> // for out_of_range +#include <string> // for basic_string, string +#include <utility> // for pair +#include "linkahead/status_code.h" // for StatusCode, get_status_description -namespace caosdb { +namespace linkahead { /* * The descriptions of the StatusCodes 1-16 are originally taken from @@ -171,6 +172,6 @@ auto get_status_description(int code) -> const std::string & { } } -} // namespace caosdb +} // namespace linkahead // LocalWords: ConnectionManager Extern diff --git a/src/caosdb/transaction.cpp b/src/linkahead/transaction.cpp similarity index 81% rename from src/caosdb/transaction.cpp rename to src/linkahead/transaction.cpp index 28f9e35fc1a70083d07c99e7f8a4fabfbe58bc32..5fafb34b67cbb4324cd178e83184948d19a77cee 100644 --- a/src/caosdb/transaction.cpp +++ b/src/linkahead/transaction.cpp @@ -1,5 +1,5 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * Copyright (C) 2021-2022 Timm Fitschen <t.fitschen@indiscale.com> * Copyright (C) 2021-2022 IndiScale GmbH <info@indiscale.com> * @@ -17,35 +17,32 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ -#include "caosdb/transaction.h" -#include "caosdb/entity/v1/main.grpc.pb.h" // for EntityTransac... -#include "caosdb/entity/v1/main.pb.h" // for TransactionRe... -#include "caosdb/file_transmission/download_request_handler.h" // Download... -#include "caosdb/file_transmission/file_reader.h" // for path -#include "caosdb/file_transmission/register_file_upload_handler.h" // for RegisterFileUploadHandler -#include "caosdb/file_transmission/upload_request_handler.h" // Upload... -#include "caosdb/logging.h" // for CAOSDB_LOG_FATAL -#include "caosdb/protobuf_helper.h" // for ProtoMessageWrapper -#include "caosdb/result_set.h" // for ResultSet -#include "caosdb/result_table.h" // for ResultTable -#include "caosdb/result_table_impl.h" // for ResultTableImpl -#include "caosdb/status_code.h" // for StatusCode -#include "caosdb/transaction_handler.h" // for EntityTransactionHandler -#include <algorithm> // for max -#include <exception> // IWYU pragma: keep -#include <filesystem> // for operator<<, path -#include <future> // for async, future -#include <google/protobuf/arena.h> // for Arena -#include <grpc/grpc.h> // for gpr_timespec -#include <map> // for map, operator!= -#include <memory> // for unique_ptr -#include <random> // for mt19937, rand... -#include <system_error> // for std::system_error -#include <utility> // for move, pair +#include "linkahead/transaction.h" +#include <google/protobuf/arena.h> +#include <grpc/grpc.h> +#include <filesystem> +#include <future> +#include <map> +#include <memory> +#include <random> +#include <string> +#include <utility> +#include "caosdb/entity/v1/main.grpc.pb.h" +#include "caosdb/entity/v1/main.pb.h" +#include "linkahead/file_transmission/download_request_handler.h" +#include "linkahead/file_transmission/register_file_upload_handler.h" +#include "linkahead/file_transmission/upload_request_handler.h" +#include "linkahead/logging.h" +#include "linkahead/protobuf_helper.h" +#include "linkahead/result_set.h" +#include "linkahead/result_table.h" +#include "linkahead/result_table_impl.h" +#include "linkahead/status_code.h" +#include "linkahead/transaction_handler.h" // IWYU pragma: no_include <cxxabi.h> // IWYU pragma: no_include "net/proto2/public/repeated_field.h" -namespace caosdb::transaction { +namespace linkahead::transaction { using caosdb::entity::v1::EntityTransactionService; using caosdb::entity::v1::FileTransmissionService; using caosdb::entity::v1::MultiTransactionRequest; @@ -168,7 +165,7 @@ auto Transaction::UpdateEntity(Entity *entity) noexcept -> StatusCode { auto Transaction::Execute() -> TransactionStatus { auto status_code = ExecuteAsynchronously(); TransactionStatus::ThrowExceptionIfError(status_code, - caosdb::get_status_description(status_code)); + linkahead::get_status_description(status_code)); auto status = WaitForIt(); status.ThrowExceptionIfError(); return status; @@ -182,7 +179,7 @@ auto Transaction::Execute() -> TransactionStatus { auto Transaction::DoExecuteTransaction() noexcept -> void { // upload files first if (!upload_files.empty()) { - CAOSDB_LOG_INFO(logger_name) << "Number of files to be uploaded: " << upload_files.size(); + LINKAHEAD_LOG_INFO(logger_name) << "Number of files to be uploaded: " << upload_files.size(); auto *registration_request = Arena::CreateMessage<RegisterFileUploadRequest>(get_arena()); auto *registration_response = Arena::CreateMessage<RegisterFileUploadResponse>(get_arena()); @@ -207,7 +204,7 @@ auto Transaction::DoExecuteTransaction() noexcept -> void { { TRANSACTION_SYNCRONIZED_BLOCK if (this->status.GetCode() == StatusCode::EXECUTING) { - CAOSDB_LOG_INFO(logger_name) << "Uploading " << file_descriptor.local_path; + LINKAHEAD_LOG_INFO(logger_name) << "Uploading " << file_descriptor.local_path; handler_ = std::make_unique<UploadRequestHandler>(&handler_, file_service.get(), &completion_queue, file_descriptor); } @@ -224,7 +221,7 @@ auto Transaction::DoExecuteTransaction() noexcept -> void { { TRANSACTION_SYNCRONIZED_BLOCK if (this->status.GetCode() == StatusCode::EXECUTING) { - CAOSDB_LOG_DEBUG(logger_name) << "RPC Request: " << RequestToString(); + LINKAHEAD_LOG_DEBUG(logger_name) << "RPC Request: " << RequestToString(); handler_ = std::make_unique<EntityTransactionHandler>(&handler_, entity_service.get(), &completion_queue, request, response); } @@ -253,7 +250,7 @@ auto Transaction::DoExecuteTransaction() noexcept -> void { { TRANSACTION_SYNCRONIZED_BLOCK if (this->status.GetCode() == StatusCode::EXECUTING) { - CAOSDB_LOG_INFO(logger_name) << "Downloading " << file_descriptor.local_path; + LINKAHEAD_LOG_INFO(logger_name) << "Downloading " << file_descriptor.local_path; handler_ = std::make_unique<DownloadRequestHandler>(&handler_, file_service.get(), &completion_queue, file_descriptor); @@ -278,7 +275,7 @@ auto Transaction::ExecuteAsynchronously() noexcept -> StatusCode { } switch (this->transaction_type) { case MIXED_READ_AND_WRITE: - CAOSDB_LOG_ERROR_AND_RETURN_STATUS( + LINKAHEAD_LOG_ERROR_AND_RETURN_STATUS( logger_name, StatusCode::UNSUPPORTED_FEATURE, "MIXED_WRITE UNSUPPORTED: The current implementation does not support " "mixed read and write transactions (containing retrievals, insertions, " @@ -324,14 +321,14 @@ auto Transaction::ProcessRetrieveResponse(RetrieveResponse *retrieve_response, } } break; default: - CAOSDB_LOG_FATAL(logger_name) << "Received invalid QueryResponseCase."; + LINKAHEAD_LOG_FATAL(logger_name) << "Received invalid QueryResponseCase."; break; } return result; } auto Transaction::ProcessTerminated() const noexcept -> void { - CAOSDB_LOG_TRACE_ENTER_AND_LEAVE(logger_name, "Transaction::ProcessTerminated()") + LINKAHEAD_LOG_TRACE_ENTER_AND_LEAVE(logger_name, "Transaction::ProcessTerminated()") bool set_error = false; auto *responses = this->response->mutable_responses(); std::vector<std::unique_ptr<Entity>> entities; @@ -360,7 +357,7 @@ auto Transaction::ProcessTerminated() const noexcept -> void { break; } default: - CAOSDB_LOG_FATAL(logger_name) << "Received invalid TransactionResponseCase."; + LINKAHEAD_LOG_FATAL(logger_name) << "Received invalid TransactionResponseCase."; break; } // default to sub_response.transaction_response_case() if (result != nullptr) { @@ -399,10 +396,10 @@ auto Transaction::WaitForIt() const noexcept -> TransactionStatus { } auto Transaction::ProcessCalls() -> TransactionStatus { - CAOSDB_LOG_TRACE_ENTER_AND_LEAVE(logger_name, "Transaction::ProcessCalls()") { + LINKAHEAD_LOG_TRACE_ENTER_AND_LEAVE(logger_name, "Transaction::ProcessCalls()") { TRANSACTION_SYNCRONIZED_BLOCK if (this->status.GetCode() != StatusCode::EXECUTING) { - CAOSDB_LOG_ERROR(logger_name) + LINKAHEAD_LOG_ERROR(logger_name) << "Transaction::ProcessCalls() was called, TransactionStatus was: " << std::to_string(this->status.GetCode()) << " - " << this->status.GetDescription(); return status; @@ -432,20 +429,20 @@ auto Transaction::ProcessCalls() -> TransactionStatus { } } else { std::string description("Invalid tag delivered by notification queue."); - CAOSDB_LOG_ERROR(logger_name) << description; + LINKAHEAD_LOG_ERROR(logger_name) << description; return TransactionStatus::RPC_ERROR(description); } } break; case NextStatus::SHUTDOWN: { - CAOSDB_LOG_ERROR(logger_name) << "Notification queue has been shut down unexpectedly."; + LINKAHEAD_LOG_ERROR(logger_name) << "Notification queue has been shut down unexpectedly."; result = handler_->GetStatus(); return result; } break; case NextStatus::TIMEOUT: { - CAOSDB_LOG_DEBUG(logger_name) << "Timeout, waiting..."; + LINKAHEAD_LOG_DEBUG(logger_name) << "Timeout, waiting..."; } break; default: - CAOSDB_LOG_FATAL(logger_name) << "Got an invalid NextStatus from CompletionQueue."; + LINKAHEAD_LOG_FATAL(logger_name) << "Got an invalid NextStatus from CompletionQueue."; result = handler_->GetStatus(); return result; } @@ -456,12 +453,12 @@ auto Transaction::ProcessCalls() -> TransactionStatus { } Transaction::~Transaction() { - CAOSDB_LOG_TRACE_ENTER_AND_LEAVE(logger_name, "Transaction::~Transaction()") + LINKAHEAD_LOG_TRACE_ENTER_AND_LEAVE(logger_name, "Transaction::~Transaction()") this->Cancel(); } void Transaction::Cancel() { - CAOSDB_LOG_TRACE_ENTER_AND_LEAVE(logger_name, "Transaction::Cancel()") + LINKAHEAD_LOG_TRACE_ENTER_AND_LEAVE(logger_name, "Transaction::Cancel()") if (this->status.GetCode() == StatusCode::CANCELLED) { return; @@ -492,4 +489,4 @@ void Transaction::Cancel() { } } -} // namespace caosdb::transaction +} // namespace linkahead::transaction diff --git a/src/caosdb/transaction_handler.cpp b/src/linkahead/transaction_handler.cpp similarity index 70% rename from src/caosdb/transaction_handler.cpp rename to src/linkahead/transaction_handler.cpp index ef4897d1392f46b374fbdf5831c3a9e74ebf9d63..57bebd963ba114df1376931739cfcfe3be149041 100644 --- a/src/caosdb/transaction_handler.cpp +++ b/src/linkahead/transaction_handler.cpp @@ -1,9 +1,9 @@ -#include "caosdb/transaction_handler.h" -#include "caosdb/logging.h" // for CAOSDB_LOG_TRACE -#include <exception> // IWYU pragma: keep +#include "linkahead/transaction_handler.h" +#include <string> // for basic_string +#include "linkahead/logging.h" // for LINKAHEAD_LOG_TRACE_ENTER_AND_LEAVE // IWYU pragma: no_include <bits/exception.h> -namespace caosdb::transaction { +namespace linkahead::transaction { EntityTransactionHandler::EntityTransactionHandler(HandlerTag tag, EntityTransactionService::Stub *stub, @@ -14,7 +14,7 @@ EntityTransactionHandler::EntityTransactionHandler(HandlerTag tag, response_(response) {} void EntityTransactionHandler::handleNewCallState() { - CAOSDB_LOG_TRACE_ENTER_AND_LEAVE(logger_name, "EntityTransactionHandler::handleNewCallState()") + LINKAHEAD_LOG_TRACE_ENTER_AND_LEAVE(logger_name, "EntityTransactionHandler::handleNewCallState()") rpc_ = stub_->PrepareAsyncMultiTransaction(&call_context, *request_, completion_queue); @@ -23,4 +23,4 @@ void EntityTransactionHandler::handleNewCallState() { rpc_->Finish(response_, &status_, tag_); } -} // namespace caosdb::transaction +} // namespace linkahead::transaction diff --git a/src/caosdb/unary_rpc_handler.cpp b/src/linkahead/unary_rpc_handler.cpp similarity index 79% rename from src/caosdb/unary_rpc_handler.cpp rename to src/linkahead/unary_rpc_handler.cpp index 6d116eafae7203498ebf431a09d85c184b619191..86c3588a53240e7a914bf5ea2f23bc09da003183 100644 --- a/src/caosdb/unary_rpc_handler.cpp +++ b/src/linkahead/unary_rpc_handler.cpp @@ -1,5 +1,5 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * Copyright (C) 2021-2022 Timm Fitschen <t.fitschen@indiscale.com> * Copyright (C) 2021-2022 IndiScale GmbH <info@indiscale.com> * @@ -46,17 +46,17 @@ * > FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * > DEALINGS IN THE SOFTWARE. */ -#include "caosdb/unary_rpc_handler.h" -#include "caosdb/logging.h" // for CAOSDB_LOG_TRACE -#include "caosdb/status_code.h" // for GENERIC_RPC_E... -#include <exception> // IWYU pragma: keep -#include <string> // for string, opera... +#include "linkahead/unary_rpc_handler.h" +#include "linkahead/logging.h" // for LINKAHEAD_LOG_TRACE +#include "linkahead/status_code.h" // for GENERIC_RPC_E... +#include <exception> // IWYU pragma: keep +#include <string> // for string, opera... // IWYU pragma: no_include <bits/exception.h> -namespace caosdb::transaction { +namespace linkahead::transaction { bool UnaryRpcHandler::OnNext(bool ok) { - CAOSDB_LOG_TRACE_ENTER_AND_LEAVE(logger_name, "UnaryRpcHandler::OnNext(bool)") + LINKAHEAD_LOG_TRACE_ENTER_AND_LEAVE(logger_name, "UnaryRpcHandler::OnNext(bool)") try { if (ok) { if (state_ == CallState::NewCall) { @@ -66,7 +66,8 @@ bool UnaryRpcHandler::OnNext(bool ok) { return false; } } else { - CAOSDB_LOG_ERROR(logger_name) << "UnaryRpcHandler::OnNext(false)!. This should not happen."; + LINKAHEAD_LOG_ERROR(logger_name) + << "UnaryRpcHandler::OnNext(false)!. This should not happen."; // TODO(tf) Handle this error: // in CallComplete state: "Client-side Finish: ok should always be true" // in ReceivingFile state: "ok indicates that the RPC is going to go to @@ -80,11 +81,11 @@ bool UnaryRpcHandler::OnNext(bool ok) { return true; } catch (std::exception &e) { - CAOSDB_LOG_ERROR(logger_name) << "UnaryRpcHandler caught an exception: " << e.what(); + LINKAHEAD_LOG_ERROR(logger_name) << "UnaryRpcHandler caught an exception: " << e.what(); transaction_status = TransactionStatus::GENERIC_ERROR(e.what()); state_ = CallState::CallComplete; } catch (...) { - CAOSDB_LOG_ERROR(logger_name) << "Transaction error: unknown exception caught"; + LINKAHEAD_LOG_ERROR(logger_name) << "Transaction error: unknown exception caught"; transaction_status = TransactionStatus::GENERIC_ERROR("UnaryRpcHandler caught an unknown exception"); state_ = CallState::CallComplete; @@ -104,21 +105,21 @@ void UnaryRpcHandler::Cancel() { } void UnaryRpcHandler::handleCallCompleteState() { - CAOSDB_LOG_TRACE_ENTER_AND_LEAVE(logger_name, "UnaryRpcHandler::handleCallCompleteState()") + LINKAHEAD_LOG_TRACE_ENTER_AND_LEAVE(logger_name, "UnaryRpcHandler::handleCallCompleteState()") switch (status_.error_code()) { case grpc::OK: - CAOSDB_LOG_TRACE(logger_name) << "UnaryRpcHandler finished successfully."; + LINKAHEAD_LOG_TRACE(logger_name) << "UnaryRpcHandler finished successfully."; break; default: auto code(static_cast<StatusCode>(status_.error_code())); std::string description(get_status_description(code) + " Original message: " + status_.error_message()); transaction_status = TransactionStatus(code, description); - CAOSDB_LOG_ERROR(logger_name) << "UnaryRpcHandler finished with an error (Code " << code - << "): " << description; + LINKAHEAD_LOG_ERROR(logger_name) + << "UnaryRpcHandler finished with an error (Code " << code << "): " << description; break; } } -} // namespace caosdb::transaction +} // namespace linkahead::transaction diff --git a/src/caosdb/utility.cpp b/src/linkahead/utility.cpp similarity index 65% rename from src/caosdb/utility.cpp rename to src/linkahead/utility.cpp index ca7e1cbe9102763ed54763f7ca1dd271ed0b06db..21521ecd83fc3de4e334254d3c912bb7dc687997 100644 --- a/src/caosdb/utility.cpp +++ b/src/linkahead/utility.cpp @@ -1,8 +1,8 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * * Copyright (C) 2021 Daniel Hornung <d.hornung@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -18,29 +18,30 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ -#include "caosdb/utility.h" -#include "caosdb/data_type.h" // for AtomicDataType, atomicdatatype_names -#include "caosdb/entity.h" // for Importance, Role, importance_names +#include "linkahead/utility.h" #include <boost/beast/core/detail/base64.hpp> // for encoded_size #include <boost/beast/core/detail/base64.ipp> // for encode -#include <boost/filesystem/string_file.hpp> // for load_string_file #include <boost/json/stream_parser.hpp> // for stream_parser #include <boost/json/value.hpp> // for value #include <cassert> // for assert -#include <map> // for map, operator!=, _Rb_tree_const_iterator -#include <memory> // for allocator, unique_ptr -#include <stdexcept> // for logic_error +#include <cstdint> // for uintmax_t +#include <limits> // for numeric_limits +#include <map> // for map, _Rb_tree_const_it... +#include <memory> // for shared_ptr, allocator +#include <stdexcept> // for out_of_range, length_e... #include <type_traits> // for underlying_type_t #include <typeinfo> // for type_info -#include <utility> // for pair +#include <utility> // for pair, move +#include "linkahead/data_type.h" // for AtomicDataType, atomic... +#include "linkahead/entity.h" // for Importance, Role, impo... -namespace caosdb::utility { +namespace linkahead::utility { using boost::json::stream_parser; using boost::json::value; -using caosdb::entity::AtomicDataType; -using caosdb::entity::Importance; -using caosdb::entity::Role; +using linkahead::entity::AtomicDataType; +using linkahead::entity::Importance; +using linkahead::entity::Role; template <typename Enum> auto getEnumNameFromValue(Enum v) -> std::string { if (std::is_same_v<std::underlying_type_t<Enum>, int>) { @@ -51,32 +52,32 @@ template <typename Enum> auto getEnumNameFromValue(Enum v) -> std::string { // Enum helper template specializations ////////////////////////////////////// template <> auto getEnumNameFromValue<Importance>(Importance v) -> std::string { - auto result = caosdb::entity::importance_names.at(v); + auto result = linkahead::entity::importance_names.at(v); return result; } template <> auto getEnumNameFromValue<Role>(Role v) -> std::string { - auto result = caosdb::entity::role_names.at(v); + auto result = linkahead::entity::role_names.at(v); return result; } template <> auto getEnumNameFromValue<AtomicDataType>(AtomicDataType v) -> std::string { - auto result = caosdb::entity::atomicdatatype_names.at(v); + auto result = linkahead::entity::atomicdatatype_names.at(v); return result; } template <> auto getEnumValueFromName<Importance>(const std::string &name) -> Importance { // TODO (dh): Why does this compile? - // if (caosdb::entity::importance_names.begin()->second == name) {} - // std::for_each(caosdb::entity::importance_names.begin(), - // caosdb::entity::importance_names.end(), + // if (linkahead::entity::importance_names.begin()->second == name) {} + // std::for_each(linkahead::entity::importance_names.begin(), + // linkahead::entity::importance_names.end(), // [](const auto &entry){}); // TODO (dh): Whereas this does not? - // auto result = std::find(caosdb::entity::importance_names.cbegin(), - // caosdb::entity::importance_names.cend(), + // auto result = std::find(linkahead::entity::importance_names.cbegin(), + // linkahead::entity::importance_names.cend(), // [name](const auto& entry){ return entry.second == name; }); // Workaround: plaint old iteration: - for (auto const &entry : caosdb::entity::importance_names) { + for (auto const &entry : linkahead::entity::importance_names) { if (entry.second == name) { return entry.first; } @@ -85,7 +86,7 @@ template <> auto getEnumValueFromName<Importance>(const std::string &name) -> Im } template <> auto getEnumValueFromName<AtomicDataType>(const std::string &name) -> AtomicDataType { - for (auto const &entry : caosdb::entity::atomicdatatype_names) { + for (auto const &entry : linkahead::entity::atomicdatatype_names) { if (entry.second == name) { return entry.first; } @@ -94,7 +95,7 @@ template <> auto getEnumValueFromName<AtomicDataType>(const std::string &name) - } template <> auto getEnumValueFromName<Role>(const std::string &name) -> Role { - for (auto const &entry : caosdb::entity::role_names) { + for (auto const &entry : linkahead::entity::role_names) { if (entry.second == name) { return entry.first; } @@ -106,7 +107,24 @@ template <> auto getEnumValueFromName<Role>(const std::string &name) -> Role { auto load_string_file(const path &file_path) -> std::string { std::string result; - boost::filesystem::load_string_file(file_path.string(), result); + + if (!exists(file_path)) { + throw std::runtime_error("File not found: " + file_path.string()); + } + + // adapted from boost::filesystem::load_string_file, which was removed in 1.84 + std::ifstream file; + file.exceptions(std::ios_base::failbit | std::ios_base::badbit); + file.open(file_path, std::ios_base::binary); + const std::uintmax_t sz = std::filesystem::file_size(file_path); + if ((sz > static_cast<std::uintmax_t>((std::numeric_limits<std::streamsize>::max)()))) { + throw(std::length_error("File size exceeds max read size")); + } + result.resize(static_cast<std::size_t>(sz), '\0'); + if (sz > 0U) { + file.read(result.data(), static_cast<std::streamsize>(sz)); + } + return result; } @@ -115,7 +133,7 @@ auto base64_encode(const std::string &plain) -> std::string { auto size_encoded = boost::beast::detail::base64::encoded_size(size_plain); std::string result = std::string(size_encoded, '\0'); - boost::beast::detail::base64::encode(&result[0], plain.c_str(), size_plain); + boost::beast::detail::base64::encode(result.data(), plain.c_str(), size_plain); return result; } @@ -123,14 +141,13 @@ auto base64_encode(const std::string &plain) -> std::string { auto _load_json_file(const path &json_file) -> value { assert(exists(json_file)); - constexpr auto buffer_size = std::size_t(4096); + constexpr auto buffer_size = static_cast<size_t>(4096); auto stream = ifstream(json_file); stream.exceptions(std::ios_base::badbit); stream_parser parser; - auto result = std::string(); auto buffer = std::string(buffer_size, '\0'); - while (stream.read(&buffer[0], buffer_size)) { + while (stream.read(buffer.data(), buffer_size)) { parser.write(buffer.c_str(), stream.gcount()); } parser.write(buffer.c_str(), stream.gcount()); @@ -182,4 +199,4 @@ auto JsonValue::operator=(JsonValue &&other) noexcept -> JsonValue & { return *this; } -} // namespace caosdb::utility +} // namespace linkahead::utility diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 659254bf1e215c6c203eb82c0d2bca030a12a0b9..7b70f9f14fcb0594f166713bee5821a96ae2f029 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,8 +1,8 @@ # -# This file is a part of the CaosDB Project. +# This file is a part of the LinkAhead Project. # # Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> -# Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> +# Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -32,7 +32,7 @@ set(test_cases test_transaction test_utility test_value - test_ccaosdb + test_clinkahead ) IF(BUILD_ACM) @@ -51,21 +51,24 @@ set(_CMAKE_CXX_CLANG_TIDY_TEST_CHECKS ) # add special cmake functions for gtest +find_package(GTest CONFIG REQUIRED) include(GoogleTest) +message(DEBUG "CMAKE_INCLUDE_PATH: ${CMAKE_INCLUDE_PATH}") # loop over all test cases and add them to the test runner list(LENGTH test_cases len_test_cases) math(EXPR len_test_cases "${len_test_cases} - 1") foreach (i RANGE "${len_test_cases}") list(GET test_cases ${i} test_case_name) - add_executable(${test_case_name} ${test_case_name}.cpp) - set(libcaosdb_TEST_SRC "${CMAKE_CURRENT_SOURCE_DIR}/${test_case_name}.cpp - ${libcaosdb_TEST_SRC}") + add_executable(${test_case_name} ${test_case_name}.cpp) + set(liblinkahead_TEST_SRC "${CMAKE_CURRENT_SOURCE_DIR}/${test_case_name}.cpp + ${liblinkahead_TEST_SRC}") target_link_libraries(${test_case_name} - PRIVATE ${LIBCAOSDB} ccaosdb ${CONAN_LIBS_GTEST} ${CONAN_LIBS_BOOST}) + PRIVATE GTest::gtest_main linkahead clinkahead GTest::gtest caosdb_grpc ${Boost_LIBRARIES}) target_include_directories(${test_case_name} - PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) + PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/include ${CMAKE_CURRENT_BINARY_DIR}) + set_target_properties(${test_case_name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}") if(_LINTING) message(STATUS "linting for tests: ${_CMAKE_CXX_INCLUDE_WHAT_YOU_USE}") set_target_properties(${test_case_name} @@ -74,16 +77,19 @@ foreach (i RANGE "${len_test_cases}") CXX_INCLUDE_WHAT_YOU_USE "${_CMAKE_CXX_INCLUDE_WHAT_YOU_USE}") endif() gtest_discover_tests(${test_case_name} - WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" + WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" PROPERTIES - LABELS "caosdb-cpplib-unit-tests" + LABELS "linkahead-cpplib-unit-tests" ) endforeach () +message(STATUS "CMAKE_BINARY_DIR ${CMAKE_BINARY_DIR}") +message(STATUS "CMAKE_CURRENT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}") + # copy test data to build dir set(TEST_DATA_DIR "${CMAKE_CURRENT_SOURCE_DIR}/test_data") -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/caosdb_test_utility.h.in - ${CMAKE_CURRENT_BINARY_DIR}/caosdb_test_utility.h) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/linkahead_test_utility.h.in + ${CMAKE_CURRENT_BINARY_DIR}/linkahead_test_utility.h) @@ -96,30 +102,30 @@ include(CodeCoverage) if (LCOV_PATH) message(STATUS "Found LCOV: ${LCOV_PATH}") - target_link_libraries(caosdb gcov) - target_link_libraries(ccaosdb gcov) + target_link_libraries(linkahead gcov) + target_link_libraries(clinkahead gcov) setup_target_for_coverage_lcov( NAME unit_test_coverage - EXECUTABLE ctest -L caosdb-cpplib-unit-tests + EXECUTABLE ctest -L linkahead-cpplib-unit-tests EXCLUDE "${CMAKE_BINARY_DIR}/*" - DEPENDENCIES caosdb ccaosdb ${test_cases} + DEPENDENCIES linkahead clinkahead ${test_cases} LCOV_ARGS --rc lcov_branch_coverage=1 --no-external GENHTML_ARGS --rc lcov_branch_coverage=1 ) message(STATUS "Adding COMPILE_FLAGS for coverage: ${COVERAGE_COMPILER_FLAGS}") - set(TARGET_CAOSDB_COMPILE_FLAGS "${TARGET_CAOSDB_COMPILE_FLAGS} ${COVERAGE_COMPILER_FLAGS}") - set(TARGET_CCAOSDB_COMPILE_FLAGS "${TARGET_CCAOSDB_COMPILE_FLAGS} ${COVERAGE_COMPILER_FLAGS}") - set(TARGET_CAOSDB_COMPILE_FLAGS ${TARGET_CAOSDB_COMPILE_FLAGS} PARENT_SCOPE) - set(TARGET_CCAOSDB_COMPILE_FLAGS ${TARGET_CCAOSDB_COMPILE_FLAGS} PARENT_SCOPE) - set_target_properties(caosdb PROPERTIES - COMPILE_FLAGS "${TARGET_CAOSDB_COMPILE_FLAGS}") - set_target_properties(ccaosdb PROPERTIES - COMPILE_FLAGS "${TARGET_CCAOSDB_COMPILE_FLAGS}") + set(TARGET_LINKAHEAD_COMPILE_FLAGS "${TARGET_LINKAHEAD_COMPILE_FLAGS} ${COVERAGE_COMPILER_FLAGS}") + set(TARGET_CLINKAHEAD_COMPILE_FLAGS "${TARGET_CLINKAHEAD_COMPILE_FLAGS} ${COVERAGE_COMPILER_FLAGS}") + set(TARGET_LINKAHEAD_COMPILE_FLAGS ${TARGET_LINKAHEAD_COMPILE_FLAGS} PARENT_SCOPE) + set(TARGET_CLINKAHEAD_COMPILE_FLAGS ${TARGET_CLINKAHEAD_COMPILE_FLAGS} PARENT_SCOPE) + set_target_properties(linkahead PROPERTIES + COMPILE_FLAGS "${TARGET_LINKAHEAD_COMPILE_FLAGS}") + set_target_properties(clinkahead PROPERTIES + COMPILE_FLAGS "${TARGET_CLINKAHEAD_COMPILE_FLAGS}") else () if (NOT SKIP_CODE_COVERAGE) message(WARNING "Could not generate code coverage report. Please install lcov.") - add_custom_target(unit_test_coverage ctest -L caosdb-cpplib-unit-tests - DEPENDS caosdb ccaosdb ${test_cases} + add_custom_target(unit_test_coverage ctest -L linkahead-cpplib-unit-tests + DEPENDS linkahead clinkahead ${test_cases} ) endif() endif () diff --git a/test/caosdb_test_utility.h.in b/test/linkahead_test_utility.h.in similarity index 95% rename from test/caosdb_test_utility.h.in rename to test/linkahead_test_utility.h.in index 8c3761e9f57432c8345f56bd4734fe633247228a..eff2eacdc933cbcbf8adc57ffc939cbd61b54afa 100644 --- a/test/caosdb_test_utility.h.in +++ b/test/linkahead_test_utility.h.in @@ -1,9 +1,9 @@ /* * - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -20,11 +20,11 @@ * */ -#ifndef CAOSDB_TEST_UTILITY_H -#define CAOSDB_TEST_UTILITY_H +#ifndef LINKAHEAD_TEST_UTILITY_H +#define LINKAHEAD_TEST_UTILITY_H #include <string> /** - * @file caosdb_test_utility.h + * @file linkahead_test_utility.h * @brief Utility for the unit tests * @author Timm Fitschen * @date 2021-07-07 diff --git a/test/test_ccaosdb.cpp b/test/test_ccaosdb.cpp deleted file mode 100644 index 71c2a829316b5b5418702686c6ea0fdfa48e5198..0000000000000000000000000000000000000000 --- a/test/test_ccaosdb.cpp +++ /dev/null @@ -1,1010 +0,0 @@ -/* - * - * This file is a part of the CaosDB Project. - * - * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - */ - -#include "caosdb/configuration.h" -#include "caosdb/status_code.h" // for StatusCode -#include "caosdb_test_utility.h" // for EXPECT_THROW_MESSAGE, TEST_DATA_DIR -#include "ccaosdb.h" // for caosdb_utility_get_env_fallback -#include <cstdint> // for int64_t -#include <cstring> // for strcmp -#include <gtest/gtest-message.h> // for Message -#include <gtest/gtest-test-part.h> // for SuiteApiResolver, TestFactoryImpl -#include <gtest/gtest_pred_impl.h> // for Test, TestInfo, EXPECT_EQ, TEST -#include <string> // for allocator, operator+, string,... - -class test_ccaosdb : public ::testing::Test { -protected: - void SetUp() override { - caosdb::configuration::ConfigurationManager::Clear(); - caosdb::configuration::ConfigurationManager::LoadSingleJSONConfiguration( - TEST_DATA_DIR + "/test_caosdb_client.json"); - } - - void TearDown() override { caosdb::configuration::ConfigurationManager::Clear(); } -}; - -TEST_F(test_ccaosdb, test_get_env_fallback) { - const char *const some_var = caosdb_utility_get_env_fallback("SOME_ENV_VAR", "fall-back"); - EXPECT_EQ("fall-back", some_var); -} - -TEST_F(test_ccaosdb, test_other_client_error) { - EXPECT_EQ(caosdb_status_code_OTHER_CLIENT_ERROR(), caosdb::StatusCode::OTHER_CLIENT_ERROR); -} - -TEST_F(test_ccaosdb, test_get_default_connection) { - caosdb_connection_connection out; - - caosdb_connection_connection_manager_get_default_connection(&out); - EXPECT_TRUE(out.wrapped_connection); -} - -TEST_F(test_ccaosdb, test_get_connection) { - caosdb_connection_connection out; - - caosdb_connection_connection_manager_get_connection(&out, "local-caosdb-admin"); - EXPECT_TRUE(out.wrapped_connection); -} - -TEST_F(test_ccaosdb, test_execute_transaction) { - caosdb_connection_connection connection; - caosdb_connection_connection_manager_get_connection(&connection, "local-caosdb-admin"); - - caosdb_transaction_transaction transaction; - caosdb_connection_connection_create_transaction(&connection, &transaction); - - EXPECT_TRUE(transaction.wrapped_transaction); - - int return_code(caosdb_transaction_transaction_retrieve_by_id(&transaction, "some_id")); - EXPECT_EQ(return_code, caosdb::StatusCode::GO_ON); - - return_code = caosdb_transaction_transaction_execute(&transaction); - EXPECT_EQ(return_code, caosdb::StatusCode::CONNECTION_ERROR); - - return_code = caosdb_transaction_delete_transaction(&transaction); - EXPECT_EQ(return_code, 0); - - caosdb_transaction_transaction multi_transaction; - caosdb_connection_connection_create_transaction(&connection, &multi_transaction); - - // We explicitely want to define a C-style array here, so we disable - // linting - const char *ids[] = {"id1", "id2", "id3"}; // NOLINT - return_code = caosdb_transaction_transaction_retrieve_by_ids(&multi_transaction, ids, 3); - EXPECT_EQ(return_code, caosdb::StatusCode::GO_ON); - - return_code = caosdb_transaction_delete_transaction(&multi_transaction); - EXPECT_EQ(return_code, 0); -} - -TEST_F(test_ccaosdb, test_multi_retrieve) { - caosdb_connection_connection connection; - caosdb_connection_connection_manager_get_connection(&connection, "local-caosdb-admin"); - - caosdb_transaction_transaction multi_transaction; - caosdb_connection_connection_create_transaction(&connection, &multi_transaction); - - // We explicitely want to define a C-style array here, so we disable - // linting - const char *ids[] = {"id1", "id2", "id3"}; // NOLINT - int return_code(caosdb_transaction_transaction_retrieve_by_ids(&multi_transaction, ids, 3)); - EXPECT_EQ(return_code, caosdb::StatusCode::GO_ON); - - return_code = caosdb_transaction_delete_transaction(&multi_transaction); - EXPECT_EQ(return_code, 0); -} - -TEST_F(test_ccaosdb, test_query) { - caosdb_connection_connection connection; - caosdb_connection_connection_manager_get_connection(&connection, "local-caosdb-admin"); - - caosdb_transaction_transaction transaction; - caosdb_connection_connection_create_transaction(&connection, &transaction); - - int return_code(caosdb_transaction_transaction_query(&transaction, "FIND ENTITY WITH id=123")); - EXPECT_EQ(return_code, caosdb::StatusCode::GO_ON); - - return_code = caosdb_transaction_delete_transaction(&transaction); - EXPECT_EQ(return_code, 0); -} - -TEST_F(test_ccaosdb, test_datatype) { - - caosdb_entity_datatype atomic; - // check that this fails - int return_code(caosdb_entity_create_atomic_datatype(&atomic, "some type")); - EXPECT_EQ(return_code, caosdb::StatusCode::ENUM_MAPPING_ERROR); - - return_code = caosdb_entity_create_atomic_datatype(&atomic, "INTEGER"); - EXPECT_EQ(return_code, 0); - - caosdb_entity_datatype reference; - return_code = caosdb_entity_create_reference_datatype(&reference, "MyType"); - EXPECT_EQ(return_code, 0); - - caosdb_entity_datatype list_of_atomics; - return_code = caosdb_entity_create_atomic_list_datatype(&list_of_atomics, "DATETIME"); - EXPECT_EQ(return_code, 0); - - caosdb_entity_datatype list_of_references; - return_code = caosdb_entity_create_reference_list_datatype(&list_of_references, "MyType"); - EXPECT_EQ(return_code, 0); - - bool is_a(false); - return_code = caosdb_entity_datatype_is_undefined(&atomic, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_FALSE(is_a); - return_code = caosdb_entity_datatype_is_atomic(&atomic, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_TRUE(is_a); - return_code = caosdb_entity_datatype_is_reference(&atomic, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_FALSE(is_a); - return_code = caosdb_entity_datatype_is_list_of_atomic(&atomic, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_FALSE(is_a); - return_code = caosdb_entity_datatype_is_list_of_reference(&atomic, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_FALSE(is_a); - - return_code = caosdb_entity_datatype_is_atomic(&reference, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_FALSE(is_a); - return_code = caosdb_entity_datatype_is_reference(&reference, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_TRUE(is_a); - return_code = caosdb_entity_datatype_is_list_of_atomic(&reference, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_FALSE(is_a); - return_code = caosdb_entity_datatype_is_list_of_reference(&reference, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_FALSE(is_a); - - return_code = caosdb_entity_datatype_is_atomic(&list_of_atomics, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_FALSE(is_a); - return_code = caosdb_entity_datatype_is_reference(&list_of_atomics, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_FALSE(is_a); - return_code = caosdb_entity_datatype_is_list_of_atomic(&list_of_atomics, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_TRUE(is_a); - return_code = caosdb_entity_datatype_is_list_of_reference(&list_of_atomics, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_FALSE(is_a); - - return_code = caosdb_entity_datatype_is_atomic(&list_of_references, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_FALSE(is_a); - return_code = caosdb_entity_datatype_is_reference(&list_of_references, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_FALSE(is_a); - return_code = caosdb_entity_datatype_is_list_of_atomic(&list_of_references, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_FALSE(is_a); - return_code = caosdb_entity_datatype_is_list_of_reference(&list_of_references, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_TRUE(is_a); - - char *name = nullptr; // NOLINT - return_code = caosdb_entity_datatype_get_datatype_name(&atomic, &name); - EXPECT_EQ(return_code, 0); - EXPECT_STREQ(name, "INTEGER"); - - return_code = caosdb_entity_datatype_get_datatype_name(&reference, &name); - EXPECT_EQ(return_code, 0); - EXPECT_STREQ(name, "MyType"); - - return_code = caosdb_entity_datatype_get_datatype_name(&list_of_atomics, &name); - EXPECT_EQ(return_code, 0); - EXPECT_STREQ(name, "DATETIME"); - - return_code = caosdb_entity_datatype_get_datatype_name(&list_of_references, &name); - EXPECT_EQ(return_code, 0); - EXPECT_STREQ(name, "MyType"); - - return_code = caosdb_entity_delete_datatype(&atomic); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_datatype(&reference); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_datatype(&list_of_atomics); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_datatype(&list_of_references); - EXPECT_EQ(return_code, 0); -} - -TEST_F(test_ccaosdb, test_value) { - - caosdb_entity_value string_value; - int return_code(caosdb_entity_create_string_value(&string_value, "value")); - EXPECT_EQ(return_code, 0); - - caosdb_entity_value int_value; - return_code = caosdb_entity_create_int_value(&int_value, 27); - EXPECT_EQ(return_code, 0); - - caosdb_entity_value bool_value; - return_code = caosdb_entity_create_bool_value(&bool_value, true); - EXPECT_EQ(return_code, 0); - - caosdb_entity_value double_value; - return_code = caosdb_entity_create_double_value(&double_value, 2.7); - EXPECT_EQ(return_code, 0); - - caosdb_entity_value string_vector_value; - const char *string_values[] = {"a", "b", "c"}; // NOLINT - return_code = caosdb_entity_create_string_vector_value(&string_vector_value, string_values, 3); - EXPECT_EQ(return_code, 0); - - caosdb_entity_value int_vector_value; - const int64_t int_values[] = {1, 2, 3}; // NOLINT - return_code = caosdb_entity_create_int_vector_value(&int_vector_value, int_values, 3); - EXPECT_EQ(return_code, 0); - - caosdb_entity_value double_vector_value; - const double double_values[] = {1.1, 2.2, 3.3}; // NOLINT - return_code = caosdb_entity_create_double_vector_value(&double_vector_value, double_values, 3); - EXPECT_EQ(return_code, 0); - - caosdb_entity_value bool_vector_value; - const bool bool_values[] = {true, false, false}; // NOLINT - return_code = caosdb_entity_create_bool_vector_value(&bool_vector_value, bool_values, 3); - EXPECT_EQ(return_code, 0); - - // One thorough check, afterwards only the ones that should be true - bool is_a(false); - return_code = caosdb_entity_value_is_null(&string_value, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_FALSE(is_a); - return_code = caosdb_entity_value_is_string(&string_value, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_TRUE(is_a); - return_code = caosdb_entity_value_is_double(&string_value, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_FALSE(is_a); - return_code = caosdb_entity_value_is_integer(&string_value, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_FALSE(is_a); - return_code = caosdb_entity_value_is_bool(&string_value, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_FALSE(is_a); - return_code = caosdb_entity_value_is_vector(&string_value, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_FALSE(is_a); - - caosdb_entity_value_is_integer(&int_value, &is_a); - EXPECT_TRUE(is_a); - - caosdb_entity_value_is_bool(&bool_value, &is_a); - EXPECT_TRUE(is_a); - - caosdb_entity_value_is_double(&double_value, &is_a); - EXPECT_TRUE(is_a); - - caosdb_entity_value_is_vector(&string_vector_value, &is_a); - EXPECT_TRUE(is_a); - - caosdb_entity_value_is_vector(&int_vector_value, &is_a); - EXPECT_TRUE(is_a); - - caosdb_entity_value_is_vector(&double_vector_value, &is_a); - EXPECT_TRUE(is_a); - - caosdb_entity_value_is_vector(&bool_vector_value, &is_a); - EXPECT_TRUE(is_a); - - char *out_string = nullptr; // NOLINT - return_code = caosdb_entity_value_get_as_string(&string_value, &out_string); - EXPECT_EQ(return_code, 0); - EXPECT_STREQ(out_string, "value"); - - int64_t out_int(0); - return_code = caosdb_entity_value_get_as_integer(&int_value, &out_int); - EXPECT_EQ(return_code, 0); - EXPECT_EQ(out_int, 27); - - bool out_bool(false); - return_code = caosdb_entity_value_get_as_bool(&bool_value, &out_bool); - EXPECT_EQ(return_code, 0); - EXPECT_TRUE(out_bool); - - double out_double(0); - return_code = caosdb_entity_value_get_as_double(&double_value, &out_double); - EXPECT_EQ(return_code, 0); - EXPECT_EQ(out_double, 2.7); - - int list_length(0); - return_code = caosdb_entity_value_get_as_vector_size(&string_vector_value, &list_length); - EXPECT_EQ(return_code, 0); - EXPECT_EQ(list_length, 3); - return_code = caosdb_entity_value_get_as_vector_size(&int_vector_value, &list_length); - EXPECT_EQ(return_code, 0); - EXPECT_EQ(list_length, 3); - return_code = caosdb_entity_value_get_as_vector_size(&double_vector_value, &list_length); - EXPECT_EQ(return_code, 0); - EXPECT_EQ(list_length, 3); - return_code = caosdb_entity_value_get_as_vector_size(&bool_vector_value, &list_length); - EXPECT_EQ(return_code, 0); - EXPECT_EQ(list_length, 3); - - // Only check for one, rest should be covered by this + scalar values - caosdb_entity_value out_val; - return_code = caosdb_entity_value_get_as_vector_at(&string_vector_value, &out_val, 0); - EXPECT_EQ(return_code, 0); - caosdb_entity_value_get_as_string(&out_val, &out_string); - EXPECT_STREQ(out_string, "a"); - return_code = caosdb_entity_value_get_as_vector_at(&string_vector_value, &out_val, 1); - EXPECT_EQ(return_code, 0); - caosdb_entity_value_get_as_string(&out_val, &out_string); - EXPECT_STREQ(out_string, "b"); - return_code = caosdb_entity_value_get_as_vector_at(&string_vector_value, &out_val, 2); - EXPECT_EQ(return_code, 0); - caosdb_entity_value_get_as_string(&out_val, &out_string); - EXPECT_STREQ(out_string, "c"); - - return_code = caosdb_entity_delete_value(&string_value); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_value(&int_value); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_value(&bool_value); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_value(&double_value); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_value(&string_vector_value); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_value(&int_vector_value); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_value(&double_vector_value); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_value(&bool_vector_value); - EXPECT_EQ(return_code, 0); -} - -TEST_F(test_ccaosdb, test_entity) { - caosdb_entity_entity entity; - - int return_code(caosdb_entity_create_entity(&entity)); - EXPECT_EQ(return_code, 0); - - // cannot be created again without deletion - // return_code = caosdb_entity_create_entity(&entity); - // EXPECT_EQ(return_code, caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR); - - // deletion and re-creation is ok - return_code = caosdb_entity_delete_entity(&entity); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_create_entity(&entity); - EXPECT_EQ(return_code, 0); - - // In-depth check for one pair of setter and getter, just compare - // the strings for the rest - return_code = caosdb_entity_entity_set_name(&entity, "length"); - EXPECT_EQ(return_code, 0); - char *out = nullptr; // NOLINT - return_code = caosdb_entity_entity_get_name(&entity, &out); - EXPECT_EQ(return_code, 0); - EXPECT_EQ(strcmp(out, "length"), 0); - - // test call without validation of result - return_code = caosdb_entity_entity_set_role(&entity, "FILE"); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_entity_set_local_path( - &entity, (TEST_DATA_DIR + "/test_caosdb_client.json").c_str()); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_entity_get_local_path(&entity, &out); - EXPECT_EQ(return_code, 0); - EXPECT_EQ(strcmp(out, (TEST_DATA_DIR + "/test_caosdb_client.json").c_str()), 0); - - // invalid role - return_code = caosdb_entity_entity_set_role(&entity, "Role does not exist"); - EXPECT_EQ(return_code, caosdb::StatusCode::ENUM_MAPPING_ERROR); - - caosdb_entity_entity_set_role(&entity, "PROPERTY"); - caosdb_entity_entity_get_role(&entity, &out); - EXPECT_EQ(strcmp(out, "PROPERTY"), 0); - - caosdb_entity_entity_set_description(&entity, "The length of an object"); - caosdb_entity_entity_get_description(&entity, &out); - EXPECT_EQ(strcmp(out, "The length of an object"), 0); - - caosdb_entity_datatype in_type; - caosdb_entity_create_atomic_datatype(&in_type, "DOUBLE"); - caosdb_entity_entity_set_datatype(&entity, &in_type); - - // verify that this doesn't work ... - // return_code = caosdb_entity_entity_get_datatype(&entity, &in_type); - // EXPECT_EQ(return_code, caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR); - caosdb_entity_datatype out_type; - // ... but does with a clean property - return_code = caosdb_entity_entity_get_datatype(&entity, &out_type); - EXPECT_EQ(return_code, 0); - bool is_a(false); - return_code = caosdb_entity_datatype_is_atomic(&out_type, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_TRUE(is_a); - return_code = caosdb_entity_datatype_is_reference(&out_type, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_FALSE(is_a); - return_code = caosdb_entity_datatype_is_list_of_atomic(&out_type, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_FALSE(is_a); - return_code = caosdb_entity_datatype_is_list_of_reference(&out_type, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_FALSE(is_a); - - caosdb_entity_datatype_get_datatype_name(&out_type, &out); - EXPECT_STREQ(out, "DOUBLE"); - - caosdb_entity_value in_value; - return_code = caosdb_entity_create_double_value(&in_value, 5.0); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_entity_set_value(&entity, &in_value); - EXPECT_EQ(return_code, 0); - - caosdb_entity_value out_value; - return_code = caosdb_entity_entity_get_value(&entity, &out_value); - EXPECT_EQ(return_code, 0); - - caosdb_entity_value_is_double(&out_value, &is_a); - EXPECT_TRUE(is_a); - caosdb_entity_value_is_null(&out_value, &is_a); - EXPECT_FALSE(is_a); - caosdb_entity_value_is_string(&out_value, &is_a); - EXPECT_FALSE(is_a); - caosdb_entity_value_is_bool(&out_value, &is_a); - EXPECT_FALSE(is_a); - caosdb_entity_value_is_integer(&out_value, &is_a); - EXPECT_FALSE(is_a); - caosdb_entity_value_is_vector(&out_value, &is_a); - EXPECT_FALSE(is_a); - - double out_double(0); - caosdb_entity_value_get_as_double(&out_value, &out_double); - EXPECT_EQ(out_double, 5.0); - - // clear to re-use - return_code = caosdb_entity_delete_datatype(&in_type); - EXPECT_EQ(return_code, 0); - caosdb_entity_create_reference_list_datatype(&in_type, "Person"); - caosdb_entity_entity_set_datatype(&entity, &in_type); - - // works without clearing since datatype is managed by the owning entity - caosdb_entity_entity_get_datatype(&entity, &out_type); - return_code = caosdb_entity_datatype_is_atomic(&out_type, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_FALSE(is_a); - return_code = caosdb_entity_datatype_is_reference(&out_type, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_FALSE(is_a); - return_code = caosdb_entity_datatype_is_list_of_atomic(&out_type, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_FALSE(is_a); - return_code = caosdb_entity_datatype_is_list_of_reference(&out_type, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_TRUE(is_a); - - caosdb_entity_datatype_get_datatype_name(&out_type, &out); - EXPECT_STREQ(out, "Person"); - - caosdb_entity_entity_set_unit(&entity, "m"); - caosdb_entity_entity_get_unit(&entity, &out); - EXPECT_EQ(strcmp(out, "m"), 0); - - return_code = caosdb_entity_delete_entity(&entity); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_datatype(&in_type); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_value(&in_value); - EXPECT_EQ(return_code, 0); -} - -TEST_F(test_ccaosdb, test_parent) { - caosdb_entity_parent parent; - - int return_code(caosdb_entity_create_parent(&parent)); - EXPECT_EQ(return_code, 0); - - caosdb_entity_parent_set_id(&parent, "some_id"); - caosdb_entity_parent_set_name(&parent, "some_name"); - - char *out = nullptr; // NOLINT - caosdb_entity_parent_get_id(&parent, &out); - EXPECT_EQ(strcmp(out, "some_id"), 0); - - caosdb_entity_parent_get_name(&parent, &out); - EXPECT_EQ(strcmp(out, "some_name"), 0); - - return_code = caosdb_entity_delete_parent(&parent); - EXPECT_EQ(return_code, 0); -} - -TEST_F(test_ccaosdb, test_property) { - caosdb_entity_property property; - - int return_code(caosdb_entity_create_property(&property)); - EXPECT_EQ(return_code, 0); - - caosdb_entity_property_set_id(&property, "some_id"); - caosdb_entity_property_set_name(&property, "some_name"); - - caosdb_entity_datatype in_type; - caosdb_entity_create_atomic_datatype(&in_type, "TEXT"); - caosdb_entity_property_set_datatype(&property, &in_type); - caosdb_entity_property_set_importance(&property, "FIX"); - caosdb_entity_property_set_unit(&property, "some_unit"); - caosdb_entity_value in_value; - caosdb_entity_create_string_value(&in_value, "some_value"); - caosdb_entity_property_set_value(&property, &in_value); - - char *out = nullptr; // NOLINT - caosdb_entity_property_get_id(&property, &out); - EXPECT_EQ(strcmp(out, "some_id"), 0); - - caosdb_entity_property_get_name(&property, &out); - EXPECT_EQ(strcmp(out, "some_name"), 0); - - caosdb_entity_datatype out_type; - return_code = caosdb_entity_property_get_datatype(&property, &out_type); - EXPECT_EQ(return_code, 0); - bool is_a(false); - - caosdb_entity_datatype_is_atomic(&out_type, &is_a); - EXPECT_TRUE(is_a); - caosdb_entity_datatype_is_reference(&out_type, &is_a); - EXPECT_FALSE(is_a); - caosdb_entity_datatype_is_list_of_atomic(&out_type, &is_a); - EXPECT_FALSE(is_a); - caosdb_entity_datatype_is_list_of_reference(&out_type, &is_a); - EXPECT_FALSE(is_a); - - caosdb_entity_datatype_get_datatype_name(&out_type, &out); - EXPECT_STREQ(out, "TEXT"); - - caosdb_entity_property_get_importance(&property, &out); - EXPECT_EQ(strcmp(out, "FIX"), 0); - - caosdb_entity_property_get_unit(&property, &out); - EXPECT_EQ(strcmp(out, "some_unit"), 0); - - caosdb_entity_value out_value; - return_code = caosdb_entity_property_get_value(&property, &out_value); - EXPECT_EQ(return_code, 0); - caosdb_entity_value_is_string(&out_value, &is_a); - EXPECT_TRUE(is_a); - caosdb_entity_value_get_as_string(&out_value, &out); - EXPECT_STREQ(out, "some_value"); - - return_code = caosdb_entity_delete_property(&property); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_datatype(&in_type); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_value(&in_value); - EXPECT_EQ(return_code, 0); -} - -TEST_F(test_ccaosdb, test_string_list_property) { - - caosdb_entity_property property; - int return_code(caosdb_entity_create_property(&property)); - EXPECT_EQ(return_code, 0); - - caosdb_entity_datatype in_type; - return_code = caosdb_entity_create_atomic_list_datatype(&in_type, "TEXT"); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_property_set_datatype(&property, &in_type); - EXPECT_EQ(return_code, 0); - - caosdb_entity_value in_value; - const char *value_list[] = {"val0", "val1", "val2"}; // NOLINT - return_code = caosdb_entity_create_string_vector_value(&in_value, value_list, 3); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_property_set_value(&property, &in_value); - EXPECT_EQ(return_code, 0); - - caosdb_entity_datatype out_type; - return_code = caosdb_entity_property_get_datatype(&property, &out_type); - EXPECT_EQ(return_code, 0); - - bool is_a(false); - caosdb_entity_datatype_is_atomic(&out_type, &is_a); - EXPECT_FALSE(is_a); - caosdb_entity_datatype_is_reference(&out_type, &is_a); - EXPECT_FALSE(is_a); - caosdb_entity_datatype_is_list_of_atomic(&out_type, &is_a); - EXPECT_TRUE(is_a); - caosdb_entity_datatype_is_list_of_reference(&out_type, &is_a); - EXPECT_FALSE(is_a); - char *out = nullptr; // NOLINT - caosdb_entity_datatype_get_datatype_name(&out_type, &out); - EXPECT_STREQ(out, "TEXT"); - - caosdb_entity_value out_value; - caosdb_entity_property_get_value(&property, &out_value); - caosdb_entity_value_is_vector(&out_value, &is_a); - EXPECT_TRUE(is_a); - int length(-1); - caosdb_entity_value_get_as_vector_size(&out_value, &length); - EXPECT_EQ(length, 3); - - caosdb_entity_value list_elt; - for (int i = 0; i < length; i++) { - return_code = caosdb_entity_value_get_as_vector_at(&out_value, &list_elt, i); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_value_get_as_string(&list_elt, &out); - EXPECT_EQ(return_code, 0); - EXPECT_STREQ(value_list[i], out); // NOLINT - } - - return_code = caosdb_entity_delete_property(&property); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_datatype(&in_type); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_value(&in_value); - EXPECT_EQ(return_code, 0); -} - -TEST_F(test_ccaosdb, test_int_list_property) { - - caosdb_entity_property property; - int return_code(caosdb_entity_create_property(&property)); - EXPECT_EQ(return_code, 0); - - caosdb_entity_datatype in_type; - caosdb_entity_create_atomic_list_datatype(&in_type, "INTEGER"); - return_code = caosdb_entity_property_set_datatype(&property, &in_type); - EXPECT_EQ(return_code, 0); - - const int64_t value_list[] = {1, 2, 3}; // NOLINT - caosdb_entity_value in_value; - caosdb_entity_create_int_vector_value(&in_value, value_list, 3); - return_code = caosdb_entity_property_set_value(&property, &in_value); - EXPECT_EQ(return_code, 0); - - caosdb_entity_datatype out_type; - return_code = caosdb_entity_property_get_datatype(&property, &out_type); - EXPECT_EQ(return_code, 0); - - bool is_a(false); - caosdb_entity_datatype_is_atomic(&out_type, &is_a); - EXPECT_FALSE(is_a); - caosdb_entity_datatype_is_reference(&out_type, &is_a); - EXPECT_FALSE(is_a); - caosdb_entity_datatype_is_list_of_atomic(&out_type, &is_a); - EXPECT_TRUE(is_a); - caosdb_entity_datatype_is_list_of_reference(&out_type, &is_a); - EXPECT_FALSE(is_a); - char *out = nullptr; // NOLINT - caosdb_entity_datatype_get_datatype_name(&out_type, &out); - EXPECT_STREQ(out, "INTEGER"); - - caosdb_entity_value out_value; - caosdb_entity_property_get_value(&property, &out_value); - caosdb_entity_value_is_vector(&out_value, &is_a); - EXPECT_TRUE(is_a); - int length(-1); - caosdb_entity_value_get_as_vector_size(&out_value, &length); - EXPECT_EQ(length, 3); - - int64_t out_int = -1; - caosdb_entity_value list_elt; - for (int i = 0; i < length; i++) { - return_code = caosdb_entity_value_get_as_vector_at(&out_value, &list_elt, i); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_value_get_as_integer(&list_elt, &out_int); - EXPECT_EQ(return_code, 0); - EXPECT_EQ(value_list[i], out_int); // NOLINT - } - - return_code = caosdb_entity_delete_property(&property); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_datatype(&in_type); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_value(&in_value); - EXPECT_EQ(return_code, 0); -} - -TEST_F(test_ccaosdb, test_bool_list_property) { - - caosdb_entity_property property; - int return_code(caosdb_entity_create_property(&property)); - EXPECT_EQ(return_code, 0); - - caosdb_entity_datatype in_type; - caosdb_entity_create_atomic_list_datatype(&in_type, "BOOLEAN"); - return_code = caosdb_entity_property_set_datatype(&property, &in_type); - EXPECT_EQ(return_code, 0); - - const bool value_list[] = {true, true, false}; // NOLINT - caosdb_entity_value in_value; - caosdb_entity_create_bool_vector_value(&in_value, value_list, 3); - return_code = caosdb_entity_property_set_value(&property, &in_value); - EXPECT_EQ(return_code, 0); - - caosdb_entity_datatype out_type; - return_code = caosdb_entity_property_get_datatype(&property, &out_type); - EXPECT_EQ(return_code, 0); - - bool is_a(false); - caosdb_entity_datatype_is_atomic(&out_type, &is_a); - EXPECT_FALSE(is_a); - caosdb_entity_datatype_is_reference(&out_type, &is_a); - EXPECT_FALSE(is_a); - caosdb_entity_datatype_is_list_of_atomic(&out_type, &is_a); - EXPECT_TRUE(is_a); - caosdb_entity_datatype_is_list_of_reference(&out_type, &is_a); - EXPECT_FALSE(is_a); - char *out = nullptr; // NOLINT - caosdb_entity_datatype_get_datatype_name(&out_type, &out); - EXPECT_STREQ(out, "BOOLEAN"); - - caosdb_entity_value out_value; - caosdb_entity_property_get_value(&property, &out_value); - caosdb_entity_value_is_vector(&out_value, &is_a); - EXPECT_TRUE(is_a); - int length(-1); - caosdb_entity_value_get_as_vector_size(&out_value, &length); - EXPECT_EQ(length, 3); - - bool out_bool(false); - caosdb_entity_value list_elt; - for (int i = 0; i < length; i++) { - return_code = caosdb_entity_value_get_as_vector_at(&out_value, &list_elt, i); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_value_get_as_bool(&list_elt, &out_bool); - EXPECT_EQ(return_code, 0); - EXPECT_EQ(value_list[i], out_bool); // NOLINT - } - - return_code = caosdb_entity_delete_property(&property); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_datatype(&in_type); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_value(&in_value); - EXPECT_EQ(return_code, 0); -} - -TEST_F(test_ccaosdb, test_entity_with_parent_and_property) { - caosdb_entity_parent input_parent; - int return_code(caosdb_entity_create_parent(&input_parent)); - EXPECT_EQ(return_code, 0); - - caosdb_entity_parent_set_id(&input_parent, "parent_id"); - caosdb_entity_parent_set_name(&input_parent, "parent_name"); - - caosdb_entity_property input_property; - return_code = caosdb_entity_create_property(&input_property); - EXPECT_EQ(return_code, 0); - - caosdb_entity_property_set_id(&input_property, "property_id"); - caosdb_entity_property_set_name(&input_property, "property_name"); - - caosdb_entity_datatype in_type; - caosdb_entity_create_atomic_datatype(&in_type, "TEXT"); - caosdb_entity_value in_value; - caosdb_entity_create_string_value(&in_value, "property_value"); - caosdb_entity_property_set_datatype(&input_property, &in_type); - caosdb_entity_property_set_value(&input_property, &in_value); - - caosdb_entity_entity entity; - return_code = caosdb_entity_create_entity(&entity); - EXPECT_EQ(return_code, 0); - - return_code = caosdb_entity_entity_append_parent(&entity, &input_parent); - EXPECT_EQ(return_code, 0); - - return_code = caosdb_entity_entity_append_property(&entity, &input_property); - EXPECT_EQ(return_code, 0); - - int count[] = {0}; // NOLINT - return_code = caosdb_entity_entity_get_parents_size(&entity, count); - EXPECT_EQ(return_code, 0); - EXPECT_EQ(*count, 1); - - return_code = caosdb_entity_entity_get_properties_size(&entity, count); - EXPECT_EQ(return_code, 0); - EXPECT_EQ(*count, 1); - - char *in = nullptr; // NOLINT - char *out = nullptr; // NOLINT - - // cannot assign an already assigned property - // return_code = caosdb_entity_entity_get_property(&entity, &input_property, 0); - // EXPECT_EQ(return_code, caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR); - caosdb_entity_property output_property; - return_code = caosdb_entity_entity_get_property(&entity, &output_property, 0); - EXPECT_EQ(return_code, 0); - - caosdb_entity_property_get_id(&input_property, &in); - caosdb_entity_property_get_id(&output_property, &out); - EXPECT_EQ(strcmp(in, out), 0); - - caosdb_entity_property_get_name(&input_property, &in); - caosdb_entity_property_get_name(&output_property, &out); - EXPECT_EQ(strcmp(in, out), 0); - - caosdb_entity_datatype out_type; - caosdb_entity_property_get_datatype(&output_property, &out_type); - - bool in_is(false); - bool out_is(false); - caosdb_entity_datatype_is_atomic(&in_type, &in_is); - caosdb_entity_datatype_is_atomic(&out_type, &out_is); - EXPECT_EQ(in_is, out_is); - caosdb_entity_datatype_is_reference(&in_type, &in_is); - caosdb_entity_datatype_is_reference(&out_type, &out_is); - EXPECT_EQ(in_is, out_is); - caosdb_entity_datatype_is_list_of_atomic(&in_type, &in_is); - caosdb_entity_datatype_is_list_of_atomic(&out_type, &out_is); - EXPECT_EQ(in_is, out_is); - caosdb_entity_datatype_is_list_of_reference(&in_type, &in_is); - caosdb_entity_datatype_is_list_of_reference(&out_type, &out_is); - EXPECT_EQ(in_is, out_is); - - caosdb_entity_datatype_get_datatype_name(&in_type, &in); - caosdb_entity_datatype_get_datatype_name(&out_type, &out); - EXPECT_STREQ(in, out); - - caosdb_entity_value out_value; - caosdb_entity_property_get_value(&output_property, &out_value); - caosdb_entity_value_is_string(&in_value, &in_is); - EXPECT_TRUE(in_is); - caosdb_entity_value_is_string(&out_value, &out_is); - EXPECT_TRUE(out_is); - caosdb_entity_value_get_as_string(&in_value, &in); - caosdb_entity_value_get_as_string(&out_value, &out); - EXPECT_STREQ(in, out); - - caosdb_entity_parent output_parent; - return_code = caosdb_entity_entity_get_parent(&entity, &output_parent, 0); - EXPECT_EQ(return_code, 0); - - caosdb_entity_parent_get_id(&input_parent, &in); - caosdb_entity_parent_get_id(&output_parent, &out); - EXPECT_EQ(strcmp(in, out), 0); - - caosdb_entity_parent_get_name(&input_parent, &in); - caosdb_entity_parent_get_name(&output_parent, &out); - EXPECT_EQ(strcmp(in, out), 0); - - // Delete everything - return_code = caosdb_entity_delete_parent(&input_parent); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_property(&input_property); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_entity(&entity); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_datatype(&in_type); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_value(&in_value); - EXPECT_EQ(return_code, 0); - - // This tests the `_deletable` flag. The wrapped cpp objects of - // `output_parent` and `output_property` are owned by the entity, so - // they have been deleted together with the entity. With a wrong - // `_deletable` flag, the following would cause segfaults. - // - return_code = caosdb_entity_delete_parent(&output_parent); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_property(&output_property); - EXPECT_EQ(return_code, 0); -} - -TEST_F(test_ccaosdb, test_remove_property) { - caosdb_entity_entity entity; - int return_code(caosdb_entity_create_entity(&entity)); - EXPECT_EQ(return_code, 0); - - // Create two properties with names - caosdb_entity_property in_prop_1; - return_code = caosdb_entity_create_property(&in_prop_1); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_property_set_name(&in_prop_1, "Property 1"); - EXPECT_EQ(return_code, 0); - - caosdb_entity_property in_prop_2; - return_code = caosdb_entity_create_property(&in_prop_2); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_property_set_name(&in_prop_2, "Property 2"); - EXPECT_EQ(return_code, 0); - - // Append them - return_code = caosdb_entity_entity_append_property(&entity, &in_prop_1); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_entity_append_property(&entity, &in_prop_2); - EXPECT_EQ(return_code, 0); - - // Delete one and see that the number of properties decreases by one - int count[] = {0}; // NOLINT - return_code = caosdb_entity_entity_get_properties_size(&entity, count); - EXPECT_EQ(return_code, 0); - EXPECT_EQ(*count, 2); - - return_code = caosdb_entity_entity_remove_property(&entity, 0); - EXPECT_EQ(return_code, 0); - - return_code = caosdb_entity_entity_get_properties_size(&entity, count); - EXPECT_EQ(return_code, 0); - EXPECT_EQ(*count, 1); - - caosdb_entity_property out_prop; - return_code = caosdb_entity_entity_get_property(&entity, &out_prop, 0); - EXPECT_EQ(return_code, 0); - - char *in = nullptr; // NOLINT - char *out = nullptr; // NOLINT - - // Deleted the first property, so the second one should remain. - return_code = caosdb_entity_property_get_name(&in_prop_2, &in); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_property_get_name(&out_prop, &out); - EXPECT_EQ(return_code, 0); - - EXPECT_EQ(strcmp(in, out), 0); - - // Delete everything we have created - return_code = caosdb_entity_delete_property(&in_prop_2); - EXPECT_EQ(return_code, 0); - - return_code = caosdb_entity_delete_property(&in_prop_1); - EXPECT_EQ(return_code, 0); - - return_code = caosdb_entity_delete_entity(&entity); - EXPECT_EQ(return_code, 0); -} - -TEST_F(test_ccaosdb, test_insert_update_delete) { - // Only test adding to a transaction. Excution and results are - // tested in integration tests. - caosdb_connection_connection connection; - caosdb_connection_connection_manager_get_default_connection(&connection); - - caosdb_transaction_transaction insert_transaction; - caosdb_connection_connection_create_transaction(&connection, &insert_transaction); - - caosdb_entity_entity entity; - caosdb_entity_create_entity(&entity); - caosdb_entity_entity_set_name(&entity, "some_name"); - caosdb_entity_entity_set_local_path(&entity, "some_name"); - caosdb_entity_entity_set_file_path(&entity, "some_name"); - - auto return_code = caosdb_transaction_transaction_insert_entity(&insert_transaction, &entity); - EXPECT_EQ(return_code, caosdb::StatusCode::GO_ON); - - caosdb_transaction_transaction update_transaction; - caosdb_connection_connection_create_transaction(&connection, &update_transaction); - - return_code = caosdb_transaction_transaction_update_entity(&update_transaction, &entity); - // No ID, so this should be an error - EXPECT_EQ(return_code, caosdb::StatusCode::ORIGINAL_ENTITY_MISSING_ID); - - caosdb_transaction_transaction delete_transaction; - caosdb_connection_connection_create_transaction(&connection, &delete_transaction); - - return_code = caosdb_transaction_transaction_delete_by_id(&delete_transaction, "some_id"); - // Could add further deletions - EXPECT_EQ(return_code, caosdb::StatusCode::GO_ON); - - caosdb_entity_delete_entity(&entity); - caosdb_transaction_delete_transaction(&insert_transaction); - caosdb_transaction_delete_transaction(&update_transaction); - caosdb_transaction_delete_transaction(&delete_transaction); -} diff --git a/test/test_clinkahead.cpp b/test/test_clinkahead.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a46f41e0dec8bfe20eb80c3ac72b9605192f4ccd --- /dev/null +++ b/test/test_clinkahead.cpp @@ -0,0 +1,1010 @@ +/* + * + * This file is a part of the LinkAhead Project. + * + * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + * + */ + +#include <gtest/gtest.h> +#include <cstdint> // for int64_t +#include <cstring> // for strcmp +#include <filesystem> // for path +#include <string> // for allocator, basic_string, operator+ +#include "clinkahead.h" // for linkahead_entity_delete_value +#include "linkahead/configuration.h" // for ConfigurationManager +#include "linkahead/status_code.h" // for StatusCode +#include "linkahead_test_utility.h" // for TEST_DATA_DIR + +class test_clinkahead : public ::testing::Test { +protected: + void SetUp() override { + linkahead::configuration::ConfigurationManager::Clear(); + linkahead::configuration::ConfigurationManager::LoadSingleJSONConfiguration( + TEST_DATA_DIR + "/test_linkahead_client.json"); + } + + void TearDown() override { linkahead::configuration::ConfigurationManager::Clear(); } +}; + +TEST_F(test_clinkahead, test_get_env_fallback) { + constexpr auto fall_back = "fall-back"; + const char *const some_var = linkahead_utility_get_env_fallback("SOME_ENV_VAR", fall_back); + EXPECT_EQ(fall_back, some_var); +} + +TEST_F(test_clinkahead, test_other_client_error) { + EXPECT_EQ(linkahead_status_code_OTHER_CLIENT_ERROR(), linkahead::StatusCode::OTHER_CLIENT_ERROR); +} + +TEST_F(test_clinkahead, test_get_default_connection) { + linkahead_connection_connection out; + + linkahead_connection_connection_manager_get_default_connection(&out); + EXPECT_TRUE(out.wrapped_connection); +} + +TEST_F(test_clinkahead, test_get_connection) { + linkahead_connection_connection out; + + linkahead_connection_connection_manager_get_connection(&out, "local-linkahead-admin"); + EXPECT_TRUE(out.wrapped_connection); +} + +TEST_F(test_clinkahead, test_execute_transaction) { + linkahead_connection_connection connection; + linkahead_connection_connection_manager_get_connection(&connection, "local-linkahead-admin"); + + linkahead_transaction_transaction transaction; + linkahead_connection_connection_create_transaction(&connection, &transaction); + + EXPECT_TRUE(transaction.wrapped_transaction); + + int return_code(linkahead_transaction_transaction_retrieve_by_id(&transaction, "some_id")); + EXPECT_EQ(return_code, linkahead::StatusCode::GO_ON); + + return_code = linkahead_transaction_transaction_execute(&transaction); + EXPECT_EQ(return_code, linkahead::StatusCode::CONNECTION_ERROR); + + return_code = linkahead_transaction_delete_transaction(&transaction); + EXPECT_EQ(return_code, 0); + + linkahead_transaction_transaction multi_transaction; + linkahead_connection_connection_create_transaction(&connection, &multi_transaction); + + // We explicitely want to define a C-style array here, so we disable + // linting + const char *ids[] = {"id1", "id2", "id3"}; // NOLINT + return_code = linkahead_transaction_transaction_retrieve_by_ids(&multi_transaction, ids, 3); + EXPECT_EQ(return_code, linkahead::StatusCode::GO_ON); + + return_code = linkahead_transaction_delete_transaction(&multi_transaction); + EXPECT_EQ(return_code, 0); +} + +TEST_F(test_clinkahead, test_multi_retrieve) { + linkahead_connection_connection connection; + linkahead_connection_connection_manager_get_connection(&connection, "local-linkahead-admin"); + + linkahead_transaction_transaction multi_transaction; + linkahead_connection_connection_create_transaction(&connection, &multi_transaction); + + // We explicitely want to define a C-style array here, so we disable + // linting + const char *ids[] = {"id1", "id2", "id3"}; // NOLINT + int return_code(linkahead_transaction_transaction_retrieve_by_ids(&multi_transaction, ids, 3)); + EXPECT_EQ(return_code, linkahead::StatusCode::GO_ON); + + return_code = linkahead_transaction_delete_transaction(&multi_transaction); + EXPECT_EQ(return_code, 0); +} + +TEST_F(test_clinkahead, test_query) { + linkahead_connection_connection connection; + linkahead_connection_connection_manager_get_connection(&connection, "local-linkahead-admin"); + + linkahead_transaction_transaction transaction; + linkahead_connection_connection_create_transaction(&connection, &transaction); + + int return_code(linkahead_transaction_transaction_query(&transaction, "FIND ENTITY WITH id=123")); + EXPECT_EQ(return_code, linkahead::StatusCode::GO_ON); + + return_code = linkahead_transaction_delete_transaction(&transaction); + EXPECT_EQ(return_code, 0); +} + +TEST_F(test_clinkahead, test_datatype) { + + linkahead_entity_datatype atomic; + // check that this fails + int return_code(linkahead_entity_create_atomic_datatype(&atomic, "some type")); + EXPECT_EQ(return_code, linkahead::StatusCode::ENUM_MAPPING_ERROR); + + return_code = linkahead_entity_create_atomic_datatype(&atomic, "INTEGER"); + EXPECT_EQ(return_code, 0); + + linkahead_entity_datatype reference; + return_code = linkahead_entity_create_reference_datatype(&reference, "MyType"); + EXPECT_EQ(return_code, 0); + + linkahead_entity_datatype list_of_atomics; + return_code = linkahead_entity_create_atomic_list_datatype(&list_of_atomics, "DATETIME"); + EXPECT_EQ(return_code, 0); + + linkahead_entity_datatype list_of_references; + return_code = linkahead_entity_create_reference_list_datatype(&list_of_references, "MyType"); + EXPECT_EQ(return_code, 0); + + bool is_a(false); + return_code = linkahead_entity_datatype_is_undefined(&atomic, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_FALSE(is_a); + return_code = linkahead_entity_datatype_is_atomic(&atomic, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_TRUE(is_a); + return_code = linkahead_entity_datatype_is_reference(&atomic, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_FALSE(is_a); + return_code = linkahead_entity_datatype_is_list_of_atomic(&atomic, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_FALSE(is_a); + return_code = linkahead_entity_datatype_is_list_of_reference(&atomic, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_FALSE(is_a); + + return_code = linkahead_entity_datatype_is_atomic(&reference, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_FALSE(is_a); + return_code = linkahead_entity_datatype_is_reference(&reference, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_TRUE(is_a); + return_code = linkahead_entity_datatype_is_list_of_atomic(&reference, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_FALSE(is_a); + return_code = linkahead_entity_datatype_is_list_of_reference(&reference, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_FALSE(is_a); + + return_code = linkahead_entity_datatype_is_atomic(&list_of_atomics, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_FALSE(is_a); + return_code = linkahead_entity_datatype_is_reference(&list_of_atomics, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_FALSE(is_a); + return_code = linkahead_entity_datatype_is_list_of_atomic(&list_of_atomics, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_TRUE(is_a); + return_code = linkahead_entity_datatype_is_list_of_reference(&list_of_atomics, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_FALSE(is_a); + + return_code = linkahead_entity_datatype_is_atomic(&list_of_references, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_FALSE(is_a); + return_code = linkahead_entity_datatype_is_reference(&list_of_references, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_FALSE(is_a); + return_code = linkahead_entity_datatype_is_list_of_atomic(&list_of_references, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_FALSE(is_a); + return_code = linkahead_entity_datatype_is_list_of_reference(&list_of_references, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_TRUE(is_a); + + char *name = nullptr; // NOLINT + return_code = linkahead_entity_datatype_get_datatype_name(&atomic, &name); + EXPECT_EQ(return_code, 0); + EXPECT_STREQ(name, "INTEGER"); + + return_code = linkahead_entity_datatype_get_datatype_name(&reference, &name); + EXPECT_EQ(return_code, 0); + EXPECT_STREQ(name, "MyType"); + + return_code = linkahead_entity_datatype_get_datatype_name(&list_of_atomics, &name); + EXPECT_EQ(return_code, 0); + EXPECT_STREQ(name, "DATETIME"); + + return_code = linkahead_entity_datatype_get_datatype_name(&list_of_references, &name); + EXPECT_EQ(return_code, 0); + EXPECT_STREQ(name, "MyType"); + + return_code = linkahead_entity_delete_datatype(&atomic); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_datatype(&reference); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_datatype(&list_of_atomics); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_datatype(&list_of_references); + EXPECT_EQ(return_code, 0); +} + +TEST_F(test_clinkahead, test_value) { + + linkahead_entity_value string_value; + int return_code(linkahead_entity_create_string_value(&string_value, "value")); + EXPECT_EQ(return_code, 0); + + linkahead_entity_value int_value; + return_code = linkahead_entity_create_int_value(&int_value, 27); + EXPECT_EQ(return_code, 0); + + linkahead_entity_value bool_value; + return_code = linkahead_entity_create_bool_value(&bool_value, true); + EXPECT_EQ(return_code, 0); + + linkahead_entity_value double_value; + return_code = linkahead_entity_create_double_value(&double_value, 2.7); + EXPECT_EQ(return_code, 0); + + linkahead_entity_value string_vector_value; + const char *string_values[] = {"a", "b", "c"}; // NOLINT + return_code = linkahead_entity_create_string_vector_value(&string_vector_value, string_values, 3); + EXPECT_EQ(return_code, 0); + + linkahead_entity_value int_vector_value; + const int64_t int_values[] = {1, 2, 3}; // NOLINT + return_code = linkahead_entity_create_int_vector_value(&int_vector_value, int_values, 3); + EXPECT_EQ(return_code, 0); + + linkahead_entity_value double_vector_value; + const double double_values[] = {1.1, 2.2, 3.3}; // NOLINT + return_code = linkahead_entity_create_double_vector_value(&double_vector_value, double_values, 3); + EXPECT_EQ(return_code, 0); + + linkahead_entity_value bool_vector_value; + const bool bool_values[] = {true, false, false}; // NOLINT + return_code = linkahead_entity_create_bool_vector_value(&bool_vector_value, bool_values, 3); + EXPECT_EQ(return_code, 0); + + // One thorough check, afterwards only the ones that should be true + bool is_a(false); + return_code = linkahead_entity_value_is_null(&string_value, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_FALSE(is_a); + return_code = linkahead_entity_value_is_string(&string_value, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_TRUE(is_a); + return_code = linkahead_entity_value_is_double(&string_value, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_FALSE(is_a); + return_code = linkahead_entity_value_is_integer(&string_value, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_FALSE(is_a); + return_code = linkahead_entity_value_is_bool(&string_value, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_FALSE(is_a); + return_code = linkahead_entity_value_is_vector(&string_value, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_FALSE(is_a); + + linkahead_entity_value_is_integer(&int_value, &is_a); + EXPECT_TRUE(is_a); + + linkahead_entity_value_is_bool(&bool_value, &is_a); + EXPECT_TRUE(is_a); + + linkahead_entity_value_is_double(&double_value, &is_a); + EXPECT_TRUE(is_a); + + linkahead_entity_value_is_vector(&string_vector_value, &is_a); + EXPECT_TRUE(is_a); + + linkahead_entity_value_is_vector(&int_vector_value, &is_a); + EXPECT_TRUE(is_a); + + linkahead_entity_value_is_vector(&double_vector_value, &is_a); + EXPECT_TRUE(is_a); + + linkahead_entity_value_is_vector(&bool_vector_value, &is_a); + EXPECT_TRUE(is_a); + + char *out_string = nullptr; // NOLINT + return_code = linkahead_entity_value_get_as_string(&string_value, &out_string); + EXPECT_EQ(return_code, 0); + EXPECT_STREQ(out_string, "value"); + + int64_t out_int(0); + return_code = linkahead_entity_value_get_as_integer(&int_value, &out_int); + EXPECT_EQ(return_code, 0); + EXPECT_EQ(out_int, 27); + + bool out_bool(false); + return_code = linkahead_entity_value_get_as_bool(&bool_value, &out_bool); + EXPECT_EQ(return_code, 0); + EXPECT_TRUE(out_bool); + + double out_double(0); + return_code = linkahead_entity_value_get_as_double(&double_value, &out_double); + EXPECT_EQ(return_code, 0); + EXPECT_EQ(out_double, 2.7); + + int list_length(0); + return_code = linkahead_entity_value_get_as_vector_size(&string_vector_value, &list_length); + EXPECT_EQ(return_code, 0); + EXPECT_EQ(list_length, 3); + return_code = linkahead_entity_value_get_as_vector_size(&int_vector_value, &list_length); + EXPECT_EQ(return_code, 0); + EXPECT_EQ(list_length, 3); + return_code = linkahead_entity_value_get_as_vector_size(&double_vector_value, &list_length); + EXPECT_EQ(return_code, 0); + EXPECT_EQ(list_length, 3); + return_code = linkahead_entity_value_get_as_vector_size(&bool_vector_value, &list_length); + EXPECT_EQ(return_code, 0); + EXPECT_EQ(list_length, 3); + + // Only check for one, rest should be covered by this + scalar values + linkahead_entity_value out_val; + return_code = linkahead_entity_value_get_as_vector_at(&string_vector_value, &out_val, 0); + EXPECT_EQ(return_code, 0); + linkahead_entity_value_get_as_string(&out_val, &out_string); + EXPECT_STREQ(out_string, "a"); + return_code = linkahead_entity_value_get_as_vector_at(&string_vector_value, &out_val, 1); + EXPECT_EQ(return_code, 0); + linkahead_entity_value_get_as_string(&out_val, &out_string); + EXPECT_STREQ(out_string, "b"); + return_code = linkahead_entity_value_get_as_vector_at(&string_vector_value, &out_val, 2); + EXPECT_EQ(return_code, 0); + linkahead_entity_value_get_as_string(&out_val, &out_string); + EXPECT_STREQ(out_string, "c"); + + return_code = linkahead_entity_delete_value(&string_value); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_value(&int_value); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_value(&bool_value); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_value(&double_value); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_value(&string_vector_value); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_value(&int_vector_value); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_value(&double_vector_value); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_value(&bool_vector_value); + EXPECT_EQ(return_code, 0); +} + +TEST_F(test_clinkahead, test_entity) { + linkahead_entity_entity entity; + + int return_code(linkahead_entity_create_entity(&entity)); + EXPECT_EQ(return_code, 0); + + // cannot be created again without deletion + // return_code = linkahead_entity_create_entity(&entity); + // EXPECT_EQ(return_code, linkahead::StatusCode::EXTERN_C_ASSIGNMENT_ERROR); + + // deletion and re-creation is ok + return_code = linkahead_entity_delete_entity(&entity); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_create_entity(&entity); + EXPECT_EQ(return_code, 0); + + // In-depth check for one pair of setter and getter, just compare + // the strings for the rest + return_code = linkahead_entity_entity_set_name(&entity, "length"); + EXPECT_EQ(return_code, 0); + char *out = nullptr; // NOLINT + return_code = linkahead_entity_entity_get_name(&entity, &out); + EXPECT_EQ(return_code, 0); + EXPECT_EQ(strcmp(out, "length"), 0); + + // test call without validation of result + return_code = linkahead_entity_entity_set_role(&entity, "FILE"); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_entity_set_local_path( + &entity, (TEST_DATA_DIR + "/test_linkahead_client.json").c_str()); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_entity_get_local_path(&entity, &out); + EXPECT_EQ(return_code, 0); + EXPECT_EQ(strcmp(out, (TEST_DATA_DIR + "/test_linkahead_client.json").c_str()), 0); + + // invalid role + return_code = linkahead_entity_entity_set_role(&entity, "Role does not exist"); + EXPECT_EQ(return_code, linkahead::StatusCode::ENUM_MAPPING_ERROR); + + linkahead_entity_entity_set_role(&entity, "PROPERTY"); + linkahead_entity_entity_get_role(&entity, &out); + EXPECT_EQ(strcmp(out, "PROPERTY"), 0); + + linkahead_entity_entity_set_description(&entity, "The length of an object"); + linkahead_entity_entity_get_description(&entity, &out); + EXPECT_EQ(strcmp(out, "The length of an object"), 0); + + linkahead_entity_datatype in_type; + linkahead_entity_create_atomic_datatype(&in_type, "DOUBLE"); + linkahead_entity_entity_set_datatype(&entity, &in_type); + + // verify that this doesn't work ... + // return_code = linkahead_entity_entity_get_datatype(&entity, &in_type); + // EXPECT_EQ(return_code, linkahead::StatusCode::EXTERN_C_ASSIGNMENT_ERROR); + linkahead_entity_datatype out_type; + // ... but does with a clean property + return_code = linkahead_entity_entity_get_datatype(&entity, &out_type); + EXPECT_EQ(return_code, 0); + bool is_a(false); + return_code = linkahead_entity_datatype_is_atomic(&out_type, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_TRUE(is_a); + return_code = linkahead_entity_datatype_is_reference(&out_type, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_FALSE(is_a); + return_code = linkahead_entity_datatype_is_list_of_atomic(&out_type, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_FALSE(is_a); + return_code = linkahead_entity_datatype_is_list_of_reference(&out_type, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_FALSE(is_a); + + linkahead_entity_datatype_get_datatype_name(&out_type, &out); + EXPECT_STREQ(out, "DOUBLE"); + + linkahead_entity_value in_value; + return_code = linkahead_entity_create_double_value(&in_value, 5.0); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_entity_set_value(&entity, &in_value); + EXPECT_EQ(return_code, 0); + + linkahead_entity_value out_value; + return_code = linkahead_entity_entity_get_value(&entity, &out_value); + EXPECT_EQ(return_code, 0); + + linkahead_entity_value_is_double(&out_value, &is_a); + EXPECT_TRUE(is_a); + linkahead_entity_value_is_null(&out_value, &is_a); + EXPECT_FALSE(is_a); + linkahead_entity_value_is_string(&out_value, &is_a); + EXPECT_FALSE(is_a); + linkahead_entity_value_is_bool(&out_value, &is_a); + EXPECT_FALSE(is_a); + linkahead_entity_value_is_integer(&out_value, &is_a); + EXPECT_FALSE(is_a); + linkahead_entity_value_is_vector(&out_value, &is_a); + EXPECT_FALSE(is_a); + + double out_double(0); + linkahead_entity_value_get_as_double(&out_value, &out_double); + EXPECT_EQ(out_double, 5.0); + + // clear to re-use + return_code = linkahead_entity_delete_datatype(&in_type); + EXPECT_EQ(return_code, 0); + linkahead_entity_create_reference_list_datatype(&in_type, "Person"); + linkahead_entity_entity_set_datatype(&entity, &in_type); + + // works without clearing since datatype is managed by the owning entity + linkahead_entity_entity_get_datatype(&entity, &out_type); + return_code = linkahead_entity_datatype_is_atomic(&out_type, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_FALSE(is_a); + return_code = linkahead_entity_datatype_is_reference(&out_type, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_FALSE(is_a); + return_code = linkahead_entity_datatype_is_list_of_atomic(&out_type, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_FALSE(is_a); + return_code = linkahead_entity_datatype_is_list_of_reference(&out_type, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_TRUE(is_a); + + linkahead_entity_datatype_get_datatype_name(&out_type, &out); + EXPECT_STREQ(out, "Person"); + + linkahead_entity_entity_set_unit(&entity, "m"); + linkahead_entity_entity_get_unit(&entity, &out); + EXPECT_EQ(strcmp(out, "m"), 0); + + return_code = linkahead_entity_delete_entity(&entity); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_datatype(&in_type); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_value(&in_value); + EXPECT_EQ(return_code, 0); +} + +TEST_F(test_clinkahead, test_parent) { + linkahead_entity_parent parent; + + int return_code(linkahead_entity_create_parent(&parent)); + EXPECT_EQ(return_code, 0); + + linkahead_entity_parent_set_id(&parent, "some_id"); + linkahead_entity_parent_set_name(&parent, "some_name"); + + char *out = nullptr; // NOLINT + linkahead_entity_parent_get_id(&parent, &out); + EXPECT_EQ(strcmp(out, "some_id"), 0); + + linkahead_entity_parent_get_name(&parent, &out); + EXPECT_EQ(strcmp(out, "some_name"), 0); + + return_code = linkahead_entity_delete_parent(&parent); + EXPECT_EQ(return_code, 0); +} + +TEST_F(test_clinkahead, test_property) { + linkahead_entity_property property; + + int return_code(linkahead_entity_create_property(&property)); + EXPECT_EQ(return_code, 0); + + linkahead_entity_property_set_id(&property, "some_id"); + linkahead_entity_property_set_name(&property, "some_name"); + + linkahead_entity_datatype in_type; + linkahead_entity_create_atomic_datatype(&in_type, "TEXT"); + linkahead_entity_property_set_datatype(&property, &in_type); + linkahead_entity_property_set_importance(&property, "FIX"); + linkahead_entity_property_set_unit(&property, "some_unit"); + linkahead_entity_value in_value; + linkahead_entity_create_string_value(&in_value, "some_value"); + linkahead_entity_property_set_value(&property, &in_value); + + char *out = nullptr; // NOLINT + linkahead_entity_property_get_id(&property, &out); + EXPECT_EQ(strcmp(out, "some_id"), 0); + + linkahead_entity_property_get_name(&property, &out); + EXPECT_EQ(strcmp(out, "some_name"), 0); + + linkahead_entity_datatype out_type; + return_code = linkahead_entity_property_get_datatype(&property, &out_type); + EXPECT_EQ(return_code, 0); + bool is_a(false); + + linkahead_entity_datatype_is_atomic(&out_type, &is_a); + EXPECT_TRUE(is_a); + linkahead_entity_datatype_is_reference(&out_type, &is_a); + EXPECT_FALSE(is_a); + linkahead_entity_datatype_is_list_of_atomic(&out_type, &is_a); + EXPECT_FALSE(is_a); + linkahead_entity_datatype_is_list_of_reference(&out_type, &is_a); + EXPECT_FALSE(is_a); + + linkahead_entity_datatype_get_datatype_name(&out_type, &out); + EXPECT_STREQ(out, "TEXT"); + + linkahead_entity_property_get_importance(&property, &out); + EXPECT_EQ(strcmp(out, "FIX"), 0); + + linkahead_entity_property_get_unit(&property, &out); + EXPECT_EQ(strcmp(out, "some_unit"), 0); + + linkahead_entity_value out_value; + return_code = linkahead_entity_property_get_value(&property, &out_value); + EXPECT_EQ(return_code, 0); + linkahead_entity_value_is_string(&out_value, &is_a); + EXPECT_TRUE(is_a); + linkahead_entity_value_get_as_string(&out_value, &out); + EXPECT_STREQ(out, "some_value"); + + return_code = linkahead_entity_delete_property(&property); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_datatype(&in_type); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_value(&in_value); + EXPECT_EQ(return_code, 0); +} + +TEST_F(test_clinkahead, test_string_list_property) { + + linkahead_entity_property property; + int return_code(linkahead_entity_create_property(&property)); + EXPECT_EQ(return_code, 0); + + linkahead_entity_datatype in_type; + return_code = linkahead_entity_create_atomic_list_datatype(&in_type, "TEXT"); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_property_set_datatype(&property, &in_type); + EXPECT_EQ(return_code, 0); + + linkahead_entity_value in_value; + const char *value_list[] = {"val0", "val1", "val2"}; // NOLINT + return_code = linkahead_entity_create_string_vector_value(&in_value, value_list, 3); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_property_set_value(&property, &in_value); + EXPECT_EQ(return_code, 0); + + linkahead_entity_datatype out_type; + return_code = linkahead_entity_property_get_datatype(&property, &out_type); + EXPECT_EQ(return_code, 0); + + bool is_a(false); + linkahead_entity_datatype_is_atomic(&out_type, &is_a); + EXPECT_FALSE(is_a); + linkahead_entity_datatype_is_reference(&out_type, &is_a); + EXPECT_FALSE(is_a); + linkahead_entity_datatype_is_list_of_atomic(&out_type, &is_a); + EXPECT_TRUE(is_a); + linkahead_entity_datatype_is_list_of_reference(&out_type, &is_a); + EXPECT_FALSE(is_a); + char *out = nullptr; // NOLINT + linkahead_entity_datatype_get_datatype_name(&out_type, &out); + EXPECT_STREQ(out, "TEXT"); + + linkahead_entity_value out_value; + linkahead_entity_property_get_value(&property, &out_value); + linkahead_entity_value_is_vector(&out_value, &is_a); + EXPECT_TRUE(is_a); + int length(-1); + linkahead_entity_value_get_as_vector_size(&out_value, &length); + EXPECT_EQ(length, 3); + + linkahead_entity_value list_elt; + for (int i = 0; i < length; i++) { + return_code = linkahead_entity_value_get_as_vector_at(&out_value, &list_elt, i); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_value_get_as_string(&list_elt, &out); + EXPECT_EQ(return_code, 0); + EXPECT_STREQ(value_list[i], out); // NOLINT + } + + return_code = linkahead_entity_delete_property(&property); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_datatype(&in_type); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_value(&in_value); + EXPECT_EQ(return_code, 0); +} + +TEST_F(test_clinkahead, test_int_list_property) { + + linkahead_entity_property property; + int return_code(linkahead_entity_create_property(&property)); + EXPECT_EQ(return_code, 0); + + linkahead_entity_datatype in_type; + linkahead_entity_create_atomic_list_datatype(&in_type, "INTEGER"); + return_code = linkahead_entity_property_set_datatype(&property, &in_type); + EXPECT_EQ(return_code, 0); + + const int64_t value_list[] = {1, 2, 3}; // NOLINT + linkahead_entity_value in_value; + linkahead_entity_create_int_vector_value(&in_value, value_list, 3); + return_code = linkahead_entity_property_set_value(&property, &in_value); + EXPECT_EQ(return_code, 0); + + linkahead_entity_datatype out_type; + return_code = linkahead_entity_property_get_datatype(&property, &out_type); + EXPECT_EQ(return_code, 0); + + bool is_a(false); + linkahead_entity_datatype_is_atomic(&out_type, &is_a); + EXPECT_FALSE(is_a); + linkahead_entity_datatype_is_reference(&out_type, &is_a); + EXPECT_FALSE(is_a); + linkahead_entity_datatype_is_list_of_atomic(&out_type, &is_a); + EXPECT_TRUE(is_a); + linkahead_entity_datatype_is_list_of_reference(&out_type, &is_a); + EXPECT_FALSE(is_a); + char *out = nullptr; // NOLINT + linkahead_entity_datatype_get_datatype_name(&out_type, &out); + EXPECT_STREQ(out, "INTEGER"); + + linkahead_entity_value out_value; + linkahead_entity_property_get_value(&property, &out_value); + linkahead_entity_value_is_vector(&out_value, &is_a); + EXPECT_TRUE(is_a); + int length(-1); + linkahead_entity_value_get_as_vector_size(&out_value, &length); + EXPECT_EQ(length, 3); + + int64_t out_int = -1; + linkahead_entity_value list_elt; + for (int i = 0; i < length; i++) { + return_code = linkahead_entity_value_get_as_vector_at(&out_value, &list_elt, i); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_value_get_as_integer(&list_elt, &out_int); + EXPECT_EQ(return_code, 0); + EXPECT_EQ(value_list[i], out_int); // NOLINT + } + + return_code = linkahead_entity_delete_property(&property); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_datatype(&in_type); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_value(&in_value); + EXPECT_EQ(return_code, 0); +} + +TEST_F(test_clinkahead, test_bool_list_property) { + + linkahead_entity_property property; + int return_code(linkahead_entity_create_property(&property)); + EXPECT_EQ(return_code, 0); + + linkahead_entity_datatype in_type; + linkahead_entity_create_atomic_list_datatype(&in_type, "BOOLEAN"); + return_code = linkahead_entity_property_set_datatype(&property, &in_type); + EXPECT_EQ(return_code, 0); + + const bool value_list[] = {true, true, false}; // NOLINT + linkahead_entity_value in_value; + linkahead_entity_create_bool_vector_value(&in_value, value_list, 3); + return_code = linkahead_entity_property_set_value(&property, &in_value); + EXPECT_EQ(return_code, 0); + + linkahead_entity_datatype out_type; + return_code = linkahead_entity_property_get_datatype(&property, &out_type); + EXPECT_EQ(return_code, 0); + + bool is_a(false); + linkahead_entity_datatype_is_atomic(&out_type, &is_a); + EXPECT_FALSE(is_a); + linkahead_entity_datatype_is_reference(&out_type, &is_a); + EXPECT_FALSE(is_a); + linkahead_entity_datatype_is_list_of_atomic(&out_type, &is_a); + EXPECT_TRUE(is_a); + linkahead_entity_datatype_is_list_of_reference(&out_type, &is_a); + EXPECT_FALSE(is_a); + char *out = nullptr; // NOLINT + linkahead_entity_datatype_get_datatype_name(&out_type, &out); + EXPECT_STREQ(out, "BOOLEAN"); + + linkahead_entity_value out_value; + linkahead_entity_property_get_value(&property, &out_value); + linkahead_entity_value_is_vector(&out_value, &is_a); + EXPECT_TRUE(is_a); + int length(-1); + linkahead_entity_value_get_as_vector_size(&out_value, &length); + EXPECT_EQ(length, 3); + + bool out_bool(false); + linkahead_entity_value list_elt; + for (int i = 0; i < length; i++) { + return_code = linkahead_entity_value_get_as_vector_at(&out_value, &list_elt, i); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_value_get_as_bool(&list_elt, &out_bool); + EXPECT_EQ(return_code, 0); + EXPECT_EQ(value_list[i], out_bool); // NOLINT + } + + return_code = linkahead_entity_delete_property(&property); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_datatype(&in_type); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_value(&in_value); + EXPECT_EQ(return_code, 0); +} + +TEST_F(test_clinkahead, test_entity_with_parent_and_property) { + linkahead_entity_parent input_parent; + int return_code(linkahead_entity_create_parent(&input_parent)); + EXPECT_EQ(return_code, 0); + + linkahead_entity_parent_set_id(&input_parent, "parent_id"); + linkahead_entity_parent_set_name(&input_parent, "parent_name"); + + linkahead_entity_property input_property; + return_code = linkahead_entity_create_property(&input_property); + EXPECT_EQ(return_code, 0); + + linkahead_entity_property_set_id(&input_property, "property_id"); + linkahead_entity_property_set_name(&input_property, "property_name"); + + linkahead_entity_datatype in_type; + linkahead_entity_create_atomic_datatype(&in_type, "TEXT"); + linkahead_entity_value in_value; + linkahead_entity_create_string_value(&in_value, "property_value"); + linkahead_entity_property_set_datatype(&input_property, &in_type); + linkahead_entity_property_set_value(&input_property, &in_value); + + linkahead_entity_entity entity; + return_code = linkahead_entity_create_entity(&entity); + EXPECT_EQ(return_code, 0); + + return_code = linkahead_entity_entity_append_parent(&entity, &input_parent); + EXPECT_EQ(return_code, 0); + + return_code = linkahead_entity_entity_append_property(&entity, &input_property); + EXPECT_EQ(return_code, 0); + + int count[] = {0}; // NOLINT + return_code = linkahead_entity_entity_get_parents_size(&entity, count); + EXPECT_EQ(return_code, 0); + EXPECT_EQ(*count, 1); + + return_code = linkahead_entity_entity_get_properties_size(&entity, count); + EXPECT_EQ(return_code, 0); + EXPECT_EQ(*count, 1); + + char *in = nullptr; // NOLINT + char *out = nullptr; // NOLINT + + // cannot assign an already assigned property + // return_code = linkahead_entity_entity_get_property(&entity, &input_property, 0); + // EXPECT_EQ(return_code, linkahead::StatusCode::EXTERN_C_ASSIGNMENT_ERROR); + linkahead_entity_property output_property; + return_code = linkahead_entity_entity_get_property(&entity, &output_property, 0); + EXPECT_EQ(return_code, 0); + + linkahead_entity_property_get_id(&input_property, &in); + linkahead_entity_property_get_id(&output_property, &out); + EXPECT_EQ(strcmp(in, out), 0); + + linkahead_entity_property_get_name(&input_property, &in); + linkahead_entity_property_get_name(&output_property, &out); + EXPECT_EQ(strcmp(in, out), 0); + + linkahead_entity_datatype out_type; + linkahead_entity_property_get_datatype(&output_property, &out_type); + + bool in_is(false); + bool out_is(false); + linkahead_entity_datatype_is_atomic(&in_type, &in_is); + linkahead_entity_datatype_is_atomic(&out_type, &out_is); + EXPECT_EQ(in_is, out_is); + linkahead_entity_datatype_is_reference(&in_type, &in_is); + linkahead_entity_datatype_is_reference(&out_type, &out_is); + EXPECT_EQ(in_is, out_is); + linkahead_entity_datatype_is_list_of_atomic(&in_type, &in_is); + linkahead_entity_datatype_is_list_of_atomic(&out_type, &out_is); + EXPECT_EQ(in_is, out_is); + linkahead_entity_datatype_is_list_of_reference(&in_type, &in_is); + linkahead_entity_datatype_is_list_of_reference(&out_type, &out_is); + EXPECT_EQ(in_is, out_is); + + linkahead_entity_datatype_get_datatype_name(&in_type, &in); + linkahead_entity_datatype_get_datatype_name(&out_type, &out); + EXPECT_STREQ(in, out); + + linkahead_entity_value out_value; + linkahead_entity_property_get_value(&output_property, &out_value); + linkahead_entity_value_is_string(&in_value, &in_is); + EXPECT_TRUE(in_is); + linkahead_entity_value_is_string(&out_value, &out_is); + EXPECT_TRUE(out_is); + linkahead_entity_value_get_as_string(&in_value, &in); + linkahead_entity_value_get_as_string(&out_value, &out); + EXPECT_STREQ(in, out); + + linkahead_entity_parent output_parent; + return_code = linkahead_entity_entity_get_parent(&entity, &output_parent, 0); + EXPECT_EQ(return_code, 0); + + linkahead_entity_parent_get_id(&input_parent, &in); + linkahead_entity_parent_get_id(&output_parent, &out); + EXPECT_EQ(strcmp(in, out), 0); + + linkahead_entity_parent_get_name(&input_parent, &in); + linkahead_entity_parent_get_name(&output_parent, &out); + EXPECT_EQ(strcmp(in, out), 0); + + // Delete everything + return_code = linkahead_entity_delete_parent(&input_parent); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_property(&input_property); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_entity(&entity); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_datatype(&in_type); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_value(&in_value); + EXPECT_EQ(return_code, 0); + + // This tests the `_deletable` flag. The wrapped cpp objects of + // `output_parent` and `output_property` are owned by the entity, so + // they have been deleted together with the entity. With a wrong + // `_deletable` flag, the following would cause segfaults. + // + return_code = linkahead_entity_delete_parent(&output_parent); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_property(&output_property); + EXPECT_EQ(return_code, 0); +} + +TEST_F(test_clinkahead, test_remove_property) { + linkahead_entity_entity entity; + int return_code(linkahead_entity_create_entity(&entity)); + EXPECT_EQ(return_code, 0); + + // Create two properties with names + linkahead_entity_property in_prop_1; + return_code = linkahead_entity_create_property(&in_prop_1); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_property_set_name(&in_prop_1, "Property 1"); + EXPECT_EQ(return_code, 0); + + linkahead_entity_property in_prop_2; + return_code = linkahead_entity_create_property(&in_prop_2); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_property_set_name(&in_prop_2, "Property 2"); + EXPECT_EQ(return_code, 0); + + // Append them + return_code = linkahead_entity_entity_append_property(&entity, &in_prop_1); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_entity_append_property(&entity, &in_prop_2); + EXPECT_EQ(return_code, 0); + + // Delete one and see that the number of properties decreases by one + int count[] = {0}; // NOLINT + return_code = linkahead_entity_entity_get_properties_size(&entity, count); + EXPECT_EQ(return_code, 0); + EXPECT_EQ(*count, 2); + + return_code = linkahead_entity_entity_remove_property(&entity, 0); + EXPECT_EQ(return_code, 0); + + return_code = linkahead_entity_entity_get_properties_size(&entity, count); + EXPECT_EQ(return_code, 0); + EXPECT_EQ(*count, 1); + + linkahead_entity_property out_prop; + return_code = linkahead_entity_entity_get_property(&entity, &out_prop, 0); + EXPECT_EQ(return_code, 0); + + char *in = nullptr; // NOLINT + char *out = nullptr; // NOLINT + + // Deleted the first property, so the second one should remain. + return_code = linkahead_entity_property_get_name(&in_prop_2, &in); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_property_get_name(&out_prop, &out); + EXPECT_EQ(return_code, 0); + + EXPECT_EQ(strcmp(in, out), 0); + + // Delete everything we have created + return_code = linkahead_entity_delete_property(&in_prop_2); + EXPECT_EQ(return_code, 0); + + return_code = linkahead_entity_delete_property(&in_prop_1); + EXPECT_EQ(return_code, 0); + + return_code = linkahead_entity_delete_entity(&entity); + EXPECT_EQ(return_code, 0); +} + +TEST_F(test_clinkahead, test_insert_update_delete) { + // Only test adding to a transaction. Excution and results are + // tested in integration tests. + linkahead_connection_connection connection; + linkahead_connection_connection_manager_get_default_connection(&connection); + + linkahead_transaction_transaction insert_transaction; + linkahead_connection_connection_create_transaction(&connection, &insert_transaction); + + linkahead_entity_entity entity; + linkahead_entity_create_entity(&entity); + linkahead_entity_entity_set_name(&entity, "some_name"); + linkahead_entity_entity_set_local_path(&entity, "some_name"); + linkahead_entity_entity_set_file_path(&entity, "some_name"); + + auto return_code = linkahead_transaction_transaction_insert_entity(&insert_transaction, &entity); + EXPECT_EQ(return_code, linkahead::StatusCode::GO_ON); + + linkahead_transaction_transaction update_transaction; + linkahead_connection_connection_create_transaction(&connection, &update_transaction); + + return_code = linkahead_transaction_transaction_update_entity(&update_transaction, &entity); + // No ID, so this should be an error + EXPECT_EQ(return_code, linkahead::StatusCode::ORIGINAL_ENTITY_MISSING_ID); + + linkahead_transaction_transaction delete_transaction; + linkahead_connection_connection_create_transaction(&connection, &delete_transaction); + + return_code = linkahead_transaction_transaction_delete_by_id(&delete_transaction, "some_id"); + // Could add further deletions + EXPECT_EQ(return_code, linkahead::StatusCode::GO_ON); + + linkahead_entity_delete_entity(&entity); + linkahead_transaction_delete_transaction(&insert_transaction); + linkahead_transaction_delete_transaction(&update_transaction); + linkahead_transaction_delete_transaction(&delete_transaction); +} diff --git a/test/test_configuration.cpp b/test/test_configuration.cpp index 6d5f2e9449e5be21452fdcca6a04f4e02f531d13..b2cc95f3e410ec72ced509a7d608dedc929c1592 100644 --- a/test/test_configuration.cpp +++ b/test/test_configuration.cpp @@ -1,9 +1,9 @@ /* * - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -19,18 +19,20 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ -#include "caosdb/configuration.h" // for ConfigurationError, Configuration... -#include "caosdb/exceptions.h" // for ConfigurationError -#include "caosdb/log_level.h" // for CAOSDB_DEFAULT_LOG_LEVEL, CAOSDB_... -#include "caosdb/logging.h" // for ConsoleSinkConfiguration, Logging... -#include "caosdb_test_utility.h" // for EXPECT_THROW_MESSAGE, TEST_DATA_DIR -#include <gtest/gtest-message.h> // for Message -#include <gtest/gtest-test-part.h> // for TestPartResult, SuiteApiResolver -#include <gtest/gtest_pred_impl.h> // for TestInfo, TEST_F, Test -#include <memory> // for make_shared -#include <string> // for operator+, allocator, string +#include <gtest/gtest.h> // for Test, TestPartResult, TestPartR... +#include <gtest/gtest-message.h> // for Message +#include <gtest/gtest-test-part.h> // for TestPartResult +#include <gtest/gtest_pred_impl.h> // for TestInfo, TEST_F, Test +#include <filesystem> // for path +#include <memory> // for make_shared, shared_ptr +#include <string> // for basic_string, operator+ +#include "linkahead/configuration.h" // for ConfigurationError, Configurati... +#include "linkahead/exceptions.h" // for ConfigurationError +#include "linkahead/log_level.h" // for LINKAHEAD_DEFAULT_LOG_LEVEL +#include "linkahead/logging.h" // for ConsoleSinkConfiguration, Loggi... +#include "linkahead_test_utility.h" // for EXPECT_THROW_MESSAGE, TEST_DATA... -namespace caosdb::configuration { +namespace linkahead::configuration { class test_configuration : public ::testing::Test { protected: @@ -39,9 +41,9 @@ protected: }; TEST_F(test_configuration, load_json) { - ConfigurationManager::LoadSingleJSONConfiguration(TEST_DATA_DIR + "/test_caosdb_client.json"); + ConfigurationManager::LoadSingleJSONConfiguration(TEST_DATA_DIR + "/test_linkahead_client.json"); EXPECT_THROW_MESSAGE(ConfigurationManager::LoadSingleJSONConfiguration("anything"), - ConfigurationError, "This CaosDB client has already been configured."); + ConfigurationError, "This LinkAhead client has already been configured."); ConfigurationManager::Clear(); EXPECT_THROW_MESSAGE(ConfigurationManager::LoadSingleJSONConfiguration("anything"), @@ -51,34 +53,34 @@ TEST_F(test_configuration, load_json) { TEST_F(test_configuration, get_default_connection_configuration_error) { EXPECT_THROW_MESSAGE(ConfigurationManager::GetDefaultConnectionName(), ConfigurationError, - "This CaosDB client has not been configured."); + "This LinkAhead client has not been configured."); ConfigurationManager::LoadSingleJSONConfiguration( - TEST_DATA_DIR + "/test_broken_caosdb_client_no_connections1.json"); + TEST_DATA_DIR + "/test_broken_linkahead_client_no_connections1.json"); EXPECT_THROW_MESSAGE(ConfigurationManager::GetDefaultConnectionName(), ConfigurationError, - "This CaosDB client hasn't any configured connections."); + "This LinkAhead client hasn't any configured connections."); ConfigurationManager::Clear(); ConfigurationManager::LoadSingleJSONConfiguration( - TEST_DATA_DIR + "/test_broken_caosdb_client_no_connections2.json"); + TEST_DATA_DIR + "/test_broken_linkahead_client_no_connections2.json"); EXPECT_THROW_MESSAGE(ConfigurationManager::GetDefaultConnectionName(), ConfigurationError, - "This CaosDB client hasn't any configured connections."); + "This LinkAhead client hasn't any configured connections."); ConfigurationManager::Clear(); ConfigurationManager::LoadSingleJSONConfiguration( - TEST_DATA_DIR + "/test_broken_caosdb_client_no_connections3.json"); + TEST_DATA_DIR + "/test_broken_linkahead_client_no_connections3.json"); EXPECT_THROW_MESSAGE(ConfigurationManager::GetDefaultConnectionName(), ConfigurationError, - "This CaosDB client hasn't any configured connections."); + "This LinkAhead client hasn't any configured connections."); ConfigurationManager::Clear(); } TEST_F(test_configuration, initialize_logging) { - auto logging_configuration = caosdb::logging::LoggingConfiguration(CAOSDB_LOG_LEVEL_ALL); - auto console_sink = std::make_shared<caosdb::logging::ConsoleSinkConfiguration>( - "console", CAOSDB_DEFAULT_LOG_LEVEL); + auto logging_configuration = linkahead::logging::LoggingConfiguration(LINKAHEAD_LOG_LEVEL_ALL); + auto console_sink = std::make_shared<linkahead::logging::ConsoleSinkConfiguration>( + "console", LINKAHEAD_DEFAULT_LOG_LEVEL); logging_configuration.AddSink(console_sink); initialize_logging(logging_configuration); } -} // namespace caosdb::configuration +} // namespace linkahead::configuration diff --git a/test/test_connection.cpp b/test/test_connection.cpp index 9b8783a0ae88f6669de4e5ec4e5a43dea26447c5..2b92e94a4d098137f7879469a83dac5a3131406e 100644 --- a/test/test_connection.cpp +++ b/test/test_connection.cpp @@ -1,9 +1,9 @@ /* * - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -20,33 +20,36 @@ * */ #ifdef BUILD_ACM -#include "caosdb/acm/user.h" // for User +#include "linkahead/acm/user.h" // for User #endif -#include "caosdb/certificate_provider.h" // for PemCertificateProvider -#include "caosdb/configuration.h" // for InsecureConnectionConfigura... -#include "caosdb/connection.h" // for ConnectionManager -#include "caosdb/exceptions.h" // for ConnectionConfigurationError -#include "caosdb_test_utility.h" // for EXPECT_THROW_MESSAGE, TEST_... -#include <gtest/gtest-message.h> // for Message -#include <gtest/gtest-test-part.h> // for SuiteApiResolver, TestPartR... -#include <gtest/gtest_pred_impl.h> // for AssertionResult, TestInfo -#include <memory> // for allocator, operator!=, shar... -#include <string> // for operator+, string +#include <gtest/gtest.h> // for Test, TestPartResult, Test +#include <gtest/gtest-message.h> // for Message +#include <gtest/gtest-test-part.h> // for TestPartResult +#include <gtest/gtest_pred_impl.h> // for AssertionResult, TestInfo +#include <filesystem> // for path +#include <memory> // for operator!=, shared_ptr +#include <string> // for basic_string, operator+ +#include "linkahead/certificate_provider.h" // for PemCertificateProvider +#include "linkahead/configuration.h" // for InsecureConnectionConfig... +#include "linkahead/connection.h" // for ConnectionManager +#include "linkahead/exceptions.h" // for ConnectionConfigurationE... +#include "linkahead_test_utility.h" // for EXPECT_THROW_MESSAGE -namespace caosdb::connection { +namespace linkahead::connection { #ifdef BUILD_ACM -using caosdb::acm::User; +using linkahead::acm::User; #endif -using caosdb::configuration::ConfigurationManager; -using caosdb::configuration::InsecureConnectionConfiguration; -using caosdb::configuration::PemCertificateProvider; -using caosdb::configuration::TlsConnectionConfiguration; +using linkahead::configuration::ConfigurationManager; +using linkahead::configuration::InsecureConnectionConfiguration; +using linkahead::configuration::PemCertificateProvider; +using linkahead::configuration::TlsConnectionConfiguration; class test_connection : public ::testing::Test { protected: void SetUp() override { ConfigurationManager::Clear(); - ConfigurationManager::LoadSingleJSONConfiguration(TEST_DATA_DIR + "/test_caosdb_client.json"); + ConfigurationManager::LoadSingleJSONConfiguration(TEST_DATA_DIR + + "/test_linkahead_client.json"); }; void TearDown() override { ConfigurationManager::Clear(); }; }; @@ -72,32 +75,32 @@ TEST_F(test_connection, configure_ssl_localhost_8080) { TEST_F(test_connection, connection_manager_unknown_connection) { EXPECT_THROW_MESSAGE( - ConnectionManager::GetConnection("test"), caosdb::exceptions::ConnectionConfigurationError, + ConnectionManager::GetConnection("test"), linkahead::exceptions::ConnectionConfigurationError, "Error with the connection named 'test': The connection 'test' has not been defined."); } TEST_F(test_connection, connection_missing_certificate) { EXPECT_THROW_MESSAGE(ConnectionManager::GetConnection("missing"), - caosdb::exceptions::ConnectionConfigurationError, + linkahead::exceptions::ConnectionConfigurationError, std::string("Error with the connection named 'missing': ") + "File does not exist (server_certificate_path): /missing"); } TEST_F(test_connection, connection_manager_get_default_connection) { auto connection = ConnectionManager::GetDefaultConnection(); - EXPECT_EQ(connection, ConnectionManager::GetConnection("local-caosdb")); + EXPECT_EQ(connection, ConnectionManager::GetConnection("local-linkahead")); } TEST_F(test_connection, connection_manager_get_connection) { - EXPECT_TRUE(ConnectionManager::GetConnection("local-caosdb-admin")); + EXPECT_TRUE(ConnectionManager::GetConnection("local-linkahead-admin")); } #ifdef BUILD_ACM TEST_F(test_connection, test_create_single_user) { auto connection = ConnectionManager::GetDefaultConnection(); User user; - EXPECT_THROW_MESSAGE(connection->CreateSingleUser(user), caosdb::exceptions::ConnectionError, + EXPECT_THROW_MESSAGE(connection->CreateSingleUser(user), linkahead::exceptions::ConnectionError, "The attempt to execute this transaction was not successful because the " "connection to the server could not be established."); } @@ -105,7 +108,7 @@ TEST_F(test_connection, test_create_single_user) { TEST_F(test_connection, test_delete_single_user) { auto connection = ConnectionManager::GetDefaultConnection(); EXPECT_THROW_MESSAGE(connection->DeleteSingleUser("realm", "user"), - caosdb::exceptions::ConnectionError, + linkahead::exceptions::ConnectionError, "The attempt to execute this transaction was not successful because the " "connection to the server could not be established."); } @@ -113,10 +116,10 @@ TEST_F(test_connection, test_delete_single_user) { TEST_F(test_connection, test_retrieve_single_user) { auto connection = ConnectionManager::GetDefaultConnection(); EXPECT_THROW_MESSAGE(auto results = connection->RetrieveSingleUser("realm", "user"), - caosdb::exceptions::ConnectionError, + linkahead::exceptions::ConnectionError, "The attempt to execute this transaction was not successful because the " "connection to the server could not be established."); } #endif -} // namespace caosdb::connection +} // namespace linkahead::connection diff --git a/test/test_data/test_broken_caosdb_client_certificate_file_non_existent.json b/test/test_data/test_broken_linkahead_client_certificate_file_non_existent.json similarity index 85% rename from test/test_data/test_broken_caosdb_client_certificate_file_non_existent.json rename to test/test_data/test_broken_linkahead_client_certificate_file_non_existent.json index 832b0a62b674af5500815ca1726ccddf9802d757..4415a62d15e3899cc20a219a51c298b62965661e 100644 --- a/test/test_data/test_broken_caosdb_client_certificate_file_non_existent.json +++ b/test/test_data/test_broken_linkahead_client_certificate_file_non_existent.json @@ -1,7 +1,7 @@ { "connections": { - "default": "local-caosdb", - "local-caosdb-admin": { + "default": "local-linkahead", + "local-linkahead-admin": { "host": "localhost", "port": 8443, "server_certificate_path": "some/path/cacert.pem", @@ -11,7 +11,7 @@ "password": "caosdb" } }, - "local-caosdb": { + "local-linkahead": { "host": "localhost", "port": 8443, "server_certificate_path": "some/path/cacert.pem", diff --git a/test/test_data/test_broken_caosdb_client_no_connections1.json b/test/test_data/test_broken_linkahead_client_no_connections1.json similarity index 100% rename from test/test_data/test_broken_caosdb_client_no_connections1.json rename to test/test_data/test_broken_linkahead_client_no_connections1.json diff --git a/test/test_data/test_broken_caosdb_client_no_connections2.json b/test/test_data/test_broken_linkahead_client_no_connections2.json similarity index 100% rename from test/test_data/test_broken_caosdb_client_no_connections2.json rename to test/test_data/test_broken_linkahead_client_no_connections2.json diff --git a/test/test_data/test_broken_caosdb_client_no_connections3.json b/test/test_data/test_broken_linkahead_client_no_connections3.json similarity index 100% rename from test/test_data/test_broken_caosdb_client_no_connections3.json rename to test/test_data/test_broken_linkahead_client_no_connections3.json diff --git a/test/test_data/test_caosdb_client.json b/test/test_data/test_linkahead_client.json similarity index 90% rename from test/test_data/test_caosdb_client.json rename to test/test_data/test_linkahead_client.json index 276c542f75353090b28918ab0ef9b33f9f0815e1..11cd2d4ba8c77a8241accb001a9317d1834f1ce6 100644 --- a/test/test_data/test_caosdb_client.json +++ b/test/test_data/test_linkahead_client.json @@ -1,7 +1,7 @@ { "connections": { - "default": "local-caosdb", - "local-caosdb-admin": { + "default": "local-linkahead", + "local-linkahead-admin": { "host": "localhost", "port": 8443, "authentication": { @@ -10,7 +10,7 @@ "password": "caosdb" } }, - "local-caosdb": { + "local-linkahead": { "host": "localhost", "port": 8443, "authentication": { diff --git a/test/test_data_type.cpp b/test/test_data_type.cpp index 6b7b8b6ea3d36135164d73c90e8f45693a49b1cc..272f373e07277fd2808c65727c5e4b20aa96b98f 100644 --- a/test/test_data_type.cpp +++ b/test/test_data_type.cpp @@ -1,9 +1,9 @@ /* * - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -19,20 +19,20 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ - -#include "caosdb/data_type.h" // for DataType, AtomicDataType -#include "caosdb/entity.h" // for Entity -#include "caosdb/entity/v1/main.pb.h" // for DataType, Ato... -#include "caosdb/logging.h" // for CAOSDB_LOG_DEBUG -#include "caosdb/protobuf_helper.h" // for CAOSDB_DEBUG_... -#include <gtest/gtest-message.h> // for Message -#include <gtest/gtest-test-part.h> // for TestPartResult, SuiteApi... -#include <gtest/gtest_pred_impl.h> // for AssertionResult, Test -#include <map> // for map, operator!= -#include <string> // for allocator -#include <utility> // for pair - -namespace caosdb::entity { +#include <gtest/gtest.h> // for TEST, EXPECT_EQ, EXPECT_FALSE, ... +#include <gtest/gtest-message.h> // for Message +#include <gtest/gtest-test-part.h> // for TestPartResult +#include <gtest/gtest_pred_impl.h> // for AssertionResult, Test, EXPECT_EQ +#include <map> // for _Rb_tree_const_iterator, map +#include <string> // for allocator, basic_string, char... +#include <utility> // for pair, move +#include "caosdb/entity/v1/main.pb.h" // for AtomicDataType, DataType, Entity +#include "linkahead/data_type.h" // for DataType, ListDataType, Refer... +#include "linkahead/entity.h" // for Entity, Role +#include "linkahead/logging.h" // for LINKAHEAD_LOG_DEBUG +#include "linkahead/protobuf_helper.h" // for reset_arena, LINKAHEAD_DEBUG_... + +namespace linkahead::entity { using ProtoEntity = caosdb::entity::v1::Entity; using ProtoParent = caosdb::entity::v1::Parent; using ProtoDataType = caosdb::entity::v1::DataType; @@ -59,7 +59,7 @@ TEST(test_data_type, test_atomic) { EXPECT_TRUE(data_type.IsAtomic()); EXPECT_EQ(data_type.GetAsAtomic(), map_el.first); } - caosdb::utility::reset_arena(); + linkahead::utility::reset_arena(); } TEST(test_data_type, test_reference) { @@ -107,8 +107,8 @@ TEST(test_data_type, test_list_of_reference) { EXPECT_TRUE(list_data_type.IsListOfReference()); EXPECT_FALSE(list_data_type.IsListOfAtomic()); const auto *wrapped = list_data_type.GetReferenceDataType().GetWrapped(); - CAOSDB_DEBUG_MESSAGE_STRING(*wrapped, out) - CAOSDB_LOG_DEBUG("caosdb::entity") << "wrapped " + out; + LINKAHEAD_DEBUG_MESSAGE_STRING(*wrapped, out) + LINKAHEAD_LOG_DEBUG("linkahead::entity") << "wrapped " + out; EXPECT_EQ(list_data_type.GetReferenceDataType().GetName(), "person"); } @@ -174,4 +174,4 @@ TEST(test_data_type, data_type_move_assignment) { EXPECT_EQ(move_data_type.ToString(), dt_string); } -} // namespace caosdb::entity +} // namespace linkahead::entity diff --git a/test/test_entity.cpp b/test/test_entity.cpp index a42e91781922c5e8b9530663b5bdbc53d4532fe3..6c5c4a7b8315404f73d04d3e76102f8d6733ed37 100644 --- a/test/test_entity.cpp +++ b/test/test_entity.cpp @@ -1,10 +1,10 @@ /* * - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> * Copyright (C) 2021 Florian Spreckelsen <f.spreckelsen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -20,35 +20,37 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ -#include "caosdb/data_type.h" // for DataType, AtomicDat... -#include "caosdb/entity.h" // for Entity, Property -#include "caosdb/entity/v1/main.grpc.pb.h" // for EntityTransactionSe... -#include "caosdb/entity/v1/main.pb.h" // for IdResponse, Message -#include "caosdb/message_code.h" // for MessageCode, ENTITY... -#include "caosdb/protobuf_helper.h" // for get_arena -#include "caosdb/status_code.h" // for StatusCode, FILE_DO... -#include "caosdb/transaction.h" // for Transaction -#include "caosdb/value.h" // for Value -#include "caosdb_test_utility.h" // for TEST_DATA_DIR #include <google/protobuf/arena.h> // for Arena +#include <gtest/gtest.h> // for Test, TestPartResult, Test #include <gtest/gtest-message.h> // for Message -#include <gtest/gtest-test-part.h> // for TestPartResult, Sui... -#include <gtest/gtest_pred_impl.h> // for Test, EXPECT_EQ -#include <iostream> // for operator<<, basic_o... -#include <memory> // for allocator, shared_ptr +#include <gtest/gtest-test-part.h> // for TestPartResult +#include <gtest/gtest_pred_impl.h> // for Test, EXPECT_EQ, Assertio... +#include <filesystem> // for path +#include <iostream> // for basic_ostream, operator<< +#include <memory> // for shared_ptr #include <stdexcept> // for out_of_range -#include <string> // for operator+, to_string +#include <string> // for basic_string, operator+ #include <utility> // for move +#include "caosdb/entity/v1/main.grpc.pb.h" // for EntityTransactionService +#include "caosdb/entity/v1/main.pb.h" // for EntityResponse, Entity +#include "linkahead/data_type.h" // for AtomicDataType, DataType +#include "linkahead/entity.h" // for Entity, Property, Parent +#include "linkahead/message_code.h" // for MessageCode +#include "linkahead/protobuf_helper.h" // for get_arena +#include "linkahead/status_code.h" // for StatusCode +#include "linkahead/transaction.h" // for Transaction, EntityTransa... +#include "linkahead/value.h" // for Value, Arena +#include "linkahead_test_utility.h" // for TEST_DATA_DIR // IWYU pragma: no_include "net/proto2/public/repeated_field.h" -namespace caosdb::entity { +namespace linkahead::entity { using caosdb::entity::v1::IdResponse; using ProtoEntity = caosdb::entity::v1::Entity; using ProtoParent = caosdb::entity::v1::Parent; using ProtoProperty = caosdb::entity::v1::Property; using ProtoAtomicDataType = caosdb::entity::v1::AtomicDataType; using caosdb::entity::v1::EntityResponse; -using caosdb::utility::get_arena; +using linkahead::utility::get_arena; using ProtoEntityRole = caosdb::entity::v1::EntityRole; TEST(test_entity, test_parent_setters) { @@ -497,7 +499,7 @@ TEST(test_entity, test_copy_to) { } TEST(test_entity, test_insert_entity) { - auto transaction = caosdb::transaction::Transaction( + auto transaction = linkahead::transaction::Transaction( std::shared_ptr<transaction::EntityTransactionService::Stub>(nullptr), std::shared_ptr<transaction::FileTransmissionService::Stub>(nullptr)); @@ -515,7 +517,7 @@ TEST(test_entity, test_insert_entity) { } TEST(test_entity, test_insert_with_role) { - auto transaction = caosdb::transaction::Transaction( + auto transaction = linkahead::transaction::Transaction( std::shared_ptr<transaction::EntityTransactionService::Stub>(nullptr), std::shared_ptr<transaction::FileTransmissionService::Stub>(nullptr)); @@ -538,7 +540,7 @@ TEST(test_entity, test_insert_with_role) { } TEST(test_entity, test_insert_with_parent) { - auto transaction = caosdb::transaction::Transaction( + auto transaction = linkahead::transaction::Transaction( std::shared_ptr<transaction::EntityTransactionService::Stub>(nullptr), std::shared_ptr<transaction::FileTransmissionService::Stub>(nullptr)); @@ -563,7 +565,7 @@ TEST(test_entity, test_insert_with_parent) { } TEST(test_entity, test_insert_with_property) { - auto transaction = caosdb::transaction::Transaction( + auto transaction = linkahead::transaction::Transaction( std::shared_ptr<transaction::EntityTransactionService::Stub>(nullptr), std::shared_ptr<transaction::FileTransmissionService::Stub>(nullptr)); @@ -736,11 +738,13 @@ TEST(test_entity, test_remove_property) { entity.AppendProperty(property10); ASSERT_EQ(entity.GetProperties().size(), 9); - std::cout << "[" << std::endl; + std::cout << "[" + << "\n"; for (int i = 0; i < 9; i++) { std::cout << " " << entity.GetProperties().at(i).GetName() << ",\n"; } - std::cout << "]" << std::endl; + std::cout << "]" + << "\n"; for (int i = 0; i < 3; i++) { auto name = "PROPERTY-" + std::to_string(i); @@ -936,4 +940,4 @@ TEST(test_entity, test_message_to_string) { "{\n \"code\": 2,\n \"description\": \"error_desc\"\n}\n"); } -} // namespace caosdb::entity +} // namespace linkahead::entity diff --git a/test/test_file_transmission.cpp b/test/test_file_transmission.cpp index c5847a0842ae8a3bb46a8126e42b31bb5b1d6451..12917317e5f47b2af0746b47ec94d7e208ce4a15 100644 --- a/test/test_file_transmission.cpp +++ b/test/test_file_transmission.cpp @@ -1,8 +1,8 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -17,18 +17,14 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ -#include "caosdb/file_transmission/file_writer.h" -#include "caosdb/file_transmission/file_reader.h" -#include <chrono> // for filesystem -#include <filesystem> // for path -#include <gtest/gtest-message.h> // for Message -#include <gtest/gtest-test-part.h> // for TestPartResult, SuiteApiResolver -#include <gtest/gtest_pred_impl.h> // for Test, EXPECT_EQ, AssertionResult -#include <string> // for string - +#include <gtest/gtest.h> +#include <filesystem> // for path, exists +#include <string> // for basic_string +#include "linkahead/file_transmission/file_reader.h" // for FileReader +#include "linkahead/file_transmission/file_writer.h" // for FileWriter namespace fs = std::filesystem; -namespace caosdb::transaction { +namespace linkahead::transaction { class test_file_transmission : public ::testing::Test { protected: @@ -42,19 +38,23 @@ protected: TEST_F(test_file_transmission, test_file_writer_reader) { ASSERT_FALSE(fs::exists(test_file_name)); - FileWriter writer(test_file_name); - std::string buffer_out(1024, 'c'); - for (int i = 0; i < 8; i++) { - writer.write(buffer_out); - EXPECT_EQ(fs::file_size(test_file_name), 1024 * (i + 1)); + { + FileWriter writer(test_file_name); + std::string buffer_out(1024, 'c'); + for (int i = 0; i < 8; i++) { + writer.write(buffer_out); + } } - - FileReader reader(test_file_name); - std::string buffer_in(1024, '\0'); - for (int i = 0; i < 8; i++) { - reader.read(buffer_in); - EXPECT_EQ(buffer_in, std::string(1024, 'c')); + EXPECT_EQ(fs::file_size(test_file_name), 1024 * 8); + + { + FileReader reader(test_file_name); + std::string buffer_in(1024, '\0'); + for (int i = 0; i < 8; i++) { + reader.read(buffer_in); + EXPECT_EQ(buffer_in, std::string(1024, 'c')); + } } } -} // namespace caosdb::transaction +} // namespace linkahead::transaction diff --git a/test/test_info.cpp b/test/test_info.cpp index 4331219ab02ae5c60e165bee7992c6466d4889f2..fc6fd3a694d9e867d08fd335704323a15e27be87 100644 --- a/test/test_info.cpp +++ b/test/test_info.cpp @@ -1,9 +1,9 @@ /* * - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -20,14 +20,12 @@ * */ -#include "caosdb/info.h" // for VersionInfo +#include <gtest/gtest.h> #include "caosdb/info/v1/main.pb.h" // for VersionInfo -#include <gtest/gtest-message.h> // for Message -#include <gtest/gtest-test-part.h> // for TestPartResult, SuiteApiRe... -#include "gtest/gtest_pred_impl.h" // for Test, EXPECT_EQ, TEST -#include <memory> // for allocator +#include "gtest/gtest_pred_impl.h" // for Test, EXPECT_EQ, TestInfo, TEST +#include "linkahead/info.h" // for VersionInfo -namespace caosdb::info { +namespace linkahead::info { using ProtoVersionInfo = caosdb::info::v1::VersionInfo; TEST(test_info, create_info_from_proto_info) { @@ -46,4 +44,4 @@ TEST(test_info, create_info_from_proto_info) { EXPECT_EQ("1234asdf", wrapper.GetBuild()); } -} // namespace caosdb::info +} // namespace linkahead::info diff --git a/test/test_issues.cpp b/test/test_issues.cpp index 6422da5f4c86128be44286d853d768cd58db3c8c..25b1a87fa539e0624b978f489ca1c251f0a528f2 100644 --- a/test/test_issues.cpp +++ b/test/test_issues.cpp @@ -1,8 +1,8 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * * Copyright (C) 2021 Daniel Hornung <d.hornung@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -17,20 +17,19 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ -#include "caosdb/configuration.h" // for InsecureConnectionConfig... -#include "caosdb/connection.h" // for Connection -#include "caosdb/result_set.h" // for ResultSet -#include "caosdb/status_code.h" // for StatusCode, EXECUTING -#include "caosdb/transaction.h" // for Transaction -#include "caosdb/transaction_status.h" // for StatusCode -#include <gtest/gtest-message.h> // for Message -#include <gtest/gtest-test-part.h> // for SuiteApiResolver, TestPa... -#include <gtest/gtest_pred_impl.h> // for Test, TestInfo, TEST -#include <memory> // for allocator, unique_ptr +#include <gtest/gtest.h> +#include <memory> // for unique_ptr +#include <string> // for basic_string +#include "linkahead/configuration.h" // for InsecureConnectionConfigur... +#include "linkahead/connection.h" // for Connection +#include "linkahead/result_set.h" // for ResultSet +#include "linkahead/status_code.h" // for StatusCode +#include "linkahead/transaction.h" // for Transaction +#include "linkahead/transaction_status.h" // for StatusCode -namespace caosdb::transaction { -using caosdb::configuration::InsecureConnectionConfiguration; -using caosdb::connection::Connection; +namespace linkahead::transaction { +using linkahead::configuration::InsecureConnectionConfiguration; +using linkahead::connection::Connection; TEST(test_issues, test_issue_11) { const auto *host = "localhost"; @@ -47,4 +46,4 @@ TEST(test_issues, test_issue_11) { EXPECT_EQ(transaction->GetResultSet().size(), 0); } -} // namespace caosdb::transaction +} // namespace linkahead::transaction diff --git a/test/test_list_properties.cpp b/test/test_list_properties.cpp index 8e69ba381c20808fa4112eca06270c8bda5fa351..8c8dfe287dd1e73a527e098aee4e75404f3b91f4 100644 --- a/test/test_list_properties.cpp +++ b/test/test_list_properties.cpp @@ -1,9 +1,9 @@ /* * - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -20,19 +20,16 @@ * */ -#include "caosdb/data_type.h" // for DataType, AtomicDataType -#include "caosdb/entity.h" // for Entity -#include "caosdb/entity/v1/main.pb.h" // for AtomicDataType, DataType -#include "caosdb/value.h" // for Value +#include <gtest/gtest.h> #include <cstdint> // for int64_t -#include <gtest/gtest-message.h> // for Message -#include <gtest/gtest-test-part.h> // for TestPartResult, SuiteApi... -#include <gtest/gtest_pred_impl.h> // for AssertionResult, Test -#include <memory> // for allocator_traits<>::valu... -#include <string> // for string +#include <string> // for basic_string, string #include <vector> // for vector +#include "caosdb/entity/v1/main.pb.h" // for AtomicDataType, DataType, Entity +#include "linkahead/data_type.h" // for AtomicDataType, DataType, List... +#include "linkahead/entity.h" // for Property, Entity, Properties +#include "linkahead/value.h" // for ScalarValue, Value -namespace caosdb::entity { +namespace linkahead::entity { using ProtoEntity = caosdb::entity::v1::Entity; using ProtoParent = caosdb::entity::v1::Parent; using ProtoDataType = caosdb::entity::v1::DataType; @@ -97,4 +94,4 @@ TEST(test_list_property, test_list_reassignment) { } } -} // namespace caosdb::entity +} // namespace linkahead::entity diff --git a/test/test_protobuf.cpp b/test/test_protobuf.cpp index 42e1e574437e47f0129cb30b336ab336613daede..a49c205dd2f9ac03860d30ff6a315692751e0efe 100644 --- a/test/test_protobuf.cpp +++ b/test/test_protobuf.cpp @@ -1,9 +1,9 @@ /* * - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -19,20 +19,17 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ -#include "caosdb/data_type.h" // for DataType, ReferenceDataType -#include "caosdb/entity.h" // for Entity -#include "caosdb/entity/v1/main.pb.h" // for RepeatedPtrField, Message -#include <google/protobuf/arena.h> // for Arena -#include <gtest/gtest-message.h> // for Message -#include <gtest/gtest-test-part.h> // for SuiteApiResolver, TestPa... -#include <gtest/gtest_pred_impl.h> // for Test, TestInfo, TEST -#include <memory> // for allocator - -namespace caosdb { +#include <google/protobuf/arena.h> // for Arena +#include <gtest/gtest.h> +#include "caosdb/entity/v1/main.pb.h" // for Entity, Message, Version, Data... +#include "linkahead/data_type.h" // for DataType, ReferenceDataType +#include "linkahead/entity.h" // for Entity + +namespace linkahead { using ProtoEntity = caosdb::entity::v1::Entity; -using caosdb::entity::Entity; using caosdb::entity::v1::Message; using google::protobuf::Arena; +using linkahead::entity::Entity; TEST(test_protobuf, test_swap_trivial) { Arena arena; @@ -113,4 +110,4 @@ TEST(test_protobuf, test_copy_nested) { EXPECT_EQ(copy_entity.GetDataType().GetAsReference().GetName(), "src_per"); } -} // namespace caosdb +} // namespace linkahead diff --git a/test/test_transaction.cpp b/test/test_transaction.cpp index ed4dcd2aa72e3e857bc871f401504147b330385b..cb936c0dab7193178c9eaec132d429e7be2a5515 100644 --- a/test/test_transaction.cpp +++ b/test/test_transaction.cpp @@ -1,5 +1,5 @@ /* - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * * Copyright (C) 2021-2022 Timm Fitschen <t.fitschen@indiscale.com> * Copyright (C) 2021-2022 IndiScale GmbH <info@indiscale.com> @@ -17,37 +17,35 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ -#include "caosdb/configuration.h" // for InsecureConnectionConfig... -#include "caosdb/connection.h" // for Connection -#include "caosdb/entity.h" // for Entity -#include "caosdb/entity/v1/main.pb.h" // for Entity -#include "caosdb/exceptions.h" // for ConnectionError -#include "caosdb/result_set.h" // for MultiResultSet, Entity, Resu... -#include "caosdb/status_code.h" // for StatusCode -#include "caosdb/transaction.h" // for Transaction -#include "caosdb/transaction_handler.h" // for MultiTransactionResponse -#include "caosdb/transaction_status.h" // for ConnectionError -#include "caosdb_test_utility.h" // for EXPECT_THROW_MESSAGE -#include <algorithm> // for max -#include <google/protobuf/arena.h> // for Arena -#include <gtest/gtest-message.h> // for Message -#include <gtest/gtest-test-part.h> // for SuiteApiResolver, TestPa... -#include <gtest/gtest_pred_impl.h> // for Test, TestInfo, TEST -#include <memory> // for allocator, unique_ptr -#include <stdexcept> // for out_of_range -#include <string> // for string, basic_string -#include <utility> // for move -#include <vector> // for vector +#include <google/protobuf/arena.h> // for Arena +#include <gtest/gtest.h> +#include <filesystem> // for path +#include <memory> // for unique_ptr, make_unique +#include <stdexcept> // for out_of_range +#include <string> // for basic_string, operator+ +#include <utility> // for move +#include <vector> // for vector +#include "caosdb/entity/v1/main.pb.h" // for RetrieveResponse, MultiTra... +#include "linkahead/configuration.h" // for InsecureConnectionConfigur... +#include "linkahead/connection.h" // for Connection +#include "linkahead/entity.h" // for Entity, Role +#include "linkahead/exceptions.h" // for ConnectionError +#include "linkahead/file_descriptor.h" // for FileDescriptor +#include "linkahead/result_set.h" // for MultiResultSet +#include "linkahead/status_code.h" // for StatusCode +#include "linkahead/transaction.h" // for Transaction, Arena, Retrie... +#include "linkahead/transaction_status.h" // for StatusCode, TransactionStatus +#include "linkahead_test_utility.h" // for EXPECT_THROW_STARTS_WITH // IWYU pragma: no_include "net/proto2/public/repeated_field.h" -namespace caosdb::transaction { -using caosdb::configuration::InsecureConnectionConfiguration; -using caosdb::connection::Connection; -using caosdb::entity::Entity; -using caosdb::exceptions::ConnectionError; +namespace linkahead::transaction { +using linkahead::configuration::InsecureConnectionConfiguration; +using linkahead::connection::Connection; +using linkahead::entity::Entity; +using linkahead::exceptions::ConnectionError; using ProtoEntity = caosdb::entity::v1::Entity; -using caosdb::entity::Role; using caosdb::entity::v1::RetrieveResponse; +using linkahead::entity::Role; TEST(test_transaction, create_transaction) { const auto *host = "localhost"; @@ -180,7 +178,7 @@ TEST(test_transaction, test_update_entity) { Connection connection(configuration); auto transaction = connection.CreateTransaction(); - caosdb::entity::Entity update_entity; + linkahead::entity::Entity update_entity; update_entity.SetName("New Name"); auto error = transaction->UpdateEntity(&update_entity); @@ -288,4 +286,4 @@ TEST(test_transaction, test_multiple_wait_for_it) { EXPECT_EQ(transaction->WaitForIt().GetCode(), StatusCode::CONNECTION_ERROR); } -} // namespace caosdb::transaction +} // namespace linkahead::transaction diff --git a/test/test_user.cpp b/test/test_user.cpp index 5715833d0f23c5e8b887a8198fe5f96324dcafd8..a2dab195fc67f29472bf371fbd066767e22e6c2e 100644 --- a/test/test_user.cpp +++ b/test/test_user.cpp @@ -1,6 +1,6 @@ /* * - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * * Copyright (C) 2022 Timm Fitschen <t.fitschen@indiscale.com> * Copyright (C) 2022 IndiScale GmbH <info@indiscale.com> @@ -20,14 +20,15 @@ * */ -#include "caosdb/acm/user.h" // for User +#include "linkahead/acm/user.h" // for User +#include <gtest/gtest.h> #include <gtest/gtest-message.h> // for Message #include <gtest/gtest-test-part.h> // for TestPartResult, SuiteApiRe... #include <gtest/gtest_pred_impl.h> // for Test, EXPECT_EQ, TEST #include <string> // for allocator, string #include <utility> // for move -namespace caosdb::acm { +namespace linkahead::acm { TEST(test_user, user_name) { auto user = User("user1"); @@ -117,4 +118,4 @@ TEST(test_user, test_move_assign) { EXPECT_EQ(user1.GetPassword(), ""); } -} // namespace caosdb::acm +} // namespace linkahead::acm diff --git a/test/test_utility.cpp b/test/test_utility.cpp index 74db29afa798ccdbf9d4be45497e1a44762d630d..9880d1e830019091ca42cc25d1cf53f4cd89bb07 100644 --- a/test/test_utility.cpp +++ b/test/test_utility.cpp @@ -1,9 +1,9 @@ /* * - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -20,21 +20,19 @@ * */ -#include "boost/beast/core/detail/base64.hpp" // for encoded_size -#include "caosdb/data_type.h" // for atomicdatatype_names -#include "caosdb/entity.h" // for importance_names, role... -#include "caosdb/status_code.h" // for get_status_description -#include "caosdb/utility.h" // for base64_encode, load_js... -#include "caosdb_test_utility.h" // for TEST_DATA_DIR -#include <gtest/gtest-message.h> // for Message -#include <gtest/gtest-test-part.h> // for TestPartResult, SuiteA... -#include <gtest/gtest_pred_impl.h> // for Test, EXPECT_EQ, TestInfo -#include <map> // for map, operator!=, _Rb_t... +#include <gtest/gtest.h> +#include <map> // for _Rb_tree_const_iterator #include <stdexcept> // for out_of_range -#include <string> // for allocator, string, ope... +#include <string> // for basic_string, string #include <utility> // for pair +#include <boost/beast/core/detail/base64.hpp> // for encoded_size +#include "linkahead/data_type.h" // for AtomicDataType, atomic... +#include "linkahead/entity.h" // for Importance, Role, impo... +#include "linkahead/status_code.h" // for get_status_description +#include "linkahead/utility.h" // for getEnumValueFromName +#include "linkahead_test_utility.h" // for EXPECT_THROW_MESSAGE -namespace caosdb::utility { +namespace linkahead::utility { TEST(test_utility, base64_encode) { auto test_plain = std::string("admin:caosdb"); @@ -46,28 +44,28 @@ TEST(test_utility, base64_encode) { TEST(test_utility, enum_names) { // All working enums - for (const auto &entry : caosdb::entity::importance_names) { - EXPECT_EQ(getEnumNameFromValue<caosdb::entity::Importance>(entry.first), entry.second); - EXPECT_EQ(getEnumValueFromName<caosdb::entity::Importance>(entry.second), entry.first); + for (const auto &entry : linkahead::entity::importance_names) { + EXPECT_EQ(getEnumNameFromValue<linkahead::entity::Importance>(entry.first), entry.second); + EXPECT_EQ(getEnumValueFromName<linkahead::entity::Importance>(entry.second), entry.first); } - for (const auto &entry : caosdb::entity::role_names) { - EXPECT_EQ(getEnumNameFromValue<caosdb::entity::Role>(entry.first), entry.second); - EXPECT_EQ(getEnumValueFromName<caosdb::entity::Role>(entry.second), entry.first); + for (const auto &entry : linkahead::entity::role_names) { + EXPECT_EQ(getEnumNameFromValue<linkahead::entity::Role>(entry.first), entry.second); + EXPECT_EQ(getEnumValueFromName<linkahead::entity::Role>(entry.second), entry.first); } - for (const auto &entry : caosdb::entity::atomicdatatype_names) { - EXPECT_EQ(getEnumNameFromValue<caosdb::entity::AtomicDataType>(entry.first), entry.second); - EXPECT_EQ(getEnumValueFromName<caosdb::entity::AtomicDataType>(entry.second), entry.first); + for (const auto &entry : linkahead::entity::atomicdatatype_names) { + EXPECT_EQ(getEnumNameFromValue<linkahead::entity::AtomicDataType>(entry.first), entry.second); + EXPECT_EQ(getEnumValueFromName<linkahead::entity::AtomicDataType>(entry.second), entry.first); } // Some non-working examples - EXPECT_THROW_MESSAGE(getEnumValueFromName<caosdb::entity::Importance>("Invalid name"), + EXPECT_THROW_MESSAGE(getEnumValueFromName<linkahead::entity::Importance>("Invalid name"), std::out_of_range, "Could not find enum value for string 'Invalid name'."); } TEST(test_utility, test_status_code_description) { - EXPECT_EQ(caosdb::get_status_description(12412323), "MISSING DESCRIPTION"); - EXPECT_EQ(caosdb::get_status_description(static_cast<int>(StatusCode::UNKNOWN)), + EXPECT_EQ(linkahead::get_status_description(12412323), "MISSING DESCRIPTION"); + EXPECT_EQ(linkahead::get_status_description(static_cast<int>(StatusCode::UNKNOWN)), "Unknown error. This is typically a bug (server or client)."); } -} // namespace caosdb::utility +} // namespace linkahead::utility diff --git a/test/test_value.cpp b/test/test_value.cpp index 8de10b9051c5ded66f8ea3b4a23581f861a75b8d..0dab4d657d6112961b3d5d7eb40e17effab04604 100644 --- a/test/test_value.cpp +++ b/test/test_value.cpp @@ -1,9 +1,9 @@ /* * - * This file is a part of the CaosDB Project. + * This file is a part of the LinkAhead Project. * * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -20,19 +20,16 @@ * */ -#include "caosdb/value.h" // for Value -#include "caosdb/entity/v1/main.pb.h" // for AtomicDataType, DataType -#include "caosdb/protobuf_helper.h" // for ProtoMessageWrapper -#include <algorithm> // for max -#include <cmath> // for isnan -#include <gtest/gtest-message.h> // for Message -#include <gtest/gtest-test-part.h> // for TestPartResult, SuiteApi... -#include <gtest/gtest_pred_impl.h> // for AssertionResult, Test -#include <initializer_list> // for initializer_list -#include <string> // for string, basic_string -#include <vector> // for vector - -namespace caosdb::entity { +#include <gtest/gtest.h> +#include <cmath> // for sqrt, isnan +#include <initializer_list> // for initializer_list +#include <string> // for basic_string, string, operator+ +#include <vector> // for vector +#include "caosdb/entity/v1/main.pb.h" // for AtomicDataType, DataType, Entity +#include "linkahead/protobuf_helper.h" // for ProtoMessageWrapper +#include "linkahead/value.h" // for Value, ScalarValue, AbstractV... + +namespace linkahead::entity { using ProtoValue = caosdb::entity::v1::Value; using ProtoEntity = caosdb::entity::v1::Entity; using ProtoParent = caosdb::entity::v1::Parent; @@ -136,6 +133,14 @@ TEST(test_value, test_list) { EXPECT_EQ(item.IsString(), true); EXPECT_EQ(item.GetAsString(), "id" + std::to_string(counter++)); } + + // Test empty lists + auto empty_content = std::vector<int>(); + Value value_0(empty_content); + EXPECT_TRUE(value_0.IsVector()); + auto const &list_value_0 = value_0.GetAsVector(); + EXPECT_EQ(list_value_0.size(), 0); + EXPECT_TRUE(list_value_0.empty()); } TEST(test_value, test_scalar_value_to_value) { @@ -193,4 +198,4 @@ TEST(test_value, test_value_to_string) { "{\n \"booleanValue\": false\n }\n ]\n }\n}\n"); } -} // namespace caosdb::entity +} // namespace linkahead::entity diff --git a/test_package/CMakeLists.txt b/test_package/CMakeLists.txt index 6e0db0446b0d4a2e1767f1ecdf2156ffb5dbb295..a11332c293a36f3859605aa9bdc3e36e70269409 100644 --- a/test_package/CMakeLists.txt +++ b/test_package/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.13) project(PackageTest CXX) ####################################################################### @@ -12,9 +12,10 @@ set(test_cases ### Set up tests using GoogleTest (GTest) ################################################### -# dependencies -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup(KEEP_RPATHS) + +find_package(linkahead CONFIG REQUIRED) +find_package(GTest CONFIG REQUIRED) +find_package(Protobuf CONFIG REQUIRED) # supress warnings during build of gtest cmake_policy(SET CMP0054 NEW) @@ -24,24 +25,37 @@ enable_testing() include(GoogleTest REQUIRED) # loop over all test cases and add them to the test runner -list(LENGTH test_cases len_test_cases) -math(EXPR len_test_cases "${len_test_cases} - 1") -foreach (i RANGE "${len_test_cases}") - list(GET test_cases ${i} test_case_name) - add_executable(${test_case_name} ${test_case_name}.cpp) - target_link_libraries(${test_case_name} PRIVATE ${CONAN_LIBS_CAOSDB} - ${CONAN_LIBS_GTEST} ${CONAN_LIBS_GRPC} ${CONAN_LIBS_ABSEIL} - ${CONAN_LIBS_OPENSSL} ${CONAN_LIBS_C-ARES} ${CONAN_LIBS_BZIP2} - ${CONAN_LIBS_PROTOBUF} ${CONAN_LIBS_ZLIB}) - if("${CMAKE_BUILD_TYPE}" MATCHES "Debug") - target_link_libraries(${test_case_name} PRIVATE caosdb_grpc) - endif() - target_include_directories(${test_case_name} PUBLIC ${CONAN_INCLUDE_DIRS}) - set_target_properties(${test_case_name} - PROPERTIES - CXX_CLANG_TIDY "${_CMAKE_CXX_CLANG_TIDY}" - CXX_INCLUDE_WHAT_YOU_USE "${_CMAKE_CXX_INCLUDE_WHAT_YOU_USE}") - gtest_discover_tests(${test_case_name} - PROPERTIES - LABELS "caosdb-cpplib-int-tests") -endforeach () +add_executable(test_info test_info.cpp) +target_link_libraries(test_info PRIVATE + GTest::gtest GTest::gtest_main + linkahead::linkahead caosdb_grpc clinkahead + protobuf::protobuf) +gtest_discover_tests(test_info) + +# foreach(test_case ${test_cases}) +# add_executable(${test_case} ${test_case}.cpp) +# target_link_libraries(${test_case} PRIVATE GTest::gtest GTest::gtest_main linkahead::linkahead) +# if("${CMAKE_BUILD_TYPE}" MATCHES "Debug") +# target_link_libraries(${test_case} PRIVATE linkahead_grpc) +# endif() +# endforeach() + + +# list(LENGTH test_cases len_test_cases) +# math(EXPR len_test_cases "${len_test_cases} - 1") +# foreach (i RANGE "${len_test_cases}") +# list(GET test_cases ${i} test_case_name) +# add_executable(${test_case_name} ${test_case_name}.cpp) +# target_link_libraries(${test_case_name} PRIVATE GTest::gtest GTest::gtest_main linkahead::linkahead) +# if("${CMAKE_BUILD_TYPE}" MATCHES "Debug") +# target_link_libraries(${test_case_name} PRIVATE linkahead_grpc) +# endif() +# target_include_directories(${test_case_name} PUBLIC ${CONAN_INCLUDE_DIRS}) +# set_target_properties(${test_case_name} +# PROPERTIES +# CXX_CLANG_TIDY "${_CMAKE_CXX_CLANG_TIDY}" +# CXX_INCLUDE_WHAT_YOU_USE "${_CMAKE_CXX_INCLUDE_WHAT_YOU_USE}") +# gtest_discover_tests(${test_case_name} +# PROPERTIES +# LABELS "linkahead-cpplib-int-tests") +# endforeach () diff --git a/test_package/conanfile.py b/test_package/conanfile.py index 541113405bfca3b1222de81124a13586fe4bbda5..a5ae1d153f4090352ca792b814b87a306a712f83 100644 --- a/test_package/conanfile.py +++ b/test_package/conanfile.py @@ -1,28 +1,40 @@ -import os +from conan import ConanFile +from conan.tools.cmake import CMake, cmake_layout, CMakeDeps, CMakeToolchain +from conan.tools.files import copy +from conan.tools.build import cross_building -from conans import ConanFile, CMake, tools - -class LibcaosdbTestConan(ConanFile): +class LiblinkaheadTestConan(ConanFile): settings = "os", "compiler", "build_type", "arch" - generators = "cmake" - build_requires = [ - ("gtest/1.11.0"), - ] + + def requirements(self): + self.requires(self.tested_reference_str) + self.test_requires("gtest/1.11.0") + self.requires("grpc/1.48.4") + self.requires("protobuf/3.21.12") + self.requires("boost/1.80.0") + + def layout(self): + cmake_layout(self, src_folder=".") + + def generate(self): + tc = CMakeToolchain(self) + tc.generate() + + cmake = CMakeDeps(self) + cmake.generate() def build(self): cmake = CMake(self) - # Current dir is "test_package/build/<build_id>" and CMakeLists.txt is - # in "test_package" cmake.configure() cmake.build() - def imports(self): - self.copy("*.dll", dst="bin", src="bin") - self.copy("*.dylib*", dst="bin", src="lib") - self.copy('*.so*', dst='bin', src='lib') + # def imports(self): + # copy("*.dll", dst="bin", src="bin") + # copy("*.dylib*", dst="bin", src="lib") + # copy('*.so*', dst='bin', src='lib') def test(self): - if not tools.cross_building(self): + if not cross_building(self): cmake = CMake(self) cmake.test() diff --git a/vcpkg b/vcpkg new file mode 160000 index 0000000000000000000000000000000000000000..333ba63a16024f05f9172fe403f9eced000389e5 --- /dev/null +++ b/vcpkg @@ -0,0 +1 @@ +Subproject commit 333ba63a16024f05f9172fe403f9eced000389e5 diff --git a/vcpkg.json b/vcpkg.json new file mode 100644 index 0000000000000000000000000000000000000000..a14833bd5658ef9fc11b510abf52147dcfd65bac --- /dev/null +++ b/vcpkg.json @@ -0,0 +1,20 @@ +{ + "name": "liblinkahead", + "version-string": "0.3.0", + "port-version": 1, + "description": "C++ library for the LinkAhead project", + "license": "AGPL-3.0-or-later", + "dependencies": [ + "boost-beast", + "boost-filesystem", + "boost-json", + "boost-log", + "boost-smart-ptr", + "boost-thread", + "grpc", + "protobuf", + "zlib", + "gtest" + ], + "builtin-baseline": "5d3798ac7388ca66c169773e46103b14077b76a4" +}