facebookincubator/oomd

Allow plugins to be written in C

phanimahesh opened this issue · 1 comments

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?

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) {
  ...
}