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/bigreq/bigreq.go | 140 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 nexgb/bigreq/bigreq.go (limited to 'nexgb/bigreq') diff --git a/nexgb/bigreq/bigreq.go b/nexgb/bigreq/bigreq.go new file mode 100644 index 0000000..8bb05c1 --- /dev/null +++ b/nexgb/bigreq/bigreq.go @@ -0,0 +1,140 @@ +package bigreq + +/* + This file was generated by bigreq.xml on May 10 2012 4:20:27pm 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 BIG-REQUESTS extension. +func Init(c *xgb.Conn) error { + reply, err := xproto.QueryExtension(c, 12, "BIG-REQUESTS").Reply() + switch { + case err != nil: + return err + case !reply.Present: + return xgb.Errorf("No extension named BIG-REQUESTS could be found on on the server.") + } + + xgb.ExtLock.Lock() + c.Extensions["BIG-REQUESTS"] = reply.MajorOpcode + for evNum, fun := range xgb.NewExtEventFuncs["BIG-REQUESTS"] { + xgb.NewEventFuncs[int(reply.FirstEvent)+evNum] = fun + } + for errNum, fun := range xgb.NewExtErrorFuncs["BIG-REQUESTS"] { + xgb.NewErrorFuncs[int(reply.FirstError)+errNum] = fun + } + xgb.ExtLock.Unlock() + + return nil +} + +func init() { + xgb.NewExtEventFuncs["BIG-REQUESTS"] = make(map[int]xgb.NewEventFun) + xgb.NewExtErrorFuncs["BIG-REQUESTS"] = make(map[int]xgb.NewErrorFun) +} + +// 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' + +// Skipping definition for base type 'Int16' + +// Skipping definition for base type 'Int32' + +// Skipping definition for base type 'Void' + +// Skipping definition for base type 'Byte' + +// Request Enable +// size: 4 +type EnableCookie struct { + *xgb.Cookie +} + +func Enable(c *xgb.Conn) EnableCookie { + cookie := c.NewCookie(true, true) + c.NewRequest(enableRequest(c), cookie) + return EnableCookie{cookie} +} + +func EnableUnchecked(c *xgb.Conn) EnableCookie { + cookie := c.NewCookie(false, true) + c.NewRequest(enableRequest(c), cookie) + return EnableCookie{cookie} +} + +// Request reply for Enable +// size: 12 +type EnableReply struct { + Sequence uint16 + Length uint32 + // padding: 1 bytes + MaximumRequestLength uint32 +} + +// Waits and reads reply data from request Enable +func (cook EnableCookie) Reply() (*EnableReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return enableReply(buf), nil +} + +// Read reply into structure from buffer for Enable +func enableReply(buf []byte) *EnableReply { + v := new(EnableReply) + 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.MaximumRequestLength = xgb.Get32(buf[b:]) + b += 4 + + return v +} + +// Write request to wire for Enable +func enableRequest(c *xgb.Conn) []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + buf[b] = c.Extensions["BIG-REQUESTS"] + 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 + + 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/bigreq/bigreq.go | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'nexgb/bigreq') diff --git a/nexgb/bigreq/bigreq.go b/nexgb/bigreq/bigreq.go index 8bb05c1..c2263a0 100644 --- a/nexgb/bigreq/bigreq.go +++ b/nexgb/bigreq/bigreq.go @@ -1,7 +1,8 @@ +// Package bigreq is the X client API for the BIG-REQUESTS extension. package bigreq /* - This file was generated by bigreq.xml on May 10 2012 4:20:27pm EDT. + This file was generated by bigreq.xml on May 10 2012 8:04:31pm EDT. This file is automatically generated. Edit at your peril! */ @@ -39,6 +40,16 @@ func init() { xgb.NewExtErrorFuncs["BIG-REQUESTS"] = make(map[int]xgb.NewErrorFun) } +// 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' + // Skipping definition for base type 'Int8' // Skipping definition for base type 'Card16' @@ -53,16 +64,6 @@ func init() { // 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' - // Request Enable // size: 4 type EnableCookie struct { -- 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/bigreq/bigreq.go | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'nexgb/bigreq') diff --git a/nexgb/bigreq/bigreq.go b/nexgb/bigreq/bigreq.go index c2263a0..3913c5f 100644 --- a/nexgb/bigreq/bigreq.go +++ b/nexgb/bigreq/bigreq.go @@ -2,7 +2,7 @@ package bigreq /* - This file was generated by bigreq.xml on May 10 2012 8:04:31pm EDT. + This file was generated by bigreq.xml on May 10 2012 11:56:18pm EDT. This file is automatically generated. Edit at your peril! */ @@ -40,6 +40,8 @@ func init() { xgb.NewExtErrorFuncs["BIG-REQUESTS"] = make(map[int]xgb.NewErrorFun) } +// Skipping definition for base type 'Float' + // Skipping definition for base type 'Card8' // Skipping definition for base type 'Int16' @@ -62,36 +64,36 @@ func init() { // Skipping definition for base type 'Bool' -// Skipping definition for base type 'Float' - -// Request Enable -// size: 4 +// EnableCookie is a cookie used only for Enable requests. type EnableCookie struct { *xgb.Cookie } +// Enable sends a checked request. +// If an error occurs, it will be returned with the reply by calling EnableCookie.Reply() func Enable(c *xgb.Conn) EnableCookie { cookie := c.NewCookie(true, true) c.NewRequest(enableRequest(c), cookie) return EnableCookie{cookie} } +// EnableUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. func EnableUnchecked(c *xgb.Conn) EnableCookie { cookie := c.NewCookie(false, true) c.NewRequest(enableRequest(c), cookie) return EnableCookie{cookie} } -// Request reply for Enable -// size: 12 +// EnableReply represents the data returned from a Enable request. type EnableReply 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 MaximumRequestLength uint32 } -// Waits and reads reply data from request Enable +// Reply blocks and returns the reply data for a Enable request. func (cook EnableCookie) Reply() (*EnableReply, error) { buf, err := cook.Cookie.Reply() if err != nil { @@ -103,7 +105,7 @@ func (cook EnableCookie) Reply() (*EnableReply, error) { return enableReply(buf), nil } -// Read reply into structure from buffer for Enable +// enableReply reads a byte slice into a EnableReply value. func enableReply(buf []byte) *EnableReply { v := new(EnableReply) b := 1 // skip reply determinant @@ -123,6 +125,7 @@ func enableReply(buf []byte) *EnableReply { } // Write request to wire for Enable +// enableRequest writes a Enable request to a byte slice. func enableRequest(c *xgb.Conn) []byte { size := 4 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/bigreq/bigreq.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'nexgb/bigreq') diff --git a/nexgb/bigreq/bigreq.go b/nexgb/bigreq/bigreq.go index 3913c5f..32dacba 100644 --- a/nexgb/bigreq/bigreq.go +++ b/nexgb/bigreq/bigreq.go @@ -2,7 +2,7 @@ package bigreq /* - This file was generated by bigreq.xml on May 10 2012 11:56:18pm EDT. + This file was generated by bigreq.xml on May 11 2012 1:58:35am EDT. This file is automatically generated. Edit at your peril! */ @@ -40,8 +40,6 @@ func init() { xgb.NewExtErrorFuncs["BIG-REQUESTS"] = 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' + // EnableCookie is a cookie used only for Enable requests. type EnableCookie struct { *xgb.Cookie -- 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/bigreq/bigreq.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'nexgb/bigreq') diff --git a/nexgb/bigreq/bigreq.go b/nexgb/bigreq/bigreq.go index 32dacba..43a15a4 100644 --- a/nexgb/bigreq/bigreq.go +++ b/nexgb/bigreq/bigreq.go @@ -2,7 +2,7 @@ package bigreq /* - This file was generated by bigreq.xml on May 11 2012 1:58:35am EDT. + This file was generated by bigreq.xml on May 11 2012 11:57:18pm EDT. This file is automatically generated. Edit at your peril! */ @@ -40,6 +40,10 @@ func init() { xgb.NewExtErrorFuncs["BIG-REQUESTS"] = make(map[int]xgb.NewErrorFun) } +// Skipping definition for base type 'Bool' + +// Skipping definition for base type 'Float' + // Skipping definition for base type 'Card8' // Skipping definition for base type 'Int16' @@ -60,10 +64,6 @@ func init() { // Skipping definition for base type 'Double' -// Skipping definition for base type 'Bool' - -// Skipping definition for base type 'Float' - // EnableCookie is a cookie used only for Enable requests. type EnableCookie struct { *xgb.Cookie @@ -72,6 +72,9 @@ type EnableCookie struct { // Enable sends a checked request. // If an error occurs, it will be returned with the reply by calling EnableCookie.Reply() func Enable(c *xgb.Conn) EnableCookie { + if _, ok := c.Extensions["BIG-REQUESTS"]; !ok { + panic("Cannot issue request 'Enable' using the uninitialized extension 'BIG-REQUESTS'. bigreq.Init(connObj) must be called first.") + } cookie := c.NewCookie(true, true) c.NewRequest(enableRequest(c), cookie) return EnableCookie{cookie} @@ -80,6 +83,9 @@ func Enable(c *xgb.Conn) EnableCookie { // EnableUnchecked sends an unchecked request. // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. func EnableUnchecked(c *xgb.Conn) EnableCookie { + if _, ok := c.Extensions["BIG-REQUESTS"]; !ok { + panic("Cannot issue request 'Enable' using the uninitialized extension 'BIG-REQUESTS'. bigreq.Init(connObj) must be called first.") + } cookie := c.NewCookie(false, true) c.NewRequest(enableRequest(c), cookie) return EnableCookie{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/bigreq/bigreq.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'nexgb/bigreq') diff --git a/nexgb/bigreq/bigreq.go b/nexgb/bigreq/bigreq.go index 43a15a4..e7bdfc8 100644 --- a/nexgb/bigreq/bigreq.go +++ b/nexgb/bigreq/bigreq.go @@ -2,7 +2,7 @@ package bigreq /* - This file was generated by bigreq.xml on May 11 2012 11:57:18pm EDT. + This file was generated by bigreq.xml on May 26 2012 6:23:12pm EDT. This file is automatically generated. Edit at your peril! */ @@ -40,12 +40,6 @@ func init() { xgb.NewExtErrorFuncs["BIG-REQUESTS"] = make(map[int]xgb.NewErrorFun) } -// Skipping definition for base type 'Bool' - -// Skipping definition for base type 'Float' - -// Skipping definition for base type 'Card8' - // Skipping definition for base type 'Int16' // Skipping definition for base type 'Int32' @@ -64,6 +58,12 @@ func init() { // Skipping definition for base type 'Double' +// Skipping definition for base type 'Bool' + +// Skipping definition for base type 'Float' + +// Skipping definition for base type 'Card8' + // EnableCookie is a cookie used only for Enable requests. type EnableCookie struct { *xgb.Cookie -- 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/bigreq/bigreq.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'nexgb/bigreq') diff --git a/nexgb/bigreq/bigreq.go b/nexgb/bigreq/bigreq.go index e7bdfc8..af03110 100644 --- a/nexgb/bigreq/bigreq.go +++ b/nexgb/bigreq/bigreq.go @@ -2,7 +2,7 @@ package bigreq /* - This file was generated by bigreq.xml on May 26 2012 6:23:12pm EDT. + This file was generated by bigreq.xml on Jun 5 2012 12:11:58am EDT. This file is automatically generated. Edit at your peril! */ @@ -40,10 +40,6 @@ func init() { xgb.NewExtErrorFuncs["BIG-REQUESTS"] = 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' @@ -64,6 +60,10 @@ func init() { // Skipping definition for base type 'Card8' +// Skipping definition for base type 'Int16' + +// Skipping definition for base type 'Int32' + // EnableCookie is a cookie used only for Enable requests. type EnableCookie struct { *xgb.Cookie -- 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/bigreq/bigreq.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'nexgb/bigreq') diff --git a/nexgb/bigreq/bigreq.go b/nexgb/bigreq/bigreq.go index af03110..2ff767a 100644 --- a/nexgb/bigreq/bigreq.go +++ b/nexgb/bigreq/bigreq.go @@ -2,7 +2,7 @@ package bigreq /* - This file was generated by bigreq.xml on Jun 5 2012 12:11:58am EDT. + This file was generated by bigreq.xml on Aug 11 2013 8:39:42pm EDT. This file is automatically generated. Edit at your peril! */ @@ -40,30 +40,30 @@ func init() { xgb.NewExtErrorFuncs["BIG-REQUESTS"] = make(map[int]xgb.NewErrorFun) } -// Skipping definition for base type 'Void' +// Skipping definition for base type 'Bool' // Skipping definition for base type 'Byte' -// Skipping definition for base type 'Int8' - -// Skipping definition for base type 'Card16' +// Skipping definition for base type 'Card8' // Skipping definition for base type 'Char' -// Skipping definition for base type 'Card32' +// Skipping definition for base type 'Void' // Skipping definition for base type 'Double' -// Skipping definition for base type 'Bool' - // 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 'Int8' + +// Skipping definition for base type 'Card16' + +// Skipping definition for base type 'Card32' + // EnableCookie is a cookie used only for Enable requests. type EnableCookie struct { *xgb.Cookie -- 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/bigreq/bigreq.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'nexgb/bigreq') diff --git a/nexgb/bigreq/bigreq.go b/nexgb/bigreq/bigreq.go index 2ff767a..d2adcc7 100644 --- a/nexgb/bigreq/bigreq.go +++ b/nexgb/bigreq/bigreq.go @@ -1,10 +1,7 @@ // Package bigreq is the X client API for the BIG-REQUESTS extension. package bigreq -/* - This file was generated by bigreq.xml on Aug 11 2013 8:39:42pm EDT. - This file is automatically generated. Edit at your peril! -*/ +// This file is automatically generated from bigreq.xml. Edit at your peril! import ( "github.com/BurntSushi/xgb" -- 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/bigreq/bigreq.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'nexgb/bigreq') diff --git a/nexgb/bigreq/bigreq.go b/nexgb/bigreq/bigreq.go index d2adcc7..6590376 100644 --- a/nexgb/bigreq/bigreq.go +++ b/nexgb/bigreq/bigreq.go @@ -19,16 +19,15 @@ func Init(c *xgb.Conn) error { return xgb.Errorf("No extension named BIG-REQUESTS could be found on on the server.") } - xgb.ExtLock.Lock() + c.ExtLock.Lock() c.Extensions["BIG-REQUESTS"] = reply.MajorOpcode + c.ExtLock.Unlock() for evNum, fun := range xgb.NewExtEventFuncs["BIG-REQUESTS"] { xgb.NewEventFuncs[int(reply.FirstEvent)+evNum] = fun } for errNum, fun := range xgb.NewExtErrorFuncs["BIG-REQUESTS"] { xgb.NewErrorFuncs[int(reply.FirstError)+errNum] = fun } - xgb.ExtLock.Unlock() - return nil } @@ -69,6 +68,8 @@ type EnableCookie struct { // Enable sends a checked request. // If an error occurs, it will be returned with the reply by calling EnableCookie.Reply() func Enable(c *xgb.Conn) EnableCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() if _, ok := c.Extensions["BIG-REQUESTS"]; !ok { panic("Cannot issue request 'Enable' using the uninitialized extension 'BIG-REQUESTS'. bigreq.Init(connObj) must be called first.") } @@ -80,6 +81,8 @@ func Enable(c *xgb.Conn) EnableCookie { // EnableUnchecked sends an unchecked request. // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. func EnableUnchecked(c *xgb.Conn) EnableCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() if _, ok := c.Extensions["BIG-REQUESTS"]; !ok { panic("Cannot issue request 'Enable' using the uninitialized extension 'BIG-REQUESTS'. bigreq.Init(connObj) must be called first.") } @@ -134,7 +137,9 @@ func enableRequest(c *xgb.Conn) []byte { b := 0 buf := make([]byte, size) + c.ExtLock.RLock() buf[b] = c.Extensions["BIG-REQUESTS"] + c.ExtLock.RUnlock() b += 1 buf[b] = 0 // request opcode -- cgit v1.2.3