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\"")
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 {
127  MHElemAction::Initialise(p, engine);
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 }
MHRoot::Activation
virtual void Activation(MHEngine *engine)
Definition: Root.cpp:70
MHObjectRef
Definition: BaseClasses.h:156
MHObjectRef::Initialise
void Initialise(MHParseNode *p, MHEngine *engine)
Definition: BaseClasses.cpp:278
MHRoot::Deactivation
virtual void Deactivation(MHEngine *engine)
Definition: Root.cpp:86
MHRoot::m_fAvailable
bool m_fAvailable
Definition: Root.h:251
MHEngine
Definition: Engine.h:72
MHObjectRef::m_nObjectNo
int m_nObjectNo
Definition: BaseClasses.h:172
MHRoot::SetVariableValue
virtual void SetVariableValue(const MHUnion &)
Definition: Root.h:108
MHElemAction::Initialise
virtual void Initialise(MHParseNode *p, MHEngine *engine)
Definition: BaseActions.cpp:31
EventIsAvailable
@ EventIsAvailable
Definition: Root.h:33
mythburn.FILE
int FILE
Definition: mythburn.py:139
MHRoot::ContentPreparation
virtual void ContentPreparation(MHEngine *)
Definition: Root.h:66
MHRoot::m_fRunning
bool m_fRunning
Definition: Root.h:252
MHRoot::m_ObjectReference
MHObjectRef m_ObjectReference
Definition: Root.h:247
MHRoot::FindByObjectNo
virtual MHRoot * FindByObjectNo(int n)
Definition: Root.cpp:116
MHGetAvailabilityStatus::Initialise
void Initialise(MHParseNode *p, MHEngine *engine) override
Definition: Root.cpp:125
MHGetAvailabilityStatus::m_rsultVar
MHObjectRef m_rsultVar
Definition: Root.h:267
MHEngine::EventTriggered
void EventTriggered(MHRoot *pSource, enum EventType ev)
Definition: Engine.h:94
hardwareprofile.config.p
p
Definition: config.py:33
ParseNode.h
EventIsDeleted
@ EventIsDeleted
Definition: Root.h:33
MHEngine::FindObject
MHRoot * FindObject(const MHObjectRef &oRef, bool failOnNotFound=true)
Definition: Engine.cpp:573
MHLOG
#define MHLOG(__level, __text)
Definition: Logging.h:36
Engine.h
MHRoot::ClassName
virtual const char * ClassName()=0
EventIsStopped
@ EventIsStopped
Definition: Root.h:33
MHLogWarning
@ MHLogWarning
Definition: freemheg.h:72
Ingredients.h
MHRoot::Initialise
virtual void Initialise(MHParseNode *p, MHEngine *engine)
Definition: Root.cpp:30
MHRoot::InvalidAction
void InvalidAction(const char *actionName)
Definition: Root.cpp:45
Root.h
MHRoot::PrintMe
virtual void PrintMe(FILE *fd, int nTabs) const
Definition: Root.cpp:38
MHRoot::Preparation
virtual void Preparation(MHEngine *engine)
Definition: Root.cpp:53
BaseClasses.h
MHRoot::GetAvailabilityStatus
virtual bool GetAvailabilityStatus()
Definition: Root.h:75
MHParseNode
Definition: ParseNode.h:38
MHElemAction::m_target
MHGenericObjectRef m_target
Definition: BaseActions.h:46
Logging.h
MHGenericObjectRef::GetValue
void GetValue(MHObjectRef &ref, MHEngine *engine) const
Definition: BaseClasses.cpp:562
MHGetAvailabilityStatus::Perform
void Perform(MHEngine *engine) override
Definition: Root.cpp:131
MHRoot::Destruction
virtual void Destruction(MHEngine *engine)
Definition: Root.cpp:98
MHObjectRef::PrintMe
void PrintMe(FILE *fd, int nTabs) const
Definition: BaseClasses.cpp:299
MHRoot
Definition: Root.h:43