blob: 2dc76d7d6a3f9cec0c89800bd7858986c0e78688 (
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
/**
* Dynamically Loaded Engine
* (C) 2010 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
#include <botan/dyn_engine.h>
#include <botan/internal/dyn_load.h>
namespace Botan {
namespace {
extern "C" {
typedef Engine* (*creator_function)(void);
typedef void (*destructor_function)(Engine*);
}
}
Dynamically_Loaded_Engine::Dynamically_Loaded_Engine(
const std::string& library_path) :
engine(0)
{
lib = new Dynamically_Loaded_Library(library_path);
try
{
creator_function creator = lib->resolve<creator_function>("create_engine");
engine = creator();
if(!engine)
throw std::runtime_error("Creator function in " + library_path + " failed");
}
catch(...)
{
delete lib;
lib = 0;
throw;
}
}
Dynamically_Loaded_Engine::~Dynamically_Loaded_Engine()
{
if(lib && engine)
{
try
{
destructor_function destroy =
lib->resolve<destructor_function>("destroy_engine");
destroy(engine);
}
catch(...)
{
delete lib;
lib = 0;
throw;
}
}
if(lib)
delete lib;
}
}
|