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

Allow plugins to be written in C #55

Open
phanimahesh opened this issue Mar 10, 2019 · 1 comment
Open

Allow plugins to be written in C #55

phanimahesh opened this issue Mar 10, 2019 · 1 comment
Labels
enhancement New feature or request

Comments

@phanimahesh
Copy link

Currently it looks like the only way to write plugins is to write them in c++.

Allowing plugins to be written in C opens up a lot of possibilities - not just C, but any language that can create C-ABI compatible stuff can be used for writing the plugin, and that list is huge compared to just C++. As I understand it, C++ has no well defined ABI which makes it hard to interface with it from any other language.

And since oomd calls the plugins rather than the other way around, it is not possible to simply "wrap" oomd either.

I understand that there might be limitations (I'm mostly thinking macros, and converting types) that make this non-trivial. However, is it possible? If yes, what needs to be done?

@danobi
Copy link
Contributor

danobi commented Mar 11, 2019

This sounds like a useful idea and I think it should be possible. Similar to how there's a BaseKillPlugin, I could see a BaseCPlugin providing a C interface to oomd's plugin API.

In theory the only C++ interfaces you'd need a C API for are the ones inside BasePlugin.h. There's a bunch of helper functions scattered around util/ but it's not strictly necessary to use them in plugins.

Then you could have a plugins structured like:

$ ls
MyCPlugin.c
BaseCPlugin.cpp

$ head BaseCPlugin.cpp
#include "MyCPlugin.c"

REGISTER_PLUGIN(my_c_plugin, ...)
...

$ head MyCPlugin.c
// magic function BaseCPlugin.cpp will try to use
int init(CMonitoredResources *res, CPluginArgs *args) {
  ...
}

// magic function BaseCPlugin.cpp will try to use
CPluginRet run(COomdContext *ctx) {
  ...
}

@danobi danobi added the enhancement New feature or request label Mar 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants