Revision 32a569fe
b/htest/Test/Ganeti/THH.hs | ||
---|---|---|
34 | 34 |
import Text.JSON |
35 | 35 |
|
36 | 36 |
import Ganeti.THH |
37 |
import Ganeti.JSON |
|
38 | 37 |
|
39 | 38 |
import Test.Ganeti.TestHelper |
40 | 39 |
import Test.Ganeti.TestCommon |
b/htools/Ganeti/Confd/Types.hs | ||
---|---|---|
50 | 50 |
|
51 | 51 |
import qualified Ganeti.Constants as C |
52 | 52 |
import Ganeti.THH |
53 |
import Ganeti.JSON |
|
54 | 53 |
|
55 | 54 |
{- |
56 | 55 |
Note that we re-export as is from Constants the following simple items: |
b/htools/Ganeti/HTools/Types.hs | ||
---|---|---|
75 | 75 |
) where |
76 | 76 |
|
77 | 77 |
import qualified Data.Map as M |
78 |
import Text.JSON (makeObj, readJSON, showJSON) |
|
79 | 78 |
|
80 | 79 |
import qualified Ganeti.Constants as C |
81 | 80 |
import qualified Ganeti.THH as THH |
82 | 81 |
import Ganeti.BasicTypes |
83 |
import Ganeti.JSON |
|
84 | 82 |
|
85 | 83 |
-- | The instance index type. |
86 | 84 |
type Idx = Int |
b/htools/Ganeti/JSON.hs | ||
---|---|---|
50 | 50 |
import qualified Text.JSON as J |
51 | 51 |
import Text.JSON.Pretty (pp_value) |
52 | 52 |
|
53 |
-- Note: this module should not import any Ganeti-specific modules |
|
54 |
-- beside BasicTypes, since it's used in THH which is used itself to |
|
55 |
-- build many other modules. |
|
56 |
|
|
53 | 57 |
import Ganeti.BasicTypes |
54 | 58 |
|
55 | 59 |
-- * JSON-related functions |
b/htools/Ganeti/Jobs.hs | ||
---|---|---|
30 | 30 |
, JobStatus(..) |
31 | 31 |
) where |
32 | 32 |
|
33 |
import Text.JSON (readJSON, showJSON, JSON) |
|
34 |
|
|
35 | 33 |
import qualified Ganeti.Constants as C |
36 | 34 |
import qualified Ganeti.THH as THH |
37 | 35 |
|
b/htools/Ganeti/Objects.hs | ||
---|---|---|
95 | 95 |
import Data.Maybe |
96 | 96 |
import qualified Data.Map as Map |
97 | 97 |
import qualified Data.Set as Set |
98 |
import Text.JSON (makeObj, showJSON, readJSON, JSON, JSValue(..))
|
|
98 |
import Text.JSON (showJSON, readJSON, JSON, JSValue(..)) |
|
99 | 99 |
import qualified Text.JSON as J |
100 | 100 |
|
101 | 101 |
import qualified Ganeti.Constants as C |
b/htools/Ganeti/OpCodes.hs | ||
---|---|---|
39 | 39 |
, allOpIDs |
40 | 40 |
) where |
41 | 41 |
|
42 |
import Text.JSON (readJSON, showJSON, makeObj, JSON, JSValue(..), fromJSString)
|
|
42 |
import Text.JSON (readJSON, showJSON, JSON, JSValue(..), fromJSString) |
|
43 | 43 |
import Text.JSON.Pretty (pp_value) |
44 | 44 |
|
45 | 45 |
import qualified Ganeti.Constants as C |
b/htools/Ganeti/Query/Language.hs | ||
---|---|---|
63 | 63 |
|
64 | 64 |
import qualified Ganeti.Constants as C |
65 | 65 |
import Ganeti.THH |
66 |
import Ganeti.JSON |
|
67 | 66 |
|
68 | 67 |
-- * THH declarations, that require ordering. |
69 | 68 |
|
b/htools/Ganeti/Rpc.hs | ||
---|---|---|
73 | 73 |
import Control.Arrow (second) |
74 | 74 |
import qualified Text.JSON as J |
75 | 75 |
import Text.JSON.Pretty (pp_value) |
76 |
import Text.JSON (makeObj) |
|
77 | 76 |
|
78 | 77 |
#ifndef NO_CURL |
79 | 78 |
import Network.Curl |
... | ... | |
84 | 83 |
import Ganeti.Objects |
85 | 84 |
import Ganeti.THH |
86 | 85 |
import Ganeti.Compat |
87 |
import Ganeti.JSON |
|
88 | 86 |
|
89 | 87 |
-- * Base RPC functionality and types |
90 | 88 |
|
b/htools/Ganeti/THH.hs | ||
---|---|---|
69 | 69 |
import qualified Text.JSON as JSON |
70 | 70 |
import Text.JSON.Pretty (pp_value) |
71 | 71 |
|
72 |
import Ganeti.JSON |
|
73 |
|
|
72 | 74 |
-- * Exported types |
73 | 75 |
|
74 | 76 |
-- | Class of objects that can be converted to 'JSObject' |
... | ... | |
239 | 241 |
|
240 | 242 |
-- | showJSON as an expression, for reuse. |
241 | 243 |
showJSONE :: Q Exp |
242 |
showJSONE = varNameE "showJSON" |
|
244 |
showJSONE = varE 'JSON.showJSON |
|
245 |
|
|
246 |
-- | makeObj as an expression, for reuse. |
|
247 |
makeObjE :: Q Exp |
|
248 |
makeObjE = varE 'JSON.makeObj |
|
249 |
|
|
250 |
-- | fromObj (Ganeti specific) as an expression, for reuse. |
|
251 |
fromObjE :: Q Exp |
|
252 |
fromObjE = varE 'fromObj |
|
243 | 253 |
|
244 | 254 |
-- | ToRaw function name. |
245 | 255 |
toRawName :: String -> Name |
... | ... | |
394 | 404 |
genShowJSON :: String -> Q Dec |
395 | 405 |
genShowJSON name = do |
396 | 406 |
body <- [| JSON.showJSON . $(varE (toRawName name)) |] |
397 |
return $ FunD (mkName "showJSON") [Clause [] (NormalB body) []]
|
|
407 |
return $ FunD 'JSON.showJSON [Clause [] (NormalB body) []]
|
|
398 | 408 |
|
399 | 409 |
-- | Creates the readJSON member of a JSON instance declaration. |
400 | 410 |
-- |
... | ... | |
417 | 427 |
$(stringE name) ++ ": " ++ e ++ " from " ++ |
418 | 428 |
show $(varE s) |
419 | 429 |
|] |
420 |
return $ FunD (mkName "readJSON") [Clause [VarP s] (NormalB body) []]
|
|
430 |
return $ FunD 'JSON.readJSON [Clause [VarP s] (NormalB body) []]
|
|
421 | 431 |
|
422 | 432 |
-- | Generates a JSON instance for a given type. |
423 | 433 |
-- |
... | ... | |
546 | 556 |
JSON.showJSON $(stringE . deCamelCase $ sname) )] |] |
547 | 557 |
flist = listE (opid:felems) |
548 | 558 |
-- and finally convert all this to a json object |
549 |
flist' = [| $(varNameE "makeObj") (concat $flist) |]
|
|
559 |
flist' = [| $makeObjE (concat $flist) |]
|
|
550 | 560 |
clause [pat] (normalB flist') [] |
551 | 561 |
|
552 | 562 |
-- | Generates the main save opcode function. |
... | ... | |
583 | 593 |
opid = mkName "op_id" |
584 | 594 |
st1 <- bindS (varP objname) [| liftM JSON.fromJSObject |
585 | 595 |
(JSON.readJSON $(varE arg1)) |] |
586 |
st2 <- bindS (varP opid) [| $(varNameE "fromObj") |
|
587 |
$(varE objname) $(stringE "OP_ID") |] |
|
596 |
st2 <- bindS (varP opid) [| $fromObjE $(varE objname) $(stringE "OP_ID") |] |
|
588 | 597 |
-- the match results (per-constructor blocks) |
589 | 598 |
mexps <- mapM (uncurry loadConstructor) opdefs |
590 | 599 |
fails <- [| fail $ "Unknown opcode " ++ $(varE opid) |] |
... | ... | |
706 | 715 |
tdlist = [| concat $flist |] |
707 | 716 |
iname = mkName "i" |
708 | 717 |
tclause <- clause [pat] (normalB tdlist) [] |
709 |
cclause <- [| $(varNameE "makeObj") . $(varE tdname) |]
|
|
718 |
cclause <- [| $makeObjE . $(varE tdname) |]
|
|
710 | 719 |
let fname = mkName ("save" ++ sname) |
711 | 720 |
sigt <- [t| $(conT name) -> JSON.JSValue |] |
712 | 721 |
return [SigD tdname tdsigt, FunD tdname [tclause], |
... | ... | |
741 | 750 |
objectShowJSON :: String -> Q Dec |
742 | 751 |
objectShowJSON name = do |
743 | 752 |
body <- [| JSON.showJSON . $(varE . mkName $ "save" ++ name) |] |
744 |
return $ FunD (mkName "showJSON") [Clause [] (NormalB body) []]
|
|
753 |
return $ FunD 'JSON.showJSON [Clause [] (NormalB body) []]
|
|
745 | 754 |
|
746 | 755 |
-- | Generates the load object functionality. |
747 | 756 |
genLoadObject :: (Field -> Q (Name, Stmt)) |
... | ... | |
775 | 784 |
-- we treat both optional types the same, since |
776 | 785 |
-- 'maybeFromObj' can deal with both missing and null values |
777 | 786 |
-- appropriately (the same) |
778 |
then [| $(varNameE "maybeFromObj") $objvar $objfield |]
|
|
787 |
then [| $(varE 'maybeFromObj) $objvar $objfield |]
|
|
779 | 788 |
else case fieldDefault field of |
780 | 789 |
Just defv -> |
781 |
[| $(varNameE "fromObjWithDefault") $objvar
|
|
790 |
[| $(varE 'fromObjWithDefault) $objvar
|
|
782 | 791 |
$objfield $defv |] |
783 |
Nothing -> [| $(varNameE "fromObj") $objvar $objfield |]
|
|
792 |
Nothing -> [| $fromObjE $objvar $objfield |]
|
|
784 | 793 |
bexp <- loadFn field loadexp objvar |
785 | 794 |
|
786 | 795 |
return (fvar, BindS (VarP fvar) bexp) |
... | ... | |
795 | 804 |
JSON.Error $ "Can't parse value for type " ++ |
796 | 805 |
$(stringE name) ++ ": " ++ e |
797 | 806 |
|] |
798 |
return $ FunD (mkName "readJSON") [Clause [VarP s] (NormalB body) []]
|
|
807 |
return $ FunD 'JSON.readJSON [Clause [VarP s] (NormalB body) []]
|
|
799 | 808 |
|
800 | 809 |
-- * Inheritable parameter tables implementation |
801 | 810 |
|
... | ... | |
886 | 895 |
-- these are used in all patterns below |
887 | 896 |
let objvar = varNameE "o" |
888 | 897 |
objfield = stringE name |
889 |
loadexp = [| $(varNameE "maybeFromObj") $objvar $objfield |]
|
|
898 |
loadexp = [| $(varE 'maybeFromObj) $objvar $objfield |]
|
|
890 | 899 |
bexp <- loadFn field loadexp objvar |
891 | 900 |
return (fvar, BindS (VarP fvar) bexp) |
892 | 901 |
|
... | ... | |
894 | 903 |
buildFromMaybe :: String -> Q Dec |
895 | 904 |
buildFromMaybe fname = |
896 | 905 |
valD (varP (mkName $ "n_" ++ fname)) |
897 |
(normalB [| $(varNameE "fromMaybe")
|
|
906 |
(normalB [| $(varE 'fromMaybe)
|
|
898 | 907 |
$(varNameE $ "f_" ++ fname) |
899 | 908 |
$(varNameE $ "p_" ++ fname) |]) [] |
900 | 909 |
|
Also available in: Unified diff