MythTV master
Root.cpp
Go to the documentation of this file.
1/* Root.cpp
2
3 Copyright (C) David C. J. Matthews 2004 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#include "Root.h"
23#include "ParseNode.h"
24#include "BaseClasses.h"
25#include "Ingredients.h"
26#include "Engine.h"
27#include "Logging.h"
28
29// Initialise the root class from the parse tree.
31{
32 MHParseNode *pArg = p->GetArgN(0); // The first argument should be present.
33 // Extract the field.
34 m_ObjectReference.Initialise(pArg, engine);
35}
36
37// Print the contents, in this case just the object reference.
38void MHRoot::PrintMe(FILE *fd, int nTabs) const
39{
40 m_ObjectReference.PrintMe(fd, nTabs);
41 fprintf(fd, "\n");
42}
43
44// An action was attempted on an object of a class which doesn't support this.
45void MHRoot::InvalidAction(const char *actionName)
46{
47 MHLOG(MHLogWarning, QString("WARN Action \"%1\" is not understood by class \"%2\"")
48 .arg(actionName, ClassName()));
49 throw "Invalid Action";
50}
51
52// Preparation - sets up the run-time representation. Sets m_fAvailable and generates IsAvailable event.
54{
55 if (m_fAvailable)
56 {
57 return; // Already prepared
58 }
59
60 // Retrieve object
61 // Set the internal attributes.
62 m_fAvailable = true;
63 engine->EventTriggered(this, EventIsAvailable);
64 // When the content becomes available generate EventContentAvailable. This is not
65 // generated if an object has no Content.
66 ContentPreparation(engine);
67}
68
69// Activation - starts running the object. Sets m_fRunning and generates IsRunning event.
71{
72 if (m_fRunning)
73 {
74 return; // Already running.
75 }
76
77 if (! m_fAvailable)
78 {
79 Preparation(engine); // Prepare it if that hasn't already been done.
80 }
81
82 // The subclasses are responsible for setting m_fRunning and generating IsRunning.
83}
84
85// Deactivation - stops running the object. Clears m_fRunning
87{
88 if (! m_fRunning)
89 {
90 return; // Already stopped.
91 }
92
93 m_fRunning = false;
94 engine->EventTriggered(this, EventIsStopped);
95}
96
97// Destruction - deletes the run-time representation. Clears m_fAvailable.
99{
100 if (! m_fAvailable)
101 {
102 return; // Already destroyed or never prepared.
103 }
104
105 if (m_fRunning)
106 {
107 Deactivation(engine); // Deactivate it if it's still running.
108 }
109
110 // We're supposed to wait until it's stopped here.
111 m_fAvailable = false;
112 engine->EventTriggered(this, EventIsDeleted);
113}
114
115// Return this object if it matches.
117{
119 {
120 return this;
121 }
122 return nullptr;
123}
124
126{
128 m_rsultVar.Initialise(p->GetArgN(1), engine);
129}
130
132{
133 // This is a special case. If the object does not exist we set the result to false.
134 MHObjectRef target;
135 m_target.GetValue(target, engine); // Get the target
136 MHRoot *pObject = engine->FindObject(target, false);
137 bool fResult = false; // Default result.
138
139 if (pObject)
140 {
141 fResult = pObject->GetAvailabilityStatus();
142 }
143
144 engine->FindObject(m_rsultVar)->SetVariableValue(fResult);
145}
#define MHLOG(__level, __text)
Definition: Logging.h:36
@ EventIsDeleted
Definition: Root.h:34
@ EventIsAvailable
Definition: Root.h:34
@ EventIsStopped
Definition: Root.h:34
virtual void Initialise(MHParseNode *p, MHEngine *engine)
Definition: BaseActions.cpp:31
MHGenericObjectRef m_target
Definition: BaseActions.h:46
MHRoot * FindObject(const MHObjectRef &oRef, bool failOnNotFound=true)
Definition: Engine.cpp:574
void EventTriggered(MHRoot *pSource, enum EventType ev)
Definition: Engine.h:94
void GetValue(MHObjectRef &ref, MHEngine *engine) const
MHObjectRef m_rsultVar
Definition: Root.h:268
void Initialise(MHParseNode *p, MHEngine *engine) override
Definition: Root.cpp:125
void Perform(MHEngine *engine) override
Definition: Root.cpp:131
void PrintMe(FILE *fd, int nTabs) const
void Initialise(MHParseNode *p, MHEngine *engine)
Definition: Root.h:45
virtual void Initialise(MHParseNode *p, MHEngine *engine)
Definition: Root.cpp:30
virtual void Activation(MHEngine *engine)
Definition: Root.cpp:70
void InvalidAction(const char *actionName)
Definition: Root.cpp:45
virtual void Destruction(MHEngine *engine)
Definition: Root.cpp:98
virtual void ContentPreparation(MHEngine *)
Definition: Root.h:67
MHObjectRef m_ObjectReference
Definition: Root.h:248
virtual bool GetAvailabilityStatus()
Definition: Root.h:76
virtual void Deactivation(MHEngine *engine)
Definition: Root.cpp:86
virtual void Preparation(MHEngine *engine)
Definition: Root.cpp:53
bool m_fRunning
Definition: Root.h:253
virtual const char * ClassName()=0
virtual void PrintMe(FILE *fd, int nTabs) const
Definition: Root.cpp:38
bool m_fAvailable
Definition: Root.h:252
virtual MHRoot * FindByObjectNo(int n)
Definition: Root.cpp:116
virtual void SetVariableValue(const MHUnion &)
Definition: Root.h:109
@ MHLogWarning
Definition: freemheg.h:78
int FILE
Definition: mythburn.py:138