diff options
-rw-r--r-- | include/libstate.h | 14 | ||||
-rw-r--r-- | src/init_def.cpp | 4 | ||||
-rw-r--r-- | src/libstate.cpp | 36 |
3 files changed, 40 insertions, 14 deletions
diff --git a/include/libstate.h b/include/libstate.h index 564605a2a..666677ff3 100644 --- a/include/libstate.h +++ b/include/libstate.h @@ -22,6 +22,15 @@ namespace Botan { class Library_State { public: + Library_State(); + ~Library_State(); + + void initialize(const InitializerOptions&, Modules&); + + void load(Modules&); + + void add_engine(class Engine*); + class Engine_Iterator { public: @@ -58,8 +67,6 @@ class Library_State class Config& config() const; - void add_engine(class Engine*); - class Mutex* get_mutex() const; class Mutex* get_named_mutex(const std::string&); @@ -72,9 +79,6 @@ class Library_State void set_transcoder(class Charset_Transcoder*); std::string transcode(const std::string, Character_Set, Character_Set) const; - - Library_State(const InitializerOptions&, Modules&); - ~Library_State(); private: Library_State(const Library_State&) {} Library_State& operator=(const Library_State&) { return (*this); } diff --git a/src/init_def.cpp b/src/init_def.cpp index 50365b3d6..abfbe646e 100644 --- a/src/init_def.cpp +++ b/src/init_def.cpp @@ -18,7 +18,9 @@ void LibraryInitializer::initialize(const InitializerOptions& args, { try { - set_global_state(new Library_State(args, modules)); + set_global_state(new Library_State); + + global_state().initialize(args, modules); if(args.fips_mode() || args.self_test()) { diff --git a/src/libstate.cpp b/src/libstate.cpp index 8d6475e64..04a5760cb 100644 --- a/src/libstate.cpp +++ b/src/libstate.cpp @@ -311,7 +311,6 @@ Config& Library_State::config() const { if(!config_obj) { - printf("Lazy creation of the global config\n"); config_obj = new Config(); config_obj->load_defaults(); } @@ -320,16 +319,23 @@ Config& Library_State::config() const } /************************************************* -* Library_State Constructor * +* Load a set of modules * *************************************************/ -Library_State::Library_State(const InitializerOptions& args, - Modules& modules) +void Library_State::initialize(const InitializerOptions& args, + Modules& modules) { + if(mutex_factory) + throw Invalid_State("Library_State has already been initialized"); + if(args.thread_safe()) mutex_factory = modules.mutex_factory(); else mutex_factory = new Default_Mutex_Factory; + cached_default_allocator = 0; + x509_state_obj = 0; + ui = 0; + timer = modules.timer(); transcoder = modules.transcoder(); @@ -340,10 +346,6 @@ Library_State::Library_State(const InitializerOptions& args, locks["allocator"] = get_mutex(); locks["rng"] = get_mutex(); locks["engine"] = get_mutex(); - rng = 0; - cached_default_allocator = 0; - x509_state_obj = 0; - ui = 0; std::vector<Allocator*> mod_allocs = modules.allocators(); for(u32bit j = 0; j != mod_allocs.size(); ++j) @@ -379,6 +381,24 @@ Library_State::Library_State(const InitializerOptions& args, } /************************************************* +* Library_State Constructor * +*************************************************/ +Library_State::Library_State() + { + mutex_factory = 0; + + timer = 0; + config_obj = 0; + x509_state_obj = 0; + + ui = 0; + transcoder = 0; + rng = 0; + cached_default_allocator = 0; + ui = 0; + } + +/************************************************* * Library_State Destructor * *************************************************/ Library_State::~Library_State() |