Botan 1.10.17

Public Member Functions | Static Public Member Functions | List of all members
Botan::LibraryInitializer Class Reference

`#include <init.h>`

## Public Member Functions
| LibraryInitializer (const std::string &options="")
| ~LibraryInitializer ()

## Static Public Member Functions
static void | deinitialize ()
static void | initialize (const std::string &options="")

## Detailed Description

This class represents the Library Initialization/Shutdown Object. It has to exceed the lifetime of any Botan object used in an application. You can call initialize/deinitialize or use LibraryInitializer in the RAII style.

Definition at line 22 of file init.h.

## Constructor & Destructor Documentation

## ◆ LibraryInitializer()

Botan::LibraryInitializer::LibraryInitializer | ( | const std::string & | options = `""` | ) |
| inline

Initialize the library

Parameters

  options | a string listing initialization options

Definition at line 40 of file init.h.

References initialize().

41 { LibraryInitializer::initialize(options); }
Botan::LibraryInitializer::initialize
static void initialize(const std::string &options="")
Definition: init.cpp:18

## ◆ ~LibraryInitializer()

Botan::LibraryInitializer::~LibraryInitializer | ( |  | ) |
| inline

Definition at line 43 of file init.h.

References deinitialize().

43 { LibraryInitializer::deinitialize(); }
Botan::LibraryInitializer::deinitialize
static void deinitialize()
Definition: init.cpp:71

## Member Function Documentation

## ◆ deinitialize()

void Botan::LibraryInitializer::deinitialize | ( |  | ) |
| static

Shutdown the library

Definition at line 71 of file init.cpp.

References Botan::Global_State_Management::set_global_state().

Referenced by initialize(), and ~LibraryInitializer().

72 {
73 Global_State_Management::set_global_state(0);
74 }
Botan::Global_State_Management::set_global_state
void set_global_state(Library_State *new_state)
Definition: global_state.cpp:49

## ◆ initialize()

void Botan::LibraryInitializer::initialize | ( | const std::string & | options = `""` | ) |
| static

Initialize the library

Parameters

  options | a string listing initialization options

Definition at line 18 of file init.cpp.

References deinitialize(), Botan::Global_State_Management::global_state(), Botan::Library_State::initialize(), Botan::Global_State_Management::set_global_state(), and Botan::split_on().

Referenced by LibraryInitializer().

19 {
20 bool thread_safe = false;
21
22 const std::vector<std::string> arg_list = split_on(arg_string, ' ');
23 for(size_t i = 0; i != arg_list.size(); ++i)
24 {
25 if(arg_list[i].size() == 0)
26 continue;
27
28 std::string name, value;
29
30 if(arg_list[i].find('=') == std::string::npos)
31 {
32 name = arg_list[i];
33 value = "true";
34 }
35 else
36 {
37 std::vector<std::string> name_and_value = split_on(arg_list[i], '=');
38 name = name_and_value[0];
39 value = name_and_value[1];
40 }
41
42 bool is_on =
43 (value == "1" || value == "true" || value == "yes" || value == "on");
44
45 if(name == "thread_safe")
46 thread_safe = is_on;
47 }
48
49 try
50 {
51 /*
52 This two stage initialization process is because Library_State's
53 constructor will implicitly refer to global state through the
54 allocators and so forth, so global_state() has to be a valid
55 reference before initialize() can be called. Yeah, gross.
56 */
57 Global_State_Management::set_global_state(new Library_State);
58
59 global_state().initialize(thread_safe);
60 }
61 catch(...)
62 {
63 deinitialize();
64 throw;
65 }
66 }
Botan::Global_State_Management::set_global_state
void set_global_state(Library_State *new_state)
Definition: global_state.cpp:49
Botan::split_on
std::vector< std::string > split_on(const std::string &str, char delim)
Definition: parsing.cpp:152
Botan::Global_State_Management::global_state
Library_State & global_state()
Definition: global_state.cpp:32
Botan::Library_State::initialize
void initialize(bool thread_safe)
Definition: libstate.cpp:197
Botan::LibraryInitializer::deinitialize
static void deinitialize()
Definition: init.cpp:71

The documentation for this class was generated from the following files:

- src/libstate/init.h
- src/libstate/init.cpp