summaryrefslogtreecommitdiff
path: root/src/Remote/KRPC
diff options
context:
space:
mode:
authorSam T <pxqr.sta@gmail.com>2013-05-12 01:07:34 +0400
committerSam T <pxqr.sta@gmail.com>2013-05-12 01:07:34 +0400
commitfd62eb70fe87b471d29cb994a60ad88f58b33ca9 (patch)
treeed8c7d69f10c1b874cc03c7d6e5064fb81b94482 /src/Remote/KRPC
parent7614ed760e137219fb4e36288abf1e78eacb2266 (diff)
~ Prepare to scheme check.
Diffstat (limited to 'src/Remote/KRPC')
-rw-r--r--src/Remote/KRPC/Method.hs22
-rw-r--r--src/Remote/KRPC/Protocol.hs17
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 #-}
2module Remote.KRPC.Method 9module 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
12import Prelude hiding ((.), id) 20import Prelude hiding ((.), id)
21import Control.Applicative
13import Control.Category 22import Control.Category
14import Control.Monad 23import Control.Monad
24import Data.ByteString as B
25import Data.List as L
26import Data.Set as S
15 27
16import Remote.KRPC.Protocol 28import 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
58methodQueryScheme :: Method a b -> KQueryScheme
59methodQueryScheme = KQueryScheme <$> B.intercalate "." . methodName
60 <*> S.fromList . methodParams
61{-# INLINE methodQueryScheme #-}
62
63
64methodRespScheme :: Method a b -> KResponseScheme
65methodRespScheme = 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
46import Control.Monad 46import Control.Monad
47import Control.Monad.IO.Class 47import Control.Monad.IO.Class
48import Control.Monad.Trans.Control 48import Control.Monad.Trans.Control
49
49import Data.BEncode 50import Data.BEncode
50import Data.ByteString as B 51import Data.ByteString as B
51import qualified Data.ByteString.Lazy as LB 52import qualified Data.ByteString.Lazy as LB
52import Data.Map as M 53import Data.Map as M
53import Data.Set as S 54import Data.Set as S
54import Data.Text as T 55import Data.Text as T
56
55import Network.Socket hiding (recvFrom) 57import Network.Socket hiding (recvFrom)
56import Network.Socket.ByteString 58import 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
135data KQuery = KQuery { 137data 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
140instance BEncodable KQuery where 142instance 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
163domen :: Map a b -> Set a
164domen = error "scheme.domen"
165
166instance KMessage KQuery KQueryScheme where 165instance 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
171type ValName = ByteString 170type ValName = ByteString
@@ -198,7 +197,7 @@ newtype KResponseScheme = KResponseScheme {
198 197
199instance KMessage KResponse KResponseScheme where 198instance 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