Skip to content

Commit ea80c16

Browse files
committed
Update delegate library
1 parent 7584aa6 commit ea80c16

66 files changed

Lines changed: 5876 additions & 381 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CMakeLists.txt

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@ cmake_minimum_required(VERSION 3.10)
1212
# Project name and language (C or C++)
1313
project(IntegrationTestFramework VERSION 1.0 LANGUAGES CXX)
1414

15+
# Set build options
16+
set (DMQ_EXTERNAL_LIB "OFF")
17+
set (DMQ_ALLOCATOR "OFF")
18+
set (DMQ_UTIL "ON")
19+
set (DMQ_THREAD "DMQ_THREAD_STDLIB")
20+
set (DMQ_SERIALIZE "DMQ_SERIALIZE_NONE")
21+
set (DMQ_TRANSPORT "DMQ_TRANSPORT_NONE")
22+
include("${CMAKE_SOURCE_DIR}/DelegateMQ/DelegateMQ.cmake")
23+
24+
# Enable integration test build
25+
set (ENABLE_IT "ON")
26+
add_compile_definitions(IT_ENABLE)
27+
1528
# Set C++ standard
1629
set(CMAKE_CXX_STANDARD 17)
1730
set(CMAKE_CXX_STANDARD_REQUIRED True)
@@ -23,13 +36,13 @@ set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:DebugDLL>")
2336
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
2437

2538
# Collect all .cpp and *.h source files in the current directory
26-
file(GLOB SOURCES "${CMAKE_SOURCE_DIR}/*.cpp" "${CMAKE_SOURCE_DIR}/*.h")
39+
file(GLOB SOURCES "*.cpp" "*.h")
2740

28-
# Collect all header files in the Delegate directory
29-
file(GLOB Delegate_HEADERS "${CMAKE_SOURCE_DIR}/Delegate/*.h")
41+
# Collect DelegateMQ predef source files
42+
list(APPEND SOURCES ${DMQ_PREDEF_SOURCES})
3043

31-
# Organize Delegate headers into a "Delegate Files" folder in Visual Studio
32-
source_group("Delegate Files" FILES ${Delegate_HEADERS})
44+
# Organize delegate source files within IDE (Visual Studio)
45+
source_group("Delegate Files" FILES ${DMQ_LIB_SOURCES})
3346

