2 This file is part of libmspcore
3 Copyright © 2006 Mikko Rasa, Mikkosoft Productions
4 Distributed under the LGPL
6 #ifndef MSP_FRAMEWORK_APPLICATION_H_
7 #define MSP_FRAMEWORK_APPLICATION_H_
14 Base class for applications. Inherit the main class from this and add a static
15 member of type RegApp<MainClass>.
20 virtual ~Application() { }
22 static int run(int, char **);
23 static void usage(const char *, const char *, bool);
27 NONE, /// No main loop - main() will just return
28 SLEEP, /// Only sleep in the main loop - useful for servers
29 TICK_SLEEP, /// Call tick every iteration, with a short sleep in between
30 TICK_YIELD /// Call tick every iteration, with sched_yield in between
36 virtual Application *create_app(int, char **)=0;
37 virtual void usage(const char *, const char *, bool)=0;
38 virtual ~RegBase() { }
44 class RegApp: public RegBase
47 Application *create_app(int argc, char **argv) { return new T(argc, argv); }
48 void usage(const char *r, const char *a, bool b) { T::usage(r, a, b); }
56 void catch_signal(int);
57 void set_loop_mode(LoopMode);
60 virtual void tick() { }
61 virtual void sighandler(int) { }
66 Application(const Application &);
67 Application &operator=(const Application &);
69 static RegBase *reg_app_;
70 static Application *app_;
72 static void sighandler_(int);
73 static void sigalrm_(int) { }