SharedLibraryPlatform.h

Go to the documentation of this file.
00001 /*<!-------------------------------------------------------------------->
00002    @class  SharedLibraryPlatform
00003    @author Travis Fischer (fisch0920@gmail.com)
00004    @date   Summer 2008
00005    
00006    @brief
00007       Platform-independent interface for low-level operations on shared, 
00008    libraries, including platform-dependent implementations for POSIX-compliant 
00009    systems and Windows systems.
00010    <!-------------------------------------------------------------------->**/
00011 
00012 #ifndef SHARED_LIBRARY_PLATFORM_H_
00013 #define SHARED_LIBRARY_PLATFORM_H_
00014 
00015 #include <dynamic/SharedLibraryCommon.h>
00016 
00017 class DLLEXPORT SharedLibraryPlatform {
00018    public:
00019       ///@name Constructors
00020       //@{-----------------------------------------------------------------
00021       
00022       inline   SharedLibraryPlatform()
00023       { }
00024       
00025       virtual ~SharedLibraryPlatform()
00026       { }
00027       
00028       
00029       //@}-----------------------------------------------------------------
00030       ///@name Main usage interface
00031       //@{-----------------------------------------------------------------
00032       
00033       /**
00034        * @brief
00035        *    Attempts to load/initialize the given shared library, optionally 
00036        * specifying the given open flags to the platform-dependent loader
00037        *
00038        * @returns a platform-dependent handle to the library on success 
00039        *          or NULL on failure
00040        */
00041       virtual SharedLibraryHandle *load(const std::string &name, 
00042                                         int openFlags = 0) = 0;
00043       
00044       /**
00045        * @brief
00046        *    Attempts to unload the given shared library
00047        * 
00048        * @returns true on success, false otherwise
00049        */
00050       virtual bool unload(SharedLibraryHandle *handle) = 0;
00051       
00052       
00053       //@}-----------------------------------------------------------------
00054       ///@name Accessors
00055       //@{-----------------------------------------------------------------
00056       
00057       /**
00058        * @returns a reference to the given symbol in this SharedLibrary or 
00059        *    NULL on error
00060        * 
00061        * @note if an error occurred, you may call getLastError to obtain a 
00062        *    human-readable string describing the error
00063        */
00064       virtual void *getSymbol(SharedLibraryHandle *handle, 
00065                               const std::string &symbol) = 0;
00066       
00067       /**
00068        * @returns a human-readable string describing the last error which 
00069        *    occurred within this SharedLibrary
00070        */
00071       virtual std::string getLastError() = 0;
00072       
00073       
00074       //@}-----------------------------------------------------------------
00075 };
00076 
00077 /**
00078  * @brief
00079  *    POSIX-compliant dl* interface (dlopen, dlsym, dlclose, dlerror...)
00080  * 
00081  * @note
00082  *    Meant for use on UNIX derivatives
00083  */
00084 class DLLEXPORT SharedLibraryPlatformPosix : public SharedLibraryPlatform {
00085    public:
00086       ///@name Constructors
00087       //@{-----------------------------------------------------------------
00088       
00089       inline   SharedLibraryPlatformPosix()
00090       { }
00091       
00092       virtual ~SharedLibraryPlatformPosix()
00093       { }
00094       
00095       
00096       //@}-----------------------------------------------------------------
00097       ///@name Main usage interface
00098       //@{-----------------------------------------------------------------
00099       
00100       /// Wrapper around dlopen
00101       virtual SharedLibraryHandle *load(const std::string &name, 
00102                                         int openFlags = 0);
00103       
00104       /// Wrapper around dlclose
00105       virtual bool unload(SharedLibraryHandle *handle);
00106       
00107       
00108       //@}-----------------------------------------------------------------
00109       ///@name Accessors
00110       //@{-----------------------------------------------------------------
00111       
00112       /// Wrapper around dlsym
00113       virtual void *getSymbol(SharedLibraryHandle *handle, 
00114                               const std::string &symbol);
00115       
00116       /// Wrapper around dlerror
00117       virtual std::string getLastError();
00118       
00119       
00120       //@}-----------------------------------------------------------------
00121 };
00122 
00123 #endif // SHARED_LIBRARY_PLATFORM_H_
00124 

Generated on 28 Feb 2009 for Milton by doxygen 1.5.6