a huge commit. splitting extensions into their own sub-packages.

This commit is contained in:
Andrew Gallant (Ocelot)
2012-05-10 17:01:42 -04:00
parent e239bb3c68
commit 0c50dc6241
81 changed files with 51645 additions and 52516 deletions

View File

@@ -4,11 +4,11 @@ import (
"errors"
)
// cookie is the internal representation of a cookie, where one is generated
// Cookie is the internal representation of a cookie, where one is generated
// for *every* request sent by XGB.
// 'cookie' is most frequently used by embedding it into a more specific
// kind of cookie, i.e., 'GetInputFocusCookie'.
type cookie struct {
type Cookie struct {
conn *Conn
Sequence uint16
replyChan chan []byte
@@ -22,8 +22,10 @@ type cookie struct {
// function for more info on those.)
// Note that a sequence number is not set until just before the request
// corresponding to this cookie is sent over the wire.
func (c *Conn) newCookie(checked, reply bool) *cookie {
cookie := &cookie{
// This function should not be used. It is exported for use in the extension
// sub-packages.
func (c *Conn) NewCookie(checked, reply bool) *Cookie {
cookie := &Cookie{
conn: c,
Sequence: 0, // we add the sequence id just before sending a request
replyChan: nil,
@@ -60,21 +62,23 @@ func (c *Conn) newCookie(checked, reply bool) *cookie {
return cookie
}
// reply detects whether this is a checked or unchecked cookie, and calls
// Reply detects whether this is a checked or unchecked cookie, and calls
// 'replyChecked' or 'replyUnchecked' appropriately.
func (c cookie) reply() ([]byte, error) {
// This should not be used. It is exported for use in extension sub-packages.
func (c Cookie) Reply() ([]byte, error) {
// checked
if c.errorChan != nil {
return c.replyChecked()
return c.ReplyChecked()
}
return c.replyUnchecked()
return c.ReplyUnchecked()
}
// replyChecked waits for a response on either the replyChan or errorChan
// ReplyChecked waits for a response on either the replyChan or errorChan
// channels. If the former arrives, the bytes are returned with a nil error.
// If the latter arrives, no bytes are returned (nil) and the error received
// is returned.
func (c cookie) replyChecked() ([]byte, error) {
// This should not be used. It is exported for use in extension sub-packages.
func (c Cookie) ReplyChecked() ([]byte, error) {
if c.replyChan == nil {
return nil, errors.New("Cannot call 'replyChecked' on a cookie that " +
"is not expecting a *reply* or an error.")
@@ -93,13 +97,14 @@ func (c cookie) replyChecked() ([]byte, error) {
panic("unreachable")
}
// replyChecked waits for a response on either the replyChan or pingChan
// ReplyChecked waits for a response on either the replyChan or pingChan
// channels. If the former arrives, the bytes are returned with a nil error.
// If the latter arrives, no bytes are returned (nil) and a nil error
// is returned. (In the latter case, the corresponding error can be retrieved
// from (Wait|Poll)ForEvent asynchronously.)
// In all honesty, you *probably* don't want to use this method.
func (c cookie) replyUnchecked() ([]byte, error) {
// This should not be used. It is exported for use in extension sub-packages.
func (c Cookie) ReplyUnchecked() ([]byte, error) {
if c.replyChan == nil {
return nil, errors.New("Cannot call 'replyUnchecked' on a cookie " +
"that is not expecting a *reply*.")
@@ -114,7 +119,7 @@ func (c cookie) replyUnchecked() ([]byte, error) {
panic("unreachable")
}
// check is used for checked requests that have no replies. It is a mechanism
// Check is used for checked requests that have no replies. It is a mechanism
// by which to report "success" or "error" in a synchronous fashion. (Therefore,
// unchecked requests without replies cannot use this method.)
// If the request causes an error, it is sent to this cookie's errorChan.
@@ -122,7 +127,8 @@ func (c cookie) replyUnchecked() ([]byte, error) {
// Thus, pingChan is sent a value when the *next* reply is read.
// If no more replies are being processed, we force a round trip request with
// GetInputFocus.
func (c cookie) check() error {
// This should not be used. It is exported for use in extension sub-packages.
func (c Cookie) Check() error {
if c.replyChan != nil {
return errors.New("Cannot call 'Check' on a cookie that is " +
"expecting a *reply*. Use 'Reply' instead.")
@@ -142,7 +148,7 @@ func (c cookie) check() error {
}
// Now force a round trip and try again, but block this time.
c.conn.GetInputFocus().Reply()
c.conn.Sync()
select {
case err := <-c.errorChan:
return err