]> git.vomp.tv Git - vompclient.git/blob - vdr.h
Sort recordings from VDR 1.3, patch from Dave
[vompclient.git] / vdr.h
1 /*
2     Copyright 2004-2005 Chris Tallon
3
4     This file is part of VOMP.
5
6     VOMP is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     VOMP is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with VOMP; if not, write to the Free Software
18     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20
21 #ifndef VDR_H
22 #define VDR_H
23
24 #include <stdio.h>
25 #include <time.h>
26 #include <pthread.h>
27 #include <vector>
28 #include <algorithm>
29
30 #include "defines.h"
31 #include "log.h"
32 #include "dsock.h"
33 #include "tcp.h"
34 #include "directory.h"
35 #include "recording.h"
36 #include "channel.h"
37 #include "event.h"
38 #include "rectimer.h"
39
40 using namespace std;
41
42  // FIXME do some tcp connection error checking and kill it!
43
44 typedef vector<Event*> EventList;
45 typedef vector<Channel*> ChannelList;
46 typedef vector<RecTimer*> RecTimerList;
47
48 struct VDRServer
49 {
50   char* ip;
51   char* name;
52 };
53
54 struct RecTimerSorter     // : public binary_function<double, double, bool>
55 {
56   bool operator() (const RecTimer* a, const RecTimer* b)
57   {
58     return a->startTime < b->startTime;
59   }
60 };
61
62 struct ServerSorter
63 {
64   bool operator() (const VDRServer& a, const VDRServer& b)
65   {
66     if (strcmp(b.name, a.name) > 0) return true;
67     return false;
68   }
69 };
70
71 struct RecordingSorter
72 {
73   bool operator() (const Recording* a, const Recording* b)
74   {
75     int c = strcmp(b->getProgName(), a->getProgName());
76     if (c > 0) return true;
77     if (c < 0) return false;
78
79     return a->start < b->start;
80   }
81 };
82
83 class VDR
84 {
85
86   public:
87     VDR();
88     ~VDR();
89     static VDR* getInstance();
90
91     int init(int port);
92     int shutdown();
93
94     void findServers(vector<VDRServer>& servers);
95     void cancelFindingServer();
96     void setServerIP(char*);
97     int connect();
98     void disconnect();
99     ULLONG getResumePoint(char* fileName);  // uses configLoad
100
101     // protocol functions
102
103     int doLogin();
104
105     Directory* getRecordingsList();
106     char*      getRecordingSummary(char* fileName);
107     int        deleteRecording(char* fileName);
108     ULLONG     streamRecording(Recording* rec);
109     ULLONG     rescanRecording();
110
111     ChannelList* getChannelsList(ULONG type);
112     int          streamChannel(ULONG number);
113
114     UCHAR*     getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived);
115     int        stopStreaming();
116     EventList* getChannelSchedule(ULONG number);
117     EventList* getChannelSchedule(ULONG number, time_t start, ULONG duration);
118     int        configSave(char* section, char* key, const char* value);
119     char*      configLoad(char* section, char* key);
120
121     RecTimerList* getRecTimersList();
122
123     // end
124
125     const static ULONG VIDEO = 1;
126     const static ULONG RADIO = 2;
127
128   private:
129     static VDR* instance;
130     Log* logger;
131     int initted;
132     int findingServer;
133     TCP* tcp;
134     int port;
135     char serverIP[16];
136     bool connected;
137     pthread_mutex_t mutex;
138
139     UCHAR* packet;
140     ULONG packetLength;
141     ULONG packetPos;
142
143     const static ULONG VDR_LOGIN               = 1;
144     const static ULONG VDR_GETRECORDINGLIST    = 2;
145     const static ULONG VDR_DELETERECORDING     = 3;
146     const static ULONG VDR_GETSUMMARY          = 4;
147     const static ULONG VDR_GETCHANNELLIST      = 5;
148     const static ULONG VDR_STREAMCHANNEL       = 6;
149     const static ULONG VDR_GETBLOCK            = 7;
150     const static ULONG VDR_STOPSTREAMING       = 8;
151     const static ULONG VDR_STREAMRECORDING     = 9;
152     const static ULONG VDR_GETCHANNELSCHEDULE  = 10;
153     const static ULONG VDR_CONFIGSAVE          = 11;
154     const static ULONG VDR_CONFIGLOAD          = 12;
155     const static ULONG VDR_RESCANRECORDING     = 13;
156     const static ULONG VDR_GETTIMERS           = 14;
157
158     int  getPacket();
159     void freePacket();
160     int  serverError();
161     char*  extractString();
162     ULONG  extractULONG();
163     ULLONG extractULLONG();
164     long   extractLONG();
165 };
166
167 #endif