[Xcb] [PATCH 3/6] Add support for file descriptor request fields

Daniel Martin consume.noise at gmail.com
Thu Nov 7 09:38:33 PST 2013


On Tue, Nov 05, 2013 at 04:39:03PM -0800, Keith Packard wrote:
> These are present in the API, but not present on the wire.
> 
> Signed-off-by: Keith Packard <keithp at keithp.com>
> ---
>  xcbgen/expr.py   |  3 ++-
>  xcbgen/xtypes.py | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
>  2 files changed, 59 insertions(+), 2 deletions(-)
> 
> diff --git a/xcbgen/expr.py b/xcbgen/expr.py
> index 4f8af6f..f9d5179 100644
> --- a/xcbgen/expr.py
> +++ b/xcbgen/expr.py
> @@ -13,7 +13,7 @@ class Field(object):
>      auto is true iff the field is on the wire but not in the request API (e.g. opcode)
>      enum is the enum name this field refers to, if any.
>      '''
> -    def __init__(self, type, field_type, field_name, visible, wire, auto, enum=None):
> +    def __init__(self, type, field_type, field_name, visible, wire, auto, enum=None, isfd=False):
>          self.type = type
>          self.field_type = field_type
>          self.field_name = field_name
> @@ -21,6 +21,7 @@ class Field(object):
>          self.visible = visible
>          self.wire = wire
>          self.auto = auto
> +        self.isfd = isfd
>  
>  
>  class Expression(object):
> diff --git a/xcbgen/xtypes.py b/xcbgen/xtypes.py
> index 5012f0b..d007635 100644
> --- a/xcbgen/xtypes.py
> +++ b/xcbgen/xtypes.py
> @@ -75,6 +75,18 @@ class Type(object):
>  
>          complex_type.fields.append(new_field)
>  
> +    def make_fd_of(self, module, complex_type, fd_name):
> +    	'''

Here's a tab, which isn't a problem for python 2.7. But, with 3.3
c_client.py fails with it:
    ...
    TabError: inconsistent use of tabs and spaces in indentation

> +        Method for making a fd member of a structure.
> +        '''
> +        new_fd = Field(self, module.get_type_name('INT32'), fd_name, True, False, False, None, True)
> +        # We dump the _placeholder_byte if any fields are added.
> +        for (idx, field) in enumerate(complex_type.fields):
> +            if field == _placeholder_byte:
> +                complex_type.fields[idx] = new_fd
> +                return
> +
> +        complex_type.fields.append(new_fd)
>  
>  class SimpleType(Type):
>      '''
> @@ -152,6 +164,44 @@ class Enum(SimpleType):
>      out = __main__.output['enum']
>  
>  
> +class FileDescriptor(SimpleType):
> +    '''
> +    Derived class which represents a file descriptor. Passed via magic kernel stuff
> +
> +    Public fields added:
> +    values contains a list of (name, value) tuples.  value is empty, or a number.
> +    bits contains a list of (name, bitnum) tuples.  items only appear if specified as a bit. bitnum is a number.
> +    '''
> +    def __init__(self, name, elt):
> +        SimpleType.__init__(self, name, 4)
> +        self.values = []
> +        self.bits = []
> +        self.doc = None
> +        for item in list(elt):
> +            if item.tag == 'doc':
> +                self.doc = Doc(name, item)
> +
> +            # First check if we're using a default value
> +            if len(list(item)) == 0:
> +                self.values.append((item.get('name'), ''))
> +                continue
> +
> +            # An explicit value or bit was specified.
> +            value = list(item)[0]
> +            if value.tag == 'value':
> +                self.values.append((item.get('name'), value.text))
> +            elif value.tag == 'bit':
> +                self.values.append((item.get('name'), '%u' % (1 << int(value.text, 0))))
> +                self.bits.append((item.get('name'), value.text))
> +
> +    def resolve(self, module):
> +        self.resolved = True
> +
> +    def fixed_size(self):
> +        return True
> +
> +    out = __main__.output['enum']
> +    
>  class ListType(Type):
>      '''
>      Derived class which represents a list of some other datatype.  Fixed- or variable-sized.
> @@ -279,6 +329,7 @@ class ComplexType(Type):
>          self.nmemb = 1
>          self.size = 0
>          self.lenfield_parent = [self]
> +        self.fds = []
>  
>      def resolve(self, module):
>          if self.resolved:
> @@ -324,9 +375,14 @@ class ComplexType(Type):
>                  type.make_member_of(module, self, field_type, field_name, visible, True, False)
>                  type.resolve(module)
>                  continue
> +            elif child.tag == 'fd':
> +                fd_name = child.get('name')
> +                type = module.get_type('INT32')
> +                type.make_fd_of(module, self, fd_name)
> +                continue
>              else:
>                  # Hit this on Reply
> -                continue 
> +                continue
>  
>              # Get the full type name for the field
>              field_type = module.get_type_name(fkey)
> -- 
> 1.8.4.2
> 
> _______________________________________________
> xorg-devel at lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: http://lists.x.org/mailman/listinfo/xorg-devel


More information about the Xcb mailing list