1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "dlLibraryTable.H"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 Foam::dlLibraryTable Foam::dlLibraryTable::loadedLibraries;
35 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
37 Foam::dlLibraryTable::dlLibraryTable()
39 HashTable<fileName, void*, Hash<void*> >()
43 Foam::dlLibraryTable::readDlLibrary::readDlLibrary
45 const dictionary& dict,
49 open(dict, libsEntry);
53 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
55 Foam::dlLibraryTable::~dlLibraryTable()
57 forAllIter(dlLibraryTable, *this, iter)
64 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
66 bool Foam::dlLibraryTable::open(const fileName& functionLibName)
68 if (functionLibName.size())
70 void* functionLibPtr =
71 dlopen(functionLibName.c_str(), RTLD_LAZY|RTLD_GLOBAL);
74 if(!functionLibPtr && functionLibName.ext()=="so") {
75 fileName lName=functionLibName.lessExt()+".dylib";
77 dlopen(lName.c_str(), RTLD_LAZY|RTLD_GLOBAL);
80 if(!functionLibPtr && functionLibName.ext()=="so") {
81 fileName lName=functionLibName.lessExt()+".dll";
83 dlopen(lName.c_str(), RTLD_LAZY|RTLD_GLOBAL);
90 "dlLibraryTable::open(const fileName& functionLibName)"
91 ) << "could not load " << dlerror()
98 if (!loadedLibraries.found(functionLibPtr))
100 loadedLibraries.insert(functionLibPtr, functionLibName);
116 bool Foam::dlLibraryTable::open
118 const dictionary& dict,
119 const word& libsEntry
122 if (dict.found(libsEntry))
124 fileNameList libNames(dict.lookup(libsEntry));
126 bool allOpened = (libNames.size() > 0);
130 allOpened = dlLibraryTable::open(libNames[i]) && allOpened;
142 // ************************************************************************* //