7 #include <msp/debug/demangle.h>
8 #include "application.h"
15 Application *Application::app_ = 0;
16 Application::Starter *Application::starter_ = 0;
17 void *Application::data_ = 0;
19 Application::Application():
24 Constructs an instance of the registered application class and runs it. If the
25 application throws a usage_error, a help message is printed. The GetOpt class
26 will throw such exceptions automatically in error conditions.
28 This function can only be called once. The global main() function provided by
29 the library normally does it automatically at program startup.
31 int Application::run(int argc, char **argv, void *data)
33 static bool called = false;
36 cerr<<"Trying to call Application::run_app twice!\n";
43 cerr<<"Trying to run with no RegisteredApplication class!\n";
53 app_ = starter_->create_app(argc, argv);
55 catch(const usage_error &e)
62 int result = app_->main();
63 Application *a = app_;
68 catch(const exception &e)
73 string msg = Debug::demangle(typeid(e).name())+":\n"+e.what();
74 MessageBoxA(0, msg.c_str(), "Uncaught exception", MB_OK|MB_ICONERROR);
76 cerr<<"An uncaught exception occurred.\n";
77 cerr<<" type: "<<Debug::demangle(typeid(e).name())<<'\n';
78 cerr<<" what(): "<<e.what()<<'\n';
86 Default main loop. Calls tick() repeatedly until exit() is called. A custom
87 main loop should monitor the done member variable and return exit_code.
89 int Application::main()
99 Sets the specified signal to be delivered to the sighandler member function.
101 void Application::catch_signal(int s)
103 signal(s, &sighandler_);
107 Causes the application to exit gracefully with the given exit code.
109 void Application::exit(int c)
116 Static wrapper function to call a member function of the Application instance.
118 void Application::sighandler_(int s)
124 Application::Starter::Starter()
127 throw logic_error("Can't create more than one Starter instance");