diff mbox series

[06/25] efw-downloader: efw-proto: add instance private structure

Message ID 20200821073111.134857-7-o-takashi@sakamocchi.jp
State New
Headers show
Series [01/25] efw-downloader: start a new project to operate on-board flash memory for Fireworks board module | expand

Commit Message

Takashi Sakamoto Aug. 21, 2020, 7:30 a.m. UTC
GObject allows instance to have private data.

This commit adds private structure to EfwProto instance.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 efw-downloader/src/efw-proto.c | 17 ++++++++++++++++-
 efw-downloader/src/efw-proto.h |  3 +++
 2 files changed, 19 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/efw-downloader/src/efw-proto.c b/efw-downloader/src/efw-proto.c
index 72b7655..72959ac 100644
--- a/efw-downloader/src/efw-proto.c
+++ b/efw-downloader/src/efw-proto.c
@@ -15,7 +15,10 @@ 
  * command to a certain address region on 1394 OHCI controller. The instance of #EfwProto reserves
  * the address region at call of #efw_proto_bind(), releases at call of #efw_proto_unbind().
  */
-G_DEFINE_TYPE(EfwProto, efw_proto, HINAWA_TYPE_FW_RESP)
+struct _EfwProtoPrivate {
+    guint32 *buf;
+};
+G_DEFINE_TYPE_WITH_PRIVATE(EfwProto, efw_proto, HINAWA_TYPE_FW_RESP)
 
 #define EFW_RESP_ADDR           0xecc080000000ull
 #define EFW_MAX_FRAME_SIZE      0x200u
@@ -94,9 +97,16 @@  EfwProto *efw_proto_new()
  */
 void efw_proto_bind(EfwProto *self, HinawaFwNode *node, GError **error)
 {
+    EfwProtoPrivate *priv;
+
     g_return_if_fail(EFW_IS_PROTO(self));
+    priv = efw_proto_get_instance_private(self);
 
     hinawa_fw_resp_reserve(HINAWA_FW_RESP(self), node, EFW_RESP_ADDR, EFW_MAX_FRAME_SIZE, error);
+    if (*error != NULL)
+        return;
+
+    priv->buf = g_malloc0(EFW_MAX_FRAME_SIZE);
 }
 
 /**
@@ -107,7 +117,12 @@  void efw_proto_bind(EfwProto *self, HinawaFwNode *node, GError **error)
  */
 void efw_proto_unbind(EfwProto *self)
 {
+    EfwProtoPrivate *priv;
+
     g_return_if_fail(EFW_IS_PROTO(self));
+    priv = efw_proto_get_instance_private(self);
 
     hinawa_fw_resp_release(HINAWA_FW_RESP(self));
+
+    g_free(priv->buf);
 }
diff --git a/efw-downloader/src/efw-proto.h b/efw-downloader/src/efw-proto.h
index fdbcbc8..bc179dc 100644
--- a/efw-downloader/src/efw-proto.h
+++ b/efw-downloader/src/efw-proto.h
@@ -27,9 +27,12 @@  G_BEGIN_DECLS
 
 typedef struct _EfwProto            EfwProto;
 typedef struct _EfwProtoClass       EfwProtoClass;
+typedef struct _EfwProtoPrivate     EfwProtoPrivate;
 
 struct _EfwProto {
     HinawaFwResp parent_instance;
+
+    EfwProtoPrivate *priv;
 };
 
 struct _EfwProtoClass {