Introduce snd_seq_client_info_get_card_number, for getting the card number of a seq client on recent kernels
PATCH 1/1 Introduce snd_seq_client_info_get_card_number, for getting the card number of a seq client on recent kernels
configure.ac +1 -1
@@ -14,7 +14,7 @@ dnl remove API = c+1:0:0 dnl ************************************************* AC_CANONICAL_HOST AM_INIT_AUTOMAKE -eval LIBTOOL_VERSION_INFO="2:0:0" +eval LIBTOOL_VERSION_INFO="3:0:1" dnl ************************************************* AM_CONDITIONAL([INSTALL_M4], [test -n "${ACLOCAL}"])
include/seq.h +1 -0
@@ -146,6 +146,7 @@ int snd_seq_client_info_get_error_bounce(const snd_seq_client_info_t *info);const unsigned char *snd_seq_client_info_get_event_filter (const snd_seq_client_info_t *info);int snd_seq_client_info_get_num_ports (const snd_seq_client_info_t *info);int snd_seq_client_info_get_event_lost (const snd_seq_client_info_t *info); +int snd_seq_client_info_get_card_number (const snd_seq_client_info_t *info);void snd_seq_client_info_set_client (snd_seq_client_info_t *info,int client);void snd_seq_client_info_set_name (snd_seq_client_info_t *info,const char *name);
include/sound/asequencer.h +4 -2
@@ -22,9 +22,10 @@#ifndef _UAPI__SOUND_ASEQUENCER_H#define _UAPI__SOUND_ASEQUENCER_H +#include <sound/asound.h> /** version of the sequencer */ -#define SNDRV_SEQ_VERSION SNDRV_PROTOCOL_VERSION (1, 0, 1) +#define SNDRV_SEQ_VERSION SNDRV_PROTOCOL_VERSION (1, 0, 2)/** * definition of sequencer event types
@@ -356,7 +357,8 @@ struct snd_seq_client_info {unsigned char event_filter[32 ];/* event filter bitmap */ int num_ports;/* RO: number of ports */ int event_lost;/* number of lost events */ -char reserved[64 ];/* for future use */ +int card_number;/* RO: card number, or -1 if no card. Added in protocol version 1.0.2 */ +char reserved[60 ];/* for future use */ };
src/seq/seq.c +12 -0
@@ -1651,6 +1651,18 @@ int snd_seq_client_info_get_event_lost(const snd_seq_client_info_t *info) }/** +* \brief Get the card number of a client_info container +* \param info client_info container +* \return the card number, -1 if no card associated with this client, or -ENOSYS if the +* kernel does not support reporting this field +*/ +int snd_seq_client_info_get_card_number (const snd_seq_client_info_t *info) +{ +assert (info); +return info->card_number; +} + +/** * \brief Set the client id of a client_info container * \param info client_info container * \param client client id
src/seq/seq_hw.c +11 -1
@@ -32,10 +32,11 @@ const char *_snd_module_seq_hw = "";#ifndef DOC_HIDDEN #define SNDRV_FILE_SEQ ALSA_DEVICE_DIRECTORY "seq"#define SNDRV_FILE_ALOADSEQ ALOAD_DEVICE_DIRECTORY "aloadSEQ" -#define SNDRV_SEQ_VERSION_MAX SNDRV_PROTOCOL_VERSION(1, 0, 1) +#define SNDRV_SEQ_VERSION_MAX SNDRV_PROTOCOL_VERSION(1, 0, 2)typedef struct {int fd; +int version; }snd_seq_hw_t ;#endif /* DOC_HIDDEN */
@@ -100,6 +101,10 @@ static int snd_seq_hw_get_client_info(snd_seq_t *seq, snd_seq_client_info_t * in/*SYSERR("SNDRV_SEQ_IOCTL_GET_CLIENT_INFO failed");*/ return -errno; } +/* The card_number field was added in protocol 1.0.2, so set to -ENOSYS if older. */ +if (hw->version <SNDRV_PROTOCOL_VERSION (1 ,0 ,2 )) { + info->card_number = -ENOSYS ; + }return 0 ; }
@@ -368,6 +373,10 @@ static int snd_seq_hw_query_next_client(snd_seq_t *seq, snd_seq_client_info_t *i/*SYSERR("SNDRV_SEQ_IOCTL_QUERY_NEXT_CLIENT failed");*/ return -errno; } +/* The card_number field was added in protocol 1.0.2, so set to -ENOSYS if older. */ +if (hw->version <SNDRV_PROTOCOL_VERSION (1 ,0 ,2 )) { + info->card_number = -ENOSYS ; + }return 0 ; }
@@ -480,6 +489,7 @@ int snd_seq_hw_open(snd_seq_t **handle, const char *name, int streams, int mode)return -ENOMEM ; } hw->fd = fd; + hw->version = ver;if (streams &SND_SEQ_OPEN_OUTPUT ) { seq->obuf = (char *)malloc (seq->obufsize =SND_SEQ_OBUF_SIZE );if (!seq->obuf) {
test/seq.c +4 -1
@@ -111,7 +111,7 @@ void show_port_info(snd_seq_t *handle, int client, int port)void show_client_info (snd_seq_t *handle,int client) { -int err, idx, min, max; +int err, idx, min, max, card_number;snd_seq_client_info_t *info;snd_seq_client_info_alloca (&info);
@@ -124,11 +124,14 @@ void show_client_info(snd_seq_t *handle, int client)fprintf (stderr,"Client %i info error: %s\n" , idx,snd_strerror (err));exit (0 ); } + card_number =snd_seq_client_info_get_card_number (info);printf ("Client %i info\n" , idx);if (verbose)printf (" Client : %i\n" ,snd_seq_client_info_get_client (info));printf (" Type : %s\n" ,snd_seq_client_info_get_type (info) ==SND_SEQ_KERNEL_CLIENT ?"kernel" :"user" );printf (" Name : %s\n" ,snd_seq_client_info_get_name (info)); +if (card_number != -ENOSYS ) +printf (" Card Number : %i\n" , card_number); } }
Signature · 1 line
2.2.0.rc0.207.ga3a616c
Quoted 6 lines · Adam Goode
/**
+ * \brief Get the card number of aclient_infocontainer
+ * \param infoclient_infocontainer
+ * \return the card number, -1 if no card associated with this client, or-ENOSYSif the
+ * kernel does not support reporting this field
+ */
-1 is used as an out-of-range value when enumerating cards. However, I don't think this convention can be applied here, because the return value is also used for error codes, and -1 would correspond to -EPERM.
Squashing all error codes into -1 is not a good idea, so I think the value -1 should be converted into an appropriate error code, probably -ENXIO.
Regards,
Clemens
At Fri, 05 Jun 2015 08:50:45 +0200,
Quoted 9 lines · Clemens Ladisch
Quoted 6 lines · Adam Goode
/**
+ * \brief Get the card number of aclient_infocontainer
+ * \param infoclient_infocontainer
+ * \return the card number, -1 if no card associated with this client, or-ENOSYSif the
+ * kernel does not support reporting this field
+ */
Quoted 7 lines
-1 is used as an out-of-range value when enumerating cards. However, I don't think this convention can be applied here, because the return value is also used for error codes, and -1 would correspond to
-EPERM.Squashing all error codes into -1 is not a good idea, so I think the value -1 should be converted into an appropriate error code, probably
-ENXIO.
Agreed.
Also, please don't include irrelevant changes in configure.ac.
thanks,
Takashi
Quoted 20 lines · Takashi Iwai
At Fri, 05 Jun 2015 08:50:45 +0200,
Quoted 6 lines · Clemens Ladisch
Quoted 4 lines · Adam Goode
/**
+ * \brief Get the card number of aclient_infocontainer
+ * \param infoclient_infocontainer
+ * \return the card number, -1 if no card associated with thisclient, or
-ENOSYSif theQuoted 10 lines
Quoted 2 lines
+ * kernel does not support reporting this field
+ */-1 is used as an out-of-range value when enumerating cards. However, I don't think this convention can be applied here, because the return value is also used for error codes, and -1 would correspond to
-EPERM.Squashing all error codes into -1 is not a good idea, so I think the value -1 should be converted into an appropriate error code, probably
-ENXIO.
Quoted 9 lines
Agreed.
Also, please don't include irrelevant changes in configure.ac.
thanks,
Takashi
Thanks for the feedback, I should have time this week to get back to you.
Adam