source: roaraudio/roarclients/roarctl.c @ 1781:43f928932e6c

Last change on this file since 1781:43f928932e6c was 1781:43f928932e6c, checked in by phi, 15 years ago

ping requires gettimeofday()

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