diff options
author | Takashi Sakamoto <o-takashi@sakamocchi.jp> | 2022-05-05 11:37:24 +0900 |
---|---|---|
committer | 坂本 貴史 <o-takashi@sakamocchi.jp> | 2022-05-05 16:09:50 +0900 |
commit | 2cfc1bddb11d40477844f8f50c8c66c0799fb17f (patch) | |
tree | 68f7863c2b80bacafef7d4780d483a1f0b663952 | |
parent | 6efd86a53b55f3f6af422c17da152d393cba05d0 (diff) | |
download | libhinoko-2cfc1bddb11d40477844f8f50c8c66c0799fb17f.tar.gz |
fw_iso_ctx: code refactoring for properties
Some properties should be implemented in derived object classes.
This commit adds helper function for the properties.
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
-rw-r--r-- | src/fw_iso_ctx.c | 55 | ||||
-rw-r--r-- | src/fw_iso_ctx_private.c | 31 | ||||
-rw-r--r-- | src/fw_iso_ctx_private.h | 16 | ||||
-rw-r--r-- | src/fw_iso_rx_multiple.c | 35 | ||||
-rw-r--r-- | src/fw_iso_rx_single.c | 18 | ||||
-rw-r--r-- | src/fw_iso_tx.c | 18 |
6 files changed, 97 insertions, 76 deletions
diff --git a/src/fw_iso_ctx.c b/src/fw_iso_ctx.c index 4a9f4d6..e777cd3 100644 --- a/src/fw_iso_ctx.c +++ b/src/fw_iso_ctx.c @@ -49,41 +49,18 @@ typedef struct { GError **error); } FwIsoCtxSource; -enum fw_iso_ctx_prop_type { - FW_ISO_CTX_PROP_TYPE_BYTES_PER_CHUNK = 1, - FW_ISO_CTX_PROP_TYPE_CHUNKS_PER_BUFFER, - FW_ISO_CTX_PROP_TYPE_REGISTERED_CHUNK_COUNT, - FW_ISO_CTX_PROP_TYPE_COUNT, -}; -static GParamSpec *fw_iso_ctx_props[FW_ISO_CTX_PROP_TYPE_COUNT] = { NULL, }; - enum fw_iso_ctx_sig_type { FW_ISO_CTX_SIG_TYPE_STOPPED = 1, FW_ISO_CTX_SIG_TYPE_COUNT, }; static guint fw_iso_ctx_sigs[FW_ISO_CTX_SIG_TYPE_COUNT] = { 0 }; -static void fw_iso_ctx_get_property(GObject *obj, guint id, GValue *val, - GParamSpec *spec) +static void fw_iso_ctx_get_property(GObject *obj, guint id, GValue *val, GParamSpec *spec) { HinokoFwIsoCtx *self = HINOKO_FW_ISO_CTX(obj); - HinokoFwIsoCtxPrivate *priv = - hinoko_fw_iso_ctx_get_instance_private(self); - - switch (id) { - case FW_ISO_CTX_PROP_TYPE_BYTES_PER_CHUNK: - g_value_set_uint(val, priv->bytes_per_chunk); - break; - case FW_ISO_CTX_PROP_TYPE_CHUNKS_PER_BUFFER: - g_value_set_uint(val, priv->chunks_per_buffer); - break; - case FW_ISO_CTX_PROP_TYPE_REGISTERED_CHUNK_COUNT: - g_value_set_uint(val, priv->registered_chunk_count); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, id, spec); - break; - } + const HinokoFwIsoCtxPrivate *priv = hinoko_fw_iso_ctx_get_instance_private(self); + + fw_iso_ctx_state_get_property(priv, obj, id, val, spec); } static void fw_iso_ctx_set_property(GObject *obj, guint id, const GValue *val, @@ -109,26 +86,24 @@ static void hinoko_fw_iso_ctx_class_init(HinokoFwIsoCtxClass *klass) gobject_class->set_property = fw_iso_ctx_set_property; gobject_class->finalize = fw_iso_ctx_finalize; - fw_iso_ctx_props[FW_ISO_CTX_PROP_TYPE_BYTES_PER_CHUNK] = - g_param_spec_uint("bytes-per-chunk", "bytes-per-chunk", + g_object_class_install_property(gobject_class, FW_ISO_CTX_PROP_TYPE_BYTES_PER_CHUNK, + g_param_spec_uint(BYTES_PER_CHUNK_PROP_NAME, "bytes-per-chunk", "The number of bytes for chunk in buffer.", 0, G_MAXUINT, 0, - G_PARAM_READABLE); - fw_iso_ctx_props[FW_ISO_CTX_PROP_TYPE_CHUNKS_PER_BUFFER] = - g_param_spec_uint("chunks-per-buffer", "chunks-per-buffer", + G_PARAM_READABLE)); + + g_object_class_install_property(gobject_class, FW_ISO_CTX_PROP_TYPE_CHUNKS_PER_BUFFER, + g_param_spec_uint(CHUNKS_PER_BUFFER_PROP_NAME, "chunks-per-buffer", "The number of chunks in buffer.", 0, G_MAXUINT, 0, - G_PARAM_READABLE); - fw_iso_ctx_props[FW_ISO_CTX_PROP_TYPE_REGISTERED_CHUNK_COUNT] = - g_param_spec_uint("registered-chunk-count", + G_PARAM_READABLE)); + + g_object_class_install_property(gobject_class, FW_ISO_CTX_PROP_TYPE_REGISTERED_CHUNK_COUNT, + g_param_spec_uint(REGISTERED_CHUNK_COUNT_PROP_NAME, "registered-chunk-count", "The number of chunk to be registered.", 0, G_MAXUINT, 0, - G_PARAM_READABLE); - - g_object_class_install_properties(gobject_class, - FW_ISO_CTX_PROP_TYPE_COUNT, - fw_iso_ctx_props); + G_PARAM_READABLE)); /** * HinokoFwIsoCtx::stopped: diff --git a/src/fw_iso_ctx_private.c b/src/fw_iso_ctx_private.c index 4754834..cb97d5f 100644 --- a/src/fw_iso_ctx_private.c +++ b/src/fw_iso_ctx_private.c @@ -6,6 +6,37 @@ #include <fcntl.h> #include <sys/mman.h> +void fw_iso_ctx_class_override_properties(GObjectClass *gobject_class) +{ + g_object_class_override_property(gobject_class, FW_ISO_CTX_PROP_TYPE_BYTES_PER_CHUNK, + BYTES_PER_CHUNK_PROP_NAME); + + g_object_class_override_property(gobject_class, FW_ISO_CTX_PROP_TYPE_CHUNKS_PER_BUFFER, + CHUNKS_PER_BUFFER_PROP_NAME); + + g_object_class_override_property(gobject_class, FW_ISO_CTX_PROP_TYPE_REGISTERED_CHUNK_COUNT, + REGISTERED_CHUNK_COUNT_PROP_NAME); +} + +void fw_iso_ctx_state_get_property(const struct fw_iso_ctx_state *state, GObject *obj, guint id, + GValue *val, GParamSpec *spec) +{ + switch (id) { + case FW_ISO_CTX_PROP_TYPE_BYTES_PER_CHUNK: + g_value_set_uint(val, state->bytes_per_chunk); + break; + case FW_ISO_CTX_PROP_TYPE_CHUNKS_PER_BUFFER: + g_value_set_uint(val, state->chunks_per_buffer); + break; + case FW_ISO_CTX_PROP_TYPE_REGISTERED_CHUNK_COUNT: + g_value_set_uint(val, state->registered_chunk_count); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, id, spec); + break; + } +} + /** * fw_iso_ctx_state_init: * @state: A [struct@FwIsoCtxState]. diff --git a/src/fw_iso_ctx_private.h b/src/fw_iso_ctx_private.h index dee46eb..8acbf57 100644 --- a/src/fw_iso_ctx_private.h +++ b/src/fw_iso_ctx_private.h @@ -41,8 +41,24 @@ struct fw_iso_ctx_state { gboolean running; }; +enum fw_iso_ctx_prop_type { + FW_ISO_CTX_PROP_TYPE_BYTES_PER_CHUNK = 1, + FW_ISO_CTX_PROP_TYPE_CHUNKS_PER_BUFFER, + FW_ISO_CTX_PROP_TYPE_REGISTERED_CHUNK_COUNT, + FW_ISO_CTX_PROP_TYPE_COUNT, +}; + +#define BYTES_PER_CHUNK_PROP_NAME "bytes-per-chunk" +#define CHUNKS_PER_BUFFER_PROP_NAME "chunks-per-buffer" +#define REGISTERED_CHUNK_COUNT_PROP_NAME "registered-chunk-count" + #define STOPPED_SIGNAL_NEME "stopped" +void fw_iso_ctx_class_override_properties(GObjectClass *gobject_class); + +void fw_iso_ctx_state_get_property(const struct fw_iso_ctx_state *state, GObject *obj, guint id, + GValue *val, GParamSpec *spec); + void fw_iso_ctx_state_init(struct fw_iso_ctx_state *state); gboolean fw_iso_ctx_state_allocate(struct fw_iso_ctx_state *state, const char *path, diff --git a/src/fw_iso_rx_multiple.c b/src/fw_iso_rx_multiple.c index d677da1..6e82de0 100644 --- a/src/fw_iso_rx_multiple.c +++ b/src/fw_iso_rx_multiple.c @@ -32,10 +32,9 @@ static void fw_iso_ctx_class_init(HinokoFwIsoCtxClass *parent_class); G_DEFINE_TYPE_WITH_PRIVATE(HinokoFwIsoRxMultiple, hinoko_fw_iso_rx_multiple, HINOKO_TYPE_FW_ISO_CTX) enum fw_iso_rx_multiple_prop_type { - FW_ISO_RX_MULTIPLE_PROP_TYPE_CHANNELS = 1, + FW_ISO_RX_MULTIPLE_PROP_TYPE_CHANNELS = FW_ISO_CTX_PROP_TYPE_COUNT, FW_ISO_RX_MULTIPLE_PROP_TYPE_COUNT, }; -static GParamSpec *fw_iso_rx_multiple_props[FW_ISO_RX_MULTIPLE_PROP_TYPE_COUNT] = { NULL, }; enum fw_iso_rx_multiple_sig_type { FW_ISO_RX_MULTIPLE_SIG_TYPE_IRQ = 1, @@ -43,17 +42,7 @@ enum fw_iso_rx_multiple_sig_type { }; static guint fw_iso_rx_multiple_sigs[FW_ISO_RX_MULTIPLE_SIG_TYPE_COUNT] = { 0 }; -static void fw_iso_rx_multiple_finalize(GObject *obj) -{ - HinokoFwIsoRxMultiple *self = HINOKO_FW_ISO_RX_MULTIPLE(obj); - - hinoko_fw_iso_rx_multiple_release(self); - - G_OBJECT_CLASS(hinoko_fw_iso_rx_multiple_parent_class)->finalize(obj); -} - -static void fw_iso_rx_multiple_get_property(GObject *obj, guint id, GValue *val, - GParamSpec *spec) +static void fw_iso_rx_multiple_get_property(GObject *obj, guint id, GValue *val, GParamSpec *spec) { HinokoFwIsoRxMultiple *self = HINOKO_FW_ISO_RX_MULTIPLE(obj); HinokoFwIsoRxMultiplePrivate *priv = @@ -69,10 +58,13 @@ static void fw_iso_rx_multiple_get_property(GObject *obj, guint id, GValue *val, } } -static void fw_iso_rx_multiple_set_property(GObject *obj, guint id, - const GValue *val, GParamSpec *spec) +static void fw_iso_rx_multiple_finalize(GObject *obj) { - G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, id, spec); + HinokoFwIsoRxMultiple *self = HINOKO_FW_ISO_RX_MULTIPLE(obj); + + hinoko_fw_iso_rx_multiple_release(self); + + G_OBJECT_CLASS(hinoko_fw_iso_rx_multiple_parent_class)->finalize(obj); } static void hinoko_fw_iso_rx_multiple_class_init(HinokoFwIsoRxMultipleClass *klass) @@ -80,22 +72,17 @@ static void hinoko_fw_iso_rx_multiple_class_init(HinokoFwIsoRxMultipleClass *kla GObjectClass *gobject_class = G_OBJECT_CLASS(klass); HinokoFwIsoCtxClass *parent_class = HINOKO_FW_ISO_CTX_CLASS(klass); - gobject_class->finalize = fw_iso_rx_multiple_finalize; gobject_class->get_property = fw_iso_rx_multiple_get_property; - gobject_class->set_property = fw_iso_rx_multiple_set_property; + gobject_class->finalize = fw_iso_rx_multiple_finalize; fw_iso_ctx_class_init(parent_class); - fw_iso_rx_multiple_props[FW_ISO_RX_MULTIPLE_PROP_TYPE_CHANNELS] = + g_object_class_install_property(gobject_class, FW_ISO_RX_MULTIPLE_PROP_TYPE_CHANNELS, g_param_spec_boxed("channels", "channels", "The array with elements to represent " "channels to be listened to", G_TYPE_BYTE_ARRAY, - G_PARAM_READABLE); - - g_object_class_install_properties(gobject_class, - FW_ISO_RX_MULTIPLE_PROP_TYPE_COUNT, - fw_iso_rx_multiple_props); + G_PARAM_READABLE)); /** * HinokoFwIsoRxMultiple::interrupted: diff --git a/src/fw_iso_rx_single.c b/src/fw_iso_rx_single.c index f13ac1f..2d1fb6c 100644 --- a/src/fw_iso_rx_single.c +++ b/src/fw_iso_rx_single.c @@ -24,6 +24,17 @@ static void fw_iso_ctx_class_init(HinokoFwIsoCtxClass *parent_class); G_DEFINE_TYPE_WITH_PRIVATE(HinokoFwIsoRxSingle, hinoko_fw_iso_rx_single, HINOKO_TYPE_FW_ISO_CTX) +enum fw_iso_rx_single_sig_type { + FW_ISO_RX_SINGLE_SIG_TYPE_IRQ = 1, + FW_ISO_RX_SINGLE_SIG_TYPE_COUNT, +}; +static guint fw_iso_rx_single_sigs[FW_ISO_RX_SINGLE_SIG_TYPE_COUNT] = { 0 }; + +static void fw_iso_rx_single_get_property(GObject *obj, guint id, GValue *val, GParamSpec *spec) +{ + return; +} + static void fw_iso_rx_single_finalize(GObject *obj) { HinokoFwIsoRxSingle *self = HINOKO_FW_ISO_RX_SINGLE(obj); @@ -33,17 +44,12 @@ static void fw_iso_rx_single_finalize(GObject *obj) G_OBJECT_CLASS(hinoko_fw_iso_rx_single_parent_class)->finalize(obj); } -enum fw_iso_rx_single_sig_type { - FW_ISO_RX_SINGLE_SIG_TYPE_IRQ = 1, - FW_ISO_RX_SINGLE_SIG_TYPE_COUNT, -}; -static guint fw_iso_rx_single_sigs[FW_ISO_RX_SINGLE_SIG_TYPE_COUNT] = { 0 }; - static void hinoko_fw_iso_rx_single_class_init(HinokoFwIsoRxSingleClass *klass) { GObjectClass *gobject_class = G_OBJECT_CLASS(klass); HinokoFwIsoCtxClass *parent_class = HINOKO_FW_ISO_CTX_CLASS(klass); + gobject_class->get_property = fw_iso_rx_single_get_property; gobject_class->finalize = fw_iso_rx_single_finalize; fw_iso_ctx_class_init(parent_class); diff --git a/src/fw_iso_tx.c b/src/fw_iso_tx.c index 2adcf86..f6d961c 100644 --- a/src/fw_iso_tx.c +++ b/src/fw_iso_tx.c @@ -18,6 +18,17 @@ static void fw_iso_ctx_class_init(HinokoFwIsoCtxClass *parent_class); G_DEFINE_TYPE_WITH_PRIVATE(HinokoFwIsoTx, hinoko_fw_iso_tx, HINOKO_TYPE_FW_ISO_CTX) +enum fw_iso_tx_sig_type { + FW_ISO_TX_SIG_TYPE_IRQ = 1, + FW_ISO_TX_SIG_TYPE_COUNT, +}; +static guint fw_iso_tx_sigs[FW_ISO_TX_SIG_TYPE_COUNT] = { 0 }; + +static void fw_iso_tx_get_property(GObject *obj, guint id, GValue *val, GParamSpec *spec) +{ + return; +} + static void fw_iso_tx_finalize(GObject *obj) { HinokoFwIsoTx *self = HINOKO_FW_ISO_TX(obj); @@ -27,17 +38,12 @@ static void fw_iso_tx_finalize(GObject *obj) G_OBJECT_CLASS(hinoko_fw_iso_tx_parent_class)->finalize(obj); } -enum fw_iso_tx_sig_type { - FW_ISO_TX_SIG_TYPE_IRQ = 1, - FW_ISO_TX_SIG_TYPE_COUNT, -}; -static guint fw_iso_tx_sigs[FW_ISO_TX_SIG_TYPE_COUNT] = { 0 }; - static void hinoko_fw_iso_tx_class_init(HinokoFwIsoTxClass *klass) { GObjectClass *gobject_class = G_OBJECT_CLASS(klass); HinokoFwIsoCtxClass *parent_class = HINOKO_FW_ISO_CTX_CLASS(klass); + gobject_class->get_property = fw_iso_tx_get_property; gobject_class->finalize = fw_iso_tx_finalize; fw_iso_ctx_class_init(parent_class); |