Leosac  0.7.0
OpenSourceAccessControl
dynamiclibrary.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014-2016 Leosac
3 
4  This file is part of Leosac.
5 
6  Leosac is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Affero General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Leosac is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Affero General Public License for more details.
15 
16  You should have received a copy of the GNU Affero General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
26 #ifndef DYNAMICLIBRARY_HPP
27 #define DYNAMICLIBRARY_HPP
28 
29 extern "C" {
30 #include <dlfcn.h>
31 }
32 
33 #include <string>
34 
39 {
40  public:
41  enum class RelocationMode : int
42  {
43  Lazy = RTLD_LAZY,
44  Now = RTLD_NOW
45  };
46 
47  public:
52  explicit DynamicLibrary(const std::string &file);
53  ~DynamicLibrary() = default;
54 
55  DynamicLibrary(const DynamicLibrary &other) = delete;
56  DynamicLibrary &operator=(const DynamicLibrary &other) = delete;
57 
58  public:
65 
70  void close();
71 
77  void *getSymbol(const std::string &symbol);
78 
82  const std::string &getFilePath() const;
83 
84  private:
85  std::string _file;
86  void *_handle;
87 };
88 
89 #endif // DYNAMICLIBRARY_HPP
DynamicLibrary(const std::string &file)
Construct a dynamic library wrapper for the shared object referenced by name.
void * getSymbol(const std::string &symbol)
Lookup a symbol by name and return a pointer to it.
const std::string & getFilePath() const
Returns the full path from which the library was loaded.
std::string _file
DynamicLibrary & operator=(const DynamicLibrary &other)=delete
void open(RelocationMode mode=RelocationMode::Lazy)
Attempts to open the shared library file so that we can access its symbols.
~DynamicLibrary()=default
Wraps a dynamic library handler and provide methods to interact with it.
void close()
Close the already opened library handler.