1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "dlLibraryTable.H"
27 #include "OSspecific.H"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 defineTypeNameAndDebug(Foam::dlLibraryTable, 0);
35 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
37 Foam::dlLibraryTable::dlLibraryTable()
41 Foam::dlLibraryTable::dlLibraryTable
43 const dictionary& dict,
47 open(dict, libsEntry);
51 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
53 Foam::dlLibraryTable::~dlLibraryTable()
55 forAllReverse(libPtrs_, i)
61 Info<< "dlLibraryTable::~dlLibraryTable() : closing "
63 << " with handle " << long(libPtrs_[i]) << endl;
71 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
73 bool Foam::dlLibraryTable::open
75 const fileName& functionLibName,
79 if (functionLibName.size())
81 void* functionLibPtr = dlOpen(functionLibName, verbose);
85 Info<< "dlLibraryTable::open : opened " << functionLibName
86 << " resulting in handle " << long(functionLibPtr) << endl;
95 "dlLibraryTable::open(const fileName&, const bool)"
96 ) << "could not load " << functionLibName
104 libPtrs_.append(functionLibPtr);
105 libNames_.append(functionLibName);
116 bool Foam::dlLibraryTable::close
118 const fileName& functionLibName,
123 forAllReverse(libNames_, i)
125 if (libNames_[i] == functionLibName)
136 Info<< "dlLibraryTable::close : closing " << functionLibName
137 << " with handle " << long(libPtrs_[index]) << endl;
140 bool ok = dlClose(libPtrs_[index]);
142 libPtrs_[index] = NULL;
143 libNames_[index] = fileName::null;
151 "dlLibraryTable::close(const fileName&)"
152 ) << "could not close " << functionLibName
165 void* Foam::dlLibraryTable::findLibrary(const fileName& functionLibName)
168 forAllReverse(libNames_, i)
170 if (libNames_[i] == functionLibName)
179 return libPtrs_[index];
185 bool Foam::dlLibraryTable::open
187 const dictionary& dict,
188 const word& libsEntry
191 if (dict.found(libsEntry))
193 fileNameList libNames(dict.lookup(libsEntry));
195 bool allOpened = !libNames.empty();
199 allOpened = dlLibraryTable::open(libNames[i]) && allOpened;
211 // ************************************************************************* //