Plugin system for text editor writen in C++ -
i creating cross platform text editor in c++. have basic base, implement features through plug-ins. but, unfortunately i'm getting in designing plug-in system. how done? can point me in right direction?
don't know if matters, i'm using wxwidgets widget kit.
you can start having base class defining specific plugin interface ie: texttransformplugin, method taking string , returning string (virtual).
each plugin inherit interface , build class eg: spanishtranslatetransformplugin in dynamic library (.so file).
from program use dlopen open library (see here c++ example). can't call class constuctor, in library define standard function (same name plugins, lets create() , give c calling conventions can use dlsym symbol , cast function returning texttransformplugin , call it.
extern "c" { texttransformplugin * create(); // return new spanishtranslatetransformplugin }
that way texttransformplugin object plugin. interface methods virtual, concrete methods called.
you have take care of lifecycle of plugin, keeping them in registry. knowing when use them, , destroying them , closing libraries.
note windows not have dlfcn.h find dlopen. there similar functionality in loadlibrary api, need abstract platforms yourself.
if use multiplatform framework qt, lot of boilerplate free , work across supported platforms. here example of pluggable paint application:
http://doc.qt.nokia.com/latest/tools-plugandpaint.html
as mentioned using wxwidgets, should equivalent functionality taking care of multiple platforms:
http://docs.wxwidgets.org/2.8/wx_wxdynamiclibrary.html , full example: http://wiki.wxwidgets.org/programs_that_support_plugins
Comments
Post a Comment