source: roaraudio/roarclients/roarcatplay.c @ 1770:c529c28e2e4b

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

passive mode only supported on systems supporting UNIX Sockets

File size: 3.3 KB
Line 
1//roarcat.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008
5 *
6 *  This file is part of roarclients a part of RoarAudio,
7 *  a cross-platform sound system for both, home and professional use.
8 *  See README for details.
9 *
10 *  This file is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License version 3
12 *  as published by the Free Software Foundation.
13 *
14 *  RoarAudio is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU General Public License for more details.
18 *
19 *  You should have received a copy of the GNU General Public License
20 *  along with this software; see the file COPYING.  If not, write to
21 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 */
24
25#include <roaraudio.h>
26
27#define BUFSIZE 1024
28
29void usage (void) {
30 printf("roarcatplay [OPTIONS]... [FILE]\n");
31
32 printf("\nOptions:\n\n");
33
34 printf("  --server SERVER    - Set server hostname\n"
35        "  --simple           - Use the simple interface (default)\n"
36        "  --passive          - Use passiv playback (experimental, works only localy)\n"
37        "  --background       - Use background playback, impleys passive mode\n"
38        "  --verbose          - Use verbose output\n"
39        "  --help             - Show this help\n"
40       );
41
42}
43
44#define MODE_SIMPLE  1
45#define MODE_PASSIVE 2
46
47int main (int argc, char * argv[]) {
48 char * server   = NULL;
49 char * k;
50 int    i;
51 char * file    = NULL;
52 int    mode    = MODE_SIMPLE;
53 int    bg      = 0;
54 int    verbose = 0;
55 struct roar_connection con[1];
56 struct roar_stream     stream[1];
57
58 for (i = 1; i < argc; i++) {
59  k = argv[i];
60
61  if ( strcmp(k, "--server") == 0 || strcmp(k, "-s") == 0 ) {
62   server = argv[++i];
63  } else if ( strcmp(k, "--simple") == 0 ) {
64   mode = MODE_SIMPLE;
65  } else if ( strcmp(k, "--passive") == 0 ) {
66   mode = MODE_PASSIVE;
67  } else if ( strcmp(k, "--background") == 0 ) {
68   bg = 1;
69  } else if ( strcmp(k, "--verbose") == 0 || strcmp(k, "-v") == 0 ) {
70   verbose++;
71  } else if ( strcmp(k, "--help") == 0 || strcmp(k, "-h") == 0 ) {
72   usage();
73   return 0;
74  } else if ( file == NULL ) {
75   file = argv[i];
76  } else {
77   fprintf(stderr, "Error: unknown argument: %s\n", k);
78   usage();
79   return 1;
80  }
81 }
82
83 if ( bg )
84  mode = MODE_PASSIVE;
85
86#ifndef ROAR_HAVE_UNIX
87 if ( mode == MODE_PASSIVE ) {
88  fprintf(stderr, "Error: passive mode is not supported on this system.\n", k);
89  return 1;
90 }
91#endif
92
93 if ( file == NULL )
94  file = "/dev/stdin";
95
96#ifndef ROAR_HAVE_UNIX
97 if ( mode == MODE_PASSIVE ) {
98  if ( roar_simple_connect(con, server, "roarcatplay") == -1 ) {
99   ROAR_ERR("Can not connect to server");
100   return 0;
101  }
102
103  if ( roar_file_play_full(con, file, 0, 1, stream) == -1 ) {
104   ROAR_ERR("Can not start playback");
105   return 1;
106  }
107
108  if ( bg ) {
109   if ( roar_stream_attach_simple(con, stream, 0) == -1 ) {
110    ROAR_ERR("Can not attach stream to server");
111   }
112  } else {
113   sleep(10);
114  }
115
116  roar_disconnect(con);
117
118 } else { // MODE_SIMPLE
119#endif
120  if ( roar_simple_play_file(file, server, "roarcatplay") == -1 ) {
121   ROAR_ERR("Can not start playback");
122   return 1;
123  }
124#ifndef ROAR_HAVE_UNIX
125 }
126#endif
127
128 return 0;
129}
130
131//ll
Note: See TracBrowser for help on using the repository browser.