[Spice-devel] [spice-common 4/5] codegen: Factor common is_server/is_client code
Pavel Grunt
pgrunt at redhat.com
Thu Jun 23 12:37:02 UTC 2016
Hi,
what will happen if both '--server' and '--client' are used on the commandline?
Only client's will be generated ?
Pavel
On Thu, 2016-06-23 at 12:57 +0200, Christophe Fergeau wrote:
> We currently have 2 very similar codepaths in the marshaller and
> demarshaller cases which check whether we are building client or server
> code, error out if we specified neither on the command line and then
> they call the same function with True or False for client/server.
>
> We can factor this code a little bit to make things a bit simpler.
> ---
> spice_codegen.py | 26 +++++++++++---------------
> 1 file changed, 11 insertions(+), 15 deletions(-)
>
> diff --git a/spice_codegen.py b/spice_codegen.py
> index 410acbd..e1aab3a 100755
> --- a/spice_codegen.py
> +++ b/spice_codegen.py
> @@ -217,28 +217,24 @@ if options.includes:
> if options.generate_enums or options.generate_dissector:
> write_enums(writer, options.generate_dissector)
>
> +if not options.server and not options.client:
> + print >> sys.stderr, "Must specify client and/or server"
> + sys.exit(1)
> +
> +if options.client:
> + is_client = True
> +else:
> + is_client = False
> +
> if options.generate_demarshallers:
> - if not options.server and not options.client:
> - print >> sys.stderr, "Must specify client and/or server"
> - sys.exit(1)
> demarshal.write_includes(writer)
> -
> - if options.server:
> - demarshal.write_protocol_parser(writer, proto, False)
> - if options.client:
> - demarshal.write_protocol_parser(writer, proto, True)
> + demarshal.write_protocol_parser(writer, proto, is_client)
>
> if options.generate_marshallers or (options.struct_marshallers and
> len(options.struct_marshallers) > 0):
> marshal.write_includes(writer)
>
> if options.generate_marshallers:
> - if not options.server and not options.client:
> - print >> sys.stderr, "Must specify client and/or server"
> - sys.exit(1)
> - if options.server:
> - marshal.write_protocol_marshaller(writer, proto, False,
> options.private_marshallers)
> - if options.client:
> - marshal.write_protocol_marshaller(writer, proto, True,
> options.private_marshallers)
> + marshal.write_protocol_marshaller(writer, proto, is_client,
> options.private_marshallers)
>
> if options.struct_marshallers:
> for structname in options.struct_marshallers:
More information about the Spice-devel
mailing list