Optimise autotools/run-in-tempdir
[ganeti-local] / htools / Ganeti / Query / Types.hs
1 {-| Implementation of the Ganeti Query2 basic types.
2
3 These are types internal to the library, and for example clients that
4 use the library should not need to import it.
5
6  -}
7
8 {-
9
10 Copyright (C) 2012 Google Inc.
11
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
16
17 This program is distributed in the hope that it will be useful, but
18 WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20 General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 02110-1301, USA.
26
27 -}
28
29 module Ganeti.Query.Types
30   ( FieldGetter(..)
31   , QffMode(..)
32   , FieldData
33   , FieldList
34   , FieldMap
35   , isRuntimeField
36   ) where
37
38 import qualified Data.Map as Map
39
40 import Ganeti.Query.Language
41 import Ganeti.Objects
42
43 -- | The type of field getters. The \"a\" type represents the type
44 -- we're querying, whereas the \"b\" type represents the \'runtime\'
45 -- data for that type (if any). Note that we don't support multiple
46 -- runtime sources, and we always consider the entire configuration as
47 -- a given (so no equivalent for Python's /*_CONFIG/ and /*_GROUP/;
48 -- configuration accesses are cheap for us).
49 data FieldGetter a b = FieldSimple  (a -> ResultEntry)
50                      | FieldRuntime (b -> a -> ResultEntry)
51                      | FieldConfig  (ConfigData -> a -> ResultEntry)
52                      | FieldUnknown
53
54 -- | Type defining how the value of a field is used in filtering. This
55 -- implements the equivalent to Python's QFF_ flags, except that we
56 -- don't use OR-able values.
57 data QffMode = QffNormal     -- ^ Value is used as-is in filters
58              | QffTimestamp  -- ^ Value is a timestamp tuple, convert to float
59                deriving (Show, Eq)
60
61
62 -- | Alias for a field data (definition and getter).
63 type FieldData a b = (FieldDefinition, FieldGetter a b, QffMode)
64
65 -- | Alias for a field data list.
66 type FieldList a b = [FieldData a b]
67
68 -- | Alias for field maps.
69 type FieldMap a b = Map.Map String (FieldData a b)
70
71 -- | Helper function to check if a getter is a runtime one.
72 isRuntimeField :: FieldGetter a b -> Bool
73 isRuntimeField (FieldRuntime _) = True
74 isRuntimeField _                = False