Message ID | OFD613C950.3416138E-ON85258711.0041B7E9-85258711.0041B7E9@sercomm.com |
---|---|
State | New |
Headers | show |
Series | ubus: add a private field to event handlers | expand |
On 2021-07-13 13:57, Louis_Hampton@SERCOMM.COM wrote: > > This is particularly useful in multithreaded non-C FFI, where > additional context from where the event handler was registered may be > critical to ensuring the output of the event is sent to the right > location. > > Signed-off-by: Louis Hampton <louis_hampton@sercomm.com> In order to get the additional context, the normal solution is to embed struct ubus_event_handler into another data structure, which contains the extra context and can be accessed via container_of. Is there a reason why this can't be done in your code as well? - Felix
We use generated Rust bindings to libubus, and our own thread as opposed to uloop. "container_of", quite aside from not being exported, violates the strong types and memory safety rules we've previously been able to uphold. This isn't an issue with callbacks from "ubus_invoke_fd", where we can pass a pointer to some private (repr(C), for those who care) type in "priv" and pick up context from that. Since we don't have direct access to C macros at all, container_of is far from ideal. This is the first instance where it has been required. Do C++ libubus users make use of "container_of"? ~ Louis Felix Fietkau writes: > On 2021-07-13 13:57, Louis_Hampton@SERCOMM.COM wrote: >> >> This is particularly useful in multithreaded non-C FFI, where >> additional context from where the event handler was registered may be >> critical to ensuring the output of the event is sent to the right >> location. >> >> Signed-off-by: Louis Hampton <louis_hampton@sercomm.com> > In order to get the additional context, the normal solution is to embed > struct ubus_event_handler into another data structure, which contains > the extra context and can be accessed via container_of. > Is there a reason why this can't be done in your code as well? > > - Felix
diff --git a/libubus.h b/libubus.h index 6925514..e6af291 100644 --- a/libubus.h +++ b/libubus.h @@ -149,6 +149,7 @@ struct ubus_event_handler { struct ubus_object obj; ubus_event_handler_t cb; + void *priv; }; struct ubus_context {
This is particularly useful in multithreaded non-C FFI, where additional context from where the event handler was registered may be critical to ensuring the output of the event is sent to the right location. Signed-off-by: Louis Hampton <louis_hampton@sercomm.com> --- libubus.h | 1 + 1 file changed, 1 insertion(+)