MythTV  master
Ingredients.cpp
Go to the documentation of this file.
1 /* Ingredients.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 "Ingredients.h"
23 #include "Root.h"
24 #include "BaseClasses.h"
25 #include "ParseNode.h"
26 #include "ASN1Codes.h"
27 #include "Actions.h"
28 #include "Engine.h"
29 #include "Logging.h"
30 
31 
32 // Copy constructor for cloning.
34 {
35  // Don't copy the object reference since that's set separately.
38  m_contentType = ref.m_contentType;
43  m_fShared = ref.m_fShared;
45  m_nCCPrio = ref.m_nCCPrio;
46 }
47 
48 
50 {
51  MHRoot::Initialise(p, engine);
52  MHParseNode *pIA = p->GetNamedArg(C_INITIALLY_ACTIVE);
53 
54  if (pIA)
55  {
57  }
58 
59  MHParseNode *pCHook = p->GetNamedArg(C_CONTENT_HOOK);
60 
61  if (pCHook)
62  {
63  m_nContentHook = pCHook->GetArgN(0)->GetIntValue();
64  }
65 
66  MHParseNode *pOrigContent = p->GetNamedArg(C_ORIGINAL_CONTENT);
67 
68  if (pOrigContent)
69  {
70  MHParseNode *pArg = pOrigContent->GetArgN(0);
71 
72  // Either a string - included content.
74  {
75  m_contentType = IN_IncludedContent;
77  }
78  else // or a sequence - referenced content.
79  {
80  // In the text version this is tagged with :ContentRef
81  m_contentType = IN_ReferencedContent;
82  m_origContentRef.Initialise(pArg->GetArgN(0), engine);
83  MHParseNode *pContentSize = pArg->GetNamedArg(C_CONTENT_SIZE);
84 
85  if (pContentSize)
86  {
87  m_nOrigContentSize = pContentSize->GetArgN(0)->GetIntValue();
88  }
89 
91 
92  if (pCCPrio)
93  {
94  m_nOrigCCPrio = pCCPrio->GetArgN(0)->GetIntValue();
95  }
96  }
97  }
98 
99  MHParseNode *pShared = p->GetNamedArg(C_SHARED);
100 
101  if (pShared)
102  {
103  m_fShared = pShared->GetArgN(0)->GetBoolValue();
104  }
105 }
106 
107 void MHIngredient::PrintMe(FILE *fd, int nTabs) const
108 {
109  MHRoot::PrintMe(fd, nTabs);
110 
111  if (! m_fInitiallyActive)
112  {
113  PrintTabs(fd, nTabs);
114  fprintf(fd, ":InitiallyActive false\n");
115  }
116 
117  if (m_nContentHook != 0)
118  {
119  PrintTabs(fd, nTabs);
120  fprintf(fd, ":CHook %d\n", m_nContentHook);
121  }
122 
123  // Original content
124  if (m_contentType == IN_IncludedContent)
125  {
126  PrintTabs(fd, nTabs);
127  fprintf(fd, ":OrigContent ");
128  m_origIncludedContent.PrintMe(fd, nTabs + 1);
129  fprintf(fd, "\n");
130  }
131  else if (m_contentType == IN_ReferencedContent)
132  {
133  PrintTabs(fd, nTabs);
134  fprintf(fd, ":OrigContent (");
135  m_origContentRef.PrintMe(fd, nTabs + 1);
136 
137  if (m_nOrigContentSize)
138  {
139  fprintf(fd, " :ContentSize %d", m_nOrigContentSize);
140  }
141 
142  if (m_nOrigCCPrio != 127)
143  {
144  fprintf(fd, " :CCPriority %d", m_nOrigCCPrio);
145  }
146 
147  fprintf(fd, " )\n");
148  }
149 
150  if (m_fShared)
151  {
152  PrintTabs(fd, nTabs);
153  fprintf(fd, ":Shared true\n");
154  }
155 }
156 
157 
158 // Prepare the object as for the parent.
160 {
161  if (m_fAvailable)
162  {
163  return;
164  }
165 
166  // Initialise the content information if any.
171  // Prepare the base class.
172  MHRoot::Preparation(engine);
173 }
174 
176 {
177  engine->CancelExternalContentRequest(this);
178  MHRoot::Destruction(engine);
179 }
180 
182 {
183  if (m_contentType == IN_IncludedContent)
184  {
185  // Included content is there - generate ContentAvailable.
186  engine->EventTriggered(this, EventContentAvailable);
187  }
188  else if (m_contentType == IN_ReferencedContent)
189  {
190  // We are requesting external content
191  engine->CancelExternalContentRequest(this);
192  engine->RequestExternalContent(this);
193  }
194 }
195 
196 // Provide updated content.
197 void MHIngredient::SetData(const MHOctetString &included, MHEngine *engine)
198 {
199  // If the content is currently Included then the data should be Included
200  // and similarly for Referenced content. I've seen cases where SetData
201  // with included content has been used erroneously with the intention that
202  // this should be the file name for referenced content.
203  if (m_contentType == IN_ReferencedContent)
204  {
205  m_contentRef.m_contentRef.Copy(included);
206  }
207  else if (m_contentType == IN_IncludedContent)
208  {
209  m_includedContent.Copy(included);
210 
211  }
212  else
213  {
214  MHLOG(MHLogWarning, "SetData with no content"); // MHEG Error
215  }
216 
217  ContentPreparation(engine);
218 }
219 
220 void MHIngredient::SetData(const MHContentRef &referenced, bool /*fSizeGiven*/, int size, bool fCCGiven, int /*cc*/, MHEngine *engine)
221 {
222  if (m_contentType != IN_ReferencedContent)
223  {
224  MHERROR("SetData with referenced content applied to an ingredient without referenced content");
225  }
226 
227  m_contentRef.Copy(referenced);
228  m_nContentSize = size;
229 
230  if (fCCGiven)
231  {
233  }
234 
235  ContentPreparation(engine);
236 }
237 
238 // Font
240 {
241  MHIngredient::Initialise(p, engine);
242  //
243 }
244 
245 void MHFont::PrintMe(FILE *fd, int nTabs) const
246 {
247  PrintTabs(fd, nTabs);
248  fprintf(fd, "{:Font");
249  MHIngredient::PrintMe(fd, nTabs + 1);
250  fprintf(fd, "****TODO\n");
251  PrintTabs(fd, nTabs);
252  fprintf(fd, "}\n");
253 }
254 
255 
256 // CursorShape
257 
259 {
260  MHIngredient::Initialise(p, engine);
261  //
262 }
263 
264 void MHCursorShape::PrintMe(FILE *fd, int nTabs) const
265 {
266  PrintTabs(fd, nTabs);
267  fprintf(fd, "{:CursorShape");
268  MHIngredient::PrintMe(fd, nTabs + 1);
269  fprintf(fd, "****TODO\n");
270  PrintTabs(fd, nTabs);
271  fprintf(fd, "}\n");
272 }
273 
274 // Palette
275 
277 {
278  MHIngredient::Initialise(p, engine);
279  //
280 }
281 
282 void MHPalette::PrintMe(FILE *fd, int nTabs) const
283 {
284  PrintTabs(fd, nTabs);
285  fprintf(fd, "{:Palette");
286  MHIngredient::PrintMe(fd, nTabs + 1);
287  fprintf(fd, "****TODO\n");
288  PrintTabs(fd, nTabs);
289  fprintf(fd, "}\n");
290 }
291 
293 {
294  MHElemAction::Initialise(p, engine); // Target
295  MHParseNode *pContent = p->GetArgN(1);
296 
297  if (pContent->m_nNodeType == MHParseNode::PNSeq)
298  {
299  // Referenced content.
300  m_fIsIncluded = false;
302  m_referenced.Initialise(pContent->GetSeqN(0), engine);
303 
304  if (pContent->GetSeqCount() > 1)
305  {
306  MHParseNode *pArg = pContent->GetSeqN(1);
307 
309  {
310  MHParseNode *pVal = pArg->GetArgN(0);
311 
312  // It may be NULL as a place-holder
313  if (pVal->m_nNodeType == MHParseNode::PNInt)
314  {
315  m_fSizePresent = true;
316  m_contentSize.Initialise(pVal, engine);
317  }
318  }
319  }
320 
321  if (pContent->GetSeqCount() > 2)
322  {
323  MHParseNode *pArg = pContent->GetSeqN(2);
324 
326  {
327  MHParseNode *pVal = pArg->GetArgN(0);
328 
329  if (pVal->m_nNodeType == MHParseNode::PNInt)
330  {
331  m_fCCPriorityPresent = true;
332  m_ccPriority.Initialise(pVal, engine);
333  }
334  }
335  }
336  }
337  else
338  {
339  m_included.Initialise(pContent, engine);
340  m_fIsIncluded = true;
341  }
342 }
343 
344 void MHSetData::PrintArgs(FILE *fd, int /*nTabs*/) const
345 {
346  if (m_fIsIncluded)
347  {
348  m_included.PrintMe(fd, 0);
349  }
350  else
351  {
352  m_referenced.PrintMe(fd, 0);
353 
354  if (m_fSizePresent)
355  {
356  fprintf(fd, " :NewContentSize ");
357  m_contentSize.PrintMe(fd, 0);
358  }
359 
361  {
362  fprintf(fd, " :NewCCPriority ");
363  m_ccPriority.PrintMe(fd, 0);
364  }
365  }
366 }
367 
369 {
370  MHObjectRef target;
371  m_target.GetValue(target, engine); // Get the target
372 
373  if (m_fIsIncluded) // Included content
374  {
375  MHOctetString included;
376  m_included.GetValue(included, engine);
377  engine->FindObject(target)->SetData(included, engine);
378  }
379  else
380  {
381  MHContentRef referenced;
382  int size = 0;
383  int cc = 0;
384  m_referenced.GetValue(referenced, engine);
385 
386  if (m_fSizePresent)
387  {
388  size = m_contentSize.GetValue(engine);
389  }
390 
392  {
393  cc = m_ccPriority.GetValue(engine);
394  }
395 
396  engine->FindObject(target)->SetData(referenced, m_fSizePresent, size, m_fCCPriorityPresent, cc, engine);
397  }
398 }
399 
400 // Clone - make a copy of the target and set the object reference variable to the new object ref.
401 void MHClone::CallAction(MHEngine *engine, MHRoot *pTarget, MHRoot *pRef)
402 {
403  // We need to get the group (scene or application) that contains the target.
404  MHObjectRef groupRef;
405  groupRef.m_groupId.Copy(pTarget->m_ObjectReference.m_groupId);
406  groupRef.m_nObjectNo = 0; // The group always has object ref zero.
407  MHRoot *pGroup = engine->FindObject(groupRef);
408  // Get the group to make the clone and add it to its ingredients.
409  pGroup->MakeClone(pTarget, pRef, engine);
410 }
MHObjectRef
Definition: BaseClasses.h:153
MHFont::Initialise
void Initialise(MHParseNode *p, MHEngine *engine) override
Definition: Ingredients.cpp:239
MHParseNode::m_nNodeType
enum NodeType m_nNodeType
Definition: ParseNode.h:46
C_NEW_CONTENT_SIZE
#define C_NEW_CONTENT_SIZE
Definition: ASN1Codes.h:267
MHEngine::RequestExternalContent
void RequestExternalContent(MHIngredient *pRequester)
Definition: Engine.cpp:969
MHIngredient::MHIngredient
MHIngredient()=default
EventContentAvailable
@ EventContentAvailable
Definition: Root.h:33
MHIngredient::SetData
void SetData(const MHOctetString &included, MHEngine *engine) override
Definition: Ingredients.cpp:197
MHIngredient::Preparation
void Preparation(MHEngine *engine) override
Definition: Ingredients.cpp:159
MHRoot::m_fAvailable
bool m_fAvailable
Definition: Root.h:251
MHSetData::m_fSizePresent
bool m_fSizePresent
Definition: Ingredients.h:138
ASN1Codes.h
MHEngine
Definition: Engine.h:72
MHParseNode::GetIntValue
int GetIntValue()
Definition: ParseNode.cpp:170
MHObjectRef::m_groupId
MHOctetString m_groupId
Definition: BaseClasses.h:169
MHObjectRef::m_nObjectNo
int m_nObjectNo
Definition: BaseClasses.h:168
MHParseNode::GetSeqN
MHParseNode * GetSeqN(int n)
Definition: ParseNode.cpp:152
MHIngredient::Initialise
void Initialise(MHParseNode *p, MHEngine *engine) override
Definition: Ingredients.cpp:49
MHParseNode::PNTagged
@ PNTagged
Definition: ParseNode.h:41
MHIngredient::m_nCCPrio
int m_nCCPrio
Definition: Ingredients.h:80
cc
Definition: cc.h:10
MHGenericContentRef::PrintMe
void PrintMe(FILE *fd, int nTabs) const
Definition: BaseClasses.cpp:605
MHGenericInteger::Initialise
void Initialise(MHParseNode *p, MHEngine *engine)
Definition: BaseClasses.cpp:397
MHIngredient::m_includedContent
MHOctetString m_includedContent
Definition: Ingredients.h:77
MHIngredient::m_origIncludedContent
MHOctetString m_origIncludedContent
Definition: Ingredients.h:72
MHElemAction::Initialise
virtual void Initialise(MHParseNode *p, MHEngine *engine)
Definition: BaseActions.cpp:31
MHSetData::m_fCCPriorityPresent
bool m_fCCPriorityPresent
Definition: Ingredients.h:139
MHIngredient::ContentPreparation
void ContentPreparation(MHEngine *engine) override
Definition: Ingredients.cpp:181
MHSetData::m_ccPriority
MHGenericInteger m_ccPriority
Definition: Ingredients.h:143
MHOctetString
Definition: BaseClasses.h:107
Actions.h
mythburn.FILE
int FILE
Definition: mythburn.py:139
MHOctetString::PrintMe
void PrintMe(FILE *fd, int nTabs) const
Definition: BaseClasses.cpp:154
C_INITIALLY_ACTIVE
#define C_INITIALLY_ACTIVE
Definition: ASN1Codes.h:89
MHRoot::m_ObjectReference
MHObjectRef m_ObjectReference
Definition: Root.h:247
MHContentRef::Initialise
void Initialise(MHParseNode *p, MHEngine *engine)
Definition: BaseClasses.cpp:798
MHEngine::CancelExternalContentRequest
void CancelExternalContentRequest(MHIngredient *pRequester)
Definition: Engine.cpp:1028
MHEngine::EventTriggered
void EventTriggered(MHRoot *pSource, enum EventType ev)
Definition: Engine.h:94
MHIngredient::m_origContentRef
MHContentRef m_origContentRef
Definition: Ingredients.h:73
MHCursorShape::Initialise
void Initialise(MHParseNode *p, MHEngine *engine) override
Definition: Ingredients.cpp:258
hardwareprofile.config.p
p
Definition: config.py:33
MHParseNode::GetSeqCount
int GetSeqCount()
Definition: ParseNode.cpp:141
ParseNode.h
MHIngredient::m_nContentSize
int m_nContentSize
Definition: Ingredients.h:79
C_NEW_CONTENT_CACHE_PRIO
#define C_NEW_CONTENT_CACHE_PRIO
Definition: ASN1Codes.h:268
MHSetData::PrintArgs
void PrintArgs(FILE *fd, int nTabs) const override
Definition: Ingredients.cpp:344
MHIngredient::m_nOrigCCPrio
int m_nOrigCCPrio
Definition: Ingredients.h:75
PrintTabs
void PrintTabs(FILE *fd, int n)
Definition: ParseNode.cpp:34
MHGenericOctetString::GetValue
void GetValue(MHOctetString &str, MHEngine *engine) const
Definition: BaseClasses.cpp:505
MHParseNode::GetArgN
MHParseNode * GetArgN(int n)
Definition: ParseNode.cpp:78
MHSetData::m_contentSize
MHGenericInteger m_contentSize
Definition: Ingredients.h:142
C_SHARED
#define C_SHARED
Definition: ASN1Codes.h:92
MHCursorShape::PrintMe
void PrintMe(FILE *fd, int nTabs) const override
Definition: Ingredients.cpp:264
MHIngredient::PrintMe
void PrintMe(FILE *fd, int nTabs) const override
Definition: Ingredients.cpp:107
MHEngine::FindObject
MHRoot * FindObject(const MHObjectRef &oRef, bool failOnNotFound=true)
Definition: Engine.cpp:574
MHParseNode::GetTagNo
int GetTagNo()
Definition: ParseNode.cpp:49
MHSetData::m_fIsIncluded
bool m_fIsIncluded
Definition: Ingredients.h:137
C_CONTENT_CACHE_PRIORITY
#define C_CONTENT_CACHE_PRIORITY
Definition: ASN1Codes.h:94
MHPalette::Initialise
void Initialise(MHParseNode *p, MHEngine *engine) override
Definition: Ingredients.cpp:276
MHLOG
#define MHLOG(__level, __text)
Definition: Logging.h:36
MHFont::PrintMe
void PrintMe(FILE *fd, int nTabs) const override
Definition: Ingredients.cpp:245
MHGenericOctetString::PrintMe
void PrintMe(FILE *fd, int nTabs) const
Definition: BaseClasses.cpp:491
Engine.h
MHLogWarning
@ MHLogWarning
Definition: freemheg.h:66
MHGenericContentRef::Initialise
void Initialise(MHParseNode *p, MHEngine *engine)
Definition: BaseClasses.cpp:586
Ingredients.h
MHIngredient
Definition: Ingredients.h:34
MHRoot::Initialise
virtual void Initialise(MHParseNode *p, MHEngine *engine)
Definition: Root.cpp:30
MHIngredient::m_nOrigContentSize
int m_nOrigContentSize
Definition: Ingredients.h:74
MHGenericOctetString::Initialise
void Initialise(MHParseNode *p, MHEngine *engine)
Definition: BaseClasses.cpp:476
MHParseNode::GetNamedArg
MHParseNode * GetNamedArg(int nTag)
Definition: ParseNode.cpp:110
MHIngredient::m_fShared
bool m_fShared
Definition: Ingredients.h:68
MHParseNode::PNSeq
@ PNSeq
Definition: ParseNode.h:41
MHParseNode::GetBoolValue
bool GetBoolValue()
Definition: ParseNode.cpp:192
Root.h
MHRoot::PrintMe
virtual void PrintMe(FILE *fd, int nTabs) const
Definition: Root.cpp:38
MHContentRef
Definition: BaseClasses.h:174
MHContentRef::m_contentRef
MHOctetString m_contentRef
Definition: BaseClasses.h:188
MHRoot::Preparation
virtual void Preparation(MHEngine *engine)
Definition: Root.cpp:52
MHIngredient::IN_ReferencedContent
@ IN_ReferencedContent
Definition: Ingredients.h:71
MHPalette::PrintMe
void PrintMe(FILE *fd, int nTabs) const override
Definition: Ingredients.cpp:282
MHSetData::Perform
void Perform(MHEngine *engine) override
Definition: Ingredients.cpp:368
BaseClasses.h
C_CONTENT_HOOK
#define C_CONTENT_HOOK
Definition: ASN1Codes.h:90
C_CONTENT_SIZE
#define C_CONTENT_SIZE
Definition: ASN1Codes.h:93
MHParseNode
Definition: ParseNode.h:39
C_ORIGINAL_CONTENT
#define C_ORIGINAL_CONTENT
Definition: ASN1Codes.h:91
MHIngredient::Destruction
void Destruction(MHEngine *engine) override
Definition: Ingredients.cpp:175
MHGenericInteger::GetValue
int GetValue(MHEngine *engine) const
Definition: BaseClasses.cpp:426
MHRoot::SetData
virtual void SetData(const MHOctetString &, MHEngine *)
Definition: Root.h:88
MHClone::CallAction
void CallAction(MHEngine *engine, MHRoot *pTarget, MHRoot *pRef) override
Definition: Ingredients.cpp:401
MHElemAction::m_target
MHGenericObjectRef m_target
Definition: BaseActions.h:46
MHParseNode::GetStringValue
void GetStringValue(MHOctetString &str)
Definition: ParseNode.cpp:203
MHRoot::MakeClone
virtual void MakeClone(MHRoot *, MHRoot *, MHEngine *)
Definition: Root.h:82
MHGenericInteger::PrintMe
void PrintMe(FILE *fd, int nTabs) const
Definition: BaseClasses.cpp:412
MHParseNode::PNString
@ PNString
Definition: ParseNode.h:41
MHSetData::m_referenced
MHGenericContentRef m_referenced
Definition: Ingredients.h:141
MHERROR
#define MHERROR(__text)
Definition: Logging.h:42
Logging.h
MHSetData::m_included
MHGenericOctetString m_included
Definition: Ingredients.h:140
MHGenericObjectRef::GetValue
void GetValue(MHObjectRef &ref, MHEngine *engine) const
Definition: BaseClasses.cpp:568
MHGenericContentRef::GetValue
void GetValue(MHContentRef &ref, MHEngine *engine) const
Definition: BaseClasses.cpp:619
MHIngredient::m_fInitiallyActive
bool m_fInitiallyActive
Definition: Ingredients.h:65
MHSetData::Initialise
void Initialise(MHParseNode *p, MHEngine *engine) override
Definition: Ingredients.cpp:292
MHIngredient::m_nContentHook
int m_nContentHook
Definition: Ingredients.h:66
MHContentRef::PrintMe
void PrintMe(FILE *fd, int nTabs) const
Definition: BaseClasses.h:181
MHContentRef::Copy
void Copy(const MHContentRef &cr)
Definition: BaseClasses.h:182
MHRoot::Destruction
virtual void Destruction(MHEngine *engine)
Definition: Root.cpp:97
MHParseNode::PNInt
@ PNInt
Definition: ParseNode.h:41
MHIngredient::m_contentRef
MHContentRef m_contentRef
Definition: Ingredients.h:78
MHOctetString::Copy
void Copy(const MHOctetString &str)
Definition: BaseClasses.cpp:131
MHIngredient::IN_IncludedContent
@ IN_IncludedContent
Definition: Ingredients.h:71
MHRoot
Definition: Root.h:44