/[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 167 by capela, Fri Jul 2 14:36:43 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 322  lscp_client_t* lscp_client_create ( cons Line 292  lscp_client_t* lscp_client_create ( cons
292      pClient->channels = NULL;      pClient->channels = NULL;
293      lscp_driver_info_init(&(pClient->audio_info));      lscp_driver_info_init(&(pClient->audio_info));
294      lscp_driver_info_init(&(pClient->midi_info));      lscp_driver_info_init(&(pClient->midi_info));
295        lscp_param_info_init(&(pClient->audio_param_info));
296        lscp_param_info_init(&(pClient->midi_param_info));
297      lscp_engine_info_init(&(pClient->engine_info));      lscp_engine_info_init(&(pClient->engine_info));
298      lscp_channel_info_init(&(pClient->channel_info));      lscp_channel_info_init(&(pClient->channel_info));
299      // Initialize error stuff.      // Initialize error stuff.
# Line 384  lscp_status_t lscp_client_destroy ( lscp Line 356  lscp_status_t lscp_client_destroy ( lscp
356      // Free up all cached members.      // Free up all cached members.
357      lscp_channel_info_reset(&(pClient->channel_info));      lscp_channel_info_reset(&(pClient->channel_info));
358      lscp_engine_info_reset(&(pClient->engine_info));      lscp_engine_info_reset(&(pClient->engine_info));
359        lscp_param_info_reset(&(pClient->midi_param_info));
360        lscp_param_info_reset(&(pClient->audio_param_info));
361      lscp_driver_info_reset(&(pClient->midi_info));      lscp_driver_info_reset(&(pClient->midi_info));
362      lscp_driver_info_reset(&(pClient->audio_info));      lscp_driver_info_reset(&(pClient->audio_info));
363      // Free available engine table.      // Free available engine table.
# Line 399  lscp_status_t lscp_client_destroy ( lscp Line 373  lscp_status_t lscp_client_destroy ( lscp
373      pClient->engines = NULL;      pClient->engines = NULL;
374      // Free result error stuff.      // Free result error stuff.
375      lscp_client_set_result(pClient, NULL, 0);      lscp_client_set_result(pClient, NULL, 0);
376      // Frre stream usage stuff.      // Free stream usage stuff.
377      if (pClient->buffer_fill)      if (pClient->buffer_fill)
378          free(pClient->buffer_fill);          free(pClient->buffer_fill);
379      pClient->buffer_fill = NULL;      pClient->buffer_fill = NULL;
# Line 1017  int lscp_get_channel_voice_count ( lscp_ Line 991  int lscp_get_channel_voice_count ( lscp_
991   *  Current number of active disk streams:   *  Current number of active disk streams:
992   *  GET CHANNEL STREAM_COUNT <sampler-channel>   *  GET CHANNEL STREAM_COUNT <sampler-channel>
993   *   *
994     *  @param pClient          Pointer to client instance structure.
995     *  @param iSamplerChannel  Sampler channel number.
996     *
997   *  @returns The number of active disk streams on success, -1 otherwise.   *  @returns The number of active disk streams on success, -1 otherwise.
998   */   */
999  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 1018  int lscp_get_channel_stream_count ( lscp
1018  }  }
1019    
1020    
1021    /**
1022     *  Current least usage of active disk streams.
1023     *
1024     *  @param pClient          Pointer to client instance structure.
1025     *  @param iSamplerChannel  Sampler channel number.
1026     *
1027     *  @returns The usage percentage of the least filled active disk stream
1028     *  on success, -1 otherwise.
1029     */
1030    int lscp_get_channel_stream_usage ( lscp_client_t *pClient, int iSamplerChannel )
1031    {
1032        char szQuery[LSCP_BUFSIZ];
1033        int  iStreamUsage = -1;
1034        const char *pszResult;
1035        const char *pszSeps = "[]%,";
1036        char *pszToken;
1037        char *pch;
1038        int   iStream;
1039        int   iPercent;
1040    
1041        if (iSamplerChannel < 0)
1042            return iStreamUsage;
1043    
1044        // Lock this section up.
1045        lscp_mutex_lock(pClient->mutex);
1046    
1047        iStream = 0;
1048        sprintf(szQuery, "GET CHANNEL BUFFER_FILL PERCENTAGE %d\r\n", iSamplerChannel);
1049        if (lscp_client_call(pClient, szQuery) == LSCP_OK) {
1050            pszResult = lscp_client_get_result(pClient);
1051            pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
1052            while (pszToken) {
1053                if (*pszToken) {
1054                    // Skip stream id.
1055                    pszToken = lscp_strtok(NULL, pszSeps, &(pch));
1056                    if (pszToken == NULL)
1057                        break;
1058                    // Get least buffer fill percentage.
1059                    iPercent = atol(pszToken);
1060                    if (iStreamUsage > iPercent || iStream == 0)
1061                        iStreamUsage = iPercent;
1062                    iStream++;
1063                }
1064                pszToken = lscp_strtok(NULL, pszSeps, &(pch));
1065            }
1066        }
1067    
1068        // Unlock this section down.
1069        lscp_mutex_unlock(pClient->mutex);
1070    
1071        return iStreamUsage;
1072    }
1073    
1074    
1075  /**  /**
1076   *  Current fill state of disk stream buffers:   *  Current fill state of disk stream buffers:
1077   *  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.167

  ViewVC Help
Powered by ViewVC