Skip to content

Commit a02ac33

Browse files
authored
Merge pull request #12 from bw-hro/dev
update uwebsocket dependency to 20.71.0 + improved testing
2 parents 74de307 + 5ea0f39 commit a02ac33

21 files changed

Lines changed: 1256 additions & 129 deletions

.github/workflows/coverage.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Code Coverage
2+
3+
permissions:
4+
pull-requests: write
5+
contents: write
6+
7+
on:
8+
push:
9+
branches:
10+
- master
11+
pull_request:
12+
13+
jobs:
14+
coverage_report:
15+
name: Generate coverage report
16+
runs-on: ubuntu-latest
17+
steps:
18+
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
22+
- name: Setup vcpkg
23+
run: |
24+
chmod +x ./tools/install-vcpkg.sh
25+
./tools/install-vcpkg.sh
26+
27+
- name: Setup lcov
28+
uses: hrishikesh-kadam/setup-lcov@v1
29+
30+
- name: Generate lcov input
31+
run: |
32+
chmod +x ./build.sh
33+
chmod +x ./test/coverage.sh
34+
./test/coverage.sh
35+
36+
- name: Report code coverage
37+
if: ${{ github.event_name == 'pull_request' }}
38+
uses: zgosalvez/github-actions-report-lcov@v3
39+
with:
40+
coverage-files: build/filtered_coverage.info
41+
minimum-coverage: 80
42+
artifact-name: code-coverage-report
43+
github-token: ${{ secrets.GITHUB_TOKEN }}
44+
update-comment: true
45+
46+
- name: Upload code coverage report
47+
if: ${{ github.ref_name == 'master' && github.event_name == 'push' }}
48+
uses: JamesIves/github-pages-deploy-action@v4
49+
with:
50+
folder: build/coverage_report
51+
target-folder: coverage-report
52+
branch: gh-pages

.github/workflows/macos.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ on:
1010
jobs:
1111
build-and-test:
1212
runs-on: macos-latest
13-
13+
1414
steps:
1515
- uses: actions/checkout@v4
1616

1717
- name: Setup vcpkg
1818
run: |
1919
chmod +x ./tools/install-vcpkg.sh
2020
./tools/install-vcpkg.sh
21-
21+
2222
- name: Build
2323
run: |
2424
chmod +x ./build.sh

