Add emulator skeleton.
[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  * All Rights Reserved.
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.1  2006/01/16 03:37:12  bernie
19  *#* Add emulator skeleton.
20  *#*
21  *#*/
22
23 #include "emul.h"
24 #include "emulwin.h"
25
26 #include <qapplication.h>
27 #include <cstdlib> // std::exit()
28
29 /// The global emulator instance.
30 Emulator *emul;
31
32 Emulator::Emulator(int &argc, char **argv) :
33         emulApp(new QApplication(argc, argv)),
34         emulWin(new EmulWin(this))
35 {
36         emulApp->setMainWidget(emulWin);
37         emulWin->show();
38 }
39
40
41 Emulator::~Emulator()
42 {
43         // we don't delete emulWin because it automatically
44         // deletes itself when closed
45         delete emulApp;
46 }
47
48
49 void Emulator::quit()
50 {
51         // WHAT A KLUDGE!
52         this->~Emulator();
53         emul = NULL;
54
55         // do we have a better way to shut down the emulation?
56         exit(0);
57 }
58
59
60 /// Main emulator entry point.
61 extern "C" void emul_init(int *argc, char *argv[])
62 {
63         ASSERT(!emul);
64
65         // setup global emulator pointer
66         emul = new Emulator(*argc, argv);
67 }
68
69 extern "C" void emul_cleanup()
70 {
71         ASSERT(emul);
72         delete emul;
73         emul = NULL;
74 }
75
76 extern "C" void emul_idle()
77 {
78         // We process GUI events when the application is idle.
79         emul->emulApp->processEvents();
80 }
81