]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/dll/example/tutorial6/tutorial6.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / dll / example / tutorial6 / tutorial6.cpp
1 // Copyright 2014 Renato Tegon Forti, Antony Polukhin.
2 // Copyright 2015 Antony Polukhin.
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
10 //[callplugcpp_tutorial6
11 #include <boost/dll/import.hpp>
12 #include <boost/function.hpp>
13 #include <iostream>
14
15 typedef boost::function<void()> callback_t;
16
17 void print_unloaded() {
18 std::cout << "unloaded" << std::endl;
19 }
20
21 int main(int argc, char* argv[]) {
22 // argv[1] contains full path to our plugin library
23 boost::filesystem::path shared_library_path = /*<-*/ b2_workarounds::first_lib_from_argv(argc, argv); /*->*/ //=argv[1];
24
25 // loading library and getting a function from it
26 boost::function<void(const callback_t&)> on_unload
27 = boost::dll::import_alias<void(const callback_t&)>(
28 shared_library_path, "on_unload"
29 );
30
31 on_unload(&print_unloaded); // adding a callback
32 std::cout << "Before library unload." << std::endl;
33
34 // Releasing last reference to the library, so that it gets unloaded
35 on_unload.clear();
36 std::cout << "After library unload." << std::endl;
37 }
38 //]
39