Report patch name instead of index in debug
[foam-extend-3.2.git] / src / foam / db / dlLibraryTable / dlLibraryTable.C
blob459065f09fa49e852101e410f7b8f15113400ceb
1 /*---------------------------------------------------------------------------*\
2   =========                 |
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 -------------------------------------------------------------------------------
8 License
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"
28 #include <dlfcn.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,
46     const word& libsEntry
49     open(dict, libsEntry);
53 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
55 Foam::dlLibraryTable::~dlLibraryTable()
57     forAllIter(dlLibraryTable, *this, iter)
58     {
59         dlclose(iter.key());
60     }
64 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
66 bool Foam::dlLibraryTable::open(const fileName& functionLibName)
68     if (functionLibName.size())
69     {
70         void* functionLibPtr =
71             dlopen(functionLibName.c_str(), RTLD_LAZY|RTLD_GLOBAL);
73 #ifdef darwin
74         if(!functionLibPtr && functionLibName.ext()=="so") {
75             fileName lName=functionLibName.lessExt()+".dylib";
76             functionLibPtr =
77                 dlopen(lName.c_str(), RTLD_LAZY|RTLD_GLOBAL);
78         }
79 #elif defined mingw
80         if(!functionLibPtr && functionLibName.ext()=="so") {
81             fileName lName=functionLibName.lessExt()+".dll";
82             functionLibPtr =
83                 dlopen(lName.c_str(), RTLD_LAZY|RTLD_GLOBAL);
84         }
85 #endif
86         if (!functionLibPtr)
87         {
88             WarningIn
89             (
90                 "dlLibraryTable::open(const fileName& functionLibName)"
91             )   << "could not load " << dlerror()
92                 << endl;
94             return false;
95         }
96         else
97         {
98             if (!loadedLibraries.found(functionLibPtr))
99             {
100                 loadedLibraries.insert(functionLibPtr, functionLibName);
101                 return true;
102             }
103             else
104             {
105                 return false;
106             }
107         }
108     }
109     else
110     {
111         return false;
112     }
116 bool Foam::dlLibraryTable::open
118     const dictionary& dict,
119     const word& libsEntry
122     if (dict.found(libsEntry))
123     {
124         fileNameList libNames(dict.lookup(libsEntry));
126         bool allOpened = (libNames.size() > 0);
128         forAll(libNames, i)
129         {
130             allOpened = dlLibraryTable::open(libNames[i]) && allOpened;
131         }
133         return allOpened;
134     }
135     else
136     {
137         return false;
138     }
142 // ************************************************************************* //