3 #include <msp/debug/demangle.h>
4 #include <msp/debug/errorreporter.h>
5 #include <msp/io/print.h>
6 #include "application.h"
13 Application *Application::app_ = 0;
14 Application::Starter *Application::starter_ = 0;
15 void *Application::data_ = 0;
17 Application::Application():
21 throw logic_error("instance already exists");
24 int Application::run(int argc, char **argv, void *data, void (*created_callback)(void *))
28 IO::cerr.write("Application::run called with no RegisteredApplication class!\n");
38 app_ = starter_->create_app(argc, argv);
40 catch(const usage_error &e)
42 IO::print(IO::cerr, "%s\n%s\n", e.what(), e.help());
47 created_callback(data);
49 int result = app_->main();
50 Application *a = app_;
55 catch(const exception &e)
58 if(const Debug::ErrorReporter *er = Debug::ErrorReporter::get_current())
59 handled = er->report_uncaught_exception(e);
63 IO::print(IO::cerr, "An uncaught exception occurred.\n");
64 IO::print(IO::cerr, " type: %s\n", Debug::demangle(typeid(e).name()));
65 IO::print(IO::cerr, " what(): %s\n", e.what());
75 int Application::main()
84 void Application::catch_signal(int s)
86 signal(s, &sighandler_);
89 void Application::exit(int c)
95 void Application::sighandler_(int s)
101 Application::Starter::Starter()
104 throw logic_error("Can't create more than one Starter instance");