]> gitweb.michael.orlitzky.com - dead/htsn.git/blob - src/TSN/FeedHosts.hs
Add scaffolding to allow logging via syslog or a file.
[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 Configured,
18 Value( List ),
19 convert )
20 import Data.Data (Data)
21 import System.Console.CmdArgs.Default (Default(..))
22 import Data.Typeable (Typeable)
23
24
25 newtype FeedHosts =
26 FeedHosts { get_feed_hosts :: [String] }
27 deriving (Data, Show, Typeable)
28
29 instance Default FeedHosts where
30 -- | The default list of feed hosts. These were found by checking
31 -- PTR records in the neighborhood of the IP address in use. There
32 -- is a feed4.sportsnetwork.com, but it was not operational when
33 -- this was written.
34 def = FeedHosts ["feed1.sportsnetwork.com",
35 "feed2.sportsnetwork.com",
36 "feed3.sportsnetwork.com"]
37
38
39 instance DCT.Configured FeedHosts where
40 -- | This allows us to read a FeedHosts object out of a Configurator
41 -- config file. By default Configurator wouldn't know what to do,
42 -- so we have to tell it that we expect a list, and if that list
43 -- has strings in it, we can apply the FeedHosts constructor to
44 -- it.
45 convert (DCT.List xs) =
46 -- mapM gives us a Maybe [String] here.
47 fmap FeedHosts (mapM convert_string xs)
48 where
49 convert_string :: DCT.Value -> Maybe String
50 convert_string = DCT.convert
51
52 -- If we read anything other than a list of values out of the file,
53 -- fail.
54 convert _ = Nothing