Sign in to follow this  
GanonPhantom

Seamless Plugin Design [C++]

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 this post


Link to post
Share on other sites
Quote:
Original post by GanonPhantom
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".
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 this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this