Botan  1.10.9
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

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

Initialize the library

Parameters
optionsa string listing initialization options

Definition at line 40 of file init.h.

References initialize().

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

Definition at line 43 of file init.h.

References deinitialize().

Member Function Documentation

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  {
74  }
void set_global_state(Library_State *new_state)
void Botan::LibraryInitializer::initialize ( const std::string &  options = "")
static

Initialize the library

Parameters
optionsa 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  */
58 
59  global_state().initialize(thread_safe);
60  }
61  catch(...)
62  {
63  deinitialize();
64  throw;
65  }
66  }
void set_global_state(Library_State *new_state)
std::vector< std::string > split_on(const std::string &str, char delim)
Definition: parsing.cpp:152
Library_State & global_state()
void initialize(bool thread_safe)
Definition: libstate.cpp:197
static void deinitialize()
Definition: init.cpp:71

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