source: roaraudio/roarclients/roarctl.c @ 2634:8d6985223fac

Last change on this file since 2634:8d6985223fac was 2634:8d6985223fac, checked in by phi, 15 years ago

show stream state

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