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