[Spice-devel,v3,46/51] Allows to specify ws_as attribute for messages

Submitted by Frediano Ziglio on July 21, 2015, 4:46 p.m.

Details

Message ID 1437497181-26929-47-git-send-email-fziglio@redhat.com
State New
Headers show

Not browsing as part of any series.

Commit Message

Frediano Ziglio July 21, 2015, 4:46 p.m.
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
---
 python_modules/dissector.py    | 7 ++++++-
 python_modules/ptypes.py       | 3 ++-
 python_modules/spice_parser.py | 4 ++--
 3 files changed, 10 insertions(+), 4 deletions(-)

Patch hide | download patch | download mbox

diff --git a/python_modules/dissector.py b/python_modules/dissector.py
index 5c6b6fc..3e1fd6d 100644
--- a/python_modules/dissector.py
+++ b/python_modules/dissector.py
@@ -914,7 +914,12 @@  def write_channel_parser(writer, channel, server):
         writer.write("static const parse_msg_func_t funcs%d[%d] = " % (d, r[1] - r[0]))
         writer.begin_block()
         for i in range(r[0], r[1]):
-            func = write_msg_parser(helpers, ids[i].message_type, server)
+            message_type = ids[i].message_type
+            if ids[i].has_attr('ws_as'):
+                type_name = ids[i].attributes['ws_as'][0]
+                assert(ptypes.type_exists(type_name))
+                message_type = ptypes.lookup_type(type_name)
+            func = write_msg_parser(helpers, message_type, server)
             writer.write(func)
             if i != r[1] -1:
                 writer.write(",")
diff --git a/python_modules/ptypes.py b/python_modules/ptypes.py
index 8c92493..e5e59e1 100644
--- a/python_modules/ptypes.py
+++ b/python_modules/ptypes.py
@@ -997,11 +997,12 @@  class MessageType(ContainerType):
             return codegen.prefix_camel("Msg", self.name)
 
 class ChannelMember(Containee):
-    def __init__(self, name, message_type, value):
+    def __init__(self, name, message_type, attribute_list, value):
         Containee.__init__(self)
         self.name = name
         self.message_type = message_type
         self.value = value
+        self.attributes = fix_attributes(attribute_list)
 
     def resolve(self, channel):
         self.channel = channel
diff --git a/python_modules/spice_parser.py b/python_modules/spice_parser.py
index 3fde843..958bf11 100644
--- a/python_modules/spice_parser.py
+++ b/python_modules/spice_parser.py
@@ -129,8 +129,8 @@  def SPICE_BNF():
         messageSpec = Group(message_ + messageBody + attributes).setParseAction(lambda toks: ptypes.MessageType(None, toks[0][1], toks[0][2])) | typename
 
         channelParent = Optional(colon + typename, default=None)
-        channelMessage = Group(messageSpec + identifier + Optional(equals + integer, default=None) + semi) \
-            .setParseAction(lambda toks: ptypes.ChannelMember(toks[0][1], toks[0][0], toks[0][2]))
+        channelMessage = Group(messageSpec + identifier + attributes + Optional(equals + integer, default=None) + semi) \
+            .setParseAction(lambda toks: ptypes.ChannelMember(toks[0][1], toks[0][0], toks[0][2], toks[0][3]))
         channelBody = channelParent + Group(lbrace + ZeroOrMore( server_ + colon | client_ + colon | channelMessage)  + rbrace)
 
         enum_ = (enum32_ | enum16_ | enum8_)