source: roaraudio/roarclients/roarctl.c @ 2399:22feff815ea4

Last change on this file since 2399:22feff815ea4 was 2399:22feff815ea4, checked in by phi, 15 years ago

better way to display things

File size: 22.8 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 char name[1024];
239 char * infotext;
240
241
242 if ( (num = roar_list_streams(con, id, ROAR_STREAMS_MAX)) == -1 ) {
243  fprintf(stderr, "Error: can not get stream list\n");
244  return;
245 }
246
247 for (i = 0; i < num; i++) {
248  printf("stream %i:\n", id[i]);
249  if ( roar_get_stream(con, &s, id[i]) == -1 ) {
250   fprintf(stderr, "Error: can not get stream info\n");
251   continue;
252  }
253  printf("Stream direction      : %s\n", roar_dir2str(s.dir));
254
255  if ( roar_stream_get_name(con, &s, name, 1024) == 0 )
256   printf("Stream name           : %s\n", name);
257
258  if ( s.pos_rel_id == -1 ) {
259   printf("Relativ position id   : none (stream not synchronized)\n");
260  } else if ( s.pos_rel_id == id[i] ) {
261   printf("Relativ position id   : %i (self synchronized)\n", s.pos_rel_id);
262  } else {
263   printf("Relativ position id   : %i (synchronized)\n", s.pos_rel_id);
264  }
265  if ( g_verbose > 1 ) {
266   if ( s.info.rate && s.info.channels ) {
267    printf("Position              : %lu S (%.3fs)\n", (unsigned long int) s.pos,
268                                    (float)s.pos/(s.info.rate*s.info.channels));
269   } else {
270    printf("Position              : %lu S\n", (unsigned long int) s.pos);
271   }
272  }
273
274  switch (s.dir) {
275   case ROAR_DIR_MIDI_IN:
276   case ROAR_DIR_MIDI_OUT:
277     infotext = " ticks/s";
278    break;
279   case ROAR_DIR_LIGHT_IN:
280   case ROAR_DIR_LIGHT_OUT:
281     infotext = " updates/s";
282    break;
283   default:
284     infotext = " Hz";
285  }
286  if ( s.info.rate )
287   printf("Stream sample rate    : %i%s\n", s.info.rate, infotext);
288  if ( s.info.bits )
289   printf("Stream bits           : %i\n", s.info.bits);
290  if ( s.info.channels )
291  printf("Stream channels       : %i\n", s.info.channels);
292
293  printf("Stream codec          : %2i (%s%s)\n", s.info.codec, roar_codec2str(s.info.codec),
294                                       s.info.codec == ROAR_CODEC_DEFAULT ? " native" : "");
295  if ( roar_stream_get_info(con, &s, &info) != -1 ) {
296   if ( info.codec != s.info.codec ) {
297    printf("Stremed codec         : %2i (%s%s)\n", info.codec, roar_codec2str(info.codec),
298                                       info.codec == ROAR_CODEC_DEFAULT ? " native" : "");
299   }
300
301   if ( g_verbose ) {
302    if ( info.block_size )
303     printf("Stream block size     : %i Byte\n", info.block_size);
304
305    printf("Underruns pre/post    : %i/%i\n",   info.pre_underruns, info.post_underruns);
306    if ( g_verbose > 1 )
307     printf("Stream delay          : %ims\n",   (int)info.delay/1000);
308
309    *flags = 0;
310    if ( info.flags & ROAR_FLAG_PRIMARY )
311     strcat(flags, "primary ");
312    if ( info.flags & ROAR_FLAG_SYNC )
313     strcat(flags, "sync ");
314    if ( info.flags & ROAR_FLAG_OUTPUT )
315     strcat(flags, "output ");
316    if ( info.flags & ROAR_FLAG_SOURCE )
317     strcat(flags, "source ");
318    if ( info.flags & ROAR_FLAG_META )
319     strcat(flags, "meta ");
320    if ( info.flags & ROAR_FLAG_AUTOCONF )
321     strcat(flags, "autoconf ");
322    if ( info.flags & ROAR_FLAG_CLEANMETA )
323     strcat(flags, "cleanmeta ");
324    if ( info.flags & ROAR_FLAG_HWMIXER )
325     strcat(flags, "hwmixer ");
326    if ( info.flags & ROAR_FLAG_PAUSE )
327     strcat(flags, "pause ");
328    if ( info.flags & ROAR_FLAG_MUTE )
329     strcat(flags, "mute ");
330    if ( info.flags & ROAR_FLAG_MMAP )
331     strcat(flags, "mmap ");
332    if ( info.flags & ROAR_FLAG_ANTIECHO )
333     strcat(flags, "antiecho ");
334    if ( info.flags & ROAR_FLAG_VIRTUAL )
335     strcat(flags, "virtual ");
336
337    printf("Flags                 : %s\n", flags);
338   }
339  }
340
341  if ( s.dir != ROAR_DIR_THRU ) {
342   display_mixer(con, id[i]);
343   show_meta_all(con, id[i]);
344  }
345 }
346
347}
348
349int display_mixer (struct roar_connection * con, int stream) {
350 int channels;
351 struct roar_mixer_settings mixer;
352 int i;
353
354 if ( roar_get_vol(con, stream, &mixer, &channels) == -1 ) {
355  fprintf(stderr, "Error: can not get stream mixer info\n");
356  return -1;
357 }
358
359 for (i = 0; i < channels; i++)
360  printf("Mixer volume chan %2i  : %i (%.2f%%)\n", i, mixer.mixer[i], (float)mixer.mixer[i]/655.35);
361
362 return 0;
363}
364
365int set_mixer (struct roar_connection * con, int * cur, int max, char * arg[]) {
366 int chans = 0;
367 int id;
368 int i;
369 int len;
370 int old_chans;
371 int vol_l, vol_r;
372 char * k;
373 struct roar_mixer_settings mixer;
374 struct roar_mixer_settings old_mixer;
375
376 if (*cur + 2 > max)
377  return -1;
378
379 id = atoi(arg[++(*cur)]);
380
381 k = arg[++(*cur)];
382
383 if ( roar_get_vol(con, id, &old_mixer, &old_chans) == -1 ) {
384  fprintf(stderr, "Error: can not get stream mixer info\n");
385  return -1;
386 }
387
388
389// TODO: clean up code here as the % vs. abs code is very duplicate...
390
391 if ( strcmp(k, "mono") == 0 && old_chans != 1 ) {
392  chans = 1;
393
394  if ( *cur + 1 > max )
395   return -1;
396
397  k   = arg[++(*cur)];
398  len = strlen(k);
399
400  if ( k[len - 1] == '%' ) {
401   k[len - 1] = 0;
402   vol_l = (atof(k)*65535)/100;
403  } else {
404   vol_l = atoi(k);
405  }
406
407  for (i = 0; i < old_chans; i++)
408   mixer.mixer[i] = vol_l;
409
410  chans = old_chans;
411
412 } else if ( strcmp(k, "stereo") == 0 && old_chans == 4 ) {
413  chans = 4;
414
415  if ( *cur + 2 > max )
416   return -1;
417
418  k   = arg[++(*cur)];
419  len = strlen(k);
420
421  if ( k[len - 1] == '%' ) {
422   k[len - 1] = 0;
423   vol_l = (atof(k)*65535)/100;
424  } else {
425   vol_l = atoi(k);
426  }
427
428  k   = arg[++(*cur)];
429  len = strlen(k);
430
431  if ( k[len - 1] == '%' ) {
432   k[len - 1] = 0;
433   vol_r = (atof(k)*65535)/100;
434  } else {
435   vol_r = atoi(k);
436  }
437
438  mixer.mixer[0] = vol_l;
439  mixer.mixer[1] = vol_r;
440  mixer.mixer[2] = vol_l;
441  mixer.mixer[3] = vol_r;
442
443 } else if ( strcmp(k, "stereo") == 0 && old_chans != 2 ) {
444  chans = 2;
445//  printf("mode: stereo; chans=%i, old_chans=%i\n", chans, old_chans);
446  ROAR_ERR("mode stereo not supported");
447  return -1;
448 } else {
449  if ( strcmp(k, "mono") == 0 ) {
450   chans = 1;
451  } else if ( strcmp(k, "stereo") == 0 ) {
452   chans = 2;
453  } else {
454   chans = atoi(k);
455  }
456
457//  printf("mode: int; chans=%i, old_chans=%i\n", chans, old_chans);
458
459  if ( *cur + chans > max )
460   return -1;
461
462  for (i = 0; i < chans; i++) {
463   k   = arg[++(*cur)];
464   len = strlen(k);
465
466   if ( k[len - 1] == '%' ) {
467    k[len - 1] = 0;
468    mixer.mixer[i] = (atof(k)*(int)65535)/100;
469   } else {
470    mixer.mixer[i] = atoi(k);
471   }
472  }
473 }
474
475 mixer.scale = 65535;
476
477 return roar_set_vol(con, id, &mixer, chans);
478}
479
480int set_meta (struct roar_connection * con, int id, char * mode, char * type, char * val) {
481 struct roar_meta   meta;
482 struct roar_stream s;
483 int mode_i = ROAR_META_MODE_SET;
484
485 memset(&s, 0, sizeof(s));
486
487 s.id = id;
488
489// printf("set_meta(*): mode='%s', type='%s', val='%s'\n", mode, type, val);
490
491 if ( strcmp(mode, "add") == 0 ) {
492  mode_i = ROAR_META_MODE_ADD;
493 }
494
495 meta.type   = roar_meta_inttype(type);
496 meta.value  = val;
497 meta.key[0] = 0;
498
499 if ( meta.type == -1 ) {
500  fprintf(stderr, "Error: unknown type: %s\n", type);
501  return -1;
502 }
503
504// printf("D: type=%i, mode=%i\n", meta.type, mode_i);
505
506 if ( roar_stream_meta_set(con, &s, mode_i, &meta) == -1 )
507  return -1;
508
509 meta.type  = ROAR_META_TYPE_NONE;
510 meta.value = NULL;
511
512 return roar_stream_meta_set(con, &s, ROAR_META_MODE_FINALIZE, &meta);
513}
514
515int load_meta (struct roar_connection * con, int id, char * file) {
516 struct roar_meta   meta;
517 struct roar_stream s;
518 int mode_i = ROAR_META_MODE_SET;
519 FILE * in;
520 char lion[1024];
521 char * v;
522
523 memset(&s, 0, sizeof(s));
524
525 s.id = id;
526
527 if ( (in = fopen(file, "r")) == NULL )
528  return -1;
529
530 while (fgets(lion, 1024, in) != NULL) {
531  if ( (v = strtok(lion, "\r\n")) != NULL )
532   if ( (v = strtok(NULL, "\r\n")) != NULL )
533    *(v-1) = 0;
534
535  if ( (v = strstr(lion, "=")) == NULL ) {
536   fprintf(stderr, "Error: can not parse meta data lion: %s\n", lion);
537   continue;
538  }
539
540  *v++ = 0;
541
542  meta.type   = roar_meta_inttype(lion);
543  meta.value  = v;
544  meta.key[0] = 0;
545
546  if ( meta.type == -1 ) {
547   fprintf(stderr, "Error: unknown type: %s\n", lion);
548   continue;
549  }
550
551  if ( roar_stream_meta_set(con, &s, mode_i, &meta) == -1 )
552   return -1;
553 }
554
555 fclose(in);
556
557 meta.type  = ROAR_META_TYPE_NONE;
558 meta.value = NULL;
559
560 return roar_stream_meta_set(con, &s, ROAR_META_MODE_FINALIZE, &meta);
561}
562
563int show_meta_type (struct roar_connection * con, int id, char * type) {
564 struct roar_meta   meta;
565 struct roar_stream s;
566
567 memset(&s, 0, sizeof(s));
568
569 s.id = id;
570
571 meta.type  = roar_meta_inttype(type);
572
573 if ( meta.type == -1 ) {
574  fprintf(stderr, "Error: unknown type: %s\n", type);
575  return -1;
576 }
577
578 if ( roar_stream_meta_get(con, &s, &meta) == -1 )
579  return -1;
580
581 printf("Meta %-17s: %s\n", roar_meta_strtype(meta.type), meta.value);
582
583 roar_meta_free(&meta);
584
585 return 0;
586}
587
588int show_meta_all (struct roar_connection * con, int id) {
589 struct roar_stream s;
590 int types[ROAR_META_MAX_PER_STREAM];
591 int i;
592 int len;
593
594 memset(&s, 0, sizeof(s));
595
596 s.id = id;
597
598 if ( (len = roar_stream_meta_list(con, &s, types, ROAR_META_MAX_PER_STREAM)) == -1 )
599  return -1;
600
601 for (i = 0; i < len; i++)
602  show_meta_type(con, id, roar_meta_strtype(types[i]));
603
604 return 0;
605}
606
607int save_meta (struct roar_connection * con, int id, char * file) {
608 struct roar_stream s;
609 struct roar_meta   meta;
610 int types[ROAR_META_MAX_PER_STREAM];
611 int i;
612 int len;
613 FILE * out;
614
615 memset(&s, 0, sizeof(s));
616
617 s.id = id;
618
619 if ( (out = fopen(file, "w")) == NULL )
620  return -1;
621
622 if ( (len = roar_stream_meta_list(con, &s, types, ROAR_META_MAX_PER_STREAM)) == -1 )
623  return -1;
624
625 for (i = 0; i < len; i++) {
626/*
627  show_meta_type(con, id, roar_meta_strtype(types[i]));
628*/
629  meta.type  = types[i];
630
631  if ( roar_stream_meta_get(con, &s, &meta) == -1 )
632   continue;
633
634//  printf("Meta %-17s: %s\n", roar_meta_strtype(meta.type), meta.value);
635
636  fprintf(out, "%s=%s\n", roar_meta_strtype(meta.type), meta.value);
637
638  roar_meta_free(&meta);
639 }
640
641 fclose(out);
642
643 return 0;
644}
645
646int set_flags (struct roar_connection * con, int id, int reset, char * flags) {
647 int f = ROAR_FLAG_NONE;
648 char * c;
649 struct roar_stream s[1];
650
651 memset(s, 0, sizeof(struct roar_stream));
652
653 s->id = id;
654
655 c = strtok(flags, ",");
656 while (c != NULL) {
657  if ( !strcmp(c, "meta") ) {
658   f |= ROAR_FLAG_META;
659  } else if ( !strcmp(c, "primary") ) {
660   f |= ROAR_FLAG_PRIMARY;
661  } else if ( !strcmp(c, "sync") ) {
662   f |= ROAR_FLAG_SYNC;
663  } else if ( !strcmp(c, "cleanmeta") ) {
664   f |= ROAR_FLAG_CLEANMETA;
665  } else if ( !strcmp(c, "hwmixer") ) {
666   f |= ROAR_FLAG_HWMIXER;
667  } else if ( !strcmp(c, "pause") ) {
668   f |= ROAR_FLAG_PAUSE;
669  } else if ( !strcmp(c, "mute") ) {
670   f |= ROAR_FLAG_MUTE;
671  } else if ( !strcmp(c, "mmap") ) {
672   f |= ROAR_FLAG_MMAP;
673  } else if ( !strcmp(c, "antiecho") ) {
674   f |= ROAR_FLAG_ANTIECHO;
675  } else {
676   fprintf(stderr, "Error: unknown flag: %s\n", c);
677   return -1;
678  }
679
680  c = strtok(NULL, ",");
681 }
682
683 return roar_stream_set_flags(con, s, f, reset);
684}
685
686int main (int argc, char * argv[]) {
687 struct roar_connection con;
688 char * server   = NULL;
689 char * k = NULL;
690 int    i;
691 int    t = 0;
692
693 for (i = 1; i < argc; i++) {
694  k = argv[i];
695
696  if ( strcmp(k, "--server") == 0 ) {
697   server = argv[++i];
698  } else if ( strcmp(k, "-v") == 0 || strcmp(k, "--verbose") == 0 ) {
699   g_verbose++;
700  } else if ( strcmp(k, "--help") == 0 ) {
701   usage();
702   return 0;
703  } else if ( *k == '-' ) {
704   fprintf(stderr, "Error: unknown argument: %s\n", k);
705   usage();
706   return 1;
707  } else {
708   break;
709  }
710 }
711
712 // connect
713
714 if ( roar_connect(&con, server) == -1 ) {
715  fprintf(stderr, "Error: Can not connect to server\n");
716  return 1;
717 }
718
719 if ( roar_identify(&con, "roarctl") == -1 ) {
720  fprintf(stderr, "Error: Can not identify to server\n");
721  return 1;
722 }
723
724 if ( i == argc ) {
725  fprintf(stderr, "Error: No Commands given\n");
726  return 0; // this is not a fatal error...
727 }
728
729 for (; i < argc; i++) {
730  k = argv[i];
731  // cmd is in k
732
733  printf("--- [ %s ] ---\n", k);
734
735  if ( !strcmp(k, "help") ) {
736   usage();
737
738  } else if ( !strcmp(k, "sleep") ) {
739   sleep(atoi(argv[++i]));
740
741  } else if ( !strcmp(k, "ping") ) {
742#ifdef ROAR_HAVE_GETTIMEOFDAY
743   if ( ping(&con, atoi(argv[++i])) == -1 ) {
744    fprintf(stderr, "Error: can not ping\n");
745   }
746#else
747    fprintf(stderr, "Error: ping not supported.\n");
748    i++;
749#endif
750
751  } else if ( !strcmp(k, "standby") || !strcmp(k, "off") ) {
752   if ( roar_set_standby(&con, ROAR_STANDBY_ACTIVE) == -1 ) {
753    fprintf(stderr, "Error: can not set mode to standby\n");
754   } else {
755    printf("going into standby\n");
756   }
757  } else if ( !strcmp(k, "resume") || !strcmp(k, "on") ) {
758   if ( roar_set_standby(&con, ROAR_STANDBY_INACTIVE) == -1 ) {
759    fprintf(stderr, "Error: can not set mode to active\n");
760   } else {
761    printf("going into active mode\n");
762   }
763
764  } else if ( !strcmp(k, "exit") ) {
765   if ( roar_exit(&con) == -1 ) {
766    fprintf(stderr, "Error: can not quit server\n");
767   } else {
768    printf("Server quited\n");
769    break;
770   }
771  } else if ( !strcmp(k, "terminate") ) {
772   if ( roar_terminate(&con, 1) == -1 ) {
773    fprintf(stderr, "Error: can not terminate server\n");
774   } else {
775    printf("Server got asked to quited\n");
776    break;
777   }
778
779  } else if ( !strcmp(k, "standbymode") ) {
780   t = roar_get_standby(&con);
781   if ( t == -1 ) {
782    fprintf(stderr, "Error: can not get stanby mode\n");
783   } else if ( t == ROAR_STANDBY_ACTIVE ) {
784    printf("Server is in standby\n");
785   } else if ( t == ROAR_STANDBY_INACTIVE ) {
786    printf("Server is active\n");
787   } else {
788    fprintf(stderr, "Error: unknown standby mode: %i\n", t);
789   }
790
791  } else if ( !strcmp(k, "whoami") ) {
792   printf("My client ID is: %i\n", roar_get_clientid(&con));
793  } else if ( !strcmp(k, "serveroinfo") ) {
794   server_oinfo(&con);
795  } else if ( !strcmp(k, "listclients") ) {
796   list_clients(&con);
797  } else if ( !strcmp(k, "liststreams") ) {
798   list_streams(&con);
799  } else if ( !strcmp(k, "allinfo") ) {
800   server_oinfo(&con);
801   printf("\n");
802   list_clients(&con);
803   printf("\n");
804   list_streams(&con);
805
806  } else if ( !strcmp(k, "kick") ) {
807   k = argv[++i];
808   if ( !strcmp(k, "client") ) {
809    t = ROAR_OT_CLIENT;
810   } else if ( !strcmp(k, "stream") ) {
811    t = ROAR_OT_STREAM;
812   } else if ( !strcmp(k, "sample") ) {
813    t = ROAR_OT_SAMPLE;
814   } else if ( !strcmp(k, "source") ) {
815    t = ROAR_OT_SOURCE;
816   } else {
817    fprintf(stderr, "Error: unknown type: %s\n", k);
818    continue;
819   }
820   //t = atoi(argv[i++]);
821   if ( roar_kick(&con, t, atoi(argv[++i])) == -1 ) {
822    fprintf(stderr, "Error: can not kick %s\n", k);
823   } else {
824    printf("%s kicked\n", k);
825   }
826
827  } else if ( !strcmp(k, "volume") ) {
828   if ( set_mixer(&con, &i, argc, argv) == -1 ) {
829    fprintf(stderr, "Error: can not set volume\n");
830   } else {
831    printf("volume changed\n");
832   }
833
834  } else if ( !strcmp(k, "flag") ) {
835   i++;
836   if ( set_flags(&con, atoi(argv[i]), ROAR_SET_FLAG, argv[i+1]) == -1 ) {
837    fprintf(stderr, "Error: can not set flags\n");
838   } else {
839    printf("flags changed\n");
840   }
841   i++;
842  } else if ( !strcmp(k, "unflag") ) {
843   i++;
844   if ( set_flags(&con, atoi(argv[i]), ROAR_RESET_FLAG, argv[i+1]) == -1 ) {
845    fprintf(stderr, "Error: can not reset flags\n");
846   } else {
847    printf("flags changed\n");
848   }
849   i++;
850  } else if ( !strcmp(k, "metaset") ) {
851   i++;
852   if ( set_meta(&con, atoi(argv[i]), argv[i+1], argv[i+2], argv[i+3]) == -1 ) {
853    fprintf(stderr, "Error: can not set meta data\n");
854   } else {
855    printf("meta data changed\n");
856   }
857   i += 3;
858  } else if ( !strcmp(k, "metaget") ) {
859   i++;
860   if ( show_meta_type(&con, atoi(argv[i]), argv[i+1]) == -1 ) {
861    fprintf(stderr, "Error: can not get meta data\n");
862   }
863   i++;
864  } else if ( !strcmp(k, "metasave") ) {
865   i++;
866   if ( save_meta(&con, atoi(argv[i]), argv[i+1]) == -1 ) {
867    fprintf(stderr, "Error: can not get meta data\n");
868   } else {
869    printf("meta data saved\n");
870   }
871   i++;
872  } else if ( !strcmp(k, "metaload") ) {
873   i++;
874   if ( load_meta(&con, atoi(argv[i]), argv[i+1]) == -1 ) {
875    fprintf(stderr, "Error: can not set meta data\n");
876   } else {
877    printf("meta data saved\n");
878   }
879   i++;
880
881  } else {
882   fprintf(stderr, "Error: invalid command: %s\n", k);
883  }
884
885 }
886
887 roar_disconnect(&con);
888
889 return 0;
890}
891
892//ll
Note: See TracBrowser for help on using the repository browser.