CMakeLists.txt

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,14 @@ set(VCPKG_BUILD_TYPE ${CMAKE_BUILD_TYPE})
4848
message("CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
4949
message("VCPKG_BUILD_TYPE: ${VCPKG_BUILD_TYPE}")
5050

51-
find_path(UWEBSOCKETS_INCLUDE_DIRS "uwebsockets/App.h")
52-
message("µWebsockets include dir: ${UWEBSOCKETS_INCLUDE_DIRS}")
53-
if(WIN32)
54-
find_library(LIBUSOCKETS_STATIC uSockets.lib)
55-
else(WIN32)
56-
find_library(LIBUSOCKETS_STATIC libuSockets.a)
57-
endif(WIN32)
58-
message(${LIBUSOCKETS_STATIC})
51+
find_package(unofficial-uwebsockets CONFIG REQUIRED)
5952

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

6356
find_package(mdns REQUIRED)
6457
find_package(nlohmann_json 3.11.2 REQUIRED)
6558
find_package(nlohmann_json_schema_validator REQUIRED)
66-
find_package(libuv REQUIRED NO_MODULE)
67-
find_package(ZLIB REQUIRED)
6859

6960
if(WT_WITH_SSL)
7061
find_package(OpenSSL REQUIRED)
@@ -83,6 +74,13 @@ if(WT_BUILD_TESTS)
8374
endif()
8475

8576
add_library(webthing-cpp INTERFACE)
77+
78+
target_link_libraries(webthing-cpp INTERFACE
79+
nlohmann_json_schema_validator::validator
80+
nlohmann_json::nlohmann_json
81+
unofficial::uwebsockets::uwebsockets
82+
)
83+
8684
target_include_directories(webthing-cpp INTERFACE
8785
$<BUILD_INTERFACE:"${CMAKE_CURRENT_SOURCE_DIR}/include}">
8886
$<INSTALL_INTERFACE:include>

build.bat

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ if %errorlevel% equ 0 (
3131
)
3232
echo Project architecture: %build_arch%
3333

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

46-
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%"
45+
echo %* | find /i "without_tests" > nul
46+
if %errorlevel% equ 0 (
47+
set "build_tests=OFF"
48+
) else (
49+
set "build_tests=ON"
50+
)
51+
echo Project build tests: %build_tests%
52+
53+
echo %* | find /i "skip_tests" > nul
54+
if %errorlevel% equ 0 (
55+
set "skip_tests=ON"
56+
) else (
57+
set "skip_tests=OFF"
58+
)
59+
echo Project skip tests: %skip_tests%
60+
61+
echo %* | find /i "without_examples" > nul
62+
if %errorlevel% equ 0 (
63+
set "build_examples=OFF"
64+
) else (
65+
set "build_examples=ON"
66+
)
67+
echo Project build examples: %build_examples%
68+
69+
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%"
4770
cmake --build "%build_dir%" --config "%build_type%" --parallel %NUMBER_OF_PROCESSORS%
4871

4972
ctest --test-dir "%build_dir%\test\"

build.sh

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@ fi
1616
if [[ "${@#release}" = "$@" ]]
1717
then
1818
build_type="Debug"
19+
code_coverage="ON"
1920
else
2021
build_type="Release"
22+
code_coverage="OFF"
2123
rm -rf $build_dir
2224
fi
2325
echo "project build type: $build_type"
26+
echo "project code coverage: $code_coverage"
2427

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

39+
if [[ "${@#without_tests}" = "$@" ]]
40+
then
41+
build_tests="ON"
42+
else
43+
build_tests="OFF"
44+
fi
45+
echo "project build tests: $build_tests"
46+
47+
if [[ "${@#skip_tests}" = "$@" ]]
48+
then
49+
skip_tests="OFF"
50+
else
51+
skip_tests="ON"
52+
fi
53+
echo "project skip tests: $build_tests"
54+
55+
if [[ "${@#without_examples}" = "$@" ]]
56+
then
57+
build_examples="ON"
58+
else
59+
build_examples="OFF"
60+
fi
61+
echo "project build examples: $build_examples"
3662

37-
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++"
63+
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++"
3864
cmake --build build --parallel $(nproc)
3965

4066
ctest --test-dir build/test/

examples/CMakeLists.txt

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,11 @@ configure_file(
77
)
88

99
set(LIBS_FOR_EXAMPLES
10-
${LIBUSOCKETS_STATIC}
11-
nlohmann_json::nlohmann_json
1210
nlohmann_json_schema_validator::validator
13-
ZLIB::ZLIB
14-
$<IF:$<TARGET_EXISTS:libuv::uv_a>,libuv::uv_a,libuv::uv>
11+
unofficial::uwebsockets::uwebsockets
1512
)
1613

17-
set(INCLUDES_FOR_EXAMPLES ../include ${UWEBSOCKETS_INCLUDE_DIRS} ${MDNS_INCLUDE_DIRS})
18-
14+
set(INCLUDES_FOR_EXAMPLES ../include)
1915

2016
function(create_example_binary cpp_file)
2117
cmake_path(GET cpp_file STEM target)
@@ -26,11 +22,6 @@ function(create_example_binary cpp_file)
2622

2723
target_include_directories("${target}" PRIVATE ${INCLUDES_FOR_EXAMPLES})
2824
target_link_libraries("${target}" PRIVATE ${LIBS_FOR_EXAMPLES})
29-
30-
if(WT_WITH_SSL)
31-
target_link_libraries("${target}" PRIVATE OpenSSL::SSL OpenSSL::Crypto)
32-
endif(WT_WITH_SSL)
33-
3425
endfunction()
3526

3627
create_example_binary(single-thing.cpp)

include/bw/webthing/server.hpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ struct MultipleThings : public ThingContainer{
9191

9292
class WebThingServer
9393
{
94+
public:
9495
struct Builder
9596
{
9697
Builder(ThingContainer things)
@@ -133,11 +134,6 @@ class WebThingServer
133134
return *this;
134135
}
135136

136-
Builder& limit_memory()
137-
{
138-
return *this;
139-
}
140-
141137
WebThingServer build()
142138
{
143139
return WebThingServer(things_, port_, hostname_, base_path_,
@@ -160,7 +156,6 @@ class WebThingServer
160156

161157
};
162158

163-
public:
164159
struct Response
165160
{
166161
Response(uWS::HttpRequest* req, uwsHttpResponse* res)
@@ -434,9 +429,7 @@ class WebThingServer
434429
else if(v.is_string())
435430
prop_setter(v.get<std::string>());
436431
else if(v.is_number_integer())
437-
prop_setter(v.get<int>());
438-
else if(v.is_number_unsigned())
439-
prop_setter(v.get<unsigned int>());
432+
prop_setter(v.get<int>());
440433
else if(v.is_number_float())
441434
prop_setter(v.get<double>());
442435
else
@@ -528,6 +521,16 @@ class WebThingServer
528521
return name;
529522
}
530523

524+
int get_port() const
525+
{
526+
return port;
527+
}
528+
529+
std::string get_base_path() const
530+
{
531+
return base_path;
532+
}
533+
531534
uWebsocketsApp* get_web_server() const
532535
{
533536
return web_server.get();
@@ -820,11 +823,9 @@ class WebThingServer
820823
if(v.is_boolean())
821824
prop_setter(v.get<bool>());
822825
else if(v.is_string())
823-
prop_setter(v.get<std::string>());
826+
prop_setter(v.get<std::string>());
824827
else if(v.is_number_integer())
825828
prop_setter(v.get<int>());
826-
else if(v.is_number_unsigned())
827-
prop_setter(v.get<unsigned int>());
828829
else if(v.is_number_float())
829830
prop_setter(v.get<double>());
830831
else

include/bw/webthing/thing.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class Thing
132132
return pds;
133133
}
134134

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

149-
// Get the thing's events as a json array.
149+
// Get the thing's events as json array.
150150
// event_name -- Optional event name to get description for
151151
json get_event_descriptions(const std::optional<std::string>& event_name = std::nullopt) const
152152
{

include/bw/webthing/version.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88

99
namespace bw::webthing {
1010

11-
constexpr const char version[] = "1.1.0";
11+
constexpr const char version[] = "1.2.0";
1212

1313
} // bw::webthing

0 commit comments

Comments
 (0)