diff options
author | Alexander Larsson <alexl@redhat.com> | 2010-06-22 10:32:08 +0200 |
---|---|---|
committer | Alexander Larsson <alexl@redhat.com> | 2010-06-22 10:54:59 +0200 |
commit | 5341b632e2b1d2527303cce3f69a8146a8d48489 (patch) | |
tree | 801fdb7345b3d008eed90780b36b59167fa68f30 | |
parent | 9123e24e7b68ad36d4ac2b8f325ea249a5ea9ff5 (diff) | |
download | spice-5341b632e2b1d2527303cce3f69a8146a8d48489.tar.gz spice-5341b632e2b1d2527303cce3f69a8146a8d48489.tar.xz spice-5341b632e2b1d2527303cce3f69a8146a8d48489.zip |
Support creating marshallers that are called indirectly
This is needed if we want to switch marshallers depending on what
major version the remote side has.
-rw-r--r-- | python_modules/marshal.py | 31 | ||||
-rwxr-xr-x | spice_codegen.py | 7 |
2 files changed, 30 insertions, 8 deletions
diff --git a/python_modules/marshal.py b/python_modules/marshal.py index 4cbf942d..4279cf0d 100644 --- a/python_modules/marshal.py +++ b/python_modules/marshal.py @@ -310,7 +310,7 @@ def write_container_marshaller(writer, container, src): writer.out_prefix = saved_out_prefix write_member_marshaller(writer, container, m, src, scope) -def write_message_marshaller(writer, message, is_server): +def write_message_marshaller(writer, message, is_server, private): writer.out_prefix = "" function_name = "spice_marshall_" + message.c_name() if writer.is_generated("marshaller", function_name): @@ -323,10 +323,11 @@ def write_message_marshaller(writer, message, is_server): n = map(lambda name: ", SpiceMarshaller **%s" % name, names) names_args = "".join(n) - writer.header.writeln("void " + function_name + "(SpiceMarshaller *m, %s *msg" % message.c_type() + names_args + ");") + if not private: + writer.header.writeln("void " + function_name + "(SpiceMarshaller *m, %s *msg" % message.c_type() + names_args + ");") scope = writer.function(function_name, - "void", + "static void" if private else "void", "SpiceMarshaller *m, %s *msg" % message.c_type() + names_args) scope.variable_def("SPICE_GNUC_UNUSED uint8_t *", "end") @@ -341,18 +342,36 @@ def write_message_marshaller(writer, message, is_server): writer.end_block() writer.newline() + return function_name -def write_protocol_marshaller(writer, proto, is_server): +def write_protocol_marshaller(writer, proto, is_server, private_marshallers): + functions = {} for c in proto.channels: channel = c.channel_type if is_server: for m in channel.client_messages: message = m.message_type - write_message_marshaller(writer, message, is_server) + f = write_message_marshaller(writer, message, is_server, private_marshallers) + functions[f] = True else: for m in channel.server_messages: message = m.message_type - write_message_marshaller(writer, message, is_server) + f= write_message_marshaller(writer, message, is_server, private_marshallers) + functions[f] = True + + if private_marshallers: + scope = writer.function("spice_message_marshallers_get", + "SpiceMessageMarshallers *", + "void") + writer.writeln("static SpiceMessageMarshallers marshallers = {NULL};").newline() + for f in sorted(functions.keys()): + member = f[len("spice_marshall_"):] + writer.assign("marshallers.%s" % member, f) + + writer.newline() + writer.statement("return &marshallers") + writer.end_block() + writer.newline() def write_trailer(writer): writer.header.writeln("#endif") diff --git a/spice_codegen.py b/spice_codegen.py index c8d0d5f2..00342500 100755 --- a/spice_codegen.py +++ b/spice_codegen.py @@ -86,6 +86,9 @@ parser.add_option("-d", "--generate-demarshallers", parser.add_option("-m", "--generate-marshallers", action="store_true", dest="generate_marshallers", default=False, help="Generate message marshallers") +parser.add_option("-P", "--private-marshallers", + action="store_true", dest="private_marshallers", default=False, + help="Generate private message marshallers") parser.add_option("-M", "--generate-struct-marshaller", action="append", dest="struct_marshallers", help="Generate struct marshallers") @@ -163,9 +166,9 @@ if options.generate_marshallers: print >> sys.stderr, "Must specify client and/or server" sys.exit(1) if options.server: - marshal.write_protocol_marshaller(writer, proto, False) + marshal.write_protocol_marshaller(writer, proto, False, options.private_marshallers) if options.client: - marshal.write_protocol_marshaller(writer, proto, True) + marshal.write_protocol_marshaller(writer, proto, True, options.private_marshallers) if options.struct_marshallers: for structname in options.struct_marshallers: |