MythTV  master
Engine.h
Go to the documentation of this file.
1 /* Engine.h
2 
3  Copyright (C) David C. J. Matthews 2004, 2008 dm at prolingua.co.uk
4 
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.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
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 http://www.gnu.org/copyleft/gpl.html
19 
20 */
21 
22 #if !defined(ENGINE_H)
23 #define ENGINE_H
24 
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 <QElapsedTimer>
37 #include <QList>
38 #include <QQueue>
39 #include <QStack>
40 #include <QTime>
41 
42 class MHDLADisplay;
43 
44 // Asynchronous event data.
46  public:
47  MHRoot *m_pEventSource {nullptr};
48  enum EventType m_eventType {EventIsAvailable};
50 };
51 
52 // Entry in the "persistent" store. At the moment it's not really persistent.
53 // The UK MHEG profile says we shouldn't store type information. That complicates
54 // the code so for the moment we do.
55 class MHPSEntry {
56  public:
57  MHPSEntry() = default;
60 };
61 
62 // Entry in the pending external content list.
64  public:
65  QString m_FileName;
67  QElapsedTimer m_time;
68 };
69 
70 class MHInteractible;
71 
72 class MHEngine: public MHEG {
73  public:
74  explicit MHEngine(MHContext *context);
75  ~MHEngine() override;
76 
77  void SetBooting() override // MHEG
78  { m_fBooting = true; }
79 
80  void DrawDisplay(const QRegion& toDraw) override; // MHEG
81 
82  void BootApplication(const char *fileName);
83  void TransitionToScene(const MHObjectRef &target);
84  bool Launch(const MHObjectRef &target, bool fIsSpawn=false);
85  void Spawn(const MHObjectRef &target) { Launch(target, true); }
86  void Quit();
87 
88  // Look up an object by its object reference. In nearly all cases we want to throw
89  // an exception if it isn't found. In a very few cases where we don't fail this
90  // returns nullptr if it isn't there.
91  MHRoot *FindObject(const MHObjectRef &oRef, bool failOnNotFound = true);
92 
93  // Called when an event is triggered. Either queues the event or finds a link that matches.
94  void EventTriggered(MHRoot *pSource, enum EventType ev)
95  { EventTriggered(pSource, ev , MHUnion()); }
96  void EventTriggered(MHRoot *pSource, enum EventType ev, const MHUnion &evData);
97 
98  // Called when a link fires to add the actions to the action stack.
99  void AddActions(const MHActionSequence &actions);
100 
101  // Display stack and draw functions.
102  void AddToDisplayStack(MHVisible *pVis);
103  void RemoveFromDisplayStack(MHVisible *pVis);
104  void Redraw(const QRegion& region); // Request a redraw.
105  // Functions to alter the Z-order.
106  void BringToFront(const MHRoot *pVis);
107  void SendToBack(const MHRoot *pVis);
108  void PutBefore(const MHRoot *pVis, const MHRoot *pRef);
109  void PutBehind(const MHRoot *pVis, const MHRoot *pRef);
110  void LockScreen() { MHApplication *app = CurrentApp(); if (app) app->m_nLockCount++; }
111  void UnlockScreen();
112 
113  // Run synchronous actions and process any asynchronous events until the queues are empty.
114  // Returns the number of milliseconds until wake-up or 0 if none.
115  std::chrono::milliseconds RunAll(void) override; // MHEG
116 
117  // Run synchronous actions.
118  void RunActions();
119  // Generate a UserAction event i.e. a key press.
120  void GenerateUserAction(int nCode) override; // MHEG
121  void EngineEvent(int nCode) override; // MHEG
122  void StreamStarted(MHStream *stream, bool bStarted) override; // MHEG
123 
124  // Called from an ingredient to request a load of external content.
125  void RequestExternalContent(MHIngredient *pRequester);
126  void CancelExternalContentRequest(MHIngredient *pRequester);
127 
128  // Load from or store to the persistent store.
129  bool LoadStorePersistent(bool fIsLoad, const MHOctetString &fileName, const MHSequence<MHObjectRef *> &variables);
130 
131  // Add and remove links to and from the active link table.
132  void AddLink(MHLink *pLink);
133  void RemoveLink(MHLink *pLink);
134 
135  bool InTransition() const { return m_fInTransition; }
136 
138 
139  // Get the various defaults. These are extracted from the current app or the (UK) MHEG defaults.
140  int GetDefaultCharSet();
141  void GetDefaultBGColour(MHColour &colour);
142  void GetDefaultTextColour(MHColour &colour);
143  void GetDefaultButtonRefColour(MHColour &colour);
145  void GetDefaultSliderRefColour(MHColour &colour);
146  int GetDefaultTextCHook();
147  int GetDefaultStreamCHook();
148  int GetDefaultBitmapCHook();
149 // void GetDefaultFont(MHFontBody &font); // Not currently implemented
151  void SetInputRegister(int nReg);
152 
155 
156  QString GetPathName(const MHOctetString &str); // Return a path relative to the home directory
157 
158  static const char *MHEGEngineProviderIdString;
159 
160  // Interaction: Set if an Interactible has the focus and is receiving key presses.
163 
164  int GetTuneInfo() { MHApplication *app = CurrentApp(); return app ? app->m_tuneInfo : 0; }
165  void SetTuneInfo(int tuneinfo) { MHApplication *app = CurrentApp(); if (app) app->m_tuneInfo = tuneinfo; }
166 
167  protected:
168  void CheckLinks(const MHObjectRef &sourceRef, enum EventType ev, const MHUnion &un);
169  MHGroup *ParseProgram(QByteArray &text);
170  void DrawRegion(const QRegion& toDraw, int nStackPos);
171 
172  QRegion m_redrawRegion; // The accumulation of repaints when the screen is locked.
173 
174  // Application stack and functions to get the current application and scene.
175  QStack<MHApplication*> m_applicationStack;
177  if (m_applicationStack.isEmpty())
178  return nullptr;
179  return m_applicationStack.top();
180  }
182  MHApplication *app = CurrentApp();
183  return app ? app->m_pCurrentScene : nullptr;
184  }
185 
186  // Action stack. Actions may generate synchronous events which fire links and add
187  // new actions. These new actions have to be processed before we continue with other
188  // actions.
189  QStack<MHElemAction*> m_actionStack;
190 
191  // Asynchronous event queue. Asynchronous events are added to this queue and handled
192  // once the action stack is empty.
193  QQueue<MHAsynchEvent*> m_eventQueue;
194 
195  // Active Link set. Active links are included in this table.
196  QList<MHLink*> m_linkTable;
197 
198  // Pending external content. If we have requested external content that has not yet arrived
199  // we make an entry in this table.
200  QList<MHExternContent*> m_externContentTable;
201  void CheckContentRequests();
202 
204 
205  bool m_fInTransition {false}; // If we get a TransitionTo, Quit etc during OnStartUp and OnCloseDown we ignore them.
206 
207  // To canonicalise the object ids we set this to the group id of the current scene or app
208  // and use that wherever we get an object id without a group id.
210 
211  MHContext *m_context {nullptr}; // Pointer to the context providing drawing and other operations
212  bool m_fBooting {true};
213 
214  MHInteractible *m_interacting {nullptr}; // Set to current interactive object if any.
215 };
216 
217 #endif
MHObjectRef
Definition: BaseClasses.h:153
MHGroup
Definition: Groups.h:46
MHEngine::CurrentScene
MHScene * CurrentScene()
Definition: Engine.h:181
MHPSEntry::m_FileName
MHOctetString m_FileName
Definition: Engine.h:58
MHEngine::RequestExternalContent
void RequestExternalContent(MHIngredient *pRequester)
Definition: Engine.cpp:1002
MHEngine::GetDefaultBGColour
void GetDefaultBGColour(MHColour &colour)
Definition: Engine.cpp:1393
Groups.h
MHEngine::m_interacting
MHInteractible * m_interacting
Definition: Engine.h:214
MHStream
Definition: Stream.h:32
MHDLADisplay
Definition: freemheg.h:174
MHEngine::GetContext
MHContext * GetContext()
Definition: Engine.h:154
MHEngine
Definition: Engine.h:72
MHEngine::DrawDisplay
void DrawDisplay(const QRegion &toDraw) override
Definition: Engine.cpp:915
MHApplication
Definition: Groups.h:117
MHEngine::MHEGEngineProviderIdString
static const char * MHEGEngineProviderIdString
Definition: Engine.h:158
MHEngine::MHEngine
MHEngine(MHContext *context)
Definition: Engine.cpp:48
MHEngine::ParseProgram
MHGroup * ParseProgram(QByteArray &text)
Definition: Engine.cpp:195
MHEngine::m_eventQueue
QQueue< MHAsynchEvent * > m_eventQueue
Definition: Engine.h:193
MHEngine::RunAll
std::chrono::milliseconds RunAll(void) override
Definition: Engine.cpp:81
MHEngine::SendToBack
void SendToBack(const MHRoot *pVis)
Definition: Engine.cpp:795
MHExternContent::m_FileName
QString m_FileName
Definition: Engine.h:65
MHAsynchEvent
Definition: Engine.h:45
MHEngine::GetDefaultButtonRefColour
void GetDefaultButtonRefColour(MHColour &colour)
Definition: Engine.cpp:1421
MHEngine::m_fBooting
bool m_fBooting
Definition: Engine.h:212
MHEngine::AddLink
void AddLink(MHLink *pLink)
Definition: Engine.cpp:724
Visible.h
MHEngine::GetDefaultSliderRefColour
void GetDefaultSliderRefColour(MHColour &colour)
Definition: Engine.cpp:1449
MHAsynchEvent::m_eventData
MHUnion m_eventData
Definition: Engine.h:49
MHApplication::m_pCurrentScene
MHScene * m_pCurrentScene
Definition: Groups.h:151
MHSequence< MHObjectRef * >
MHOctetString
Definition: BaseClasses.h:107
Actions.h
MHEngine::SetTuneInfo
void SetTuneInfo(int tuneinfo)
Definition: Engine.h:165
MHEngine::GetPathName
QString GetPathName(const MHOctetString &str)
Definition: Engine.cpp:534
MHEngine::m_currentGroupId
MHOctetString m_currentGroupId
Definition: Engine.h:209
MHEngine::m_context
MHContext * m_context
Definition: Engine.h:211
MHEngine::GetDefaultStreamCHook
int GetDefaultStreamCHook()
Definition: Engine.cpp:1474
MHEngine::GetGroupId
MHOctetString & GetGroupId()
Definition: Engine.h:153
MHEngine::RemoveFromDisplayStack
void RemoveFromDisplayStack(MHVisible *pVis)
Definition: Engine.cpp:760
MHEngine::Redraw
void Redraw(const QRegion &region)
Definition: Engine.cpp:929
MHEngine::CancelExternalContentRequest
void CancelExternalContentRequest(MHIngredient *pRequester)
Definition: Engine.cpp:1061
MHEngine::EventTriggered
void EventTriggered(MHRoot *pSource, enum EventType ev)
Definition: Engine.h:94
MHEngine::~MHEngine
~MHEngine() override
Definition: Engine.cpp:59
MHEngine::CheckLinks
void CheckLinks(const MHObjectRef &sourceRef, enum EventType ev, const MHUnion &un)
Definition: Engine.cpp:717
MHEngine::GetDefaultBitmapCHook
int GetDefaultBitmapCHook()
Definition: Engine.cpp:1485
MHUnion
Definition: BaseClasses.h:283
MHEngine::InTransition
bool InTransition() const
Definition: Engine.h:135
EventType
EventType
Definition: Root.h:33
feature
static const std::array< featureStruct, 7 > feature
Definition: audiooutputsettings.cpp:434
hardwareprofile.config.p
p
Definition: config.py:33
MHEngine::GetDefaultHighlightRefColour
void GetDefaultHighlightRefColour(MHColour &colour)
Definition: Engine.cpp:1435
MHEngine::LockScreen
void LockScreen()
Definition: Engine.h:110
MHEngine::PutBefore
void PutBefore(const MHRoot *pVis, const MHRoot *pRef)
Definition: Engine.cpp:813
MHEngine::FindObject
MHRoot * FindObject(const MHObjectRef &oRef, bool failOnNotFound=true)
Definition: Engine.cpp:585
MHColour
Definition: BaseClasses.h:139
MHEngine::GetDefaultTextCHook
int GetDefaultTextCHook()
Definition: Engine.cpp:1463
MHExternContent::m_time
QElapsedTimer m_time
Definition: Engine.h:67
MHScene
Definition: Groups.h:88
MHApplication::m_tuneInfo
int m_tuneInfo
Definition: Groups.h:142
MHEngine::m_applicationStack
QStack< MHApplication * > m_applicationStack
Definition: Engine.h:175
MHEngine::GetInteraction
MHInteractible * GetInteraction(void)
Definition: Engine.h:161
MHApplication::m_nLockCount
int m_nLockCount
Definition: Groups.h:145
Ingredients.h
MHEngine::SetBooting
void SetBooting() override
Definition: Engine.h:77
MHEngine::GetDefaultTextColour
void GetDefaultTextColour(MHColour &colour)
Definition: Engine.cpp:1407
MHEngine::TransitionToScene
void TransitionToScene(const MHObjectRef &target)
Definition: Engine.cpp:420
MHIngredient
Definition: Ingredients.h:33
MHEngine::AddActions
void AddActions(const MHActionSequence &actions)
Definition: Engine.cpp:735
MHEngine::AddToDisplayStack
void AddToDisplayStack(MHVisible *pVis)
Definition: Engine.cpp:745
MHEngine::GetDefaultFontAttrs
void GetDefaultFontAttrs(MHOctetString &str)
Definition: Engine.cpp:1496
MHEngine::m_actionStack
QStack< MHElemAction * > m_actionStack
Definition: Engine.h:189
Root.h
MHEngine::GenerateUserAction
void GenerateUserAction(int nCode) override
Definition: Engine.cpp:948
MHPSEntry::m_Data
MHOwnPtrSequence< MHUnion > m_Data
Definition: Engine.h:59
MHPSEntry
Definition: Engine.h:55
MHEngine::m_redrawRegion
QRegion m_redrawRegion
Definition: Engine.h:172
MHVisible
Definition: Visible.h:35
MHEngine::m_externContentTable
QList< MHExternContent * > m_externContentTable
Definition: Engine.h:200
MHEngine::UnlockScreen
void UnlockScreen()
Definition: Engine.cpp:935
MHEngine::CurrentApp
MHApplication * CurrentApp()
Definition: Engine.h:176
MHEngine::GetDefaultCharSet
int GetDefaultCharSet()
Definition: Engine.cpp:1382
BaseClasses.h
MHEngine::Spawn
void Spawn(const MHObjectRef &target)
Definition: Engine.h:85
MHActionSequence
Definition: Actions.h:28
MHContext
Definition: freemheg.h:98
MHEngine::GetTuneInfo
int GetTuneInfo()
Definition: Engine.h:164
MHEngine::EngineEvent
void EngineEvent(int nCode) override
Definition: Engine.cpp:988
MHEngine::StreamStarted
void StreamStarted(MHStream *stream, bool bStarted) override
Definition: Engine.cpp:996
MHPSEntry::MHPSEntry
MHPSEntry()=default
MHEngine::SetInputRegister
void SetInputRegister(int nReg)
Definition: Engine.cpp:528
MHEngine::LoadStorePersistent
bool LoadStorePersistent(bool fIsLoad, const MHOctetString &fileName, const MHSequence< MHObjectRef * > &variables)
Definition: Engine.cpp:1143
MHEG
Definition: freemheg.h:54
freemheg.h
MHEngine::BringToFront
void BringToFront(const MHRoot *pVis)
Definition: Engine.cpp:777
MHEngine::PutBehind
void PutBehind(const MHRoot *pVis, const MHRoot *pRef)
Definition: Engine.cpp:847
MHEngine::SetInteraction
void SetInteraction(MHInteractible *p)
Definition: Engine.h:162
MHExternContent::m_pRequester
MHIngredient * m_pRequester
Definition: Engine.h:66
MHEngine::m_fInTransition
bool m_fInTransition
Definition: Engine.h:205
MHAsynchEvent::m_pEventSource
MHRoot * m_pEventSource
Definition: Engine.h:47
MHEngine::RemoveLink
void RemoveLink(MHLink *pLink)
Definition: Engine.cpp:729
MHEngine::DrawRegion
void DrawRegion(const QRegion &toDraw, int nStackPos)
Definition: Engine.cpp:881
MHExternContent
Definition: Engine.h:63
MHEngine::m_persistentStore
MHOwnPtrSequence< MHPSEntry > m_persistentStore
Definition: Engine.h:203
MHEngine::Quit
void Quit()
Definition: Engine.cpp:378
MHEngine::m_linkTable
QList< MHLink * > m_linkTable
Definition: Engine.h:196
MHEngine::RunActions
void RunActions()
Definition: Engine.cpp:625
MHEngine::BootApplication
void BootApplication(const char *fileName)
MHOwnPtrSequence< MHUnion >
EventIsAvailable
@ EventIsAvailable
Definition: Root.h:34
MHEngine::CheckContentRequests
void CheckContentRequests()
Definition: Engine.cpp:1082
MHEngine::GetEngineSupport
bool GetEngineSupport(const MHOctetString &feature)
Definition: Engine.cpp:1225
MHInteractible
Definition: Visible.h:138
MHRoot
Definition: Root.h:44
MHEngine::Launch
bool Launch(const MHObjectRef &target, bool fIsSpawn=false)
Definition: Engine.cpp:274