14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 |
Lesser General Public License for more details. |
Lesser General Public License for more details. |
16 |
|
|
17 |
You should have received a copy of the GNU Lesser General Public |
You should 14have received a copy of the GNU Lesser General Public |
18 |
License along with this library; if not, write to the Free Software |
License along with this library; if not, write to the Free Software |
19 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
20 |
|
|
40 |
static void _lscp_client_evt_proc ( void *pvClient ) |
static void _lscp_client_evt_proc ( void *pvClient ) |
41 |
{ |
{ |
42 |
lscp_client_t *pClient = (lscp_client_t *) pvClient; |
lscp_client_t *pClient = (lscp_client_t *) pvClient; |
43 |
|
|
44 |
fd_set fds; // File descriptor list for select(). |
fd_set fds; // File descriptor list for select(). |
45 |
int fd, fdmax; // Maximum file descriptor number. |
int fd, fdmax; // Maximum file descriptor number. |
46 |
struct timeval tv; // For specifying a timeout value. |
struct timeval tv; // For specifying a timeout value. |
47 |
int iSelect; // Holds select return status. |
int iSelect; // Holds select return status. |
48 |
int iTimeout; |
int iTimeout; |
49 |
|
|
50 |
char achBuffer[LSCP_BUFSIZ]; |
char achBuffer[LSCP_BUFSIZ]; |
51 |
int cchBuffer; |
int cchBuffer; |
52 |
const char *pszSeps = ":\r\n"; |
const char *pszSeps = ":\r\n"; |
69 |
|
|
70 |
// Use the timeout (x10) select feature ... |
// Use the timeout (x10) select feature ... |
71 |
iTimeout = 10 * pClient->iTimeout; |
iTimeout = 10 * pClient->iTimeout; |
72 |
if (iTimeout > 1000) { |
if (iTimeout >= 1000) { |
73 |
tv.tv_sec = iTimeout / 1000; |
tv.tv_sec = iTimeout / 1000; |
74 |
iTimeout -= tv.tv_sec * 1000; |
iTimeout -= tv.tv_sec * 1000; |
75 |
} |
} |
114 |
lscp_socket_perror("_lscp_client_evt_proc: select"); |
lscp_socket_perror("_lscp_client_evt_proc: select"); |
115 |
pClient->evt.iState = 0; |
pClient->evt.iState = 0; |
116 |
} |
} |
117 |
|
|
118 |
// Finally, always signal the event. |
// Finally, always signal the event. |
119 |
lscp_cond_signal(pClient->cond); |
lscp_cond_signal(pClient->cond); |
120 |
} |
} |
164 |
closesocket(sock); |
closesocket(sock); |
165 |
return LSCP_FAILED; |
return LSCP_FAILED; |
166 |
} |
} |
167 |
|
|
168 |
// Set our socket agent struct... |
// Set our socket agent struct... |
169 |
lscp_socket_agent_init(&(pClient->evt), sock, &addr, cAddr); |
lscp_socket_agent_init(&(pClient->evt), sock, &addr, cAddr); |
170 |
|
|
171 |
// And finally the service thread... |
// And finally the service thread... |
172 |
return lscp_socket_agent_start(&(pClient->evt), _lscp_client_evt_proc, pClient, 0); |
return lscp_socket_agent_start(&(pClient->evt), _lscp_client_evt_proc, pClient, 0); |
173 |
} |
} |
198 |
|
|
199 |
// Wait on response. |
// Wait on response. |
200 |
lscp_cond_wait(pClient->cond, pClient->mutex); |
lscp_cond_wait(pClient->cond, pClient->mutex); |
201 |
|
|
202 |
// Update as naively as we can... |
// Update as naively as we can... |
203 |
if (iSubscribe) |
if (iSubscribe) |
204 |
pClient->events |= event; |
pClient->events |= event; |
337 |
lscp_device_port_info_init(&(pClient->midi_port_info)); |
lscp_device_port_info_init(&(pClient->midi_port_info)); |
338 |
lscp_param_info_init(&(pClient->audio_channel_param_info)); |
lscp_param_info_init(&(pClient->audio_channel_param_info)); |
339 |
lscp_param_info_init(&(pClient->midi_port_param_info)); |
lscp_param_info_init(&(pClient->midi_port_param_info)); |
340 |
|
lscp_server_info_init(&(pClient->server_info)); |
341 |
lscp_engine_info_init(&(pClient->engine_info)); |
lscp_engine_info_init(&(pClient->engine_info)); |
342 |
lscp_channel_info_init(&(pClient->channel_info)); |
lscp_channel_info_init(&(pClient->channel_info)); |
343 |
// Initialize error stuff. |
// Initialize error stuff. |
348 |
pClient->iStreamCount = 0; |
pClient->iStreamCount = 0; |
349 |
// Default timeout value. |
// Default timeout value. |
350 |
pClient->iTimeout = LSCP_TIMEOUT_MSECS; |
pClient->iTimeout = LSCP_TIMEOUT_MSECS; |
351 |
|
pClient->iTimeoutCount = 0; |
352 |
|
|
353 |
// Initialize the transaction mutex. |
// Initialize the transaction mutex. |
354 |
lscp_mutex_init(pClient->mutex); |
lscp_mutex_init(pClient->mutex); |
398 |
|
|
399 |
// Lock this section up. |
// Lock this section up. |
400 |
lscp_mutex_lock(pClient->mutex); |
lscp_mutex_lock(pClient->mutex); |
401 |
|
|
402 |
// Free up all cached members. |
// Free up all cached members. |
403 |
lscp_channel_info_free(&(pClient->channel_info)); |
lscp_channel_info_free(&(pClient->channel_info)); |
404 |
lscp_engine_info_free(&(pClient->engine_info)); |
lscp_engine_info_free(&(pClient->engine_info)); |
405 |
|
lscp_server_info_free(&(pClient->server_info)); |
406 |
lscp_param_info_free(&(pClient->midi_port_param_info)); |
lscp_param_info_free(&(pClient->midi_port_param_info)); |
407 |
lscp_param_info_free(&(pClient->audio_channel_param_info)); |
lscp_param_info_free(&(pClient->audio_channel_param_info)); |
408 |
lscp_device_port_info_free(&(pClient->midi_port_info)); |
lscp_device_port_info_free(&(pClient->midi_port_info)); |
503 |
lscp_status_t lscp_client_query ( lscp_client_t *pClient, const char *pszQuery ) |
lscp_status_t lscp_client_query ( lscp_client_t *pClient, const char *pszQuery ) |
504 |
{ |
{ |
505 |
lscp_status_t ret; |
lscp_status_t ret; |
506 |
|
|
507 |
// Lock this section up. |
// Lock this section up. |
508 |
lscp_mutex_lock(pClient->mutex); |
lscp_mutex_lock(pClient->mutex); |
509 |
|
|
510 |
// Just make the now guarded call. |
// Just make the now guarded call. |
511 |
ret = lscp_client_call(pClient, pszQuery); |
ret = lscp_client_call(pClient, pszQuery); |
512 |
|
|
513 |
// Unlock this section down. |
// Unlock this section down. |
514 |
lscp_mutex_unlock(pClient->mutex); |
lscp_mutex_unlock(pClient->mutex); |
515 |
|
|
516 |
return ret; |
return ret; |
517 |
} |
} |
518 |
|
|
556 |
|
|
557 |
/** |
/** |
558 |
* Register frontend for receiving event messages: |
* Register frontend for receiving event messages: |
559 |
* SUBSCRIBE CHANNELS | VOICE_COUNT | STREAM_COUNT | BUFFER_FILL |
* SUBSCRIBE CHANNEL_COUNT | VOICE_COUNT | STREAM_COUNT | BUFFER_FILL |
560 |
* | CHANNEL_INFO | MISCELLANEOUS |
* | CHANNEL_INFO | MISCELLANEOUS |
561 |
* |
* |
562 |
* @param pClient Pointer to client instance structure. |
* @param pClient Pointer to client instance structure. |
577 |
// If applicable, start the alternate connection... |
// If applicable, start the alternate connection... |
578 |
if (pClient->events == LSCP_EVENT_NONE) |
if (pClient->events == LSCP_EVENT_NONE) |
579 |
ret = _lscp_client_evt_connect(pClient); |
ret = _lscp_client_evt_connect(pClient); |
580 |
|
|
581 |
// Send the subscription commands. |
// Send the subscription commands. |
582 |
if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNELS)) |
if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_COUNT)) |
583 |
ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_CHANNELS); |
ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_CHANNEL_COUNT); |
584 |
if (ret == LSCP_OK && (events & LSCP_EVENT_VOICE_COUNT)) |
if (ret == LSCP_OK && (events & LSCP_EVENT_VOICE_COUNT)) |
585 |
ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_VOICE_COUNT); |
ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_VOICE_COUNT); |
586 |
if (ret == LSCP_OK && (events & LSCP_EVENT_STREAM_COUNT)) |
if (ret == LSCP_OK && (events & LSCP_EVENT_STREAM_COUNT)) |
601 |
|
|
602 |
/** |
/** |
603 |
* Deregister frontend from receiving UDP event messages anymore: |
* Deregister frontend from receiving UDP event messages anymore: |
604 |
* SUBSCRIBE CHANNELS | VOICE_COUNT | STREAM_COUNT | BUFFER_FILL |
* SUBSCRIBE CHANNEL_COUNT | VOICE_COUNT | STREAM_COUNT | BUFFER_FILL |
605 |
* | CHANNEL_INFO | MISCELLANEOUS |
* | CHANNEL_INFO | MISCELLANEOUS |
606 |
* |
* |
607 |
* @param pClient Pointer to client instance structure. |
* @param pClient Pointer to client instance structure. |
620 |
lscp_mutex_lock(pClient->mutex); |
lscp_mutex_lock(pClient->mutex); |
621 |
|
|
622 |
// Send the unsubscription commands. |
// Send the unsubscription commands. |
623 |
if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNELS)) |
if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_COUNT)) |
624 |
ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_CHANNELS); |
ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_CHANNEL_COUNT); |
625 |
if (ret == LSCP_OK && (events & LSCP_EVENT_VOICE_COUNT)) |
if (ret == LSCP_OK && (events & LSCP_EVENT_VOICE_COUNT)) |
626 |
ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_VOICE_COUNT); |
ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_VOICE_COUNT); |
627 |
if (ret == LSCP_OK && (events & LSCP_EVENT_STREAM_COUNT)) |
if (ret == LSCP_OK && (events & LSCP_EVENT_STREAM_COUNT)) |
772 |
|
|
773 |
if (pClient == NULL) |
if (pClient == NULL) |
774 |
return NULL; |
return NULL; |
775 |
|
|
776 |
// Lock this section up. |
// Lock this section up. |
777 |
lscp_mutex_lock(pClient->mutex); |
lscp_mutex_lock(pClient->mutex); |
778 |
|
|
809 |
|
|
810 |
if (lscp_client_call(pClient, "ADD CHANNEL\r\n") == LSCP_OK) |
if (lscp_client_call(pClient, "ADD CHANNEL\r\n") == LSCP_OK) |
811 |
iSamplerChannel = atoi(lscp_client_get_result(pClient)); |
iSamplerChannel = atoi(lscp_client_get_result(pClient)); |
812 |
|
|
813 |
// Unlock this section down. |
// Unlock this section down. |
814 |
lscp_mutex_unlock(pClient->mutex); |
lscp_mutex_unlock(pClient->mutex); |
815 |
|
|
839 |
|
|
840 |
|
|
841 |
/** |
/** |
842 |
* Getting all available engines: |
* Getting all available engines count: |
843 |
* GET AVAILABLE_ENGINES |
* GET AVAILABLE_ENGINES |
844 |
* |
* |
845 |
* @param pClient Pointer to client instance structure. |
* @param pClient Pointer to client instance structure. |
846 |
* |
* |
847 |
|
* @returns The current total number of sampler engines on success, |
848 |
|
* -1 otherwise. |
849 |
|
*/ |
850 |
|
int lscp_get_available_engines ( lscp_client_t *pClient ) |
851 |
|
{ |
852 |
|
int iAvailableEngines = -1; |
853 |
|
|
854 |
|
// Lock this section up. |
855 |
|
lscp_mutex_lock(pClient->mutex); |
856 |
|
|
857 |
|
if (lscp_client_call(pClient, "GET AVAILABLE_ENGINES\r\n") == LSCP_OK) |
858 |
|
iAvailableEngines = atoi(lscp_client_get_result(pClient)); |
859 |
|
|
860 |
|
// Unlock this section down. |
861 |
|
lscp_mutex_unlock(pClient->mutex); |
862 |
|
|
863 |
|
return iAvailableEngines; |
864 |
|
} |
865 |
|
|
866 |
|
|
867 |
|
/** |
868 |
|
* Getting all available engines: |
869 |
|
* LIST AVAILABLE_ENGINES |
870 |
|
* |
871 |
|
* @param pClient Pointer to client instance structure. |
872 |
|
* |
873 |
* @returns A NULL terminated array of engine name strings, |
* @returns A NULL terminated array of engine name strings, |
874 |
* or NULL in case of failure. |
* or NULL in case of failure. |
875 |
*/ |
*/ |
876 |
const char **lscp_get_available_engines ( lscp_client_t *pClient ) |
const char **lscp_list_available_engines ( lscp_client_t *pClient ) |
877 |
{ |
{ |
878 |
const char *pszSeps = ","; |
const char *pszSeps = ","; |
879 |
|
|
885 |
pClient->engines = NULL; |
pClient->engines = NULL; |
886 |
} |
} |
887 |
|
|
888 |
if (lscp_client_call(pClient, "GET AVAILABLE_ENGINES\r\n") == LSCP_OK) |
if (lscp_client_call(pClient, "LIST AVAILABLE_ENGINES\r\n") == LSCP_OK) |
889 |
pClient->engines = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps); |
pClient->engines = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps); |
890 |
|
|
891 |
// Unlock this section down. |
// Unlock this section down. |
943 |
} |
} |
944 |
} |
} |
945 |
else pEngineInfo = NULL; |
else pEngineInfo = NULL; |
946 |
|
|
947 |
// Unlock this section down. |
// Unlock this section down. |
948 |
lscp_mutex_unlock(pClient->mutex); |
lscp_mutex_unlock(pClient->mutex); |
949 |
|
|
976 |
|
|
977 |
// Lock this section up. |
// Lock this section up. |
978 |
lscp_mutex_lock(pClient->mutex); |
lscp_mutex_lock(pClient->mutex); |
979 |
|
|
980 |
pChannelInfo = &(pClient->channel_info); |
pChannelInfo = &(pClient->channel_info); |
981 |
lscp_channel_info_reset(pChannelInfo); |
lscp_channel_info_reset(pChannelInfo); |
982 |
|
|
1057 |
} |
} |
1058 |
} |
} |
1059 |
else pChannelInfo = NULL; |
else pChannelInfo = NULL; |
1060 |
|
|
1061 |
// Unlock this section up. |
// Unlock this section up. |
1062 |
lscp_mutex_unlock(pClient->mutex); |
lscp_mutex_unlock(pClient->mutex); |
1063 |
|
|
1250 |
else while (iStream < pClient->iStreamCount) |
else while (iStream < pClient->iStreamCount) |
1251 |
pBufferFill[iStream++].stream_usage = 0; |
pBufferFill[iStream++].stream_usage = 0; |
1252 |
} |
} |
1253 |
|
|
1254 |
// Unlock this section down. |
// Unlock this section down. |
1255 |
lscp_mutex_unlock(pClient->mutex); |
lscp_mutex_unlock(pClient->mutex); |
1256 |
|
|
1470 |
} |
} |
1471 |
|
|
1472 |
|
|
1473 |
|
/** |
1474 |
|
* Getting information about the server. |
1475 |
|
* GET SERVER INFO |
1476 |
|
* |
1477 |
|
* @param pClient Pointer to client instance structure. |
1478 |
|
* |
1479 |
|
* @returns A pointer to a @ref lscp_server_info_t structure, with all the |
1480 |
|
* information of the current connected server, or NULL in case of failure. |
1481 |
|
*/ |
1482 |
|
lscp_server_info_t *lscp_get_server_info ( lscp_client_t *pClient ) |
1483 |
|
{ |
1484 |
|
lscp_server_info_t *pServerInfo; |
1485 |
|
const char *pszResult; |
1486 |
|
const char *pszSeps = ":"; |
1487 |
|
const char *pszCrlf = "\r\n"; |
1488 |
|
char *pszToken; |
1489 |
|
char *pch; |
1490 |
|
|
1491 |
|
// Lock this section up. |
1492 |
|
lscp_mutex_lock(pClient->mutex); |
1493 |
|
|
1494 |
|
pServerInfo = &(pClient->server_info); |
1495 |
|
lscp_server_info_reset(pServerInfo); |
1496 |
|
|
1497 |
|
if (lscp_client_call(pClient, "GET SERVER INFO\r\n") == LSCP_OK) { |
1498 |
|
pszResult = lscp_client_get_result(pClient); |
1499 |
|
pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch)); |
1500 |
|
while (pszToken) { |
1501 |
|
if (strcasecmp(pszToken, "DESCRIPTION") == 0) { |
1502 |
|
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1503 |
|
if (pszToken) |
1504 |
|
lscp_unquote_dup(&(pServerInfo->description), &pszToken); |
1505 |
|
} |
1506 |
|
else if (strcasecmp(pszToken, "VERSION") == 0) { |
1507 |
|
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
1508 |
|
if (pszToken) |
1509 |
|
lscp_unquote_dup(&(pServerInfo->version), &pszToken); |
1510 |
|
} |
1511 |
|
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
1512 |
|
} |
1513 |
|
} |
1514 |
|
else pServerInfo = NULL; |
1515 |
|
|
1516 |
|
// Unlock this section down. |
1517 |
|
lscp_mutex_unlock(pClient->mutex); |
1518 |
|
|
1519 |
|
return pServerInfo; |
1520 |
|
} |
1521 |
|
|
1522 |
|
|
1523 |
// end of client.c |
// end of client.c |