From: Takashi Sakamoto Date: Sun, 9 Feb 2020 03:20:53 +0000 (+0900) Subject: timer: instance_info: add properties X-Git-Tag: v0.1.0~345 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=a3b96a96f745de6550ebe785239341ae3f874a2e;p=alsa-gobject.git timer: instance_info: add properties Signed-off-by: Takashi Sakamoto --- diff --git a/src/timer/instance-info.c b/src/timer/instance-info.c index 47c0bbe..61fbce1 100644 --- a/src/timer/instance-info.c +++ b/src/timer/instance-info.c @@ -1,11 +1,94 @@ // SPDX-License-Identifier: LGPL-3.0-or-later #include "instance-info.h" -G_DEFINE_TYPE(ALSATimerInstanceInfo, alsatimer_instance_info, G_TYPE_OBJECT) +#include + +struct _ALSATimerInstanceInfoPrivate { + struct snd_timer_info info; +}; +G_DEFINE_TYPE_WITH_PRIVATE(ALSATimerInstanceInfo, alsatimer_instance_info, G_TYPE_OBJECT) + +enum timer_instance_info_props { + TIMER_INSTANCE_INFO_PROP_FLAGS = 1, + TIMER_INSTANCE_INFO_PROP_CARD_ID, + TIMER_INSTANCE_INFO_PROP_ID, + TIMER_INSTANCE_INFO_PROP_NAME, + TIMER_INSTANCE_INFO_PROP_RESOLUTION, + TIMER_INSTANCE_INFO_PROP_COUNT, +}; +static GParamSpec *timer_instance_info_props[TIMER_INSTANCE_INFO_PROP_COUNT] = { NULL, }; + +static void timer_instance_info_get_property(GObject *obj, guint id, GValue *val, + GParamSpec *spec) +{ + ALSATimerInstanceInfo *self = ALSATIMER_INSTANCE_INFO(obj); + ALSATimerInstanceInfoPrivate *priv = + alsatimer_instance_info_get_instance_private(self); + + switch (id) { + case TIMER_INSTANCE_INFO_PROP_FLAGS: + g_value_set_flags(val, (ALSATimerDeviceInfoFlag)priv->info.flags); + break; + case TIMER_INSTANCE_INFO_PROP_CARD_ID: + g_value_set_int(val, priv->info.card); + break; + case TIMER_INSTANCE_INFO_PROP_ID: + g_value_set_static_string(val, (const char *)priv->info.id); + break; + case TIMER_INSTANCE_INFO_PROP_NAME: + g_value_set_static_string(val, (const char*)priv->info.name); + break; + case TIMER_INSTANCE_INFO_PROP_RESOLUTION: + g_value_set_uint64(val, (guint64)priv->info.resolution); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, id, spec); + break; + } +} static void alsatimer_instance_info_class_init(ALSATimerInstanceInfoClass *klass) { - return; + GObjectClass *gobject_class = G_OBJECT_CLASS(klass); + + gobject_class->get_property = timer_instance_info_get_property; + + timer_instance_info_props[TIMER_INSTANCE_INFO_PROP_FLAGS] = + g_param_spec_flags("flags", "flags", + "The flags for attached timer.", + ALSATIMER_TYPE_DEVICE_INFO_FLAG, + 0, + G_PARAM_READABLE); + + timer_instance_info_props[TIMER_INSTANCE_INFO_PROP_CARD_ID] = + g_param_spec_int("card-id", "card-id", + "The numerical ID of sound card for attached timer.", + G_MININT, G_MAXINT, + -1, + G_PARAM_READABLE); + + timer_instance_info_props[TIMER_INSTANCE_INFO_PROP_ID] = + g_param_spec_string("id", "id", + "The string ID of attached timer.", + "", + G_PARAM_READABLE); + + timer_instance_info_props[TIMER_INSTANCE_INFO_PROP_NAME] = + g_param_spec_string("name", "name", + "The name of attached timer.", + "", + G_PARAM_READABLE); + + timer_instance_info_props[TIMER_INSTANCE_INFO_PROP_RESOLUTION] = + g_param_spec_uint64("resolution", "resolution", + "The resolution of attached timer in nano seconds.", + 0, G_MAXUINT64, + 0, + G_PARAM_READABLE); + + g_object_class_install_properties(gobject_class, + TIMER_INSTANCE_INFO_PROP_COUNT, + timer_instance_info_props); } static void alsatimer_instance_info_init(ALSATimerInstanceInfo *self) diff --git a/src/timer/instance-info.h b/src/timer/instance-info.h index 52c4b1d..f31082e 100644 --- a/src/timer/instance-info.h +++ b/src/timer/instance-info.h @@ -5,7 +5,7 @@ #include #include -#include +#include G_BEGIN_DECLS @@ -33,9 +33,12 @@ G_BEGIN_DECLS typedef struct _ALSATimerInstanceInfo ALSATimerInstanceInfo; typedef struct _ALSATimerInstanceInfoClass ALSATimerInstanceInfoClass; +typedef struct _ALSATimerInstanceInfoPrivate ALSATimerInstanceInfoPrivate; struct _ALSATimerInstanceInfo { GObject parent_instance; + + ALSATimerInstanceInfoPrivate *priv; }; struct _ALSATimerInstanceInfoClass { diff --git a/tests/alsatimer-instance-info b/tests/alsatimer-instance-info index 7af17db..59ba773 100644 --- a/tests/alsatimer-instance-info +++ b/tests/alsatimer-instance-info @@ -10,7 +10,13 @@ gi.require_version('ALSATimer', '0.0') from gi.repository import ALSATimer target = ALSATimer.InstanceInfo() -props = () +props = ( + 'flags', + 'card-id', + 'id', + 'name', + 'resolution', +) methods = () signals = ()