module ZooKeeper
( I.zooVersion
, I.zooSetDebugLevel
, zookeeperResInit
, U.withResource
, U.Resource
, zooCreate
, zooSet
, zooGet
, zooWatchGet
, zooGetChildren
, zooWatchGetChildren
, zooGetChildren2
, zooWatchGetChildren2
, zooDelete
, zooDeleteAll
, zooExists
, zooWatchExists
, zooGetAcl
, zooMulti
, zooCreateOpInit
, zooDeleteOpInit
, zooSetOpInit
, zooCheckOpInit
, zooClientID
, zooState
, zooRecvTimeout
, isUnrecoverable
, zookeeperInit
, zookeeperClose
) where
import Control.Monad (void, when, zipWithM, (<=<))
import Data.Bifunctor (first)
import Data.Maybe (fromMaybe)
import Foreign.C (CInt)
import Foreign.Ptr (FunPtr, Ptr, freeHaskellFunPtr,
nullFunPtr, nullPtr, plusPtr)
import GHC.Stack (HasCallStack)
import qualified Z.Data.CBytes as CBytes
import Z.Data.CBytes (CBytes)
import Z.Data.Vector (Bytes)
import qualified Z.Foreign as Z
import qualified ZooKeeper.Exception as E
import qualified ZooKeeper.Internal.FFI as I
import qualified ZooKeeper.Internal.Types as I
import qualified ZooKeeper.Internal.Utils as U
import qualified ZooKeeper.Types as T
zookeeperResInit
:: CBytes
-> Maybe T.WatcherFn
-> CInt
-> Maybe T.ClientID
-> CInt
-> U.Resource T.ZHandle
zookeeperResInit :: CBytes
-> Maybe WatcherFn
-> CInt
-> Maybe ClientID
-> CInt
-> Resource ZHandle
zookeeperResInit CBytes
host Maybe WatcherFn
fn CInt
timeout Maybe ClientID
mclientid CInt
flags = (ZHandle, FunPtr CWatcherFn) -> ZHandle
forall a b. (a, b) -> a
fst ((ZHandle, FunPtr CWatcherFn) -> ZHandle)
-> Resource (ZHandle, FunPtr CWatcherFn) -> Resource ZHandle
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
IO (ZHandle, FunPtr CWatcherFn)
-> ((ZHandle, FunPtr CWatcherFn) -> IO ())
-> Resource (ZHandle, FunPtr CWatcherFn)
forall a. IO a -> (a -> IO ()) -> Resource a
U.initResource (CBytes
-> Maybe WatcherFn
-> CInt
-> Maybe ClientID
-> CInt
-> IO (ZHandle, FunPtr CWatcherFn)
zookeeperInit CBytes
host Maybe WatcherFn
fn CInt
timeout Maybe ClientID
mclientid CInt
flags) (ZHandle, FunPtr CWatcherFn) -> IO ()
zookeeperClose
zooCreate :: HasCallStack
=> T.ZHandle
-> CBytes
-> Maybe Bytes
-> T.AclVector
-> T.CreateMode
-> IO T.StringCompletion
zooCreate :: ZHandle
-> CBytes
-> Maybe Bytes
-> AclVector
-> CreateMode
-> IO StringCompletion
zooCreate ZHandle
zh CBytes
path Maybe Bytes
m_value AclVector
acl CreateMode
mode =
CBytes -> (BA# Word8 -> IO StringCompletion) -> IO StringCompletion
forall a. CBytes -> (BA# Word8 -> IO a) -> IO a
CBytes.withCBytesUnsafe CBytes
path ((BA# Word8 -> IO StringCompletion) -> IO StringCompletion)
-> (BA# Word8 -> IO StringCompletion) -> IO StringCompletion
forall a b. (a -> b) -> a -> b
$ \BA# Word8
path' ->
case Maybe Bytes
m_value of
Just Bytes
value -> Bytes
-> (BA# Word8 -> Int -> Int -> IO StringCompletion)
-> IO StringCompletion
forall a b.
Prim a =>
PrimVector a -> (BA# Word8 -> Int -> Int -> IO b) -> IO b
Z.withPrimVectorUnsafe Bytes
value ((BA# Word8 -> Int -> Int -> IO StringCompletion)
-> IO StringCompletion)
-> (BA# Word8 -> Int -> Int -> IO StringCompletion)
-> IO StringCompletion
forall a b. (a -> b) -> a -> b
$ \BA# Word8
val' Int
offset Int
len -> do
let cfun :: StablePtr PrimMVar -> Int -> Ptr StringCompletion -> IO CInt
cfun = ZHandle
-> BA# Word8
-> BA# Word8
-> Int
-> Int
-> AclVector
-> CreateMode
-> StablePtr PrimMVar
-> Int
-> Ptr StringCompletion
-> IO CInt
I.c_hs_zoo_acreate ZHandle
zh BA# Word8
path' BA# Word8
val' Int
offset Int
len AclVector
acl CreateMode
mode
Either CInt StringCompletion -> IO StringCompletion
forall a. HasCallStack => Either CInt a -> IO a
E.throwZooErrorIfLeft (Either CInt StringCompletion -> IO StringCompletion)
-> IO (Either CInt StringCompletion) -> IO StringCompletion
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Int
-> (Ptr StringCompletion -> IO CInt)
-> (Ptr StringCompletion -> IO StringCompletion)
-> (StablePtr PrimMVar -> Int -> Ptr StringCompletion -> IO CInt)
-> IO (Either CInt StringCompletion)
forall a.
HasCallStack =>
Int
-> (Ptr a -> IO CInt)
-> (Ptr a -> IO a)
-> (StablePtr PrimMVar -> Int -> Ptr a -> IO CInt)
-> IO (Either CInt a)
I.withZKAsync Int
csize Ptr StringCompletion -> IO CInt
forall a. Completion a => Ptr a -> IO CInt
I.peekRet Ptr StringCompletion -> IO StringCompletion
forall a. Completion a => Ptr a -> IO a
I.peekData StablePtr PrimMVar -> Int -> Ptr StringCompletion -> IO CInt
cfun
Maybe Bytes
Nothing -> do
let cfun :: StablePtr PrimMVar -> Int -> Ptr StringCompletion -> IO CInt
cfun = ZHandle
-> BA# Word8
-> Ptr CChar
-> Int
-> Int
-> AclVector
-> CreateMode
-> StablePtr PrimMVar
-> Int
-> Ptr StringCompletion
-> IO CInt
I.c_hs_zoo_acreate' ZHandle
zh BA# Word8
path' Ptr CChar
forall a. Ptr a
nullPtr Int
0 (-Int
1) AclVector
acl CreateMode
mode
Either CInt StringCompletion -> IO StringCompletion
forall a. HasCallStack => Either CInt a -> IO a
E.throwZooErrorIfLeft (Either CInt StringCompletion -> IO StringCompletion)
-> IO (Either CInt StringCompletion) -> IO StringCompletion
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Int
-> (Ptr StringCompletion -> IO CInt)
-> (Ptr StringCompletion -> IO StringCompletion)
-> (StablePtr PrimMVar -> Int -> Ptr StringCompletion -> IO CInt)
-> IO (Either CInt StringCompletion)
forall a.
HasCallStack =>
Int
-> (Ptr a -> IO CInt)
-> (Ptr a -> IO a)
-> (StablePtr PrimMVar -> Int -> Ptr a -> IO CInt)
-> IO (Either CInt a)
I.withZKAsync Int
csize Ptr StringCompletion -> IO CInt
forall a. Completion a => Ptr a -> IO CInt
I.peekRet Ptr StringCompletion -> IO StringCompletion
forall a. Completion a => Ptr a -> IO a
I.peekData StablePtr PrimMVar -> Int -> Ptr StringCompletion -> IO CInt
cfun
where
csize :: Int
csize = Completion StringCompletion => Int
forall a. Completion a => Int
I.csize @T.StringCompletion
zooSet :: HasCallStack
=> T.ZHandle
-> CBytes
-> Maybe Bytes
-> Maybe CInt
-> IO T.StatCompletion
zooSet :: ZHandle -> CBytes -> Maybe Bytes -> Maybe CInt -> IO StatCompletion
zooSet ZHandle
zh CBytes
path Maybe Bytes
m_value Maybe CInt
m_version = CBytes -> (BA# Word8 -> IO StatCompletion) -> IO StatCompletion
forall a. CBytes -> (BA# Word8 -> IO a) -> IO a
CBytes.withCBytesUnsafe CBytes
path ((BA# Word8 -> IO StatCompletion) -> IO StatCompletion)
-> (BA# Word8 -> IO StatCompletion) -> IO StatCompletion
forall a b. (a -> b) -> a -> b
$ \BA# Word8
path' -> do
let csize :: Int
csize = Completion StatCompletion => Int
forall a. Completion a => Int
I.csize @T.StatCompletion
version :: CInt
version = CInt -> Maybe CInt -> CInt
forall a. a -> Maybe a -> a
fromMaybe (-CInt
1) Maybe CInt
m_version
case Maybe Bytes
m_value of
Just Bytes
value -> Bytes
-> (BA# Word8 -> Int -> Int -> IO StatCompletion)
-> IO StatCompletion
forall a b.
Prim a =>
PrimVector a -> (BA# Word8 -> Int -> Int -> IO b) -> IO b
Z.withPrimVectorUnsafe Bytes
value ((BA# Word8 -> Int -> Int -> IO StatCompletion)
-> IO StatCompletion)
-> (BA# Word8 -> Int -> Int -> IO StatCompletion)
-> IO StatCompletion
forall a b. (a -> b) -> a -> b
$ \BA# Word8
val' Int
offset Int
len -> do
let cfunc :: StablePtr PrimMVar -> Int -> Ptr StatCompletion -> IO CInt
cfunc = ZHandle
-> BA# Word8
-> BA# Word8
-> Int
-> Int
-> CInt
-> StablePtr PrimMVar
-> Int
-> Ptr StatCompletion
-> IO CInt
I.c_hs_zoo_aset ZHandle
zh BA# Word8
path' BA# Word8
val' Int
offset Int
len CInt
version
Either CInt StatCompletion -> IO StatCompletion
forall a. HasCallStack => Either CInt a -> IO a
E.throwZooErrorIfLeft (Either CInt StatCompletion -> IO StatCompletion)
-> IO (Either CInt StatCompletion) -> IO StatCompletion
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Int
-> (Ptr StatCompletion -> IO CInt)
-> (Ptr StatCompletion -> IO StatCompletion)
-> (StablePtr PrimMVar -> Int -> Ptr StatCompletion -> IO CInt)
-> IO (Either CInt StatCompletion)
forall a.
HasCallStack =>
Int
-> (Ptr a -> IO CInt)
-> (Ptr a -> IO a)
-> (StablePtr PrimMVar -> Int -> Ptr a -> IO CInt)
-> IO (Either CInt a)
I.withZKAsync Int
csize Ptr StatCompletion -> IO CInt
forall a. Completion a => Ptr a -> IO CInt
I.peekRet Ptr StatCompletion -> IO StatCompletion
forall a. Completion a => Ptr a -> IO a
I.peekData StablePtr PrimMVar -> Int -> Ptr StatCompletion -> IO CInt
cfunc
Maybe Bytes
Nothing -> do
let cfunc :: StablePtr PrimMVar -> Int -> Ptr StatCompletion -> IO CInt
cfunc = ZHandle
-> BA# Word8
-> Ptr Word8
-> Int
-> Int
-> CInt
-> StablePtr PrimMVar
-> Int
-> Ptr StatCompletion
-> IO CInt
I.c_hs_zoo_aset' ZHandle
zh BA# Word8
path' Ptr Word8
forall a. Ptr a
nullPtr Int
0 (-Int
1) CInt
version
Either CInt StatCompletion -> IO StatCompletion
forall a. HasCallStack => Either CInt a -> IO a
E.throwZooErrorIfLeft (Either CInt StatCompletion -> IO StatCompletion)
-> IO (Either CInt StatCompletion) -> IO StatCompletion
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Int
-> (Ptr StatCompletion -> IO CInt)
-> (Ptr StatCompletion -> IO StatCompletion)
-> (StablePtr PrimMVar -> Int -> Ptr StatCompletion -> IO CInt)
-> IO (Either CInt StatCompletion)
forall a.
HasCallStack =>
Int
-> (Ptr a -> IO CInt)
-> (Ptr a -> IO a)
-> (StablePtr PrimMVar -> Int -> Ptr a -> IO CInt)
-> IO (Either CInt a)
I.withZKAsync Int
csize Ptr StatCompletion -> IO CInt
forall a. Completion a => Ptr a -> IO CInt
I.peekRet Ptr StatCompletion -> IO StatCompletion
forall a. Completion a => Ptr a -> IO a
I.peekData StablePtr PrimMVar -> Int -> Ptr StatCompletion -> IO CInt
cfunc
zooGet :: HasCallStack
=> T.ZHandle
-> CBytes
-> IO T.DataCompletion
zooGet :: ZHandle -> CBytes -> IO DataCompletion
zooGet ZHandle
zh CBytes
path = CBytes -> (BA# Word8 -> IO DataCompletion) -> IO DataCompletion
forall a. CBytes -> (BA# Word8 -> IO a) -> IO a
CBytes.withCBytesUnsafe CBytes
path ((BA# Word8 -> IO DataCompletion) -> IO DataCompletion)
-> (BA# Word8 -> IO DataCompletion) -> IO DataCompletion
forall a b. (a -> b) -> a -> b
$ \BA# Word8
path' ->
let csize :: Int
csize = Completion DataCompletion => Int
forall a. Completion a => Int
I.csize @T.DataCompletion
cfunc :: StablePtr PrimMVar -> Int -> Ptr DataCompletion -> IO CInt
cfunc = ZHandle
-> BA# Word8
-> CInt
-> StablePtr PrimMVar
-> Int
-> Ptr DataCompletion
-> IO CInt
I.c_hs_zoo_aget ZHandle
zh BA# Word8
path' CInt
0
in Either CInt DataCompletion -> IO DataCompletion
forall a. HasCallStack => Either CInt a -> IO a
E.throwZooErrorIfLeft (Either CInt DataCompletion -> IO DataCompletion)
-> IO (Either CInt DataCompletion) -> IO DataCompletion
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Int
-> (Ptr DataCompletion -> IO CInt)
-> (Ptr DataCompletion -> IO DataCompletion)
-> (StablePtr PrimMVar -> Int -> Ptr DataCompletion -> IO CInt)
-> IO (Either CInt DataCompletion)
forall a.
HasCallStack =>
Int
-> (Ptr a -> IO CInt)
-> (Ptr a -> IO a)
-> (StablePtr PrimMVar -> Int -> Ptr a -> IO CInt)
-> IO (Either CInt a)
I.withZKAsync Int
csize Ptr DataCompletion -> IO CInt
forall a. Completion a => Ptr a -> IO CInt
I.peekRet Ptr DataCompletion -> IO DataCompletion
forall a. Completion a => Ptr a -> IO a
I.peekData StablePtr PrimMVar -> Int -> Ptr DataCompletion -> IO CInt
cfunc
zooWatchGet
:: HasCallStack
=> T.ZHandle
-> CBytes
-> (T.HsWatcherCtx -> IO ())
-> (T.DataCompletion -> IO ())
-> IO ()
zooWatchGet :: ZHandle
-> CBytes
-> (HsWatcherCtx -> IO ())
-> (DataCompletion -> IO ())
-> IO ()
zooWatchGet ZHandle
zh CBytes
path HsWatcherCtx -> IO ()
watchfn DataCompletion -> IO ()
datafn = CBytes -> (BA# Word8 -> IO ()) -> IO ()
forall a. CBytes -> (BA# Word8 -> IO a) -> IO a
CBytes.withCBytesUnsafe CBytes
path ((BA# Word8 -> IO ()) -> IO ()) -> (BA# Word8 -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \BA# Word8
path' ->
let csize :: Int
csize = Completion DataCompletion => Int
forall a. Completion a => Int
I.csize @T.DataCompletion
watchfn' :: Either CInt HsWatcherCtx -> IO ()
watchfn' = HsWatcherCtx -> IO ()
watchfn (HsWatcherCtx -> IO ())
-> (Either CInt HsWatcherCtx -> IO HsWatcherCtx)
-> Either CInt HsWatcherCtx
-> IO ()
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< Either CInt HsWatcherCtx -> IO HsWatcherCtx
forall a. HasCallStack => Either CInt a -> IO a
E.throwZooErrorIfLeft
datafn' :: Either CInt DataCompletion -> IO ()
datafn' = DataCompletion -> IO ()
datafn (DataCompletion -> IO ())
-> (Either CInt DataCompletion -> IO DataCompletion)
-> Either CInt DataCompletion
-> IO ()
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< Either CInt DataCompletion -> IO DataCompletion
forall a. HasCallStack => Either CInt a -> IO a
E.throwZooErrorIfLeft
in Int
-> (Ptr HsWatcherCtx -> IO CInt)
-> (Ptr HsWatcherCtx -> IO HsWatcherCtx)
-> (Either CInt HsWatcherCtx -> IO ())
-> Int
-> (Ptr DataCompletion -> IO CInt)
-> (Ptr DataCompletion -> IO DataCompletion)
-> (Either CInt DataCompletion -> IO ())
-> (StablePtr PrimMVar
-> StablePtr PrimMVar
-> Int
-> Ptr HsWatcherCtx
-> Ptr DataCompletion
-> IO CInt)
-> IO ()
forall a b.
HasCallStack =>
Int
-> (Ptr a -> IO CInt)
-> (Ptr a -> IO a)
-> (Either CInt a -> IO ())
-> Int
-> (Ptr b -> IO CInt)
-> (Ptr b -> IO b)
-> (Either CInt b -> IO ())
-> (StablePtr PrimMVar
-> StablePtr PrimMVar -> Int -> Ptr a -> Ptr b -> IO CInt)
-> IO ()
I.withZKAsync2
Int
I.hsWatcherCtxSize (\Ptr HsWatcherCtx
_ -> CInt -> IO CInt
forall (m :: * -> *) a. Monad m => a -> m a
return CInt
E.CZOK) Ptr HsWatcherCtx -> IO HsWatcherCtx
I.peekHsWatcherCtx Either CInt HsWatcherCtx -> IO ()
watchfn'
Int
csize Ptr DataCompletion -> IO CInt
forall a. Completion a => Ptr a -> IO CInt
I.peekRet Ptr DataCompletion -> IO DataCompletion
forall a. Completion a => Ptr a -> IO a
I.peekData Either CInt DataCompletion -> IO ()
datafn'
(ZHandle
-> BA# Word8
-> StablePtr PrimMVar
-> StablePtr PrimMVar
-> Int
-> Ptr HsWatcherCtx
-> Ptr DataCompletion
-> IO CInt
I.c_hs_zoo_awget ZHandle
zh BA# Word8
path')
zooDelete :: HasCallStack
=> T.ZHandle
-> CBytes
-> Maybe CInt
-> IO ()
zooDelete :: ZHandle -> CBytes -> Maybe CInt -> IO ()
zooDelete ZHandle
zh CBytes
path Maybe CInt
m_version = CBytes -> (BA# Word8 -> IO ()) -> IO ()
forall a. CBytes -> (BA# Word8 -> IO a) -> IO a
CBytes.withCBytesUnsafe CBytes
path ((BA# Word8 -> IO ()) -> IO ()) -> (BA# Word8 -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \BA# Word8
path' ->
let csize :: Int
csize = Completion VoidCompletion => Int
forall a. Completion a => Int
I.csize @T.VoidCompletion
cfunc :: StablePtr PrimMVar -> Int -> Ptr VoidCompletion -> IO CInt
cfunc = ZHandle
-> BA# Word8
-> CInt
-> StablePtr PrimMVar
-> Int
-> Ptr VoidCompletion
-> IO CInt
I.c_hs_zoo_adelete ZHandle
zh BA# Word8
path' CInt
version
version :: CInt
version = CInt -> Maybe CInt -> CInt
forall a. a -> Maybe a -> a
fromMaybe (-CInt
1) Maybe CInt
m_version
in IO VoidCompletion -> IO ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (IO VoidCompletion -> IO ()) -> IO VoidCompletion -> IO ()
forall a b. (a -> b) -> a -> b
$ Either CInt VoidCompletion -> IO VoidCompletion
forall a. HasCallStack => Either CInt a -> IO a
E.throwZooErrorIfLeft (Either CInt VoidCompletion -> IO VoidCompletion)
-> IO (Either CInt VoidCompletion) -> IO VoidCompletion
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Int
-> (Ptr VoidCompletion -> IO CInt)
-> (Ptr VoidCompletion -> IO VoidCompletion)
-> (StablePtr PrimMVar -> Int -> Ptr VoidCompletion -> IO CInt)
-> IO (Either CInt VoidCompletion)
forall a.
HasCallStack =>
Int
-> (Ptr a -> IO CInt)
-> (Ptr a -> IO a)
-> (StablePtr PrimMVar -> Int -> Ptr a -> IO CInt)
-> IO (Either CInt a)
I.withZKAsync Int
csize Ptr VoidCompletion -> IO CInt
forall a. Completion a => Ptr a -> IO CInt
I.peekRet Ptr VoidCompletion -> IO VoidCompletion
forall a. Completion a => Ptr a -> IO a
I.peekData StablePtr PrimMVar -> Int -> Ptr VoidCompletion -> IO CInt
cfunc
zooDeleteAll :: HasCallStack => T.ZHandle -> CBytes -> IO ()
zooDeleteAll :: ZHandle -> CBytes -> IO ()
zooDeleteAll ZHandle
zh CBytes
path = do
T.StringsCompletion (T.StringVector [CBytes]
children) <- HasCallStack => ZHandle -> CBytes -> IO StringsCompletion
ZHandle -> CBytes -> IO StringsCompletion
zooGetChildren ZHandle
zh CBytes
path
(CBytes -> IO ()) -> [CBytes] -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (HasCallStack => ZHandle -> CBytes -> IO ()
ZHandle -> CBytes -> IO ()
zooDeleteAll ZHandle
zh (CBytes -> IO ()) -> (CBytes -> CBytes) -> CBytes -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((CBytes
path CBytes -> CBytes -> CBytes
forall a. Semigroup a => a -> a -> a
<> CBytes
"/") CBytes -> CBytes -> CBytes
forall a. Semigroup a => a -> a -> a
<>)) [CBytes]
children
HasCallStack => ZHandle -> CBytes -> Maybe CInt -> IO ()
ZHandle -> CBytes -> Maybe CInt -> IO ()
zooDelete ZHandle
zh CBytes
path Maybe CInt
forall a. Maybe a
Nothing
zooExists :: HasCallStack
=> T.ZHandle
-> CBytes
-> IO (Maybe T.StatCompletion)
zooExists :: ZHandle -> CBytes -> IO (Maybe StatCompletion)
zooExists ZHandle
zh CBytes
path =
CBytes
-> (BA# Word8 -> IO (Maybe StatCompletion))
-> IO (Maybe StatCompletion)
forall a. CBytes -> (BA# Word8 -> IO a) -> IO a
CBytes.withCBytesUnsafe CBytes
path ((BA# Word8 -> IO (Maybe StatCompletion))
-> IO (Maybe StatCompletion))
-> (BA# Word8 -> IO (Maybe StatCompletion))
-> IO (Maybe StatCompletion)
forall a b. (a -> b) -> a -> b
$ \BA# Word8
path' ->
let csize :: Int
csize = Completion StatCompletion => Int
forall a. Completion a => Int
I.csize @T.StatCompletion
cfunc :: StablePtr PrimMVar -> Int -> Ptr StatCompletion -> IO CInt
cfunc = ZHandle
-> BA# Word8
-> CInt
-> StablePtr PrimMVar
-> Int
-> Ptr StatCompletion
-> IO CInt
I.c_hs_zoo_aexists ZHandle
zh BA# Word8
path' CInt
0
in (CInt -> Bool)
-> Either CInt StatCompletion -> IO (Maybe StatCompletion)
forall a.
HasCallStack =>
(CInt -> Bool) -> Either CInt a -> IO (Maybe a)
E.throwZooErrorIfLeft' (CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
== CInt
E.CZNONODE) (Either CInt StatCompletion -> IO (Maybe StatCompletion))
-> IO (Either CInt StatCompletion) -> IO (Maybe StatCompletion)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Int
-> (Ptr StatCompletion -> IO CInt)
-> (Ptr StatCompletion -> IO StatCompletion)
-> (StablePtr PrimMVar -> Int -> Ptr StatCompletion -> IO CInt)
-> IO (Either CInt StatCompletion)
forall a.
HasCallStack =>
Int
-> (Ptr a -> IO CInt)
-> (Ptr a -> IO a)
-> (StablePtr PrimMVar -> Int -> Ptr a -> IO CInt)
-> IO (Either CInt a)
I.withZKAsync Int
csize Ptr StatCompletion -> IO CInt
forall a. Completion a => Ptr a -> IO CInt
I.peekRet Ptr StatCompletion -> IO StatCompletion
forall a. Completion a => Ptr a -> IO a
I.peekData StablePtr PrimMVar -> Int -> Ptr StatCompletion -> IO CInt
cfunc
zooWatchExists
:: HasCallStack
=> T.ZHandle
-> CBytes
-> (T.HsWatcherCtx -> IO ())
-> (Maybe T.StatCompletion -> IO ())
-> IO ()
zooWatchExists :: ZHandle
-> CBytes
-> (HsWatcherCtx -> IO ())
-> (Maybe StatCompletion -> IO ())
-> IO ()
zooWatchExists ZHandle
zh CBytes
path HsWatcherCtx -> IO ()
watchfn Maybe StatCompletion -> IO ()
statfn =
let csize :: Int
csize = Completion StatCompletion => Int
forall a. Completion a => Int
I.csize @T.StatCompletion
watchfn' :: Either CInt HsWatcherCtx -> IO ()
watchfn' = HsWatcherCtx -> IO ()
watchfn (HsWatcherCtx -> IO ())
-> (Either CInt HsWatcherCtx -> IO HsWatcherCtx)
-> Either CInt HsWatcherCtx
-> IO ()
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< Either CInt HsWatcherCtx -> IO HsWatcherCtx
forall a. HasCallStack => Either CInt a -> IO a
E.throwZooErrorIfLeft
statfn' :: Either CInt StatCompletion -> IO ()
statfn' = Maybe StatCompletion -> IO ()
statfn (Maybe StatCompletion -> IO ())
-> (Either CInt StatCompletion -> IO (Maybe StatCompletion))
-> Either CInt StatCompletion
-> IO ()
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< (CInt -> Bool)
-> Either CInt StatCompletion -> IO (Maybe StatCompletion)
forall a.
HasCallStack =>
(CInt -> Bool) -> Either CInt a -> IO (Maybe a)
E.throwZooErrorIfLeft' (CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
== CInt
E.CZNONODE)
in CBytes -> (BA# Word8 -> IO ()) -> IO ()
forall a. CBytes -> (BA# Word8 -> IO a) -> IO a
CBytes.withCBytesUnsafe CBytes
path ((BA# Word8 -> IO ()) -> IO ()) -> (BA# Word8 -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \BA# Word8
path' ->
Int
-> (Ptr HsWatcherCtx -> IO CInt)
-> (Ptr HsWatcherCtx -> IO HsWatcherCtx)
-> (Either CInt HsWatcherCtx -> IO ())
-> Int
-> (Ptr StatCompletion -> IO CInt)
-> (Ptr StatCompletion -> IO StatCompletion)
-> (Either CInt StatCompletion -> IO ())
-> (StablePtr PrimMVar
-> StablePtr PrimMVar
-> Int
-> Ptr HsWatcherCtx
-> Ptr StatCompletion
-> IO CInt)
-> IO ()
forall a b.
HasCallStack =>
Int
-> (Ptr a -> IO CInt)
-> (Ptr a -> IO a)
-> (Either CInt a -> IO ())
-> Int
-> (Ptr b -> IO CInt)
-> (Ptr b -> IO b)
-> (Either CInt b -> IO ())
-> (StablePtr PrimMVar
-> StablePtr PrimMVar -> Int -> Ptr a -> Ptr b -> IO CInt)
-> IO ()
I.withZKAsync2
Int
I.hsWatcherCtxSize (\Ptr HsWatcherCtx
_ -> CInt -> IO CInt
forall (m :: * -> *) a. Monad m => a -> m a
return CInt
E.CZOK) Ptr HsWatcherCtx -> IO HsWatcherCtx
I.peekHsWatcherCtx Either CInt HsWatcherCtx -> IO ()
watchfn'
Int
csize Ptr StatCompletion -> IO CInt
forall a. Completion a => Ptr a -> IO CInt
I.peekRet Ptr StatCompletion -> IO StatCompletion
forall a. Completion a => Ptr a -> IO a
I.peekData Either CInt StatCompletion -> IO ()
statfn'
(ZHandle
-> BA# Word8
-> StablePtr PrimMVar
-> StablePtr PrimMVar
-> Int
-> Ptr HsWatcherCtx
-> Ptr StatCompletion
-> IO CInt
I.c_hs_zoo_awexists ZHandle
zh BA# Word8
path')
zooGetChildren
:: HasCallStack
=> T.ZHandle
-> CBytes
-> IO T.StringsCompletion
zooGetChildren :: ZHandle -> CBytes -> IO StringsCompletion
zooGetChildren ZHandle
zh CBytes
path = CBytes
-> (BA# Word8 -> IO StringsCompletion) -> IO StringsCompletion
forall a. CBytes -> (BA# Word8 -> IO a) -> IO a
CBytes.withCBytesUnsafe CBytes
path ((BA# Word8 -> IO StringsCompletion) -> IO StringsCompletion)
-> (BA# Word8 -> IO StringsCompletion) -> IO StringsCompletion
forall a b. (a -> b) -> a -> b
$ \BA# Word8
path' -> do
let csize :: Int
csize = Completion StringsCompletion => Int
forall a. Completion a => Int
I.csize @T.StringsCompletion
cfunc :: StablePtr PrimMVar -> Int -> Ptr StringsCompletion -> IO CInt
cfunc = ZHandle
-> BA# Word8
-> CInt
-> StablePtr PrimMVar
-> Int
-> Ptr StringsCompletion
-> IO CInt
I.c_hs_zoo_aget_children ZHandle
zh BA# Word8
path' CInt
0
in Either CInt StringsCompletion -> IO StringsCompletion
forall a. HasCallStack => Either CInt a -> IO a
E.throwZooErrorIfLeft (Either CInt StringsCompletion -> IO StringsCompletion)
-> IO (Either CInt StringsCompletion) -> IO StringsCompletion
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Int
-> (Ptr StringsCompletion -> IO CInt)
-> (Ptr StringsCompletion -> IO StringsCompletion)
-> (StablePtr PrimMVar -> Int -> Ptr StringsCompletion -> IO CInt)
-> IO (Either CInt StringsCompletion)
forall a.
HasCallStack =>
Int
-> (Ptr a -> IO CInt)
-> (Ptr a -> IO a)
-> (StablePtr PrimMVar -> Int -> Ptr a -> IO CInt)
-> IO (Either CInt a)
I.withZKAsync Int
csize Ptr StringsCompletion -> IO CInt
forall a. Completion a => Ptr a -> IO CInt
I.peekRet Ptr StringsCompletion -> IO StringsCompletion
forall a. Completion a => Ptr a -> IO a
I.peekData StablePtr PrimMVar -> Int -> Ptr StringsCompletion -> IO CInt
cfunc
zooWatchGetChildren
:: HasCallStack
=> T.ZHandle
-> CBytes
-> (T.HsWatcherCtx -> IO ())
-> (T.StringsCompletion -> IO ())
-> IO ()
zooWatchGetChildren :: ZHandle
-> CBytes
-> (HsWatcherCtx -> IO ())
-> (StringsCompletion -> IO ())
-> IO ()
zooWatchGetChildren ZHandle
zh CBytes
path HsWatcherCtx -> IO ()
watchfn StringsCompletion -> IO ()
stringsfn =
let csize :: Int
csize = Completion StringsCompletion => Int
forall a. Completion a => Int
I.csize @T.StringsCompletion
watchfn' :: Either CInt HsWatcherCtx -> IO ()
watchfn' = HsWatcherCtx -> IO ()
watchfn (HsWatcherCtx -> IO ())
-> (Either CInt HsWatcherCtx -> IO HsWatcherCtx)
-> Either CInt HsWatcherCtx
-> IO ()
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< Either CInt HsWatcherCtx -> IO HsWatcherCtx
forall a. HasCallStack => Either CInt a -> IO a
E.throwZooErrorIfLeft
stringsfn' :: Either CInt StringsCompletion -> IO ()
stringsfn' = StringsCompletion -> IO ()
stringsfn (StringsCompletion -> IO ())
-> (Either CInt StringsCompletion -> IO StringsCompletion)
-> Either CInt StringsCompletion
-> IO ()
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< Either CInt StringsCompletion -> IO StringsCompletion
forall a. HasCallStack => Either CInt a -> IO a
E.throwZooErrorIfLeft
in CBytes -> (BA# Word8 -> IO ()) -> IO ()
forall a. CBytes -> (BA# Word8 -> IO a) -> IO a
CBytes.withCBytesUnsafe CBytes
path ((BA# Word8 -> IO ()) -> IO ()) -> (BA# Word8 -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \BA# Word8
path' ->
Int
-> (Ptr HsWatcherCtx -> IO CInt)
-> (Ptr HsWatcherCtx -> IO HsWatcherCtx)
-> (Either CInt HsWatcherCtx -> IO ())
-> Int
-> (Ptr StringsCompletion -> IO CInt)
-> (Ptr StringsCompletion -> IO StringsCompletion)
-> (Either CInt StringsCompletion -> IO ())
-> (StablePtr PrimMVar
-> StablePtr PrimMVar
-> Int
-> Ptr HsWatcherCtx
-> Ptr StringsCompletion
-> IO CInt)
-> IO ()
forall a b.
HasCallStack =>
Int
-> (Ptr a -> IO CInt)
-> (Ptr a -> IO a)
-> (Either CInt a -> IO ())
-> Int
-> (Ptr b -> IO CInt)
-> (Ptr b -> IO b)
-> (Either CInt b -> IO ())
-> (StablePtr PrimMVar
-> StablePtr PrimMVar -> Int -> Ptr a -> Ptr b -> IO CInt)
-> IO ()
I.withZKAsync2
Int
I.hsWatcherCtxSize (\Ptr HsWatcherCtx
_ -> CInt -> IO CInt
forall (m :: * -> *) a. Monad m => a -> m a
return CInt
E.CZOK) Ptr HsWatcherCtx -> IO HsWatcherCtx
I.peekHsWatcherCtx Either CInt HsWatcherCtx -> IO ()
watchfn'
Int
csize Ptr StringsCompletion -> IO CInt
forall a. Completion a => Ptr a -> IO CInt
I.peekRet Ptr StringsCompletion -> IO StringsCompletion
forall a. Completion a => Ptr a -> IO a
I.peekData Either CInt StringsCompletion -> IO ()
stringsfn'
(ZHandle
-> BA# Word8
-> StablePtr PrimMVar
-> StablePtr PrimMVar
-> Int
-> Ptr HsWatcherCtx
-> Ptr StringsCompletion
-> IO CInt
I.c_hs_zoo_awget_children ZHandle
zh BA# Word8
path')
zooGetChildren2
:: HasCallStack
=> T.ZHandle
-> CBytes
-> IO T.StringsStatCompletion
zooGetChildren2 :: ZHandle -> CBytes -> IO StringsStatCompletion
zooGetChildren2 ZHandle
zh CBytes
path = CBytes
-> (BA# Word8 -> IO StringsStatCompletion)
-> IO StringsStatCompletion
forall a. CBytes -> (BA# Word8 -> IO a) -> IO a
CBytes.withCBytesUnsafe CBytes
path ((BA# Word8 -> IO StringsStatCompletion)
-> IO StringsStatCompletion)
-> (BA# Word8 -> IO StringsStatCompletion)
-> IO StringsStatCompletion
forall a b. (a -> b) -> a -> b
$ \BA# Word8
path' -> do
let csize :: Int
csize = Completion StringsStatCompletion => Int
forall a. Completion a => Int
I.csize @T.StringsStatCompletion
cfunc :: StablePtr PrimMVar -> Int -> Ptr StringsStatCompletion -> IO CInt
cfunc = ZHandle
-> BA# Word8
-> CInt
-> StablePtr PrimMVar
-> Int
-> Ptr StringsStatCompletion
-> IO CInt
I.c_hs_zoo_aget_children2 ZHandle
zh BA# Word8
path' CInt
0
in Either CInt StringsStatCompletion -> IO StringsStatCompletion
forall a. HasCallStack => Either CInt a -> IO a
E.throwZooErrorIfLeft (Either CInt StringsStatCompletion -> IO StringsStatCompletion)
-> IO (Either CInt StringsStatCompletion)
-> IO StringsStatCompletion
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Int
-> (Ptr StringsStatCompletion -> IO CInt)
-> (Ptr StringsStatCompletion -> IO StringsStatCompletion)
-> (StablePtr PrimMVar
-> Int -> Ptr StringsStatCompletion -> IO CInt)
-> IO (Either CInt StringsStatCompletion)
forall a.
HasCallStack =>
Int
-> (Ptr a -> IO CInt)
-> (Ptr a -> IO a)
-> (StablePtr PrimMVar -> Int -> Ptr a -> IO CInt)
-> IO (Either CInt a)
I.withZKAsync Int
csize Ptr StringsStatCompletion -> IO CInt
forall a. Completion a => Ptr a -> IO CInt
I.peekRet Ptr StringsStatCompletion -> IO StringsStatCompletion
forall a. Completion a => Ptr a -> IO a
I.peekData StablePtr PrimMVar -> Int -> Ptr StringsStatCompletion -> IO CInt
cfunc
zooWatchGetChildren2
:: HasCallStack
=> T.ZHandle
-> CBytes
-> (T.HsWatcherCtx -> IO ())
-> (T.StringsStatCompletion -> IO ())
-> IO ()
zooWatchGetChildren2 :: ZHandle
-> CBytes
-> (HsWatcherCtx -> IO ())
-> (StringsStatCompletion -> IO ())
-> IO ()
zooWatchGetChildren2 ZHandle
zh CBytes
path HsWatcherCtx -> IO ()
watchfn StringsStatCompletion -> IO ()
strsStatfn =
let csize :: Int
csize = Completion StringsStatCompletion => Int
forall a. Completion a => Int
I.csize @T.StringsStatCompletion
watchfn' :: Either CInt HsWatcherCtx -> IO ()
watchfn' = HsWatcherCtx -> IO ()
watchfn (HsWatcherCtx -> IO ())
-> (Either CInt HsWatcherCtx -> IO HsWatcherCtx)
-> Either CInt HsWatcherCtx
-> IO ()
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< Either CInt HsWatcherCtx -> IO HsWatcherCtx
forall a. HasCallStack => Either CInt a -> IO a
E.throwZooErrorIfLeft
stringsfn' :: Either CInt StringsStatCompletion -> IO ()
stringsfn' = StringsStatCompletion -> IO ()
strsStatfn (StringsStatCompletion -> IO ())
-> (Either CInt StringsStatCompletion -> IO StringsStatCompletion)
-> Either CInt StringsStatCompletion
-> IO ()
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< Either CInt StringsStatCompletion -> IO StringsStatCompletion
forall a. HasCallStack => Either CInt a -> IO a
E.throwZooErrorIfLeft
in CBytes -> (BA# Word8 -> IO ()) -> IO ()
forall a. CBytes -> (BA# Word8 -> IO a) -> IO a
CBytes.withCBytesUnsafe CBytes
path ((BA# Word8 -> IO ()) -> IO ()) -> (BA# Word8 -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \BA# Word8
path' ->
Int
-> (Ptr HsWatcherCtx -> IO CInt)
-> (Ptr HsWatcherCtx -> IO HsWatcherCtx)
-> (Either CInt HsWatcherCtx -> IO ())
-> Int
-> (Ptr StringsStatCompletion -> IO CInt)
-> (Ptr StringsStatCompletion -> IO StringsStatCompletion)
-> (Either CInt StringsStatCompletion -> IO ())
-> (StablePtr PrimMVar
-> StablePtr PrimMVar
-> Int
-> Ptr HsWatcherCtx
-> Ptr StringsStatCompletion
-> IO CInt)
-> IO ()
forall a b.
HasCallStack =>
Int
-> (Ptr a -> IO CInt)
-> (Ptr a -> IO a)
-> (Either CInt a -> IO ())
-> Int
-> (Ptr b -> IO CInt)
-> (Ptr b -> IO b)
-> (Either CInt b -> IO ())
-> (StablePtr PrimMVar
-> StablePtr PrimMVar -> Int -> Ptr a -> Ptr b -> IO CInt)
-> IO ()
I.withZKAsync2
Int
I.hsWatcherCtxSize (\Ptr HsWatcherCtx
_ -> CInt -> IO CInt
forall (m :: * -> *) a. Monad m => a -> m a
return CInt
E.CZOK) Ptr HsWatcherCtx -> IO HsWatcherCtx
I.peekHsWatcherCtx Either CInt HsWatcherCtx -> IO ()
watchfn'
Int
csize Ptr StringsStatCompletion -> IO CInt
forall a. Completion a => Ptr a -> IO CInt
I.peekRet Ptr StringsStatCompletion -> IO StringsStatCompletion
forall a. Completion a => Ptr a -> IO a
I.peekData Either CInt StringsStatCompletion -> IO ()
stringsfn'
(ZHandle
-> BA# Word8
-> StablePtr PrimMVar
-> StablePtr PrimMVar
-> Int
-> Ptr HsWatcherCtx
-> Ptr StringsStatCompletion
-> IO CInt
I.c_hs_zoo_awget_children2 ZHandle
zh BA# Word8
path')
zooGetAcl
:: HasCallStack
=> T.ZHandle
-> CBytes
-> IO T.AclCompletion
zooGetAcl :: ZHandle -> CBytes -> IO AclCompletion
zooGetAcl ZHandle
zh CBytes
path = CBytes -> (BA# Word8 -> IO AclCompletion) -> IO AclCompletion
forall a. CBytes -> (BA# Word8 -> IO a) -> IO a
CBytes.withCBytesUnsafe CBytes
path ((BA# Word8 -> IO AclCompletion) -> IO AclCompletion)
-> (BA# Word8 -> IO AclCompletion) -> IO AclCompletion
forall a b. (a -> b) -> a -> b
$ \BA# Word8
path' -> do
let csize :: Int
csize = Completion AclCompletion => Int
forall a. Completion a => Int
I.csize @T.AclCompletion
cfunc :: StablePtr PrimMVar -> Int -> Ptr AclCompletion -> IO CInt
cfunc = ZHandle
-> BA# Word8
-> StablePtr PrimMVar
-> Int
-> Ptr AclCompletion
-> IO CInt
I.c_hs_zoo_aget_acl ZHandle
zh BA# Word8
path'
in Either CInt AclCompletion -> IO AclCompletion
forall a. HasCallStack => Either CInt a -> IO a
E.throwZooErrorIfLeft (Either CInt AclCompletion -> IO AclCompletion)
-> IO (Either CInt AclCompletion) -> IO AclCompletion
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Int
-> (Ptr AclCompletion -> IO CInt)
-> (Ptr AclCompletion -> IO AclCompletion)
-> (StablePtr PrimMVar -> Int -> Ptr AclCompletion -> IO CInt)
-> IO (Either CInt AclCompletion)
forall a.
HasCallStack =>
Int
-> (Ptr a -> IO CInt)
-> (Ptr a -> IO a)
-> (StablePtr PrimMVar -> Int -> Ptr a -> IO CInt)
-> IO (Either CInt a)
I.withZKAsync Int
csize Ptr AclCompletion -> IO CInt
forall a. Completion a => Ptr a -> IO CInt
I.peekRet Ptr AclCompletion -> IO AclCompletion
forall a. Completion a => Ptr a -> IO a
I.peekData StablePtr PrimMVar -> Int -> Ptr AclCompletion -> IO CInt
cfunc
zooMulti
:: HasCallStack
=> T.ZHandle
-> [T.ZooOp]
-> IO [T.ZooOpResult]
zooMulti :: ZHandle -> [ZooOp] -> IO [ZooOpResult]
zooMulti ZHandle
zh [ZooOp]
ops = do
let len :: Int
len = [ZooOp] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [ZooOp]
ops
completionSize :: Int
completionSize = Completion VoidCompletion => Int
forall a. Completion a => Int
I.csize @T.VoidCompletion
chunkPtr :: Ptr a -> Int -> [Ptr b]
chunkPtr Ptr a
ptr Int
size = (Int -> Ptr b) -> [Int] -> [Ptr b]
forall a b. (a -> b) -> [a] -> [b]
map (\Int
i -> Ptr a
ptr Ptr a -> Int -> Ptr b
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
size)) [Int
0..Int
lenInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1]
mbai :: MutableByteArray RealWorld
mbai@(Z.MutableByteArray MutableByteArray# RealWorld
mbai#) <- Int -> IO (MutableByteArray (PrimState IO))
forall (m :: * -> *).
PrimMonad m =>
Int -> m (MutableByteArray (PrimState m))
Z.newPinnedByteArray (Int
I.zooOpSize Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
len)
mbar :: MutableByteArray RealWorld
mbar@(Z.MutableByteArray MutableByteArray# RealWorld
mbar#) <- Int -> IO (MutableByteArray (PrimState IO))
forall (m :: * -> *).
PrimMonad m =>
Int -> m (MutableByteArray (PrimState m))
Z.newPinnedByteArray (Int
I.zooOpResultSize Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
len)
let ptr :: Ptr Word8
ptr = MutableByteArray RealWorld -> Ptr Word8
forall s. MutableByteArray s -> Ptr Word8
Z.mutableByteArrayContents MutableByteArray RealWorld
mbai
ptr_result :: Ptr Word8
ptr_result = MutableByteArray RealWorld -> Ptr Word8
forall s. MutableByteArray s -> Ptr Word8
Z.mutableByteArrayContents MutableByteArray RealWorld
mbar
[(Ptr CZooOpResult -> IO ZooOpResult, TouchListBytes)]
res <- ((ZooOp, Ptr CZooOp)
-> IO (Ptr CZooOpResult -> IO ZooOpResult, TouchListBytes))
-> [(ZooOp, Ptr CZooOp)]
-> IO [(Ptr CZooOpResult -> IO ZooOpResult, TouchListBytes)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (ZooOp, Ptr CZooOp)
-> IO (Ptr CZooOpResult -> IO ZooOpResult, TouchListBytes)
initOp ([(ZooOp, Ptr CZooOp)]
-> IO [(Ptr CZooOpResult -> IO ZooOpResult, TouchListBytes)])
-> [(ZooOp, Ptr CZooOp)]
-> IO [(Ptr CZooOpResult -> IO ZooOpResult, TouchListBytes)]
forall a b. (a -> b) -> a -> b
$ [ZooOp] -> [Ptr CZooOp] -> [(ZooOp, Ptr CZooOp)]
forall a b. [a] -> [b] -> [(a, b)]
zip [ZooOp]
ops (Ptr Word8 -> Int -> [Ptr CZooOp]
forall a b. Ptr a -> Int -> [Ptr b]
chunkPtr Ptr Word8
ptr Int
I.zooOpSize)
Either CInt VoidCompletion -> IO VoidCompletion
forall a. HasCallStack => Either CInt a -> IO a
E.throwZooErrorIfLeft (Either CInt VoidCompletion -> IO VoidCompletion)
-> IO (Either CInt VoidCompletion) -> IO VoidCompletion
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<
TouchListBytes
-> Int
-> (Ptr VoidCompletion -> IO CInt)
-> (Ptr VoidCompletion -> IO VoidCompletion)
-> (StablePtr PrimMVar -> Int -> Ptr VoidCompletion -> IO CInt)
-> IO (Either CInt VoidCompletion)
forall a.
HasCallStack =>
TouchListBytes
-> Int
-> (Ptr a -> IO CInt)
-> (Ptr a -> IO a)
-> (StablePtr PrimMVar -> Int -> Ptr a -> IO CInt)
-> IO (Either CInt a)
I.withZKAsync' (((Ptr CZooOpResult -> IO ZooOpResult, TouchListBytes)
-> TouchListBytes)
-> [(Ptr CZooOpResult -> IO ZooOpResult, TouchListBytes)]
-> TouchListBytes
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (Ptr CZooOpResult -> IO ZooOpResult, TouchListBytes)
-> TouchListBytes
forall a b. (a, b) -> b
snd [(Ptr CZooOpResult -> IO ZooOpResult, TouchListBytes)]
res) Int
completionSize Ptr VoidCompletion -> IO CInt
forall a. Completion a => Ptr a -> IO CInt
I.peekRet Ptr VoidCompletion -> IO VoidCompletion
forall a. Completion a => Ptr a -> IO a
I.peekData
(ZHandle
-> CInt
-> MutableByteArray# RealWorld
-> MutableByteArray# RealWorld
-> StablePtr PrimMVar
-> Int
-> Ptr VoidCompletion
-> IO CInt
I.c_hs_zoo_amulti ZHandle
zh (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
len) MutableByteArray# RealWorld
mbai# MutableByteArray# RealWorld
mbar#)
((Ptr CZooOpResult -> IO ZooOpResult)
-> Ptr CZooOpResult -> IO ZooOpResult)
-> [Ptr CZooOpResult -> IO ZooOpResult]
-> [Ptr CZooOpResult]
-> IO [ZooOpResult]
forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> m c) -> [a] -> [b] -> m [c]
zipWithM (Ptr CZooOpResult -> IO ZooOpResult)
-> Ptr CZooOpResult -> IO ZooOpResult
forall a b. (a -> b) -> a -> b
($) (((Ptr CZooOpResult -> IO ZooOpResult, TouchListBytes)
-> Ptr CZooOpResult -> IO ZooOpResult)
-> [(Ptr CZooOpResult -> IO ZooOpResult, TouchListBytes)]
-> [Ptr CZooOpResult -> IO ZooOpResult]
forall a b. (a -> b) -> [a] -> [b]
map (Ptr CZooOpResult -> IO ZooOpResult, TouchListBytes)
-> Ptr CZooOpResult -> IO ZooOpResult
forall a b. (a, b) -> a
fst [(Ptr CZooOpResult -> IO ZooOpResult, TouchListBytes)]
res) (Ptr Word8 -> Int -> [Ptr CZooOpResult]
forall a b. Ptr a -> Int -> [Ptr b]
chunkPtr Ptr Word8
ptr_result Int
I.zooOpResultSize)
initOp :: (I.ZooOp, Ptr I.CZooOp)
-> IO (Ptr I.CZooOpResult -> IO T.ZooOpResult, I.TouchListBytes)
initOp :: (ZooOp, Ptr CZooOp)
-> IO (Ptr CZooOpResult -> IO ZooOpResult, TouchListBytes)
initOp (I.ZooCreateOp Ptr CZooOp -> IO (MutableByteArray RealWorld, TouchListBytes)
f, Ptr CZooOp
p) = (MutableByteArray RealWorld -> Ptr CZooOpResult -> IO ZooOpResult)
-> (MutableByteArray RealWorld, TouchListBytes)
-> (Ptr CZooOpResult -> IO ZooOpResult, TouchListBytes)
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first MutableByteArray RealWorld -> Ptr CZooOpResult -> IO ZooOpResult
I.peekZooCreateOpResult ((MutableByteArray RealWorld, TouchListBytes)
-> (Ptr CZooOpResult -> IO ZooOpResult, TouchListBytes))
-> IO (MutableByteArray RealWorld, TouchListBytes)
-> IO (Ptr CZooOpResult -> IO ZooOpResult, TouchListBytes)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` Ptr CZooOp -> IO (MutableByteArray RealWorld, TouchListBytes)
f Ptr CZooOp
p
initOp (I.ZooDeleteOp Ptr CZooOp -> IO ((), TouchListBytes)
f, Ptr CZooOp
p) = (() -> Ptr CZooOpResult -> IO ZooOpResult)
-> ((), TouchListBytes)
-> (Ptr CZooOpResult -> IO ZooOpResult, TouchListBytes)
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first ((Ptr CZooOpResult -> IO ZooOpResult)
-> () -> Ptr CZooOpResult -> IO ZooOpResult
forall a b. a -> b -> a
const Ptr CZooOpResult -> IO ZooOpResult
I.peekZooDeleteOpResult) (((), TouchListBytes)
-> (Ptr CZooOpResult -> IO ZooOpResult, TouchListBytes))
-> IO ((), TouchListBytes)
-> IO (Ptr CZooOpResult -> IO ZooOpResult, TouchListBytes)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` Ptr CZooOp -> IO ((), TouchListBytes)
f Ptr CZooOp
p
initOp (I.ZooSetOp Ptr CZooOp -> IO (MutableByteArray RealWorld, TouchListBytes)
f, Ptr CZooOp
p) = (MutableByteArray RealWorld -> Ptr CZooOpResult -> IO ZooOpResult)
-> (MutableByteArray RealWorld, TouchListBytes)
-> (Ptr CZooOpResult -> IO ZooOpResult, TouchListBytes)
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first MutableByteArray RealWorld -> Ptr CZooOpResult -> IO ZooOpResult
I.peekZooSetOpResult ((MutableByteArray RealWorld, TouchListBytes)
-> (Ptr CZooOpResult -> IO ZooOpResult, TouchListBytes))
-> IO (MutableByteArray RealWorld, TouchListBytes)
-> IO (Ptr CZooOpResult -> IO ZooOpResult, TouchListBytes)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` Ptr CZooOp -> IO (MutableByteArray RealWorld, TouchListBytes)
f Ptr CZooOp
p
initOp (I.ZooCheckOp Ptr CZooOp -> IO ((), TouchListBytes)
f, Ptr CZooOp
p) = (() -> Ptr CZooOpResult -> IO ZooOpResult)
-> ((), TouchListBytes)
-> (Ptr CZooOpResult -> IO ZooOpResult, TouchListBytes)
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first ((Ptr CZooOpResult -> IO ZooOpResult)
-> () -> Ptr CZooOpResult -> IO ZooOpResult
forall a b. a -> b -> a
const Ptr CZooOpResult -> IO ZooOpResult
I.peekZooCheckOpResult) (((), TouchListBytes)
-> (Ptr CZooOpResult -> IO ZooOpResult, TouchListBytes))
-> IO ((), TouchListBytes)
-> IO (Ptr CZooOpResult -> IO ZooOpResult, TouchListBytes)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` Ptr CZooOp -> IO ((), TouchListBytes)
f Ptr CZooOp
p
{-# INLINE initOp #-}
zooCreateOpInit
:: CBytes
-> Maybe Bytes
-> CInt
-> T.AclVector
-> T.CreateMode
-> T.ZooOp
zooCreateOpInit :: CBytes -> Maybe Bytes -> CInt -> AclVector -> CreateMode -> ZooOp
zooCreateOpInit CBytes
path Maybe Bytes
m_value CInt
buflen AclVector
acl CreateMode
mode = (Ptr CZooOp -> IO (MutableByteArray RealWorld, TouchListBytes))
-> ZooOp
I.ZooCreateOp ((Ptr CZooOp -> IO (MutableByteArray RealWorld, TouchListBytes))
-> ZooOp)
-> (Ptr CZooOp -> IO (MutableByteArray RealWorld, TouchListBytes))
-> ZooOp
forall a b. (a -> b) -> a -> b
$ \Ptr CZooOp
op -> do
let buflen' :: CInt
buflen' = CInt
buflen CInt -> CInt -> CInt
forall a. Num a => a -> a -> a
+ CInt
1
CBytes
-> (BA# Word8 -> IO (MutableByteArray RealWorld, TouchListBytes))
-> IO (MutableByteArray RealWorld, TouchListBytes)
forall a. CBytes -> (BA# Word8 -> IO a) -> IO a
CBytes.withCBytesUnsafe CBytes
path ((BA# Word8 -> IO (MutableByteArray RealWorld, TouchListBytes))
-> IO (MutableByteArray RealWorld, TouchListBytes))
-> (BA# Word8 -> IO (MutableByteArray RealWorld, TouchListBytes))
-> IO (MutableByteArray RealWorld, TouchListBytes)
forall a b. (a -> b) -> a -> b
$ \BA# Word8
path' -> do
mba :: MutableByteArray RealWorld
mba@(Z.MutableByteArray MutableByteArray# RealWorld
mba#) <- Int -> IO (MutableByteArray (PrimState IO))
forall (m :: * -> *).
PrimMonad m =>
Int -> m (MutableByteArray (PrimState m))
Z.newPinnedByteArray (CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral CInt
buflen')
case Maybe Bytes
m_value of
Just Bytes
value -> Bytes -> (BA# Word8 -> Int -> Int -> IO ()) -> IO ()
forall a b.
Prim a =>
PrimVector a -> (BA# Word8 -> Int -> Int -> IO b) -> IO b
Z.withPrimVectorUnsafe Bytes
value ((BA# Word8 -> Int -> Int -> IO ()) -> IO ())
-> (BA# Word8 -> Int -> Int -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \BA# Word8
val' Int
offset Int
len ->
Ptr CZooOp
-> BA# Word8
-> BA# Word8
-> Int
-> Int
-> AclVector
-> CreateMode
-> MutableByteArray# RealWorld
-> CInt
-> IO ()
I.c_hs_zoo_create_op_init Ptr CZooOp
op BA# Word8
path' BA# Word8
val' Int
offset Int
len AclVector
acl CreateMode
mode MutableByteArray# RealWorld
mba# CInt
buflen'
Maybe Bytes
Nothing ->
Ptr CZooOp
-> BA# Word8
-> Ptr CChar
-> Int
-> Int
-> AclVector
-> CreateMode
-> MutableByteArray# RealWorld
-> CInt
-> IO ()
I.c_hs_zoo_create_op_init' Ptr CZooOp
op BA# Word8
path' Ptr CChar
forall a. Ptr a
nullPtr Int
0 (-Int
1) AclVector
acl CreateMode
mode MutableByteArray# RealWorld
mba# CInt
buflen'
MutableByteArray RealWorld
mba_path <- ByteArray -> IO (MutableByteArray (PrimState IO))
forall (m :: * -> *).
PrimMonad m =>
ByteArray -> m (MutableByteArray (PrimState m))
Z.unsafeThawByteArray (ByteArray -> IO (MutableByteArray (PrimState IO)))
-> ByteArray -> IO (MutableByteArray (PrimState IO))
forall a b. (a -> b) -> a -> b
$ BA# Word8 -> ByteArray
Z.ByteArray BA# Word8
path'
(MutableByteArray RealWorld, TouchListBytes)
-> IO (MutableByteArray RealWorld, TouchListBytes)
forall (m :: * -> *) a. Monad m => a -> m a
return (MutableByteArray RealWorld
mba, [MutableByteArray RealWorld
mba_path, MutableByteArray RealWorld
mba])
zooDeleteOpInit
:: CBytes
-> Maybe CInt
-> T.ZooOp
zooDeleteOpInit :: CBytes -> Maybe CInt -> ZooOp
zooDeleteOpInit CBytes
path Maybe CInt
m_version = (Ptr CZooOp -> IO ((), TouchListBytes)) -> ZooOp
I.ZooDeleteOp ((Ptr CZooOp -> IO ((), TouchListBytes)) -> ZooOp)
-> (Ptr CZooOp -> IO ((), TouchListBytes)) -> ZooOp
forall a b. (a -> b) -> a -> b
$ \Ptr CZooOp
op -> do
CBytes
-> (BA# Word8 -> IO ((), TouchListBytes))
-> IO ((), TouchListBytes)
forall a. CBytes -> (BA# Word8 -> IO a) -> IO a
CBytes.withCBytesUnsafe CBytes
path ((BA# Word8 -> IO ((), TouchListBytes)) -> IO ((), TouchListBytes))
-> (BA# Word8 -> IO ((), TouchListBytes))
-> IO ((), TouchListBytes)
forall a b. (a -> b) -> a -> b
$ \BA# Word8
path' -> do
Ptr CZooOp -> BA# Word8 -> CInt -> IO ()
I.c_zoo_delete_op_init Ptr CZooOp
op BA# Word8
path' (CInt -> Maybe CInt -> CInt
forall a. a -> Maybe a -> a
fromMaybe (-CInt
1) Maybe CInt
m_version)
MutableByteArray RealWorld
mba_path <- ByteArray -> IO (MutableByteArray (PrimState IO))
forall (m :: * -> *).
PrimMonad m =>
ByteArray -> m (MutableByteArray (PrimState m))
Z.unsafeThawByteArray (ByteArray -> IO (MutableByteArray (PrimState IO)))
-> ByteArray -> IO (MutableByteArray (PrimState IO))
forall a b. (a -> b) -> a -> b
$ BA# Word8 -> ByteArray
Z.ByteArray BA# Word8
path'
((), TouchListBytes) -> IO ((), TouchListBytes)
forall (m :: * -> *) a. Monad m => a -> m a
return ((), [MutableByteArray RealWorld
mba_path])
zooSetOpInit
:: CBytes
-> Maybe Bytes
-> Maybe CInt
-> T.ZooOp
zooSetOpInit :: CBytes -> Maybe Bytes -> Maybe CInt -> ZooOp
zooSetOpInit CBytes
path Maybe Bytes
m_value Maybe CInt
m_version = (Ptr CZooOp -> IO (MutableByteArray RealWorld, TouchListBytes))
-> ZooOp
I.ZooSetOp ((Ptr CZooOp -> IO (MutableByteArray RealWorld, TouchListBytes))
-> ZooOp)
-> (Ptr CZooOp -> IO (MutableByteArray RealWorld, TouchListBytes))
-> ZooOp
forall a b. (a -> b) -> a -> b
$ \Ptr CZooOp
op -> do
CBytes
-> (BA# Word8 -> IO (MutableByteArray RealWorld, TouchListBytes))
-> IO (MutableByteArray RealWorld, TouchListBytes)
forall a. CBytes -> (BA# Word8 -> IO a) -> IO a
CBytes.withCBytesUnsafe CBytes
path ((BA# Word8 -> IO (MutableByteArray RealWorld, TouchListBytes))
-> IO (MutableByteArray RealWorld, TouchListBytes))
-> (BA# Word8 -> IO (MutableByteArray RealWorld, TouchListBytes))
-> IO (MutableByteArray RealWorld, TouchListBytes)
forall a b. (a -> b) -> a -> b
$ \BA# Word8
path' -> do
mba :: MutableByteArray RealWorld
mba@(Z.MutableByteArray MutableByteArray# RealWorld
mba#) <- Int -> IO (MutableByteArray (PrimState IO))
forall (m :: * -> *).
PrimMonad m =>
Int -> m (MutableByteArray (PrimState m))
Z.newPinnedByteArray Int
I.statSize
let version :: CInt
version = CInt -> Maybe CInt -> CInt
forall a. a -> Maybe a -> a
fromMaybe (-CInt
1) Maybe CInt
m_version
case Maybe Bytes
m_value of
Just Bytes
value -> Bytes -> (BA# Word8 -> Int -> Int -> IO ()) -> IO ()
forall a b.
Prim a =>
PrimVector a -> (BA# Word8 -> Int -> Int -> IO b) -> IO b
Z.withPrimVectorUnsafe Bytes
value ((BA# Word8 -> Int -> Int -> IO ()) -> IO ())
-> (BA# Word8 -> Int -> Int -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \BA# Word8
val' Int
offset Int
len ->
Ptr CZooOp
-> BA# Word8
-> BA# Word8
-> Int
-> Int
-> CInt
-> MutableByteArray# RealWorld
-> IO ()
I.c_hs_zoo_set_op_init Ptr CZooOp
op BA# Word8
path' BA# Word8
val' Int
offset Int
len CInt
version MutableByteArray# RealWorld
mba#
Maybe Bytes
Nothing -> Ptr CZooOp
-> BA# Word8
-> Ptr Word8
-> Int
-> Int
-> CInt
-> MutableByteArray# RealWorld
-> IO ()
I.c_hs_zoo_set_op_init' Ptr CZooOp
op BA# Word8
path' Ptr Word8
forall a. Ptr a
nullPtr Int
0 (-Int
1) CInt
version MutableByteArray# RealWorld
mba#
MutableByteArray RealWorld
mba_path <- ByteArray -> IO (MutableByteArray (PrimState IO))
forall (m :: * -> *).
PrimMonad m =>
ByteArray -> m (MutableByteArray (PrimState m))
Z.unsafeThawByteArray (ByteArray -> IO (MutableByteArray (PrimState IO)))
-> ByteArray -> IO (MutableByteArray (PrimState IO))
forall a b. (a -> b) -> a -> b
$ BA# Word8 -> ByteArray
Z.ByteArray BA# Word8
path'
(MutableByteArray RealWorld, TouchListBytes)
-> IO (MutableByteArray RealWorld, TouchListBytes)
forall (m :: * -> *) a. Monad m => a -> m a
return (MutableByteArray RealWorld
mba, [MutableByteArray RealWorld
mba_path, MutableByteArray RealWorld
mba])
zooCheckOpInit
:: CBytes
-> CInt
-> T.ZooOp
zooCheckOpInit :: CBytes -> CInt -> ZooOp
zooCheckOpInit CBytes
path CInt
version = (Ptr CZooOp -> IO ((), TouchListBytes)) -> ZooOp
I.ZooCheckOp ((Ptr CZooOp -> IO ((), TouchListBytes)) -> ZooOp)
-> (Ptr CZooOp -> IO ((), TouchListBytes)) -> ZooOp
forall a b. (a -> b) -> a -> b
$ \Ptr CZooOp
op -> do
CBytes
-> (BA# Word8 -> IO ((), TouchListBytes))
-> IO ((), TouchListBytes)
forall a. CBytes -> (BA# Word8 -> IO a) -> IO a
CBytes.withCBytesUnsafe CBytes
path ((BA# Word8 -> IO ((), TouchListBytes)) -> IO ((), TouchListBytes))
-> (BA# Word8 -> IO ((), TouchListBytes))
-> IO ((), TouchListBytes)
forall a b. (a -> b) -> a -> b
$ \BA# Word8
path' -> do
Ptr CZooOp -> BA# Word8 -> CInt -> IO ()
I.c_zoo_check_op_init Ptr CZooOp
op BA# Word8
path' CInt
version
MutableByteArray RealWorld
mba_path <- ByteArray -> IO (MutableByteArray (PrimState IO))
forall (m :: * -> *).
PrimMonad m =>
ByteArray -> m (MutableByteArray (PrimState m))
Z.unsafeThawByteArray (ByteArray -> IO (MutableByteArray (PrimState IO)))
-> ByteArray -> IO (MutableByteArray (PrimState IO))
forall a b. (a -> b) -> a -> b
$ BA# Word8 -> ByteArray
Z.ByteArray BA# Word8
path'
((), TouchListBytes) -> IO ((), TouchListBytes)
forall (m :: * -> *) a. Monad m => a -> m a
return ((), [MutableByteArray RealWorld
mba_path])
zookeeperInit
:: CBytes
-> Maybe T.WatcherFn
-> CInt
-> Maybe T.ClientID
-> CInt
-> IO (T.ZHandle, FunPtr I.CWatcherFn)
zookeeperInit :: CBytes
-> Maybe WatcherFn
-> CInt
-> Maybe ClientID
-> CInt
-> IO (ZHandle, FunPtr CWatcherFn)
zookeeperInit CBytes
host Maybe WatcherFn
mfn CInt
timeout Maybe ClientID
mclientid CInt
flags = do
let clientid :: ClientID
clientid = ClientID -> Maybe ClientID -> ClientID
forall a. a -> Maybe a -> a
fromMaybe (Ptr () -> ClientID
I.ClientID Ptr ()
forall a. Ptr a
nullPtr) Maybe ClientID
mclientid
FunPtr CWatcherFn
fnPtr <- IO (FunPtr CWatcherFn)
-> (WatcherFn -> IO (FunPtr CWatcherFn))
-> Maybe WatcherFn
-> IO (FunPtr CWatcherFn)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (FunPtr CWatcherFn -> IO (FunPtr CWatcherFn)
forall (f :: * -> *) a. Applicative f => a -> f a
pure FunPtr CWatcherFn
forall a. FunPtr a
nullFunPtr) WatcherFn -> IO (FunPtr CWatcherFn)
I.mkWatcherFnPtr Maybe WatcherFn
mfn
ZHandle
zh <- CBytes -> (Ptr Word8 -> IO ZHandle) -> IO ZHandle
forall a. CBytes -> (Ptr Word8 -> IO a) -> IO a
CBytes.withCBytes CBytes
host ((Ptr Word8 -> IO ZHandle) -> IO ZHandle)
-> (Ptr Word8 -> IO ZHandle) -> IO ZHandle
forall a b. (a -> b) -> a -> b
$ \Ptr Word8
host' -> do
Ptr Word8
-> FunPtr CWatcherFn
-> CInt
-> ClientID
-> Ptr Any
-> CInt
-> IO ZHandle
forall a.
Ptr Word8
-> FunPtr CWatcherFn
-> CInt
-> ClientID
-> Ptr a
-> CInt
-> IO ZHandle
I.zookeeper_init Ptr Word8
host' FunPtr CWatcherFn
fnPtr CInt
timeout ClientID
clientid Ptr Any
forall a. Ptr a
nullPtr CInt
flags
(ZHandle, FunPtr CWatcherFn) -> IO (ZHandle, FunPtr CWatcherFn)
forall (m :: * -> *) a. Monad m => a -> m a
return (ZHandle
zh, FunPtr CWatcherFn
fnPtr)
zookeeperClose :: (T.ZHandle, FunPtr I.CWatcherFn) -> IO ()
zookeeperClose :: (ZHandle, FunPtr CWatcherFn) -> IO ()
zookeeperClose (ZHandle
zh, FunPtr CWatcherFn
fnptr) = do
Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (FunPtr CWatcherFn
fnptr FunPtr CWatcherFn -> FunPtr CWatcherFn -> Bool
forall a. Eq a => a -> a -> Bool
/= FunPtr CWatcherFn
forall a. FunPtr a
nullFunPtr) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ FunPtr CWatcherFn -> IO ()
forall a. FunPtr a -> IO ()
freeHaskellFunPtr FunPtr CWatcherFn
fnptr
IO CInt -> IO ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$ HasCallStack => CInt -> IO CInt
CInt -> IO CInt
E.throwZooErrorIfNotOK (CInt -> IO CInt) -> IO CInt -> IO CInt
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< ZHandle -> IO CInt
I.c_zookeeper_close ZHandle
zh
{-# INLINABLE zookeeperClose #-}
zooClientID :: T.ZHandle -> IO T.ClientID
zooClientID :: ZHandle -> IO ClientID
zooClientID = ZHandle -> IO ClientID
I.c_zoo_client_id
isUnrecoverable
:: T.ZHandle
-> IO Bool
isUnrecoverable :: ZHandle -> IO Bool
isUnrecoverable ZHandle
zh = (CInt -> CInt -> Bool
forall a. Ord a => a -> a -> Bool
< CInt
0) (CInt -> Bool) -> IO CInt -> IO Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ZHandle -> IO CInt
I.c_is_unrecoverable ZHandle
zh
zooState :: T.ZHandle -> IO T.ZooState
zooState :: ZHandle -> IO ZooState
zooState = ZHandle -> IO ZooState
I.c_zoo_state
zooRecvTimeout :: T.ZHandle -> IO CInt
zooRecvTimeout :: ZHandle -> IO CInt
zooRecvTimeout = ZHandle -> IO CInt
I.c_zoo_recv_timeout