converting to new reply/cookie scheme
This commit is contained in:
parent
a5d4ad6c9d
commit
c222d406b0
|
@ -158,6 +158,33 @@ func (e *UnaryOp) Initialize(p *Protocol) {
|
||||||
e.Expr.Initialize(p)
|
e.Expr.Initialize(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Padding struct {
|
||||||
|
Expr Expression
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *Padding) Concrete() bool {
|
||||||
|
return e.Expr.Concrete()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *Padding) Eval() uint {
|
||||||
|
return uint(pad(int(e.Expr.Eval())))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *Padding) Reduce(prefix string) string {
|
||||||
|
if e.Concrete() {
|
||||||
|
return fmt.Sprintf("%d", e.Eval())
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("pad(%s)", e.Expr.Reduce(prefix))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *Padding) String() string {
|
||||||
|
return e.Reduce("")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *Padding) Initialize(p *Protocol) {
|
||||||
|
e.Expr.Initialize(p)
|
||||||
|
}
|
||||||
|
|
||||||
type PopCount struct {
|
type PopCount struct {
|
||||||
Expr Expression
|
Expr Expression
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,14 @@ func (e *Event) Define(c *Context) {
|
||||||
// Makes sure that this event type is an Event interface.
|
// Makes sure that this event type is an Event interface.
|
||||||
c.Putln("func (v %s) ImplementsEvent() { }", e.EvType())
|
c.Putln("func (v %s) ImplementsEvent() { }", e.EvType())
|
||||||
c.Putln("")
|
c.Putln("")
|
||||||
|
c.Putln("func (v %s) SequenceId() uint16 {", e.EvType())
|
||||||
|
if e.NoSequence {
|
||||||
|
c.Putln("return uint16(0)")
|
||||||
|
} else {
|
||||||
|
c.Putln("return v.Sequence")
|
||||||
|
}
|
||||||
|
c.Putln("}")
|
||||||
|
c.Putln("")
|
||||||
|
|
||||||
// Let's the XGB event loop read this event.
|
// Let's the XGB event loop read this event.
|
||||||
c.Putln("func init() {")
|
c.Putln("func init() {")
|
||||||
|
@ -99,6 +107,14 @@ func (e *EventCopy) Define(c *Context) {
|
||||||
// Makes sure that this event type is an Event interface.
|
// Makes sure that this event type is an Event interface.
|
||||||
c.Putln("func (v %s) ImplementsEvent() { }", e.EvType())
|
c.Putln("func (v %s) ImplementsEvent() { }", e.EvType())
|
||||||
c.Putln("")
|
c.Putln("")
|
||||||
|
c.Putln("func (v %s) SequenceId() uint16 {", e.EvType())
|
||||||
|
if e.Old.(*Event).NoSequence {
|
||||||
|
c.Putln("return uint16(0)")
|
||||||
|
} else {
|
||||||
|
c.Putln("return v.Sequence")
|
||||||
|
}
|
||||||
|
c.Putln("}")
|
||||||
|
c.Putln("")
|
||||||
|
|
||||||
// Let's the XGB event loop read this event.
|
// Let's the XGB event loop read this event.
|
||||||
c.Putln("func init() {")
|
c.Putln("func init() {")
|
||||||
|
|
|
@ -8,30 +8,51 @@ import (
|
||||||
func (r *Request) Define(c *Context) {
|
func (r *Request) Define(c *Context) {
|
||||||
c.Putln("// Request %s", r.SrcName())
|
c.Putln("// Request %s", r.SrcName())
|
||||||
c.Putln("// size: %s", r.Size(c))
|
c.Putln("// size: %s", r.Size(c))
|
||||||
|
c.Putln("type %s cookie", r.CookieName())
|
||||||
if r.Reply != nil {
|
if r.Reply != nil {
|
||||||
c.Putln("func (c *Conn) %s(%s) (*%s, error) {",
|
c.Putln("func (c *Conn) %s(%s) %s {",
|
||||||
r.SrcName(), r.ParamNameTypes(), r.ReplyName())
|
r.SrcName(), r.ParamNameTypes(), r.CookieName())
|
||||||
c.Putln("return c.%s(c.%s(%s))",
|
c.Putln("cookie := c.newCookie(true, true)")
|
||||||
r.ReplyName(), r.ReqName(), r.ParamNames())
|
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("}")
|
||||||
c.Putln("")
|
c.Putln("")
|
||||||
|
|
||||||
r.WriteRequest(c)
|
|
||||||
r.ReadReply(c)
|
r.ReadReply(c)
|
||||||
} else {
|
} else {
|
||||||
c.Putln("// Write request to wire for %s", r.SrcName())
|
c.Putln("// Write request to wire for %s", r.SrcName())
|
||||||
c.Putln("func (c *Conn) %s(%s) {", r.SrcName(), r.ParamNameTypes())
|
c.Putln("func (c *Conn) %s(%s) %s {",
|
||||||
r.WriteRequestFields(c)
|
r.SrcName(), r.ParamNameTypes(), r.CookieName())
|
||||||
c.Putln("c.sendRequest(false, buf)")
|
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("}")
|
||||||
c.Putln("")
|
c.Putln("")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
r.WriteRequest(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Request) ReadReply(c *Context) {
|
func (r *Request) ReadReply(c *Context) {
|
||||||
c.Putln("// Request reply for %s", r.SrcName())
|
c.Putln("// Request reply for %s", r.SrcName())
|
||||||
c.Putln("// size: %s", r.Reply.Size())
|
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("Sequence uint16")
|
||||||
c.Putln("Length uint32")
|
c.Putln("Length uint32")
|
||||||
for _, field := range r.Reply.Fields {
|
for _, field := range r.Reply.Fields {
|
||||||
|
@ -40,15 +61,21 @@ func (r *Request) ReadReply(c *Context) {
|
||||||
c.Putln("}")
|
c.Putln("}")
|
||||||
c.Putln("")
|
c.Putln("")
|
||||||
|
|
||||||
c.Putln("// Read reply %s", r.SrcName())
|
c.Putln("// Waits and reads reply data from request %s", r.SrcName())
|
||||||
c.Putln("func (c *Conn) %s(cook *Cookie) (*%s, error) {",
|
c.Putln("func (cook %s) Reply() (*%s, error) {",
|
||||||
r.ReplyName(), r.ReplyName())
|
r.CookieName(), r.ReplyTypeName())
|
||||||
c.Putln("buf, err := c.waitForReply(cook)")
|
c.Putln("buf, err := cookie(cook).reply()")
|
||||||
c.Putln("if err != nil {")
|
c.Putln("if err != nil {")
|
||||||
c.Putln("return nil, err")
|
c.Putln("return nil, err")
|
||||||
|
c.Putln("}")
|
||||||
|
c.Putln("return %s(buf), nil", r.ReplyName())
|
||||||
c.Putln("}")
|
c.Putln("}")
|
||||||
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("b := 1 // skip reply determinant")
|
||||||
c.Putln("")
|
c.Putln("")
|
||||||
for i, field := range r.Reply.Fields {
|
for i, field := range r.Reply.Fields {
|
||||||
|
@ -63,21 +90,14 @@ func (r *Request) ReadReply(c *Context) {
|
||||||
field.Read(c, "v.")
|
field.Read(c, "v.")
|
||||||
c.Putln("")
|
c.Putln("")
|
||||||
}
|
}
|
||||||
c.Putln("return v, nil")
|
c.Putln("return v")
|
||||||
c.Putln("}")
|
c.Putln("}")
|
||||||
c.Putln("")
|
c.Putln("")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Request) WriteRequest(c *Context) {
|
func (r *Request) WriteRequest(c *Context) {
|
||||||
c.Putln("// Write request to wire for %s", r.SrcName())
|
c.Putln("// Write request to wire for %s", r.SrcName())
|
||||||
c.Putln("func (c *Conn) %s(%s) *Cookie {", r.ReqName(), r.ParamNameTypes())
|
c.Putln("func %s(%s) []byte {", 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("size := %s", r.Size(c))
|
c.Putln("size := %s", r.Size(c))
|
||||||
c.Putln("b := 0")
|
c.Putln("b := 0")
|
||||||
c.Putln("buf := make([]byte, size)")
|
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("buf[b] = %d // request opcode", r.Opcode)
|
||||||
c.Putln("b += 1")
|
c.Putln("b += 1")
|
||||||
c.Putln("")
|
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 {
|
for i, field := range r.Fields {
|
||||||
if i == 1 {
|
if i == 1 {
|
||||||
c.Putln("Put16(buf[b:], uint16(size / 4)) "+
|
c.Putln("Put16(buf[b:], uint16(size / 4)) "+
|
||||||
|
@ -95,6 +121,9 @@ func (r *Request) WriteRequestFields(c *Context) {
|
||||||
field.Write(c, "")
|
field.Write(c, "")
|
||||||
c.Putln("")
|
c.Putln("")
|
||||||
}
|
}
|
||||||
|
c.Putln("return buf")
|
||||||
|
c.Putln("}")
|
||||||
|
c.Putln("")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Request) ParamNames() string {
|
func (r *Request) ParamNames() string {
|
||||||
|
@ -102,7 +131,10 @@ func (r *Request) ParamNames() string {
|
||||||
for _, field := range r.Fields {
|
for _, field := range r.Fields {
|
||||||
switch f := field.(type) {
|
switch f := field.(type) {
|
||||||
case *ValueField:
|
case *ValueField:
|
||||||
names = append(names, f.MaskName)
|
// mofos...
|
||||||
|
if r.SrcName() != "ConfigureWindow" {
|
||||||
|
names = append(names, f.MaskName)
|
||||||
|
}
|
||||||
names = append(names, f.ListName)
|
names = append(names, f.ListName)
|
||||||
case *PadField:
|
case *PadField:
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"unicode"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Protocol struct {
|
type Protocol struct {
|
||||||
|
@ -58,6 +59,16 @@ func (r *Request) XmlName() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Request) ReplyName() string {
|
func (r *Request) ReplyName() string {
|
||||||
|
if r.Reply == nil {
|
||||||
|
log.Panicf("Cannot call 'ReplyName' on request %s, which has no reply.",
|
||||||
|
r.SrcName())
|
||||||
|
}
|
||||||
|
name := r.SrcName()
|
||||||
|
lower := string(unicode.ToLower(rune(name[0]))) + name[1:]
|
||||||
|
return fmt.Sprintf("%sReply", lower)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Request) ReplyTypeName() string {
|
||||||
if r.Reply == nil {
|
if r.Reply == nil {
|
||||||
log.Panicf("Cannot call 'ReplyName' on request %s, which has no reply.",
|
log.Panicf("Cannot call 'ReplyName' on request %s, which has no reply.",
|
||||||
r.SrcName())
|
r.SrcName())
|
||||||
|
@ -66,7 +77,13 @@ func (r *Request) ReplyName() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Request) ReqName() string {
|
func (r *Request) ReqName() string {
|
||||||
return fmt.Sprintf("%sRequest", r.SrcName())
|
name := r.SrcName()
|
||||||
|
lower := string(unicode.ToLower(rune(name[0]))) + name[1:]
|
||||||
|
return fmt.Sprintf("%sRequest", lower)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Request) CookieName() string {
|
||||||
|
return fmt.Sprintf("%sCookie", r.SrcName())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Size for Request needs a context.
|
// Size for Request needs a context.
|
||||||
|
@ -99,7 +116,9 @@ func (r *Request) Size(c *Context) Size {
|
||||||
size = size.Add(field.Size())
|
size = size.Add(field.Size())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return size
|
return newExpressionSize(&Padding{
|
||||||
|
Expr: size.Expression,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
type Reply struct {
|
type Reply struct {
|
||||||
|
|
Loading…
Reference in New Issue