X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Rakka%2FEnvironment.hs;h=d68892b61590336f7e78c22f6dc5836cb35a5f63;hb=2ad43b49ecc25bdf87dd19037fd63c12428992ae;hp=069f9eba3ceb34e8ea2d57c4ccf7551b3c155874;hpb=790089d18791029ad268b3306ca71f8d5ae44ce1;p=Rakka.git diff --git a/Rakka/Environment.hs b/Rakka/Environment.hs index 069f9eb..d68892b 100644 --- a/Rakka/Environment.hs +++ b/Rakka/Environment.hs @@ -1,25 +1,64 @@ module Rakka.Environment ( Environment(..) + , InterpTable , setupEnv + , getInterpTable + , getInterpTableA ) where +import Control.Arrow.ArrowIO +import Data.IORef +import Data.Map (Map) +import qualified Data.Map as M import Network import qualified Network.HTTP.Lucu.Config as LC +import Rakka.Storage +import Rakka.SystemConfig +import Rakka.Wiki.Interpreter +import Rakka.Wiki.Interpreter.Base data Environment = Environment { - envLocalStateDir :: FilePath - , envLucuConf :: LC.Config + envLocalStateDir :: !FilePath + , envLucuConf :: !LC.Config + , envStorage :: !Storage + , envSysConf :: !SystemConfig + , envInterpTable :: !(IORef InterpTable) } +type InterpTable = Map String Interpreter + + setupEnv :: FilePath -> PortNumber -> IO Environment setupEnv lsdir portNum = do let lucuConf = LC.defaultConfig { LC.cnfServerPort = PortNumber portNum } + storage = mkStorage + sysConf = mkSystemConfig lucuConf + interpTable <- mkInterpTable return $ Environment { envLocalStateDir = lsdir , envLucuConf = lucuConf - } \ No newline at end of file + , envStorage = storage + , envSysConf = sysConf + , envInterpTable = interpTable + } + + +mkInterpTable :: IO (IORef InterpTable) +mkInterpTable = newIORef (listToTable baseInterpreters) + where + listToTable :: [Interpreter] -> InterpTable + listToTable xs + = M.fromList [ (commandName x, x) | x <- xs ] + + +getInterpTable :: Environment -> IO InterpTable +getInterpTable = readIORef . envInterpTable + + +getInterpTableA :: ArrowIO a => Environment -> a b InterpTable +getInterpTableA = arrIO0 . getInterpTable