# Seamless Plugin Design [C++]

This topic is 3425 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Im currently working on the "plugin" part of my engine, and im trying to create a system that is "seamless". What i mean by that, is make it as easy as possible to integrate and replace plugins without having to reconfigure alot of things. Currently, the plan is to have a Plugin Manager, which on startup, will load specified Plugins, that are declared in a .cfg file. What i think i wanna do here is have it load all plugins in a plugin folder, and check for collisions of old version, and same-type plugins (such as, you cant have 2 socket plugins in the folder at the same time). The current problem im running into is instancing classes. Because i have to call from the manager Manager.CreatePlugin("Socket");, to get the current socket plugin that is loaded, which is a pain, because in a server, you have to create Sockets all the time. The plugin system needs to be multi-platform, so i cant use _declspec(import), but instead i use an interface, and in the DLL/SO i have the class implimentation with a CreatePlugin function in the DLL. So the real problem is, how can i instance a new plugin without having to call Manager.CreatePlugin("Socket") all the time, and instead do something that is more generalize like "new". Thanks, GanonPhantom

##### Share on other sites
Quote:
 Original post by GanonPhantomSo the real problem is, how can i instance a new plugin without having to call Manager.CreatePlugin("Socket") all the time, and instead do something that is more generalize like "new".
You can wrap that factory call in a function:
Socket *newSocket() {	return dynamic_cast<Socket *>( manager.createPlugin("Socket") );}
although this does require the manager to be globally accessible. I don't really see anything wrong with your initial approach though, it is a very common design pattern known as a factory.

##### Share on other sites
What I did with my GUI was use function pointers, I load the addresses from the functions on the DLL at start up and then just call the pointers as I would a normal function during runtime, I use a C API though.