/[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 144 by capela, Thu Jun 24 18:25:11 2004 UTC revision 171 by capela, Mon Jul 5 16:26:44 2004 UTC
# Line 46  static void _lscp_client_evt_proc ( void Line 46  static void _lscp_client_evt_proc ( void
46      char *pszToken;      char *pszToken;
47      char *pch;      char *pch;
48      int   cchToken;      int   cchToken;
49      lscp_event_t event = LSCP_EVENT_NONE;      lscp_event_t event;
50    
51  #ifdef DEBUG  #ifdef DEBUG
52      fprintf(stderr, "_lscp_client_evt_proc: Client waiting for events.\n");      fprintf(stderr, "_lscp_client_evt_proc: Client waiting for events.\n");
# Line 62  static void _lscp_client_evt_proc ( void Line 62  static void _lscp_client_evt_proc ( void
62              pszToken = lscp_strtok(achBuffer, pszSeps, &(pch)); // Have "NOTIFY".              pszToken = lscp_strtok(achBuffer, pszSeps, &(pch)); // Have "NOTIFY".
63              if (strcasecmp(pszToken, "NOTIFY") == 0) {              if (strcasecmp(pszToken, "NOTIFY") == 0) {
64                  pszToken = lscp_strtok(NULL, pszSeps, &(pch));                  pszToken = lscp_strtok(NULL, pszSeps, &(pch));
65                  if (strcasecmp(pszToken, "CHANNELS") == 0)                  event    = lscp_event_from_text(pszToken);
                     event = LSCP_EVENT_CHANNELS;  
                 else if (strcasecmp(pszToken, "VOICE_COUNT") == 0)  
                     event = LSCP_EVENT_VOICE_COUNT;  
                 else if (strcasecmp(pszToken, "STREAM_COUNT") == 0)  
                     event = LSCP_EVENT_STREAM_COUNT;  
                 else if (strcasecmp(pszToken, "BUFFER_FILL") == 0)  
                     event = LSCP_EVENT_BUFFER_FILL;  
                 else if (strcasecmp(pszToken, "CHANNEL_INFO") == 0)  
                     event = LSCP_EVENT_CHANNEL_INFO;  
                 else if (strcasecmp(pszToken, "MISCELLANEOUS") == 0)  
                     event = LSCP_EVENT_MISCELLANEOUS;  
66                  // And pick the rest of data...                  // And pick the rest of data...
67                  pszToken = lscp_strtok(NULL, pszSeps, &(pch));                  pszToken = lscp_strtok(NULL, pszSeps, &(pch));
68                  cchToken = (pszToken == NULL ? 0 : strlen(pszToken));                  cchToken = (pszToken == NULL ? 0 : strlen(pszToken));
# Line 153  static lscp_status_t _lscp_client_evt_co Line 142  static lscp_status_t _lscp_client_evt_co
142  // Subscribe to a single event.  // Subscribe to a single event.
143  static lscp_status_t _lscp_client_evt_request ( lscp_client_t *pClient, int iSubscribe, lscp_event_t event )  static lscp_status_t _lscp_client_evt_request ( lscp_client_t *pClient, int iSubscribe, lscp_event_t event )
144  {  {
145      char *pszEvent;      const char *pszEvent;
146      char  szQuery[LSCP_BUFSIZ];      char  szQuery[LSCP_BUFSIZ];
147      int   cchQuery;      int   cchQuery;
148    
# Line 161  static lscp_status_t _lscp_client_evt_re Line 150  static lscp_status_t _lscp_client_evt_re
150          return LSCP_FAILED;          return LSCP_FAILED;
151    
152      // Which (single) event?      // Which (single) event?
153      switch (event) {      pszEvent = lscp_event_to_text(event);
154        case LSCP_EVENT_CHANNELS:      if (pszEvent == NULL)
         pszEvent = "CHANNELS";  
         break;  
       case LSCP_EVENT_VOICE_COUNT:  
         pszEvent = "VOICE_COUNT";  
         break;  
       case LSCP_EVENT_STREAM_COUNT:  
         pszEvent = "STREAM_COUNT";  
         break;  
       case LSCP_EVENT_BUFFER_FILL:  
         pszEvent = "BUFFER_FILL";  
         break;  
       case LSCP_EVENT_CHANNEL_INFO:  
         pszEvent = "CHANNEL_INFO";  
         break;  
       case LSCP_EVENT_MISCELLANEOUS:  
         pszEvent = "CHANNEL_INFO";  
         break;  
       default:  
155          return LSCP_FAILED;          return LSCP_FAILED;
156      }  
       
157      // Build the query string...      // Build the query string...
158      cchQuery = sprintf(szQuery, "%sSUBSCRIBE %s\n\n", (iSubscribe == 0 ? "UN" : ""), pszEvent);      cchQuery = sprintf(szQuery, "%sSUBSCRIBE %s\n\n", (iSubscribe == 0 ? "UN" : ""), pszEvent);
159      // Just send data, forget result...      // Just send data, forget result...
# Line 320  lscp_client_t* lscp_client_create ( cons Line 290  lscp_client_t* lscp_client_create ( cons
290      pClient->midi_devices = NULL;      pClient->midi_devices = NULL;
291      pClient->engines = NULL;      pClient->engines = NULL;
292      pClient->channels = NULL;      pClient->channels = NULL;
293      lscp_driver_info_init(&(pClient->audio_info));      lscp_driver_info_init(&(pClient->audio_driver_info));
294      lscp_driver_info_init(&(pClient->midi_info));      lscp_driver_info_init(&(pClient->midi_driver_info));
295        lscp_device_info_init(&(pClient->audio_device_info));
296        lscp_device_info_init(&(pClient->midi_device_info));
297        lscp_param_info_init(&(pClient->audio_param_info));
298        lscp_param_info_init(&(pClient->midi_param_info));
299        lscp_device_port_info_init(&(pClient->audio_channel_info));
300        lscp_device_port_info_init(&(pClient->midi_port_info));
301        lscp_param_info_init(&(pClient->audio_channel_param_info));
302        lscp_param_info_init(&(pClient->midi_port_param_info));
303      lscp_engine_info_init(&(pClient->engine_info));      lscp_engine_info_init(&(pClient->engine_info));
304      lscp_channel_info_init(&(pClient->channel_info));      lscp_channel_info_init(&(pClient->channel_info));
305      // Initialize error stuff.      // Initialize error stuff.
# Line 384  lscp_status_t lscp_client_destroy ( lscp Line 362  lscp_status_t lscp_client_destroy ( lscp
362      // Free up all cached members.      // Free up all cached members.
363      lscp_channel_info_reset(&(pClient->channel_info));      lscp_channel_info_reset(&(pClient->channel_info));
364      lscp_engine_info_reset(&(pClient->engine_info));      lscp_engine_info_reset(&(pClient->engine_info));
365      lscp_driver_info_reset(&(pClient->midi_info));      lscp_param_info_reset(&(pClient->midi_port_param_info));
366      lscp_driver_info_reset(&(pClient->audio_info));      lscp_param_info_reset(&(pClient->audio_channel_param_info));
367        lscp_device_port_info_reset(&(pClient->midi_port_info));
368        lscp_device_port_info_reset(&(pClient->audio_channel_info));
369        lscp_param_info_reset(&(pClient->midi_param_info));
370        lscp_param_info_reset(&(pClient->audio_param_info));
371        lscp_device_info_reset(&(pClient->midi_device_info));
372        lscp_device_info_reset(&(pClient->audio_device_info));
373        lscp_driver_info_reset(&(pClient->midi_driver_info));
374        lscp_driver_info_reset(&(pClient->audio_driver_info));
375      // Free available engine table.      // Free available engine table.
376      lscp_szsplit_destroy(pClient->audio_drivers);      lscp_szsplit_destroy(pClient->audio_drivers);
377      lscp_szsplit_destroy(pClient->midi_drivers);      lscp_szsplit_destroy(pClient->midi_drivers);
# Line 399  lscp_status_t lscp_client_destroy ( lscp Line 385  lscp_status_t lscp_client_destroy ( lscp
385      pClient->engines = NULL;      pClient->engines = NULL;
386      // Free result error stuff.      // Free result error stuff.
387      lscp_client_set_result(pClient, NULL, 0);      lscp_client_set_result(pClient, NULL, 0);
388      // Frre stream usage stuff.      // Free stream usage stuff.
389      if (pClient->buffer_fill)      if (pClient->buffer_fill)
390          free(pClient->buffer_fill);          free(pClient->buffer_fill);
391      pClient->buffer_fill = NULL;      pClient->buffer_fill = NULL;
# Line 1017  int lscp_get_channel_voice_count ( lscp_ Line 1003  int lscp_get_channel_voice_count ( lscp_
1003   *  Current number of active disk streams:   *  Current number of active disk streams:
1004   *  GET CHANNEL STREAM_COUNT <sampler-channel>   *  GET CHANNEL STREAM_COUNT <sampler-channel>
1005   *   *
1006     *  @param pClient          Pointer to client instance structure.
1007     *  @param iSamplerChannel  Sampler channel number.
1008     *
1009   *  @returns The number of active disk streams on success, -1 otherwise.   *  @returns The number of active disk streams on success, -1 otherwise.
1010   */   */
1011  int lscp_get_channel_stream_count ( lscp_client_t *pClient, int iSamplerChannel )  int lscp_get_channel_stream_count ( lscp_client_t *pClient, int iSamplerChannel )
# Line 1041  int lscp_get_channel_stream_count ( lscp Line 1030  int lscp_get_channel_stream_count ( lscp
1030  }  }
1031    
1032    
1033    /**
1034     *  Current least usage of active disk streams.
1035     *
1036     *  @param pClient          Pointer to client instance structure.
1037     *  @param iSamplerChannel  Sampler channel number.
1038     *
1039     *  @returns The usage percentage of the least filled active disk stream
1040     *  on success, -1 otherwise.
1041     */
1042    int lscp_get_channel_stream_usage ( lscp_client_t *pClient, int iSamplerChannel )
1043    {
1044        char szQuery[LSCP_BUFSIZ];
1045        int  iStreamUsage = -1;
1046        const char *pszResult;
1047        const char *pszSeps = "[]%,";
1048        char *pszToken;
1049        char *pch;
1050        int   iStream;
1051        int   iPercent;
1052    
1053        if (iSamplerChannel < 0)
1054            return iStreamUsage;
1055    
1056        // Lock this section up.
1057        lscp_mutex_lock(pClient->mutex);
1058    
1059        iStream = 0;
1060        sprintf(szQuery, "GET CHANNEL BUFFER_FILL PERCENTAGE %d\r\n", iSamplerChannel);
1061        if (lscp_client_call(pClient, szQuery) == LSCP_OK) {
1062            pszResult = lscp_client_get_result(pClient);
1063            pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
1064            while (pszToken) {
1065                if (*pszToken) {
1066                    // Skip stream id.
1067                    pszToken = lscp_strtok(NULL, pszSeps, &(pch));
1068                    if (pszToken == NULL)
1069                        break;
1070                    // Get least buffer fill percentage.
1071                    iPercent = atol(pszToken);
1072                    if (iStreamUsage > iPercent || iStream == 0)
1073                        iStreamUsage = iPercent;
1074                    iStream++;
1075                }
1076                pszToken = lscp_strtok(NULL, pszSeps, &(pch));
1077            }
1078        }
1079    
1080        // Unlock this section down.
1081        lscp_mutex_unlock(pClient->mutex);
1082    
1083        return iStreamUsage;
1084    }
1085    
1086    
1087  /**  /**
1088   *  Current fill state of disk stream buffers:   *  Current fill state of disk stream buffers:
1089   *  GET CHANNEL BUFFER_FILL {BYTES|PERCENTAGE} <sampler-channel>   *  GET CHANNEL BUFFER_FILL {BYTES|PERCENTAGE} <sampler-channel>

Legend:
Removed from v.144  
changed lines
  Added in v.171

  ViewVC Help
Powered by ViewVC