1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
|
/*
* Copyright (C) 2004-2011 NXP Software
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
************************************************************************
* @file M4OSA_FileWriter.c
* @brief File writer for Android
* @note This file implements functions to write in a file.
************************************************************************
*/
#include "M4OSA_Debug.h"
#include "M4OSA_FileCommon_priv.h"
#include "M4OSA_FileWriter.h"
#include "M4OSA_FileWriter_priv.h"
#include "M4OSA_Memory.h"
#ifdef M4OSA_FILE_BLOCK_WITH_SEMAPHORE
#include "M4OSA_Semaphore.h"
#endif /* M4OSA_FILE_BLOCK_WITH_SEMAPHORE */
/**
************************************************************************
* @brief This function opens the provided URL and returns its context.
* If an error occured, the context is set to NULL.
* @param pContext: (OUT) Context of the core file writer
* @param pUrl: (IN) URL of the input file
* @param fileModeAccess: (IN) File mode access
* @return M4NO_ERROR: there is no error
* @return M4ERR_PARAMETER: at least one parameter is NULL
* @return M4ERR_ALLOC: there is no more memory available
* @return M4ERR_NOT_IMPLEMENTED: the URL does not match with the supported
* file
* @return M4ERR_FILE_NOT_FOUND: the file cannot be found
* @return M4ERR_FILE_LOCKED: the file is locked by an other
* application/process
* @return M4ERR_FILE_BAD_MODE_ACCESS: the file mode access is not correct
************************************************************************
*/
M4OSA_ERR M4OSA_fileWriteOpen(M4OSA_Context* pContext, M4OSA_Void* pUrl,
M4OSA_UInt32 fileModeAccess)
{
M4OSA_TRACE1_3("M4OSA_fileWriteOpen : pC = 0x%p fd = 0x%p mode = %d",
pContext, pUrl, fileModeAccess);
return M4OSA_fileCommonOpen(M4OSA_FILE_WRITER, pContext, pUrl,
fileModeAccess);
}
/**
************************************************************************
* @brief This function writes the 'size' bytes stored at 'data' memory
* in the file selected by its context.
* @note The caller is responsible for allocating/de-allocating the
* memory for 'data' parameter.
* @note Moreover the data pointer must be allocated to store at least
* 'size' bytes.
* @param pContext: (IN/OUT) Context of the core file reader
* @param buffer: (IN) Data pointer of the write data
* @param size: (IN) Size of the data to write (in bytes)
* @return M4NO_ERROR: there is no error
* @return M4ERR_PARAMETER: at least one parameter is NULL
* @return M4ERR_BAD_CONTEXT: provided context is not a valid one
* @return M4ERR_ALLOC: there is no more memory available
************************************************************************
*/
M4OSA_ERR M4OSA_fileWriteData(M4OSA_Context pContext, M4OSA_MemAddr8 data,
M4OSA_UInt32 uiSize)
{
M4OSA_FileContext* pFileContext = pContext;
M4OSA_ERR err;
M4OSA_UInt32 uiSizeWrite;
M4OSA_TRACE2_2("M4OSA_fileWriteData : data = 0x%p size = %lu", data,
uiSize);
M4OSA_DEBUG_IF2(M4OSA_NULL == pContext, M4ERR_PARAMETER,
"M4OSA_fileWriteData: pContext is M4OSA_NULL");
M4OSA_DEBUG_IF2(M4OSA_NULL == data, M4ERR_PARAMETER,
"M4OSA_fileWriteData: data is M4OSA_NULL");
M4OSA_DEBUG_IF2(0 == uiSize, M4ERR_PARAMETER,
"M4OSA_fileWriteData: uiSize is 0");
#ifdef M4OSA_FILE_BLOCK_WITH_SEMAPHORE
M4OSA_DEBUG_IF2(M4OSA_NULL == pFileContext->semaphore_context,
M4ERR_BAD_CONTEXT,
"M4OSA_fileWriteData: semaphore_context is M4OSA_NULL");
#endif /* M4OSA_FILE_BLOCK_WITH_SEMAPHORE */
if (M4OSA_kDescRWAccess == pFileContext->m_DescrModeAccess)
{
M4OSA_UInt32 WriteSize;
err = M4NO_ERROR;
WriteSize = fwrite((void *)data,1, uiSize, pFileContext->file_desc);
if(WriteSize != uiSize)
{
/* converts the error to PSW format*/
err = ((M4OSA_UInt32)(M4_ERR)<<30)+(((M4OSA_FILE_WRITER)&0x003FFF)<<16)+(M4OSA_Int16)(WriteSize);
M4OSA_TRACE1_1("M4OSA_FileWriteData error:%x",err);
}
fflush(pFileContext->file_desc);
M4OSA_FPOS_ADD_CONST_UINT32(pFileContext->write_position, pFileContext->write_position, WriteSize);
/* Update the file size */
if(M4OSA_FPOS_COMPARE(pFileContext->write_position, pFileContext->file_size) > 0)
{
M4OSA_FPOS_SET(pFileContext->file_size, pFileContext->write_position);
}
return err;
}
#ifdef M4OSA_FILE_BLOCK_WITH_SEMAPHORE
M4OSA_semaphoreWait(pFileContext->semaphore_context, M4OSA_WAIT_FOREVER);
#endif /* M4OSA_FILE_BLOCK_WITH_SEMAPHORE */
if(pFileContext->current_seek != SeekWrite)
{
/* fseek to the last read position */
err = M4OSA_fileCommonSeek(pContext, M4OSA_kFileSeekBeginning,
&(pFileContext->write_position));
if(M4OSA_ERR_IS_ERROR(err))
{
#ifdef M4OSA_FILE_BLOCK_WITH_SEMAPHORE
M4OSA_semaphorePost(pFileContext->semaphore_context);
#endif /* M4OSA_FILE_BLOCK_WITH_SEMAPHORE */
M4OSA_DEBUG(err, "M4OSA_fileWriteData: M4OSA_fileCommonSeek");
return err;
}
pFileContext->current_seek = SeekWrite;
}
/* Write data */
uiSizeWrite = fwrite(data, sizeof(M4OSA_Char), uiSize, pFileContext->file_desc);
if(uiSizeWrite == (M4OSA_UInt32)-1)
{
#ifdef M4OSA_FILE_BLOCK_WITH_SEMAPHORE
M4OSA_semaphorePost(pFileContext->semaphore_context);
#endif /* M4OSA_FILE_BLOCK_WITH_SEMAPHORE */
/* An error occured */
M4OSA_DEBUG(M4ERR_BAD_CONTEXT, "M4OSA_fileWriteData: fwrite failed");
return M4ERR_BAD_CONTEXT;
}
M4OSA_FPOS_ADD_CONST_UINT32(pFileContext->write_position,
pFileContext->write_position,
uiSizeWrite);
/* Update the file size */
if(M4OSA_FPOS_COMPARE(pFileContext->write_position, pFileContext->file_size) > 0)
{
M4OSA_FPOS_SET(pFileContext->file_size, pFileContext->write_position);
}
if((M4OSA_UInt32)uiSizeWrite < uiSize)
{
#ifdef M4OSA_FILE_BLOCK_WITH_SEMAPHORE
M4OSA_semaphorePost(pFileContext->semaphore_context);
#endif /* M4OSA_FILE_BLOCK_WITH_SEMAPHORE */
M4OSA_DEBUG(M4ERR_ALLOC, "M4OSA_fileWriteData");
return M4ERR_ALLOC;
}
#ifdef M4OSA_FILE_BLOCK_WITH_SEMAPHORE
M4OSA_semaphorePost(pFileContext->semaphore_context);
#endif /* M4OSA_FILE_BLOCK_WITH_SEMAPHORE */
return M4NO_ERROR;
}
/**
************************************************************************
* @brief This function seeks at the provided position in the core file
* writer (selected by its 'context'). The position is related to
* the seekMode parameter it can be either from the beginning,
* from the end or from the current postion. To support large file
* access (more than 2GBytes), the position is provided on a 64
* bits.
* @note If this function returns an error the current position pointer
* in the file must not change. Else the current position pointer
* must be updated.
* @param pContext: (IN/OUT) Context of the core file reader
* @param seekMode: (IN) Seek access mode
* @param position: (IN/OUT) Position in the file
* @return M4NO_ERROR: there is no error
* @return M4ERR_PARAMETER: at least one parameter is NULL
* @return M4ERR_BAD_CONTEXT: provided context is not a valid one
* @return M4ERR_ALLOC: there is no more memory available
* @return M4ERR_FILE_INVALID_POSITION: the position cannot be reached
************************************************************************
*/
M4OSA_ERR M4OSA_fileWriteSeek(M4OSA_Context pContext, M4OSA_FileSeekAccessMode seekMode,
M4OSA_FilePosition* pPosition)
{
M4OSA_FileContext* pFileContext = (M4OSA_FileContext*)pContext;
M4OSA_ERR err;
M4OSA_TRACE2_2("M4OSA_fileWriteSeek : mode = %d pos = %lu",
seekMode, (M4OSA_NULL != pPosition) ? (*pPosition) : 0);
M4OSA_DEBUG_IF2(M4OSA_NULL == pContext, M4ERR_PARAMETER,
"M4OSA_fileWriteSeek: pContext is M4OSA_NULL");
M4OSA_DEBUG_IF2(0 == seekMode, M4ERR_PARAMETER,
"M4OSA_fileWriteSeek: seemMode is 0");
M4OSA_DEBUG_IF2(M4OSA_NULL == pPosition, M4ERR_PARAMETER,
"M4OSA_fileWriteSeek: pPosition is M4OSA_NULL");
#ifdef M4OSA_FILE_BLOCK_WITH_SEMAPHORE
M4OSA_DEBUG_IF2(M4OSA_NULL == pFileContext->semaphore_context, M4ERR_BAD_CONTEXT,
"M4OSA_fileWriteSeek: semaphore_context is M4OSA_NULL");
#endif /* M4OSA_FILE_BLOCK_WITH_SEMAPHORE */
if (M4OSA_kDescRWAccess == pFileContext->m_DescrModeAccess) /* read write */
{
M4OSA_UInt32 SeekModeOption;
/*The position for the seek mode between the SHP and the OSAl part are different */
if (M4OSA_kFileSeekBeginning == seekMode)
{
SeekModeOption = SEEK_SET;
}
else if (M4OSA_kFileSeekEnd == seekMode)
{
SeekModeOption = SEEK_END;
}
else if (M4OSA_kFileSeekCurrent == seekMode)
{
SeekModeOption = SEEK_CUR;
}
else
{
M4OSA_TRACE1_0("M4OSA_fileWriteSeek: END WITH ERROR !!! (CONVERION ERROR FOR THE SEEK MODE) ");
return M4ERR_PARAMETER;
}
/**
* Go to the desired position */
err = fseek(pFileContext->file_desc,*pPosition,SeekModeOption);
if(err != 0)
{
/* converts the error to PSW format*/
err=((M4OSA_UInt32)(M4_ERR)<<30)+(((M4OSA_FILE_WRITER)&0x003FFF)<<16)+(M4OSA_Int16)(err);
M4OSA_TRACE1_1("M4OSA_FileWriteSeek error:%x",err);
}
else
{
return M4NO_ERROR;
}
return err;
}
#ifdef M4OSA_FILE_BLOCK_WITH_SEMAPHORE
M4OSA_semaphoreWait(pFileContext->semaphore_context, M4OSA_WAIT_FOREVER);
#endif /* M4OSA_FILE_BLOCK_WITH_SEMAPHORE */
err = M4OSA_fileCommonSeek(pContext, seekMode, pPosition);
if(M4OSA_ERR_IS_ERROR(err))
{
M4OSA_DEBUG(err, "M4OSA_fileWriteSeek: M4OSA_fileCommonSeek");
#ifdef M4OSA_FILE_BLOCK_WITH_SEMAPHORE
M4OSA_semaphorePost(pFileContext->semaphore_context);
#endif /* M4OSA_FILE_BLOCK_WITH_SEMAPHORE */
return err;
}
M4OSA_FPOS_SET(pFileContext->write_position, *pPosition);
pFileContext->current_seek = SeekWrite;
#ifdef M4OSA_FILE_BLOCK_WITH_SEMAPHORE
M4OSA_semaphorePost(pFileContext->semaphore_context);
#endif /* M4OSA_FILE_BLOCK_WITH_SEMAPHORE */
return M4NO_ERROR;
}
/**
************************************************************************
* @brief This function asks the core file writer to close the file
* (associated to the context).
* @note The context of the core file writer is freed.
* @param pContext: (IN/OUT) Context of the core file writer
* @return M4NO_ERROR: there is no error
* @return M4ERR_PARAMETER: at least one parameter is NULL
* @return M4ERR_BAD_CONTEXT: provided context is not a valid one
* @return M4ERR_ALLOC: there is no more memory available
************************************************************************
*/
M4OSA_ERR M4OSA_fileWriteClose(M4OSA_Context pContext)
{
M4OSA_FileContext* pFileContext = (M4OSA_FileContext*)pContext;
M4OSA_TRACE1_1("M4OSA_fileWriteClose : pC = 0x%p", pContext);
M4OSA_DEBUG_IF2(M4OSA_NULL == pContext, M4ERR_PARAMETER,
"M4OSA_fileWriteClose: pContext is M4OSA_NULL");
return M4OSA_fileCommonClose(M4OSA_FILE_WRITER, pContext);
}
/**
************************************************************************
* @brief This function flushes the stream associated to the context.
* @param pContext: (IN/OUT) Context of the core file writer
* @return M4NO_ERROR: there is no error
* @return M4ERR_PARAMETER: at least one parameter is NULL
* @return M4ERR_BAD_CONTEXT: provided context is not a valid one
************************************************************************
*/
M4OSA_ERR M4OSA_fileWriteFlush(M4OSA_Context pContext)
{
M4OSA_FileContext* pFileContext = pContext;
M4OSA_ERR err = M4NO_ERROR;
M4OSA_TRACE2_1("M4OSA_fileWriteFlush : pC = 0x%p", pContext);
M4OSA_DEBUG_IF2(M4OSA_NULL == pContext, M4ERR_PARAMETER,
"M4OSA_fileWriteFlush: pcontext is M4OSA_NULL");
#ifdef M4OSA_FILE_BLOCK_WITH_SEMAPHORE
M4OSA_DEBUG_IF2(M4OSA_NULL == pFileContext->semaphore_context, M4ERR_BAD_CONTEXT,
"M4OSA_fileWriteFlush: semaphore_context is M4OSA_NULL");
#endif /* M4OSA_FILE_BLOCK_WITH_SEMAPHORE */
#ifdef M4OSA_FILE_BLOCK_WITH_SEMAPHORE
M4OSA_semaphoreWait(pFileContext->semaphore_context, M4OSA_WAIT_FOREVER);
#endif /* M4OSA_FILE_BLOCK_WITH_SEMAPHORE */
if (fflush(pFileContext->file_desc) != 0)
{
err = M4ERR_BAD_CONTEXT;
}
#ifdef M4OSA_FILE_BLOCK_WITH_SEMAPHORE
M4OSA_semaphorePost(pFileContext->semaphore_context);
#endif /* M4OSA_FILE_BLOCK_WITH_SEMAPHORE */
return err;
}
/**
************************************************************************
* @brief This function asks the core file writer to return the value
* associated with the optionID.
* The caller is responsible for allocating/de-allocating the
* memory of the value field.
* @note 'value' must be cast according to the type related to the
* optionID
* As the caller is responsible for allocating/de-allocating the
* 'value' field, the callee must copy this field
* to its internal variable.
* @param pContext: (IN/OUT) Context of the core file writer
* @param optionID: (IN) ID of the option
* @param value: (OUT) Value of the option
* @return M4NO_ERROR: there is no error
* @return M4ERR_PARAMETER: at least one parameter is NULL
* @return M4ERR_BAD_CONTEXT: provided context is not a valid one
* @return M4ERR_BAD_OPTION_ID: the optionID is not a valid one
* @return M4ERR_WRITE_ONLY: this option is a write only one
* @return M4ERR_NOT_IMPLEMENTED: this option is not implemented
************************************************************************
*/
M4OSA_ERR M4OSA_fileWriteGetOption(M4OSA_Context pContext, M4OSA_OptionID optionID,
M4OSA_DataOption* pOptionValue)
{
M4OSA_FileContext* pFileContext = pContext;
M4OSA_TRACE2_1("M4OSA_fileWriteGetOption : option = 0x%x", optionID);
M4OSA_DEBUG_IF2(M4OSA_NULL == pContext, M4ERR_PARAMETER,
"M4OSA_fileWriteGetOption: pContext is M4OSA_NULL");
M4OSA_DEBUG_IF2(optionID == 0, M4ERR_PARAMETER, "M4OSA_fileWriteGetOption");
M4OSA_DEBUG_IF2(M4OSA_NULL == pOptionValue, M4ERR_PARAMETER,
"M4OSA_fileWriteGetOption: pOtionValue is M4OSA_NULL");
M4OSA_DEBUG_IF2(!M4OSA_OPTION_ID_IS_COREID(optionID, M4OSA_FILE_WRITER),
M4ERR_BAD_OPTION_ID, "M4OSA_fileWriteGetOption");
M4OSA_DEBUG_IF2(!M4OSA_OPTION_ID_IS_READABLE(optionID), M4ERR_WRITE_ONLY,
"M4OSA_fileWriteGetOption");
#ifdef M4OSA_FILE_BLOCK_WITH_SEMAPHORE
M4OSA_DEBUG_IF2(M4OSA_NULL == pFileContext->semaphore_context, M4ERR_BAD_CONTEXT,
"M4OSA_fileWriteGetOption: semaphore_context is M4OSA_NULL");
#endif /* M4OSA_FILE_BLOCK_WITH_SEMAPHORE */
switch(optionID)
{
#if(M4OSA_OPTIONID_FILE_WRITE_GET_FILE_POSITION == M4OSA_TRUE)
case M4OSA_kFileWriteGetFilePosition:
{
M4OSA_FilePosition* position = (M4OSA_FilePosition*)pOptionValue;
#ifdef M4OSA_FILE_BLOCK_WITH_SEMAPHORE
M4OSA_semaphoreWait(pFileContext->semaphore_context, M4OSA_WAIT_FOREVER);
#endif /* M4OSA_FILE_BLOCK_WITH_SEMAPHORE */
*position = pFileContext->write_position;
#ifdef M4OSA_FILE_BLOCK_WITH_SEMAPHORE
M4OSA_semaphorePost(pFileContext->semaphore_context);
#endif /* M4OSA_FILE_BLOCK_WITH_SEMAPHORE */
return M4NO_ERROR;
}
#endif /*M4OSA_OPTIONID_FILE_WRITE_GET_FILE_POSITION*/
#if(M4OSA_OPTIONID_FILE_WRITE_GET_FILE_SIZE == M4OSA_TRUE)
case M4OSA_kFileWriteGetFileSize:
{
M4OSA_FilePosition* position = (M4OSA_FilePosition*)pOptionValue;
if(M4OSA_kDescRWAccess == pFileContext->m_DescrModeAccess)
{
M4OSA_Int32 iSavePos = 0;
M4OSA_Int32 iSize = 0;
iSavePos = ftell(pFileContext->file_desc); /*1- Check the first position */
fseek(pFileContext->file_desc, 0, SEEK_END); /*2- Go to the end of the file */
*position = ftell(pFileContext->file_desc); /*3- Check the file size*/
fseek(pFileContext->file_desc, iSavePos, SEEK_SET); /*4- go to the first position*/
return M4NO_ERROR;
}
#ifdef M4OSA_FILE_BLOCK_WITH_SEMAPHORE
M4OSA_semaphoreWait(pFileContext->semaphore_context, M4OSA_WAIT_FOREVER);
#endif /* M4OSA_FILE_BLOCK_WITH_SEMAPHORE */
*position = pFileContext->file_size;
#ifdef M4OSA_FILE_BLOCK_WITH_SEMAPHORE
M4OSA_semaphorePost(pFileContext->semaphore_context);
#endif /* M4OSA_FILE_BLOCK_WITH_SEMAPHORE */
return M4NO_ERROR;
}
#endif /*M4OSA_OPTIONID_FILE_WRITE_GET_FILE_SIZE*/
#if(M4OSA_OPTIONID_FILE_WRITE_GET_URL == M4OSA_TRUE)
case M4OSA_kFileWriteGetURL:
{
return M4OSA_fileCommonGetURL (pContext, (M4OSA_Char**)pOptionValue);
}
#endif /*M4OSA_OPTIONID_FILE_WRITE_GET_URL*/
#if(M4OSA_OPTIONID_FILE_WRITE_GET_FILE_ATTRIBUTE == M4OSA_TRUE)
case M4OSA_kFileWriteGetAttribute:
{
return M4OSA_fileCommonGetAttribute(pContext,
(M4OSA_FileAttribute*)pOptionValue);
}
#endif /*M4OSA_OPTIONID_FILE_WRITE_GET_FILE_ATTRIBUTE*/
#if(M4OSA_OPTIONID_FILE_WRITE_GET_READER_CONTEXT == M4OSA_TRUE)
case M4OSA_kFileWriteGetReaderContext:
{
M4OSA_FileModeAccess access = pFileContext->access_mode;
M4OSA_DEBUG_IF1(!(access & M4OSA_kFileRead), M4ERR_BAD_CONTEXT,
"M4OSA_fileWriteGetOption: M4OSA_kFileRead");
M4OSA_DEBUG_IF1(!(access & M4OSA_kFileWrite), M4ERR_BAD_CONTEXT,
"M4OSA_fileWriteGetOption: M4OSA_kFileWrite");
pFileContext->coreID_read = M4OSA_FILE_READER;
*pOptionValue = pContext;
return M4NO_ERROR;
}
#endif /*M4OSA_OPTIONID_FILE_WRITE_GET_READER_CONTEXT*/
case M4OSA_kFileWriteLockMode:
{
*(M4OSA_UInt32*)pOptionValue = pFileContext->m_uiLockMode;
return M4NO_ERROR;
}
}
M4OSA_DEBUG(M4ERR_NOT_IMPLEMENTED, "M4OSA_fileWriteGetOption");
return M4ERR_NOT_IMPLEMENTED;
}
/**
************************************************************************
* @brief This function asks the core file writer to set the value
* associated with the optionID.
* The caller is responsible for allocating/de-allocating the
* memory of the value field.
* @note As the caller is responsible for allocating/de-allocating the
* 'value' field, the callee must copy this field to its internal
* variable.
* @param pContext: (IN/OUT) Context of the core file writer
* @param optionID: (IN) ID of the option
* @param value: (IN) Value of the option
* @return M4NO_ERROR: there is no error
* @return M4ERR_PARAMETER: at least one parameter is NULL
* @return M4ERR_BAD_CONTEXT: provided context is not a valid one
* @return M4ERR_BAD_OPTION_ID: the optionID is not a valid one
* @return M4ERR_READ_ONLY: this option is a read only one
* @return M4ERR_NOT_IMPLEMENTED: this option is not implemented
************************************************************************
*/
M4OSA_ERR M4OSA_fileWriteSetOption(M4OSA_Context pContext,
M4OSA_OptionID optionID,
M4OSA_DataOption optionValue)
{
M4OSA_FileContext* pFileContext = pContext;
M4OSA_TRACE2_1("M4OSA_fileWriteSetOption : option = 0x%x", optionID);
M4OSA_DEBUG_IF2(M4OSA_NULL == pContext, M4ERR_PARAMETER,
"M4OSA_fileWriteSetOption");
M4OSA_DEBUG_IF2(0 == optionID, M4ERR_PARAMETER, "M4OSA_fileWriteSetOption");
M4OSA_DEBUG_IF2(!M4OSA_OPTION_ID_IS_COREID(optionID, M4OSA_FILE_WRITER),
M4ERR_BAD_OPTION_ID, "M4OSA_fileWriteSetOption");
M4OSA_DEBUG_IF2(!M4OSA_OPTION_ID_IS_WRITABLE(optionID), M4ERR_READ_ONLY,
"M4OSA_fileReadSetOption");
#ifdef M4OSA_FILE_BLOCK_WITH_SEMAPHORE
M4OSA_DEBUG_IF2(M4OSA_NULL == pFileContext->semaphore_context, M4ERR_BAD_CONTEXT,
"M4OSA_fileWriteSetOption: semaphore_context is M4OSA_NULL");
#endif /* M4OSA_FILE_BLOCK_WITH_SEMAPHORE */
switch(optionID)
{
case M4OSA_kFileWriteLockMode:
{
pFileContext->m_uiLockMode = (M4OSA_UInt32)*(M4OSA_UInt32*)optionValue;
return M4NO_ERROR;
}
case M4OSA_kFileWriteDescMode:
{
pFileContext->m_DescrModeAccess = (M4OSA_Int32)*(M4OSA_Int32*)optionValue;
return M4NO_ERROR;
}
default:
return M4ERR_NOT_IMPLEMENTED;
}
return M4ERR_NOT_IMPLEMENTED;
}
|