dlLibraryTable.C
Go to the documentation of this file.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 #include "dlLibraryTable.H"
00028
00029 #include <dlfcn.h>
00030
00031
00032
00033 Foam::dlLibraryTable Foam::dlLibraryTable::loadedLibraries;
00034
00035
00036
00037
00038 Foam::dlLibraryTable::dlLibraryTable()
00039 :
00040 HashTable<fileName, void*, Hash<void*> >()
00041 {}
00042
00043
00044 Foam::dlLibraryTable::readDlLibrary::readDlLibrary
00045 (
00046 const dictionary& dict,
00047 const word& libsEntry
00048 )
00049 {
00050 open(dict, libsEntry);
00051 }
00052
00053
00054
00055
00056 Foam::dlLibraryTable::~dlLibraryTable()
00057 {
00058 forAllIter(dlLibraryTable, *this, iter)
00059 {
00060 dlclose(iter.key());
00061 }
00062 }
00063
00064
00065
00066
00067 bool Foam::dlLibraryTable::open(const fileName& functionLibName)
00068 {
00069 if (functionLibName.size())
00070 {
00071 void* functionLibPtr =
00072 dlopen(functionLibName.c_str(), RTLD_LAZY|RTLD_GLOBAL);
00073
00074 if (!functionLibPtr)
00075 {
00076 WarningIn
00077 (
00078 "dlLibraryTable::open(const fileName& functionLibName)"
00079 ) << "could not load " << dlerror()
00080 << endl;
00081
00082 return false;
00083 }
00084 else
00085 {
00086 if (!loadedLibraries.found(functionLibPtr))
00087 {
00088 loadedLibraries.insert(functionLibPtr, functionLibName);
00089 return true;
00090 }
00091 else
00092 {
00093 return false;
00094 }
00095 }
00096 }
00097 else
00098 {
00099 return false;
00100 }
00101 }
00102
00103
00104 bool Foam::dlLibraryTable::open
00105 (
00106 const dictionary& dict,
00107 const word& libsEntry
00108 )
00109 {
00110 if (dict.found(libsEntry))
00111 {
00112 fileNameList libNames(dict.lookup(libsEntry));
00113
00114 bool allOpened = (libNames.size() > 0);
00115
00116 forAll(libNames, i)
00117 {
00118 allOpened = dlLibraryTable::open(libNames[i]) && allOpened;
00119 }
00120
00121 return allOpened;
00122 }
00123 else
00124 {
00125 return false;
00126 }
00127 }
00128
00129
00130
Copyright © 2000-2009 OpenCFD Ltd