Re: [PATCH spice-common 2/4] codegen: Remove duplicate client and server code from ChannelType::resolve

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
> ---
>  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?

Apart from this, looks good to me.

Christophe

Attachment: signature.asc
Description: PGP signature

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel

[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]