Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Code Coverage

permissions:
pull-requests: write
contents: write

on:
push:
branches:
- master
pull_request:

jobs:
coverage_report:
name: Generate coverage report
runs-on: ubuntu-latest
steps:

- name: Checkout code
uses: actions/checkout@v4

- name: Setup vcpkg
run: |
chmod +x ./tools/install-vcpkg.sh
./tools/install-vcpkg.sh

- name: Setup lcov
uses: hrishikesh-kadam/setup-lcov@v1

- name: Generate lcov input
run: |
chmod +x ./build.sh
chmod +x ./test/coverage.sh
./test/coverage.sh

- name: Report code coverage
if: ${{ github.event_name == 'pull_request' }}
uses: zgosalvez/github-actions-report-lcov@v3
with:
coverage-files: build/filtered_coverage.info
minimum-coverage: 80
artifact-name: code-coverage-report
github-token: ${{ secrets.GITHUB_TOKEN }}
update-comment: true

- name: Upload code coverage report
if: ${{ github.ref_name == 'master' && github.event_name == 'push' }}
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: build/coverage_report
target-folder: coverage-report
branch: gh-pages
4 changes: 2 additions & 2 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ on:
jobs:
build-and-test:
runs-on: macos-latest

steps:
- uses: actions/checkout@v4

- name: Setup vcpkg
run: |
chmod +x ./tools/install-vcpkg.sh
./tools/install-vcpkg.sh

