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

Generate grpc_server.h/grpc_server.cpp, support selectively building plugins #1776

Merged
merged 3 commits into from
Jul 1, 2022

Conversation

julianoes
Copy link
Collaborator

@julianoes julianoes commented May 18, 2022

cmake/tools: generate grpc_server, list plugins

This is refactoring around the way the plugins are built into the mavsdk
library as well as the mavsdk_server executable.

The changes contain the following:

  • Auto-generation of grpc_server.h and grpc_server.cpp from jinja2 templates. This means that the mavsdk_server is always in sync and new plugins don't have to be added to it manually anymore.
  • As a side effects this removes the ugly rewriting of CMakeLists.txt based on the auto-generated plugins and instead uses a separate plugins.txt file that is used throughout.
  • The cmake variable ENABLED_PLUGINS can be used to manually select the plugins to be built for users requiring to do so.

To use this, the enabled plugins can be passed at configure time:

cmake -DENABLED_PLUGINS:list="action;telemetry;info;" ...

FYI @devbharat

@julianoes julianoes requested a review from JonasVautherin May 18, 2022 04:58
JonasVautherin
JonasVautherin previously approved these changes May 18, 2022
Copy link
Collaborator

@JonasVautherin JonasVautherin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Just not passing the CI (yet), but otherwise it's pretty cool 😎

builder.RegisterService(&_camera_service);
#endif

#ifdef CAMERA_SERVER_ENABLED
Copy link
Contributor

@devbharat devbharat May 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks a bit not elegant, maybe the 3 lines can be wrapped into some macro Call like REGISTER_IF_ENABLE(…) but it’s auto generated so also does not matter so much.
Or I wonder if it’s possible to somehow move it within the plugin header🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, it's not pretty but it's just auto-generated, and at least it's not out of sync like it often was in the past because someone would add a plugin and they and us maintainers would both forget to update it.

The plugin header includes are not there at all, so not sure how it would be there.

Copy link
Contributor

@devbharat devbharat May 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I agree. The only way i could imagine moving this into the plugin would be through lazy plugin somehow(or passing builder around), am not sure if that’s possible, is also rather cosmetic and not so important.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That might actually work. Any reason why builder is not a member variable? then each service could take a pointer to the builder in their constructor, and register/stop within the plugins like we do with server plugins impl. Anyways, can come in later if we want to do it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite understand how you imagine it. Feel free to make a PR or code example to show it. This can also happen later, of course.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@devbharat I think what you suggest makes sense, thanks!

@JonasVautherin can you check that change in diffy as well? You know this part of the code.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll check ASAP 👍

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks clean. Just wondering: is it fine to register a service in its own constructor?

Copy link
Contributor

@devbharat devbharat May 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was also not sure of that, but the unit test thing seems to work. Worst case we can have like a two step constructor that creates the service and registers it and then returns the object.

Perhaps not the best idea to put it directly in the constructor(they construct another service with it on the call here), although its in the body so everything else should already have been constructed.

Edit: Ah no, they just take a pointer to it, so its not 'so bad', but perhaps still better to avoid.

JonasVautherin
JonasVautherin previously approved these changes May 18, 2022
devbharat
devbharat previously approved these changes May 18, 2022
@JonasVautherin JonasVautherin dismissed stale reviews from devbharat and themself via a78a2ed May 19, 2022 08:14
This is refactoring around the way the plugins are built into the mavsdk
library as well as the mavsdk_server executable.

The changes contain the following:
- Auto-generation of grpc_server.h and grpc_server.cpp from jinja2
  templates. This means that the mavsdk_server is always in sync and
  new plugins don't have to be added to it manually anymore.
- As a side effects this removes the ugly rewriting of CMakeLists.txt
  based on the auto-generated plugins and instead uses a separate
  plugins.txt file that is used throughout.
- The cmake variable ENABLED_PLUGINS can be used to manually select the
  plugins to be built for users requiring to do so.
JonasVautherin
JonasVautherin previously approved these changes Jun 30, 2022
@julianoes julianoes merged commit b80c37b into main Jul 1, 2022
@julianoes julianoes deleted the pr-plugin-list branch July 1, 2022 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants