MHEG5  18.9.0
MHEG5 Documentation
mh5tps.c
Go to the documentation of this file.
1 /*******************************************************************************
2  * Copyright © 2014 The DTVKit Open Software Foundation Ltd (www.dtvkit.org)
3  * Copyright © 2012 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  *******************************************************************************/
25 /*---includes for this file--------------------------------------------------*/
26 #include "stdio.h"
27 #include <assert.h>
28 #include <string.h>
29 
30 #include "mh5base.h"
31 #include "mh5tps.h"
32 #include "mh5misc.h"
33 
34 #include "mherrors.h"
35 #include "techtype.h"
36 #ifndef INCLUDE_TPS
37 #include "mheg5_nvm.h"
38 #else
39 #include "mh5memory.h"
40 #include "mh5date.h"
41 #include "dvb_service.h"
42 #include "stb_nvm.h"
43 #include "glue_queue.h"
44 #endif
45 /*---constant definitions for this file--------------------------------------*/
46 
47 #define FILESIZE_MAX 100
48 #define MAX_PATH_LEN 64
49 
50 #ifdef INCLUDE_TPS
51 #define MAX_FILES 800
52 #define TPS_DIRECTORY "tps/"
53 #define MAX_WRITES_IN_PERIOD 64
54 #define WRITE_PERIOD_DAYS 28
55 #define HEADER_SIZE 9
56 
57 //#define DEBUG_TPS
58 #ifdef DEBUG_TPS
59 #define DBG_PRINT(x) DBG_PRINTF x
60 #define DBG_TPS(x) do { DBG_PRINTF("%s: ", __func__); DBG_PRINTF x; } while (0)
61 #else
62 #define DBG_TPS(x)
63 #define DBG_PRINT(x)
64 #endif
65 
66 #endif
67 
68 /*---local typedef structs for this file-------------------------------------*/
70 
71 #ifdef INCLUDE_TPS
72 typedef struct s_TruePersistentFile
73 {
74  U32BIT filename_len;
75  U8BIT *filename;
76  char *file_path;
77 
78  S_DvbLocator service_info;
79  U8BIT num_writes;
80  U32BIT write_date;
81  void *file_data;
82  MHEG5Int file_len;
83  struct s_TruePersistentFile *next;
84  struct s_TruePersistentFile *previous;
85 } t_TruePersistentFile;
86 #endif
87 
88 /*---local (static) variable declarations for this file----------------------*/
89 #ifdef INCLUDE_TPS
90 static t_TruePersistentFile *file_list_head = NULL;
91 static t_TruePersistentFile *file_list_tail = NULL;
92 static U16BIT file_count = 0;
93 static BOOLEAN init = FALSE;
94 static pS_DvbLocator current_file_list = NULL;
95 static MHEG5Bool TPS_enabled = MHEG5TRUE;
96 static S_DvbLocator current_service;
97 #endif
98 
99 /*---local function prototypes for this file---------------------------------*/
100 
101 #ifdef INCLUDE_TPS
102 
103 static BOOLEAN TPS_StorageRead(S_STRING filename, void **data, U32BIT *data_len);
104 static BOOLEAN TPS_StorageWrite(S_STRING filename, void *data, U32BIT data_len);
105 static E_MhegErr TPS_StorageOpen();
106 static void TPS_StorageClose(void);
107 static BOOLEAN TPS_StorageGetEnabled();
108 
109 static void FreeFile(t_TruePersistentFile *file);
110 static void DeleteFile(t_TruePersistentFile *file);
111 static void ClearCache();
112 static BOOLEAN AddFileToList(t_TruePersistentFile *file);
113 static BOOLEAN LoadFile(char *filename);
114 static t_TruePersistentFile* FindFileByName(S_STRING filename);
115 static BOOLEAN DeleteFileByService(pS_DvbLocator service_info);
116 static BOOLEAN DeleteOldFile();
117 static BOOLEAN ServicesEqual(pS_DvbLocator service_a,
118  pS_DvbLocator service_b);
119 static MHEG5Bool WriteFileToStore( t_TruePersistentFile *out_file);
120 static t_TruePersistentFile* NewFile(S_STRING filename, void *data, MHEG5Int len,
121  pS_DvbLocator service, U32BIT today);
122 
123 static t_TruePersistentFile* OverwriteFileEntry(void *data, MHEG5Int len,
124  pS_DvbLocator service, U32BIT today,
125  t_TruePersistentFile *replaced_file);
126 
127 static t_TruePersistentFile* UpdateFileEntry(t_TruePersistentFile *file, void *data, MHEG5Int len,
128  pS_DvbLocator service);
129 
130 static U32BIT Read32Bits(U8BIT *bytes);
131 static void Store32Bits(U8BIT *bytes, U32BIT value);
132 static U16BIT Read16Bits(U8BIT *bytes);
133 static void Store16Bits(U8BIT *bytes, U16BIT value);
134 
135 #endif
136 
137 /*---global function definitions---------------------------------------------*/
138 
145 {
146  current_service = *pDvbLoc;
147 }
148 
158 {
159  S_STRING filename;
160  BOOLEAN rc = FALSE;
161  filename.zptr = fn.data;
162  filename.zlen = fn.len;
163 
164  DBG_TPS(("reading:%.*s\n", (int)fn.len, fn.data));
165  if (filename.zlen && filename.zlen < 9)
166  {
167  rc = TPS_StorageRead(filename, data, (U32BIT *)len);
168  }
169  if (rc == TRUE)
170  {
171 #ifdef DEBUG_TPS
172  int i;
173  DBG_TPS(("read:\n"));
174  for (i = 0; i < *len; i++)
175  {
176  DBG_PRINT(("0x%x ", ((U8BIT *)*data)[i]));
177  }
178  DBG_PRINT(("\n"));
179 #endif
180  return MHEG5TRUE;
181  }
182  else
183  {
184  return MHEG5FALSE;
185  }
186 }
187 
197 {
198  MHEG5Bool success = MHEG5FALSE;
199  BOOLEAN rc = FALSE;
200 
201  if (len <= FILESIZE_MAX)
202  {
203  S_STRING filename;
204 #ifdef DEBUG_TPS
205  int i;
206  DBG_TPS(("writing:%.*s\n", (int)fn.len, fn.data));
207  DBG_TPS(("writing:\n"));
208  for (i = 0; i < len; i++)
209  {
210  DBG_PRINT(("0x%x ", ((U8BIT *)data)[i]));
211  }
212  DBG_PRINT(("\n"));
213 #endif
214  filename.zptr = fn.data;
215  filename.zlen = fn.len;
216  if (filename.zlen && filename.zlen < 9)
217  {
218  rc = TPS_StorageWrite(filename, data, len);
219  }
220  if (rc)
221  {
222  success = MHEG5TRUE;
223  }
224  }
225 
226  return success;
227 }
228 
236 {
237  if (TPS_StorageGetEnabled())
238  {
239  return MHEG5TRUE;
240  }
241  else
242  {
243  return MHEG5FALSE;
244  }
245 }
246 
252 void MHEG5TpsClose(void)
253 {
254  TPS_StorageClose();
255 }
256 
257 #ifdef INCLUDE_TPS
258 
265 static void MHEG5NotifyTpsFilesChanged(void *dummy)
266 {
267  USE_UNWANTED_PARAM(dummy);
268  TPS_StorageClose();
269 }
270 
278 E_MhegErr MHEG5_NotifyNvmFilesChanged(void)
279 {
280  MHEG5eventMessage_t event_msg;
281  event_msg.proc_msg_func = MHEG5NotifyTpsFilesChanged;
282  event_msg.data_type = DT_VALUE;
283  return VQ_PutMsg(&event_msg, PRTY_NORMAL);
284 }
285 
294 static BOOLEAN TPS_StorageRead(S_STRING filename, void **data, U32BIT *data_len)
295 {
296  t_TruePersistentFile *file_entry;
297  if (!TPS_enabled)
298  {
299  return FALSE;
300  }
301  /*open the store and read files into cache*/
302  TPS_StorageOpen();
303 
304  file_entry = FindFileByName(filename);
305  if (file_entry)
306  {
307  *data = file_entry->file_data;
308  *data_len = file_entry->file_len;
309  return TRUE;
310  }
311  else
312  {
313  return FALSE;
314  }
315 }
316 
325 static BOOLEAN TPS_StorageWrite(S_STRING filename, void *data, U32BIT data_len)
326 {
327  t_TruePersistentFile *replaced_file;
328  t_TruePersistentFile *updated_file;
329  BOOLEAN write = TRUE;
330  BOOLEAN check_service = TRUE;
331  BOOLEAN success = FALSE;
332  U32BIT day, sec;
333 
334  if (!TPS_enabled)
335  {
336  return FALSE;
337  }
338 
339  TPS_StorageOpen();
340  MHEG5getDate((S32BIT *)&day, (S32BIT *)&sec );
341 
342  DBG_TPS(("current service_id 0x%x\n", current_service.service_id));
343 
344  replaced_file = FindFileByName(filename);
345  /*if the file exists check if we can write to it*/
346  if (replaced_file)
347  {
348  DBG_TPS(("File exists\n"));
349  if (replaced_file->write_date >= day - WRITE_PERIOD_DAYS)
350  {
351  replaced_file->num_writes = 0;
352  }
353 
354  if (replaced_file->num_writes >= MAX_WRITES_IN_PERIOD)
355  {
356  write = FALSE;
357  DBG_TPS(("Warning: File has been written too many times\n"));
358  }
359  /*if the file being overwritten is assigned to a different service
360  then there may be files assigned to the current service that will
361  need to be deleted*/
362  else if (ServicesEqual(&current_service, &replaced_file->service_info))
363  {
364  check_service = FALSE;
365  }
366  }
367 
368  if (write && check_service)
369  {
370  /*delete any file already on the current service*/
371  DeleteFileByService(&current_service);
372  }
373  /*if the store is full, delete an old file*/
374  if (write && file_count == MAX_FILES)
375  {
376  DBG_TPS(("Store full, deleting old files\n"));
377  DeleteOldFile();
378  if (file_count == MAX_FILES)
379  {
380  write = FALSE;
381  }
382  }
383 
384  if (write)
385  {
386  if (replaced_file)
387  {
388  updated_file = OverwriteFileEntry(data, data_len, &current_service, day, replaced_file);
389  }
390  else
391  {
392  updated_file = NewFile(filename, data, data_len, &current_service, day);
393  }
394  if (WriteFileToStore( updated_file ))
395  {
396  file_count++;
397  success = TRUE;
398  }
399  }
400 
401  return success;
402 }
403 
408 static void FreeFile(t_TruePersistentFile *file)
409 {
410  assert(file);
411 
412  if (file->file_path)
413  {
414  MHEG5freeMem(file->file_path);
415  }
416  if (file->file_data)
417  {
418  MHEG5freeMem(file->file_data);
419  }
420  MHEG5freeMem(file);
421  file_count--;
422 }
423 
428 static void DeleteFile(t_TruePersistentFile *file)
429 {
430  assert(file);
431 
432  if (file->next)
433  {
434  file->next->previous = file->previous;
435  }
436  else
437  {
438  file_list_tail = file->previous;
439  }
440 
441 
442  if (file->previous)
443  {
444  file->previous->next = file->next;
445  }
446  else
447  {
448  file_list_head = file->next;
449  }
450 
451  STB_NVMDeleteFile( (U8BIT *) file->file_path );
452  FreeFile(file);
453 }
454 
459 static void ClearCache(void)
460 {
461  t_TruePersistentFile *current;
462  t_TruePersistentFile *next;
463 
464  current = file_list_head;
465 
466  while (current)
467  {
468  next = current->next;
469  FreeFile(current);
470  current = next;
471  }
472  file_list_head = NULL;
473  file_list_tail = NULL;
474 }
475 
476 /*******************************************************************************
477  *@begin
478  * NAME: AddFileToList
479  * Adds a file read from NVM to the file list
480  *
481  * Returns :
482  *
483  * Parameter Flow Description
484  * ------------------------------------------------------------------------------
485  *
486  *
487  * Externals Flow Usage
488  * ------------------------------------------------------------------------------
489  *
490  * Additional information:
491  *
492  *@end
493  *******************************************************************************/
494 static BOOLEAN AddFileToList(t_TruePersistentFile *file)
495 {
496  t_TruePersistentFile *current;
497  assert(file);
498  if (file_list_tail == NULL)
499  {
500  file_list_tail = file;
501  file_list_head = file;
502  }
503  else
504  {
505  current = file_list_tail;
506  while (current)
507  {
508  if (file->write_date >= current->write_date)
509  {
510  file->previous = current;
511  file->next = current->next;
512  if (current->next)
513  {
514  current->next->previous = file;
515  current->next = file;
516  }
517  else
518  {
519  file_list_tail = file;
520  current->next = file;
521  }
522  return TRUE;
523  }
524  else
525  {
526  current = current->previous;
527  }
528  }
529  if (current == NULL)
530  {
531  file_list_head->previous = file;
532  file->next = file_list_head;
533  file_list_head = file;
534  }
535  }
536  return TRUE;
537 }
538 
543 static BOOLEAN LoadFile(char *filename)
544 {
545  char *full_path;
546  t_TruePersistentFile *new_file;
547  void *filep = NULL;
548  U8BIT *data;
549  U32BIT file_size;
550  U32BIT offset = 0;
551  pS_DvbLocator service_info;
552  BOOLEAN success = FALSE;
553 
554  /*refomat the filename*/
555  full_path = MHEG5getMem(strlen(TPS_DIRECTORY) + strlen(filename) + 1);
556 
557  memcpy(full_path, (char *)TPS_DIRECTORY, strlen(TPS_DIRECTORY) + 1);
558  strncat(full_path, filename, strlen(filename) + 1);
559 
560  DBG_TPS(("Loading File %s\n", filename));
561 
562  new_file = MHEG5getMem(sizeof(t_TruePersistentFile));
563 
564  new_file->previous = NULL;
565  new_file->next = NULL;
566  new_file->num_writes = 0;
567  new_file->write_date = 0;
568  new_file->file_path = full_path;
569  new_file->filename = (U8BIT *)full_path + strlen(TPS_DIRECTORY);
570  new_file->filename_len = strlen(filename);
571 
572  STB_NVMFileSize((U8BIT *) full_path, &file_size);
573 
574  /*if the file is less than the header size, don't bother loading it*/
575  if (file_size >= HEADER_SIZE)
576  {
577  filep = STB_NVMOpenFile((U8BIT *) full_path, FILE_MODE_READ);
578  }
579 
580  if (filep)
581  {
582  data = MHEG5getMem(file_size);
583  if (data)
584  {
585  if (STB_NVMReadFile(filep, data, file_size) == file_size)
586  {
587  service_info = &new_file->service_info;
588 
589  service_info->original_network_id = Read16Bits(data + offset);
590  offset += 2;
591  service_info->service_id = Read16Bits(data + offset);
592  offset += 2;
593 
594  service_info->transport_stream_id = 0;
595 
596  new_file->num_writes = *(data + offset);
597  offset += 1;
598  new_file->write_date = Read32Bits(data + offset);
599  offset += 4;
600 
601  new_file->file_len = file_size - offset;
602  new_file->file_data = MHEG5getMem(new_file->file_len);
603  if (new_file->file_data)
604  {
605  memcpy(new_file->file_data, data + offset, new_file->file_len);
606  success = AddFileToList(new_file);
607  }
608  }
609  MHEG5freeMem(data);
610  }
611  STB_NVMCloseFile(filep);
612  }
613  else
614  {
615  MHEG5freeMem(new_file);
616  MHEG5freeMem(full_path);
617  }
618 
619  return success;
620 }
621 
622 static U32BIT Read32Bits(U8BIT *bytes)
623 {
624  U32BIT buffer;
625 
626  buffer = bytes[3];
627  buffer <<= 8;
628  buffer |= bytes[2];
629  buffer <<= 8;
630  buffer |= bytes[1];
631  buffer <<= 8;
632  buffer |= bytes[0];
633 
634  return buffer;
635 }
636 
637 static void Store32Bits(U8BIT *bytes, U32BIT value)
638 {
639  bytes[0] = value & 0xFF;
640  bytes[1] = (value >> 8) & 0xFF;
641  bytes[2] = (value >> 16) & 0xFF;
642  bytes[3] = (value >> 24) & 0xFF;
643 }
644 
645 static U16BIT Read16Bits(U8BIT *bytes)
646 {
647  U16BIT buffer;
648 
649  buffer = bytes[1];
650  buffer <<= 8;
651  buffer |= bytes[0];
652 
653  return buffer;
654 }
655 
656 static void Store16Bits(U8BIT *bytes, U16BIT value)
657 {
658  bytes[0] = value & 0xFF;
659  bytes[1] = (value >> 8) & 0xFF;
660 }
661 
665 static E_MhegErr TPS_StorageOpen(void)
666 {
667  void *directory;
668  char filename_buffer[MAX_PATH_LEN];
669  E_MhegErr retval = MHERR_OK;
670  E_STB_DIR_ENTRY_TYPE entry_type;
671 
672  if (!init && TPS_enabled)
673  {
674  init = TRUE;
675  directory = STB_NVMOpenDirectory((U8BIT *) TPS_DIRECTORY);
676  if (!directory)
677  {
678  return FALSE;
679  }
680  while (STB_NVMReadDirectory(directory, (U8BIT *) filename_buffer, MAX_PATH_LEN, &entry_type))
681  {
682  if (entry_type == DIR_ENTRY_FILE)
683  {
684  if (!LoadFile(filename_buffer))
685  {
686  retval = MHERR_OTHER;
687  break;
688  }
689  file_count++;
690  }
691  }
692  STB_NVMCloseDirectory(directory);
693  }
694  return retval;
695 }
696 
700 static void TPS_StorageClose(void)
701 {
702  if (init)
703  {
704  ClearCache();
705  file_count = 0;
706  }
707  init = FALSE;
708 }
709 
714 static t_TruePersistentFile* FindFileByName(S_STRING filename)
715 {
716  t_TruePersistentFile *file_entry;
717  file_entry = file_list_tail;
718 
719  while (file_entry)
720  {
721  if (filename.zlen == file_entry->filename_len)
722  {
723  if (!memcmp(filename.zptr, file_entry->filename, filename.zlen))
724  {
725  break;
726  }
727  }
728  file_entry = file_entry->previous;
729  }
730  return file_entry;
731 }
732 
739 static BOOLEAN DeleteOldFile(void)
740 {
741  t_TruePersistentFile *current;
742  S32BIT index;
743 
744  current = file_list_head;
745 
746  while (current)
747  {
748  DVB_MhegDvbLocatorToIndex(&current->service_info, &index);
749  if (index == -1)
750  {
751  DeleteFile(current);
752  return TRUE;
753  }
754  current = current->next;
755  }
756  return FALSE;
757 }
758 
763 static BOOLEAN ServicesEqual(pS_DvbLocator service_a, pS_DvbLocator service_b)
764 {
765  BOOLEAN same = TRUE;
766 
767  if (service_a->service_id != service_b->service_id)
768  {
769  same = FALSE;
770  }
771  else if (service_a->original_network_id != service_b->original_network_id)
772  {
773  same = FALSE;
774  }
775 
776  return same;
777 }
778 
785 static BOOLEAN DeleteFileByService(pS_DvbLocator service_info)
786 {
787  t_TruePersistentFile *file_entry;
788 
789  file_entry = file_list_head;
790  DBG_TPS(("deleting files on service 0x%x\n", service_info->service_id));
791  while (file_entry)
792  {
793  if (ServicesEqual(service_info, &file_entry->service_info))
794  {
795  DeleteFile(file_entry);
796  return TRUE;
797  }
798 
799  file_entry = file_entry->next;
800  }
801  return FALSE;
802 }
803 
808 static MHEG5Bool WriteFileToStore( t_TruePersistentFile *out_file)
809 {
810  void *filep = NULL;
811  U8BIT *file_data;
812  U32BIT len;
813  int offset = 0;
814 
815  len = HEADER_SIZE;
816 
817  len += out_file->file_len;
818 
819  file_data = MHEG5getMem(len);
820  if (file_data)
821  {
822  Store16Bits(file_data + offset, out_file->service_info.original_network_id);
823  offset += 2;
824  Store16Bits(file_data + offset, out_file->service_info.service_id);
825  offset += 2;
826  memcpy(file_data + offset, &out_file->num_writes, 1);
827  offset++;
828  Store32Bits(file_data + offset, out_file->write_date);
829  offset += 4;
830 
831  memcpy(file_data + offset, out_file->file_data, out_file->file_len);
832 
833  filep = STB_NVMOpenFile((U8BIT *) out_file->file_path, FILE_MODE_OVERWRITE);
834  }
835  if (filep)
836  {
837  STB_NVMWriteFile(filep, file_data, len);
838  STB_NVMCloseFile(filep);
839  return MHEG5TRUE;
840  }
841  else
842  {
843  return MHEG5FALSE;
844  }
845 }
846 
858 static t_TruePersistentFile* NewFile(S_STRING filename, void *data, MHEG5Int len,
859  pS_DvbLocator service, U32BIT today)
860 
861 {
862  t_TruePersistentFile *new_file;
863  MHEG5Bool success = MHEG5FALSE;
864  char *full_path;
865 
866  new_file = MHEG5getMem(sizeof(t_TruePersistentFile));
867  if (new_file)
868  {
869  full_path = MHEG5getMem(strlen(TPS_DIRECTORY) + filename.zlen + 1);
870  if (full_path)
871  {
872  success = MHEG5TRUE;
873  }
874  }
875 
876  if (success)
877  {
878  *full_path = 0;
879  strncat(full_path, TPS_DIRECTORY, strlen(TPS_DIRECTORY));
880  strncat(full_path, (char *)filename.zptr, filename.zlen);
881 
882  new_file->file_path = full_path;
883  new_file->filename = (U8BIT *)full_path + strlen(TPS_DIRECTORY);
884  new_file->filename_len = filename.zlen;
885  new_file->num_writes = 1;
886  new_file->write_date = today;
887 
888  UpdateFileEntry(new_file, data, len, service);
889  }
890  return new_file;
891 }
892 
898 static t_TruePersistentFile* OverwriteFileEntry(void *data, MHEG5Int len,
899  pS_DvbLocator service, U32BIT today,
900  t_TruePersistentFile *replaced_file)
901 {
902  MHEG5Bool success = MHEG5TRUE;
903 
904  assert(replaced_file);
905 
906 
907  if (today <= replaced_file->write_date + WRITE_PERIOD_DAYS)
908  {
909  if (replaced_file->num_writes == MAX_WRITES_IN_PERIOD)
910  {
911  success = MHEG5FALSE;
912  }
913  else
914  {
915  replaced_file->num_writes++;
916  }
917  }
918  else
919  {
920  replaced_file->write_date = today;
921  replaced_file->num_writes = 1;
922  }
923 
924  if (success)
925  {
926  /*if it is in the middle of the list*/
927  if (replaced_file->previous && replaced_file->next)
928  {
929  /*join the previous and next items together*/
930  replaced_file->previous->next = replaced_file->next;
931  replaced_file->next->previous = replaced_file->previous;
932  }
933  else if (replaced_file->next) /*if it is the first item*/
934  {
935  /*push the next item to the head*/
936  replaced_file->next->previous = NULL;
937  }
938  else if (replaced_file->previous) /*it is at the end*/
939  {
940  replaced_file->previous->next = NULL;
941  }
942 
943  if (file_list_head == replaced_file)
944  {
945  file_list_head = replaced_file->next;
946  }
947  if (file_list_tail == replaced_file)
948  {
949  file_list_tail = replaced_file->previous;
950  }
951 
952  /*free the old file data*/
953  MHEG5freeMem(replaced_file->file_data);
954  replaced_file->file_data = NULL;
955  replaced_file->file_len = 0;
956  replaced_file->next = NULL;
957  replaced_file->previous = NULL;
958  return UpdateFileEntry(replaced_file, data, len, service);
959  }
960  else
961  {
962  return NULL;
963  }
964 }
965 
970 static t_TruePersistentFile* UpdateFileEntry(t_TruePersistentFile *file, void *data, MHEG5Int len,
971  pS_DvbLocator service)
972 {
973  if (file_list_tail)
974  {
975  file_list_tail->next = file;
976  }
977  else
978  {
979  file_list_head = file;
980  }
981 
982 
983  file->previous = file_list_tail;
984  file->next = NULL;
985  file_list_tail = file;
986 
987  file->service_info.original_network_id = service->original_network_id;
988  file->service_info.transport_stream_id = service->transport_stream_id;
989  file->service_info.service_id = service->service_id;
990  file->file_data = MHEG5getMem( len );
991  if (file->file_data)
992  {
993  memcpy(file->file_data, data, len);
994  file->file_len = len;
995 
996  return file;
997  }
998  else
999  {
1000  return NULL;
1001  }
1002 }
1003 
1009 E_MhegErr MHEG5_GetTPSStatus(BOOLEAN *enabled)
1010 {
1011  *enabled = (TPS_enabled) ? TRUE : FALSE;
1012  return MHERR_OK;
1013 }
1014 
1021 E_MhegErr MHEG5_EnableTPS(BOOLEAN enabled)
1022 {
1023  if (TPS_enabled && !enabled)
1024  {
1025  TPS_StorageClose();
1026  }
1027 
1028  TPS_enabled = enabled;
1029  return MHERR_OK;
1030 }
1031 
1038 E_MhegErr MHEG5_GetTPSServices(U16BIT *pfile_count, pS_DvbLocator *first_file)
1039 {
1040  t_TruePersistentFile *cursor;
1041 
1042  if (current_file_list)
1043  {
1044  return MHERR_COMP_ALREADY_OPEN;
1045  }
1046  TPS_StorageOpen();
1047  if (file_count)
1048  {
1049  current_file_list = MHEG5getMem(sizeof(S_DvbLocator) * file_count);
1050  if (current_file_list)
1051  {
1052  for (cursor = file_list_head, file_count = 0; cursor; file_count++, cursor = cursor->next)
1053  {
1054  current_file_list[file_count].original_network_id = cursor->service_info.original_network_id;
1055  current_file_list[file_count].transport_stream_id = cursor->service_info.transport_stream_id;
1056  current_file_list[file_count].service_id = cursor->service_info.service_id;
1057  }
1058  *pfile_count = file_count;
1059  *first_file = current_file_list;
1060  }
1061  else
1062  {
1063  *pfile_count = 0;
1064  *first_file = NULL;
1065  return MHERR_OTHER;
1066  }
1067  }
1068  else
1069  {
1070  *pfile_count = 0;
1071  *first_file = NULL;
1072  }
1073  return MHERR_OK;
1074 }
1075 
1081 E_MhegErr MHEG5_AckTPSServiceList(void)
1082 {
1083  if (current_file_list)
1084  {
1085  MHEG5freeMem(current_file_list);
1086  current_file_list = NULL;
1087  }
1088  return MHERR_OK;
1089 }
1090 
1097 E_MhegErr MHEG5_RemoveTPSFile(pS_DvbLocator service)
1098 {
1099  if (DeleteFileByService(service))
1100  {
1101  return MHERR_OK;
1102  }
1103  else
1104  {
1105  return MHERR_OBJECT_NOT_FOUND;
1106  }
1107 }
1108 
1112 BOOLEAN TPS_StorageGetEnabled(void)
1113 {
1114  return TPS_enabled ? TRUE : FALSE;
1115 }
1116 
1117 #endif
Date functions.
void * STB_NVMOpenFile(U8BIT *name, E_STB_DSK_FILE_MODE mode)
Opens an existing file or creates a new one.
Basis MHEG5 data types.
E_MhegErr VQ_PutMsg(S_MhegMessage *pMsg, E_PRIORITY priority)
Post event or section message on queue. Copies data into queue.
Definition: glue_queue.c:248
MHEG5Bool MHEG5TpsWrite(MHEG5String fn, void *data, MHEG5Int len)
Write data passed from the application into the TPS stroe.
Definition: mh5tps.c:196
F_MSG_PROCESS proc_msg_func
Definition: glue_queue.h:198
void STB_NVMCloseDirectory(void *dir)
Closes the directory for reading.
MHEG5Bool MHEG5GetTpsStatus(void)
Get the status of the TPS store for the PST resident program. none.
Definition: mh5tps.c:235
void MHEG5TpsClose(void)
Close the clear the store and delete the cache none.
Definition: mh5tps.c:252
const char * data
Definition: mh5gate.c:56
True Persistent Storage functions.
MHEG5 queue.
E_STB_DIR_ENTRY_TYPE
Definition: stb_nvm.h:48
#define MHEG5getMem
Definition: glue_memory.h:93
void MHEG5getDate(S32BIT *day, S32BIT *sec)
Modified Julian Date - see Davic 9.2.12.1.
Definition: mh5date.c:111
Miscellaneous.
MHEG5Bool MHEG5TpsRead(MHEG5String fn, void **data, MHEG5Int *len)
Read a file from the TPS store and pass it back to the application.
Definition: mh5tps.c:157
void STB_NVMCloseFile(void *file)
Flushes and closes an open file.
U8BIT * zptr
Definition: dtvstring.h:31
U16BIT transport_stream_id
Definition: dvblocator.h:33
E_MhegErr
Definition: mherrors.h:28
S_DvbLocator * pS_DvbLocator
Definition: mh5tps.c:69
BOOLEAN STB_NVMFileSize(U8BIT *filename, U32BIT *filesize)
Returns the size in KB of the given file.
#define MAX_PATH_LEN
Definition: mh5tps.c:48
MHEG5 engine interface error codes.
U16BIT original_network_id
Definition: dvblocator.h:32
uint8_t U8BIT
Definition: techtype.h:82
void * STB_NVMOpenDirectory(U8BIT *dir_name)
Opens a directory in order to read the entries.
long MHEG5Int
Definition: mh5base.h:73
DVB Service information functions are required by MHEG5 engine. All required functions should be non-...
#define MHEG5freeMem
Definition: glue_memory.h:94
short MHEG5Bool
Definition: mh5base.h:71
U32BIT STB_NVMReadFile(void *file, U8BIT *data, U32BIT size)
Reads data from an open file.
MHEG5Byte * data
Definition: mh5base.h:85
void MHEG5TpsSetCurrentService(S_DvbLocator *pDvbLoc)
Set current service for application none.
Definition: mh5tps.c:144
int len
Definition: mh5gate.c:57
int32_t S32BIT
Definition: techtype.h:87
#define MHEG5TRUE
Definition: mh5base.h:49
E_DATA_TYPE data_type
Definition: glue_queue.h:199
#define FILESIZE_MAX
Definition: mh5tps.c:47
uint16_t U16BIT
Definition: techtype.h:84
File System types.
System Wide Global Technical Data Type Definitions.
BOOLEAN STB_NVMReadDirectory(void *dir, U8BIT *filename, U16BIT filename_len, E_STB_DIR_ENTRY_TYPE *entry_type)
Reads the next entry from the directory, returning the name of the entry and the type of the entry...
U16BIT service_id
Definition: dvblocator.h:34
redirection include
Definition: mg_png.c:52
U32BIT STB_NVMWriteFile(void *file, U8BIT *data, U32BIT size)
Writes data to an open file.
#define FALSE
Definition: techtype.h:68
Non-Volatile Memory functions and file access for caching files during power cycles. All file/path names are relative to some implementation dependent root path for MHEG&#39;s NVM storage area. So a path of "" (i.e. zero length name), is the root directory of storage area.
MHEG5Int len
Definition: mh5base.h:84
U8BIT BOOLEAN
Definition: techtype.h:99
#define USE_UNWANTED_PARAM(param)
Definition: techtype.h:48
U32BIT zlen
Definition: dtvstring.h:30
#define TRUE
Definition: techtype.h:69
E_MhegErr DVB_MhegDvbLocatorToIndex(S_DvbLocator *pDvbLocator, S32BIT *pServiceIndex)
Get a DVB implementation dependant service index - an integer greater or equal to 0...
#define MHEG5FALSE
Definition: mh5base.h:48
uint32_t U32BIT
Definition: techtype.h:86
BOOLEAN STB_NVMDeleteFile(U8BIT *filename)
Deletes the file.