]> git.alsa-project.org Git - alsa-gobject.git/commitdiff
timer: device_params: add properties
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Sun, 9 Feb 2020 03:20:53 +0000 (12:20 +0900)
committer坂本 貴史 <o-takashi@sakamocchi.jp>
Tue, 11 Feb 2020 04:28:18 +0000 (13:28 +0900)
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
src/timer/alsatimer.map
src/timer/device-params.c
src/timer/device-params.h
src/timer/privates.h
tests/alsatimer-device-params

index 4935ff7502c6e980ca41c444045e4297bd7aa04c..0dbab883f5f02bf9f10087edbfd3402420708892 100644 (file)
@@ -25,6 +25,7 @@ ALSA_GOBJECT_0_0_0 {
     "alsatimer_device_status_get_type";
 
     "alsatimer_device_params_get_type";
+    "alsatimer_device_params_new";
   local:
     *;
 };
index 73e05afa36ccaf134fe409ae596abfc8bc817ce6..b7b5406414a4561978aca39b67b9276f57742fcc 100644 (file)
@@ -1,14 +1,96 @@
 // SPDX-License-Identifier: LGPL-3.0-or-later
-#include "device-params.h"
+#include "privates.h"
 
+struct _ALSATimerDeviceParamsPrivate {
+    struct snd_timer_gparams params;
+};
 G_DEFINE_TYPE(ALSATimerDeviceParams, alsatimer_device_params, G_TYPE_OBJECT)
 
+enum timer_device_params_prop_type {
+    TIMER_DEVICE_PARAMS_PROP_PERIOD_NUM = 1,
+    TIMER_DEVICE_PARAMS_PROP_PERIOD_DEN,
+    TIMER_DEVICE_PARAMS_PROP_COUNT,
+};
+static GParamSpec *timer_device_params_props[TIMER_DEVICE_PARAMS_PROP_COUNT] = { NULL, };
+
+static void timer_device_params_set_property(GObject *obj, guint id,
+                                            const GValue *val, GParamSpec *spec)
+{
+    ALSATimerDeviceParams *self = ALSATIMER_DEVICE_PARAMS(obj);
+    ALSATimerDeviceParamsPrivate *priv =
+                            alsatimer_device_params_get_instance_private(self);
+
+    switch (id) {
+    case TIMER_DEVICE_PARAMS_PROP_PERIOD_NUM:
+        priv->params.period_num = (unsigned long)g_value_get_uint64(val);
+        break;
+    case TIMER_DEVICE_PARAMS_PROP_PERIOD_DEN:
+        priv->params.period_den = (unsigned long)g_value_get_uint64(val);
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, id, spec);
+        break;
+    }
+}
+
+static void timer_device_params_get_property(GObject *obj, guint id,
+                                             GValue *val, GParamSpec *spec)
+{
+    ALSATimerDeviceParams *self = ALSATIMER_DEVICE_PARAMS(obj);
+    ALSATimerDeviceParamsPrivate *priv =
+                            alsatimer_device_params_get_instance_private(self);
+
+    switch (id) {
+    case TIMER_DEVICE_PARAMS_PROP_PERIOD_NUM:
+        g_value_set_uint64(val, priv->params.period_num);
+        break;
+    case TIMER_DEVICE_PARAMS_PROP_PERIOD_DEN:
+        g_value_set_uint64(val, priv->params.period_den);
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, id, spec);
+        break;
+    }
+}
+
 static void alsatimer_device_params_class_init(ALSATimerDeviceParamsClass *klass)
 {
-    return;
+    GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+
+    gobject_class->set_property = timer_device_params_set_property;
+    gobject_class->get_property = timer_device_params_get_property;
+
+    timer_device_params_props[TIMER_DEVICE_PARAMS_PROP_PERIOD_NUM] =
+        g_param_spec_uint64("period-numerator", "period-numerator",
+                            "The numerator of period for timer.",
+                            0, G_MAXUINT64,
+                            0,
+                            G_PARAM_READWRITE);
+
+    timer_device_params_props[TIMER_DEVICE_PARAMS_PROP_PERIOD_DEN] =
+        g_param_spec_uint64("period-denominator", "period-denominator",
+                            "The denominator of period for timer.",
+                            0, G_MAXUINT64,
+                            0,
+                            G_PARAM_READWRITE);
+
+    g_object_class_install_properties(gobject_class,
+                    TIMER_DEVICE_PARAMS_PROP_COUNT, timer_device_params_props);
 }
 
 static void alsatimer_device_params_init(ALSATimerDeviceParams *self)
 {
     return;
 }
+
+/**
+ * alsatimer_device_params_new:
+ *
+ * Instantiate #ALSATimerDeviceParams object and return the instance.
+ *
+ * Returns: an instance of #ALSATimerDeviceParams.
+ */
+ALSATimerDeviceParams *alsatimer_device_params_new()
+{
+    return g_object_new(ALSATIMER_TYPE_DEVICE_PARAMS, NULL);
+}
index 09be8833e924f1f92fda23106dababde6115edca..47c57f8f78ab6684a195e848f50a5160c79bb02f 100644 (file)
@@ -5,6 +5,8 @@
 #include <glib.h>
 #include <glib-object.h>
 
+#include <timer/device-id.h>
+
 G_BEGIN_DECLS
 
 #define ALSATIMER_TYPE_DEVICE_PARAMS    (alsatimer_device_params_get_type())
@@ -31,9 +33,12 @@ G_BEGIN_DECLS
 
 typedef struct _ALSATimerDeviceParams           ALSATimerDeviceParams;
 typedef struct _ALSATimerDeviceParamsClass      ALSATimerDeviceParamsClass;
+typedef struct _ALSATimerDeviceParamsPrivate    ALSATimerDeviceParamsPrivate;
 
 struct _ALSATimerDeviceParams {
     GObject parent_instance;
+
+    ALSATimerDeviceParamsPrivate *priv;
 };
 
 struct _ALSATimerDeviceParamsClass {
@@ -42,6 +47,8 @@ struct _ALSATimerDeviceParamsClass {
 
 GType alsatimer_device_params_get_type() G_GNUC_CONST;
 
+ALSATimerDeviceParams *alsatimer_device_params_new();
+
 G_END_DECLS
 
 #endif
index 81cb6af27a74de0fcf37b00e64f25c4cd06f4e93..e29e8485716afc598b65730ed2393e8dbbafcca4 100644 (file)
@@ -4,6 +4,7 @@
 
 #include "device-info.h"
 #include "device-status.h"
+#include "device-params.h"
 
 #include <sound/asound.h>
 
index 2370959e0755f6082553a2d5fd51738afcacfac0..5474794ec388a1f192aa250db21192612f8852f3 100644 (file)
@@ -10,8 +10,13 @@ gi.require_version('ALSATimer', '0.0')
 from gi.repository import ALSATimer
 
 target = ALSATimer.DeviceParams()
-props = ()
-methods = ()
+props = (
+    'period-numerator',
+    'period-denominator',
+)
+methods = (
+    'new',
+)
 signals = ()
 
 if not test(target, props, methods, signals):