In the beginning, or at least on Thu, 06 Feb 1997 12:46:20 -0600, Dave
Quote:>But using a shared library means that you have to have it around
>at compile time. I'm looking for a means of using external routines
>that are available at runtime, but might not be around at compile
>time.
>Specifically, I'm interested in creating some number of externally
>callable routines that generate reports. At install time the
>customer may choose to add all or some of the routines, and as
>time goes on I'd like to add new routines without requiring a new
>executable as well.
As a design issue, shared/dynamic libs is probably where you are going.
Say your app has several sales reports. You create a shared lib (libSL.so)
that has all the possible reports in it: rep1 rep2 ... rep9
Now your customer could pick which reports they want by adding them to
a resource file.
Reports 1-4 & 7 are wanted, then the resource file contains:
SLREP=rep1,rep2,rep3,rep4,rep7
Next you write some kind of menu:
char *SLReportMenu() {
/* This parses the resource file and presents just the allowed choices;
returning a pointer to the report name selected (NULL for no report).
coding omitted for the moment ...
*/
Quote:}
Finally the top level function that does the work.
int DoSalesReport() {
void *hdl;
void (*fptr)();
char *str;
/* get desired report name */
if ( NULL == (str=SLReportMenu())) {
/* exit quietly */
return(0);
}
/* open the sales report lib */
if (NULL == (hdl = dlopen("libSL.so", RTLD_LAZY))) {
error("missing shared lib ...");
return(-1);
}
/* point to the report function */
if (NULL == (fptr = dlsym(hdl, str))) {
error("invalid report name ...");
return(-1);
}
(*fptr)(); /* generate the report */
dlclose(hdl); /* close the lib */
return(0);
Quote:}
Later, as additional reports are written, your customer would install the new
libSL.so, add/edit the rc file to enable the new reports and fire it up ...
--
Calcasieu Lumber Co. Austin TX
---- "Ya jus' mash that butt'n, righ' jere" ---