]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/dll/example/tutorial3/tutorial3.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / dll / example / tutorial3 / tutorial3.cpp
1 // Copyright 2014 Renato Tegon Forti, Antony Polukhin.
2 // Copyright Antony Polukhin, 2015-2022.
3 //
4 // Distributed under the Boost Software License, Version 1.0.
5 // (See accompanying file LICENSE_1_0.txt
6 // or copy at http://www.boost.org/LICENSE_1_0.txt)
7
8 #include "../b2_workarounds.hpp"
9 //[callplugcpp_tutorial3
10 #include <boost/dll/import.hpp> // for import_alias
11 #include <boost/make_shared.hpp>
12 #include <boost/function.hpp>
13 #include <iostream>
14 #include "../tutorial_common/my_plugin_api.hpp"
15
16 namespace dll = boost::dll;
17
18 std::size_t search_for_symbols(const std::vector<boost::dll::fs::path>& plugins) {
19 std::size_t plugins_found = 0;
20
21 for (std::size_t i = 0; i < plugins.size(); ++i) {
22 std::cout << "Loading plugin: " << plugins[i] << '\n';
23 dll::shared_library lib(plugins[i], dll::load_mode::append_decorations);
24 if (!lib.has("create_plugin")) {
25 // no such symbol
26 continue;
27 }
28
29 // library has symbol, importing...
30 typedef boost::shared_ptr<my_plugin_api> (pluginapi_create_t)();
31 boost::function<pluginapi_create_t> creator
32 = dll::import_alias<pluginapi_create_t>(boost::move(lib), "create_plugin");
33
34 std::cout << "Matching plugin name: " << creator()->name() << std::endl;
35 ++ plugins_found;
36 }
37
38 return plugins_found;
39 }
40
41 //]
42
43 int main(int argc, char* argv[]) {
44 BOOST_ASSERT(argc >= 3);
45 std::vector<boost::dll::fs::path> plugins;
46 plugins.reserve(argc - 1);
47 for (int i = 1; i < argc; ++i) {
48 if (b2_workarounds::is_shared_library(argv[i])) {
49 plugins.push_back(argv[i]);
50 }
51 }
52
53 const std::size_t res = search_for_symbols(plugins);
54 BOOST_ASSERT(res == 1);
55 (void)res;
56 }