All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Library.cpp
Go to the documentation of this file.
1 /*
2  * Library.cpp
3  *
4  * This file is part of the HausmiSEP project
5  *
6  * Copyright (C) 2012, 2013 Marco Alvarado (malvcr@gmail.com)
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #include <HSEP/Library.h>
23 
24 #include <dlfcn.h>
25 
26 namespace HSEP {
27 
28  Library::Library(const char* pType, string& pPathRef) : HSEPObject(pType) {
29 
33  dlerror();
34  aHandlerPtr = dlopen(pPathRef.c_str(), RTLD_LAZY);
35  if (nullptr != aHandlerPtr) {
36  setValid();
37  }
38  else {
39  setInvalid();
40  setLastError(dlerror());
41  }
42  dlerror();
43 
44  } // Library constructor
45 
47 
48  if (valid()) {
49  dlclose(aHandlerPtr);
50  }
51 
52  } // Library destructor
53 
54  void* Library::getMethodPtr(string& pMethodNameRef) {
55 
56  void* vMethodPtr = nullptr;
57 
58  if (valid()) {
59  vMethodPtr = dlsym(aHandlerPtr,pMethodNameRef.c_str());
60  }
61  return vMethodPtr;
62 
63  } // Library::getMethod
64 
66 
67  if (valid()) {
68  dlclose(aHandlerPtr);
69  setInvalid();
70  }
71 
72  } // Library::invalidate
73 
74 } // HSEP namespace
75 
76