source: roaraudio/roarclients/roarctl.c @ 1630:b7db925dbfd1

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

added command ping to roarctl

File size: 20.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#include <pwd.h>
27#include <grp.h>
28#include <sys/time.h>
29#include <time.h>
30
31int g_verbose = 0;
32
33int display_mixer (struct roar_connection * con, int stream);
34int show_meta_all (struct roar_connection * con, int id);
35
36void usage (void) {
37 printf("roarctl [OPTIONS]... COMMAND [OPTS] [COMMAND [OPTS] [COMMAND [OPTS] [...]]]\n");
38
39 printf("\nOptions:\n\n");
40
41 printf("  --server SERVER         - Set server hostname\n"
42        "  --help                  - Show this help\n"
43        "  --verbose   -v          - Show verbose output\n"
44       );
45
46 printf("\nCommands:\n\n");
47 printf(
48        "  help                    - Show this help\n"
49        "  sleep TIME              - Sleeps for TIME seconds\n"
50        "  ping  NUM               - Do NUM pings using NOOP commands\n"
51        "\n"
52        "  standby, off            - Go into standby mode\n"
53        "  resume, on              - Go into active mode\n"
54        "  standbymode             - Show current standby mode\n"
55        "  exit                    - Quits the roard (must be used as last command)\n"
56        "  terminate               - Like exit but let the server up to serve still connected clients,\n"
57        "                            new clients cann't connect and the server terminates after the last\n"
58        "                            client disconnected\n"
59        "\n"
60        "  volume ID CHAN V0 V1... - Sets volume for stream ID\n"
61        "                            CHAN is the number of channels or 'mono' or 'stereo'\n"
62        "                            if mono or stereo is chosen roarctl trys to set\n"
63        "                            sensfull values for all channels even if the output\n"
64        "                            is has more channels.\n"
65        "                            all other args are the volumes of the channels\n"
66        "                            you may use integer or percent values.\n"
67        "                            percent values can flooding points.\n"
68        "\n"
69        "  flag   ID FLAGS         - Sets flags FLAGS on stream ID. FLAGS may be a comma\n"
70        "                            seperated list of flags.\n"
71        "  unflag ID FLAGS         - Unsets flags on a stream. See flag.\n"
72        "\n"
73        "  kick TYPE ID            - Kicks object of TYPE with id ID\n"
74        "                            Types: client stream sample source\n"
75        "\n"
76        "  metasave ID FILE        - Saves meta data of stream ID to file FILE\n"
77        "  metaload ID FILE        - Loads meta data from file FILE and set it on stream ID\n"
78        "\n"
79        "  serveroinfo             - Gets Informations about server output\n"
80        "  listclients             - Gets Informations about clients\n"
81        "  liststreams             - Gets Informations about streams\n"
82        "  allinfo                 - Get all infos\n"
83       );
84}
85
86int ping (struct roar_connection * con, int num) {
87 struct timeval         try, ans;
88 struct roar_message    m;
89 register int           ret;
90 int i;
91
92 for (i = 0; i < num; i++) {
93  m.cmd = ROAR_CMD_NOOP;
94  m.datalen = 0;
95
96  gettimeofday(&try, NULL);
97  ret = roar_req(con, &m, NULL);
98  gettimeofday(&ans, NULL);
99
100  if ( ret == -1 )
101   return -1;
102
103  while (ans.tv_sec > try.tv_sec) {
104   ans.tv_sec--;
105   ans.tv_usec += 1000000;
106  }
107  ans.tv_usec -= try.tv_usec;
108
109  printf("Pong from server: seq=%i time=%.2fms\n", i, ans.tv_usec/1000.0);
110
111  if ( i != (num - 1) )
112   sleep(1);
113 }
114
115 return 0;
116}
117
118void server_oinfo (struct roar_connection * con) {
119 struct roar_stream s;
120
121 if ( roar_server_oinfo(con, &s) == -1 ) {
122  fprintf(stderr, "Error: can not get server output info\n");
123  return;
124 }
125
126 printf("Stream direction      : %s\n", roar_dir2str(s.dir));
127 printf("Server Output rate    : %i\n", s.info.rate);
128 printf("Server Output bits    : %i\n", s.info.bits);
129 printf("Server Output channels: %i\n", s.info.channels);
130 printf("Server Output codec   : %i (%s%s)\n", s.info.codec, roar_codec2str(s.info.codec),
131                                     s.info.codec == ROAR_CODEC_DEFAULT ? " native" : "");
132// printf("Server Output rate: %i", s.info.rate);
133  if ( g_verbose > 1 )
134   printf("Server Position       : %lu S (%.3fs)\n", (unsigned long int) s.pos, (float)s.pos/(s.info.rate*s.info.channels));
135}
136
137const char * proc_name (pid_t pid) {
138 static char ret[80] = "?";
139#ifdef __linux__
140 char file[80], buf[80], *r;
141 int  i;
142
143 snprintf(file, 79, "/proc/%i/exe", pid);
144 file[79] = 0;
145
146 ret[0] = '?';
147 ret[1] = 0;
148
149 if ( (i = readlink(file, buf, 79)) != -1 ) {
150  buf[i] = 0;
151  if ( (r = strrchr(buf, '/')) != NULL ) {
152   r++;
153   if ( *r != 0 )
154    strcpy(ret, r);
155  }
156 }
157#endif
158
159 return ret;
160}
161
162void list_clients (struct roar_connection * con) {
163 int i;
164 int num;
165 int h;
166 int id[ROAR_CLIENTS_MAX];
167 struct roar_client c;
168 struct group  * grp = NULL;
169 struct passwd * pwd = NULL;
170
171 if ( (num = roar_list_clients(con, id, ROAR_CLIENTS_MAX)) == -1 ) {
172  fprintf(stderr, "Error: can not get client list\n");
173  return;
174 }
175
176 for (i = 0; i < num; i++) {
177  printf("client %i:\n", id[i]);
178  if ( roar_get_client(con, &c, id[i]) == -1 ) {
179   fprintf(stderr, "Error: can not get client info\n");
180   continue;
181  }
182  printf("Player name           : %s\n", c.name);
183  printf("Player PID            : %i(%s)\n", c.pid, proc_name(c.pid));
184  if ( c.uid != -1 ) {
185   pwd = getpwuid(c.uid);
186   grp = getgrgid(c.gid);
187   printf("Player UID/GID        : %i(%s)/%i(%s)\n", c.uid, pwd ? pwd->pw_name : "?", c.gid, grp ? grp->gr_name : "?");
188  }
189  if ( c.execed != -1 )
190   printf("Execed stream         : %i\n", c.execed);
191
192  for (h = 0; h < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; h++)
193   if ( c.streams[h] != -1 )
194    printf("stream                : %i\n", c.streams[h]);
195 }
196
197}
198
199void list_streams (struct roar_connection * con) {
200 int i;
201 int num;
202 int id[ROAR_STREAMS_MAX];
203 struct roar_stream s;
204 struct roar_stream_info info;
205 char flags[1024];
206
207
208 if ( (num = roar_list_streams(con, id, ROAR_STREAMS_MAX)) == -1 ) {
209  fprintf(stderr, "Error: can not get stream list\n");
210  return;
211 }
212
213 for (i = 0; i < num; i++) {
214  printf("stream %i:\n", id[i]);
215  if ( roar_get_stream(con, &s, id[i]) == -1 ) {
216   fprintf(stderr, "Error: can not get stream info\n");
217   continue;
218  }
219  printf("Stream direction      : %s\n", roar_dir2str(s.dir));
220  if ( s.pos_rel_id == -1 ) {
221   printf("Relativ position id   : none (stream not synchronized)\n");
222  } else if ( s.pos_rel_id == id[i] ) {
223   printf("Relativ position id   : %i (self synchronized)\n", s.pos_rel_id);
224  } else {
225   printf("Relativ position id   : %i (synchronized)\n", s.pos_rel_id);
226  }
227  if ( g_verbose > 1 )
228   printf("Position              : %lu S (%.3fs)\n", (unsigned long int) s.pos, (float)s.pos/(s.info.rate*s.info.channels));
229  printf("Input rate            : %i\n", s.info.rate);
230  printf("Input bits            : %i\n", s.info.bits);
231  printf("Input channels        : %i\n", s.info.channels);
232  printf("Input codec           : %2i (%s%s)\n", s.info.codec, roar_codec2str(s.info.codec),
233                                       s.info.codec == ROAR_CODEC_DEFAULT ? " native" : "");
234  if ( roar_stream_get_info(con, &s, &info) != -1 ) {
235   printf("Input codec (streamed): %2i (%s%s)\n", info.codec, roar_codec2str(info.codec),
236                                      info.codec == ROAR_CODEC_DEFAULT ? " native" : "");
237   if ( g_verbose ) {
238    printf("Input block size      : %i Byte\n", info.block_size);
239    printf("Underruns pre/post    : %i/%i\n",   info.pre_underruns, info.post_underruns);
240    if ( g_verbose > 1 )
241     printf("Stream delay          : %ims\n",   (int)info.delay/1000);
242
243    *flags = 0;
244    if ( info.flags & ROAR_FLAG_PRIMARY )
245     strcat(flags, "primary ");
246    if ( info.flags & ROAR_FLAG_SYNC )
247     strcat(flags, "sync ");
248    if ( info.flags & ROAR_FLAG_OUTPUT )
249     strcat(flags, "output ");
250    if ( info.flags & ROAR_FLAG_SOURCE )
251     strcat(flags, "source ");
252    if ( info.flags & ROAR_FLAG_META )
253     strcat(flags, "meta ");
254    if ( info.flags & ROAR_FLAG_AUTOCONF )
255     strcat(flags, "autoconf ");
256    if ( info.flags & ROAR_FLAG_CLEANMETA )
257     strcat(flags, "cleanmeta ");
258    if ( info.flags & ROAR_FLAG_HWMIXER )
259     strcat(flags, "hwmixer ");
260    if ( info.flags & ROAR_FLAG_PAUSE )
261     strcat(flags, "pause ");
262
263    printf("Flags                 : %s\n", flags);
264   }
265  }
266  display_mixer(con, id[i]);
267  show_meta_all(con, id[i]);
268 }
269
270}
271
272int display_mixer (struct roar_connection * con, int stream) {
273 int channels;
274 struct roar_mixer_settings mixer;
275 int i;
276
277 if ( roar_get_vol(con, stream, &mixer, &channels) == -1 ) {
278  fprintf(stderr, "Error: can not get stream mixer info\n");
279  return -1;
280 }
281
282 for (i = 0; i < channels; i++)
283  printf("Mixer volume chan %2i  : %i (%.2f%%)\n", i, mixer.mixer[i], (float)mixer.mixer[i]/655.35);
284
285 return 0;
286}
287
288int set_mixer (struct roar_connection * con, int * cur, int max, char * arg[]) {
289 int chans = 0;
290 int id;
291 int i;
292 int len;
293 int old_chans;
294 int vol_l, vol_r;
295 char * k;
296 struct roar_mixer_settings mixer;
297 struct roar_mixer_settings old_mixer;
298
299 if (*cur + 2 > max)
300  return -1;
301
302 id = atoi(arg[++(*cur)]);
303
304 k = arg[++(*cur)];
305
306 if ( roar_get_vol(con, id, &old_mixer, &old_chans) == -1 ) {
307  fprintf(stderr, "Error: can not get stream mixer info\n");
308  return -1;
309 }
310
311
312// TODO: clean up code here as the % vs. abs code is very duplicate...
313
314 if ( strcmp(k, "mono") == 0 && old_chans != 1 ) {
315  chans = 1;
316
317  if ( *cur + 1 > max )
318   return -1;
319
320  k   = arg[++(*cur)];
321  len = strlen(k);
322
323  if ( k[len - 1] == '%' ) {
324   k[len - 1] = 0;
325   vol_l = (atof(k)*65535)/100;
326  } else {
327   vol_l = atoi(k);
328  }
329
330  for (i = 0; i < old_chans; i++)
331   mixer.mixer[i] = vol_l;
332
333  chans = old_chans;
334
335 } else if ( strcmp(k, "stereo") == 0 && old_chans == 4 ) {
336  chans = 4;
337
338  if ( *cur + 2 > max )
339   return -1;
340
341  k   = arg[++(*cur)];
342  len = strlen(k);
343
344  if ( k[len - 1] == '%' ) {
345   k[len - 1] = 0;
346   vol_l = (atof(k)*65535)/100;
347  } else {
348   vol_l = atoi(k);
349  }
350
351  k   = arg[++(*cur)];
352  len = strlen(k);
353
354  if ( k[len - 1] == '%' ) {
355   k[len - 1] = 0;
356   vol_r = (atof(k)*65535)/100;
357  } else {
358   vol_r = atoi(k);
359  }
360
361  mixer.mixer[0] = vol_l;
362  mixer.mixer[1] = vol_r;
363  mixer.mixer[2] = vol_l;
364  mixer.mixer[3] = vol_r;
365
366 } else if ( strcmp(k, "stereo") == 0 && old_chans != 2 ) {
367  chans = 2;
368//  printf("mode: stereo; chans=%i, old_chans=%i\n", chans, old_chans);
369  ROAR_ERR("mode stereo not supported");
370  return -1;
371 } else {
372  if ( strcmp(k, "mono") == 0 ) {
373   chans = 1;
374  } else if ( strcmp(k, "stereo") == 0 ) {
375   chans = 2;
376  } else {
377   chans = atoi(k);
378  }
379
380//  printf("mode: int; chans=%i, old_chans=%i\n", chans, old_chans);
381
382  if ( *cur + chans > max )
383   return -1;
384
385  for (i = 0; i < chans; i++) {
386   k   = arg[++(*cur)];
387   len = strlen(k);
388
389   if ( k[len - 1] == '%' ) {
390    k[len - 1] = 0;
391    mixer.mixer[i] = (atof(k)*(int)65535)/100;
392   } else {
393    mixer.mixer[i] = atoi(k);
394   }
395  }
396 }
397
398 mixer.scale = 65535;
399
400 return roar_set_vol(con, id, &mixer, chans);
401}
402
403int set_meta (struct roar_connection * con, int id, char * mode, char * type, char * val) {
404 struct roar_meta   meta;
405 struct roar_stream s;
406 int mode_i = ROAR_META_MODE_SET;
407
408 memset(&s, 0, sizeof(s));
409
410 s.id = id;
411
412// printf("set_meta(*): mode='%s', type='%s', val='%s'\n", mode, type, val);
413
414 if ( strcmp(mode, "add") == 0 ) {
415  mode_i = ROAR_META_MODE_ADD;
416 }
417
418 meta.type   = roar_meta_inttype(type);
419 meta.value  = val;
420 meta.key[0] = 0;
421
422 if ( meta.type == -1 ) {
423  fprintf(stderr, "Error: unknown type: %s\n", type);
424  return -1;
425 }
426
427// printf("D: type=%i, mode=%i\n", meta.type, mode_i);
428
429 if ( roar_stream_meta_set(con, &s, mode_i, &meta) == -1 )
430  return -1;
431
432 meta.type  = ROAR_META_TYPE_NONE;
433 meta.value = NULL;
434
435 return roar_stream_meta_set(con, &s, ROAR_META_MODE_FINALIZE, &meta);
436}
437
438int load_meta (struct roar_connection * con, int id, char * file) {
439 struct roar_meta   meta;
440 struct roar_stream s;
441 int mode_i = ROAR_META_MODE_SET;
442 FILE * in;
443 char lion[1024];
444 char * v;
445
446 memset(&s, 0, sizeof(s));
447
448 s.id = id;
449
450 if ( (in = fopen(file, "r")) == NULL )
451  return -1;
452
453 while (fgets(lion, 1024, in) != NULL) {
454  if ( (v = strtok(lion, "\r\n")) != NULL )
455   if ( (v = strtok(NULL, "\r\n")) != NULL )
456    *(v-1) = 0;
457
458  if ( (v = strstr(lion, "=")) == NULL ) {
459   fprintf(stderr, "Error: can not parse meta data lion: %s\n", lion);
460   continue;
461  }
462
463  *v++ = 0;
464
465  meta.type   = roar_meta_inttype(lion);
466  meta.value  = v;
467  meta.key[0] = 0;
468
469  if ( meta.type == -1 ) {
470   fprintf(stderr, "Error: unknown type: %s\n", lion);
471   continue;
472  }
473
474  if ( roar_stream_meta_set(con, &s, mode_i, &meta) == -1 )
475   return -1;
476 }
477
478 fclose(in);
479
480 meta.type  = ROAR_META_TYPE_NONE;
481 meta.value = NULL;
482
483 return roar_stream_meta_set(con, &s, ROAR_META_MODE_FINALIZE, &meta);
484}
485
486int show_meta_type (struct roar_connection * con, int id, char * type) {
487 struct roar_meta   meta;
488 struct roar_stream s;
489
490 memset(&s, 0, sizeof(s));
491
492 s.id = id;
493
494 meta.type  = roar_meta_inttype(type);
495
496 if ( meta.type == -1 ) {
497  fprintf(stderr, "Error: unknown type: %s\n", type);
498  return -1;
499 }
500
501 if ( roar_stream_meta_get(con, &s, &meta) == -1 )
502  return -1;
503
504 printf("Meta %-17s: %s\n", roar_meta_strtype(meta.type), meta.value);
505
506 roar_meta_free(&meta);
507
508 return 0;
509}
510
511int show_meta_all (struct roar_connection * con, int id) {
512 struct roar_stream s;
513 int types[ROAR_META_MAX_PER_STREAM];
514 int i;
515 int len;
516
517 memset(&s, 0, sizeof(s));
518
519 s.id = id;
520
521 if ( (len = roar_stream_meta_list(con, &s, types, ROAR_META_MAX_PER_STREAM)) == -1 )
522  return -1;
523
524 for (i = 0; i < len; i++)
525  show_meta_type(con, id, roar_meta_strtype(types[i]));
526
527 return 0;
528}
529
530int save_meta (struct roar_connection * con, int id, char * file) {
531 struct roar_stream s;
532 struct roar_meta   meta;
533 int types[ROAR_META_MAX_PER_STREAM];
534 int i;
535 int len;
536 FILE * out;
537
538 memset(&s, 0, sizeof(s));
539
540 s.id = id;
541
542 if ( (out = fopen(file, "w")) == NULL )
543  return -1;
544
545 if ( (len = roar_stream_meta_list(con, &s, types, ROAR_META_MAX_PER_STREAM)) == -1 )
546  return -1;
547
548 for (i = 0; i < len; i++) {
549/*
550  show_meta_type(con, id, roar_meta_strtype(types[i]));
551*/
552  meta.type  = types[i];
553
554  if ( roar_stream_meta_get(con, &s, &meta) == -1 )
555   continue;
556
557//  printf("Meta %-17s: %s\n", roar_meta_strtype(meta.type), meta.value);
558
559  fprintf(out, "%s=%s\n", roar_meta_strtype(meta.type), meta.value);
560
561  roar_meta_free(&meta);
562 }
563
564 fclose(out);
565
566 return 0;
567}
568
569int set_flags (struct roar_connection * con, int id, int reset, char * flags) {
570 int f = ROAR_FLAG_NONE;
571 char * c;
572 struct roar_stream s[1];
573
574 memset(s, 0, sizeof(struct roar_stream));
575
576 s->id = id;
577
578 c = strtok(flags, ",");
579 while (c != NULL) {
580  if ( !strcmp(c, "meta") ) {
581   f |= ROAR_FLAG_META;
582  } else if ( !strcmp(c, "primary") ) {
583   f |= ROAR_FLAG_PRIMARY;
584  } else if ( !strcmp(c, "sync") ) {
585   f |= ROAR_FLAG_SYNC;
586  } else if ( !strcmp(c, "cleanmeta") ) {
587   f |= ROAR_FLAG_CLEANMETA;
588  } else if ( !strcmp(c, "hwmixer") ) {
589   f |= ROAR_FLAG_HWMIXER;
590  } else if ( !strcmp(c, "pause") ) {
591   f |= ROAR_FLAG_PAUSE;
592  } else {
593   fprintf(stderr, "Error: unknown flag: %s\n", c);
594   return -1;
595  }
596
597  c = strtok(NULL, ",");
598 }
599
600 return roar_stream_set_flags(con, s, f, reset);
601}
602
603int main (int argc, char * argv[]) {
604 struct roar_connection con;
605 char * server   = NULL;
606 char * k = NULL;
607 int    i;
608 int    t = 0;
609
610 for (i = 1; i < argc; i++) {
611  k = argv[i];
612
613  if ( strcmp(k, "--server") == 0 ) {
614   server = argv[++i];
615  } else if ( strcmp(k, "-v") == 0 || strcmp(k, "--verbose") == 0 ) {
616   g_verbose++;
617  } else if ( strcmp(k, "--help") == 0 ) {
618   usage();
619   return 0;
620  } else if ( *k == '-' ) {
621   fprintf(stderr, "Error: unknown argument: %s\n", k);
622   usage();
623   return 1;
624  } else {
625   break;
626  }
627 }
628
629 // connect
630
631 if ( roar_connect(&con, server) == -1 ) {
632  fprintf(stderr, "Error: Can not connect to server\n");
633  return 1;
634 }
635
636 if ( roar_identify(&con, "roarctl") == -1 ) {
637  fprintf(stderr, "Error: Can not identify to server\n");
638  return 1;
639 }
640
641 if ( i == argc ) {
642  fprintf(stderr, "Error: No Commands given\n");
643  return 0; // this is not a fatal error...
644 }
645
646 for (; i < argc; i++) {
647  k = argv[i];
648  // cmd is in k
649
650  printf("--- [ %s ] ---\n", k);
651
652  if ( !strcmp(k, "help") ) {
653   usage();
654
655  } else if ( !strcmp(k, "sleep") ) {
656   sleep(atoi(argv[++i]));
657
658  } else if ( !strcmp(k, "ping") ) {
659   if ( ping(&con, atoi(argv[++i])) == -1 ) {
660    fprintf(stderr, "Error: can not ping\n");
661   }
662
663  } else if ( !strcmp(k, "standby") || !strcmp(k, "off") ) {
664   if ( roar_set_standby(&con, ROAR_STANDBY_ACTIVE) == -1 ) {
665    fprintf(stderr, "Error: can not set mode to standby\n");
666   } else {
667    printf("going into standby\n");
668   }
669  } else if ( !strcmp(k, "resume") || !strcmp(k, "on") ) {
670   if ( roar_set_standby(&con, ROAR_STANDBY_INACTIVE) == -1 ) {
671    fprintf(stderr, "Error: can not set mode to active\n");
672   } else {
673    printf("going into active mode\n");
674   }
675
676  } else if ( !strcmp(k, "exit") ) {
677   if ( roar_exit(&con) == -1 ) {
678    fprintf(stderr, "Error: can not quit server\n");
679   } else {
680    printf("Server quited\n");
681    break;
682   }
683  } else if ( !strcmp(k, "terminate") ) {
684   if ( roar_terminate(&con, 1) == -1 ) {
685    fprintf(stderr, "Error: can not terminate server\n");
686   } else {
687    printf("Server got asked to quited\n");
688    break;
689   }
690
691  } else if ( !strcmp(k, "standbymode") ) {
692   t = roar_get_standby(&con);
693   if ( t == -1 ) {
694    fprintf(stderr, "Error: can not get stanby mode\n");
695   } else if ( t == ROAR_STANDBY_ACTIVE ) {
696    printf("Server is in standby\n");
697   } else if ( t == ROAR_STANDBY_INACTIVE ) {
698    printf("Server is active\n");
699   } else {
700    fprintf(stderr, "Error: unknown standby mode: %i\n", t);
701   }
702
703  } else if ( !strcmp(k, "whoami") ) {
704   printf("My client ID is: %i\n", roar_get_clientid(&con));
705  } else if ( !strcmp(k, "serveroinfo") ) {
706   server_oinfo(&con);
707  } else if ( !strcmp(k, "listclients") ) {
708   list_clients(&con);
709  } else if ( !strcmp(k, "liststreams") ) {
710   list_streams(&con);
711  } else if ( !strcmp(k, "allinfo") ) {
712   server_oinfo(&con);
713   printf("\n");
714   list_clients(&con);
715   printf("\n");
716   list_streams(&con);
717
718  } else if ( !strcmp(k, "kick") ) {
719   k = argv[++i];
720   if ( !strcmp(k, "client") ) {
721    t = ROAR_OT_CLIENT;
722   } else if ( !strcmp(k, "stream") ) {
723    t = ROAR_OT_STREAM;
724   } else if ( !strcmp(k, "sample") ) {
725    t = ROAR_OT_SAMPLE;
726   } else if ( !strcmp(k, "source") ) {
727    t = ROAR_OT_SOURCE;
728   } else {
729    fprintf(stderr, "Error: unknown type: %s\n", k);
730    continue;
731   }
732   //t = atoi(argv[i++]);
733   if ( roar_kick(&con, t, atoi(argv[++i])) == -1 ) {
734    fprintf(stderr, "Error: can not kick %s\n", k);
735   } else {
736    printf("%s kicked\n", k);
737   }
738
739  } else if ( !strcmp(k, "volume") ) {
740   if ( set_mixer(&con, &i, argc, argv) == -1 ) {
741    fprintf(stderr, "Error: can not set volume\n");
742   } else {
743    printf("volume changed\n");
744   }
745
746  } else if ( !strcmp(k, "flag") ) {
747   i++;
748   if ( set_flags(&con, atoi(argv[i]), ROAR_SET_FLAG, argv[i+1]) == -1 ) {
749    fprintf(stderr, "Error: can not set flags\n");
750   } else {
751    printf("flags changed\n");
752   }
753   i++;
754  } else if ( !strcmp(k, "unflag") ) {
755   i++;
756   if ( set_flags(&con, atoi(argv[i]), ROAR_RESET_FLAG, argv[i+1]) == -1 ) {
757    fprintf(stderr, "Error: can not reset flags\n");
758   } else {
759    printf("flags changed\n");
760   }
761   i++;
762  } else if ( !strcmp(k, "metaset") ) {
763   i++;
764   if ( set_meta(&con, atoi(argv[i]), argv[i+1], argv[i+2], argv[i+3]) == -1 ) {
765    fprintf(stderr, "Error: can not set meta data\n");
766   } else {
767    printf("meta data changed\n");
768   }
769   i += 3;
770  } else if ( !strcmp(k, "metaget") ) {
771   i++;
772   if ( show_meta_type(&con, atoi(argv[i]), argv[i+1]) == -1 ) {
773    fprintf(stderr, "Error: can not get meta data\n");
774   }
775   i++;
776  } else if ( !strcmp(k, "metasave") ) {
777   i++;
778   if ( save_meta(&con, atoi(argv[i]), argv[i+1]) == -1 ) {
779    fprintf(stderr, "Error: can not get meta data\n");
780   } else {
781    printf("meta data saved\n");
782   }
783   i++;
784  } else if ( !strcmp(k, "metaload") ) {
785   i++;
786   if ( load_meta(&con, atoi(argv[i]), argv[i+1]) == -1 ) {
787    fprintf(stderr, "Error: can not set meta data\n");
788   } else {
789    printf("meta data saved\n");
790   }
791   i++;
792
793  } else {
794   fprintf(stderr, "Error: invalid command: %s\n", k);
795  }
796
797 }
798
799 roar_disconnect(&con);
800
801 return 0;
802}
803
804//ll
Note: See TracBrowser for help on using the repository browser.