]> git.vomp.tv Git - vompclient.git/blob - vdr.h
Display server names
[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 RecTimerSorter     // : public binary_function<double, double, bool>
49 {
50   bool operator() (const RecTimer* a, const RecTimer* b)
51   {
52     return a->startTime < b->startTime;
53   }
54 };
55
56 struct VDRServer
57 {
58   char* ip;
59   char* name;
60 };
61
62 struct ServerSorter
63 {
64   bool operator() (const VDRServer a, const VDRServer b)
65   {
66     printf("%s %s\n", a.name, b.name);
67     if (strcmp(b.name, a.name) > 0) return true;
68     return false;
69   }
70 };
71
72 class VDR
73 {
74
75   public:
76     VDR();
77     ~VDR();
78     static VDR* getInstance();
79
80     int init(int port);
81     int shutdown();
82
83     void findServers(vector<VDRServer>& servers);
84     void cancelFindingServer();
85     void setServerIP(char*);
86     int connect();
87     void disconnect();
88     ULLONG getResumePoint(char* fileName);  // uses configLoad
89
90     // protocol functions
91
92     int doLogin();
93
94     Directory* getRecordingsList();
95     char*      getRecordingSummary(char* fileName);
96     int        deleteRecording(char* fileName);
97     ULLONG     streamRecording(Recording* rec);
98     ULLONG     rescanRecording();
99
100     ChannelList* getChannelsList(ULONG type);
101     int          streamChannel(ULONG number);
102
103     UCHAR*     getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived);
104     int        stopStreaming();
105     EventList* getChannelSchedule(ULONG number);
106     EventList* getChannelSchedule(ULONG number, time_t start, ULONG duration);
107     int        configSave(char* section, char* key, const char* value);
108     char*      configLoad(char* section, char* key);
109
110     RecTimerList* getRecTimersList();
111
112     // end
113
114     const static ULONG VIDEO = 1;
115     const static ULONG RADIO = 2;
116
117   private:
118     static VDR* instance;
119     Log* logger;
120     int initted;
121     int findingServer;
122     TCP* tcp;
123     int port;
124     char serverIP[16];
125     bool connected;
126     pthread_mutex_t mutex;
127
128     UCHAR* packet;
129     ULONG packetLength;
130     ULONG packetPos;
131
132     const static ULONG VDR_LOGIN               = 1;
133     const static ULONG VDR_GETRECORDINGLIST    = 2;
134     const static ULONG VDR_DELETERECORDING     = 3;
135     const static ULONG VDR_GETSUMMARY          = 4;
136     const static ULONG VDR_GETCHANNELLIST      = 5;
137     const static ULONG VDR_STREAMCHANNEL       = 6;
138     const static ULONG VDR_GETBLOCK            = 7;
139     const static ULONG VDR_STOPSTREAMING       = 8;
140     const static ULONG VDR_STREAMRECORDING     = 9;
141     const static ULONG VDR_GETCHANNELSCHEDULE  = 10;
142     const static ULONG VDR_CONFIGSAVE          = 11;
143     const static ULONG VDR_CONFIGLOAD          = 12;
144     const static ULONG VDR_RESCANRECORDING     = 13;
145     const static ULONG VDR_GETTIMERS           = 14;
146
147     int  getPacket();
148     void freePacket();
149     int  serverError();
150     char*  extractString();
151     ULONG  extractULONG();
152     ULLONG extractULLONG();
153     long   extractLONG();
154 };
155
156 #endif