[Xcb] C code mapping of <switch>

Christoph Reimann chrr at arcor.de
Sat Jun 5 00:47:57 PDT 2010


Hi once more,
this is closely related to the mail I just send, so you might want to
read that first.
Peter Harris advised me to change a valueparam to switch so I could
study the semantics - also one could possibly autogenerate parts of
xcb_aux in the util module directly from xml.
So in case of xproto's CreateWindow one gets a quite lengthy switch
statement (see below at the end) and I currently have changed
c_client.py to produce the following C code for this:

typedef struct xcb_create_window_value_list_t {
    xcb_pixmap_t   background_pixmap; /**<  */
    uint32_t       background_pixel; /**<  */
    xcb_pixmap_t   border_pixmap; /**<  */
    uint32_t       border_pixel; /**<  */
    uint32_t       bit_gravity; /**<  */
    uint32_t       win_gravity; /**<  */
    uint32_t       backing_store; /**<  */
    uint32_t       backing_planes; /**<  */
    uint32_t       backing_pixel; /**<  */
    uint32_t       override_redirect; /**<  */
    uint32_t       save_under; /**<  */
    uint32_t       event_mask; /**<  */
    uint32_t       dont_propagate; /**<  */
    xcb_colormap_t colormap; /**<  */
    xcb_cursor_t   cursor; /**<  */
} xcb_create_window_value_list_t;

which looks a lot like xcb_params_cw_t I admit :)
But with this struct autogenerated the request function can be changed
as well (in fact for <switch> to be generic it has to be as not all
switches can be mapped to a list of uint32_t):

xcb_create_window_checked (xcb_connection_t               *c  /**< */,
                           uint8_t                         depth  /**< */,
                           xcb_window_t                    wid  /**< */,
                           xcb_window_t                    parent  /**< */,
                           int16_t                         x  /**< */,
                           int16_t                         y  /**< */,
                           uint16_t                        width  /**< */,
                           uint16_t                        height  /**< */,
                           uint16_t
border_width  /**< */,
                           uint16_t                        _class  /**< */,
                           xcb_visualid_t                  visual  /**< */,
                           uint32_t                        value_mask  /**< */,
                           xcb_create_window_value_list_t  value_list  /**< */);

This, again, looks a lot like xcb_aux_create_window.
Last I would like to serialize switch element-wise (see my other
mail), i.e. generate as many if statements as there are fields in
xcb_create_window_value_list_t and send only those struct fields on
the wire where value_mask  indicates it, in pseudo-code for
fixed-sized bitcase fields:

if ((switch_mask & bitcase_mask) == bitcase_mask) {
    xcb_parts[index].iov_base = (char *) &value_list.bitcase_field;
    xcb_parts[index].iov_len  = sizeof(bitcase_field_type);
    index++;
}

I am glad for any comments, please note that I would only like to test
switch at this stage, so this is not necessarily a proposal to replace
all valueparams with it (especially as the API would change).

Have a nice weekend,
Christoph


<switch> version of CreateWindow's valueparam:

    <switch name="value_list">
      <fieldref>value_mask</fieldref>
      <bitcase>
        <enumref ref="CW">BackPixmap</enumref>
        <field name="background_pixmap" type="PIXMAP" altenum="BackPixmap" />
      </bitcase>
      <bitcase>
        <enumref ref="CW">BackPixel</enumref>
        <field name="background_pixel" type="CARD32" />
      </bitcase>
      <bitcase>
        <enumref ref="CW">BorderPixmap</enumref>
        <field name="border_pixmap" type="PIXMAP" altenum="BorderPixmap" />
      </bitcase>
      <bitcase>
        <enumref ref="CW">BorderPixel</enumref>
        <field name="border_pixel" type="CARD32" />
      </bitcase>
      <bitcase>
        <enumref ref="CW">BitGravity</enumref>
        <field name="bit_gravity" type="CARD32" enum="Gravity" />
      </bitcase>
      <bitcase>
        <enumref ref="CW">WinGravity</enumref>
        <field name="win_gravity" type="CARD32" enum="Gravity" />
      </bitcase>
      <bitcase>
        <enumref ref="CW">BackingStore</enumref>
        <field name="backing_store" type="CARD32" enum="BackingStore" />
      </bitcase>
      <bitcase>
        <enumref ref="CW">BackingPlanes</enumref>
        <field name="backing_planes" type="CARD32" />
      </bitcase>
      <bitcase>
        <enumref ref="CW">BackingPixel</enumref>
        <field name="backing_pixel" type="CARD32" />
      </bitcase>
      <bitcase>
        <enumref ref="CW">OverrideRedirect</enumref>
        <field name="override_redirect" type="CARD32" />
      </bitcase>
      <bitcase>
        <enumref ref="CW">SaveUnder</enumref>
        <field name="save_under" type="CARD32" />
      </bitcase>
      <bitcase>
        <enumref ref="CW">EventMask</enumref>
        <field name="event_mask" type="CARD32" enum="EventMask" />
      </bitcase>
      <bitcase>
        <enumref ref="CW">DontPropagate</enumref>
        <field name="dont_propagate" type="CARD32" enum="EventMask" />
      </bitcase>
      <bitcase>
        <enumref ref="CW">Colormap</enumref>
        <field name="colormap" type="COLORMAP" altenum="ColorMap" />
      </bitcase>
      <bitcase>
        <enumref ref="CW">Cursor</enumref>
        <field name="cursor" type="CURSOR" altenum="Cursor" />
      </bitcase>
    </switch>


More information about the Xcb mailing list