[Spice-devel] [PATCH v6 20/42] dissector: Handle structures

Frediano Ziglio fziglio at redhat.com
Thu Aug 13 06:11:59 PDT 2015


Generate a function to parse the structure and call it to be able to
reuse it.

Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 python_modules/dissector.py | 20 ++++++++++++++++++++
 tests/Makefile.am           |  1 +
 tests/check_dissector       |  2 ++
 tests/out_struct1.txt       |  7 +++++++
 tests/test.proto            |  9 +++++++++
 5 files changed, 39 insertions(+)
 create mode 100644 tests/out_struct1.txt

diff --git a/python_modules/dissector.py b/python_modules/dissector.py
index 09f1585..51466e9 100644
--- a/python_modules/dissector.py
+++ b/python_modules/dissector.py
@@ -310,9 +310,29 @@ def write_array(writer, container, member, nelements, array, dest, scope):
 def write_pointer(writer, container, member, t, dest, scope):
     assert(t.is_pointer())
 
+
+def write_struct_func(writer, t, func_name, index):
+    func_name = 'dissect_spice_struct_' + t.name
+
+    if writer.is_generated("struct", t.name):
+        return
+    writer.set_is_generated("struct", t.name)
+
+    writer = writer.function_helper()
+    scope = writer.function(func_name, "guint32", "GlobalInfo *glb _U_, proto_tree *tree _U_, guint32 offset, gint32 index _U_", True)
+    dest = RootDestination(scope)
+    write_container_parser(writer, t, dest)
+    writer.statement('return offset')
+    writer.end_block()
+
+
 def write_struct(writer, member, t, index, dest, scope):
     assert(t.is_struct())
 
+    func_name = 'dissect_spice_struct_' + t.name
+    write_struct_func(writer, t, func_name, index)
+    writer.assign('offset', '%s(glb, %s, offset, %s)' % (func_name, dest.level.tree, index))
+
 def write_member_primitive(writer, container, member, t, dest, scope):
     assert(t.is_primitive())
 
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 0e8b214..be4df74 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -58,6 +58,7 @@ EXTRA_DIST =				\
 	out_empty.txt			\
 	data_base1			\
 	out_base1.txt			\
+	out_struct1.txt			\
 	$(NULL)
 
 CLEANFILES = test.c test.h enums.h dissector.c dissector.h *.trs check_dissector.txt
diff --git a/tests/check_dissector b/tests/check_dissector
index bff3853..767ee9d 100755
--- a/tests/check_dissector
+++ b/tests/check_dissector
@@ -54,4 +54,6 @@ fi
 # check just base types
 check data_base1 1 1 out_base1.txt
 
+check data_base1 1 1 out_struct1.txt --client
+
 exit 0
diff --git a/tests/out_struct1.txt b/tests/out_struct1.txt
new file mode 100644
index 0000000..a1d429c
--- /dev/null
+++ b/tests/out_struct1.txt
@@ -0,0 +1,7 @@
+--- tree
+    --- item
+    Text: 33154 (0x8182)
+    Name: dummy
+    Abbrev: spice2.auto.Dummy_dummy
+    Type: FT_UINT16
+    Base: BASE_DEC
diff --git a/tests/test.proto b/tests/test.proto
index 28d7769..06fa303 100644
--- a/tests/test.proto
+++ b/tests/test.proto
@@ -30,6 +30,10 @@ flags32 F32 {
 	N, O, P, Q
 };
 
+struct Dummy {
+    uint16 dummy;
+};
+
 channel BaseChannel {
   server:
     message {
@@ -49,6 +53,11 @@ channel BaseChannel {
 	F32 f32;
     } Base1 = 1;
     Empty empty = 100;
+
+  client:
+    message {
+        Dummy struct;
+    } Struct1 = 1;
 };
 
 protocol Spice {
-- 
2.4.3



More information about the Spice-devel mailing list