dvbd / src / dvbsched.cpp @ 59be6a47
History | View | Annotate | Download (4.83 KB)
1 |
/*
|
---|---|
2 |
Copyright 2003 John Knottenbelt
|
3 |
|
4 |
This program is free software; you can redistribute it and/or modify
|
5 |
it under the terms of the GNU General Public License as published by
|
6 |
the Free Software Foundation; either version 2 of the License, or
|
7 |
(at your option) any later version.
|
8 |
|
9 |
This program is distributed in the hope that it will be useful,
|
10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12 |
GNU General Public License for more details.
|
13 |
|
14 |
You should have received a copy of the GNU General Public License
|
15 |
along with this program; if not, write to the Free Software
|
16 |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
|
17 |
*/
|
18 |
|
19 |
#include "config.h" |
20 |
#include "dvbd.h" |
21 |
#include "utils.h" |
22 |
#include "stringutil.h" |
23 |
#include "select.h" |
24 |
#include "clientconnection.h" |
25 |
#include "unixclientsocket.h" |
26 |
#include "parsetime.h" |
27 |
|
28 |
#include <string> |
29 |
#include <iostream> |
30 |
#include <time.h> |
31 |
#include <getopt.h> |
32 |
#include <cerrno> |
33 |
#include <fstream> |
34 |
|
35 |
// Unfortunately, large file support (LFS) in gcc 3.2, 3.3 is broken
|
36 |
// on Debian sarge/sid. Work around with LFS_WORKAROUND
|
37 |
|
38 |
#define LFS_WORKAROUND
|
39 |
|
40 |
#ifdef LFS_WORKAROUND
|
41 |
#include <fcntl.h> |
42 |
#include <ext/stdio_filebuf.h> |
43 |
#endif
|
44 |
|
45 |
void usage(const char *progname); |
46 |
time_t convertTime(const char *theTime); |
47 |
|
48 |
int main(int argc, char *argv[]) |
49 |
{ |
50 |
// improve iostream performance
|
51 |
std::ios::sync_with_stdio(false);
|
52 |
|
53 |
std::string socketFile = DEFAULT_SOCKET_FILE;
|
54 |
bool convertToPS = false; |
55 |
int priority = 10; |
56 |
|
57 |
while (true) { |
58 |
static struct option long_options[] = { |
59 |
{"priority", 1, 0, 'p'}, |
60 |
{"socket", 1, 0, 's'}, |
61 |
{"ps", 0, 0, 'P'}, |
62 |
{0, 0, 0, 0} |
63 |
}; |
64 |
|
65 |
int option_index = 0; |
66 |
int c = getopt_long(argc, argv, "d:s:", long_options, &option_index); |
67 |
if (c == -1) |
68 |
break;
|
69 |
switch (c) {
|
70 |
case 'p': |
71 |
priority = toInt(optarg); |
72 |
break;
|
73 |
case 's': |
74 |
socketFile = optarg; |
75 |
break;
|
76 |
case 'P': |
77 |
convertToPS = true;
|
78 |
break;
|
79 |
default:
|
80 |
usage(argv[0]);
|
81 |
return 1; |
82 |
} |
83 |
} |
84 |
|
85 |
if (argc - optind != 5) { |
86 |
if (argc - optind != 0) |
87 |
std::cerr << "Incorrect number of arguments passed (expected 5, got "
|
88 |
<< argc - optind << ")\n\n";
|
89 |
|
90 |
usage(argv[0]);
|
91 |
return 1; |
92 |
} |
93 |
|
94 |
// Parse the command line arguments
|
95 |
std::string type(argv[optind++]);
|
96 |
std::string channel(argv[optind++]);
|
97 |
time_t scheduleTime = convertTime(argv[optind++]); |
98 |
unsigned duration = toInt(argv[optind++]);
|
99 |
std::string outputFile = argv[optind++];
|
100 |
|
101 |
ClientConnection client(socketFile); |
102 |
if (!client) {
|
103 |
std::cerr << "Fatal error: failed to connect to server on socket " << socketFile << std::endl;
|
104 |
return 1; |
105 |
} |
106 |
|
107 |
// Schedule
|
108 |
|
109 |
int job = client.schedule(type, channel, convertToPS, scheduleTime, duration, priority, outputFile);
|
110 |
|
111 |
if (job < 0) { |
112 |
std::cerr << "Failed to schedule job\n";
|
113 |
return 1; |
114 |
} |
115 |
|
116 |
std::cout << "Job number is " << job << std::endl;
|
117 |
|
118 |
StringList messages; |
119 |
client.checkSchedule(messages); |
120 |
|
121 |
if (!messages.empty()) {
|
122 |
std::cout << "The following schedule problems were identified:\n";
|
123 |
for (StringList::iterator i = messages.begin(); i != messages.end(); i++)
|
124 |
std::cout << *i << "\n";
|
125 |
|
126 |
std::cout << "Do you still wish to schedule the job?\n";
|
127 |
|
128 |
char answer;
|
129 |
while (std::cin >> answer) {
|
130 |
switch (tolower(answer)) {
|
131 |
case 'y': |
132 |
std::cout << "Job Scheduled\n";
|
133 |
return 0; |
134 |
case 'n': |
135 |
client.removeJob(job); |
136 |
std::cout << "Job not scheduled.\n";
|
137 |
return 0; |
138 |
default:
|
139 |
std::cout << "Please answer Y or N\n";
|
140 |
break;
|
141 |
} |
142 |
} |
143 |
} |
144 |
|
145 |
} |
146 |
|
147 |
time_t convertTime(const char *theTime) |
148 |
{ |
149 |
// Check that the date time is OK
|
150 |
char *argv[2] = { const_cast<char *>(theTime), 0 }; |
151 |
time_t result = parsetime( 1, argv );
|
152 |
if (result == 0) { |
153 |
std::cerr << "Fatal error: failed to parse date time: " << theTime << "\n"; |
154 |
exit(1);
|
155 |
} |
156 |
return result;
|
157 |
} |
158 |
|
159 |
void usage(const char *progname) { |
160 |
std::cerr << "Usage: " << progname << " [OPTION] TYPE CHANNEL TIME DURATION OUTPUT\n" |
161 |
<< "Schedule DVB recording for channel CHANNEL, using DVB-card\n"
|
162 |
<< "\n"
|
163 |
<< "TYPE can be dvb-t, dvb-s or dvb-c.\n"
|
164 |
<< "TIME is time to schedule recording. format is\n"
|
165 |
<< " same as for at(1)."
|
166 |
<< "DURATION is time to stream for in minutes.\n"
|
167 |
<< "OUTPUT is the output file, must be owned by the user\n"
|
168 |
<< " and writable by dvbd.\n"
|
169 |
<< "\n"
|
170 |
<< " -p, --priority Priority of stream (default is 10\n"
|
171 |
<< " higher priorities may dislodge lower\n"
|
172 |
<< " ones).\n"
|
173 |
<< " -s, --socket Specify socket to connect to\n"
|
174 |
<< " (default is " << DEFAULT_SOCKET_FILE << ")\n" |
175 |
<< " -P, --ps Convert stream to program stream\n";
|
176 |
} |
177 |
|
178 |
// For parsetime
|
179 |
extern "C" |
180 |
int yywrap()
|
181 |
{ |
182 |
return 1; |
183 |
} |