Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add macro to teach sdbus-c++ about user-defined structs #440

Merged
merged 1 commit into from
May 6, 2024

Conversation

sangelovic
Copy link
Collaborator

@sangelovic sangelovic commented Apr 30, 2024

This introduces SDBUSCPP_REGISTER_STRUCT() macro that helps clients conveniently, in one line, teach sdbus-c++ to recognize and accept their custom C++ struct types wherever D-Bus structs are expected in a D-Bus API.

The macro saves some boilerplate that would otherwise be needed on client side for every registered struct.

@sangelovic sangelovic marked this pull request as ready for review April 30, 2024 15:05
@sangelovic
Copy link
Collaborator Author

@hellow554 I prepared a macro that avoids the boilerplate and registers a struct in sdbus-c++ as a one-liner. E.g. SDBUSCPP_REGISTER_STRUCT(PersonData, name, surname, age, address);. Have a look into this MR. Does it look attractive to you? :-)

It supports up to 16 struct members currently. Is that enough for you?

@hellow554
Copy link
Contributor

That really looks good. Thanks a lot for that :)

It supports up to 16 struct members currently. Is that enough for you?

I guess?
You could add something like this maybe?

#define SDBUSCPP_REGISTER_STRUCT(struct, ...)  \
  #error "Not more than 16 Parameters are supported, please open an issue if you would like to see this feature"

Not sure if that's possible thought...

@sangelovic sangelovic force-pushed the feat/struct-macro branch 2 times, most recently from 95aa6bf to 180e9f5 Compare May 6, 2024 17:54
@sangelovic
Copy link
Collaborator Author

@hellow554 It's not possible AFAIK. I've added a static assert that checks that the count of arguments if less or equal to 16, but it only works nicely (i.e. the compilation stops there showing directly the accompanying message) if there is not more than 32 arguments. Otherwise the number expands to one of the struct member names, leading to wrong syntax, which stops the compilation with a slightly different message, but at least in my compiler the 3rd link in the error message points to the static assert code (because that's where there is an undefined symbol), so after some digging clients can figure out the cause of the compilation failure.

@sangelovic sangelovic merged commit 14942db into master May 6, 2024
6 checks passed
@sangelovic sangelovic deleted the feat/struct-macro branch May 6, 2024 18:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants