1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "dlLibraryTable.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 Foam::dlLibraryTable Foam::dlLibraryTable::loadedLibraries;
36 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
38 Foam::dlLibraryTable::dlLibraryTable()
40 HashTable<fileName, void*, Hash<void*> >()
44 Foam::dlLibraryTable::readDlLibrary::readDlLibrary
46 const dictionary& dict,
50 open(dict, libsEntry);
54 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
56 Foam::dlLibraryTable::~dlLibraryTable()
58 forAllIter(dlLibraryTable, *this, iter)
65 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
67 bool Foam::dlLibraryTable::open(const fileName& functionLibName)
69 if (functionLibName.size())
71 void* functionLibPtr =
72 dlopen(functionLibName.c_str(), RTLD_LAZY|RTLD_GLOBAL);
75 if(!functionLibPtr && functionLibName.ext()=="so") {
76 fileName lName=functionLibName.lessExt()+".dylib";
78 dlopen(lName.c_str(), RTLD_LAZY|RTLD_GLOBAL);
85 "dlLibraryTable::open(const fileName& functionLibName)"
86 ) << "could not load " << dlerror()
93 if (!loadedLibraries.found(functionLibPtr))
95 loadedLibraries.insert(functionLibPtr, functionLibName);
111 bool Foam::dlLibraryTable::open
113 const dictionary& dict,
114 const word& libsEntry
117 if (dict.found(libsEntry))
119 fileNameList libNames(dict.lookup(libsEntry));
121 bool allOpened = (libNames.size() > 0);
125 allOpened = dlLibraryTable::open(libNames[i]) && allOpened;
137 // ************************************************************************* //