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

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

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

revision 107 by capela, Fri Jun 4 21:06:59 2004 UTC revision 163 by capela, Wed Jun 30 15:16:03 2004 UTC
# Line 25  Line 25 
25    
26  // Local prototypes.  // Local prototypes.
27    
28  static lscp_driver_info_t *_lscp_driver_info_query (lscp_client_t *pClient, lscp_driver_info_t *pDriverInfo, const char *pszQuery);  static lscp_driver_info_t *_lscp_driver_info_query (lscp_client_t *pClient, lscp_driver_info_t *pDriverInfo, char *pszQuery);
29    static lscp_param_info_t  *_lscp_param_info_query  (lscp_client_t *pClient, lscp_param_info_t *pParamInfo, char *pszQuery, lscp_param_t *pDepList);
30    
31    
32  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
33  // Local funtions.  // Local funtions.
34    
35  // Common driver type query command.  // Common driver type query command.
36  static lscp_driver_info_t *_lscp_driver_info_query ( lscp_client_t *pClient, lscp_driver_info_t *pDriverInfo, const char *pszQuery )  static lscp_driver_info_t *_lscp_driver_info_query ( lscp_client_t *pClient, lscp_driver_info_t *pDriverInfo, char *pszQuery )
37  {  {
38      const char *pszResult;      const char *pszResult;
39      const char *pszSeps = ":";      const char *pszSeps = ":";
# Line 40  static lscp_driver_info_t *_lscp_driver_ Line 41  static lscp_driver_info_t *_lscp_driver_
41      char *pszToken;      char *pszToken;
42      char *pch;      char *pch;
43    
44        // Lock this section up.
45        lscp_mutex_lock(pClient->mutex);
46    
47      lscp_driver_info_reset(pDriverInfo);      lscp_driver_info_reset(pDriverInfo);
48        if (lscp_client_call(pClient, pszQuery) == LSCP_OK) {
49            pszResult = lscp_client_get_result(pClient);
50            pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
51            while (pszToken) {
52                if (strcasecmp(pszToken, "DESCRIPTION") == 0) {
53                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
54                    if (pszToken)
55                        pDriverInfo->description = lscp_unquote(&pszToken, 1);
56                }
57                else if (strcasecmp(pszToken, "VERSION") == 0) {
58                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
59                    if (pszToken)
60                        pDriverInfo->version = lscp_unquote(&pszToken, 1);
61                }
62                else if (strcasecmp(pszToken, "PARAMETERS") == 0) {
63                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
64                    if (pszToken)
65                        pDriverInfo->parameters = lscp_szsplit_create(pszToken, ",");
66                }
67                pszToken = lscp_strtok(NULL, pszSeps, &(pch));
68            }
69        }
70        
71        // Unlock this section down.
72        lscp_mutex_unlock(pClient->mutex);
73    
74      if (lscp_client_query(pClient, pszQuery) != LSCP_OK)      return pDriverInfo;
75          return NULL;  }
76    
77      pszResult = lscp_client_get_result(pClient);  
78      pszToken = lscp_strtok(pszResult, pszSeps, &(pch));  // Common parameter info query command.
79      while (pszToken) {  static lscp_param_info_t *_lscp_param_info_query ( lscp_client_t *pClient, lscp_param_info_t *pParamInfo, char *pszQuery, lscp_param_t *pDepList )
80          if (strcasecmp(pszToken, "DESCRIPTION") == 0) {  {
81              pszToken = lscp_strtok(NULL, pszCrlf, &(pch));      const char *pszResult;
82              if (pszToken)      const char *pszSeps = ":";
83                  pDriverInfo->description = lscp_unquote(&pszToken, 1);      const char *pszCrlf = "\r\n";
84          }      char *pszToken;
85          else if (strcasecmp(pszToken, "VERSION") == 0) {      char *pch;
86              pszToken = lscp_strtok(NULL, pszCrlf, &(pch));  
87              if (pszToken)      // Lock this section up.
88                  pDriverInfo->version = lscp_unquote(&pszToken, 1);      lscp_mutex_lock(pClient->mutex);
89          }  
90          else if (strcasecmp(pszToken, "PARAMETERS") == 0) {      lscp_param_info_reset(pParamInfo);
91              pszToken = lscp_strtok(NULL, pszCrlf, &(pch));      lscp_param_concat(pszQuery, LSCP_BUFSIZ, pDepList);
92              if (pszToken)      if (lscp_client_call(pClient, pszQuery) == LSCP_OK) {
93                  pDriverInfo->parameters = lscp_szsplit_create(pszToken, ",");          pszResult = lscp_client_get_result(pClient);
94            pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
95            while (pszToken) {
96                if (strcasecmp(pszToken, "TYPE") == 0) {
97                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
98                    if (pszToken) {
99                        pszToken = lscp_unquote(&pszToken, 0);
100                        if (strcasecmp(pszToken, "BOOL") == 0)
101                            pParamInfo->type = LSCP_TYPE_BOOL;
102                        else if (strcasecmp(pszToken, "INT") == 0)
103                            pParamInfo->type = LSCP_TYPE_INT;
104                        else if (strcasecmp(pszToken, "FLOAT") == 0)
105                            pParamInfo->type = LSCP_TYPE_FLOAT;
106                        else if (strcasecmp(pszToken, "STRING") == 0)
107                            pParamInfo->type = LSCP_TYPE_STRING;
108                    }
109                }
110                else if (strcasecmp(pszToken, "DESCRIPTION") == 0) {
111                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
112                    if (pszToken)
113                        pParamInfo->description = lscp_unquote(&pszToken, 1);
114                }
115                else if (strcasecmp(pszToken, "MANDATORY") == 0) {
116                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
117                    if (pszToken)
118                        pParamInfo->mandatory = (strcasecmp(lscp_unquote(&pszToken, 0), "TRUE") == 0);
119                }
120                else if (strcasecmp(pszToken, "FIX") == 0) {
121                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
122                    if (pszToken)
123                        pParamInfo->fix = (strcasecmp(lscp_unquote(&pszToken, 0), "TRUE") == 0);
124                }
125                else if (strcasecmp(pszToken, "MULTIPLICITY") == 0) {
126                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
127                    if (pszToken)
128                        pParamInfo->multiplicity = (strcasecmp(lscp_unquote(&pszToken, 0), "TRUE") == 0);
129                }
130                else if (strcasecmp(pszToken, "DEPENDS") == 0) {
131                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
132                    if (pszToken)
133                        pParamInfo->depends = lscp_szsplit_create(pszToken, ",");
134                }
135                else if (strcasecmp(pszToken, "DEFAULT") == 0) {
136                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
137                    if (pszToken)
138                        pParamInfo->defaultv = lscp_unquote(&pszToken, 1);
139                }
140                else if (strcasecmp(pszToken, "RANGE_MIN") == 0) {
141                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
142                    if (pszToken)
143                        pParamInfo->range_min = lscp_unquote(&pszToken, 1);
144                }
145                else if (strcasecmp(pszToken, "RANGE_MAX") == 0) {
146                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
147                    if (pszToken)
148                        pParamInfo->range_max = lscp_unquote(&pszToken, 1);
149                }
150                else if (strcasecmp(pszToken, "POSSIBILITIES") == 0) {
151                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
152                    if (pszToken)
153                        pParamInfo->possibilities = lscp_szsplit_create(pszToken, ",");
154                }
155                pszToken = lscp_strtok(NULL, pszSeps, &(pch));
156          }          }
         pszToken = lscp_strtok(NULL, pszSeps, &(pch));  
157      }      }
158    
159      return pDriverInfo;      // Unlock this section down.
160        lscp_mutex_unlock(pClient->mutex);
161    
162        return pParamInfo;
163  }  }
164    
165    
# Line 86  const char ** lscp_get_available_audio_d Line 179  const char ** lscp_get_available_audio_d
179  {  {
180      const char *pszSeps = ",";      const char *pszSeps = ",";
181    
182        // Lock this section up.
183        lscp_mutex_lock(pClient->mutex);
184    
185      if (pClient->audio_drivers) {      if (pClient->audio_drivers) {
186          lscp_szsplit_destroy(pClient->audio_drivers);          lscp_szsplit_destroy(pClient->audio_drivers);
187          pClient->audio_drivers = NULL;          pClient->audio_drivers = NULL;
188      }      }
189    
190      if (lscp_client_query(pClient, "GET AVAILABLE_AUDIO_OUTPUT_DRIVERS\r\n") == LSCP_OK)      if (lscp_client_call(pClient, "GET AVAILABLE_AUDIO_OUTPUT_DRIVERS\r\n") == LSCP_OK)
191          pClient->audio_drivers = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps);          pClient->audio_drivers = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps);
192    
193        // Unlock this section down.
194        lscp_mutex_unlock(pClient->mutex);
195    
196      return (const char **) pClient->audio_drivers;      return (const char **) pClient->audio_drivers;
197  }  }
198    
# Line 134  lscp_driver_info_t* lscp_get_audio_drive Line 233  lscp_driver_info_t* lscp_get_audio_drive
233   */   */
234  lscp_param_info_t *lscp_get_audio_driver_param_info ( lscp_client_t *pClient, const char *pszAudioDriver, const char *pszParam, lscp_param_t *pDepList )  lscp_param_info_t *lscp_get_audio_driver_param_info ( lscp_client_t *pClient, const char *pszAudioDriver, const char *pszParam, lscp_param_t *pDepList )
235  {  {
236      lscp_param_info_t *pParamInfo = NULL;      char szQuery[LSCP_BUFSIZ];
237    
238      if (pClient == NULL)      if (pClient == NULL)
239          return NULL;          return NULL;
# Line 142  lscp_param_info_t *lscp_get_audio_driver Line 241  lscp_param_info_t *lscp_get_audio_driver
241          return NULL;          return NULL;
242      if (pszParam == NULL)      if (pszParam == NULL)
243          return NULL;          return NULL;
     if (pDepList == NULL)  
         return NULL;  
244    
245      return pParamInfo;      sprintf(szQuery, "GET AUDIO_OUTPUT_DRIVER_PARAMETER INFO %s %s\r\n", pszAudioDriver, pszParam);
246        return _lscp_param_info_query(pClient, &(pClient->audio_param_info), szQuery, pDepList);
247  }  }
248    
249    
# Line 201  lscp_status_t lscp_destroy_audio_device Line 299  lscp_status_t lscp_destroy_audio_device
299    
300    
301  /**  /**
302   *  Getting all created audio output devices.   *  Getting all created audio output device count.
303   *  GET AUDIO_OUTPUT_DEVICES   *  GET AUDIO_OUTPUT_DEVICES
304   *   *
305   *  @param pClient  Pointer to client instance structure.   *  @param pClient  Pointer to client instance structure.
306   *   *
307     *  @returns The current total number of audio devices on success,
308     *  -1 otherwise.
309     */
310    int lscp_get_audio_devices ( lscp_client_t *pClient )
311    {
312        int iAudioDevices = -1;
313    
314        // Lock this section up.
315        lscp_mutex_lock(pClient->mutex);
316    
317        if (lscp_client_call(pClient, "GET AUDIO_OUTPUT_DEVICES\r\n") == LSCP_OK)
318            iAudioDevices = atoi(lscp_client_get_result(pClient));
319    
320        // Unlock this section down.
321        lscp_mutex_unlock(pClient->mutex);
322    
323        return iAudioDevices;
324    }
325    
326    
327    /**
328     *  Getting all created audio output device list.
329     *  LIST AUDIO_OUTPUT_DEVICES
330     *
331     *  @param pClient  Pointer to client instance structure.
332     *
333   *  @returns An array of audio device number identifiers,   *  @returns An array of audio device number identifiers,
334   *  terminated with -1 on success, or NULL in case of failure.   *  terminated with -1 on success, or NULL in case of failure.
335   */   */
336  int *lscp_get_audio_devices ( lscp_client_t *pClient )  int *lscp_list_audio_devices ( lscp_client_t *pClient )
337  {  {
338      int *piAudioDevices = NULL;      const char *pszSeps = ",";
339    
340      if (pClient == NULL)      if (pClient == NULL)
341          return NULL;          return NULL;
342    
343      return piAudioDevices;      // Lock this section up.
344        lscp_mutex_lock(pClient->mutex);
345    
346        if (pClient->audio_devices) {
347            lscp_isplit_destroy(pClient->audio_devices);
348            pClient->audio_devices = NULL;
349        }
350    
351        if (lscp_client_call(pClient, "LIST AUDIO_OUTPUT_DEVICES\r\n") == LSCP_OK)
352            pClient->audio_devices = lscp_isplit_create(lscp_client_get_result(pClient), pszSeps);
353    
354        // Unlock this section down.
355        lscp_mutex_unlock(pClient->mutex);
356    
357        return pClient->audio_devices;
358  }  }
359    
360    
# Line 367  const char** lscp_get_available_midi_dri Line 505  const char** lscp_get_available_midi_dri
505  {  {
506      const char *pszSeps = ",";      const char *pszSeps = ",";
507    
508        // Lock this section up.
509        lscp_mutex_lock(pClient->mutex);
510    
511      if (pClient->midi_drivers) {      if (pClient->midi_drivers) {
512          lscp_szsplit_destroy(pClient->midi_drivers);          lscp_szsplit_destroy(pClient->midi_drivers);
513          pClient->midi_drivers = NULL;          pClient->midi_drivers = NULL;
514      }      }
515    
516      if (lscp_client_query(pClient, "GET AVAILABLE_MIDI_INPUT_DRIVERS\r\n") == LSCP_OK)      if (lscp_client_call(pClient, "GET AVAILABLE_MIDI_INPUT_DRIVERS\r\n") == LSCP_OK)
517          pClient->midi_drivers = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps);          pClient->midi_drivers = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps);
518    
519        // Unlock this section up.
520        lscp_mutex_unlock(pClient->mutex);
521    
522      return (const char **) pClient->midi_drivers;      return (const char **) pClient->midi_drivers;
523  }  }
524    
# Line 417  lscp_driver_info_t* lscp_get_midi_driver Line 561  lscp_driver_info_t* lscp_get_midi_driver
561   */   */
562  lscp_param_info_t *lscp_get_midi_driver_param_info ( lscp_client_t *pClient, const char *pszMidiDriver, const char *pszParam, lscp_param_t *pDepList )  lscp_param_info_t *lscp_get_midi_driver_param_info ( lscp_client_t *pClient, const char *pszMidiDriver, const char *pszParam, lscp_param_t *pDepList )
563  {  {
564      lscp_param_info_t *pParamInfo = NULL;      char szQuery[LSCP_BUFSIZ];
565    
566      if (pClient == NULL)      if (pClient == NULL)
567          return NULL;          return NULL;
# Line 425  lscp_param_info_t *lscp_get_midi_driver_ Line 569  lscp_param_info_t *lscp_get_midi_driver_
569          return NULL;          return NULL;
570      if (pszParam == NULL)      if (pszParam == NULL)
571          return NULL;          return NULL;
     if (pDepList == NULL)  
         return NULL;  
572    
573      return pParamInfo;      sprintf(szQuery, "GET MIDI_INPUT_DRIVER_PARAMETER INFO %s %s\r\n", pszMidiDriver, pszParam);
574        return _lscp_param_info_query(pClient, &(pClient->midi_param_info), szQuery, pDepList);
575  }  }
576    
577    
# Line 484  lscp_status_t lscp_destroy_midi_device ( Line 627  lscp_status_t lscp_destroy_midi_device (
627    
628    
629  /**  /**
630   *  Getting all created MIDI input devices.   *  Getting all created MIDI intput device count.
631   *  GET MIDI_INPUT_DEVICES   *  GET MIDI_INPUT_DEVICES
632   *   *
633   *  @param pClient  Pointer to client instance structure.   *  @param pClient  Pointer to client instance structure.
634   *   *
635     *  @returns The current total number of MIDI devices on success,
636     *  -1 otherwise.
637     */
638    int lscp_get_midi_devices ( lscp_client_t *pClient )
639    {
640        int iMidiDevices = -1;
641    
642        // Lock this section up.
643        lscp_mutex_lock(pClient->mutex);
644    
645        if (lscp_client_call(pClient, "GET MIDI_INPUT_DEVICES\r\n") == LSCP_OK)
646            iMidiDevices = atoi(lscp_client_get_result(pClient));
647            
648        // Unlock this section down.
649        lscp_mutex_unlock(pClient->mutex);
650    
651        return iMidiDevices;
652    }
653    
654    
655    /**
656     *  Getting all created MIDI intput device list.
657     *  LIST MIDI_INPUT_DEVICES
658     *
659     *  @param pClient  Pointer to client instance structure.
660     *
661   *  @returns An array of MIDI device number identifiers,   *  @returns An array of MIDI device number identifiers,
662   *  terminated with -1 on success, or NULL in case of failure.   *  terminated with -1 on success, or NULL in case of failure.
663   */   */
664  int *lscp_get_midi_devices ( lscp_client_t *pClient )  int *lscp_list_midi_devices ( lscp_client_t *pClient )
665  {  {
666      int *piMidiDevices = NULL;      const char *pszSeps = ",";
667    
668      if (pClient == NULL)      if (pClient == NULL)
669          return NULL;          return NULL;
670    
671      return piMidiDevices;      // Lock this section up.
672        lscp_mutex_lock(pClient->mutex);
673    
674        if (pClient->midi_devices) {
675            lscp_isplit_destroy(pClient->midi_devices);
676            pClient->midi_devices = NULL;
677        }
678    
679        if (lscp_client_call(pClient, "LIST MIDI_INPUT_DEVICES\r\n") == LSCP_OK)
680            pClient->midi_devices = lscp_isplit_create(lscp_client_get_result(pClient), pszSeps);
681    
682        // Unlock this section down.
683        lscp_mutex_unlock(pClient->mutex);
684    
685        return pClient->midi_devices;
686  }  }
687    
688    

Legend:
Removed from v.107  
changed lines
  Added in v.163

  ViewVC Help
Powered by ViewVC