1 | //roarctl.c: |
---|
2 | |
---|
3 | #include <roaraudio.h> |
---|
4 | |
---|
5 | void usage (void) { |
---|
6 | printf("roarcat [OPTIONS]... COMMAND [OPTS] [COMMAND [OPTS] [COMMAND [OPTS] [...]]]\n"); |
---|
7 | |
---|
8 | printf("\nOptions:\n\n"); |
---|
9 | |
---|
10 | printf(" --server SERVER - Set server hostname\n" |
---|
11 | " --help - Show this help\n" |
---|
12 | ); |
---|
13 | |
---|
14 | printf("\nCommands:\n\n"); |
---|
15 | printf( |
---|
16 | " help - Show this help\n" |
---|
17 | "\n" |
---|
18 | " standby, off - Go into standby mode\n" |
---|
19 | " resume, on - Go into active mode\n" |
---|
20 | " standbymode - Show current standby mode\n" |
---|
21 | " exit - Quits the roard (must be used as last command)\n" |
---|
22 | "\n" |
---|
23 | " kick TYPE ID - Kicks object of TYPE with id ID\n" |
---|
24 | " Types: client stream sample source\n" |
---|
25 | "\n" |
---|
26 | " serveroinfo - Gets Informations about server output\n" |
---|
27 | " listclients - Gets Informations about clients\n" |
---|
28 | " liststreams - Gets Informations about streams\n" |
---|
29 | " allinfo - Get all infos\n" |
---|
30 | ); |
---|
31 | } |
---|
32 | |
---|
33 | void server_oinfo (struct roar_connection * con) { |
---|
34 | struct roar_stream s; |
---|
35 | |
---|
36 | if ( roar_server_oinfo(con, &s) == -1 ) { |
---|
37 | fprintf(stderr, "Error: can not get server output info\n"); |
---|
38 | return; |
---|
39 | } |
---|
40 | |
---|
41 | printf("Stream direction : %s\n", roar_dir2str(s.dir)); |
---|
42 | printf("Server Output rate : %i\n", s.info.rate); |
---|
43 | printf("Server Output bits : %i\n", s.info.bits); |
---|
44 | printf("Server Output channels: %i\n", s.info.channels); |
---|
45 | printf("Server Output codec : %i (%s%s)\n", s.info.codec, roar_codec2str(s.info.codec), |
---|
46 | s.info.codec == ROAR_CODEC_DEFAULT ? " native" : ""); |
---|
47 | // printf("Server Output rate: %i", s.info.rate); |
---|
48 | } |
---|
49 | |
---|
50 | void list_clients (struct roar_connection * con) { |
---|
51 | int i; |
---|
52 | int num; |
---|
53 | int h; |
---|
54 | int id[ROAR_CLIENTS_MAX]; |
---|
55 | struct roar_client c; |
---|
56 | |
---|
57 | if ( (num = roar_list_clients(con, id, ROAR_CLIENTS_MAX)) == -1 ) { |
---|
58 | fprintf(stderr, "Error: can not get client list\n"); |
---|
59 | return; |
---|
60 | } |
---|
61 | |
---|
62 | for (i = 0; i < num; i++) { |
---|
63 | printf("client %i:\n", id[i]); |
---|
64 | if ( roar_get_client(con, &c, id[i]) == -1 ) { |
---|
65 | fprintf(stderr, "Error: can not get client info\n"); |
---|
66 | continue; |
---|
67 | } |
---|
68 | printf("Player name : %s\n", c.name); |
---|
69 | if ( c.execed != -1 ) |
---|
70 | printf("Execed stream : %i\n", c.execed); |
---|
71 | |
---|
72 | for (h = 0; h < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; h++) |
---|
73 | if ( c.streams[h] != -1 ) |
---|
74 | printf("stream : %i\n", c.streams[h]); |
---|
75 | } |
---|
76 | |
---|
77 | } |
---|
78 | |
---|
79 | void list_streams (struct roar_connection * con) { |
---|
80 | int i; |
---|
81 | int num; |
---|
82 | int id[ROAR_STREAMS_MAX]; |
---|
83 | struct roar_stream s; |
---|
84 | |
---|
85 | |
---|
86 | if ( (num = roar_list_streams(con, id, ROAR_STREAMS_MAX)) == -1 ) { |
---|
87 | fprintf(stderr, "Error: can not get stream list\n"); |
---|
88 | return; |
---|
89 | } |
---|
90 | |
---|
91 | for (i = 0; i < num; i++) { |
---|
92 | printf("stream %i:\n", id[i]); |
---|
93 | if ( roar_get_stream(con, &s, id[i]) == -1 ) { |
---|
94 | fprintf(stderr, "Error: can not get stream info\n"); |
---|
95 | continue; |
---|
96 | } |
---|
97 | printf("Stream direction : %s\n", roar_dir2str(s.dir)); |
---|
98 | if ( s.pos_rel_id == -1 ) |
---|
99 | printf("Relativ position id : none (stream not synchronized)\n"); |
---|
100 | else |
---|
101 | printf("Relativ position id : %i\n", s.pos_rel_id); |
---|
102 | printf("Input rate : %i\n", s.info.rate); |
---|
103 | printf("Input bits : %i\n", s.info.bits); |
---|
104 | printf("Input channels : %i\n", s.info.channels); |
---|
105 | printf("Input codec : %i (%s%s)\n", s.info.codec, roar_codec2str(s.info.codec), |
---|
106 | s.info.codec == ROAR_CODEC_DEFAULT ? " native" : ""); |
---|
107 | } |
---|
108 | |
---|
109 | } |
---|
110 | |
---|
111 | |
---|
112 | int main (int argc, char * argv[]) { |
---|
113 | struct roar_connection con; |
---|
114 | char * server = NULL; |
---|
115 | char * k = NULL; |
---|
116 | int i; |
---|
117 | int t = 0; |
---|
118 | |
---|
119 | for (i = 1; i < argc; i++) { |
---|
120 | k = argv[i]; |
---|
121 | |
---|
122 | if ( strcmp(k, "--server") == 0 ) { |
---|
123 | server = k; |
---|
124 | } else if ( strcmp(k, "--help") == 0 ) { |
---|
125 | usage(); |
---|
126 | return 0; |
---|
127 | } else if ( *k == '-' ) { |
---|
128 | fprintf(stderr, "Error: unknown argument: %s\n", k); |
---|
129 | usage(); |
---|
130 | return 1; |
---|
131 | } else { |
---|
132 | break; |
---|
133 | } |
---|
134 | } |
---|
135 | |
---|
136 | // connect |
---|
137 | |
---|
138 | if ( roar_connect(&con, server) == -1 ) { |
---|
139 | fprintf(stderr, "Error: Can not connect to server\n"); |
---|
140 | return 1; |
---|
141 | } |
---|
142 | |
---|
143 | if ( roar_identify(&con, "roarctl") == -1 ) { |
---|
144 | fprintf(stderr, "Error: Can not identify to server\n"); |
---|
145 | return 1; |
---|
146 | } |
---|
147 | |
---|
148 | if ( i == argc ) { |
---|
149 | fprintf(stderr, "Error: No Commands given\n"); |
---|
150 | return 0; // this is not a fatal error... |
---|
151 | } |
---|
152 | |
---|
153 | for (; i < argc; i++) { |
---|
154 | k = argv[i]; |
---|
155 | // cmd is in k |
---|
156 | |
---|
157 | printf("--- [ %s ] ---\n", k); |
---|
158 | |
---|
159 | if ( !strcmp(k, "help") ) { |
---|
160 | usage(); |
---|
161 | |
---|
162 | |
---|
163 | } else if ( !strcmp(k, "standby") || !strcmp(k, "off") ) { |
---|
164 | if ( roar_set_standby(&con, ROAR_STANDBY_ACTIVE) == -1 ) { |
---|
165 | fprintf(stderr, "Error: can not set mode to standby\n"); |
---|
166 | } else { |
---|
167 | printf("going into standby\n"); |
---|
168 | } |
---|
169 | } else if ( !strcmp(k, "resume") || !strcmp(k, "on") ) { |
---|
170 | if ( roar_set_standby(&con, ROAR_STANDBY_INACTIVE) == -1 ) { |
---|
171 | fprintf(stderr, "Error: can not set mode to active\n"); |
---|
172 | } else { |
---|
173 | printf("going into active mode\n"); |
---|
174 | } |
---|
175 | |
---|
176 | } else if ( !strcmp(k, "exit") ) { |
---|
177 | if ( roar_exit(&con) == -1 ) { |
---|
178 | fprintf(stderr, "Error: can not quit server\n"); |
---|
179 | } else { |
---|
180 | printf("Server quited\n"); |
---|
181 | break; |
---|
182 | } |
---|
183 | |
---|
184 | } else if ( !strcmp(k, "standbymode") ) { |
---|
185 | t = roar_get_standby(&con); |
---|
186 | if ( t == -1 ) { |
---|
187 | fprintf(stderr, "Error: can not get stanby mode\n"); |
---|
188 | } else if ( t == ROAR_STANDBY_ACTIVE ) { |
---|
189 | printf("Server is in standby\n"); |
---|
190 | } else if ( t == ROAR_STANDBY_INACTIVE ) { |
---|
191 | printf("Server is active\n"); |
---|
192 | } else { |
---|
193 | fprintf(stderr, "Error: unknown standby mode: %i\n", t); |
---|
194 | } |
---|
195 | |
---|
196 | } else if ( !strcmp(k, "serveroinfo") ) { |
---|
197 | server_oinfo(&con); |
---|
198 | } else if ( !strcmp(k, "listclients") ) { |
---|
199 | list_clients(&con); |
---|
200 | } else if ( !strcmp(k, "liststreams") ) { |
---|
201 | list_streams(&con); |
---|
202 | } else if ( !strcmp(k, "allinfo") ) { |
---|
203 | server_oinfo(&con); |
---|
204 | printf("\n"); |
---|
205 | list_clients(&con); |
---|
206 | printf("\n"); |
---|
207 | list_streams(&con); |
---|
208 | |
---|
209 | } else if ( !strcmp(k, "kick") ) { |
---|
210 | k = argv[++i]; |
---|
211 | if ( !strcmp(k, "client") ) { |
---|
212 | t = ROAR_OT_CLIENT; |
---|
213 | } else if ( !strcmp(k, "stream") ) { |
---|
214 | t = ROAR_OT_STREAM; |
---|
215 | } else if ( !strcmp(k, "sample") ) { |
---|
216 | t = ROAR_OT_SAMPLE; |
---|
217 | } else if ( !strcmp(k, "source") ) { |
---|
218 | t = ROAR_OT_SOURCE; |
---|
219 | } else { |
---|
220 | fprintf(stderr, "Error: unknown type: %s\n", k); |
---|
221 | continue; |
---|
222 | } |
---|
223 | //t = atoi(argv[i++]); |
---|
224 | if ( roar_kick(&con, t, atoi(argv[++i])) == -1 ) { |
---|
225 | fprintf(stderr, "Error: can not kick %s\n", k); |
---|
226 | } else { |
---|
227 | printf("%s kicked\n", k); |
---|
228 | } |
---|
229 | |
---|
230 | } else { |
---|
231 | fprintf(stderr, "Error: invalid command: %s\n", k); |
---|
232 | } |
---|
233 | |
---|
234 | } |
---|
235 | |
---|
236 | roar_disconnect(&con); |
---|
237 | |
---|
238 | return 0; |
---|
239 | } |
---|
240 | |
---|
241 | //ll |
---|