]> git.vomp.tv Git - vompclient.git/blob - vdr.h
Multiple options pages
[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 struct DirectorySorter
84 {
85   bool operator() (const Directory* a, const Directory* b)
86   {
87     int c = strcmp(b->name, a->name);
88     if (c > 0) return true;
89     return false;
90   }
91 };
92
93 class VDR
94 {
95
96   public:
97     VDR();
98     ~VDR();
99     static VDR* getInstance();
100
101     int init(int port);
102     int shutdown();
103
104     void findServers(vector<VDRServer>& servers);
105     void cancelFindingServer();
106     void setServerIP(char*);
107     int connect();
108     void disconnect();
109     ULLONG getResumePoint(char* fileName);  // uses configLoad
110
111     // protocol functions
112
113     int doLogin();
114
115     Directory* getRecordingsList();
116     char*      getRecordingSummary(char* fileName);
117     int        deleteRecording(char* fileName);
118     ULLONG     streamRecording(Recording* rec);
119     ULLONG     rescanRecording();
120
121     ChannelList* getChannelsList(ULONG type);
122     int          streamChannel(ULONG number);
123
124     UCHAR*     getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived);
125     int        stopStreaming();
126     EventList* getChannelSchedule(ULONG number);
127     EventList* getChannelSchedule(ULONG number, time_t start, ULONG duration);
128     int        configSave(char* section, char* key, const char* value);
129     char*      configLoad(char* section, char* key);
130
131     RecTimerList* getRecTimersList();
132
133     // end
134
135     const static ULONG VIDEO = 1;
136     const static ULONG RADIO = 2;
137
138   private:
139     static VDR* instance;
140     Log* logger;
141     int initted;
142     int findingServer;
143     TCP* tcp;
144     int port;
145     char serverIP[16];
146     bool connected;
147     pthread_mutex_t mutex;
148
149     UCHAR* packet;
150     ULONG packetLength;
151     ULONG packetPos;
152
153     const static ULONG VDR_LOGIN               = 1;
154     const static ULONG VDR_GETRECORDINGLIST    = 2;
155     const static ULONG VDR_DELETERECORDING     = 3;
156     const static ULONG VDR_GETSUMMARY          = 4;
157     const static ULONG VDR_GETCHANNELLIST      = 5;
158     const static ULONG VDR_STREAMCHANNEL       = 6;
159     const static ULONG VDR_GETBLOCK            = 7;
160     const static ULONG VDR_STOPSTREAMING       = 8;
161     const static ULONG VDR_STREAMRECORDING     = 9;
162     const static ULONG VDR_GETCHANNELSCHEDULE  = 10;
163     const static ULONG VDR_CONFIGSAVE          = 11;
164     const static ULONG VDR_CONFIGLOAD          = 12;
165     const static ULONG VDR_RESCANRECORDING     = 13;
166     const static ULONG VDR_GETTIMERS           = 14;
167
168     int  getPacket();
169     void freePacket();
170     int  serverError();
171     char*  extractString();
172     ULONG  extractULONG();
173     ULLONG extractULLONG();
174     long   extractLONG();
175 };
176
177 #endif