source: roaraudio/roarclients/roarctl.c @ 5372:63f373fa5790

Last change on this file since 5372:63f373fa5790 was 5372:63f373fa5790, checked in by phi, 12 years ago

added support for ITST "build"

File size: 38.9 KB
Line 
1//roarctl.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2011
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, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
23 *
24 */
25
26/* ckport options:
27 * ckport: ignore-symbol: roar_req of target libroar0 -- Used within ping command.
28 */
29
30#define _UNITS_T_BASE_USEC
31
32#include <roaraudio.h>
33#include <roaraudio/units.h>
34#include <libroardsp/libroardsp.h>
35
36#if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_SETUID)
37#define _POSIX_USERS
38#endif
39
40#ifdef _POSIX_USERS
41#include <pwd.h>
42#include <grp.h>
43#endif
44
45#include <sys/time.h>
46#include <time.h>
47
48#ifdef ROAR_HAVE_LIBM
49#include <math.h>
50#endif
51
52int g_verbose = 0;
53
54void display_client (struct roar_connection * con, int id);
55void display_stream (struct roar_connection * con, int id);
56int display_mixer (struct roar_connection * con, int stream);
57int show_meta_all (struct roar_connection * con, int id);
58
59void usage (void) {
60 printf("roarctl [OPTIONS]... COMMAND [OPTS] [COMMAND [OPTS] [COMMAND [OPTS] [...]]]\n");
61
62 printf("\nOptions:\n\n");
63
64 printf("  --server SERVER         - Set server hostname\n"
65        "  --help                  - Show this help\n"
66        "  --verbose   -v          - Show verbose output\n"
67        "  --list-aiprofiles       - Show audio info profiles and exit\n"
68        "  --list-libstandards     - Gets list of library (libroar) supported standards\n"
69        "  --enum-servers          - Show a list of possible servers\n"
70        "  --hash-password         - Hash a password and exit\n"
71       );
72
73 printf("\nCommands:\n\n");
74 printf(
75        "  help                    - Show this help\n"
76        "  sleep TIME              - Sleeps for TIME seconds\n"
77#ifdef ROAR_HAVE_GETTIMEOFDAY
78        "  ping  NUM               - Do NUM pings using NOOP commands\n"
79#endif
80        "  whoami                  - Get own client ID\n"
81        "\n"
82        "  listaiprofiles          - list audio info profiles\n"
83        "  aiprofileget PROFILE    - show audio info profile PROFILE\n"
84        "\n"
85        "  standby, off            - Go into standby mode\n"
86        "  resume, on              - Go into active mode\n"
87        "  standbymode             - Show current standby mode\n"
88        "  exit                    - Quits the roard (must be used as last command)\n"
89        "  terminate               - Like exit but let the server up to serve still connected clients,\n"
90        "                            new clients cann't connect and the server terminates after the last\n"
91        "                            client disconnected\n"
92        "\n"
93        "  volume ID CHAN [scale S] V0 V1...\n"
94        "                          - Sets volume for stream ID\n"
95        "                            CHAN is the number of channels or 'mono' or 'stereo'\n"
96        "                            if mono or stereo is chosen roarctl trys to set\n"
97        "                            sensfull values for all channels even if the output\n"
98        "                            is has more channels.\n"
99        "                            An optional scale can be given using S.\n"
100        "                            all other args are the volumes of the channels\n"
101        "                            you may use integer or percent values.\n"
102        "                            percent values can floating points.\n"
103        "\n"
104        "  flag   ID FLAGS         - Sets flags FLAGS on stream ID. FLAGS may be a comma\n"
105        "                            separated list of flags.\n"
106        "  unflag ID FLAGS         - Unsets flags on a stream. See flag.\n"
107        "  toogleflag ID FLAGS     - Toggels flags on a stream. See flag.\n"
108        "  protectflag ID FLAGS    - Protects flags on a stream. Those flags can not be\n"
109        "                            changed anymore after the they got protected. See flag.\n"
110        "\n"
111        "  role ID ROLE            - Set role ROLE on stream ID.\n"
112        "\n"
113        "  kick TYPE ID            - Kicks object of TYPE with id ID\n"
114        "                            Types: client stream sample source\n"
115        "  newvirtual P D E R B C  - Adds a new virtual (child) stream\n"
116        "                            Parameters:\n"
117        "                             P: Parent stream ID, D: Direction,\n"
118        "                             E: codEc, R: sample Rate,\n"
119        "                             B: bits per sample, C: nummer of channels\n"
120        "\n"
121        "  metaget  ID TYPE        - Read meta date of type TYPE from stream ID\n"
122// TODO: document metaset here.
123        "  metasave ID FILE        - Saves meta data of stream ID to file FILE\n"
124        "  metaload ID FILE        - Loads meta data from file FILE and set it on stream ID\n"
125        "\n"
126        "  serverinfo              - Gets general information about the server\n"
127        "  servertime              - Gets server's time\n"
128        "  serveroinfo             - Gets Information about server output\n"
129        "  serveroinfo2 DIR        - Gets Information about server output for stream direction dir\n"
130        "\n"
131        "  serverstandards         - Gets list of server supported standards\n"
132        "  libstandards            - Gets list of library (libroar) supported standards\n"
133        "\n"
134        "  listclients             - Gets Information about clients\n"
135        "  clientinfo ID           - Gets Information about client ID\n"
136        "  liststreams             - Gets Information about streams\n"
137        "  streaminfo ID           - Gets Information about stream ID\n"
138        "  allinfo                 - Get all infos\n"
139       );
140}
141
142static void _bin2hex(char * out, char * in, size_t inlen, int uppercase) {
143 const char * tab = uppercase ? "0123456789ABCDEF" : "0123456789abcdef";
144 unsigned char c;
145 int nib0, nib1;
146
147 for (; inlen; inlen--) {
148  c = *(in++);
149  nib0 = (c & 0x0F) >> 0;
150  nib1 = (c & 0xF0) >> 4;
151//  printf("inlen=%zu, c=%u, nibs={%i, %i}\n", inlen, (unsigned)c, nib1, nib0);
152  *(out++) = tab[nib1];
153  *(out++) = tab[nib0];
154 }
155 *out = 0;
156}
157
158int hash_password (void) {
159 char * pw = NULL;
160 char salt[8];
161 char digest[24];
162 char out[2*(8+24)+3+5+1] = "tiger:";
163
164 if ( roar_passwd_simple_ask_pw(&pw, "Password to hash?", NULL) == -1 )
165  return -1;
166
167 roar_random_gen_nonce(salt, sizeof(salt));
168
169 roar_hash_salted_buffer(digest, pw, roar_mm_strlen(pw), ROAR_HT_TIGER, salt, sizeof(salt));
170
171 roar_mm_free(pw);
172
173 _bin2hex(out+6, salt, sizeof(salt), 0);
174 out[6+16] = ':';
175 _bin2hex(out+6+16+1, digest, sizeof(digest), 0);
176
177 out[sizeof(out)-1] = 0;
178
179 printf("Password: %s\n", out);
180
181 return 0;
182}
183
184int enum_servers (void) {
185 struct roar_server * list;
186 struct roar_server * c;
187 int flags    = ROAR_ENUM_FLAG_DESC|ROAR_ENUM_FLAG_LOCATION;
188 int dir      = -1;
189 int socktype = -1;
190 int i;
191
192 if ( (list = roar_enum_servers(flags, dir, socktype)) == NULL )
193  return -1;
194
195 printf("Server           Location         Description\n");
196 printf("----------------------------------------------------------------------\n");
197
198 for (i = 0; ; i++) {
199  c = &(list[i]);
200  printf("%-16s %-16s %s\n",
201             c->server      == NULL ? "(default)" : c->server,
202             c->location    == NULL ? ""          : c->location,
203             c->description == NULL ? ""          : c->description
204        );
205  if ( c->server == NULL )
206   break;
207 }
208
209 roar_enum_servers_free(list);
210
211 return 0;
212}
213
214#ifdef ROAR_HAVE_GETTIMEOFDAY
215int ping (struct roar_connection * con, int num) {
216 struct timeval         try, ans;
217 struct roar_message    m;
218 register int           ret;
219 int                    i;
220 double                 cur, min = 3600*1000, max = 0, sum = 0;
221
222 if ( num == 0 )
223  return 0;
224
225 for (i = 0; i < num; i++) {
226  memset(&m, 0, sizeof(m));
227
228  m.cmd = ROAR_CMD_NOOP;
229  m.stream  = -1;
230  m.datalen =  0;
231
232  // we use roar_req() directly here because of speed.
233  // roar_noop() does basicly the same but is a bit slower.
234
235  gettimeofday(&try, NULL);
236  ret = roar_req(con, &m, NULL);
237  gettimeofday(&ans, NULL);
238
239  if ( ret == -1 )
240   return -1;
241
242  while (ans.tv_sec > try.tv_sec) {
243   ans.tv_sec--;
244   ans.tv_usec += 1000000;
245  }
246  ans.tv_usec -= try.tv_usec;
247
248  printf("Pong from server: seq=%i time=%.3fms\n", i, (cur = ans.tv_usec/1000.0));
249
250  sum += cur;
251  if ( min > cur )
252   min = cur;
253  if ( cur > max )
254   max = cur;
255
256  if ( i != (num - 1) )
257   roar_sleep(1);
258 }
259
260 printf("\n--- ping statistics ---\n");
261 printf("%i packets transmitted\n", i);
262 printf("rtt min/avg/max = %.3f/%.3f/%.3f ms\n", min, sum/(double)i, max);
263
264 return 0;
265}
266#endif
267
268#define _pm(m,n) if ( info->m != NULL ) printf("Server %-15s: %s\n", (n), (info->m));
269void server_info (struct roar_connection * con) {
270 struct roar_server_info * info = roar_server_info(con);
271 long hostid;
272
273 if ( info == NULL ) {
274  fprintf(stderr, "Error: can not get server info\n");
275  return;
276 }
277
278 _pm(version, "Version");
279 _pm(location, "Location");
280 _pm(description, "Description");
281 _pm(contact, "Contact");
282 _pm(serial, "Serial");
283 _pm(address, "Address");
284 _pm(uiurl, "UI URL");
285 _pm(license, "License");
286// _pm(hostid, "HostID");
287 if ( info->hostid != NULL ) {
288  if ( sscanf(info->hostid, "0x%lx", &hostid) != 1 )
289   hostid = 0;
290
291  if ( hostid ) {
292   printf("Server %-15s: %s (%li.%li.%li.%li)\n", "HostID", info->hostid,
293           ((hostid & 0x00FF0000UL) >> 16UL),
294           ((hostid & 0xFF000000UL) >> 24UL),
295           ((hostid & 0x000000FFUL) >>  0UL),
296           ((hostid & 0x0000FF00UL) >>  8UL)
297         );
298  } else {
299   printf("Server %-15s: %s\n", "HostID", info->hostid);
300  }
301 }
302 _pm(build, "Build");
303 _pm(un.sysname, "System sysname");
304 _pm(un.release, "System release");
305 _pm(un.nodename, "System nodename");
306 _pm(un.machine, "System machine");
307
308 roar_server_info_free(info);
309}
310#undef _pm
311
312void server_time (struct roar_connection * con) {
313 struct roar_time time;
314
315 if ( roar_get_time(con, &time) == -1 ) {
316  fprintf(stderr, "Error: can not get server time: %s\n", roar_vs_strerr(roar_error));
317  return;
318 }
319
320 if ( g_verbose ) {
321  printf("Server time           : %llu.%06llu [+%llu/2^64] sec\n",
322         (long long unsigned int)time.t_sec,
323         (long long unsigned int) time.t_ssec / 18446744073709LLU,
324         (long long unsigned int) time.t_ssec);
325 } else {
326  if ( time.c_freq == 1000000000LL && time.t_ssec == 0 ) {
327   printf("Server time           : %llu sec\n",
328          (long long unsigned int)time.t_sec);
329  } else {
330   printf("Server time           : %llu.%06llu sec\n",
331          (long long unsigned int)time.t_sec,
332          (long long unsigned int) time.t_ssec / 18446744073709LLU);
333  }
334 }
335 if ( time.c_freq )
336  printf("Server clock frequency: %f Hz\n", (float)((double)time.c_freq / (double)1000000000.));
337 if ( time.c_drift ) {
338#ifdef ROAR_HAVE_LIBM
339  printf("Server clock drift    : %llu:2^64 (~10^%f)\n",
340         (long long unsigned int)time.c_drift, logf((float)time.c_drift)/2.302585f);
341#else
342  printf("Server clock drift    : %llu:2^64\n",
343         (long long unsigned int)time.c_drift);
344#endif
345 }
346}
347
348void server_oinfo (struct roar_connection * con, int dir) {
349 struct roar_stream s;
350
351 if ( roar_server_oinfo(con, &s, dir) == -1 ) {
352  fprintf(stderr, "Error: can not get server output info\n");
353  return;
354 }
355
356 printf("Stream direction      : %s\n", roar_dir2str(s.dir));
357 printf("Server Output rate    : %i Hz\n", s.info.rate);
358 printf("Server Output bits    : %i\n", s.info.bits);
359 printf("Server Output channels: %i\n", s.info.channels);
360 printf("Server Output codec   : %i (%s%s)\n", s.info.codec, roar_codec2str(s.info.codec),
361                                     s.info.codec == ROAR_CODEC_DEFAULT ? " native" : "");
362// printf("Server Output rate: %i", s.info.rate);
363  if ( g_verbose > 1 && s.pos != (uint32_t)-1 )
364   printf("Server Position       : %lu S (%.3fs)\n", (unsigned long int) s.pos, (float)s.pos/(s.info.rate*s.info.channels));
365}
366
367static void print_stds (const struct roar_stds * stds) {
368 size_t i;
369 int vendor, standard, version;
370 char numbuf[2][8];
371 const char * vendor_name;
372
373 for (i = 0; i < stds->stds_len; i++) {
374  vendor   = ROAR_STD_VENDOR(stds->stds[i]);
375  standard = ROAR_STD_STD(stds->stds[i]);
376  version  = ROAR_STD_VERSION(stds->stds[i]);
377
378  if ( (vendor_name = roar_stds_vendor2str(vendor)) == NULL ) {
379   snprintf(numbuf[0], sizeof(numbuf[0]), "%i", vendor);
380   numbuf[0][sizeof(numbuf[0])-1] = 0;
381   vendor_name = numbuf[0];
382  }
383
384  if ( version == 0 ) {
385   numbuf[1][0] = 0;
386  } else {
387   snprintf(numbuf[1], sizeof(numbuf[1]), "-%i", version);
388   numbuf[1][sizeof(numbuf[1])-1] = 0;
389  }
390
391  printf("Server standard       : %s-%i%s\n", vendor_name, standard, numbuf[1]);
392 }
393}
394
395void server_standards (struct roar_connection * con) {
396 struct roar_stds * stds;
397
398 if ( roar_caps_stds(con, &stds, NULL, -1) == -1 ) {
399  fprintf(stderr, "Error: can not get server standards\n");
400  return;
401 }
402
403 print_stds(stds);
404
405 roar_stds_free(stds);
406}
407
408void lib_standards (void) {
409 print_stds(libroar_libstds());
410}
411
412const char * proc_name (pid_t pid) {
413 static char ret[80] = "?";
414#ifdef __linux__
415 char file[80], buf[80], *r;
416 int  i;
417
418 snprintf(file, sizeof(file)-1, "/proc/%i/exe", pid);
419 file[sizeof(file)-1] = 0;
420
421 ret[0] = '?';
422 ret[1] = 0;
423
424 if ( (i = readlink(file, buf, sizeof(buf)-1)) != -1 ) {
425  buf[i] = 0;
426  if ( (r = strrchr(buf, '/')) != NULL ) {
427   r++;
428   if ( *r != 0 ) {
429    strncpy(ret, r, sizeof(ret)-1);
430    ret[sizeof(ret)-1] = 0;
431   }
432  }
433 }
434#else
435 (void)pid;
436#endif
437
438 return ret;
439}
440
441void list_clients (struct roar_connection * con) {
442 int i;
443 int num;
444 int id[ROAR_CLIENTS_MAX];
445
446 if ( (num = roar_list_clients(con, id, ROAR_CLIENTS_MAX)) == -1 ) {
447  fprintf(stderr, "Error: can not get client list\n");
448  return;
449 }
450
451 for (i = 0; i < num; i++) {
452  display_client(con, id[i]);
453 }
454}
455
456void display_client (struct roar_connection * con, int id) {
457 static int self_id = -1;
458 static struct roar_client   self_client_store;
459 static struct roar_client * self_client = NULL;
460 struct roar_client c;
461 char tmp[80];
462 int h;
463#ifdef _POSIX_USERS
464 struct group  * grp = NULL;
465 struct passwd * pwd = NULL;
466#endif
467
468 if ( self_id == -1 ) {
469  if ( (self_id = roar_get_clientid(con)) != -1 ) {
470   if ( roar_get_client(con, &self_client_store, self_id) == -1 ) {
471    self_id = -1;
472   } else {
473    self_client = &self_client_store;
474   }
475  }
476 }
477
478 printf("client %i:\n", id);
479 if ( roar_get_client(con, &c, id) == -1 ) {
480  fprintf(stderr, "Error: can not get client info\n");
481  return;
482 }
483
484 if ( c.name[0] != '\0' )
485  printf("Client name           : %s\n", c.name);
486  if ( roar_nnode_get_socktype(&(c.nnode)) != ROAR_SOCKET_TYPE_UNKNOWN ) {
487  if ( roar_nnode_to_str(&(c.nnode), tmp, sizeof(tmp)) == 0 ) {
488   printf("Client network node   : %s\n", tmp);
489  }
490 }
491
492 if ( c.pid != -1 ) {
493  if ( self_id != -1 && roar_nnode_cmp(&(self_client->nnode), &(c.nnode)) == 0 ) {
494   printf("Client PID            : %i(%s)\n", c.pid, proc_name(c.pid));
495  } else {
496   printf("Client PID            : %i\n", c.pid);
497  }
498 }
499 if ( c.uid != -1 ) {
500#ifdef _POSIX_USERS
501  if ( self_id != -1 && roar_nnode_cmp(&(self_client->nnode), &(c.nnode)) == 0 ) {
502   pwd = getpwuid(c.uid);
503   grp = getgrgid(c.gid);
504   printf("Client UID/GID        : %i(%s)/%i(%s)\n", c.uid, pwd ? pwd->pw_name : "?", c.gid, grp ? grp->gr_name : "?");
505  } else {
506#else
507  if ( 1 ) {
508#endif
509   printf("Client UID/GID        : %i/%i\n", c.uid, c.gid);
510  }
511 }
512
513 if ( g_verbose && c.proto != ROAR_PROTO_NONE ) {
514  printf("Client Protocol       : %s\n", roar_proto2str(c.proto));
515 }
516
517 if ( g_verbose && c.byteorder != ROAR_BYTEORDER_UNKNOWN ) {
518  if ( c.byteorder == ROAR_BYTEORDER_NETWORK ) {
519   roar_mm_strscpy(tmp, " (network byteorder");
520  } else {
521   *tmp = 0;
522  }
523
524  if ( c.byteorder == ROAR_BYTEORDER_NATIVE ) {
525   if ( *tmp ) {
526    roar_mm_strscat(tmp, ", native");
527   } else {
528    roar_mm_strscpy(tmp, " (native");
529   }
530  }
531
532  if ( *tmp )
533   roar_mm_strscat(tmp, ")");
534
535  printf("Client Byteorder      : %s%s\n", roar_byteorder2str(c.byteorder), tmp);
536 }
537
538 if ( c.execed != -1 )
539  printf("Execed stream         : %i\n", c.execed);
540
541 for (h = 0; h < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; h++)
542  if ( c.streams[h] != -1 )
543   printf("stream                : %i\n", c.streams[h]);
544}
545
546void list_streams (struct roar_connection * con) {
547 int i;
548 int num;
549 int id[ROAR_STREAMS_MAX];
550
551 if ( (num = roar_list_streams(con, id, ROAR_STREAMS_MAX)) == -1 ) {
552  fprintf(stderr, "Error: can not get stream list\n");
553  return;
554 }
555
556 for (i = 0; i < num; i++) {
557  display_stream(con, id[i]);
558 }
559}
560
561void display_stream (struct roar_connection * con, int id) {
562 char chanmap[ROAR_MAX_CHANNELS];
563 struct roar_stream s;
564 struct roar_stream_info info;
565 char buffer[1024];
566 char * flags = buffer;
567 char * name  = buffer;
568 char * infotext;
569 const char * mime;
570 size_t len;
571
572 printf("stream %i:\n", id);
573 if ( roar_get_stream(con, &s, id) == -1 ) {
574  fprintf(stderr, "Error: can not get stream info\n");
575  return;
576 }
577 printf("Stream direction      : %s\n", roar_dir2str(s.dir));
578
579 if ( roar_stream_get_name(con, &s, name, sizeof(buffer)) == 0 )
580  printf("Stream name           : %s\n", name);
581
582 if ( (int)s.pos_rel_id == -1 ) {
583  printf("Relativ position id   : none (stream not synchronized)\n");
584 } else if ( (int)s.pos_rel_id == id ) {
585  printf("Relativ position id   : %i (self synchronized)\n", s.pos_rel_id);
586 } else {
587  printf("Relativ position id   : %i (synchronized)\n", s.pos_rel_id);
588 }
589 if ( g_verbose > 1 && s.pos != (uint32_t)-1 ) {
590  if ( s.info.rate && s.info.channels ) {
591   printf("Position              : %lu S (%.3fs)\n", (unsigned long int) s.pos,
592                                   (float)s.pos/(s.info.rate*s.info.channels));
593  } else {
594   printf("Position              : %lu S\n", (unsigned long int) s.pos);
595  }
596 }
597
598 switch (s.dir) {
599  case ROAR_DIR_MIDI_IN:
600  case ROAR_DIR_MIDI_OUT:
601    infotext = " ticks/s";
602   break;
603  case ROAR_DIR_LIGHT_IN:
604  case ROAR_DIR_LIGHT_OUT:
605    infotext = " updates/s";
606   break;
607  default:
608    infotext = " Hz";
609 }
610 if ( s.info.rate )
611  printf("Stream sample rate    : %i%s\n", s.info.rate, infotext);
612 if ( s.info.bits )
613  printf("Stream bits           : %i\n", s.info.bits);
614 if ( s.info.channels )
615  printf("Stream channels       : %i\n", s.info.channels);
616
617 mime = roar_codec2mime(s.info.codec);
618 printf("Stream codec          : %2i (%s%s%s%s)\n", s.info.codec, roar_codec2str(s.info.codec),
619                                      s.info.codec == ROAR_CODEC_DEFAULT ? " native" : "",
620                                      mime == NULL ? "" : " mimetype:",
621                                      mime == NULL ? "" : mime
622                                     );
623 if ( roar_stream_get_info(con, &s, &info) != -1 ) {
624  if ( info.codec != s.info.codec ) {
625   mime = roar_codec2mime(info.codec);
626   printf("Streamed codec        : %2i (%s%s%s%s)\n", info.codec, roar_codec2str(info.codec),
627                                      info.codec == ROAR_CODEC_DEFAULT ? " native" : "",
628                                      mime == NULL ? "" : " mimetype:",
629                                      mime == NULL ? "" : mime
630                                     );
631  }
632
633  if ( g_verbose ) {
634   if ( info.block_size )
635    printf("Stream block size     : %i Byte\n", info.block_size);
636
637   printf("Underruns pre/post    : %i/%i\n",   info.pre_underruns, info.post_underruns);
638   if ( g_verbose > 1 )
639    printf("Stream delay          : %ims (%.2fm)\n",   (int)info.delay/1000, (info.delay*(float)_SPEED_OF_SOUND));
640
641   if ( g_verbose > 1 )
642    printf("Stream mixer          : %i\n",   info.mixer);
643
644   if ( g_verbose > 1 )
645    printf("Stream state          : %s\n",   roar_streamstate2str(info.state));
646
647   if ( g_verbose > 1 )
648    printf("Stream role           : %s\n",   roar_role2str(info.role));
649
650   *flags = 0;
651#define _strcat(dst,src) roar_mm_strlcat((dst),(src), sizeof(buffer))
652   if ( info.flags & ROAR_FLAG_PRIMARY )
653    _strcat(flags, "primary ");
654   if ( info.flags & ROAR_FLAG_SYNC )
655    _strcat(flags, "sync ");
656   if ( info.flags & ROAR_FLAG_OUTPUT )
657    _strcat(flags, "output ");
658   if ( info.flags & ROAR_FLAG_SOURCE )
659    _strcat(flags, "source ");
660   if ( info.flags & ROAR_FLAG_META )
661    _strcat(flags, "meta ");
662   if ( info.flags & ROAR_FLAG_AUTOCONF )
663    _strcat(flags, "autoconf ");
664   if ( info.flags & ROAR_FLAG_CLEANMETA )
665    _strcat(flags, "cleanmeta ");
666   if ( info.flags & ROAR_FLAG_HWMIXER )
667    _strcat(flags, "hwmixer ");
668   if ( info.flags & ROAR_FLAG_PAUSE )
669    _strcat(flags, "pause ");
670   if ( info.flags & ROAR_FLAG_MUTE )
671    _strcat(flags, "mute ");
672   if ( info.flags & ROAR_FLAG_MMAP )
673    _strcat(flags, "mmap ");
674   if ( info.flags & ROAR_FLAG_ANTIECHO )
675    _strcat(flags, "antiecho ");
676   if ( info.flags & ROAR_FLAG_VIRTUAL )
677    _strcat(flags, "virtual ");
678   if ( info.flags & ROAR_FLAG_RECSOURCE )
679    _strcat(flags, "recsource ");
680   if ( info.flags & ROAR_FLAG_PASSMIXER )
681    _strcat(flags, "passmixer ");
682   if ( info.flags & ROAR_FLAG_PRETHRU )
683    _strcat(flags, "prethru ");
684   if ( info.flags & ROAR_FLAG_IMMUTABLE )
685    _strcat(flags, "immutable ");
686   if ( info.flags & ROAR_FLAG_ENHANCE )
687    _strcat(flags, "enhance ");
688   if ( info.flags & ROAR_FLAG_SINGLESINK )
689    _strcat(flags, "singlesink ");
690#undef _strcat
691
692   printf("Flags                 : %s\n", flags);
693  }
694 }
695
696 if ( g_verbose ) {
697  len = ROAR_MAX_CHANNELS;
698  if ( roar_stream_get_chanmap(con, &s, chanmap, &len) == -1 ) {
699   fprintf(stderr, "Error: can not get stream channel map\n");
700  } else {
701   if ( roardsp_chanlist2str(chanmap, len, buffer, 1024) == -1 ) {
702    fprintf(stderr, "Error: can not convert channel map into string\n");
703   } else {
704    printf("Channel Map           : %s\n", buffer);
705   }
706  }
707 }
708
709 if ( s.dir != ROAR_DIR_THRU ) {
710  display_mixer(con, id);
711  show_meta_all(con, id);
712 }
713}
714
715int display_mixer (struct roar_connection * con, int stream) {
716 struct roar_mixer_settings mixer;
717 int channels;
718 int i;
719 float fs;
720
721 if ( roar_get_vol(con, stream, &mixer, &channels) == -1 ) {
722  fprintf(stderr, "Error: can not get stream mixer info for stream %i\n", stream);
723  return -1;
724 }
725
726#ifdef ROAR_HAVE_LIBM
727#define _DB ", %.2fdB"
728#else
729#define _DB ""
730#endif
731
732 fs = (float)mixer.scale / 100.;
733
734 if ( channels ) { // we hide RPG info for zero-channel streams
735  printf("Mixer ReplayGain      : %i/%i (%.2f%%" _DB ")\n", mixer.rpg_mul, mixer.rpg_div,
736                                                          100.*(float)mixer.rpg_mul/((float)mixer.rpg_div)
737#ifdef ROAR_HAVE_LIBM
738                           , 20*log10f((float)mixer.rpg_mul/(float)mixer.rpg_div)
739#endif
740        );
741 }
742
743 for (i = 0; i < channels; i++)
744  printf("Mixer volume chan %2i  : %i/%i (%.2f%%" _DB ")\n", i, mixer.mixer[i], mixer.scale,
745                           (float)mixer.mixer[i]/fs
746#ifdef ROAR_HAVE_LIBM
747                          , 20*log10f((float)mixer.mixer[i]/(float)mixer.scale)
748#endif
749        );
750
751 return 0;
752}
753
754static unsigned int set_mixer_parse_volume (char * k, int len, uint16_t scale) {
755 float fs = scale;
756
757 switch (k[len - 1]) {
758  case '%':
759    k[len - 1] = 0;
760    return (atof(k)*fs)/100.;
761   break;
762#ifdef ROAR_HAVE_LIBM
763  case 'b':
764  case 'B':
765    // TODO: can we hanle the error better?
766    if ( len < 2 )
767     return 0;
768
769    k[len - 2] = 0;
770    return powf(10, atof(k)/20.f)*fs;
771   break;
772#endif
773 }
774
775 return atoi(k);
776}
777
778int set_mixer (struct roar_connection * con, int * cur, int max, char * arg[]) {
779 uint16_t scale = 65535;
780 int chans = 0;
781 int id;
782 int i;
783 int len;
784 int old_chans;
785 char * k;
786 struct roar_mixer_settings mixer;
787 struct roar_mixer_settings old_mixer;
788 int mode = ROAR_SET_VOL_ALL;
789
790 if (*cur + 2 > max)
791  return -1;
792
793 id = atoi(arg[++(*cur)]);
794
795 k = arg[++(*cur)];
796
797 if ( !strcmp(arg[*cur + 1], "scale") ) {
798  (*cur)++; // 'scale'
799  (*cur)++;
800  scale = set_mixer_parse_volume(arg[*cur], strlen(arg[*cur]), 65535);
801 }
802
803 mixer.scale = scale;
804
805 if ( roar_get_vol(con, id, &old_mixer, &old_chans) == -1 ) {
806  fprintf(stderr, "Error: can not get stream mixer info for stream %i\n", id);
807  return -1;
808 }
809
810 if ( strcmp(k, "mono") == 0 ) {
811  chans = 1;
812  mode  = ROAR_SET_VOL_UNMAPPED;
813 } else if ( strcmp(k, "stereo") == 0 ) {
814  chans = 2;
815  mode  = ROAR_SET_VOL_UNMAPPED;
816 } else {
817  chans = atoi(k);
818 }
819
820 // ensure most simple mode:
821 if ( old_chans == chans && mode == ROAR_SET_VOL_UNMAPPED )
822  mode = ROAR_SET_VOL_ALL;
823
824 if ( *cur + chans > max )
825  return -1;
826
827 for (i = 0; i < chans; i++) {
828  k   = arg[++(*cur)];
829  len = strlen(k);
830
831  mixer.mixer[i] = set_mixer_parse_volume(k, len, scale);
832 }
833
834 if ( roar_set_vol(con, id, &mixer, chans, mode) == 0 )
835  return 0;
836
837 // no fallback if already using ROAR_SET_VOL_ALL:
838 if ( mode == ROAR_SET_VOL_ALL )
839  return -1;
840
841 if ( roar_conv_volume(&mixer, &mixer, old_chans, chans) == -1 )
842  return -1;
843
844 chans = old_chans;
845 mode  = ROAR_SET_VOL_ALL;
846
847 if ( roar_set_vol(con, id, &mixer, chans, mode) == 0 )
848  return 0;
849
850 return -1;
851}
852
853
854int newvirtual (struct roar_connection * con, char *p_s, char *d_s, char *e_s, char *r_s, char *b_s, char *c_s) {
855 struct roar_stream s;
856 int dir    = roar_str2dir(d_s);
857 int parent = atoi(p_s);
858
859 ROAR_DBG("newvirtual(*): dir=%i, parent=%i", dir, parent);
860
861 if ( roar_stream_new(&s, atoi(r_s), atoi(c_s), atoi(b_s), roar_str2codec(e_s)) == -1 )
862  return -1;
863
864 return roar_simple_connect_virtual(con, &s, parent, dir);
865}
866
867int set_meta (struct roar_connection * con, int id, char * mode, char * type, char * val) {
868 struct roar_meta   meta;
869 struct roar_stream s;
870 int mode_i = ROAR_META_MODE_SET;
871
872 if ( roar_stream_new_by_id(&s, id) == -1 )
873  return -1;
874
875// printf("set_meta(*): mode='%s', type='%s', val='%s'\n", mode, type, val);
876
877 if ( strcmp(mode, "add") == 0 ) {
878  mode_i = ROAR_META_MODE_ADD;
879 }
880
881 meta.type   = roar_meta_inttype(type);
882 meta.value  = val;
883 meta.key[0] = 0;
884
885 if ( meta.type == -1 ) {
886  fprintf(stderr, "Error: unknown type: %s\n", type);
887  return -1;
888 }
889
890// printf("D: type=%i, mode=%i\n", meta.type, mode_i);
891
892 if ( roar_stream_meta_set(con, &s, mode_i, &meta) == -1 )
893  return -1;
894
895 meta.type  = ROAR_META_TYPE_NONE;
896 meta.value = NULL;
897
898 return roar_stream_meta_set(con, &s, ROAR_META_MODE_FINALIZE, &meta);
899}
900
901int load_meta (struct roar_connection * con, int id, char * file) {
902 struct roar_meta   meta;
903 struct roar_stream s;
904 int mode_i = ROAR_META_MODE_SET;
905 FILE * in;
906 char lion[1024];
907 char * v;
908
909 if ( roar_stream_new_by_id(&s, id) == -1 )
910  return -1;
911
912 if ( (in = fopen(file, "r")) == NULL )
913  return -1;
914
915 while (fgets(lion, 1024, in) != NULL) {
916  if ( (v = strtok(lion, "\r\n")) != NULL )
917   if ( (v = strtok(NULL, "\r\n")) != NULL )
918    *(v-1) = 0;
919
920  if ( (v = strstr(lion, "=")) == NULL ) {
921   fprintf(stderr, "Error: can not parse meta data lion: %s\n", lion);
922   continue;
923  }
924
925  *v++ = 0;
926
927  meta.type   = roar_meta_inttype(lion);
928  meta.value  = v;
929  meta.key[0] = 0;
930
931  if ( meta.type == -1 ) {
932   fprintf(stderr, "Error: unknown type: %s\n", lion);
933   continue;
934  }
935
936  if ( roar_stream_meta_set(con, &s, mode_i, &meta) == -1 ) {
937   fclose(in);
938   return -1;
939  }
940 }
941
942 fclose(in);
943
944 meta.type  = ROAR_META_TYPE_NONE;
945 meta.value = NULL;
946
947 return roar_stream_meta_set(con, &s, ROAR_META_MODE_FINALIZE, &meta);
948}
949
950int show_meta_type (struct roar_connection * con, int id, char * type) {
951 struct roar_meta   meta;
952 struct roar_stream s;
953
954 if ( roar_stream_new_by_id(&s, id) == -1 )
955  return -1;
956
957 meta.type  = roar_meta_inttype(type);
958
959 if ( meta.type == -1 ) {
960  fprintf(stderr, "Error: unknown type: %s\n", type);
961  return -1;
962 }
963
964 if ( roar_stream_meta_get(con, &s, &meta) == -1 )
965  return -1;
966
967 printf("Meta %-17s: %s\n", roar_meta_strtype(meta.type), meta.value);
968
969 roar_meta_free(&meta);
970
971 return 0;
972}
973
974int show_meta_all (struct roar_connection * con, int id) {
975 struct roar_stream s;
976 int types[ROAR_META_MAX_PER_STREAM];
977 int i;
978 int len;
979
980 if ( roar_stream_new_by_id(&s, id) == -1 )
981  return -1;
982
983 if ( (len = roar_stream_meta_list(con, &s, types, ROAR_META_MAX_PER_STREAM)) == -1 )
984  return -1;
985
986 for (i = 0; i < len; i++)
987  show_meta_type(con, id, roar_meta_strtype(types[i]));
988
989 return 0;
990}
991
992int save_meta (struct roar_connection * con, int id, char * file) {
993 struct roar_stream s;
994 struct roar_meta   meta;
995 int types[ROAR_META_MAX_PER_STREAM];
996 int i;
997 int len;
998 FILE * out;
999
1000 if ( roar_stream_new_by_id(&s, id) == -1 )
1001  return -1;
1002
1003 if ( (len = roar_stream_meta_list(con, &s, types, ROAR_META_MAX_PER_STREAM)) == -1 )
1004  return -1;
1005
1006 if ( (out = fopen(file, "w")) == NULL )
1007  return -1;
1008
1009 for (i = 0; i < len; i++) {
1010/*
1011  show_meta_type(con, id, roar_meta_strtype(types[i]));
1012*/
1013  meta.type  = types[i];
1014
1015  if ( roar_stream_meta_get(con, &s, &meta) == -1 )
1016   continue;
1017
1018//  printf("Meta %-17s: %s\n", roar_meta_strtype(meta.type), meta.value);
1019
1020  fprintf(out, "%s=%s\n", roar_meta_strtype(meta.type), meta.value);
1021
1022  roar_meta_free(&meta);
1023 }
1024
1025 fclose(out);
1026
1027 return 0;
1028}
1029
1030int set_flags (struct roar_connection * con, int id, int action, char * flags) {
1031 uint32_t f = ROAR_FLAG_NONE;
1032 char * c;
1033 struct roar_stream s[1];
1034
1035 if ( roar_stream_new_by_id(s, id) == -1 )
1036  return -1;
1037
1038 c = strtok(flags, ",");
1039 while (c != NULL) {
1040  if ( !strcmp(c, "meta") ) {
1041   f |= ROAR_FLAG_META;
1042  } else if ( !strcmp(c, "primary") ) {
1043   f |= ROAR_FLAG_PRIMARY;
1044  } else if ( !strcmp(c, "sync") ) {
1045   f |= ROAR_FLAG_SYNC;
1046  } else if ( !strcmp(c, "cleanmeta") ) {
1047   f |= ROAR_FLAG_CLEANMETA;
1048  } else if ( !strcmp(c, "hwmixer") ) {
1049   f |= ROAR_FLAG_HWMIXER;
1050  } else if ( !strcmp(c, "pause") ) {
1051   f |= ROAR_FLAG_PAUSE;
1052  } else if ( !strcmp(c, "mute") ) {
1053   f |= ROAR_FLAG_MUTE;
1054  } else if ( !strcmp(c, "mmap") ) {
1055   f |= ROAR_FLAG_MMAP;
1056  } else if ( !strcmp(c, "antiecho") ) {
1057   f |= ROAR_FLAG_ANTIECHO;
1058  } else if ( !strcmp(c, "recsource") ) {
1059   f |= ROAR_FLAG_RECSOURCE;
1060  } else if ( !strcmp(c, "passmixer") ) {
1061   f |= ROAR_FLAG_PASSMIXER;
1062  } else if ( !strcmp(c, "virtual") ) {
1063   f |= ROAR_FLAG_VIRTUAL;
1064  } else if ( !strcmp(c, "prethru") ) {
1065   f |= ROAR_FLAG_PRETHRU;
1066  } else if ( !strcmp(c, "immutable") ) {
1067   f |= ROAR_FLAG_IMMUTABLE;
1068  } else if ( !strcmp(c, "enhance") ) {
1069   f |= ROAR_FLAG_ENHANCE;
1070  } else if ( !strcmp(c, "singlesink") ) {
1071   f |= ROAR_FLAG_SINGLESINK;
1072  } else {
1073   fprintf(stderr, "Error: unknown flag: %s\n", c);
1074   return -1;
1075  }
1076
1077  c = strtok(NULL, ",");
1078 }
1079
1080 return roar_stream_set_flags(con, s, f, action);
1081}
1082
1083int set_role (struct roar_connection * con, int id, int role) {
1084 struct roar_stream s;
1085
1086 if ( id == -1 )
1087  return -1;
1088
1089 if ( roar_stream_new_by_id(&s, id) == -1 )
1090  return -1;
1091
1092 if ( roar_stream_set_role(con, &s, role) == -1 )
1093  return -1;
1094
1095 return 0;
1096}
1097
1098int show_aiprofile (const char * profile) {
1099 struct roar_audio_info info;
1100 const char * mime;
1101
1102 if ( roar_profile2info(&info, profile) == -1 ) {
1103  fprintf(stderr, "Error: unknown profile: %s\n", profile);
1104  return -1;
1105 }
1106
1107 mime = roar_codec2mime(info.codec);
1108
1109 printf("Profile Name          : %s\n", profile);
1110
1111 if ( info.rate )
1112  printf("Profile sample rate   : %i\n", info.rate);
1113 if ( info.bits )
1114  printf("Profile bits          : %i\n", info.bits);
1115 if ( info.channels )
1116  printf("Profile channels      : %i\n", info.channels);
1117
1118 printf("Profile codec         : %2i (%s%s%s%s)\n", info.codec, roar_codec2str(info.codec),
1119                                       info.codec == ROAR_CODEC_DEFAULT ? " native" : "",
1120                                       mime == NULL ? "" : " mimetype:",
1121                                       mime == NULL ? "" : mime);
1122
1123 return 0;
1124}
1125
1126int list_aiprofiles (void) {
1127 const char * list[1024];
1128 ssize_t ret;
1129 ssize_t i;
1130
1131 ret = roar_profiles_list(list, 1024, 0);
1132
1133 if ( ret == -1 ) {
1134  fprintf(stderr, "Error: can not read list of profiles\n");
1135  return -1;
1136 }
1137
1138 for (i = 0; i < ret; i++) {
1139  printf("profile %lli:\n", (long long signed int)i);
1140  show_aiprofile(list[i]);
1141 }
1142
1143 return 0;
1144}
1145
1146int main (int argc, char * argv[]) {
1147 struct roar_connection con;
1148 char * server   = NULL;
1149 char * k = NULL;
1150 int    i;
1151 int    t = 0;
1152
1153 for (i = 1; i < argc; i++) {
1154  k = argv[i];
1155
1156  if ( strcmp(k, "--server") == 0 ) {
1157   server = argv[++i];
1158  } else if ( strcmp(k, "-v") == 0 || strcmp(k, "--verbose") == 0 ) {
1159   g_verbose++;
1160  } else if ( strcmp(k, "--help") == 0 ) {
1161   usage();
1162   return 0;
1163  } else if ( strcmp(k, "--list-aiprofiles") == 0 ) {
1164   list_aiprofiles();
1165   return 0;
1166  } else if ( strcmp(k, "--list-libstandards") == 0 ) {
1167   lib_standards();
1168   return 0;
1169  } else if ( strcmp(k, "--enum-servers") == 0 ) {
1170   enum_servers();
1171   return 0;
1172  } else if ( strcmp(k, "--hash-password") == 0 ) {
1173   hash_password();
1174   return 0;
1175  } else if ( *k == '-' ) {
1176   fprintf(stderr, "Error: unknown argument: %s\n", k);
1177   usage();
1178   return 1;
1179  } else {
1180   break;
1181  }
1182 }
1183
1184 // connect
1185
1186 if ( roar_simple_connect(&con, server, "roarctl") == -1 ) {
1187  fprintf(stderr, "Error: Can not connect to server: %s: %s(%i)\n",
1188          server == NULL ? "(default)" : server, roar_vs_strerr(roar_error), roar_error);
1189  return 1;
1190 }
1191
1192 if ( i == argc ) {
1193  fprintf(stderr, "Error: No Commands given\n");
1194  return 0; // this is not a fatal error...
1195 }
1196
1197 for (; i < argc; i++) {
1198  k = argv[i];
1199  // cmd is in k
1200
1201  printf("--- [ %s ] ---\n", k);
1202
1203  if ( !strcmp(k, "help") ) {
1204   usage();
1205
1206  } else if ( !strcmp(k, "sleep") ) {
1207   roar_sleep(atoi(argv[++i]));
1208
1209  } else if ( !strcmp(k, "ping") ) {
1210#ifdef ROAR_HAVE_GETTIMEOFDAY
1211   if ( ping(&con, atoi(argv[++i])) == -1 ) {
1212    fprintf(stderr, "Error: can not ping\n");
1213   }
1214#else
1215    fprintf(stderr, "Error: ping not supported.\n");
1216    i++;
1217#endif
1218
1219  } else if ( !strcmp(k, "standby") || !strcmp(k, "off") ) {
1220   if ( roar_set_standby(&con, ROAR_STANDBY_ACTIVE) == -1 ) {
1221    fprintf(stderr, "Error: can not set mode to standby\n");
1222   } else {
1223    printf("going into standby\n");
1224   }
1225  } else if ( !strcmp(k, "resume") || !strcmp(k, "on") ) {
1226   if ( roar_set_standby(&con, ROAR_STANDBY_INACTIVE) == -1 ) {
1227    fprintf(stderr, "Error: can not set mode to active\n");
1228   } else {
1229    printf("going into active mode\n");
1230   }
1231
1232  } else if ( !strcmp(k, "exit") ) {
1233   if ( roar_terminate(&con, 0) == -1 ) {
1234    fprintf(stderr, "Error: can not quit server\n");
1235   } else {
1236    printf("Server quited\n");
1237    break;
1238   }
1239  } else if ( !strcmp(k, "terminate") ) {
1240   if ( roar_terminate(&con, 1) == -1 ) {
1241    fprintf(stderr, "Error: can not terminate server\n");
1242   } else {
1243    printf("Server got asked to quited\n");
1244    break;
1245   }
1246
1247  } else if ( !strcmp(k, "standbymode") ) {
1248   t = roar_get_standby(&con);
1249   if ( t == -1 ) {
1250    fprintf(stderr, "Error: can not get stanby mode\n");
1251   } else if ( t == ROAR_STANDBY_ACTIVE ) {
1252    printf("Server is in standby\n");
1253   } else if ( t == ROAR_STANDBY_INACTIVE ) {
1254    printf("Server is active\n");
1255   } else {
1256    fprintf(stderr, "Error: unknown standby mode: %i\n", t);
1257   }
1258
1259  } else if ( !strcmp(k, "whoami") ) {
1260   printf("My client ID is: %i\n", roar_get_clientid(&con));
1261  } else if ( !strcmp(k, "serverinfo") ) {
1262   server_info(&con);
1263  } else if ( !strcmp(k, "servertime") ) {
1264   server_time(&con);
1265  } else if ( !strcmp(k, "serveroinfo") ) {
1266   server_oinfo(&con, -1);
1267  } else if ( !strcmp(k, "serveroinfo2") ) {
1268   t = roar_str2dir(argv[++i]);
1269   if ( t == -1 ) {
1270    fprintf(stderr, "Error: unknown stream direction: %s\n", argv[i]);
1271   } else {
1272    server_oinfo(&con, t);
1273   }
1274  } else if ( !strcmp(k, "serverstandards") ) {
1275   server_standards(&con);
1276  } else if ( !strcmp(k, "libstandards") ) {
1277   lib_standards();
1278  } else if ( !strcmp(k, "listclients") ) {
1279   list_clients(&con);
1280  } else if ( !strcmp(k, "clientinfo") ) {
1281   display_client(&con, atoi(argv[++i]));
1282  } else if ( !strcmp(k, "liststreams") ) {
1283   list_streams(&con);
1284  } else if ( !strcmp(k, "streaminfo") ) {
1285   display_stream(&con, atoi(argv[++i]));
1286  } else if ( !strcmp(k, "allinfo") ) {
1287   server_oinfo(&con, -1);
1288   printf("\n");
1289   list_clients(&con);
1290   printf("\n");
1291   list_streams(&con);
1292
1293  } else if ( !strcmp(k, "kick") ) {
1294   t = roar_str2ot((k = argv[++i]));
1295   if ( t == -1 ) {
1296    fprintf(stderr, "Error: unknown type: %s\n", k);
1297    continue;
1298   }
1299   //t = atoi(argv[i++]);
1300   if ( roar_kick(&con, t, atoi(argv[++i])) == -1 ) {
1301    fprintf(stderr, "Error: can not kick %s\n", k);
1302   } else {
1303    printf("%s kicked\n", k);
1304   }
1305
1306  } else if ( !strcmp(k, "newvirtual") ) {
1307   if ( newvirtual(&con, argv[i+1], argv[i+2], argv[i+3], argv[i+4], argv[i+5], argv[i+6]) == -1 ) {
1308    fprintf(stderr, "Error: can not create new virtual stream\n");
1309   } else {
1310    printf("virtual stream created\n");
1311   }
1312   i += 6;
1313
1314  } else if ( !strcmp(k, "volume") ) {
1315   if ( set_mixer(&con, &i, argc, argv) == -1 ) {
1316    fprintf(stderr, "Error: can not set volume\n");
1317   } else {
1318    printf("volume changed\n");
1319   }
1320
1321  } else if ( !strcmp(k, "flag") ) {
1322   i++;
1323   if ( set_flags(&con, atoi(argv[i]), ROAR_SET_FLAG, argv[i+1]) == -1 ) {
1324    fprintf(stderr, "Error: can not set flags\n");
1325   } else {
1326    printf("flags changed\n");
1327   }
1328   i++;
1329  } else if ( !strcmp(k, "unflag") ) {
1330   i++;
1331   if ( set_flags(&con, atoi(argv[i]), ROAR_RESET_FLAG, argv[i+1]) == -1 ) {
1332    fprintf(stderr, "Error: can not reset flags\n");
1333   } else {
1334    printf("flags changed\n");
1335   }
1336   i++;
1337  } else if ( !strcmp(k, "toggleflag") ) {
1338   i++;
1339   if ( set_flags(&con, atoi(argv[i]), ROAR_TOGGLE_FLAG, argv[i+1]) == -1 ) {
1340    fprintf(stderr, "Error: can not toggle flags\n");
1341   } else {
1342    printf("flags changed\n");
1343   }
1344   i++;
1345  } else if ( !strcmp(k, "protectflag") ) {
1346   i++;
1347   if ( set_flags(&con, atoi(argv[i]), ROAR_NOOP_FLAG|ROAR_PROTECT_FLAG, argv[i+1]) == -1 ) {
1348    fprintf(stderr, "Error: can not protect flags\n");
1349   } else {
1350    printf("flags protected\n");
1351   }
1352   i++;
1353
1354  } else if ( !strcmp(k, "role") ) {
1355   i++;
1356   if ( set_role(&con, atoi(argv[i]), roar_str2role(argv[i+1])) == -1 ) {
1357    fprintf(stderr, "Error: can not set stream role\n");
1358   } else {
1359    printf("stream role set\n");
1360   }
1361   i++;
1362
1363  } else if ( !strcmp(k, "metaset") ) {
1364   i++;
1365   if ( set_meta(&con, atoi(argv[i]), argv[i+1], argv[i+2], argv[i+3]) == -1 ) {
1366    fprintf(stderr, "Error: can not set meta data\n");
1367   } else {
1368    printf("meta data changed\n");
1369   }
1370   i += 3;
1371  } else if ( !strcmp(k, "metaget") ) {
1372   i++;
1373   if ( show_meta_type(&con, atoi(argv[i]), argv[i+1]) == -1 ) {
1374    fprintf(stderr, "Error: can not get meta data\n");
1375   }
1376   i++;
1377  } else if ( !strcmp(k, "metasave") ) {
1378   i++;
1379   if ( save_meta(&con, atoi(argv[i]), argv[i+1]) == -1 ) {
1380    fprintf(stderr, "Error: can not get meta data\n");
1381   } else {
1382    printf("meta data saved\n");
1383   }
1384   i++;
1385  } else if ( !strcmp(k, "metaload") ) {
1386   i++;
1387   if ( load_meta(&con, atoi(argv[i]), argv[i+1]) == -1 ) {
1388    fprintf(stderr, "Error: can not set meta data\n");
1389   } else {
1390    printf("meta data saved\n");
1391   }
1392   i++;
1393
1394
1395  } else if ( !strcmp(k, "listaiprofiles") || !strcmp(k, "listprofiles") ) {
1396   if ( list_aiprofiles() == -1 ) {
1397    fprintf(stderr, "Error: can not list profiles\n");
1398   }
1399  } else if ( !strcmp(k, "aiprofileget") || !strcmp(k, "profileget") ) {
1400   i++;
1401   if ( show_aiprofile(argv[i]) == -1 ) {
1402    fprintf(stderr, "Error: can not get profile data\n");
1403   }
1404  } else {
1405   fprintf(stderr, "Error: invalid command: %s\n", k);
1406  }
1407
1408 }
1409
1410 roar_disconnect(&con);
1411
1412 return 0;
1413}
1414
1415//ll
Note: See TracBrowser for help on using the repository browser.