X-Git-Url: https://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FTSN%2FXML%2FHeartbeat.hs;h=b44f9309379cf9e8fb8d6e51d9d8367c0084c36a;hb=071f8f23b010afab6ab916c480035753c82fc962;hp=a3a169347385b3197f018af5d914c4b1c5a6e266;hpb=610f18c6810edc6bb5dee5cad8bff9e8e59b408a;p=dead%2Fhtsn-import.git diff --git a/src/TSN/XML/Heartbeat.hs b/src/TSN/XML/Heartbeat.hs index a3a1693..b44f930 100644 --- a/src/TSN/XML/Heartbeat.hs +++ b/src/TSN/XML/Heartbeat.hs @@ -1,15 +1,19 @@ +{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE ScopedTypeVariables #-} -- | Handle documents defined by Heartbeat.dtd. -- module TSN.XML.Heartbeat ( + dtd, verify, -- * Tests heartbeat_tests ) where -- System imports. +import Data.Time.Clock ( UTCTime ) import Data.Tuple.Curry ( uncurryN ) +import qualified GHC.Generics as GHC ( Generic ) import Test.Tasty ( TestTree, testGroup ) import Test.Tasty.HUnit ( (@?=), testCase ) import Text.XML.HXT.Core ( @@ -23,19 +27,30 @@ import Text.XML.HXT.Core ( xpWrap ) -- Local imports. +import Generics ( Generic(..), to_tuple ) import TSN.DbImport ( ImportResult(..) ) +import TSN.Picklers ( xp_time_stamp ) import Xml ( pickle_unpickle, unpickleable ) +-- | The DTD to which this module corresponds. +-- +dtd :: String +dtd = "Heartbeat.dtd" + -- | The data structure that holds the XML representation of a -- Heartbeat message. -- data Message = - Message { - xml_file_id :: Int, - heading :: String, - time_stamp :: String } - deriving (Eq, Show) + Message + Int -- xml_file_id + String -- heading + UTCTime -- time_stamp + deriving (Eq, GHC.Generic, Show) + +-- | For 'Generics.to_tuple'. +-- +instance Generic Message -- | A (un)pickler that turns a Heartbeat XML file into a 'Message' @@ -47,12 +62,9 @@ pickle_message = xpWrap (from_tuple, to_tuple) $ xpTriple (xpElem "XML_File_ID" xpInt) (xpElem "heading" xpText) - (xpElem "time_stamp" xpText) + (xpElem "time_stamp" xp_time_stamp) where from_tuple = uncurryN Message - to_tuple m = (xml_file_id m, - heading m, - time_stamp m) -- | Verify (and report) the received heartbeat. We return @@ -63,7 +75,7 @@ verify :: XmlTree -> IO ImportResult verify xml = do let root_element = unpickleDoc pickle_message xml return $ case root_element of - Nothing -> ImportFailed "Could not unpickle document in import_generic." + Nothing -> ImportFailed "Could not unpickle document to be verified." Just _ -> ImportSkipped "Heartbeat received. Thump." --