source: roaraudio/roarclients/roarctl.c @ 2550:86e7ca0bd7a1

Last change on this file since 2550:86e7ca0bd7a1 was 2550:86e7ca0bd7a1, checked in by phi, 15 years ago

print player protocol

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