78 static MHEG5Int memUsed(
void)
83 for (i = 0; i < MAXFILES; i++)
85 rc += file_list[i].data.len;
96 static MHEG5Int numUsed(
void)
101 for (i = 0; i < MAXFILES; i++)
103 rc += (file_list[i].free == MHEG5FALSE);
120 for (i = 0; i != MAXFILES; i++)
122 file_list[i].data.len = 0;
123 file_list[i].name.len = 0;
124 file_list[i].next = 0;
125 file_list[i].prev = 0;
126 file_list[i].free = MHEG5TRUE;
141 for (i = 0; i != MAXFILES; i++)
143 if (!file_list[i].free)
147 file_list[i].name.len = 0;
148 file_list[i].next = 0;
149 file_list[i].prev = 0;
150 file_list[i].free = MHEG5TRUE;
170 INFO_PRINT((
"BEGIN: MHEG5storageWrite - File [%.*s], Length [0x%x].\n", fn.len, fn.data, len));
173 if (len > MHEG5STORAGE_MEMSIZE)
175 DEBUG_PRINT((
"ERROR: MHEG5storageWrite - File [%.*s] too big [0x%x].\n", fn.len, fn.data, len));
180 for (i = 0; i != MAXFILES; i++)
185 INFO_PRINT((
"WARNING: MHEG5storageWrite - Found duplicate file name [%.*s] in list.\n", fn.len, fn.data));
189 file_list[i].free = MHEG5TRUE;
192 if (file_list[i].prev != 0)
194 file_list[i].prev->next = file_list[i].next;
197 if (file_list[i].next != 0)
199 file_list[i].next->prev = file_list[i].prev;
202 if (file_list_top == &file_list[i])
204 file_list_top = file_list[i].next;
207 file_list[i].prev = 0;
208 file_list[i].next = 0;
215 while ((memUsed() + len > MHEG5STORAGE_MEMSIZE || count == MAXFILES) &&
216 (file_list_top != 0))
218 INFO_PRINT((
"WARNING: MHEG5storageWrite - Not enough space in list, deleting files.\n"));
219 temp_file = file_list_top;
222 DEBUG_PRINT((
"ERROR: MHEG5storageWrite - Cannot remove from empty list.\n"));
226 while (temp_file->next != 0)
228 temp_file = temp_file->next;
234 temp_file->free = MHEG5TRUE;
237 if (temp_file->prev != 0)
239 temp_file->prev->next = temp_file->next;
242 if (file_list_top == temp_file)
253 while (i < MAXFILES && file_list[i].free != MHEG5TRUE)
260 DEBUG_PRINT((
"ERROR: MHEG5storageWrite - No empty slot in list.\n"));
265 file_list[i].data.data = STR_DataAlloc( len );
266 if (!file_list[i].data.data)
268 DEBUG_PRINT((
"ERROR: MHEG5storageWrite - Unable to allocate memory for file.\n"));
272 file_list[i].data.len = len;
273 file_list[i].free = MHEG5FALSE;
274 memcpy(file_list[i].data.data, buf, len);
277 file_list[i].next = file_list_top;
278 if (file_list[i].next != 0)
280 file_list[i].next->prev = &file_list[i];
282 file_list[i].prev = 0;
283 file_list_top = &file_list[i];
285 INFO_PRINT((
"SUCCESS: MHEG5storageWrite - File [%.*s] added to list.\n", fn.len, fn.data));
300 INFO_PRINT((
"BEGIN: MHEG5storageRead - File [%.*s].\n", fn.len, fn.data));
302 if (buf == 0 || len == 0)
304 DEBUG_PRINT((
"ERROR: MHEG5storageRead - Bad data variable pointer passed.\n"));
307 for (i = 0; i < MAXFILES; i++)
311 *buf = file_list[i].data.data;
312 *len = file_list[i].data.len;
314 INFO_PRINT((
"SUCCESS: MHEG5storageRead - Found file [%.*s] in list.\n", fn.len, fn.data));
318 INFO_PRINT((
"WARNING: MHEG5storageRead - Unable to find file [%.*s] in list.\n", fn.len, fn.data));
MHEG5Bool MHEG5storageWrite(MHEG5String fn, void *buf, MHEG5Int len)
Write a file to the persistent store.
MHEG5Bool MHEG5stringEqual(MHEG5String *s1, MHEG5String *s2)
Compare two Strings (case sensitive!)
MHEG5String MHEG5stringCopy(MHEG5String source)
<Function description>="">
void MHEG5InitStore(void)
Initialise Persistent Storage.
void MHEG5stringDestruct(MHEG5String *item)
Destruct a MHEG5String.
void MHEG5ResetStore(void)
destroy Persistent Storage - only really useful on platform like WINDOWS
MHEG5Bool MHEG5storageRead(MHEG5String fn, void **buf, MHEG5Int *len)
Read a file from the persistent store.
This file defines the profile for the MHEG engine.
Mheg5 logging and debug printing.
Persistent storage module. The engine provides a persistent storage for 1024 bytes of data...