[Spice-devel] [spice-common 4/5] codegen: Factor common is_server/is_client code

Frediano Ziglio fziglio at redhat.com
Fri Jun 24 08:53:25 UTC 2016


> 
> On Fri, Jun 24, 2016 at 04:04:36AM -0400, Frediano Ziglio wrote:
> >  
> > > Hi,
> > > 
> > > what will happen if both '--server' and '--client' are used on the
> > > commandline?
> > > Only client's will be generated ?
> > > 
> > > Pavel
> > > 
> > 
> > Agreed, form the comment on code and code looks like you can specify both
> > (client and server) to have both processed, from your comments looks like
> > you can't specify both.
> 
> Agreed too that it won't allow both to be specified, I'd say this does
> not make sense though, and that they should be mutually exclusive.
> But I don't mind dropping this patch.
> 
> Christophe
> 

Mumble mumble... I was actually looking at the code.
Looks like there can be only one destination file.
So what happen if client and server is generated at the same time?
Both code is written into a single file? Does it make sense?

Actually I did the test. A single C file with both client and server
code is generated which make sense.

Not clear if make sense to move the 

    if not options.server and not options.client:
        print >> sys.stderr, "Must specify client and/or server"
        sys.exit(1)

lines outside the two ifs.

Frediano

> > 
> > Frediano
> > 
> > > 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