source: roaraudio/roarclients/roarctl.c @ 1631:cd711280ad60

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

added stats, fixed behavor if num is zero

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