From 95d0d50277217b48c5e7bca7b2c349aa7b19f280 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Sat, 5 May 2012 06:18:39 +0200
Subject: [PATCH] Auto-define a LuxiReq data type
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

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 | 3 +++
 htools/Ganeti/THH.hs  | 5 ++++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/htools/Ganeti/Luxi.hs b/htools/Ganeti/Luxi.hs
index dd38c5a47..3afd41ffb 100644
--- a/htools/Ganeti/Luxi.hs
+++ b/htools/Ganeti/Luxi.hs
@@ -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")
 
diff --git a/htools/Ganeti/THH.hs b/htools/Ganeti/THH.hs
index 859eb81b1..cc41388c3 100644
--- a/htools/Ganeti/THH.hs
+++ b/htools/Ganeti/THH.hs
@@ -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
-- 
GitLab