Leosac  0.7.0
OpenSourceAccessControl
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 
63  ~ModuleManager();
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 };
This is the header file for a generated source file, GitSHA1.cpp.
That class helps manage the configuration for the application and its module.
std::shared_ptr< DynamicLibrary > lib_
Pointer to the library object.
std::string name_
Name of the module, as specified in the configuration file.
zmqpp::context & ctx_
Core of Leosac.
Definition: kernel.hpp:73
Leosac::CoreUtilsPtr core_utils_
A second module manager that loads "ZMQ aware" module – modules that talks to the application throug...
std::unique_ptr< zmqpp::actor > actor_
Actor object that runs the module code.
std::shared_ptr< CoreUtils > CoreUtilsPtr
Definition: LeosacFwd.hpp:35
std::set< ModuleInfo > modules_
Internal helper struct that store informations related to module that are useful to the module manage...
Leosac::ConfigManager & config_manager_
DynamicLibrary class.
std::vector< std::string > path_
const Leosac::ConfigManager & cfg_