- name: Build
run: |
chmod +x ./build.sh
Expand Down
18 changes: 8 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,14 @@ set(VCPKG_BUILD_TYPE ${CMAKE_BUILD_TYPE})
message("CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
message("VCPKG_BUILD_TYPE: ${VCPKG_BUILD_TYPE}")

find_path(UWEBSOCKETS_INCLUDE_DIRS "uwebsockets/App.h")
message("µWebsockets include dir: ${UWEBSOCKETS_INCLUDE_DIRS}")
if(WIN32)
find_library(LIBUSOCKETS_STATIC uSockets.lib)
else(WIN32)
find_library(LIBUSOCKETS_STATIC libuSockets.a)
endif(WIN32)
message(${LIBUSOCKETS_STATIC})
find_package(unofficial-uwebsockets CONFIG REQUIRED)

find_path(MDNS_INCLUDE_DIRS "mdns.h")
message("mdns include dir: ${MDNS_INCLUDE_DIRS}")

find_package(mdns REQUIRED)
find_package(nlohmann_json 3.11.2 REQUIRED)
find_package(nlohmann_json_schema_validator REQUIRED)
find_package(libuv REQUIRED NO_MODULE)
find_package(ZLIB REQUIRED)

if(WT_WITH_SSL)
find_package(OpenSSL REQUIRED)
Expand All @@ -83,6 +74,13 @@ if(WT_BUILD_TESTS)
endif()

add_library(webthing-cpp INTERFACE)

target_link_libraries(webthing-cpp INTERFACE
nlohmann_json_schema_validator::validator
nlohmann_json::nlohmann_json
unofficial::uwebsockets::uwebsockets
)

target_include_directories(webthing-cpp INTERFACE
$<BUILD_INTERFACE:"${CMAKE_CURRENT_SOURCE_DIR}/include}">
$<INSTALL_INTERFACE:include>
Expand Down
27 changes: 25 additions & 2 deletions build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ if %errorlevel% equ 0 (
)
echo Project architecture: %build_arch%


echo %* | find /i "with_ssl" > nul
if %errorlevel% equ 0 (
set "ssl_support=ON"
Expand All @@ -43,7 +42,31 @@ if %errorlevel% equ 0 (
echo Project SSL support: %ssl_support%
copy %vcpkg_file% vcpkg.json

cmake -B "%build_dir%" -S . -DWT_WITH_SSL=%ssl_support% -DCMAKE_BUILD_TYPE=%build_type% -DCMAKE_TOOLCHAIN_FILE="%toolchain_file%" -DVCPKG_TARGET_TRIPLET="%vcpkg_triplet%" -G "Visual Studio 17 2022" -A "%build_arch%"
echo %* | find /i "without_tests" > nul
if %errorlevel% equ 0 (
set "build_tests=OFF"
) else (
set "build_tests=ON"
)
echo Project build tests: %build_tests%

echo %* | find /i "skip_tests" > nul
if %errorlevel% equ 0 (
set "skip_tests=ON"
) else (
set "skip_tests=OFF"
)
echo Project skip tests: %skip_tests%

echo %* | find /i "without_examples" > nul
if %errorlevel% equ 0 (
set "build_examples=OFF"
) else (
set "build_examples=ON"
)
echo Project build examples: %build_examples%

cmake -B "%build_dir%" -S . -DWT_BUILD_TESTS=%build_tests% -DWT_SKIP_TESTS=%skip_tests% -DWT_BUILD_EXAMPLES=%build_examples% -DWT_WITH_SSL=%ssl_support% -DCMAKE_BUILD_TYPE=%build_type% -DCMAKE_TOOLCHAIN_FILE="%toolchain_file%" -DVCPKG_TARGET_TRIPLET="%vcpkg_triplet%" -G "Visual Studio 17 2022" -A "%build_arch%"
cmake --build "%build_dir%" --config "%build_type%" --parallel %NUMBER_OF_PROCESSORS%

ctest --test-dir "%build_dir%\test\"
28 changes: 27 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ fi
if [[ "${@#release}" = "$@" ]]
then
build_type="Debug"
code_coverage="ON"
else
build_type="Release"
code_coverage="OFF"
rm -rf $build_dir
fi
echo "project build type: $build_type"
echo "project code coverage: $code_coverage"

if [[ "${@#with_ssl}" = "$@" ]]
then
Expand All @@ -33,8 +36,31 @@ fi
echo "project SSL support: $ssl_support"
cp $vcpkg_file vcpkg.json

if [[ "${@#without_tests}" = "$@" ]]
then
build_tests="ON"
else
build_tests="OFF"
fi
echo "project build tests: $build_tests"

if [[ "${@#skip_tests}" = "$@" ]]
then
skip_tests="OFF"
else
skip_tests="ON"
fi
echo "project skip tests: $build_tests"

if [[ "${@#without_examples}" = "$@" ]]
then
build_examples="ON"
else
build_examples="OFF"
fi
echo "project build examples: $build_examples"

cmake -B build -S . -D"WT_WITH_SSL=$ssl_support" -D"CMAKE_BUILD_TYPE=$build_type" -D"CMAKE_TOOLCHAIN_FILE=$toolchain_file" -D"CMAKE_MAKE_PROGRAM:PATH=make" -D"CMAKE_CXX_COMPILER=g++"
cmake -B build -S . -D"WT_BUILD_TESTS=$build_tests" -D"WT_SKIP_TESTS=$skip_tests" -D"WT_BUILD_EXAMPLES=$build_examples" -D"WT_WITH_SSL=$ssl_support" -D"CMAKE_BUILD_TYPE=$build_type" -D"WT_ENABLE_COVERAGE=$code_coverage" -D"CMAKE_TOOLCHAIN_FILE=$toolchain_file" -D"CMAKE_MAKE_PROGRAM:PATH=make" -D"CMAKE_CXX_COMPILER=g++"
cmake --build build --parallel $(nproc)

ctest --test-dir build/test/
13 changes: 2 additions & 11 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@ configure_file(
)

set(LIBS_FOR_EXAMPLES
${LIBUSOCKETS_STATIC}
nlohmann_json::nlohmann_json
nlohmann_json_schema_validator::validator
ZLIB::ZLIB
$<IF:$<TARGET_EXISTS:libuv::uv_a>,libuv::uv_a,libuv::uv>
unofficial::uwebsockets::uwebsockets
)

set(INCLUDES_FOR_EXAMPLES ../include ${UWEBSOCKETS_INCLUDE_DIRS} ${MDNS_INCLUDE_DIRS})

set(INCLUDES_FOR_EXAMPLES ../include)

function(create_example_binary cpp_file)
cmake_path(GET cpp_file STEM target)
Expand All @@ -26,11 +22,6 @@ function(create_example_binary cpp_file)

target_include_directories("${target}" PRIVATE ${INCLUDES_FOR_EXAMPLES})
target_link_libraries("${target}" PRIVATE ${LIBS_FOR_EXAMPLES})

if(WT_WITH_SSL)
target_link_libraries("${target}" PRIVATE OpenSSL::SSL OpenSSL::Crypto)
endif(WT_WITH_SSL)

endfunction()

create_example_binary(single-thing.cpp)
Expand Down
25 changes: 13 additions & 12 deletions include/bw/webthing/server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ struct MultipleThings : public ThingContainer{

class WebThingServer
{
public:
struct Builder
{
Builder(ThingContainer things)
Expand Down Expand Up @@ -133,11 +134,6 @@ class WebThingServer
return *this;
}

Builder& limit_memory()
{
return *this;
}

WebThingServer build()
{
return WebThingServer(things_, port_, hostname_, base_path_,
Expand All @@ -160,7 +156,6 @@ class WebThingServer

};

public:
struct Response
{
Response(uWS::HttpRequest* req, uwsHttpResponse* res)
Expand Down Expand Up @@ -434,9 +429,7 @@ class WebThingServer
else if(v.is_string())
prop_setter(v.get<std::string>());
else if(v.is_number_integer())
prop_setter(v.get<int>());
else if(v.is_number_unsigned())
prop_setter(v.get<unsigned int>());
prop_setter(v.get<int>());
else if(v.is_number_float())
prop_setter(v.get<double>());
else
Expand Down Expand Up @@ -528,6 +521,16 @@ class WebThingServer
return name;
}

int get_port() const
{
return port;
}

std::string get_base_path() const
{
return base_path;
}

uWebsocketsApp* get_web_server() const
{
return web_server.get();
Expand Down Expand Up @@ -820,11 +823,9 @@ class WebThingServer
if(v.is_boolean())
prop_setter(v.get<bool>());
else if(v.is_string())
prop_setter(v.get<std::string>());
prop_setter(v.get<std::string>());
else if(v.is_number_integer())
prop_setter(v.get<int>());
else if(v.is_number_unsigned())
prop_setter(v.get<unsigned int>());
else if(v.is_number_float())
prop_setter(v.get<double>());
else
Expand Down
4 changes: 2 additions & 2 deletions include/bw/webthing/thing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class Thing
return pds;
}

// Get the thing's actions a json array
// Get the thing's actions as json array
// action_name -- Optional action name to get description for
json get_action_descriptions(std::optional<std::string> action_name = std::nullopt) const
{
Expand All @@ -146,7 +146,7 @@ class Thing
return descriptions;
}

// Get the thing's events as a json array.
// Get the thing's events as json array.
// event_name -- Optional event name to get description for
json get_event_descriptions(const std::optional<std::string>& event_name = std::nullopt) const
{
Expand Down
2 changes: 1 addition & 1 deletion include/bw/webthing/version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@

namespace bw::webthing {

constexpr const char version[] = "1.1.0";
constexpr const char version[] = "1.2.0";

} // bw::webthing
Loading
Loading