source: roaraudio/roarclients/roarctl.c @ 5149:b7345c9daac1

Last change on this file since 5149:b7345c9daac1 was 5149:b7345c9daac1, checked in by phi, 13 years ago

added support to list standards the client lib supports (not yet complet)

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