[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Usata-commits] Changes to usata2/src/main.cpp
From: |
David Lau |
Subject: |
[Usata-commits] Changes to usata2/src/main.cpp |
Date: |
Fri, 21 Jan 2005 17:47:02 -0500 |
Index: usata2/src/main.cpp
diff -u usata2/src/main.cpp:1.26 usata2/src/main.cpp:1.27
--- usata2/src/main.cpp:1.26 Thu Jan 20 18:44:12 2005
+++ usata2/src/main.cpp Fri Jan 21 22:47:01 2005
@@ -10,7 +10,7 @@
// included in the software distribution, or visit
// http://www.fsf.org/licenses/gpl.html.
//
-// $Id: main.cpp,v 1.26 2005/01/20 18:44:12 skunix Exp $
+// $Id: main.cpp,v 1.27 2005/01/21 22:47:01 skunix Exp $
/**
@@ -20,14 +20,17 @@
**/
#include <string>
#include <iostream>
-
+#include <boost/function.hpp>
#include <boost/format.hpp>
#include "system.hpp"
#include "build_info.hpp"
#include "usata.hpp"
+#include "util.hpp"
#include "config.hpp"
#include "log.hpp"
#include "exception_types.hpp"
+#include "object-registry.hpp"
+
using namespace usata;
namespace usata
@@ -48,16 +51,17 @@
std::abort();
}
- void cxx_init()
+ void cxx_init(bool use_custom_terminate=false)
{
std::set_unexpected(unexpected_exception_handler);
// Putting this into conditional compile because it obscures
// errors i.e. does not display information about what exception
// is uncaught - descender
-#ifdef CUSTOM_TERMINATE
- std::set_terminate(terminate_handler);
-#endif
+ // Changed it to a variable, so it can be set through the
+ // configuration - sku
+ if (use_custom_terminate)
+ std::set_terminate(terminate_handler);
}
std::string get_default_config_file()
@@ -93,25 +97,44 @@
return;
}
-int main(int argc, char **argv)
+namespace
+{
+void shutdown()
+{
+ ObjectRegistry::die();
+ usata::system::quit();
+}
+
+void stage0()
{
init_config();
cxx_init();
setup_log();
+ return;
+}
+
+
+}
+int main(int argc, char **argv)
+{
+ stage0();
+ usata::at_scope_exit cleanup(&shutdown);
std::auto_ptr<Configuration> op_conf(parse_options(argc, argv));
// load config
ConfigSection csection("config");
-
+
log::BufferedStream logstream;
std::string cfile = csection.get("filename",get_default_config_file());
load_config(cfile);
+
+ // then export op_conf to the global config
op_conf->value_export(get_configuration());
op_conf.reset();
- logstream << boost::format("Loaded config file \"%1%\"") % cfile <<
log::commit;
- // then export op_conf
+ logstream << boost::format("Loaded config file \"%1%\"") % cfile
+ << log::commit;
try
{
@@ -119,7 +142,9 @@
}
catch (std::runtime_error &error)
{
- logstream << log::set_level(log::Level::ERROR) <<
"system::init() failed:\n\t" << error.what();
+ logstream << log::set_level(log::Level::ERROR)
+ << "system::init() failed:\n\t"
+ << error.what();
return 1;
}
int exit_value;
@@ -130,9 +155,13 @@
}
catch (std::runtime_error& error)
{
- std::cerr << "uncaught exception occurred" <<std::endl;
- std::cerr << "This is a bug in the program." <<std::endl;
- std::cerr << ">>> " << error.what() << std::endl;
+ std::cerr << "uncaught exception occurred"
+ << std::endl
+ << "This is a bug in the program."
+ << std::endl;
+ std::cerr << ">>>>"
+ << error.what()
+ << std::endl;
exit_value = 2;
}
catch (exceptions::FatalError &fe)
@@ -141,7 +170,6 @@
exit_value = 1;
}
- usata::system::quit();
return exit_value;
}