[PATCH 02/21] device-class: Introduce pa_device_class_t

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



My plan is to use the device class in node names. There is already the
PA_PROP_DEVICE_FORM_FACTOR property, which is almost the same thing as
the device class, but since that property can contain arbitrary
values, I want to have a way to sanitize the property value to some
controlled set of device classes. The way I chose to do that was to
introduce an enumeration with from_string() and to_string()
operations.

I wouldn't be surprised if further uses for the device class
enumeration were found in the future.
---
 src/Makefile.am              |  1 +
 src/pulsecore/device-class.c | 69 +++++++++++++++++++++++++++++++++++++++++++
 src/pulsecore/device-class.h | 70 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 140 insertions(+)
 create mode 100644 src/pulsecore/device-class.c
 create mode 100644 src/pulsecore/device-class.h

diff --git a/src/Makefile.am b/src/Makefile.am
index 2521670..41ff87c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -874,6 +874,7 @@ libpulsecore_ at PA_MAJORMINOR@_la_SOURCES = \
 		pulsecore/core-scache.c pulsecore/core-scache.h \
 		pulsecore/core-subscribe.c pulsecore/core-subscribe.h \
 		pulsecore/core.c pulsecore/core.h \
+		pulsecore/device-class.c pulsecore/device-class.h \
 		pulsecore/fdsem.c pulsecore/fdsem.h \
 		pulsecore/hook-list.c pulsecore/hook-list.h \
 		pulsecore/ltdl-helper.c pulsecore/ltdl-helper.h \
diff --git a/src/pulsecore/device-class.c b/src/pulsecore/device-class.c
new file mode 100644
index 0000000..73f20ae
--- /dev/null
+++ b/src/pulsecore/device-class.c
@@ -0,0 +1,69 @@
+/***
+  This file is part of PulseAudio.
+
+  Copyright (c) 2013 Intel Corporation
+  Author: Tanu Kaskinen <tanu.kaskinen at intel.com>
+
+  PulseAudio is free software; you can redistribute it and/or modify
+  it under the terms of the GNU Lesser General Public License as published
+  by the Free Software Foundation; either version 2.1 of the License,
+  or (at your option) any later version.
+
+  PulseAudio is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with PulseAudio; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+  USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <pulsecore/core-util.h>
+#include <pulsecore/macro.h>
+
+#include "device-class.h"
+
+static const char * const string_table[PA_DEVICE_CLASS_MAX] = {
+    [PA_DEVICE_CLASS_UNKNOWN] = "unknown",
+    [PA_DEVICE_CLASS_COMPUTER] = "computer",
+    [PA_DEVICE_CLASS_PHONE] = "phone",
+    [PA_DEVICE_CLASS_HEADSET] = "headset",
+    [PA_DEVICE_CLASS_HANDSFREE] = "handsfree",
+    [PA_DEVICE_CLASS_MICROPHONE] = "microphone",
+    [PA_DEVICE_CLASS_SPEAKERS] = "speakers",
+    [PA_DEVICE_CLASS_HEADPHONES] = "headphones",
+    [PA_DEVICE_CLASS_PORTABLE] = "portable",
+    [PA_DEVICE_CLASS_CAR] = "car",
+    [PA_DEVICE_CLASS_SETTOP_BOX] = "set-top-box",
+    [PA_DEVICE_CLASS_HIFI] = "hifi",
+    [PA_DEVICE_CLASS_VCR] = "vcr",
+    [PA_DEVICE_CLASS_VIDEO_CAMERA] = "video-camera",
+    [PA_DEVICE_CLASS_CAMCORDER] = "camcorder",
+    [PA_DEVICE_CLASS_VIDEO_DISPLAY_AND_SPEAKERS] = "video-display-and-speakers",
+    [PA_DEVICE_CLASS_VIDEO_CONFERENCING] = "video-conferencing",
+    [PA_DEVICE_CLASS_GAMING_OR_TOY] = "gaming-or-toy",
+    [PA_DEVICE_CLASS_TUNER] = "tuner"
+};
+
+pa_device_class_t pa_device_class_from_string(const char *str) {
+    unsigned i;
+
+    pa_assert(str);
+
+    for (i = 0; i < PA_DEVICE_CLASS_MAX; i++) {
+        if (pa_streq(str, string_table[i]))
+            return (pa_device_class_t) i;
+    }
+
+    return PA_DEVICE_CLASS_UNKNOWN;
+}
+
+const char *pa_device_class_to_string(pa_device_class_t class) {
+    return string_table[class];
+}
diff --git a/src/pulsecore/device-class.h b/src/pulsecore/device-class.h
new file mode 100644
index 0000000..e820fc2
--- /dev/null
+++ b/src/pulsecore/device-class.h
@@ -0,0 +1,70 @@
+#ifndef fooformfactorhfoo
+#define fooformfactorhfoo
+
+/***
+  This file is part of PulseAudio.
+
+  Copyright (c) 2013 Intel Corporation
+  Author: Tanu Kaskinen <tanu.kaskinen at intel.com>
+
+  PulseAudio is free software; you can redistribute it and/or modify
+  it under the terms of the GNU Lesser General Public License as published
+  by the Free Software Foundation; either version 2.1 of the License,
+  or (at your option) any later version.
+
+  PulseAudio is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with PulseAudio; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+  USA.
+***/
+
+/* One source of device class definitions is the Bluetooth specification:
+ * https://www.bluetooth.org/en-us/specification/assigned-numbers-overview/baseband
+ *
+ * The Bluetooth specification divides device classes to major and minor
+ * classes. We don't list every possible Bluetooth minor device class here.
+ * Instead, the "computer" and "phone" major classes in Bluetooth are mapped to
+ * single "computer" and "phone" classes here. Almost all of the minor classes
+ * in the "audio/video" major class in Bluetooth have their own device class
+ * here. All other Bluetooth major device classes are categorized as "unknown"
+ * (they are not likely to have audio capabilities).
+ *
+ * Even though this list is heavily based on the Bluetooth specification, this
+ * is not intended to be Bluetooth specific in any way. New classes can be
+ * freely added if something is missing. */
+typedef enum {
+    /* This can mean that we don't have enough information about the device
+     * class, or we don't understand the information (e.g. udev can give
+     * arbitrary strings as the form factor). */
+    PA_DEVICE_CLASS_UNKNOWN,
+
+    PA_DEVICE_CLASS_COMPUTER,
+    PA_DEVICE_CLASS_PHONE,
+    PA_DEVICE_CLASS_HEADSET,
+    PA_DEVICE_CLASS_HANDSFREE,
+    PA_DEVICE_CLASS_MICROPHONE,
+    PA_DEVICE_CLASS_SPEAKERS,
+    PA_DEVICE_CLASS_HEADPHONES,
+    PA_DEVICE_CLASS_PORTABLE,
+    PA_DEVICE_CLASS_CAR,
+    PA_DEVICE_CLASS_SETTOP_BOX,
+    PA_DEVICE_CLASS_HIFI,
+    PA_DEVICE_CLASS_VCR,
+    PA_DEVICE_CLASS_VIDEO_CAMERA,
+    PA_DEVICE_CLASS_CAMCORDER,
+    PA_DEVICE_CLASS_VIDEO_DISPLAY_AND_SPEAKERS,
+    PA_DEVICE_CLASS_VIDEO_CONFERENCING,
+    PA_DEVICE_CLASS_GAMING_OR_TOY,
+    PA_DEVICE_CLASS_TUNER, /* XXX: Should there be separate classes for radio and TV tuners? */
+    PA_DEVICE_CLASS_MAX
+} pa_device_class_t;
+
+pa_device_class_t pa_device_class_from_string(const char *str);
+const char *pa_device_class_to_string(pa_device_class_t class);
+
+#endif
-- 
1.8.1.2



[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux