20 |
**/ |
**/ |
21 |
#include <string> |
#include <string> |
22 |
#include <iostream> |
#include <iostream> |
23 |
|
#include <boost/function.hpp> |
24 |
#include <boost/format.hpp> |
#include <boost/format.hpp> |
25 |
#include "system.hpp" |
#include "system.hpp" |
26 |
#include "build_info.hpp" |
#include "build_info.hpp" |
27 |
#include "usata.hpp" |
#include "usata.hpp" |
28 |
|
#include "util.hpp" |
29 |
#include "config.hpp" |
#include "config.hpp" |
30 |
#include "log.hpp" |
#include "log.hpp" |
31 |
#include "exception_types.hpp" |
#include "exception_types.hpp" |
32 |
|
#include "object-registry.hpp" |
33 |
|
|
34 |
using namespace usata; |
using namespace usata; |
35 |
|
|
36 |
namespace usata |
namespace usata |
51 |
std::abort(); |
std::abort(); |
52 |
} |
} |
53 |
|
|
54 |
void cxx_init() |
void cxx_init(bool use_custom_terminate=false) |
55 |
{ |
{ |
56 |
std::set_unexpected(unexpected_exception_handler); |
std::set_unexpected(unexpected_exception_handler); |
57 |
|
|
58 |
// Putting this into conditional compile because it obscures |
// Putting this into conditional compile because it obscures |
59 |
// errors i.e. does not display information about what exception |
// errors i.e. does not display information about what exception |
60 |
// is uncaught - descender |
// is uncaught - descender |
61 |
#ifdef CUSTOM_TERMINATE |
// Changed it to a variable, so it can be set through the |
62 |
std::set_terminate(terminate_handler); |
// configuration - sku |
63 |
#endif |
if (use_custom_terminate) |
64 |
|
std::set_terminate(terminate_handler); |
65 |
} |
} |
66 |
|
|
67 |
std::string get_default_config_file() |
std::string get_default_config_file() |
97 |
return; |
return; |
98 |
} |
} |
99 |
|
|
100 |
int main(int argc, char **argv) |
namespace |
101 |
|
{ |
102 |
|
void shutdown() |
103 |
|
{ |
104 |
|
ObjectRegistry::die(); |
105 |
|
usata::system::quit(); |
106 |
|
} |
107 |
|
|
108 |
|
void stage0() |
109 |
{ |
{ |
110 |
init_config(); |
init_config(); |
111 |
cxx_init(); |
cxx_init(); |
112 |
setup_log(); |
setup_log(); |
113 |
|
return; |
114 |
|
} |
115 |
|
|
116 |
|
|
117 |
|
} |
118 |
|
int main(int argc, char **argv) |
119 |
|
{ |
120 |
|
stage0(); |
121 |
|
usata::at_scope_exit cleanup(&shutdown); |
122 |
|
|
123 |
std::auto_ptr<Configuration> op_conf(parse_options(argc, argv)); |
std::auto_ptr<Configuration> op_conf(parse_options(argc, argv)); |
124 |
|
|
125 |
// load config |
// load config |
126 |
ConfigSection csection("config"); |
ConfigSection csection("config"); |
127 |
|
|
128 |
log::BufferedStream logstream; |
log::BufferedStream logstream; |
129 |
std::string cfile = csection.get("filename",get_default_config_file()); |
std::string cfile = csection.get("filename",get_default_config_file()); |
130 |
load_config(cfile); |
load_config(cfile); |
131 |
|
|
132 |
|
// then export op_conf to the global config |
133 |
op_conf->value_export(get_configuration()); |
op_conf->value_export(get_configuration()); |
134 |
op_conf.reset(); |
op_conf.reset(); |
135 |
|
|
136 |
logstream << boost::format("Loaded config file \"%1%\"") % cfile << log::commit; |
logstream << boost::format("Loaded config file \"%1%\"") % cfile |
137 |
// then export op_conf |
<< log::commit; |
138 |
|
|
139 |
try |
try |
140 |
{ |
{ |
142 |
} |
} |
143 |
catch (std::runtime_error &error) |
catch (std::runtime_error &error) |
144 |
{ |
{ |
145 |
logstream << log::set_level(log::Level::ERROR) << "system::init() failed:\n\t" << error.what(); |
logstream << log::set_level(log::Level::ERROR) |
146 |
|
<< "system::init() failed:\n\t" |
147 |
|
<< error.what(); |
148 |
return 1; |
return 1; |
149 |
} |
} |
150 |
int exit_value; |
int exit_value; |
155 |
} |
} |
156 |
catch (std::runtime_error& error) |
catch (std::runtime_error& error) |
157 |
{ |
{ |
158 |
std::cerr << "uncaught exception occurred" <<std::endl; |
std::cerr << "uncaught exception occurred" |
159 |
std::cerr << "This is a bug in the program." <<std::endl; |
<< std::endl |
160 |
std::cerr << ">>> " << error.what() << std::endl; |
<< "This is a bug in the program." |
161 |
|
<< std::endl; |
162 |
|
std::cerr << ">>>>" |
163 |
|
<< error.what() |
164 |
|
<< std::endl; |
165 |
exit_value = 2; |
exit_value = 2; |
166 |
} |
} |
167 |
catch (exceptions::FatalError &fe) |
catch (exceptions::FatalError &fe) |
170 |
exit_value = 1; |
exit_value = 1; |
171 |
} |
} |
172 |
|
|
|
usata::system::quit(); |
|
173 |
return exit_value; |
return exit_value; |
174 |
} |
} |
175 |
|
|