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);
53 
54  if (pIA)
55  {
57  }
58 
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, cc = 0;
383  m_Referenced.GetValue(referenced, engine);
384 
385  if (m_fSizePresent)
386  {
387  size = m_ContentSize.GetValue(engine);
388  }
389 
391  {
392  cc = m_CCPriority.GetValue(engine);
393  }
394 
395  engine->FindObject(target)->SetData(referenced, m_fSizePresent, size, m_fCCPriorityPresent, cc, engine);
396  }
397 }
398 
399 // Clone - make a copy of the target and set the object reference variable to the new object ref.
400 void MHClone::CallAction(MHEngine *engine, MHRoot *pTarget, MHRoot *pRef)
401 {
402  // We need to get the group (scene or application) that contains the target.
403  MHObjectRef groupRef;
404  groupRef.m_GroupId.Copy(pTarget->m_ObjectReference.m_GroupId);
405  groupRef.m_nObjectNo = 0; // The group always has object ref zero.
406  MHRoot *pGroup = engine->FindObject(groupRef);
407  // Get the group to make the clone and add it to its ingredients.
408  pGroup->MakeClone(pTarget, pRef, engine);
409 }
void PrintMe(FILE *fd, int nTabs) const
Definition: BaseClasses.h:179
void Preparation(MHEngine *engine) override
virtual void Destruction(MHEngine *engine)
Definition: Root.cpp:97
void Initialise(MHParseNode *p, MHEngine *engine)
#define C_CONTENT_CACHE_PRIORITY
Definition: ASN1Codes.h:94
Definition: cc.h:13
int m_nOrigContentSize
Definition: Ingredients.h:74
void PrintMe(FILE *fd, int nTabs) const override
#define MHERROR(__text)
Definition: Logging.h:42
#define C_ORIGINAL_CONTENT
Definition: ASN1Codes.h:91
void PrintMe(FILE *fd, int nTabs) const override
void PrintMe(FILE *fd, int nTabs) const
MHGenericObjectRef m_Target
Definition: BaseActions.h:46
virtual void PrintMe(FILE *fd, int nTabs) const
Definition: Root.cpp:38
enum NodeType m_nNodeType
Definition: ParseNode.h:46
bool m_fAvailable
Definition: Root.h:207
void PrintMe(FILE *fd, int nTabs) const override
void RequestExternalContent(MHIngredient *pRequester)
Definition: Engine.cpp:969
int GetValue(MHEngine *engine) const
MHOctetString m_OrigIncludedContent
Definition: Ingredients.h:72
void GetValue(MHOctetString &str, MHEngine *engine) const
bool m_fInitiallyActive
Definition: Ingredients.h:65
int m_nContentHook
Definition: Ingredients.h:66
MHGenericInteger m_CCPriority
Definition: Ingredients.h:143
#define C_INITIALLY_ACTIVE
Definition: ASN1Codes.h:89
void Copy(const MHContentRef &cr)
Definition: BaseClasses.h:180
void GetValue(MHObjectRef &ref, MHEngine *engine) const
void Initialise(MHParseNode *p, MHEngine *engine) override
void ContentPreparation(MHEngine *engine) override
void PrintArgs(FILE *fd, int nTabs) const override
void PrintMe(FILE *fd, int nTabs) const override
void PrintTabs(FILE *fd, int n)
Definition: ParseNode.cpp:34
MHGenericOctetString m_Included
Definition: Ingredients.h:140
MHParseNode * GetSeqN(int n)
Definition: ParseNode.cpp:152
void Copy(const MHOctetString &str)
void Perform(MHEngine *engine) override
void Initialise(MHParseNode *p, MHEngine *engine) override
Definition: Ingredients.cpp:49
#define C_NEW_CONTENT_SIZE
Definition: ASN1Codes.h:267
int GetIntValue()
Definition: ParseNode.cpp:170
bool m_fShared
Definition: Ingredients.h:68
void CancelExternalContentRequest(MHIngredient *pRequester)
Definition: Engine.cpp:1028
#define C_SHARED
Definition: ASN1Codes.h:92
void EventTriggered(MHRoot *pSource, enum EventType ev)
Definition: Engine.h:93
void CallAction(MHEngine *engine, MHRoot *pTarget, MHRoot *pRef) override
MHGenericContentRef m_Referenced
Definition: Ingredients.h:141
#define C_CONTENT_HOOK
Definition: ASN1Codes.h:90
void Initialise(MHParseNode *p, MHEngine *engine)
void GetStringValue(MHOctetString &str)
Definition: ParseNode.cpp:203
MHParseNode * GetNamedArg(int nTag)
Definition: ParseNode.cpp:110
int m_nOrigCCPrio
Definition: Ingredients.h:75
void PrintMe(FILE *fd, int nTabs) const
MHIngredient()=default
int m_nContentSize
Definition: Ingredients.h:79
bool m_fCCPriorityPresent
Definition: Ingredients.h:139
bool m_fIsIncluded
Definition: Ingredients.h:137
Definition: Root.h:43
void Initialise(MHParseNode *p, MHEngine *engine) override
MHObjectRef m_ObjectReference
Definition: Root.h:203
int FILE
Definition: mythburn.py:110
void Initialise(MHParseNode *p, MHEngine *engine)
void SetData(const MHOctetString &included, MHEngine *engine) override
void Destruction(MHEngine *engine) override
MHOctetString m_IncludedContent
Definition: Ingredients.h:77
void PrintMe(FILE *fd, int nTabs) const
MHGenericInteger m_ContentSize
Definition: Ingredients.h:142
virtual void MakeClone(MHRoot *, MHRoot *, MHEngine *)
Definition: Root.h:81
virtual void Initialise(MHParseNode *p, MHEngine *engine)
Definition: Root.cpp:30
MHContentRef m_OrigContentRef
Definition: Ingredients.h:73
void Initialise(MHParseNode *p, MHEngine *engine)
MHRoot * FindObject(const MHObjectRef &oRef, bool failOnNotFound=true)
Definition: Engine.cpp:573
#define MHLOG(__level, __text)
Definition: Logging.h:36
virtual void Initialise(MHParseNode *p, MHEngine *engine)
Definition: BaseActions.cpp:31
int GetSeqCount()
Definition: ParseNode.cpp:141
MHOctetString m_ContentRef
Definition: BaseClasses.h:186
bool GetBoolValue()
Definition: ParseNode.cpp:192
#define C_CONTENT_SIZE
Definition: ASN1Codes.h:93
MHOctetString m_GroupId
Definition: BaseClasses.h:167
MHParseNode * GetArgN(int n)
Definition: ParseNode.cpp:78
int GetTagNo()
Definition: ParseNode.cpp:49
void Initialise(MHParseNode *p, MHEngine *engine) override
void Initialise(MHParseNode *p, MHEngine *engine) override
virtual void SetData(const MHOctetString &, MHEngine *)
Definition: Root.h:85
void GetValue(MHContentRef &ref, MHEngine *engine) const
#define C_NEW_CONTENT_CACHE_PRIO
Definition: ASN1Codes.h:268
void PrintMe(FILE *fd, int nTabs) const
bool m_fSizePresent
Definition: Ingredients.h:138
MHContentRef m_ContentRef
Definition: Ingredients.h:78
virtual void Preparation(MHEngine *engine)
Definition: Root.cpp:52