![]() |
Register | Login | |||||
![]() |
Main
| Memberlist
| Active users
| Calendar
| Chat
| Online users Ranks | FAQ | ACS | Stats | Color Chart | Search | Photo album |
![]()
| |
0 users currently in Programming. |
Acmlm's Board - I3 Archive - Programming - Which method is better for a plugin system? |
New poll | ![]() ![]() |
Add to favorites | Next newer thread | Next older thread |
Which would you suggest?READ THE POST FIRST | Method A |
50.0%, 2 votes | Method B |
|
0.0%, 0 vote | Method C |
25.0%, 1 vote | Something else (post it!) |
25.0%, 1 vote | Multi-voting is disabled. 4 users have voted.
| |
User | Post | ||
HyperHacker![]() Star Mario Finally being paid to code in VB! If only I still enjoyed that. <_< Wii #7182 6487 4198 1828 ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Since: 11-18-05 From: Canada, w00t! My computer's specs, if anyone gives a damn. STOP TRUNCATING THIS >8^( Last post: 6330 days Last view: 6330 days |
| ||
I'm just trying to decide which method I should use. Right now I have a functioning system using method A, but the disadvantages are becoming apparent. The system works like this:
Each plugin is a DLL, loaded by the main program. The program provides functions that the plugins can call, and the plugins have a callback function which is used to provide information about things that happen (the plugin being removed, settings changing, etc). Each plugin can be loaded and unloaded at will, and each has a build ID specifying what build of the program they were designed for, so that old plugins can be supported. Additionally, there is a permission system that can be used to prevent plugins from doing things like loading/unloading other plugins, creating windows, etc. This is only meant to disable unwanted behaviours or allow for buggy plugins to still be partially useable, not as a security system (since most of the functions could be done via the Windows API anyway). Method A Each plugin exports an init function which is passed a few pointers. These pointers point to an array of function pointers (the functions provided by the main program), structures containing info about each plugin (the current plugin's index in this array is also provided), and structures containing info about each window created by plugins. To create a window, a plugin calls the window-creating function, and it returns an index into the array of window structures for the window it just created. For notifications, the plugins pass the address of their callback function to a function to register it, and the callback function is called as necessary. (Right now there's a separate function for each notification, but I plan to merge it into one general-purpose function.) The plugins are compiled with a list of which function pointer does what using #define, like so: #define DoThis Functions[0] #define DoThat Functions[1] etc. (Functions is the pointer to the function pointers.) Pros: ![]() ![]() ![]() ![]() Cons: ![]() ![]() Method B Works basically like Windows. Plugins are passed only one function pointer, which points to a function that retrieves other function pointers. Plugins pass this function a name and it gets the pointer to the function it names (like Windows' GetProcAddress). Notifications are done by a callback function, but the message is a string rather than a numeric ID. Pros: ![]() ![]() ![]() ![]() ![]() Cons: ![]() ![]() ![]() Method C Entirely string-based method. Plugins are passed the pointer to a command function. To call a function, a plugin calls this command function and specifies the name and parameters in a string, like this: DoCommand("DrawString 10,30,\"Blah blah\") Or possibly like this (specifying what each parameter is): DoCommand("DrawString X=10 Y=30 Text=\"Blah blah\") Message handling would work the same way, with each message being a string specifying both its message and parameters. Pros: ![]() ![]() ![]() ![]() ![]() ![]() ![]() Cons: ![]() ![]() DrawString(xpos,ypos,text); You would have to do this: sprintf(Temp,"DrawString %d %d \"%s\"",xpos,ypos,text); DoCommand(Temp); A variable-argument method could potentially be used to call the command function, but it'd essentially be the same thing. #define may be useable to allow you to write it the first way, but it'd still be doing the second method. May be a problem if Temp is too short. ![]() Open to suggestions if anyone has any other ideas. (edited by HyperHacker on 01-11-06 11:35 PM) (edited by HyperHacker on 01-12-06 11:31 PM) |
|||
DarkPhoenix![]() Red Goomba ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Since: 12-27-05 Last post: 6334 days Last view: 6334 days |
| ||
As much as my vote tends to disagree with me (did I misclick? I'm quite sure I clicked B), Method B seems like the best compromise. Fighting to support 64-bit systems seems to me (and I may be biased from the fact that I don't use a 64-bit processor) to be overkill. The user base is too small to kill yourself over...though I guess that probably depends on what you're writing. The Windows style solution will probably be the most sane to work with if you plan on releasing newer versions every so often, or releasing the sourcecode, especially since plugin developers might not be too happy if their plugins stop functioning properly whenever you release a major update. | |||
HyperHacker![]() Star Mario Finally being paid to code in VB! If only I still enjoyed that. <_< Wii #7182 6487 4198 1828 ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Since: 11-18-05 From: Canada, w00t! My computer's specs, if anyone gives a damn. STOP TRUNCATING THIS >8^( Last post: 6330 days Last view: 6330 days |
| ||
It's small now, but I imagine it'll grow as 64-bit CPUs become cheaper and more supported. And really, I'm not concerned about people having to update their plugins to be compatible as I am with older, abandoned ones not working anymore. When I upgraded to lololol V1.5, a lot of my older extensions didn't work any more, and some of them have never and probably will never be updated to work with it. I want to avoid that. (edited by HyperHacker on 01-12-06 12:27 AM) |
|||
||bass Administrator ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Since: 11-17-05 From: Salem, Connecticut Last post: 6331 days Last view: 6329 days |
| ||
I'd just like to take a second to point out that the 64 bit version of windows creates a virtual 32 bit runtime for any win32 processes. Assuming they ran XP or Vista, anyone running the 32 bit version of your software, even on a 64 bit system would automatically be given a 32 bit runtime enviroment to run in.
Also, you could always make a translation/proxy plugin to run 32 bit plugins on the 64 bit version of your software. |
|||
HyperHacker![]() Star Mario Finally being paid to code in VB! If only I still enjoyed that. <_< Wii #7182 6487 4198 1828 ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Since: 11-18-05 From: Canada, w00t! My computer's specs, if anyone gives a damn. STOP TRUNCATING THIS >8^( Last post: 6330 days Last view: 6330 days |
| ||
I thought it would do that, but wasn't quite sure. (Guess it kinda has to. ![]() |
|||
||bass Administrator ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Since: 11-17-05 From: Salem, Connecticut Last post: 6331 days Last view: 6329 days |
| ||
Originally posted by HyperHackerYea. Somewhat surprisingly though, 16 bit windows applications no longer run. That kinda sucks because alot of GOOD older games like the origional Dr. Brain games were all 16 bit. Then again, you can always install DOSBox. |
|||
sloat![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Since: 11-18-05 From: Delaware, US Last post: 6433 days Last view: 6433 days |
| ||
I'd say keep the main program functions separate and make a plugin SDK -- an interface for the plugin to access the main program (if it really needs it). There might be a way to have the application export functions (like a dll) and use a header/library for the plugin to have access. Or if that doesn't work, you can have a message-only or otherwise hidden window in the application for the plugin to communicate with via messages.
The rest of the plugin would be a bunch of callbacks that it registers (in the init function or whatever) to specific application events. The main application would keep a linked-list of event-handlers so more than one plugin can handle the same event. When that event gets fired, the application simply walks down the chain until it reaches the end, or a plugin has asked the chain to stop. I wouldn't worry too much about 64-bit and 32-bit at the moment. Yeah, the plugin would probably have to be recompiled, but so would the application. |
|||
HyperHacker![]() Star Mario Finally being paid to code in VB! If only I still enjoyed that. <_< Wii #7182 6487 4198 1828 ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Since: 11-18-05 From: Canada, w00t! My computer's specs, if anyone gives a damn. STOP TRUNCATING THIS >8^( Last post: 6330 days Last view: 6330 days |
| ||
Well, poop... 4-way tie. ![]() Sloat, your idea sounds interesting. Basically like method B but not using strings? It could work, but it loses the advantages you get from using strings. I've thought about this a bit more and I think I could actually implement a combination of B and C. That is, B, but with a function that does string commands like C. One advantage I forgot to add to B and C (which I'll do now) is that plugins could register their own strings for easy cross-plugin communication. That is, plugin X registers the string "MakeXDoSomething". Once this is done, plugin Y can look up the address for "MakeXDoSomething", and if it exists, call it. The actual call would just pass the parameters along to plugin X in a message. BTW if it makes any difference, this program is only designed for WinXP and up, since it requires a lot of XP-only features. However I'll probably use similar systems in other programs that may be used on older OSes. (edited by HyperHacker on 01-12-06 11:29 PM) |
|||
DarkPhoenix![]() Red Goomba ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Since: 12-27-05 Last post: 6334 days Last view: 6334 days |
| ||
My apologies for screwing up your poll...
And, some more reasoning - I could be wrong about this, since I haven't thought this all through, but while it might be useful to combine multiple function calls into one string, among other things, Method C seems likely to produce a higher density of errors. Even if it's just a small syntax issue, convoluted code means more coding time and more debug time, which will likely translate into a lower quantity and quality of plugins for your app. These all might be insignificant sacrifices if plugins aren't really a huge part of the program, like if they're only used for reading/writing files. If, however, they're an integral part to the program's functionality, simplifying the code that plugin developers have to write might have a more significant effect on how well the program succeeds at its task in the long run than even the coding you do on the main program. ...I miss Dr.Brain. |
Add to favorites | Next newer thread | Next older thread |
Acmlm's Board - I3 Archive - Programming - Which method is better for a plugin system? |
![]() ![]() |