00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "Ingredients.h"
00023 #include "Root.h"
00024 #include "BaseClasses.h"
00025 #include "ParseNode.h"
00026 #include "ASN1Codes.h"
00027 #include "Actions.h"
00028 #include "Engine.h"
00029 #include "Logging.h"
00030
00031
00032 MHIngredient::MHIngredient()
00033 {
00034 m_fInitiallyActive = true;
00035 m_nContentHook = 0;
00036 m_fShared = false;
00037 m_nOrigContentSize = 0;
00038 m_nOrigCCPrio = 127;
00039 m_nContentSize = 0;
00040 m_nCCPrio = 0;
00041 m_ContentType = IN_NoContent;
00042 }
00043
00044
00045 MHIngredient::MHIngredient(const MHIngredient &ref): MHRoot(ref)
00046 {
00047
00048 m_fInitiallyActive = ref.m_fInitiallyActive;
00049 m_nContentHook = ref.m_nContentHook;
00050 m_ContentType = ref.m_ContentType;
00051 m_OrigIncludedContent.Copy(ref.m_OrigIncludedContent);
00052 m_OrigContentRef.Copy(ref.m_OrigContentRef);
00053 m_nOrigContentSize = ref.m_nOrigContentSize;
00054 m_nOrigCCPrio = ref.m_nOrigCCPrio;
00055 m_fShared = ref.m_fShared;
00056 m_nContentSize = ref.m_nContentSize;
00057 m_nCCPrio = ref.m_nCCPrio;
00058 }
00059
00060
00061 void MHIngredient::Initialise(MHParseNode *p, MHEngine *engine)
00062 {
00063 MHRoot::Initialise(p, engine);
00064 MHParseNode *pIA = p->GetNamedArg(C_INITIALLY_ACTIVE);
00065
00066 if (pIA)
00067 {
00068 m_fInitiallyActive = pIA->GetArgN(0)->GetBoolValue();
00069 }
00070
00071 MHParseNode *pCHook = p->GetNamedArg(C_CONTENT_HOOK);
00072
00073 if (pCHook)
00074 {
00075 m_nContentHook = pCHook->GetArgN(0)->GetIntValue();
00076 }
00077
00078 MHParseNode *pOrigContent = p->GetNamedArg(C_ORIGINAL_CONTENT);
00079
00080 if (pOrigContent)
00081 {
00082 MHParseNode *pArg = pOrigContent->GetArgN(0);
00083
00084
00085 if (pArg->m_nNodeType == MHParseNode::PNString)
00086 {
00087 m_ContentType = IN_IncludedContent;
00088 pArg->GetStringValue(m_OrigIncludedContent);
00089 }
00090 else
00091 {
00092
00093 m_ContentType = IN_ReferencedContent;
00094 m_OrigContentRef.Initialise(pArg->GetArgN(0), engine);
00095 MHParseNode *pContentSize = pArg->GetNamedArg(C_CONTENT_SIZE);
00096
00097 if (pContentSize)
00098 {
00099 m_nOrigContentSize = pContentSize->GetArgN(0)->GetIntValue();
00100 }
00101
00102 MHParseNode *pCCPrio = pArg->GetNamedArg(C_CONTENT_CACHE_PRIORITY);
00103
00104 if (pCCPrio)
00105 {
00106 m_nOrigCCPrio = pCCPrio->GetArgN(0)->GetIntValue();
00107 }
00108 }
00109 }
00110
00111 MHParseNode *pShared = p->GetNamedArg(C_SHARED);
00112
00113 if (pShared)
00114 {
00115 m_fShared = pShared->GetArgN(0)->GetBoolValue();
00116 }
00117 }
00118
00119 void MHIngredient::PrintMe(FILE *fd, int nTabs) const
00120 {
00121 MHRoot::PrintMe(fd, nTabs);
00122
00123 if (! m_fInitiallyActive)
00124 {
00125 PrintTabs(fd, nTabs);
00126 fprintf(fd, ":InitiallyActive false\n");
00127 }
00128
00129 if (m_nContentHook != 0)
00130 {
00131 PrintTabs(fd, nTabs);
00132 fprintf(fd, ":CHook %d\n", m_nContentHook);
00133 }
00134
00135
00136 if (m_ContentType == IN_IncludedContent)
00137 {
00138 PrintTabs(fd, nTabs);
00139 fprintf(fd, ":OrigContent ");
00140 m_OrigIncludedContent.PrintMe(fd, nTabs + 1);
00141 fprintf(fd, "\n");
00142 }
00143 else if (m_ContentType == IN_ReferencedContent)
00144 {
00145 PrintTabs(fd, nTabs);
00146 fprintf(fd, ":OrigContent (");
00147 m_OrigContentRef.PrintMe(fd, nTabs + 1);
00148
00149 if (m_nOrigContentSize)
00150 {
00151 fprintf(fd, " :ContentSize %d", m_nOrigContentSize);
00152 }
00153
00154 if (m_nOrigCCPrio != 127)
00155 {
00156 fprintf(fd, " :CCPriority %d", m_nOrigCCPrio);
00157 }
00158
00159 fprintf(fd, " )\n");
00160 }
00161
00162 if (m_fShared)
00163 {
00164 PrintTabs(fd, nTabs);
00165 fprintf(fd, ":Shared true\n");
00166 }
00167 }
00168
00169
00170
00171 void MHIngredient::Preparation(MHEngine *engine)
00172 {
00173 if (m_fAvailable)
00174 {
00175 return;
00176 }
00177
00178
00179 m_IncludedContent.Copy(m_OrigIncludedContent);
00180 m_ContentRef.Copy(m_OrigContentRef);
00181 m_nContentSize = m_nOrigContentSize;
00182 m_nCCPrio = m_nOrigCCPrio;
00183
00184 MHRoot::Preparation(engine);
00185 }
00186
00187 void MHIngredient::Destruction(MHEngine *engine)
00188 {
00189 engine->CancelExternalContentRequest(this);
00190 MHRoot::Destruction(engine);
00191 }
00192
00193 void MHIngredient::ContentPreparation(MHEngine *engine)
00194 {
00195 if (m_ContentType == IN_IncludedContent)
00196 {
00197
00198 engine->EventTriggered(this, EventContentAvailable);
00199 }
00200 else if (m_ContentType == IN_ReferencedContent)
00201 {
00202
00203 engine->CancelExternalContentRequest(this);
00204 engine->RequestExternalContent(this);
00205 }
00206 }
00207
00208
00209 void MHIngredient::SetData(const MHOctetString &included, MHEngine *engine)
00210 {
00211
00212
00213
00214
00215 if (m_ContentType == IN_ReferencedContent)
00216 {
00217 m_ContentRef.m_ContentRef.Copy(included);
00218 }
00219 else if (m_ContentType == IN_IncludedContent)
00220 {
00221 m_IncludedContent.Copy(included);
00222
00223 }
00224 else
00225 {
00226 MHLOG(MHLogWarning, "SetData with no content");
00227 }
00228
00229 ContentPreparation(engine);
00230 }
00231
00232 void MHIngredient::SetData(const MHContentRef &referenced, bool , int size, bool fCCGiven, int , MHEngine *engine)
00233 {
00234 if (m_ContentType != IN_ReferencedContent)
00235 {
00236 MHERROR("SetData with referenced content applied to an ingredient without referenced content");
00237 }
00238
00239 m_ContentRef.Copy(referenced);
00240 m_nContentSize = size;
00241
00242 if (fCCGiven)
00243 {
00244 m_nCCPrio = m_nOrigCCPrio;
00245 }
00246
00247 ContentPreparation(engine);
00248 }
00249
00250
00251 MHFont::MHFont()
00252 {
00253
00254 }
00255
00256 MHFont::~MHFont()
00257 {
00258
00259 }
00260
00261 void MHFont::Initialise(MHParseNode *p, MHEngine *engine)
00262 {
00263 MHIngredient::Initialise(p, engine);
00264
00265 }
00266
00267 void MHFont::PrintMe(FILE *fd, int nTabs) const
00268 {
00269 PrintTabs(fd, nTabs);
00270 fprintf(fd, "{:Font");
00271 MHIngredient::PrintMe(fd, nTabs + 1);
00272 fprintf(fd, "****TODO\n");
00273 PrintTabs(fd, nTabs);
00274 fprintf(fd, "}\n");
00275 }
00276
00277
00278
00279
00280 MHCursorShape::MHCursorShape()
00281 {
00282
00283 }
00284
00285 MHCursorShape::~MHCursorShape()
00286 {
00287
00288 }
00289
00290 void MHCursorShape::Initialise(MHParseNode *p, MHEngine *engine)
00291 {
00292 MHIngredient::Initialise(p, engine);
00293
00294 }
00295
00296 void MHCursorShape::PrintMe(FILE *fd, int nTabs) const
00297 {
00298 PrintTabs(fd, nTabs);
00299 fprintf(fd, "{:CursorShape");
00300 MHIngredient::PrintMe(fd, nTabs + 1);
00301 fprintf(fd, "****TODO\n");
00302 PrintTabs(fd, nTabs);
00303 fprintf(fd, "}\n");
00304 }
00305
00306
00307
00308 MHPalette::MHPalette()
00309 {
00310
00311 }
00312
00313 MHPalette::~MHPalette()
00314 {
00315
00316 }
00317
00318 void MHPalette::Initialise(MHParseNode *p, MHEngine *engine)
00319 {
00320 MHIngredient::Initialise(p, engine);
00321
00322 }
00323
00324 void MHPalette::PrintMe(FILE *fd, int nTabs) const
00325 {
00326 PrintTabs(fd, nTabs);
00327 fprintf(fd, "{:Palette");
00328 MHIngredient::PrintMe(fd, nTabs + 1);
00329 fprintf(fd, "****TODO\n");
00330 PrintTabs(fd, nTabs);
00331 fprintf(fd, "}\n");
00332 }
00333
00334 void MHSetData::Initialise(MHParseNode *p, MHEngine *engine)
00335 {
00336 MHElemAction::Initialise(p, engine);
00337 MHParseNode *pContent = p->GetArgN(1);
00338
00339 if (pContent->m_nNodeType == MHParseNode::PNSeq)
00340 {
00341
00342 m_fIsIncluded = false;
00343 m_fSizePresent = m_fCCPriorityPresent = false;
00344 m_Referenced.Initialise(pContent->GetSeqN(0), engine);
00345
00346 if (pContent->GetSeqCount() > 1)
00347 {
00348 MHParseNode *pArg = pContent->GetSeqN(1);
00349
00350 if (pArg->m_nNodeType == MHParseNode::PNTagged && pArg->GetTagNo() == C_NEW_CONTENT_SIZE)
00351 {
00352 MHParseNode *pVal = pArg->GetArgN(0);
00353
00354
00355 if (pVal->m_nNodeType == MHParseNode::PNInt)
00356 {
00357 m_fSizePresent = true;
00358 m_ContentSize.Initialise(pVal, engine);
00359 }
00360 }
00361 }
00362
00363 if (pContent->GetSeqCount() > 2)
00364 {
00365 MHParseNode *pArg = pContent->GetSeqN(2);
00366
00367 if (pArg->m_nNodeType == MHParseNode::PNTagged && pArg->GetTagNo() == C_NEW_CONTENT_CACHE_PRIO)
00368 {
00369 MHParseNode *pVal = pArg->GetArgN(0);
00370
00371 if (pVal->m_nNodeType == MHParseNode::PNInt)
00372 {
00373 m_fCCPriorityPresent = true;
00374 m_CCPriority.Initialise(pVal, engine);
00375 }
00376 }
00377 }
00378 }
00379 else
00380 {
00381 m_Included.Initialise(pContent, engine);
00382 m_fIsIncluded = true;
00383 }
00384 }
00385
00386 void MHSetData::PrintArgs(FILE *fd, int) const
00387 {
00388 if (m_fIsIncluded)
00389 {
00390 m_Included.PrintMe(fd, 0);
00391 }
00392 else
00393 {
00394 m_Referenced.PrintMe(fd, 0);
00395
00396 if (m_fSizePresent)
00397 {
00398 fprintf(fd, " :NewContentSize ");
00399 m_ContentSize.PrintMe(fd, 0);
00400 }
00401
00402 if (m_fCCPriorityPresent)
00403 {
00404 fprintf(fd, " :NewCCPriority ");
00405 m_CCPriority.PrintMe(fd, 0);
00406 }
00407 }
00408 }
00409
00410 void MHSetData::Perform(MHEngine *engine)
00411 {
00412 MHObjectRef target;
00413 m_Target.GetValue(target, engine);
00414
00415 if (m_fIsIncluded)
00416 {
00417 MHOctetString included;
00418 m_Included.GetValue(included, engine);
00419 engine->FindObject(target)->SetData(included, engine);
00420 }
00421 else
00422 {
00423 MHContentRef referenced;
00424 int size, cc;
00425 m_Referenced.GetValue(referenced, engine);
00426
00427 if (m_fSizePresent)
00428 {
00429 size = m_ContentSize.GetValue(engine);
00430 }
00431 else
00432 {
00433 size = 0;
00434 }
00435
00436 if (m_fCCPriorityPresent)
00437 {
00438 cc = m_CCPriority.GetValue(engine);
00439 }
00440 else
00441 {
00442 cc = 0;
00443 }
00444
00445 engine->FindObject(target)->SetData(referenced, m_fSizePresent, size, m_fCCPriorityPresent, cc, engine);
00446 }
00447 }
00448
00449
00450 void MHClone::CallAction(MHEngine *engine, MHRoot *pTarget, MHRoot *pRef)
00451 {
00452
00453 MHObjectRef groupRef;
00454 groupRef.m_GroupId.Copy(pTarget->m_ObjectReference.m_GroupId);
00455 groupRef.m_nObjectNo = 0;
00456 MHRoot *pGroup = engine->FindObject(groupRef);
00457
00458 pGroup->MakeClone(pTarget, pRef, engine);
00459 }