Skip to content

libsese/sese

Sese Framework

logo
license lang buildsystem
CodeFactor Status GitHub Workflow Status (with event) GitHub Workflow Status (with event) GitHub Workflow Status (with event)

Intro

This is a cross-platform framework for developing fundamental components, used to some extent as a supplement to the standard library. It is positioned similarly to Boost and folly with respect to the standard library. The project uses C++ 17 standard and introduces vcpkg as a package manager to help us simplify dependency management issues.

Demo

Builtin logger

#include <sese/record/Marco.h>
// ...
SESE_INFO("hello world");
SESE_WARN("error %s", err.what().c_str());

2024-05-15T15:54:48.296Z I main.cpp:8 Main:7116> hello world
2024-05-15T15:54:48.296Z W main.cpp:9 Main:7116> error End of file


HTTP Controller

#include <sese/service/http/HttpServer_V3.h>
// ...
SESE_CTRL(MyController, std::mutex mutex{}; int times = 0) {
    SESE_INFO("LOADING MyController");
    SESE_URL(timers, RequestType::GET, "/times") {
        sese::Locker locker(mutex);
        times += 1;
        auto message = "timers = '" + std::to_string(this->times) + "'\n";
        resp.getBody().write(message.data(), message.length());
    };
    SESE_URL(say, RequestType::GET, "/say?<say>") {
        auto words = req.get("say");
        auto message = "you say '" + words + "'\n";
        resp.getBody().write(message.data(), message.length());
    };
    SESE_INFO("LOADED");
}

Cross-process communication

#include <sese/system/IPC.h>
#include <sese/record/Marco.h>
// ···
// server
auto channel = sese::system::IPCChannel::create("Test", 1024);
    while (true) {
        auto messages = channel->read(1);
        if (messages.empty()) {
            sese::sleep(1s);
            continue;
        }
        for (auto &&msg: messages) {
            SESE_INFO("recv %s", msg.getDataAsString().c_str());

            if (msg.getDataAsString() == "Exit") {
                goto end;
            }
        }
    }
end:
    return 0;
// ···
// client
auto channel = sese::system::IPCChannel::use("Test");
channel->write(1, "Hello");
channel->write(2, "Hi");
channel->write(1, "Exit");

Build

For Developers/Contributors

  1. Configure the development environment

For Windows users, please install and config the vcpkg.

For non-Windows users, vcpkg is likewise available. But at the same time, you can choose to install the dependencies using the native system dependency management tool. We have provided several preset installation scripts.

  • Ubuntu
sudo ./scripts/install_ubuntu_deps.sh
  • Fedora
sudo ./scripts/install_fedora_deps.sh
  • macOS
./scripts/install_darwin_deps.sh
  1. Compilation options

If you have vcpkg configured, you can simply configure the dependencies by setting the toolchain file.

If you're using a system dependency management tool, you'll need to manually add the 'SESE_USE_NATIVE_MANAGER' compilation option after pressing the corresponding dependency.

sese/CMakeLists.txt

Lines 8 to 16 in 4cd7438

option(SESE_USE_NATIVE_MANAGER "use the unix-like packages control" OFF)
option(SESE_BUILD_TEST "build unit test targets" OFF)
option(SESE_BUILD_EXAMPLE "build example targets" OFF)
option(SESE_AUTO_VCPKG "auto find vcpkg and include toolchain" OFF)
option(SESE_USE_ASYNC_LOGGER "use async logger" OFF)
option(SESE_USE_ARCHIVE "add archive support" OFF)
option(SESE_DB_USE_SQLITE "add sqlite support" ON)
option(SESE_DB_USE_MARIADB "add mariadb and mysql support" OFF)
option(SESE_DB_USE_POSTGRES "add postgresql support" OFF)

Tip

Please refer to the latest CMakeLists.txt file understands the corresponding functional options Or you can just use our default CMakePresets.json, which will enable most of the options by default.

  1. Compile

Configuring the finished compilation options only requires a regular build, such as:

cmake --build build/linux-debug -- -j 4

For Normal Users

For common users, we recommend using vcpkg to import this dependency, you can refer to our template project to config your project()

Warning

Projects can also be installed on ordinary machines as normal projects, but this is not a recommended practice and cannot be supported. If you want to do this, you can refer to the 'Build' > 'For Developers/Contributors' section on dependency management tools.

The main job is to write the project's dependency configuration file, for example:

vcpkg.json

{
  "dependencies": [
    "sese"
  ]
}

Important

As of today (2024-05-15), this project has not yet entered the list of built-in libraries. This means that you need to write an additional configuration file for importing our private registry

vcpkg-configuration.json

{
  "default-registry": {
    "kind": "git",
    "repository": "https://github.com/microsoft/vcpkg.git",
    "baseline": "c8696863d371ab7f46e213d8f5ca923c4aef2a00"
  },
  "registries": [
    {
      "kind": "git",
      "repository": "https://github.com/libsese/vcpkg-registry.git",
      "baseline": "73268778d5f796f188ca66f71536377b171ee37e",
      "packages": [
        "sese"
      ]
    }
  ]
}

If you're not using vcpkg, the above steps are unnecessary.

Testing

We used googletest as our testing framework. Detailed information about our tests can be found in github actions, including the results of various platforms and linux test coverage.

Platform Entry Unit Test Coverage Test
Windows Unit Tests
Linux Unit Tests
macOS Unit Tests
  1. Local Testing
  • Services on Ubuntu workflow

If you need to run full tests locally, you may need to pay attention to the database side of the test, which requires some additional service and configuration support.

services:
mariadb:
image: mariadb
env:
MARIADB_ROOT_HOST: '%'
MARIADB_USER: libsese
MARIADB_PASSWORD: libsese
MARIADB_ROOT_PASSWORD: libsese
ports:
- '127.0.0.1:18806:3306'
postgresql:
image: postgres
env:
POSTGRES_PASSWORD: libsese
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- '127.0.0.1:18080:5432'

- name: Setup Database
working-directory: ${{ github.workspace }}
env:
PGPASSWORD: libsese
run: |
mysql -uroot -plibsese -h 127.0.0.1 -P 18806 < ./scripts/mysql_dump.sql
psql -U postgres -d postgres -h 127.0.0.1 -p 18080 -f ./scripts/postgres_dump.sql
mkdir build
sqlite3 build/db_test.db < scripts/sqlite_dump.sql

-DSESE_DB_MYSQL_CONNECTION_STRING="host=127.0.0.1\;port=18806\;user=root\;pwd=libsese\;db=db_test\;"
-DSESE_DB_PSQL_CONNECTION_STRING="host=127.0.0.1\;port=18080\;user=postgres\;pwd=libsese\;db=db_test\;"
-DSESE_DB_SQLITE_CONNECTION_STRING="${{ github.workspace }}/build/db_test.db"
-DCMAKE_CXX_FLAGS="--coverage -fprofile-update=atomic"

  • Deploy services through docker-compose
docker-compose up -d
sqlite3 build/db_test.db < scripts/sqlite_dump.sql
  1. Generate coverage test reports

Gcovr needs to be installed, either by pip or using the System Package Manager.

mkdir -p build/coverage/html
gcovr --config gcovr-html.cfg

Note

Generating coverage test data first requires setting some additional compilation options to generate test data such as gcov format, such as GCC compilation options:

-DCMAKE_CXX_FLAGS="--coverage -fprofile-update=atomic"

Documents

Documents will be updated automatically with the update of the main branch to making pages.

Document content is automatically generated from code comments, and the docs directory actually houses some of the resources needed to build the document.