PyEventEngine 0.6.0.post3__cp312-cp312-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. event_engine/__infra__.pxd +2 -0
  2. event_engine/__init__.pxd +2 -0
  3. event_engine/__init__.py +37 -0
  4. event_engine/base/__infra__.pxd +9 -0
  5. event_engine/base/__init__.pxd +9 -0
  6. event_engine/base/__init__.py +82 -0
  7. event_engine/base/c_allocator_protocol.c +10817 -0
  8. event_engine/base/c_allocator_protocol.cp312-win_amd64.pyd +0 -0
  9. event_engine/base/c_allocator_protocol.h +23 -0
  10. event_engine/base/c_allocator_protocol.pxd +31 -0
  11. event_engine/base/c_allocator_protocol.pyx +99 -0
  12. event_engine/capi/__infra__.pxd +189 -0
  13. event_engine/capi/__init__.pxd +189 -0
  14. event_engine/capi/__init__.py +84 -0
  15. event_engine/capi/c_engine.c +28711 -0
  16. event_engine/capi/c_engine.cp312-win_amd64.pyd +0 -0
  17. event_engine/capi/c_engine.h +393 -0
  18. event_engine/capi/c_engine.pxd +84 -0
  19. event_engine/capi/c_engine.pyi +424 -0
  20. event_engine/capi/c_engine.pyx +560 -0
  21. event_engine/capi/c_event.c +19921 -0
  22. event_engine/capi/c_event.cp312-win_amd64.pyd +0 -0
  23. event_engine/capi/c_event.h +342 -0
  24. event_engine/capi/c_event.pxd +159 -0
  25. event_engine/capi/c_event.pyi +226 -0
  26. event_engine/capi/c_event.pyx +387 -0
  27. event_engine/capi/c_topic.c +30978 -0
  28. event_engine/capi/c_topic.cp312-win_amd64.pyd +0 -0
  29. event_engine/capi/c_topic.h +1007 -0
  30. event_engine/capi/c_topic.pxd +147 -0
  31. event_engine/capi/c_topic.pyi +580 -0
  32. event_engine/capi/c_topic.pyx +725 -0
  33. event_engine/capi/fallback_engine.py +670 -0
  34. event_engine/includes/event_engine/base/c_allocator_protocol.c +10817 -0
  35. event_engine/includes/event_engine/base/c_allocator_protocol.h +23 -0
  36. event_engine/includes/event_engine/capi/c_engine.c +28711 -0
  37. event_engine/includes/event_engine/capi/c_engine.h +393 -0
  38. event_engine/includes/event_engine/capi/c_event.c +19921 -0
  39. event_engine/includes/event_engine/capi/c_event.h +342 -0
  40. event_engine/includes/event_engine/capi/c_topic.c +30978 -0
  41. event_engine/includes/event_engine/capi/c_topic.h +1007 -0
  42. event_engine/native/__init__.py +60 -0
  43. event_engine/native/_event.py +420 -0
  44. event_engine/native/_topic.py +171 -0
  45. event_engine/native/engine.py +746 -0
  46. event_engine/native/event.py +467 -0
  47. event_engine/native/topic.py +945 -0
  48. pyeventengine-0.6.0.post3.dist-info/METADATA +189 -0
  49. pyeventengine-0.6.0.post3.dist-info/RECORD +52 -0
  50. pyeventengine-0.6.0.post3.dist-info/WHEEL +5 -0
  51. pyeventengine-0.6.0.post3.dist-info/licenses/LICENSE +21 -0
  52. pyeventengine-0.6.0.post3.dist-info/top_level.txt +1 -0
