Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

dynload.H

Go to the documentation of this file.
00001 /*
00002  * Copyright 1998, Brown University, Providence, RI.
00003  * 
00004  *                         All Rights Reserved
00005  * 
00006  * Permission to use, copy, modify, and distribute this software and its
00007  * documentation for any purpose other than its incorporation into a
00008  * commercial product is hereby granted without fee, provided that the
00009  * above copyright notice appear in all copies and that both that
00010  * copyright notice and this permission notice appear in supporting
00011  * documentation, and that the name of Brown University not be used in
00012  * advertising or publicity pertaining to distribution of the software
00013  * without specific, written prior permission.
00014  * 
00015  * BROWN UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
00016  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ANY
00017  * PARTICULAR PURPOSE.  IN NO EVENT SHALL BROWN UNIVERSITY BE LIABLE FOR
00018  * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00019  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00020  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
00021  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00022  */
00023 #ifndef DYNLOAD_H
00024 #define DYNLOAD_H
00025 
00026 #include "std/config.H"
00027 #include "std/hash.H"
00028 #include "std/strings.H"
00029 
00030 typedef void *(*VOIDfunc)();
00031 
00032 /**********************************************************************
00033  * SYMld
00034  *
00035  *      Class for finding dynamically loaded symbols.
00036  *  Find() attempts to locate a symbol corresponding to the specified
00037  *         string name.  If the symbol is not currently loaded, then
00038  *         symbols of the form FOObar are parsed into libfoo.so and
00039  *         a search is performed for that library in a search path,
00040  *         specified by $GLUE_ROOT/...
00041  *  load_module() attempts to both find parameterless function 
00042  *         symbol (loading a library if necessary as described above) 
00043  *         and then to call that function.
00044  *  load_path() attempts to load the shared library specified by its pathname
00045  *
00046  **********************************************************************/
00047 class DllImpExp SYMld {
00048    protected:
00049             HASH<VOIDfunc>  _entries;
00050      static SYMld          *_dflt;
00051      static Cstr_ptr        _extension;
00052 
00053             void             print_error(ostream &, Cstr_ptr &name, char *path);
00054             VOIDfunc         load(char *path, char *name);
00055             VOIDfunc         find(Cstr_ptr &);
00056 
00057    public :
00058                      SYMld():_entries(128) { }
00059      static VOIDfunc Find       (Cstr_ptr &);
00060      static bool     load_module(Cstr_ptr &mod);
00061      static void     load_path  (Cstr_ptr &path);
00062             void     unload     (Cstr_ptr &s);
00063      static void     Unload     (Cstr_ptr &s) { if(_dflt) _dflt->unload(s); }
00064 };
00065 
00066 #if defined(__GNUC_MINOR__) && __GNUC_MINOR__ < 96
00067 #define JOT_CANT_DO_SYMEXEC
00068 #endif
00069 
00070 // Call a function from a shared library that has one parameter
00071 template <class T>
00072 void SYMexec(VOIDfunc f, T a) {
00073 #ifdef JOT_CANT_DO_SYMEXEC
00074    cerr << "SYMexec: not supported" << endl;
00075 #else
00076    ((void (*)(T))f)(a); 
00077 #endif
00078 }
00079 
00080 // Call a function from a shared library that has two parameters
00081 template <class T, class U>
00082 void SYMexec(VOIDfunc f, T a, U b) {
00083 #ifdef JOT_CANT_DO_SYMEXEC
00084    cerr << "SYMexec: not supported under g++" << endl;
00085 #else
00086    ((void (*)(T, U))f)(a, b);
00087 #endif
00088 }
00089 
00090 // Call a function from a shared library that has three parameters
00091 template <class T, class U, class V>
00092 void SYMexec(VOIDfunc f, T a, U b, V c) {
00093 #ifdef JOT_CANT_DO_SYMEXEC
00094    cerr << "SYMexec: not supported under g++" << endl;
00095 #else
00096    ((void (*)(T, U, V))f)(a, b, c); 
00097 #endif
00098 }
00099 #endif

Generated on Mon Sep 15 16:25:56 2003 for gluebase by doxygen1.2.18