summaryrefslogtreecommitdiff
path: root/global.h
blob: 8046b0f80f34272d25dcf7395ad27a07296200d2 (plain)
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
/*
 * global.h: A plugin for the Video Disk Recorder
 *
 * See the README file for copyright information and how to reach the author.
 *
 * $Id$
 */

#ifndef __global_h_
#define __global_h_

#include <netinet/if_ether.h>
#include <sys/types.h>

#include <vdr/channels.h>

#define MIN_WAITTIME 10
#define MAX_WAITTIME 120
#define MIN_EVENTTIMEDIFF 5
#define MAX_EVENTTIMEDIFF 10

class cGlobalInfosatdata
{
#define _GetByte( ptr, bitnum ) ( (((char*)ptr)+bitnum/8) )
#define _GetBit( ptr, bitnum ) ( (*_GetByte(ptr, bitnum) >> (bitnum%8)) & 1 )
#define _SetBit( ptr, bitnum, val ) ( val ? \
	(*_GetByte(ptr, bitnum) |= (1<<(bitnum%8))) : \
	(*_GetByte(ptr, bitnum) &= ~(1<<(bitnum%8))) )
private:
    bool        ready;
    bool        processed;
    u_char      day;
    u_char      month;
    u_short     pktcnt;
    u_char      bitfield[8192];
    char        file[1024];
public:
    cGlobalInfosatdata();
    bool isReady2Process()
    {
        return (ready && !processed);
    }
    bool wasProcessed()
    {
        return (ready && processed);
    }
    int  Day()
    {
        return day;
    }
    int  Month()
    {
        return month;
    }
    int  Packetcount()
    {
        return pktcnt;
    }
    void SetProcessed()
    {
        processed=true;
    }
    void ResetProcessed()
    {
        processed=false;
    }
    bool GetBit(int Bitnumber)
    {
        return _GetBit(bitfield,Bitnumber);
    }
    void SetBit(int Bitnumber,bool Value)
    {
        _SetBit(bitfield,Bitnumber,Value);
    }
    const char *GetFile() const
    {
        return (char *) &file;
    }

    bool NeverSeen(int Day, int Month, int Packetcount);
    void Init(char *File, int Day, int Month, int Packetcount);
    bool ReceivedAll();
    int ReceivedPercent();
    int Load(int fd);
    int Save(int fd);
#ifdef INFOSATEPG_DEBUG
    void Debug(const char *Directory);
#endif
};

class cGlobalInfosatepg
{
#define USE_NOTHING       0


#define USE_SHORTTEXT     1
#define USE_SHORTLONGTEXT 2
#define USE_SHORTTEXTEPG  3
#define USE_INTELLIGENT   4
#define USE_ALL           5

    /*
    #define USE_NOTHING       0
    #define USE_SHORTTEXT     1
    #define USE_LONGTEXT      2
    #define USE_EXTEPG        4
    #define
    */

    struct infosatchannels
    {
        tChannelID ChannelID;
        int Usage;
    };

#define EPG_FIRST_DAY_MAC 1
#define EPG_LAST_DAY_MAC  7
#define EPG_DAYS          7

private:
    const char *directory;
    u_char MAC[5];
    time_t timer;
    bool Switched;
    int this_day;
    int this_month;
public:
    cGlobalInfosatepg();
    ~cGlobalInfosatepg();
    int Channel;
    int Pid;
    int EventTimeDiff;
    int WaitTime;
    int WakeupTime; // 0100 = 01:00  1222 = 12:22

    const char *Directory()
    {
        return directory;
    }
    bool SetDirectory(const char *Directory);
    bool CheckMAC(struct ethhdr *eth_hdr);
    void SetTimer()
    {
        timer=time(NULL);
    }
    bool isWaitOk()
    {
        return (time(NULL)>(timer+(time_t) WaitTime));
    }
    void SetSwitched(bool Value)
    {
        Switched=Value;
    }
    bool isSwitched()
    {
        return Switched;
    }

public:
    cGlobalInfosatdata Infosatdata[EPG_DAYS+1];
    int Load();
    int Save();
    void Lock(time_t Now);
    bool isLocked(int *Day, int *Month);
    bool isLocked()
    {
        return isLocked(NULL,NULL);
    }

private:
    int numinfosatchannels;
    struct infosatchannels *infosatchannels;
public:
    void AddChannel(tChannelID ChannelID,int Usage);
    tChannelID GetChannelID(int Index);
    bool SetChannelUse(int Index,int Usage);
    void ResetProcessedFlags(void);
    int GetChannelUse(int Index);
    bool ChannelExists(tChannelID ChannelID,int *Index);
    int InfosatChannels()
    {
        return numinfosatchannels;
    }
};
#endif