feat add EventBus
Some checks failed
rpcrypto-build / build (Debug, himix200.toolchain.cmake) (push) Failing after 10s
rpcrypto-build / build (Debug, hisiv510.toolchain.cmake) (push) Failing after 10s
rpcrypto-build / build (Release, himix200.toolchain.cmake) (push) Failing after 10s
rpcrypto-build / build (Release, hisiv510.toolchain.cmake) (push) Failing after 10s
linux-x64-gcc / linux-gcc (push) Failing after 14s
linux-mips64-gcc / linux-gcc-mips64el (push) Failing after 20s
linux-hisiv500-gcc / linux-gcc-hisiv500 (push) Failing after 22s

This commit is contained in:
tqcq 2024-01-19 10:46:55 +08:00
parent 30f46d994f
commit d5ae2b9797
5 changed files with 43 additions and 17 deletions

1
3party/EventBus Submodule

@ -0,0 +1 @@
Subproject commit 62046399d423b74fd2612c85ef287bc6d309e0b4

View File

@ -2500,7 +2500,7 @@ template<typename T>
using hash = std::hash<tl::optional<T>>;
// if <= C++14
#if __cplusplus < 201703L
// #if __cplusplus < 201703L
template<typename T>
using optional = tl::optional<T>;
@ -2530,7 +2530,7 @@ make_optional(std::initializer_list<U> il, Args &&...args)
}
constexpr tl::nullopt_t nullopt{tl::nullopt};
#endif
// #endif
}// namespace ulib
#endif

View File

@ -80,6 +80,8 @@ set(FMT_USE_CPP11
CACHE BOOL "Use C++11" FORCE)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/3party/fmt)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/3party/sqlpp11)
set(ENABLE_TEST OFF)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/3party/EventBus)
set(JSONCPP_WITH_TESTS OFF)
set(JSONCPP_WITH_POST_BUILD_UNITTEST OFF)
@ -92,7 +94,7 @@ target_sources(
${PROJECT_NAME} PRIVATE src/ulib/empty.cpp src/ulib/log/logger.cpp
src/ulib/log/log.cpp src/ulib/log/level.cpp)
target_link_libraries(${PROJECT_NAME} PUBLIC fmt::fmt jsoncpp_static
sqlpp11::sqlpp11)
sqlpp11::sqlpp11 Dexode::EventBus)
target_compile_definitions(${PROJECT_NAME} PRIVATE ULIB_LIBRARY_IMPL)
target_include_directories(
${PROJECT_NAME}

View File

@ -0,0 +1,22 @@
#include <gtest/gtest.h>
#include <dexode/EventBus.hpp>
TEST(EventBus, BaseTest)
{
struct TestEvent {
int value;
};
dexode::EventBus bus;
auto listener = dexode::EventBus::Listener::createNotOwning(bus);
int callCount = 0;
{
listener.listen([&](const TestEvent &event) {
EXPECT_EQ(1, event.value);
++callCount;
});
bus.postpone(TestEvent{1});
EXPECT_EQ(bus.process(), 1);
EXPECT_EQ(callCount, 1);
}
}

View File

@ -13,6 +13,7 @@ add_executable(
ulib/system/thread_unittest.cpp
ulib/system/thread_pool_unittest.cpp
ulib/system/timer_unittest.cpp
3party/EventBus/EventBus_unittest.cpp
3party/inja/inja_unittest.cpp
3party/optional/optional_unittest.cpp
3party/sqlpp11/sqlpp11_unittest.cpp