|
| 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