--- liblscp/trunk/src/client.c 2005/02/11 13:32:19 370 +++ liblscp/trunk/src/client.c 2005/06/09 15:55:49 625 @@ -14,7 +14,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - You should have received a copy of the GNU Lesser General Public + You should 14have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA @@ -40,13 +40,13 @@ static void _lscp_client_evt_proc ( void *pvClient ) { lscp_client_t *pClient = (lscp_client_t *) pvClient; - + fd_set fds; // File descriptor list for select(). int fd, fdmax; // Maximum file descriptor number. struct timeval tv; // For specifying a timeout value. int iSelect; // Holds select return status. int iTimeout; - + char achBuffer[LSCP_BUFSIZ]; int cchBuffer; const char *pszSeps = ":\r\n"; @@ -69,7 +69,7 @@ // Use the timeout (x10) select feature ... iTimeout = 10 * pClient->iTimeout; - if (iTimeout > 1000) { + if (iTimeout >= 1000) { tv.tv_sec = iTimeout / 1000; iTimeout -= tv.tv_sec * 1000; } @@ -114,7 +114,7 @@ lscp_socket_perror("_lscp_client_evt_proc: select"); pClient->evt.iState = 0; } - + // Finally, always signal the event. lscp_cond_signal(pClient->cond); } @@ -164,10 +164,10 @@ closesocket(sock); return LSCP_FAILED; } - + // Set our socket agent struct... lscp_socket_agent_init(&(pClient->evt), sock, &addr, cAddr); - + // And finally the service thread... return lscp_socket_agent_start(&(pClient->evt), _lscp_client_evt_proc, pClient, 0); } @@ -198,7 +198,7 @@ // Wait on response. lscp_cond_wait(pClient->cond, pClient->mutex); - + // Update as naively as we can... if (iSubscribe) pClient->events |= event; @@ -337,6 +337,7 @@ lscp_device_port_info_init(&(pClient->midi_port_info)); lscp_param_info_init(&(pClient->audio_channel_param_info)); lscp_param_info_init(&(pClient->midi_port_param_info)); + lscp_server_info_init(&(pClient->server_info)); lscp_engine_info_init(&(pClient->engine_info)); lscp_channel_info_init(&(pClient->channel_info)); // Initialize error stuff. @@ -347,6 +348,7 @@ pClient->iStreamCount = 0; // Default timeout value. pClient->iTimeout = LSCP_TIMEOUT_MSECS; + pClient->iTimeoutCount = 0; // Initialize the transaction mutex. lscp_mutex_init(pClient->mutex); @@ -396,10 +398,11 @@ // Lock this section up. lscp_mutex_lock(pClient->mutex); - + // Free up all cached members. lscp_channel_info_free(&(pClient->channel_info)); lscp_engine_info_free(&(pClient->engine_info)); + lscp_server_info_free(&(pClient->server_info)); lscp_param_info_free(&(pClient->midi_port_param_info)); lscp_param_info_free(&(pClient->audio_channel_param_info)); lscp_device_port_info_free(&(pClient->midi_port_info)); @@ -500,16 +503,16 @@ lscp_status_t lscp_client_query ( lscp_client_t *pClient, const char *pszQuery ) { lscp_status_t ret; - + // Lock this section up. lscp_mutex_lock(pClient->mutex); // Just make the now guarded call. ret = lscp_client_call(pClient, pszQuery); - + // Unlock this section down. lscp_mutex_unlock(pClient->mutex); - + return ret; } @@ -553,7 +556,7 @@ /** * Register frontend for receiving event messages: - * SUBSCRIBE CHANNELS | VOICE_COUNT | STREAM_COUNT | BUFFER_FILL + * SUBSCRIBE CHANNEL_COUNT | VOICE_COUNT | STREAM_COUNT | BUFFER_FILL * | CHANNEL_INFO | MISCELLANEOUS * * @param pClient Pointer to client instance structure. @@ -574,10 +577,10 @@ // If applicable, start the alternate connection... if (pClient->events == LSCP_EVENT_NONE) ret = _lscp_client_evt_connect(pClient); - + // Send the subscription commands. - if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNELS)) - ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_CHANNELS); + if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_COUNT)) + ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_CHANNEL_COUNT); if (ret == LSCP_OK && (events & LSCP_EVENT_VOICE_COUNT)) ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_VOICE_COUNT); if (ret == LSCP_OK && (events & LSCP_EVENT_STREAM_COUNT)) @@ -598,7 +601,7 @@ /** * Deregister frontend from receiving UDP event messages anymore: - * SUBSCRIBE CHANNELS | VOICE_COUNT | STREAM_COUNT | BUFFER_FILL + * SUBSCRIBE CHANNEL_COUNT | VOICE_COUNT | STREAM_COUNT | BUFFER_FILL * | CHANNEL_INFO | MISCELLANEOUS * * @param pClient Pointer to client instance structure. @@ -617,8 +620,8 @@ lscp_mutex_lock(pClient->mutex); // Send the unsubscription commands. - if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNELS)) - ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_CHANNELS); + if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_COUNT)) + ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_CHANNEL_COUNT); if (ret == LSCP_OK && (events & LSCP_EVENT_VOICE_COUNT)) ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_VOICE_COUNT); if (ret == LSCP_OK && (events & LSCP_EVENT_STREAM_COUNT)) @@ -769,7 +772,7 @@ if (pClient == NULL) return NULL; - + // Lock this section up. lscp_mutex_lock(pClient->mutex); @@ -806,7 +809,7 @@ if (lscp_client_call(pClient, "ADD CHANNEL\r\n") == LSCP_OK) iSamplerChannel = atoi(lscp_client_get_result(pClient)); - + // Unlock this section down. lscp_mutex_unlock(pClient->mutex); @@ -836,15 +839,41 @@ /** - * Getting all available engines: + * Getting all available engines count: * GET AVAILABLE_ENGINES * * @param pClient Pointer to client instance structure. * + * @returns The current total number of sampler engines on success, + * -1 otherwise. + */ +int lscp_get_available_engines ( lscp_client_t *pClient ) +{ + int iAvailableEngines = -1; + + // Lock this section up. + lscp_mutex_lock(pClient->mutex); + + if (lscp_client_call(pClient, "GET AVAILABLE_ENGINES\r\n") == LSCP_OK) + iAvailableEngines = atoi(lscp_client_get_result(pClient)); + + // Unlock this section down. + lscp_mutex_unlock(pClient->mutex); + + return iAvailableEngines; +} + + +/** + * Getting all available engines: + * LIST AVAILABLE_ENGINES + * + * @param pClient Pointer to client instance structure. + * * @returns A NULL terminated array of engine name strings, * or NULL in case of failure. */ -const char **lscp_get_available_engines ( lscp_client_t *pClient ) +const char **lscp_list_available_engines ( lscp_client_t *pClient ) { const char *pszSeps = ","; @@ -856,7 +885,7 @@ pClient->engines = NULL; } - if (lscp_client_call(pClient, "GET AVAILABLE_ENGINES\r\n") == LSCP_OK) + if (lscp_client_call(pClient, "LIST AVAILABLE_ENGINES\r\n") == LSCP_OK) pClient->engines = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps); // Unlock this section down. @@ -914,7 +943,7 @@ } } else pEngineInfo = NULL; - + // Unlock this section down. lscp_mutex_unlock(pClient->mutex); @@ -947,7 +976,7 @@ // Lock this section up. lscp_mutex_lock(pClient->mutex); - + pChannelInfo = &(pClient->channel_info); lscp_channel_info_reset(pChannelInfo); @@ -989,6 +1018,11 @@ if (pszToken) pChannelInfo->instrument_nr = atoi(lscp_ltrim(pszToken)); } + else if (strcasecmp(pszToken, "INSTRUMENT_NAME") == 0) { + pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); + if (pszToken) + lscp_unquote_dup(&(pChannelInfo->instrument_name), &pszToken); + } else if (strcasecmp(pszToken, "INSTRUMENT_STATUS") == 0) { pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); if (pszToken) @@ -1023,7 +1057,7 @@ } } else pChannelInfo = NULL; - + // Unlock this section up. lscp_mutex_unlock(pClient->mutex); @@ -1216,7 +1250,7 @@ else while (iStream < pClient->iStreamCount) pBufferFill[iStream++].stream_usage = 0; } - + // Unlock this section down. lscp_mutex_unlock(pClient->mutex); @@ -1436,4 +1470,54 @@ } +/** + * Getting information about the server. + * GET SERVER INFO + * + * @param pClient Pointer to client instance structure. + * + * @returns A pointer to a @ref lscp_server_info_t structure, with all the + * information of the current connected server, or NULL in case of failure. + */ +lscp_server_info_t *lscp_get_server_info ( lscp_client_t *pClient ) +{ + lscp_server_info_t *pServerInfo; + const char *pszResult; + const char *pszSeps = ":"; + const char *pszCrlf = "\r\n"; + char *pszToken; + char *pch; + + // Lock this section up. + lscp_mutex_lock(pClient->mutex); + + pServerInfo = &(pClient->server_info); + lscp_server_info_reset(pServerInfo); + + if (lscp_client_call(pClient, "GET SERVER INFO\r\n") == LSCP_OK) { + pszResult = lscp_client_get_result(pClient); + pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch)); + while (pszToken) { + if (strcasecmp(pszToken, "DESCRIPTION") == 0) { + pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); + if (pszToken) + lscp_unquote_dup(&(pServerInfo->description), &pszToken); + } + else if (strcasecmp(pszToken, "VERSION") == 0) { + pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); + if (pszToken) + lscp_unquote_dup(&(pServerInfo->version), &pszToken); + } + pszToken = lscp_strtok(NULL, pszSeps, &(pch)); + } + } + else pServerInfo = NULL; + + // Unlock this section down. + lscp_mutex_unlock(pClient->mutex); + + return pServerInfo; +} + + // end of client.c