diff options
Diffstat (limited to 'nexgb/xgbgen/go_request_reply.go')
-rw-r--r-- | nexgb/xgbgen/go_request_reply.go | 84 |
1 files changed, 58 insertions, 26 deletions
diff --git a/nexgb/xgbgen/go_request_reply.go b/nexgb/xgbgen/go_request_reply.go index e6180a1..00c48f9 100644 --- a/nexgb/xgbgen/go_request_reply.go +++ b/nexgb/xgbgen/go_request_reply.go @@ -8,30 +8,51 @@ import ( func (r *Request) Define(c *Context) { c.Putln("// Request %s", r.SrcName()) c.Putln("// size: %s", r.Size(c)) + c.Putln("type %s cookie", r.CookieName()) if r.Reply != nil { - c.Putln("func (c *Conn) %s(%s) (*%s, error) {", - r.SrcName(), r.ParamNameTypes(), r.ReplyName()) - c.Putln("return c.%s(c.%s(%s))", - r.ReplyName(), r.ReqName(), r.ParamNames()) + c.Putln("func (c *Conn) %s(%s) %s {", + r.SrcName(), r.ParamNameTypes(), r.CookieName()) + c.Putln("cookie := c.newCookie(true, true)") + c.Putln("c.newRequest(%s(%s), cookie)", r.ReqName(), r.ParamNames()) + c.Putln("return %s(cookie)", r.CookieName()) + c.Putln("}") + c.Putln("") + + c.Putln("func (c *Conn) %sUnchecked(%s) %s {", + r.SrcName(), r.ParamNameTypes(), r.CookieName()) + c.Putln("cookie := c.newCookie(false, true)") + c.Putln("c.newRequest(%s(%s), cookie)", r.ReqName(), r.ParamNames()) + c.Putln("return %s(cookie)", r.CookieName()) c.Putln("}") c.Putln("") - r.WriteRequest(c) r.ReadReply(c) } else { c.Putln("// Write request to wire for %s", r.SrcName()) - c.Putln("func (c *Conn) %s(%s) {", r.SrcName(), r.ParamNameTypes()) - r.WriteRequestFields(c) - c.Putln("c.sendRequest(false, buf)") + c.Putln("func (c *Conn) %s(%s) %s {", + r.SrcName(), r.ParamNameTypes(), r.CookieName()) + c.Putln("cookie := c.newCookie(false, false)") + c.Putln("c.newRequest(%s(%s), cookie)", r.ReqName(), r.ParamNames()) + c.Putln("return %s(cookie)", r.CookieName()) + c.Putln("}") + c.Putln("") + + c.Putln("func (c *Conn) %sChecked(%s) %s {", + r.SrcName(), r.ParamNameTypes(), r.CookieName()) + c.Putln("cookie := c.newCookie(true, false)") + c.Putln("c.newRequest(%s(%s), cookie)", r.ReqName(), r.ParamNames()) + c.Putln("return %s(cookie)", r.CookieName()) c.Putln("}") c.Putln("") } + + r.WriteRequest(c) } func (r *Request) ReadReply(c *Context) { c.Putln("// Request reply for %s", r.SrcName()) c.Putln("// size: %s", r.Reply.Size()) - c.Putln("type %s struct {", r.ReplyName()) + c.Putln("type %s struct {", r.ReplyTypeName()) c.Putln("Sequence uint16") c.Putln("Length uint32") for _, field := range r.Reply.Fields { @@ -40,15 +61,21 @@ func (r *Request) ReadReply(c *Context) { c.Putln("}") c.Putln("") - c.Putln("// Read reply %s", r.SrcName()) - c.Putln("func (c *Conn) %s(cook *Cookie) (*%s, error) {", - r.ReplyName(), r.ReplyName()) - c.Putln("buf, err := c.waitForReply(cook)") - c.Putln("if err != nil {") - c.Putln("return nil, err") + c.Putln("// Waits and reads reply data from request %s", r.SrcName()) + c.Putln("func (cook %s) Reply() (*%s, error) {", + r.CookieName(), r.ReplyTypeName()) + c.Putln("buf, err := cookie(cook).reply()") + c.Putln("if err != nil {") + c.Putln("return nil, err") + c.Putln("}") + c.Putln("return %s(buf), nil", r.ReplyName()) c.Putln("}") c.Putln("") - c.Putln("v := new(%s)", r.ReplyName()) + + c.Putln("// Read reply into structure from buffer for %s", r.SrcName()) + c.Putln("func %s(buf []byte) *%s {", + r.ReplyName(), r.ReplyTypeName()) + c.Putln("v := new(%s)", r.ReplyTypeName()) c.Putln("b := 1 // skip reply determinant") c.Putln("") for i, field := range r.Reply.Fields { @@ -63,21 +90,14 @@ func (r *Request) ReadReply(c *Context) { field.Read(c, "v.") c.Putln("") } - c.Putln("return v, nil") + c.Putln("return v") c.Putln("}") c.Putln("") } func (r *Request) WriteRequest(c *Context) { c.Putln("// Write request to wire for %s", r.SrcName()) - c.Putln("func (c *Conn) %s(%s) *Cookie {", r.ReqName(), r.ParamNameTypes()) - r.WriteRequestFields(c) - c.Putln("return c.sendRequest(true, buf)") - c.Putln("}") - c.Putln("") -} - -func (r *Request) WriteRequestFields(c *Context) { + c.Putln("func %s(%s) []byte {", r.ReqName(), r.ParamNameTypes()) c.Putln("size := %s", r.Size(c)) c.Putln("b := 0") c.Putln("buf := make([]byte, size)") @@ -85,6 +105,12 @@ func (r *Request) WriteRequestFields(c *Context) { c.Putln("buf[b] = %d // request opcode", r.Opcode) c.Putln("b += 1") c.Putln("") + if strings.ToLower(c.protocol.Name) != "xproto" { + c.Putln("buf[b] = c.extensions[\"%s\"]", + strings.ToUpper(c.protocol.ExtXName)) + c.Putln("b += 1") + c.Putln("") + } for i, field := range r.Fields { if i == 1 { c.Putln("Put16(buf[b:], uint16(size / 4)) "+ @@ -95,6 +121,9 @@ func (r *Request) WriteRequestFields(c *Context) { field.Write(c, "") c.Putln("") } + c.Putln("return buf") + c.Putln("}") + c.Putln("") } func (r *Request) ParamNames() string { @@ -102,7 +131,10 @@ func (r *Request) ParamNames() string { for _, field := range r.Fields { switch f := field.(type) { case *ValueField: - names = append(names, f.MaskName) + // mofos... + if r.SrcName() != "ConfigureWindow" { + names = append(names, f.MaskName) + } names = append(names, f.ListName) case *PadField: continue |