FireBirdLib - Topfield TMS PVR TAP Programming Library
HDD_TAP_Start.c
Go to the documentation of this file.
1#include <sys/types.h>
2#include <sys/shm.h>
3#include <string.h>
4#include "FBLib_tap.h"
5
7
8dword HDD_TAP_Start(const char *TAPFileName, bool BatchMode, void* ParameterBlock, dword *TAPID)
9{
10 TRACEENTER();
11
12 dword ret, Result;
13 tDirEntry _TempWorkFolder;
14 dword *_hddTapFolder;
15 char CurrentDir[FBLIB_DIR_SIZE], FileName[MAX_FILE_NAME_SIZE + 1];
16 int shmidBatch = 0, shmidParameterBlock = 0;
17 char *segptrBatch = NULL;
18 tTAPInfo TAPInfo;
19
20 //Set the TAPID and batch flag
21 if(!HDD_TAP_GetInfo(TAPFileName, &TAPInfo))
22 {
23 TRACEEXIT();
24 return 0;
25 }
26
27 if(TAPID != NULL) *TAPID = TAPInfo.TAPID;
28
29 //Create a shared memory if batch mode has been selected
30 //Just the existence is checked, no data transfered
31 if(BatchMode)
32 {
33 shmidBatch = shmget(BATCHMODEKEY, 1, IPC_CREAT);
34 segptrBatch = (char*)shmat(shmidBatch, 0, 0);
35 }
36
37 //Create a shared memory for the parameter block
38 //Opposed the the TF5000 version, the existence of this shared memory block
39 //is checked by StartedByTAP()
41 shmidParameterBlock = shmget(PARAMBLOCKKEY, sizeof(TYPE_Parametered_Tap), IPC_CREAT);
42 if(shmidParameterBlock != -1)
43 {
44 fbl_parametered_tap = (TYPE_Parametered_Tap*)shmat(shmidParameterBlock, 0, 0);
45
46 //Set the TAPID and parameter block
48 fbl_parametered_tap->id = TAPInfo.TAPID;
49 fbl_parametered_tap->pParameterBlock = (dword)ParameterBlock;
50 }
51
52 _hddTapFolder = (dword*)FIS_vHddTapFolder();
53
54 Result = 0;
56
57 //"Calculate" the current absolute directory of the new TAP and remove the last /
58 ConvertPathType(TAPFileName, CurrentDir, PF_LinuxPathOnly);
59 if(CurrentDir[strlen(CurrentDir) - 1] == '/') CurrentDir[strlen(CurrentDir) - 1] = '\0';
60
61 //Create a new folder structure
62 memset(&_TempWorkFolder, 0, sizeof(_TempWorkFolder));
63 _TempWorkFolder.Magic = 0xbacaed31;
64 ret = ApplHdd_SelectFolder(&_TempWorkFolder, &CurrentDir[1]);
65
66 if(!ret)
67 {
68 ApplHdd_SetWorkFolder(&_TempWorkFolder);
69 memcpy((void*)_hddTapFolder[0], &_TempWorkFolder, sizeof(_TempWorkFolder));
70
71 ConvertPathType(TAPFileName, FileName, PF_FileNameOnly);
72 Appl_ExecProgram(FileName);
73 Result = 1;
74 }
75
76 if(BatchMode && segptrBatch)
77 {
78 shmdt(segptrBatch);
79 shmctl(shmidBatch, IPC_RMID, 0);
80 }
81
82 if((int)fbl_parametered_tap != -1)
83 {
85 shmctl(shmidParameterBlock, IPC_RMID, 0);
86 }
87
88 //Reset the batch flag and start parameters
89 memset(&fbl_parametered_tap, 0, sizeof(fbl_parametered_tap));
90
92
93 TRACEEXIT();
94 return Result;
95}
void ApplHdd_RestoreWorkFolder(void)
void ApplHdd_SaveWorkFolder(void)
dword ApplHdd_SelectFolder(tDirEntry *FolderStruct, char *FolderPath)
void ApplHdd_SetWorkFolder(tDirEntry *FolderStruct)
void Appl_ExecProgram(char *FileName)
void ConvertPathType(const char *Source, char *Dest, tPathFormat DestFormat)
#define BATCHMODEKEY
Definition: FBLib_tap.h:8
#define MAGIC
Definition: FBLib_tap.h:6
#define PARAMBLOCKKEY
Definition: FBLib_tap.h:9
dword FIS_vHddTapFolder(void)
dword HDD_TAP_Start(const char *TAPFileName, bool BatchMode, void *ParameterBlock, dword *TAPID)
Definition: HDD_TAP_Start.c:8
TYPE_Parametered_Tap * fbl_parametered_tap
Definition: HDD_TAP_Start.c:6
#define FBLIB_DIR_SIZE
Definition: libFireBird.h:1871
bool HDD_TAP_GetInfo(const char *FileName, tTAPInfo *pTAPInfo)
#define TRACEEXIT()
Definition: libFireBird.h:1244
#define TRACEENTER()
Definition: libFireBird.h:1243
@ PF_LinuxPathOnly
Definition: libFireBird.h:1924
@ PF_FileNameOnly
Definition: libFireBird.h:1922
dword Magic
Definition: libFireBird.h:1446
dword TAPID
Definition: libFireBird.h:2592