aboutsummaryrefslogtreecommitdiff
path: root/nexgb/xgbgen
diff options
context:
space:
mode:
authorAndrew Gallant (Ocelot) <Andrew.Gallant@tufts.edu>2012-05-11 23:58:52 -0400
committerAndrew Gallant (Ocelot) <Andrew.Gallant@tufts.edu>2012-05-11 23:58:52 -0400
commit29942bf078c92fea681e42ca5029592526f00718 (patch)
treecee802ebe16e0b118c9be0f6265e26d31e8a5845 /nexgb/xgbgen
parentfb3128ed2a83a0f644661cedebbe5bfda3f4951e (diff)
downloadhaven-29942bf078c92fea681e42ca5029592526f00718.tar.gz
haven-29942bf078c92fea681e42ca5029592526f00718.tar.xz
haven-29942bf078c92fea681e42ca5029592526f00718.zip
panic when an extension request is issued before an extension has been initialized. but give a nice error message for the happy people.
Diffstat (limited to 'nexgb/xgbgen')
-rw-r--r--nexgb/xgbgen/go_request_reply.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/nexgb/xgbgen/go_request_reply.go b/nexgb/xgbgen/go_request_reply.go
index eca0c10..62d9936 100644
--- a/nexgb/xgbgen/go_request_reply.go
+++ b/nexgb/xgbgen/go_request_reply.go
@@ -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())