Monday, December 24, 2018

Mappingthe xcb functions

We like:

NewConn myconn;
NewWindow mywin myconn; // Standard linux command
StrOut mywin "Hello World" 1,2; // write text at char positions 1,2

The tokens, mywin and myconn have become symbol entries in Xchars, which has a simple and fast symbol table.  There exists a mechanical map that unfolds the script request into xcb calls, correctly. It can be constructed automatically, and I experimented with it.  I know how to defeat the gcc warning machine.   The symbol entry mywin points me to  a map and a connection. The map correctly constructs the call as:

PolyFill mypoly:  // becomes:

arg[0].polyfill(arg[1].conn,arg[2].drawable,arg[3].gc,i,arg[4].rect);

Say What? A text processing machine takes the proto.h file from xcb and creates these forms using unions. So the interface to xcb knows nothing except how to select argument types from a map. Most of the precmpile text processing can be cut paste and replace in a text editor.

I have sample typedefs doing this below the fold.  The text processing machine adds to the union and identifies the union selector. The c code all automatically generated, when said and done. The process drivenby the symbol table entries and precompiled mappings.



typedef  xcb_void_cookie_t PolyFill(
xcb_connection_t*,
xcb_drawable_t,
xcb_gcontext_t,
uint32_t,
const xcb_rectangle_t *);
typedef xcb_void_cookie_t ChangeGC(
xcb_connection_t *,
xcb_gcontext_t    ,
uint32_t    ,
      const uint32_t *);
  typedef union {
ChangeGC * change_gc;
PolyFill* polyfill;
void * cmd;
xcb_connection_t * conn;
xcb_window_t win;
xcb_gcontext_t gc;
xcb_font_t  font;
xcb_void_cookie_t cookie;
xcb_drawable_t drawable;
xcb_rectangle_t* rect;
} Val;

No comments: