Creating a wrapper to two identical shared libraries

S

SoofaLoofa

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
 
D

David Resnick

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,954
Messages
2,570,116
Members
46,704
Latest member
BernadineF

Latest Threads

Top