[Spice-devel] [PATCH spice-common 2/4] codegen: Remove duplicate client and server code from ChannelType::resolve
Frediano Ziglio
fziglio at redhat.com
Wed May 16 15:34:55 UTC 2018
>
> On Mon, May 14, 2018 at 11:18:52PM +0100, Frediano Ziglio wrote:
> > Code that handled client and server messages check was the same, just
> > changed some variable names.
> > Instead use a class to store same information and reuse the code.
> > This allows easier extension of the 2 path of code.
> >
> > Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
> > ---
> > python_modules/ptypes.py | 66 +++++++++++++++++-----------------------
> > 1 file changed, 28 insertions(+), 38 deletions(-)
> >
> > diff --git a/python_modules/ptypes.py b/python_modules/ptypes.py
> > index 0f6d8d6..ef580aa 100644
> > --- a/python_modules/ptypes.py
> > +++ b/python_modules/ptypes.py
> > @@ -1024,53 +1024,43 @@ class ChannelType(Type):
> > if self.base != None:
> > self.base = self.base.resolve()
> >
> > - server_messages = self.base.server_messages[:]
> > - server_messages_byname =
> > self.base.server_messages_byname.copy()
> > - client_messages = self.base.client_messages[:]
> > - client_messages_byname =
> > self.base.client_messages_byname.copy()
> > -
> > # Set default member_name, FooChannel -> foo
> > self.member_name = self.name[:-7].lower()
> > - else:
> > - server_messages = []
> > - server_messages_byname = {}
> > - client_messages = []
> > - client_messages_byname = {}
> >
> > - server_count = 1
> > - client_count = 1
> > + class MessagesInfo:
> > + def __init__(self, base, is_server):
> > + self.is_server = is_server
> > + if base != None:
> > + kind = 'server' if is_server else 'client'
> > + self.messages = base.__dict__[kind + '_messages'][:]
> > + self.messages_byname = base.__dict__[kind +
> > '_messages_byname'].copy()
>
> Not a huge fan of __dict__[kind + 'xxx']. Maybe pass
> self.base.server_messages_byname/self.base.client_messages (or the
> server counterpart) to the constructor rather than a boolean?
>
Still need the boolean. Also self.base is not always a valid object so
you would end up moving the check outside the __init__.
I'll try to code that way.
> Apart from this, looks good to me.
>
> Christophe
>
Frediano
More information about the Spice-devel
mailing list