Shared Library Question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • listigerBiber

    Shared Library Question

    Hello,

    i want to extend a program of mine with a plugin architecture.
    I can load and use the shared libs which are implementations of a
    abstract base class without any problems. But what i need is a
    bi-directional interface, the plugins have to acess objects of the
    main programm (pointers to them are passed at plugin initialisation) .
    This works too - but only if i include the header and .cpp files of
    these api objects into every plugin - and that is bloated bullshit !

    is there a way to include the api .h files only and uses the
    implementation code from the main-application (gcc 3.2 linux 2.4) ??
    if i try to do that library loading fails with unresolved symbols
    .....

    Thanx C.S.
  • Victor Bazarov

    #2
    Re: Shared Library Question

    "listigerBi ber" <c.straehle@urz .uni-heidelberg.de> wrote...[color=blue]
    > i want to extend a program of mine with a plugin architecture.
    > I can load and use the shared libs which are implementations of a
    > abstract base class without any problems. But what i need is a
    > bi-directional interface, the plugins have to acess objects of the
    > main programm (pointers to them are passed at plugin initialisation) .
    > This works too - but only if i include the header and .cpp files of
    > these api objects into every plugin - and that is bloated bullshit !
    >
    > is there a way to include the api .h files only and uses the
    > implementation code from the main-application (gcc 3.2 linux 2.4) ??
    > if i try to do that library loading fails with unresolved symbols
    > ....[/color]

    What you need is to provide an SDK to the writers of plug-ins. You
    have determined what classes plug-ins need, now you have to expose
    those classes. The most convenient way is to create "pure abstract"
    interfaces. The real objects that will do the work you will create
    on demand in some kind of factory function. The plug-ins will call
    your factory or will receive the pointers to base classes some other
    way, then will call the methods of those base classes, which will
    resolve in calls to the implementations through polymorphism.

    So, you basically on the right track. Simply extract the interface
    the plug-ins will use into the base class, declare those functions
    virtual and pure. Make your classes derive from those interfaces,
    create the instances of your classes and pass the addresses as base
    class pointers to plug-ins.

    Victor


    Comment

    • Allen

      #3
      Re: Shared Library Question

      Hi listigerBiber, all,
      [color=blue]
      > One way to implement a C interface which I have used quite a lot is to[/color]
      make[color=blue]
      > each plugin have only one function. The function returns a pointer to a C
      > struct which has nothing but function pointers.[/color]

      id's QuakeII engine (GPL) uses a very similar method. The loading
      module and loaded module exchange references through one function call.

      struct import
      {
      //lots of pointers to funcs in other module
      } Ii;

      struct export
      {
      //lots more pointers to funcs in current module
      }Ie;

      //init pointers in Ie to local functions you want to access in other module

      __declspec(dlle xport) import GetAPI(export Ie); //defined in other
      module--platform specific interface
      Ii = GetAPI(Ie); //this func saves off the Ie info and then inits the Ii
      pointers to its local funcs to be accessed in the calling module


      I have a different method for doing the same thing. I made a global
      data tree where each node looks like:

      struct Glob
      {
      char szName[MAX_STRING];
      DWORD dwFlags; //valid fields and requests
      char szValue[MAX_STRING];
      int iValue;
      float fValue;
      void* pVoid;
      PGLOB pParentGlob;
      PGLOB pLeftGlob;
      PGLOB pRightGlob;
      };

      Then, pointers to my equivalent of the above import/export structs would
      be placed in Glob::pVoid for all to access.

      HTH
      --

      Best wishes,
      Allen

      No SPAM in my email !!




      Comment

      • Cy Edmunds

        #4
        Re: Shared Library Question

        "Allen" <allen-terri-ng@att.SPAM.net > wrote in message
        news:WMwZa.9523 6$0v4.6549963@b gtnsc04-news.ops.worldn et.att.net...[color=blue]
        > Hi listigerBiber, all,
        >[color=green]
        > > One way to implement a C interface which I have used quite a lot is to[/color]
        > make[color=green]
        > > each plugin have only one function. The function returns a pointer to a[/color][/color]
        C[color=blue][color=green]
        > > struct which has nothing but function pointers.[/color]
        >
        > id's QuakeII engine (GPL) uses a very similar method. The loading
        > module and loaded module exchange references through one function call.
        >
        > struct import
        > {
        > //lots of pointers to funcs in other module
        > } Ii;
        >
        > struct export
        > {
        > //lots more pointers to funcs in current module
        > }Ie;
        >
        > //init pointers in Ie to local functions you want to access in other[/color]
        module[color=blue]
        >
        > __declspec(dlle xport) import GetAPI(export Ie); //defined in other
        > module--platform specific interface
        > Ii = GetAPI(Ie); //this func saves off the Ie info and then inits the[/color]
        Ii[color=blue]
        > pointers to its local funcs to be accessed in the calling module
        >
        >
        > I have a different method for doing the same thing. I made a global
        > data tree where each node looks like:
        >
        > struct Glob
        > {
        > char szName[MAX_STRING];
        > DWORD dwFlags; //valid fields and requests
        > char szValue[MAX_STRING];
        > int iValue;
        > float fValue;
        > void* pVoid;
        > PGLOB pParentGlob;
        > PGLOB pLeftGlob;
        > PGLOB pRightGlob;
        > };
        >
        > Then, pointers to my equivalent of the above import/export structs[/color]
        would[color=blue]
        > be placed in Glob::pVoid for all to access.
        >
        > HTH
        > --
        >
        > Best wishes,
        > Allen
        >
        > No SPAM in my email !!
        >[/color]


        Funny you should mention QuakeII. I'm the author of the QuakeII mods WoD7
        and WoD8. :) But as you say, it was iD software that wrote the stuff you're
        talking about.

        Guess in this context I'll use my real sig, including my QuakeII clan name
        LOL

        --
        Cycho{HHR}



        Comment

        • listigerBiber

          #5
          Re: Shared Library Question

          Thank you very much !
          your hint with the abstract base class for the pluginfactory worked
          ....
          of course the pluginfactory or application api must have a pure
          virtual base class !!

          "Victor Bazarov" <v.Abazarov@att Abi.com> wrote in message news:<9ltZa.795 03$It4.39326@rw crnsc51.ops.asp .att.net>...[color=blue]
          > "listigerBi ber" <c.straehle@urz .uni-heidelberg.de> wrote...[color=green]
          > > i want to extend a program of mine with a plugin architecture.
          > > I can load and use the shared libs which are implementations of a
          > > abstract base class without any problems. But what i need is a
          > > bi-directional interface, the plugins have to acess objects of the
          > > main programm (pointers to them are passed at plugin initialisation) .
          > > This works too - but only if i include the header and .cpp files of
          > > these api objects into every plugin - and that is bloated bullshit !
          > >
          > > is there a way to include the api .h files only and uses the
          > > implementation code from the main-application (gcc 3.2 linux 2.4) ??
          > > if i try to do that library loading fails with unresolved symbols
          > > ....[/color]
          >
          > What you need is to provide an SDK to the writers of plug-ins. You
          > have determined what classes plug-ins need, now you have to expose
          > those classes. The most convenient way is to create "pure abstract"
          > interfaces. The real objects that will do the work you will create
          > on demand in some kind of factory function. The plug-ins will call
          > your factory or will receive the pointers to base classes some other
          > way, then will call the methods of those base classes, which will
          > resolve in calls to the implementations through polymorphism.
          >
          > So, you basically on the right track. Simply extract the interface
          > the plug-ins will use into the base class, declare those functions
          > virtual and pure. Make your classes derive from those interfaces,
          > create the instances of your classes and pass the addresses as base
          > class pointers to plug-ins.
          >
          > Victor[/color]

          Comment

          Working...