TGI has asked for the wisdom of the Perl Monks concerning the following question:

I've got an application that has been growing bigger and more complex over the last few years. Lately, we've developed the desire to allow our customers to add functionality via a plugin interface.

The basic goals are:

The approach that comes to mind is to use either shared libraries or executables with a predefined interface.

If I use libraries, can I create an XS or Inline::C style interface that will let me talk to multiple different libraries?

If I use separate executables, what should I be considering for passing data and commands between application and the plugins?

I'm looking for general thoughts and leaders to further research. Any pointers would be greatly appreciated.


TGI says moo

Replies are listed 'Best First'.
Re: Cross platform, multilanguage plugins
by Joost (Canon) on Feb 13, 2007 at 22:46 UTC
    What kind of application are we talking about? Especially, what kind of operations should the plugins be able to do? Should plugins have their own GUI, be integrated into the main app's GUI or don't they have a GUI at all?

    Plugins can be written in many languages - Perl, C, VB, Python, etc.
    This suggests you either want a C-level interface (i.e. a dynamic library) or some kind of language independent interface (preferably text based - I might even go for XML)

    If you go for a shared library, you might want to consider SWIG, since you can use it to build a single C interface and generate wrappers for different languages including perl, python and C#.

    The mechanism should work on both unix and Windows systems.
    Do you also want to have plugins running on remote machines?

    I think I'd go with either a C library based interface for complex/dynamic systems, or some kind of XML "filter" system for "single shot" plugins: App -> XML out -> pipe into plugin -> xml response -> read back.

      The application (written in perl) is used for environmental monitoring.

      The two sorts of plugins we have discussed would

      • Define new data fields that are calculated based on existing data. For example if you have air temperature and humidity, but want a dew point field, you can write a dew point plugin, install it and then any sensors that can provide the required fields will magically also provide dewpoint.
      • Define an action. The app has the ability to trigger a notification if certain events occur. Right now we only offer one common behavior. We would like to allow our customers to create additional behaviors. For example, an action might be "Send SMS Message". Actions would need to have some UI associated with them.

      The two types of plugins need not operate in the same way, as long as they are easy to install.

      Plugins only need to run on the same machine as is hosting the main application.

      The basic flow of execution would be:

      1. App collects data from sensor
      2. App calculates any custom fields from field plugins
      3. App checks for any conditions that would cause an alert
      4. If an alert occurs do any actions associated with the alert.

      Worst case, we will be dealing with data collection occuring at most tens of times an hour across hundreds of sensors with tens of fields each. Depending on the connection type, it can take as little as 2 seconds to get data from a sensor, or as much as 2 minutes.

      Thanks for the ideas.


      TGI says moo

Re: Cross platform, multilanguage plugins
by jdporter (Paladin) on Feb 14, 2007 at 13:01 UTC

    Given your description, I'd opt for stand-alone external executables and a well-defined command-line interface.

    One such standard is CGI. I've never heard of it being used by anything other than a web server, but there's no reason it couldn't be. And it's very well supported in all languages.

    Another possibility is SOAP. I haven't heard of it being used in this way (fork a process and talk SOAP to it over the pipes), but again, there's no reason it couldn't be done, and the SOAP spec explicitly says any communication medium is fair game.

    Depending on how you define, the above could be found to be too resource intensive.

    If your application is Apache based, then an obvious avenue is to use Apache modules, such as mod_perl, mod_php, mod_python, etc.

    A word spoken in Mind will reach its own level, in the objective world, by its own weight

      Unfortunately, my app is not apache based.

      More research on my part shows that Inkscape seems to use small executables for its extensions.

      The question of whether this approach will be "too resource intensive" is rather open. The only way to tell is to try some tests. A big benefit on the resources side is that this approach protects me from memory leaks caused by badly written plugins.

      Thanks for your comments.


      TGI says moo

Re:Cross platform, multilanguage plugins
by jdrago_999 (Hermit) on Feb 14, 2007 at 00:05 UTC
    Check out Inline::WSC - it allows VBScript and JavaScript functions to be called from Perl.

    Unfortunately it only works on Windows.