From 20cb2a1f111009aa184d32ab221e032188f4cf5e Mon Sep 17 00:00:00 2001 From: Takashi Sakamoto Date: Sun, 9 Feb 2020 12:20:53 +0900 Subject: [PATCH] timer: device_params: add properties Signed-off-by: Takashi Sakamoto --- src/timer/alsatimer.map | 1 + src/timer/device-params.c | 86 ++++++++++++++++++++++++++++++++++- src/timer/device-params.h | 7 +++ src/timer/privates.h | 1 + tests/alsatimer-device-params | 9 +++- 5 files changed, 100 insertions(+), 4 deletions(-) diff --git a/src/timer/alsatimer.map b/src/timer/alsatimer.map index 4935ff7..0dbab88 100644 --- a/src/timer/alsatimer.map +++ b/src/timer/alsatimer.map @@ -25,6 +25,7 @@ ALSA_GOBJECT_0_0_0 { "alsatimer_device_status_get_type"; "alsatimer_device_params_get_type"; + "alsatimer_device_params_new"; local: *; }; diff --git a/src/timer/device-params.c b/src/timer/device-params.c index 73e05af..b7b5406 100644 --- a/src/timer/device-params.c +++ b/src/timer/device-params.c @@ -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); +} diff --git a/src/timer/device-params.h b/src/timer/device-params.h index 09be883..47c57f8 100644 --- a/src/timer/device-params.h +++ b/src/timer/device-params.h @@ -5,6 +5,8 @@ #include #include +#include + 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 diff --git a/src/timer/privates.h b/src/timer/privates.h index 81cb6af..e29e848 100644 --- a/src/timer/privates.h +++ b/src/timer/privates.h @@ -4,6 +4,7 @@ #include "device-info.h" #include "device-status.h" +#include "device-params.h" #include diff --git a/tests/alsatimer-device-params b/tests/alsatimer-device-params index 2370959..5474794 100644 --- a/tests/alsatimer-device-params +++ b/tests/alsatimer-device-params @@ -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): -- 2.47.3