/[svn]/liblscp/trunk/src/client.c
ViewVC logotype

Diff of /liblscp/trunk/src/client.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 278 by capela, Mon Oct 11 11:59:31 2004 UTC revision 564 by capela, Sun May 22 22:02:00 2005 UTC
# Line 2  Line 2 
2  //  //
3  /****************************************************************************  /****************************************************************************
4     liblscp - LinuxSampler Control Protocol API     liblscp - LinuxSampler Control Protocol API
5     Copyright (C) 2004, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2004-2005, rncbc aka Rui Nuno Capela. All rights reserved.
6    
7     This library is free software; you can redistribute it and/or     This library is free software; you can redistribute it and/or
8     modify it under the terms of the GNU Lesser General Public     modify it under the terms of the GNU Lesser General Public
# Line 40  static lscp_status_t    _lscp_client_evt Line 40  static lscp_status_t    _lscp_client_evt
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";
# Line 111  static void _lscp_client_evt_proc ( void Line 111  static void _lscp_client_evt_proc ( void
111              }              }
112          }   // Check if select has in error.          }   // Check if select has in error.
113          else if (iSelect < 0) {          else if (iSelect < 0) {
114              lscp_socket_perror("_lscp_client_call: 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      }      }
# Line 164  static lscp_status_t _lscp_client_evt_co Line 164  static lscp_status_t _lscp_client_evt_co
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  }  }
# Line 198  static lscp_status_t _lscp_client_evt_re Line 198  static lscp_status_t _lscp_client_evt_re
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;
# Line 337  lscp_client_t* lscp_client_create ( cons Line 337  lscp_client_t* lscp_client_create ( cons
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.
# Line 396  lscp_status_t lscp_client_destroy ( lscp Line 397  lscp_status_t lscp_client_destroy ( lscp
397    
398      // Lock this section up.      // Lock this section up.
399      lscp_mutex_lock(pClient->mutex);      lscp_mutex_lock(pClient->mutex);
400        
401      // Free up all cached members.      // Free up all cached members.
402      lscp_channel_info_free(&(pClient->channel_info));      lscp_channel_info_free(&(pClient->channel_info));
403      lscp_engine_info_free(&(pClient->engine_info));      lscp_engine_info_free(&(pClient->engine_info));
404        lscp_server_info_free(&(pClient->server_info));
405      lscp_param_info_free(&(pClient->midi_port_param_info));      lscp_param_info_free(&(pClient->midi_port_param_info));
406      lscp_param_info_free(&(pClient->audio_channel_param_info));      lscp_param_info_free(&(pClient->audio_channel_param_info));
407      lscp_device_port_info_free(&(pClient->midi_port_info));      lscp_device_port_info_free(&(pClient->midi_port_info));
# Line 500  int lscp_client_get_timeout ( lscp_clien Line 502  int lscp_client_get_timeout ( lscp_clien
502  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 )
503  {  {
504      lscp_status_t ret;      lscp_status_t ret;
505        
506      // Lock this section up.      // Lock this section up.
507      lscp_mutex_lock(pClient->mutex);      lscp_mutex_lock(pClient->mutex);
508    
509      // Just make the now guarded call.      // Just make the now guarded call.
510      ret = lscp_client_call(pClient, pszQuery);      ret = lscp_client_call(pClient, pszQuery);
511        
512      // Unlock this section down.      // Unlock this section down.
513      lscp_mutex_unlock(pClient->mutex);      lscp_mutex_unlock(pClient->mutex);
514        
515      return ret;      return ret;
516  }  }
517    
# Line 553  int lscp_client_get_errno ( lscp_client_ Line 555  int lscp_client_get_errno ( lscp_client_
555    
556  /**  /**
557   *  Register frontend for receiving event messages:   *  Register frontend for receiving event messages:
558   *  SUBSCRIBE CHANNELS | VOICE_COUNT | STREAM_COUNT | BUFFER_FILL   *  SUBSCRIBE CHANNEL_COUNT | VOICE_COUNT | STREAM_COUNT | BUFFER_FILL
559   *      | CHANNEL_INFO | MISCELLANEOUS   *      | CHANNEL_INFO | MISCELLANEOUS
560   *   *
561   *  @param pClient  Pointer to client instance structure.   *  @param pClient  Pointer to client instance structure.
# Line 574  lscp_status_t lscp_client_subscribe ( ls Line 576  lscp_status_t lscp_client_subscribe ( ls
576      // If applicable, start the alternate connection...      // If applicable, start the alternate connection...
577      if (pClient->events == LSCP_EVENT_NONE)      if (pClient->events == LSCP_EVENT_NONE)
578          ret = _lscp_client_evt_connect(pClient);          ret = _lscp_client_evt_connect(pClient);
579        
580      // Send the subscription commands.      // Send the subscription commands.
581      if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNELS))      if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_COUNT))
582          ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_CHANNELS);          ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_CHANNEL_COUNT);
583      if (ret == LSCP_OK && (events & LSCP_EVENT_VOICE_COUNT))      if (ret == LSCP_OK && (events & LSCP_EVENT_VOICE_COUNT))
584          ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_VOICE_COUNT);          ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_VOICE_COUNT);
585      if (ret == LSCP_OK && (events & LSCP_EVENT_STREAM_COUNT))      if (ret == LSCP_OK && (events & LSCP_EVENT_STREAM_COUNT))
# Line 598  lscp_status_t lscp_client_subscribe ( ls Line 600  lscp_status_t lscp_client_subscribe ( ls
600    
601  /**  /**
602   *  Deregister frontend from receiving UDP event messages anymore:   *  Deregister frontend from receiving UDP event messages anymore:
603   *  SUBSCRIBE CHANNELS | VOICE_COUNT | STREAM_COUNT | BUFFER_FILL   *  SUBSCRIBE CHANNEL_COUNT | VOICE_COUNT | STREAM_COUNT | BUFFER_FILL
604   *      | CHANNEL_INFO | MISCELLANEOUS   *      | CHANNEL_INFO | MISCELLANEOUS
605   *   *
606   *  @param pClient  Pointer to client instance structure.   *  @param pClient  Pointer to client instance structure.
# Line 617  lscp_status_t lscp_client_unsubscribe ( Line 619  lscp_status_t lscp_client_unsubscribe (
619      lscp_mutex_lock(pClient->mutex);      lscp_mutex_lock(pClient->mutex);
620    
621      // Send the unsubscription commands.      // Send the unsubscription commands.
622      if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNELS))      if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_COUNT))
623          ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_CHANNELS);          ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_CHANNEL_COUNT);
624      if (ret == LSCP_OK && (events & LSCP_EVENT_VOICE_COUNT))      if (ret == LSCP_OK && (events & LSCP_EVENT_VOICE_COUNT))
625          ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_VOICE_COUNT);          ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_VOICE_COUNT);
626      if (ret == LSCP_OK && (events & LSCP_EVENT_STREAM_COUNT))      if (ret == LSCP_OK && (events & LSCP_EVENT_STREAM_COUNT))
# Line 769  int *lscp_list_channels ( lscp_client_t Line 771  int *lscp_list_channels ( lscp_client_t
771    
772      if (pClient == NULL)      if (pClient == NULL)
773          return NULL;          return NULL;
774            
775      // Lock this section up.      // Lock this section up.
776      lscp_mutex_lock(pClient->mutex);      lscp_mutex_lock(pClient->mutex);
777    
# Line 806  int lscp_add_channel ( lscp_client_t *pC Line 808  int lscp_add_channel ( lscp_client_t *pC
808    
809      if (lscp_client_call(pClient, "ADD CHANNEL\r\n") == LSCP_OK)      if (lscp_client_call(pClient, "ADD CHANNEL\r\n") == LSCP_OK)
810          iSamplerChannel = atoi(lscp_client_get_result(pClient));          iSamplerChannel = atoi(lscp_client_get_result(pClient));
811            
812      // Unlock this section down.      // Unlock this section down.
813      lscp_mutex_unlock(pClient->mutex);      lscp_mutex_unlock(pClient->mutex);
814    
# Line 836  lscp_status_t lscp_remove_channel ( lscp Line 838  lscp_status_t lscp_remove_channel ( lscp
838    
839    
840  /**  /**
841   *  Getting all available engines:   *  Getting all available engines count:
842   *  GET AVAILABLE_ENGINES   *  GET AVAILABLE_ENGINES
843   *   *
844   *  @param pClient  Pointer to client instance structure.   *  @param pClient  Pointer to client instance structure.
845   *   *
846     *  @returns The current total number of sampler engines on success,
847     *  -1 otherwise.
848     */
849    int lscp_get_available_engines ( lscp_client_t *pClient )
850    {
851        int iAvailableEngines = -1;
852    
853        // Lock this section up.
854        lscp_mutex_lock(pClient->mutex);
855    
856        if (lscp_client_call(pClient, "GET AVAILABLE_ENGINES\r\n") == LSCP_OK)
857            iAvailableEngines = atoi(lscp_client_get_result(pClient));
858    
859        // Unlock this section down.
860        lscp_mutex_unlock(pClient->mutex);
861    
862        return iAvailableEngines;
863    }
864    
865    
866    /**
867     *  Getting all available engines:
868     *  LIST AVAILABLE_ENGINES
869     *
870     *  @param pClient  Pointer to client instance structure.
871     *
872   *  @returns A NULL terminated array of engine name strings,   *  @returns A NULL terminated array of engine name strings,
873   *  or NULL in case of failure.   *  or NULL in case of failure.
874   */   */
875  const char **lscp_get_available_engines ( lscp_client_t *pClient )  const char **lscp_list_available_engines ( lscp_client_t *pClient )
876  {  {
877      const char *pszSeps = ",";      const char *pszSeps = ",";
878    
# Line 856  const char **lscp_get_available_engines Line 884  const char **lscp_get_available_engines
884          pClient->engines = NULL;          pClient->engines = NULL;
885      }      }
886    
887      if (lscp_client_call(pClient, "GET AVAILABLE_ENGINES\r\n") == LSCP_OK)      if (lscp_client_call(pClient, "LIST AVAILABLE_ENGINES\r\n") == LSCP_OK)
888          pClient->engines = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps);          pClient->engines = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps);
889    
890      // Unlock this section down.      // Unlock this section down.
# Line 914  lscp_engine_info_t *lscp_get_engine_info Line 942  lscp_engine_info_t *lscp_get_engine_info
942          }          }
943      }      }
944      else pEngineInfo = NULL;      else pEngineInfo = NULL;
945        
946      // Unlock this section down.      // Unlock this section down.
947      lscp_mutex_unlock(pClient->mutex);      lscp_mutex_unlock(pClient->mutex);
948    
# Line 947  lscp_channel_info_t *lscp_get_channel_in Line 975  lscp_channel_info_t *lscp_get_channel_in
975    
976      // Lock this section up.      // Lock this section up.
977      lscp_mutex_lock(pClient->mutex);      lscp_mutex_lock(pClient->mutex);
978        
979      pChannelInfo = &(pClient->channel_info);      pChannelInfo = &(pClient->channel_info);
980      lscp_channel_info_reset(pChannelInfo);      lscp_channel_info_reset(pChannelInfo);
981    
# Line 989  lscp_channel_info_t *lscp_get_channel_in Line 1017  lscp_channel_info_t *lscp_get_channel_in
1017                  if (pszToken)                  if (pszToken)
1018                      pChannelInfo->instrument_nr = atoi(lscp_ltrim(pszToken));                      pChannelInfo->instrument_nr = atoi(lscp_ltrim(pszToken));
1019              }              }
1020                else if (strcasecmp(pszToken, "INSTRUMENT_NAME") == 0) {
1021                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1022                    if (pszToken)
1023                        lscp_unquote_dup(&(pChannelInfo->instrument_name), &pszToken);
1024                }
1025              else if (strcasecmp(pszToken, "INSTRUMENT_STATUS") == 0) {              else if (strcasecmp(pszToken, "INSTRUMENT_STATUS") == 0) {
1026                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1027                  if (pszToken)                  if (pszToken)
# Line 1006  lscp_channel_info_t *lscp_get_channel_in Line 1039  lscp_channel_info_t *lscp_get_channel_in
1039              }              }
1040              else if (strcasecmp(pszToken, "MIDI_INPUT_CHANNEL") == 0) {              else if (strcasecmp(pszToken, "MIDI_INPUT_CHANNEL") == 0) {
1041                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1042                  if (pszToken)                  if (pszToken) {
1043                      pChannelInfo->midi_channel = atoi(lscp_ltrim(pszToken));                      pszToken = lscp_ltrim(pszToken);
1044                        if (strcasecmp(pszToken, "ALL") == 0)
1045                            pChannelInfo->midi_channel = LSCP_MIDI_CHANNEL_ALL;
1046                        else
1047                            pChannelInfo->midi_channel = atoi(pszToken);
1048                    }
1049              }              }
1050              else if (strcasecmp(pszToken, "VOLUME") == 0) {              else if (strcasecmp(pszToken, "VOLUME") == 0) {
1051                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
# Line 1018  lscp_channel_info_t *lscp_get_channel_in Line 1056  lscp_channel_info_t *lscp_get_channel_in
1056          }          }
1057      }      }
1058      else pChannelInfo = NULL;      else pChannelInfo = NULL;
1059        
1060      // Unlock this section up.      // Unlock this section up.
1061      lscp_mutex_unlock(pClient->mutex);      lscp_mutex_unlock(pClient->mutex);
1062    
# Line 1211  lscp_buffer_fill_t *lscp_get_channel_buf Line 1249  lscp_buffer_fill_t *lscp_get_channel_buf
1249          else while (iStream < pClient->iStreamCount)          else while (iStream < pClient->iStreamCount)
1250              pBufferFill[iStream++].stream_usage = 0;              pBufferFill[iStream++].stream_usage = 0;
1251      }      }
1252        
1253      // Unlock this section down.      // Unlock this section down.
1254      lscp_mutex_unlock(pClient->mutex);      lscp_mutex_unlock(pClient->mutex);
1255    
# Line 1431  lscp_status_t lscp_reset_sampler ( lscp_ Line 1469  lscp_status_t lscp_reset_sampler ( lscp_
1469  }  }
1470    
1471    
1472    /**
1473     *  Getting information about the server.
1474     *  GET SERVER INFO
1475     *
1476     *  @param pClient  Pointer to client instance structure.
1477     *
1478     *  @returns A pointer to a @ref lscp_server_info_t structure, with all the
1479     *  information of the current connected server, or NULL in case of failure.
1480     */
1481    lscp_server_info_t *lscp_get_server_info ( lscp_client_t *pClient )
1482    {
1483        lscp_server_info_t *pServerInfo;
1484        const char *pszResult;
1485        const char *pszSeps = ":";
1486        const char *pszCrlf = "\r\n";
1487        char *pszToken;
1488        char *pch;
1489    
1490        // Lock this section up.
1491        lscp_mutex_lock(pClient->mutex);
1492    
1493        pServerInfo = &(pClient->server_info);
1494        lscp_engine_info_reset(pServerInfo);
1495    
1496        if (lscp_client_call(pClient, "GET SERVER INFO\r\n") == LSCP_OK) {
1497            pszResult = lscp_client_get_result(pClient);
1498            pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
1499            while (pszToken) {
1500                if (strcasecmp(pszToken, "DESCRIPTION") == 0) {
1501                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1502                    if (pszToken)
1503                        lscp_unquote_dup(&(pServerInfo->description), &pszToken);
1504                }
1505                else if (strcasecmp(pszToken, "VERSION") == 0) {
1506                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1507                    if (pszToken)
1508                        lscp_unquote_dup(&(pServerInfo->version), &pszToken);
1509                }
1510                pszToken = lscp_strtok(NULL, pszSeps, &(pch));
1511            }
1512        }
1513        else pServerInfo = NULL;
1514    
1515        // Unlock this section down.
1516        lscp_mutex_unlock(pClient->mutex);
1517    
1518        return pServerInfo;
1519    }
1520    
1521    
1522  // end of client.c  // end of client.c

Legend:
Removed from v.278  
changed lines
  Added in v.564

  ViewVC Help
Powered by ViewVC