MHEG5  18.9.0
MHEG5 Documentation
mh5tokengroup.c
Go to the documentation of this file.
1 /*******************************************************************************
2  * Copyright © 2014 The DTVKit Open Software Foundation Ltd (www.dtvkit.org)
3  * Copyright © 2004 Ocean Blue Software Ltd
4  * Copyright © 2000 Koninklijke Philips Electronics N.V
5  *
6  * This file is part of a DTVKit Software Component
7  * You are permitted to copy, modify or distribute this file subject to the terms
8  * of the DTVKit 1.0 Licence which can be found in licence.txt or at www.dtvkit.org
9  *
10  * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
11  * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES
12  * OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
13  *
14  * If you or your organisation is not a member of DTVKit then you have access
15  * to this source code outside of the terms of the licence agreement
16  * and you are expected to delete this and any associated files immediately.
17  * Further information on DTVKit, membership and terms can be found at www.dtvkit.org
18  *******************************************************************************/
36 /*---includes for this file--------------------------------------------------*/
37 #include <string.h>
38 
39 #include "mh5tokengroup.h"
40 #include "mh5object.h" /* for actions */
41 #include "mh5variable.h" /* for actions */
42 #include "mh5memory.h" /* for constructor/destructor */
43 #include "mh5final.h"
44 #include "mh5queue.h" /* Events */
45 #include "mh5debug.h"
46 #include "mh5gate.h"
47 
48 /*---constant definitions for this file--------------------------------------*/
49 
50 
51 /*---local typedef structs for this file-------------------------------------*/
52 
53 /*---local (static) variable declarations for this file----------------------*/
54 
55 /*---local function definitions----------------------------------------------*/
56 
57 /*---global function definitions---------------------------------------------*/
58 
64 /*
65  Debug
66  */
67 #ifdef MH5PRINTOUT
68 
74 void MHEG5tokenGroupPrint(MHEG5TokenGroup *tokenGroup, char *out)
75 {
76  MHEG5TokenSlot *currTGItem;
77  U32BIT token_num, actions_num, num;
78  MHEG5ActionList *actions_ptr;
79 
80  MHEG5ingredientPrint(&tokenGroup->ingredient, out);
81  MHEG5tokenManagerPrint(&tokenGroup->tokenManager, out);
82 
83  /* tokenGroupItems */
84  MHEG5indent(out);
85  MHEG_PRINT(out, ":TokenGroupItems (");
86  MHEG5incIndent();
87 
88  currTGItem = tokenGroup->tokens_ptr + 1;
89  token_num = tokenGroup->tokens_num - 1;
90  MHEG5newLine(out);
91  while (token_num != 0)
92  {
93  MHEG5incIndent();
94  MHEG5indent(out);
95  MHEG_PRINT(out, "(");
96  /* Object reference */
97  if ((tokenGroup->ingredient.root.grp == currTGItem->groupid.ptr.group) ||
98  ((currTGItem->groupid.len) && MHEG5sameGroup(tokenGroup->ingredient.root.grp, currTGItem->groupid)))
99  {
100  MHEG5intPrint(currTGItem->id, out);
101  }
102  else
103  {
104  MHEG_PRINT(out, "(");
105  MHEG5stringPrint(*((MHEG5String *)&currTGItem->groupid), out);
106  MHEG_PRINT(out, " ");
107  MHEG5intPrint(currTGItem->id, out);
108  MHEG_PRINT(out, ")");
109  }
110  MHEG5newLine(out);
111  MHEG5indent(out);
112  MHEG_PRINT(out, ":ActionSlots (");
113  MHEG5newLine(out);
114  MHEG5incIndent();
115 
116  /* Sequence of actionslots */
117  actions_num = currTGItem->actions_num;
118  actions_ptr = currTGItem->actions_ptr;
119  num = 1;
120  while (actions_num != 0)
121  {
122  MHEG5indent(out);
123  MHEG_PRINT(out, "( // AS=");
124  MHEG5intPrint(num, out);
125  MHEG5newLine(out);
126  MHEG5actionPrint(*actions_ptr, out);
127  MHEG5indent(out);
128  MHEG_PRINT(out, ")");
129  MHEG5newLine(out);
130  actions_ptr++;
131  actions_num--;
132  num++;
133  }
134  MHEG5decIndent();
135  MHEG5indent(out);
136  MHEG_PRINT(out, ")");
137  MHEG5newLine(out);
138 
139  MHEG5decIndent();
140  MHEG5indent(out);
141  MHEG_PRINT(out, ")");
142  MHEG5newLine(out);
143 
144  currTGItem++;
145  token_num--;
146  }
147  MHEG5decIndent();
148  MHEG5newLine(out);
149  MHEG5indent(out);
150  MHEG_PRINT(out, ")");
151  MHEG5newLine(out);
152  currTGItem = tokenGroup->tokens_ptr;
153  actions_num = currTGItem->actions_num;
154  if (actions_num != 0)
155  {
156  /* noTokenActionSlots */
157  MHEG5indent(out);
158  MHEG_PRINT(out, ":NoTokenActionSlot ");
159  MHEG5newLine(out);
160  MHEG5incIndent();
161 
162  actions_ptr = currTGItem->actions_ptr;
163  do
164  {
165  MHEG5indent(out);
166  MHEG_PRINT(out, "(");
167  MHEG5newLine(out);
168  MHEG5actionPrint(*actions_ptr, out);
169  MHEG5indent(out);
170  MHEG_PRINT(out, ")");
171  MHEG5newLine(out);
172  actions_ptr++;
173  actions_num--;
174  }
175  while (actions_num != 0);
176  MHEG5decIndent();
177  MHEG5newLine(out);
178  }
179 }
180 
181 #endif
182 
183 
192 {
193  MHEG5TokenSlot *token_ptr;
194  U32BIT token_num, actions_num;
195  MHEG5ActionList *actions_ptr;
196 
197  assert(tokenGroup);
198 
199  MHEG5ingredientFree(&tokenGroup->ingredient);
200  MHEG5tokenManagerFree(&tokenGroup->tokenManager);
201 
202  token_ptr = tokenGroup->tokens_ptr;
203  token_num = tokenGroup->tokens_num;
204  while (token_num)
205  {
206  if (token_ptr->groupid.len)
207  {
208  MHEG5stringDestruct((MHEG5String *)&token_ptr->groupid);
209  }
210  actions_num = token_ptr->actions_num;
211  actions_ptr = token_ptr->actions_ptr;
212  while (actions_num)
213  {
214  MHEG5actionDestruct(*actions_ptr);
215  actions_ptr++;
216  actions_num--;
217  }
218  token_ptr++;
219  token_num--;
220  }
221 }
222 
223 /*
224  29.1.3 Own internal attributes
225  This class defines no additional internal attribute.
226  29.2 Events
227  This class has the same events as its base classes, with identical semantics.
228  */
230 {
231  U32BIT token_num;
232  MHEG5TokenSlot *token_ptr;
233  U32BIT actions_num;
234  MHEG5ActionList *actions_ptr;
235 
236  assert(tokenGroup);
237 
238  token_ptr = tokenGroup->tokens_ptr;
239  token_num = tokenGroup->tokens_num;
240  while (token_num)
241  {
242  actions_num = token_ptr->actions_num;
243  actions_ptr = token_ptr->actions_ptr;
244 
245  while (actions_num)
246  {
247  MHEG5queueResolveTargets( *actions_ptr );
248  actions_ptr++;
249  actions_num--;
250  }
251  token_ptr++;
252  token_num--;
253  }
255  MHEG5ingredientPrepare(&tokenGroup->ingredient);
256 }
257 
258 /*
259  Âctivation
260  Execute the following sequence of actions:
261  1. Apply the Activation behaviour as inherited from the Presentable class.
262  2. Apply the activation behaviour to each item in the order given by
263  TokenGroupItems.
264  3. Generate a TokenMovedTo event with the value of the TokenPosition
265  attribute as associated data.
266  4. Set the RunningStatus to True and generate an IsRunning event.
267  */
269 {
270  MHEG5TokenSlot *token_ptr;
271  MHEG5Root *item;
272  U32BIT token_num;
273 
274  assert(tokenGroup);
275 
276  if (!tokenGroup->ingredient.root.runningStatus)
277  {
278  if (!tokenGroup->ingredient.root.availabilityStatus)
279  {
280  MHEG5tokenGroupPrepare( tokenGroup );
281  }
282  /* Could call the base class activation behaviour, but */
283  /* MHEG5ingredientActivate(&tokenGroup->ingredient); <- does nothing, so don't bother */
284 
285  token_ptr = tokenGroup->tokens_ptr + 1;
286  token_num = tokenGroup->tokens_num - 1;
287  while (token_num)
288  {
289  item = MHEG5findObject(token_ptr->groupid, token_ptr->id);
290  if (item)
291  {
292  MHEG5finalActivate(item);
293  }
294  token_ptr++;
295  token_num--;
296  }
298  tokenGroup->ingredient.root.runningStatus = MHEG5TRUE;
299  MHEG5sendSync((MHEG5Root *)tokenGroup, MHEG5ISRUNNING, 0);
300  }
301 }
302 
303 /*
304  Deactivation
305  1. Generate a TokenMoveFrom event with the value of the TokenPosition
306  attribute as associated data.
307  2. Apply the Deactivation behaviour as inherited from the Presentable class.
308  */
310 {
311  assert(tokenGroup);
312 
313  if (tokenGroup->ingredient.root.runningStatus)
314  {
317  }
318 }
319 
321 {
322  U32BIT token_num;
323  MHEG5TokenSlot *token_ptr;
324  U32BIT actions_num;
325  MHEG5ActionList *actions_ptr;
326  assert(tokenGroup);
327 
328  MHEG5ingredientDestruct(&tokenGroup->ingredient);
330 
331  token_ptr = tokenGroup->tokens_ptr;
332  token_num = tokenGroup->tokens_num;
333  while (token_num)
334  {
335  actions_num = token_ptr->actions_num;
336  actions_ptr = token_ptr->actions_ptr;
337 
338  while( actions_num )
339  {
340  MHEG5queueUnresolveTargets( *actions_ptr );
341  actions_ptr++;
342  actions_num--;
343  }
344  token_ptr++;
345  token_num--;
346  }
347 }
348 
349 #ifdef TRACING
350 static void TraceToken( MHEG5TokenGroup *tkn, MHEG5Int t_posn, MHEG5Int idx )
351 {
352  int ind = (event_indent_num << 1) + 1;
353  char buff[160];
354 
355  ind = (event_indent_num << 1) % MAX_EVENT_INDENT;
356 
357  buff[ind + 1] = 0;
358  while (ind != 0)
359  {
360  buff[ind] = ' ';
361  ind--;
362  }
363  buff[0] = '\n';
364  DBG_PRINTF( buff );
365  DBG_PRINTF("Tokengroup: %c%ld posn: %d aslot: %d",
366  (tkn->ingredient.root.grp->root.clazz == MHEG5SCENE) ? 'S' : 'A', tkn->ingredient.root.id, t_posn, idx );
367 }
368 
369 #endif /*TRACING*/
370 
371 /*
372  Actions
373  */
374 /*
375  CallActionSlot (Index)
376  Execute an Action object associated with the item that currently has the token.
377  Execute the following sequence of actions:
378  1. If TokenPosition is set to 0, consider the ActionSlots sequence of the
379  NoTokenActionSlots attribute.
380  2. If TokenPosition is different from 0, consider the ActionSlots sequence that is
381  associated with the item that currently has the token.
382  3. Consider the ActionSlot that is at position Index in the ActionSlots sequence. If
383  this ActionSlot is NULL, then ignore the effect of the CallActionSlot action.
384  Otherwise, execute that ActionSlot.
385 
386  The execution of the CallActionSlot action is not completed until the ActionSlot
387  action has been executed.
388 
389  Provisions of use:
390  The Target object shall be an active TokenGroup object.
391  Index shall be set in the range [0, number of items in TokenGroupItem].
392  */
394 {
395  MHEG5Int idx = 0, position = 0;
396  MHEG5TokenSlot *token_ptr;
397  MHEG5ActionList *actions_ptr;
398 
399  if ((target->clazz != MHEG5TOKENGROUP) && (target->clazz != MHEG5LISTGROUP))
400  {
401  return MHEG5ERR_WRONGTARGET;
402  }
403 
404  if (!params)
405  {
407  }
408  MHEG5resolveGenericInteger(params, &idx);
409 
410  position = ((MHEG5TokenGroup *)target)->tokenManager.tokenPosition;
411 
412  #ifdef TRACING
413  extra_trace_param = (position << 16) | idx;
414  #endif
415 
416  if (position >= ((MHEG5TokenGroup *)target)->tokens_num || position < 0)
417  {
418  return MHEG5ERR_NOSUCHITEM;
419  }
420  else
421  {
422  token_ptr = ((MHEG5TokenGroup *)target)->tokens_ptr;
423  token_ptr += position;
424  if (idx <= token_ptr->actions_num && idx > 0)
425  {
426  actions_ptr = token_ptr->actions_ptr + idx - 1;
427 
428  #ifdef MHEG5LOG
429  MHEG5LogPrintf(MHEG5CALLS, "MHEG5callActionSlot position = %d, %d\n", position, idx);
430  #endif
431 
432  #ifdef TRACING
433  if (mheg_trace_debug & (TACTIONS | TEVNTS))
434  TraceToken((MHEG5TokenGroup *)target, position, idx );
435  #endif
436 
437  MHEG5PrependActionList( *actions_ptr );
438  }
439  else
440  {
441  return MHEG5ERR_NOSUCHSLOT;
442  }
443  }
444  return MHEG5ERR_NOERROR;
445 }
446 
MHEG5Bool availabilityStatus
Definition: mh5root.h:52
void MHEG5tokenManagerDestruct(MHEG5TokenManager *tokenManager)
Destruct a TokenManager object.
void MHEG5tokenManagerFree(MHEG5TokenManager *tokenManager)
Free off all memory associated with the specified object, including any exchanged attributes and inte...
Distributor for Prepare, Destruct, Activate, Deactivate and Clone calls. Distribute the +Prepare +Des...
MHEG5Bool MHEG5sameGroup(MH5GroupPtr gptr, MH5GroupRef gref)
Compares group ptr with group ref to see whether they both reference the same group. The first is pointer to group, the second can be a relative group name and will be converted to absolute prior to the comparison, so two different references that resolve to reference the same group name produces a True return value.
Definition: mh5gate.c:517
void MHEG5finalActivate(MHEG5Root *item)
Definition: mh5final.c:260
#define DBG_PRINTF(...)
Definition: glue_debug.h:127
void MHEG5PrependActionList(MHEG5ActionList actions)
Execute the supplied list of actions before others.
Definition: mh5queue.c:1502
MHEG5Root * MHEG5findObject(MH5GroupRef gid, MHEG5Int id)
Definition: mh5object.c:65
MHEG5GList * MHEG5resolveGenericInteger(MHEG5GList *params, MHEG5Int *value)
Definition: mh5object.c:510
MHEG5Final clazz
Definition: mh5root.h:55
void MHEG5ingredientDestruct(MHEG5Ingredient *ingredient)
Implementation of the Destruction behaviour Execute the following sequence of actions: ...
union sMH5GroupRef::@5 ptr
MHEG5ErrorCode MHEG5callActionSlot(MHEG5Root *target, MHEG5GList *params)
MHEG5Int tokens_num
Definition: mh5tokengroup.h:65
void MHEG5tokenGroupDestruct(MHEG5TokenGroup *tokenGroup)
MH5GroupPtr grp
Definition: mh5root.h:57
Implement the MHEG5 Variable Class 21 Variable Class Defines a variable within the context of a Group...
void MHEG5stringDestruct(MHEG5String *item)
Destruct a MHEG5String.
Definition: mh5base.c:686
long MHEG5Int
Definition: mh5base.h:73
Implement the MHEG5 Tokengroup Class 29 TokenGroup Class. Defines a group of Visible objects for navi...
void MHEG5tokenManagerPrepare(MHEG5TokenManager *tokenManager)
Sets all internal attributes for the specified object to their default values.
void MHEG5tokenGroupDeactivate(MHEG5TokenGroup *tokenGroup)
Implement Functions to support Service Gateways. Functions for standarizing several GroupIDs like +DS...
void MHEG5tokenGroupPrepare(MHEG5TokenGroup *tokenGroup)
void MHEG5tokenGroupActivate(MHEG5TokenGroup *tokenGroup)
MHEG5ErrorCode
Definition: mh5base.h:222
MHEG5TokenSlot * tokens_ptr
Definition: mh5tokengroup.h:66
Event handling. Implementation of a combined queue for events and actions. This is the eventsystem wh...
MHEG5Int actions_num
Definition: mh5tokengroup.h:53
#define MHEG5TRUE
Definition: mh5base.h:49
void MHEG5tokenGroupFree(MHEG5TokenGroup *tokenGroup)
<Function description>="">
void MHEG5ingredientDeactivate(MHEG5Ingredient *ingredient)
Implementation of Deactivate behaviour Inherrited from Root class.
Implement functions to retrieve MHEG5objects by GroupID and ID.
void MHEG5ingredientPrepare(MHEG5Ingredient *ingredient)
Implementation of the Preparation behaviour Inherrited from Root class.
Mheg5 logging and debug printing.
MHEG5Ingredient ingredient
Definition: mh5tokengroup.h:61
MHEG5Int len
Definition: mh5base.h:99
MHEG5Bool runningStatus
Definition: mh5root.h:51
MHEG5Root root
Definition: mh5group.h:50
redirection include
void MHEG5actionDestruct(MHEG5ActionList actions)
<Function description>="">
Definition: mh5action.c:118
MHEG5Int id
Definition: mh5root.h:48
void MHEG5queueUnresolveTargets(MHEG5ActionList actions)
Clear targets for the action list.
Definition: mh5queue.c:1204
MH5GroupRef groupid
Definition: mh5tokengroup.h:52
MH5GroupPtr group
Definition: mh5base.h:103
MHEG5ActionList * actions_ptr
Definition: mh5tokengroup.h:54
void MHEG5queueResolveTargets(MHEG5ActionList actions)
Finds targets for the action list.
Definition: mh5queue.c:1182
#define MAX_EVENT_INDENT
Definition: mh5action.h:37
void MHEG5ingredientFree(MHEG5Ingredient *ingredient)
Free off all memory associated with the specified object, including any exchanged attributes and inte...
MHEG5TokenManager tokenManager
Definition: mh5tokengroup.h:62
uint32_t U32BIT
Definition: techtype.h:86
void MHEG5sendSync(MHEG5Root *source, MHEG5EventType event, MHEG5Int data)
Store an event in the synchronous event queue.
Definition: mh5queue.c:1651