DSMCC  17.9.0
 All Data Structures Files Functions Typedefs
clDsmDir.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  *
5  * This file is part of a DTVKit Software Component
6  * You are permitted to copy, modify or distribute this file subject to the terms
7  * of the DTVKit 1.0 Licence which can be found in licence.txt or at www.dtvkit.org
8  *
9  * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
10  * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES
11  * OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
12  *
13  * If you or your organisation is not a member of DTVKit then you have access
14  * to this source code outside of the terms of the licence agreement
15  * and you are expected to delete this and any associated files immediately.
16  * Further information on DTVKit, membership and terms can be found at www.dtvkit.org
17  *******************************************************************************/
24 /*---includes for this file--------------------------------------------------*/
25 #include "clDsmSystem.h"
26 #include "dsmObject.h"
27 #include "module.h"
28 #include "moduleData.h"
29 
30 
31 /*------------------------------- Local Macros -------------------------------*/
32 
33 
34 /*------------------------------ Exported Data -----------------------------*/
35 
36 
37 /*--------------------------------Local Types --------------------------------*/
38 
39 
40 /*------------------------------- Local Statics ------------------------------*/
41 
42 
43 /*------------------- Local prototypes/forward declarations ------------------*/
44 
45 
46 /*---------------------------- Exported Functions ----------------------------*/
47 
48 
49 /*******************************************************************************
50 *
51 * The directory object (dirObj) must be LOADED and OPEN.
52 *
53 * Retrieves the total number of directory entries and the total length of all
54 * entry names.
55 *
56 * RETURNS:
57 * CLDSM_OK (0)
58 * CLDSM_ERR_INVALID_OBJECT_HANDLE
59 * CLDSM_ERR_INVALID_OBJECT_TYPE
60 * CLDSM_ERR_OBJECT_NOT_LOADED
61 * CLDSM_ERR_OBJECT_NOT_OPEN
62 *
63 *******************************************************************************/
64 E_DscError CDSM_DirEntrySizes(
65  /*I*/ H_DsmObject dir,
66  /*O*/ U16BIT *nameCount,
67  /*O*/ U16BIT *totalNameLength )
68 {
69  P_DsmObject pDsmObject = (P_DsmObject) dir;
70  E_DscError err;
71  P_Module pModule;
72  MemPtr mpObjectData;
73  MemPtr mpBindingData;
74  U16BIT numBindings;
75  U16BIT nameLens;
76 
77  if (!DSM_OBJECT_VALIDATE( pDsmObject ))
78  {
79  dsmDP1(("API ERROR: Invalid object handle\n"));
80  err = CLDSM_ERR_INVALID_OBJECT_HANDLE;
81  }
82  else if (pDsmObject->status != OBJ_LOAD_COMPLETED)
83  {
84  err = CLDSM_ERR_OBJECT_NOT_LOADED;
85  }
86  else if (pDsmObject->objectDataSeq == NULL)
87  {
88  err = CLDSM_ERR_OBJECT_NOT_OPEN;
89  }
90  else
91  {
92  switch (pDsmObject->kind)
93  {
94  default:
95  err = CLDSM_ERR_INVALID_OBJECT_TYPE;
96  break;
97 
98  case DIRECTORY_OBJ:
99  case SERVICE_GATEWAY_OBJ:
100  pModule = pDsmObject->pModule;
101  if (!moduleDataFindObject(pModule->hModuleData, pModule->moduleInfo.originalSize,
102  &(pDsmObject->objectInfo.objectKey), &mpObjectData ))
103  {
104  err = CLDSM_ERR_OBJECT_NOT_LOADED;
105  }
106  else
107  {
108  numBindings = odDirCountAndFirstBinding( mpObjectData, &(pDsmObject->objectInfo), &mpBindingData );
109  *nameCount = numBindings;
110  nameLens = 0;
111  while (numBindings--)
112  {
113  nameLens += odDirBindingNameLength( mpBindingData );
114  if (!odDirGetNextBinding( mpBindingData, &mpBindingData ))
115  {
116  break;
117  }
118  }
119  *totalNameLength = nameLens;
120  err = CLDSM_OK;
121  }
122  }
123  }
124  return err;
125 }
126 
127 /*******************************************************************************
128 *
129 * The directory object (dirObj) must be LOADED and OPEN.
130 *
131 * Retrieve the first entry handle
132 *
133 * RETURNS:
134 * CLDSM_OK (0)
135 * CLDSM_ERR_INVALID_OBJECT_HANDLE
136 * CLDSM_ERR_INVALID_OBJECT_TYPE
137 * CLDSM_ERR_OBJECT_NOT_LOADED
138 * CLDSM_ERR_OBJECT_NOT_OPEN
139 * CLDSM_ERR_END_OF_DATA
140 *
141 *******************************************************************************/
142 E_DscError CDSM_DirEntryFirst(
143  /*I*/ H_DsmObject dir,
144  /*O*/ void **pFirstEntry )
145 {
146  P_DsmObject pDsmObject = (P_DsmObject) dir;
147  E_DscError err;
148  P_Module pModule;
149  MemPtr mpObjectData;
150 
151  if (!DSM_OBJECT_VALIDATE( pDsmObject ))
152  {
153  dsmDP1(("API ERROR: Invalid object handle\n"));
154  err = CLDSM_ERR_INVALID_OBJECT_HANDLE;
155  }
156  else if (pDsmObject->status != OBJ_LOAD_COMPLETED)
157  {
158  err = CLDSM_ERR_OBJECT_NOT_LOADED;
159  }
160  else if (pDsmObject->objectDataSeq == NULL)
161  {
162  err = CLDSM_ERR_OBJECT_NOT_OPEN;
163  }
164  else
165  {
166  switch (pDsmObject->kind)
167  {
168  default:
169  err = CLDSM_ERR_INVALID_OBJECT_TYPE;
170  break;
171 
172  case DIRECTORY_OBJ:
173  case SERVICE_GATEWAY_OBJ:
174  pModule = pDsmObject->pModule;
175  if (!moduleDataFindObject(pModule->hModuleData, pModule->moduleInfo.originalSize,
176  &(pDsmObject->objectInfo.objectKey), &mpObjectData ))
177  {
178  err = CLDSM_ERR_OBJECT_NOT_LOADED;
179  }
180  else
181  {
182  if (!odDirCountAndFirstBinding( mpObjectData, &(pDsmObject->objectInfo), (PU8BIT *)pFirstEntry ))
183  {
184  *pFirstEntry = NULL;
185  err = CLDSM_ERR_END_OF_DATA;
186  }
187  else
188  {
189  err = CLDSM_OK;
190  }
191  }
192  }
193  }
194  return err;
195 }
196 
197 /*******************************************************************************
198 *
199 * Directory entry handle (entryHandle) is return by dsmDirEntryGetFirst or
200 * dsmDirEntryGetNext.
201 *
202 * Retrieve the next entry handle
203 *
204 * RETURNS:
205 * CLDSM_OK (0)
206 * CLDSM_ERR_INTERNAL
207 *
208 *******************************************************************************/
209 E_DscError CDSM_DirEntryNext(
210  /*I*/ void *entryHandle,
211  /*O*/ void **pNextEntry )
212 {
213  if (!odDirGetNextBinding((const PU8BIT)entryHandle, (PU8BIT *)pNextEntry ))
214  {
215  return CLDSM_ERR_INTERNAL;
216  }
217  return CLDSM_OK;
218 }
219 
220 /*******************************************************************************
221 *
222 * The directory entry handle is return by dsmDirEntryGetFirst or
223 * dsmDirEntryGetNext.
224 *
225 * Retrieve name length
226 *
227 * RETURNS:
228 * Length of name copied
229 *
230 *******************************************************************************/
231 U16BIT CDSM_DirEntryNameLength(
232  /*I*/ void *entryHandle )
233 {
234  return odDirBindingNameLength((PU8BIT)entryHandle );
235 }
236 
237 /*******************************************************************************
238 *
239 * The directory entry handle is return by dsmDirEntryGetFirst or
240 * dsmDirEntryGetNext.
241 *
242 * Copy name for entry to supplied memory location (pName)
243 * Caller should ensure there is enough space in location
244 *
245 * RETURNS:
246 * Length of name copied
247 *
248 *******************************************************************************/
249 U16BIT CDSM_DirEntryNameCopy(
250  /*I*/ void *entryHandle,
251  /*O*/ U8BIT *pName )
252 {
253  return odDirBindingNameCopy((PU8BIT)entryHandle, pName );
254 }
255 
256 /*******************************************************************************
257 *
258 * Get the kind of entry this is
259 *
260 * RETURNS:
261 * E_DsmObjectKind
262 *
263 *******************************************************************************/
264 E_DsmObjectKind CDSM_DirEntryKind( void *entryHandle )
265 {
266  U32BIT kind;
267  if (odDirGetBindingKind((PU8BIT)entryHandle, &kind))
268  {
269  return convertObjectKindStr( kind );
270  }
271  return ANON_OBJ;
272 }
273 
274 /*----------------------------------------------------------------------------*/
General include file for clDsm library internal definitions.
Header to dsmObject module - functions for managing DSM object heap.
Header to the 'module' module - Functions/methods for creating/destroying and managing attributes of ...
Header to the moduleData module.