diff options
Diffstat (limited to 'src/Remote/KRPC.hs')
-rw-r--r-- | src/Remote/KRPC.hs | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/Remote/KRPC.hs b/src/Remote/KRPC.hs index 3659ec66..5c913daa 100644 --- a/src/Remote/KRPC.hs +++ b/src/Remote/KRPC.hs | |||
@@ -164,7 +164,7 @@ data Method param result = Method { | |||
164 | , methodVals :: [ValName] | 164 | , methodVals :: [ValName] |
165 | } deriving (Eq, Ord, Generic) | 165 | } deriving (Eq, Ord, Generic) |
166 | 166 | ||
167 | instance BEncodable (Method a b) | 167 | instance BEncode (Method a b) |
168 | 168 | ||
169 | instance (Typeable a, Typeable b) => Show (Method a b) where | 169 | instance (Typeable a, Typeable b) => Show (Method a b) where |
170 | showsPrec _ = showsMethod | 170 | showsPrec _ = showsMethod |
@@ -224,16 +224,16 @@ method :: MethodName -> [ParamName] -> [ValName] -> Method param result | |||
224 | method = Method | 224 | method = Method |
225 | {-# INLINE method #-} | 225 | {-# INLINE method #-} |
226 | 226 | ||
227 | lookupKey :: ParamName -> Map ByteString BEncode -> Result BEncode | 227 | lookupKey :: ParamName -> BDict -> Result BValue |
228 | lookupKey x = maybe (Left ("not found key " ++ BC.unpack x)) Right . M.lookup x | 228 | lookupKey x = maybe (Left ("not found key " ++ BC.unpack x)) Right . M.lookup x |
229 | 229 | ||
230 | extractArgs :: [ParamName] -> Map ParamName BEncode -> Result BEncode | 230 | extractArgs :: [ParamName] -> BDict -> Result BValue |
231 | extractArgs [] d = Right $ if M.null d then BList [] else BDict d | 231 | extractArgs [] d = Right $ if M.null d then BList [] else BDict d |
232 | extractArgs [x] d = lookupKey x d | 232 | extractArgs [x] d = lookupKey x d |
233 | extractArgs xs d = BList <$> mapM (`lookupKey` d) xs | 233 | extractArgs xs d = BList <$> mapM (`lookupKey` d) xs |
234 | {-# INLINE extractArgs #-} | 234 | {-# INLINE extractArgs #-} |
235 | 235 | ||
236 | injectVals :: [ParamName] -> BEncode -> [(ParamName, BEncode)] | 236 | injectVals :: [ParamName] -> BValue -> [(ParamName, BValue)] |
237 | injectVals [] (BList []) = [] | 237 | injectVals [] (BList []) = [] |
238 | injectVals [] (BDict d ) = M.toList d | 238 | injectVals [] (BDict d ) = M.toList d |
239 | injectVals [] be = invalidParamList [] be | 239 | injectVals [] be = invalidParamList [] be |
@@ -242,7 +242,7 @@ injectVals ps (BList as) = L.zip ps as | |||
242 | injectVals ps be = invalidParamList ps be | 242 | injectVals ps be = invalidParamList ps be |
243 | {-# INLINE injectVals #-} | 243 | {-# INLINE injectVals #-} |
244 | 244 | ||
245 | invalidParamList :: [ParamName] -> BEncode -> a | 245 | invalidParamList :: [ParamName] -> BValue -> a |
246 | invalidParamList pl be | 246 | invalidParamList pl be |
247 | = error $ "KRPC invalid parameter list: " ++ show pl ++ "\n" ++ | 247 | = error $ "KRPC invalid parameter list: " ++ show pl ++ "\n" ++ |
248 | "while procedure args are: " ++ show be | 248 | "while procedure args are: " ++ show be |
@@ -262,14 +262,14 @@ instance Exception RPCException | |||
262 | -- | Address of remote can be called by client. | 262 | -- | Address of remote can be called by client. |
263 | type RemoteAddr = KRemoteAddr | 263 | type RemoteAddr = KRemoteAddr |
264 | 264 | ||
265 | queryCall :: BEncodable param | 265 | queryCall :: BEncode param |
266 | => KRemote -> KRemoteAddr | 266 | => KRemote -> KRemoteAddr |
267 | -> Method param result -> param -> IO () | 267 | -> Method param result -> param -> IO () |
268 | queryCall sock addr m arg = sendMessage q addr sock | 268 | queryCall sock addr m arg = sendMessage q addr sock |
269 | where | 269 | where |
270 | q = kquery (methodName m) (injectVals (methodParams m) (toBEncode arg)) | 270 | q = kquery (methodName m) (injectVals (methodParams m) (toBEncode arg)) |
271 | 271 | ||
272 | getResult :: BEncodable result | 272 | getResult :: BEncode result |
273 | => KRemote | 273 | => KRemote |
274 | -> Method param result -> IO result | 274 | -> Method param result -> IO result |
275 | getResult sock m = do | 275 | getResult sock m = do |
@@ -285,7 +285,7 @@ getResult sock m = do | |||
285 | -- | Makes remote procedure call. Throws RPCException on any error | 285 | -- | Makes remote procedure call. Throws RPCException on any error |
286 | -- occurred. | 286 | -- occurred. |
287 | call :: (MonadBaseControl IO host, MonadIO host) | 287 | call :: (MonadBaseControl IO host, MonadIO host) |
288 | => (BEncodable param, BEncodable result) | 288 | => (BEncode param, BEncode result) |
289 | => RemoteAddr -- ^ Address of callee. | 289 | => RemoteAddr -- ^ Address of callee. |
290 | -> Method param result -- ^ Procedure to call. | 290 | -> Method param result -- ^ Procedure to call. |
291 | -> param -- ^ Arguments passed by callee to procedure. | 291 | -> param -- ^ Arguments passed by callee to procedure. |
@@ -294,7 +294,7 @@ call addr m arg = liftIO $ withRemote $ \sock -> do call_ sock addr m arg | |||
294 | 294 | ||
295 | -- | The same as 'call' but use already opened socket. | 295 | -- | The same as 'call' but use already opened socket. |
296 | call_ :: (MonadBaseControl IO host, MonadIO host) | 296 | call_ :: (MonadBaseControl IO host, MonadIO host) |
297 | => (BEncodable param, BEncodable result) | 297 | => (BEncode param, BEncode result) |
298 | => Remote -- ^ Socket to use | 298 | => Remote -- ^ Socket to use |
299 | -> RemoteAddr -- ^ Address of callee. | 299 | -> RemoteAddr -- ^ Address of callee. |
300 | -> Method param result -- ^ Procedure to call. | 300 | -> Method param result -- ^ Procedure to call. |
@@ -313,7 +313,7 @@ type MethodHandler remote = (MethodName, HandlerBody remote) | |||
313 | -- we can safely erase types in (==>) | 313 | -- we can safely erase types in (==>) |
314 | -- | Assign method implementation to the method signature. | 314 | -- | Assign method implementation to the method signature. |
315 | (==>) :: forall (remote :: * -> *) (param :: *) (result :: *). | 315 | (==>) :: forall (remote :: * -> *) (param :: *) (result :: *). |
316 | (BEncodable param, BEncodable result) | 316 | (BEncode param, BEncode result) |
317 | => Monad remote | 317 | => Monad remote |
318 | => Method param result -- ^ Signature. | 318 | => Method param result -- ^ Signature. |
319 | -> (param -> remote result) -- ^ Implementation. | 319 | -> (param -> remote result) -- ^ Implementation. |
@@ -324,7 +324,7 @@ infix 1 ==> | |||
324 | 324 | ||
325 | -- | Similar to '==>@' but additionally pass caller address. | 325 | -- | Similar to '==>@' but additionally pass caller address. |
326 | (==>@) :: forall (remote :: * -> *) (param :: *) (result :: *). | 326 | (==>@) :: forall (remote :: * -> *) (param :: *) (result :: *). |
327 | (BEncodable param, BEncodable result) | 327 | (BEncode param, BEncode result) |
328 | => Monad remote | 328 | => Monad remote |
329 | => Method param result -- ^ Signature. | 329 | => Method param result -- ^ Signature. |
330 | -> (KRemoteAddr -> param -> remote result) -- ^ Implementation. | 330 | -> (KRemoteAddr -> param -> remote result) -- ^ Implementation. |