summaryrefslogtreecommitdiffhomepage
path: root/plugin.cpp
blob: 9c47ed2324ccb74eb0d5b8729cd5c9c3e3d00eb8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "plugin.h"

#include <boost/dll/import.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/filesystem.hpp>

#include <iostream>
#include <filesystem>

#include "plugin_interface.h"

namespace dll = boost::dll;
namespace fs = std::filesystem;
using namespace std::string_literals;

void load_plugins(Config& config)
{
 const auto& plugin_directories{config.PluginDirectories()};

 for (const auto& dir: plugin_directories) {
  for (auto& path: fs::recursive_directory_iterator(dir)) {
   if (path.is_regular_file()) {

    dll::fs::path lib_path{path.path()};

    boost::shared_ptr<webserver_plugin_interface> plugin = dll::import<webserver_plugin_interface>(lib_path, "webserver_plugin", dll::load_mode::append_decorations);
    if (!plugin)
     throw std::runtime_error("Can't load plugin");

    std::cout << "Plugin: " << plugin->generate_page("a") << std::endl;
   }
  }
 }

}