DSMCC  17.9.0
 All Data Structures Files Functions Typedefs
moduleData.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 © 2001 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  *******************************************************************************/
25 /*---includes for this file--------------------------------------------------*/
26 #include "clDsmSystem.h"
27 #include "moduleData.h"
28 
29 #include "cacheMgr.h"
30 #include "object.h"
31 #include "defMemUtilsMgd.h" /* -- Default mem type for module */
32 
33 
34 /*------------------------------- Local Macros -------------------------------*/
35 
36 
37 /*------------------------------ Exported Data -----------------------------*/
38 
39 
40 /*--------------------------------Local Types --------------------------------*/
41 
42 typedef struct s_ModuleData
43 {
44  U32BIT size;
45  U16BIT open;
46  U16BIT idel;
47 } S_ModuleData;
48 
49 /*------------------------------- Local Statics ------------------------------*/
50 
51 
52 
53 /*------------------- local prototypes/forward declarations ------------------*/
54 
55 
56 /*---------------------------- Exported Functions ----------------------------*/
57 
58 
59 /* /////////////////////////////////////////////////////////////////////////////
60 // moduleDataCreate
61 //
63 E_DscError moduleDataCreate( P_DsmCoreInst idp,
64  U32BIT dataSize, P_ModuleData *phModuleData )
65 {
66  E_DscError err;
67 
68  dsmDP3(("moduleDataCreate()\n"));
69  dsmAssert((idp != NULL));
70  dsmAssert((dataSize > 0));
71  dsmAssert((phModuleData != NULL));
72 
73  *phModuleData = (P_ModuleData)DSC_CmMemGet( idp, sizeof(S_ModuleData) + dataSize );
74  if (*phModuleData == NULL)
75  {
76  err = CLDSM_ERR_MEM_HEAP_FULL;
77  }
78  else
79  {
80  err = CLDSM_OK;
81  (*phModuleData)->size = dataSize;
82  (*phModuleData)->open = 0;
83  (*phModuleData)->idel = 0;
84  }
85 
86  DEBUG_CHK( err == CLDSM_OK,
87  dsmDP1(("ERROR: moduleDataCreate %u\n", err)));
88  dsmDP3(("exit moduleDataCreate -> rtn: %u\n", err));
89  return err;
90 }
91 
92 /* /////////////////////////////////////////////////////////////////////////////
93 // moduleDataDestroy
94 //
96 void moduleDataDestroy( P_DsmCoreInst idp, P_ModuleData *phModuleData )
97 {
98  dsmDP3(("moduleDataDestroy()\n"));
99  dsmAssert((idp != NULL));
100  dsmAssert((phModuleData != NULL));
101  dsmAssert((*phModuleData != NULL));
102 
103  if ((*phModuleData)->open)
104  {
105  (*phModuleData)->idel = 0xFFFF;
106  }
107  else
108  {
109  DSC_CmMemRelease( idp, *phModuleData );
110  }
111  *phModuleData = NULL;
112 
113  dsmDP3(("exit moduleDataDestroy\n"));
114 }
115 
116 MemPtr moduleDataPtr(P_ModuleData pModuleData)
117 {
118  dsmAssert((pModuleData != NULL));
119  return ((MemPtr)pModuleData) + sizeof(S_ModuleData);
120 }
121 
122 MemPtr moduleDataOpen(P_ModuleData pModuleData)
123 {
124  dsmAssert((pModuleData != NULL));
125  pModuleData->open++;
126  return moduleDataPtr(pModuleData);
127 }
128 
129 void moduleDataClose(P_DsmCoreInst idp, P_ModuleData pModuleData)
130 {
131  dsmAssert((pModuleData != NULL));
132  if (pModuleData->open)
133  {
134  pModuleData->open--;
135  }
136  if (pModuleData->open == 0 && pModuleData->idel == 0xFFFF)
137  {
138  DSC_CmMemRelease( idp, pModuleData );
139  }
140 }
141 
142 
143 /* /////////////////////////////////////////////////////////////////////////////
144 // moduleDataFindObject
145 //
147 U32BIT moduleDataFindObject(
148  /*I*/ P_ModuleData pModuleData, U32BIT dataLength, P_ObjectKey pObjectKey,
149  /*O*/ MemPtr *mpObject )
150 {
151  MemPtr mpObjectData;
152  MemPos currPos;
153  MemPos endPos;
154  BOOLEAN valid = FALSE;
155  U32BIT objectLength = 0;
156  S_ObjectKey currObjectKey;
157  U32BIT currObjectLength;
158  BOOLEAN objKeysMatch;
159  U8BIT *pObjKeyData;
160  U8BIT *pCurrKeyData;
161 
162  dsmDP3(("moduleDataFindObject()\n"));
163  dsmAssert((pModuleData != NULL));
164 
165  dsmAssert((pObjectKey != NULL));
166  dsmAssert(((pObjectKey->length > 0) && (pObjectKey->length <= 4)));
167  dsmAssert((mpObject != NULL));
168 
169  if (!dataLength)
170  {
171  DBG2(DD_GEN,"zero length")
172  }
173 
174  /* -- Open MemPtr for accessing objects in module data */
175  MEMPTR_OPEN( moduleDataPtr(pModuleData), mpObjectData );
176 
177  /* -- Determine end position of search data */
178  GET_POS( mpObjectData, currPos );
179  endPos = currPos + dataLength;
180 
181  /* -- mpObjectData -> first BIOP::<object>Message */
182 
183  while (currPos < endPos)
184  {
185  /* -- mpObjectData -> current BIOP::<object>Message */
186  valid = objectDataGetKeyAndLen( mpObjectData, &currObjectKey,
187  &currObjectLength );
188  if (valid)
189  {
190  /*TODO: check sufficient data in module for object (length)?*/
191 
192  /*
193  -- Check if objectKeysMatch
194  --
195  -- Uses switch to make it fast (& avoid function call overhead
196  -- of memcmp). By far the most common case used is case 1.
197  */
198 
199  /* -- Currently only used here - should put this functionality in
200  -- a macro if required elsewhere */
201 
202  dsmAssert(((currObjectKey.length > 0) &&
203  (currObjectKey.length <= 4)));
204 
205  objKeysMatch = FALSE;
206 
207  if (currObjectKey.length == pObjectKey->length)
208  {
209  pObjKeyData = pObjectKey->data;
210  pCurrKeyData = currObjectKey.data;
211 
212  switch (pObjectKey->length)
213  {
214  case 1:
215  if (*pCurrKeyData == *pObjKeyData)
216  {
217  objKeysMatch = TRUE;
218  }
219  break;
220 
221  case 2:
222  if (*(pCurrKeyData)++ == *(pObjKeyData)++)
223  {
224  if (*pCurrKeyData == *pObjKeyData)
225  {
226  objKeysMatch = TRUE;
227  }
228  }
229  break;
230 
231  case 3:
232  if (*(pCurrKeyData)++ == *(pObjKeyData)++)
233  {
234  if (*(pCurrKeyData)++ == *(pObjKeyData)++)
235  {
236  if (*pCurrKeyData == *pObjKeyData)
237  {
238  objKeysMatch = TRUE;
239  }
240  }
241  }
242  break;
243 
244  case 4:
245  if (*(pCurrKeyData)++ == *(pObjKeyData)++)
246  {
247  if (*(pCurrKeyData)++ == *(pObjKeyData)++)
248  {
249  if (*(pCurrKeyData)++ == *(pObjKeyData)++)
250  {
251  if (*pCurrKeyData == *pObjKeyData)
252  {
253  objKeysMatch = TRUE;
254  }
255  }
256  }
257  }
258  break;
259 
260  default:
261  break;
262  }
263  }
264 
265  if (objKeysMatch == TRUE)
266  {
267  SET_POS_ABS( *mpObject, currPos );
268  objectLength = currObjectLength;
269  break;
270  }
271  else
272  {
273  /* -- Skip current object data */
274  SET_POS_REL( mpObjectData, currObjectLength );
275 
276  /* -- Find next (potential) object start position */
277  GET_POS( mpObjectData, currPos );
278  }
279  }
280  else
281  {
282  break;
283  }
284  }
285  MEMPTR_CLOSE( mpObjectData );
286 
287  dsmDP3(("exit moduleDataFindObject -> rtn: %u\n", objectLength));
288  return objectLength;
289 }
290 
291 /*------------------------------ Local Functions -----------------------------*/
292 
293 
294 /*----------------------------------------------------------------------------*/
General include file for clDsm library internal definitions.
Header to the cacheMgr module.
Header to the object module - functions/methods accessing data of object messages inside modules...
Defines memory access utils to work with managed (MemMgr) memory.
Header to the moduleData module.