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.
38 void 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.
45 void MHRoot::InvalidAction(const char *actionName)
46 {
47  MHLOG(MHLogWarning, QString("WARN Action \"%1\" is not understood by class \"%2\"").arg(actionName).arg(ClassName()));
48  throw "Invalid Action";
49 }
50 
51 // Preparation - sets up the run-time representation. Sets m_fAvailable and generates IsAvailable event.
53 {
54  if (m_fAvailable)
55  {
56  return; // Already prepared
57  }
58 
59  // Retrieve object
60  // Set the internal attributes.
61  m_fAvailable = true;
62  engine->EventTriggered(this, EventIsAvailable);
63  // When the content becomes available generate EventContentAvailable. This is not
64  // generated if an object has no Content.
65  ContentPreparation(engine);
66 }
67 
68 // Activation - starts running the object. Sets m_fRunning and generates IsRunning event.
70 {
71  if (m_fRunning)
72  {
73  return; // Already running.
74  }
75 
76  if (! m_fAvailable)
77  {
78  Preparation(engine); // Prepare it if that hasn't already been done.
79  }
80 
81  // The subclasses are responsible for setting m_fRunning and generating IsRunning.
82 }
83 
84 // Deactivation - stops running the object. Clears m_fRunning
86 {
87  if (! m_fRunning)
88  {
89  return; // Already stopped.
90  }
91 
92  m_fRunning = false;
93  engine->EventTriggered(this, EventIsStopped);
94 }
95 
96 // Destruction - deletes the run-time representation. Clears m_fAvailable.
98 {
99  if (! m_fAvailable)
100  {
101  return; // Already destroyed or never prepared.
102  }
103 
104  if (m_fRunning)
105  {
106  Deactivation(engine); // Deactivate it if it's still running.
107  }
108 
109  // We're supposed to wait until it's stopped here.
110  m_fAvailable = false;
111  engine->EventTriggered(this, EventIsDeleted);
112 }
113 
114 // Return this object if it matches.
116 {
118  {
119  return this;
120  }
121  return nullptr;
122 }
123 
125 {
126  MHElemAction::Initialise(p, engine);
127  m_ResultVar.Initialise(p->GetArgN(1), engine);
128 }
129 
131 {
132  // This is a special case. If the object does not exist we set the result to false.
133  MHObjectRef target;
134  m_Target.GetValue(target, engine); // Get the target
135  MHRoot *pObject = engine->FindObject(target, false);
136  bool fResult = false; // Default result.
137 
138  if (pObject)
139  {
140  fResult = pObject->GetAvailabilityStatus();
141  }
142 
143  engine->FindObject(m_ResultVar)->SetVariableValue(fResult);
144 }
virtual void Destruction(MHEngine *engine)
Definition: Root.cpp:97
void PrintMe(FILE *fd, int nTabs) const
void Perform(MHEngine *engine) override
Definition: Root.cpp:130
virtual void SetVariableValue(const MHUnion &)
Definition: Root.h:101
MHGenericObjectRef m_Target
Definition: BaseActions.h:46
virtual MHRoot * FindByObjectNo(int n)
Definition: Root.cpp:115
virtual void PrintMe(FILE *fd, int nTabs) const
Definition: Root.cpp:38
void InvalidAction(const char *actionName)
Definition: Root.cpp:45
virtual void Activation(MHEngine *engine)
Definition: Root.cpp:69
bool m_fAvailable
Definition: Root.h:207
virtual void Deactivation(MHEngine *engine)
Definition: Root.cpp:85
virtual const char * ClassName()=0
void GetValue(MHObjectRef &ref, MHEngine *engine) const
MHObjectRef m_ResultVar
Definition: Root.h:223
virtual bool GetAvailabilityStatus()
Definition: Root.h:75
virtual void ContentPreparation(MHEngine *)
Definition: Root.h:66
void EventTriggered(MHRoot *pSource, enum EventType ev)
Definition: Engine.h:93
void Initialise(MHParseNode *p, MHEngine *engine) override
Definition: Root.cpp:124
Definition: Root.h:43
bool m_fRunning
Definition: Root.h:208
MHObjectRef m_ObjectReference
Definition: Root.h:203
int FILE
Definition: mythburn.py:110
virtual void Initialise(MHParseNode *p, MHEngine *engine)
Definition: Root.cpp:30
MHRoot * FindObject(const MHObjectRef &oRef, bool failOnNotFound=true)
Definition: Engine.cpp:575
#define MHLOG(__level, __text)
Definition: Logging.h:36
virtual void Initialise(MHParseNode *p, MHEngine *engine)
Definition: BaseActions.cpp:31
void Initialise(MHParseNode *p, MHEngine *engine)
MHParseNode * GetArgN(int n)
Definition: ParseNode.cpp:78
virtual void Preparation(MHEngine *engine)
Definition: Root.cpp:52