Revision a0d61e1f
src/dvbsched.cpp | ||
---|---|---|
53 | 53 |
std::string socketFile = DEFAULT_SOCKET_FILE; |
54 | 54 |
bool convertToPS = false; |
55 | 55 |
int priority = 10; |
56 |
bool removeSpecified = false; |
|
57 |
int removeJob = -1; |
|
56 | 58 |
|
57 | 59 |
while (true) { |
58 | 60 |
static struct option long_options[] = { |
59 | 61 |
{"priority", 1, 0, 'p'}, |
60 | 62 |
{"socket", 1, 0, 's'}, |
61 | 63 |
{"ps", 0, 0, 'P'}, |
64 |
{"remove", 1, 0, 'r'}, |
|
62 | 65 |
{0, 0, 0, 0} |
63 | 66 |
}; |
64 | 67 |
|
65 | 68 |
int option_index = 0; |
66 |
int c = getopt_long(argc, argv, "Pd:s:", long_options, &option_index); |
|
69 |
int c = getopt_long(argc, argv, "r:Pd:s:", long_options, &option_index);
|
|
67 | 70 |
if (c == -1) |
68 | 71 |
break; |
69 | 72 |
switch (c) { |
... | ... | |
76 | 79 |
case 'P': |
77 | 80 |
convertToPS = true; |
78 | 81 |
break; |
82 |
case 'r': |
|
83 |
removeSpecified = true; |
|
84 |
removeJob = toInt(optarg); |
|
85 |
break; |
|
79 | 86 |
default: |
80 | 87 |
usage(argv[0]); |
81 | 88 |
return 1; |
82 | 89 |
} |
83 | 90 |
} |
84 | 91 |
|
85 |
if (argc - optind != 5) { |
|
92 |
if (!removeSpecified && argc - optind != 5) {
|
|
86 | 93 |
if (argc - optind != 0) |
87 | 94 |
std::cerr << "Incorrect number of arguments passed (expected 5, got " |
88 | 95 |
<< argc - optind << ")\n\n"; |
... | ... | |
91 | 98 |
return 1; |
92 | 99 |
} |
93 | 100 |
|
101 |
ClientConnection client(socketFile); |
|
102 |
if (!client) { |
|
103 |
std::cerr << "Failed to connect to server:\n" << client.getError() << std::endl; |
|
104 |
return 1; |
|
105 |
} |
|
106 |
|
|
107 |
if (removeSpecified) { |
|
108 |
if (!client.removeJob(removeJob)) { |
|
109 |
std::cerr << "Failed to remove job: " << client.getError() << "\n"; |
|
110 |
return 1; |
|
111 |
} |
|
112 |
return 0; |
|
113 |
} |
|
114 |
|
|
94 | 115 |
// Parse the command line arguments |
95 | 116 |
std::string type(argv[optind++]); |
96 | 117 |
std::string channel(argv[optind++]); |
... | ... | |
98 | 119 |
unsigned duration = toInt(argv[optind++]); |
99 | 120 |
std::string outputFile = argv[optind++]; |
100 | 121 |
|
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 | 122 |
// Schedule |
108 | 123 |
|
109 |
int job = client.schedule(type, channel, convertToPS, scheduleTime, duration, priority, outputFile);
|
|
124 |
int job = client.schedule(type, channel, convertToPS, scheduleTime, duration, priority, outputFile); |
|
110 | 125 |
|
111 |
if (job < 0) {
|
|
112 |
std::cerr << "Failed to schedule job: " << client.getError() << "\n";
|
|
113 |
return 1;
|
|
114 |
}
|
|
126 |
if (job < 0) { |
|
127 |
std::cerr << "Failed to schedule job: " << client.getError() << "\n"; |
|
128 |
return 1; |
|
129 |
} |
|
115 | 130 |
|
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 |
} |
|
131 |
std::cout << "Job number is " << job << std::endl; |
|
132 |
|
|
133 |
StringList messages; |
|
134 |
client.checkSchedule(messages); |
|
135 |
|
|
136 |
if (!messages.empty()) { |
|
137 |
std::cout << "The following schedule problems were identified:\n"; |
|
138 |
for (StringList::iterator i = messages.begin(); i != messages.end(); i++) |
|
139 |
std::cout << *i << "\n"; |
|
140 |
|
|
141 |
std::cout << "Do you still wish to schedule the job?\n"; |
|
142 |
|
|
143 |
char answer; |
|
144 |
while (std::cin >> answer) { |
|
145 |
switch (tolower(answer)) { |
|
146 |
case 'y': |
|
147 |
std::cout << "Job Scheduled\n"; |
|
148 |
return 0; |
|
149 |
case 'n': |
|
150 |
client.removeJob(job); |
|
151 |
std::cout << "Job not scheduled.\n"; |
|
152 |
return 0; |
|
153 |
default: |
|
154 |
std::cout << "Please answer Y or N\n"; |
|
155 |
break; |
|
142 | 156 |
} |
143 | 157 |
} |
158 |
} |
|
144 | 159 |
|
145 | 160 |
} |
146 | 161 |
|
... | ... | |
158 | 173 |
|
159 | 174 |
void usage(const char *progname) { |
160 | 175 |
std::cerr << "Usage: " << progname << " [OPTION] TYPE CHANNEL TIME DURATION OUTPUT\n" |
176 |
<< " " << progname << " -r JOB\n" |
|
161 | 177 |
<< "Schedule DVB recording for channel CHANNEL, using DVB-card\n" |
162 | 178 |
<< "\n" |
163 | 179 |
<< "TYPE can be dvb-t, dvb-s or dvb-c.\n" |
... | ... | |
170 | 186 |
<< " -p, --priority Priority of stream (default is 10\n" |
171 | 187 |
<< " higher priorities may dislodge lower\n" |
172 | 188 |
<< " ones).\n" |
189 |
<< " -r, --remove Remove a job from the schedule\n" |
|
173 | 190 |
<< " -s, --socket Specify socket to connect to\n" |
174 | 191 |
<< " (default is " << DEFAULT_SOCKET_FILE << ")\n" |
175 | 192 |
<< " -P, --ps Convert stream to program stream\n"; |
Also available in: Unified diff