DSMCC  17.9.0
 All Data Structures Files Functions Typedefs
clDsmFile.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 © 2002 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 "dsmObject.h"
28 
29 
30 /*------------------------------- Local Macros -------------------------------*/
31 
32 
33 /*------------------------------ Exported Data -----------------------------*/
34 
35 
36 /*--------------------------------Local Types --------------------------------*/
37 
38 
39 /*------------------------------- Local Statics ------------------------------*/
40 
41 
42 /*------------------- Local prototypes/forward declarations ------------------*/
43 
44 
45 /*---------------------------- Exported Functions ----------------------------*/
46 
47 /*
48 -- Get length of specified file data
49 */
50 E_DscError CDSM_FileGetSize(
51  /*I*/ H_DsmObject file,
52  /*O*/ U32BIT *pSize )
53 {
54  P_DsmObject pDsmObject = (P_DsmObject) file;
55  E_DscError err = CLDSM_OK;
56 
57  dsmDP2(("CDSM_FileGetSize( %p, %p )\n", file, pSize));
58 
59  API_PARAM_CHK( file, dsmDP1(("ERROR: Invalid object handle\n")),
60  err = CLDSM_ERR_INVALID_OBJECT_HANDLE; goto _return );
61  API_PARAM_CHK( pSize, dsmDP1(("ERROR: Illegal parameter\n")),
62  err = CLDSM_ERR_ILLEGAL_PARAMETER; goto _return );
63 
64 
65  if (!DSM_OBJECT_VALIDATE( pDsmObject ))
66  {
67  dsmDP1(("API ERROR: Invalid object handle\n"));
68  err = CLDSM_ERR_INVALID_OBJECT_HANDLE;
69  }
70  else if (pDsmObject->status != OBJ_LOAD_COMPLETED)
71  {
72  err = CLDSM_ERR_OBJECT_NOT_LOADED;
73  }
74  else if (pDsmObject->kind != FILE_OBJ)
75  {
76  err = CLDSM_ERR_INVALID_OBJECT_TYPE;
77  }
78  else if (pDsmObject->objectDataSeq == NULL)
79  {
80  err = CLDSM_ERR_OBJECT_NOT_OPEN;
81  }
82  else
83  {
84  memSeqSize( pDsmObject->objectDataSeq, pSize );
85  }
86 
87  goto _return; /* -- Prevents compiler warnings when no API checking */
88 _return:
89  DEBUG_CHK( err == CLDSM_OK,
90  dsmDP1(("ERROR: dsmFileGetSize: %u\n", err)));
91  dsmDP2(("exit dsmFileGetSize -> rtn: %u, o/p: %u \n", err, *pSize));
92  return err;
93 }
94 
95 /*
96 -- Read specified number of bytes of data from (opened) file
97 */
98 E_DscError CDSM_FileRead(
99  /*I*/ H_DsmObject file, U32BIT numBytes,
100  /*O*/ U8BIT *pDest, U32BIT *pNumBytesActual )
101 {
102  P_DsmObject pDsmObject = (P_DsmObject) file;
103  E_DsmMemErr memErr;
104  E_DscError err = CLDSM_OK;
105 
106  dsmDP2(("CDSM_FileRead( %p, %u, %p, %p )\n",
107  file, numBytes, pDest, pNumBytesActual));
108 
109  API_PARAM_CHK( file, dsmDP1(("ERROR: Invalid object handle\n")),
110  err = CLDSM_ERR_INVALID_OBJECT_HANDLE; goto _return );
111  API_PARAM_CHK( pDest, dsmDP1(("ERROR: Illegal parameter\n")),
112  err = CLDSM_ERR_ILLEGAL_PARAMETER; goto _return );
113  API_PARAM_CHK( pNumBytesActual, dsmDP1(("ERROR: Illegal parameter\n")),
114  err = CLDSM_ERR_ILLEGAL_PARAMETER; goto _return );
115 
116 
117  if (!DSM_OBJECT_VALIDATE( pDsmObject ))
118  {
119  dsmDP1(("API ERROR: Invalid object handle\n"));
120  err = CLDSM_ERR_INVALID_OBJECT_HANDLE;
121  }
122  else if (pDsmObject->status != OBJ_LOAD_COMPLETED)
123  {
124  err = CLDSM_ERR_OBJECT_NOT_LOADED;
125  }
126  else if (pDsmObject->kind != FILE_OBJ)
127  {
128  err = CLDSM_ERR_INVALID_OBJECT_TYPE;
129  }
130  else if (pDsmObject->objectDataSeq == NULL)
131  {
132  err = CLDSM_ERR_OBJECT_NOT_OPEN;
133  }
134  else
135  {
136  memErr = memSeqRead( pDsmObject->objectDataSeq,
137  pDest, numBytes, pNumBytesActual );
138 
139  if (memErr == MEM_ERR_SEQ_END_OF_DATA)
140  {
141  err = CLDSM_ERR_END_OF_DATA;
142  }
143  }
144 
145  goto _return; /* -- Prevents compiler warnings when no API checking */
146 _return:
147  DEBUG_CHK( err == CLDSM_OK,
148  dsmDP1(("ERROR: dsmFileRead: %u\n", err)));
149  dsmDP2(("exit dsmFileRead -> rtn: %u, o/p: %u data bytes\n",
150  err, *pNumBytesActual));
151  return err;
152 }
153 
154 E_DscError CDSM_FileDirect(
155  /*I*/ H_DsmObject file,
156  /*O*/ U8BIT **ppDest, U32BIT *pNumBytesActual )
157 {
158  P_DsmObject pDsmObject = (P_DsmObject) file;
159  E_DscError err = CLDSM_OK;
160 
161  dsmDP2(("CDSM_FileDirect( %p, %u, %p, %p )\n",
162  file, ppDest, pNumBytesActual));
163 
164  API_PARAM_CHK( file, dsmDP1(("ERROR: Invalid object handle\n")),
165  err = CLDSM_ERR_INVALID_OBJECT_HANDLE; goto _return );
166  API_PARAM_CHK( ppDest, dsmDP1(("ERROR: Illegal parameter\n")),
167  err = CLDSM_ERR_ILLEGAL_PARAMETER; goto _return );
168  API_PARAM_CHK( pNumBytesActual, dsmDP1(("ERROR: Illegal parameter\n")),
169  err = CLDSM_ERR_ILLEGAL_PARAMETER; goto _return );
170 
171 
172  if (!DSM_OBJECT_VALIDATE( pDsmObject ))
173  {
174  dsmDP1(("API ERROR: Invalid object handle\n"));
175  err = CLDSM_ERR_INVALID_OBJECT_HANDLE;
176  }
177  else if (pDsmObject->status != OBJ_LOAD_COMPLETED)
178  {
179  err = CLDSM_ERR_OBJECT_NOT_LOADED;
180  }
181  else if (pDsmObject->kind != FILE_OBJ)
182  {
183  err = CLDSM_ERR_INVALID_OBJECT_TYPE;
184  }
185  else if (pDsmObject->objectDataSeq == NULL)
186  {
187  err = CLDSM_ERR_OBJECT_NOT_OPEN;
188  }
189  else
190  {
191  memSeqAccessContig( pDsmObject->objectDataSeq, ppDest, pNumBytesActual );
192  }
193 
194  goto _return; /* -- Prevents compiler warnings when no API checking */
195 _return:
196  DEBUG_CHK( err == CLDSM_OK,
197  dsmDP1(("ERROR: clDsmFileDirect: %u\n", err)));
198  dsmDP2(("exit clDsmFileDirect -> rtn: %u, o/p: %u data bytes\n",
199  err, *pNumBytesActual));
200  return err;
201 }
202 
203 /*
204 -- Read single byte of data from (opened) file
205 */
206 E_DscError CDSM_FileReadByte(
207  /*I*/ H_DsmObject file,
208  /*O*/ U8BIT *pDest )
209 {
210  P_DsmObject pDsmObject = (P_DsmObject) file;
211  E_DsmMemErr memErr;
212  E_DscError err = CLDSM_OK;
213 
214  dsmDP2(("CDSM_FileReadByte( %p, %p )\n", file, pDest));
215 
216  API_PARAM_CHK( file, dsmDP1(("ERROR: Invalid object handle\n")),
217  err = CLDSM_ERR_INVALID_OBJECT_HANDLE; goto _return );
218  API_PARAM_CHK( pDest, dsmDP1(("ERROR: Illegal parameter\n")),
219  err = CLDSM_ERR_ILLEGAL_PARAMETER; goto _return );
220 
221 
222  if (!DSM_OBJECT_VALIDATE( pDsmObject ))
223  {
224  dsmDP1(("API ERROR: Invalid object handle\n"));
225  err = CLDSM_ERR_INVALID_OBJECT_HANDLE;
226  }
227  else if (pDsmObject->status != OBJ_LOAD_COMPLETED)
228  {
229  err = CLDSM_ERR_OBJECT_NOT_LOADED;
230  }
231  else if (pDsmObject->kind != FILE_OBJ)
232  {
233  err = CLDSM_ERR_INVALID_OBJECT_TYPE;
234  }
235  else if (pDsmObject->objectDataSeq == NULL)
236  {
237  err = CLDSM_ERR_OBJECT_NOT_OPEN;
238  }
239  else
240  {
241  memErr = memSeqReadByte( pDsmObject->objectDataSeq, pDest );
242 
243  if (memErr == MEM_ERR_SEQ_END_OF_DATA)
244  {
245  err = CLDSM_ERR_END_OF_DATA;
246  }
247  }
248 
249  goto _return; /* -- Prevents compiler warnings when no API checking */
250 _return:
251  DEBUG_CHK( err == CLDSM_OK,
252  dsmDP1(("ERROR: dsmFileReadByte: %u\n", err)));
253  dsmDP2(("exit dsmFileReadByte -> rtn: %u, o/p: %u \n", err, *pDest));
254  return err;
255 }
256 
257 /*
258 -- Set absolute file data 'cursor' position
259 */
260 E_DscError CDSM_FileSetPosAbs(
261  /*I*/ H_DsmObject file, U32BIT absPosition )
262 {
263  P_DsmObject pDsmObject = (P_DsmObject) file;
264  E_DsmMemErr memErr;
265  E_DscError err = CLDSM_OK;
266 
267  dsmDP2(("CDSM_FileSetPosAbs( %p, %u )\n", file, absPosition));
268 
269  API_PARAM_CHK( file, dsmDP1(("ERROR: Invalid object handle\n")),
270  err = CLDSM_ERR_INVALID_OBJECT_HANDLE; goto _return );
271 
272 
273  if (!DSM_OBJECT_VALIDATE( pDsmObject ))
274  {
275  dsmDP1(("API ERROR: Invalid object handle\n"));
276  err = CLDSM_ERR_INVALID_OBJECT_HANDLE;
277  }
278  else if (pDsmObject->status != OBJ_LOAD_COMPLETED)
279  {
280  err = CLDSM_ERR_OBJECT_NOT_LOADED;
281  }
282  else if (pDsmObject->kind != FILE_OBJ)
283  {
284  err = CLDSM_ERR_INVALID_OBJECT_TYPE;
285  }
286  else if (pDsmObject->objectDataSeq == NULL)
287  {
288  err = CLDSM_ERR_OBJECT_NOT_OPEN;
289  }
290  else
291  {
292  memErr = memSeqSetPosAbs( pDsmObject->objectDataSeq, absPosition );
293 
294  if (memErr == MEM_ERR_SEQ_END_OF_DATA)
295  {
296  err = CLDSM_ERR_END_OF_DATA;
297  }
298  }
299 
300  goto _return; /* -- Prevents compiler warnings when no API checking */
301 _return:
302  DEBUG_CHK( err == CLDSM_OK,
303  dsmDP1(("ERROR: dsmFileSetPosAbs: %u\n", err)));
304  dsmDP2(("exit dsmFileSetPosAbs -> rtn: %u \n", err));
305  return err;
306 }
307 
308 /*
309 -- Set relative file data 'cursor' position
310 */
311 E_DscError CDSM_FileSetPosRel(
312  /*I*/ H_DsmObject file, S32BIT relPosition )
313 {
314  P_DsmObject pDsmObject = (P_DsmObject) file;
315  E_DsmMemErr memErr;
316  E_DscError err = CLDSM_OK;
317 
318  dsmDP2(("CDSM_FileSetPosRel( %p, %d )\n", file, relPosition));
319 
320  API_PARAM_CHK( file, dsmDP1(("ERROR: Invalid object handle\n")),
321  err = CLDSM_ERR_INVALID_OBJECT_HANDLE; goto _return );
322 
323 
324  if (!DSM_OBJECT_VALIDATE( pDsmObject ))
325  {
326  dsmDP1(("API ERROR: Invalid object handle\n"));
327  err = CLDSM_ERR_INVALID_OBJECT_HANDLE;
328  }
329  else if (pDsmObject->status != OBJ_LOAD_COMPLETED)
330  {
331  err = CLDSM_ERR_OBJECT_NOT_LOADED;
332  }
333  else if (pDsmObject->kind != FILE_OBJ)
334  {
335  err = CLDSM_ERR_INVALID_OBJECT_TYPE;
336  }
337  else if (pDsmObject->objectDataSeq == NULL)
338  {
339  err = CLDSM_ERR_OBJECT_NOT_OPEN;
340  }
341  else
342  {
343  memErr = memSeqSetPosRel( pDsmObject->objectDataSeq, relPosition );
344 
345  if (memErr == MEM_ERR_SEQ_END_OF_DATA)
346  {
347  err = CLDSM_ERR_END_OF_DATA;
348  }
349  }
350 
351  goto _return; /* -- Prevents compiler warnings when no API checking */
352 _return:
353  DEBUG_CHK( err == CLDSM_OK,
354  dsmDP1(("ERROR: dsmFileSetPosRel: %u\n", err)));
355  dsmDP2(("exit dsmFileSetPosRel -> rtn: %u \n", err));
356  return err;
357 }
358 
359 /*
360 -- Read file data 'cursor' position
361 */
362 E_DscError CDSM_FileGetPos(
363  /*I*/ H_DsmObject file, U32BIT *pPosition )
364 {
365  P_DsmObject pDsmObject = (P_DsmObject) file;
366  E_DscError err = CLDSM_OK;
367 
368  dsmDP2(("CDSM_FileGetPos( %p, %p )\n", file, pPosition));
369 
370  API_PARAM_CHK( file, dsmDP1(("ERROR: Invalid object handle\n")),
371  err = CLDSM_ERR_INVALID_OBJECT_HANDLE; goto _return );
372  API_PARAM_CHK( pPosition, dsmDP1(("ERROR: Illegal parameter\n")),
373  err = CLDSM_ERR_ILLEGAL_PARAMETER; goto _return );
374 
375 
376  if (!DSM_OBJECT_VALIDATE( pDsmObject ))
377  {
378  dsmDP1(("API ERROR: Invalid object handle\n"));
379  err = CLDSM_ERR_INVALID_OBJECT_HANDLE;
380  }
381  else if (pDsmObject->status != OBJ_LOAD_COMPLETED)
382  {
383  err = CLDSM_ERR_OBJECT_NOT_LOADED;
384  }
385  else if (pDsmObject->kind != FILE_OBJ)
386  {
387  err = CLDSM_ERR_INVALID_OBJECT_TYPE;
388  }
389  else if (pDsmObject->objectDataSeq == NULL)
390  {
391  err = CLDSM_ERR_OBJECT_NOT_OPEN;
392  }
393  else
394  {
395  memSeqReadPos( pDsmObject->objectDataSeq, pPosition );
396  }
397 
398  goto _return; /* -- Prevents compiler warnings when no API checking */
399 _return:
400  DEBUG_CHK( err == CLDSM_OK,
401  dsmDP1(("ERROR: dsmFileGetPos: %u\n", err)));
402  dsmDP2(("exit dsmFileGetPos -> rtn: %u, o/p: %u \n", err, *pPosition));
403  return err;
404 }
405 
406 /*----------------------------------------------------------------------------*/
General include file for clDsm library internal definitions.
Header to dsmObject module - functions for managing DSM object heap.