]> git.vomp.tv Git - vompclient.git/blob - vdr.h
Completion of move recording code. Fixes for dir counts, other bugs.
[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 #ifndef WIN32
27   #include <pthread.h>
28 #else
29   //Find threading replacements
30 #endif
31 #include <vector>
32 #include <algorithm>
33
34 #include "defines.h"
35 #include "log.h"
36 #include "dsock.h"
37 #include "tcp.h"
38 #include "channel.h"
39 #include "event.h"
40 #include "rectimer.h"
41 #include "recman.h"
42
43 using namespace std;
44
45 typedef vector<Event*> EventList;
46 typedef vector<Channel*> ChannelList;
47 typedef vector<RecTimer*> RecTimerList;
48
49 struct VDRServer
50 {
51   char* ip;
52   char* name;
53 };
54
55 struct RecTimerSorter     // : public binary_function<double, double, bool>
56 {
57   bool operator() (const RecTimer* a, const RecTimer* b)
58   {
59     return a->startTime < b->startTime;
60   }
61 };
62
63 struct ServerSorter
64 {
65   bool operator() (const VDRServer& a, const VDRServer& b)
66   {
67     if (strcmp(b.name, a.name) > 0) return true;
68     return false;
69   }
70 };
71
72
73 class VDR
74 {
75
76   public:
77     VDR();
78     ~VDR();
79     static VDR* getInstance();
80
81     int init(int port);
82     int shutdown();
83
84     void findServers(vector<VDRServer>& servers);
85     void cancelFindingServer();
86     void setServerIP(char*);
87     int connect();
88     void disconnect();
89     bool isConnected() { return connected; }
90     ULLONG getResumePoint(char* fileName);  // uses configLoad
91
92     void setReceiveWindow(size_t size);
93
94     // protocol functions
95     // for the following, if result == false then the connection has died
96     //  doLogin
97     //  getRecordingList
98     //  getChannelsList
99     //  getChannelSchedule
100     //  getRecTimersList
101     // isConnected can be called after the following to determine if still ok
102     //  getRecordingSummary
103     //  deleteRecording
104     //  streamRecording
105     //  rescanRecording
106     //  positionFromFrameNumber
107     //  streamChannel
108     //  getBlock
109     //  stopStreaming
110     //  configLoad
111     //  configSave
112     //  setEventTimer
113
114     int doLogin();
115
116     bool       getRecordingsList(RecMan* recman);
117     char*      getRecordingSummary(char* fileName);
118     int        deleteRecording(char* fileName);
119     char*      moveRecording(char* fileName, char* newPath);
120     ULLONG     streamRecording(char* fileName);
121     ULLONG     rescanRecording();
122     ULLONG     positionFromFrameNumber(ULONG frameNumber);
123     ULONG      frameNumberFromPosition(ULLONG position);
124
125     ChannelList* getChannelsList(ULONG type);
126     int          streamChannel(ULONG number);
127
128     UCHAR*     getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived);
129     int        stopStreaming();
130     EventList* getChannelSchedule(ULONG number);
131     EventList* getChannelSchedule(ULONG number, time_t start, ULONG duration);
132     int        configSave(char* section, char* key, const char* value);
133     char*      configLoad(char* section, char* key);
134     ULONG      setEventTimer(char* timerString);
135
136     RecTimerList* getRecTimersList();
137
138     // end
139
140     const static ULONG VIDEO = 1;
141     const static ULONG RADIO = 2;
142
143   private:
144     static VDR* instance;
145     Log* logger;
146     int initted;
147     int findingServer;
148     TCP* tcp;
149     int port;
150     char serverIP[16];
151     bool connected;
152 #ifndef WIN32
153     pthread_mutex_t mutex;
154 #else
155     HANDLE mutex;
156 #endif
157
158     UCHAR* packet;
159     ULONG packetLength;
160     ULONG packetPos;
161
162     const static ULONG VDR_LOGIN               = 1;
163     const static ULONG VDR_GETRECORDINGLIST    = 2;
164     const static ULONG VDR_DELETERECORDING     = 3;
165     const static ULONG VDR_GETSUMMARY          = 4;
166     const static ULONG VDR_GETCHANNELLIST      = 5;
167     const static ULONG VDR_STREAMCHANNEL       = 6;
168     const static ULONG VDR_GETBLOCK            = 7;
169     const static ULONG VDR_STOPSTREAMING       = 8;
170     const static ULONG VDR_STREAMRECORDING     = 9;
171     const static ULONG VDR_GETCHANNELSCHEDULE  = 10;
172     const static ULONG VDR_CONFIGSAVE          = 11;
173     const static ULONG VDR_CONFIGLOAD          = 12;
174     const static ULONG VDR_RESCANRECORDING     = 13;
175     const static ULONG VDR_GETTIMERS           = 14;
176     const static ULONG VDR_SETTIMER            = 15;
177     const static ULONG VDR_POSFROMFRAME        = 16;
178     const static ULONG VDR_FRAMEFROMPOS        = 17;
179     const static ULONG VDR_MOVERECORDING       = 18;
180
181     int  getPacket();
182     void freePacket();
183     int  serverError();
184     char*  extractString();
185     ULONG  extractULONG();
186     ULLONG extractULLONG();
187     long   extractLONG();
188 };
189
190 #endif
191