MythTV  master
Go to the documentation of this file.
1 /* Engine.h
3  Copyright (C) David C. J. Matthews 2004, 2008 dm at
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU General Public License
7  as published by the Free Software Foundation; either version 2
8  of the License, or (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  GNU General Public License for more details.
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
18  Or, point your browser to
20 */
22 #if !defined(ENGINE_H)
23 #define ENGINE_H
25 #include "freemheg.h"
26 #include "Root.h"
27 #include "Ingredients.h"
28 #include "BaseClasses.h"
29 #include "Groups.h"
30 #include "Visible.h"
31 #include "Actions.h"
32 #include "Link.h"
33 #include <QString>
34 #include <QRect>
35 #include <QRegion>
36 #include <QList>
37 #include <QStack>
38 #include <QQueue>
39 #include <QTime>
41 class MHDLADisplay;
43 // Asynchronous event data.
45  public:
46  MHRoot *m_pEventSource {nullptr};
49 };
51 // Entry in the "persistent" store. At the moment it's not really persistent.
52 // The UK MHEG profile says we shouldn't store type information. That complicates
53 // the code so for the moment we do.
54 class MHPSEntry {
55  public:
56  MHPSEntry() = default;
59 };
61 // Entry in the pending external content list.
63  public:
64  QString m_FileName;
66  QTime m_time;
67 };
69 class MHInteractible;
71 class MHEngine: public MHEG {
72  public:
73  explicit MHEngine(MHContext *context);
74  ~MHEngine() override;
76  void SetBooting() override // MHEG
77  { m_fBooting = true; }
79  void DrawDisplay(QRegion toDraw) override; // MHEG
81  void BootApplication(const char *fileName);
82  void TransitionToScene(const MHObjectRef &target);
83  bool Launch(const MHObjectRef &target, bool fIsSpawn=false);
84  void Spawn(const MHObjectRef &target) { Launch(target, true); }
85  void Quit();
87  // Look up an object by its object reference. In nearly all cases we want to throw
88  // an exception if it isn't found. In a very few cases where we don't fail this
89  // returns nullptr if it isn't there.
90  MHRoot *FindObject(const MHObjectRef &oRef, bool failOnNotFound = true);
92  // Called when an event is triggered. Either queues the event or finds a link that matches.
93  void EventTriggered(MHRoot *pSource, enum EventType ev)
94  { EventTriggered(pSource, ev , MHUnion()); }
95  void EventTriggered(MHRoot *pSource, enum EventType ev, const MHUnion &evData);
97  // Called when a link fires to add the actions to the action stack.
98  void AddActions(const MHActionSequence &actions);
100  // Display stack and draw functions.
101  void AddToDisplayStack(MHVisible *pVis);
102  void RemoveFromDisplayStack(MHVisible *pVis);
103  void Redraw(const QRegion& region); // Request a redraw.
104  // Functions to alter the Z-order.
105  void BringToFront(const MHRoot *pVis);
106  void SendToBack(const MHRoot *pVis);
107  void PutBefore(const MHRoot *pVis, const MHRoot *pRef);
108  void PutBehind(const MHRoot *pVis, const MHRoot *pRef);
110  void UnlockScreen();
112  // Run synchronous actions and process any asynchronous events until the queues are empty.
113  // Returns the number of milliseconds until wake-up or 0 if none.
114  int RunAll(void) override; // MHEG
116  // Run synchronous actions.
117  void RunActions();
118  // Generate a UserAction event i.e. a key press.
119  void GenerateUserAction(int nCode) override; // MHEG
120  void EngineEvent(int nCode) override; // MHEG
121  void StreamStarted(MHStream *stream, bool bStarted) override; // MHEG
123  // Called from an ingredient to request a load of external content.
124  void RequestExternalContent(MHIngredient *pRequester);
125  void CancelExternalContentRequest(MHIngredient *pRequester);
127  // Load from or store to the persistent store.
128  bool LoadStorePersistent(bool fIsLoad, const MHOctetString &fileName, const MHSequence<MHObjectRef *> &variables);
130  // Add and remove links to and from the active link table.
131  void AddLink(MHLink *pLink);
132  void RemoveLink(MHLink *pLink);
134  bool InTransition() { return m_fInTransition; }
136  bool GetEngineSupport(const MHOctetString &feature);
138  // Get the various defaults. These are extracted from the current app or the (UK) MHEG defaults.
139  int GetDefaultCharSet();
140  void GetDefaultBGColour(MHColour &colour);
141  void GetDefaultTextColour(MHColour &colour);
142  void GetDefaultButtonRefColour(MHColour &colour);
144  void GetDefaultSliderRefColour(MHColour &colour);
145  int GetDefaultTextCHook();
146  int GetDefaultStreamCHook();
147  int GetDefaultBitmapCHook();
148 // void GetDefaultFont(MHFontBody &font); // Not currently implemented
150  void SetInputRegister(int nReg);
155  QString GetPathName(const MHOctetString &str); // Return a path relative to the home directory
157  static const char *MHEGEngineProviderIdString;
159  // Interaction: Set if an Interactible has the focus and is receiving key presses.
163  int GetTuneInfo() { return CurrentApp() ? CurrentApp()->m_tuneinfo : 0; }
164  void SetTuneInfo(int tuneinfo) { if (CurrentApp()) CurrentApp()->m_tuneinfo = tuneinfo; }
166  protected:
167  void CheckLinks(const MHObjectRef &sourceRef, enum EventType ev, const MHUnion &un);
168  MHGroup *ParseProgram(QByteArray &text);
169  void DrawRegion(const QRegion& toDraw, int nStackPos);
171  QRegion m_redrawRegion; // The accumulation of repaints when the screen is locked.
173  // Application stack and functions to get the current application and scene.
174  QStack<MHApplication*> m_ApplicationStack;
176  if (m_ApplicationStack.isEmpty())
177  return nullptr;
178  return;
179  }
180  MHScene *CurrentScene() { return CurrentApp() == nullptr ? nullptr : CurrentApp()->m_pCurrentScene; }
182  // Action stack. Actions may generate synchronous events which fire links and add
183  // new actions. These new actions have to be processed before we continue with other
184  // actions.
185  QStack<MHElemAction*> m_ActionStack;
187  // Asynchronous event queue. Asynchronous events are added to this queue and handled
188  // once the action stack is empty.
189  QQueue<MHAsynchEvent*> m_EventQueue;
191  // Active Link set. Active links are included in this table.
192  QList<MHLink*> m_LinkTable;
194  // Pending external content. If we have requested external content that has not yet arrived
195  // we make an entry in this table.
196  QList<MHExternContent*> m_ExternContentTable;
197  void CheckContentRequests();
201  bool m_fInTransition {false}; // If we get a TransitionTo, Quit etc during OnStartUp and OnCloseDown we ignore them.
203  // To canonicalise the object ids we set this to the group id of the current scene or app
204  // and use that wherever we get an object id without a group id.
207  MHContext *m_Context {nullptr}; // Pointer to the context providing drawing and other operations
208  bool m_fBooting {true};
210  MHInteractible *m_Interacting {nullptr}; // Set to current interactive object if any.
211 };
213 #endif
void GetDefaultTextColour(MHColour &colour)
Definition: Engine.cpp:1369
bool m_fInTransition
Definition: Engine.h:201
int GetDefaultCharSet()
Definition: Engine.cpp:1344
void AddToDisplayStack(MHVisible *pVis)
Definition: Engine.cpp:734
int m_tuneinfo
Definition: Groups.h:140
void RunActions()
Definition: Engine.cpp:614
void GetDefaultButtonRefColour(MHColour &colour)
Definition: Engine.cpp:1383
void RemoveFromDisplayStack(MHVisible *pVis)
Definition: Engine.cpp:746
QList< MHExternContent * > m_ExternContentTable
Definition: Engine.h:196
MHOwnPtrSequence< MHPSEntry > m_PersistentStore
Definition: Engine.h:199
int GetDefaultStreamCHook()
Definition: Engine.cpp:1436
void SetTuneInfo(int tuneinfo)
Definition: Engine.h:164
MHOwnPtrSequence< MHUnion > m_Data
Definition: Engine.h:58
~MHEngine() override
Definition: Engine.cpp:59
MHScene * m_pCurrentScene
Definition: Groups.h:149
void PutBefore(const MHRoot *pVis, const MHRoot *pRef)
Definition: Engine.cpp:790
void GetDefaultBGColour(MHColour &colour)
Definition: Engine.cpp:1355
void GetDefaultSliderRefColour(MHColour &colour)
Definition: Engine.cpp:1411
void RequestExternalContent(MHIngredient *pRequester)
Definition: Engine.cpp:969
void AddLink(MHLink *pLink)
Definition: Engine.cpp:713
MHScene * CurrentScene()
Definition: Engine.h:180
bool Launch(const MHObjectRef &target, bool fIsSpawn=false)
Definition: Engine.cpp:274
void RemoveLink(MHLink *pLink)
Definition: Engine.cpp:718
MHApplication * CurrentApp()
Definition: Engine.h:175
QTime m_time
Definition: Engine.h:66
MHContext * GetContext()
Definition: Engine.h:153
QString m_FileName
Definition: Engine.h:64
void StreamStarted(MHStream *stream, bool bStarted) override
Definition: Engine.cpp:963
int m_nLockCount
Definition: Groups.h:143
void Redraw(const QRegion &region)
Definition: Engine.cpp:899
int GetDefaultBitmapCHook()
Definition: Engine.cpp:1447
int GetDefaultTextCHook()
Definition: Engine.cpp:1425
Definition: freemheg.h:48
bool InTransition()
Definition: Engine.h:134
void GetDefaultHighlightRefColour(MHColour &colour)
Definition: Engine.cpp:1397
QStack< MHElemAction * > m_ActionStack
Definition: Engine.h:185
MHInteractible * m_Interacting
Definition: Engine.h:210
void CancelExternalContentRequest(MHIngredient *pRequester)
Definition: Engine.cpp:1028
void EventTriggered(MHRoot *pSource, enum EventType ev)
Definition: Engine.h:93
bool LoadStorePersistent(bool fIsLoad, const MHOctetString &fileName, const MHSequence< MHObjectRef * > &variables)
Definition: Engine.cpp:1110
QRegion m_redrawRegion
Definition: Engine.h:171
void CheckContentRequests()
Definition: Engine.cpp:1049
void SetInteraction(MHInteractible *p)
Definition: Engine.h:161
MHGroup * ParseProgram(QByteArray &text)
Definition: Engine.cpp:195
void PutBehind(const MHRoot *pVis, const MHRoot *pRef)
Definition: Engine.cpp:821
void CheckLinks(const MHObjectRef &sourceRef, enum EventType ev, const MHUnion &un)
Definition: Engine.cpp:706
Definition: Root.h:43
int GetTuneInfo()
Definition: Engine.h:163
void TransitionToScene(const MHObjectRef &target)
Definition: Engine.cpp:419
Definition: Groups.h:86
enum EventType m_eventType
Definition: Engine.h:47
MHUnion m_eventData
Definition: Engine.h:48
MHContext * m_Context
Definition: Engine.h:207
void GetDefaultFontAttrs(MHOctetString &str)
Definition: Engine.cpp:1458
MHRoot * m_pEventSource
Definition: Engine.h:46
void DrawDisplay(QRegion toDraw) override
Definition: Engine.cpp:886
QStack< MHApplication * > m_ApplicationStack
Definition: Engine.h:174
void UnlockScreen()
Definition: Engine.cpp:905
MHRoot * FindObject(const MHObjectRef &oRef, bool failOnNotFound=true)
Definition: Engine.cpp:574
QString GetPathName(const MHOctetString &str)
Definition: Engine.cpp:524
MHOctetString m_CurrentGroupId
Definition: Engine.h:205
Definition: Groups.h:45
void BootApplication(const char *fileName)
MHOctetString & GetGroupId()
Definition: Engine.h:152
void BringToFront(const MHRoot *pVis)
Definition: Engine.cpp:760
void DrawRegion(const QRegion &toDraw, int nStackPos)
Definition: Engine.cpp:852
void SetBooting() override
Definition: Engine.h:76
QQueue< MHAsynchEvent * > m_EventQueue
Definition: Engine.h:189
void Quit()
Definition: Engine.cpp:378
void Spawn(const MHObjectRef &target)
Definition: Engine.h:84
MHInteractible * GetInteraction(void)
Definition: Engine.h:160
int RunAll(void) override
Definition: Engine.cpp:81
void SetInputRegister(int nReg)
Definition: Engine.cpp:518
Definition: Root.h:33
MHEngine(MHContext *context)
Definition: Engine.cpp:48
void LockScreen()
Definition: Engine.h:109
void SendToBack(const MHRoot *pVis)
Definition: Engine.cpp:775
static const char * MHEGEngineProviderIdString
Definition: Engine.h:157
void AddActions(const MHActionSequence &actions)
Definition: Engine.cpp:724
QList< MHLink * > m_LinkTable
Definition: Engine.h:192
void EngineEvent(int nCode) override
Definition: Engine.cpp:955
MHOctetString m_FileName
Definition: Engine.h:57
bool m_fBooting
Definition: Engine.h:208
MHIngredient * m_pRequester
Definition: Engine.h:65
bool GetEngineSupport(const MHOctetString &feature)
Definition: Engine.cpp:1188
void GenerateUserAction(int nCode) override
Definition: Engine.cpp:915