diff options
author | Sam T <pxqr.sta@gmail.com> | 2013-05-12 01:07:34 +0400 |
---|---|---|
committer | Sam T <pxqr.sta@gmail.com> | 2013-05-12 01:07:34 +0400 |
commit | fd62eb70fe87b471d29cb994a60ad88f58b33ca9 (patch) | |
tree | ed8c7d69f10c1b874cc03c7d6e5064fb81b94482 /src/Remote/KRPC | |
parent | 7614ed760e137219fb4e36288abf1e78eacb2266 (diff) |
~ Prepare to scheme check.
Diffstat (limited to 'src/Remote/KRPC')
-rw-r--r-- | src/Remote/KRPC/Method.hs | 22 | ||||
-rw-r--r-- | src/Remote/KRPC/Protocol.hs | 17 |
2 files changed, 29 insertions, 10 deletions
diff --git a/src/Remote/KRPC/Method.hs b/src/Remote/KRPC/Method.hs index 3c757d07..420ceacf 100644 --- a/src/Remote/KRPC/Method.hs +++ b/src/Remote/KRPC/Method.hs | |||
@@ -1,6 +1,14 @@ | |||
1 | -- | | ||
2 | -- Copyright : (c) Sam T. 2013 | ||
3 | -- License : MIT | ||
4 | -- Maintainer : pxqr.sta@gmail.com | ||
5 | -- Stability : experimental | ||
6 | -- Portability : portable | ||
7 | -- | ||
1 | {-# LANGUAGE OverloadedStrings #-} | 8 | {-# LANGUAGE OverloadedStrings #-} |
2 | module Remote.KRPC.Method | 9 | module Remote.KRPC.Method |
3 | ( Method(methodName, methodParams, methodVals) | 10 | ( Method(methodName, methodParams, methodVals) |
11 | , methodQueryScheme, methodRespScheme | ||
4 | 12 | ||
5 | -- * Construction | 13 | -- * Construction |
6 | , method | 14 | , method |
@@ -10,13 +18,16 @@ module Remote.KRPC.Method | |||
10 | ) where | 18 | ) where |
11 | 19 | ||
12 | import Prelude hiding ((.), id) | 20 | import Prelude hiding ((.), id) |
21 | import Control.Applicative | ||
13 | import Control.Category | 22 | import Control.Category |
14 | import Control.Monad | 23 | import Control.Monad |
24 | import Data.ByteString as B | ||
25 | import Data.List as L | ||
26 | import Data.Set as S | ||
15 | 27 | ||
16 | import Remote.KRPC.Protocol | 28 | import Remote.KRPC.Protocol |
17 | 29 | ||
18 | 30 | ||
19 | |||
20 | -- | The | 31 | -- | The |
21 | -- | 32 | -- |
22 | -- * argument: type of method parameter | 33 | -- * argument: type of method parameter |
@@ -44,6 +55,15 @@ instance Category Method where | |||
44 | (.) = composeM | 55 | (.) = composeM |
45 | {-# INLINE (.) #-} | 56 | {-# INLINE (.) #-} |
46 | 57 | ||
58 | methodQueryScheme :: Method a b -> KQueryScheme | ||
59 | methodQueryScheme = KQueryScheme <$> B.intercalate "." . methodName | ||
60 | <*> S.fromList . methodParams | ||
61 | {-# INLINE methodQueryScheme #-} | ||
62 | |||
63 | |||
64 | methodRespScheme :: Method a b -> KResponseScheme | ||
65 | methodRespScheme = KResponseScheme . S.fromList . methodVals | ||
66 | {-# INLINE methodRespScheme #-} | ||
47 | 67 | ||
48 | -- TODO ppMethod | 68 | -- TODO ppMethod |
49 | 69 | ||
diff --git a/src/Remote/KRPC/Protocol.hs b/src/Remote/KRPC/Protocol.hs index e7fbea11..625aba25 100644 --- a/src/Remote/KRPC/Protocol.hs +++ b/src/Remote/KRPC/Protocol.hs | |||
@@ -24,12 +24,12 @@ module Remote.KRPC.Protocol | |||
24 | , KError(..), errorCode, mkKError | 24 | , KError(..), errorCode, mkKError |
25 | 25 | ||
26 | -- * Query | 26 | -- * Query |
27 | , KQuery(queryMethod, queryParams), MethodName, ParamName, kquery | 27 | , KQuery(queryMethod, queryArgs), MethodName, ParamName, kquery |
28 | , KQueryScheme(qscMethod, qscParams) | 28 | , KQueryScheme(KQueryScheme, qscMethod, qscParams) |
29 | 29 | ||
30 | -- * Response | 30 | -- * Response |
31 | , KResponse(respVals), ValName, kresponse | 31 | , KResponse(respVals), ValName, kresponse |
32 | , KResponseScheme(rscVals) | 32 | , KResponseScheme(KResponseScheme, rscVals) |
33 | 33 | ||
34 | , sendMessage, recvResponse | 34 | , sendMessage, recvResponse |
35 | 35 | ||
@@ -46,12 +46,14 @@ import Control.Exception.Lifted | |||
46 | import Control.Monad | 46 | import Control.Monad |
47 | import Control.Monad.IO.Class | 47 | import Control.Monad.IO.Class |
48 | import Control.Monad.Trans.Control | 48 | import Control.Monad.Trans.Control |
49 | |||
49 | import Data.BEncode | 50 | import Data.BEncode |
50 | import Data.ByteString as B | 51 | import Data.ByteString as B |
51 | import qualified Data.ByteString.Lazy as LB | 52 | import qualified Data.ByteString.Lazy as LB |
52 | import Data.Map as M | 53 | import Data.Map as M |
53 | import Data.Set as S | 54 | import Data.Set as S |
54 | import Data.Text as T | 55 | import Data.Text as T |
56 | |||
55 | import Network.Socket hiding (recvFrom) | 57 | import Network.Socket hiding (recvFrom) |
56 | import Network.Socket.ByteString | 58 | import Network.Socket.ByteString |
57 | 59 | ||
@@ -134,7 +136,7 @@ type ParamName = ByteString | |||
134 | -- TODO document that it is and how transferred | 136 | -- TODO document that it is and how transferred |
135 | data KQuery = KQuery { | 137 | data KQuery = KQuery { |
136 | queryMethod :: MethodName | 138 | queryMethod :: MethodName |
137 | , queryParams :: Map ParamName BEncode | 139 | , queryArgs :: Map ParamName BEncode |
138 | } deriving (Show, Read, Eq, Ord) | 140 | } deriving (Show, Read, Eq, Ord) |
139 | 141 | ||
140 | instance BEncodable KQuery where | 142 | instance BEncodable KQuery where |
@@ -160,12 +162,9 @@ data KQueryScheme = KQueryScheme { | |||
160 | , qscParams :: Set ParamName | 162 | , qscParams :: Set ParamName |
161 | } deriving (Show, Read, Eq, Ord) | 163 | } deriving (Show, Read, Eq, Ord) |
162 | 164 | ||
163 | domen :: Map a b -> Set a | ||
164 | domen = error "scheme.domen" | ||
165 | |||
166 | instance KMessage KQuery KQueryScheme where | 165 | instance KMessage KQuery KQueryScheme where |
167 | {-# SPECIALIZE instance KMessage KQuery KQueryScheme #-} | 166 | {-# SPECIALIZE instance KMessage KQuery KQueryScheme #-} |
168 | scheme q = KQueryScheme (queryMethod q) (domen (queryParams q)) | 167 | scheme q = KQueryScheme (queryMethod q) (M.keysSet (queryArgs q)) |
169 | {-# INLINE scheme #-} | 168 | {-# INLINE scheme #-} |
170 | 169 | ||
171 | type ValName = ByteString | 170 | type ValName = ByteString |
@@ -198,7 +197,7 @@ newtype KResponseScheme = KResponseScheme { | |||
198 | 197 | ||
199 | instance KMessage KResponse KResponseScheme where | 198 | instance KMessage KResponse KResponseScheme where |
200 | {-# SPECIALIZE instance KMessage KResponse KResponseScheme #-} | 199 | {-# SPECIALIZE instance KMessage KResponse KResponseScheme #-} |
201 | scheme = KResponseScheme . domen . respVals | 200 | scheme = KResponseScheme . keysSet . respVals |
202 | {-# INLINE scheme #-} | 201 | {-# INLINE scheme #-} |
203 | 202 | ||
204 | 203 | ||