]> git.alsa-project.org Git - alsa-gobject.git/commitdiff
hwdep: add error domain for implementators of DeviceCommon interface
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Fri, 3 Jun 2022 03:36:48 +0000 (12:36 +0900)
committerTakashi Sakamoto <o-takashi@sakamocchi.jp>
Fri, 3 Jun 2022 03:36:48 +0000 (12:36 +0900)
The implementator of DeviceCommon interface should operate character
device for ALSA HwDep interface, thus it can receive any type of error
as a result of system call. Some of the error may be common.

This commit adds error domain for the case.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
src/hwdep/alsahwdep-enum-types.h
src/hwdep/alsahwdep.map
src/hwdep/device-common.c
src/hwdep/device-common.h
tests/alsahwdep-enums

index a8c84d071336cd41204abd5092da54dd6a9fb4b9..a58e13475b91d7ce951f214dc58666026e46db45 100644 (file)
@@ -7,7 +7,7 @@
 G_BEGIN_DECLS
 
 /**
- *ALSAHwdepIfaceType:
+ * ALSAHwdepIfaceType:
  * @ALSAHWDEP_IFACE_TYPE_OPL2:              For OPL2 sound chip.
  * @ALSAHWDEP_IFACE_TYPE_OPL3:              For OPL3 sound chip.
  * @ALSAHWDEP_IFACE_TYPE_OPL4:              For OPL4 sound chip.
@@ -68,6 +68,26 @@ typedef enum {
     ALSAHWDEP_IFACE_TYPE_FW_FIREFACE,
 } ALSAHwdepIfaceType;
 
+/**
+ * ALSAHwdepDeviceCommonError:
+ *  @ALSAHWDEP_DEVICE_COMMON_ERROR_FAILED:              The operation failed due to unspecified reason.
+ *  @ALSAHWDEP_DEVICE_COMMON_ERROR_IS_OPENED:           The instance is already associated to character device.
+ *  @ALSAHWDEP_DEVICE_COMMON_ERROR_IS_NOT_OPENED:       The instance is not associated to character device yet.
+ *  @ALSAHWDEP_DEVICE_COMMON_ERROR_IS_USED:             The character device is already used.
+ *  @ALSAHWDEP_DEVICE_COMMON_ERROR_IS_NOT_SUPPORTED:    The HwDep device associated to the character device is not supported.
+ *  @ALSAHWDEP_DEVICE_COMMON_ERROR_IS_DISCONNECTED:     The sound card is under disconnected state.
+ *
+ * A set of enumerations for code of ALSAHwDep.DeviceCommonError error domain.
+ */
+typedef enum {
+    ALSAHWDEP_DEVICE_COMMON_ERROR_FAILED = 1,
+    ALSAHWDEP_DEVICE_COMMON_ERROR_IS_OPENED,
+    ALSAHWDEP_DEVICE_COMMON_ERROR_IS_NOT_OPENED,
+    ALSAHWDEP_DEVICE_COMMON_ERROR_IS_USED,
+    ALSAHWDEP_DEVICE_COMMON_ERROR_IS_NOT_SUPPORTED,
+    ALSAHWDEP_DEVICE_COMMON_ERROR_IS_DISCONNECTED,
+} ALSAHwdepDeviceCommonError;
+
 G_END_DECLS
 
 #endif
index a37cca4f8bfcb0f0193a7aa9804a12e83cf3e665..ea361f1399550502464551ab16ee82bc255c8c79 100644 (file)
@@ -19,4 +19,8 @@ ALSA_GOBJECT_0_3_0 {
     "alsahwdep_device_common_get_protocol_version";
     "alsahwdep_device_common_get_device_info";
     "alsahwdep_device_common_create_source";
+
+    "alsahwdep_device_common_error_quark";
+    "alsahwdep_device_common_error_get_type";
+    "alsahwdep_device_common_error_to_label";
 } ALSA_GOBJECT_0_0_0;
index d6f9f75ca890d835ac2f7ec7ace34c0dc82bc334..a20ea40297b73f5f4ef8753791414ce1955cba0a 100644 (file)
@@ -14,6 +14,56 @@ static void alsahwdep_device_common_default_init(ALSAHwdepDeviceCommonInterface
 
 G_DEFINE_INTERFACE(ALSAHwdepDeviceCommon, alsahwdep_device_common, G_TYPE_OBJECT)
 
+/**
+ * alsahwdep_device_common_error_quark:
+ *
+ * Return the [alias@GLib.Quark] for [struct@GLib.Error] with code in ALSAHwdep.DeviceCommonError
+ * enumerations.
+ *
+ * Returns: A [alias@GLib.Quark].
+ */
+G_DEFINE_QUARK(alsahwdep-device-common-error-quark, alsahwdep_device_common_error)
+
+/**
+ * alsahwdep_device_common_error_to_label:
+ * @code: A ALSAHwdep.DeviceCommonError.
+ * @label: (out) (transfer none): The string label of error.
+ *
+ * Retrieve the string label of error from code.
+ */
+void alsahwdep_device_common_error_to_label(ALSAHwdepDeviceCommonError code, const char **label)
+{
+    static const char *const labels[] = {
+        [ALSAHWDEP_DEVICE_COMMON_ERROR_FAILED] =
+                            "The operation failed due to unspecified reason.",
+        [ALSAHWDEP_DEVICE_COMMON_ERROR_IS_OPENED] =
+                            "The instance is already associated to character device.",
+        [ALSAHWDEP_DEVICE_COMMON_ERROR_IS_NOT_OPENED] =
+                            "The instance is not associated to character device yet.",
+        [ALSAHWDEP_DEVICE_COMMON_ERROR_IS_USED] =
+                            "The character device is already used.",
+        [ALSAHWDEP_DEVICE_COMMON_ERROR_IS_NOT_SUPPORTED] =
+                            "The HwDep device associated to the character device is not supported.",
+        [ALSAHWDEP_DEVICE_COMMON_ERROR_IS_DISCONNECTED] =
+                            "The sound card is under disconnected state.",
+    };
+
+    switch (code) {
+    case ALSAHWDEP_DEVICE_COMMON_ERROR_FAILED:
+    case ALSAHWDEP_DEVICE_COMMON_ERROR_IS_OPENED:
+    case ALSAHWDEP_DEVICE_COMMON_ERROR_IS_NOT_OPENED:
+    case ALSAHWDEP_DEVICE_COMMON_ERROR_IS_USED:
+    case ALSAHWDEP_DEVICE_COMMON_ERROR_IS_NOT_SUPPORTED:
+    case ALSAHWDEP_DEVICE_COMMON_ERROR_IS_DISCONNECTED:
+        break;
+    default:
+        code = ALSAHWDEP_DEVICE_COMMON_ERROR_FAILED;
+        break;
+    }
+
+    *label = labels[code];
+}
+
 static void alsahwdep_device_common_default_init(ALSAHwdepDeviceCommonInterface *iface)
 {
     /**
index 247f419a1e469804c61c21dc52cf5cea83d3eee2..39382db3d6370e62b576a393099f58366a099f1d 100644 (file)
@@ -10,6 +10,10 @@ G_BEGIN_DECLS
 
 G_DECLARE_INTERFACE(ALSAHwdepDeviceCommon, alsahwdep_device_common, ALSAHWDEP, DEVICE_COMMON, GObject)
 
+GQuark alsahwdep_device_common_error_quark();
+
+void alsahwdep_device_common_error_to_label(ALSAHwdepDeviceCommonError code, const char **label);
+
 struct _ALSAHwdepDeviceCommonInterface {
     GTypeInterface parent_iface;
 
index d6b0747a971fab70800ccdca717e01d735b15d34..5ad287bebe2623c97351b16101e2d05278cbdd9a 100644 (file)
@@ -35,8 +35,18 @@ iface_types = (
     'FW_FIREFACE',
 )
 
+device_common_error_types = (
+    'FAILED',
+    'IS_OPENED',
+    'IS_NOT_OPENED',
+    'IS_USED',
+    'IS_NOT_SUPPORTED',
+    'IS_DISCONNECTED',
+)
+
 types = {
     ALSAHwdep.IfaceType:    iface_types,
+    ALSAHwdep.DeviceCommonError: device_common_error_types,
 }
 
 for obj, types in types.items():