3 #include <msp/debug/demangle.h>
4 #include <msp/debug/errorreporter.h>
5 #include <msp/fs/utils.h>
6 #include <msp/io/print.h>
7 #include "application.h"
14 Application *Application::app_ = 0;
15 Application::Starter *Application::starter_ = 0;
16 const char *Application::argv0_ = 0;
17 string Application::name_;
18 void *Application::data_ = 0;
20 Application::Application(const string &n):
24 throw logic_error("instance already exists");
29 name_ = FS::basename(argv0_);
32 int Application::run(int argc, char **argv, void *data, void (*created_callback)(void *))
36 IO::cerr.write("Application::run called with no RegisteredApplication class!\n");
47 app_ = starter_->create_app(argc, argv);
49 catch(const usage_error &e)
51 IO::print(IO::cerr, "%s\n%s\n", e.what(), e.help());
56 created_callback(data);
58 int result = app_->main();
59 Application *a = app_;
64 catch(const exception &e)
67 if(const Debug::ErrorReporter *er = Debug::ErrorReporter::get_current())
68 handled = er->report_uncaught_exception(e);
72 IO::print(IO::cerr, "An uncaught exception occurred.\n");
73 IO::print(IO::cerr, " type: %s\n", Debug::demangle(typeid(e).name()));
74 IO::print(IO::cerr, " what(): %s\n", e.what());
84 int Application::main()
93 void Application::catch_signal(int s)
95 signal(s, &sighandler_);
98 void Application::exit(int c)
104 void Application::sighandler_(int s)
110 Application::Starter::Starter()
113 throw logic_error("Can't create more than one Starter instance");