@@ -0,0 +1,342 @@
1
+ #ifndef C_EVENT_H
2
+ #define C_EVENT_H
3
+
4
+ #include <stdint.h>
5
+ #include <stdlib.h>
6
+
7
+ #include <cbase/allocator_protocol/c_allocator_protocol.h>
8
+ #include <event_engine/capi/c_topic.h>
9
+
10
+ /* @brief Message payload stored in the queue
11
+ *
12
+ * This structure holds the message data along with optional
13
+ * metadata such as topic pointer, Python-compatible args/kwargs,
14
+ * and a sequence identifier.
15
+ */
16
+ typedef struct evt_message_payload {
17
+ void* args; // optional user data pointer
18
+ evt_topic* topic; // optional Topic borrowed pointer
19
+ uint64_t seq_id; // optional sequence id (0 if unused)
20
+ } evt_message_payload;
21
+
22
+ typedef void (*evt_callback_bare)(void);
23
+
24
+ typedef void (*evt_callback_with_args)(void* args);
25
+
26
+ typedef void (*evt_callback_with_topic)(evt_topic* topic);
27
+
28
+ typedef void (*evt_callback_with_userdata)(void* user_data);
29
+
30
+ typedef void (*evt_callback_with_args_topic)(void* args, evt_topic* topic);
31
+
32
+ typedef void (*evt_callback_with_args_userdata)(void* args, void* user_data);
33
+
34
+ typedef void (*evt_callback_with_topic_userdata)(evt_topic* topic, void* user_data);
35
+
36
+ typedef void (*evt_callback_with_args_topic_userdata)(void* args, evt_topic* topic, void* user_data);
37
+
38
+ typedef void (*evt_callback_with_payload)(evt_message_payload* payload);
39
+
40
+ typedef void (*evt_callback_with_payload_userdata)(evt_message_payload* payload, void* user_data);
41
+
42
+ // clang-format off
43
+
44
+ typedef enum evt_callback_type {
45
+ EVT_CALLBACK_BARE = 0,
46
+ EVT_CALLBACK_WITH_ARGS = 1,
47
+ EVT_CALLBACK_WITH_TOPIC = 2,
48
+ EVT_CALLBACK_WITH_USERDATA = 4,
49
+ EVT_CALLBACK_WITH_ARGS_TOPIC = 3,
50
+ EVT_CALLBACK_WITH_ARGS_USERDATA = 5,
51
+ EVT_CALLBACK_WITH_TOPIC_USERDATA = 6,
52
+ EVT_CALLBACK_WITH_ARGS_TOPIC_USERDATA = 7,
53
+ EVT_CALLBACK_WITH_PAYLOAD = 8,
54
+ EVT_CALLBACK_WITH_PAYLOAD_USERDATA = 12,
55
+ } evt_callback_type;
56
+
57
+ typedef union evt_callback_variants {
58
+ evt_callback_bare bare;
59
+ evt_callback_with_args with_args;
60
+ evt_callback_with_topic with_topic;
61
+ evt_callback_with_userdata with_userdata;
62
+ evt_callback_with_args_topic with_args_topic;
63
+ evt_callback_with_args_userdata with_args_userdata;
64
+ evt_callback_with_topic_userdata with_topic_userdata;
65
+ evt_callback_with_args_topic_userdata with_args_topic_userdata;
66
+ evt_callback_with_payload with_payload;
67
+ evt_callback_with_payload_userdata with_payload_userdata;
68
+ } evt_callback_variants;
69
+
70
+ // clang-format on
71
+
72
+ typedef struct evt_callback {
73
+ evt_callback_type type;
74
+ evt_callback_variants fn;
75
+ void* user_data;
76
+ } evt_callback;
77
+
78
+ typedef enum evt_hook_watcher_type {
79
+ EVT_HOOK_WATCHER_PRE_INVOKED = 0,
80
+ EVT_HOOK_WATCHER_POST_INVOKED = 1,
81
+ } evt_hook_watcher_type;
82
+
83
+ typedef struct evt_hook evt_hook;
84
+
85
+ typedef void (*evt_hook_watcher_fn)(evt_hook* hook, evt_hook_watcher_type watcher_type, evt_message_payload* payload, void* user_data);
86
+
87
+ typedef struct evt_hook_watcher {
88
+ evt_hook_watcher_fn fn;
89
+ void* user_data;
90
+ } evt_hook_watcher;
91
+
92
+ typedef enum evt_hook_ret_code {
93
+ EVT_HOOK_OK = 0,
94
+ EVT_HOOK_ERR_INVALID_INPUT = -1,
95
+ EVT_HOOK_ERR_OOM = -2,
96
+ EVT_HOOK_ERR_DUPLICATE = -3,
97
+ } evt_hook_ret_code;
98
+
99
+ typedef struct evt_hook {
100
+ evt_topic* topic;
101
+ evt_callback* callbacks;
102
+ size_t n_callbacks;
103
+ evt_hook_watcher* pre_watchers;
104
+ size_t n_pre_watchers;
105
+ evt_hook_watcher* post_watchers;
106
+ size_t n_post_watchers;
107
+ } evt_hook;
108
+
109
+ static inline void c_evt_callback_invoke(const evt_callback* callback, evt_message_payload* payload) {
110
+ if (!callback) return;
111
+ void* args = payload ? payload->args : NULL;
112
+ evt_topic* topic = payload ? payload->topic : NULL;
113
+ void* user_data = callback->user_data;
114
+
115
+ switch (callback->type) {
116
+ case EVT_CALLBACK_WITH_PAYLOAD_USERDATA:
117
+ if (callback->fn.with_payload_userdata) callback->fn.with_payload_userdata(payload, user_data);
118
+ break;
119
+ case EVT_CALLBACK_WITH_PAYLOAD:
120
+ if (callback->fn.with_payload) callback->fn.with_payload(payload);
121
+ break;
122
+ case EVT_CALLBACK_WITH_ARGS_TOPIC_USERDATA:
123
+ if (callback->fn.with_args_topic_userdata) callback->fn.with_args_topic_userdata(args, topic, user_data);
124
+ break;
125
+ case EVT_CALLBACK_WITH_TOPIC_USERDATA:
126
+ if (callback->fn.with_topic_userdata) callback->fn.with_topic_userdata(topic, user_data);
127
+ break;
128
+ case EVT_CALLBACK_WITH_ARGS_USERDATA:
129
+ if (callback->fn.with_args_userdata) callback->fn.with_args_userdata(args, user_data);
130
+ break;
131
+ case EVT_CALLBACK_WITH_ARGS_TOPIC:
132
+ if (callback->fn.with_args_topic) callback->fn.with_args_topic(args, topic);
133
+ break;
134
+ case EVT_CALLBACK_WITH_TOPIC:
135
+ if (callback->fn.with_topic) callback->fn.with_topic(topic);
136
+ break;
137
+ case EVT_CALLBACK_WITH_ARGS:
138
+ if (callback->fn.with_args) callback->fn.with_args(args);
139
+ break;
140
+ case EVT_CALLBACK_WITH_USERDATA:
141
+ if (callback->fn.with_userdata) callback->fn.with_userdata(user_data);
142
+ break;
143
+ case EVT_CALLBACK_BARE:
144
+ if (callback->fn.bare) callback->fn.bare();
145
+ break;
146
+ default:
147
+ break;
148
+ }
149
+ }
150
+
151
+ static inline evt_hook* c_evt_hook_new(evt_topic* topic, allocator_protocol* allocator) {
152
+ evt_hook* hook = (evt_hook*) c_ap_alloc(sizeof(evt_hook), allocator);
153
+ if (!hook) return NULL;
154
+
155
+ hook->topic = topic;
156
+ hook->callbacks = NULL;
157
+ hook->n_callbacks = 0;
158
+ hook->pre_watchers = NULL;
159
+ hook->n_pre_watchers = 0;
160
+ hook->post_watchers = NULL;
161
+ hook->n_post_watchers = 0;
162
+ return hook;
163
+ }
164
+
165
+ static inline void c_evt_hook_free(evt_hook* hook) {
166
+ if (!hook) return;
167
+ if (hook->callbacks) free(hook->callbacks);
168
+ if (hook->pre_watchers) free(hook->pre_watchers);
169
+ if (hook->post_watchers) free(hook->post_watchers);
170
+ c_ap_free(hook);
171
+ }
172
+
173
+ static inline int c_evt_hook_add_watcher(evt_hook* hook, evt_hook_watcher_fn fn, void* user_data, evt_hook_watcher_type type) {
174
+ if (!hook || !fn) return EVT_HOOK_ERR_INVALID_INPUT;
175
+
176
+ if (type == EVT_HOOK_WATCHER_PRE_INVOKED) {
177
+ const size_t new_count = hook->n_pre_watchers + 1;
178
+ evt_hook_watcher* grown = (evt_hook_watcher*) realloc(hook->pre_watchers, new_count * sizeof(evt_hook_watcher));
179
+ if (!grown) return EVT_HOOK_ERR_OOM;
180
+ hook->pre_watchers = grown;
181
+ hook->pre_watchers[hook->n_pre_watchers].fn = fn;
182
+ hook->pre_watchers[hook->n_pre_watchers].user_data = user_data;
183
+ hook->n_pre_watchers = new_count;
184
+ return EVT_HOOK_OK;
185
+ }
186
+ else if (type == EVT_HOOK_WATCHER_POST_INVOKED) {
187
+ const size_t new_count = hook->n_post_watchers + 1;
188
+ evt_hook_watcher* grown = (evt_hook_watcher*) realloc(hook->post_watchers, new_count * sizeof(evt_hook_watcher));
189
+ if (!grown) return EVT_HOOK_ERR_OOM;
190
+ hook->post_watchers = grown;
191
+ hook->post_watchers[hook->n_post_watchers].fn = fn;
192
+ hook->post_watchers[hook->n_post_watchers].user_data = user_data;
193
+ hook->n_post_watchers = new_count;
194
+ return EVT_HOOK_OK;
195
+ }
196
+ return EVT_HOOK_ERR_INVALID_INPUT;
197
+ }
198
+
199
+ static inline int c_evt_hook_register_callback(evt_hook* hook, const void* fn, evt_callback_type ftype, void* user_data, int deduplicate) {
200
+ if (!hook || !fn) return EVT_HOOK_ERR_INVALID_INPUT;
201
+
202
+ /* Deduplication check: compare function pointer and type */
203
+ if (hook->callbacks && deduplicate) {
204
+ for (size_t i = 0; i < hook->n_callbacks; ++i) {
205
+ const evt_callback* callback = &hook->callbacks[i];
206
+ if (callback->type != ftype) continue;
207
+ const void* existing = NULL;
208
+ switch (callback->type) {
209
+ case EVT_CALLBACK_WITH_TOPIC:
210
+ existing = (const void*) callback->fn.with_topic;
211
+ break;
212
+ case EVT_CALLBACK_WITH_ARGS:
213
+ existing = (const void*) callback->fn.with_args;
214
+ break;
215
+ case EVT_CALLBACK_WITH_USERDATA:
216
+ existing = (const void*) callback->fn.with_userdata;
217
+ break;
218
+ case EVT_CALLBACK_WITH_ARGS_TOPIC:
219
+ existing = (const void*) callback->fn.with_args_topic;
220
+ break;
221
+ case EVT_CALLBACK_WITH_ARGS_USERDATA:
222
+ existing = (const void*) callback->fn.with_args_userdata;
223
+ break;
224
+ case EVT_CALLBACK_WITH_TOPIC_USERDATA:
225
+ existing = (const void*) callback->fn.with_topic_userdata;
226
+ break;
227
+ case EVT_CALLBACK_WITH_ARGS_TOPIC_USERDATA:
228
+ existing = (const void*) callback->fn.with_args_topic_userdata;
229
+ break;
230
+ case EVT_CALLBACK_WITH_PAYLOAD:
231
+ existing = (const void*) callback->fn.with_payload;
232
+ break;
233
+ case EVT_CALLBACK_WITH_PAYLOAD_USERDATA:
234
+ existing = (const void*) callback->fn.with_payload_userdata;
235
+ break;
236
+ case EVT_CALLBACK_BARE:
237
+ existing = (const void*) callback->fn.bare;
238
+ break;
239
+ default:
240
+ break;
241
+ }
242
+ if (existing == fn && callback->user_data == user_data) {
243
+ return EVT_HOOK_ERR_DUPLICATE; /* duplicate ignored */
244
+ }
245
+ }
246
+ }
247
+
248
+ const size_t new_count = hook->n_callbacks + 1;
249
+ evt_callback* grown = (evt_callback*) realloc(hook->callbacks, new_count * sizeof(evt_callback));
250
+ if (!grown) return EVT_HOOK_ERR_OOM;
251
+ hook->callbacks = grown;
252
+
253
+ evt_callback* cb = hook->callbacks + hook->n_callbacks;
254
+ cb->type = ftype;
255
+ cb->user_data = user_data;
256
+
257
+ switch (ftype) {
258
+ case EVT_CALLBACK_WITH_TOPIC:
259
+ cb->fn.with_topic = (evt_callback_with_topic) fn;
260
+ break;
261
+ case EVT_CALLBACK_WITH_ARGS:
262
+ cb->fn.with_args = (evt_callback_with_args) fn;
263
+ break;
264
+ case EVT_CALLBACK_WITH_USERDATA:
265
+ cb->fn.with_userdata = (evt_callback_with_userdata) fn;
266
+ break;
267
+ case EVT_CALLBACK_WITH_ARGS_TOPIC:
268
+ cb->fn.with_args_topic = (evt_callback_with_args_topic) fn;
269
+ break;
270
+ case EVT_CALLBACK_WITH_ARGS_USERDATA:
271
+ cb->fn.with_args_userdata = (evt_callback_with_args_userdata) fn;
272
+ break;
273
+ case EVT_CALLBACK_WITH_TOPIC_USERDATA:
274
+ cb->fn.with_topic_userdata = (evt_callback_with_topic_userdata) fn;
275
+ break;
276
+ case EVT_CALLBACK_WITH_ARGS_TOPIC_USERDATA:
277
+ cb->fn.with_args_topic_userdata = (evt_callback_with_args_topic_userdata) fn;
278
+ break;
279
+ case EVT_CALLBACK_WITH_PAYLOAD:
280
+ cb->fn.with_payload = (evt_callback_with_payload) fn;
281
+ break;
282
+ case EVT_CALLBACK_WITH_PAYLOAD_USERDATA:
283
+ cb->fn.with_payload_userdata = (evt_callback_with_payload_userdata) fn;
284
+ break;
285
+ case EVT_CALLBACK_BARE:
286
+ cb->fn.bare = (evt_callback_bare) fn;
287
+ break;
288
+ default:
289
+ cb->fn.bare = NULL;
290
+ break;
291
+ }
292
+
293
+ hook->n_callbacks = new_count;
294
+ return EVT_HOOK_OK;
295
+ }
296
+
297
+ static inline int c_evt_hook_pop_callback(evt_hook* hook, size_t idx) {
298
+ if (!hook) return EVT_HOOK_ERR_INVALID_INPUT;
299
+ if (idx >= hook->n_callbacks) return EVT_HOOK_ERR_INVALID_INPUT;
300
+
301
+ /* shift left to fill the gap */
302
+ for (size_t i = idx + 1; i < hook->n_callbacks; ++i) {
303
+ hook->callbacks[i - 1] = hook->callbacks[i];
304
+ }
305
+
306
+ hook->n_callbacks -= 1;
307
+
308
+ if (hook->n_callbacks == 0) {
309
+ free(hook->callbacks);
310
+ hook->callbacks = NULL;
311
+ }
312
+ else {
313
+ /* optional shrink; ignore failure to avoid losing callbacks */
314
+ evt_callback* shrunk = (evt_callback*) realloc(hook->callbacks, hook->n_callbacks * sizeof(evt_callback));
315
+ if (shrunk) hook->callbacks = shrunk;
316
+ }
317
+
318
+ return EVT_HOOK_OK;
319
+ }
320
+
321
+ static inline int c_evt_hook_invoke(evt_hook* hook, evt_message_payload* payload) {
322
+ if (!hook) return EVT_HOOK_ERR_INVALID_INPUT;
323
+
324
+ evt_hook_watcher* watcher = hook->pre_watchers;
325
+ for (size_t i = 0; i < hook->n_pre_watchers; ++i) {
326
+ watcher->fn(hook, EVT_HOOK_WATCHER_PRE_INVOKED, payload, watcher->user_data);
327
+ watcher++;
328
+ }
329
+
330
+ for (size_t i = 0; i < hook->n_callbacks; ++i) {
331
+ c_evt_callback_invoke(&hook->callbacks[i], payload);
332
+ }
333
+
334
+ watcher = hook->post_watchers;
335
+ for (size_t i = 0; i < hook->n_post_watchers; ++i) {
336
+ watcher->fn(hook, EVT_HOOK_WATCHER_POST_INVOKED, payload, watcher->user_data);
337
+ watcher++;
338
+ }
339
+ return EVT_HOOK_OK;
340
+ }
341
+
342
+ #endif /* C_EVENT_H */