3 This file is part of libmspcore
4 Copyright © 2006 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
7 #ifndef MSP_CORE_APPLICATION_H_
8 #define MSP_CORE_APPLICATION_H_
10 #include "semaphore.h"
15 Base class for applications. Inherit the main class from this and add a static
16 member of type RegApp<MainClass>.
21 virtual ~Application() { }
23 static int run(int, char **);
24 static void usage(const char *, const char *, bool);
28 NONE, /// No main loop - main() will just return
29 SLEEP, /// Only sleep in the main loop - useful for servers
30 TICK_SLEEP, /// Call tick every iteration, with a short sleep in between
31 TICK_YIELD, /// Call tick every iteration, with sched_yield in between
32 TICK_BUSY /// Call tick every iteration
38 virtual Application *create_app(int, char **)=0;
39 virtual void usage(const char *, const char *, bool)=0;
40 virtual ~RegBase() { }
46 class RegApp: public RegBase
49 Application *create_app(int argc, char **argv) { return new T(argc, argv); }
50 void usage(const char *r, const char *a, bool b) { T::usage(r, a, b); }
58 void catch_signal(int);
59 void set_loop_mode(LoopMode);
62 virtual void tick() { }
63 virtual void sighandler(int) { }
68 Application(const Application &);
69 Application &operator=(const Application &);
71 static RegBase *reg_app_;
72 static Application *app_;
74 static void sighandler_(int);
75 static void sigalrm_(int) { }