All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Sakamoto <o-takashi@sakamocchi.jp>
To: clemens@ladisch.de, tiwai@suse.de, perex@perex.cz
Cc: alsa-devel@alsa-project.org,
	linux1394-devel@lists.sourceforge.net, ffado-devel@lists.sf.net
Subject: [PATCH 12/13] libhinawa: add 'unit_query' as a query for ALSA FireWire devices
Date: Sun, 25 Jan 2015 20:34:33 +0900	[thread overview]
Message-ID: <1422185674-16431-13-git-send-email-o-takashi@sakamocchi.jp> (raw)
In-Reply-To: <1422185674-16431-1-git-send-email-o-takashi@sakamocchi.jp>

To construct an instance of snd_unit/snd_dice/snd_efw, applications need
to know which hwdep device is corresponding to the target unit.

This commit adds HINAWA_TYPE_UNIT_QUERY object to query hwdep devices for
FireWire unit. This object has no constructor, therefore applications can
get sibling hwdep device or the type of given hwdep device without any
instances.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 libhinawa/doc/reference/hinawa-docs.sgml |   1 +
 libhinawa/src/Makefile.am                |   7 +-
 libhinawa/src/unit_query.c               | 116 +++++++++++++++++++++++++++++++
 libhinawa/src/unit_query.h               |  48 +++++++++++++
 4 files changed, 170 insertions(+), 2 deletions(-)
 create mode 100644 libhinawa/src/unit_query.c
 create mode 100644 libhinawa/src/unit_query.h

diff --git a/libhinawa/doc/reference/hinawa-docs.sgml b/libhinawa/doc/reference/hinawa-docs.sgml
index 731ae15..dbfa0f2 100644
--- a/libhinawa/doc/reference/hinawa-docs.sgml
+++ b/libhinawa/doc/reference/hinawa-docs.sgml
@@ -37,6 +37,7 @@
             <xi:include href="xml/snd_unit.xml"/>
             <xi:include href="xml/snd_dice.xml"/>
             <xi:include href="xml/snd_efw.xml"/>
+            <xi:include href="xml/unit_query.xml"/>
         </chapter>
     </part>
 
diff --git a/libhinawa/src/Makefile.am b/libhinawa/src/Makefile.am
index b746bf1..4fbbdd3 100644
--- a/libhinawa/src/Makefile.am
+++ b/libhinawa/src/Makefile.am
@@ -38,7 +38,9 @@ libhinawa_la_SOURCES =				\
 	snd_dice.h				\
 	snd_dice.c				\
 	snd_efw.h				\
-	snd_efw.c
+	snd_efw.c				\
+	unit_query.h				\
+	unit_query.c
 
 pkginclude_HEADERS =				\
 	hinawa_sigs_marshal.h			\
@@ -48,7 +50,8 @@ pkginclude_HEADERS =				\
 	fw_fcp.h				\
 	snd_unit.h				\
 	snd_dice.h				\
