|
7 | 7 | from libcpp.vector cimport vector
|
8 | 8 | from ..utils._typedefs cimport float32_t, float64_t, intp_t, int32_t, uint32_t
|
9 | 9 |
|
| 10 | + |
| 11 | +# a simple, general purpose event broker. |
| 12 | +# |
| 13 | +# it utilizes a somewhat clunky interface built around an event handler closure |
| 14 | +# struct, as we are trying to balance generality with execution speed, and in |
| 15 | +# practice nothing's faster than simply applying a function pointer. |
| 16 | +# |
| 17 | +# the idea is we would like something like a closure for event handlers, so that |
| 18 | +# we may bind instances to instance-specific parameter values, like say you have |
| 19 | +# a "threshold" parameter and you would like threshold-dependent handler behavior, |
| 20 | +# but you want this threshold configurable at runtime. so we keep this threshold |
| 21 | +# parameter in an environment bound to a "closure" instance, which is just a struct |
| 22 | +# with a pointer to the environment instance and handler function. now vectors of |
| 23 | +# these closures are compact, fast to iterate through, and low overhead to execute. |
| 24 | +# |
| 25 | +# the idea with EventType is that you have an event broker handling a class of |
| 26 | +# conceptually related events, like suppose "server" events, and EventType would |
| 27 | +# typically be values from an enum like say: |
| 28 | +# |
| 29 | +# cdef enum ServerEvent: |
| 30 | +# SERVER_UP = 1 |
| 31 | +# SERVER_DOWN = 2 |
| 32 | +# SERVER_ON_FIRE = 3 |
| 33 | +# |
| 34 | +# an assumption of the current implementation is that these enum values are small |
| 35 | +# integers, and we use them to allocate and index into a listener vector. |
| 36 | +# |
| 37 | +# EventData is simply a pointer to whatever event payload information is relevant |
| 38 | +# to your handler, and it is expected that event_type maps to an associated handler |
| 39 | +# which knows what specific "concrete" type to cast its event_data to. |
| 40 | + |
10 | 41 | ctypedef int EventType
|
11 | 42 | ctypedef void* EventHandlerEnv
|
12 | 43 | ctypedef void* EventData
|
|
0 commit comments