I am trying to create a plugin for an IM application using C ++. The IM application is also implemented using C ++. The plugin system must support javascript plugins.
These plugins can interact with the IM application, for example, third-party developers can implement a github-robot-plugin that can send wenbhook messages to the IM application when his / her github project has any changes (it may look like Slack, with the exception of Slack, it is not a C ++ application).
I read the article Building your own plug-in structure , which implements a very simple but complete plug-in structure. He developed a plugin manager to manage the registration, creation, and destruction of any plugin. The most important thing I learned from this article is that each plugin is essentially an interface.
I implemented a bridge class that allows javascript to interact with C ++. The javascript program can provide a command and some parameters and call C ++ to perform some logical actions, although the methods provided by the bridge class. For example, using a javascript plugin, a third-party developer must provide some html resources. If you click the "Save github account information" button in html, javascript will send the "save_account_info" command to the bridge, and C ++ will save your github account information in a local database.
I am not very sure that it is a good idea to provide an interface like the following, which a third developer should do if they want to make a plugin:
class IPlugin {
public:
virtual std::string bridge_call(std::string cmd, Json params) = 0;
};
class SomePlugin : public IPlugin {
public:
virtual std::string bridge_call(std::string cmd, Json params) {
if (cmd == "some_command_1") {
} else if (cmd == "some_command_2") {
}
}
};
Any suggestion is much appreciated.