libGimbal 0.1.0
C17-Based Extended Standard Library and Cross-Language Runtime Framework
Loading...
Searching...
No Matches
gimbal_signal.h
Go to the documentation of this file.
1/*! \file
2 * \brief Signals, connections, and related API
3 * \ingroup signals
4 * \author Falco Girgis
5 * \copyright MIT License
6 *
7 * \todo
8 * - GBL_SIGNALS() DSL
9 * - GblSignal_next() for iteration
10 * - GblSignal_uninstallAll(GblType type)
11 */
12
13#ifndef GIMBAL_SIGNAL_H
14#define GIMBAL_SIGNAL_H
15
16#include "../types/gimbal_type.h"
17#include "../../core/gimbal_typedefs.h"
18#include "../../preprocessor/gimbal_macro_composition.h"
19#include "gimbal_closure.h"
20
21#define GBL_SIGNALS(instanceStruct, /* signals */...)
22#define GBL_SIGNALS_REGISTER(instanceStruct, /* marshals */...)
23#define GBL_EMIT(emitter, ...) (GblSignal_emit(GBL_INSTANCE(emitter), __VA_ARGS__))
24#define GBL_CONNECT(...) (GBL_VA_OVERLOAD_CALL_ARGC(GBL_CONNECT, __VA_ARGS__))
25
27
28GBL_EXPORT GBL_RESULT GblSignal_install (GblType ownerType,
29 const char* pName,
30 GblMarshalFn pFnCMarshal,
31 size_t argCount,
32 ...) GBL_NOEXCEPT;
33
34GBL_EXPORT GBL_RESULT GblSignal_uninstall (GblType ownerType,
35 const char* pName) GBL_NOEXCEPT;
36
37GBL_EXPORT GBL_RESULT GblSignal_uninstallAll (GblType ownerType) GBL_NOEXCEPT;
38
39GBL_EXPORT GBL_RESULT GblSignal_connect (GblInstance* pEmitter,
40 const char* pSignalName,
41 GblInstance* pReceiver,
42 GblFnPtr pFnCCallback,
43 void* pUserdata) GBL_NOEXCEPT;
44
45GBL_EXPORT GBL_RESULT GblSignal_connectClass (GblInstance* pEmitter,
46 const char* pSignalName,
47 GblInstance* pReceiver,
48 GblType classType,
49 size_t methodOffset) GBL_NOEXCEPT;
50
51GBL_EXPORT GBL_RESULT GblSignal_connectSignal (GblInstance* pEmitter,
52 const char* pSignalName,
53 GblInstance* pDstEmitter,
54 const char* pDstSignalName) GBL_NOEXCEPT;
55
56GBL_EXPORT GBL_RESULT GblSignal_connectClosure (GblInstance* pEmitter,
57 const char* pSignalName,
58 GblInstance* pReceiver,
59 GblClosure* pClosure) GBL_NOEXCEPT;
60
61GBL_EXPORT size_t GblSignal_disconnect (GblInstance* pEmitter,
62 const char* pSignalName,
63 GblInstance* pReceiver,
64 GblClosure* pClosure) GBL_NOEXCEPT;
65
66GBL_EXPORT GblBool GblSignal_block (GblInstance* pInstance,
67 const char* pSignalName,
68 GblBool blocked) GBL_NOEXCEPT;
69
70GBL_EXPORT GblBool GblSignal_blockAll (GblInstance* pInstance,
71 GblBool blocked) GBL_NOEXCEPT;
72
73GBL_EXPORT size_t GblSignal_connectionCount (GblInstance* pInstance,
74 const char* pSignalName) GBL_NOEXCEPT;
75
76GBL_EXPORT GBL_RESULT GblSignal_emit (GblInstance* pEmitter,
77 const char* pSignalName,
78 ...) GBL_NOEXCEPT;
79
80GBL_EXPORT GBL_RESULT GblSignal_emitVaList (GblInstance* pEmitter,
81 const char* pSignalName,
82 va_list* pVarArgs) GBL_NOEXCEPT;
83
84GBL_EXPORT GBL_RESULT GblSignal_emitVariants (GblInstance* pEmitter,
85 const char* pSignalName,
86 GblVariant* pArgs) GBL_NOEXCEPT;
87
88GBL_EXPORT GblInstance* GblSignal_emitter (void) GBL_NOEXCEPT;
89
90GBL_EXPORT GblInstance* GblSignal_receiver (void) GBL_NOEXCEPT;
91
92#define GblSignal_connect(...) GBL_VA_OVERLOAD_CALL_ARGC(GblSignal_connect, __VA_ARGS__)
93
94// ===== IMPLEMENTATION =====
95
96///\cond
97#define GblSignal_connect_3(emitter, signal, callback)
98 (GblSignal_connect_4(emitter, signal, emitter, callback))
99#define GblSignal_connect_4(emitter, signal, receiver, callback)
100 (GblSignal_connect_5(emitter, signal, receiver, callback, GBL_NULL))
101#define GblSignal_connect_5(emitter, signal, receiver, callback, userdata)
102 ((GblSignal_connect)(emitter, signal, receiver, callback, userdata))
103
104#define GBL_CONNECT_3(emitter, signal, callback)
105 (GBL_CONNECT_4(emitter, signal, emitter, callback))
106#define GBL_CONNECT_4(emitter, signal, receiver, callback)
107 (GBL_CONNECT_5(emitter, signal, receiver, callback, GBL_NULL))
108#define GBL_CONNECT_5(emitter, signal, receiver, callback, userdata)
109 ((GblSignal_connect)(GBL_INSTANCE(emitter), signal, GBL_INSTANCE(receiver), GBL_CALLBACK(callback), (void*)userdata))
110
111#define GBL_SIGNALS_(instance, ...)
112 GBL_INLINE GBL_RESULT instance##_registerSignals_(instance* pSelf, GblMarshalFn* pMarshals) {
113 GBL_UNUSED(pSelf, pMarshals);
114 GBL_CTX_BEGIN(NULL);
115 GBL_TUPLE_FOREACH(GBL_SIGNAL_INSTALL_, instance, (__VA_ARGS__))
116 GBL_CTX_END();
117 }
118
119
120#define GBL_SIGNAL_INSTALL_(instance, signal)
121
122#if 0
123GBL_CTX_VERIFY_CALL(GblSignal_install(GBL_TYPEID(instance),
124 GBL_STRINGIFY(GBL_TUPLE_FIRST signal),
125 pMarshals++,
126 GBL_NARG signal - 1,
127 GBL_TUPLE_FOREACH(GBL_SIGNAL_ARG_TYPE_, instance, GBL_TUPLE_REST(signal) )));
128#endif
129
130#define GBL_SIGNAL_ARG_TYPE_(instance, pair)
131 GBL_TUPLE_FIRST(pair),
132
133#define GBL_SIGNALS_REGISTER_(instance, marshals)
134 instance##_registerSignals_(instance, marshals)
135///\endcond
136
138
139#endif // GIMBAL_SIGNAL_H
#define GBL_CALLBACK(fn)
Casts a C function pointer to a generic callback type.
#define GBL_NULL
#define GBL_NOEXCEPT
#define GBL_INLINE
#define GBL_CTX_BEGIN(...)
Definition gimbal_ctx.h:561
#define GBL_CTX_END()
Definition gimbal_ctx.h:574
#define GBL_DECLS_BEGIN
#define GBL_UNUSED(...)
#define GBL_EXPORT
#define GBL_INSTANCE(self)
Casts GblInstance-compatible to GblInstance.
#define GBL_TUPLE_FIRST(...)
#define GBL_TUPLE_FOREACH(MACRO_, DATA_, TUPLE_)
#define GBL_VA_OVERLOAD_CALL_ARGC(BASE,...)
#define GblSignal_connect(...)
#define GBL_CONNECT(...)
void(* GblFnPtr)()
Type used for holding an untyped function pointer.
uint8_t GblBool
Basic boolean type, standardized to sizeof(char)
uintptr_t GblType
Meta Type UUID.
Definition gimbal_type.h:51