FireBirdLib - Topfield TMS PVR TAP Programming Library
EPGInfo_CreateCache.c
Go to the documentation of this file.
1#include <stdio.h>
2#include <stdlib.h>
3#include <fcntl.h>
4#include <unistd.h>
5#include <sys/mman.h>
6#include <sys/stat.h>
7#include "FBLib_EPG.h"
8
9bool EPGInfo_CreateCache(int NrRecords)
10{
11 TRACEENTER();
12
13 extern dword __tap_ud__;
14
15 TAP_SPrint(EPGCacheFile, "/mnt/hd/tmp/EPGCache_%x.bin", __tap_ud__);
16
18
19 EPGInfoCacheSize = NrRecords * sizeof(TYPE_EPGInfo);
20
21 //Delete the old cache
22 unlink(EPGCacheFile);
23
24 mkdir("/mnt/hd/tmp", 0777);
25 EPGInfoCacheFile = open(EPGCacheFile, O_RDWR | O_CREAT | O_TRUNC, (mode_t)0600);
26
27 if(EPGInfoCacheFile == -1)
28 {
29 LogEntryFBLibPrintf(TRUE, "EPGInfo: failed to create the memory mapped EPG cache");
30
31 TRACEEXIT();
32 return FALSE;
33 }
34
35 //Increase the size of the cache as needed
37 {
38 LogEntryFBLibPrintf(TRUE, "EPGInfo: failed to stretch the memory mapped EPG cache");
39 close(EPGInfoCacheFile);
40 unlink(EPGCacheFile);
41
42 TRACEEXIT();
43 return FALSE;
44 }
45 write(EPGInfoCacheFile, "", 1);
46
47 //Map the memory
48 EPGInfoCacheMap = mmap(0, EPGInfoCacheSize, PROT_READ | PROT_WRITE, MAP_SHARED, EPGInfoCacheFile, 0);
49 if(EPGInfoCacheMap == MAP_FAILED)
50 {
51 LogEntryFBLibPrintf(TRUE, "EPGInfo: failed to memory map the EPG cache file");
52 close(EPGInfoCacheFile);
53 unlink(EPGCacheFile);
54
55 TRACEEXIT();
56 return FALSE;
57 }
58
60
61 TRACEEXIT();
62 return TRUE;
63}
bool EPGInfo_CreateCache(int NrRecords)
void EPGInfo_DestroyCache(void)
char EPGCacheFile[40]
dword EPGInfoCacheSize
byte * EPGInfoCacheMap
int EPGInfoCacheFile
TYPE_EPGInfo * EPGInfoCache
const dword __tap_ud__
void LogEntryFBLibPrintf(bool Console, char *format,...)
#define SEEK_SET
Definition: libFireBird.h:1875
#define TRACEEXIT()
Definition: libFireBird.h:1244
#define TRACEENTER()
Definition: libFireBird.h:1243