Botan 1.10.17
dyn_engine.cpp
Go to the documentation of this file.
1/**
2* Dynamically Loaded Engine
3* (C) 2010 Jack Lloyd
4*
5* Distributed under the terms of the Botan license
6*/
7
8#include <botan/dyn_engine.h>
9#include <botan/internal/dyn_load.h>
10
11namespace Botan {
12
13namespace {
14
15extern "C" {
16 typedef Engine* (*creator_func)(void);
17 typedef u32bit (*module_version_func)(void);
18}
19
20}
21
23 const std::string& library_path) :
24 engine(0)
25 {
26 lib = new Dynamically_Loaded_Library(library_path);
27
28 try
29 {
30 module_version_func get_version =
31 lib->resolve<module_version_func>("module_version");
32
33 const u32bit mod_version = get_version();
34
35 if(mod_version != 20101003)
36 throw std::runtime_error("Incompatible version in " +
37 library_path + " of " +
38 to_string(mod_version));
39
40 creator_func creator =
41 lib->resolve<creator_func>("create_engine");
42
43 engine = creator();
44
45 if(!engine)
46 throw std::runtime_error("Creator function in " +
47 library_path + " failed");
48 }
49 catch(...)
50 {
51 delete lib;
52 lib = 0;
53 throw;
54 }
55 }
56
58 {
59 delete engine;
60 delete lib;
61 }
62
63}
Dynamically_Loaded_Engine(const std::string &lib_path)
Dynamically_Loaded_Library(const std::string &lib_name)
Definition dyn_load.cpp:31
std::string to_string(u64bit n, size_t min_len)
Definition parsing.cpp:42
unsigned int u32bit
Definition types.h:32