MythTV  0.26-pre
Engine.h
Go to the documentation of this file.
00001 /* Engine.h
00002 
00003    Copyright (C)  David C. J. Matthews 2004, 2008  dm at prolingua.co.uk
00004 
00005    This program is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU General Public License
00007    as published by the Free Software Foundation; either version 2
00008    of the License, or (at your option) any later version.
00009 
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013    GNU General Public License for more details.
00014 
00015    You should have received a copy of the GNU General Public License
00016    along with this program; if not, write to the Free Software
00017    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00018    Or, point your browser to http://www.gnu.org/copyleft/gpl.html
00019 
00020 */
00021 
00022 #if !defined(ENGINE_H)
00023 #define ENGINE_H
00024 
00025 #include "freemheg.h"
00026 #include "Root.h"
00027 #include "Ingredients.h"
00028 #include "BaseClasses.h"
00029 #include "Groups.h"
00030 #include "Visible.h"
00031 #include "Actions.h"
00032 #include "Link.h"
00033 #include <QString>
00034 #include <QRect>
00035 #include <QRegion>
00036 #include <QList>
00037 #include <QStack>
00038 #include <QQueue>
00039 #include <QTime>
00040 
00041 class MHDLADisplay;
00042 
00043 // Asynchronous event data.
00044 class MHAsynchEvent {
00045   public:
00046     MHRoot *pEventSource;
00047     enum EventType eventType;
00048     MHUnion eventData;
00049 };
00050 
00051 // Entry in the "persistent" store.  At the moment it's not really persistent.
00052 // The UK MHEG profile says we shouldn't store type information.  That complicates
00053 // the code so for the moment we do.
00054 class MHPSEntry {
00055   public:
00056     MHPSEntry() {}
00057     MHOctetString m_FileName;
00058     MHOwnPtrSequence <MHUnion> m_Data;
00059 };
00060 
00061 // Entry in the pending external content list.
00062 class MHExternContent {
00063   public:
00064     QString m_FileName;
00065     MHIngredient *m_pRequester; 
00066     QTime m_time;
00067 };
00068 
00069 class MHInteractible;
00070 
00071 class MHEngine: public MHEG {
00072   public:
00073     MHEngine(MHContext *context);
00074     virtual ~MHEngine();
00075 
00076     virtual void SetBooting() { m_fBooting = true; }
00077 
00078     virtual void DrawDisplay(QRegion toDraw);
00079 
00080     void BootApplication(const char *fileName);
00081     void TransitionToScene(const MHObjectRef &);
00082     bool Launch(const MHObjectRef &target, bool fIsSpawn=false);
00083     void Spawn(const MHObjectRef &target) { Launch(target, true); }
00084     void Quit();
00085 
00086     // Look up an object by its object reference.  In nearly all cases we want to throw
00087     // an exception if it isn't found.  In a very few cases where we don't fail this
00088     // returns NULL if it isn't there.
00089     MHRoot *FindObject(const MHObjectRef &objr, bool failOnNotFound = true);
00090 
00091     // Called when an event is triggered.  Either queues the event or finds a link that matches.
00092     void EventTriggered(MHRoot *pSource, enum EventType ev)
00093     { EventTriggered(pSource, ev , MHUnion()); }
00094     void EventTriggered(MHRoot *pSource, enum EventType, const MHUnion &evData);
00095 
00096     // Called when a link fires to add the actions to the action stack.
00097     void AddActions(const MHActionSequence &actions);
00098 
00099     // Display stack and draw functions.
00100     void AddToDisplayStack(MHVisible *pVis);
00101     void RemoveFromDisplayStack(MHVisible *pVis);
00102     void Redraw(QRegion region); // Request a redraw.
00103     // Functions to alter the Z-order.
00104     void BringToFront(const MHRoot *pVis);
00105     void SendToBack(const MHRoot *pVis);
00106     void PutBefore(const MHRoot *pVis, const MHRoot *pRef);
00107     void PutBehind(const MHRoot *pVis, const MHRoot *pRef);
00108     void LockScreen() { CurrentApp()->m_nLockCount++; }
00109     void UnlockScreen();
00110 
00111     // Run synchronous actions and process any asynchronous events until the queues are empty.
00112     // Returns the number of milliseconds until wake-up or 0 if none.
00113     virtual int RunAll(void);
00114 
00115     // Run synchronous actions.
00116     void RunActions();
00117     // Generate a UserAction event i.e. a key press.
00118     virtual void GenerateUserAction(int nCode);
00119     virtual void EngineEvent(int nCode);
00120 
00121     // Called from an ingredient to request a load of external content.
00122     void RequestExternalContent(MHIngredient *pRequester);
00123     void CancelExternalContentRequest(MHIngredient *pRequester);
00124 
00125     // Load from or store to the persistent store.
00126     bool LoadStorePersistent(bool fIsLoad, const MHOctetString &fileName, const MHSequence<MHObjectRef *> &variables);
00127 
00128     // Add and remove links to and from the active link table.
00129     void AddLink(MHLink *pLink);
00130     void RemoveLink(MHLink *pLink);
00131 
00132     bool InTransition() { return m_fInTransition; }
00133 
00134     bool GetEngineSupport(const MHOctetString &feature);
00135 
00136     // Get the various defaults.  These are extracted from the current app or the (UK) MHEG defaults.
00137     int GetDefaultCharSet();
00138     void GetDefaultBGColour(MHColour &colour);
00139     void GetDefaultTextColour(MHColour &colour);
00140     void GetDefaultButtonRefColour(MHColour &colour);
00141     void GetDefaultHighlightRefColour(MHColour &colour);
00142     void GetDefaultSliderRefColour(MHColour &colour);
00143     int GetDefaultTextCHook();
00144     int GetDefaultStreamCHook();
00145     int GetDefaultBitmapCHook();
00146 //  void GetDefaultFont(MHFontBody &font); // Not currently implemented
00147     void GetDefaultFontAttrs(MHOctetString &str);
00148     void SetInputRegister(int nReg);
00149 
00150     MHOctetString &GetGroupId() { return m_CurrentGroupId; }
00151     MHContext *GetContext() { return m_Context; }
00152 
00153     QString GetPathName(const MHOctetString &str); // Return a path relative to the home directory
00154 
00155     static const char *MHEGEngineProviderIdString;
00156 
00157     // Interaction: Set if an Interactible has the focus and is receiving key presses.
00158     MHInteractible *GetInteraction(void) { return m_Interacting; }
00159     void SetInteraction(MHInteractible *p) { m_Interacting = p; }
00160 
00161     int GetTuneInfo() { return CurrentApp() ? CurrentApp()->m_tuneinfo : 0; }
00162     void SetTuneInfo(int tuneinfo) { if (CurrentApp()) CurrentApp()->m_tuneinfo = tuneinfo; }
00163 
00164   protected:
00165     void CheckLinks(const MHObjectRef &sourceRef, enum EventType ev, const MHUnion &un);
00166     MHGroup *ParseProgram(QByteArray &text);
00167     void DrawRegion(QRegion toDraw, int nStackPos);
00168 
00169     QRegion m_redrawRegion; // The accumulation of repaints when the screen is locked.
00170 
00171     // Application stack and functions to get the current application and scene.
00172     QStack<MHApplication*> m_ApplicationStack;
00173     MHApplication *CurrentApp() {
00174         if (m_ApplicationStack.isEmpty())
00175             return NULL;
00176         else
00177             return m_ApplicationStack.top();
00178     }
00179     MHScene *CurrentScene() { return CurrentApp() == NULL ? NULL : CurrentApp()->m_pCurrentScene; }
00180 
00181     // Action stack.  Actions may generate synchronous events which fire links and add
00182     // new actions.  These new actions have to be processed before we continue with other
00183     // actions.
00184     QStack<MHElemAction*> m_ActionStack;
00185 
00186     // Asynchronous event queue.  Asynchronous events are added to this queue and handled
00187     // once the action stack is empty.
00188     QQueue<MHAsynchEvent*> m_EventQueue;
00189 
00190     // Active Link set.  Active links are included in this table.
00191     QList<MHLink*> m_LinkTable;
00192 
00193     // Pending external content.  If we have requested external content that has not yet arrived
00194     // we make an entry in this table.
00195     QList<MHExternContent*> m_ExternContentTable;
00196     void CheckContentRequests();
00197 
00198     MHOwnPtrSequence <MHPSEntry> m_PersistentStore;
00199 
00200     bool m_fInTransition; // If we get a TransitionTo, Quit etc during OnStartUp and OnCloseDown we ignore them.
00201 
00202     // To canonicalise the object ids we set this to the group id of the current scene or app
00203     // and use that wherever we get an object id without a group id.
00204     MHOctetString   m_CurrentGroupId;
00205 
00206     MHContext       *m_Context; // Pointer to the context providing drawing and other operations
00207     bool            m_fBooting;
00208 
00209     MHInteractible  *m_Interacting; // Set to current interactive object if any.
00210 };
00211 
00212 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends