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_ContentType = IN_NoContent;
00040 }
00041
00042
00043 MHIngredient::MHIngredient(const MHIngredient &ref): MHRoot(ref)
00044 {
00045
00046 m_fInitiallyActive = ref.m_fInitiallyActive;
00047 m_nContentHook = ref.m_nContentHook;
00048 m_ContentType = ref.m_ContentType;
00049 m_OrigIncludedContent.Copy(ref.m_OrigIncludedContent);
00050 m_OrigContentRef.Copy(ref.m_OrigContentRef);
00051 m_nOrigContentSize = ref.m_nOrigContentSize;
00052 m_nOrigCCPrio = ref.m_nOrigCCPrio;
00053 m_fShared = ref.m_fShared;
00054 }
00055
00056
00057 void MHIngredient::Initialise(MHParseNode *p, MHEngine *engine)
00058 {
00059 MHRoot::Initialise(p, engine);
00060 MHParseNode *pIA = p->GetNamedArg(C_INITIALLY_ACTIVE);
00061 if (pIA) m_fInitiallyActive = pIA->GetArgN(0)->GetBoolValue();
00062
00063 MHParseNode *pCHook = p->GetNamedArg(C_CONTENT_HOOK);
00064 if (pCHook) m_nContentHook = pCHook->GetArgN(0)->GetIntValue();
00065
00066 MHParseNode *pOrigContent = p->GetNamedArg(C_ORIGINAL_CONTENT);
00067 if (pOrigContent) {
00068 MHParseNode *pArg = pOrigContent->GetArgN(0);
00069
00070 if (pArg->m_nNodeType == MHParseNode::PNString) {
00071 m_ContentType = IN_IncludedContent;
00072 pArg->GetStringValue(m_OrigIncludedContent);
00073 }
00074 else {
00075
00076 m_ContentType = IN_ReferencedContent;
00077 m_OrigContentRef.Initialise(pArg->GetArgN(0), engine);
00078 MHParseNode *pContentSize = pArg->GetNamedArg(C_CONTENT_SIZE);
00079 if (pContentSize) m_nOrigContentSize = pContentSize->GetArgN(0)->GetIntValue();
00080 MHParseNode *pCCPrio = pArg->GetNamedArg(C_CONTENT_CACHE_PRIORITY);
00081 if (pCCPrio) m_nOrigCCPrio = pCCPrio->GetArgN(0)->GetIntValue();
00082 }
00083 }
00084
00085 MHParseNode *pShared = p->GetNamedArg(C_SHARED);
00086 if (pShared) m_fShared = pShared->GetArgN(0)->GetBoolValue();
00087 }
00088
00089 void MHIngredient::PrintMe(FILE *fd, int nTabs) const
00090 {
00091 MHRoot::PrintMe(fd, nTabs);
00092 if (! m_fInitiallyActive) { PrintTabs(fd, nTabs); fprintf(fd, ":InitiallyActive false\n"); }
00093 if (m_nContentHook != 0) { PrintTabs(fd, nTabs); fprintf(fd, ":CHook %d\n", m_nContentHook); }
00094
00095 if (m_ContentType == IN_IncludedContent) {
00096 PrintTabs(fd, nTabs);
00097 fprintf(fd, ":OrigContent ");
00098 m_OrigIncludedContent.PrintMe(fd, nTabs+1);
00099 fprintf(fd, "\n");
00100 }
00101 else if (m_ContentType == IN_ReferencedContent) {
00102 PrintTabs(fd, nTabs);
00103 fprintf(fd, ":OrigContent (");
00104 m_OrigContentRef.PrintMe(fd, nTabs+1);
00105 if (m_nOrigContentSize) fprintf(fd, " :ContentSize %d", m_nOrigContentSize);
00106 if (m_nOrigCCPrio != 127) fprintf(fd, " :CCPriority %d", m_nOrigCCPrio);
00107 fprintf(fd, " )\n");
00108 }
00109 if (m_fShared) { PrintTabs(fd, nTabs); fprintf(fd, ":Shared true\n"); }
00110 }
00111
00112
00113
00114 void MHIngredient::Preparation(MHEngine *engine)
00115 {
00116 if (m_fAvailable) return;
00117
00118 m_IncludedContent.Copy(m_OrigIncludedContent);
00119 m_ContentRef.Copy(m_OrigContentRef);
00120 m_nContentSize = m_nOrigContentSize;
00121 m_nCCPrio = m_nOrigCCPrio;
00122
00123 MHRoot::Preparation(engine);
00124 }
00125
00126 void MHIngredient::Destruction(MHEngine *engine)
00127 {
00128 engine->CancelExternalContentRequest(this);
00129 MHRoot::Destruction(engine);
00130 }
00131
00132 void MHIngredient::ContentPreparation(MHEngine *engine)
00133 {
00134 if (m_ContentType == IN_IncludedContent) {
00135
00136 engine->EventTriggered(this, EventContentAvailable);
00137 }
00138 else if (m_ContentType == IN_ReferencedContent) {
00139
00140 engine->CancelExternalContentRequest(this);
00141 engine->RequestExternalContent(this);
00142 }
00143 }
00144
00145
00146 void MHIngredient::SetData(const MHOctetString &included, MHEngine *engine)
00147 {
00148
00149
00150
00151
00152 if (m_ContentType == IN_ReferencedContent) {
00153 m_ContentRef.m_ContentRef.Copy(included);
00154 }
00155 else if (m_ContentType == IN_IncludedContent) {
00156 m_IncludedContent.Copy(included);
00157
00158 }
00159 else MHLOG(MHLogWarning, "SetData with no content");
00160 ContentPreparation(engine);
00161 }
00162
00163 void MHIngredient::SetData(const MHContentRef &referenced, bool , int size, bool fCCGiven, int , MHEngine *engine)
00164 {
00165 if (m_ContentType != IN_ReferencedContent)
00166 MHERROR("SetData with referenced content applied to an ingredient without referenced content");
00167 m_ContentRef.Copy(referenced);
00168 m_nContentSize = size;
00169 if (fCCGiven) m_nCCPrio = m_nOrigCCPrio;
00170 ContentPreparation(engine);
00171 }
00172
00173
00174 MHFont::MHFont()
00175 {
00176
00177 }
00178
00179 MHFont::~MHFont()
00180 {
00181
00182 }
00183
00184 void MHFont::Initialise(MHParseNode *p, MHEngine *engine)
00185 {
00186 MHIngredient::Initialise(p, engine);
00187
00188 }
00189
00190 void MHFont::PrintMe(FILE *fd, int nTabs) const
00191 {
00192 PrintTabs(fd, nTabs); fprintf(fd, "{:Font");
00193 MHIngredient::PrintMe(fd, nTabs+1);
00194 fprintf(fd, "****TODO\n");
00195 PrintTabs(fd, nTabs); fprintf(fd, "}\n");
00196 }
00197
00198
00199
00200
00201 MHCursorShape::MHCursorShape()
00202 {
00203
00204 }
00205
00206 MHCursorShape::~MHCursorShape()
00207 {
00208
00209 }
00210
00211 void MHCursorShape::Initialise(MHParseNode *p, MHEngine *engine)
00212 {
00213 MHIngredient::Initialise(p, engine);
00214
00215 }
00216
00217 void MHCursorShape::PrintMe(FILE *fd, int nTabs) const
00218 {
00219 PrintTabs(fd, nTabs); fprintf(fd, "{:CursorShape");
00220 MHIngredient::PrintMe(fd, nTabs+1);
00221 fprintf(fd, "****TODO\n");
00222 PrintTabs(fd, nTabs); fprintf(fd, "}\n");
00223 }
00224
00225
00226
00227 MHPalette::MHPalette()
00228 {
00229
00230 }
00231
00232 MHPalette::~MHPalette()
00233 {
00234
00235 }
00236
00237 void MHPalette::Initialise(MHParseNode *p, MHEngine *engine)
00238 {
00239 MHIngredient::Initialise(p, engine);
00240
00241 }
00242
00243 void MHPalette::PrintMe(FILE *fd, int nTabs) const
00244 {
00245 PrintTabs(fd, nTabs); fprintf(fd, "{:Palette");
00246 MHIngredient::PrintMe(fd, nTabs+1);
00247 fprintf(fd, "****TODO\n");
00248 PrintTabs(fd, nTabs); fprintf(fd, "}\n");
00249 }
00250
00251 void MHSetData::Initialise(MHParseNode *p, MHEngine *engine)
00252 {
00253 MHElemAction::Initialise(p, engine);
00254 MHParseNode *pContent = p->GetArgN(1);
00255 if (pContent->m_nNodeType == MHParseNode::PNSeq) {
00256
00257 m_fIsIncluded = false;
00258 m_fSizePresent = m_fCCPriorityPresent = false;
00259 m_Referenced.Initialise(pContent->GetSeqN(0), engine);
00260
00261 if (pContent->GetSeqCount() > 1) {
00262 MHParseNode *pArg = pContent->GetSeqN(1);
00263 if (pArg->m_nNodeType == MHParseNode::PNTagged && pArg->GetTagNo() == C_NEW_CONTENT_SIZE) {
00264 MHParseNode *pVal = pArg->GetArgN(0);
00265
00266 if (pVal->m_nNodeType == MHParseNode::PNInt) {
00267 m_fSizePresent = true;
00268 m_ContentSize.Initialise(pVal, engine);
00269 }
00270 }
00271 }
00272
00273 if (pContent->GetSeqCount() > 2) {
00274 MHParseNode *pArg = pContent->GetSeqN(2);
00275 if (pArg->m_nNodeType == MHParseNode::PNTagged && pArg->GetTagNo() == C_NEW_CONTENT_CACHE_PRIO) {
00276 MHParseNode *pVal = pArg->GetArgN(0);
00277 if (pVal->m_nNodeType == MHParseNode::PNInt) {
00278 m_fCCPriorityPresent = true;
00279 m_CCPriority.Initialise(pVal, engine);
00280 }
00281 }
00282 }
00283 }
00284 else {
00285 m_Included.Initialise(pContent, engine);
00286 m_fIsIncluded = true;
00287 }
00288 }
00289
00290 void MHSetData::PrintArgs(FILE *fd, int) const
00291 {
00292 if (m_fIsIncluded) m_Included.PrintMe(fd, 0);
00293 else {
00294 m_Referenced.PrintMe(fd, 0);
00295 if (m_fSizePresent){
00296 fprintf(fd, " :NewContentSize ");
00297 m_ContentSize.PrintMe(fd, 0);
00298 }
00299 if (m_fCCPriorityPresent) {
00300 fprintf(fd, " :NewCCPriority ");
00301 m_CCPriority.PrintMe(fd, 0);
00302 }
00303 }
00304 }
00305
00306 void MHSetData::Perform(MHEngine *engine)
00307 {
00308 MHObjectRef target;
00309 m_Target.GetValue(target, engine);
00310 if (m_fIsIncluded) {
00311 MHOctetString included;
00312 m_Included.GetValue(included, engine);
00313 engine->FindObject(target)->SetData(included, engine);
00314 }
00315 else {
00316 MHContentRef referenced;
00317 int size, cc;
00318 m_Referenced.GetValue(referenced, engine);
00319 if (m_fSizePresent) size = m_ContentSize.GetValue(engine); else size = 0;
00320 if (m_fCCPriorityPresent) cc = m_CCPriority.GetValue(engine); else cc = 0;
00321 engine->FindObject(target)->SetData(referenced, m_fSizePresent, size, m_fCCPriorityPresent, cc, engine);
00322 }
00323 }
00324
00325
00326 void MHClone::CallAction(MHEngine *engine, MHRoot *pTarget, MHRoot *pRef)
00327 {
00328
00329 MHObjectRef groupRef;
00330 groupRef.m_GroupId.Copy(pTarget->m_ObjectReference.m_GroupId);
00331 groupRef.m_nObjectNo = 0;
00332 MHRoot *pGroup = engine->FindObject(groupRef);
00333
00334 pGroup->MakeClone(pTarget, pRef, engine);
00335 }