]> git.alsa-project.org Git - alsa-gobject.git/commitdiff
seq: event_variable: add accessor methods and constructor
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Wed, 1 Apr 2020 09:13:28 +0000 (18:13 +0900)
committer坂本 貴史 <o-takashi@sakamocchi.jp>
Fri, 3 Apr 2020 13:06:25 +0000 (22:06 +0900)
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
src/seq/alsaseq.map
src/seq/event-variable.c
src/seq/event-variable.h
src/seq/event.c
src/seq/privates.h
tests/alsaseq-event-variable

index a3ecbe080741fd79c964c4db90564d441f16c7fe..5589432db2b5a1d9cf8d82aafbb0591be54210f4 100644 (file)
@@ -65,6 +65,9 @@ ALSA_GOBJECT_0_0_0 {
     "alsaseq_event_fixed_new";
 
     "alsaseq_event_variable_get_type";
+    "alsaseq_event_variable_new";
+    "alsaseq_event_variable_get_data";
+    "alsaseq_event_variable_set_data";
   local:
     *;
 };
index 7cb192fa7f9776f845ef963af6b358a85ba3dbbd..537388cdf45afd5c0f0fbae8d8570e7fc40ea723 100644 (file)
 // SPDX-License-Identifier: LGPL-3.0-or-later
 #include "event-variable.h"
+#include "privates.h"
 
-G_DEFINE_TYPE(ALSASeqEventVariable, alsaseq_event_variable, ALSASEQ_TYPE_EVENT)
+#include <errno.h>
+
+struct _ALSASeqEventVariablePrivate {
+    void *data;
+};
+G_DEFINE_TYPE_WITH_PRIVATE(ALSASeqEventVariable, alsaseq_event_variable, ALSASEQ_TYPE_EVENT)
+
+static void seq_event_variable_finalize(GObject *obj)
+{
+    ALSASeqEventVariable *self = ALSASEQ_EVENT_VARIABLE(obj);
+    ALSASeqEventVariablePrivate *priv =
+                            alsaseq_event_variable_get_instance_private(self);
+
+    if (priv->data != NULL)
+        g_free(priv->data);
+
+    G_OBJECT_CLASS(alsaseq_event_variable_parent_class)->finalize(obj);
+}
 
 static void alsaseq_event_variable_class_init(ALSASeqEventVariableClass *klass)
 {
-    return;
+    GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+
+    gobject_class->finalize = seq_event_variable_finalize;
 }
 
 static void alsaseq_event_variable_init(ALSASeqEventVariable *self)
 {
-    return;
+    ALSASeqEventVariablePrivate *priv =
+                            alsaseq_event_variable_get_instance_private(self);
+
+    priv->data = NULL;
+}
+
+/**
+ * alsaseq_event_variable_new:
+ * @event_type: A #ALSASeqEventType.
+ * @error: A #GError.
+ *
+ * Allocate and return an instance of #ALSASeqEventVariable class.
+ *
+ * Returns: (transfer full): A #ALSASeqEventVariable.
+ */
+ALSASeqEventVariable *alsaseq_event_variable_new(ALSASeqEventType event_type,
+                                                 GError **error)
+{
+    switch (event_type) {
+    case SNDRV_SEQ_EVENT_SYSEX:
+    case SNDRV_SEQ_EVENT_BOUNCE:
+    case SNDRV_SEQ_EVENT_USR_VAR0:
+    case SNDRV_SEQ_EVENT_USR_VAR1:
+    case SNDRV_SEQ_EVENT_USR_VAR2:
+    case SNDRV_SEQ_EVENT_USR_VAR3:
+    case SNDRV_SEQ_EVENT_USR_VAR4:
+        break;
+    default:
+        generate_error(error, EINVAL);
+        break;
+    }
+
+    return g_object_new(ALSASEQ_TYPE_EVENT_VARIABLE,
+                        "type", event_type,
+                        "length-mode", ALSASEQ_EVENT_LENGTH_MODE_VARIABLE,
+                        NULL);
+}
+
+/**
+ * alsaseq_event_variable_get_data:
+ * @self: A #ALSASeqEventVariable.
+ * @data: (array length=size)(out)(transfer none): The pointer to external data.
+ * @size: The size of data.
+ *
+ * Refer to the external data for the event.
+ */
+void alsaseq_event_variable_get_data(ALSASeqEventVariable *self,
+                                     const guint8 **data, gsize *size)
+{
+    ALSASeqEvent *parent;
+    struct snd_seq_event *ev;
+
+    g_return_if_fail(ALSASEQ_IS_EVENT_VARIABLE(self));
+    parent = ALSASEQ_EVENT(self);
+    seq_event_refer_private(parent, &ev);
+
+    *data = ev->data.ext.ptr;
+    *size = ev->data.ext.len;
+}
+
+/**
+ * alsaseq_event_variable_set_data:
+ * @self: A #ALSASeqEventVariable.
+ * @data: (array length=size)(transfer none): The pointer to external data.
+ * @size: The size of data.
+ *
+ * Allocate and copy the external data for the event.
+ */
+void alsaseq_event_variable_set_data(ALSASeqEventVariable *self,
+                                     const guint8 *data, gsize size)
+{
+    ALSASeqEventVariablePrivate *priv;
+    ALSASeqEvent *parent;
+    struct snd_seq_event *ev;
+
+    g_return_if_fail(ALSASEQ_IS_EVENT_VARIABLE(self));
+    priv = alsaseq_event_variable_get_instance_private(self);
+    parent = ALSASEQ_EVENT(self);
+    seq_event_refer_private(parent, &ev);
+
+    if (priv->data != NULL)
+        g_free(priv->data);
+    priv->data = NULL;
+    ev->data.ext.ptr = NULL;
+    ev->data.ext.len = 0;
+
+    priv->data = g_memdup(data, size);
+    if (priv->data == NULL)
+        return;
+
+    ev->data.ext.ptr = priv->data;
+    ev->data.ext.len = size;
 }
