Leosac  0.8.0
Open Source Access Control
module_manager.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 
20 #pragma once
21 
22 #include "LeosacFwd.hpp"
23 #include "boost/property_tree/ptree.hpp"
26 #include <list>
27 #include <map>
28 #include <set>
29 #include <string>
30 #include <vector>
31 #include <zmqpp/actor.hpp>
32 
33 namespace Leosac
34 {
35 class ConfigManager;
36 }
37 
55 {
56  public:
61  ModuleManager(zmqpp::context &ctx, Leosac::Kernel &k);
62 
64 
65 
73  struct ModuleInfo
74  {
75  ~ModuleInfo();
77 
78  ModuleInfo(const ModuleInfo &) = delete;
79  ModuleInfo &operator=(const ModuleInfo &) = delete;
80 
85 
86  ModuleInfo &operator=(ModuleInfo &&) = delete;
87 
91  std::string name_;
92 
96  mutable std::shared_ptr<DynamicLibrary> lib_;
97 
101  mutable std::unique_ptr<zmqpp::actor> actor_;
102 
103  bool operator<(const ModuleInfo &o) const;
104 
105  private:
107  };
108 
115  void initModules();
116 
123  bool initModule(const std::string &name);
124 
128  void initModule(ModuleInfo *modinfo);
129 
134  void stopModules(bool soft = false);
135 
139  void addToPath(const std::string &dir);
140 
148  bool loadModule(const std::string &module_name);
149 
153  std::vector<std::string> modules_names() const;
154 
163  bool has_module(const std::string &name) const;
164 
168  const std::vector<std::string> &get_module_path() const;
169 
170  private:
176  void unloadLibraries();
177 
188  bool stopModule(const std::string &name);
189 
199  void stopModule(ModuleInfo *modinfo, bool soft = false);
200 
201 
202  ModuleInfo *find_module_by_name(const std::string &name) const;
203 
211  std::shared_ptr<DynamicLibrary> load_library_file(const std::string &full_path);
212 
213  std::vector<std::string> path_;
214  std::set<ModuleInfo> modules_;
215 
216  zmqpp::context &ctx_;
219 };
ModuleManager::ModuleInfo::operator<
bool operator<(const ModuleInfo &o) const
Definition: module_manager.cpp:311
ModuleManager::ModuleInfo::actor_
std::unique_ptr< zmqpp::actor > actor_
Actor object that runs the module code.
Definition: module_manager.hpp:101
Leosac::ConfigManager
That class helps manage the configuration for the application and its module.
Definition: ConfigManager.hpp:45
ModuleManager::ModuleManager
ModuleManager(zmqpp::context &ctx, Leosac::Kernel &k)
Construct the module manager.
Definition: module_manager.cpp:29
LeosacFwd.hpp
ModuleManager
A second module manager that loads "ZMQ aware" module – modules that talks to the application through...
Definition: module_manager.hpp:54
ModuleManager::initModules
void initModules()
Actually call the init_module() function of each library we loaded.
Definition: module_manager.cpp:69
ModuleManager::core_utils_
Leosac::CoreUtilsPtr core_utils_
Definition: module_manager.hpp:218
ModuleManager::~ModuleManager
~ModuleManager()
Definition: module_manager.cpp:36
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
ModuleManager::find_module_by_name
ModuleInfo * find_module_by_name(const std::string &name) const
Definition: module_manager.cpp:291
dynamiclibrary.hpp
DynamicLibrary class.
ModuleManager::modules_names
std::vector< std::string > modules_names() const
Returns the list of the name of the loaded modules.
Definition: module_manager.cpp:278
ModuleManager::get_module_path
const std::vector< std::string > & get_module_path() const
Return the list of paths where we search for module.
Definition: module_manager.cpp:306
ModuleManager::load_library_file
std::shared_ptr< DynamicLibrary > load_library_file(const std::string &full_path)
This will load (actually calling dlopen()) the library file located at full_path.
Definition: module_manager.cpp:182
ModuleManager::ModuleInfo::ModuleInfo
ModuleInfo(const Leosac::ConfigManager &cfg)
Definition: module_manager.cpp:260
ModuleManager::ModuleInfo::~ModuleInfo
~ModuleInfo()
Definition: module_manager.cpp:256
ModuleManager::ModuleInfo::cfg_
const Leosac::ConfigManager & cfg_
Definition: module_manager.hpp:106
ModuleManager::initModule
bool initModule(const std::string &name)
Attempt to find a module using its name, then load it.
Definition: module_manager.cpp:133
ModuleManager::config_manager_
Leosac::ConfigManager & config_manager_
Definition: module_manager.hpp:217
ModuleManager::modules_
std::set< ModuleInfo > modules_
Definition: module_manager.hpp:214
Leosac::Kernel
Core of Leosac.
Definition: kernel.hpp:73
ModuleManager::ModuleInfo
Internal helper struct that store informations related to module that are useful to the module manage...
Definition: module_manager.hpp:73
ModuleManager::ModuleInfo::operator=
ModuleInfo & operator=(const ModuleInfo &)=delete
ModuleManager::ctx_
zmqpp::context & ctx_
Definition: module_manager.hpp:216
ModuleManager::stopModules
void stopModules(bool soft=false)
Opposite of init module.
Definition: module_manager.cpp:198
ModuleManager::addToPath
void addToPath(const std::string &dir)
Add a directory to a path.
Definition: module_manager.cpp:148
ModuleManager::has_module
bool has_module(const std::string &name) const
Do we have some informations about the module "name".
Definition: module_manager.cpp:301
ModuleManager::loadModule
bool loadModule(const std::string &module_name)
Search the path and load a module based on a property tree for this module.
Definition: module_manager.cpp:154
Leosac::CoreUtilsPtr
std::shared_ptr< CoreUtils > CoreUtilsPtr
Definition: LeosacFwd.hpp:35
ConfigManager.hpp
ModuleManager::stopModule
bool stopModule(const std::string &name)
Stop a module by name and remove its config info from the config manager.
Definition: module_manager.cpp:240
ModuleManager::ModuleInfo::name_
std::string name_
Name of the module, as specified in the configuration file.
Definition: module_manager.hpp:91
ModuleManager::unloadLibraries
void unloadLibraries()
Close library handler.
Definition: module_manager.cpp:53
ModuleManager::path_
std::vector< std::string > path_
Definition: module_manager.hpp:213
ModuleManager::ModuleInfo::lib_
std::shared_ptr< DynamicLibrary > lib_
Pointer to the library object.
Definition: module_manager.hpp:96