[CRIU] [PATCH 1/4] protobuf: add show support for images payload

Kinsbursky Stanislav skinsbursky at openvz.org
Wed Jul 25 08:40:27 EDT 2012


Payload handler can be passed into generic protobuf show function.

Signed-off-by: Stanislav Kinsbursky <skinsbursky at openvz.org>

---
 include/protobuf.h |   14 ++++++++++----
 protobuf.c         |    7 ++++++-
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/include/protobuf.h b/include/protobuf.h
index 5edb7cb..0958fb5 100644
--- a/include/protobuf.h
+++ b/include/protobuf.h
@@ -59,17 +59,23 @@ extern int pb_write_object_with_header(int fd, void *obj,
 #include <google/protobuf-c/protobuf-c.h>
 
 extern void do_pb_show_plain(int fd, const ProtobufCMessageDescriptor *d,
-		pb_unpack_t unpack, pb_free_t free, int single_entry);
+		pb_unpack_t unpack, pb_free_t free, int single_entry,
+		void (*payload_hadler)(int fd, void *obj));
 
 /* Don't have objects at hands to also do typechecking here */
-#define pb_show_plain(__fd, __proto_message_name)			\
+#define pb_show_plain_payload(__fd, __proto_message_name, payload_hadler)		\
 	do_pb_show_plain(__fd, &__proto_message_name##__descriptor,	\
 			(pb_unpack_t)__proto_message_name##__unpack,			\
-			(pb_free_t)__proto_message_name##__free_unpacked, 0)
+			(pb_free_t)__proto_message_name##__free_unpacked,		\
+			0, payload_hadler)
+
+#define pb_show_plain(__fd, __proto_message_name)			\
+	pb_show_plain_payload(__fd, __proto_message_name, NULL)
 
 #define pb_show_vertical(__fd, __proto_message_name)			\
 	do_pb_show_plain(__fd, &__proto_message_name##__descriptor,	\
 			(pb_unpack_t)__proto_message_name##__unpack,			\
-			(pb_free_t)__proto_message_name##__free_unpacked, 1)
+			(pb_free_t)__proto_message_name##__free_unpacked,		\
+			1, NULL)
 
 #endif /* PROTOBUF_H__ */
diff --git a/protobuf.c b/protobuf.c
index 279b487..42e836b 100644
--- a/protobuf.c
+++ b/protobuf.c
@@ -210,10 +210,14 @@ static void pb_show_msg(const void *msg, pb_pr_ctl_t *ctl)
 	}
 }
 
+static inline void pb_no_payload(int fd, void *obj) { }
+
 void do_pb_show_plain(int fd, const ProtobufCMessageDescriptor *md,
-		pb_unpack_t unpack, pb_free_t free, int single_entry)
+		pb_unpack_t unpack, pb_free_t free, int single_entry,
+		void (*payload_hadler)(int fd, void *obj))
 {
 	pb_pr_ctl_t ctl = {NULL, single_entry, 0};
+	void (*handle_payload)(int fd, void *obj) = (payload_hadler) ? : pb_no_payload;
 
 	while (1) {
 		void *obj;
@@ -223,6 +227,7 @@ void do_pb_show_plain(int fd, const ProtobufCMessageDescriptor *md,
 
 		ctl.arg = (void *)md;
 		pb_show_msg(obj, &ctl);
+		handle_payload(fd, obj);
 		free(obj, NULL);
 		if (single_entry)
 			break;



More information about the CRIU mailing list