473,385 Members | 1,474 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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.
Jul 19 '05 #1
4 4162
"listigerBiber" <c.********@urz.uni-heidelberg.de> wrote...
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
....


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
Jul 19 '05 #2
Hi listigerBiber, all,
One way to implement a C interface which I have used quite a lot is to make each plugin have only one function. The function returns a pointer to a C
struct which has nothing but function pointers.


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(dllexport) 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 !!


Jul 19 '05 #3
"Allen" <al************@att.SPAM.net> wrote in message
news:WM*********************@bgtnsc04-news.ops.worldnet.att.net...
Hi listigerBiber, all,
One way to implement a C interface which I have used quite a lot is to make
each plugin have only one function. The function returns a pointer to a C struct which has nothing but function pointers.


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(dllexport) 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 !!

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}
http://home.rochester.rr.com/cyhome/
Jul 19 '05 #4
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.********@attAbi.com> wrote in message news:<9l*******************@rwcrnsc51.ops.asp.att. net>...
"listigerBiber" <c.********@urz.uni-heidelberg.de> wrote...
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
....


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

Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Phil | last post by:
I realize this is the php group, but I have a question that recurses back to my php install. My objective is a pure 64 bit shared object installation of php 5.0 on UltraSparc Solaris 9 compiled...
1
by: AH | last post by:
I have two functions in my shared library which are declared as follows: void setName(const std::string& str); std::vector<std::string> getInfo(); Since the code is compiled and in shared...
9
by: Invalidlastname | last post by:
Hi, We developed some assemblies which use EnterpriseServices queued components. In order to use EnterpriseServices, these assemblies need to be installed into GAC. I used the pre-build and...
6
by: Jeff | last post by:
Hi - I understand how to create a directory folder, but how can I programatically create a _shared_ directory folder and set its permissions?? (I'm using VB.NET.) Thanks for your help. -...
11
by: Matt Kowalczyk | last post by:
I hope I am posting this to the right newsgroup. I tried submitting this to the autoconf@gnu.org mailing list, but I see no activity. If this is the wrong newsgroup, I would appriciate a...
0
by: zztlhb | last post by:
Hi, I currently hit an issue that I would like to use a function statically linked to a shared library but my program use the same function from another shared library. Here is what I do: 1. I...
3
by: abhi147 | last post by:
Hi , I am trying to create a shared library and trying to load it usinf dlopen() function . My code and steps to create and load the *.so is : /*** test.c ***/ #include <stdio.h> void...
5
by: David T. Ashley | last post by:
I've occasionally had trouble compiling and linking programs that use shared libraries. That never made a lot of sense to me, because I thought the operating system went hunting for the symbols...
4
by: gopan | last post by:
I want to call the 'stat' system call dynamically. In other words, I want to use the dlopen to dynamically load a shared library and bind to the stat function using dlsym. I want to be able to...
11
by: sunil | last post by:
Hi , Am facing one problem while deploying the shared library in different boxes. I devoloped one shared library for TAM suite ( This is a IBM product for different authentication mechanisms)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.