3447
# Platform-specific linker flags
3548
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
@@ -51,15 +64,15 @@ include_directories(
5164
# Add subdirectories to include path if building integration tests
5265
if (ENABLE_IT)
5366
include_directories(
67+
${DMQ_ROOT_DIR}
5468
${CMAKE_SOURCE_DIR}/Logger/it
55-
${CMAKE_SOURCE_DIR}/Delegate
5669
${CMAKE_SOURCE_DIR}/IntegrationTest
5770
${CMAKE_SOURCE_DIR}/GoogleTest/googletest/include
5871
)
5972
endif()
6073

6174
# Add an executable target
62-
add_executable(IntegrationTestFrameworkApp ${SOURCES} ${Delegate_HEADERS})
75+
add_executable(IntegrationTestFrameworkApp ${SOURCES} ${DMQ_LIB_SOURCES})
6376

6477
# Add subdirectories to build (product related code)
6578
add_subdirectory(Logger/src)

Delegate/DelegateInvoker.h

Lines changed: 0 additions & 37 deletions
This file was deleted.

Delegate/DelegateLib.h

Lines changed: 0 additions & 62 deletions
This file was deleted.

Delegate/DelegateThread.h

Lines changed: 0 additions & 33 deletions
This file was deleted.

DelegateMQ/Common.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Set C++ standard
2+
# C++17 minimum required
3+
set(CMAKE_CXX_STANDARD 17)
4+
set(CMAKE_CXX_STANDARD_REQUIRED True)
5+
6+
7+

DelegateMQ/DelegateMQ.cmake

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
set (DMQ_ROOT_DIR "${CMAKE_CURRENT_LIST_DIR}")
2+
3+
if(EXISTS "${DMQ_ROOT_DIR}/Common.cmake")
4+
include ("${DMQ_ROOT_DIR}/Common.cmake")
5+
else()
6+
message(FATAL_ERROR "Common.cmake not found.")
7+
endif()
8+
9+
if(EXISTS "${DMQ_ROOT_DIR}/Predef.cmake")
10+
include ("${DMQ_ROOT_DIR}/Predef.cmake")
11+
else()
12+
message(FATAL_ERROR "Predef.cmake not found.")
13+
endif()
14+
15+
if (DMQ_EXTERNAL_LIB)
16+
if(EXISTS "${DMQ_ROOT_DIR}/External.cmake")
17+
include ("${DMQ_ROOT_DIR}/External.cmake")
18+
else()
19+
message(FATAL_ERROR "External.cmake not found.")
20+
endif()
21+
endif()
22+
23+
if(EXISTS "${DMQ_ROOT_DIR}/Macros.cmake")
24+
include ("${DMQ_ROOT_DIR}/Macros.cmake")
25+
else()
26+
message(FATAL_ERROR "Macros.cmake not found.")
27+
endif()
28+

DelegateMQ/DelegateMQ.h

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#ifndef _DELEGATE_MQ_H
2+
#define _DELEGATE_MQ_H
3+
4+
// Delegate.h
5+
// @see https://github.com/endurodave/DelegateMQ
6+
// David Lafreniere, 2025.
7+
8+
/// @file
9+
/// @brief DelegateMQ.h is a single include to obtain all delegate functionality.
10+
///
11+
/// A C++ delegate library capable of invoking any callable function either synchronously
12+
/// or asynchronously on a user specified thread of control. It is also capable of calling
13+
/// a function remotely over any transport protocol.
14+
///
15+
/// Asynchronous function calls support both non-blocking and blocking modes with a timeout.
16+
/// The library supports all types of target functions, including free functions, class
17+
/// member functions, static class functions, lambdas, and `std::function`. It is capable of
18+
/// handling any function signature, regardless of the number of arguments or return value.
19+
/// All argument types are supported, including by value, pointers, pointers to pointers,
20+
/// and references. The delegate library takes care of the intricate details of function
21+
/// invocation across thread boundaries. Thread-safe delegate containers stores delegate
22+
/// instances with a matching function signature.
23+
///
24+
/// A delegate instance can be:
25+
///
26+
/// * Copied freely.
27+
/// * Compared to same type delegatesand `nullptr`.
28+
/// * Reassigned.
29+
/// * Called.
30+
///
31+
/// Typical use cases are:
32+
///
33+
/// * Asynchronous Method Invocation(AMI)
34+
/// * Publish / Subscribe(Observer) Pattern
35+
/// * Anonymous, Asynchronous Thread - Safe Callbacks
36+
/// * Event - Driven Programming
37+
/// * Thread - Safe Asynchronous API
38+
/// * Design Patterns(Active Object)
39+
///
40+
/// The delegate library's asynchronous features differ from `std::async` in that the
41+
/// caller-specified thread of control is used to invoke the target function bound to
42+
/// the delegate, rather than a random thread from the thread pool. The asynchronous
43+
/// variants copy the argument data into the event queue, ensuring safe transport to the
44+
/// destination thread, regardless of the argument type. This approach provides 'fire and
45+
/// forget' functionality, allowing the caller to avoid waiting or worrying about
46+
/// out-of-scope stack variables being accessed by the target thread.
47+
///
48+
/// The `Async` and `AsyncWait` class variants may throw `std::bad_alloc` if heap allocation
49+
/// fails within `operator()(Args... args)`. Alternatively, define `DMQ_ASSERTS` to use `assert`
50+
/// as opposed to exceptions. All other delegate class functions do not throw exceptions.
51+
///
52+
/// Github repository location:
53+
/// https://github.com/endurodave/DelegateMQ
54+
///
55+
/// See README.md, DETAILS.md, EXAMPLES.md, and source code Doxygen comments for more information.
56+
57+
#include "delegate/DelegateOpt.h"
58+
#include "delegate/MulticastDelegateSafe.h"
59+
#include "delegate/UnicastDelegate.h"
60+
#include "delegate/DelegateAsync.h"
61+
#include "delegate/DelegateAsyncWait.h"
62+
#include "delegate/DelegateRemote.h"
63+
64+
#if defined(DMQ_THREAD_STDLIB)
65+
#include "predef/os/stdlib/Thread.h"
66+
#include "predef/os/stdlib/ThreadMsg.h"
67+
#elif defined(DMQ_THREAD_FREERTOS)
68+
#include "predef/os/freertos/Thread.h"
69+
#include "predef/os/freertos/ThreadMsg.h"
70+
#elif defined(DMQ_THREAD_NONE)
71+
// Create a custom application-specific thread
72+
#else
73+
#error "Thread implemention not found."
74+
#endif
75+
76+
#if defined(DMQ_SERIALIZE_MSGPACK)
77+
#include "predef/serialize/msgpack/Serializer.h"
78+
#elif defined(DMQ_SERIALIZE_RAPIDJSON)
79+
#include "predef/serialize/rapidjson/Serializer.h"
80+
#elif defined(DMQ_SERIALIZE_SERIALIZE)
81+
#include "predef/serialize/serialize/Serializer.h"
82+
#elif defined(DMQ_SERIALIZE_NONE)
83+
// Create a custom application-sepcific serializer
84+
#else
85+
#error "Serialize implementation not found."
86+
#endif
87+
88+
#if defined(DMQ_TRANSPORT_ZEROMQ)
89+
#include "predef/dispatcher/Dispatcher.h"
90+
#include "predef/transport/zeromq/ZeroMqTransport.h"
91+
#elif defined(DMQ_TRANSPORT_WIN32_PIPE)
92+
#include "predef/dispatcher/Dispatcher.h"
93+
#include "predef/transport/win32-pipe/Win32PipeTransport.h"
94+
#elif defined(DMQ_TRANSPORT_WIN32_UDP)
95+
#include "predef/dispatcher/Dispatcher.h"
96+
#include "predef/transport/win32-udp/Win32UdpTransport.h"
97+
#elif defined(DMQ_TRANSPORT_NONE)
98+
// Create a custom application-specific transport
99+
#else
100+
#error "Transport implementation not found."
101+
#endif
102+
103+
#include "predef/util/Fault.h"
104+
#include "predef/util/Timer.h"
105+
#include "predef/util/AsyncInvoke.h"
106+
107+
#endif

0 commit comments

Comments
 (0)