source: roaraudio/roarclients/roarctl.c @ 5289:ddb3677af4d0

Last change on this file since 5289:ddb3677af4d0 was 5279:bb3ff1f2be28, checked in by phi, 12 years ago

added support to hostid and license to server info struct, added support for contact, serial and uiurl ITST to roard.

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(un.sysname, "System sysname");
303 _pm(un.release, "System release");
304 _pm(un.nodename, "System nodename");
305 _pm(un.machine, "System machine");
306
307 roar_server_info_free(info);
308}
309#undef _pm
310
311void server_time (struct roar_connection * con) {
312 struct roar_time time;
313
314 if ( roar_get_time(con, &time) == -1 ) {
315  fprintf(stderr, "Error: can not get server time: %s\n", roar_vs_strerr(roar_error));
316  return;
317 }
318
319 if ( g_verbose ) {
320  printf("Server time           : %llu.%06llu [+%llu/2^64] sec\n",
321         (long long unsigned int)time.t_sec,
322         (long long unsigned int) time.t_ssec / 18446744073709LLU,
323         (long long unsigned int) time.t_ssec);
324 } else {
325  if ( time.c_freq == 1000000000LL && time.t_ssec == 0 ) {
326   printf("Server time           : %llu sec\n",
327          (long long unsigned int)time.t_sec);
328  } else {
329   printf("Server time           : %llu.%06llu sec\n",
330          (long long unsigned int)time.t_sec,
331          (long long unsigned int) time.t_ssec / 18446744073709LLU);
332  }
333 }
334 if ( time.c_freq )
335  printf("Server clock frequency: %f Hz\n", (float)((double)time.c_freq / (double)1000000000.));
336 if ( time.c_drift ) {
337#ifdef ROAR_HAVE_LIBM
338  printf("Server clock drift    : %llu:2^64 (~10^%f)\n",
339         (long long unsigned int)time.c_drift, logf((float)time.c_drift)/2.302585f);
340#else
341  printf("Server clock drift    : %llu:2^64\n",
342         (long long unsigned int)time.c_drift);
343#endif
344 }
345}
346
347void server_oinfo (struct roar_connection * con, int dir) {
348 struct roar_stream s;
349
350 if ( roar_server_oinfo(con, &s, dir) == -1 ) {
351  fprintf(stderr, "Error: can not get server output info\n");
352  return;
353 }
354
355 printf("Stream direction      : %s\n", roar_dir2str(s.dir));
356 printf("Server Output rate    : %i Hz\n", s.info.rate);
357 printf("Server Output bits    : %i\n", s.info.bits);
358 printf("Server Output channels: %i\n", s.info.channels);
359 printf("Server Output codec   : %i (%s%s)\n", s.info.codec, roar_codec2str(s.info.codec),
360                                     s.info.codec == ROAR_CODEC_DEFAULT ? " native" : "");
361// printf("Server Output rate: %i", s.info.rate);
362  if ( g_verbose > 1 && s.pos != (uint32_t)-1 )
363   printf("Server Position       : %lu S (%.3fs)\n", (unsigned long int) s.pos, (float)s.pos/(s.info.rate*s.info.channels));
364}
365
366static void print_stds (const struct roar_stds * stds) {
367 size_t i;
368 int vendor, standard, version;
369 char numbuf[2][8];
370 const char * vendor_name;
371
372 for (i = 0; i < stds->stds_len; i++) {
373  vendor   = ROAR_STD_VENDOR(stds->stds[i]);
374  standard = ROAR_STD_STD(stds->stds[i]);
375  version  = ROAR_STD_VERSION(stds->stds[i]);
376
377  if ( (vendor_name = roar_stds_vendor2str(vendor)) == NULL ) {
378   snprintf(numbuf[0], sizeof(numbuf[0]), "%i", vendor);
379   numbuf[0][sizeof(numbuf[0])-1] = 0;
380   vendor_name = numbuf[0];
381  }
382
383  if ( version == 0 ) {
384   numbuf[1][0] = 0;
385  } else {
386   snprintf(numbuf[1], sizeof(numbuf[1]), "-%i", version);
387   numbuf[1][sizeof(numbuf[1])-1] = 0;
388  }
389
390  printf("Server standard       : %s-%i%s\n", vendor_name, standard, numbuf[1]);
391 }
392}
393
394void server_standards (struct roar_connection * con) {
395 struct roar_stds * stds;
396
397 if ( roar_caps_stds(con, &stds, NULL, -1) == -1 ) {
398  fprintf(stderr, "Error: can not get server standards\n");
399  return;
400 }
401
402 print_stds(stds);
403
404 roar_stds_free(stds);
405}
406
407void lib_standards (void) {
408 print_stds(libroar_libstds());
409}
410
411const char * proc_name (pid_t pid) {
412 static char ret[80] = "?";
413#ifdef __linux__
414 char file[80], buf[80], *r;
415 int  i;
416
417 snprintf(file, sizeof(file)-1, "/proc/%i/exe", pid);
418 file[sizeof(file)-1] = 0;
419
420 ret[0] = '?';
421 ret[1] = 0;
422
423 if ( (i = readlink(file, buf, sizeof(buf)-1)) != -1 ) {
424  buf[i] = 0;
425  if ( (r = strrchr(buf, '/')) != NULL ) {
426   r++;
427   if ( *r != 0 ) {
428    strncpy(ret, r, sizeof(ret)-1);
429    ret[sizeof(ret)-1] = 0;
430   }
431  }
432 }
433#else
434 (void)pid;
435#endif
436
437 return ret;
438}
439
440void list_clients (struct roar_connection * con) {
441 int i;
442 int num;
443 int id[ROAR_CLIENTS_MAX];
444
445 if ( (num = roar_list_clients(con, id, ROAR_CLIENTS_MAX)) == -1 ) {
446  fprintf(stderr, "Error: can not get client list\n");
447  return;
448 }
449
450 for (i = 0; i < num; i++) {
451  display_client(con, id[i]);
452 }
453}
454
455void display_client (struct roar_connection * con, int id) {
456 static int self_id = -1;
457 static struct roar_client   self_client_store;
458 static struct roar_client * self_client = NULL;
459 struct roar_client c;
460 char tmp[80];
461 int h;
462#ifdef _POSIX_USERS
463 struct group  * grp = NULL;
464 struct passwd * pwd = NULL;
465#endif
466
467 if ( self_id == -1 ) {
468  if ( (self_id = roar_get_clientid(con)) != -1 ) {
469   if ( roar_get_client(con, &self_client_store, self_id) == -1 ) {
470    self_id = -1;
471   } else {
472    self_client = &self_client_store;
473   }
474  }
475 }
476
477 printf("client %i:\n", id);
478 if ( roar_get_client(con, &c, id) == -1 ) {
479  fprintf(stderr, "Error: can not get client info\n");
480  return;
481 }
482
483 if ( c.name[0] != '\0' )
484  printf("Client name           : %s\n", c.name);
485  if ( roar_nnode_get_socktype(&(c.nnode)) != ROAR_SOCKET_TYPE_UNKNOWN ) {
486  if ( roar_nnode_to_str(&(c.nnode), tmp, sizeof(tmp)) == 0 ) {
487   printf("Client network node   : %s\n", tmp);
488  }
489 }
490
491 if ( c.pid != -1 ) {
492  if ( self_id != -1 && roar_nnode_cmp(&(self_client->nnode), &(c.nnode)) == 0 ) {
493   printf("Client PID            : %i(%s)\n", c.pid, proc_name(c.pid));
494  } else {
495   printf("Client PID            : %i\n", c.pid);
496  }
497 }
498 if ( c.uid != -1 ) {
499#ifdef _POSIX_USERS
500  if ( self_id != -1 && roar_nnode_cmp(&(self_client->nnode), &(c.nnode)) == 0 ) {
501   pwd = getpwuid(c.uid);
502   grp = getgrgid(c.gid);
503   printf("Client UID/GID        : %i(%s)/%i(%s)\n", c.uid, pwd ? pwd->pw_name : "?", c.gid, grp ? grp->gr_name : "?");
504  } else {
505#else
506  if ( 1 ) {
507#endif
508   printf("Client UID/GID        : %i/%i\n", c.uid, c.gid);
509  }
510 }
511
512 if ( g_verbose && c.proto != ROAR_PROTO_NONE ) {
513  printf("Client Protocol       : %s\n", roar_proto2str(c.proto));
514 }
515
516 if ( g_verbose && c.byteorder != ROAR_BYTEORDER_UNKNOWN ) {
517  if ( c.byteorder == ROAR_BYTEORDER_NETWORK ) {
518   roar_mm_strscpy(tmp, " (network byteorder");
519  } else {
520   *tmp = 0;
521  }
522
523  if ( c.byteorder == ROAR_BYTEORDER_NATIVE ) {
524   if ( *tmp ) {
525    roar_mm_strscat(tmp, ", native");
526   } else {
527    roar_mm_strscpy(tmp, " (native");
528   }
529  }
530
531  if ( *tmp )
532   roar_mm_strscat(tmp, ")");
533
534  printf("Client Byteorder      : %s%s\n", roar_byteorder2str(c.byteorder), tmp);
535 }
536
537 if ( c.execed != -1 )
538  printf("Execed stream         : %i\n", c.execed);
539
540 for (h = 0; h < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; h++)
541  if ( c.streams[h] != -1 )
542   printf("stream                : %i\n", c.streams[h]);
543}
544
545void list_streams (struct roar_connection * con) {
546 int i;
547 int num;
548 int id[ROAR_STREAMS_MAX];
549
550 if ( (num = roar_list_streams(con, id, ROAR_STREAMS_MAX)) == -1 ) {
551  fprintf(stderr, "Error: can not get stream list\n");
552  return;
553 }
554
555 for (i = 0; i < num; i++) {
556  display_stream(con, id[i]);
557 }
558}
559
560void display_stream (struct roar_connection * con, int id) {
561 char chanmap[ROAR_MAX_CHANNELS];
562 struct roar_stream s;
563 struct roar_stream_info info;
564 char buffer[1024];
565 char * flags = buffer;
566 char * name  = buffer;
567 char * infotext;
568 const char * mime;
569 size_t len;
570
571 printf("stream %i:\n", id);
572 if ( roar_get_stream(con, &s, id) == -1 ) {
573  fprintf(stderr, "Error: can not get stream info\n");
574  return;
575 }
576 printf("Stream direction      : %s\n", roar_dir2str(s.dir));
577
578 if ( roar_stream_get_name(con, &s, name, sizeof(buffer)) == 0 )
579  printf("Stream name           : %s\n", name);
580
581 if ( (int)s.pos_rel_id == -1 ) {
582  printf("Relativ position id   : none (stream not synchronized)\n");
583 } else if ( (int)s.pos_rel_id == id ) {
584  printf("Relativ position id   : %i (self synchronized)\n", s.pos_rel_id);
585 } else {
586  printf("Relativ position id   : %i (synchronized)\n", s.pos_rel_id);
587 }
588 if ( g_verbose > 1 && s.pos != (uint32_t)-1 ) {
589  if ( s.info.rate && s.info.channels ) {
590   printf("Position              : %lu S (%.3fs)\n", (unsigned long int) s.pos,
591                                   (float)s.pos/(s.info.rate*s.info.channels));
592  } else {
593   printf("Position              : %lu S\n", (unsigned long int) s.pos);
594  }
595 }
596
597 switch (s.dir) {
598  case ROAR_DIR_MIDI_IN:
599  case ROAR_DIR_MIDI_OUT:
600    infotext = " ticks/s";
601   break;
602  case ROAR_DIR_LIGHT_IN:
603  case ROAR_DIR_LIGHT_OUT:
604    infotext = " updates/s";
605   break;
606  default:
607    infotext = " Hz";
608 }
609 if ( s.info.rate )
610  printf("Stream sample rate    : %i%s\n", s.info.rate, infotext);
611 if ( s.info.bits )
612  printf("Stream bits           : %i\n", s.info.bits);
613 if ( s.info.channels )
614  printf("Stream channels       : %i\n", s.info.channels);
615
616 mime = roar_codec2mime(s.info.codec);
617 printf("Stream codec          : %2i (%s%s%s%s)\n", s.info.codec, roar_codec2str(s.info.codec),
618                                      s.info.codec == ROAR_CODEC_DEFAULT ? " native" : "",
619                                      mime == NULL ? "" : " mimetype:",
620                                      mime == NULL ? "" : mime
621                                     );
622 if ( roar_stream_get_info(con, &s, &info) != -1 ) {
623  if ( info.codec != s.info.codec ) {
624   mime = roar_codec2mime(info.codec);
625   printf("Streamed codec        : %2i (%s%s%s%s)\n", info.codec, roar_codec2str(info.codec),
626                                      info.codec == ROAR_CODEC_DEFAULT ? " native" : "",
627                                      mime == NULL ? "" : " mimetype:",
628                                      mime == NULL ? "" : mime
629                                     );
630  }
631
632  if ( g_verbose ) {
633   if ( info.block_size )
634    printf("Stream block size     : %i Byte\n", info.block_size);
635
636   printf("Underruns pre/post    : %i/%i\n",   info.pre_underruns, info.post_underruns);
637   if ( g_verbose > 1 )
638    printf("Stream delay          : %ims (%.2fm)\n",   (int)info.delay/1000, (info.delay*(float)_SPEED_OF_SOUND));
639
640   if ( g_verbose > 1 )
641    printf("Stream mixer          : %i\n",   info.mixer);
642
643   if ( g_verbose > 1 )
644    printf("Stream state          : %s\n",   roar_streamstate2str(info.state));
645
646   if ( g_verbose > 1 )
647    printf("Stream role           : %s\n",   roar_role2str(info.role));
648
649   *flags = 0;
650#define _strcat(dst,src) roar_mm_strlcat((dst),(src), sizeof(buffer))
651   if ( info.flags & ROAR_FLAG_PRIMARY )
652    _strcat(flags, "primary ");
653   if ( info.flags & ROAR_FLAG_SYNC )
654    _strcat(flags, "sync ");
655   if ( info.flags & ROAR_FLAG_OUTPUT )
656    _strcat(flags, "output ");
657   if ( info.flags & ROAR_FLAG_SOURCE )
658    _strcat(flags, "source ");
659   if ( info.flags & ROAR_FLAG_META )
660    _strcat(flags, "meta ");
661   if ( info.flags & ROAR_FLAG_AUTOCONF )
662    _strcat(flags, "autoconf ");
663   if ( info.flags & ROAR_FLAG_CLEANMETA )
664    _strcat(flags, "cleanmeta ");
665   if ( info.flags & ROAR_FLAG_HWMIXER )
666    _strcat(flags, "hwmixer ");
667   if ( info.flags & ROAR_FLAG_PAUSE )
668    _strcat(flags, "pause ");
669   if ( info.flags & ROAR_FLAG_MUTE )
670    _strcat(flags, "mute ");
671   if ( info.flags & ROAR_FLAG_MMAP )
672    _strcat(flags, "mmap ");
673   if ( info.flags & ROAR_FLAG_ANTIECHO )
674    _strcat(flags, "antiecho ");
675   if ( info.flags & ROAR_FLAG_VIRTUAL )
676    _strcat(flags, "virtual ");
677   if ( info.flags & ROAR_FLAG_RECSOURCE )
678    _strcat(flags, "recsource ");
679   if ( info.flags & ROAR_FLAG_PASSMIXER )
680    _strcat(flags, "passmixer ");
681   if ( info.flags & ROAR_FLAG_PRETHRU )
682    _strcat(flags, "prethru ");
683   if ( info.flags & ROAR_FLAG_IMMUTABLE )
684    _strcat(flags, "immutable ");
685   if ( info.flags & ROAR_FLAG_ENHANCE )
686    _strcat(flags, "enhance ");
687   if ( info.flags & ROAR_FLAG_SINGLESINK )
688    _strcat(flags, "singlesink ");
689#undef _strcat
690
691   printf("Flags                 : %s\n", flags);
692  }
693 }
694
695 if ( g_verbose ) {
696  len = ROAR_MAX_CHANNELS;
697  if ( roar_stream_get_chanmap(con, &s, chanmap, &len) == -1 ) {
698   fprintf(stderr, "Error: can not get stream channel map\n");
699  } else {
700   if ( roardsp_chanlist2str(chanmap, len, buffer, 1024) == -1 ) {
701    fprintf(stderr, "Error: can not convert channel map into string\n");
702   } else {
703    printf("Channel Map           : %s\n", buffer);
704   }
705  }
706 }
707
708 if ( s.dir != ROAR_DIR_THRU ) {
709  display_mixer(con, id);
710  show_meta_all(con, id);
711 }
712}
713
714int display_mixer (struct roar_connection * con, int stream) {
715 struct roar_mixer_settings mixer;
716 int channels;
717 int i;
718 float fs;
719
720 if ( roar_get_vol(con, stream, &mixer, &channels) == -1 ) {
721  fprintf(stderr, "Error: can not get stream mixer info for stream %i\n", stream);
722  return -1;
723 }
724
725#ifdef ROAR_HAVE_LIBM
726#define _DB ", %.2fdB"
727#else
728#define _DB ""
729#endif
730
731 fs = (float)mixer.scale / 100.;
732
733 if ( channels ) { // we hide RPG info for zero-channel streams
734  printf("Mixer ReplayGain      : %i/%i (%.2f%%" _DB ")\n", mixer.rpg_mul, mixer.rpg_div,
735                                                          100.*(float)mixer.rpg_mul/((float)mixer.rpg_div)
736#ifdef ROAR_HAVE_LIBM
737                           , 20*log10f((float)mixer.rpg_mul/(float)mixer.rpg_div)
738#endif
739        );
740 }
741
742 for (i = 0; i < channels; i++)
743  printf("Mixer volume chan %2i  : %i/%i (%.2f%%" _DB ")\n", i, mixer.mixer[i], mixer.scale,
744                           (float)mixer.mixer[i]/fs
745#ifdef ROAR_HAVE_LIBM
746                          , 20*log10f((float)mixer.mixer[i]/(float)mixer.scale)
747#endif
748        );
749
750 return 0;
751}
752
753static unsigned int set_mixer_parse_volume (char * k, int len, uint16_t scale) {
754 float fs = scale;
755
756 switch (k[len - 1]) {
757  case '%':
758    k[len - 1] = 0;
759    return (atof(k)*fs)/100.;
760   break;
761#ifdef ROAR_HAVE_LIBM
762  case 'b':
763  case 'B':
764    // TODO: can we hanle the error better?
765    if ( len < 2 )
766     return 0;
767
768    k[len - 2] = 0;
769    return powf(10, atof(k)/20.f)*fs;
770   break;
771#endif
772 }
773
774 return atoi(k);
775}
776
777int set_mixer (struct roar_connection * con, int * cur, int max, char * arg[]) {
778 uint16_t scale = 65535;
779 int chans = 0;
780 int id;
781 int i;
782 int len;
783 int old_chans;
784 char * k;
785 struct roar_mixer_settings mixer;
786 struct roar_mixer_settings old_mixer;
787 int mode = ROAR_SET_VOL_ALL;
788
789 if (*cur + 2 > max)
790  return -1;
791
792 id = atoi(arg[++(*cur)]);
793
794 k = arg[++(*cur)];
795
796 if ( !strcmp(arg[*cur + 1], "scale") ) {
797  (*cur)++; // 'scale'
798  (*cur)++;
799  scale = set_mixer_parse_volume(arg[*cur], strlen(arg[*cur]), 65535);
800 }
801
802 mixer.scale = scale;
803
804 if ( roar_get_vol(con, id, &old_mixer, &old_chans) == -1 ) {
805  fprintf(stderr, "Error: can not get stream mixer info for stream %i\n", id);
806  return -1;
807 }
808
809 if ( strcmp(k, "mono") == 0 ) {
810  chans = 1;
811  mode  = ROAR_SET_VOL_UNMAPPED;
812 } else if ( strcmp(k, "stereo") == 0 ) {
813  chans = 2;
814  mode  = ROAR_SET_VOL_UNMAPPED;
815 } else {
816  chans = atoi(k);
817 }
818
819 // ensure most simple mode:
820 if ( old_chans == chans && mode == ROAR_SET_VOL_UNMAPPED )
821  mode = ROAR_SET_VOL_ALL;
822
823 if ( *cur + chans > max )
824  return -1;
825
826 for (i = 0; i < chans; i++) {
827  k   = arg[++(*cur)];
828  len = strlen(k);
829
830  mixer.mixer[i] = set_mixer_parse_volume(k, len, scale);
831 }
832
833 if ( roar_set_vol(con, id, &mixer, chans, mode) == 0 )
834  return 0;
835
836 // no fallback if already using ROAR_SET_VOL_ALL:
837 if ( mode == ROAR_SET_VOL_ALL )
838  return -1;
839
840 if ( roar_conv_volume(&mixer, &mixer, old_chans, chans) == -1 )
841  return -1;
842
843 chans = old_chans;
844 mode  = ROAR_SET_VOL_ALL;
845
846 if ( roar_set_vol(con, id, &mixer, chans, mode) == 0 )
847  return 0;
848
849 return -1;
850}
851
852
853int newvirtual (struct roar_connection * con, char *p_s, char *d_s, char *e_s, char *r_s, char *b_s, char *c_s) {
854 struct roar_stream s;
855 int dir    = roar_str2dir(d_s);
856 int parent = atoi(p_s);
857
858 ROAR_DBG("newvirtual(*): dir=%i, parent=%i", dir, parent);
859
860 if ( roar_stream_new(&s, atoi(r_s), atoi(c_s), atoi(b_s), roar_str2codec(e_s)) == -1 )
861  return -1;
862
863 return roar_simple_connect_virtual(con, &s, parent, dir);
864}
865
866int set_meta (struct roar_connection * con, int id, char * mode, char * type, char * val) {
867 struct roar_meta   meta;
868 struct roar_stream s;
869 int mode_i = ROAR_META_MODE_SET;
870
871 if ( roar_stream_new_by_id(&s, id) == -1 )
872  return -1;
873
874// printf("set_meta(*): mode='%s', type='%s', val='%s'\n", mode, type, val);
875
876 if ( strcmp(mode, "add") == 0 ) {
877  mode_i = ROAR_META_MODE_ADD;
878 }
879
880 meta.type   = roar_meta_inttype(type);
881 meta.value  = val;
882 meta.key[0] = 0;
883
884 if ( meta.type == -1 ) {
885  fprintf(stderr, "Error: unknown type: %s\n", type);
886  return -1;
887 }
888
889// printf("D: type=%i, mode=%i\n", meta.type, mode_i);
890
891 if ( roar_stream_meta_set(con, &s, mode_i, &meta) == -1 )
892  return -1;
893
894 meta.type  = ROAR_META_TYPE_NONE;
895 meta.value = NULL;
896
897 return roar_stream_meta_set(con, &s, ROAR_META_MODE_FINALIZE, &meta);
898}
899
900int load_meta (struct roar_connection * con, int id, char * file) {
901 struct roar_meta   meta;
902 struct roar_stream s;
903 int mode_i = ROAR_META_MODE_SET;
904 FILE * in;
905 char lion[1024];
906 char * v;
907
908 if ( roar_stream_new_by_id(&s, id) == -1 )
909  return -1;
910
911 if ( (in = fopen(file, "r")) == NULL )
912  return -1;
913
914 while (fgets(lion, 1024, in) != NULL) {
915  if ( (v = strtok(lion, "\r\n")) != NULL )
916   if ( (v = strtok(NULL, "\r\n")) != NULL )
917    *(v-1) = 0;
918
919  if ( (v = strstr(lion, "=")) == NULL ) {
920   fprintf(stderr, "Error: can not parse meta data lion: %s\n", lion);
921   continue;
922  }
923
924  *v++ = 0;
925
926  meta.type   = roar_meta_inttype(lion);
927  meta.value  = v;
928  meta.key[0] = 0;
929
930  if ( meta.type == -1 ) {
931   fprintf(stderr, "Error: unknown type: %s\n", lion);
932   continue;
933  }
934
935  if ( roar_stream_meta_set(con, &s, mode_i, &meta) == -1 ) {
936   fclose(in);
937   return -1;
938  }
939 }
940
941 fclose(in);
942
943 meta.type  = ROAR_META_TYPE_NONE;
944 meta.value = NULL;
945
946 return roar_stream_meta_set(con, &s, ROAR_META_MODE_FINALIZE, &meta);
947}
948
949int show_meta_type (struct roar_connection * con, int id, char * type) {
950 struct roar_meta   meta;
951 struct roar_stream s;
952
953 if ( roar_stream_new_by_id(&s, id) == -1 )
954  return -1;
955
956 meta.type  = roar_meta_inttype(type);
957
958 if ( meta.type == -1 ) {
959  fprintf(stderr, "Error: unknown type: %s\n", type);
960  return -1;
961 }
962
963 if ( roar_stream_meta_get(con, &s, &meta) == -1 )
964  return -1;
965
966 printf("Meta %-17s: %s\n", roar_meta_strtype(meta.type), meta.value);
967
968 roar_meta_free(&meta);
969
970 return 0;
971}
972
973int show_meta_all (struct roar_connection * con, int id) {
974 struct roar_stream s;
975 int types[ROAR_META_MAX_PER_STREAM];
976 int i;
977 int len;
978
979 if ( roar_stream_new_by_id(&s, id) == -1 )
980  return -1;
981
982 if ( (len = roar_stream_meta_list(con, &s, types, ROAR_META_MAX_PER_STREAM)) == -1 )
983  return -1;
984
985 for (i = 0; i < len; i++)
986  show_meta_type(con, id, roar_meta_strtype(types[i]));
987
988 return 0;
989}
990
991int save_meta (struct roar_connection * con, int id, char * file) {
992 struct roar_stream s;
993 struct roar_meta   meta;
994 int types[ROAR_META_MAX_PER_STREAM];
995 int i;
996 int len;
997 FILE * out;
998
999 if ( roar_stream_new_by_id(&s, id) == -1 )
1000  return -1;
1001
1002 if ( (len = roar_stream_meta_list(con, &s, types, ROAR_META_MAX_PER_STREAM)) == -1 )
1003  return -1;
1004
1005 if ( (out = fopen(file, "w")) == NULL )
1006  return -1;
1007
1008 for (i = 0; i < len; i++) {
1009/*
1010  show_meta_type(con, id, roar_meta_strtype(types[i]));
1011*/
1012  meta.type  = types[i];
1013
1014  if ( roar_stream_meta_get(con, &s, &meta) == -1 )
1015   continue;
1016
1017//  printf("Meta %-17s: %s\n", roar_meta_strtype(meta.type), meta.value);
1018
1019  fprintf(out, "%s=%s\n", roar_meta_strtype(meta.type), meta.value);
1020
1021  roar_meta_free(&meta);
1022 }
1023
1024 fclose(out);
1025
1026 return 0;
1027}
1028
1029int set_flags (struct roar_connection * con, int id, int action, char * flags) {
1030 uint32_t f = ROAR_FLAG_NONE;
1031 char * c;
1032 struct roar_stream s[1];
1033
1034 if ( roar_stream_new_by_id(s, id) == -1 )
1035  return -1;
1036
1037 c = strtok(flags, ",");
1038 while (c != NULL) {
1039  if ( !strcmp(c, "meta") ) {
1040   f |= ROAR_FLAG_META;
1041  } else if ( !strcmp(c, "primary") ) {
1042   f |= ROAR_FLAG_PRIMARY;
1043  } else if ( !strcmp(c, "sync") ) {
1044   f |= ROAR_FLAG_SYNC;
1045  } else if ( !strcmp(c, "cleanmeta") ) {
1046   f |= ROAR_FLAG_CLEANMETA;
1047  } else if ( !strcmp(c, "hwmixer") ) {
1048   f |= ROAR_FLAG_HWMIXER;
1049  } else if ( !strcmp(c, "pause") ) {
1050   f |= ROAR_FLAG_PAUSE;
1051  } else if ( !strcmp(c, "mute") ) {
1052   f |= ROAR_FLAG_MUTE;
1053  } else if ( !strcmp(c, "mmap") ) {
1054   f |= ROAR_FLAG_MMAP;
1055  } else if ( !strcmp(c, "antiecho") ) {
1056   f |= ROAR_FLAG_ANTIECHO;
1057  } else if ( !strcmp(c, "recsource") ) {
1058   f |= ROAR_FLAG_RECSOURCE;
1059  } else if ( !strcmp(c, "passmixer") ) {
1060   f |= ROAR_FLAG_PASSMIXER;
1061  } else if ( !strcmp(c, "virtual") ) {
1062   f |= ROAR_FLAG_VIRTUAL;
1063  } else if ( !strcmp(c, "prethru") ) {
1064   f |= ROAR_FLAG_PRETHRU;
1065  } else if ( !strcmp(c, "immutable") ) {
1066   f |= ROAR_FLAG_IMMUTABLE;
1067  } else if ( !strcmp(c, "enhance") ) {
1068   f |= ROAR_FLAG_ENHANCE;
1069  } else if ( !strcmp(c, "singlesink") ) {
1070   f |= ROAR_FLAG_SINGLESINK;
1071  } else {
1072   fprintf(stderr, "Error: unknown flag: %s\n", c);
1073   return -1;
1074  }
1075
1076  c = strtok(NULL, ",");
1077 }
1078
1079 return roar_stream_set_flags(con, s, f, action);
1080}
1081
1082int set_role (struct roar_connection * con, int id, int role) {
1083 struct roar_stream s;
1084
1085 if ( id == -1 )
1086  return -1;
1087
1088 if ( roar_stream_new_by_id(&s, id) == -1 )
1089  return -1;
1090
1091 if ( roar_stream_set_role(con, &s, role) == -1 )
1092  return -1;
1093
1094 return 0;
1095}
1096
1097int show_aiprofile (const char * profile) {
1098 struct roar_audio_info info;
1099 const char * mime;
1100
1101 if ( roar_profile2info(&info, profile) == -1 ) {
1102  fprintf(stderr, "Error: unknown profile: %s\n", profile);
1103  return -1;
1104 }
1105
1106 mime = roar_codec2mime(info.codec);
1107
1108 printf("Profile Name          : %s\n", profile);
1109
1110 if ( info.rate )
1111  printf("Profile sample rate   : %i\n", info.rate);
1112 if ( info.bits )
1113  printf("Profile bits          : %i\n", info.bits);
1114 if ( info.channels )
1115  printf("Profile channels      : %i\n", info.channels);
1116
1117 printf("Profile codec         : %2i (%s%s%s%s)\n", info.codec, roar_codec2str(info.codec),
1118                                       info.codec == ROAR_CODEC_DEFAULT ? " native" : "",
1119                                       mime == NULL ? "" : " mimetype:",
1120                                       mime == NULL ? "" : mime);
1121
1122 return 0;
1123}
1124
1125int list_aiprofiles (void) {
1126 const char * list[1024];
1127 ssize_t ret;
1128 ssize_t i;
1129
1130 ret = roar_profiles_list(list, 1024, 0);
1131
1132 if ( ret == -1 ) {
1133  fprintf(stderr, "Error: can not read list of profiles\n");
1134  return -1;
1135 }
1136
1137 for (i = 0; i < ret; i++) {
1138  printf("profile %lli:\n", (long long signed int)i);
1139  show_aiprofile(list[i]);
1140 }
1141
1142 return 0;
1143}
1144
1145int main (int argc, char * argv[]) {
1146 struct roar_connection con;
1147 char * server   = NULL;
1148 char * k = NULL;
1149 int    i;
1150 int    t = 0;
1151
1152 for (i = 1; i < argc; i++) {
1153  k = argv[i];
1154
1155  if ( strcmp(k, "--server") == 0 ) {
1156   server = argv[++i];
1157  } else if ( strcmp(k, "-v") == 0 || strcmp(k, "--verbose") == 0 ) {
1158   g_verbose++;
1159  } else if ( strcmp(k, "--help") == 0 ) {
1160   usage();
1161   return 0;
1162  } else if ( strcmp(k, "--list-aiprofiles") == 0 ) {
1163   list_aiprofiles();
1164   return 0;
1165  } else if ( strcmp(k, "--list-libstandards") == 0 ) {
1166   lib_standards();
1167   return 0;
1168  } else if ( strcmp(k, "--enum-servers") == 0 ) {
1169   enum_servers();
1170   return 0;
1171  } else if ( strcmp(k, "--hash-password") == 0 ) {
1172   hash_password();
1173   return 0;
1174  } else if ( *k == '-' ) {
1175   fprintf(stderr, "Error: unknown argument: %s\n", k);
1176   usage();
1177   return 1;
1178  } else {
1179   break;
1180  }
1181 }
1182
1183 // connect
1184
1185 if ( roar_simple_connect(&con, server, "roarctl") == -1 ) {
1186  fprintf(stderr, "Error: Can not connect to server: %s: %s(%i)\n",
1187          server == NULL ? "(default)" : server, roar_vs_strerr(roar_error), roar_error);
1188  return 1;
1189 }
1190
1191 if ( i == argc ) {
1192  fprintf(stderr, "Error: No Commands given\n");
1193  return 0; // this is not a fatal error...
1194 }
1195
1196 for (; i < argc; i++) {
1197  k = argv[i];
1198  // cmd is in k
1199
1200  printf("--- [ %s ] ---\n", k);
1201
1202  if ( !strcmp(k, "help") ) {
1203   usage();
1204
1205  } else if ( !strcmp(k, "sleep") ) {
1206   roar_sleep(atoi(argv[++i]));
1207
1208  } else if ( !strcmp(k, "ping") ) {
1209#ifdef ROAR_HAVE_GETTIMEOFDAY
1210   if ( ping(&con, atoi(argv[++i])) == -1 ) {
1211    fprintf(stderr, "Error: can not ping\n");
1212   }
1213#else
1214    fprintf(stderr, "Error: ping not supported.\n");
1215    i++;
1216#endif
1217
1218  } else if ( !strcmp(k, "standby") || !strcmp(k, "off") ) {
1219   if ( roar_set_standby(&con, ROAR_STANDBY_ACTIVE) == -1 ) {
1220    fprintf(stderr, "Error: can not set mode to standby\n");
1221   } else {
1222    printf("going into standby\n");
1223   }
1224  } else if ( !strcmp(k, "resume") || !strcmp(k, "on") ) {
1225   if ( roar_set_standby(&con, ROAR_STANDBY_INACTIVE) == -1 ) {
1226    fprintf(stderr, "Error: can not set mode to active\n");
1227   } else {
1228    printf("going into active mode\n");
1229   }
1230
1231  } else if ( !strcmp(k, "exit") ) {
1232   if ( roar_terminate(&con, 0) == -1 ) {
1233    fprintf(stderr, "Error: can not quit server\n");
1234   } else {
1235    printf("Server quited\n");
1236    break;
1237   }
1238  } else if ( !strcmp(k, "terminate") ) {
1239   if ( roar_terminate(&con, 1) == -1 ) {
1240    fprintf(stderr, "Error: can not terminate server\n");
1241   } else {
1242    printf("Server got asked to quited\n");
1243    break;
1244   }
1245
1246  } else if ( !strcmp(k, "standbymode") ) {
1247   t = roar_get_standby(&con);
1248   if ( t == -1 ) {
1249    fprintf(stderr, "Error: can not get stanby mode\n");
1250   } else if ( t == ROAR_STANDBY_ACTIVE ) {
1251    printf("Server is in standby\n");
1252   } else if ( t == ROAR_STANDBY_INACTIVE ) {
1253    printf("Server is active\n");
1254   } else {
1255    fprintf(stderr, "Error: unknown standby mode: %i\n", t);
1256   }
1257
1258  } else if ( !strcmp(k, "whoami") ) {
1259   printf("My client ID is: %i\n", roar_get_clientid(&con));
1260  } else if ( !strcmp(k, "serverinfo") ) {
1261   server_info(&con);
1262  } else if ( !strcmp(k, "servertime") ) {
1263   server_time(&con);
1264  } else if ( !strcmp(k, "serveroinfo") ) {
1265   server_oinfo(&con, -1);
1266  } else if ( !strcmp(k, "serveroinfo2") ) {
1267   t = roar_str2dir(argv[++i]);
1268   if ( t == -1 ) {
1269    fprintf(stderr, "Error: unknown stream direction: %s\n", argv[i]);
1270   } else {
1271    server_oinfo(&con, t);
1272   }
1273  } else if ( !strcmp(k, "serverstandards") ) {
1274   server_standards(&con);
1275  } else if ( !strcmp(k, "libstandards") ) {
1276   lib_standards();
1277  } else if ( !strcmp(k, "listclients") ) {
1278   list_clients(&con);
1279  } else if ( !strcmp(k, "clientinfo") ) {
1280   display_client(&con, atoi(argv[++i]));
1281  } else if ( !strcmp(k, "liststreams") ) {
1282   list_streams(&con);
1283  } else if ( !strcmp(k, "streaminfo") ) {
1284   display_stream(&con, atoi(argv[++i]));
1285  } else if ( !strcmp(k, "allinfo") ) {
1286   server_oinfo(&con, -1);
1287   printf("\n");
1288   list_clients(&con);
1289   printf("\n");
1290   list_streams(&con);
1291
1292  } else if ( !strcmp(k, "kick") ) {
1293   t = roar_str2ot((k = argv[++i]));
1294   if ( t == -1 ) {
1295    fprintf(stderr, "Error: unknown type: %s\n", k);
1296    continue;
1297   }
1298   //t = atoi(argv[i++]);
1299   if ( roar_kick(&con, t, atoi(argv[++i])) == -1 ) {
1300    fprintf(stderr, "Error: can not kick %s\n", k);
1301   } else {
1302    printf("%s kicked\n", k);
1303   }
1304
1305  } else if ( !strcmp(k, "newvirtual") ) {
1306   if ( newvirtual(&con, argv[i+1], argv[i+2], argv[i+3], argv[i+4], argv[i+5], argv[i+6]) == -1 ) {
1307    fprintf(stderr, "Error: can not create new virtual stream\n");
1308   } else {
1309    printf("virtual stream created\n");
1310   }
1311   i += 6;
1312
1313  } else if ( !strcmp(k, "volume") ) {
1314   if ( set_mixer(&con, &i, argc, argv) == -1 ) {
1315    fprintf(stderr, "Error: can not set volume\n");
1316   } else {
1317    printf("volume changed\n");
1318   }
1319
1320  } else if ( !strcmp(k, "flag") ) {
1321   i++;
1322   if ( set_flags(&con, atoi(argv[i]), ROAR_SET_FLAG, argv[i+1]) == -1 ) {
1323    fprintf(stderr, "Error: can not set flags\n");
1324   } else {
1325    printf("flags changed\n");
1326   }
1327   i++;
1328  } else if ( !strcmp(k, "unflag") ) {
1329   i++;
1330   if ( set_flags(&con, atoi(argv[i]), ROAR_RESET_FLAG, argv[i+1]) == -1 ) {
1331    fprintf(stderr, "Error: can not reset flags\n");
1332   } else {
1333    printf("flags changed\n");
1334   }
1335   i++;
1336  } else if ( !strcmp(k, "toggleflag") ) {
1337   i++;
1338   if ( set_flags(&con, atoi(argv[i]), ROAR_TOGGLE_FLAG, argv[i+1]) == -1 ) {
1339    fprintf(stderr, "Error: can not toggle flags\n");
1340   } else {
1341    printf("flags changed\n");
1342   }
1343   i++;
1344  } else if ( !strcmp(k, "protectflag") ) {
1345   i++;
1346   if ( set_flags(&con, atoi(argv[i]), ROAR_NOOP_FLAG|ROAR_PROTECT_FLAG, argv[i+1]) == -1 ) {
1347    fprintf(stderr, "Error: can not protect flags\n");
1348   } else {
1349    printf("flags protected\n");
1350   }
1351   i++;
1352
1353  } else if ( !strcmp(k, "role") ) {
1354   i++;
1355   if ( set_role(&con, atoi(argv[i]), roar_str2role(argv[i+1])) == -1 ) {
1356    fprintf(stderr, "Error: can not set stream role\n");
1357   } else {
1358    printf("stream role set\n");
1359   }
1360   i++;
1361
1362  } else if ( !strcmp(k, "metaset") ) {
1363   i++;
1364   if ( set_meta(&con, atoi(argv[i]), argv[i+1], argv[i+2], argv[i+3]) == -1 ) {
1365    fprintf(stderr, "Error: can not set meta data\n");
1366   } else {
1367    printf("meta data changed\n");
1368   }
1369   i += 3;
1370  } else if ( !strcmp(k, "metaget") ) {
1371   i++;
1372   if ( show_meta_type(&con, atoi(argv[i]), argv[i+1]) == -1 ) {
1373    fprintf(stderr, "Error: can not get meta data\n");
1374   }
1375   i++;
1376  } else if ( !strcmp(k, "metasave") ) {
1377   i++;
1378   if ( save_meta(&con, atoi(argv[i]), argv[i+1]) == -1 ) {
1379    fprintf(stderr, "Error: can not get meta data\n");
1380   } else {
1381    printf("meta data saved\n");
1382   }
1383   i++;
1384  } else if ( !strcmp(k, "metaload") ) {
1385   i++;
1386   if ( load_meta(&con, atoi(argv[i]), argv[i+1]) == -1 ) {
1387    fprintf(stderr, "Error: can not set meta data\n");
1388   } else {
1389    printf("meta data saved\n");
1390   }
1391   i++;
1392
1393
1394  } else if ( !strcmp(k, "listaiprofiles") || !strcmp(k, "listprofiles") ) {
1395   if ( list_aiprofiles() == -1 ) {
1396    fprintf(stderr, "Error: can not list profiles\n");
1397   }
1398  } else if ( !strcmp(k, "aiprofileget") || !strcmp(k, "profileget") ) {
1399   i++;
1400   if ( show_aiprofile(argv[i]) == -1 ) {
1401    fprintf(stderr, "Error: can not get profile data\n");
1402   }
1403  } else {
1404   fprintf(stderr, "Error: invalid command: %s\n", k);
1405  }
1406
1407 }
1408
1409 roar_disconnect(&con);
1410
1411 return 0;
1412}
1413
1414//ll
Note: See TracBrowser for help on using the repository browser.