C++ libubus wrapper

Felix Fietkau nbd at nbd.name
Thu Feb 4 04:32:28 EST 2021

On 2021-02-03 20:02, Wojciech Jowsa wrote:
> Hi,
> I would like to write a libubus wrapper in C++. When looking into
> ubus_method and ubus_handler_t structures I don't see a place where I
> could pass a this pointer. It makes the handling of ubus calls in C++
> a bit complicated.
> The solution to that case would be adding a void pointer to the
> ubus_method structure (like in the ubus_request struct). This way it
> would be possible to pass e.g function pointer.
> Would it be possible to add a void pointer to ubus_method structure?
> If yes then I will provide the patch asap.
I don't think a 'this' pointer should be in the ubus_method. Methods can
typically be shared between multiple ubus_objects, and the 'this'
pointer would typically go into the ubus_object.
However, even there it is not necessary to have a void pointer directly
in the struct. You can simply embed the ubus_object in another data
structure which contains the 'this' pointer (or maybe is even embedded
in the C++ object directly)

I don't write code in C++ myself, so if there's something I'm missing
here, please let me know and show me some details.

- Felix

More information about the openwrt-devel mailing list