Auto-define a LuxiReq data type
authorIustin Pop <iustin@google.com>
Sat, 5 May 2012 04:18:39 +0000 (06:18 +0200)
committerIustin Pop <iustin@google.com>
Tue, 8 May 2012 10:37:55 +0000 (12:37 +0200)
We currently auto-generate a LuxiOp data type, which holds the entire
operation (including parameters). However, having a data type just for
the method call would be useful, so let's change THH to also
defineSADT for the Luxi constructors.

Currently I don't know how to match automatically a LuxiReq to its
LuxiOp counterpart (not even sure we need that), so any matching will
remain manual.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: RenĂ© Nussbaumer <rn@google.com>

htools/Ganeti/Luxi.hs
htools/Ganeti/THH.hs

index dd38c5a..3afd41f 100644 (file)
@@ -29,6 +29,7 @@ module Ganeti.Luxi
   ( LuxiOp(..)
   , QrViaLuxi(..)
   , ResultStatus(..)
+  , LuxiReq(..)
   , Client
   , checkRS
   , getClient
@@ -144,6 +145,8 @@ $(genLuxiOp "LuxiOp"
     )
   ])
 
+$(makeJSONInstance ''LuxiReq)
+
 -- | The serialisation of LuxiOps into strings in messages.
 $(genStrOfOp ''LuxiOp "strOfOp")
 
index 859eb81..cc41388 100644 (file)
@@ -543,7 +543,10 @@ genLuxiOp name cons = do
             cons
   let declD = DataD [] (mkName name) [] decl_d [''Show, ''Read]
   (savesig, savefn) <- genSaveLuxiOp cons
-  return [declD, savesig, savefn]
+  req_defs <- declareSADT "LuxiReq" .
+              map (\(str, _) -> ("Req" ++ str, mkName ("luxiReq" ++ str))) $
+                  cons
+  return $ [declD, savesig, savefn] ++ req_defs
 
 -- | Generates the \"save\" expression for a single luxi parameter.
 saveLuxiField :: Name -> LuxiParam -> Q Exp