module Ceilometer.Types.Base
(
PRSimple(..), prSimple
, PRCompoundEvent(..), prCompoundEvent
, eventVal, eventEndpoint, eventVerb, eventStatus
, PRCompoundPollster(..), prCompoundPollster
, pollsterVal, pollsterStatus
, PFEndpoint(..), pfEndpoint
, PFValue64, PFValue32, PFValueString, PFValueText
, Flavor, FlavorMap
) where
import Control.Lens hiding (Fold, Simple)
import Data.Bimap (Bimap)
import Data.Binary (Word32, Word64, Word8)
import qualified Data.Binary as B
import qualified Data.Binary.Get as B
import qualified Data.Binary.Put as B
import Data.Text (Text)
import Ceilometer.Types.TH
type Flavor = Text
type FlavorMap = Bimap Flavor Word32
newtype PRSimple = PRSimple { _prSimpleVal :: Word64 }
deriving (Show, Read, Eq)
prSimple :: Iso' Word64 PRSimple
prSimple = iso PRSimple _prSimpleVal
data PRCompoundEvent = PRCompoundEvent
{ _eventVal :: !Word32
, _eventEndpoint :: !Word8
, _eventVerb :: !Word8
, _eventStatus :: !Word8
} deriving (Show, Eq)
makeLenses ''PRCompoundEvent
prCompoundEvent :: Iso' Word64 PRCompoundEvent
prCompoundEvent = iso getIt putIt
where getIt bytes = flip B.runGet (B.encode bytes) $ do
a <- B.getWord32be
_ <- B.getWord8
c <- B.getWord8
d <- B.getWord8
e <- B.getWord8
return $ PRCompoundEvent a c d e
putIt x = B.decode $ B.runPut $ do
B.putWord32be $ x ^. eventVal
B.putWord8 0
B.putWord8 $ x ^. eventEndpoint
B.putWord8 $ x ^. eventVerb
B.putWord8 $ x ^. eventStatus
data PRCompoundPollster = PRCompoundPollster
{ _pollsterVal :: !Word32
, _pollsterStatus :: !Word8
} deriving (Eq, Show)
makeLenses ''PRCompoundPollster
prCompoundPollster :: Iso' Word64 PRCompoundPollster
prCompoundPollster = iso getIt putIt
where getIt bytes = flip B.runGet (B.encode bytes) $ do
a <- B.getWord32be
_ <- B.getWord8
_ <- B.getWord8
_ <- B.getWord8
e <- B.getWord8
return $ PRCompoundPollster a e
putIt x = B.decode $ B.runPut $ do
B.putWord32be $ x ^. pollsterVal
B.putWord8 0
B.putWord8 0
B.putWord8 0
B.putWord8 $ x ^. pollsterStatus
type PFValue64 = Word64
type PFValue32 = Word32
type PFValueString = String
type PFValueText = Text
$(declarePF "" ("Endpoint", ''Word8)
[ ("Instant", 0)
, ("Start", 1)
, ("End", 2) ]
[ ''Show, ''Read, ''Eq, ''Bounded, ''Enum ])