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
108void 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
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.
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.
198void 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 {
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
221void 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{
243 //
244}
245
246void 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{
262 //
263}
264
265void 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{
280 //
281}
282
283void 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 {
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
345void 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.
402void 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}
@ C_ORIGINAL_CONTENT
Definition: ASN1Codes.h:94
@ C_INITIALLY_ACTIVE
Definition: ASN1Codes.h:92
@ C_NEW_CONTENT_CACHE_PRIO
Definition: ASN1Codes.h:271
@ C_CONTENT_CACHE_PRIORITY
Definition: ASN1Codes.h:97
@ C_CONTENT_HOOK
Definition: ASN1Codes.h:93
@ C_SHARED
Definition: ASN1Codes.h:95
@ C_CONTENT_SIZE
Definition: ASN1Codes.h:96
@ C_NEW_CONTENT_SIZE
Definition: ASN1Codes.h:270
#define MHERROR(__text)
Definition: Logging.h:42
#define MHLOG(__level, __text)
Definition: Logging.h:36
void PrintTabs(FILE *fd, int n)
Definition: ParseNode.cpp:34
@ EventContentAvailable
Definition: Root.h:34
void CallAction(MHEngine *engine, MHRoot *pTarget, MHRoot *pRef) override
void Initialise(MHParseNode *p, MHEngine *engine)
MHOctetString m_contentRef
Definition: BaseClasses.h:189
void Copy(const MHContentRef &cr)
Definition: BaseClasses.h:183
void PrintMe(FILE *fd, int nTabs) const
Definition: BaseClasses.h:182
void PrintMe(FILE *fd, int nTabs) const override
void Initialise(MHParseNode *p, MHEngine *engine) override
virtual void Initialise(MHParseNode *p, MHEngine *engine)
Definition: BaseActions.cpp:31
MHGenericObjectRef m_target
Definition: BaseActions.h:46
MHRoot * FindObject(const MHObjectRef &oRef, bool failOnNotFound=true)
Definition: Engine.cpp:574
void RequestExternalContent(MHIngredient *pRequester)
Definition: Engine.cpp:999
void EventTriggered(MHRoot *pSource, enum EventType ev)
Definition: Engine.h:94
void CancelExternalContentRequest(MHIngredient *pRequester)
Definition: Engine.cpp:1064
void Initialise(MHParseNode *p, MHEngine *engine) override
void PrintMe(FILE *fd, int nTabs) const override
void GetValue(MHContentRef &ref, MHEngine *engine) const
void Initialise(MHParseNode *p, MHEngine *engine)
void PrintMe(FILE *fd, int nTabs) const
void Initialise(MHParseNode *p, MHEngine *engine)
int GetValue(MHEngine *engine) const
void PrintMe(FILE *fd, int nTabs) const
void GetValue(MHObjectRef &ref, MHEngine *engine) const
void PrintMe(FILE *fd, int nTabs) const
void Initialise(MHParseNode *p, MHEngine *engine)
void GetValue(MHOctetString &str, MHEngine *engine) const
void ContentPreparation(MHEngine *engine) override
void Destruction(MHEngine *engine) override
MHContentRef m_contentRef
Definition: Ingredients.h:78
void Preparation(MHEngine *engine) override
MHOctetString m_includedContent
Definition: Ingredients.h:77
int m_nOrigContentSize
Definition: Ingredients.h:74
bool m_fShared
Definition: Ingredients.h:68
bool m_fInitiallyActive
Definition: Ingredients.h:65
int m_nContentSize
Definition: Ingredients.h:79
MHIngredient()=default
MHOctetString m_origIncludedContent
Definition: Ingredients.h:72
void Initialise(MHParseNode *p, MHEngine *engine) override
Definition: Ingredients.cpp:50
int m_nOrigCCPrio
Definition: Ingredients.h:75
int m_nContentHook
Definition: Ingredients.h:66
void PrintMe(FILE *fd, int nTabs) const override
void SetData(const MHOctetString &included, MHEngine *engine) override
MHContentRef m_origContentRef
Definition: Ingredients.h:73
@ IN_ReferencedContent
Definition: Ingredients.h:71
@ IN_IncludedContent
Definition: Ingredients.h:71
MHOctetString m_groupId
Definition: BaseClasses.h:170
void Copy(const MHOctetString &str)
void PrintMe(FILE *fd, int nTabs) const
void Initialise(MHParseNode *p, MHEngine *engine) override
void PrintMe(FILE *fd, int nTabs) const override
MHParseNode * GetSeqN(int n)
Definition: ParseNode.cpp:152
MHParseNode * GetArgN(int n)
Definition: ParseNode.cpp:78
void GetStringValue(MHOctetString &str)
Definition: ParseNode.cpp:203
int GetTagNo()
Definition: ParseNode.cpp:49
bool GetBoolValue()
Definition: ParseNode.cpp:192
int GetSeqCount()
Definition: ParseNode.cpp:141
MHParseNode * GetNamedArg(int nTag)
Definition: ParseNode.cpp:110
enum NodeType m_nNodeType
Definition: ParseNode.h:46
int GetIntValue()
Definition: ParseNode.cpp:170
Definition: Root.h:45
virtual void Initialise(MHParseNode *p, MHEngine *engine)
Definition: Root.cpp:30
virtual void Destruction(MHEngine *engine)
Definition: Root.cpp:98
MHObjectRef m_ObjectReference
Definition: Root.h:248
virtual void MakeClone(MHRoot *, MHRoot *, MHEngine *)
Definition: Root.h:83
virtual void Preparation(MHEngine *engine)
Definition: Root.cpp:53
virtual void SetData(const MHOctetString &, MHEngine *)
Definition: Root.h:89
virtual void PrintMe(FILE *fd, int nTabs) const
Definition: Root.cpp:38
bool m_fAvailable
Definition: Root.h:252
bool m_fSizePresent
Definition: Ingredients.h:138
bool m_fIsIncluded
Definition: Ingredients.h:137
MHGenericInteger m_contentSize
Definition: Ingredients.h:142
void Initialise(MHParseNode *p, MHEngine *engine) override
void Perform(MHEngine *engine) override
bool m_fCCPriorityPresent
Definition: Ingredients.h:139
MHGenericInteger m_ccPriority
Definition: Ingredients.h:143
MHGenericContentRef m_referenced
Definition: Ingredients.h:141
void PrintArgs(FILE *fd, int nTabs) const override
MHGenericOctetString m_included
Definition: Ingredients.h:140
@ MHLogWarning
Definition: freemheg.h:78
int FILE
Definition: mythburn.py:138