-	snd_efw.h
+	snd_efw.h				\
+	unit_query.h
 
 hinawa_sigs_marshal.list:
 	$(AM_V_GEN)( find | grep \.c$$ | xargs cat | 			\
diff --git a/libhinawa/src/unit_query.c b/libhinawa/src/unit_query.c
new file mode 100644
index 0000000..669513d
--- /dev/null
+++ b/libhinawa/src/unit_query.c
@@ -0,0 +1,116 @@
+#include <unistd.h>
+#include <alsa/asoundlib.h>
+#include <sound/firewire.h>
+
+#include "unit_query.h"
+
+/**
+ * SECTION:unit_query
+ * @Title: HinawaUnitQuery
+ * @Short_description: An query to seek ALSA FireWire devices
+ *
+ */
+G_DEFINE_TYPE(HinawaUnitQuery, hinawa_unit_query, G_TYPE_OBJECT)
+
+static void unit_query_dispose(GObject *obj)
+{
+	G_OBJECT_CLASS(hinawa_unit_query_parent_class)->dispose(obj);
+}
+
+static void unit_query_finalize(GObject *gobject)
+{
+	G_OBJECT_CLASS(hinawa_unit_query_parent_class)->finalize(gobject);
+}
+
+static void hinawa_unit_query_class_init(HinawaUnitQueryClass *klass)
+{
+	GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+
+	gobject_class->dispose = unit_query_dispose;
+	gobject_class->finalize = unit_query_finalize;
+}
+
+static void hinawa_unit_query_init(HinawaUnitQuery *self)
+{
+	return;
+}
+
+/**
+ * hinawa_unit_query_get_sibling:
+ * @id: The ID of sibling.
+ * @exception: A #GError
+ *
+ * Returns: the ID of sibling.
+ */
+gint hinawa_unit_query_get_sibling(gint id, GError **exception)
+{
+	snd_ctl_t *handle = NULL;
+	int err;
+
+	/* NOTE: at least one sound device is expected to be detected. */
+	err = snd_ctl_open(&handle, "hw:0", 0);
+	if (err < 0)
+		goto end;
+
+	err = snd_ctl_hwdep_next_device(handle, &id);
+	if (err < 0)
+		goto end;
+	if (id < 0) {
+		err = -ENODEV;
+		goto end;
+	}
+
+	hinawa_unit_query_get_unit_type(id, exception);
+end:
+	if (err < 0) {
+		id = -1;
+		g_set_error(exception, g_quark_from_static_string(__func__),
+			    -err, "%s", snd_strerror(err));
+	}
+	if (handle != NULL)
+		snd_ctl_close(handle);
+
+	return id;
+}
+
+/**
+ * hinawa_unit_query_get_unit_type:
+ * @id: An ID for unit.
+ * @exception: An #GError
+ *
+ * Returns: The types of the unit. The value of SNDRV_FIREWIRE_TYPE_XXX.
+ */
+gint hinawa_unit_query_get_unit_type(gint id, GError **exception)
+{
+	snd_hwdep_t *handle = NULL;
+	char path[10] = {0};
+	struct snd_firewire_get_info info;
+	gint type = -1;
+	int err;
+
+	/* Check id and make device string */
+	if (id < 0) {
+		err = -EINVAL;
+		goto end;
+	}
+	snprintf(path, sizeof(path), "hw:%d", id);
+
+	/* Open hwdep handle. */
+	err = snd_hwdep_open(&handle, path, 0);
+	if (err < 0)
+		goto end;
+
+	/* Get FireWire sound device information. */
+	err = snd_hwdep_ioctl(handle, SNDRV_FIREWIRE_IOCTL_GET_INFO, &info);
+	if (err < 0)
+		goto end;
+	type = info.type;
+end:
+	if (err < 0)
+		g_set_error(exception, g_quark_from_static_string(__func__),
+			    -err, "%s", snd_strerror(err));
+	if (handle != NULL)
+		snd_hwdep_close(handle);
+
+	return type;
+}
diff --git a/libhinawa/src/unit_query.h b/libhinawa/src/unit_query.h
new file mode 100644
index 0000000..cdaf09b
--- /dev/null
+++ b/libhinawa/src/unit_query.h
@@ -0,0 +1,48 @@
+#ifndef __ALSA_TOOLS_HINAWA_UNIT_QUERY_H__
+#define __ALSA_TOOLS_HINAWA_UNIT_QUERY_H__
+
+#include <glib.h>
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define HINAWA_TYPE_UNIT_QUERY	(hinawa_unit_query_get_type())
+
+#define HINAWA_UNIT_QUERY(obj)					\
+	(G_TYPE_CHECK_INSTANCE_CAST((obj),			\
+				    HINAWA_TYPE_UNIT_QUERY,	\
+				    HinawaUnitQuery))
+#define HINAWA_IS_UNIT_QUERY(obj)				\
+	(G_TYPE_CHECK_INSTANCE_TYPE((obj),			\
+				    HINAWA_TYPE_UNIT_QUERY))
+
+#define HINAWA_UNIT_QUERY_CLASS(klass)				\
+	(G_TYPE_CHECK_CLASS_CAST((klass),			\
+				 HINAWA_TYPE_UNIT_QUERY,	\
+				 HinawaUnitQueryClass))
+#define HINAWA_IS_UNIT_QUERY_CLASS(klass)			\
+	(G_TYPE_CHECK_CLASS_TYPE((klass),			\
+				 HINAWA_TYPE_UNIT_QUERY))
+#define HINAWA_UNIT_QUERY_GET_CLASS(obj)			\
+	(G_TYPE_INSTANCE_GET_CLASS((obj),			\
+				   HINAWA_TYPE_UNIT_QUERY,	\
+				   HinawaUnitQueryClass))
+
+typedef struct _HinawaUnitQuery		HinawaUnitQuery;
+typedef struct _HinawaUnitQueryClass	HinawaUnitQueryClass;
+
+struct _HinawaUnitQuery {
+	GObject parent_instance;
+};
+
+struct _HinawaUnitQueryClass {
+	GObjectClass parent_class;
+};
+
+GType hinawa_unit_query_get_type(void) G_GNUC_CONST;
+
+gint hinawa_unit_query_get_sibling(gint id, GError **exception);
+
+gint hinawa_unit_query_get_unit_type(gint id, GError **exception);
+
+#endif
-- 
2.1.0


------------------------------------------------------------------------------
New Year. New Location. New Benefits. New Data Center in Ashburn, VA.
GigeNET is offering a free month of service with a new server in Ashburn.
Choose from 2 high performing configs, both with 100TB of bandwidth.
Higher redundancy.Lower latency.Increased capacity.Completely compliant.
http://p.sf.net/sfu/gigenet

  parent reply	other threads:[~2015-01-25 11:34 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-25 11:34 [RFC][PATCH 00/13] alsa-tools: libhinawa for control applications of FireWire devices Takashi Sakamoto
2015-01-25 11:34 ` [PATCH 01/13] libhinawa: add build definitions Takashi Sakamoto
2015-01-25 11:34 ` [PATCH 02/13] libhinawa: add hinawa context Takashi Sakamoto
2015-01-27 15:35   ` Takashi Sakamoto
2015-01-25 11:34 ` [PATCH 03/13] libhinawa: support GTK-Doc to generate references Takashi Sakamoto
2015-01-25 11:34 ` [PATCH 04/13] libhinawa: add 'fw_unit' object as a listener for FireWire unit Takashi Sakamoto
2015-01-25 11:34 ` [PATCH 05/13] libhinawa: support GObject Introspection for language bindings Takashi Sakamoto
2015-01-25 11:34 ` [PATCH 06/13] libhinawa: add 'fw_resp' object as a responder for FireWire transaction Takashi Sakamoto
2015-01-25 11:34 ` [PATCH 07/13] libhinawa: add 'fw_req' object as requester " Takashi Sakamoto
2015-01-25 11:34 ` [PATCH 08/13] libhinawa: add 'fw_fcp' object as a helper of FCP transaction Takashi Sakamoto
2015-01-25 11:34 ` [PATCH 09/13] libhinawa: add 'snd_unit' object as a listener for ALSA FireWire devices Takashi Sakamoto
2015-01-25 11:34 ` [PATCH 10/13] libhinawa: add 'snd_dice' object as a helper for Dice notification Takashi Sakamoto
2015-01-25 11:34 ` [PATCH 11/13] libhinawa: add 'snd_efw' object as a helper for EFW transaction Takashi Sakamoto
2015-01-25 11:34 ` Takashi Sakamoto [this message]
2015-01-25 11:34 ` [PATCH 13/13] libhinawa: add sample scripts Takashi Sakamoto
2015-01-25 12:14   ` [alsa-devel] " Alexander E. Patrakov
2015-01-27 15:09     ` Takashi Sakamoto
2015-01-27 15:16       ` Alexander E. Patrakov
2015-01-26 23:05 ` [FFADO-devel] [RFC][PATCH 00/13] alsa-tools: libhinawa for control applications of FireWire devices Jonathan Woithe
2015-03-20  9:28 ` Damien Zammit
2015-03-20 10:09   ` [alsa-devel] " Clemens Ladisch

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1422185674-16431-13-git-send-email-o-takashi@sakamocchi.jp \
    --to=o-takashi@sakamocchi.jp \
    --cc=alsa-devel@alsa-project.org \
    --cc=clemens@ladisch.de \
    --cc=ffado-devel@lists.sf.net \
    --cc=linux1394-devel@lists.sourceforge.net \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.