[Spice-devel] [PATCH v4 36/41] codegen: Allows to specify ws_as attribute for messages
Frediano Ziglio
fziglio at redhat.com
Thu Jul 23 08:54:53 PDT 2015
Signed-off-by: Frediano Ziglio <fziglio at 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(-)
diff --git a/python_modules/dissector.py b/python_modules/dissector.py
index 8580ca8..064ed64 100644
--- a/python_modules/dissector.py
+++ b/python_modules/dissector.py
@@ -913,7 +913,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 e5d0ebd..a4fdb2d 100644
--- a/python_modules/ptypes.py
+++ b/python_modules/ptypes.py
@@ -995,11 +995,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_)
--
2.1.0
More information about the Spice-devel
mailing list