source: roaraudio/roarclients/roarctl.c @ 2620:d84d2de62245

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

added native and network byteorder specal info to byteorder info of players

File size: 23.6 KB
Line 
1//roarctl.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008
5 *
6 *  This file is part of roarclients a part of RoarAudio,
7 *  a cross-platform sound system for both, home and professional use.
8 *  See README for details.
9 *
10 *  This file is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License version 3
12 *  as published by the Free Software Foundation.
13 *
14 *  RoarAudio is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU General Public License for more details.
18 *
19 *  You should have received a copy of the GNU General Public License
20 *  along with this software; see the file COPYING.  If not, write to
21 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 */
24
25#include <roaraudio.h>
26
27#if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_SETUID)
28#define _POSIX_USERS
29#endif
30
31#ifdef _POSIX_USERS
32#include <pwd.h>
33#include <grp.h>
34#endif
35
36#include <sys/time.h>
37#include <time.h>
38
39int g_verbose = 0;
40
41int display_mixer (struct roar_connection * con, int stream);
42int show_meta_all (struct roar_connection * con, int id);
43
44void usage (void) {
45 printf("roarctl [OPTIONS]... COMMAND [OPTS] [COMMAND [OPTS] [COMMAND [OPTS] [...]]]\n");
46
47 printf("\nOptions:\n\n");
48
49 printf("  --server SERVER         - Set server hostname\n"
50        "  --help                  - Show this help\n"
51        "  --verbose   -v          - Show verbose output\n"
52       );
53
54 printf("\nCommands:\n\n");
55 printf(
56        "  help                    - Show this help\n"
57        "  sleep TIME              - Sleeps for TIME seconds\n"
58#ifdef ROAR_HAVE_GETTIMEOFDAY
59        "  ping  NUM               - Do NUM pings using NOOP commands\n"
60#endif
61        "\n"
62        "  standby, off            - Go into standby mode\n"
63        "  resume, on              - Go into active mode\n"
64        "  standbymode             - Show current standby mode\n"
65        "  exit                    - Quits the roard (must be used as last command)\n"
66        "  terminate               - Like exit but let the server up to serve still connected clients,\n"
67        "                            new clients cann't connect and the server terminates after the last\n"
68        "                            client disconnected\n"
69        "\n"
70        "  volume ID CHAN V0 V1... - Sets volume for stream ID\n"
71        "                            CHAN is the number of channels or 'mono' or 'stereo'\n"
72        "                            if mono or stereo is chosen roarctl trys to set\n"
73        "                            sensfull values for all channels even if the output\n"
74        "                            is has more channels.\n"
75        "                            all other args are the volumes of the channels\n"
76        "                            you may use integer or percent values.\n"
77        "                            percent values can flooding points.\n"
78        "\n"
79        "  flag   ID FLAGS         - Sets flags FLAGS on stream ID. FLAGS may be a comma\n"
80        "                            seperated list of flags.\n"
81        "  unflag ID FLAGS         - Unsets flags on a stream. See flag.\n"
82        "\n"
83        "  kick TYPE ID            - Kicks object of TYPE with id ID\n"
84        "                            Types: client stream sample source\n"
85        "\n"
86        "  metasave ID FILE        - Saves meta data of stream ID to file FILE\n"
87        "  metaload ID FILE        - Loads meta data from file FILE and set it on stream ID\n"
88        "\n"
89        "  serveroinfo             - Gets Informations about server output\n"
90        "  listclients             - Gets Informations about clients\n"
91        "  liststreams             - Gets Informations about streams\n"
92        "  allinfo                 - Get all infos\n"
93       );
94}
95
96#ifdef ROAR_HAVE_GETTIMEOFDAY
97int ping (struct roar_connection * con, int num) {
98 struct timeval         try, ans;
99 struct roar_message    m;
100 register int           ret;
101 int                    i;
102 double                 cur, min = 3600*1000, max = 0, sum = 0;
103
104 if ( num == 0 )
105  return 0;
106
107 for (i = 0; i < num; i++) {
108  m.cmd = ROAR_CMD_NOOP;
109  m.datalen = 0;
110
111  gettimeofday(&try, NULL);
112  ret = roar_req(con, &m, NULL);
113  gettimeofday(&ans, NULL);
114
115  if ( ret == -1 )
116   return -1;
117
118  while (ans.tv_sec > try.tv_sec) {
119   ans.tv_sec--;
120   ans.tv_usec += 1000000;
121  }
122  ans.tv_usec -= try.tv_usec;
123
124  printf("Pong from server: seq=%i time=%.3fms\n", i, (cur = ans.tv_usec/1000.0));
125
126  sum += cur;
127  if ( min > cur )
128   min = cur;
129  if ( cur > max )
130   max = cur;
131
132  if ( i != (num - 1) )
133   sleep(1);
134 }
135
136 printf("\n--- ping statistics ---\n");
137 printf("%i packets transmitted\n", i);
138 printf("rtt min/avg/max = %.3f/%.3f/%.3f ms\n", min, sum/(double)i, max);
139
140 return 0;
141}
142#endif
143
144void server_oinfo (struct roar_connection * con) {
145 struct roar_stream s;
146
147 if ( roar_server_oinfo(con, &s) == -1 ) {
148  fprintf(stderr, "Error: can not get server output info\n");
149  return;
150 }
151
152 printf("Stream direction      : %s\n", roar_dir2str(s.dir));
153 printf("Server Output rate    : %i\n", s.info.rate);
154 printf("Server Output bits    : %i\n", s.info.bits);
155 printf("Server Output channels: %i\n", s.info.channels);
156 printf("Server Output codec   : %i (%s%s)\n", s.info.codec, roar_codec2str(s.info.codec),
157                                     s.info.codec == ROAR_CODEC_DEFAULT ? " native" : "");
158// printf("Server Output rate: %i", s.info.rate);
159  if ( g_verbose > 1 )
160   printf("Server Position       : %lu S (%.3fs)\n", (unsigned long int) s.pos, (float)s.pos/(s.info.rate*s.info.channels));
161}
162
163const char * proc_name (pid_t pid) {
164 static char ret[80] = "?";
165#ifdef __linux__
166 char file[80], buf[80], *r;
167 int  i;
168
169 snprintf(file, 79, "/proc/%i/exe", pid);
170 file[79] = 0;
171
172 ret[0] = '?';
173 ret[1] = 0;
174
175 if ( (i = readlink(file, buf, 79)) != -1 ) {
176  buf[i] = 0;
177  if ( (r = strrchr(buf, '/')) != NULL ) {
178   r++;
179   if ( *r != 0 )
180    strcpy(ret, r);
181  }
182 }
183#endif
184
185 return ret;
186}
187
188void list_clients (struct roar_connection * con) {
189 int i;
190 int num;
191 int h;
192 int id[ROAR_CLIENTS_MAX];
193 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("Player name           : %s\n", c.name);
212  printf("Player 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("Player UID/GID        : %i(%s)/%i(%s)\n", c.uid, pwd ? pwd->pw_name : "?", c.gid, grp ? grp->gr_name : "?");
218#else
219   printf("Player UID/GID        : %i/%i\n", c.uid, c.gid);
220#endif
221  }
222
223  if ( g_verbose && c.proto != ROAR_PROTO_NONE ) {
224   printf("Player 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("Player 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    *flags = 0;
337    if ( info.flags & ROAR_FLAG_PRIMARY )
338     strcat(flags, "primary ");
339    if ( info.flags & ROAR_FLAG_SYNC )
340     strcat(flags, "sync ");
341    if ( info.flags & ROAR_FLAG_OUTPUT )
342     strcat(flags, "output ");
343    if ( info.flags & ROAR_FLAG_SOURCE )
344     strcat(flags, "source ");
345    if ( info.flags & ROAR_FLAG_META )
346     strcat(flags, "meta ");
347    if ( info.flags & ROAR_FLAG_AUTOCONF )
348     strcat(flags, "autoconf ");
349    if ( info.flags & ROAR_FLAG_CLEANMETA )
350     strcat(flags, "cleanmeta ");
351    if ( info.flags & ROAR_FLAG_HWMIXER )
352     strcat(flags, "hwmixer ");
353    if ( info.flags & ROAR_FLAG_PAUSE )
354     strcat(flags, "pause ");
355    if ( info.flags & ROAR_FLAG_MUTE )
356     strcat(flags, "mute ");
357    if ( info.flags & ROAR_FLAG_MMAP )
358     strcat(flags, "mmap ");
359    if ( info.flags & ROAR_FLAG_ANTIECHO )
360     strcat(flags, "antiecho ");
361    if ( info.flags & ROAR_FLAG_VIRTUAL )
362     strcat(flags, "virtual ");
363    if ( info.flags & ROAR_FLAG_RECSOURCE )
364     strcat(flags, "recsource ");
365    if ( info.flags & ROAR_FLAG_PASSMIXER )
366     strcat(flags, "passmixer ");
367
368    printf("Flags                 : %s\n", flags);
369   }
370  }
371
372  if ( s.dir != ROAR_DIR_THRU ) {
373   display_mixer(con, id[i]);
374   show_meta_all(con, id[i]);
375  }
376 }
377
378}
379
380int display_mixer (struct roar_connection * con, int stream) {
381 int channels;
382 struct roar_mixer_settings mixer;
383 int i;
384
385 if ( roar_get_vol(con, stream, &mixer, &channels) == -1 ) {
386  fprintf(stderr, "Error: can not get stream mixer info\n");
387  return -1;
388 }
389
390 for (i = 0; i < channels; i++)
391  printf("Mixer volume chan %2i  : %i (%.2f%%)\n", i, mixer.mixer[i], (float)mixer.mixer[i]/655.35);
392
393 return 0;
394}
395
396int set_mixer (struct roar_connection * con, int * cur, int max, char * arg[]) {
397 int chans = 0;
398 int id;
399 int i;
400 int len;
401 int old_chans;
402 int vol_l, vol_r;
403 char * k;
404 struct roar_mixer_settings mixer;
405 struct roar_mixer_settings old_mixer;
406
407 if (*cur + 2 > max)
408  return -1;
409
410 id = atoi(arg[++(*cur)]);
411
412 k = arg[++(*cur)];
413
414 if ( roar_get_vol(con, id, &old_mixer, &old_chans) == -1 ) {
415  fprintf(stderr, "Error: can not get stream mixer info\n");
416  return -1;
417 }
418
419
420// TODO: clean up code here as the % vs. abs code is very duplicate...
421
422 if ( strcmp(k, "mono") == 0 && old_chans != 1 ) {
423  chans = 1;
424
425  if ( *cur + 1 > max )
426   return -1;
427
428  k   = arg[++(*cur)];
429  len = strlen(k);
430
431  if ( k[len - 1] == '%' ) {
432   k[len - 1] = 0;
433   vol_l = (atof(k)*65535)/100;
434  } else {
435   vol_l = atoi(k);
436  }
437
438  for (i = 0; i < old_chans; i++)
439   mixer.mixer[i] = vol_l;
440
441  chans = old_chans;
442
443 } else if ( strcmp(k, "stereo") == 0 && old_chans == 4 ) {
444  chans = 4;
445
446  if ( *cur + 2 > max )
447   return -1;
448
449  k   = arg[++(*cur)];
450  len = strlen(k);
451
452  if ( k[len - 1] == '%' ) {
453   k[len - 1] = 0;
454   vol_l = (atof(k)*65535)/100;
455  } else {
456   vol_l = atoi(k);
457  }
458
459  k   = arg[++(*cur)];
460  len = strlen(k);
461
462  if ( k[len - 1] == '%' ) {
463   k[len - 1] = 0;
464   vol_r = (atof(k)*65535)/100;
465  } else {
466   vol_r = atoi(k);
467  }
468
469  mixer.mixer[0] = vol_l;
470  mixer.mixer[1] = vol_r;
471  mixer.mixer[2] = vol_l;
472  mixer.mixer[3] = vol_r;
473
474 } else if ( strcmp(k, "stereo") == 0 && old_chans != 2 ) {
475  chans = 2;
476//  printf("mode: stereo; chans=%i, old_chans=%i\n", chans, old_chans);
477  ROAR_ERR("mode stereo not supported");
478  return -1;
479 } else {
480  if ( strcmp(k, "mono") == 0 ) {
481   chans = 1;
482  } else if ( strcmp(k, "stereo") == 0 ) {
483   chans = 2;
484  } else {
485   chans = atoi(k);
486  }
487
488//  printf("mode: int; chans=%i, old_chans=%i\n", chans, old_chans);
489
490  if ( *cur + chans > max )
491   return -1;
492
493  for (i = 0; i < chans; i++) {
494   k   = arg[++(*cur)];
495   len = strlen(k);
496
497   if ( k[len - 1] == '%' ) {
498    k[len - 1] = 0;
499    mixer.mixer[i] = (atof(k)*(int)65535)/100;
500   } else {
501    mixer.mixer[i] = atoi(k);
502   }
503  }
504 }
505
506 mixer.scale = 65535;
507
508 return roar_set_vol(con, id, &mixer, chans);
509}
510
511int set_meta (struct roar_connection * con, int id, char * mode, char * type, char * val) {
512 struct roar_meta   meta;
513 struct roar_stream s;
514 int mode_i = ROAR_META_MODE_SET;
515
516 memset(&s, 0, sizeof(s));
517
518 s.id = id;
519
520// printf("set_meta(*): mode='%s', type='%s', val='%s'\n", mode, type, val);
521
522 if ( strcmp(mode, "add") == 0 ) {
523  mode_i = ROAR_META_MODE_ADD;
524 }
525
526 meta.type   = roar_meta_inttype(type);
527 meta.value  = val;
528 meta.key[0] = 0;
529
530 if ( meta.type == -1 ) {
531  fprintf(stderr, "Error: unknown type: %s\n", type);
532  return -1;
533 }
534
535// printf("D: type=%i, mode=%i\n", meta.type, mode_i);
536
537 if ( roar_stream_meta_set(con, &s, mode_i, &meta) == -1 )
538  return -1;
539
540 meta.type  = ROAR_META_TYPE_NONE;
541 meta.value = NULL;
542
543 return roar_stream_meta_set(con, &s, ROAR_META_MODE_FINALIZE, &meta);
544}
545
546int load_meta (struct roar_connection * con, int id, char * file) {
547 struct roar_meta   meta;
548 struct roar_stream s;
549 int mode_i = ROAR_META_MODE_SET;
550 FILE * in;
551 char lion[1024];
552 char * v;
553
554 memset(&s, 0, sizeof(s));
555
556 s.id = id;
557
558 if ( (in = fopen(file, "r")) == NULL )
559  return -1;
560
561 while (fgets(lion, 1024, in) != NULL) {
562  if ( (v = strtok(lion, "\r\n")) != NULL )
563   if ( (v = strtok(NULL, "\r\n")) != NULL )
564    *(v-1) = 0;
565
566  if ( (v = strstr(lion, "=")) == NULL ) {
567   fprintf(stderr, "Error: can not parse meta data lion: %s\n", lion);
568   continue;
569  }
570
571  *v++ = 0;
572
573  meta.type   = roar_meta_inttype(lion);
574  meta.value  = v;
575  meta.key[0] = 0;
576
577  if ( meta.type == -1 ) {
578   fprintf(stderr, "Error: unknown type: %s\n", lion);
579   continue;
580  }
581
582  if ( roar_stream_meta_set(con, &s, mode_i, &meta) == -1 )
583   return -1;
584 }
585
586 fclose(in);
587
588 meta.type  = ROAR_META_TYPE_NONE;
589 meta.value = NULL;
590
591 return roar_stream_meta_set(con, &s, ROAR_META_MODE_FINALIZE, &meta);
592}
593
594int show_meta_type (struct roar_connection * con, int id, char * type) {
595 struct roar_meta   meta;
596 struct roar_stream s;
597
598 memset(&s, 0, sizeof(s));
599
600 s.id = id;
601
602 meta.type  = roar_meta_inttype(type);
603
604 if ( meta.type == -1 ) {
605  fprintf(stderr, "Error: unknown type: %s\n", type);
606  return -1;
607 }
608
609 if ( roar_stream_meta_get(con, &s, &meta) == -1 )
610  return -1;
611
612 printf("Meta %-17s: %s\n", roar_meta_strtype(meta.type), meta.value);
613
614 roar_meta_free(&meta);
615
616 return 0;
617}
618
619int show_meta_all (struct roar_connection * con, int id) {
620 struct roar_stream s;
621 int types[ROAR_META_MAX_PER_STREAM];
622 int i;
623 int len;
624
625 memset(&s, 0, sizeof(s));
626
627 s.id = id;
628
629 if ( (len = roar_stream_meta_list(con, &s, types, ROAR_META_MAX_PER_STREAM)) == -1 )
630  return -1;
631
632 for (i = 0; i < len; i++)
633  show_meta_type(con, id, roar_meta_strtype(types[i]));
634
635 return 0;
636}
637
638int save_meta (struct roar_connection * con, int id, char * file) {
639 struct roar_stream s;
640 struct roar_meta   meta;
641 int types[ROAR_META_MAX_PER_STREAM];
642 int i;
643 int len;
644 FILE * out;
645
646 memset(&s, 0, sizeof(s));
647
648 s.id = id;
649
650 if ( (out = fopen(file, "w")) == NULL )
651  return -1;
652
653 if ( (len = roar_stream_meta_list(con, &s, types, ROAR_META_MAX_PER_STREAM)) == -1 )
654  return -1;
655
656 for (i = 0; i < len; i++) {
657/*
658  show_meta_type(con, id, roar_meta_strtype(types[i]));
659*/
660  meta.type  = types[i];
661
662  if ( roar_stream_meta_get(con, &s, &meta) == -1 )
663   continue;
664
665//  printf("Meta %-17s: %s\n", roar_meta_strtype(meta.type), meta.value);
666
667  fprintf(out, "%s=%s\n", roar_meta_strtype(meta.type), meta.value);
668
669  roar_meta_free(&meta);
670 }
671
672 fclose(out);
673
674 return 0;
675}
676
677int set_flags (struct roar_connection * con, int id, int reset, char * flags) {
678 int f = ROAR_FLAG_NONE;
679 char * c;
680 struct roar_stream s[1];
681
682 memset(s, 0, sizeof(struct roar_stream));
683
684 s->id = id;
685
686 c = strtok(flags, ",");
687 while (c != NULL) {
688  if ( !strcmp(c, "meta") ) {
689   f |= ROAR_FLAG_META;
690  } else if ( !strcmp(c, "primary") ) {
691   f |= ROAR_FLAG_PRIMARY;
692  } else if ( !strcmp(c, "sync") ) {
693   f |= ROAR_FLAG_SYNC;
694  } else if ( !strcmp(c, "cleanmeta") ) {
695   f |= ROAR_FLAG_CLEANMETA;
696  } else if ( !strcmp(c, "hwmixer") ) {
697   f |= ROAR_FLAG_HWMIXER;
698  } else if ( !strcmp(c, "pause") ) {
699   f |= ROAR_FLAG_PAUSE;
700  } else if ( !strcmp(c, "mute") ) {
701   f |= ROAR_FLAG_MUTE;
702  } else if ( !strcmp(c, "mmap") ) {
703   f |= ROAR_FLAG_MMAP;
704  } else if ( !strcmp(c, "antiecho") ) {
705   f |= ROAR_FLAG_ANTIECHO;
706  } else if ( !strcmp(c, "recsource") ) {
707   f |= ROAR_FLAG_RECSOURCE;
708  } else if ( !strcmp(c, "passmixer") ) {
709   f |= ROAR_FLAG_PASSMIXER;
710  } else {
711   fprintf(stderr, "Error: unknown flag: %s\n", c);
712   return -1;
713  }
714
715  c = strtok(NULL, ",");
716 }
717
718 return roar_stream_set_flags(con, s, f, reset);
719}
720
721int main (int argc, char * argv[]) {
722 struct roar_connection con;
723 char * server   = NULL;
724 char * k = NULL;
725 int    i;
726 int    t = 0;
727
728 for (i = 1; i < argc; i++) {
729  k = argv[i];
730
731  if ( strcmp(k, "--server") == 0 ) {
732   server = argv[++i];
733  } else if ( strcmp(k, "-v") == 0 || strcmp(k, "--verbose") == 0 ) {
734   g_verbose++;
735  } else if ( strcmp(k, "--help") == 0 ) {
736   usage();
737   return 0;
738  } else if ( *k == '-' ) {
739   fprintf(stderr, "Error: unknown argument: %s\n", k);
740   usage();
741   return 1;
742  } else {
743   break;
744  }
745 }
746
747 // connect
748
749 if ( roar_connect(&con, server) == -1 ) {
750  fprintf(stderr, "Error: Can not connect to server\n");
751  return 1;
752 }
753
754 if ( roar_identify(&con, "roarctl") == -1 ) {
755  fprintf(stderr, "Error: Can not identify to server\n");
756  return 1;
757 }
758
759 if ( i == argc ) {
760  fprintf(stderr, "Error: No Commands given\n");
761  return 0; // this is not a fatal error...
762 }
763
764 for (; i < argc; i++) {
765  k = argv[i];
766  // cmd is in k
767
768  printf("--- [ %s ] ---\n", k);
769
770  if ( !strcmp(k, "help") ) {
771   usage();
772
773  } else if ( !strcmp(k, "sleep") ) {
774   sleep(atoi(argv[++i]));
775
776  } else if ( !strcmp(k, "ping") ) {
777#ifdef ROAR_HAVE_GETTIMEOFDAY
778   if ( ping(&con, atoi(argv[++i])) == -1 ) {
779    fprintf(stderr, "Error: can not ping\n");
780   }
781#else
782    fprintf(stderr, "Error: ping not supported.\n");
783    i++;
784#endif
785
786  } else if ( !strcmp(k, "standby") || !strcmp(k, "off") ) {
787   if ( roar_set_standby(&con, ROAR_STANDBY_ACTIVE) == -1 ) {
788    fprintf(stderr, "Error: can not set mode to standby\n");
789   } else {
790    printf("going into standby\n");
791   }
792  } else if ( !strcmp(k, "resume") || !strcmp(k, "on") ) {
793   if ( roar_set_standby(&con, ROAR_STANDBY_INACTIVE) == -1 ) {
794    fprintf(stderr, "Error: can not set mode to active\n");
795   } else {
796    printf("going into active mode\n");
797   }
798
799  } else if ( !strcmp(k, "exit") ) {
800   if ( roar_exit(&con) == -1 ) {
801    fprintf(stderr, "Error: can not quit server\n");
802   } else {
803    printf("Server quited\n");
804    break;
805   }
806  } else if ( !strcmp(k, "terminate") ) {
807   if ( roar_terminate(&con, 1) == -1 ) {
808    fprintf(stderr, "Error: can not terminate server\n");
809   } else {
810    printf("Server got asked to quited\n");
811    break;
812   }
813
814  } else if ( !strcmp(k, "standbymode") ) {
815   t = roar_get_standby(&con);
816   if ( t == -1 ) {
817    fprintf(stderr, "Error: can not get stanby mode\n");
818   } else if ( t == ROAR_STANDBY_ACTIVE ) {
819    printf("Server is in standby\n");
820   } else if ( t == ROAR_STANDBY_INACTIVE ) {
821    printf("Server is active\n");
822   } else {
823    fprintf(stderr, "Error: unknown standby mode: %i\n", t);
824   }
825
826  } else if ( !strcmp(k, "whoami") ) {
827   printf("My client ID is: %i\n", roar_get_clientid(&con));
828  } else if ( !strcmp(k, "serveroinfo") ) {
829   server_oinfo(&con);
830  } else if ( !strcmp(k, "listclients") ) {
831   list_clients(&con);
832  } else if ( !strcmp(k, "liststreams") ) {
833   list_streams(&con);
834  } else if ( !strcmp(k, "allinfo") ) {
835   server_oinfo(&con);
836   printf("\n");
837   list_clients(&con);
838   printf("\n");
839   list_streams(&con);
840
841  } else if ( !strcmp(k, "kick") ) {
842   k = argv[++i];
843   if ( !strcmp(k, "client") ) {
844    t = ROAR_OT_CLIENT;
845   } else if ( !strcmp(k, "stream") ) {
846    t = ROAR_OT_STREAM;
847   } else if ( !strcmp(k, "sample") ) {
848    t = ROAR_OT_SAMPLE;
849   } else if ( !strcmp(k, "source") ) {
850    t = ROAR_OT_SOURCE;
851   } else {
852    fprintf(stderr, "Error: unknown type: %s\n", k);
853    continue;
854   }
855   //t = atoi(argv[i++]);
856   if ( roar_kick(&con, t, atoi(argv[++i])) == -1 ) {
857    fprintf(stderr, "Error: can not kick %s\n", k);
858   } else {
859    printf("%s kicked\n", k);
860   }
861
862  } else if ( !strcmp(k, "volume") ) {
863   if ( set_mixer(&con, &i, argc, argv) == -1 ) {
864    fprintf(stderr, "Error: can not set volume\n");
865   } else {
866    printf("volume changed\n");
867   }
868
869  } else if ( !strcmp(k, "flag") ) {
870   i++;
871   if ( set_flags(&con, atoi(argv[i]), ROAR_SET_FLAG, argv[i+1]) == -1 ) {
872    fprintf(stderr, "Error: can not set flags\n");
873   } else {
874    printf("flags changed\n");
875   }
876   i++;
877  } else if ( !strcmp(k, "unflag") ) {
878   i++;
879   if ( set_flags(&con, atoi(argv[i]), ROAR_RESET_FLAG, argv[i+1]) == -1 ) {
880    fprintf(stderr, "Error: can not reset flags\n");
881   } else {
882    printf("flags changed\n");
883   }
884   i++;
885  } else if ( !strcmp(k, "metaset") ) {
886   i++;
887   if ( set_meta(&con, atoi(argv[i]), argv[i+1], argv[i+2], argv[i+3]) == -1 ) {
888    fprintf(stderr, "Error: can not set meta data\n");
889   } else {
890    printf("meta data changed\n");
891   }
892   i += 3;
893  } else if ( !strcmp(k, "metaget") ) {
894   i++;
895   if ( show_meta_type(&con, atoi(argv[i]), argv[i+1]) == -1 ) {
896    fprintf(stderr, "Error: can not get meta data\n");
897   }
898   i++;
899  } else if ( !strcmp(k, "metasave") ) {
900   i++;
901   if ( save_meta(&con, atoi(argv[i]), argv[i+1]) == -1 ) {
902    fprintf(stderr, "Error: can not get meta data\n");
903   } else {
904    printf("meta data saved\n");
905   }
906   i++;
907  } else if ( !strcmp(k, "metaload") ) {
908   i++;
909   if ( load_meta(&con, atoi(argv[i]), argv[i+1]) == -1 ) {
910    fprintf(stderr, "Error: can not set meta data\n");
911   } else {
912    printf("meta data saved\n");
913   }
914   i++;
915
916  } else {
917   fprintf(stderr, "Error: invalid command: %s\n", k);
918  }
919
920 }
921
922 roar_disconnect(&con);
923
924 return 0;
925}
926
927//ll
Note: See TracBrowser for help on using the repository browser.