1 |
capela |
105 |
// example_server.c |
2 |
|
|
// |
3 |
|
|
/**************************************************************************** |
4 |
capela |
921 |
liblscp - LinuxSampler Control Protocol API |
5 |
capela |
869 |
Copyright (C) 2004-2006, rncbc aka Rui Nuno Capela. All rights reserved. |
6 |
capela |
105 |
|
7 |
|
|
This program is free software; you can redistribute it and/or |
8 |
|
|
modify it under the terms of the GNU General Public License |
9 |
|
|
as published by the Free Software Foundation; either version 2 |
10 |
|
|
of the License, or (at your option) any later version. |
11 |
|
|
|
12 |
|
|
This program is distributed in the hope that it will be useful, |
13 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
|
|
GNU General Public License for more details. |
16 |
|
|
|
17 |
capela |
921 |
You should have received a copy of the GNU General Public License along |
18 |
|
|
with this program; if not, write to the Free Software Foundation, Inc., |
19 |
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
20 |
capela |
105 |
|
21 |
|
|
*****************************************************************************/ |
22 |
|
|
|
23 |
|
|
#include "server.h" |
24 |
|
|
#include "parser.h" |
25 |
|
|
|
26 |
|
|
#include <time.h> |
27 |
|
|
|
28 |
|
|
#define SERVER_PORT 8888 |
29 |
|
|
|
30 |
|
|
#if defined(WIN32) |
31 |
|
|
static WSADATA _wsaData; |
32 |
|
|
#endif |
33 |
|
|
|
34 |
capela |
985 |
|
35 |
capela |
105 |
//////////////////////////////////////////////////////////////////////// |
36 |
|
|
|
37 |
|
|
lscp_status_t server_callback ( lscp_connect_t *pConnect, const char *pchBuffer, int cchBuffer, void *pvData ) |
38 |
|
|
{ |
39 |
capela |
963 |
lscp_status_t ret = LSCP_OK; |
40 |
|
|
lscp_parser_t tok; |
41 |
|
|
const char *pszResult = NULL; |
42 |
|
|
char szTemp[4096]; |
43 |
|
|
int i; |
44 |
|
|
static int iSamplerChannel = 0; |
45 |
|
|
static int iAudioDevice = 0; |
46 |
|
|
static int iMidiDevice = 0; |
47 |
capela |
983 |
static int iMidiMaps = 0; |
48 |
capela |
963 |
static int iMidiInstruments = 0; |
49 |
capela |
105 |
|
50 |
capela |
963 |
if (pchBuffer == NULL) { |
51 |
|
|
fprintf(stderr, "server_callback: addr=%s port=%d: ", |
52 |
|
|
inet_ntoa(pConnect->client.addr.sin_addr), |
53 |
|
|
htons(pConnect->client.addr.sin_port)); |
54 |
|
|
switch (cchBuffer) { |
55 |
|
|
case LSCP_CONNECT_OPEN: |
56 |
|
|
fprintf(stderr, "New client connection.\n"); |
57 |
|
|
break; |
58 |
|
|
case LSCP_CONNECT_CLOSE: |
59 |
|
|
fprintf(stderr, "Connection closed.\n"); |
60 |
|
|
break; |
61 |
|
|
} |
62 |
|
|
return ret; |
63 |
|
|
} |
64 |
capela |
105 |
|
65 |
capela |
963 |
lscp_socket_trace("server_callback", &(pConnect->client.addr), pchBuffer, cchBuffer); |
66 |
capela |
105 |
|
67 |
capela |
963 |
lscp_parser_init(&tok, pchBuffer, cchBuffer); |
68 |
capela |
105 |
|
69 |
capela |
963 |
if (lscp_parser_test(&tok, "GET")) { |
70 |
|
|
if (lscp_parser_test(&tok, "CHANNEL")) { |
71 |
|
|
if (lscp_parser_test(&tok, "INFO")) { |
72 |
|
|
// Getting sampler channel informations: |
73 |
|
|
// GET CHANNEL INFO <sampler-channel> |
74 |
|
|
pszResult = "ENGINE_NAME: DummyEngine\r\n" |
75 |
|
|
"INSTRUMENT_FILE: DummyInstrument.gig\r\n" |
76 |
|
|
"INSTRUMENT_NR: 0\r\n" |
77 |
|
|
"INSTRUMENT_NAME: Dummy Instrument\r\n" |
78 |
|
|
"INSTRUMENT_STATUS: 100\r\n" |
79 |
|
|
"AUDIO_OUTPUT_DEVICE: 0\r\n" |
80 |
|
|
"AUDIO_OUTPUT_CHANNELS: 2\r\n" |
81 |
|
|
"AUDIO_OUTPUT_ROUTING: 0,1\r\n" |
82 |
|
|
"MIDI_INPUT_DEVICE: 0\r\n" |
83 |
|
|
"MIDI_INPUT_PORT: 0\r\n" |
84 |
|
|
"MIDI_INPUT_CHANNEL: ALL\r\n" |
85 |
|
|
"VOLUME: 0.5\r\n" |
86 |
|
|
"MUTE: FALSE\r\n" |
87 |
|
|
"SOLO: TRUE\r\n" |
88 |
capela |
948 |
".\r\n"; |
89 |
capela |
963 |
} |
90 |
|
|
else if (lscp_parser_test(&tok, "VOICE_COUNT")) { |
91 |
|
|
// Current number of active voices: |
92 |
|
|
// GET CHANNEL VOICE_COUNT <sampler-channel> |
93 |
|
|
sprintf(szTemp, "%d\r\n", rand() % 100); |
94 |
|
|
pszResult = szTemp; |
95 |
|
|
} |
96 |
|
|
else if (lscp_parser_test(&tok, "STREAM_COUNT")) { |
97 |
|
|
// Current number of active disk streams: |
98 |
|
|
// GET CHANNEL STREAM_COUNT <sampler-channel> |
99 |
|
|
pszResult = "3\r\n"; |
100 |
|
|
} |
101 |
|
|
else if (lscp_parser_test(&tok, "BUFFER_FILL")) { |
102 |
|
|
if (lscp_parser_test(&tok, "BYTES")) { |
103 |
|
|
// Current fill state of disk stream buffers: |
104 |
|
|
// GET CHANNEL BUFFER_FILL BYTES <sampler-channel> |
105 |
|
|
sprintf(szTemp, "[1]%d,[2]%d,[3]%d\r\n", rand(), rand(), rand()); |
106 |
|
|
pszResult = szTemp; |
107 |
|
|
} |
108 |
|
|
else if (lscp_parser_test(&tok, "PERCENTAGE")) { |
109 |
|
|
// Current fill state of disk stream buffers: |
110 |
|
|
// GET CHANNEL BUFFER_FILL PERCENTAGE <sampler-channel> |
111 |
|
|
sprintf(szTemp, "[1]%d%%,[2]%d%%,[3]%d%%\r\n", rand() % 100, rand() % 100, rand() % 100); |
112 |
|
|
pszResult = szTemp; |
113 |
|
|
} |
114 |
|
|
else ret = LSCP_FAILED; |
115 |
|
|
} |
116 |
|
|
else ret = LSCP_FAILED; |
117 |
|
|
} |
118 |
|
|
else if (lscp_parser_test(&tok, "CHANNELS")) { |
119 |
|
|
// Current number of sampler channels: |
120 |
|
|
// GET CHANNELS |
121 |
|
|
sprintf(szTemp, "%d\r\n", iSamplerChannel); |
122 |
|
|
pszResult = szTemp; |
123 |
|
|
} |
124 |
|
|
else if (lscp_parser_test(&tok, "AVAILABLE_AUDIO_OUTPUT_DRIVERS")) { |
125 |
|
|
// Getting all available audio output driver count. |
126 |
|
|
// GET AVAILABLE_AUDIO_OUTPUT_DRIVERS |
127 |
|
|
pszResult = "2\r\n"; |
128 |
|
|
} |
129 |
|
|
else if (lscp_parser_test(&tok, "AVAILABLE_MIDI_INPUT_DRIVERS")) { |
130 |
|
|
// Getting all available MIDI input driver count. |
131 |
|
|
// GET AVAILABLE_MIDI_INPUT_DRIVERS |
132 |
|
|
pszResult = "1\r\n"; |
133 |
|
|
} |
134 |
|
|
else if (lscp_parser_test2(&tok, "AUDIO_OUTPUT_DRIVER", "INFO")) { |
135 |
|
|
// Getting informations about a specific audio output driver. |
136 |
|
|
// GET AUDIO_OUTPUT_DRIVER INFO <audio-output-type> |
137 |
|
|
if (lscp_parser_test(&tok, "Alsa")) { |
138 |
|
|
pszResult = "DESCRIPTION: 'ALSA PCM'\r\n" |
139 |
|
|
"VERSION: '1.0'\r\n" |
140 |
|
|
"PARAMETERS: channels,samplerate,active\r\n" |
141 |
|
|
".\r\n"; |
142 |
|
|
} |
143 |
|
|
else if (lscp_parser_test(&tok, "Jack")) { |
144 |
|
|
pszResult = "DESCRIPTION: JACK Audio Connection Kit\r\n" |
145 |
|
|
"VERSION: 0.98.1\r\n" |
146 |
|
|
"PARAMETERS: channels,samplerate,active\r\n" |
147 |
|
|
".\r\n"; |
148 |
|
|
} |
149 |
|
|
else ret = LSCP_FAILED; |
150 |
|
|
} |
151 |
|
|
else if (lscp_parser_test2(&tok, "MIDI_INPUT_DRIVER", "INFO")) { |
152 |
|
|
// Getting informations about a specific MIDI input driver. |
153 |
|
|
// GET MIDI_INPUT_DRIVER INFO <midi-input-type> |
154 |
|
|
if (lscp_parser_test(&tok, "Alsa")) { |
155 |
|
|
pszResult = "DESCRIPTION: ALSA Sequencer\r\n" |
156 |
|
|
"VERSION: 1.0\r\n" |
157 |
|
|
"PARAMETERS: ports,active\r\n" |
158 |
|
|
".\r\n"; |
159 |
|
|
} |
160 |
|
|
else ret = LSCP_FAILED; |
161 |
|
|
} |
162 |
|
|
else if (lscp_parser_test2(&tok, "AUDIO_OUTPUT_DRIVER_PARAMETER", "INFO")) { |
163 |
|
|
// Getting informations about a specific audio output driver parameter. |
164 |
|
|
// GET AUDIO_OUTPUT_DRIVER_PARAMETER INFO <audio-output-type> <param> |
165 |
|
|
if (lscp_parser_test(&tok, "Alsa")) { |
166 |
|
|
if (lscp_parser_test(&tok, "active")) { |
167 |
|
|
pszResult = "DESCRIPTION: 'ALSA PCM active state'\r\n" |
168 |
|
|
"TYPE: BOOL\r\n" |
169 |
|
|
"MANDATORY: TRUE\r\n" |
170 |
|
|
"FIX: TRUE\r\n" |
171 |
|
|
"MULTIPLICITY: FALSE\r\n" |
172 |
|
|
"DEPENDS: channels,samplerate,card\r\n" |
173 |
|
|
"DEFAULT: TRUE\r\n" |
174 |
|
|
"RANGE_MIN: FALSE\r\n" |
175 |
|
|
"RANGE_MAX: TRUE\r\n" |
176 |
|
|
"POSSIBILITIES: FALSE,TRUE\r\n" |
177 |
|
|
".\r\n"; |
178 |
|
|
} |
179 |
|
|
else if (lscp_parser_test(&tok, "channels")) { |
180 |
|
|
pszResult = "DESCRIPTION: 'Number of ALSA PCM channels'\r\n" |
181 |
|
|
"TYPE: INT\r\n" |
182 |
|
|
"MANDATORY: TRUE\r\n" |
183 |
|
|
"FIX: TRUE\r\n" |
184 |
|
|
"MULTIPLICITY: FALSE\r\n" |
185 |
|
|
"DEFAULT: 2\r\n" |
186 |
|
|
".\r\n"; |
187 |
|
|
} |
188 |
|
|
else if (lscp_parser_test(&tok, "samplerate")) { |
189 |
|
|
pszResult = "DESCRIPTION: 'ALSA PCM sample rate'\r\n" |
190 |
|
|
"TYPE: INT\r\n" |
191 |
|
|
"MANDATORY: TRUE\r\n" |
192 |
|
|
"FIX: TRUE\r\n" |
193 |
|
|
"MULTIPLICITY: TRUE\r\n" |
194 |
|
|
"DEFAULT: 44100\r\n" |
195 |
|
|
"POSSIBILITIES: 44100,48000,96000\r\n" |
196 |
|
|
".\r\n"; |
197 |
|
|
} |
198 |
|
|
else ret = LSCP_FAILED; |
199 |
|
|
} |
200 |
|
|
else if (lscp_parser_test(&tok, "Jack")) { |
201 |
|
|
if (lscp_parser_test(&tok, "active")) { |
202 |
|
|
pszResult = "DESCRIPTION: 'JACK active state'\r\n" |
203 |
|
|
"TYPE: BOOL\r\n" |
204 |
|
|
"MANDATORY: TRUE\r\n" |
205 |
|
|
"FIX: TRUE\r\n" |
206 |
|
|
"MULTIPLICITY: FALSE\r\n" |
207 |
|
|
"DEPENDS: channels,samplerate\r\n" |
208 |
|
|
"DEFAULT: TRUE\r\n" |
209 |
|
|
"RANGE_MIN: FALSE\r\n" |
210 |
|
|
"RANGE_MAX: TRUE\r\n" |
211 |
|
|
"POSSIBILITIES: FALSE,TRUE\r\n" |
212 |
|
|
".\r\n"; |
213 |
|
|
} |
214 |
|
|
else if (lscp_parser_test(&tok, "channels")) { |
215 |
|
|
pszResult = "DESCRIPTION: 'Number of JACK audio channels'\r\n" |
216 |
|
|
"TYPE: INT\r\n" |
217 |
|
|
"MANDATORY: TRUE\r\n" |
218 |
|
|
"FIX: TRUE\r\n" |
219 |
|
|
"MULTIPLICITY: FALSE\r\n" |
220 |
|
|
"DEFAULT: 2\r\n" |
221 |
|
|
".\r\n"; |
222 |
|
|
} |
223 |
|
|
else if (lscp_parser_test(&tok, "samplerate")) { |
224 |
|
|
pszResult = "DESCRIPTION: 'JACK sample rate'\r\n" |
225 |
|
|
"TYPE: INT\r\n" |
226 |
|
|
"MANDATORY: TRUE\r\n" |
227 |
|
|
"FIX: TRUE\r\n" |
228 |
|
|
"MULTIPLICITY: TRUE\r\n" |
229 |
|
|
"DEFAULT: 44100\r\n" |
230 |
|
|
"POSSIBILITIES: 44100,48000,96000\r\n" |
231 |
|
|
".\r\n"; |
232 |
|
|
} |
233 |
|
|
else ret = LSCP_FAILED; |
234 |
|
|
} |
235 |
|
|
else ret = LSCP_FAILED; |
236 |
|
|
} |
237 |
|
|
else if (lscp_parser_test2(&tok, "MIDI_INPUT_DRIVER_PARAMETER", "INFO")) { |
238 |
|
|
// Getting informations about a specific MIDI input driver parameter. |
239 |
|
|
// GET MIDI_INPUT_DRIVER_PARAMETER INFO <midi-input-type> <param> |
240 |
|
|
if (lscp_parser_test(&tok, "Alsa")) { |
241 |
|
|
if (lscp_parser_test(&tok, "active")) { |
242 |
|
|
pszResult = "DESCRIPTION: 'ALSA Sequencer device active state'\r\n" |
243 |
|
|
"TYPE: BOOL\r\n" |
244 |
|
|
"MANDATORY: TRUE\r\n" |
245 |
|
|
"FIX: TRUE\r\n" |
246 |
|
|
"MULTIPLICITY: FALSE\r\n" |
247 |
|
|
"DEPENDS: channels,ports\r\n" |
248 |
|
|
"DEFAULT: TRUE\r\n" |
249 |
|
|
"RANGE_MIN: FALSE\r\n" |
250 |
|
|
"RANGE_MAX: TRUE\r\n" |
251 |
|
|
"POSSIBILITIES: FALSE,TRUE\r\n" |
252 |
|
|
".\r\n"; |
253 |
|
|
} |
254 |
|
|
else if (lscp_parser_test(&tok, "ports")) { |
255 |
|
|
pszResult = "DESCRIPTION: 'Number of ALSA Sequencer ports'\r\n" |
256 |
|
|
"TYPE: INT\r\n" |
257 |
|
|
"MANDATORY: FALSE\r\n" |
258 |
|
|
"FIX: FALSE\r\n" |
259 |
|
|
"MULTIPLICITY: FALSE\r\n" |
260 |
|
|
"DEFAULT: 1\r\n" |
261 |
|
|
"RANGE_MIN: 1\r\n" |
262 |
|
|
"RANGE_MAX: 4\r\n" |
263 |
|
|
".\r\n"; |
264 |
|
|
} |
265 |
|
|
else ret = LSCP_FAILED; |
266 |
|
|
} |
267 |
|
|
else ret = LSCP_FAILED; |
268 |
|
|
} |
269 |
|
|
else if (lscp_parser_test2(&tok, "AUDIO_OUTPUT_DEVICE", "INFO")) { |
270 |
|
|
// Getting informations about a specific audio output device. |
271 |
|
|
// GET AUDIO_OUTPUT_DEVICE INFO <audio-device-id> |
272 |
|
|
if (lscp_parser_nextint(&tok) < iAudioDevice) { |
273 |
|
|
pszResult = "driver: Alsa\r\n" |
274 |
|
|
"active: TRUE\r\n" |
275 |
|
|
"channels: 2\r\n" |
276 |
|
|
"samplerate: 44100\r\n" |
277 |
|
|
".\r\n"; |
278 |
|
|
} |
279 |
|
|
else ret = LSCP_FAILED; |
280 |
|
|
} |
281 |
|
|
else if (lscp_parser_test2(&tok, "MIDI_INPUT_DEVICE", "INFO")) { |
282 |
|
|
// Getting informations about a specific MIDI input device. |
283 |
|
|
// GET MIDI_INPUT_DEVICE INFO <midi-device-id> |
284 |
|
|
if (lscp_parser_nextint(&tok) < iMidiDevice) { |
285 |
|
|
pszResult = "driver: Alsa\r\n" |
286 |
|
|
"active: TRUE\r\n" |
287 |
|
|
"channels: 16\r\n" |
288 |
|
|
"ports: 1\r\n" |
289 |
|
|
".\r\n"; |
290 |
|
|
} |
291 |
|
|
else ret = LSCP_FAILED; |
292 |
|
|
} |
293 |
|
|
else if (lscp_parser_test2(&tok, "AUDIO_OUTPUT_CHANNEL", "INFO")) { |
294 |
|
|
// Getting informations about an audio channel. |
295 |
|
|
// GET AUDIO_OUTPUT_CHANNEL INFO <audio-device-id> <audio-channel> |
296 |
|
|
if (lscp_parser_nextint(&tok) < iAudioDevice) { |
297 |
|
|
pszResult = "name: DummyMonitor\r\n" |
298 |
|
|
"is_mix_channel: FALSE\r\n" |
299 |
|
|
"mix_channel_destination: 0\r\n" |
300 |
|
|
".\r\n"; |
301 |
|
|
} |
302 |
|
|
else ret = LSCP_FAILED; |
303 |
|
|
} |
304 |
|
|
else if (lscp_parser_test2(&tok, "MIDI_INPUT_PORT", "INFO")) { |
305 |
|
|
// Getting informations about a MIDI port. |
306 |
|
|
// GET MIDI_INPUT_PORT INFO <midi-device-id> <midi-port> |
307 |
|
|
if (lscp_parser_nextint(&tok) < iMidiDevice) { |
308 |
|
|
pszResult = "name: DummyKeyboard\r\n" |
309 |
|
|
"alsa_seq_bindings: '64:0'\r\n" |
310 |
|
|
".\r\n"; |
311 |
|
|
} |
312 |
|
|
else ret = LSCP_FAILED; |
313 |
|
|
} |
314 |
|
|
else if (lscp_parser_test2(&tok, "AUDIO_OUTPUT_CHANNEL_PARAMETER", "INFO")) { |
315 |
|
|
// Getting informations about specific audio channel parameter. |
316 |
|
|
// GET AUDIO_OUTPUT_CHANNEL_PARAMETER INFO <audio-device-id> <audio-channel> <param> |
317 |
|
|
if (lscp_parser_nextint(&tok) < iAudioDevice) { |
318 |
|
|
lscp_parser_nextint(&tok); |
319 |
|
|
if (lscp_parser_test(&tok, "is_mix_channel")) { |
320 |
|
|
pszResult = "DESCRIPTION: 'Whether this is an audio mix channel'\r\n" |
321 |
|
|
"TYPE: BOOL\r\n" |
322 |
|
|
"MANDATORY: TRUE\r\n" |
323 |
|
|
"FIX: FALSE\r\n" |
324 |
|
|
"MULTIPLICITY: FALSE\r\n" |
325 |
|
|
"POSSIBILITIES: FALSE,TRUE\r\n" |
326 |
|
|
".\r\n"; |
327 |
|
|
} |
328 |
|
|
else if (lscp_parser_test(&tok, "mix_channel_destination")) { |
329 |
|
|
pszResult = "DESCRIPTION: 'Audio mix channel destination'\r\n" |
330 |
|
|
"TYPE: INT\r\n" |
331 |
|
|
"MANDATORY: TRUE\r\n" |
332 |
|
|
"FIX: FALSE\r\n" |
333 |
|
|
"MULTIPLICITY: TRUE\r\n" |
334 |
|
|
"POSSIBILITIES: 0,1\r\n" |
335 |
|
|
".\r\n"; |
336 |
|
|
} |
337 |
|
|
else ret = LSCP_FAILED; |
338 |
|
|
} |
339 |
|
|
else ret = LSCP_FAILED; |
340 |
|
|
} |
341 |
|
|
else if (lscp_parser_test2(&tok, "MIDI_INPUT_PORT_PARAMETER", "INFO")) { |
342 |
|
|
// Getting informations about specific MIDI port parameter. |
343 |
|
|
// GET MIDI_INPUT_PORT_PARAMETER INFO <midi-device-id> <midi-port> <param> |
344 |
|
|
if (lscp_parser_nextint(&tok) < iMidiDevice) { |
345 |
|
|
lscp_parser_nextint(&tok); |
346 |
|
|
if (lscp_parser_test(&tok, "alsa_seq_bindings")) { |
347 |
|
|
pszResult = "DESCRIPTION: 'Alsa sequencer port bindings'\r\n" |
348 |
|
|
"TYPE: STRING\r\n" |
349 |
|
|
"MANDATORY: TRUE\r\n" |
350 |
|
|
"FIX: FALSE\r\n" |
351 |
|
|
"MULTIPLICITY: TRUE\r\n" |
352 |
|
|
"POSSIBILITIES: '64:0','68:0','68:1'\r\n" |
353 |
|
|
".\r\n"; |
354 |
|
|
} |
355 |
|
|
else ret = LSCP_FAILED; |
356 |
|
|
} |
357 |
|
|
else ret = LSCP_FAILED; |
358 |
|
|
} |
359 |
|
|
else if (lscp_parser_test(&tok, "AUDIO_OUTPUT_DEVICES")) { |
360 |
|
|
// Getting all created audio output device count. |
361 |
|
|
// GET AUDIO_OUTPUT_DEVICES |
362 |
|
|
sprintf(szTemp, "%d\r\n", iAudioDevice); |
363 |
|
|
pszResult = szTemp; |
364 |
|
|
} |
365 |
|
|
else if (lscp_parser_test(&tok, "MIDI_INPUT_DEVICES")) { |
366 |
|
|
// Getting all created MID input device count. |
367 |
|
|
// GET MIDI_INPUT_DEVICES |
368 |
|
|
sprintf(szTemp, "%d\r\n", iMidiDevice); |
369 |
|
|
pszResult = szTemp; |
370 |
|
|
} |
371 |
|
|
else if (lscp_parser_test(&tok, "AVAILABLE_ENGINES")) { |
372 |
|
|
// Getting all available engine count: |
373 |
|
|
// GET AVAILABLE_ENGINES |
374 |
|
|
pszResult = "3\r\n"; |
375 |
|
|
} |
376 |
|
|
else if (lscp_parser_test2(&tok, "SERVER", "INFO")) { |
377 |
|
|
// Getting information about the server. |
378 |
|
|
// GET SERVER INFO |
379 |
|
|
sprintf(szTemp, "DESCRIPTION: example_server (%s) %s\r\n" |
380 |
|
|
"VERSION: %s\r\n.\r\n", lscp_server_package(), |
381 |
|
|
lscp_server_build(), lscp_server_version()); |
382 |
|
|
pszResult = szTemp; |
383 |
|
|
} |
384 |
|
|
else if (lscp_parser_test2(&tok, "ENGINE", "INFO")) { |
385 |
|
|
// Getting information about an engine. |
386 |
|
|
// GET ENGINE INFO <engine-name> |
387 |
|
|
if (lscp_parser_test(&tok, "GigEngine")) { |
388 |
|
|
pszResult = "DESCRIPTION: GigaSampler Engine\r\n" |
389 |
|
|
"VERSION: 0.3\r\n" |
390 |
|
|
".\r\n"; |
391 |
|
|
} |
392 |
|
|
else if (lscp_parser_test(&tok, "DLSEngine")) { |
393 |
|
|
pszResult = "DESCRIPTION: 'DLS Generic Engine'\r\n" |
394 |
|
|
"VERSION: 0.2\r\n" |
395 |
|
|
".\r\n"; |
396 |
|
|
} |
397 |
|
|
else if (lscp_parser_test(&tok, "AkaiEngine")) { |
398 |
|
|
pszResult = "DESCRIPTION: Akai Sampler Engine\r\n" |
399 |
|
|
"VERSION: 0.1\r\n" |
400 |
|
|
".\r\n"; |
401 |
|
|
} |
402 |
|
|
else ret = LSCP_FAILED; |
403 |
|
|
} |
404 |
|
|
else if (lscp_parser_test(&tok, "TOTAL_VOICE_COUNT")) { |
405 |
|
|
// Current number of active voices: |
406 |
|
|
// GET TOTAL_VOICE_COUNT |
407 |
|
|
sprintf(szTemp, "%d\r\n", rand() % 100); |
408 |
|
|
pszResult = szTemp; |
409 |
|
|
} |
410 |
|
|
else if (lscp_parser_test(&tok, "TOTAL_VOICE_COUNT_MAX")) { |
411 |
|
|
// Maximum amount of active voices: |
412 |
|
|
// GET TOTAL_VOICE_COUNT_MAX |
413 |
|
|
sprintf(szTemp, "%d\r\n", rand() % 100); |
414 |
|
|
pszResult = szTemp; |
415 |
|
|
} |
416 |
|
|
else if (lscp_parser_test(&tok, "MIDI_INSTRUMENTS")) { |
417 |
|
|
// Get the total count of MIDI instrument map entries: |
418 |
|
|
// GET MIDI_INSTRUMENTS |
419 |
|
|
sprintf(szTemp, "%d\r\n", iMidiInstruments); |
420 |
|
|
pszResult = szTemp; |
421 |
|
|
} |
422 |
capela |
983 |
else if (lscp_parser_test(&tok, "MIDI_INSTRUMENT_MAPS")) { |
423 |
|
|
// Get the total count of MIDI instrument maps: |
424 |
|
|
// GET MIDI_INSTRUMENT_MAPS |
425 |
|
|
sprintf(szTemp, "%d\r\n", iMidiMaps); |
426 |
|
|
pszResult = szTemp; |
427 |
|
|
} |
428 |
|
|
else if (lscp_parser_test2(&tok, "MIDI_INSTRUMENT_MAP", "INFO")) { |
429 |
capela |
963 |
// Getting information about a MIDI instrument map entry: |
430 |
capela |
983 |
// GET MIDI_INSTRUMENT_MAP INFO <midi-map> |
431 |
capela |
985 |
strcpy(szTemp, "NAME: "); |
432 |
|
|
switch (lscp_parser_nextint(&tok)) { |
433 |
|
|
case 0: |
434 |
|
|
strcat(szTemp, "Chromatic\r\n"); |
435 |
|
|
break; |
436 |
|
|
case 1: |
437 |
|
|
strcat(szTemp, "Drum Kits\r\n"); |
438 |
|
|
break; |
439 |
|
|
} |
440 |
|
|
strcat(szTemp, ".\r\n"); |
441 |
|
|
pszResult = szTemp; |
442 |
capela |
983 |
} |
443 |
|
|
else if (lscp_parser_test2(&tok, "MIDI_INSTRUMENT", "INFO")) { |
444 |
|
|
// Getting information about a MIDI instrument map entry: |
445 |
|
|
// GET MIDI_INSTRUMENT INFO <midi-map> <midi-bank> <midi-prog> |
446 |
capela |
963 |
pszResult = "NAME: DummyName\r\n" |
447 |
|
|
"ENGINE_NAME: DummyEngine\r\n" |
448 |
|
|
"INSTRUMENT_FILE: DummyInstrument.gig\r\n" |
449 |
|
|
"INSTRUMENT_NR: 0\r\n" |
450 |
|
|
"INSTRUMENT_NAME: Dummy Instrument\r\n" |
451 |
|
|
"LOAD_MODE: ON_DEMAND\r\n" |
452 |
|
|
"VOLUME: 0.5\r\n" |
453 |
|
|
".\r\n"; |
454 |
|
|
} |
455 |
|
|
else ret = LSCP_FAILED; |
456 |
|
|
} |
457 |
|
|
else if (lscp_parser_test(&tok, "LIST")) { |
458 |
|
|
if (lscp_parser_test(&tok, "CHANNELS")) { |
459 |
|
|
// Getting all created sampler channel list. |
460 |
|
|
// LIST CHANNELS |
461 |
capela |
983 |
szTemp[0] = (char) 0; |
462 |
capela |
963 |
for (i = 0; i < iSamplerChannel && strlen(szTemp) < sizeof(szTemp) - 8; i++) { |
463 |
|
|
if (i > 0) |
464 |
|
|
strcat(szTemp, ","); |
465 |
|
|
sprintf(szTemp + strlen(szTemp), "%d", i); |
466 |
|
|
} |
467 |
|
|
strcat(szTemp, "\r\n"); |
468 |
|
|
pszResult = szTemp; |
469 |
|
|
} |
470 |
|
|
else if (lscp_parser_test(&tok, "AVAILABLE_ENGINES")) { |
471 |
|
|
// Getting all available engines: |
472 |
|
|
// LIST AVAILABLE_ENGINES |
473 |
|
|
pszResult = "GigEngine,DLSEngine,AkaiEngine\r\n"; |
474 |
|
|
} |
475 |
|
|
else if (lscp_parser_test(&tok, "AVAILABLE_AUDIO_OUTPUT_DRIVERS")) { |
476 |
|
|
// Getting all available audio output drivers. |
477 |
|
|
// LIST AVAILABLE_AUDIO_OUTPUT_DRIVERS |
478 |
|
|
pszResult = "ALSA,JACK\r\n"; |
479 |
|
|
} |
480 |
|
|
else if (lscp_parser_test(&tok, "AVAILABLE_MIDI_INPUT_DRIVERS")) { |
481 |
|
|
// Getting all available MIDI input drivers. |
482 |
|
|
// LIST AVAILABLE_MIDI_INPUT_DRIVERS |
483 |
|
|
pszResult = "ALSA\r\n"; |
484 |
|
|
} |
485 |
|
|
else if (lscp_parser_test(&tok, "AUDIO_OUTPUT_DEVICES")) { |
486 |
|
|
// Getting all created audio output device list. |
487 |
|
|
// LIST AUDIO_OUTPUT_DEVICES |
488 |
capela |
983 |
szTemp[0] = (char) 0; |
489 |
capela |
963 |
for (i = 0; i < iAudioDevice && strlen(szTemp) < sizeof(szTemp) - 8; i++) { |
490 |
|
|
if (i > 0) |
491 |
|
|
strcat(szTemp, ","); |
492 |
|
|
sprintf(szTemp + strlen(szTemp), "%d", i); |
493 |
|
|
} |
494 |
|
|
strcat(szTemp, "\r\n"); |
495 |
|
|
pszResult = szTemp; |
496 |
|
|
} |
497 |
|
|
else if (lscp_parser_test(&tok, "MIDI_INPUT_DEVICES")) { |
498 |
|
|
// Getting all created MID input device list. |
499 |
|
|
// LIST MIDI_INPUT_DEVICES |
500 |
capela |
983 |
szTemp[0] = (char) 0; |
501 |
capela |
963 |
for (i = 0; i < iMidiDevice && strlen(szTemp) < sizeof(szTemp) - 8; i++) { |
502 |
|
|
if (i > 0) |
503 |
|
|
strcat(szTemp, ","); |
504 |
|
|
sprintf(szTemp + strlen(szTemp), "%d", i); |
505 |
|
|
} |
506 |
|
|
strcat(szTemp, "\r\n"); |
507 |
|
|
pszResult = szTemp; |
508 |
|
|
} |
509 |
|
|
else if (lscp_parser_test(&tok, "MIDI_INSTRUMENTS")) { |
510 |
|
|
// Getting indeces of all MIDI instrument map entries: |
511 |
|
|
// LIST MIDI_INSTRUMENTS |
512 |
capela |
983 |
szTemp[0] = (char) 0; |
513 |
capela |
963 |
for (i = 0; i < iMidiInstruments && strlen(szTemp) < sizeof(szTemp) - 16; i++) { |
514 |
|
|
if (i > 0) |
515 |
|
|
strcat(szTemp, ","); |
516 |
|
|
sprintf(szTemp + strlen(szTemp), "{0,%d,%d}", i / 128, i % 128); |
517 |
|
|
} |
518 |
|
|
strcat(szTemp, "\r\n"); |
519 |
|
|
pszResult = szTemp; |
520 |
|
|
} |
521 |
capela |
983 |
else if (lscp_parser_test(&tok, "MIDI_INSTRUMENT_MAPS")) { |
522 |
|
|
// Getting indeces of all MIDI instrument map entries: |
523 |
|
|
// LIST MIDI_INSTRUMENT_MAPS |
524 |
|
|
szTemp[0] = (char) 0; |
525 |
|
|
for (i = 0; i < iMidiMaps && strlen(szTemp) < sizeof(szTemp) - 8; i++) { |
526 |
|
|
if (i > 0) |
527 |
|
|
strcat(szTemp, ","); |
528 |
|
|
sprintf(szTemp + strlen(szTemp), "%d", i); |
529 |
|
|
} |
530 |
|
|
strcat(szTemp, "\r\n"); |
531 |
|
|
pszResult = szTemp; |
532 |
|
|
} |
533 |
capela |
963 |
else ret = LSCP_FAILED; |
534 |
|
|
} |
535 |
|
|
else if (lscp_parser_test(&tok, "SET")) { |
536 |
|
|
if (lscp_parser_test(&tok, "CHANNEL")) { |
537 |
|
|
if (lscp_parser_test(&tok, "VOLUME")) { |
538 |
|
|
// Setting channel volume: |
539 |
|
|
// SET CHANNEL VOLUME <sampler-channel> <volume> |
540 |
|
|
} |
541 |
|
|
else if (lscp_parser_test(&tok, "MUTE")) { |
542 |
|
|
// Muting a sampler channel: |
543 |
|
|
// SET CHANNEL MUTE <sampler-channel> <mute> |
544 |
|
|
} |
545 |
|
|
else if (lscp_parser_test(&tok, "SOLO")) { |
546 |
|
|
// Soloing a sampler channel: |
547 |
|
|
// SET CHANNEL SOLO <sampler-channel> <solo> |
548 |
|
|
} |
549 |
|
|
else if (lscp_parser_test(&tok, "AUDIO_OUTPUT_TYPE")) { |
550 |
|
|
// Setting audio output type: |
551 |
|
|
// SET CHANNEL AUDIO_OUTPUT_TYPE <sampler-channel> <audio-output-type> |
552 |
|
|
} |
553 |
|
|
else if (lscp_parser_test(&tok, "AUDIO_OUTPUT_DEVICE")) { |
554 |
|
|
// Setting audio output device: |
555 |
|
|
// SET CHANNEL AUDIO_OUTPUT_DEVICE <sampler-channel> <device-id> |
556 |
|
|
} |
557 |
|
|
else if (lscp_parser_test(&tok, "AUDIO_OUTPUT_CHANNEL")) { |
558 |
|
|
// Setting audio output channel: |
559 |
|
|
// SET CHANNEL AUDIO_OUTPUT_CHANNEL <sampler-channel> <audio-in> <audio-out> |
560 |
|
|
} |
561 |
|
|
else if (lscp_parser_test(&tok, "MIDI_INPUT_TYPE")) { |
562 |
|
|
// Setting MIDI input type: |
563 |
|
|
// SET CHANNEL MIDI_INPUT_TYPE <sampler-channel> <midi-input-type> |
564 |
|
|
} |
565 |
|
|
else if (lscp_parser_test(&tok, "MIDI_INPUT_DEVICE")) { |
566 |
|
|
// Setting MIDI input device: |
567 |
|
|
// SET CHANNEL MIDI_INPUT_DEVICE <sampler-channel> <device-id> |
568 |
|
|
} |
569 |
|
|
else if (lscp_parser_test(&tok, "MIDI_INPUT_PORT")) { |
570 |
|
|
// Setting MIDI input port: |
571 |
|
|
// SET CHANNEL MIDI_INPUT_PORT <sampler-channel> <midi-input-port> |
572 |
|
|
} |
573 |
|
|
else if (lscp_parser_test(&tok, "MIDI_INPUT_CHANNEL")) { |
574 |
|
|
// Setting MIDI input channel: |
575 |
|
|
// SET CHANNEL MIDI_INPUT_CHANNEL <sampler-channel> <midi-input-chan> |
576 |
|
|
} |
577 |
capela |
985 |
else if (lscp_parser_test(&tok, "MIDI_INSTRUMENT_MAP")) { |
578 |
|
|
// Setting MIDI instrument mapl: |
579 |
|
|
// SET CHANNEL MIDI_INSTRUMENT_MAP <sampler-channel> <midi-map> |
580 |
|
|
} |
581 |
capela |
963 |
else ret = LSCP_FAILED; |
582 |
|
|
} |
583 |
capela |
983 |
else if (lscp_parser_test2(&tok, "MIDI_INSTRUMENT_MAP", "NAME")) { |
584 |
|
|
// Setting MIDI instrument map name: |
585 |
|
|
// SET MIDI_INSTRUMENT_MAP NAME <midi-map> <map-name> |
586 |
|
|
} |
587 |
capela |
963 |
else ret = LSCP_FAILED; |
588 |
|
|
} |
589 |
|
|
else if (lscp_parser_test(&tok, "LOAD")) { |
590 |
|
|
if (lscp_parser_test(&tok, "ENGINE")) { |
591 |
|
|
// Loading a sampler engine: |
592 |
|
|
// LOAD ENGINE <engine-name> <sampler-channel> |
593 |
|
|
} |
594 |
|
|
else if (lscp_parser_test(&tok, "INSTRUMENT")) { |
595 |
|
|
// Loading an instrument: |
596 |
|
|
// LOAD INSTRUMENT [NON_MODAL] <filename> <instr-index> <sampler-channel> |
597 |
|
|
} |
598 |
|
|
else ret = LSCP_FAILED; |
599 |
|
|
} |
600 |
capela |
983 |
else if (lscp_parser_test(&tok, "ADD")) { |
601 |
|
|
if (lscp_parser_test(&tok, "CHANNEL")) { |
602 |
|
|
// Adding a new sampler channel: |
603 |
|
|
// ADD CHANNEL |
604 |
|
|
if (iSamplerChannel < 16) { |
605 |
|
|
sprintf(szTemp, "OK[%d]\r\n", iSamplerChannel++); |
606 |
|
|
pszResult = szTemp; |
607 |
|
|
} else { |
608 |
|
|
iSamplerChannel = 0; |
609 |
|
|
ret = LSCP_FAILED; |
610 |
|
|
} |
611 |
capela |
963 |
} |
612 |
capela |
983 |
else if (lscp_parser_test(&tok, "MIDI_INSTRUMENT_MAP")) { |
613 |
|
|
// Adding a new MIDI instrument map: |
614 |
|
|
// ADD MIDI_INSTRUMENT_MAP <map-name> |
615 |
|
|
if (iMidiMaps < 2) { |
616 |
|
|
sprintf(szTemp, "OK[%d]\r\n", iMidiMaps++); |
617 |
|
|
pszResult = szTemp; |
618 |
|
|
} else { |
619 |
|
|
iMidiMaps = 0; |
620 |
|
|
ret = LSCP_FAILED; |
621 |
|
|
} |
622 |
|
|
} |
623 |
capela |
963 |
} |
624 |
capela |
983 |
else if (lscp_parser_test(&tok, "REMOVE")) { |
625 |
|
|
if (lscp_parser_test(&tok, "CHANNEL")) { |
626 |
|
|
// Removing a sampler channel: |
627 |
|
|
// REMOVE CHANNEL <sampler-channel> |
628 |
|
|
if (lscp_parser_nextint(&tok) >= 0) |
629 |
|
|
iSamplerChannel--; |
630 |
|
|
else |
631 |
|
|
ret = LSCP_FAILED; |
632 |
|
|
} |
633 |
|
|
else if (lscp_parser_test(&tok, "MIDI_INSTRUMENT_MAP")) { |
634 |
|
|
// Removing a MIDI instrument map: |
635 |
|
|
// REMOVE MIDI_INSTRUMENT_MAP <midi-map> |
636 |
|
|
if (lscp_parser_nextint(&tok) >= 0) |
637 |
|
|
iMidiMaps--; |
638 |
|
|
else |
639 |
|
|
ret = LSCP_FAILED; |
640 |
|
|
} |
641 |
capela |
963 |
} |
642 |
|
|
else if (lscp_parser_test(&tok, "RESET")) { |
643 |
|
|
if (lscp_parser_test(&tok, "CHANNEL")) { |
644 |
|
|
// Resetting a sampler channel: |
645 |
|
|
// RESET CHANNEL <sampler-channel> |
646 |
|
|
if (lscp_parser_nextint(&tok) > iSamplerChannel) |
647 |
|
|
ret = LSCP_FAILED; |
648 |
|
|
} else { |
649 |
|
|
// Reset sampler: |
650 |
|
|
// RESET |
651 |
|
|
iSamplerChannel = 0; |
652 |
|
|
iAudioDevice = 0; |
653 |
|
|
iMidiDevice = 0; |
654 |
|
|
} |
655 |
|
|
} |
656 |
|
|
else if (lscp_parser_test(&tok, "CREATE")) { |
657 |
|
|
if (lscp_parser_test(&tok, "AUDIO_OUTPUT_DEVICE")) { |
658 |
|
|
// Creating an audio output device. |
659 |
|
|
// CREATE AUDIO_OUTPUT_DEVICE <audio-output-driver> [<params>] |
660 |
|
|
if (iAudioDevice < 8) { |
661 |
|
|
sprintf(szTemp, "OK[%d]\r\n", iAudioDevice++); |
662 |
|
|
pszResult = szTemp; |
663 |
|
|
} else { |
664 |
|
|
iAudioDevice = 0; |
665 |
|
|
ret = LSCP_FAILED; |
666 |
|
|
} |
667 |
|
|
} |
668 |
|
|
else if (lscp_parser_test(&tok, "MIDI_INPUT_DEVICE")) { |
669 |
|
|
// Creating an MIDI input device. |
670 |
|
|
// CREATE MIDI_INPUT_DEVICE <midi-input-driver> [<params>] |
671 |
|
|
if (iMidiDevice < 8) { |
672 |
|
|
sprintf(szTemp, "OK[%d]\r\n", iMidiDevice++); |
673 |
|
|
pszResult = szTemp; |
674 |
|
|
} else { |
675 |
|
|
iMidiDevice = 0; |
676 |
|
|
ret = LSCP_FAILED; |
677 |
|
|
} |
678 |
|
|
} |
679 |
|
|
else ret = LSCP_FAILED; |
680 |
|
|
} |
681 |
|
|
else if (lscp_parser_test(&tok, "DESTROY")) { |
682 |
|
|
if (lscp_parser_test(&tok, "AUDIO_OUTPUT_DEVICE")) { |
683 |
|
|
// Destroying an audio output device. |
684 |
|
|
// DESTROY AUDIO_OUTPUT_DEVICE <audio-device-id> |
685 |
|
|
if (lscp_parser_nextint(&tok) < iAudioDevice) |
686 |
|
|
iAudioDevice--; |
687 |
|
|
else |
688 |
|
|
ret = LSCP_FAILED; |
689 |
|
|
} |
690 |
|
|
else if (lscp_parser_test(&tok, "MIDI_INPUT_DEVICE")) { |
691 |
|
|
// Destroying an MIDI intput device. |
692 |
|
|
// DESTROY MIDI_INPUT_DEVICE <midi-device-id> |
693 |
|
|
if (lscp_parser_nextint(&tok) < iMidiDevice) |
694 |
|
|
iMidiDevice--; |
695 |
|
|
else |
696 |
|
|
ret = LSCP_FAILED; |
697 |
|
|
} |
698 |
|
|
else ret = LSCP_FAILED; |
699 |
|
|
} |
700 |
|
|
else if (lscp_parser_test2(&tok, "MAP", "MIDI_INSTRUMENT")) { |
701 |
|
|
// Create or replace a MIDI instrumnet map entry: |
702 |
capela |
983 |
// MAP MIDI_INSTRUMENT <midi-map> <midi-bank> <midi-prog> |
703 |
capela |
963 |
// <engine-name> <filename> <instr-index> <volume> <load-mode> [<name>] |
704 |
|
|
iMidiInstruments++; |
705 |
|
|
} |
706 |
|
|
else if (lscp_parser_test2(&tok, "UNMAP", "MIDI_INSTRUMENT")) { |
707 |
|
|
// Remove an entry from the MIDI instrument map: |
708 |
capela |
983 |
// UNMAP MIDI_INSTRUMENT <midi-map> <midi-bank> <midi-prog> |
709 |
capela |
963 |
if (iMidiInstruments > 0) |
710 |
|
|
iMidiInstruments--; |
711 |
|
|
else |
712 |
|
|
ret = LSCP_FAILED; |
713 |
|
|
} |
714 |
|
|
else if (lscp_parser_test2(&tok, "CLEAR", "MIDI_INSTRUMENTS")) { |
715 |
|
|
// Clear the MIDI instrumnet map: |
716 |
|
|
// CLEAR MIDI_INSTRUMENTS |
717 |
|
|
} |
718 |
|
|
else if (lscp_parser_test(&tok, "SUBSCRIBE")) { |
719 |
|
|
// Register frontend for receiving event notification messages: |
720 |
|
|
// SUBSCRIBE <event> |
721 |
|
|
ret = lscp_server_subscribe(pConnect, lscp_event_from_text(lscp_parser_next(&tok))); |
722 |
|
|
} |
723 |
|
|
else if (lscp_parser_test(&tok, "UNSUBSCRIBE")) { |
724 |
|
|
// Deregister frontend for not receiving event notification messages anymore: |
725 |
|
|
// UNSUBSCRIBE <event> |
726 |
|
|
ret = lscp_server_unsubscribe(pConnect, lscp_event_from_text(lscp_parser_next(&tok))); |
727 |
|
|
} |
728 |
|
|
else if (lscp_parser_test(&tok, "QUIT")) { |
729 |
|
|
// Close client connection: |
730 |
|
|
// QUIT |
731 |
|
|
lscp_parser_free(&tok); |
732 |
|
|
return LSCP_FAILED; // Disconnect. |
733 |
|
|
} |
734 |
|
|
else ret = LSCP_FAILED; |
735 |
capela |
105 |
|
736 |
capela |
963 |
lscp_parser_free(&tok); |
737 |
capela |
105 |
|
738 |
capela |
963 |
if (pszResult == NULL) |
739 |
|
|
pszResult = (ret == LSCP_OK ? "OK\r\n" : "ERR:1:Failed\r\n"); |
740 |
capela |
105 |
|
741 |
capela |
963 |
fprintf(stderr, "> %s", pszResult); |
742 |
capela |
105 |
|
743 |
capela |
963 |
return lscp_server_result(pConnect, pszResult, strlen(pszResult)); |
744 |
capela |
105 |
} |
745 |
|
|
|
746 |
capela |
985 |
|
747 |
capela |
105 |
//////////////////////////////////////////////////////////////////////// |
748 |
|
|
|
749 |
capela |
189 |
|
750 |
capela |
105 |
void server_usage (void) |
751 |
|
|
{ |
752 |
capela |
963 |
printf("\n %s %s (Build: %s)\n", lscp_server_package(), lscp_server_version(), lscp_server_build()); |
753 |
capela |
105 |
|
754 |
capela |
963 |
fputs("\n Available server commands: help, exit, quit, list", stdout); |
755 |
|
|
fputs("\n (all else are broadcast verbatim to subscribers)\n\n", stdout); |
756 |
capela |
105 |
} |
757 |
|
|
|
758 |
|
|
void server_prompt (void) |
759 |
|
|
{ |
760 |
capela |
963 |
fputs("lscp_server> ", stdout); |
761 |
capela |
105 |
} |
762 |
|
|
|
763 |
|
|
int main (int argc, char *argv[] ) |
764 |
|
|
{ |
765 |
capela |
963 |
lscp_server_t *pServer; |
766 |
|
|
char szLine[200]; |
767 |
|
|
int cchLine; |
768 |
|
|
lscp_connect_t *p; |
769 |
capela |
105 |
|
770 |
|
|
#if defined(WIN32) |
771 |
capela |
963 |
if (WSAStartup(MAKEWORD(1, 1), &_wsaData) != 0) { |
772 |
|
|
fprintf(stderr, "lscp_server: WSAStartup failed.\n"); |
773 |
|
|
return -1; |
774 |
|
|
} |
775 |
capela |
105 |
#endif |
776 |
|
|
|
777 |
capela |
963 |
srand(time(NULL)); |
778 |
capela |
105 |
|
779 |
capela |
963 |
pServer = lscp_server_create(SERVER_PORT, server_callback, NULL); |
780 |
|
|
if (pServer == NULL) |
781 |
|
|
return -1; |
782 |
capela |
105 |
|
783 |
capela |
963 |
server_usage(); |
784 |
|
|
server_prompt(); |
785 |
capela |
105 |
|
786 |
capela |
963 |
while (fgets(szLine, sizeof(szLine), stdin)) { |
787 |
capela |
105 |
|
788 |
capela |
963 |
cchLine = strlen(szLine); |
789 |
|
|
while (cchLine > 0 && (szLine[cchLine - 1] == '\n' || szLine[cchLine - 1] == '\r')) |
790 |
|
|
cchLine--; |
791 |
|
|
szLine[cchLine] = '\0'; |
792 |
capela |
105 |
|
793 |
capela |
963 |
if (strcmp(szLine, "exit") == 0 || strcmp(szLine, "quit") == 0) |
794 |
|
|
break; |
795 |
|
|
else |
796 |
|
|
if (strcmp(szLine, "list") == 0) { |
797 |
|
|
for (p = pServer->connects.first; p; p = p->next) { |
798 |
|
|
printf("client: sock=%d addr=%s port=%d events=0x%04x.\n", |
799 |
|
|
p->client.sock, |
800 |
|
|
inet_ntoa(p->client.addr.sin_addr), |
801 |
|
|
ntohs(p->client.addr.sin_port), |
802 |
|
|
(int) p->events |
803 |
|
|
); |
804 |
|
|
} |
805 |
|
|
} |
806 |
|
|
else |
807 |
|
|
if (cchLine > 0 && strcmp(szLine, "help") != 0) |
808 |
|
|
lscp_server_broadcast(pServer, LSCP_EVENT_MISCELLANEOUS, szLine, strlen(szLine)); |
809 |
|
|
else |
810 |
|
|
server_usage(); |
811 |
capela |
105 |
|
812 |
capela |
963 |
server_prompt(); |
813 |
|
|
} |
814 |
capela |
105 |
|
815 |
capela |
963 |
lscp_server_destroy(pServer); |
816 |
capela |
105 |
|
817 |
|
|
#if defined(WIN32) |
818 |
capela |
963 |
WSACleanup(); |
819 |
capela |
105 |
#endif |
820 |
|
|
|
821 |
capela |
963 |
return 0; |
822 |
capela |
105 |
} |
823 |
|
|
|
824 |
|
|
// end of example_server.c |