gplug (general plugin management library) is a general plugin management library.
gplug is used for unified management of plugins in applications. It is responsible for loading, initializing, deinitializing, and unloading individual plugins, and supports adding and removing plugins at runtime.
gplug is designed to separate the plug-in interface from the user function interface. The plugin manager obtains the plugin function interface through the plugin specification interface, and then can directly interact with the plugin.
There are three main parts in gplug: plugin, plugin manager, and plugin configuration file.
Each plugin is identified by a unique ID (file key), and the plugin must implement an interface that conforms to the plugin specification.
The plugin manager uses a configuration file to manage the plugins in a unified manner. The configuration file contains parameters such as FileKey , delay loading.
The plugin manager initializes the corresponding plugin according to the file ID (FileKey), obtains the pointer of the plugin function interface function according to the function ID (InterfaceKey), and calls the function interface of different plugins.
gplug documentation is generated using Doxygen.
The interface is divided into two parts, the plugin manager interface and the plugin specification interface.
A plugin needs to implement the plugin interface, and the application program calls the plugin manager interface to implement plugin management.
The process of developing is as follows:
Define the plugin functional interface ↓ Implement the plugin function interface ↓ Export plugin unified interface ↓ Create configuration file ↓ Use the PlugMgr interface to call the Plugin function interface
This is an example of developing a plugin according to the flow.
Check out more examples here.
- Clone the repository
git clone https://gitee.com/QWorkShop/gplug.git
-
Generate the necessary build files
In this step, the third-party library will be cloned.
cd EVHttpServer
cmake -B build -S . -DCMAKE_INSTALL_PREFIX=/path/to/install -DCMAKE_BUILD_TYPE=Release
- Compile the source code. In this step, third-party libraries, gplug library, samples, tests will be compiled.
cmake --build build
- Install to system
cmake --install build
Now you can use the gplug library, include the header file in the code, link the gplug library when compiling.