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 int Application::run(int argc, char **argv, void *data)
23 static bool called = false;
26 IO::cerr.write("Trying to call Application::run_app twice!\n");
33 IO::cerr.write("Trying to run with no RegisteredApplication class!\n");
43 app_ = starter_->create_app(argc, argv);
45 catch(const usage_error &e)
47 IO::print(IO::cerr, "%s\n%s\n", e.what(), e.help());
51 int result = app_->main();
52 Application *a = app_;
57 catch(const exception &e)
60 if(const Debug::ErrorReporter *er = Debug::ErrorReporter::get_current())
61 handled = er->report_uncaught_exception(e);
65 IO::print(IO::cerr, "An uncaught exception occurred.\n");
66 IO::print(IO::cerr, " type: %s\n", Debug::demangle(typeid(e).name()));
67 IO::print(IO::cerr, " what(): %s\n", e.what());
76 int Application::main()
85 void Application::catch_signal(int s)
87 signal(s, &sighandler_);
90 void Application::exit(int c)
96 void Application::sighandler_(int s)
102 Application::Starter::Starter()
105 throw logic_error("Can't create more than one Starter instance");