Please create an account to participate in the Slashdot moderation system

 



Forgot your password?
typodupeerror
×
Programming IT Technology

Learning About Plug-In Architectures? 34

Pimpbot5000 queries: "I've searched high and low for a book/website/etc to get me up to speed on plugin architectures, but so far the pigeons aren't delivering. Where can a programmer go to learn about the different approaches, and their respective (dis)advantages? Most resources I've come across merely point you in the direction of creating plugins for existing projects, or quickly skip over the design phase and get straight to the 'and now you use dlopen()/dlsym() to...' part." I know quite a few plug-in architectures are language specific, but a resource that went over several schemes for each language would be a valuable thing for every coder's library.
This discussion has been archived. No new comments can be posted.

Learning About Plug-In Architectures?

Comments Filter:
  • Well, don't... (Score:5, Insightful)

    by joto ( 134244 ) on Wednesday April 03, 2002 @07:09AM (#3276011)
    Don't design a plugin-architecture. It is a static and unchangeable abomination that must be stopped, that people keep adding incompatible plugin architectures to every program.

    A much better alternative is to offer a standard extension language, such as Python, Tcl, ELK, SIOD, Guile, lua, or even (the horrors) Perl. Now, most anyone of these languages have a plugin architecture, so if for any reason, you need native code speed, it can be done by writing a WHATEVERLANGUAGE-plugin.

    The difficulty of creating a plugin architecture yourself over dlopen, is that you will most likely do it wrong at first try. A little bit less wrong on the second try, and so on... But each minor change you make to the plugin-architecture will probably break almost everything. So it's better to hand the problem off to the scripting-language-implementors...

    • Re:Well, don't... (Score:3, Insightful)

      by boltar ( 263391 )
      Are you for real? The last thing most people want to have to do when designing a piece of software
      that can take dynamic extension is have to worry about the vaguiaries of some scripting language
      since then you not only have to worry about your own bugs but bugs in the language itself. I had
      to do something like that with Tcl. Never again!
      The interpreter was so ridden with memory leaks
      that we had to withdraw our software and rewrite it with tcl removed.
      Anyway , so what if different programs have different plugin architectures. Would you expect
      to be able to use your netscape flash plugin with MySql or something? I fail to see the issue.
      • I have to agree with boltar. I would also make the
        point that using multiple languages always creates
        a maintenance problem. Good design simplifies
        code, rather than sucking in a vast body of
        unmaintainable spaghetti, and forcing you to hire
        botique language experts.

        And really, if you write a plugin in SIOD or
        Python for MySQL, it's not going to do you any
        more good in Netscape than a native code plugin
        would do.

        Generic object services is what the first poster
        is talking about, not plugins. Use IIOP or SOAP
        for that sort of thing.

        Having said all of that, the state of practice
        in plugin architecture does lag the state of
        the art by quite a bit, so this thread may shed
        some very welcome light on the subject. I
        suggest moving it to a development site, such
        as advogato.

        • I suggest moving it to a development site, such as advogato.

          Are you serious? I've looked at advogato and that site is weak.They barely have any replies to the few articles that they post. And sure some of the comments are good but the net gain from reading all the comments is a tiny pimple. I wish there was a good site for this purpose but unless you're like arstechnica with Hannibal you're screwed. The basic fact is that you need someone really knowledgeable about the topic.

          t.

  • Runtime aggregation. (Score:2, Interesting)

    by Cuthalion ( 65550 )
    Well, assuming that you absolutely must design a plugin system, lookin into some runtime aggregation systems (COM or CORBA depending on your platform and needs). That's basically with these techologies are for. (Well there are other uses as well, no flames on this please.)

    Question: How many of you have worked on a project that's designed your own damned COM-like system?
    • by foobar104 ( 206452 ) on Wednesday April 03, 2002 @10:30AM (#3276567) Journal
      Well, assuming that you absolutely must design a plugin system, lookin into some runtime aggregation systems (COM or CORBA depending on your platform and needs). That's basically with these techologies are for.

      Hmm... I don't think I agree.

      When I think "plugin," I think of an application loading and executing some code from a DSO or whatever at run-time.

      When I think "CORBA," I think of two running applications communicating with each other at run-time.

      They're fundamentally different things. If you were to design your plug-in architecture using CORBA, you'd have to have your programmers build little applications that would have to be started and to run alongside your main app, just so your main app could make remote calls to them. Seems kinda silly to me.
      • The beauty of binary interoperability systems like CORBA or COM is that if the operating system is written so allow the auto starting of these "little programs" then you don't have to start all of these little programs to make the main program work. DLL's on the Windows plateform are great for this (I don't know about Unix's dynamically linked library system). When your program loads it will request these components and they will be loaded up and then made available for you automagically.

        Thinking of CORBA or COM in the manner you are thinking of it will severely limit your uses of these technologies.
        • Um... okay. I suppose this may be true if you're using the right ORB. But in general it sounds like you're confusing dynamic linking with remote procedure calls. I say this because you use the words "CORBA" and "DLL," apparently, to refer to the same thing. They don't.

          It's an issue of address space. If I dlopen() a library and dlsym() a symbol, I can then call the function associated with that symbol and have that function run inside the calling program's address space, using the program code from the DSO I opened. It is, for all purposes, as if that code had been compiled into my program from the beginning. I can do things like pass it pointers and get pointers in return, because we're all running in one big happy address space.

          Generally speaking, though, calls over CORBA interfaces (I won't speak about COM because I neither know about, nor are particularly interested in, it) cause code to be executed in another address space. Even if the other program is started at first reference, there's still another program out there, with a separate address space. Calling it requires a context switch, and it also (and more importantly) requires that you serialize and send any relevant data from caller to callee, and back again. If you're a program like Photoshop, and the plugin is going to operate on the image in memory, a requirement that you must pass the whole image to the plug-in process would be pretty dumb.

          While it may be possible to use an ORB to broker calls to and from DSOs linked into your application at compile time, I'm not aware of any method for using the ORB to link in objects at run time. Of course there may be one, but I'm not aware of it.

          Generally, I'm coming down on the side that says CORBA (and possibly COM, if it's fundamentally similar to CORBA) is great and cool, but utterly and completely inappropriate for writing plug-ins, in the traditional sense.
          • > Generally, I'm coming down on the side that says CORBA (and possibly COM, if it's fundamentally similar to CORBA) is great and cool, but utterly and completely inappropriate for writing plug-ins, in the traditional sense.

            Actually, CORBA is bad for plug-ins, but COM is great.
            That is beacuse COM has in-proc servers, meaning that it is on the same adress space, and is extremely fast.
            Most of the plugins for MS products are COM components that implements a particular interface.

            • That is beacuse COM has in-proc servers, meaning that it is on the same adress space, and is extremely fast.

              See? There you go. I didn't know that. I therefore reframe my opinion: CORBA is bad for plugins, and COM is just plain bad. ;-)

              (I was kidding. Don't post anything about how COM is okay. I have no opinion about COM.)
          • Actually, TAO (The ACE ORB) has features to have dynamically loaded in-process servers, and to disable most of the features that makes other ORB's in-proc servers slower than COM or virtual C++ method invocation (stuff like method interception for example).

            I wonder why you would choose CORBA if it was to disable all of the features that make it CORBA. Compatibility with other ORBs might be a reason, but I don't think that the kind of objects that you might want to have in-process and so on would be any good on other ORBs.

            Some CORBA proponents will often claim that out-of-process is safer anyway, so that if you have a plugin crash, it won't take down your application, but most applications that do it that way becomes more or less confused after a plugin crashed, some to the point of crashing, so I don't see that being *that* much good anyway.
          • Sorry I guess I missed a sentence or two in my post. I understand that COM and CORBA are object models that allow binary interoperability which has nothing to do with RPC or dynamic linking. I also know that RPC/LPC and the ability to dynamically link are different things. RPC/LPC are just communication mechanism between processes either on the same system (LPC) or on different systems across a network (RPC). Dynamic linking is the ability for a binary to load up another binaries image into its own address space at run time. This is versus static linking where that other binary is loaded with the orginal's binary at runtime. This is achieved by putting both binaries into the same binary during the linking phase of building.
  • You may design your app on top of objects like COM and then integrate a VBA like suite in it to allow everyone write their own plugin thingy in the application. Of course, this is a pure MS type solution but I believe the extensibility way of the Office package is great.

    Integrating VBA is a bit costly, so you may try Microsoft Scripting Runtime (scrrun.dll) instead, its free. You will still be able to use application's object model from vbscript.
  • by Twylite ( 234238 ) <twylite AT crypt DOT co DOT za> on Wednesday April 03, 2002 @08:53AM (#3276216) Homepage

    In talking about a 'plug-in' architecture, from what viewpoint or for what purpose are you looking at the problem?

    The first possibility I forsee is that you are developing an application which requires extensibility via third-party modules. In such a case that only design I am aware of (or rather, than I can think of at the moment) is to specify one or more APIs which the plug-in must implement, and then have the facility in your main application to register binary libraries. The application queries the libraries for the API(s) supported, and slots it in somewhere for use at the appropriate point.

    The second possibility is that you are developing a plug-in architecture for a language, for others to use in a generic fashion. Your best bet is to study the way this is done in existing languages, and (as many other posters have said) don't do another plug-in architecture for a language that has one.

    I had a third possibility in mind, but it seems to have been taken by a pigeon ;)

    • I'm looking to add a dosage of extensibility to an application, in this case a distributed debugger. The plugins developed at first will most likely be fairly tame, such as providing visualizers for program state (arrays and whatnot). As things progress, and as the project goals mature over time, it may be necessary to go further and add full extensibility for the support of different low-level debuggers (gdb and the like).

      The initial step seems to fall nicely within the realm of defining a plugin interface and using dlopen()/dlsym(). The second step isn't quite as clear, my initial thoughts tell me the extension language approach is best, because I don't fancy myself capable of designing a generic API for all debugger functionality. : )

      And while direct suggestions and tips are great (and much appreciated!), I prefer to see what all the options on the table are, and do my best to not reinvent the wheel (nor the spokes, nor the inner tube, nor the valve stem). : P I'm fairly surprised this sort of information hasn't been aggregated in some place, because it must have been the cause of many many needlessly repeated hours of thought/effort/frustration/re-implementation.

      -Greg
      • Rather than using static APIs, use a container
        architecture, with dynamic typing. Let each plugin
        describe its methods with a snippet of XML, and
        let the plugins communicate using XML method
        invocations. Implement the application as a plugin
        which obtains a thread of control from the
        container and scripts the other plugins. When the
        container starts up, it can load and initialize
        all the plugins, including the application logic
        plugin. By using XML interface descriptions, it
        becomes trivial to implement inheritance between
        plugins, and by using XML invokations, it becomes
        trivial to make the component architecture network
        transparent.

        Hmmm.... this sounds familiar....

  • Bamboo (Score:3, Informative)

    by Gill Bates ( 88647 ) on Wednesday April 03, 2002 @09:20AM (#3276279)
    Take a look at Bamboo, which is a plugin (or component) framework.

    Bamboo home page [watsen.net]

    • I wonder why Bamboo used ACE and then moved to NSPR?

      Curious...

      http://watsen.net/Bamboo/

      Early 1999 to Present
      In the true spirit of Bamboo, we try to defer as many decisions as possible regarding the application until runtime. Sometime in early 1999 it occurred to us that there was one last assumption we were making: C++. Although we were using other languages with Bamboo (a Java AWT GUI and some Python scripts), their code segments were embedded into C++ modules. That is, is was not possible to have a 100% Java (i.e. platform- independent) module, which is rather troubling for some Java purists. We are now in the process of correcting this omission with a brand new architecture that simultaneously attempts to solve some other issues. For instance, we are replacing ACE with NSPR (the Netscape Portable Runtime), adding automatic code documentation (Doc++), adding printable docs (HyperLatex), a bug-tracking database (Bugzilla), searching of both the online docs and the bug database, and an online SCM (Perforce).

  • You define an interface (uh, "Plugin"?) which has a fixed API for your program to query it, and your provides some API so it can manipulate the program. In this API you might want to include a "bus" or event system that all plugins share so they can talk to other plugins without having to know about them ahead of time.

    Bam. There's your plugin "architecture". What is the problem?
  • My own design (Score:4, Informative)

    by Manax ( 41161 ) <toertel-slashdot ... minus herbivore> on Wednesday April 03, 2002 @09:35AM (#3276335) Homepage
    I've done a 'plug-in' like architecture before, in that case the modules weren't loaded dynamically, but were configured at load time (kinda sorta like winamp, ya gotta reload it).

    The key design element method is to make it object oriented, take the class's interface as your API, and bang, you've got a plugin interface.

    A little info on my design. I was working on a driver to interface with a custom communication board. Well, we had an original version of the board that we abandoned, a later version which was really used, a test board for that one, and then one or two more.... Each board did communication with a companion board on another device.

    My design was to abstract out the UART control, the low-level protocol, the FPGA control code and a couple of other things into seperate interchangable objects. These were objects, but implemented in C, since it wasn't possible to use C++ in the kernel on this platform. Each of those components were configured and plugged into the system at driver load time.

    Now, I could have made this slightly different, by pulling out the individual components into seperate modules, loaded as needed, but in this case, that would have been overkill. But the principle is identical.

    Back to your original question. I didn't have any books, or other guides to assist with the design. The design fell out of the original needs, after a reasonable amount of refactoring, and a bit of good architecture skill.

    In your case, without knowing more details about the application, it's hard to help much. If this is for a general use application, your API will probably be insufficient the first time, so it would be worth your time to think about how you will handle large scale changes to the api. (Are you going to maintain backward compatibility? Are you going to support multiple APIs at the same time? Are you going to add additional specific interfaces over time?) But the core idea again is an OO design where the plug-in is just an object.

  • by jilles ( 20976 ) on Wednesday April 03, 2002 @10:05AM (#3276472) Homepage
    Your question is very vague but I'll bite. First of all you need to understand the design solutions you can use. There are various ways of implenting plugins. Most of them depend on a component model like COM, JavaBeans or Corba. Essential is that you separate the consumer of functionality from the provider of functionality by specifying an interface.

    You'll find that the more advanced types of plugin mechanisms are usually implemented in Java. This is no coincidence because Java has a few mechanisms built into the language that enable these mechanisms: reflection (i.e. discovering what methods/properties a class has at run-time), classloaders (load a class at run-time and let it run in a sandbox, destroy classloader to unload the class), dynamic linking (classes are resolved at run-time rather than compile time). An architecture that uses all of this is Jini. Often this is seen as a failed Sun project but the design behind Jini is still very cool.

    A final word of advice: don't invent your own plugin mechanism but reuse existing ones.
    • Objective-C has similar mechanisms built-in, and dynamic loading of components is nothing new there, being available since way back (1989?), as far as I know.

      But then, Java is of the same language family as Smalltalk and Objective-C, only with a C++-style syntax, so I suppose this is no coincidence either (that Java has similar mechanisms to Objective-C and Smalltalk).
      • Of these kinds of languages Java is simply the most widely used which is why I highlighted it. Outside the macintosh platform, objective C is not used very often as far as I know. Smalltalk is pretty much a thing of the past now. Even research papers mostly use Java (or derived languages) nowadays for examples/case studies/etc.

        Java was created by people who worked on smalltalk and self in the eighties so it is definately no coincidence that it has a lot in common with those languages.
  • You have XPLC [sourceforge.net] (shameless plug, that's the one I'm working on), CrystalSpace's SCF [sourceforge.net] ("Shared Class Facility"), theKompany.com's Korelib [thekompany.com], as well as others, including the previously mentioned Bamboo and Bonobo, but others like KDE's KPart/XPart, Mozilla's XPCOM and OpenOffice's UNO. You might even count Microsoft's .NET as well, if you want to.

    Clemens Szyperski [microsoft.com]'s book, Component Software - Beyond Object-Oriented Programming [microsoft.com], is an excellent book on that subject.

    • Thanks for the links. : )

      Hopefully to the benefit of everyone, I'll mention a couple sites I found (mostly through Pierre's book link [microsoft.com]) which contain a lot of potentially useful info:

      • Cetus Links [mini.net]: thousands of links to component arch info

      Anyone know what the dealie is with Korelib? The idea looks excellent, and potentially very useful for myself, but the project seems not to have been touched for over a year.

      -Greg

      • Last commit in their CVS tree dates from 2001/12/12, so it wasn't *that* long, but still a few months.

        If you like Korelib's idea, XPLC is pretty similar, with maybe exception of the UUIDs instead of strings as component identifiers.

        XPLC is getting more development time than before, since my employer, Net Integration Technologies (http://www.net-itech.com/) is allowing me to work a full day per week on XPLC, in addition to what I used to do on nights and weekends.

        On the other hand, Korelib seems to be somewhat more usable currently (XPLC is generally usable, but dynamic loading of components is not in yet, so it's usefulness is limited), being used in some of theKompany.com's applications.
  • jEdit (Score:3, Informative)

    by mjjk2 ( 328266 ) on Wednesday April 03, 2002 @06:48PM (#3280239) Homepage
    jEdit's [jedit.org] excellent (and very logical) plugin architecture is extensively described in the documentation. Check the site for more details.
  • by Anonymous Coward

    Make sure you leave yourself an option open so that you can screw the developers [suck.com] later, if necessary.
  • Rather than specifying a particular plugin model (COM etc.) it goes without saying that you should read and enjoy the classic "Design Patterns" (Gamma,Helm,Johnson,Vlissides pub Addison-Wesley, ISBN 0-201-63361-2).

    This will give some insight into component architectures in general, and the way that different approaches are applicable to different modes of use.

Happiness is twin floppies.

Working...