/[svn]/liblscp/trunk/examples/example_client.c
ViewVC logotype

Contents of /liblscp/trunk/examples/example_client.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 523 - (show annotations) (download)
Mon May 9 10:17:12 2005 UTC (15 years ago) by capela
File MIME type: text/plain
File size: 21688 byte(s)
* [bug #9] Fixed for a LSCP command syntax convention
consistency, regarding the enumeration of available
sampler engines, Audio and MIDI drivers; this has
affected the signature of the following functions:
  lscp_get_available_engines();
  lscp_get_available_audio_drivers();
  lscp_get_available_midi_drivers();
which are now returning an integer count of engines
and drivers, respectively, while the following
functions are now being introduced:
  lscp_list_available_engines();
  lscp_list_available_audio_drivers();
  lscp_list_available_midi_drivers();
taking on the previous functionality, returning
a comma separated list of names.

1 // example_client.c
2 //
3 /****************************************************************************
4 Copyright (C) 2004-2005, rncbc aka Rui Nuno Capela. All rights reserved.
5
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
20 *****************************************************************************/
21
22 #include "lscp/client.h"
23 #include "lscp/device.h"
24
25 #include <time.h>
26
27 #define SERVER_PORT 8888
28
29 #if defined(WIN32)
30 static WSADATA _wsaData;
31 #endif
32
33 ////////////////////////////////////////////////////////////////////////
34
35 lscp_status_t client_callback ( lscp_client_t *pClient, lscp_event_t event, const char *pchData, int cchData, void *pvData )
36 {
37 lscp_status_t ret = LSCP_FAILED;
38
39 char *pszData = (char *) malloc(cchData + 1);
40 if (pszData) {
41 memcpy(pszData, pchData, cchData);
42 pszData[cchData] = (char) 0;
43 printf("client_callback: event=%s (0x%04x) [%s]\n", lscp_event_to_text(event), (int) event, pszData);
44 free(pszData);
45 ret = LSCP_OK;
46 }
47
48 return ret;
49 }
50
51 ////////////////////////////////////////////////////////////////////////
52
53 int client_test_int ( int i )
54 {
55 printf("%d\n", i);
56 return (i >= 0 ? 0 : 1);
57 }
58
59
60 int client_test_status ( lscp_status_t s )
61 {
62 const char *pszStatus;
63
64 switch (s) {
65 case LSCP_OK: pszStatus = "OK"; break;
66 case LSCP_FAILED: pszStatus = "FAILED"; break;
67 case LSCP_ERROR: pszStatus = "ERROR"; break;
68 case LSCP_WARNING: pszStatus = "WARNING"; break;
69 case LSCP_TIMEOUT: pszStatus = "TIMEOUT"; break;
70 case LSCP_QUIT: pszStatus = "QUIT"; break;
71 default: pszStatus = "NONE"; break;
72 }
73 printf("%s\n", pszStatus);
74 return (s == LSCP_OK ? 0 : 1);
75 }
76
77
78 int client_test_isplit ( int *piSplit )
79 {
80 int i;
81
82 printf("{");
83 for (i = 0; piSplit && piSplit[i] >= 0; i++) {
84 if (i > 0)
85 printf(",");
86 printf(" %d", piSplit[i]);
87 }
88 printf(" }\n");
89 return 0;
90 }
91
92
93 int client_test_szsplit ( char **ppszSplit )
94 {
95 int i;
96
97 printf("{");
98 for (i = 0; ppszSplit && ppszSplit[i]; i++) {
99 if (i > 0)
100 printf(",");
101 printf(" %s", ppszSplit[i]);
102 }
103 printf(" }\n");
104 return 0;
105 }
106
107
108 int client_test_params ( lscp_param_t *pParams )
109 {
110 int i;
111
112 printf("{");
113 for (i = 0; pParams && pParams[i].key; i++) {
114 if (i > 0)
115 printf(",");
116 printf(" %s='%s'", pParams[i].key, pParams[i].value);
117 }
118 printf(" }\n");
119 return 0;
120 }
121
122
123 int client_test_param_info ( lscp_param_info_t *pParamInfo )
124 {
125 const char *pszType;
126
127 if (pParamInfo == NULL) {
128 printf("(nil)\n");
129 return 1;
130 }
131 switch (pParamInfo->type) {
132 case LSCP_TYPE_BOOL: pszType = "BOOL"; break;
133 case LSCP_TYPE_INT: pszType = "INT"; break;
134 case LSCP_TYPE_FLOAT: pszType = "FLOAT"; break;
135 case LSCP_TYPE_STRING: pszType = "STRING"; break;
136 default: pszType = "NONE"; break;
137 }
138 printf("{\n");
139 printf(" param_info.type = %d (%s)\n", (int) pParamInfo->type, pszType);
140 printf(" param_info.description = %s\n", pParamInfo->description);
141 printf(" param_info.mandatory = %d\n", pParamInfo->mandatory);
142 printf(" param_info.fix = %d\n", pParamInfo->fix);
143 printf(" param_info.multiplicity = %d\n", pParamInfo->multiplicity);
144 printf(" param_info.depends = "); client_test_szsplit(pParamInfo->depends);
145 printf(" param_info.defaultv = %s\n", pParamInfo->defaultv);
146 printf(" param_info.range_min = %s\n", pParamInfo->range_min);
147 printf(" param_info.range_max = %s\n", pParamInfo->range_max);
148 printf(" param_info.possibilities = "); client_test_szsplit(pParamInfo->possibilities);
149 printf(" }\n");
150 return 0;
151 }
152
153
154 int client_test_driver_info ( lscp_driver_info_t *pDriverInfo )
155 {
156 if (pDriverInfo == NULL) {
157 printf("(nil)\n");
158 return 1;
159 }
160 printf("{\n");
161 printf(" driver_info.description = %s\n", pDriverInfo->description);
162 printf(" driver_info.version = %s\n", pDriverInfo->version);
163 printf(" driver_info.parameters = "); client_test_szsplit(pDriverInfo->parameters);
164 printf(" }\n");
165 return 0;
166 }
167
168
169 int client_test_device_info ( lscp_device_info_t *pDeviceInfo )
170 {
171 if (pDeviceInfo == NULL) {
172 printf("(nil)\n");
173 return 1;
174 }
175 printf("{\n");
176 printf(" device_info.driver = %s\n", pDeviceInfo->driver);
177 printf(" device_info.params = "); client_test_params(pDeviceInfo->params);
178 printf(" }\n");
179 return 0;
180 }
181
182
183 int client_test_device_port_info ( lscp_device_port_info_t *pDevicePortInfo )
184 {
185 if (pDevicePortInfo == NULL) {
186 printf("(nil)\n");
187 return 1;
188 }
189 printf("{\n");
190 printf(" device_port_info.name = %s\n", pDevicePortInfo->name);
191 printf(" device_port_info.params = "); client_test_params(pDevicePortInfo->params);
192 printf(" }\n");
193 return 0;
194 }
195
196
197 int client_test_engine_info ( lscp_engine_info_t *pEngineInfo )
198 {
199 if (pEngineInfo == NULL) {
200 printf("(nil)\n");
201 return 1;
202 }
203 printf("{\n");
204 printf(" engine_info.description = %s\n", pEngineInfo->description);
205 printf(" engine_info.version = %s\n", pEngineInfo->version);
206 printf(" }\n");
207 return 0;
208 }
209
210
211 int client_test_channel_info ( lscp_channel_info_t *pChannelInfo )
212 {
213 if (pChannelInfo == NULL) {
214 printf("(nil)\n");
215 return 1;
216 }
217 printf("{\n");
218 printf(" channel_info.engine_name = %s\n", pChannelInfo->engine_name);
219 printf(" channel_info.audio_device = %d\n", pChannelInfo->audio_device);
220 printf(" channel_info.audio_channels = %d\n", pChannelInfo->audio_channels);
221 printf(" channel_info.audio_routing = "); client_test_szsplit(pChannelInfo->audio_routing);
222 printf(" channel_info.instrument_file = %s\n", pChannelInfo->instrument_file);
223 printf(" channel_info.instrument_nr = %d\n", pChannelInfo->instrument_nr);
224 printf(" channel_info.instrument_name = %s\n", pChannelInfo->instrument_name);
225 printf(" channel_info.instrument_status = %d\n", pChannelInfo->instrument_status);
226 printf(" channel_info.midi_device = %d\n", pChannelInfo->midi_device);
227 printf(" channel_info.midi_port = %d\n", pChannelInfo->midi_port);
228 printf(" channel_info.midi_channel = %d\n", pChannelInfo->midi_channel);
229 printf(" channel_info.volume = %g\n", pChannelInfo->volume);
230 printf(" }\n");
231 return 0;
232 }
233
234
235 int client_test_buffer_fill ( lscp_buffer_fill_t *pBufferFill )
236 {
237 if (pBufferFill == NULL) {
238 printf("(nil)\n");
239 return 1;
240 }
241 printf("{ <%p> }\n", pBufferFill);
242 return 0;
243 }
244
245
246 ////////////////////////////////////////////////////////////////////////
247
248 static int g_test_step = 0;
249 static int g_test_count = 0;
250 static int g_test_fails = 0;
251
252
253 void client_test_start ( clock_t *pclk ) { *pclk = clock(); }
254 float client_test_elapsed ( clock_t *pclk ) { return (float) ((long) clock() - *pclk) / (float) CLOCKS_PER_SEC; }
255
256 typedef int * isplit;
257 typedef char ** szsplit;
258 typedef lscp_status_t status;
259 typedef lscp_driver_info_t * driver_info;
260 typedef lscp_device_info_t * device_info;
261 typedef lscp_device_port_info_t * device_port_info;
262 typedef lscp_param_info_t * param_info;
263 typedef lscp_engine_info_t * engine_info;
264 typedef lscp_channel_info_t * channel_info;
265 typedef lscp_buffer_fill_t * buffer_fill;
266
267 #define CLIENT_TEST(p, t, x) { clock_t c; void *v; g_test_count++; \
268 printf("\n" #x ":\n"); client_test_start(&c); v = (void *) (x); \
269 printf(" elapsed=%gs errno=%d result='%s...' ret=", \
270 client_test_elapsed(&c), \
271 lscp_client_get_errno(p), \
272 lscp_client_get_result(p)); \
273 if (client_test_##t((t)(v))) { g_test_fails++; getchar(); } \
274 else if (g_test_step) getchar(); }
275
276
277 void client_test_engine ( lscp_client_t *pClient, const char *pszEngine, const char *pszAudioDriver, int iAudioDevice, const char *pszMidiDriver, int iMidiDevice )
278 {
279 int iSamplerChannel;
280
281 printf("\n--- pszEngine=\"%s\" pszAudioDevice=\"%s\" iAudioDevice=%d pszMidiDevice=\"%s\" iMidiDevice=%d ---\n", pszEngine, pszAudioDriver, iAudioDevice, pszMidiDriver, iMidiDevice);
282 CLIENT_TEST(pClient, engine_info, lscp_get_engine_info(pClient, pszEngine));
283 CLIENT_TEST(pClient, int, lscp_get_channels(pClient));
284 CLIENT_TEST(pClient, isplit, lscp_list_channels(pClient));
285 CLIENT_TEST(pClient, int, iSamplerChannel = lscp_add_channel(pClient));
286 printf("\n--- iSamplerChannel=%d ---\n", iSamplerChannel);
287 CLIENT_TEST(pClient, channel_info, lscp_get_channel_info(pClient, iSamplerChannel));
288 CLIENT_TEST(pClient, status, lscp_load_engine(pClient, pszEngine, iSamplerChannel));
289 CLIENT_TEST(pClient, status, lscp_load_instrument(pClient, "DefaultInstrument.gig", 0, iSamplerChannel));
290 CLIENT_TEST(pClient, int, lscp_get_channel_voice_count(pClient, iSamplerChannel));
291 CLIENT_TEST(pClient, int, lscp_get_channel_stream_count(pClient, iSamplerChannel));
292 CLIENT_TEST(pClient, int, lscp_get_channel_stream_usage(pClient, iSamplerChannel));
293 CLIENT_TEST(pClient, buffer_fill, lscp_get_channel_buffer_fill(pClient, LSCP_USAGE_BYTES, iSamplerChannel));
294 CLIENT_TEST(pClient, buffer_fill, lscp_get_channel_buffer_fill(pClient, LSCP_USAGE_PERCENTAGE, iSamplerChannel));
295 CLIENT_TEST(pClient, status, lscp_set_channel_audio_type(pClient, iSamplerChannel, pszAudioDriver));
296 CLIENT_TEST(pClient, status, lscp_set_channel_audio_device(pClient, iSamplerChannel, 0));
297 CLIENT_TEST(pClient, status, lscp_set_channel_audio_channel(pClient, iSamplerChannel, 0, 1));
298 CLIENT_TEST(pClient, status, lscp_set_channel_midi_type(pClient, iSamplerChannel, pszMidiDriver));
299 CLIENT_TEST(pClient, status, lscp_set_channel_midi_device(pClient, iSamplerChannel, 0));
300 CLIENT_TEST(pClient, status, lscp_set_channel_midi_channel(pClient, iSamplerChannel, 0));
301 CLIENT_TEST(pClient, status, lscp_set_channel_midi_port(pClient, iSamplerChannel, 0));
302 CLIENT_TEST(pClient, status, lscp_set_channel_volume(pClient, iSamplerChannel, 0.5));
303 CLIENT_TEST(pClient, channel_info, lscp_get_channel_info(pClient, iSamplerChannel));
304 CLIENT_TEST(pClient, status, lscp_reset_channel(pClient, iSamplerChannel));
305 CLIENT_TEST(pClient, status, lscp_remove_channel(pClient, iSamplerChannel));
306 }
307
308
309 void client_test_midi_port ( lscp_client_t *pClient, int iMidiDevice, int iMidiPort )
310 {
311 lscp_device_port_info_t *pMidiPortInfo;
312 const char *pszParam;
313 int i;
314
315 printf("\n--- iMidiDevice=%d iMidiPort=%d ---\n", iMidiDevice, iMidiPort);
316 CLIENT_TEST(pClient, device_port_info, pMidiPortInfo = lscp_get_midi_port_info(pClient, iMidiDevice, iMidiPort));
317 if (pMidiPortInfo && pMidiPortInfo->params) {
318 for (i = 0; pMidiPortInfo->params[i].key; i++) {
319 pszParam = pMidiPortInfo->params[i].key;
320 printf("\n--- iMidiDevice=%d iMidiPort=%d pszParam=\"%s\" ---\n", iMidiDevice, iMidiPort, pszParam);
321 CLIENT_TEST(pClient, param_info, lscp_get_midi_port_param_info(pClient, iMidiDevice, iMidiPort, pszParam));
322 }
323 }
324 }
325
326
327 void client_test_audio_channel ( lscp_client_t *pClient, int iAudioDevice, int iAudioChannel )
328 {
329 lscp_device_port_info_t *pAudioChannelInfo;
330 const char *pszParam;
331 int i;
332
333 printf("\n--- iAudioDevice=%d iAudioChannel=%d ---\n", iAudioDevice, iAudioChannel);
334 CLIENT_TEST(pClient, device_port_info, pAudioChannelInfo = lscp_get_audio_channel_info(pClient, iAudioDevice, iAudioChannel));
335 if (pAudioChannelInfo && pAudioChannelInfo->params) {
336 for (i = 0; pAudioChannelInfo->params[i].key; i++) {
337 pszParam = pAudioChannelInfo->params[i].key;
338 printf("\n--- iAudioDevice=%d iAudioChannel=%d pszParam=\"%s\" ---\n", iAudioDevice, iAudioChannel, pszParam);
339 CLIENT_TEST(pClient, param_info, lscp_get_audio_channel_param_info(pClient, iAudioDevice, iAudioChannel, pszParam));
340 }
341 }
342 }
343
344
345 void client_test_midi_device ( lscp_client_t *pClient, int iMidiDevice )
346 {
347 lscp_device_info_t *pDeviceInfo;
348 const char *pszValue;
349 int iMidiPort, iMidiPorts;
350
351 printf("\n--- iMidiDevice=%d ---\n", iMidiDevice);
352 CLIENT_TEST(pClient, device_info, pDeviceInfo = lscp_get_midi_device_info(pClient, iMidiDevice));
353 if (pDeviceInfo && pDeviceInfo->params) {
354 pszValue = lscp_get_param_value(pDeviceInfo->params, "ports");
355 if (pszValue) {
356 iMidiPorts = atoi(pszValue);
357 for (iMidiPort = 0; iMidiPort < iMidiPorts; iMidiPort++)
358 client_test_midi_port(pClient, iMidiDevice, iMidiPort);
359 }
360 }
361 }
362
363
364 void client_test_audio_device ( lscp_client_t *pClient, int iAudioDevice )
365 {
366 lscp_device_info_t *pDeviceInfo;
367 const char *pszValue;
368 int iAudioChannel, iAudioChannels;
369
370 printf("\n--- iAudioDevice=%d ---\n", iAudioDevice);
371 CLIENT_TEST(pClient, device_info, pDeviceInfo = lscp_get_audio_device_info(pClient, iAudioDevice));
372 if (pDeviceInfo && pDeviceInfo->params) {
373 pszValue = lscp_get_param_value(pDeviceInfo->params, "channels");
374 if (pszValue) {
375 iAudioChannels = atoi(pszValue);
376 for (iAudioChannel = 0; iAudioChannel < iAudioChannels; iAudioChannel++)
377 client_test_audio_channel(pClient, iAudioDevice, iAudioChannel);
378 }
379 }
380 }
381
382
383 void client_test_midi_driver ( lscp_client_t *pClient, const char *pszMidiDriver )
384 {
385 lscp_driver_info_t *pDriverInfo;
386 const char *pszParam;
387 int i;
388
389 printf("\n--- pszMidiDriver=\"%s\" ---\n", pszMidiDriver);
390 CLIENT_TEST(pClient, driver_info, pDriverInfo = lscp_get_midi_driver_info(pClient, pszMidiDriver));
391 if (pDriverInfo && pDriverInfo->parameters) {
392 for (i = 0; pDriverInfo->parameters[i]; i++) {
393 pszParam = pDriverInfo->parameters[i];
394 printf("\n--- pszMidiDriver=\"%s\" pszParam=\"%s\" ---\n", pszMidiDriver, pszParam);
395 CLIENT_TEST(pClient, param_info, lscp_get_midi_driver_param_info(pClient, pszMidiDriver, pszParam, NULL));
396 }
397 }
398 }
399
400
401 void client_test_audio_driver ( lscp_client_t *pClient, const char *pszAudioDriver )
402 {
403 lscp_driver_info_t *pDriverInfo;
404 const char *pszParam;
405 int i;
406
407 printf("\n--- pszAudioDriver=\"%s\" ---\n", pszAudioDriver);
408 CLIENT_TEST(pClient, driver_info, pDriverInfo = lscp_get_audio_driver_info(pClient, pszAudioDriver));
409 if (pDriverInfo && pDriverInfo->parameters) {
410 for (i = 0; pDriverInfo->parameters[i]; i++) {
411 pszParam = pDriverInfo->parameters[i];
412 printf("\n--- pszAudioDriver=\"%s\" pszParam=\"%s\" ---\n", pszAudioDriver, pszParam);
413 CLIENT_TEST(pClient, param_info, lscp_get_audio_driver_param_info(pClient, pszAudioDriver, pszParam, NULL));
414 }
415 }
416 }
417
418
419 void client_test_all ( lscp_client_t *pClient, int step )
420 {
421 const char **ppszAudioDrivers, **ppszMidiDrivers, **ppszEngines;
422 const char *pszAudioDriver, *pszMidiDriver, *pszEngine;
423 int iAudioDriver, iMidiDriver, iEngine;
424 int iAudio, iAudioDevice, iMidi, iMidiDevice;
425 int iNewAudioDevice, iNewMidiDevice;
426 int *piAudioDevices, *piMidiDevices;
427
428 g_test_step = step;
429 g_test_count = 0;
430 g_test_fails = 0;
431
432 CLIENT_TEST(pClient, int, lscp_get_available_audio_drivers(pClient));
433 CLIENT_TEST(pClient, szsplit, ppszAudioDrivers = lscp_list_available_audio_drivers(pClient));
434 if (ppszAudioDrivers == NULL) {
435 fprintf(stderr, "client_test: No audio drivers available.\n");
436 return;
437 }
438
439 CLIENT_TEST(pClient, int, lscp_get_available_midi_drivers(pClient));
440 CLIENT_TEST(pClient, szsplit, ppszMidiDrivers = lscp_list_available_midi_drivers(pClient));
441 if (ppszMidiDrivers == NULL) {
442 fprintf(stderr, "client_test: No MIDI drivers available.\n");
443 return;
444 }
445
446 CLIENT_TEST(pClient, int, lscp_get_available_engines(pClient));
447 CLIENT_TEST(pClient, szsplit, ppszEngines = lscp_list_available_engines(pClient));
448 if (ppszEngines == NULL) {
449 fprintf(stderr, "client_test: No engines available.\n");
450 return;
451 }
452
453 for (iAudioDriver = 0; ppszAudioDrivers[iAudioDriver]; iAudioDriver++) {
454 pszAudioDriver = ppszAudioDrivers[iAudioDriver];
455 client_test_audio_driver(pClient, pszAudioDriver);
456 CLIENT_TEST(pClient, int, iNewAudioDevice = lscp_create_audio_device(pClient, pszAudioDriver, NULL));
457 CLIENT_TEST(pClient, int, lscp_get_audio_devices(pClient));
458 CLIENT_TEST(pClient, isplit, piAudioDevices = lscp_list_audio_devices(pClient));
459 for (iAudio = 0; piAudioDevices && piAudioDevices[iAudio] >= 0; iAudio++) {
460 iAudioDevice = piAudioDevices[iAudio];
461 client_test_audio_device(pClient, iAudioDevice);
462 for (iMidiDriver = 0; ppszMidiDrivers[iMidiDriver]; iMidiDriver++) {
463 pszMidiDriver = ppszMidiDrivers[iMidiDriver];
464 client_test_midi_driver(pClient, pszMidiDriver);
465 CLIENT_TEST(pClient, int, iNewMidiDevice = lscp_create_midi_device(pClient, pszMidiDriver, NULL));
466 CLIENT_TEST(pClient, int, lscp_get_midi_devices(pClient));
467 CLIENT_TEST(pClient, isplit, piMidiDevices = lscp_list_midi_devices(pClient));
468 for (iMidi = 0; piMidiDevices && piMidiDevices[iMidi] >= 0; iMidi++) {
469 iMidiDevice = piMidiDevices[iMidi];
470 client_test_midi_device(pClient, iMidiDevice);
471 for (iEngine = 0; ppszEngines[iEngine]; iEngine++) {
472 pszEngine = ppszEngines[iEngine];
473 client_test_engine(pClient, pszEngine, pszAudioDriver, iAudioDevice, pszMidiDriver, iMidiDevice);
474 }
475 }
476 CLIENT_TEST(pClient, status, lscp_destroy_midi_device(pClient, iNewMidiDevice));
477 }
478 }
479 CLIENT_TEST(pClient, status, lscp_destroy_audio_device(pClient, iNewAudioDevice));
480 }
481
482 CLIENT_TEST(pClient, status, lscp_reset_sampler(pClient));
483
484 printf("\n\n");
485 printf(" Total: %d tests, %d failed.\n\n", g_test_count, g_test_fails);
486 }
487
488
489 ////////////////////////////////////////////////////////////////////////
490
491 void client_usage (void)
492 {
493 printf("\n %s %s (Build: %s)\n", lscp_client_package(), lscp_client_version(), lscp_client_build());
494
495 fputs("\n Available commands: help, test[step], exit, quit, subscribe, unsubscribe", stdout);
496 fputs("\n (all else are sent verbatim to server)\n\n", stdout);
497
498 }
499
500 void client_prompt (void)
501 {
502 fputs("lscp_client> ", stdout);
503 }
504
505 int main (int argc, char *argv[] )
506 {
507 lscp_client_t *pClient;
508 char *pszHost = "localhost";
509 char szLine[1024];
510 int cchLine;
511 lscp_status_t ret;
512
513 #if defined(WIN32)
514 if (WSAStartup(MAKEWORD(1, 1), &_wsaData) != 0) {
515 fprintf(stderr, "lscp_client: WSAStartup failed.\n");
516 return -1;
517 }
518 #endif
519
520 if (argc > 1)
521 pszHost = argv[1];
522
523 pClient = lscp_client_create(pszHost, SERVER_PORT, client_callback, NULL);
524 if (pClient == NULL)
525 return -1;
526
527 client_usage();
528 client_prompt();
529
530 while (fgets(szLine, sizeof(szLine) - 3, stdin)) {
531
532 cchLine = strlen(szLine);
533 while (cchLine > 0 && (szLine[cchLine - 1] == '\n' || szLine[cchLine - 1] == '\r'))
534 cchLine--;
535 szLine[cchLine] = '\0';
536
537 if (strcmp(szLine, "exit") == 0 || strcmp(szLine, "quit") == 0)
538 break;
539 else
540 if (strcmp(szLine, "subscribe") == 0)
541 lscp_client_subscribe(pClient, LSCP_EVENT_MISCELLANEOUS);
542 else
543 if (strcmp(szLine, "unsubscribe") == 0)
544 lscp_client_unsubscribe(pClient, LSCP_EVENT_MISCELLANEOUS);
545 else
546 if (strcmp(szLine, "test") == 0)
547 client_test_all(pClient, 0);
548 else
549 if (strcmp(szLine, "teststep") == 0 || strcmp(szLine, "test step") == 0)
550 client_test_all(pClient, 1);
551 else
552 if (cchLine > 0 && strcmp(szLine, "help") != 0) {
553 szLine[cchLine++] = '\r';
554 szLine[cchLine++] = '\n';
555 szLine[cchLine] = '\0';
556 ret = lscp_client_query(pClient, szLine);
557 printf("%s\n(errno = %d)\n", lscp_client_get_result(pClient), lscp_client_get_errno(pClient));
558 if (ret == LSCP_QUIT)
559 break;
560 }
561 else client_usage();
562
563 client_prompt();
564 }
565
566 lscp_client_destroy(pClient);
567
568 #if defined(WIN32)
569 WSACleanup();
570 #endif
571
572 return 0;
573 }
574
575 // end of example_client.c

  ViewVC Help
Powered by ViewVC