/[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 921 - (show annotations) (download)
Sun Sep 24 12:55:48 2006 UTC (17 years, 7 months ago) by capela
File MIME type: text/plain
File size: 22540 byte(s)
GPL address update.

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

  ViewVC Help
Powered by ViewVC