00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #ifndef _VPR_LIBRARY_NSPR_H_
00043 #define _VPR_LIBRARY_NSPR_H_
00044
00045 #include <vpr/vprConfig.h>
00046
00047 #include <stdlib.h>
00048 #include <string>
00049 #include <prlink.h>
00050
00051 #include <vpr/Util/ReturnStatus.h>
00052
00053
00054 namespace vpr
00055 {
00056
00069 class VPR_CLASS_API LibraryNSPR
00070 {
00071 public:
00081 LibraryNSPR(const std::string& name)
00082 : mName(name)
00083 , mLibrary(NULL)
00084 {
00085 ;
00086 }
00087
00097 LibraryNSPR()
00098 : mName("")
00099 , mLibrary(NULL)
00100 {
00101 ;
00102 }
00103
00107 LibraryNSPR(const LibraryNSPR& lib)
00108 : mName("")
00109 , mLibrary(NULL)
00110 {
00111 copy(lib);
00112 }
00113
00117 ~LibraryNSPR()
00118 {
00119 if ( NULL != mLibrary )
00120 {
00121 unload();
00122 }
00123 }
00124
00128 LibraryNSPR& operator=(const LibraryNSPR& lib)
00129 {
00130 copy(lib);
00131 return *this;
00132 }
00133
00137 const std::string& getName() const
00138 {
00139 return mName;
00140 }
00141
00151 vpr::ReturnStatus load();
00152
00161 vpr::ReturnStatus unload();
00162
00169 bool isLoaded() const
00170 {
00171 return mLibrary != NULL;
00172 }
00173
00175
00191 void* findSymbol(const char* symbolName)
00192 {
00193 return PR_FindSymbol(mLibrary, symbolName);
00194 }
00195
00196 void* findSymbol(const std::string& symbolName)
00197 {
00198 return findSymbol(symbolName.c_str());
00199 }
00201
00203
00207 static void* findSymbolAndLibrary(const char* symbolName, LibraryNSPR& lib)
00208 {
00209 return PR_FindSymbolAndLibrary(symbolName, &lib.mLibrary);
00210 }
00211
00212 static void* findSymbolAndLibrary(const std::string& symbolName,
00213 LibraryNSPR& lib)
00214 {
00215 return findSymbolAndLibrary(symbolName.c_str(), lib);
00216 }
00218
00219 protected:
00223 void copy(const LibraryNSPR& lib)
00224 {
00225 this->mName = lib.mName;
00226 this->mLibrary = lib.mLibrary;
00227 }
00228
00229 private:
00230 std::string mName;
00231 PRLibrary* mLibrary;
00232 };
00233
00234 }
00235
00236
00237 #endif