Revision 08f7d24d
b/src/Ganeti/Rpc.hs | ||
---|---|---|
379 | 379 |
|
380 | 380 |
-- ** Version |
381 | 381 |
|
382 |
-- | Version |
|
383 |
-- Query node version. |
|
384 |
-- Note: We can't use THH as it does not know what to do with empty dict |
|
385 |
data RpcCallVersion = RpcCallVersion {} |
|
386 |
deriving (Show, Eq) |
|
387 |
|
|
388 |
instance J.JSON RpcCallVersion where |
|
389 |
showJSON _ = J.JSNull |
|
390 |
readJSON J.JSNull = return RpcCallVersion |
|
391 |
readJSON _ = fail "Unable to read RpcCallVersion" |
|
382 |
-- | Query node version. |
|
383 |
$(buildObject "RpcCallVersion" "rpcCallVersion" []) |
|
392 | 384 |
|
385 |
-- | Query node reply. |
|
393 | 386 |
$(buildObject "RpcResultVersion" "rpcResultVersion" |
394 | 387 |
[ simpleField "version" [t| Int |] |
395 | 388 |
]) |
b/src/Ganeti/THH.hs | ||
---|---|---|
791 | 791 |
genLoadObject load_fn sname fields = do |
792 | 792 |
let name = mkName sname |
793 | 793 |
funname = mkName $ "load" ++ sname |
794 |
arg1 = mkName "v" |
|
794 |
arg1 = mkName $ if null fields then "_" else "v"
|
|
795 | 795 |
objname = mkName "o" |
796 | 796 |
opid = mkName "op_id" |
797 | 797 |
st1 <- bindS (varP objname) [| liftM JSON.fromJSObject |
... | ... | |
799 | 799 |
fbinds <- mapM load_fn fields |
800 | 800 |
let (fnames, fstmts) = unzip fbinds |
801 | 801 |
let cval = foldl (\accu fn -> AppE accu (VarE fn)) (ConE name) fnames |
802 |
fstmts' = st1:fstmts ++ [NoBindS (AppE (VarE 'return) cval)] |
|
802 |
retstmt = [NoBindS (AppE (VarE 'return) cval)] |
|
803 |
-- FIXME: should we require an empty dict for an empty type? |
|
804 |
-- this allows any JSValue right now |
|
805 |
fstmts' = if null fields |
|
806 |
then retstmt |
|
807 |
else st1:fstmts ++ retstmt |
|
803 | 808 |
sigt <- [t| JSON.JSValue -> JSON.Result $(conT name) |] |
804 | 809 |
return $ (SigD funname sigt, |
805 | 810 |
FunD funname [Clause [VarP arg1] (NormalB (DoE fstmts')) []]) |
Also available in: Unified diff