]> git.alsa-project.org Git - alsa-gobject.git/commitdiff
seq: add private structure and constructor
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Mon, 8 Jun 2020 14:10:10 +0000 (23:10 +0900)
committer坂本 貴史 <o-takashi@sakamocchi.jp>
Tue, 9 Jun 2020 00:16:09 +0000 (09:16 +0900)
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
src/seq/alsaseq.map
src/seq/event-cntr.c
src/seq/event-cntr.h
src/seq/privates.h
tests/alsaseq-event-cntr

index 09985d38b98ab684aba1d729836e0b2caba384bc..d03af9bc623c08f2ad74145cf428d7455da2d435 100644 (file)
@@ -171,6 +171,7 @@ ALSA_GOBJECT_0_0_0 {
     "alsaseq_remove_filter_new_with_real_time";
 
     "alsaseq_event_cntr_get_type";
+    "alsaseq_event_cntr_new";
   local:
     *;
 };
index 7d96ff5c4035d7d3d9e9cc430b55c25c25dc23df..cc935c237024463654c3e17214eb81cf0f81c7e8 100644 (file)
@@ -1,13 +1,76 @@
-#include "event-cntr.h"
+// SPDX-License-Identifier: LGPL-3.0-or-later
+#include "privates.h"
 
-G_DEFINE_TYPE(ALSASeqEventCntr, alsaseq_event_cntr, G_TYPE_OBJECT)
+#include <errno.h>
+
+typedef struct _ALSASeqEventCntrPrivate {
+    guint8 *buf;
+    gsize length;
+
+    gboolean allocated;
+} ALSASeqEventCntrPrivate;
+G_DEFINE_TYPE_WITH_PRIVATE(ALSASeqEventCntr, alsaseq_event_cntr, G_TYPE_OBJECT)
+
+static void seq_event_cntr_finaize(GObject *obj)
+{
+    ALSASeqEventCntr *self = ALSASEQ_EVENT_CNTR(obj);
+    ALSASeqEventCntrPrivate *priv =
+                                alsaseq_event_cntr_get_instance_private(self);
+
+    if (priv->allocated)
+        g_free(priv->buf);
+
+    G_OBJECT_CLASS(alsaseq_event_cntr_parent_class)->finalize(obj);
+}
 
 static void alsaseq_event_cntr_class_init(ALSASeqEventCntrClass *klass)
 {
-    return;
+    GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+
+    gobject_class->finalize = seq_event_cntr_finaize;
 }
 
 static void alsaseq_event_cntr_init(ALSASeqEventCntr *self)
 {
-    return;
+    ALSASeqEventCntrPrivate *priv =
+                                alsaseq_event_cntr_get_instance_private(self);
+
+    priv->buf = NULL;
+    priv->length = 0;
+    priv->allocated = FALSE;
+}
+
+/**
+ * alsaseq_event_cntr_new:
+ * @count: The number of events going to be allocated.
+ * @error: A #GError.
+ *
+ * Allocates and return an instance of #ALSASeqEventCntr to store the count
+ * of events.
+ *
+ * Returns: A #ALSASeqEventCntr.
+ */
+ALSASeqEventCntr *alsaseq_event_cntr_new(guint count, GError **error)
+{
+    ALSASeqEventCntr *self = g_object_new(ALSASEQ_TYPE_EVENT_CNTR, NULL);
+    ALSASeqEventCntrPrivate *priv =
+                                alsaseq_event_cntr_get_instance_private(self);
+    struct snd_seq_event *ev;
+    int i;
+
+    priv->length = sizeof(struct snd_seq_event) * count;
+    priv->buf = g_try_malloc0(priv->length);
+    if (priv->buf == NULL) {
+        generate_error(error, ENOMEM);
+        return NULL;
+    }
+    priv->allocated = TRUE;
+
+    ev = (struct snd_seq_event *)priv->buf;
+    for (i = 0; i < count; ++i) {
+        ev[i].type = SNDRV_SEQ_EVENT_NONE;
+        ev[i].queue = SNDRV_SEQ_QUEUE_DIRECT;
+    }
+
+    return self;
 }
index 8a6ca8576711011729c10ddf637951d19d4c3f10..c737606423efe2c6c31c8e54cdc227667cdd7516 100644 (file)
@@ -31,9 +31,12 @@ G_BEGIN_DECLS
 
 typedef struct _ALSASeqEventCntr            ALSASeqEventCntr;
 typedef struct _ALSASeqEventCntrClass       ALSASeqEventCntrClass;
+typedef struct _ALSASeqEventCntrPrivate     ALSASeqEventCntrPrivate;
 
 struct _ALSASeqEventCntr {
     GObject parent_instance;
+
+    ALSASeqEventCntrPrivate *priv;
 };
 
 struct _ALSASeqEventCntrClass {
@@ -42,6 +45,8 @@ struct _ALSASeqEventCntrClass {
 
 GType alsaseq_event_cntr_get_type() G_GNUC_CONST;
 
+ALSASeqEventCntr *alsaseq_event_cntr_new(guint count, GError **error);
+
 G_END_DECLS
 
 #endif
index 6556e21d2a94e271824510f3b83dfd03ca985da0..ff07c7b62794cc544735eb229a9d8a4187c6064d 100644 (file)
@@ -17,6 +17,7 @@
 #include "queue-status.h"
 #include "queue-tempo.h"
 #include "queue-timer.h"
+#include "event-cntr.h"
 
 #include <sound/asequencer.h>
 
index d3e19864e80946f77a35fcb6d160bd504272d1ec..96231900319008f5184869068a4ea5bdead81ae2 100644 (file)
@@ -11,7 +11,9 @@ from gi.repository import ALSASeq
 
 target = ALSASeq.EventCntr()
 props = ()
-methods = ()
+methods = (
+    'new',
+)
 signals = ()
 
 if not test(target, props, methods, signals):