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