Port to Qt 4.1.
[bertos.git] / emul / emul.cpp
1 /**
2  * \file
3  * <!--
4  * Copyright 2006 Develer S.r.l. (http://www.develer.com/)
5  * Copyright 2000, 2001 Bernardo Innocenti <bernie@codewiz.org>
6  * This file is part of DevLib - See README.devlib for information.
7  * -->
8  *
9  * \version $Id$
10  *
11  * \author Bernardo Innocenti <bernie@develer.com>
12  *
13  * \brief Qt-based emulator framework for embedded applications (implementation)
14  */
15
16 /*#*
17  *#* $Log$
18  *#* Revision 1.3  2006/02/20 02:00:40  bernie
19  *#* Port to Qt 4.1.
20  *#*
21  *#* Revision 1.2  2006/01/16 03:51:51  bernie
22  *#* Fix boilerplate.
23  *#*
24  *#* Revision 1.1  2006/01/16 03:37:12  bernie
25  *#* Add emulator skeleton.
26  *#*
27  *#*/
28
29 #include "emul.h"
30 #include "emulwin.h"
31 #include <cfg/module.h>
32
33 #include <cstdlib> // std::exit()
34
35 #if _QT < 4
36         #include <qapplication.h>
37 #else
38         #include <QtGui/qapplication.h>
39 #endif
40
41
42 /// The global emulator instance.
43 Emulator *emul;
44
45 Emulator::Emulator(int &argc, char **argv) :
46         emulApp(new QApplication(argc, argv)),
47         emulWin(new EmulWin(this))
48 {
49         #if QT_VERSION < ((4 << 16) + (0 << 8) + 0)
50                 emulApp->setMainWidget(emulWin);
51         #endif
52         emulWin->show();
53 }
54
55
56 Emulator::~Emulator()
57 {
58         // we don't delete emulWin because it automatically
59         // deletes itself when closed
60         delete emulApp;
61 }
62
63
64 NORETURN void Emulator::quit()
65 {
66         // WHAT A KLUDGE!
67         this->~Emulator();
68         emul = NULL;
69
70         // do we have a better way to shut down the emulation?
71         exit(0);
72 }
73
74 MOD_DEFINE(emul)
75
76 /// Main emulator entry point.
77 extern "C" void emul_init(int *argc, char *argv[])
78 {
79         // setup global emulator pointer
80         emul = new Emulator(*argc, argv);
81
82         MOD_INIT(emul);
83 }
84
85 extern "C" void emul_cleanup()
86 {
87         MOD_CLEANUP(emul);
88
89         delete emul;
90         emul = NULL;
91 }
92
93 extern "C" void emul_idle()
94 {
95         // We process GUI events when the application is idle.
96         emul->emulApp->processEvents();
97 }
98