1 | //roarctl.c: |
---|
2 | |
---|
3 | /* |
---|
4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2013 |
---|
5 | * |
---|
6 | * This file is part of roarclients a part of RoarAudio, |
---|
7 | * a cross-platform sound system for both, home and professional use. |
---|
8 | * See README for details. |
---|
9 | * |
---|
10 | * This file is free software; you can redistribute it and/or modify |
---|
11 | * it under the terms of the GNU General Public License version 3 |
---|
12 | * as published by the Free Software Foundation. |
---|
13 | * |
---|
14 | * RoarAudio is distributed in the hope that it will be useful, |
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 | * GNU General Public License for more details. |
---|
18 | * |
---|
19 | * You should have received a copy of the GNU General Public License |
---|
20 | * along with this software; see the file COPYING. If not, write to |
---|
21 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
22 | * Boston, MA 02110-1301, USA. |
---|
23 | * |
---|
24 | */ |
---|
25 | |
---|
26 | /* ckport options: |
---|
27 | * ckport: ignore-symbol: roar_req of target libroar0 -- Used within ping command. |
---|
28 | */ |
---|
29 | |
---|
30 | #define _UNITS_T_BASE_USEC |
---|
31 | |
---|
32 | #include <roaraudio.h> |
---|
33 | #include <roaraudio/units.h> |
---|
34 | #include <libroardsp/libroardsp.h> |
---|
35 | |
---|
36 | #if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_SETUID) |
---|
37 | #define _POSIX_USERS |
---|
38 | #endif |
---|
39 | |
---|
40 | #ifdef _POSIX_USERS |
---|
41 | #include <pwd.h> |
---|
42 | #include <grp.h> |
---|
43 | #endif |
---|
44 | |
---|
45 | #include <sys/time.h> |
---|
46 | #include <time.h> |
---|
47 | |
---|
48 | #ifdef ROAR_HAVE_LIBM |
---|
49 | #include <math.h> |
---|
50 | #endif |
---|
51 | |
---|
52 | int g_verbose = 0; |
---|
53 | |
---|
54 | void display_client (struct roar_connection * con, int id); |
---|
55 | void display_stream (struct roar_connection * con, int id); |
---|
56 | int display_mixer (struct roar_connection * con, int stream); |
---|
57 | int show_meta_all (struct roar_connection * con, int id); |
---|
58 | |
---|
59 | void usage (void) { |
---|
60 | printf("roarctl [OPTIONS]... COMMAND [OPTS] [COMMAND [OPTS] [COMMAND [OPTS] [...]]]\n"); |
---|
61 | |
---|
62 | printf("\nOptions:\n\n"); |
---|
63 | |
---|
64 | printf(" --server SERVER - Set server hostname\n" |
---|
65 | " --help - Show this help\n" |
---|
66 | " --verbose -v - Show verbose output\n" |
---|
67 | " --list-aiprofiles - Show audio info profiles and exit\n" |
---|
68 | " --list-libstandards - Gets list of library (libroar) supported standards\n" |
---|
69 | " --enum-servers - Show a list of possible servers\n" |
---|
70 | " --hash-password - Hash a password and exit\n" |
---|
71 | ); |
---|
72 | |
---|
73 | printf("\nCommands:\n\n"); |
---|
74 | printf( |
---|
75 | " help - Show this help\n" |
---|
76 | " sleep TIME - Sleeps for TIME seconds\n" |
---|
77 | #ifdef ROAR_HAVE_GETTIMEOFDAY |
---|
78 | " ping NUM - Do NUM pings using NOOP commands\n" |
---|
79 | #endif |
---|
80 | " servername - Show name of server currently connected to\n" |
---|
81 | " whoami - Get own client ID\n" |
---|
82 | "\n" |
---|
83 | " beep - Ask the server to beep.\n" |
---|
84 | "\n" |
---|
85 | " listaiprofiles - list audio info profiles\n" |
---|
86 | " aiprofileget PROFILE - show audio info profile PROFILE\n" |
---|
87 | "\n" |
---|
88 | " standby, off - Go into standby mode\n" |
---|
89 | " resume, on - Go into active mode\n" |
---|
90 | " standbymode - Show current standby mode\n" |
---|
91 | " exit - Quits the roard (must be used as last command)\n" |
---|
92 | " terminate - Like exit but let the server up to serve still connected clients,\n" |
---|
93 | " new clients cann't connect and the server terminates after the last\n" |
---|
94 | " client disconnected\n" |
---|
95 | "\n" |
---|
96 | " volume ID CHAN [scale S] V0 V1...\n" |
---|
97 | " - Sets volume for stream ID\n" |
---|
98 | " CHAN is the number of channels or 'mono' or 'stereo'\n" |
---|
99 | " if mono or stereo is chosen roarctl trys to set\n" |
---|
100 | " sensfull values for all channels even if the output\n" |
---|
101 | " is has more channels.\n" |
---|
102 | " An optional scale can be given using S.\n" |
---|
103 | " all other args are the volumes of the channels\n" |
---|
104 | " you may use integer or percent values.\n" |
---|
105 | " percent values can floating points.\n" |
---|
106 | "\n" |
---|
107 | " flag ID FLAGS - Sets flags FLAGS on stream ID. FLAGS may be a comma\n" |
---|
108 | " separated list of flags.\n" |
---|
109 | " unflag ID FLAGS - Unsets flags on a stream. See flag.\n" |
---|
110 | " toogleflag ID FLAGS - Toggels flags on a stream. See flag.\n" |
---|
111 | " protectflag ID FLAGS - Protects flags on a stream. Those flags can not be\n" |
---|
112 | " changed anymore after the they got protected. See flag.\n" |
---|
113 | "\n" |
---|
114 | " role ID ROLE - Set role ROLE on stream ID.\n" |
---|
115 | "\n" |
---|
116 | " kick TYPE ID - Kicks object of TYPE with id ID\n" |
---|
117 | " Types: client stream sample source\n" |
---|
118 | " newvirtual P D E R B C - Adds a new virtual (child) stream\n" |
---|
119 | " Parameters:\n" |
---|
120 | " P: Parent stream ID, D: Direction,\n" |
---|
121 | " E: codEc, R: sample Rate,\n" |
---|
122 | " B: bits per sample, C: nummer of channels\n" |
---|
123 | "\n" |
---|
124 | " metaget ID TYPE - Read meta date of type TYPE from stream ID\n" |
---|
125 | // TODO: document metaset here. |
---|
126 | " metasave ID FILE - Saves meta data of stream ID to file FILE\n" |
---|
127 | " metaload ID FILE - Loads meta data from file FILE and set it on stream ID\n" |
---|
128 | "\n" |
---|
129 | " serverinfo - Gets general information about the server\n" |
---|
130 | " libinfo - Gets general information about the library (libroar)\n" |
---|
131 | " servertime - Gets server's time\n" |
---|
132 | " serveroinfo - Gets Information about server output\n" |
---|
133 | " serveroinfo2 DIR - Gets Information about server output for stream direction dir\n" |
---|
134 | "\n" |
---|
135 | " serverstandards - Gets list of server supported standards\n" |
---|
136 | " libstandards - Gets list of library (libroar) supported standards\n" |
---|
137 | "\n" |
---|
138 | " listclients - Gets Information about clients\n" |
---|
139 | " clientinfo ID - Gets Information about client ID\n" |
---|
140 | " liststreams - Gets Information about streams\n" |
---|
141 | " streaminfo ID - Gets Information about stream ID\n" |
---|
142 | " allinfo - Get all infos\n" |
---|
143 | ); |
---|
144 | } |
---|
145 | |
---|
146 | static void _bin2hex(char * out, char * in, size_t inlen, int uppercase) { |
---|
147 | const char * tab = uppercase ? "0123456789ABCDEF" : "0123456789abcdef"; |
---|
148 | unsigned char c; |
---|
149 | int nib0, nib1; |
---|
150 | |
---|
151 | for (; inlen; inlen--) { |
---|
152 | c = *(in++); |
---|
153 | nib0 = (c & 0x0F) >> 0; |
---|
154 | nib1 = (c & 0xF0) >> 4; |
---|
155 | // printf("inlen=%zu, c=%u, nibs={%i, %i}\n", inlen, (unsigned)c, nib1, nib0); |
---|
156 | *(out++) = tab[nib1]; |
---|
157 | *(out++) = tab[nib0]; |
---|
158 | } |
---|
159 | *out = 0; |
---|
160 | } |
---|
161 | |
---|
162 | int hash_password (void) { |
---|
163 | char * pw = NULL; |
---|
164 | char salt[8]; |
---|
165 | char digest[24]; |
---|
166 | char out[2*(8+24)+3+5+1] = "tiger:"; |
---|
167 | |
---|
168 | if ( roar_passwd_simple_ask_pw(&pw, "Password to hash?", NULL) == -1 ) |
---|
169 | return -1; |
---|
170 | |
---|
171 | roar_random_gen_nonce(salt, sizeof(salt)); |
---|
172 | |
---|
173 | roar_hash_salted_buffer(digest, pw, roar_mm_strlen(pw), ROAR_HT_TIGER, salt, sizeof(salt)); |
---|
174 | |
---|
175 | roar_mm_free(pw); |
---|
176 | |
---|
177 | _bin2hex(out+6, salt, sizeof(salt), 0); |
---|
178 | out[6+16] = ':'; |
---|
179 | _bin2hex(out+6+16+1, digest, sizeof(digest), 0); |
---|
180 | |
---|
181 | out[sizeof(out)-1] = 0; |
---|
182 | |
---|
183 | printf("Password: %s\n", out); |
---|
184 | |
---|
185 | return 0; |
---|
186 | } |
---|
187 | |
---|
188 | int enum_servers (void) { |
---|
189 | struct roar_server * list; |
---|
190 | struct roar_server * c; |
---|
191 | int flags = ROAR_ENUM_FLAG_DESC|ROAR_ENUM_FLAG_LOCATION; |
---|
192 | int dir = -1; |
---|
193 | int socktype = -1; |
---|
194 | int i; |
---|
195 | |
---|
196 | if ( (list = roar_enum_servers(flags, dir, socktype)) == NULL ) |
---|
197 | return -1; |
---|
198 | |
---|
199 | printf("Server Location Description\n"); |
---|
200 | printf("----------------------------------------------------------------------\n"); |
---|
201 | |
---|
202 | for (i = 0; ; i++) { |
---|
203 | c = &(list[i]); |
---|
204 | printf("%-16s %-16s %s\n", |
---|
205 | c->server == NULL ? "(default)" : c->server, |
---|
206 | c->location == NULL ? "" : c->location, |
---|
207 | c->description == NULL ? "" : c->description |
---|
208 | ); |
---|
209 | if ( c->server == NULL ) |
---|
210 | break; |
---|
211 | } |
---|
212 | |
---|
213 | roar_enum_servers_free(list); |
---|
214 | |
---|
215 | return 0; |
---|
216 | } |
---|
217 | |
---|
218 | #ifdef ROAR_HAVE_GETTIMEOFDAY |
---|
219 | int ping (struct roar_connection * con, int num) { |
---|
220 | struct timeval try, ans; |
---|
221 | struct roar_message m; |
---|
222 | register int ret; |
---|
223 | int i; |
---|
224 | double cur, min = 3600*1000, max = 0, sum = 0; |
---|
225 | |
---|
226 | if ( num == 0 ) |
---|
227 | return 0; |
---|
228 | |
---|
229 | for (i = 0; i < num; i++) { |
---|
230 | memset(&m, 0, sizeof(m)); |
---|
231 | |
---|
232 | m.cmd = ROAR_CMD_NOOP; |
---|
233 | m.stream = -1; |
---|
234 | m.datalen = 0; |
---|
235 | |
---|
236 | // we use roar_req() directly here because of speed. |
---|
237 | // roar_noop() does basicly the same but is a bit slower. |
---|
238 | |
---|
239 | gettimeofday(&try, NULL); |
---|
240 | ret = roar_req(con, &m, NULL); |
---|
241 | gettimeofday(&ans, NULL); |
---|
242 | |
---|
243 | if ( ret == -1 ) |
---|
244 | return -1; |
---|
245 | |
---|
246 | while (ans.tv_sec > try.tv_sec) { |
---|
247 | ans.tv_sec--; |
---|
248 | ans.tv_usec += 1000000; |
---|
249 | } |
---|
250 | ans.tv_usec -= try.tv_usec; |
---|
251 | |
---|
252 | cur = ans.tv_usec/1000.0; |
---|
253 | |
---|
254 | printf("Pong from server: seq=%i time=%.3f%cs\n", i, cur < 0.5 ? cur*1000.0 : cur, cur < 0.5 ? 'u' : 'm'); |
---|
255 | |
---|
256 | sum += cur; |
---|
257 | if ( min > cur ) |
---|
258 | min = cur; |
---|
259 | if ( cur > max ) |
---|
260 | max = cur; |
---|
261 | |
---|
262 | if ( i != (num - 1) ) |
---|
263 | roar_sleep(1); |
---|
264 | } |
---|
265 | |
---|
266 | printf("\n--- ping statistics ---\n"); |
---|
267 | printf("%i packets transmitted\n", i); |
---|
268 | printf("rtt min/avg/max = %.3f/%.3f/%.3f ms\n", min, sum/(double)i, max); |
---|
269 | |
---|
270 | return 0; |
---|
271 | } |
---|
272 | #endif |
---|
273 | |
---|
274 | #define _pm(m,n) if ( info->m != NULL ) printf(con != NULL ? "Server %-15s: %s\n" : "Library %-14s: %s\n", (n), (info->m)); |
---|
275 | void server_info (struct roar_connection * con) { |
---|
276 | struct roar_server_info * info = con != NULL ? roar_server_info(con) : roar_library_info(); |
---|
277 | long hostid; |
---|
278 | |
---|
279 | if ( info == NULL ) { |
---|
280 | fprintf(stderr, "Error: can not get server info\n"); |
---|
281 | return; |
---|
282 | } |
---|
283 | |
---|
284 | _pm(version, "Version"); |
---|
285 | _pm(location, "Location"); |
---|
286 | _pm(description, "Description"); |
---|
287 | _pm(contact, "Contact"); |
---|
288 | _pm(serial, "Serial"); |
---|
289 | _pm(address, "Address"); |
---|
290 | _pm(uiurl, "UI URL"); |
---|
291 | _pm(license, "License"); |
---|
292 | // _pm(hostid, "HostID"); |
---|
293 | if ( info->hostid != NULL ) { |
---|
294 | if ( sscanf(info->hostid, "0x%lx", &hostid) != 1 ) |
---|
295 | hostid = 0; |
---|
296 | |
---|
297 | if ( hostid ) { |
---|
298 | printf(con != NULL ? "Server %-15s: %s (%li.%li.%li.%li)\n" |
---|
299 | : "Library %-14s: %s (%li.%li.%li.%li)\n", "HostID", info->hostid, |
---|
300 | ((hostid & 0x00FF0000UL) >> 16UL), |
---|
301 | ((hostid & 0xFF000000UL) >> 24UL), |
---|
302 | ((hostid & 0x000000FFUL) >> 0UL), |
---|
303 | ((hostid & 0x0000FF00UL) >> 8UL) |
---|
304 | ); |
---|
305 | } else { |
---|
306 | _pm(hostid, "HostID"); |
---|
307 | } |
---|
308 | } |
---|
309 | _pm(build, "Build"); |
---|
310 | _pm(un.sysname, "System sysname"); |
---|
311 | _pm(un.release, "System release"); |
---|
312 | _pm(un.nodename, "System nodename"); |
---|
313 | _pm(un.machine, "System machine"); |
---|
314 | |
---|
315 | roar_server_info_free(info); |
---|
316 | } |
---|
317 | #undef _pm |
---|
318 | |
---|
319 | void server_time (struct roar_connection * con) { |
---|
320 | struct roar_time time; |
---|
321 | #ifdef ROAR_HAVE_CTIME_R |
---|
322 | time_t server_time; |
---|
323 | char server_time_buf[32]; |
---|
324 | #endif |
---|
325 | |
---|
326 | |
---|
327 | if ( roar_get_time(con, &time) == -1 ) { |
---|
328 | fprintf(stderr, "Error: can not get server time: %s\n", roar_vs_strerr(roar_error)); |
---|
329 | return; |
---|
330 | } |
---|
331 | |
---|
332 | #ifdef ROAR_HAVE_CTIME_R |
---|
333 | server_time = time.t_sec; |
---|
334 | if ( ctime_r(&server_time, server_time_buf) == NULL ) |
---|
335 | server_time_buf[0] = 0; |
---|
336 | |
---|
337 | if ( server_time_buf[0] ) |
---|
338 | if ( server_time_buf[strlen(server_time_buf)-1] == '\n' ) |
---|
339 | server_time_buf[strlen(server_time_buf)-1] = 0; |
---|
340 | #endif |
---|
341 | |
---|
342 | if ( g_verbose ) { |
---|
343 | printf("Server time : %s%s%s%" LIBROAR__ll "u.%06" LIBROAR__ll "u [+%" LIBROAR__ll "u/2^64] sec\n", |
---|
344 | #ifdef ROAR_HAVE_CTIME_R |
---|
345 | "\"", |
---|
346 | server_time_buf, |
---|
347 | "\" ", |
---|
348 | #else |
---|
349 | "", "", "", |
---|
350 | #endif |
---|
351 | (LIBROAR__longlong unsigned int)time.t_sec, |
---|
352 | (LIBROAR__longlong unsigned int) time.t_ssec / 18446744073709LLU, |
---|
353 | (LIBROAR__longlong unsigned int) time.t_ssec); |
---|
354 | } else { |
---|
355 | if ( time.c_freq == 1000000000LL && time.t_ssec == 0 ) { |
---|
356 | printf("Server time : %s%s%s%" LIBROAR__ll "u sec\n", |
---|
357 | #ifdef ROAR_HAVE_CTIME_R |
---|
358 | "\"", |
---|
359 | server_time_buf, |
---|
360 | "\" ", |
---|
361 | #else |
---|
362 | "", "", "", |
---|
363 | #endif |
---|
364 | (LIBROAR__longlong unsigned int)time.t_sec); |
---|
365 | } else { |
---|
366 | printf("Server time : %s%s%s%" LIBROAR__ll "u.%06" LIBROAR__ll"u sec\n", |
---|
367 | #ifdef ROAR_HAVE_CTIME_R |
---|
368 | "\"", |
---|
369 | server_time_buf, |
---|
370 | "\" ", |
---|
371 | #else |
---|
372 | "", "", "", |
---|
373 | #endif |
---|
374 | (LIBROAR__longlong unsigned int)time.t_sec, |
---|
375 | (LIBROAR__longlong unsigned int) time.t_ssec / 18446744073709LLU); |
---|
376 | } |
---|
377 | } |
---|
378 | if ( time.c_freq ) |
---|
379 | printf("Server clock frequency: %f Hz\n", (float)((double)time.c_freq / (double)1000000000.)); |
---|
380 | if ( time.c_drift ) { |
---|
381 | #ifdef ROAR_HAVE_LIBM |
---|
382 | printf("Server clock drift : %" LIBROAR__ll "u:2^64 (~10^%f)\n", |
---|
383 | (LIBROAR__longlong unsigned int)time.c_drift, logf((float)time.c_drift)/2.302585f); |
---|
384 | #else |
---|
385 | printf("Server clock drift : %" LIBROAR__ll "u:2^64\n", |
---|
386 | (LIBROAR__longlong unsigned int)time.c_drift); |
---|
387 | #endif |
---|
388 | } |
---|
389 | } |
---|
390 | |
---|
391 | void server_oinfo (struct roar_connection * con, int dir) { |
---|
392 | struct roar_stream s; |
---|
393 | |
---|
394 | if ( roar_server_oinfo(con, &s, dir) == -1 ) { |
---|
395 | fprintf(stderr, "Error: can not get server output info\n"); |
---|
396 | return; |
---|
397 | } |
---|
398 | |
---|
399 | printf("Stream direction : %s\n", roar_dir2str(s.dir)); |
---|
400 | printf("Server Output rate : %i Hz\n", s.info.rate); |
---|
401 | printf("Server Output bits : %i\n", s.info.bits); |
---|
402 | printf("Server Output channels: %i\n", s.info.channels); |
---|
403 | printf("Server Output codec : %i (%s%s)\n", s.info.codec, roar_codec2str(s.info.codec), |
---|
404 | s.info.codec == ROAR_CODEC_DEFAULT ? " native" : ""); |
---|
405 | // printf("Server Output rate: %i", s.info.rate); |
---|
406 | if ( g_verbose > 1 && s.pos != (uint32_t)-1 ) { |
---|
407 | if ( s.info.rate && s.info.channels ) { |
---|
408 | printf("Server Position : %lu S (%.3fs)\n", (unsigned long int) s.pos, (float)s.pos/(s.info.rate*s.info.channels)); |
---|
409 | } else { |
---|
410 | printf("Server Position : %lu S\n", (unsigned long int) s.pos); |
---|
411 | } |
---|
412 | } |
---|
413 | } |
---|
414 | |
---|
415 | static void print_stds (const struct roar_stds * stds) { |
---|
416 | size_t i; |
---|
417 | int vendor, standard, version; |
---|
418 | char numbuf[2][8]; |
---|
419 | const char * vendor_name; |
---|
420 | |
---|
421 | for (i = 0; i < stds->stds_len; i++) { |
---|
422 | vendor = ROAR_STD_VENDOR(stds->stds[i]); |
---|
423 | standard = ROAR_STD_STD(stds->stds[i]); |
---|
424 | version = ROAR_STD_VERSION(stds->stds[i]); |
---|
425 | |
---|
426 | if ( (vendor_name = roar_stds_vendor2str(vendor)) == NULL ) { |
---|
427 | snprintf(numbuf[0], sizeof(numbuf[0]), "%i", vendor); |
---|
428 | numbuf[0][sizeof(numbuf[0])-1] = 0; |
---|
429 | vendor_name = numbuf[0]; |
---|
430 | } |
---|
431 | |
---|
432 | if ( version == 0 ) { |
---|
433 | numbuf[1][0] = 0; |
---|
434 | } else { |
---|
435 | snprintf(numbuf[1], sizeof(numbuf[1]), "-%i", version); |
---|
436 | numbuf[1][sizeof(numbuf[1])-1] = 0; |
---|
437 | } |
---|
438 | |
---|
439 | printf("Server standard : %s-%i%s\n", vendor_name, standard, numbuf[1]); |
---|
440 | } |
---|
441 | } |
---|
442 | |
---|
443 | void server_standards (struct roar_connection * con) { |
---|
444 | struct roar_stds * stds; |
---|
445 | |
---|
446 | if ( roar_caps_stds(con, &stds, NULL, -1) == -1 ) { |
---|
447 | fprintf(stderr, "Error: can not get server standards\n"); |
---|
448 | return; |
---|
449 | } |
---|
450 | |
---|
451 | print_stds(stds); |
---|
452 | |
---|
453 | roar_stds_free(stds); |
---|
454 | } |
---|
455 | |
---|
456 | void lib_standards (void) { |
---|
457 | print_stds(libroar_libstds()); |
---|
458 | } |
---|
459 | |
---|
460 | const char * proc_name (pid_t pid) { |
---|
461 | static char ret[80] = "?"; |
---|
462 | #ifdef __linux__ |
---|
463 | char file[80], buf[80], *r; |
---|
464 | int i; |
---|
465 | |
---|
466 | snprintf(file, sizeof(file)-1, "/proc/%i/exe", pid); |
---|
467 | file[sizeof(file)-1] = 0; |
---|
468 | |
---|
469 | ret[0] = '?'; |
---|
470 | ret[1] = 0; |
---|
471 | |
---|
472 | if ( (i = readlink(file, buf, sizeof(buf)-1)) != -1 ) { |
---|
473 | buf[i] = 0; |
---|
474 | if ( (r = strrchr(buf, '/')) != NULL ) { |
---|
475 | r++; |
---|
476 | if ( *r != 0 ) { |
---|
477 | strncpy(ret, r, sizeof(ret)-1); |
---|
478 | ret[sizeof(ret)-1] = 0; |
---|
479 | } |
---|
480 | } |
---|
481 | } |
---|
482 | #else |
---|
483 | (void)pid; |
---|
484 | #endif |
---|
485 | |
---|
486 | return ret; |
---|
487 | } |
---|
488 | |
---|
489 | void list_clients (struct roar_connection * con) { |
---|
490 | int i; |
---|
491 | int num; |
---|
492 | int id[ROAR_CLIENTS_MAX]; |
---|
493 | |
---|
494 | if ( (num = roar_list_clients(con, id, ROAR_CLIENTS_MAX)) == -1 ) { |
---|
495 | fprintf(stderr, "Error: can not get client list\n"); |
---|
496 | return; |
---|
497 | } |
---|
498 | |
---|
499 | for (i = 0; i < num; i++) { |
---|
500 | display_client(con, id[i]); |
---|
501 | } |
---|
502 | } |
---|
503 | |
---|
504 | void display_client (struct roar_connection * con, int id) { |
---|
505 | static int self_id = -1; |
---|
506 | static struct roar_client self_client_store; |
---|
507 | static struct roar_client * self_client = NULL; |
---|
508 | struct roar_client c; |
---|
509 | char tmp[80]; |
---|
510 | int h; |
---|
511 | #ifdef _POSIX_USERS |
---|
512 | struct group * grp = NULL; |
---|
513 | struct passwd * pwd = NULL; |
---|
514 | #endif |
---|
515 | |
---|
516 | if ( self_id == -1 ) { |
---|
517 | if ( (self_id = roar_get_clientid(con)) != -1 ) { |
---|
518 | if ( roar_get_client(con, &self_client_store, self_id) == -1 ) { |
---|
519 | self_id = -1; |
---|
520 | } else { |
---|
521 | self_client = &self_client_store; |
---|
522 | } |
---|
523 | } |
---|
524 | } |
---|
525 | |
---|
526 | printf("client %i:\n", id); |
---|
527 | if ( roar_get_client(con, &c, id) == -1 ) { |
---|
528 | fprintf(stderr, "Error: can not get client info\n"); |
---|
529 | return; |
---|
530 | } |
---|
531 | |
---|
532 | if ( c.name[0] != '\0' ) |
---|
533 | printf("Client name : %s\n", c.name); |
---|
534 | if ( roar_nnode_get_socktype(&(c.nnode)) != ROAR_SOCKET_TYPE_UNKNOWN ) { |
---|
535 | if ( roar_nnode_to_str(&(c.nnode), tmp, sizeof(tmp)) == 0 ) { |
---|
536 | printf("Client network node : %s\n", tmp); |
---|
537 | } |
---|
538 | } |
---|
539 | |
---|
540 | if ( c.pid != -1 ) { |
---|
541 | if ( self_id != -1 && roar_nnode_cmp(&(self_client->nnode), &(c.nnode)) == 0 ) { |
---|
542 | printf("Client PID : %i(%s)\n", c.pid, proc_name(c.pid)); |
---|
543 | } else { |
---|
544 | printf("Client PID : %i\n", c.pid); |
---|
545 | } |
---|
546 | } |
---|
547 | if ( c.uid != -1 ) { |
---|
548 | #ifdef _POSIX_USERS |
---|
549 | if ( self_id != -1 && roar_nnode_cmp(&(self_client->nnode), &(c.nnode)) == 0 ) { |
---|
550 | pwd = getpwuid(c.uid); |
---|
551 | grp = getgrgid(c.gid); |
---|
552 | printf("Client UID/GID : %i(%s)/%i(%s)\n", c.uid, pwd ? pwd->pw_name : "?", c.gid, grp ? grp->gr_name : "?"); |
---|
553 | } else { |
---|
554 | #else |
---|
555 | if ( 1 ) { |
---|
556 | #endif |
---|
557 | printf("Client UID/GID : %i/%i\n", c.uid, c.gid); |
---|
558 | } |
---|
559 | } |
---|
560 | |
---|
561 | if ( g_verbose && c.proto != ROAR_PROTO_NONE ) { |
---|
562 | printf("Client Protocol : %s\n", roar_proto2str(c.proto)); |
---|
563 | } |
---|
564 | |
---|
565 | if ( g_verbose && c.byteorder != ROAR_BYTEORDER_UNKNOWN ) { |
---|
566 | if ( c.byteorder == ROAR_BYTEORDER_NETWORK ) { |
---|
567 | roar_mm_strscpy(tmp, " (network byteorder"); |
---|
568 | } else { |
---|
569 | *tmp = 0; |
---|
570 | } |
---|
571 | |
---|
572 | if ( c.byteorder == ROAR_BYTEORDER_NATIVE ) { |
---|
573 | if ( *tmp ) { |
---|
574 | roar_mm_strscat(tmp, ", native"); |
---|
575 | } else { |
---|
576 | roar_mm_strscpy(tmp, " (native"); |
---|
577 | } |
---|
578 | } |
---|
579 | |
---|
580 | if ( *tmp ) |
---|
581 | roar_mm_strscat(tmp, ")"); |
---|
582 | |
---|
583 | printf("Client Byteorder : %s%s\n", roar_byteorder2str(c.byteorder), tmp); |
---|
584 | } |
---|
585 | |
---|
586 | if ( c.execed != -1 ) |
---|
587 | printf("Execed stream : %i\n", c.execed); |
---|
588 | |
---|
589 | for (h = 0; h < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; h++) |
---|
590 | if ( c.streams[h] != -1 ) |
---|
591 | printf("stream : %i\n", c.streams[h]); |
---|
592 | } |
---|
593 | |
---|
594 | void list_streams (struct roar_connection * con) { |
---|
595 | int i; |
---|
596 | int num; |
---|
597 | int id[ROAR_STREAMS_MAX]; |
---|
598 | |
---|
599 | if ( (num = roar_list_streams(con, id, ROAR_STREAMS_MAX)) == -1 ) { |
---|
600 | fprintf(stderr, "Error: can not get stream list\n"); |
---|
601 | return; |
---|
602 | } |
---|
603 | |
---|
604 | for (i = 0; i < num; i++) { |
---|
605 | display_stream(con, id[i]); |
---|
606 | } |
---|
607 | } |
---|
608 | |
---|
609 | void display_stream (struct roar_connection * con, int id) { |
---|
610 | char chanmap[ROAR_MAX_CHANNELS]; |
---|
611 | struct roar_stream s; |
---|
612 | struct roar_stream_info info; |
---|
613 | char buffer[1024]; |
---|
614 | char * flags = buffer; |
---|
615 | char * name = buffer; |
---|
616 | char * infotext; |
---|
617 | const char * mime; |
---|
618 | size_t len; |
---|
619 | |
---|
620 | printf("stream %i:\n", id); |
---|
621 | if ( roar_get_stream(con, &s, id) == -1 ) { |
---|
622 | fprintf(stderr, "Error: can not get stream info\n"); |
---|
623 | return; |
---|
624 | } |
---|
625 | printf("Stream direction : %s\n", roar_dir2str(s.dir)); |
---|
626 | |
---|
627 | if ( roar_stream_get_name(con, &s, name, sizeof(buffer)) == 0 ) |
---|
628 | printf("Stream name : %s\n", name); |
---|
629 | |
---|
630 | if ( (int)s.pos_rel_id == -1 ) { |
---|
631 | printf("Relativ position id : none (stream not synchronized)\n"); |
---|
632 | } else if ( (int)s.pos_rel_id == id ) { |
---|
633 | printf("Relativ position id : %i (self synchronized)\n", s.pos_rel_id); |
---|
634 | } else { |
---|
635 | printf("Relativ position id : %i (synchronized)\n", s.pos_rel_id); |
---|
636 | } |
---|
637 | if ( g_verbose > 1 && s.pos != (uint32_t)-1 ) { |
---|
638 | if ( s.info.rate && s.info.channels ) { |
---|
639 | printf("Position : %lu S (%.3fs)\n", (unsigned long int) s.pos, |
---|
640 | (float)s.pos/(s.info.rate*s.info.channels)); |
---|
641 | } else { |
---|
642 | printf("Position : %lu S\n", (unsigned long int) s.pos); |
---|
643 | } |
---|
644 | } |
---|
645 | |
---|
646 | switch (s.dir) { |
---|
647 | case ROAR_DIR_MIDI_IN: |
---|
648 | case ROAR_DIR_MIDI_OUT: |
---|
649 | infotext = " ticks/s"; |
---|
650 | break; |
---|
651 | case ROAR_DIR_LIGHT_IN: |
---|
652 | case ROAR_DIR_LIGHT_OUT: |
---|
653 | infotext = " updates/s"; |
---|
654 | break; |
---|
655 | default: |
---|
656 | infotext = " Hz"; |
---|
657 | } |
---|
658 | if ( s.info.rate ) |
---|
659 | printf("Stream sample rate : %i%s\n", s.info.rate, infotext); |
---|
660 | if ( s.info.bits ) |
---|
661 | printf("Stream bits : %i\n", s.info.bits); |
---|
662 | if ( s.info.channels ) |
---|
663 | printf("Stream channels : %i\n", s.info.channels); |
---|
664 | |
---|
665 | mime = roar_codec2mime(s.info.codec); |
---|
666 | printf("Stream codec : %2i (%s%s%s%s)\n", s.info.codec, roar_codec2str(s.info.codec), |
---|
667 | s.info.codec == ROAR_CODEC_DEFAULT ? " native" : "", |
---|
668 | mime == NULL ? "" : " mimetype:", |
---|
669 | mime == NULL ? "" : mime |
---|
670 | ); |
---|
671 | if ( roar_stream_get_info(con, &s, &info) != -1 ) { |
---|
672 | if ( info.codec != s.info.codec ) { |
---|
673 | mime = roar_codec2mime(info.codec); |
---|
674 | printf("Streamed codec : %2i (%s%s%s%s)\n", info.codec, roar_codec2str(info.codec), |
---|
675 | info.codec == ROAR_CODEC_DEFAULT ? " native" : "", |
---|
676 | mime == NULL ? "" : " mimetype:", |
---|
677 | mime == NULL ? "" : mime |
---|
678 | ); |
---|
679 | } |
---|
680 | |
---|
681 | if ( g_verbose ) { |
---|
682 | if ( info.block_size ) |
---|
683 | printf("Stream block size : %i Byte\n", info.block_size); |
---|
684 | |
---|
685 | printf("Underruns pre/post : %i/%i\n", info.pre_underruns, info.post_underruns); |
---|
686 | if ( g_verbose > 1 ) |
---|
687 | printf("Stream delay : %ims (%.2fm)\n", (int)info.delay/1000, (info.delay*(float)_SPEED_OF_SOUND)); |
---|
688 | |
---|
689 | if ( g_verbose > 1 ) |
---|
690 | printf("Stream mixer : %i\n", info.mixer); |
---|
691 | |
---|
692 | if ( g_verbose > 1 ) |
---|
693 | printf("Stream state : %s\n", roar_streamstate2str(info.state)); |
---|
694 | |
---|
695 | if ( g_verbose > 1 ) |
---|
696 | printf("Stream role : %s\n", roar_role2str(info.role)); |
---|
697 | |
---|
698 | *flags = 0; |
---|
699 | #define _strcat(dst,src) roar_mm_strlcat((dst),(src), sizeof(buffer)) |
---|
700 | if ( info.flags & ROAR_FLAG_PRIMARY ) |
---|
701 | _strcat(flags, "primary "); |
---|
702 | if ( info.flags & ROAR_FLAG_SYNC ) |
---|
703 | _strcat(flags, "sync "); |
---|
704 | if ( info.flags & ROAR_FLAG_OUTPUT ) |
---|
705 | _strcat(flags, "output "); |
---|
706 | if ( info.flags & ROAR_FLAG_SOURCE ) |
---|
707 | _strcat(flags, "source "); |
---|
708 | if ( info.flags & ROAR_FLAG_META ) |
---|
709 | _strcat(flags, "meta "); |
---|
710 | if ( info.flags & ROAR_FLAG_AUTOCONF ) |
---|
711 | _strcat(flags, "autoconf "); |
---|
712 | if ( info.flags & ROAR_FLAG_CLEANMETA ) |
---|
713 | _strcat(flags, "cleanmeta "); |
---|
714 | if ( info.flags & ROAR_FLAG_HWMIXER ) |
---|
715 | _strcat(flags, "hwmixer "); |
---|
716 | if ( info.flags & ROAR_FLAG_PAUSE ) |
---|
717 | _strcat(flags, "pause "); |
---|
718 | if ( info.flags & ROAR_FLAG_MUTE ) |
---|
719 | _strcat(flags, "mute "); |
---|
720 | if ( info.flags & ROAR_FLAG_MMAP ) |
---|
721 | _strcat(flags, "mmap "); |
---|
722 | if ( info.flags & ROAR_FLAG_ANTIECHO ) |
---|
723 | _strcat(flags, "antiecho "); |
---|
724 | if ( info.flags & ROAR_FLAG_VIRTUAL ) |
---|
725 | _strcat(flags, "virtual "); |
---|
726 | if ( info.flags & ROAR_FLAG_RECSOURCE ) |
---|
727 | _strcat(flags, "recsource "); |
---|
728 | if ( info.flags & ROAR_FLAG_PASSMIXER ) |
---|
729 | _strcat(flags, "passmixer "); |
---|
730 | if ( info.flags & ROAR_FLAG_PRETHRU ) |
---|
731 | _strcat(flags, "prethru "); |
---|
732 | if ( info.flags & ROAR_FLAG_IMMUTABLE ) |
---|
733 | _strcat(flags, "immutable "); |
---|
734 | if ( info.flags & ROAR_FLAG_ENHANCE ) |
---|
735 | _strcat(flags, "enhance "); |
---|
736 | if ( info.flags & ROAR_FLAG_SINGLESINK ) |
---|
737 | _strcat(flags, "singlesink "); |
---|
738 | #undef _strcat |
---|
739 | |
---|
740 | printf("Flags : %s\n", flags); |
---|
741 | } |
---|
742 | } |
---|
743 | |
---|
744 | if ( g_verbose && (s.info.channels != 0 && s.info.channels <= ROAR_MAX_CHANNELS) ) { |
---|
745 | len = ROAR_MAX_CHANNELS; |
---|
746 | if ( roar_stream_get_chanmap(con, &s, chanmap, &len) == -1 ) { |
---|
747 | fprintf(stderr, "Error: can not get stream channel map\n"); |
---|
748 | } else { |
---|
749 | if ( roardsp_chanlist2str(chanmap, len, buffer, 1024) == -1 ) { |
---|
750 | fprintf(stderr, "Error: can not convert channel map into string\n"); |
---|
751 | } else { |
---|
752 | printf("Channel Map : %s\n", buffer); |
---|
753 | } |
---|
754 | } |
---|
755 | } |
---|
756 | |
---|
757 | if ( s.dir != ROAR_DIR_THRU ) { |
---|
758 | if ( s.info.channels != 0 && s.info.channels <= ROAR_MAX_CHANNELS ) { |
---|
759 | display_mixer(con, id); |
---|
760 | } |
---|
761 | show_meta_all(con, id); |
---|
762 | } |
---|
763 | } |
---|
764 | |
---|
765 | int display_mixer (struct roar_connection * con, int stream) { |
---|
766 | struct roar_stream_rpg rpg; |
---|
767 | struct roar_mixer_settings mixer; |
---|
768 | struct roar_stream s; |
---|
769 | int channels; |
---|
770 | int i; |
---|
771 | float fs; |
---|
772 | |
---|
773 | if ( roar_get_vol(con, stream, &mixer, &channels) == -1 ) { |
---|
774 | fprintf(stderr, "Error: can not get stream mixer info for stream %i\n", stream); |
---|
775 | return -1; |
---|
776 | } |
---|
777 | |
---|
778 | roar_stream_new_by_id(&s, stream); |
---|
779 | if ( roar_stream_get_rpg(con, &s, &rpg) != -1 ) { |
---|
780 | printf("ReplayGain Mode : %s\n", roar_rpgmode2str(rpg.mode)); |
---|
781 | } |
---|
782 | |
---|
783 | #ifdef ROAR_HAVE_LIBM |
---|
784 | #define _DB ", %.2fdB" |
---|
785 | #else |
---|
786 | #define _DB "" |
---|
787 | #endif |
---|
788 | |
---|
789 | fs = (float)mixer.scale / 100.; |
---|
790 | |
---|
791 | if ( channels ) { // we hide RPG info for zero-channel streams |
---|
792 | printf("Mixer ReplayGain : %i/%i (%.2f%%" _DB ")\n", mixer.rpg_mul, mixer.rpg_div, |
---|
793 | 100.*(float)mixer.rpg_mul/((float)mixer.rpg_div) |
---|
794 | #ifdef ROAR_HAVE_LIBM |
---|
795 | , 20*log10f((float)mixer.rpg_mul/(float)mixer.rpg_div) |
---|
796 | #endif |
---|
797 | ); |
---|
798 | } |
---|
799 | |
---|
800 | for (i = 0; i < channels; i++) |
---|
801 | printf("Mixer volume chan %2i : %i/%i (%.2f%%" _DB ")\n", i, mixer.mixer[i], mixer.scale, |
---|
802 | (float)mixer.mixer[i]/fs |
---|
803 | #ifdef ROAR_HAVE_LIBM |
---|
804 | , 20*log10f((float)mixer.mixer[i]/(float)mixer.scale) |
---|
805 | #endif |
---|
806 | ); |
---|
807 | |
---|
808 | return 0; |
---|
809 | } |
---|
810 | |
---|
811 | static unsigned int set_mixer_parse_volume (char * k, int len, uint16_t scale) { |
---|
812 | float fs = scale; |
---|
813 | |
---|
814 | switch (k[len - 1]) { |
---|
815 | case '%': |
---|
816 | k[len - 1] = 0; |
---|
817 | return (atof(k)*fs)/100.; |
---|
818 | break; |
---|
819 | #ifdef ROAR_HAVE_LIBM |
---|
820 | case 'b': |
---|
821 | case 'B': |
---|
822 | // TODO: can we hanle the error better? |
---|
823 | if ( len < 2 ) |
---|
824 | return 0; |
---|
825 | |
---|
826 | k[len - 2] = 0; |
---|
827 | return powf(10, atof(k)/20.f)*fs; |
---|
828 | break; |
---|
829 | #endif |
---|
830 | } |
---|
831 | |
---|
832 | return atoi(k); |
---|
833 | } |
---|
834 | |
---|
835 | int set_mixer (struct roar_connection * con, int * cur, int max, char * arg[]) { |
---|
836 | uint16_t scale = 65535; |
---|
837 | int chans = 0; |
---|
838 | int id; |
---|
839 | int i; |
---|
840 | int len; |
---|
841 | int old_chans; |
---|
842 | char * k; |
---|
843 | struct roar_mixer_settings mixer; |
---|
844 | struct roar_mixer_settings old_mixer; |
---|
845 | int mode = ROAR_SET_VOL_ALL; |
---|
846 | |
---|
847 | if (*cur + 2 > max) |
---|
848 | return -1; |
---|
849 | |
---|
850 | id = atoi(arg[++(*cur)]); |
---|
851 | |
---|
852 | k = arg[++(*cur)]; |
---|
853 | |
---|
854 | if ( !strcmp(arg[*cur + 1], "scale") ) { |
---|
855 | (*cur)++; // 'scale' |
---|
856 | (*cur)++; |
---|
857 | scale = set_mixer_parse_volume(arg[*cur], strlen(arg[*cur]), 65535); |
---|
858 | } |
---|
859 | |
---|
860 | mixer.scale = scale; |
---|
861 | |
---|
862 | if ( roar_get_vol(con, id, &old_mixer, &old_chans) == -1 ) { |
---|
863 | fprintf(stderr, "Error: can not get stream mixer info for stream %i\n", id); |
---|
864 | return -1; |
---|
865 | } |
---|
866 | |
---|
867 | if ( strcmp(k, "mono") == 0 ) { |
---|
868 | chans = 1; |
---|
869 | mode = ROAR_SET_VOL_UNMAPPED; |
---|
870 | } else if ( strcmp(k, "stereo") == 0 ) { |
---|
871 | chans = 2; |
---|
872 | mode = ROAR_SET_VOL_UNMAPPED; |
---|
873 | } else { |
---|
874 | chans = atoi(k); |
---|
875 | } |
---|
876 | |
---|
877 | // ensure most simple mode: |
---|
878 | if ( old_chans == chans && mode == ROAR_SET_VOL_UNMAPPED ) |
---|
879 | mode = ROAR_SET_VOL_ALL; |
---|
880 | |
---|
881 | if ( *cur + chans > max ) |
---|
882 | return -1; |
---|
883 | |
---|
884 | for (i = 0; i < chans; i++) { |
---|
885 | k = arg[++(*cur)]; |
---|
886 | len = strlen(k); |
---|
887 | |
---|
888 | mixer.mixer[i] = set_mixer_parse_volume(k, len, scale); |
---|
889 | } |
---|
890 | |
---|
891 | if ( roar_set_vol(con, id, &mixer, chans, mode) == 0 ) |
---|
892 | return 0; |
---|
893 | |
---|
894 | // no fallback if already using ROAR_SET_VOL_ALL: |
---|
895 | if ( mode == ROAR_SET_VOL_ALL ) |
---|
896 | return -1; |
---|
897 | |
---|
898 | if ( roar_conv_volume(&mixer, &mixer, old_chans, chans) == -1 ) |
---|
899 | return -1; |
---|
900 | |
---|
901 | chans = old_chans; |
---|
902 | mode = ROAR_SET_VOL_ALL; |
---|
903 | |
---|
904 | if ( roar_set_vol(con, id, &mixer, chans, mode) == 0 ) |
---|
905 | return 0; |
---|
906 | |
---|
907 | return -1; |
---|
908 | } |
---|
909 | |
---|
910 | |
---|
911 | int newvirtual (struct roar_connection * con, char *p_s, char *d_s, char *e_s, char *r_s, char *b_s, char *c_s) { |
---|
912 | struct roar_stream s; |
---|
913 | int dir = roar_str2dir(d_s); |
---|
914 | int parent = atoi(p_s); |
---|
915 | |
---|
916 | ROAR_DBG("newvirtual(*): dir=%i, parent=%i", dir, parent); |
---|
917 | |
---|
918 | if ( roar_stream_new(&s, roar_str2rate(r_s), roar_str2channels(c_s), roar_str2bits(b_s), roar_str2codec(e_s)) == -1 ) |
---|
919 | return -1; |
---|
920 | |
---|
921 | return roar_simple_connect_virtual(con, &s, parent, dir); |
---|
922 | } |
---|
923 | |
---|
924 | int set_meta (struct roar_connection * con, int id, char * mode, char * type, char * val) { |
---|
925 | struct roar_meta meta; |
---|
926 | struct roar_stream s; |
---|
927 | int mode_i = ROAR_META_MODE_SET; |
---|
928 | |
---|
929 | if ( roar_stream_new_by_id(&s, id) == -1 ) |
---|
930 | return -1; |
---|
931 | |
---|
932 | // printf("set_meta(*): mode='%s', type='%s', val='%s'\n", mode, type, val); |
---|
933 | |
---|
934 | if ( strcmp(mode, "add") == 0 ) { |
---|
935 | mode_i = ROAR_META_MODE_ADD; |
---|
936 | } |
---|
937 | |
---|
938 | meta.type = roar_meta_inttype(type); |
---|
939 | meta.value = val; |
---|
940 | meta.key[0] = 0; |
---|
941 | |
---|
942 | if ( meta.type == -1 ) { |
---|
943 | fprintf(stderr, "Error: unknown type: %s\n", type); |
---|
944 | return -1; |
---|
945 | } |
---|
946 | |
---|
947 | // printf("D: type=%i, mode=%i\n", meta.type, mode_i); |
---|
948 | |
---|
949 | if ( roar_stream_meta_set(con, &s, mode_i, &meta) == -1 ) |
---|
950 | return -1; |
---|
951 | |
---|
952 | meta.type = ROAR_META_TYPE_NONE; |
---|
953 | meta.value = NULL; |
---|
954 | |
---|
955 | return roar_stream_meta_set(con, &s, ROAR_META_MODE_FINALIZE, &meta); |
---|
956 | } |
---|
957 | |
---|
958 | int load_meta (struct roar_connection * con, int id, char * file) { |
---|
959 | struct roar_meta meta; |
---|
960 | struct roar_stream s; |
---|
961 | int mode_i = ROAR_META_MODE_SET; |
---|
962 | FILE * in; |
---|
963 | char lion[1024]; |
---|
964 | char * v; |
---|
965 | |
---|
966 | if ( roar_stream_new_by_id(&s, id) == -1 ) |
---|
967 | return -1; |
---|
968 | |
---|
969 | if ( (in = fopen(file, "r")) == NULL ) |
---|
970 | return -1; |
---|
971 | |
---|
972 | while (fgets(lion, 1024, in) != NULL) { |
---|
973 | if ( (v = strtok(lion, "\r\n")) != NULL ) |
---|
974 | if ( (v = strtok(NULL, "\r\n")) != NULL ) |
---|
975 | *(v-1) = 0; |
---|
976 | |
---|
977 | if ( (v = strstr(lion, "=")) == NULL ) { |
---|
978 | fprintf(stderr, "Error: can not parse meta data lion: %s\n", lion); |
---|
979 | continue; |
---|
980 | } |
---|
981 | |
---|
982 | *v++ = 0; |
---|
983 | |
---|
984 | meta.type = roar_meta_inttype(lion); |
---|
985 | meta.value = v; |
---|
986 | meta.key[0] = 0; |
---|
987 | |
---|
988 | if ( meta.type == -1 ) { |
---|
989 | fprintf(stderr, "Error: unknown type: %s\n", lion); |
---|
990 | continue; |
---|
991 | } |
---|
992 | |
---|
993 | if ( roar_stream_meta_set(con, &s, mode_i, &meta) == -1 ) { |
---|
994 | fclose(in); |
---|
995 | return -1; |
---|
996 | } |
---|
997 | } |
---|
998 | |
---|
999 | fclose(in); |
---|
1000 | |
---|
1001 | meta.type = ROAR_META_TYPE_NONE; |
---|
1002 | meta.value = NULL; |
---|
1003 | |
---|
1004 | return roar_stream_meta_set(con, &s, ROAR_META_MODE_FINALIZE, &meta); |
---|
1005 | } |
---|
1006 | |
---|
1007 | int show_meta_type (struct roar_connection * con, int id, const char * type) { |
---|
1008 | struct roar_meta meta; |
---|
1009 | struct roar_stream s; |
---|
1010 | |
---|
1011 | if ( roar_stream_new_by_id(&s, id) == -1 ) |
---|
1012 | return -1; |
---|
1013 | |
---|
1014 | meta.type = roar_meta_inttype(type); |
---|
1015 | |
---|
1016 | if ( meta.type == -1 ) { |
---|
1017 | fprintf(stderr, "Error: unknown type: %s\n", type); |
---|
1018 | return -1; |
---|
1019 | } |
---|
1020 | |
---|
1021 | if ( roar_stream_meta_get(con, &s, &meta) == -1 ) |
---|
1022 | return -1; |
---|
1023 | |
---|
1024 | printf("Meta %-17s: %s\n", roar_meta_strtype(meta.type), meta.value); |
---|
1025 | |
---|
1026 | roar_meta_free(&meta); |
---|
1027 | |
---|
1028 | return 0; |
---|
1029 | } |
---|
1030 | |
---|
1031 | int show_meta_all (struct roar_connection * con, int id) { |
---|
1032 | struct roar_stream s; |
---|
1033 | int types[ROAR_META_MAX_PER_STREAM]; |
---|
1034 | int i; |
---|
1035 | int len; |
---|
1036 | |
---|
1037 | if ( roar_stream_new_by_id(&s, id) == -1 ) |
---|
1038 | return -1; |
---|
1039 | |
---|
1040 | if ( (len = roar_stream_meta_list(con, &s, types, ROAR_META_MAX_PER_STREAM)) == -1 ) |
---|
1041 | return -1; |
---|
1042 | |
---|
1043 | for (i = 0; i < len; i++) |
---|
1044 | show_meta_type(con, id, roar_meta_strtype(types[i])); |
---|
1045 | |
---|
1046 | return 0; |
---|
1047 | } |
---|
1048 | |
---|
1049 | int save_meta (struct roar_connection * con, int id, char * file) { |
---|
1050 | struct roar_stream s; |
---|
1051 | struct roar_meta meta; |
---|
1052 | int types[ROAR_META_MAX_PER_STREAM]; |
---|
1053 | int i; |
---|
1054 | int len; |
---|
1055 | FILE * out; |
---|
1056 | |
---|
1057 | if ( roar_stream_new_by_id(&s, id) == -1 ) |
---|
1058 | return -1; |
---|
1059 | |
---|
1060 | if ( (len = roar_stream_meta_list(con, &s, types, ROAR_META_MAX_PER_STREAM)) == -1 ) |
---|
1061 | return -1; |
---|
1062 | |
---|
1063 | if ( (out = fopen(file, "w")) == NULL ) |
---|
1064 | return -1; |
---|
1065 | |
---|
1066 | for (i = 0; i < len; i++) { |
---|
1067 | /* |
---|
1068 | show_meta_type(con, id, roar_meta_strtype(types[i])); |
---|
1069 | */ |
---|
1070 | meta.type = types[i]; |
---|
1071 | |
---|
1072 | if ( roar_stream_meta_get(con, &s, &meta) == -1 ) |
---|
1073 | continue; |
---|
1074 | |
---|
1075 | // printf("Meta %-17s: %s\n", roar_meta_strtype(meta.type), meta.value); |
---|
1076 | |
---|
1077 | fprintf(out, "%s=%s\n", roar_meta_strtype(meta.type), meta.value); |
---|
1078 | |
---|
1079 | roar_meta_free(&meta); |
---|
1080 | } |
---|
1081 | |
---|
1082 | fclose(out); |
---|
1083 | |
---|
1084 | return 0; |
---|
1085 | } |
---|
1086 | |
---|
1087 | int set_flags (struct roar_connection * con, int id, int action, char * flags) { |
---|
1088 | uint32_t f = ROAR_FLAG_NONE; |
---|
1089 | char * c; |
---|
1090 | struct roar_stream s[1]; |
---|
1091 | |
---|
1092 | if ( roar_stream_new_by_id(s, id) == -1 ) |
---|
1093 | return -1; |
---|
1094 | |
---|
1095 | c = strtok(flags, ","); |
---|
1096 | while (c != NULL) { |
---|
1097 | if ( !strcmp(c, "meta") ) { |
---|
1098 | f |= ROAR_FLAG_META; |
---|
1099 | } else if ( !strcmp(c, "primary") ) { |
---|
1100 | f |= ROAR_FLAG_PRIMARY; |
---|
1101 | } else if ( !strcmp(c, "sync") ) { |
---|
1102 | f |= ROAR_FLAG_SYNC; |
---|
1103 | } else if ( !strcmp(c, "cleanmeta") ) { |
---|
1104 | f |= ROAR_FLAG_CLEANMETA; |
---|
1105 | } else if ( !strcmp(c, "hwmixer") ) { |
---|
1106 | f |= ROAR_FLAG_HWMIXER; |
---|
1107 | } else if ( !strcmp(c, "pause") ) { |
---|
1108 | f |= ROAR_FLAG_PAUSE; |
---|
1109 | } else if ( !strcmp(c, "mute") ) { |
---|
1110 | f |= ROAR_FLAG_MUTE; |
---|
1111 | } else if ( !strcmp(c, "mmap") ) { |
---|
1112 | f |= ROAR_FLAG_MMAP; |
---|
1113 | } else if ( !strcmp(c, "antiecho") ) { |
---|
1114 | f |= ROAR_FLAG_ANTIECHO; |
---|
1115 | } else if ( !strcmp(c, "recsource") ) { |
---|
1116 | f |= ROAR_FLAG_RECSOURCE; |
---|
1117 | } else if ( !strcmp(c, "passmixer") ) { |
---|
1118 | f |= ROAR_FLAG_PASSMIXER; |
---|
1119 | } else if ( !strcmp(c, "virtual") ) { |
---|
1120 | f |= ROAR_FLAG_VIRTUAL; |
---|
1121 | } else if ( !strcmp(c, "prethru") ) { |
---|
1122 | f |= ROAR_FLAG_PRETHRU; |
---|
1123 | } else if ( !strcmp(c, "immutable") ) { |
---|
1124 | f |= ROAR_FLAG_IMMUTABLE; |
---|
1125 | } else if ( !strcmp(c, "enhance") ) { |
---|
1126 | f |= ROAR_FLAG_ENHANCE; |
---|
1127 | } else if ( !strcmp(c, "singlesink") ) { |
---|
1128 | f |= ROAR_FLAG_SINGLESINK; |
---|
1129 | } else { |
---|
1130 | fprintf(stderr, "Error: unknown flag: %s\n", c); |
---|
1131 | return -1; |
---|
1132 | } |
---|
1133 | |
---|
1134 | c = strtok(NULL, ","); |
---|
1135 | } |
---|
1136 | |
---|
1137 | return roar_stream_set_flags(con, s, f, action); |
---|
1138 | } |
---|
1139 | |
---|
1140 | int set_role (struct roar_connection * con, int id, int role) { |
---|
1141 | struct roar_stream s; |
---|
1142 | |
---|
1143 | if ( id == -1 ) |
---|
1144 | return -1; |
---|
1145 | |
---|
1146 | if ( roar_stream_new_by_id(&s, id) == -1 ) |
---|
1147 | return -1; |
---|
1148 | |
---|
1149 | if ( roar_stream_set_role(con, &s, role) == -1 ) |
---|
1150 | return -1; |
---|
1151 | |
---|
1152 | return 0; |
---|
1153 | } |
---|
1154 | |
---|
1155 | int show_aiprofile (const char * profile) { |
---|
1156 | struct roar_audio_info info; |
---|
1157 | const char * mime; |
---|
1158 | |
---|
1159 | if ( roar_profile2info(&info, profile) == -1 ) { |
---|
1160 | fprintf(stderr, "Error: unknown profile: %s\n", profile); |
---|
1161 | return -1; |
---|
1162 | } |
---|
1163 | |
---|
1164 | mime = roar_codec2mime(info.codec); |
---|
1165 | |
---|
1166 | printf("Profile Name : %s\n", profile); |
---|
1167 | |
---|
1168 | if ( info.rate ) |
---|
1169 | printf("Profile sample rate : %i\n", info.rate); |
---|
1170 | if ( info.bits ) |
---|
1171 | printf("Profile bits : %i\n", info.bits); |
---|
1172 | if ( info.channels ) |
---|
1173 | printf("Profile channels : %i\n", info.channels); |
---|
1174 | |
---|
1175 | printf("Profile codec : %2i (%s%s%s%s)\n", info.codec, roar_codec2str(info.codec), |
---|
1176 | info.codec == ROAR_CODEC_DEFAULT ? " native" : "", |
---|
1177 | mime == NULL ? "" : " mimetype:", |
---|
1178 | mime == NULL ? "" : mime); |
---|
1179 | |
---|
1180 | return 0; |
---|
1181 | } |
---|
1182 | |
---|
1183 | int list_aiprofiles (void) { |
---|
1184 | const char * list[1024]; |
---|
1185 | ssize_t ret; |
---|
1186 | ssize_t i; |
---|
1187 | |
---|
1188 | ret = roar_profiles_list(list, 1024, 0); |
---|
1189 | |
---|
1190 | if ( ret == -1 ) { |
---|
1191 | fprintf(stderr, "Error: can not read list of profiles\n"); |
---|
1192 | return -1; |
---|
1193 | } |
---|
1194 | |
---|
1195 | for (i = 0; i < ret; i++) { |
---|
1196 | printf("profile %" LIBROAR__ll "i:\n", (LIBROAR__longlong signed int)i); |
---|
1197 | show_aiprofile(list[i]); |
---|
1198 | } |
---|
1199 | |
---|
1200 | return 0; |
---|
1201 | } |
---|
1202 | |
---|
1203 | int main (int argc, char * argv[]) { |
---|
1204 | struct roar_connection con; |
---|
1205 | const char * server = NULL; |
---|
1206 | const char * k = NULL; |
---|
1207 | int i; |
---|
1208 | int t = 0; |
---|
1209 | |
---|
1210 | for (i = 1; i < argc; i++) { |
---|
1211 | k = argv[i]; |
---|
1212 | |
---|
1213 | if ( strcmp(k, "--server") == 0 ) { |
---|
1214 | server = argv[++i]; |
---|
1215 | } else if ( strcmp(k, "-v") == 0 || strcmp(k, "--verbose") == 0 ) { |
---|
1216 | g_verbose++; |
---|
1217 | } else if ( strcmp(k, "--help") == 0 ) { |
---|
1218 | usage(); |
---|
1219 | return 0; |
---|
1220 | } else if ( strcmp(k, "--list-aiprofiles") == 0 ) { |
---|
1221 | list_aiprofiles(); |
---|
1222 | return 0; |
---|
1223 | } else if ( strcmp(k, "--list-libstandards") == 0 ) { |
---|
1224 | lib_standards(); |
---|
1225 | return 0; |
---|
1226 | } else if ( strcmp(k, "--enum-servers") == 0 ) { |
---|
1227 | enum_servers(); |
---|
1228 | return 0; |
---|
1229 | } else if ( strcmp(k, "--hash-password") == 0 ) { |
---|
1230 | hash_password(); |
---|
1231 | return 0; |
---|
1232 | } else if ( *k == '-' ) { |
---|
1233 | fprintf(stderr, "Error: unknown argument: %s\n", k); |
---|
1234 | usage(); |
---|
1235 | return 1; |
---|
1236 | } else { |
---|
1237 | break; |
---|
1238 | } |
---|
1239 | } |
---|
1240 | |
---|
1241 | // connect |
---|
1242 | |
---|
1243 | if ( roar_simple_connect(&con, server, "roarctl") == -1 ) { |
---|
1244 | fprintf(stderr, "Error: Can not connect to server: %s: %s(%i)\n", |
---|
1245 | server == NULL ? "(default)" : server, roar_vs_strerr(roar_error), roar_error); |
---|
1246 | return 1; |
---|
1247 | } |
---|
1248 | |
---|
1249 | if ( i == argc ) { |
---|
1250 | fprintf(stderr, "Error: No Commands given\n"); |
---|
1251 | return 0; // this is not a fatal error... |
---|
1252 | } |
---|
1253 | |
---|
1254 | for (; i < argc; i++) { |
---|
1255 | k = argv[i]; |
---|
1256 | // cmd is in k |
---|
1257 | |
---|
1258 | printf("--- [ %s ] ---\n", k); |
---|
1259 | |
---|
1260 | if ( !strcmp(k, "help") ) { |
---|
1261 | usage(); |
---|
1262 | |
---|
1263 | } else if ( !strcmp(k, "sleep") ) { |
---|
1264 | roar_sleep(atoi(argv[++i])); |
---|
1265 | |
---|
1266 | } else if ( !strcmp(k, "ping") ) { |
---|
1267 | #ifdef ROAR_HAVE_GETTIMEOFDAY |
---|
1268 | if ( ping(&con, atoi(argv[++i])) == -1 ) { |
---|
1269 | fprintf(stderr, "Error: can not ping\n"); |
---|
1270 | } |
---|
1271 | #else |
---|
1272 | fprintf(stderr, "Error: ping not supported.\n"); |
---|
1273 | i++; |
---|
1274 | #endif |
---|
1275 | } else if ( !strcmp(k, "servername") ) { |
---|
1276 | printf("Server Name : %s\n", roar_get_connection_server(&con)); |
---|
1277 | |
---|
1278 | } else if ( !strcmp(k, "standby") || !strcmp(k, "off") ) { |
---|
1279 | if ( roar_set_standby(&con, ROAR_STANDBY_ACTIVE) == -1 ) { |
---|
1280 | fprintf(stderr, "Error: can not set mode to standby\n"); |
---|
1281 | } else { |
---|
1282 | printf("going into standby\n"); |
---|
1283 | } |
---|
1284 | } else if ( !strcmp(k, "resume") || !strcmp(k, "on") ) { |
---|
1285 | if ( roar_set_standby(&con, ROAR_STANDBY_INACTIVE) == -1 ) { |
---|
1286 | fprintf(stderr, "Error: can not set mode to active\n"); |
---|
1287 | } else { |
---|
1288 | printf("going into active mode\n"); |
---|
1289 | } |
---|
1290 | |
---|
1291 | } else if ( !strcmp(k, "exit") ) { |
---|
1292 | if ( roar_terminate(&con, 0) == -1 ) { |
---|
1293 | fprintf(stderr, "Error: can not quit server\n"); |
---|
1294 | } else { |
---|
1295 | printf("Server quited\n"); |
---|
1296 | break; |
---|
1297 | } |
---|
1298 | } else if ( !strcmp(k, "terminate") ) { |
---|
1299 | if ( roar_terminate(&con, 1) == -1 ) { |
---|
1300 | fprintf(stderr, "Error: can not terminate server\n"); |
---|
1301 | } else { |
---|
1302 | printf("Server got asked to quited\n"); |
---|
1303 | break; |
---|
1304 | } |
---|
1305 | |
---|
1306 | } else if ( !strcmp(k, "standbymode") ) { |
---|
1307 | t = roar_get_standby(&con); |
---|
1308 | if ( t == -1 ) { |
---|
1309 | fprintf(stderr, "Error: can not get stanby mode\n"); |
---|
1310 | } else if ( t == ROAR_STANDBY_ACTIVE ) { |
---|
1311 | printf("Server is in standby\n"); |
---|
1312 | } else if ( t == ROAR_STANDBY_INACTIVE ) { |
---|
1313 | printf("Server is active\n"); |
---|
1314 | } else { |
---|
1315 | fprintf(stderr, "Error: unknown standby mode: %i\n", t); |
---|
1316 | } |
---|
1317 | |
---|
1318 | } else if ( !strcmp(k, "whoami") ) { |
---|
1319 | printf("My client ID is: %i\n", roar_get_clientid(&con)); |
---|
1320 | } else if ( !strcmp(k, "beep") ) { |
---|
1321 | roar_beep(&con, NULL); |
---|
1322 | } else if ( !strcmp(k, "serverinfo") ) { |
---|
1323 | server_info(&con); |
---|
1324 | } else if ( !strcmp(k, "libinfo") ) { |
---|
1325 | server_info(NULL); |
---|
1326 | } else if ( !strcmp(k, "servertime") ) { |
---|
1327 | server_time(&con); |
---|
1328 | } else if ( !strcmp(k, "serveroinfo") ) { |
---|
1329 | server_oinfo(&con, -1); |
---|
1330 | } else if ( !strcmp(k, "serveroinfo2") ) { |
---|
1331 | t = roar_str2dir(argv[++i]); |
---|
1332 | if ( t == -1 ) { |
---|
1333 | fprintf(stderr, "Error: unknown stream direction: %s\n", argv[i]); |
---|
1334 | } else { |
---|
1335 | server_oinfo(&con, t); |
---|
1336 | } |
---|
1337 | } else if ( !strcmp(k, "serverstandards") ) { |
---|
1338 | server_standards(&con); |
---|
1339 | } else if ( !strcmp(k, "libstandards") ) { |
---|
1340 | lib_standards(); |
---|
1341 | } else if ( !strcmp(k, "listclients") ) { |
---|
1342 | list_clients(&con); |
---|
1343 | } else if ( !strcmp(k, "clientinfo") ) { |
---|
1344 | display_client(&con, atoi(argv[++i])); |
---|
1345 | } else if ( !strcmp(k, "liststreams") ) { |
---|
1346 | list_streams(&con); |
---|
1347 | } else if ( !strcmp(k, "streaminfo") ) { |
---|
1348 | display_stream(&con, atoi(argv[++i])); |
---|
1349 | } else if ( !strcmp(k, "allinfo") ) { |
---|
1350 | server_info(&con); |
---|
1351 | printf("\n"); |
---|
1352 | server_time(&con); |
---|
1353 | printf("\n"); |
---|
1354 | server_standards(&con); |
---|
1355 | printf("\n"); |
---|
1356 | server_oinfo(&con, -1); |
---|
1357 | printf("\n"); |
---|
1358 | list_clients(&con); |
---|
1359 | printf("\n"); |
---|
1360 | list_streams(&con); |
---|
1361 | |
---|
1362 | } else if ( !strcmp(k, "kick") ) { |
---|
1363 | t = roar_str2ot((k = argv[++i])); |
---|
1364 | if ( t == -1 ) { |
---|
1365 | fprintf(stderr, "Error: unknown type: %s\n", k); |
---|
1366 | continue; |
---|
1367 | } |
---|
1368 | //t = atoi(argv[i++]); |
---|
1369 | if ( roar_kick(&con, t, atoi(argv[++i])) == -1 ) { |
---|
1370 | fprintf(stderr, "Error: can not kick %s\n", k); |
---|
1371 | } else { |
---|
1372 | printf("%s kicked\n", k); |
---|
1373 | } |
---|
1374 | |
---|
1375 | } else if ( !strcmp(k, "newvirtual") ) { |
---|
1376 | if ( newvirtual(&con, argv[i+1], argv[i+2], argv[i+3], argv[i+4], argv[i+5], argv[i+6]) == -1 ) { |
---|
1377 | fprintf(stderr, "Error: can not create new virtual stream\n"); |
---|
1378 | } else { |
---|
1379 | printf("virtual stream created\n"); |
---|
1380 | } |
---|
1381 | i += 6; |
---|
1382 | |
---|
1383 | } else if ( !strcmp(k, "volume") ) { |
---|
1384 | if ( set_mixer(&con, &i, argc, argv) == -1 ) { |
---|
1385 | fprintf(stderr, "Error: can not set volume\n"); |
---|
1386 | } else { |
---|
1387 | printf("volume changed\n"); |
---|
1388 | } |
---|
1389 | |
---|
1390 | } else if ( !strcmp(k, "flag") ) { |
---|
1391 | i++; |
---|
1392 | if ( set_flags(&con, atoi(argv[i]), ROAR_SET_FLAG, argv[i+1]) == -1 ) { |
---|
1393 | fprintf(stderr, "Error: can not set flags\n"); |
---|
1394 | } else { |
---|
1395 | printf("flags changed\n"); |
---|
1396 | } |
---|
1397 | i++; |
---|
1398 | } else if ( !strcmp(k, "unflag") ) { |
---|
1399 | i++; |
---|
1400 | if ( set_flags(&con, atoi(argv[i]), ROAR_RESET_FLAG, argv[i+1]) == -1 ) { |
---|
1401 | fprintf(stderr, "Error: can not reset flags\n"); |
---|
1402 | } else { |
---|
1403 | printf("flags changed\n"); |
---|
1404 | } |
---|
1405 | i++; |
---|
1406 | } else if ( !strcmp(k, "toggleflag") ) { |
---|
1407 | i++; |
---|
1408 | if ( set_flags(&con, atoi(argv[i]), ROAR_TOGGLE_FLAG, argv[i+1]) == -1 ) { |
---|
1409 | fprintf(stderr, "Error: can not toggle flags\n"); |
---|
1410 | } else { |
---|
1411 | printf("flags changed\n"); |
---|
1412 | } |
---|
1413 | i++; |
---|
1414 | } else if ( !strcmp(k, "protectflag") ) { |
---|
1415 | i++; |
---|
1416 | if ( set_flags(&con, atoi(argv[i]), ROAR_NOOP_FLAG|ROAR_PROTECT_FLAG, argv[i+1]) == -1 ) { |
---|
1417 | fprintf(stderr, "Error: can not protect flags\n"); |
---|
1418 | } else { |
---|
1419 | printf("flags protected\n"); |
---|
1420 | } |
---|
1421 | i++; |
---|
1422 | |
---|
1423 | } else if ( !strcmp(k, "role") ) { |
---|
1424 | i++; |
---|
1425 | if ( set_role(&con, atoi(argv[i]), roar_str2role(argv[i+1])) == -1 ) { |
---|
1426 | fprintf(stderr, "Error: can not set stream role\n"); |
---|
1427 | } else { |
---|
1428 | printf("stream role set\n"); |
---|
1429 | } |
---|
1430 | i++; |
---|
1431 | |
---|
1432 | } else if ( !strcmp(k, "metaset") ) { |
---|
1433 | i++; |
---|
1434 | if ( set_meta(&con, atoi(argv[i]), argv[i+1], argv[i+2], argv[i+3]) == -1 ) { |
---|
1435 | fprintf(stderr, "Error: can not set meta data\n"); |
---|
1436 | } else { |
---|
1437 | printf("meta data changed\n"); |
---|
1438 | } |
---|
1439 | i += 3; |
---|
1440 | } else if ( !strcmp(k, "metaget") ) { |
---|
1441 | i++; |
---|
1442 | if ( show_meta_type(&con, atoi(argv[i]), argv[i+1]) == -1 ) { |
---|
1443 | fprintf(stderr, "Error: can not get meta data\n"); |
---|
1444 | } |
---|
1445 | i++; |
---|
1446 | } else if ( !strcmp(k, "metasave") ) { |
---|
1447 | i++; |
---|
1448 | if ( save_meta(&con, atoi(argv[i]), argv[i+1]) == -1 ) { |
---|
1449 | fprintf(stderr, "Error: can not get meta data\n"); |
---|
1450 | } else { |
---|
1451 | printf("meta data saved\n"); |
---|
1452 | } |
---|
1453 | i++; |
---|
1454 | } else if ( !strcmp(k, "metaload") ) { |
---|
1455 | i++; |
---|
1456 | if ( load_meta(&con, atoi(argv[i]), argv[i+1]) == -1 ) { |
---|
1457 | fprintf(stderr, "Error: can not set meta data\n"); |
---|
1458 | } else { |
---|
1459 | printf("meta data saved\n"); |
---|
1460 | } |
---|
1461 | i++; |
---|
1462 | |
---|
1463 | |
---|
1464 | } else if ( !strcmp(k, "listaiprofiles") || !strcmp(k, "listprofiles") ) { |
---|
1465 | if ( list_aiprofiles() == -1 ) { |
---|
1466 | fprintf(stderr, "Error: can not list profiles\n"); |
---|
1467 | } |
---|
1468 | } else if ( !strcmp(k, "aiprofileget") || !strcmp(k, "profileget") ) { |
---|
1469 | i++; |
---|
1470 | if ( show_aiprofile(argv[i]) == -1 ) { |
---|
1471 | fprintf(stderr, "Error: can not get profile data\n"); |
---|
1472 | } |
---|
1473 | } else { |
---|
1474 | fprintf(stderr, "Error: invalid command: %s\n", k); |
---|
1475 | } |
---|
1476 | |
---|
1477 | } |
---|
1478 | |
---|
1479 | roar_disconnect(&con); |
---|
1480 | |
---|
1481 | return 0; |
---|
1482 | } |
---|
1483 | |
---|
1484 | //ll |
---|