Recent

Author Topic: Plugin System  (Read 12340 times)

Jell0wed

  • New Member
  • *
  • Posts: 28
  • I love cookies.
Plugin System
« on: July 20, 2011, 03:56:41 pm »
Hi,

I would like to implement a plugin system for my application. I wish to place every plugin into a same dir (lets say ./plugins/). In my configuration file (which is XML based, I could specify which plugin to use and everything related to select which plugin to use)...

In each plugin, I would like to "store" a unit or some functions... and with every plugin having the same name of the function to use (let say its my function "Parse") ...

The only problem is... I don't know how to do it and how to do it in the right way...

Thanks!

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4469
  • I like bugs.
Re: Plugin System
« Reply #1 on: July 20, 2011, 05:24:17 pm »
Use shared libraries (.dll on Windows and .so on Linux etc.). You must define an API that those libraries must implement.

Another choice is some interpreted macro language integrated in your app. It can be little easier for the people creating the plugins.

Then, you must think if it makes sense to use plugins at all.
It makes sense if there are other people writing those plugins and they can't implement the features directly to your application's source code.
In relatively small applications it makes more sense to integrate all code into one binary.
Lazarus has (static) packages which are kind of plugins, but Lazarus is a rather big project.

Juha
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

Jell0wed

  • New Member
  • *
  • Posts: 28
  • I love cookies.
Re: Plugin System
« Reply #2 on: July 20, 2011, 07:23:48 pm »
Quote
Another choice is some interpreted macro language integrated in your app. It can be little easier for the people creating the plugins.

Macro language... Is it that thing with LUA script (or python I think?)
How do we integrate these little script into my source code? :O

Chronos

  • Full Member
  • ***
  • Posts: 241
    • PascalClassLibrary
Re: Plugin System
« Reply #3 on: July 20, 2011, 09:21:43 pm »
Interesting topic...

As I simply enter keywords "delphi plugin system" to google I get received immediately very useful results: http://www.google.cz/search?hl=cs&source=hp&biw=1280&bih=678&q=delphi+plugin+system&aq=f&aqi=&aql=&oq=

First result answers most of question http://stackoverflow.com/questions/365968/how-best-to-add-plugin-capability-to-a-delphi-program

Even there is link to nice tutorial on bottom of stackoverflow page http://www.uil.net/uArticles/ImplementingPluginsforyou.html for DLL plugin system

Remaining question is for which kind of application we really need plugin system instead of direct static linked code contributed by others.

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Plugin System
« Reply #4 on: July 21, 2011, 10:34:48 am »
Remaining question is for which kind of application we really need plugin system instead of direct static linked code contributed by others.
One obvious use: closed source application for which you want users to have the opportunity to write custom functionality, e.g. import/export plugins, or data processing functionality such as text processing plugins, graphics filter plugins...
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Jell0wed

  • New Member
  • *
  • Posts: 28
  • I love cookies.
Re: Plugin System
« Reply #5 on: July 21, 2011, 08:36:22 pm »
Okay, so as I read this topic, I've realised that I didn't need to implement such a plugin system... I'll write it directly into my application's source code! :)

Thanks !

garlar27

  • Hero Member
  • *****
  • Posts: 652
Re: Plugin System
« Reply #6 on: July 21, 2011, 10:54:00 pm »
Remaining question is for which kind of application we really need plugin system instead of direct static linked code contributed by others.
One obvious use: closed source application for which you want users to have the opportunity to write custom functionality, e.g. import/export plugins, or data processing functionality such as text processing plugins, graphics filter plugins...


Other use: you have your application, which can use different modules if some client want some modules and not the others.
Another one: Your modules change often because of the clients. you can build customized modules for them.

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Plugin System
« Reply #7 on: July 22, 2011, 08:02:14 am »
Exactly, garlar :) And it also decouples the main program from the plugins so you can have backward/forward compatibility.

To be hones, you could achieve this decoupling using proper object oriented design and a lot of discipline if using one single source...

(Of course, you'd also have to be disciplined not to change the plugin API, but if you have a lot of plugins out there, you'll regret changing the API if it breaks compatibility  :) )
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4469
  • I like bugs.
Re: Plugin System
« Reply #8 on: July 23, 2011, 11:26:35 am »
Plugins may sound like a good idea first. Let your "user community" extend and improve your application while the application itself remains untouched. Right...

How many projects have a user community able and willing to code such plugins?
Please remember that writing a plugin is more difficult than implementing the same in program's own code. You can't use dynamic strings in the API for example when using .dll (or .so).

To get such a user community an application must already be quite good. It has required lots of design and work then. At that point it MAYBE makes sense to provide a plugin API.
Very few open source projects make it to such level. There are hundreds of thousands of projects out there (just look at SourceForge) and most of them are doomed to oblivion. Yet, many of them have wasted their development resources for creating a plugin API.

I suggest you concentrate making your application as good as possible in its task. Then, if it becomes good it will gain users and maybe contributors.
If an application grows very popular then somebody may ask for a plugin system to maintain his extensions. Then you should implement it! In 99,9 % of cases it will never happen though.

The same rules apply for closed source SW. It needs to be big and popular before the plugins make sense.
Customization can be done without plugins by enabling and disabling some features etc.

When the first feature in a startup project is a plugin API, it is often a (subconscious) message for the "user community" to actually implement the SW, based on the idea of the author. Sorry guys but it doesn't work that way.

Juha
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Plugin System
« Reply #9 on: July 23, 2011, 11:28:53 am »
Interesting points, Juha. Having never implemented a plugin system myself, I agree with you  :)
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

 

TinyPortal © 2005-2018