source: roaraudio/roarclients/roarctl.c @ 5236:0a8740e27666

Last change on this file since 5236:0a8740e27666 was 5236:0a8740e27666, checked in by phi, 12 years ago

Removed roar_set_vol() and roar_server_oinfo(), as well as roar_exit().

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