panic when an extension request is issued before an extension has been initialized. but give a nice error message for the happy people.

This commit is contained in:
Andrew Gallant (Ocelot)
2012-05-11 23:58:52 -04:00
parent fb3128ed2a
commit 29942bf078
29 changed files with 2876 additions and 202 deletions

View File

@@ -18,6 +18,7 @@ func (r *Request) Define(c *Context) {
"by calling %s.Reply()", r.CookieName())
c.Putln("func %s(c *xgb.Conn, %s) %s {",
r.SrcName(), r.ParamNameTypes(), r.CookieName())
r.CheckExt(c)
c.Putln("cookie := c.NewCookie(true, true)")
c.Putln("c.NewRequest(%s(c, %s), cookie)", r.ReqName(), r.ParamNames())
c.Putln("return %s{cookie}", r.CookieName())
@@ -29,6 +30,7 @@ func (r *Request) Define(c *Context) {
"xgb.WaitForEvent or xgb.PollForEvent.")
c.Putln("func %sUnchecked(c *xgb.Conn, %s) %s {",
r.SrcName(), r.ParamNameTypes(), r.CookieName())
r.CheckExt(c)
c.Putln("cookie := c.NewCookie(false, true)")
c.Putln("c.NewRequest(%s(c, %s), cookie)", r.ReqName(), r.ParamNames())
c.Putln("return %s{cookie}", r.CookieName())
@@ -42,6 +44,7 @@ func (r *Request) Define(c *Context) {
"xgb.WaitForEvent or xgb.PollForEvent.")
c.Putln("func %s(c *xgb.Conn, %s) %s {",
r.SrcName(), r.ParamNameTypes(), r.CookieName())
r.CheckExt(c)
c.Putln("cookie := c.NewCookie(false, false)")
c.Putln("c.NewRequest(%s(c, %s), cookie)", r.ReqName(), r.ParamNames())
c.Putln("return %s{cookie}", r.CookieName())
@@ -53,6 +56,7 @@ func (r *Request) Define(c *Context) {
"%s.Check()", r.CookieName())
c.Putln("func %sChecked(c *xgb.Conn, %s) %s {",
r.SrcName(), r.ParamNameTypes(), r.CookieName())
r.CheckExt(c)
c.Putln("cookie := c.NewCookie(true, false)")
c.Putln("c.NewRequest(%s(c, %s), cookie)", r.ReqName(), r.ParamNames())
c.Putln("return %s{cookie}", r.CookieName())
@@ -71,6 +75,18 @@ func (r *Request) Define(c *Context) {
r.WriteRequest(c)
}
func (r *Request) CheckExt(c *Context) {
if !c.protocol.isExt() {
return
}
c.Putln("if _, ok := c.Extensions[\"%s\"]; !ok {",
strings.ToUpper(c.protocol.ExtXName))
c.Putln("panic(\"Cannot issue request '%s' using the uninitialized " +
"extension '%s'. %s.Init(connObj) must be called first.\")",
r.SrcName(), c.protocol.ExtXName, c.protocol.PkgName())
c.Putln("}")
}
func (r *Request) ReadReply(c *Context) {
c.Putln("// %s represents the data returned from a %s request.",
r.ReplyTypeName(), r.SrcName())