-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
plugin initialization is now generated by the system
- Loading branch information
Showing
14 changed files
with
86 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ dependencies: | |
- ixset | ||
- acid-state | ||
- typerep-map | ||
- threads | ||
|
||
library: | ||
source-dirs: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
ServerTemplate/src/Static/Cmd.hs → ServerTemplate/src/Static/Plugins.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
module Static.Cmd where | ||
module Static.Plugins where | ||
|
||
import qualified Plugins.Incrementer | ||
import Static.ServerTypes | ||
import qualified Data.TMap as TM | ||
import Control.Concurrent.Thread (forkIO) | ||
|
||
initStateCmds :: IO PluginState | ||
initStateCmds = do | ||
let pluginState = TM.empty | ||
p1 <- initPlugin :: IO Plugins.Incrementer.Counter | ||
(_,p1) <- forkIO $ initPlugin :: IO Plugins.Incrementer.Counter | ||
return $ TM.insert p1 pluginState |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
module Generate.Plugins where | ||
|
||
import qualified Data.Text as T | ||
import Types | ||
|
||
generatePlugins :: [Plugin] -> T.Text | ||
generatePlugins ps = | ||
let | ||
onePlugin n (Plugin name) = T.concat[" (_,rp",T.pack $ show n,") <- forkIO $ (initPlugin :: IO Plugins.",T.pack name,".",T.pack name,")"] | ||
oneResult n = T.concat[" p",T.pack $ show n," <- result =<< rp", T.pack $ show n] | ||
return n = T.concat[" return $ ",T.concat $ map (\n -> T.concat ["TM.insert p",T.pack $ show n," $ "]) [0..length ps - 1], "TM.empty"] | ||
in | ||
T.unlines $ | ||
[ | ||
"module Static.Plugins where" | ||
, "import Static.ServerTypes" | ||
, "import qualified Data.TMap as TM" | ||
, "import Control.Concurrent.Thread (forkIO, result)\n" | ||
, T.concat $ map (\(Plugin p) -> T.concat["import qualified Plugins.",T.pack p,"\n"]) ps,"" | ||
, "initStateCmds :: IO PluginState" | ||
, "initStateCmds = do" | ||
] | ||
++ | ||
(map (uncurry onePlugin) $ zip [0..] ps) | ||
++ | ||
(map oneResult [0..length ps - 1]) | ||
++ | ||
[ | ||
return $ length ps | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters