module Ros.Graph.ParameterServer (deleteParam, setParam, getParam, searchParam,
subscribeParam, unsubscribeParam, hasParam,
getParamNames) where
import Network.XmlRpc.Client
import Network.XmlRpc.Internals (XmlRpcType)
import Ros.Internal.RosTypes
deleteParam :: URI -> CallerID -> ParamName -> IO (Int,String,Int)
deleteParam = flip remote "deleteParam"
setParam :: XmlRpcType a => URI -> CallerID -> ParamName -> a -> IO (Int,String,Int)
setParam = flip remote "setParam"
handleParam :: (Int,String,a) -> IO (Maybe a)
handleParam (1,_,x) = return $ Just x
handleParam (_,_,_) = return Nothing
getParam :: XmlRpcType a => URI -> CallerID -> ParamName -> IO (Maybe a)
getParam uri caller name = handleParam =<< remote uri "getParam" caller name
searchParam :: URI -> CallerID -> ParamName -> IO (Maybe String)
searchParam uri caller name = handle =<< remote uri "searchParam" caller name
where handle :: (Int, String, String) -> IO (Maybe String)
handle (1, _, n) = return $ Just n
handle (_, _, _) = return $ Nothing
subscribeParam :: XmlRpcType a => URI -> CallerID -> URI -> ParamName ->
IO (Maybe a)
subscribeParam uri caller myUri name =
handleParam =<< remote uri "subscribeParam" caller myUri name
unsubscribeParam :: URI -> CallerID -> URI -> ParamName -> IO (Either String Bool)
unsubscribeParam uri caller myUri name =
handle =<< remote uri "unsubscribeParam" caller myUri name
where handle :: (Int, String, Int) -> IO (Either String Bool)
handle (1, _, 0) = return $ Right False
handle (1, _, _) = return $ Right True
handle (_, msg, _) = return $ Left msg
hasParam :: URI -> CallerID -> ParamName -> IO (Either String Bool)
hasParam uri caller name = handle =<< remote uri "hasParam" caller name
where handle :: (Int,String,Bool) -> IO (Either String Bool)
handle (1,_,b) = return $ Right b
handle (_,msg,_) = return $ Left msg
getParamNames :: URI -> CallerID -> IO (Either String [String])
getParamNames uri caller = handle =<< remote uri "getParamNames" caller
where handle :: (Int, String, [String]) -> IO (Either String [String])
handle (1,_,names) = return $ Right names
handle (_,msg,_) = return $ Left msg