source: roaraudio/roarclients/roarctl.c @ 2617:b5912694dfb3

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

show byte order or client in case we know it

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