From e345bec401d492b68a00cbebf8e35f8cb19dc1c8 Mon Sep 17 00:00:00 2001 From: Takashi Sakamoto Date: Mon, 11 Apr 2022 17:41:05 +0900 Subject: fw_resp: use an utility macro to declare GObject-derived object Since gobject v2.44, an utility macro is available to declare GObject-derived objects. This commit replaces existent boireplates with it. Signed-off-by: Takashi Sakamoto --- src/fw_node.c | 4 ++-- src/fw_resp.c | 4 ++-- src/fw_resp.h | 32 +------------------------------- 3 files changed, 5 insertions(+), 35 deletions(-) diff --git a/src/fw_node.c b/src/fw_node.c index 511e483..e6b5b39 100644 --- a/src/fw_node.c +++ b/src/fw_node.c @@ -462,8 +462,8 @@ static gboolean dispatch_src(GSource *gsrc, GSourceFunc cb, gpointer user_data) if (HINAWA_IS_FW_NODE((gpointer)common->closure) && common->type == FW_CDEV_EVENT_BUS_RESET) { handle_update(src->self); - } else if (HINAWA_IS_FW_RESP(common->closure) && common->type == FW_CDEV_EVENT_REQUEST2) { - hinawa_fw_resp_handle_request(HINAWA_FW_RESP(common->closure), + } else if (HINAWA_IS_FW_RESP((gpointer)common->closure) && common->type == FW_CDEV_EVENT_REQUEST2) { + hinawa_fw_resp_handle_request(HINAWA_FW_RESP((gpointer)common->closure), (struct fw_cdev_event_request2 *)common); } else if (HINAWA_IS_FW_REQ((gpointer)common->closure) && common->type == FW_CDEV_EVENT_RESPONSE) { struct fw_cdev_event_response *ev = (struct fw_cdev_event_response *)common; diff --git a/src/fw_resp.c b/src/fw_resp.c index 0775f8f..122eb4e 100644 --- a/src/fw_resp.c +++ b/src/fw_resp.c @@ -40,7 +40,7 @@ static const char *const err_msgs[] = { g_set_error(exception, HINAWA_FW_RESP_ERROR, HINAWA_FW_RESP_ERROR_FAILED, \ format " %d(%s)", arg, errno, strerror(errno)) -struct _HinawaFwRespPrivate { +typedef struct { HinawaFwNode *node; guint64 offset; @@ -51,7 +51,7 @@ struct _HinawaFwRespPrivate { gsize req_length; guint8 *resp_frame; gsize resp_length; -}; +} HinawaFwRespPrivate; G_DEFINE_TYPE_WITH_PRIVATE(HinawaFwResp, hinawa_fw_resp, G_TYPE_OBJECT) // This object has one property. diff --git a/src/fw_resp.h b/src/fw_resp.h index 9116b48..89d5d31 100644 --- a/src/fw_resp.h +++ b/src/fw_resp.h @@ -8,40 +8,12 @@ G_BEGIN_DECLS #define HINAWA_TYPE_FW_RESP (hinawa_fw_resp_get_type()) -#define HINAWA_FW_RESP(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj), \ - HINAWA_TYPE_FW_RESP, \ - HinawaFwResp)) -#define HINAWA_IS_FW_RESP(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj), \ - HINAWA_TYPE_FW_RESP)) - -#define HINAWA_FW_RESP_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass), \ - HINAWA_TYPE_FW_RESP, \ - HinawaFwRespClass)) -#define HINAWA_IS_FW_RESP_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE((klass), \ - HINAWA_TYPE_FW_RESP)) -#define HINAWA_FW_RESP_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS((obj), \ - HINAWA_TYPE_FW_RESP, \ - HinawaFwRespClass)) +G_DECLARE_DERIVABLE_TYPE(HinawaFwResp, hinawa_fw_resp, HINAWA, FW_RESP, GObject); #define HINAWA_FW_RESP_ERROR hinawa_fw_resp_error_quark() GQuark hinawa_fw_resp_error_quark(); -typedef struct _HinawaFwResp HinawaFwResp; -typedef struct _HinawaFwRespClass HinawaFwRespClass; -typedef struct _HinawaFwRespPrivate HinawaFwRespPrivate; - -struct _HinawaFwResp { - GObject parent_instance; - - HinawaFwRespPrivate *priv; -}; - struct _HinawaFwRespClass { GObjectClass parent_class; @@ -92,8 +64,6 @@ struct _HinawaFwRespClass { const guint8 *frame, guint length); }; -GType hinawa_fw_resp_get_type(void) G_GNUC_CONST; - HinawaFwResp *hinawa_fw_resp_new(void); void hinawa_fw_resp_reserve_within_region(HinawaFwResp *self, HinawaFwNode *node, -- cgit 1.2.3-korg