Botan  1.10.9
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 
11 namespace Botan {
12 
13 namespace {
14 
15 extern "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 }
T resolve(const std::string &symbol)
Definition: dyn_load.h:52
Dynamically_Loaded_Engine(const std::string &lib_path)
Definition: dyn_engine.cpp:22
std::string to_string(u64bit n, size_t min_len)
Definition: parsing.cpp:42
unsigned int u32bit
Definition: types.h:32