Creating a wrapper to two identical shared libraries

Discussion in 'C Programming' started by SoofaLoofa, Mar 14, 2008.

  1. SoofaLoofa

    SoofaLoofa Guest

    Hi,

    I am working on a large software project where we need to program for
    two identical devices. Let's call them A and B. We have already
    coded all of the functionality of A and created a shared library out
    of this code that we can call libA.so. To support device B we re-
    compile this code and create a second shared library: libB.so. Now we
    have two shared libraries that can control their respective devices
    independently.

    The problem that we are having is that it would be advantageous in
    certain cases to access either or both devices from the same piece of
    code. However, since libA and libB have identical method names how
    can we link these to the same code to access them? I'd like to create
    a wrapper class that gives access to both shared libraries. Ideally,
    the functionality of the wrapper would give global access to the
    libraries through an array index so that if I make a call like lib[0]-
    >GetDeviceType(); it would link to libA and if I make a call like

    lib[1]->GetDeviceType(); it would link to libB. Of course the index
    into the lib array could vary at run-time.

    Any suggestions on this or design ideas that might work? Can this
    work at all?

    Kevin
    SoofaLoofa, Mar 14, 2008
    #1
    1. Advertising

  2. On Mar 14, 9:35 am, SoofaLoofa <> wrote:
    > Hi,
    >
    > I am working on a large software project where we need to program for
    > two identical devices. Let's call them A and B. We have already
    > coded all of the functionality of A and created a shared library out
    > of this code that we can call libA.so. To support device B we re-
    > compile this code and create a second shared library: libB.so. Now we
    > have two shared libraries that can control their respective devices
    > independently.
    >
    > The problem that we are having is that it would be advantageous in
    > certain cases to access either or both devices from the same piece of
    > code. However, since libA and libB have identical method names how
    > can we link these to the same code to access them? I'd like to create
    > a wrapper class that gives access to both shared libraries. Ideally,
    > the functionality of the wrapper would give global access to the
    > libraries through an array index so that if I make a call like lib[0]->GetDeviceType(); it would link to libA and if I make a call like
    >
    > lib[1]->GetDeviceType(); it would link to libB. Of course the index
    > into the lib array could vary at run-time.
    >
    > Any suggestions on this or design ideas that might work? Can this
    > work at all?


    You problem leaves the domain of C and goes off into system specific
    stuff. From the library naming convention, I'd guess you are using
    some flavor of unix and suggest asking about it in
    comp.unix.programmer. <OT> What you want to do is presumably quite
    possible on your system, BTW, by loading the libraries dynamically
    instead of linking against them. Look up dlopen and dlsym, may well
    help you along, or may not. </OT>

    -David
    David Resnick, Mar 14, 2008
    #2
    1. Advertising

  3. OK I will post this in comp.unix.progammer. Thank you.
    Kevin Sookocheff, Mar 14, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. wapsiii
    Replies:
    0
    Views:
    515
    wapsiii
    Apr 10, 2006
  2. Harald Kirsch
    Replies:
    4
    Views:
    17,503
    Dale King
    Apr 15, 2006
  3. ann
    Replies:
    13
    Views:
    661
    Patricia Shanahan
    Sep 13, 2005
  4. chris Struhar
    Replies:
    1
    Views:
    305
    Jacques Labuschagne
    Jul 19, 2003
  5. Neroku
    Replies:
    12
    Views:
    554
    Oliver Wong
    Feb 12, 2007
Loading...

Share This Page