-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
72 additions
and
7 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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{-# LANGUAGE DeriveGeneric #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
module ConfigParser where | ||
|
||
import Data.Aeson | ||
import GHC.Generics | ||
import qualified Data.ByteString.Lazy as B | ||
|
||
jsonFile :: FilePath | ||
jsonFile = "config-sample.json" | ||
|
||
data DistributionConfig = Config [ProcessConfig] [String] deriving (Show,Generic) | ||
|
||
data ProcessConfig = PConfig String [String] deriving (Show,Generic) | ||
|
||
instance FromJSON DistributionConfig where | ||
parseJSON = withObject "DistribuitionConfig" $ \obj -> do | ||
ps <- obj .: "processes" | ||
vs <- obj .: "shared_variables" | ||
return (Config ps vs) | ||
|
||
instance FromJSON ProcessConfig where | ||
parseJSON = withObject "ProcessConfig" $ \obj -> do | ||
i <- obj .: "process_id" | ||
as <- obj .: "actions" | ||
return (PConfig i as) | ||
|
||
parseConfig :: FilePath -> IO (Either String DistributionConfig) | ||
parseConfig file = do content <- B.readFile file | ||
return (eitherDecode content) | ||
|
||
-- main :: IO () | ||
-- main = parseJson jsonFile >>= print |
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,29 @@ | ||
{ | ||
"processes": [ | ||
{ | ||
"process_id": "node0", | ||
"actions": [ | ||
"InitiateProbe", | ||
"SendMsg(0)", | ||
"Deactivate(0)" | ||
] | ||
}, | ||
{ | ||
"process_id": "node1", | ||
"actions": [ | ||
"PassToken(1)", | ||
"SendMsg(1)", | ||
"Deactivate(1)" | ||
] | ||
}, | ||
{ | ||
"process_id": "node2", | ||
"actions": [ | ||
"PassToken(2)", | ||
"SendMsg(2)", | ||
"Deactivate(2)" | ||
] | ||
} | ||
], | ||
"shared_variables": ["tcolor", "tpos", "active"] | ||
} |