index 9ca930353802845c0bdd004cce13ed42b4ace5fd..169c26c9956b2e32ba42de948508b33caac744f2 100644 (file)
@@ -33,9 +33,12 @@ G_BEGIN_DECLS
 
 typedef struct _ALSASeqEventVariable        ALSASeqEventVariable;
 typedef struct _ALSASeqEventVariableClass   ALSASeqEventVariableClass;
+typedef struct _ALSASeqEventVariablePrivate ALSASeqEventVariablePrivate;
 
 struct _ALSASeqEventVariable {
     ALSASeqEvent parent_instance;
+
+    ALSASeqEventVariablePrivate *priv;
 };
 
 struct _ALSASeqEventVariableClass {
@@ -44,6 +47,13 @@ struct _ALSASeqEventVariableClass {
 
 GType alsaseq_event_variable_get_type() G_GNUC_CONST;
 
+ALSASeqEventVariable *alsaseq_event_variable_new(ALSASeqEventType event_type,
+                                                 GError **error);
+
+void alsaseq_event_variable_get_data(ALSASeqEventVariable *self,
+                                     const guint8 **data, gsize *size);
+void alsaseq_event_variable_set_data(ALSASeqEventVariable *self,
+                                     const guint8 *data, gsize size);
 G_END_DECLS
 
 #endif
index 8d6a08e47f10069fb817fb8af5810528be501cd3..dd4958405abd1c6359a2b6a9d40e91484296d2e8 100644 (file)
@@ -232,3 +232,9 @@ static void alsaseq_event_init(ALSASeqEvent *self)
 {
     return;
 }
+
+void seq_event_refer_private(ALSASeqEvent *self, struct snd_seq_event **ev)
+{
+    ALSASeqEventPrivate *priv = alsaseq_event_get_instance_private(self);
+    *ev = &priv->ev;
+}
index 6604029d31f3e122b6881ad459478bc6e899fa60..2ec43a40c9319d6cf1d7a182254d057744fe3d62 100644 (file)
@@ -35,6 +35,8 @@ void seq_port_info_refer_private(ALSASeqPortInfo *self,
 void seq_client_pool_refer_private(ALSASeqClientPool *self,
                                    struct snd_seq_client_pool **pool);
 
+void seq_event_refer_private(ALSASeqEvent *self, struct snd_seq_event **ev);
+
 G_END_DECLS
 
 #endif
index f28a42aabf042842c746c2a18cbc074d9b4fea37..4ead81b0f6a208b4dbcc27e2bff0a73595d3913d 100644 (file)
@@ -11,7 +11,11 @@ from gi.repository import ALSASeq
 
 target = ALSASeq.EventVariable()
 props = ()
-methods = ()
+methods = (
+    'new',
+    'get_data',
+    'set_data',
+)
 signals = ()
 
 if not test(target, props, methods, signals):