source: roaraudio/roarclients/roarctl.c @ 1810:b58f4673a31f

Last change on this file since 1810:b58f4673a31f was 1810:b58f4673a31f, checked in by phi, 15 years ago

do not print ch/bits/rate on light streams

File size: 21.6 KB
Line 
1//roarctl.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008
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, 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 */
24
25#include <roaraudio.h>
26
27#if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_SETUID)
28#define _POSIX_USERS
29#endif
30
31#ifdef _POSIX_USERS
32#include <pwd.h>
33#include <grp.h>
34#endif
35
36#include <sys/time.h>
37#include <time.h>
38
39int g_verbose = 0;
40
41int display_mixer (struct roar_connection * con, int stream);
42int show_meta_all (struct roar_connection * con, int id);
43
44void usage (void) {
45 printf("roarctl [OPTIONS]... COMMAND [OPTS] [COMMAND [OPTS] [COMMAND [OPTS] [...]]]\n");
46
47 printf("\nOptions:\n\n");
48
49 printf("  --server SERVER         - Set server hostname\n"
50        "  --help                  - Show this help\n"
51        "  --verbose   -v          - Show verbose output\n"
52       );
53
54 printf("\nCommands:\n\n");
55 printf(
56        "  help                    - Show this help\n"
57        "  sleep TIME              - Sleeps for TIME seconds\n"
58#ifdef ROAR_HAVE_GETTIMEOFDAY
59        "  ping  NUM               - Do NUM pings using NOOP commands\n"
60#endif
61        "\n"
62        "  standby, off            - Go into standby mode\n"
63        "  resume, on              - Go into active mode\n"
64        "  standbymode             - Show current standby mode\n"
65        "  exit                    - Quits the roard (must be used as last command)\n"
66        "  terminate               - Like exit but let the server up to serve still connected clients,\n"
67        "                            new clients cann't connect and the server terminates after the last\n"
68        "                            client disconnected\n"
69        "\n"
70        "  volume ID CHAN V0 V1... - Sets volume for stream ID\n"
71        "                            CHAN is the number of channels or 'mono' or 'stereo'\n"
72        "                            if mono or stereo is chosen roarctl trys to set\n"
73        "                            sensfull values for all channels even if the output\n"
74        "                            is has more channels.\n"
75        "                            all other args are the volumes of the channels\n"
76        "                            you may use integer or percent values.\n"
77        "                            percent values can flooding points.\n"
78        "\n"
79        "  flag   ID FLAGS         - Sets flags FLAGS on stream ID. FLAGS may be a comma\n"
80        "                            seperated list of flags.\n"
81        "  unflag ID FLAGS         - Unsets flags on a stream. See flag.\n"
82        "\n"
83        "  kick TYPE ID            - Kicks object of TYPE with id ID\n"
84        "                            Types: client stream sample source\n"
85        "\n"
86        "  metasave ID FILE        - Saves meta data of stream ID to file FILE\n"
87        "  metaload ID FILE        - Loads meta data from file FILE and set it on stream ID\n"
88        "\n"
89        "  serveroinfo             - Gets Informations about server output\n"
90        "  listclients             - Gets Informations about clients\n"
91        "  liststreams             - Gets Informations about streams\n"
92        "  allinfo                 - Get all infos\n"
93       );
94}
95
96#ifdef ROAR_HAVE_GETTIMEOFDAY
97int ping (struct roar_connection * con, int num) {
98 struct timeval         try, ans;
99 struct roar_message    m;
100 register int           ret;
101 int                    i;
102 double                 cur, min = 3600*1000, max = 0, sum = 0;
103
104 if ( num == 0 )
105  return 0;
106
107 for (i = 0; i < num; i++) {
108  m.cmd = ROAR_CMD_NOOP;
109  m.datalen = 0;
110
111  gettimeofday(&try, NULL);
112  ret = roar_req(con, &m, NULL);
113  gettimeofday(&ans, NULL);
114
115  if ( ret == -1 )
116   return -1;
117
118  while (ans.tv_sec > try.tv_sec) {
119   ans.tv_sec--;
120   ans.tv_usec += 1000000;
121  }
122  ans.tv_usec -= try.tv_usec;
123
124  printf("Pong from server: seq=%i time=%.3fms\n", i, (cur = ans.tv_usec/1000.0));
125
126  sum += cur;
127  if ( min > cur )
128   min = cur;
129  if ( cur > max )
130   max = cur;
131
132  if ( i != (num - 1) )
133   sleep(1);
134 }
135
136 printf("\n--- ping statistics ---\n");
137 printf("%i packets transmitted\n", i);
138 printf("rtt min/avg/max = %.3f/%.3f/%.3f ms\n", min, sum/(double)i, max);
139
140 return 0;
141}
142#endif
143
144void server_oinfo (struct roar_connection * con) {
145 struct roar_stream s;
146
147 if ( roar_server_oinfo(con, &s) == -1 ) {
148  fprintf(stderr, "Error: can not get server output info\n");
149  return;
150 }
151
152 printf("Stream direction      : %s\n", roar_dir2str(s.dir));
153 printf("Server Output rate    : %i\n", s.info.rate);
154 printf("Server Output bits    : %i\n", s.info.bits);
155 printf("Server Output channels: %i\n", s.info.channels);
156 printf("Server Output codec   : %i (%s%s)\n", s.info.codec, roar_codec2str(s.info.codec),
157                                     s.info.codec == ROAR_CODEC_DEFAULT ? " native" : "");
158// printf("Server Output rate: %i", s.info.rate);
159  if ( g_verbose > 1 )
160   printf("Server Position       : %lu S (%.3fs)\n", (unsigned long int) s.pos, (float)s.pos/(s.info.rate*s.info.channels));
161}
162
163const char * proc_name (pid_t pid) {
164 static char ret[80] = "?";
165#ifdef __linux__
166 char file[80], buf[80], *r;
167 int  i;
168
169 snprintf(file, 79, "/proc/%i/exe", pid);
170 file[79] = 0;
171
172 ret[0] = '?';
173 ret[1] = 0;
174
175 if ( (i = readlink(file, buf, 79)) != -1 ) {
176  buf[i] = 0;
177  if ( (r = strrchr(buf, '/')) != NULL ) {
178   r++;
179   if ( *r != 0 )
180    strcpy(ret, r);
181  }
182 }
183#endif
184
185 return ret;
186}
187
188void list_clients (struct roar_connection * con) {
189 int i;
190 int num;
191 int h;
192 int id[ROAR_CLIENTS_MAX];
193 struct roar_client c;
194#ifdef _POSIX_USERS
195 struct group  * grp = NULL;
196 struct passwd * pwd = NULL;
197#endif
198
199 if ( (num = roar_list_clients(con, id, ROAR_CLIENTS_MAX)) == -1 ) {
200  fprintf(stderr, "Error: can not get client list\n");
201  return;
202 }
203
204 for (i = 0; i < num; i++) {
205  printf("client %i:\n", id[i]);
206  if ( roar_get_client(con, &c, id[i]) == -1 ) {
207   fprintf(stderr, "Error: can not get client info\n");
208   continue;
209  }
210  printf("Player name           : %s\n", c.name);
211  printf("Player PID            : %i(%s)\n", c.pid, proc_name(c.pid));
212  if ( c.uid != -1 ) {
213#ifdef _POSIX_USERS
214   pwd = getpwuid(c.uid);
215   grp = getgrgid(c.gid);
216   printf("Player UID/GID        : %i(%s)/%i(%s)\n", c.uid, pwd ? pwd->pw_name : "?", c.gid, grp ? grp->gr_name : "?");
217#else
218   printf("Player UID/GID        : %i/%i\n", c.uid, c.gid);
219#endif
220  }
221  if ( c.execed != -1 )
222   printf("Execed stream         : %i\n", c.execed);
223
224  for (h = 0; h < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; h++)
225   if ( c.streams[h] != -1 )
226    printf("stream                : %i\n", c.streams[h]);
227 }
228
229}
230
231void list_streams (struct roar_connection * con) {
232 int i;
233 int num;
234 int id[ROAR_STREAMS_MAX];
235 struct roar_stream s;
236 struct roar_stream_info info;
237 char flags[1024];
238
239
240 if ( (num = roar_list_streams(con, id, ROAR_STREAMS_MAX)) == -1 ) {
241  fprintf(stderr, "Error: can not get stream list\n");
242  return;
243 }
244
245 for (i = 0; i < num; i++) {
246  printf("stream %i:\n", id[i]);
247  if ( roar_get_stream(con, &s, id[i]) == -1 ) {
248   fprintf(stderr, "Error: can not get stream info\n");
249   continue;
250  }
251  printf("Stream direction      : %s\n", roar_dir2str(s.dir));
252  if ( s.pos_rel_id == -1 ) {
253   printf("Relativ position id   : none (stream not synchronized)\n");
254  } else if ( s.pos_rel_id == id[i] ) {
255   printf("Relativ position id   : %i (self synchronized)\n", s.pos_rel_id);
256  } else {
257   printf("Relativ position id   : %i (synchronized)\n", s.pos_rel_id);
258  }
259  if ( g_verbose > 1 )
260   printf("Position              : %lu S (%.3fs)\n", (unsigned long int) s.pos, (float)s.pos/(s.info.rate*s.info.channels));
261
262  if ( s.dir != ROAR_DIR_LIGHT_IN && s.dir != ROAR_DIR_LIGHT_OUT ) {
263   printf("Input rate            : %i\n", s.info.rate);
264   printf("Input bits            : %i\n", s.info.bits);
265   printf("Input channels        : %i\n", s.info.channels);
266  }
267
268  printf("Input codec           : %2i (%s%s)\n", s.info.codec, roar_codec2str(s.info.codec),
269                                       s.info.codec == ROAR_CODEC_DEFAULT ? " native" : "");
270  if ( roar_stream_get_info(con, &s, &info) != -1 ) {
271   printf("Input codec (streamed): %2i (%s%s)\n", info.codec, roar_codec2str(info.codec),
272                                      info.codec == ROAR_CODEC_DEFAULT ? " native" : "");
273   if ( g_verbose ) {
274    printf("Input block size      : %i Byte\n", info.block_size);
275    printf("Underruns pre/post    : %i/%i\n",   info.pre_underruns, info.post_underruns);
276    if ( g_verbose > 1 )
277     printf("Stream delay          : %ims\n",   (int)info.delay/1000);
278
279    *flags = 0;
280    if ( info.flags & ROAR_FLAG_PRIMARY )
281     strcat(flags, "primary ");
282    if ( info.flags & ROAR_FLAG_SYNC )
283     strcat(flags, "sync ");
284    if ( info.flags & ROAR_FLAG_OUTPUT )
285     strcat(flags, "output ");
286    if ( info.flags & ROAR_FLAG_SOURCE )
287     strcat(flags, "source ");
288    if ( info.flags & ROAR_FLAG_META )
289     strcat(flags, "meta ");
290    if ( info.flags & ROAR_FLAG_AUTOCONF )
291     strcat(flags, "autoconf ");
292    if ( info.flags & ROAR_FLAG_CLEANMETA )
293     strcat(flags, "cleanmeta ");
294    if ( info.flags & ROAR_FLAG_HWMIXER )
295     strcat(flags, "hwmixer ");
296    if ( info.flags & ROAR_FLAG_PAUSE )
297     strcat(flags, "pause ");
298
299    printf("Flags                 : %s\n", flags);
300   }
301  }
302  display_mixer(con, id[i]);
303  show_meta_all(con, id[i]);
304 }
305
306}
307
308int display_mixer (struct roar_connection * con, int stream) {
309 int channels;
310 struct roar_mixer_settings mixer;
311 int i;
312
313 if ( roar_get_vol(con, stream, &mixer, &channels) == -1 ) {
314  fprintf(stderr, "Error: can not get stream mixer info\n");
315  return -1;
316 }
317
318 for (i = 0; i < channels; i++)
319  printf("Mixer volume chan %2i  : %i (%.2f%%)\n", i, mixer.mixer[i], (float)mixer.mixer[i]/655.35);
320
321 return 0;
322}
323
324int set_mixer (struct roar_connection * con, int * cur, int max, char * arg[]) {
325 int chans = 0;
326 int id;
327 int i;
328 int len;
329 int old_chans;
330 int vol_l, vol_r;
331 char * k;
332 struct roar_mixer_settings mixer;
333 struct roar_mixer_settings old_mixer;
334
335 if (*cur + 2 > max)
336  return -1;
337
338 id = atoi(arg[++(*cur)]);
339
340 k = arg[++(*cur)];
341
342 if ( roar_get_vol(con, id, &old_mixer, &old_chans) == -1 ) {
343  fprintf(stderr, "Error: can not get stream mixer info\n");
344  return -1;
345 }
346
347
348// TODO: clean up code here as the % vs. abs code is very duplicate...
349
350 if ( strcmp(k, "mono") == 0 && old_chans != 1 ) {
351  chans = 1;
352
353  if ( *cur + 1 > max )
354   return -1;
355
356  k   = arg[++(*cur)];
357  len = strlen(k);
358
359  if ( k[len - 1] == '%' ) {
360   k[len - 1] = 0;
361   vol_l = (atof(k)*65535)/100;
362  } else {
363   vol_l = atoi(k);
364  }
365
366  for (i = 0; i < old_chans; i++)
367   mixer.mixer[i] = vol_l;
368
369  chans = old_chans;
370
371 } else if ( strcmp(k, "stereo") == 0 && old_chans == 4 ) {
372  chans = 4;
373
374  if ( *cur + 2 > max )
375   return -1;
376
377  k   = arg[++(*cur)];
378  len = strlen(k);
379
380  if ( k[len - 1] == '%' ) {
381   k[len - 1] = 0;
382   vol_l = (atof(k)*65535)/100;
383  } else {
384   vol_l = atoi(k);
385  }
386
387  k   = arg[++(*cur)];
388  len = strlen(k);
389
390  if ( k[len - 1] == '%' ) {
391   k[len - 1] = 0;
392   vol_r = (atof(k)*65535)/100;
393  } else {
394   vol_r = atoi(k);
395  }
396
397  mixer.mixer[0] = vol_l;
398  mixer.mixer[1] = vol_r;
399  mixer.mixer[2] = vol_l;
400  mixer.mixer[3] = vol_r;
401
402 } else if ( strcmp(k, "stereo") == 0 && old_chans != 2 ) {
403  chans = 2;
404//  printf("mode: stereo; chans=%i, old_chans=%i\n", chans, old_chans);
405  ROAR_ERR("mode stereo not supported");
406  return -1;
407 } else {
408  if ( strcmp(k, "mono") == 0 ) {
409   chans = 1;
410  } else if ( strcmp(k, "stereo") == 0 ) {
411   chans = 2;
412  } else {
413   chans = atoi(k);
414  }
415
416//  printf("mode: int; chans=%i, old_chans=%i\n", chans, old_chans);
417
418  if ( *cur + chans > max )
419   return -1;
420
421  for (i = 0; i < chans; i++) {
422   k   = arg[++(*cur)];
423   len = strlen(k);
424
425   if ( k[len - 1] == '%' ) {
426    k[len - 1] = 0;
427    mixer.mixer[i] = (atof(k)*(int)65535)/100;
428   } else {
429    mixer.mixer[i] = atoi(k);
430   }
431  }
432 }
433
434 mixer.scale = 65535;
435
436 return roar_set_vol(con, id, &mixer, chans);
437}
438
439int set_meta (struct roar_connection * con, int id, char * mode, char * type, char * val) {
440 struct roar_meta   meta;
441 struct roar_stream s;
442 int mode_i = ROAR_META_MODE_SET;
443
444 memset(&s, 0, sizeof(s));
445
446 s.id = id;
447
448// printf("set_meta(*): mode='%s', type='%s', val='%s'\n", mode, type, val);
449
450 if ( strcmp(mode, "add") == 0 ) {
451  mode_i = ROAR_META_MODE_ADD;
452 }
453
454 meta.type   = roar_meta_inttype(type);
455 meta.value  = val;
456 meta.key[0] = 0;
457
458 if ( meta.type == -1 ) {
459  fprintf(stderr, "Error: unknown type: %s\n", type);
460  return -1;
461 }
462
463// printf("D: type=%i, mode=%i\n", meta.type, mode_i);
464
465 if ( roar_stream_meta_set(con, &s, mode_i, &meta) == -1 )
466  return -1;
467
468 meta.type  = ROAR_META_TYPE_NONE;
469 meta.value = NULL;
470
471 return roar_stream_meta_set(con, &s, ROAR_META_MODE_FINALIZE, &meta);
472}
473
474int load_meta (struct roar_connection * con, int id, char * file) {
475 struct roar_meta   meta;
476 struct roar_stream s;
477 int mode_i = ROAR_META_MODE_SET;
478 FILE * in;
479 char lion[1024];
480 char * v;
481
482 memset(&s, 0, sizeof(s));
483
484 s.id = id;
485
486 if ( (in = fopen(file, "r")) == NULL )
487  return -1;
488
489 while (fgets(lion, 1024, in) != NULL) {
490  if ( (v = strtok(lion, "\r\n")) != NULL )
491   if ( (v = strtok(NULL, "\r\n")) != NULL )
492    *(v-1) = 0;
493
494  if ( (v = strstr(lion, "=")) == NULL ) {
495   fprintf(stderr, "Error: can not parse meta data lion: %s\n", lion);
496   continue;
497  }
498
499  *v++ = 0;
500
501  meta.type   = roar_meta_inttype(lion);
502  meta.value  = v;
503  meta.key[0] = 0;
504
505  if ( meta.type == -1 ) {
506   fprintf(stderr, "Error: unknown type: %s\n", lion);
507   continue;
508  }
509
510  if ( roar_stream_meta_set(con, &s, mode_i, &meta) == -1 )
511   return -1;
512 }
513
514 fclose(in);
515
516 meta.type  = ROAR_META_TYPE_NONE;
517 meta.value = NULL;
518
519 return roar_stream_meta_set(con, &s, ROAR_META_MODE_FINALIZE, &meta);
520}
521
522int show_meta_type (struct roar_connection * con, int id, char * type) {
523 struct roar_meta   meta;
524 struct roar_stream s;
525
526 memset(&s, 0, sizeof(s));
527
528 s.id = id;
529
530 meta.type  = roar_meta_inttype(type);
531
532 if ( meta.type == -1 ) {
533  fprintf(stderr, "Error: unknown type: %s\n", type);
534  return -1;
535 }
536
537 if ( roar_stream_meta_get(con, &s, &meta) == -1 )
538  return -1;
539
540 printf("Meta %-17s: %s\n", roar_meta_strtype(meta.type), meta.value);
541
542 roar_meta_free(&meta);
543
544 return 0;
545}
546
547int show_meta_all (struct roar_connection * con, int id) {
548 struct roar_stream s;
549 int types[ROAR_META_MAX_PER_STREAM];
550 int i;
551 int len;
552
553 memset(&s, 0, sizeof(s));
554
555 s.id = id;
556
557 if ( (len = roar_stream_meta_list(con, &s, types, ROAR_META_MAX_PER_STREAM)) == -1 )
558  return -1;
559
560 for (i = 0; i < len; i++)
561  show_meta_type(con, id, roar_meta_strtype(types[i]));
562
563 return 0;
564}
565
566int save_meta (struct roar_connection * con, int id, char * file) {
567 struct roar_stream s;
568 struct roar_meta   meta;
569 int types[ROAR_META_MAX_PER_STREAM];
570 int i;
571 int len;
572 FILE * out;
573
574 memset(&s, 0, sizeof(s));
575
576 s.id = id;
577
578 if ( (out = fopen(file, "w")) == NULL )
579  return -1;
580
581 if ( (len = roar_stream_meta_list(con, &s, types, ROAR_META_MAX_PER_STREAM)) == -1 )
582  return -1;
583
584 for (i = 0; i < len; i++) {
585/*
586  show_meta_type(con, id, roar_meta_strtype(types[i]));
587*/
588  meta.type  = types[i];
589
590  if ( roar_stream_meta_get(con, &s, &meta) == -1 )
591   continue;
592
593//  printf("Meta %-17s: %s\n", roar_meta_strtype(meta.type), meta.value);
594
595  fprintf(out, "%s=%s\n", roar_meta_strtype(meta.type), meta.value);
596
597  roar_meta_free(&meta);
598 }
599
600 fclose(out);
601
602 return 0;
603}
604
605int set_flags (struct roar_connection * con, int id, int reset, char * flags) {
606 int f = ROAR_FLAG_NONE;
607 char * c;
608 struct roar_stream s[1];
609
610 memset(s, 0, sizeof(struct roar_stream));
611
612 s->id = id;
613
614 c = strtok(flags, ",");
615 while (c != NULL) {
616  if ( !strcmp(c, "meta") ) {
617   f |= ROAR_FLAG_META;
618  } else if ( !strcmp(c, "primary") ) {
619   f |= ROAR_FLAG_PRIMARY;
620  } else if ( !strcmp(c, "sync") ) {
621   f |= ROAR_FLAG_SYNC;
622  } else if ( !strcmp(c, "cleanmeta") ) {
623   f |= ROAR_FLAG_CLEANMETA;
624  } else if ( !strcmp(c, "hwmixer") ) {
625   f |= ROAR_FLAG_HWMIXER;
626  } else if ( !strcmp(c, "pause") ) {
627   f |= ROAR_FLAG_PAUSE;
628  } else {
629   fprintf(stderr, "Error: unknown flag: %s\n", c);
630   return -1;
631  }
632
633  c = strtok(NULL, ",");
634 }
635
636 return roar_stream_set_flags(con, s, f, reset);
637}
638
639int main (int argc, char * argv[]) {
640 struct roar_connection con;
641 char * server   = NULL;
642 char * k = NULL;
643 int    i;
644 int    t = 0;
645
646 for (i = 1; i < argc; i++) {
647  k = argv[i];
648
649  if ( strcmp(k, "--server") == 0 ) {
650   server = argv[++i];
651  } else if ( strcmp(k, "-v") == 0 || strcmp(k, "--verbose") == 0 ) {
652   g_verbose++;
653  } else if ( strcmp(k, "--help") == 0 ) {
654   usage();
655   return 0;
656  } else if ( *k == '-' ) {
657   fprintf(stderr, "Error: unknown argument: %s\n", k);
658   usage();
659   return 1;
660  } else {
661   break;
662  }
663 }
664
665 // connect
666
667 if ( roar_connect(&con, server) == -1 ) {
668  fprintf(stderr, "Error: Can not connect to server\n");
669  return 1;
670 }
671
672 if ( roar_identify(&con, "roarctl") == -1 ) {
673  fprintf(stderr, "Error: Can not identify to server\n");
674  return 1;
675 }
676
677 if ( i == argc ) {
678  fprintf(stderr, "Error: No Commands given\n");
679  return 0; // this is not a fatal error...
680 }
681
682 for (; i < argc; i++) {
683  k = argv[i];
684  // cmd is in k
685
686  printf("--- [ %s ] ---\n", k);
687
688  if ( !strcmp(k, "help") ) {
689   usage();
690
691  } else if ( !strcmp(k, "sleep") ) {
692   sleep(atoi(argv[++i]));
693
694  } else if ( !strcmp(k, "ping") ) {
695#ifdef ROAR_HAVE_GETTIMEOFDAY
696   if ( ping(&con, atoi(argv[++i])) == -1 ) {
697    fprintf(stderr, "Error: can not ping\n");
698   }
699#else
700    fprintf(stderr, "Error: ping not supported.\n");
701    i++;
702#endif
703
704  } else if ( !strcmp(k, "standby") || !strcmp(k, "off") ) {
705   if ( roar_set_standby(&con, ROAR_STANDBY_ACTIVE) == -1 ) {
706    fprintf(stderr, "Error: can not set mode to standby\n");
707   } else {
708    printf("going into standby\n");
709   }
710  } else if ( !strcmp(k, "resume") || !strcmp(k, "on") ) {
711   if ( roar_set_standby(&con, ROAR_STANDBY_INACTIVE) == -1 ) {
712    fprintf(stderr, "Error: can not set mode to active\n");
713   } else {
714    printf("going into active mode\n");
715   }
716
717  } else if ( !strcmp(k, "exit") ) {
718   if ( roar_exit(&con) == -1 ) {
719    fprintf(stderr, "Error: can not quit server\n");
720   } else {
721    printf("Server quited\n");
722    break;
723   }
724  } else if ( !strcmp(k, "terminate") ) {
725   if ( roar_terminate(&con, 1) == -1 ) {
726    fprintf(stderr, "Error: can not terminate server\n");
727   } else {
728    printf("Server got asked to quited\n");
729    break;
730   }
731
732  } else if ( !strcmp(k, "standbymode") ) {
733   t = roar_get_standby(&con);
734   if ( t == -1 ) {
735    fprintf(stderr, "Error: can not get stanby mode\n");
736   } else if ( t == ROAR_STANDBY_ACTIVE ) {
737    printf("Server is in standby\n");
738   } else if ( t == ROAR_STANDBY_INACTIVE ) {
739    printf("Server is active\n");
740   } else {
741    fprintf(stderr, "Error: unknown standby mode: %i\n", t);
742   }
743
744  } else if ( !strcmp(k, "whoami") ) {
745   printf("My client ID is: %i\n", roar_get_clientid(&con));
746  } else if ( !strcmp(k, "serveroinfo") ) {
747   server_oinfo(&con);
748  } else if ( !strcmp(k, "listclients") ) {
749   list_clients(&con);
750  } else if ( !strcmp(k, "liststreams") ) {
751   list_streams(&con);
752  } else if ( !strcmp(k, "allinfo") ) {
753   server_oinfo(&con);
754   printf("\n");
755   list_clients(&con);
756   printf("\n");
757   list_streams(&con);
758
759  } else if ( !strcmp(k, "kick") ) {
760   k = argv[++i];
761   if ( !strcmp(k, "client") ) {
762    t = ROAR_OT_CLIENT;
763   } else if ( !strcmp(k, "stream") ) {
764    t = ROAR_OT_STREAM;
765   } else if ( !strcmp(k, "sample") ) {
766    t = ROAR_OT_SAMPLE;
767   } else if ( !strcmp(k, "source") ) {
768    t = ROAR_OT_SOURCE;
769   } else {
770    fprintf(stderr, "Error: unknown type: %s\n", k);
771    continue;
772   }
773   //t = atoi(argv[i++]);
774   if ( roar_kick(&con, t, atoi(argv[++i])) == -1 ) {
775    fprintf(stderr, "Error: can not kick %s\n", k);
776   } else {
777    printf("%s kicked\n", k);
778   }
779
780  } else if ( !strcmp(k, "volume") ) {
781   if ( set_mixer(&con, &i, argc, argv) == -1 ) {
782    fprintf(stderr, "Error: can not set volume\n");
783   } else {
784    printf("volume changed\n");
785   }
786
787  } else if ( !strcmp(k, "flag") ) {
788   i++;
789   if ( set_flags(&con, atoi(argv[i]), ROAR_SET_FLAG, argv[i+1]) == -1 ) {
790    fprintf(stderr, "Error: can not set flags\n");
791   } else {
792    printf("flags changed\n");
793   }
794   i++;
795  } else if ( !strcmp(k, "unflag") ) {
796   i++;
797   if ( set_flags(&con, atoi(argv[i]), ROAR_RESET_FLAG, argv[i+1]) == -1 ) {
798    fprintf(stderr, "Error: can not reset flags\n");
799   } else {
800    printf("flags changed\n");
801   }
802   i++;
803  } else if ( !strcmp(k, "metaset") ) {
804   i++;
805   if ( set_meta(&con, atoi(argv[i]), argv[i+1], argv[i+2], argv[i+3]) == -1 ) {
806    fprintf(stderr, "Error: can not set meta data\n");
807   } else {
808    printf("meta data changed\n");
809   }
810   i += 3;
811  } else if ( !strcmp(k, "metaget") ) {
812   i++;
813   if ( show_meta_type(&con, atoi(argv[i]), argv[i+1]) == -1 ) {
814    fprintf(stderr, "Error: can not get meta data\n");
815   }
816   i++;
817  } else if ( !strcmp(k, "metasave") ) {
818   i++;
819   if ( save_meta(&con, atoi(argv[i]), argv[i+1]) == -1 ) {
820    fprintf(stderr, "Error: can not get meta data\n");
821   } else {
822    printf("meta data saved\n");
823   }
824   i++;
825  } else if ( !strcmp(k, "metaload") ) {
826   i++;
827   if ( load_meta(&con, atoi(argv[i]), argv[i+1]) == -1 ) {
828    fprintf(stderr, "Error: can not set meta data\n");
829   } else {
830    printf("meta data saved\n");
831   }
832   i++;
833
834  } else {
835   fprintf(stderr, "Error: invalid command: %s\n", k);
836  }
837
838 }
839
840 roar_disconnect(&con);
841
842 return 0;
843}
844
845//ll
Note: See TracBrowser for help on using the repository browser.