2 #include <msp/io/print.h>
3 #include "application.h"
10 Application *Application::app_ = 0;
11 Application::Starter *Application::starter_ = 0;
12 void *Application::data_ = 0;
14 Application::Application():
19 Constructs an instance of the registered application class and runs it. If the
20 application throws a usage_error, a help message is printed. The GetOpt class
21 will throw such exceptions automatically in error conditions.
23 This function can only be called once. The global main() function provided by
24 the library normally does it automatically at program startup.
26 int Application::run(int argc, char **argv, void *data)
28 static bool called = false;
31 IO::cerr.write("Trying to call Application::run_app twice!\n");
38 IO::cerr.write("Trying to run with no RegisteredApplication class!\n");
48 app_ = starter_->create_app(argc, argv);
50 catch(const usage_error &e)
52 IO::print(IO::cerr, "%s\n%s\n", e.what(), e.help());
56 int result = app_->main();
57 Application *a = app_;
62 catch(const exception &e)
73 Default main loop. Calls tick() repeatedly until exit() is called. A custom
74 main loop should monitor the done member variable and return exit_code.
76 int Application::main()
86 Sets the specified signal to be delivered to the sighandler member function.
88 void Application::catch_signal(int s)
90 signal(s, &sighandler_);
94 Causes the application to exit gracefully with the given exit code.
96 void Application::exit(int c)
103 Static wrapper function to call a member function of the Application instance.
105 void Application::sighandler_(int s)
111 Application::Starter::Starter()
114 throw logic_error("Can't create more than one Starter instance");