| 43 | // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // |
| 44 | |
| 45 | void* Foam::codedBase::loadLibrary |
| 46 | ( |
| 47 | const fileName& libPath, |
| 48 | const string& globalFuncName, |
| 49 | const dictionary& contextDict |
| 50 | ) const |
| 51 | { |
| 52 | void* lib = 0; |
| 53 | |
| 54 | // avoid compilation by loading an existing library |
| 55 | if (!libPath.empty()) |
| 56 | { |
| 57 | if (libs().open(libPath, false)) |
| 58 | { |
| 59 | lib = libs().findLibrary(libPath); |
| 60 | |
| 61 | // verify the loaded version and unload if needed |
| 62 | if (lib) |
| 63 | { |
| 64 | // provision for manual execution of code after loading |
| 65 | if (dlSymFound(lib, globalFuncName)) |
| 66 | { |
| 67 | loaderFunctionType function = |
| 68 | reinterpret_cast<loaderFunctionType> |
| 69 | ( |
| 70 | dlSym(lib, globalFuncName) |
| 71 | ); |
| 72 | |
| 73 | if (function) |
| 74 | { |
| 75 | (*function)(true); // force load |
| 76 | } |
| 77 | else |
| 78 | { |
| 79 | FatalIOErrorInFunction |
| 80 | ( |
| 81 | contextDict |
| 82 | ) << "Failed looking up symbol " << globalFuncName |
| 83 | << nl << "from " << libPath << exit(FatalIOError); |
| 84 | } |
| 85 | } |
| 86 | else |
| 87 | { |
| 88 | FatalIOErrorInFunction |
| 89 | ( |
| 90 | contextDict |
| 91 | ) << "Failed looking up symbol " << globalFuncName << nl |
| 92 | << "from " << libPath << exit(FatalIOError); |
| 93 | |
| 94 | lib = 0; |
| 95 | if (!libs().close(libPath, false)) |
| 96 | { |
| 97 | FatalIOErrorInFunction |
| 98 | ( |
| 99 | contextDict |
| 100 | ) << "Failed unloading library " |
| 101 | << libPath |
| 102 | << exit(FatalIOError); |
no test coverage detected