OSDN Git Service

control: add empty plugin
authorJaroslav Kysela <perex@perex.cz>
Tue, 6 Apr 2021 18:34:18 +0000 (20:34 +0200)
committerJaroslav Kysela <perex@perex.cz>
Wed, 7 Apr 2021 14:24:20 +0000 (16:24 +0200)
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
src/control/Makefile.am
src/control/control.c
src/control/control_empty.c [new file with mode: 0644]
src/control/control_symbols.c

index 5080269..eb66fa5 100644 (file)
@@ -1,7 +1,8 @@
 EXTRA_LTLIBRARIES = libcontrol.la
 
 libcontrol_la_SOURCES = cards.c tlv.c namehint.c hcontrol.c \
-                        control.c control_hw.c setup.c ctlparse.c \
+                       control.c control_hw.c control_empty.c \
+                       setup.c ctlparse.c \
                        control_plugin.c control_symbols.c
 if BUILD_CTL_PLUGIN_REMAP
 libcontrol_la_SOURCES += control_remap.c
index 1968d5a..602735d 100644 (file)
@@ -1345,7 +1345,7 @@ snd_ctl_t *snd_async_handler_get_ctl(snd_async_handler_t *handler)
 }
 
 static const char *const build_in_ctls[] = {
-       "hw", "remap", "shm", NULL
+       "hw", "empty", "remap", "shm", NULL
 };
 
 static int snd_ctl_open_conf(snd_ctl_t **ctlp, const char *name,
diff --git a/src/control/control_empty.c b/src/control/control_empty.c
new file mode 100644 (file)
index 0000000..49d1026
--- /dev/null
@@ -0,0 +1,101 @@
+/**
+ * \file control/control_empty.c
+ * \ingroup Control_Plugins
+ * \brief Control Empty Plugin Interface
+ * \author Jaroslav Kysela <perex@perex.cz>
+ * \date 2021
+ */
+/*
+ *  Control - Empty plugin
+ *  Copyright (c) 2021 by Jaroslav Kysela <perex@perex.cz>
+ *
+ *
+ *   This library 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.
+ *
+ *   This program 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 Lesser General Public License for more details.
+ *
+ *   You should have received a copy of the GNU Lesser General Public
+ *   License along with this library; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#include "control_local.h"
+
+#ifndef PIC
+/* entry for static linking */
+const char *_snd_module_ctl_empty = "";
+#endif
+
+/*! \page control_plugins
+
+\section control_plugins_empty Plugin: Empty
+
+This plugin just redirects the control device to another plugin.
+
+\code
+ctl.name {
+       type empty              # Empty Control
+       child STR               # Slave name
+       # or
+       child {                 # Child definition
+               ...
+       }
+}
+\endcode
+
+\subsection control_plugins_empty_funcref Function reference
+
+<UL>
+  <LI>_snd_ctl_empty_open()
+</UL>
+
+*/
+
+/**
+ * \brief Creates a new Empty Control
+ * \param handlep Returns created Control handle
+ * \param name Name of Control
+ * \param root Root configuration node
+ * \param conf Configuration node with empty Control description
+ * \param mode Control mode
+ * \retval zero on success otherwise a negative error code
+ * \warning Using of this function might be dangerous in the sense
+ *          of compatibility reasons. The prototype might be freely
+ *          changed in future.
+ */
+int _snd_ctl_empty_open(snd_ctl_t **handlep, const char *name ATTRIBUTE_UNUSED,
+                       snd_config_t *root, snd_config_t *conf,  int mode)
+{
+       snd_config_t *child = NULL;
+       snd_config_iterator_t i, next;
+
+       snd_config_for_each(i, next, conf) {
+               snd_config_t *n = snd_config_iterator_entry(i);
+               const char *id;
+               if (snd_config_get_id(n, &id) < 0)
+                       continue;
+               if (_snd_conf_generic_id(id))
+                       continue;
+               if (strcmp(id, "child") == 0) {
+                       child = n;
+                       continue;
+               }
+               SNDERR("Unknown field %s", id);
+               return -EINVAL;
+       }
+       if (!child) {
+               SNDERR("child is not defined");
+               return -EINVAL;
+       }
+       return _snd_ctl_open_named_child(handlep, name, root, child, mode, conf);
+}
+#ifndef DOC_HIDDEN
+SND_DLSYM_BUILD_VERSION(_snd_ctl_empty_open, SND_CONTROL_DLSYM_VERSION);
+#endif
index 10d4689..5e6c4e9 100644 (file)
 #ifndef PIC
 
 extern const char *_snd_module_control_hw;
+extern const char *_snd_module_control_empty;
 extern const char *_snd_module_control_remap;
 extern const char *_snd_module_control_shm;
 extern const char *_snd_module_control_ext;
 
 static const char **snd_control_open_objects[] = {
        &_snd_module_control_hw,
+       &_snd_module_control_empty,
 #include "ctl_symbols_list.c"
 };