]> gitweb.michael.orlitzky.com - dead/htsn.git/blob - src/TSN/FeedHosts.hs
Add more code comments.
[dead/htsn.git] / src / TSN / FeedHosts.hs
1 {-# LANGUAGE DeriveDataTypeable #-}
2
3 -- | A newtype around a list of Strings which represent the feed
4 -- hosts. This is all to avoid an orphan instance of Configured for
5 -- [String] if we had defined one in e.g. OptionalConfiguration.
6 --
7 -- This was placed under the "TSN" namespace because its Default
8 -- instance is specific to TSN, even though otherwise it's just a
9 -- list of strings.
10 --
11 module TSN.FeedHosts
12 where
13
14 -- DC is needed only for the DCT.Configured instance of String.
15 import qualified Data.Configurator as DC()
16 import qualified Data.Configurator.Types as DCT
17 import Data.Data (Data)
18 import System.Console.CmdArgs.Default (Default(..))
19 import Data.Typeable (Typeable)
20
21
22 newtype FeedHosts =
23 FeedHosts { get_feed_hosts :: [String] }
24 deriving (Data, Show, Typeable)
25
26 instance Default FeedHosts where
27 -- | The default list of feed hosts. These were found by checking
28 -- PTR records in the neighborhood of the IP address in use. There
29 -- is a feed4.sportsnetwork.com, but it was not operational when
30 -- this was written.
31 def = FeedHosts ["feed1.sportsnetwork.com",
32 "feed2.sportsnetwork.com",
33 "feed3.sportsnetwork.com"]
34
35
36 instance DCT.Configured FeedHosts where
37 -- | This allows us to read a FeedHosts object out of a Configurator
38 -- config file. By default Configurator wouldn't know what to do,
39 -- so we have to tell it that we expect a list, and if that list
40 -- has strings in it, we can apply the FeedHosts constructor to
41 -- it.
42 convert (DCT.List xs) =
43 -- mapM gives us a Maybe [String] here.
44 fmap FeedHosts (mapM convert_string xs)
45 where
46 convert_string :: DCT.Value -> Maybe String
47 convert_string = DCT.convert
48
49 -- If we read anything other than a list of values out of the file,
50 -- fail.
51 convert _ = Nothing