aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlloyd <[email protected]>2006-09-20 08:20:31 +0000
committerlloyd <[email protected]>2006-09-20 08:20:31 +0000
commit869fa8a3fa7dfedc55ec4c9ece7be00d1118c309 (patch)
tree6b83f57dd0f6b8dc3a5998a1621d958d098aff82
parentde37a33633c96366216644a898b8c23fcd0f29a4 (diff)
Make the initialization/deinitialization functions static members of
the LibraryInitializer class, rather than global functions floating around inside the Init namespace. Allow callers to provide an alternative Modules object.
-rw-r--r--include/init.h22
-rw-r--r--src/init_def.cpp38
2 files changed, 25 insertions, 35 deletions
diff --git a/include/init.h b/include/init.h
index 1f8c3d742..db3dd24f7 100644
--- a/include/init.h
+++ b/include/init.h
@@ -37,22 +37,16 @@ class InitializerOptions
class LibraryInitializer
{
public:
- LibraryInitializer(const std::string& = "");
- LibraryInitializer(const InitializerOptions&);
- ~LibraryInitializer();
+ static void initialize(const std::string& = "");
+ static void initialize(const InitializerOptions&);
+ static void initialize(const InitializerOptions&, class Modules&);
+ static void deinitialize();
+
+ LibraryInitializer(const std::string& args = "") { initialize(args); }
+ LibraryInitializer(const InitializerOptions& args) { initialize(args); }
+ ~LibraryInitializer() { deinitialize(); }
};
-namespace Init {
-
-/*************************************************
-* Main Library Initialization/Shutdown Functions *
-*************************************************/
-void initialize(const InitializerOptions&);
-void deinitialize();
-
-}
-
-
}
#endif
diff --git a/src/init_def.cpp b/src/init_def.cpp
index 1388445f5..6faa5d86f 100644
--- a/src/init_def.cpp
+++ b/src/init_def.cpp
@@ -17,39 +17,37 @@ namespace Botan {
/*************************************************
* Library Initialization *
*************************************************/
-LibraryInitializer::LibraryInitializer(const std::string& arg_string)
+void LibraryInitializer::initialize(const std::string& arg_string)
{
InitializerOptions args(arg_string);
- Init::initialize(args);
+ initialize(args);
}
/*************************************************
* Library Initialization *
*************************************************/
-LibraryInitializer::LibraryInitializer(const InitializerOptions& args)
+void LibraryInitializer::initialize(const InitializerOptions& args)
{
- Init::initialize(args);
- }
-
-/*************************************************
-* Library Shutdown *
-*************************************************/
-LibraryInitializer::~LibraryInitializer()
- {
- Init::deinitialize();
+ try
+ {
+ Builtin_Modules modules(args);
+ initialize(args, modules);
+ }
+ catch(...)
+ {
+ deinitialize();
+ throw;
+ }
}
-namespace Init {
-
/*************************************************
* Library Initialization *
*************************************************/
-void initialize(const InitializerOptions& args)
+void LibraryInitializer::initialize(const InitializerOptions& args,
+ Modules& modules)
{
try
{
- Builtin_Modules modules(args);
-
set_global_state(
new Library_State(
args.thread_safe() ?
@@ -95,7 +93,7 @@ void initialize(const InitializerOptions& args)
throw Self_Test_Failure("FIPS-140 startup tests");
}
}
- catch(std::exception)
+ catch(...)
{
deinitialize();
throw;
@@ -105,11 +103,9 @@ void initialize(const InitializerOptions& args)
/*************************************************
* Library Shutdown *
*************************************************/
-void deinitialize()
+void LibraryInitializer::deinitialize()
{
set_global_state(0);
}
}
-
-}