1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
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);
78 "dlLibraryTable::open(const fileName& functionLibName)"
79 ) << "could not load " << dlerror()
86 if (!loadedLibraries.found(functionLibPtr))
88 loadedLibraries.insert(functionLibPtr, functionLibName);
104 bool Foam::dlLibraryTable::open
106 const dictionary& dict,
107 const word& libsEntry
110 if (dict.found(libsEntry))
112 fileNameList libNames(dict.lookup(libsEntry));
114 bool allOpened = (libNames.size() > 0);
118 allOpened = dlLibraryTable::open(libNames[i]) && allOpened;
130 // ************************************************************************* //