From 0c50dc6241fa21712e041cfa2bfb9db4ccaef10a Mon Sep 17 00:00:00 2001 From: "Andrew Gallant (Ocelot)" Date: Thu, 10 May 2012 17:01:42 -0400 Subject: a huge commit. splitting extensions into their own sub-packages. --- nexgb/record/record.go | 1089 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1089 insertions(+) create mode 100644 nexgb/record/record.go (limited to 'nexgb/record/record.go') diff --git a/nexgb/record/record.go b/nexgb/record/record.go new file mode 100644 index 0000000..04d514b --- /dev/null +++ b/nexgb/record/record.go @@ -0,0 +1,1089 @@ +package record + +/* + This file was generated by record.xml on May 10 2012 4:20:28pm EDT. + This file is automatically generated. Edit at your peril! +*/ + +import ( + "github.com/BurntSushi/xgb" + + "github.com/BurntSushi/xgb/xproto" +) + +// Init must be called before using the RECORD extension. +func Init(c *xgb.Conn) error { + reply, err := xproto.QueryExtension(c, 6, "RECORD").Reply() + switch { + case err != nil: + return err + case !reply.Present: + return xgb.Errorf("No extension named RECORD could be found on on the server.") + } + + xgb.ExtLock.Lock() + c.Extensions["RECORD"] = reply.MajorOpcode + for evNum, fun := range xgb.NewExtEventFuncs["RECORD"] { + xgb.NewEventFuncs[int(reply.FirstEvent)+evNum] = fun + } + for errNum, fun := range xgb.NewExtErrorFuncs["RECORD"] { + xgb.NewErrorFuncs[int(reply.FirstError)+errNum] = fun + } + xgb.ExtLock.Unlock() + + return nil +} + +func init() { + xgb.NewExtEventFuncs["RECORD"] = make(map[int]xgb.NewEventFun) + xgb.NewExtErrorFuncs["RECORD"] = make(map[int]xgb.NewErrorFun) +} + +// Skipping definition for base type 'Int16' + +// Skipping definition for base type 'Int32' + +// Skipping definition for base type 'Void' + +// Skipping definition for base type 'Byte' + +// Skipping definition for base type 'Int8' + +// Skipping definition for base type 'Card16' + +// Skipping definition for base type 'Char' + +// Skipping definition for base type 'Card32' + +// Skipping definition for base type 'Double' + +// Skipping definition for base type 'Bool' + +// Skipping definition for base type 'Float' + +// Skipping definition for base type 'Card8' + +const ( + HTypeFromServerTime = 1 + HTypeFromClientTime = 2 + HTypeFromClientSequence = 4 +) + +const ( + CsCurrentClients = 1 + CsFutureClients = 2 + CsAllClients = 3 +) + +type Context uint32 + +func NewContextId(c *xgb.Conn) (Context, error) { + id, err := c.NewId() + if err != nil { + return 0, err + } + return Context(id), nil +} + +type ElementHeader byte + +type ClientSpec uint32 + +// 'Range8' struct definition +// Size: 2 +type Range8 struct { + First byte + Last byte +} + +// Struct read Range8 +func Range8Read(buf []byte, v *Range8) int { + b := 0 + + v.First = buf[b] + b += 1 + + v.Last = buf[b] + b += 1 + + return b +} + +// Struct list read Range8 +func Range8ReadList(buf []byte, dest []Range8) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = Range8{} + b += Range8Read(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Struct write Range8 +func (v Range8) Bytes() []byte { + buf := make([]byte, 2) + b := 0 + + buf[b] = v.First + b += 1 + + buf[b] = v.Last + b += 1 + + return buf +} + +// Write struct list Range8 +func Range8ListBytes(buf []byte, list []Range8) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += xgb.Pad(len(structBytes)) + } + return b +} + +// 'Range16' struct definition +// Size: 4 +type Range16 struct { + First uint16 + Last uint16 +} + +// Struct read Range16 +func Range16Read(buf []byte, v *Range16) int { + b := 0 + + v.First = xgb.Get16(buf[b:]) + b += 2 + + v.Last = xgb.Get16(buf[b:]) + b += 2 + + return b +} + +// Struct list read Range16 +func Range16ReadList(buf []byte, dest []Range16) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = Range16{} + b += Range16Read(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Struct write Range16 +func (v Range16) Bytes() []byte { + buf := make([]byte, 4) + b := 0 + + xgb.Put16(buf[b:], v.First) + b += 2 + + xgb.Put16(buf[b:], v.Last) + b += 2 + + return buf +} + +// Write struct list Range16 +func Range16ListBytes(buf []byte, list []Range16) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += xgb.Pad(len(structBytes)) + } + return b +} + +// 'ExtRange' struct definition +// Size: 6 +type ExtRange struct { + Major Range8 + Minor Range16 +} + +// Struct read ExtRange +func ExtRangeRead(buf []byte, v *ExtRange) int { + b := 0 + + v.Major = Range8{} + b += Range8Read(buf[b:], &v.Major) + + v.Minor = Range16{} + b += Range16Read(buf[b:], &v.Minor) + + return b +} + +// Struct list read ExtRange +func ExtRangeReadList(buf []byte, dest []ExtRange) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = ExtRange{} + b += ExtRangeRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Struct write ExtRange +func (v ExtRange) Bytes() []byte { + buf := make([]byte, 6) + b := 0 + + { + structBytes := v.Major.Bytes() + copy(buf[b:], structBytes) + b += xgb.Pad(len(structBytes)) + } + + { + structBytes := v.Minor.Bytes() + copy(buf[b:], structBytes) + b += xgb.Pad(len(structBytes)) + } + + return buf +} + +// Write struct list ExtRange +func ExtRangeListBytes(buf []byte, list []ExtRange) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += xgb.Pad(len(structBytes)) + } + return b +} + +// 'Range' struct definition +// Size: 24 +type Range struct { + CoreRequests Range8 + CoreReplies Range8 + ExtRequests ExtRange + ExtReplies ExtRange + DeliveredEvents Range8 + DeviceEvents Range8 + Errors Range8 + ClientStarted bool + ClientDied bool +} + +// Struct read Range +func RangeRead(buf []byte, v *Range) int { + b := 0 + + v.CoreRequests = Range8{} + b += Range8Read(buf[b:], &v.CoreRequests) + + v.CoreReplies = Range8{} + b += Range8Read(buf[b:], &v.CoreReplies) + + v.ExtRequests = ExtRange{} + b += ExtRangeRead(buf[b:], &v.ExtRequests) + + v.ExtReplies = ExtRange{} + b += ExtRangeRead(buf[b:], &v.ExtReplies) + + v.DeliveredEvents = Range8{} + b += Range8Read(buf[b:], &v.DeliveredEvents) + + v.DeviceEvents = Range8{} + b += Range8Read(buf[b:], &v.DeviceEvents) + + v.Errors = Range8{} + b += Range8Read(buf[b:], &v.Errors) + + if buf[b] == 1 { + v.ClientStarted = true + } else { + v.ClientStarted = false + } + b += 1 + + if buf[b] == 1 { + v.ClientDied = true + } else { + v.ClientDied = false + } + b += 1 + + return b +} + +// Struct list read Range +func RangeReadList(buf []byte, dest []Range) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = Range{} + b += RangeRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Struct write Range +func (v Range) Bytes() []byte { + buf := make([]byte, 24) + b := 0 + + { + structBytes := v.CoreRequests.Bytes() + copy(buf[b:], structBytes) + b += xgb.Pad(len(structBytes)) + } + + { + structBytes := v.CoreReplies.Bytes() + copy(buf[b:], structBytes) + b += xgb.Pad(len(structBytes)) + } + + { + structBytes := v.ExtRequests.Bytes() + copy(buf[b:], structBytes) + b += xgb.Pad(len(structBytes)) + } + + { + structBytes := v.ExtReplies.Bytes() + copy(buf[b:], structBytes) + b += xgb.Pad(len(structBytes)) + } + + { + structBytes := v.DeliveredEvents.Bytes() + copy(buf[b:], structBytes) + b += xgb.Pad(len(structBytes)) + } + + { + structBytes := v.DeviceEvents.Bytes() + copy(buf[b:], structBytes) + b += xgb.Pad(len(structBytes)) + } + + { + structBytes := v.Errors.Bytes() + copy(buf[b:], structBytes) + b += xgb.Pad(len(structBytes)) + } + + if v.ClientStarted { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + if v.ClientDied { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + return buf +} + +// Write struct list Range +func RangeListBytes(buf []byte, list []Range) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += xgb.Pad(len(structBytes)) + } + return b +} + +// 'ClientInfo' struct definition +// Size: (8 + xgb.Pad((int(NumRanges) * 24))) +type ClientInfo struct { + ClientResource ClientSpec + NumRanges uint32 + Ranges []Range // size: xgb.Pad((int(NumRanges) * 24)) +} + +// Struct read ClientInfo +func ClientInfoRead(buf []byte, v *ClientInfo) int { + b := 0 + + v.ClientResource = ClientSpec(xgb.Get32(buf[b:])) + b += 4 + + v.NumRanges = xgb.Get32(buf[b:]) + b += 4 + + v.Ranges = make([]Range, v.NumRanges) + b += RangeReadList(buf[b:], v.Ranges) + + return b +} + +// Struct list read ClientInfo +func ClientInfoReadList(buf []byte, dest []ClientInfo) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = ClientInfo{} + b += ClientInfoRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Struct write ClientInfo +func (v ClientInfo) Bytes() []byte { + buf := make([]byte, (8 + xgb.Pad((int(v.NumRanges) * 24)))) + b := 0 + + xgb.Put32(buf[b:], uint32(v.ClientResource)) + b += 4 + + xgb.Put32(buf[b:], v.NumRanges) + b += 4 + + b += RangeListBytes(buf[b:], v.Ranges) + + return buf +} + +// Write struct list ClientInfo +func ClientInfoListBytes(buf []byte, list []ClientInfo) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += xgb.Pad(len(structBytes)) + } + return b +} + +// Struct list size ClientInfo +func ClientInfoListSize(list []ClientInfo) int { + size := 0 + for _, item := range list { + size += (8 + xgb.Pad((int(item.NumRanges) * 24))) + } + return size +} + +// Error definition BadContext (0) +// Size: 32 + +const BadBadContext = 0 + +type BadContextError struct { + Sequence uint16 + NiceName string + InvalidRecord uint32 +} + +// Error read BadContext +func BadContextErrorNew(buf []byte) xgb.Error { + v := BadContextError{} + v.NiceName = "BadContext" + + b := 1 // skip error determinant + b += 1 // don't read error number + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.InvalidRecord = xgb.Get32(buf[b:]) + b += 4 + + return v +} + +func (err BadContextError) ImplementsError() {} + +func (err BadContextError) SequenceId() uint16 { + return err.Sequence +} + +func (err BadContextError) BadId() uint32 { + return 0 +} + +func (err BadContextError) Error() string { + fieldVals := make([]string, 0, 1) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("InvalidRecord: %d", err.InvalidRecord)) + return "BadBadContext {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtErrorFuncs["RECORD"][0] = BadContextErrorNew +} + +// Request QueryVersion +// size: 8 +type QueryVersionCookie struct { + *xgb.Cookie +} + +func QueryVersion(c *xgb.Conn, MajorVersion uint16, MinorVersion uint16) QueryVersionCookie { + cookie := c.NewCookie(true, true) + c.NewRequest(queryVersionRequest(c, MajorVersion, MinorVersion), cookie) + return QueryVersionCookie{cookie} +} + +func QueryVersionUnchecked(c *xgb.Conn, MajorVersion uint16, MinorVersion uint16) QueryVersionCookie { + cookie := c.NewCookie(false, true) + c.NewRequest(queryVersionRequest(c, MajorVersion, MinorVersion), cookie) + return QueryVersionCookie{cookie} +} + +// Request reply for QueryVersion +// size: 12 +type QueryVersionReply struct { + Sequence uint16 + Length uint32 + // padding: 1 bytes + MajorVersion uint16 + MinorVersion uint16 +} + +// Waits and reads reply data from request QueryVersion +func (cook QueryVersionCookie) Reply() (*QueryVersionReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return queryVersionReply(buf), nil +} + +// Read reply into structure from buffer for QueryVersion +func queryVersionReply(buf []byte) *QueryVersionReply { + v := new(QueryVersionReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.MajorVersion = xgb.Get16(buf[b:]) + b += 2 + + v.MinorVersion = xgb.Get16(buf[b:]) + b += 2 + + return v +} + +// Write request to wire for QueryVersion +func queryVersionRequest(c *xgb.Conn, MajorVersion uint16, MinorVersion uint16) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + buf[b] = c.Extensions["RECORD"] + b += 1 + + buf[b] = 0 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put16(buf[b:], MajorVersion) + b += 2 + + xgb.Put16(buf[b:], MinorVersion) + b += 2 + + return buf +} + +// Request CreateContext +// size: xgb.Pad(((20 + xgb.Pad((int(NumClientSpecs) * 4))) + xgb.Pad((int(NumRanges) * 24)))) +type CreateContextCookie struct { + *xgb.Cookie +} + +// Write request to wire for CreateContext +func CreateContext(c *xgb.Conn, Context Context, ElementHeader ElementHeader, NumClientSpecs uint32, NumRanges uint32, ClientSpecs []ClientSpec, Ranges []Range) CreateContextCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(createContextRequest(c, Context, ElementHeader, NumClientSpecs, NumRanges, ClientSpecs, Ranges), cookie) + return CreateContextCookie{cookie} +} + +func CreateContextChecked(c *xgb.Conn, Context Context, ElementHeader ElementHeader, NumClientSpecs uint32, NumRanges uint32, ClientSpecs []ClientSpec, Ranges []Range) CreateContextCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(createContextRequest(c, Context, ElementHeader, NumClientSpecs, NumRanges, ClientSpecs, Ranges), cookie) + return CreateContextCookie{cookie} +} + +func (cook CreateContextCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for CreateContext +func createContextRequest(c *xgb.Conn, Context Context, ElementHeader ElementHeader, NumClientSpecs uint32, NumRanges uint32, ClientSpecs []ClientSpec, Ranges []Range) []byte { + size := xgb.Pad(((20 + xgb.Pad((int(NumClientSpecs) * 4))) + xgb.Pad((int(NumRanges) * 24)))) + b := 0 + buf := make([]byte, size) + + buf[b] = c.Extensions["RECORD"] + b += 1 + + buf[b] = 1 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Context)) + b += 4 + + buf[b] = byte(ElementHeader) + b += 1 + + b += 3 // padding + + xgb.Put32(buf[b:], NumClientSpecs) + b += 4 + + xgb.Put32(buf[b:], NumRanges) + b += 4 + + for i := 0; i < int(NumClientSpecs); i++ { + xgb.Put32(buf[b:], uint32(ClientSpecs[i])) + b += 4 + } + b = xgb.Pad(b) + + b += RangeListBytes(buf[b:], Ranges) + + return buf +} + +// Request RegisterClients +// size: xgb.Pad(((20 + xgb.Pad((int(NumClientSpecs) * 4))) + xgb.Pad((int(NumRanges) * 24)))) +type RegisterClientsCookie struct { + *xgb.Cookie +} + +// Write request to wire for RegisterClients +func RegisterClients(c *xgb.Conn, Context Context, ElementHeader ElementHeader, NumClientSpecs uint32, NumRanges uint32, ClientSpecs []ClientSpec, Ranges []Range) RegisterClientsCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(registerClientsRequest(c, Context, ElementHeader, NumClientSpecs, NumRanges, ClientSpecs, Ranges), cookie) + return RegisterClientsCookie{cookie} +} + +func RegisterClientsChecked(c *xgb.Conn, Context Context, ElementHeader ElementHeader, NumClientSpecs uint32, NumRanges uint32, ClientSpecs []ClientSpec, Ranges []Range) RegisterClientsCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(registerClientsRequest(c, Context, ElementHeader, NumClientSpecs, NumRanges, ClientSpecs, Ranges), cookie) + return RegisterClientsCookie{cookie} +} + +func (cook RegisterClientsCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for RegisterClients +func registerClientsRequest(c *xgb.Conn, Context Context, ElementHeader ElementHeader, NumClientSpecs uint32, NumRanges uint32, ClientSpecs []ClientSpec, Ranges []Range) []byte { + size := xgb.Pad(((20 + xgb.Pad((int(NumClientSpecs) * 4))) + xgb.Pad((int(NumRanges) * 24)))) + b := 0 + buf := make([]byte, size) + + buf[b] = c.Extensions["RECORD"] + b += 1 + + buf[b] = 2 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Context)) + b += 4 + + buf[b] = byte(ElementHeader) + b += 1 + + b += 3 // padding + + xgb.Put32(buf[b:], NumClientSpecs) + b += 4 + + xgb.Put32(buf[b:], NumRanges) + b += 4 + + for i := 0; i < int(NumClientSpecs); i++ { + xgb.Put32(buf[b:], uint32(ClientSpecs[i])) + b += 4 + } + b = xgb.Pad(b) + + b += RangeListBytes(buf[b:], Ranges) + + return buf +} + +// Request UnregisterClients +// size: xgb.Pad((12 + xgb.Pad((int(NumClientSpecs) * 4)))) +type UnregisterClientsCookie struct { + *xgb.Cookie +} + +// Write request to wire for UnregisterClients +func UnregisterClients(c *xgb.Conn, Context Context, NumClientSpecs uint32, ClientSpecs []ClientSpec) UnregisterClientsCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(unregisterClientsRequest(c, Context, NumClientSpecs, ClientSpecs), cookie) + return UnregisterClientsCookie{cookie} +} + +func UnregisterClientsChecked(c *xgb.Conn, Context Context, NumClientSpecs uint32, ClientSpecs []ClientSpec) UnregisterClientsCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(unregisterClientsRequest(c, Context, NumClientSpecs, ClientSpecs), cookie) + return UnregisterClientsCookie{cookie} +} + +func (cook UnregisterClientsCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for UnregisterClients +func unregisterClientsRequest(c *xgb.Conn, Context Context, NumClientSpecs uint32, ClientSpecs []ClientSpec) []byte { + size := xgb.Pad((12 + xgb.Pad((int(NumClientSpecs) * 4)))) + b := 0 + buf := make([]byte, size) + + buf[b] = c.Extensions["RECORD"] + b += 1 + + buf[b] = 3 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Context)) + b += 4 + + xgb.Put32(buf[b:], NumClientSpecs) + b += 4 + + for i := 0; i < int(NumClientSpecs); i++ { + xgb.Put32(buf[b:], uint32(ClientSpecs[i])) + b += 4 + } + b = xgb.Pad(b) + + return buf +} + +// Request GetContext +// size: 8 +type GetContextCookie struct { + *xgb.Cookie +} + +func GetContext(c *xgb.Conn, Context Context) GetContextCookie { + cookie := c.NewCookie(true, true) + c.NewRequest(getContextRequest(c, Context), cookie) + return GetContextCookie{cookie} +} + +func GetContextUnchecked(c *xgb.Conn, Context Context) GetContextCookie { + cookie := c.NewCookie(false, true) + c.NewRequest(getContextRequest(c, Context), cookie) + return GetContextCookie{cookie} +} + +// Request reply for GetContext +// size: (32 + ClientInfoListSize(InterceptedClients)) +type GetContextReply struct { + Sequence uint16 + Length uint32 + Enabled bool + ElementHeader ElementHeader + // padding: 3 bytes + NumInterceptedClients uint32 + // padding: 16 bytes + InterceptedClients []ClientInfo // size: ClientInfoListSize(InterceptedClients) +} + +// Waits and reads reply data from request GetContext +func (cook GetContextCookie) Reply() (*GetContextReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getContextReply(buf), nil +} + +// Read reply into structure from buffer for GetContext +func getContextReply(buf []byte) *GetContextReply { + v := new(GetContextReply) + b := 1 // skip reply determinant + + if buf[b] == 1 { + v.Enabled = true + } else { + v.Enabled = false + } + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.ElementHeader = ElementHeader(buf[b]) + b += 1 + + b += 3 // padding + + v.NumInterceptedClients = xgb.Get32(buf[b:]) + b += 4 + + b += 16 // padding + + v.InterceptedClients = make([]ClientInfo, v.NumInterceptedClients) + b += ClientInfoReadList(buf[b:], v.InterceptedClients) + + return v +} + +// Write request to wire for GetContext +func getContextRequest(c *xgb.Conn, Context Context) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + buf[b] = c.Extensions["RECORD"] + b += 1 + + buf[b] = 4 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Context)) + b += 4 + + return buf +} + +// Request EnableContext +// size: 8 +type EnableContextCookie struct { + *xgb.Cookie +} + +func EnableContext(c *xgb.Conn, Context Context) EnableContextCookie { + cookie := c.NewCookie(true, true) + c.NewRequest(enableContextRequest(c, Context), cookie) + return EnableContextCookie{cookie} +} + +func EnableContextUnchecked(c *xgb.Conn, Context Context) EnableContextCookie { + cookie := c.NewCookie(false, true) + c.NewRequest(enableContextRequest(c, Context), cookie) + return EnableContextCookie{cookie} +} + +// Request reply for EnableContext +// size: (32 + xgb.Pad(((int(Length) * 4) * 1))) +type EnableContextReply struct { + Sequence uint16 + Length uint32 + Category byte + ElementHeader ElementHeader + ClientSwapped bool + // padding: 2 bytes + XidBase uint32 + ServerTime uint32 + RecSequenceNum uint32 + // padding: 8 bytes + Data []byte // size: xgb.Pad(((int(Length) * 4) * 1)) +} + +// Waits and reads reply data from request EnableContext +func (cook EnableContextCookie) Reply() (*EnableContextReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return enableContextReply(buf), nil +} + +// Read reply into structure from buffer for EnableContext +func enableContextReply(buf []byte) *EnableContextReply { + v := new(EnableContextReply) + b := 1 // skip reply determinant + + v.Category = buf[b] + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.ElementHeader = ElementHeader(buf[b]) + b += 1 + + if buf[b] == 1 { + v.ClientSwapped = true + } else { + v.ClientSwapped = false + } + b += 1 + + b += 2 // padding + + v.XidBase = xgb.Get32(buf[b:]) + b += 4 + + v.ServerTime = xgb.Get32(buf[b:]) + b += 4 + + v.RecSequenceNum = xgb.Get32(buf[b:]) + b += 4 + + b += 8 // padding + + v.Data = make([]byte, (int(v.Length) * 4)) + copy(v.Data[:(int(v.Length)*4)], buf[b:]) + b += xgb.Pad(int((int(v.Length) * 4))) + + return v +} + +// Write request to wire for EnableContext +func enableContextRequest(c *xgb.Conn, Context Context) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + buf[b] = c.Extensions["RECORD"] + b += 1 + + buf[b] = 5 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Context)) + b += 4 + + return buf +} + +// Request DisableContext +// size: 8 +type DisableContextCookie struct { + *xgb.Cookie +} + +// Write request to wire for DisableContext +func DisableContext(c *xgb.Conn, Context Context) DisableContextCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(disableContextRequest(c, Context), cookie) + return DisableContextCookie{cookie} +} + +func DisableContextChecked(c *xgb.Conn, Context Context) DisableContextCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(disableContextRequest(c, Context), cookie) + return DisableContextCookie{cookie} +} + +func (cook DisableContextCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for DisableContext +func disableContextRequest(c *xgb.Conn, Context Context) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + buf[b] = c.Extensions["RECORD"] + b += 1 + + buf[b] = 6 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Context)) + b += 4 + + return buf +} + +// Request FreeContext +// size: 8 +type FreeContextCookie struct { + *xgb.Cookie +} + +// Write request to wire for FreeContext +func FreeContext(c *xgb.Conn, Context Context) FreeContextCookie { + cookie := c.NewCookie(false, false) + c.NewRequest(freeContextRequest(c, Context), cookie) + return FreeContextCookie{cookie} +} + +func FreeContextChecked(c *xgb.Conn, Context Context) FreeContextCookie { + cookie := c.NewCookie(true, false) + c.NewRequest(freeContextRequest(c, Context), cookie) + return FreeContextCookie{cookie} +} + +func (cook FreeContextCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for FreeContext +func freeContextRequest(c *xgb.Conn, Context Context) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + buf[b] = c.Extensions["RECORD"] + b += 1 + + buf[b] = 7 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Context)) + b += 4 + + return buf +} -- cgit v1.2.3 From a3363755cdfdafdf02d5a772bd47a462e99af057 Mon Sep 17 00:00:00 2001 From: "Andrew Gallant (Ocelot)" Date: Thu, 10 May 2012 20:06:22 -0400 Subject: adding package header comments --- nexgb/record/record.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'nexgb/record/record.go') diff --git a/nexgb/record/record.go b/nexgb/record/record.go index 04d514b..740353d 100644 --- a/nexgb/record/record.go +++ b/nexgb/record/record.go @@ -1,7 +1,8 @@ +// Package record is the X client API for the RECORD extension. package record /* - This file was generated by record.xml on May 10 2012 4:20:28pm EDT. + This file was generated by record.xml on May 10 2012 8:04:32pm EDT. This file is automatically generated. Edit at your peril! */ @@ -39,6 +40,10 @@ func init() { xgb.NewExtErrorFuncs["RECORD"] = make(map[int]xgb.NewErrorFun) } +// Skipping definition for base type 'Float' + +// Skipping definition for base type 'Card8' + // Skipping definition for base type 'Int16' // Skipping definition for base type 'Int32' @@ -59,10 +64,6 @@ func init() { // Skipping definition for base type 'Bool' -// Skipping definition for base type 'Float' - -// Skipping definition for base type 'Card8' - const ( HTypeFromServerTime = 1 HTypeFromClientTime = 2 -- cgit v1.2.3 From c00652934e4ec68016a152b9bea10273b0be8726 Mon Sep 17 00:00:00 2001 From: "Andrew Gallant (Ocelot)" Date: Thu, 10 May 2012 23:57:34 -0400 Subject: better docs --- nexgb/record/record.go | 176 +++++++++++++++++++++++++++---------------------- 1 file changed, 99 insertions(+), 77 deletions(-) (limited to 'nexgb/record/record.go') diff --git a/nexgb/record/record.go b/nexgb/record/record.go index 740353d..28b268e 100644 --- a/nexgb/record/record.go +++ b/nexgb/record/record.go @@ -2,7 +2,7 @@ package record /* - This file was generated by record.xml on May 10 2012 8:04:32pm EDT. + This file was generated by record.xml on May 10 2012 11:56:19pm EDT. This file is automatically generated. Edit at your peril! */ @@ -90,14 +90,12 @@ type ElementHeader byte type ClientSpec uint32 -// 'Range8' struct definition -// Size: 2 type Range8 struct { First byte Last byte } -// Struct read Range8 +// Range8Read reads a byte slice into a Range8 value. func Range8Read(buf []byte, v *Range8) int { b := 0 @@ -110,7 +108,7 @@ func Range8Read(buf []byte, v *Range8) int { return b } -// Struct list read Range8 +// Range8ReadList reads a byte slice into a list of Range8 values. func Range8ReadList(buf []byte, dest []Range8) int { b := 0 for i := 0; i < len(dest); i++ { @@ -120,7 +118,7 @@ func Range8ReadList(buf []byte, dest []Range8) int { return xgb.Pad(b) } -// Struct write Range8 +// Bytes writes a Range8 value to a byte slice. func (v Range8) Bytes() []byte { buf := make([]byte, 2) b := 0 @@ -134,7 +132,7 @@ func (v Range8) Bytes() []byte { return buf } -// Write struct list Range8 +// Range8ListBytes writes a list of %s(MISSING) values to a byte slice. func Range8ListBytes(buf []byte, list []Range8) int { b := 0 var structBytes []byte @@ -146,14 +144,12 @@ func Range8ListBytes(buf []byte, list []Range8) int { return b } -// 'Range16' struct definition -// Size: 4 type Range16 struct { First uint16 Last uint16 } -// Struct read Range16 +// Range16Read reads a byte slice into a Range16 value. func Range16Read(buf []byte, v *Range16) int { b := 0 @@ -166,7 +162,7 @@ func Range16Read(buf []byte, v *Range16) int { return b } -// Struct list read Range16 +// Range16ReadList reads a byte slice into a list of Range16 values. func Range16ReadList(buf []byte, dest []Range16) int { b := 0 for i := 0; i < len(dest); i++ { @@ -176,7 +172,7 @@ func Range16ReadList(buf []byte, dest []Range16) int { return xgb.Pad(b) } -// Struct write Range16 +// Bytes writes a Range16 value to a byte slice. func (v Range16) Bytes() []byte { buf := make([]byte, 4) b := 0 @@ -190,7 +186,7 @@ func (v Range16) Bytes() []byte { return buf } -// Write struct list Range16 +// Range16ListBytes writes a list of %s(MISSING) values to a byte slice. func Range16ListBytes(buf []byte, list []Range16) int { b := 0 var structBytes []byte @@ -202,14 +198,12 @@ func Range16ListBytes(buf []byte, list []Range16) int { return b } -// 'ExtRange' struct definition -// Size: 6 type ExtRange struct { Major Range8 Minor Range16 } -// Struct read ExtRange +// ExtRangeRead reads a byte slice into a ExtRange value. func ExtRangeRead(buf []byte, v *ExtRange) int { b := 0 @@ -222,7 +216,7 @@ func ExtRangeRead(buf []byte, v *ExtRange) int { return b } -// Struct list read ExtRange +// ExtRangeReadList reads a byte slice into a list of ExtRange values. func ExtRangeReadList(buf []byte, dest []ExtRange) int { b := 0 for i := 0; i < len(dest); i++ { @@ -232,7 +226,7 @@ func ExtRangeReadList(buf []byte, dest []ExtRange) int { return xgb.Pad(b) } -// Struct write ExtRange +// Bytes writes a ExtRange value to a byte slice. func (v ExtRange) Bytes() []byte { buf := make([]byte, 6) b := 0 @@ -252,7 +246,7 @@ func (v ExtRange) Bytes() []byte { return buf } -// Write struct list ExtRange +// ExtRangeListBytes writes a list of %s(MISSING) values to a byte slice. func ExtRangeListBytes(buf []byte, list []ExtRange) int { b := 0 var structBytes []byte @@ -264,8 +258,6 @@ func ExtRangeListBytes(buf []byte, list []ExtRange) int { return b } -// 'Range' struct definition -// Size: 24 type Range struct { CoreRequests Range8 CoreReplies Range8 @@ -278,7 +270,7 @@ type Range struct { ClientDied bool } -// Struct read Range +// RangeRead reads a byte slice into a Range value. func RangeRead(buf []byte, v *Range) int { b := 0 @@ -320,7 +312,7 @@ func RangeRead(buf []byte, v *Range) int { return b } -// Struct list read Range +// RangeReadList reads a byte slice into a list of Range values. func RangeReadList(buf []byte, dest []Range) int { b := 0 for i := 0; i < len(dest); i++ { @@ -330,7 +322,7 @@ func RangeReadList(buf []byte, dest []Range) int { return xgb.Pad(b) } -// Struct write Range +// Bytes writes a Range value to a byte slice. func (v Range) Bytes() []byte { buf := make([]byte, 24) b := 0 @@ -394,7 +386,7 @@ func (v Range) Bytes() []byte { return buf } -// Write struct list Range +// RangeListBytes writes a list of %s(MISSING) values to a byte slice. func RangeListBytes(buf []byte, list []Range) int { b := 0 var structBytes []byte @@ -406,15 +398,13 @@ func RangeListBytes(buf []byte, list []Range) int { return b } -// 'ClientInfo' struct definition -// Size: (8 + xgb.Pad((int(NumRanges) * 24))) type ClientInfo struct { ClientResource ClientSpec NumRanges uint32 Ranges []Range // size: xgb.Pad((int(NumRanges) * 24)) } -// Struct read ClientInfo +// ClientInfoRead reads a byte slice into a ClientInfo value. func ClientInfoRead(buf []byte, v *ClientInfo) int { b := 0 @@ -430,7 +420,7 @@ func ClientInfoRead(buf []byte, v *ClientInfo) int { return b } -// Struct list read ClientInfo +// ClientInfoReadList reads a byte slice into a list of ClientInfo values. func ClientInfoReadList(buf []byte, dest []ClientInfo) int { b := 0 for i := 0; i < len(dest); i++ { @@ -440,7 +430,7 @@ func ClientInfoReadList(buf []byte, dest []ClientInfo) int { return xgb.Pad(b) } -// Struct write ClientInfo +// Bytes writes a ClientInfo value to a byte slice. func (v ClientInfo) Bytes() []byte { buf := make([]byte, (8 + xgb.Pad((int(v.NumRanges) * 24)))) b := 0 @@ -456,7 +446,7 @@ func (v ClientInfo) Bytes() []byte { return buf } -// Write struct list ClientInfo +// ClientInfoListBytes writes a list of %s(MISSING) values to a byte slice. func ClientInfoListBytes(buf []byte, list []ClientInfo) int { b := 0 var structBytes []byte @@ -468,7 +458,7 @@ func ClientInfoListBytes(buf []byte, list []ClientInfo) int { return b } -// Struct list size ClientInfo +// ClientInfoListSize computes the size (bytes) of a list of ClientInfo values. func ClientInfoListSize(list []ClientInfo) int { size := 0 for _, item := range list { @@ -477,9 +467,7 @@ func ClientInfoListSize(list []ClientInfo) int { return size } -// Error definition BadContext (0) -// Size: 32 - +// BadBadContext is the error number for a BadBadContext. const BadBadContext = 0 type BadContextError struct { @@ -488,7 +476,7 @@ type BadContextError struct { InvalidRecord uint32 } -// Error read BadContext +// BadContextErrorNew constructs a BadContextError value that implements xgb.Error from a byte slice. func BadContextErrorNew(buf []byte) xgb.Error { v := BadContextError{} v.NiceName = "BadContext" @@ -505,8 +493,8 @@ func BadContextErrorNew(buf []byte) xgb.Error { return v } -func (err BadContextError) ImplementsError() {} - +// SequenceId returns the sequence id attached to the BadBadContext error. +// This is mostly used internally. func (err BadContextError) SequenceId() uint16 { return err.Sequence } @@ -527,35 +515,37 @@ func init() { xgb.NewExtErrorFuncs["RECORD"][0] = BadContextErrorNew } -// Request QueryVersion -// size: 8 +// QueryVersionCookie is a cookie used only for QueryVersion requests. type QueryVersionCookie struct { *xgb.Cookie } +// QueryVersion sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryVersionCookie.Reply() func QueryVersion(c *xgb.Conn, MajorVersion uint16, MinorVersion uint16) QueryVersionCookie { cookie := c.NewCookie(true, true) c.NewRequest(queryVersionRequest(c, MajorVersion, MinorVersion), cookie) return QueryVersionCookie{cookie} } +// QueryVersionUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. func QueryVersionUnchecked(c *xgb.Conn, MajorVersion uint16, MinorVersion uint16) QueryVersionCookie { cookie := c.NewCookie(false, true) c.NewRequest(queryVersionRequest(c, MajorVersion, MinorVersion), cookie) return QueryVersionCookie{cookie} } -// Request reply for QueryVersion -// size: 12 +// QueryVersionReply represents the data returned from a QueryVersion request. type QueryVersionReply struct { - Sequence uint16 - Length uint32 + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply // padding: 1 bytes MajorVersion uint16 MinorVersion uint16 } -// Waits and reads reply data from request QueryVersion +// Reply blocks and returns the reply data for a QueryVersion request. func (cook QueryVersionCookie) Reply() (*QueryVersionReply, error) { buf, err := cook.Cookie.Reply() if err != nil { @@ -567,7 +557,7 @@ func (cook QueryVersionCookie) Reply() (*QueryVersionReply, error) { return queryVersionReply(buf), nil } -// Read reply into structure from buffer for QueryVersion +// queryVersionReply reads a byte slice into a QueryVersionReply value. func queryVersionReply(buf []byte) *QueryVersionReply { v := new(QueryVersionReply) b := 1 // skip reply determinant @@ -590,6 +580,7 @@ func queryVersionReply(buf []byte) *QueryVersionReply { } // Write request to wire for QueryVersion +// queryVersionRequest writes a QueryVersion request to a byte slice. func queryVersionRequest(c *xgb.Conn, MajorVersion uint16, MinorVersion uint16) []byte { size := 8 b := 0 @@ -613,30 +604,35 @@ func queryVersionRequest(c *xgb.Conn, MajorVersion uint16, MinorVersion uint16) return buf } -// Request CreateContext -// size: xgb.Pad(((20 + xgb.Pad((int(NumClientSpecs) * 4))) + xgb.Pad((int(NumRanges) * 24)))) +// CreateContextCookie is a cookie used only for CreateContext requests. type CreateContextCookie struct { *xgb.Cookie } -// Write request to wire for CreateContext +// CreateContext sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. func CreateContext(c *xgb.Conn, Context Context, ElementHeader ElementHeader, NumClientSpecs uint32, NumRanges uint32, ClientSpecs []ClientSpec, Ranges []Range) CreateContextCookie { cookie := c.NewCookie(false, false) c.NewRequest(createContextRequest(c, Context, ElementHeader, NumClientSpecs, NumRanges, ClientSpecs, Ranges), cookie) return CreateContextCookie{cookie} } +// CreateContextChecked sends a checked request. +// If an error occurs, it can be retrieved using CreateContextCookie.Check() func CreateContextChecked(c *xgb.Conn, Context Context, ElementHeader ElementHeader, NumClientSpecs uint32, NumRanges uint32, ClientSpecs []ClientSpec, Ranges []Range) CreateContextCookie { cookie := c.NewCookie(true, false) c.NewRequest(createContextRequest(c, Context, ElementHeader, NumClientSpecs, NumRanges, ClientSpecs, Ranges), cookie) return CreateContextCookie{cookie} } +// Check returns an error if one occurred for checked requests that are not expecting a reply. +// This cannot be called for requests expecting a reply, nor for unchecked requests. func (cook CreateContextCookie) Check() error { return cook.Cookie.Check() } // Write request to wire for CreateContext +// createContextRequest writes a CreateContext request to a byte slice. func createContextRequest(c *xgb.Conn, Context Context, ElementHeader ElementHeader, NumClientSpecs uint32, NumRanges uint32, ClientSpecs []ClientSpec, Ranges []Range) []byte { size := xgb.Pad(((20 + xgb.Pad((int(NumClientSpecs) * 4))) + xgb.Pad((int(NumRanges) * 24)))) b := 0 @@ -676,30 +672,35 @@ func createContextRequest(c *xgb.Conn, Context Context, ElementHeader ElementHea return buf } -// Request RegisterClients -// size: xgb.Pad(((20 + xgb.Pad((int(NumClientSpecs) * 4))) + xgb.Pad((int(NumRanges) * 24)))) +// RegisterClientsCookie is a cookie used only for RegisterClients requests. type RegisterClientsCookie struct { *xgb.Cookie } -// Write request to wire for RegisterClients +// RegisterClients sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. func RegisterClients(c *xgb.Conn, Context Context, ElementHeader ElementHeader, NumClientSpecs uint32, NumRanges uint32, ClientSpecs []ClientSpec, Ranges []Range) RegisterClientsCookie { cookie := c.NewCookie(false, false) c.NewRequest(registerClientsRequest(c, Context, ElementHeader, NumClientSpecs, NumRanges, ClientSpecs, Ranges), cookie) return RegisterClientsCookie{cookie} } +// RegisterClientsChecked sends a checked request. +// If an error occurs, it can be retrieved using RegisterClientsCookie.Check() func RegisterClientsChecked(c *xgb.Conn, Context Context, ElementHeader ElementHeader, NumClientSpecs uint32, NumRanges uint32, ClientSpecs []ClientSpec, Ranges []Range) RegisterClientsCookie { cookie := c.NewCookie(true, false) c.NewRequest(registerClientsRequest(c, Context, ElementHeader, NumClientSpecs, NumRanges, ClientSpecs, Ranges), cookie) return RegisterClientsCookie{cookie} } +// Check returns an error if one occurred for checked requests that are not expecting a reply. +// This cannot be called for requests expecting a reply, nor for unchecked requests. func (cook RegisterClientsCookie) Check() error { return cook.Cookie.Check() } // Write request to wire for RegisterClients +// registerClientsRequest writes a RegisterClients request to a byte slice. func registerClientsRequest(c *xgb.Conn, Context Context, ElementHeader ElementHeader, NumClientSpecs uint32, NumRanges uint32, ClientSpecs []ClientSpec, Ranges []Range) []byte { size := xgb.Pad(((20 + xgb.Pad((int(NumClientSpecs) * 4))) + xgb.Pad((int(NumRanges) * 24)))) b := 0 @@ -739,30 +740,35 @@ func registerClientsRequest(c *xgb.Conn, Context Context, ElementHeader ElementH return buf } -// Request UnregisterClients -// size: xgb.Pad((12 + xgb.Pad((int(NumClientSpecs) * 4)))) +// UnregisterClientsCookie is a cookie used only for UnregisterClients requests. type UnregisterClientsCookie struct { *xgb.Cookie } -// Write request to wire for UnregisterClients +// UnregisterClients sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. func UnregisterClients(c *xgb.Conn, Context Context, NumClientSpecs uint32, ClientSpecs []ClientSpec) UnregisterClientsCookie { cookie := c.NewCookie(false, false) c.NewRequest(unregisterClientsRequest(c, Context, NumClientSpecs, ClientSpecs), cookie) return UnregisterClientsCookie{cookie} } +// UnregisterClientsChecked sends a checked request. +// If an error occurs, it can be retrieved using UnregisterClientsCookie.Check() func UnregisterClientsChecked(c *xgb.Conn, Context Context, NumClientSpecs uint32, ClientSpecs []ClientSpec) UnregisterClientsCookie { cookie := c.NewCookie(true, false) c.NewRequest(unregisterClientsRequest(c, Context, NumClientSpecs, ClientSpecs), cookie) return UnregisterClientsCookie{cookie} } +// Check returns an error if one occurred for checked requests that are not expecting a reply. +// This cannot be called for requests expecting a reply, nor for unchecked requests. func (cook UnregisterClientsCookie) Check() error { return cook.Cookie.Check() } // Write request to wire for UnregisterClients +// unregisterClientsRequest writes a UnregisterClients request to a byte slice. func unregisterClientsRequest(c *xgb.Conn, Context Context, NumClientSpecs uint32, ClientSpecs []ClientSpec) []byte { size := xgb.Pad((12 + xgb.Pad((int(NumClientSpecs) * 4)))) b := 0 @@ -792,29 +798,31 @@ func unregisterClientsRequest(c *xgb.Conn, Context Context, NumClientSpecs uint3 return buf } -// Request GetContext -// size: 8 +// GetContextCookie is a cookie used only for GetContext requests. type GetContextCookie struct { *xgb.Cookie } +// GetContext sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetContextCookie.Reply() func GetContext(c *xgb.Conn, Context Context) GetContextCookie { cookie := c.NewCookie(true, true) c.NewRequest(getContextRequest(c, Context), cookie) return GetContextCookie{cookie} } +// GetContextUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. func GetContextUnchecked(c *xgb.Conn, Context Context) GetContextCookie { cookie := c.NewCookie(false, true) c.NewRequest(getContextRequest(c, Context), cookie) return GetContextCookie{cookie} } -// Request reply for GetContext -// size: (32 + ClientInfoListSize(InterceptedClients)) +// GetContextReply represents the data returned from a GetContext request. type GetContextReply struct { - Sequence uint16 - Length uint32 + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply Enabled bool ElementHeader ElementHeader // padding: 3 bytes @@ -823,7 +831,7 @@ type GetContextReply struct { InterceptedClients []ClientInfo // size: ClientInfoListSize(InterceptedClients) } -// Waits and reads reply data from request GetContext +// Reply blocks and returns the reply data for a GetContext request. func (cook GetContextCookie) Reply() (*GetContextReply, error) { buf, err := cook.Cookie.Reply() if err != nil { @@ -835,7 +843,7 @@ func (cook GetContextCookie) Reply() (*GetContextReply, error) { return getContextReply(buf), nil } -// Read reply into structure from buffer for GetContext +// getContextReply reads a byte slice into a GetContextReply value. func getContextReply(buf []byte) *GetContextReply { v := new(GetContextReply) b := 1 // skip reply determinant @@ -870,6 +878,7 @@ func getContextReply(buf []byte) *GetContextReply { } // Write request to wire for GetContext +// getContextRequest writes a GetContext request to a byte slice. func getContextRequest(c *xgb.Conn, Context Context) []byte { size := 8 b := 0 @@ -890,29 +899,31 @@ func getContextRequest(c *xgb.Conn, Context Context) []byte { return buf } -// Request EnableContext -// size: 8 +// EnableContextCookie is a cookie used only for EnableContext requests. type EnableContextCookie struct { *xgb.Cookie } +// EnableContext sends a checked request. +// If an error occurs, it will be returned with the reply by calling EnableContextCookie.Reply() func EnableContext(c *xgb.Conn, Context Context) EnableContextCookie { cookie := c.NewCookie(true, true) c.NewRequest(enableContextRequest(c, Context), cookie) return EnableContextCookie{cookie} } +// EnableContextUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. func EnableContextUnchecked(c *xgb.Conn, Context Context) EnableContextCookie { cookie := c.NewCookie(false, true) c.NewRequest(enableContextRequest(c, Context), cookie) return EnableContextCookie{cookie} } -// Request reply for EnableContext -// size: (32 + xgb.Pad(((int(Length) * 4) * 1))) +// EnableContextReply represents the data returned from a EnableContext request. type EnableContextReply struct { - Sequence uint16 - Length uint32 + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply Category byte ElementHeader ElementHeader ClientSwapped bool @@ -924,7 +935,7 @@ type EnableContextReply struct { Data []byte // size: xgb.Pad(((int(Length) * 4) * 1)) } -// Waits and reads reply data from request EnableContext +// Reply blocks and returns the reply data for a EnableContext request. func (cook EnableContextCookie) Reply() (*EnableContextReply, error) { buf, err := cook.Cookie.Reply() if err != nil { @@ -936,7 +947,7 @@ func (cook EnableContextCookie) Reply() (*EnableContextReply, error) { return enableContextReply(buf), nil } -// Read reply into structure from buffer for EnableContext +// enableContextReply reads a byte slice into a EnableContextReply value. func enableContextReply(buf []byte) *EnableContextReply { v := new(EnableContextReply) b := 1 // skip reply determinant @@ -981,6 +992,7 @@ func enableContextReply(buf []byte) *EnableContextReply { } // Write request to wire for EnableContext +// enableContextRequest writes a EnableContext request to a byte slice. func enableContextRequest(c *xgb.Conn, Context Context) []byte { size := 8 b := 0 @@ -1001,30 +1013,35 @@ func enableContextRequest(c *xgb.Conn, Context Context) []byte { return buf } -// Request DisableContext -// size: 8 +// DisableContextCookie is a cookie used only for DisableContext requests. type DisableContextCookie struct { *xgb.Cookie } -// Write request to wire for DisableContext +// DisableContext sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. func DisableContext(c *xgb.Conn, Context Context) DisableContextCookie { cookie := c.NewCookie(false, false) c.NewRequest(disableContextRequest(c, Context), cookie) return DisableContextCookie{cookie} } +// DisableContextChecked sends a checked request. +// If an error occurs, it can be retrieved using DisableContextCookie.Check() func DisableContextChecked(c *xgb.Conn, Context Context) DisableContextCookie { cookie := c.NewCookie(true, false) c.NewRequest(disableContextRequest(c, Context), cookie) return DisableContextCookie{cookie} } +// Check returns an error if one occurred for checked requests that are not expecting a reply. +// This cannot be called for requests expecting a reply, nor for unchecked requests. func (cook DisableContextCookie) Check() error { return cook.Cookie.Check() } // Write request to wire for DisableContext +// disableContextRequest writes a DisableContext request to a byte slice. func disableContextRequest(c *xgb.Conn, Context Context) []byte { size := 8 b := 0 @@ -1045,30 +1062,35 @@ func disableContextRequest(c *xgb.Conn, Context Context) []byte { return buf } -// Request FreeContext -// size: 8 +// FreeContextCookie is a cookie used only for FreeContext requests. type FreeContextCookie struct { *xgb.Cookie } -// Write request to wire for FreeContext +// FreeContext sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. func FreeContext(c *xgb.Conn, Context Context) FreeContextCookie { cookie := c.NewCookie(false, false) c.NewRequest(freeContextRequest(c, Context), cookie) return FreeContextCookie{cookie} } +// FreeContextChecked sends a checked request. +// If an error occurs, it can be retrieved using FreeContextCookie.Check() func FreeContextChecked(c *xgb.Conn, Context Context) FreeContextCookie { cookie := c.NewCookie(true, false) c.NewRequest(freeContextRequest(c, Context), cookie) return FreeContextCookie{cookie} } +// Check returns an error if one occurred for checked requests that are not expecting a reply. +// This cannot be called for requests expecting a reply, nor for unchecked requests. func (cook FreeContextCookie) Check() error { return cook.Cookie.Check() } // Write request to wire for FreeContext +// freeContextRequest writes a FreeContext request to a byte slice. func freeContextRequest(c *xgb.Conn, Context Context) []byte { size := 8 b := 0 -- cgit v1.2.3 From 3e6b3544934cb71e3a3b0edf9bc184241ac1ad7f Mon Sep 17 00:00:00 2001 From: "Andrew Gallant (Ocelot)" Date: Fri, 11 May 2012 01:58:52 -0400 Subject: add a little more docs for errors --- nexgb/record/record.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'nexgb/record/record.go') diff --git a/nexgb/record/record.go b/nexgb/record/record.go index 28b268e..5623e50 100644 --- a/nexgb/record/record.go +++ b/nexgb/record/record.go @@ -2,7 +2,7 @@ package record /* - This file was generated by record.xml on May 10 2012 11:56:19pm EDT. + This file was generated by record.xml on May 11 2012 1:58:36am EDT. This file is automatically generated. Edit at your peril! */ @@ -499,10 +499,13 @@ func (err BadContextError) SequenceId() uint16 { return err.Sequence } +// BadId returns the 'BadValue' number if one exists for the BadBadContext error. If no bad value exists, 0 is returned. func (err BadContextError) BadId() uint32 { return 0 } +// Error returns a rudimentary string representation of the BadBadContext error. + func (err BadContextError) Error() string { fieldVals := make([]string, 0, 1) fieldVals = append(fieldVals, "NiceName: "+err.NiceName) -- cgit v1.2.3 From 29942bf078c92fea681e42ca5029592526f00718 Mon Sep 17 00:00:00 2001 From: "Andrew Gallant (Ocelot)" Date: Fri, 11 May 2012 23:58:52 -0400 Subject: panic when an extension request is issued before an extension has been initialized. but give a nice error message for the happy people. --- nexgb/record/record.go | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) (limited to 'nexgb/record/record.go') diff --git a/nexgb/record/record.go b/nexgb/record/record.go index 5623e50..a9ae7ea 100644 --- a/nexgb/record/record.go +++ b/nexgb/record/record.go @@ -2,7 +2,7 @@ package record /* - This file was generated by record.xml on May 11 2012 1:58:36am EDT. + This file was generated by record.xml on May 11 2012 11:57:19pm EDT. This file is automatically generated. Edit at your peril! */ @@ -526,6 +526,9 @@ type QueryVersionCookie struct { // QueryVersion sends a checked request. // If an error occurs, it will be returned with the reply by calling QueryVersionCookie.Reply() func QueryVersion(c *xgb.Conn, MajorVersion uint16, MinorVersion uint16) QueryVersionCookie { + if _, ok := c.Extensions["RECORD"]; !ok { + panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") + } cookie := c.NewCookie(true, true) c.NewRequest(queryVersionRequest(c, MajorVersion, MinorVersion), cookie) return QueryVersionCookie{cookie} @@ -534,6 +537,9 @@ func QueryVersion(c *xgb.Conn, MajorVersion uint16, MinorVersion uint16) QueryVe // QueryVersionUnchecked sends an unchecked request. // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. func QueryVersionUnchecked(c *xgb.Conn, MajorVersion uint16, MinorVersion uint16) QueryVersionCookie { + if _, ok := c.Extensions["RECORD"]; !ok { + panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") + } cookie := c.NewCookie(false, true) c.NewRequest(queryVersionRequest(c, MajorVersion, MinorVersion), cookie) return QueryVersionCookie{cookie} @@ -615,6 +621,9 @@ type CreateContextCookie struct { // CreateContext sends an unchecked request. // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. func CreateContext(c *xgb.Conn, Context Context, ElementHeader ElementHeader, NumClientSpecs uint32, NumRanges uint32, ClientSpecs []ClientSpec, Ranges []Range) CreateContextCookie { + if _, ok := c.Extensions["RECORD"]; !ok { + panic("Cannot issue request 'CreateContext' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") + } cookie := c.NewCookie(false, false) c.NewRequest(createContextRequest(c, Context, ElementHeader, NumClientSpecs, NumRanges, ClientSpecs, Ranges), cookie) return CreateContextCookie{cookie} @@ -623,6 +632,9 @@ func CreateContext(c *xgb.Conn, Context Context, ElementHeader ElementHeader, Nu // CreateContextChecked sends a checked request. // If an error occurs, it can be retrieved using CreateContextCookie.Check() func CreateContextChecked(c *xgb.Conn, Context Context, ElementHeader ElementHeader, NumClientSpecs uint32, NumRanges uint32, ClientSpecs []ClientSpec, Ranges []Range) CreateContextCookie { + if _, ok := c.Extensions["RECORD"]; !ok { + panic("Cannot issue request 'CreateContext' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") + } cookie := c.NewCookie(true, false) c.NewRequest(createContextRequest(c, Context, ElementHeader, NumClientSpecs, NumRanges, ClientSpecs, Ranges), cookie) return CreateContextCookie{cookie} @@ -683,6 +695,9 @@ type RegisterClientsCookie struct { // RegisterClients sends an unchecked request. // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. func RegisterClients(c *xgb.Conn, Context Context, ElementHeader ElementHeader, NumClientSpecs uint32, NumRanges uint32, ClientSpecs []ClientSpec, Ranges []Range) RegisterClientsCookie { + if _, ok := c.Extensions["RECORD"]; !ok { + panic("Cannot issue request 'RegisterClients' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") + } cookie := c.NewCookie(false, false) c.NewRequest(registerClientsRequest(c, Context, ElementHeader, NumClientSpecs, NumRanges, ClientSpecs, Ranges), cookie) return RegisterClientsCookie{cookie} @@ -691,6 +706,9 @@ func RegisterClients(c *xgb.Conn, Context Context, ElementHeader ElementHeader, // RegisterClientsChecked sends a checked request. // If an error occurs, it can be retrieved using RegisterClientsCookie.Check() func RegisterClientsChecked(c *xgb.Conn, Context Context, ElementHeader ElementHeader, NumClientSpecs uint32, NumRanges uint32, ClientSpecs []ClientSpec, Ranges []Range) RegisterClientsCookie { + if _, ok := c.Extensions["RECORD"]; !ok { + panic("Cannot issue request 'RegisterClients' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") + } cookie := c.NewCookie(true, false) c.NewRequest(registerClientsRequest(c, Context, ElementHeader, NumClientSpecs, NumRanges, ClientSpecs, Ranges), cookie) return RegisterClientsCookie{cookie} @@ -751,6 +769,9 @@ type UnregisterClientsCookie struct { // UnregisterClients sends an unchecked request. // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. func UnregisterClients(c *xgb.Conn, Context Context, NumClientSpecs uint32, ClientSpecs []ClientSpec) UnregisterClientsCookie { + if _, ok := c.Extensions["RECORD"]; !ok { + panic("Cannot issue request 'UnregisterClients' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") + } cookie := c.NewCookie(false, false) c.NewRequest(unregisterClientsRequest(c, Context, NumClientSpecs, ClientSpecs), cookie) return UnregisterClientsCookie{cookie} @@ -759,6 +780,9 @@ func UnregisterClients(c *xgb.Conn, Context Context, NumClientSpecs uint32, Clie // UnregisterClientsChecked sends a checked request. // If an error occurs, it can be retrieved using UnregisterClientsCookie.Check() func UnregisterClientsChecked(c *xgb.Conn, Context Context, NumClientSpecs uint32, ClientSpecs []ClientSpec) UnregisterClientsCookie { + if _, ok := c.Extensions["RECORD"]; !ok { + panic("Cannot issue request 'UnregisterClients' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") + } cookie := c.NewCookie(true, false) c.NewRequest(unregisterClientsRequest(c, Context, NumClientSpecs, ClientSpecs), cookie) return UnregisterClientsCookie{cookie} @@ -809,6 +833,9 @@ type GetContextCookie struct { // GetContext sends a checked request. // If an error occurs, it will be returned with the reply by calling GetContextCookie.Reply() func GetContext(c *xgb.Conn, Context Context) GetContextCookie { + if _, ok := c.Extensions["RECORD"]; !ok { + panic("Cannot issue request 'GetContext' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") + } cookie := c.NewCookie(true, true) c.NewRequest(getContextRequest(c, Context), cookie) return GetContextCookie{cookie} @@ -817,6 +844,9 @@ func GetContext(c *xgb.Conn, Context Context) GetContextCookie { // GetContextUnchecked sends an unchecked request. // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. func GetContextUnchecked(c *xgb.Conn, Context Context) GetContextCookie { + if _, ok := c.Extensions["RECORD"]; !ok { + panic("Cannot issue request 'GetContext' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") + } cookie := c.NewCookie(false, true) c.NewRequest(getContextRequest(c, Context), cookie) return GetContextCookie{cookie} @@ -910,6 +940,9 @@ type EnableContextCookie struct { // EnableContext sends a checked request. // If an error occurs, it will be returned with the reply by calling EnableContextCookie.Reply() func EnableContext(c *xgb.Conn, Context Context) EnableContextCookie { + if _, ok := c.Extensions["RECORD"]; !ok { + panic("Cannot issue request 'EnableContext' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") + } cookie := c.NewCookie(true, true) c.NewRequest(enableContextRequest(c, Context), cookie) return EnableContextCookie{cookie} @@ -918,6 +951,9 @@ func EnableContext(c *xgb.Conn, Context Context) EnableContextCookie { // EnableContextUnchecked sends an unchecked request. // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. func EnableContextUnchecked(c *xgb.Conn, Context Context) EnableContextCookie { + if _, ok := c.Extensions["RECORD"]; !ok { + panic("Cannot issue request 'EnableContext' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") + } cookie := c.NewCookie(false, true) c.NewRequest(enableContextRequest(c, Context), cookie) return EnableContextCookie{cookie} @@ -1024,6 +1060,9 @@ type DisableContextCookie struct { // DisableContext sends an unchecked request. // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. func DisableContext(c *xgb.Conn, Context Context) DisableContextCookie { + if _, ok := c.Extensions["RECORD"]; !ok { + panic("Cannot issue request 'DisableContext' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") + } cookie := c.NewCookie(false, false) c.NewRequest(disableContextRequest(c, Context), cookie) return DisableContextCookie{cookie} @@ -1032,6 +1071,9 @@ func DisableContext(c *xgb.Conn, Context Context) DisableContextCookie { // DisableContextChecked sends a checked request. // If an error occurs, it can be retrieved using DisableContextCookie.Check() func DisableContextChecked(c *xgb.Conn, Context Context) DisableContextCookie { + if _, ok := c.Extensions["RECORD"]; !ok { + panic("Cannot issue request 'DisableContext' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") + } cookie := c.NewCookie(true, false) c.NewRequest(disableContextRequest(c, Context), cookie) return DisableContextCookie{cookie} @@ -1073,6 +1115,9 @@ type FreeContextCookie struct { // FreeContext sends an unchecked request. // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. func FreeContext(c *xgb.Conn, Context Context) FreeContextCookie { + if _, ok := c.Extensions["RECORD"]; !ok { + panic("Cannot issue request 'FreeContext' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") + } cookie := c.NewCookie(false, false) c.NewRequest(freeContextRequest(c, Context), cookie) return FreeContextCookie{cookie} @@ -1081,6 +1126,9 @@ func FreeContext(c *xgb.Conn, Context Context) FreeContextCookie { // FreeContextChecked sends a checked request. // If an error occurs, it can be retrieved using FreeContextCookie.Check() func FreeContextChecked(c *xgb.Conn, Context Context) FreeContextCookie { + if _, ok := c.Extensions["RECORD"]; !ok { + panic("Cannot issue request 'FreeContext' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") + } cookie := c.NewCookie(true, false) c.NewRequest(freeContextRequest(c, Context), cookie) return FreeContextCookie{cookie} -- cgit v1.2.3 From 4ea94ca0fef7786ce21722cbb02a9cf069bdedd9 Mon Sep 17 00:00:00 2001 From: "Andrew Gallant (Ocelot)" Date: Sat, 26 May 2012 18:24:52 -0400 Subject: Bug fix in the generator that was outputting %(MISSING) crud. --- nexgb/record/record.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'nexgb/record/record.go') diff --git a/nexgb/record/record.go b/nexgb/record/record.go index a9ae7ea..0ae6d81 100644 --- a/nexgb/record/record.go +++ b/nexgb/record/record.go @@ -2,7 +2,7 @@ package record /* - This file was generated by record.xml on May 11 2012 11:57:19pm EDT. + This file was generated by record.xml on May 26 2012 6:23:13pm EDT. This file is automatically generated. Edit at your peril! */ @@ -40,8 +40,6 @@ func init() { xgb.NewExtErrorFuncs["RECORD"] = make(map[int]xgb.NewErrorFun) } -// Skipping definition for base type 'Float' - // Skipping definition for base type 'Card8' // Skipping definition for base type 'Int16' @@ -64,6 +62,8 @@ func init() { // Skipping definition for base type 'Bool' +// Skipping definition for base type 'Float' + const ( HTypeFromServerTime = 1 HTypeFromClientTime = 2 @@ -132,7 +132,7 @@ func (v Range8) Bytes() []byte { return buf } -// Range8ListBytes writes a list of %s(MISSING) values to a byte slice. +// Range8ListBytes writes a list of Range8 values to a byte slice. func Range8ListBytes(buf []byte, list []Range8) int { b := 0 var structBytes []byte @@ -186,7 +186,7 @@ func (v Range16) Bytes() []byte { return buf } -// Range16ListBytes writes a list of %s(MISSING) values to a byte slice. +// Range16ListBytes writes a list of Range16 values to a byte slice. func Range16ListBytes(buf []byte, list []Range16) int { b := 0 var structBytes []byte @@ -246,7 +246,7 @@ func (v ExtRange) Bytes() []byte { return buf } -// ExtRangeListBytes writes a list of %s(MISSING) values to a byte slice. +// ExtRangeListBytes writes a list of ExtRange values to a byte slice. func ExtRangeListBytes(buf []byte, list []ExtRange) int { b := 0 var structBytes []byte @@ -386,7 +386,7 @@ func (v Range) Bytes() []byte { return buf } -// RangeListBytes writes a list of %s(MISSING) values to a byte slice. +// RangeListBytes writes a list of Range values to a byte slice. func RangeListBytes(buf []byte, list []Range) int { b := 0 var structBytes []byte @@ -446,7 +446,7 @@ func (v ClientInfo) Bytes() []byte { return buf } -// ClientInfoListBytes writes a list of %s(MISSING) values to a byte slice. +// ClientInfoListBytes writes a list of ClientInfo values to a byte slice. func ClientInfoListBytes(buf []byte, list []ClientInfo) int { b := 0 var structBytes []byte -- cgit v1.2.3 From a9eae45cb3977bce5983e817d00d4584d176b044 Mon Sep 17 00:00:00 2001 From: "Andrew Gallant (Ocelot)" Date: Tue, 5 Jun 2012 00:14:34 -0400 Subject: Refresh build. Eh. --- nexgb/record/record.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'nexgb/record/record.go') diff --git a/nexgb/record/record.go b/nexgb/record/record.go index 0ae6d81..4bed730 100644 --- a/nexgb/record/record.go +++ b/nexgb/record/record.go @@ -2,7 +2,7 @@ package record /* - This file was generated by record.xml on May 26 2012 6:23:13pm EDT. + This file was generated by record.xml on Jun 5 2012 12:11:59am EDT. This file is automatically generated. Edit at your peril! */ @@ -40,6 +40,8 @@ func init() { xgb.NewExtErrorFuncs["RECORD"] = make(map[int]xgb.NewErrorFun) } +// Skipping definition for base type 'Float' + // Skipping definition for base type 'Card8' // Skipping definition for base type 'Int16' @@ -62,8 +64,6 @@ func init() { // Skipping definition for base type 'Bool' -// Skipping definition for base type 'Float' - const ( HTypeFromServerTime = 1 HTypeFromClientTime = 2 -- cgit v1.2.3 From 0685fb57e14104ee4ad9f70ec94f787a9a22c028 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Sun, 11 Aug 2013 20:43:26 -0400 Subject: Update to latest xproto XML. --- nexgb/record/record.go | 838 ++++++++++++++++++++++++------------------------- 1 file changed, 419 insertions(+), 419 deletions(-) (limited to 'nexgb/record/record.go') diff --git a/nexgb/record/record.go b/nexgb/record/record.go index 4bed730..2bbfe1c 100644 --- a/nexgb/record/record.go +++ b/nexgb/record/record.go @@ -2,7 +2,7 @@ package record /* - This file was generated by record.xml on Jun 5 2012 12:11:59am EDT. + This file was generated by record.xml on Aug 11 2013 8:39:43pm EDT. This file is automatically generated. Edit at your peril! */ @@ -40,100 +40,107 @@ func init() { xgb.NewExtErrorFuncs["RECORD"] = make(map[int]xgb.NewErrorFun) } -// Skipping definition for base type 'Float' - -// Skipping definition for base type 'Card8' - -// Skipping definition for base type 'Int16' - -// Skipping definition for base type 'Int32' - -// Skipping definition for base type 'Void' - -// Skipping definition for base type 'Byte' +// BadBadContext is the error number for a BadBadContext. +const BadBadContext = 0 -// Skipping definition for base type 'Int8' +type BadContextError struct { + Sequence uint16 + NiceName string + InvalidRecord uint32 +} -// Skipping definition for base type 'Card16' +// BadContextErrorNew constructs a BadContextError value that implements xgb.Error from a byte slice. +func BadContextErrorNew(buf []byte) xgb.Error { + v := BadContextError{} + v.NiceName = "BadContext" -// Skipping definition for base type 'Char' + b := 1 // skip error determinant + b += 1 // don't read error number -// Skipping definition for base type 'Card32' + v.Sequence = xgb.Get16(buf[b:]) + b += 2 -// Skipping definition for base type 'Double' + v.InvalidRecord = xgb.Get32(buf[b:]) + b += 4 -// Skipping definition for base type 'Bool' + return v +} -const ( - HTypeFromServerTime = 1 - HTypeFromClientTime = 2 - HTypeFromClientSequence = 4 -) +// SequenceId returns the sequence id attached to the BadBadContext error. +// This is mostly used internally. +func (err BadContextError) SequenceId() uint16 { + return err.Sequence +} -const ( - CsCurrentClients = 1 - CsFutureClients = 2 - CsAllClients = 3 -) +// BadId returns the 'BadValue' number if one exists for the BadBadContext error. If no bad value exists, 0 is returned. +func (err BadContextError) BadId() uint32 { + return 0 +} -type Context uint32 +// Error returns a rudimentary string representation of the BadBadContext error. -func NewContextId(c *xgb.Conn) (Context, error) { - id, err := c.NewId() - if err != nil { - return 0, err - } - return Context(id), nil +func (err BadContextError) Error() string { + fieldVals := make([]string, 0, 1) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("InvalidRecord: %d", err.InvalidRecord)) + return "BadBadContext {" + xgb.StringsJoin(fieldVals, ", ") + "}" } -type ElementHeader byte - -type ClientSpec uint32 +func init() { + xgb.NewExtErrorFuncs["RECORD"][0] = BadContextErrorNew +} -type Range8 struct { - First byte - Last byte +type ClientInfo struct { + ClientResource ClientSpec + NumRanges uint32 + Ranges []Range // size: xgb.Pad((int(NumRanges) * 24)) } -// Range8Read reads a byte slice into a Range8 value. -func Range8Read(buf []byte, v *Range8) int { +// ClientInfoRead reads a byte slice into a ClientInfo value. +func ClientInfoRead(buf []byte, v *ClientInfo) int { b := 0 - v.First = buf[b] - b += 1 + v.ClientResource = ClientSpec(xgb.Get32(buf[b:])) + b += 4 - v.Last = buf[b] - b += 1 + v.NumRanges = xgb.Get32(buf[b:]) + b += 4 + + v.Ranges = make([]Range, v.NumRanges) + b += RangeReadList(buf[b:], v.Ranges) return b } -// Range8ReadList reads a byte slice into a list of Range8 values. -func Range8ReadList(buf []byte, dest []Range8) int { +// ClientInfoReadList reads a byte slice into a list of ClientInfo values. +func ClientInfoReadList(buf []byte, dest []ClientInfo) int { b := 0 for i := 0; i < len(dest); i++ { - dest[i] = Range8{} - b += Range8Read(buf[b:], &dest[i]) + dest[i] = ClientInfo{} + b += ClientInfoRead(buf[b:], &dest[i]) } return xgb.Pad(b) } -// Bytes writes a Range8 value to a byte slice. -func (v Range8) Bytes() []byte { - buf := make([]byte, 2) +// Bytes writes a ClientInfo value to a byte slice. +func (v ClientInfo) Bytes() []byte { + buf := make([]byte, (8 + xgb.Pad((int(v.NumRanges) * 24)))) b := 0 - buf[b] = v.First - b += 1 + xgb.Put32(buf[b:], uint32(v.ClientResource)) + b += 4 - buf[b] = v.Last - b += 1 + xgb.Put32(buf[b:], v.NumRanges) + b += 4 + + b += RangeListBytes(buf[b:], v.Ranges) return buf } -// Range8ListBytes writes a list of Range8 values to a byte slice. -func Range8ListBytes(buf []byte, list []Range8) int { +// ClientInfoListBytes writes a list of ClientInfo values to a byte slice. +func ClientInfoListBytes(buf []byte, list []ClientInfo) int { b := 0 var structBytes []byte for _, item := range list { @@ -144,59 +151,34 @@ func Range8ListBytes(buf []byte, list []Range8) int { return b } -type Range16 struct { - First uint16 - Last uint16 +// ClientInfoListSize computes the size (bytes) of a list of ClientInfo values. +func ClientInfoListSize(list []ClientInfo) int { + size := 0 + for _, item := range list { + size += (8 + xgb.Pad((int(item.NumRanges) * 24))) + } + return size } -// Range16Read reads a byte slice into a Range16 value. -func Range16Read(buf []byte, v *Range16) int { - b := 0 - - v.First = xgb.Get16(buf[b:]) - b += 2 - - v.Last = xgb.Get16(buf[b:]) - b += 2 +type ClientSpec uint32 - return b -} +type Context uint32 -// Range16ReadList reads a byte slice into a list of Range16 values. -func Range16ReadList(buf []byte, dest []Range16) int { - b := 0 - for i := 0; i < len(dest); i++ { - dest[i] = Range16{} - b += Range16Read(buf[b:], &dest[i]) +func NewContextId(c *xgb.Conn) (Context, error) { + id, err := c.NewId() + if err != nil { + return 0, err } - return xgb.Pad(b) + return Context(id), nil } -// Bytes writes a Range16 value to a byte slice. -func (v Range16) Bytes() []byte { - buf := make([]byte, 4) - b := 0 - - xgb.Put16(buf[b:], v.First) - b += 2 - - xgb.Put16(buf[b:], v.Last) - b += 2 - - return buf -} +const ( + CsCurrentClients = 1 + CsFutureClients = 2 + CsAllClients = 3 +) -// Range16ListBytes writes a list of Range16 values to a byte slice. -func Range16ListBytes(buf []byte, list []Range16) int { - b := 0 - var structBytes []byte - for _, item := range list { - structBytes = item.Bytes() - copy(buf[b:], structBytes) - b += xgb.Pad(len(structBytes)) - } - return b -} +type ElementHeader byte type ExtRange struct { Major Range8 @@ -258,6 +240,12 @@ func ExtRangeListBytes(buf []byte, list []ExtRange) int { return b } +const ( + HTypeFromServerTime = 1 + HTypeFromClientTime = 2 + HTypeFromClientSequence = 4 +) + type Range struct { CoreRequests Range8 CoreReplies Range8 @@ -398,56 +386,50 @@ func RangeListBytes(buf []byte, list []Range) int { return b } -type ClientInfo struct { - ClientResource ClientSpec - NumRanges uint32 - Ranges []Range // size: xgb.Pad((int(NumRanges) * 24)) +type Range16 struct { + First uint16 + Last uint16 } -// ClientInfoRead reads a byte slice into a ClientInfo value. -func ClientInfoRead(buf []byte, v *ClientInfo) int { +// Range16Read reads a byte slice into a Range16 value. +func Range16Read(buf []byte, v *Range16) int { b := 0 - v.ClientResource = ClientSpec(xgb.Get32(buf[b:])) - b += 4 - - v.NumRanges = xgb.Get32(buf[b:]) - b += 4 + v.First = xgb.Get16(buf[b:]) + b += 2 - v.Ranges = make([]Range, v.NumRanges) - b += RangeReadList(buf[b:], v.Ranges) + v.Last = xgb.Get16(buf[b:]) + b += 2 return b } -// ClientInfoReadList reads a byte slice into a list of ClientInfo values. -func ClientInfoReadList(buf []byte, dest []ClientInfo) int { +// Range16ReadList reads a byte slice into a list of Range16 values. +func Range16ReadList(buf []byte, dest []Range16) int { b := 0 for i := 0; i < len(dest); i++ { - dest[i] = ClientInfo{} - b += ClientInfoRead(buf[b:], &dest[i]) + dest[i] = Range16{} + b += Range16Read(buf[b:], &dest[i]) } return xgb.Pad(b) } -// Bytes writes a ClientInfo value to a byte slice. -func (v ClientInfo) Bytes() []byte { - buf := make([]byte, (8 + xgb.Pad((int(v.NumRanges) * 24)))) +// Bytes writes a Range16 value to a byte slice. +func (v Range16) Bytes() []byte { + buf := make([]byte, 4) b := 0 - xgb.Put32(buf[b:], uint32(v.ClientResource)) - b += 4 - - xgb.Put32(buf[b:], v.NumRanges) - b += 4 + xgb.Put16(buf[b:], v.First) + b += 2 - b += RangeListBytes(buf[b:], v.Ranges) + xgb.Put16(buf[b:], v.Last) + b += 2 return buf } -// ClientInfoListBytes writes a list of ClientInfo values to a byte slice. -func ClientInfoListBytes(buf []byte, list []ClientInfo) int { +// Range16ListBytes writes a list of Range16 values to a byte slice. +func Range16ListBytes(buf []byte, list []Range16) int { b := 0 var structBytes []byte for _, item := range list { @@ -458,160 +440,83 @@ func ClientInfoListBytes(buf []byte, list []ClientInfo) int { return b } -// ClientInfoListSize computes the size (bytes) of a list of ClientInfo values. -func ClientInfoListSize(list []ClientInfo) int { - size := 0 - for _, item := range list { - size += (8 + xgb.Pad((int(item.NumRanges) * 24))) - } - return size +type Range8 struct { + First byte + Last byte } -// BadBadContext is the error number for a BadBadContext. -const BadBadContext = 0 - -type BadContextError struct { - Sequence uint16 - NiceName string - InvalidRecord uint32 -} - -// BadContextErrorNew constructs a BadContextError value that implements xgb.Error from a byte slice. -func BadContextErrorNew(buf []byte) xgb.Error { - v := BadContextError{} - v.NiceName = "BadContext" - - b := 1 // skip error determinant - b += 1 // don't read error number - - v.Sequence = xgb.Get16(buf[b:]) - b += 2 - - v.InvalidRecord = xgb.Get32(buf[b:]) - b += 4 - - return v -} - -// SequenceId returns the sequence id attached to the BadBadContext error. -// This is mostly used internally. -func (err BadContextError) SequenceId() uint16 { - return err.Sequence -} +// Range8Read reads a byte slice into a Range8 value. +func Range8Read(buf []byte, v *Range8) int { + b := 0 -// BadId returns the 'BadValue' number if one exists for the BadBadContext error. If no bad value exists, 0 is returned. -func (err BadContextError) BadId() uint32 { - return 0 -} + v.First = buf[b] + b += 1 -// Error returns a rudimentary string representation of the BadBadContext error. + v.Last = buf[b] + b += 1 -func (err BadContextError) Error() string { - fieldVals := make([]string, 0, 1) - fieldVals = append(fieldVals, "NiceName: "+err.NiceName) - fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) - fieldVals = append(fieldVals, xgb.Sprintf("InvalidRecord: %d", err.InvalidRecord)) - return "BadBadContext {" + xgb.StringsJoin(fieldVals, ", ") + "}" + return b } -func init() { - xgb.NewExtErrorFuncs["RECORD"][0] = BadContextErrorNew +// Range8ReadList reads a byte slice into a list of Range8 values. +func Range8ReadList(buf []byte, dest []Range8) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = Range8{} + b += Range8Read(buf[b:], &dest[i]) + } + return xgb.Pad(b) } -// QueryVersionCookie is a cookie used only for QueryVersion requests. -type QueryVersionCookie struct { - *xgb.Cookie -} +// Bytes writes a Range8 value to a byte slice. +func (v Range8) Bytes() []byte { + buf := make([]byte, 2) + b := 0 -// QueryVersion sends a checked request. -// If an error occurs, it will be returned with the reply by calling QueryVersionCookie.Reply() -func QueryVersion(c *xgb.Conn, MajorVersion uint16, MinorVersion uint16) QueryVersionCookie { - if _, ok := c.Extensions["RECORD"]; !ok { - panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") - } - cookie := c.NewCookie(true, true) - c.NewRequest(queryVersionRequest(c, MajorVersion, MinorVersion), cookie) - return QueryVersionCookie{cookie} -} + buf[b] = v.First + b += 1 -// QueryVersionUnchecked sends an unchecked request. -// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. -func QueryVersionUnchecked(c *xgb.Conn, MajorVersion uint16, MinorVersion uint16) QueryVersionCookie { - if _, ok := c.Extensions["RECORD"]; !ok { - panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") - } - cookie := c.NewCookie(false, true) - c.NewRequest(queryVersionRequest(c, MajorVersion, MinorVersion), cookie) - return QueryVersionCookie{cookie} -} + buf[b] = v.Last + b += 1 -// QueryVersionReply represents the data returned from a QueryVersion request. -type QueryVersionReply struct { - Sequence uint16 // sequence number of the request for this reply - Length uint32 // number of bytes in this reply - // padding: 1 bytes - MajorVersion uint16 - MinorVersion uint16 + return buf } -// Reply blocks and returns the reply data for a QueryVersion request. -func (cook QueryVersionCookie) Reply() (*QueryVersionReply, error) { - buf, err := cook.Cookie.Reply() - if err != nil { - return nil, err - } - if buf == nil { - return nil, nil +// Range8ListBytes writes a list of Range8 values to a byte slice. +func Range8ListBytes(buf []byte, list []Range8) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += xgb.Pad(len(structBytes)) } - return queryVersionReply(buf), nil + return b } -// queryVersionReply reads a byte slice into a QueryVersionReply value. -func queryVersionReply(buf []byte) *QueryVersionReply { - v := new(QueryVersionReply) - b := 1 // skip reply determinant - - b += 1 // padding - - v.Sequence = xgb.Get16(buf[b:]) - b += 2 +// Skipping definition for base type 'Bool' - v.Length = xgb.Get32(buf[b:]) // 4-byte units - b += 4 +// Skipping definition for base type 'Byte' - v.MajorVersion = xgb.Get16(buf[b:]) - b += 2 +// Skipping definition for base type 'Card8' - v.MinorVersion = xgb.Get16(buf[b:]) - b += 2 +// Skipping definition for base type 'Char' - return v -} +// Skipping definition for base type 'Void' -// Write request to wire for QueryVersion -// queryVersionRequest writes a QueryVersion request to a byte slice. -func queryVersionRequest(c *xgb.Conn, MajorVersion uint16, MinorVersion uint16) []byte { - size := 8 - b := 0 - buf := make([]byte, size) +// Skipping definition for base type 'Double' - buf[b] = c.Extensions["RECORD"] - b += 1 +// Skipping definition for base type 'Float' - buf[b] = 0 // request opcode - b += 1 +// Skipping definition for base type 'Int16' - xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units - b += 2 +// Skipping definition for base type 'Int32' - xgb.Put16(buf[b:], MajorVersion) - b += 2 +// Skipping definition for base type 'Int8' - xgb.Put16(buf[b:], MinorVersion) - b += 2 +// Skipping definition for base type 'Card16' - return buf -} +// Skipping definition for base type 'Card32' // CreateContextCookie is a cookie used only for CreateContext requests. type CreateContextCookie struct { @@ -687,50 +592,50 @@ func createContextRequest(c *xgb.Conn, Context Context, ElementHeader ElementHea return buf } -// RegisterClientsCookie is a cookie used only for RegisterClients requests. -type RegisterClientsCookie struct { +// DisableContextCookie is a cookie used only for DisableContext requests. +type DisableContextCookie struct { *xgb.Cookie } -// RegisterClients sends an unchecked request. +// DisableContext sends an unchecked request. // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. -func RegisterClients(c *xgb.Conn, Context Context, ElementHeader ElementHeader, NumClientSpecs uint32, NumRanges uint32, ClientSpecs []ClientSpec, Ranges []Range) RegisterClientsCookie { +func DisableContext(c *xgb.Conn, Context Context) DisableContextCookie { if _, ok := c.Extensions["RECORD"]; !ok { - panic("Cannot issue request 'RegisterClients' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") + panic("Cannot issue request 'DisableContext' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") } cookie := c.NewCookie(false, false) - c.NewRequest(registerClientsRequest(c, Context, ElementHeader, NumClientSpecs, NumRanges, ClientSpecs, Ranges), cookie) - return RegisterClientsCookie{cookie} + c.NewRequest(disableContextRequest(c, Context), cookie) + return DisableContextCookie{cookie} } -// RegisterClientsChecked sends a checked request. -// If an error occurs, it can be retrieved using RegisterClientsCookie.Check() -func RegisterClientsChecked(c *xgb.Conn, Context Context, ElementHeader ElementHeader, NumClientSpecs uint32, NumRanges uint32, ClientSpecs []ClientSpec, Ranges []Range) RegisterClientsCookie { +// DisableContextChecked sends a checked request. +// If an error occurs, it can be retrieved using DisableContextCookie.Check() +func DisableContextChecked(c *xgb.Conn, Context Context) DisableContextCookie { if _, ok := c.Extensions["RECORD"]; !ok { - panic("Cannot issue request 'RegisterClients' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") + panic("Cannot issue request 'DisableContext' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") } cookie := c.NewCookie(true, false) - c.NewRequest(registerClientsRequest(c, Context, ElementHeader, NumClientSpecs, NumRanges, ClientSpecs, Ranges), cookie) - return RegisterClientsCookie{cookie} + c.NewRequest(disableContextRequest(c, Context), cookie) + return DisableContextCookie{cookie} } // Check returns an error if one occurred for checked requests that are not expecting a reply. // This cannot be called for requests expecting a reply, nor for unchecked requests. -func (cook RegisterClientsCookie) Check() error { +func (cook DisableContextCookie) Check() error { return cook.Cookie.Check() } -// Write request to wire for RegisterClients -// registerClientsRequest writes a RegisterClients request to a byte slice. -func registerClientsRequest(c *xgb.Conn, Context Context, ElementHeader ElementHeader, NumClientSpecs uint32, NumRanges uint32, ClientSpecs []ClientSpec, Ranges []Range) []byte { - size := xgb.Pad(((20 + xgb.Pad((int(NumClientSpecs) * 4))) + xgb.Pad((int(NumRanges) * 24)))) +// Write request to wire for DisableContext +// disableContextRequest writes a DisableContext request to a byte slice. +func disableContextRequest(c *xgb.Conn, Context Context) []byte { + size := 8 b := 0 buf := make([]byte, size) buf[b] = c.Extensions["RECORD"] b += 1 - buf[b] = 2 // request opcode + buf[b] = 6 // request opcode b += 1 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units @@ -739,72 +644,173 @@ func registerClientsRequest(c *xgb.Conn, Context Context, ElementHeader ElementH xgb.Put32(buf[b:], uint32(Context)) b += 4 - buf[b] = byte(ElementHeader) + return buf +} + +// EnableContextCookie is a cookie used only for EnableContext requests. +type EnableContextCookie struct { + *xgb.Cookie +} + +// EnableContext sends a checked request. +// If an error occurs, it will be returned with the reply by calling EnableContextCookie.Reply() +func EnableContext(c *xgb.Conn, Context Context) EnableContextCookie { + if _, ok := c.Extensions["RECORD"]; !ok { + panic("Cannot issue request 'EnableContext' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(enableContextRequest(c, Context), cookie) + return EnableContextCookie{cookie} +} + +// EnableContextUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func EnableContextUnchecked(c *xgb.Conn, Context Context) EnableContextCookie { + if _, ok := c.Extensions["RECORD"]; !ok { + panic("Cannot issue request 'EnableContext' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(enableContextRequest(c, Context), cookie) + return EnableContextCookie{cookie} +} + +// EnableContextReply represents the data returned from a EnableContext request. +type EnableContextReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + Category byte + ElementHeader ElementHeader + ClientSwapped bool + // padding: 2 bytes + XidBase uint32 + ServerTime uint32 + RecSequenceNum uint32 + // padding: 8 bytes + Data []byte // size: xgb.Pad(((int(Length) * 4) * 1)) +} + +// Reply blocks and returns the reply data for a EnableContext request. +func (cook EnableContextCookie) Reply() (*EnableContextReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return enableContextReply(buf), nil +} + +// enableContextReply reads a byte slice into a EnableContextReply value. +func enableContextReply(buf []byte) *EnableContextReply { + v := new(EnableContextReply) + b := 1 // skip reply determinant + + v.Category = buf[b] b += 1 - b += 3 // padding + v.Sequence = xgb.Get16(buf[b:]) + b += 2 - xgb.Put32(buf[b:], NumClientSpecs) + v.Length = xgb.Get32(buf[b:]) // 4-byte units b += 4 - xgb.Put32(buf[b:], NumRanges) - b += 4 + v.ElementHeader = ElementHeader(buf[b]) + b += 1 - for i := 0; i < int(NumClientSpecs); i++ { - xgb.Put32(buf[b:], uint32(ClientSpecs[i])) - b += 4 + if buf[b] == 1 { + v.ClientSwapped = true + } else { + v.ClientSwapped = false } - b = xgb.Pad(b) + b += 1 - b += RangeListBytes(buf[b:], Ranges) + b += 2 // padding + + v.XidBase = xgb.Get32(buf[b:]) + b += 4 + + v.ServerTime = xgb.Get32(buf[b:]) + b += 4 + + v.RecSequenceNum = xgb.Get32(buf[b:]) + b += 4 + + b += 8 // padding + + v.Data = make([]byte, (int(v.Length) * 4)) + copy(v.Data[:(int(v.Length)*4)], buf[b:]) + b += xgb.Pad(int((int(v.Length) * 4))) + + return v +} + +// Write request to wire for EnableContext +// enableContextRequest writes a EnableContext request to a byte slice. +func enableContextRequest(c *xgb.Conn, Context Context) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + buf[b] = c.Extensions["RECORD"] + b += 1 + + buf[b] = 5 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Context)) + b += 4 return buf } -// UnregisterClientsCookie is a cookie used only for UnregisterClients requests. -type UnregisterClientsCookie struct { +// FreeContextCookie is a cookie used only for FreeContext requests. +type FreeContextCookie struct { *xgb.Cookie } -// UnregisterClients sends an unchecked request. +// FreeContext sends an unchecked request. // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. -func UnregisterClients(c *xgb.Conn, Context Context, NumClientSpecs uint32, ClientSpecs []ClientSpec) UnregisterClientsCookie { +func FreeContext(c *xgb.Conn, Context Context) FreeContextCookie { if _, ok := c.Extensions["RECORD"]; !ok { - panic("Cannot issue request 'UnregisterClients' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") + panic("Cannot issue request 'FreeContext' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") } cookie := c.NewCookie(false, false) - c.NewRequest(unregisterClientsRequest(c, Context, NumClientSpecs, ClientSpecs), cookie) - return UnregisterClientsCookie{cookie} + c.NewRequest(freeContextRequest(c, Context), cookie) + return FreeContextCookie{cookie} } -// UnregisterClientsChecked sends a checked request. -// If an error occurs, it can be retrieved using UnregisterClientsCookie.Check() -func UnregisterClientsChecked(c *xgb.Conn, Context Context, NumClientSpecs uint32, ClientSpecs []ClientSpec) UnregisterClientsCookie { +// FreeContextChecked sends a checked request. +// If an error occurs, it can be retrieved using FreeContextCookie.Check() +func FreeContextChecked(c *xgb.Conn, Context Context) FreeContextCookie { if _, ok := c.Extensions["RECORD"]; !ok { - panic("Cannot issue request 'UnregisterClients' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") + panic("Cannot issue request 'FreeContext' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") } cookie := c.NewCookie(true, false) - c.NewRequest(unregisterClientsRequest(c, Context, NumClientSpecs, ClientSpecs), cookie) - return UnregisterClientsCookie{cookie} + c.NewRequest(freeContextRequest(c, Context), cookie) + return FreeContextCookie{cookie} } // Check returns an error if one occurred for checked requests that are not expecting a reply. // This cannot be called for requests expecting a reply, nor for unchecked requests. -func (cook UnregisterClientsCookie) Check() error { +func (cook FreeContextCookie) Check() error { return cook.Cookie.Check() } -// Write request to wire for UnregisterClients -// unregisterClientsRequest writes a UnregisterClients request to a byte slice. -func unregisterClientsRequest(c *xgb.Conn, Context Context, NumClientSpecs uint32, ClientSpecs []ClientSpec) []byte { - size := xgb.Pad((12 + xgb.Pad((int(NumClientSpecs) * 4)))) +// Write request to wire for FreeContext +// freeContextRequest writes a FreeContext request to a byte slice. +func freeContextRequest(c *xgb.Conn, Context Context) []byte { + size := 8 b := 0 buf := make([]byte, size) buf[b] = c.Extensions["RECORD"] b += 1 - buf[b] = 3 // request opcode + buf[b] = 7 // request opcode b += 1 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units @@ -813,15 +819,6 @@ func unregisterClientsRequest(c *xgb.Conn, Context Context, NumClientSpecs uint3 xgb.Put32(buf[b:], uint32(Context)) b += 4 - xgb.Put32(buf[b:], NumClientSpecs) - b += 4 - - for i := 0; i < int(NumClientSpecs); i++ { - xgb.Put32(buf[b:], uint32(ClientSpecs[i])) - b += 4 - } - b = xgb.Pad(b) - return buf } @@ -932,50 +929,44 @@ func getContextRequest(c *xgb.Conn, Context Context) []byte { return buf } -// EnableContextCookie is a cookie used only for EnableContext requests. -type EnableContextCookie struct { +// QueryVersionCookie is a cookie used only for QueryVersion requests. +type QueryVersionCookie struct { *xgb.Cookie } -// EnableContext sends a checked request. -// If an error occurs, it will be returned with the reply by calling EnableContextCookie.Reply() -func EnableContext(c *xgb.Conn, Context Context) EnableContextCookie { +// QueryVersion sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryVersionCookie.Reply() +func QueryVersion(c *xgb.Conn, MajorVersion uint16, MinorVersion uint16) QueryVersionCookie { if _, ok := c.Extensions["RECORD"]; !ok { - panic("Cannot issue request 'EnableContext' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") + panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") } cookie := c.NewCookie(true, true) - c.NewRequest(enableContextRequest(c, Context), cookie) - return EnableContextCookie{cookie} + c.NewRequest(queryVersionRequest(c, MajorVersion, MinorVersion), cookie) + return QueryVersionCookie{cookie} } -// EnableContextUnchecked sends an unchecked request. +// QueryVersionUnchecked sends an unchecked request. // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. -func EnableContextUnchecked(c *xgb.Conn, Context Context) EnableContextCookie { +func QueryVersionUnchecked(c *xgb.Conn, MajorVersion uint16, MinorVersion uint16) QueryVersionCookie { if _, ok := c.Extensions["RECORD"]; !ok { - panic("Cannot issue request 'EnableContext' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") + panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") } cookie := c.NewCookie(false, true) - c.NewRequest(enableContextRequest(c, Context), cookie) - return EnableContextCookie{cookie} + c.NewRequest(queryVersionRequest(c, MajorVersion, MinorVersion), cookie) + return QueryVersionCookie{cookie} } -// EnableContextReply represents the data returned from a EnableContext request. -type EnableContextReply struct { - Sequence uint16 // sequence number of the request for this reply - Length uint32 // number of bytes in this reply - Category byte - ElementHeader ElementHeader - ClientSwapped bool - // padding: 2 bytes - XidBase uint32 - ServerTime uint32 - RecSequenceNum uint32 - // padding: 8 bytes - Data []byte // size: xgb.Pad(((int(Length) * 4) * 1)) +// QueryVersionReply represents the data returned from a QueryVersion request. +type QueryVersionReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + MajorVersion uint16 + MinorVersion uint16 } -// Reply blocks and returns the reply data for a EnableContext request. -func (cook EnableContextCookie) Reply() (*EnableContextReply, error) { +// Reply blocks and returns the reply data for a QueryVersion request. +func (cook QueryVersionCookie) Reply() (*QueryVersionReply, error) { buf, err := cook.Cookie.Reply() if err != nil { return nil, err @@ -983,16 +974,15 @@ func (cook EnableContextCookie) Reply() (*EnableContextReply, error) { if buf == nil { return nil, nil } - return enableContextReply(buf), nil + return queryVersionReply(buf), nil } -// enableContextReply reads a byte slice into a EnableContextReply value. -func enableContextReply(buf []byte) *EnableContextReply { - v := new(EnableContextReply) +// queryVersionReply reads a byte slice into a QueryVersionReply value. +func queryVersionReply(buf []byte) *QueryVersionReply { + v := new(QueryVersionReply) b := 1 // skip reply determinant - v.Category = buf[b] - b += 1 + b += 1 // padding v.Sequence = xgb.Get16(buf[b:]) b += 2 @@ -1000,39 +990,18 @@ func enableContextReply(buf []byte) *EnableContextReply { v.Length = xgb.Get32(buf[b:]) // 4-byte units b += 4 - v.ElementHeader = ElementHeader(buf[b]) - b += 1 - - if buf[b] == 1 { - v.ClientSwapped = true - } else { - v.ClientSwapped = false - } - b += 1 - - b += 2 // padding - - v.XidBase = xgb.Get32(buf[b:]) - b += 4 - - v.ServerTime = xgb.Get32(buf[b:]) - b += 4 - - v.RecSequenceNum = xgb.Get32(buf[b:]) - b += 4 - - b += 8 // padding + v.MajorVersion = xgb.Get16(buf[b:]) + b += 2 - v.Data = make([]byte, (int(v.Length) * 4)) - copy(v.Data[:(int(v.Length)*4)], buf[b:]) - b += xgb.Pad(int((int(v.Length) * 4))) + v.MinorVersion = xgb.Get16(buf[b:]) + b += 2 return v } -// Write request to wire for EnableContext -// enableContextRequest writes a EnableContext request to a byte slice. -func enableContextRequest(c *xgb.Conn, Context Context) []byte { +// Write request to wire for QueryVersion +// queryVersionRequest writes a QueryVersion request to a byte slice. +func queryVersionRequest(c *xgb.Conn, MajorVersion uint16, MinorVersion uint16) []byte { size := 8 b := 0 buf := make([]byte, size) @@ -1040,62 +1009,65 @@ func enableContextRequest(c *xgb.Conn, Context Context) []byte { buf[b] = c.Extensions["RECORD"] b += 1 - buf[b] = 5 // request opcode + buf[b] = 0 // request opcode b += 1 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units b += 2 - xgb.Put32(buf[b:], uint32(Context)) - b += 4 + xgb.Put16(buf[b:], MajorVersion) + b += 2 + + xgb.Put16(buf[b:], MinorVersion) + b += 2 return buf } -// DisableContextCookie is a cookie used only for DisableContext requests. -type DisableContextCookie struct { +// RegisterClientsCookie is a cookie used only for RegisterClients requests. +type RegisterClientsCookie struct { *xgb.Cookie } -// DisableContext sends an unchecked request. +// RegisterClients sends an unchecked request. // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. -func DisableContext(c *xgb.Conn, Context Context) DisableContextCookie { +func RegisterClients(c *xgb.Conn, Context Context, ElementHeader ElementHeader, NumClientSpecs uint32, NumRanges uint32, ClientSpecs []ClientSpec, Ranges []Range) RegisterClientsCookie { if _, ok := c.Extensions["RECORD"]; !ok { - panic("Cannot issue request 'DisableContext' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") + panic("Cannot issue request 'RegisterClients' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") } cookie := c.NewCookie(false, false) - c.NewRequest(disableContextRequest(c, Context), cookie) - return DisableContextCookie{cookie} + c.NewRequest(registerClientsRequest(c, Context, ElementHeader, NumClientSpecs, NumRanges, ClientSpecs, Ranges), cookie) + return RegisterClientsCookie{cookie} } -// DisableContextChecked sends a checked request. -// If an error occurs, it can be retrieved using DisableContextCookie.Check() -func DisableContextChecked(c *xgb.Conn, Context Context) DisableContextCookie { +// RegisterClientsChecked sends a checked request. +// If an error occurs, it can be retrieved using RegisterClientsCookie.Check() +func RegisterClientsChecked(c *xgb.Conn, Context Context, ElementHeader ElementHeader, NumClientSpecs uint32, NumRanges uint32, ClientSpecs []ClientSpec, Ranges []Range) RegisterClientsCookie { if _, ok := c.Extensions["RECORD"]; !ok { - panic("Cannot issue request 'DisableContext' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") + panic("Cannot issue request 'RegisterClients' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") } cookie := c.NewCookie(true, false) - c.NewRequest(disableContextRequest(c, Context), cookie) - return DisableContextCookie{cookie} + c.NewRequest(registerClientsRequest(c, Context, ElementHeader, NumClientSpecs, NumRanges, ClientSpecs, Ranges), cookie) + return RegisterClientsCookie{cookie} } // Check returns an error if one occurred for checked requests that are not expecting a reply. // This cannot be called for requests expecting a reply, nor for unchecked requests. -func (cook DisableContextCookie) Check() error { +func (cook RegisterClientsCookie) Check() error { return cook.Cookie.Check() } -// Write request to wire for DisableContext -// disableContextRequest writes a DisableContext request to a byte slice. -func disableContextRequest(c *xgb.Conn, Context Context) []byte { - size := 8 +// Write request to wire for RegisterClients +// registerClientsRequest writes a RegisterClients request to a byte slice. +func registerClientsRequest(c *xgb.Conn, Context Context, ElementHeader ElementHeader, NumClientSpecs uint32, NumRanges uint32, ClientSpecs []ClientSpec, Ranges []Range) []byte { + size := xgb.Pad(((20 + xgb.Pad((int(NumClientSpecs) * 4))) + xgb.Pad((int(NumRanges) * 24)))) b := 0 buf := make([]byte, size) buf[b] = c.Extensions["RECORD"] b += 1 - buf[b] = 6 // request opcode + buf[b] = 2 // request opcode b += 1 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units @@ -1104,53 +1076,72 @@ func disableContextRequest(c *xgb.Conn, Context Context) []byte { xgb.Put32(buf[b:], uint32(Context)) b += 4 + buf[b] = byte(ElementHeader) + b += 1 + + b += 3 // padding + + xgb.Put32(buf[b:], NumClientSpecs) + b += 4 + + xgb.Put32(buf[b:], NumRanges) + b += 4 + + for i := 0; i < int(NumClientSpecs); i++ { + xgb.Put32(buf[b:], uint32(ClientSpecs[i])) + b += 4 + } + b = xgb.Pad(b) + + b += RangeListBytes(buf[b:], Ranges) + return buf } -// FreeContextCookie is a cookie used only for FreeContext requests. -type FreeContextCookie struct { +// UnregisterClientsCookie is a cookie used only for UnregisterClients requests. +type UnregisterClientsCookie struct { *xgb.Cookie } -// FreeContext sends an unchecked request. +// UnregisterClients sends an unchecked request. // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. -func FreeContext(c *xgb.Conn, Context Context) FreeContextCookie { +func UnregisterClients(c *xgb.Conn, Context Context, NumClientSpecs uint32, ClientSpecs []ClientSpec) UnregisterClientsCookie { if _, ok := c.Extensions["RECORD"]; !ok { - panic("Cannot issue request 'FreeContext' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") + panic("Cannot issue request 'UnregisterClients' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") } cookie := c.NewCookie(false, false) - c.NewRequest(freeContextRequest(c, Context), cookie) - return FreeContextCookie{cookie} + c.NewRequest(unregisterClientsRequest(c, Context, NumClientSpecs, ClientSpecs), cookie) + return UnregisterClientsCookie{cookie} } -// FreeContextChecked sends a checked request. -// If an error occurs, it can be retrieved using FreeContextCookie.Check() -func FreeContextChecked(c *xgb.Conn, Context Context) FreeContextCookie { +// UnregisterClientsChecked sends a checked request. +// If an error occurs, it can be retrieved using UnregisterClientsCookie.Check() +func UnregisterClientsChecked(c *xgb.Conn, Context Context, NumClientSpecs uint32, ClientSpecs []ClientSpec) UnregisterClientsCookie { if _, ok := c.Extensions["RECORD"]; !ok { - panic("Cannot issue request 'FreeContext' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") + panic("Cannot issue request 'UnregisterClients' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") } cookie := c.NewCookie(true, false) - c.NewRequest(freeContextRequest(c, Context), cookie) - return FreeContextCookie{cookie} + c.NewRequest(unregisterClientsRequest(c, Context, NumClientSpecs, ClientSpecs), cookie) + return UnregisterClientsCookie{cookie} } // Check returns an error if one occurred for checked requests that are not expecting a reply. // This cannot be called for requests expecting a reply, nor for unchecked requests. -func (cook FreeContextCookie) Check() error { +func (cook UnregisterClientsCookie) Check() error { return cook.Cookie.Check() } -// Write request to wire for FreeContext -// freeContextRequest writes a FreeContext request to a byte slice. -func freeContextRequest(c *xgb.Conn, Context Context) []byte { - size := 8 +// Write request to wire for UnregisterClients +// unregisterClientsRequest writes a UnregisterClients request to a byte slice. +func unregisterClientsRequest(c *xgb.Conn, Context Context, NumClientSpecs uint32, ClientSpecs []ClientSpec) []byte { + size := xgb.Pad((12 + xgb.Pad((int(NumClientSpecs) * 4)))) b := 0 buf := make([]byte, size) buf[b] = c.Extensions["RECORD"] b += 1 - buf[b] = 7 // request opcode + buf[b] = 3 // request opcode b += 1 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units @@ -1159,5 +1150,14 @@ func freeContextRequest(c *xgb.Conn, Context Context) []byte { xgb.Put32(buf[b:], uint32(Context)) b += 4 + xgb.Put32(buf[b:], NumClientSpecs) + b += 4 + + for i := 0; i < int(NumClientSpecs); i++ { + xgb.Put32(buf[b:], uint32(ClientSpecs[i])) + b += 4 + } + b = xgb.Pad(b) + return buf } -- cgit v1.2.3 From b06a8ca97625c1134449c3af65d9ac3fb251a613 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Sun, 11 Aug 2013 20:45:36 -0400 Subject: Don't needlessly change source files every time. --- nexgb/record/record.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'nexgb/record/record.go') diff --git a/nexgb/record/record.go b/nexgb/record/record.go index 2bbfe1c..8cb495e 100644 --- a/nexgb/record/record.go +++ b/nexgb/record/record.go @@ -1,10 +1,7 @@ // Package record is the X client API for the RECORD extension. package record -/* - This file was generated by record.xml on Aug 11 2013 8:39:43pm EDT. - This file is automatically generated. Edit at your peril! -*/ +// This file is automatically generated from record.xml. Edit at your peril! import ( "github.com/BurntSushi/xgb" -- cgit v1.2.3 From 38b293e74db6631873d5dfd74cf731eb7b76737d Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Sun, 11 Aug 2013 20:54:15 -0400 Subject: Padding on a list is on the length of the list. There was a bug where padding was being computed on each element of the list. Close #5. --- nexgb/record/record.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'nexgb/record/record.go') diff --git a/nexgb/record/record.go b/nexgb/record/record.go index 8cb495e..2644f13 100644 --- a/nexgb/record/record.go +++ b/nexgb/record/record.go @@ -143,9 +143,9 @@ func ClientInfoListBytes(buf []byte, list []ClientInfo) int { for _, item := range list { structBytes = item.Bytes() copy(buf[b:], structBytes) - b += xgb.Pad(len(structBytes)) + b += len(structBytes) } - return b + return xgb.Pad(b) } // ClientInfoListSize computes the size (bytes) of a list of ClientInfo values. @@ -232,9 +232,9 @@ func ExtRangeListBytes(buf []byte, list []ExtRange) int { for _, item := range list { structBytes = item.Bytes() copy(buf[b:], structBytes) - b += xgb.Pad(len(structBytes)) + b += len(structBytes) } - return b + return xgb.Pad(b) } const ( @@ -378,9 +378,9 @@ func RangeListBytes(buf []byte, list []Range) int { for _, item := range list { structBytes = item.Bytes() copy(buf[b:], structBytes) - b += xgb.Pad(len(structBytes)) + b += len(structBytes) } - return b + return xgb.Pad(b) } type Range16 struct { @@ -432,9 +432,9 @@ func Range16ListBytes(buf []byte, list []Range16) int { for _, item := range list { structBytes = item.Bytes() copy(buf[b:], structBytes) - b += xgb.Pad(len(structBytes)) + b += len(structBytes) } - return b + return xgb.Pad(b) } type Range8 struct { @@ -486,9 +486,9 @@ func Range8ListBytes(buf []byte, list []Range8) int { for _, item := range list { structBytes = item.Bytes() copy(buf[b:], structBytes) - b += xgb.Pad(len(structBytes)) + b += len(structBytes) } - return b + return xgb.Pad(b) } // Skipping definition for base type 'Bool' -- cgit v1.2.3 From 2dc9914b5e6b74c353771e56e90dfd2dd33e0202 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Sat, 28 Dec 2013 09:33:09 -0500 Subject: When writing, don't pad the length of bytes produced from inner structs/unions. Each type should take care of its own padding. Close #14. --- nexgb/record/record.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'nexgb/record/record.go') diff --git a/nexgb/record/record.go b/nexgb/record/record.go index 2644f13..3777422 100644 --- a/nexgb/record/record.go +++ b/nexgb/record/record.go @@ -213,13 +213,13 @@ func (v ExtRange) Bytes() []byte { { structBytes := v.Major.Bytes() copy(buf[b:], structBytes) - b += xgb.Pad(len(structBytes)) + b += len(structBytes) } { structBytes := v.Minor.Bytes() copy(buf[b:], structBytes) - b += xgb.Pad(len(structBytes)) + b += len(structBytes) } return buf @@ -315,43 +315,43 @@ func (v Range) Bytes() []byte { { structBytes := v.CoreRequests.Bytes() copy(buf[b:], structBytes) - b += xgb.Pad(len(structBytes)) + b += len(structBytes) } { structBytes := v.CoreReplies.Bytes() copy(buf[b:], structBytes) - b += xgb.Pad(len(structBytes)) + b += len(structBytes) } { structBytes := v.ExtRequests.Bytes() copy(buf[b:], structBytes) - b += xgb.Pad(len(structBytes)) + b += len(structBytes) } { structBytes := v.ExtReplies.Bytes() copy(buf[b:], structBytes) - b += xgb.Pad(len(structBytes)) + b += len(structBytes) } { structBytes := v.DeliveredEvents.Bytes() copy(buf[b:], structBytes) - b += xgb.Pad(len(structBytes)) + b += len(structBytes) } { structBytes := v.DeviceEvents.Bytes() copy(buf[b:], structBytes) - b += xgb.Pad(len(structBytes)) + b += len(structBytes) } { structBytes := v.Errors.Bytes() copy(buf[b:], structBytes) - b += xgb.Pad(len(structBytes)) + b += len(structBytes) } if v.ClientStarted { -- cgit v1.2.3 From a548d9d0f7b889627c43b18811357fad88760b2d Mon Sep 17 00:00:00 2001 From: aarzilli Date: Fri, 2 May 2014 15:09:23 +0200 Subject: Fix Issue #21: automatic calculation of alignment padding after lists --- nexgb/record/record.go | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) (limited to 'nexgb/record/record.go') diff --git a/nexgb/record/record.go b/nexgb/record/record.go index 3777422..30be090 100644 --- a/nexgb/record/record.go +++ b/nexgb/record/record.go @@ -133,7 +133,7 @@ func (v ClientInfo) Bytes() []byte { b += RangeListBytes(buf[b:], v.Ranges) - return buf + return buf[:b] } // ClientInfoListBytes writes a list of ClientInfo values to a byte slice. @@ -222,7 +222,7 @@ func (v ExtRange) Bytes() []byte { b += len(structBytes) } - return buf + return buf[:b] } // ExtRangeListBytes writes a list of ExtRange values to a byte slice. @@ -368,7 +368,7 @@ func (v Range) Bytes() []byte { } b += 1 - return buf + return buf[:b] } // RangeListBytes writes a list of Range values to a byte slice. @@ -422,7 +422,7 @@ func (v Range16) Bytes() []byte { xgb.Put16(buf[b:], v.Last) b += 2 - return buf + return buf[:b] } // Range16ListBytes writes a list of Range16 values to a byte slice. @@ -476,7 +476,7 @@ func (v Range8) Bytes() []byte { buf[b] = v.Last b += 1 - return buf + return buf[:b] } // Range8ListBytes writes a list of Range8 values to a byte slice. @@ -551,7 +551,7 @@ func (cook CreateContextCookie) Check() error { // Write request to wire for CreateContext // createContextRequest writes a CreateContext request to a byte slice. func createContextRequest(c *xgb.Conn, Context Context, ElementHeader ElementHeader, NumClientSpecs uint32, NumRanges uint32, ClientSpecs []ClientSpec, Ranges []Range) []byte { - size := xgb.Pad(((20 + xgb.Pad((int(NumClientSpecs) * 4))) + xgb.Pad((int(NumRanges) * 24)))) + size := xgb.Pad((((20 + xgb.Pad((int(NumClientSpecs) * 4))) + 4) + xgb.Pad((int(NumRanges) * 24)))) b := 0 buf := make([]byte, size) @@ -561,7 +561,7 @@ func createContextRequest(c *xgb.Conn, Context Context, ElementHeader ElementHea buf[b] = 1 // request opcode b += 1 - xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + blen := b b += 2 xgb.Put32(buf[b:], uint32(Context)) @@ -582,11 +582,14 @@ func createContextRequest(c *xgb.Conn, Context Context, ElementHeader ElementHea xgb.Put32(buf[b:], uint32(ClientSpecs[i])) b += 4 } - b = xgb.Pad(b) + + b = (b + 3) & ^3 // alignment gap b += RangeListBytes(buf[b:], Ranges) - return buf + b = xgb.Pad(b) + xgb.Put16(buf[blen:], uint16(b/4)) // write request size in 4-byte units + return buf[:b] } // DisableContextCookie is a cookie used only for DisableContext requests. @@ -737,7 +740,7 @@ func enableContextReply(buf []byte) *EnableContextReply { v.Data = make([]byte, (int(v.Length) * 4)) copy(v.Data[:(int(v.Length)*4)], buf[b:]) - b += xgb.Pad(int((int(v.Length) * 4))) + b += int((int(v.Length) * 4)) return v } @@ -1057,7 +1060,7 @@ func (cook RegisterClientsCookie) Check() error { // Write request to wire for RegisterClients // registerClientsRequest writes a RegisterClients request to a byte slice. func registerClientsRequest(c *xgb.Conn, Context Context, ElementHeader ElementHeader, NumClientSpecs uint32, NumRanges uint32, ClientSpecs []ClientSpec, Ranges []Range) []byte { - size := xgb.Pad(((20 + xgb.Pad((int(NumClientSpecs) * 4))) + xgb.Pad((int(NumRanges) * 24)))) + size := xgb.Pad((((20 + xgb.Pad((int(NumClientSpecs) * 4))) + 4) + xgb.Pad((int(NumRanges) * 24)))) b := 0 buf := make([]byte, size) @@ -1067,7 +1070,7 @@ func registerClientsRequest(c *xgb.Conn, Context Context, ElementHeader ElementH buf[b] = 2 // request opcode b += 1 - xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + blen := b b += 2 xgb.Put32(buf[b:], uint32(Context)) @@ -1088,11 +1091,14 @@ func registerClientsRequest(c *xgb.Conn, Context Context, ElementHeader ElementH xgb.Put32(buf[b:], uint32(ClientSpecs[i])) b += 4 } - b = xgb.Pad(b) + + b = (b + 3) & ^3 // alignment gap b += RangeListBytes(buf[b:], Ranges) - return buf + b = xgb.Pad(b) + xgb.Put16(buf[blen:], uint16(b/4)) // write request size in 4-byte units + return buf[:b] } // UnregisterClientsCookie is a cookie used only for UnregisterClients requests. @@ -1154,7 +1160,6 @@ func unregisterClientsRequest(c *xgb.Conn, Context Context, NumClientSpecs uint3 xgb.Put32(buf[b:], uint32(ClientSpecs[i])) b += 4 } - b = xgb.Pad(b) return buf } -- cgit v1.2.3 From becaf43dcb3e9832c3eb951ff9908ed697868152 Mon Sep 17 00:00:00 2001 From: aarzilli Date: Tue, 1 Mar 2016 15:41:38 +0100 Subject: Read/Write mutex for Extensions map --- nexgb/record/record.go | 53 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 3 deletions(-) (limited to 'nexgb/record/record.go') diff --git a/nexgb/record/record.go b/nexgb/record/record.go index 30be090..5469170 100644 --- a/nexgb/record/record.go +++ b/nexgb/record/record.go @@ -19,16 +19,15 @@ func Init(c *xgb.Conn) error { return xgb.Errorf("No extension named RECORD could be found on on the server.") } - xgb.ExtLock.Lock() + c.ExtLock.Lock() c.Extensions["RECORD"] = reply.MajorOpcode + c.ExtLock.Unlock() for evNum, fun := range xgb.NewExtEventFuncs["RECORD"] { xgb.NewEventFuncs[int(reply.FirstEvent)+evNum] = fun } for errNum, fun := range xgb.NewExtErrorFuncs["RECORD"] { xgb.NewErrorFuncs[int(reply.FirstError)+errNum] = fun } - xgb.ExtLock.Unlock() - return nil } @@ -523,6 +522,8 @@ type CreateContextCookie struct { // CreateContext sends an unchecked request. // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. func CreateContext(c *xgb.Conn, Context Context, ElementHeader ElementHeader, NumClientSpecs uint32, NumRanges uint32, ClientSpecs []ClientSpec, Ranges []Range) CreateContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() if _, ok := c.Extensions["RECORD"]; !ok { panic("Cannot issue request 'CreateContext' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") } @@ -534,6 +535,8 @@ func CreateContext(c *xgb.Conn, Context Context, ElementHeader ElementHeader, Nu // CreateContextChecked sends a checked request. // If an error occurs, it can be retrieved using CreateContextCookie.Check() func CreateContextChecked(c *xgb.Conn, Context Context, ElementHeader ElementHeader, NumClientSpecs uint32, NumRanges uint32, ClientSpecs []ClientSpec, Ranges []Range) CreateContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() if _, ok := c.Extensions["RECORD"]; !ok { panic("Cannot issue request 'CreateContext' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") } @@ -555,7 +558,9 @@ func createContextRequest(c *xgb.Conn, Context Context, ElementHeader ElementHea b := 0 buf := make([]byte, size) + c.ExtLock.RLock() buf[b] = c.Extensions["RECORD"] + c.ExtLock.RUnlock() b += 1 buf[b] = 1 // request opcode @@ -600,6 +605,8 @@ type DisableContextCookie struct { // DisableContext sends an unchecked request. // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. func DisableContext(c *xgb.Conn, Context Context) DisableContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() if _, ok := c.Extensions["RECORD"]; !ok { panic("Cannot issue request 'DisableContext' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") } @@ -611,6 +618,8 @@ func DisableContext(c *xgb.Conn, Context Context) DisableContextCookie { // DisableContextChecked sends a checked request. // If an error occurs, it can be retrieved using DisableContextCookie.Check() func DisableContextChecked(c *xgb.Conn, Context Context) DisableContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() if _, ok := c.Extensions["RECORD"]; !ok { panic("Cannot issue request 'DisableContext' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") } @@ -632,7 +641,9 @@ func disableContextRequest(c *xgb.Conn, Context Context) []byte { b := 0 buf := make([]byte, size) + c.ExtLock.RLock() buf[b] = c.Extensions["RECORD"] + c.ExtLock.RUnlock() b += 1 buf[b] = 6 // request opcode @@ -655,6 +666,8 @@ type EnableContextCookie struct { // EnableContext sends a checked request. // If an error occurs, it will be returned with the reply by calling EnableContextCookie.Reply() func EnableContext(c *xgb.Conn, Context Context) EnableContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() if _, ok := c.Extensions["RECORD"]; !ok { panic("Cannot issue request 'EnableContext' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") } @@ -666,6 +679,8 @@ func EnableContext(c *xgb.Conn, Context Context) EnableContextCookie { // EnableContextUnchecked sends an unchecked request. // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. func EnableContextUnchecked(c *xgb.Conn, Context Context) EnableContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() if _, ok := c.Extensions["RECORD"]; !ok { panic("Cannot issue request 'EnableContext' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") } @@ -752,7 +767,9 @@ func enableContextRequest(c *xgb.Conn, Context Context) []byte { b := 0 buf := make([]byte, size) + c.ExtLock.RLock() buf[b] = c.Extensions["RECORD"] + c.ExtLock.RUnlock() b += 1 buf[b] = 5 // request opcode @@ -775,6 +792,8 @@ type FreeContextCookie struct { // FreeContext sends an unchecked request. // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. func FreeContext(c *xgb.Conn, Context Context) FreeContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() if _, ok := c.Extensions["RECORD"]; !ok { panic("Cannot issue request 'FreeContext' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") } @@ -786,6 +805,8 @@ func FreeContext(c *xgb.Conn, Context Context) FreeContextCookie { // FreeContextChecked sends a checked request. // If an error occurs, it can be retrieved using FreeContextCookie.Check() func FreeContextChecked(c *xgb.Conn, Context Context) FreeContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() if _, ok := c.Extensions["RECORD"]; !ok { panic("Cannot issue request 'FreeContext' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") } @@ -807,7 +828,9 @@ func freeContextRequest(c *xgb.Conn, Context Context) []byte { b := 0 buf := make([]byte, size) + c.ExtLock.RLock() buf[b] = c.Extensions["RECORD"] + c.ExtLock.RUnlock() b += 1 buf[b] = 7 // request opcode @@ -830,6 +853,8 @@ type GetContextCookie struct { // GetContext sends a checked request. // If an error occurs, it will be returned with the reply by calling GetContextCookie.Reply() func GetContext(c *xgb.Conn, Context Context) GetContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() if _, ok := c.Extensions["RECORD"]; !ok { panic("Cannot issue request 'GetContext' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") } @@ -841,6 +866,8 @@ func GetContext(c *xgb.Conn, Context Context) GetContextCookie { // GetContextUnchecked sends an unchecked request. // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. func GetContextUnchecked(c *xgb.Conn, Context Context) GetContextCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() if _, ok := c.Extensions["RECORD"]; !ok { panic("Cannot issue request 'GetContext' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") } @@ -914,7 +941,9 @@ func getContextRequest(c *xgb.Conn, Context Context) []byte { b := 0 buf := make([]byte, size) + c.ExtLock.RLock() buf[b] = c.Extensions["RECORD"] + c.ExtLock.RUnlock() b += 1 buf[b] = 4 // request opcode @@ -937,6 +966,8 @@ type QueryVersionCookie struct { // QueryVersion sends a checked request. // If an error occurs, it will be returned with the reply by calling QueryVersionCookie.Reply() func QueryVersion(c *xgb.Conn, MajorVersion uint16, MinorVersion uint16) QueryVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() if _, ok := c.Extensions["RECORD"]; !ok { panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") } @@ -948,6 +979,8 @@ func QueryVersion(c *xgb.Conn, MajorVersion uint16, MinorVersion uint16) QueryVe // QueryVersionUnchecked sends an unchecked request. // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. func QueryVersionUnchecked(c *xgb.Conn, MajorVersion uint16, MinorVersion uint16) QueryVersionCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() if _, ok := c.Extensions["RECORD"]; !ok { panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") } @@ -1006,7 +1039,9 @@ func queryVersionRequest(c *xgb.Conn, MajorVersion uint16, MinorVersion uint16) b := 0 buf := make([]byte, size) + c.ExtLock.RLock() buf[b] = c.Extensions["RECORD"] + c.ExtLock.RUnlock() b += 1 buf[b] = 0 // request opcode @@ -1032,6 +1067,8 @@ type RegisterClientsCookie struct { // RegisterClients sends an unchecked request. // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. func RegisterClients(c *xgb.Conn, Context Context, ElementHeader ElementHeader, NumClientSpecs uint32, NumRanges uint32, ClientSpecs []ClientSpec, Ranges []Range) RegisterClientsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() if _, ok := c.Extensions["RECORD"]; !ok { panic("Cannot issue request 'RegisterClients' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") } @@ -1043,6 +1080,8 @@ func RegisterClients(c *xgb.Conn, Context Context, ElementHeader ElementHeader, // RegisterClientsChecked sends a checked request. // If an error occurs, it can be retrieved using RegisterClientsCookie.Check() func RegisterClientsChecked(c *xgb.Conn, Context Context, ElementHeader ElementHeader, NumClientSpecs uint32, NumRanges uint32, ClientSpecs []ClientSpec, Ranges []Range) RegisterClientsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() if _, ok := c.Extensions["RECORD"]; !ok { panic("Cannot issue request 'RegisterClients' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") } @@ -1064,7 +1103,9 @@ func registerClientsRequest(c *xgb.Conn, Context Context, ElementHeader ElementH b := 0 buf := make([]byte, size) + c.ExtLock.RLock() buf[b] = c.Extensions["RECORD"] + c.ExtLock.RUnlock() b += 1 buf[b] = 2 // request opcode @@ -1109,6 +1150,8 @@ type UnregisterClientsCookie struct { // UnregisterClients sends an unchecked request. // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. func UnregisterClients(c *xgb.Conn, Context Context, NumClientSpecs uint32, ClientSpecs []ClientSpec) UnregisterClientsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() if _, ok := c.Extensions["RECORD"]; !ok { panic("Cannot issue request 'UnregisterClients' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") } @@ -1120,6 +1163,8 @@ func UnregisterClients(c *xgb.Conn, Context Context, NumClientSpecs uint32, Clie // UnregisterClientsChecked sends a checked request. // If an error occurs, it can be retrieved using UnregisterClientsCookie.Check() func UnregisterClientsChecked(c *xgb.Conn, Context Context, NumClientSpecs uint32, ClientSpecs []ClientSpec) UnregisterClientsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() if _, ok := c.Extensions["RECORD"]; !ok { panic("Cannot issue request 'UnregisterClients' using the uninitialized extension 'RECORD'. record.Init(connObj) must be called first.") } @@ -1141,7 +1186,9 @@ func unregisterClientsRequest(c *xgb.Conn, Context Context, NumClientSpecs uint3 b := 0 buf := make([]byte, size) + c.ExtLock.RLock() buf[b] = c.Extensions["RECORD"] + c.ExtLock.RUnlock() b += 1 buf[b] = 3 // request opcode -- cgit v1.2.3 From 3906399e7c2a40fbaf355de572cf50a314083f64 Mon Sep 17 00:00:00 2001 From: aarzilli Date: Wed, 18 Jan 2017 10:52:16 +0100 Subject: Regenerated from xcb-proto 1.12 --- nexgb/record/record.go | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) (limited to 'nexgb/record/record.go') diff --git a/nexgb/record/record.go b/nexgb/record/record.go index 5469170..1cb022b 100644 --- a/nexgb/record/record.go +++ b/nexgb/record/record.go @@ -554,7 +554,7 @@ func (cook CreateContextCookie) Check() error { // Write request to wire for CreateContext // createContextRequest writes a CreateContext request to a byte slice. func createContextRequest(c *xgb.Conn, Context Context, ElementHeader ElementHeader, NumClientSpecs uint32, NumRanges uint32, ClientSpecs []ClientSpec, Ranges []Range) []byte { - size := xgb.Pad((((20 + xgb.Pad((int(NumClientSpecs) * 4))) + 4) + xgb.Pad((int(NumRanges) * 24)))) + size := xgb.Pad(((20 + xgb.Pad((int(NumClientSpecs) * 4))) + xgb.Pad((int(NumRanges) * 24)))) b := 0 buf := make([]byte, size) @@ -566,7 +566,7 @@ func createContextRequest(c *xgb.Conn, Context Context, ElementHeader ElementHea buf[b] = 1 // request opcode b += 1 - blen := b + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units b += 2 xgb.Put32(buf[b:], uint32(Context)) @@ -588,13 +588,9 @@ func createContextRequest(c *xgb.Conn, Context Context, ElementHeader ElementHea b += 4 } - b = (b + 3) & ^3 // alignment gap - b += RangeListBytes(buf[b:], Ranges) - b = xgb.Pad(b) - xgb.Put16(buf[blen:], uint16(b/4)) // write request size in 4-byte units - return buf[:b] + return buf } // DisableContextCookie is a cookie used only for DisableContext requests. @@ -1099,7 +1095,7 @@ func (cook RegisterClientsCookie) Check() error { // Write request to wire for RegisterClients // registerClientsRequest writes a RegisterClients request to a byte slice. func registerClientsRequest(c *xgb.Conn, Context Context, ElementHeader ElementHeader, NumClientSpecs uint32, NumRanges uint32, ClientSpecs []ClientSpec, Ranges []Range) []byte { - size := xgb.Pad((((20 + xgb.Pad((int(NumClientSpecs) * 4))) + 4) + xgb.Pad((int(NumRanges) * 24)))) + size := xgb.Pad(((20 + xgb.Pad((int(NumClientSpecs) * 4))) + xgb.Pad((int(NumRanges) * 24)))) b := 0 buf := make([]byte, size) @@ -1111,7 +1107,7 @@ func registerClientsRequest(c *xgb.Conn, Context Context, ElementHeader ElementH buf[b] = 2 // request opcode b += 1 - blen := b + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units b += 2 xgb.Put32(buf[b:], uint32(Context)) @@ -1133,13 +1129,9 @@ func registerClientsRequest(c *xgb.Conn, Context Context, ElementHeader ElementH b += 4 } - b = (b + 3) & ^3 // alignment gap - b += RangeListBytes(buf[b:], Ranges) - b = xgb.Pad(b) - xgb.Put16(buf[blen:], uint16(b/4)) // write request size in 4-byte units - return buf[:b] + return buf } // UnregisterClientsCookie is a cookie used only for UnregisterClients requests. -- cgit v1.2.3