{-# LINE 1 "lib/Asapo/Raw/Producer.hsc" #-}
{-# LANGUAGE CApiFFI #-}
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}

-- hsc2hs needs the include to find the C structure


module Asapo.Raw.Producer
  ( AsapoProducerHandle (AsapoProducerHandle),
    AsapoRequestCallbackPayloadHandle (AsapoRequestCallbackPayloadHandle),
    AsapoMessageHeaderHandle (AsapoMessageHeaderHandle),
    AsapoRequestCallback,
    createRequestCallback,
    kMaxMessageSize,
    asapo_free_producer_handle,
    kNCustomParams,
    kDefaultIngestMode,
    kMaxVersionSize,
    asapo_free_message_header_handle,
    AsapoRequestHandlerType,
    kTcp,
    kFilesystem,
    AsapoIngestModeFlags,
    kTransferData,
    AsapoOpcode,
    kOpcodeUnknownOp,
    kOpcodeTransferData,
    kOpcodeTransferDatasetData,
    kOpcodeStreamInfo,
    kOpcodeLastStream,
    kOpcodeGetBufferData,
    kOpcodeAuthorize,
    kOpcodeTransferMetaData,
    kOpcodeDeleteStream,
    kOpcodeGetMeta,
    kOpcodeCount,
    kOpcodePersistStream,
    kTransferMetaDataOnly,
    kStoreInFilesystem,
    kStoreInDatabase,
    AsapoMetaIngestOp,
    kInsert,
    kReplace,
    kUpdate,
    AsapoLogLevel,
    asapoLogLevelNone,
    asapoLogLevelError,
    asapoLogLevelInfo,
    asapoLogLevelDebug,
    asapoLogLevelWarning,
    asapo_create_producer,
    asapo_producer_get_version_info,
    asapo_producer_get_stream_info,
    asapo_producer_get_stream_meta,
    asapo_producer_get_beamtime_meta,
    asapo_producer_delete_stream,
    asapo_producer_get_last_stream,
    asapo_create_message_header,
    asapo_producer_send,
    asapo_producer_send_file,
    asapo_producer_send_stream_finished_flag,
    asapo_producer_send_beamtime_metadata,
    asapo_producer_send_stream_metadata,
    asapo_request_callback_payload_get_response,
    asapo_request_callback_payload_get_original_header,
    asapo_producer_set_log_level,
    asapo_producer_enable_local_log,
    asapo_producer_enable_remote_log,
    asapo_producer_set_credentials,
    asapo_producer_get_requests_queue_size,
    asapo_producer_get_requests_queue_volume_mb,
    asapo_producer_set_requests_queue_limits,
    asapo_producer_wait_requests_finished,
    AsapoGenericRequestHeader(..)
  )
where

import Data.Functor((<$>))
import Data.Word(Word64)
import Asapo.Raw.Common
  ( AsapoBool,
    AsapoErrorHandle (AsapoErrorHandle),
    AsapoSourceCredentialsHandle (AsapoSourceCredentialsHandle),
    AsapoStreamInfoHandle (AsapoStreamInfoHandle),
    AsapoStringHandle (AsapoStringHandle),
    ConstCString,
    asapo_free_handle
  )
import Foreign.C.ConstPtr (ConstPtr (ConstPtr))
import Foreign.C.String (CString)
import Foreign.C.Types (CInt (CInt), CSize (CSize), CUChar (CUChar))
import Foreign.Ptr (FunPtr, Ptr, plusPtr)
import Foreign (with, peekArray)
import Foreign.Storable (Storable(alignment, peek, peekByteOff, poke, sizeOf))
import System.IO (IO)
import Prelude (error, fromIntegral)
import Control.Applicative((<*>), pure)

newtype {-# CTYPE "asapo/producer_c.h" "AsapoProducerHandle" #-} AsapoProducerHandle = AsapoProducerHandle (Ptr ()) deriving (Ptr AsapoProducerHandle -> IO AsapoProducerHandle
Ptr AsapoProducerHandle -> Int -> IO AsapoProducerHandle
Ptr AsapoProducerHandle -> Int -> AsapoProducerHandle -> IO ()
Ptr AsapoProducerHandle -> AsapoProducerHandle -> IO ()
AsapoProducerHandle -> Int
(AsapoProducerHandle -> Int)
-> (AsapoProducerHandle -> Int)
-> (Ptr AsapoProducerHandle -> Int -> IO AsapoProducerHandle)
-> (Ptr AsapoProducerHandle -> Int -> AsapoProducerHandle -> IO ())
-> (forall b. Ptr b -> Int -> IO AsapoProducerHandle)
-> (forall b. Ptr b -> Int -> AsapoProducerHandle -> IO ())
-> (Ptr AsapoProducerHandle -> IO AsapoProducerHandle)
-> (Ptr AsapoProducerHandle -> AsapoProducerHandle -> IO ())
-> Storable AsapoProducerHandle
forall b. Ptr b -> Int -> IO AsapoProducerHandle
forall b. Ptr b -> Int -> AsapoProducerHandle -> IO ()
forall a.
(a -> Int)
-> (a -> Int)
-> (Ptr a -> Int -> IO a)
-> (Ptr a -> Int -> a -> IO ())
-> (forall b. Ptr b -> Int -> IO a)
-> (forall b. Ptr b -> Int -> a -> IO ())
-> (Ptr a -> IO a)
-> (Ptr a -> a -> IO ())
-> Storable a
$csizeOf :: AsapoProducerHandle -> Int
sizeOf :: AsapoProducerHandle -> Int
$calignment :: AsapoProducerHandle -> Int
alignment :: AsapoProducerHandle -> Int
$cpeekElemOff :: Ptr AsapoProducerHandle -> Int -> IO AsapoProducerHandle
peekElemOff :: Ptr AsapoProducerHandle -> Int -> IO AsapoProducerHandle
$cpokeElemOff :: Ptr AsapoProducerHandle -> Int -> AsapoProducerHandle -> IO ()
pokeElemOff :: Ptr AsapoProducerHandle -> Int -> AsapoProducerHandle -> IO ()
$cpeekByteOff :: forall b. Ptr b -> Int -> IO AsapoProducerHandle
peekByteOff :: forall b. Ptr b -> Int -> IO AsapoProducerHandle
$cpokeByteOff :: forall b. Ptr b -> Int -> AsapoProducerHandle -> IO ()
pokeByteOff :: forall b. Ptr b -> Int -> AsapoProducerHandle -> IO ()
$cpeek :: Ptr AsapoProducerHandle -> IO AsapoProducerHandle
peek :: Ptr AsapoProducerHandle -> IO AsapoProducerHandle
$cpoke :: Ptr AsapoProducerHandle -> AsapoProducerHandle -> IO ()
poke :: Ptr AsapoProducerHandle -> AsapoProducerHandle -> IO ()
Storable)

asapo_free_producer_handle :: AsapoProducerHandle -> IO ()
asapo_free_producer_handle :: AsapoProducerHandle -> IO ()
asapo_free_producer_handle (AsapoProducerHandle Ptr ()
ptr) = Ptr () -> (Ptr (Ptr ()) -> IO ()) -> IO ()
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Ptr ()
ptr \Ptr (Ptr ())
ptr' -> Ptr (Ptr ()) -> IO ()
asapo_free_handle Ptr (Ptr ())
ptr'

newtype {-# CTYPE "asapo/producer_c.h" "AsapoRequestCallbackPayloadHandle" #-} AsapoRequestCallbackPayloadHandle = AsapoRequestCallbackPayloadHandle (Ptr ()) deriving (Ptr AsapoRequestCallbackPayloadHandle
-> IO AsapoRequestCallbackPayloadHandle
Ptr AsapoRequestCallbackPayloadHandle
-> Int -> IO AsapoRequestCallbackPayloadHandle
Ptr AsapoRequestCallbackPayloadHandle
-> Int -> AsapoRequestCallbackPayloadHandle -> IO ()
Ptr AsapoRequestCallbackPayloadHandle
-> AsapoRequestCallbackPayloadHandle -> IO ()
AsapoRequestCallbackPayloadHandle -> Int
(AsapoRequestCallbackPayloadHandle -> Int)
-> (AsapoRequestCallbackPayloadHandle -> Int)
-> (Ptr AsapoRequestCallbackPayloadHandle
    -> Int -> IO AsapoRequestCallbackPayloadHandle)
-> (Ptr AsapoRequestCallbackPayloadHandle
    -> Int -> AsapoRequestCallbackPayloadHandle -> IO ())
-> (forall b. Ptr b -> Int -> IO AsapoRequestCallbackPayloadHandle)
-> (forall b.
    Ptr b -> Int -> AsapoRequestCallbackPayloadHandle -> IO ())
-> (Ptr AsapoRequestCallbackPayloadHandle
    -> IO AsapoRequestCallbackPayloadHandle)
-> (Ptr AsapoRequestCallbackPayloadHandle
    -> AsapoRequestCallbackPayloadHandle -> IO ())
-> Storable AsapoRequestCallbackPayloadHandle
forall b. Ptr b -> Int -> IO AsapoRequestCallbackPayloadHandle
forall b.
Ptr b -> Int -> AsapoRequestCallbackPayloadHandle -> IO ()
forall a.
(a -> Int)
-> (a -> Int)
-> (Ptr a -> Int -> IO a)
-> (Ptr a -> Int -> a -> IO ())
-> (forall b. Ptr b -> Int -> IO a)
-> (forall b. Ptr b -> Int -> a -> IO ())
-> (Ptr a -> IO a)
-> (Ptr a -> a -> IO ())
-> Storable a
$csizeOf :: AsapoRequestCallbackPayloadHandle -> Int
sizeOf :: AsapoRequestCallbackPayloadHandle -> Int
$calignment :: AsapoRequestCallbackPayloadHandle -> Int
alignment :: AsapoRequestCallbackPayloadHandle -> Int
$cpeekElemOff :: Ptr AsapoRequestCallbackPayloadHandle
-> Int -> IO AsapoRequestCallbackPayloadHandle
peekElemOff :: Ptr AsapoRequestCallbackPayloadHandle
-> Int -> IO AsapoRequestCallbackPayloadHandle
$cpokeElemOff :: Ptr AsapoRequestCallbackPayloadHandle
-> Int -> AsapoRequestCallbackPayloadHandle -> IO ()
pokeElemOff :: Ptr AsapoRequestCallbackPayloadHandle
-> Int -> AsapoRequestCallbackPayloadHandle -> IO ()
$cpeekByteOff :: forall b. Ptr b -> Int -> IO AsapoRequestCallbackPayloadHandle
peekByteOff :: forall b. Ptr b -> Int -> IO AsapoRequestCallbackPayloadHandle
$cpokeByteOff :: forall b.
Ptr b -> Int -> AsapoRequestCallbackPayloadHandle -> IO ()
pokeByteOff :: forall b.
Ptr b -> Int -> AsapoRequestCallbackPayloadHandle -> IO ()
$cpeek :: Ptr AsapoRequestCallbackPayloadHandle
-> IO AsapoRequestCallbackPayloadHandle
peek :: Ptr AsapoRequestCallbackPayloadHandle
-> IO AsapoRequestCallbackPayloadHandle
$cpoke :: Ptr AsapoRequestCallbackPayloadHandle
-> AsapoRequestCallbackPayloadHandle -> IO ()
poke :: Ptr AsapoRequestCallbackPayloadHandle
-> AsapoRequestCallbackPayloadHandle -> IO ()
Storable)

newtype {-# CTYPE "asapo/producer_c.h" "AsapoMessageHeaderHandle" #-} AsapoMessageHeaderHandle = AsapoMessageHeaderHandle (Ptr ()) deriving (Ptr AsapoMessageHeaderHandle -> IO AsapoMessageHeaderHandle
Ptr AsapoMessageHeaderHandle -> Int -> IO AsapoMessageHeaderHandle
Ptr AsapoMessageHeaderHandle
-> Int -> AsapoMessageHeaderHandle -> IO ()
Ptr AsapoMessageHeaderHandle -> AsapoMessageHeaderHandle -> IO ()
AsapoMessageHeaderHandle -> Int
(AsapoMessageHeaderHandle -> Int)
-> (AsapoMessageHeaderHandle -> Int)
-> (Ptr AsapoMessageHeaderHandle
    -> Int -> IO AsapoMessageHeaderHandle)
-> (Ptr AsapoMessageHeaderHandle
    -> Int -> AsapoMessageHeaderHandle -> IO ())
-> (forall b. Ptr b -> Int -> IO AsapoMessageHeaderHandle)
-> (forall b. Ptr b -> Int -> AsapoMessageHeaderHandle -> IO ())
-> (Ptr AsapoMessageHeaderHandle -> IO AsapoMessageHeaderHandle)
-> (Ptr AsapoMessageHeaderHandle
    -> AsapoMessageHeaderHandle -> IO ())
-> Storable AsapoMessageHeaderHandle
forall b. Ptr b -> Int -> IO AsapoMessageHeaderHandle
forall b. Ptr b -> Int -> AsapoMessageHeaderHandle -> IO ()
forall a.
(a -> Int)
-> (a -> Int)
-> (Ptr a -> Int -> IO a)
-> (Ptr a -> Int -> a -> IO ())
-> (forall b. Ptr b -> Int -> IO a)
-> (forall b. Ptr b -> Int -> a -> IO ())
-> (Ptr a -> IO a)
-> (Ptr a -> a -> IO ())
-> Storable a
$csizeOf :: AsapoMessageHeaderHandle -> Int
sizeOf :: AsapoMessageHeaderHandle -> Int
$calignment :: AsapoMessageHeaderHandle -> Int
alignment :: AsapoMessageHeaderHandle -> Int
$cpeekElemOff :: Ptr AsapoMessageHeaderHandle -> Int -> IO AsapoMessageHeaderHandle
peekElemOff :: Ptr AsapoMessageHeaderHandle -> Int -> IO AsapoMessageHeaderHandle
$cpokeElemOff :: Ptr AsapoMessageHeaderHandle
-> Int -> AsapoMessageHeaderHandle -> IO ()
pokeElemOff :: Ptr AsapoMessageHeaderHandle
-> Int -> AsapoMessageHeaderHandle -> IO ()
$cpeekByteOff :: forall b. Ptr b -> Int -> IO AsapoMessageHeaderHandle
peekByteOff :: forall b. Ptr b -> Int -> IO AsapoMessageHeaderHandle
$cpokeByteOff :: forall b. Ptr b -> Int -> AsapoMessageHeaderHandle -> IO ()
pokeByteOff :: forall b. Ptr b -> Int -> AsapoMessageHeaderHandle -> IO ()
$cpeek :: Ptr AsapoMessageHeaderHandle -> IO AsapoMessageHeaderHandle
peek :: Ptr AsapoMessageHeaderHandle -> IO AsapoMessageHeaderHandle
$cpoke :: Ptr AsapoMessageHeaderHandle -> AsapoMessageHeaderHandle -> IO ()
poke :: Ptr AsapoMessageHeaderHandle -> AsapoMessageHeaderHandle -> IO ()
Storable)

asapo_free_message_header_handle :: AsapoMessageHeaderHandle -> IO ()
asapo_free_message_header_handle :: AsapoMessageHeaderHandle -> IO ()
asapo_free_message_header_handle (AsapoMessageHeaderHandle Ptr ()
ptr) = Ptr () -> (Ptr (Ptr ()) -> IO ()) -> IO ()
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Ptr ()
ptr \Ptr (Ptr ())
ptr' -> Ptr (Ptr ()) -> IO ()
asapo_free_handle Ptr (Ptr ())
ptr'

type AsapoRequestCallback = Ptr () -> AsapoRequestCallbackPayloadHandle -> AsapoErrorHandle -> IO ()

foreign import ccall "wrapper" createRequestCallback :: AsapoRequestCallback -> IO (FunPtr AsapoRequestCallback)

foreign import capi "asapo/producer_c.h value kMaxMessageSize" kMaxMessageSize :: CSize

foreign import capi "asapo/producer_c.h value kMaxVersionSize" kMaxVersionSize :: CSize

foreign import capi "asapo/producer_c.h value kNCustomParams" kNCustomParams :: CSize

type AsapoOpcode = CInt

foreign import capi "asapo/producer_c.h value kOpcodeUnknownOp" kOpcodeUnknownOp :: AsapoOpcode

foreign import capi "asapo/producer_c.h value kOpcodeTransferData" kOpcodeTransferData :: AsapoOpcode

foreign import capi "asapo/producer_c.h value kOpcodeTransferDatasetData" kOpcodeTransferDatasetData :: AsapoOpcode

foreign import capi "asapo/producer_c.h value kOpcodeStreamInfo" kOpcodeStreamInfo :: AsapoOpcode

foreign import capi "asapo/producer_c.h value kOpcodeLastStream" kOpcodeLastStream :: AsapoOpcode

foreign import capi "asapo/producer_c.h value kOpcodeGetBufferData" kOpcodeGetBufferData :: AsapoOpcode

foreign import capi "asapo/producer_c.h value kOpcodeAuthorize" kOpcodeAuthorize :: AsapoOpcode

foreign import capi "asapo/producer_c.h value kOpcodeTransferMetaData" kOpcodeTransferMetaData :: AsapoOpcode

foreign import capi "asapo/producer_c.h value kOpcodeDeleteStream" kOpcodeDeleteStream :: AsapoOpcode

foreign import capi "asapo/producer_c.h value kOpcodeGetMeta" kOpcodeGetMeta :: AsapoOpcode

foreign import capi "asapo/producer_c.h value kOpcodeCount" kOpcodeCount :: AsapoOpcode

foreign import capi "asapo/producer_c.h value kOpcodePersistStream" kOpcodePersistStream :: AsapoOpcode

data AsapoGenericRequestHeader = AsapoGenericRequestHeader
  { AsapoGenericRequestHeader -> AsapoOpcode
asapoGenericRequestHeaderOpCode :: !AsapoOpcode,
    AsapoGenericRequestHeader -> Word64
asapoGenericRequestHeaderDataId :: !Word64,
    AsapoGenericRequestHeader -> Word64
asapoGenericRequestHeaderDataSize :: !Word64,
    AsapoGenericRequestHeader -> Word64
asapoGenericRequestHeaderMetaSize :: !Word64,
    AsapoGenericRequestHeader -> [Word64]
asapoGenericRequestHeaderCustomData :: ![Word64],
    AsapoGenericRequestHeader -> CString
asapoGenericRequestHeaderMessage :: !CString,
    AsapoGenericRequestHeader -> CString
asapoGenericRequestHeaderStream :: !CString,
    AsapoGenericRequestHeader -> CString
asapoGenericRequestHeaderApiVersion :: !CString
  }

instance Storable AsapoGenericRequestHeader where
  sizeOf :: AsapoGenericRequestHeader -> Int
sizeOf AsapoGenericRequestHeader
_ = ((Int
2120))
{-# LINE 161 "lib/Asapo/Raw/Producer.hsc" #-}
  alignment _ = (8)
{-# LINE 162 "lib/Asapo/Raw/Producer.hsc" #-}
  peek ptr = do
    customData <- peekArray (fromIntegral kNCustomParams) (((\hsc_ptr -> hsc_ptr `plusPtr` 32)) ptr)
{-# LINE 164 "lib/Asapo/Raw/Producer.hsc" #-}
    opCode <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) ptr
{-# LINE 165 "lib/Asapo/Raw/Producer.hsc" #-}
    dataId <- ((\hsc_ptr -> peekByteOff hsc_ptr 8)) ptr
{-# LINE 166 "lib/Asapo/Raw/Producer.hsc" #-}
    dataSize <- ((\hsc_ptr -> peekByteOff hsc_ptr 16)) ptr
{-# LINE 167 "lib/Asapo/Raw/Producer.hsc" #-}
    metaSize <- ((\hsc_ptr -> peekByteOff hsc_ptr 24)) ptr
{-# LINE 168 "lib/Asapo/Raw/Producer.hsc" #-}
    let message' = ((\hsc_ptr -> hsc_ptr `plusPtr` 56)) ptr
{-# LINE 169 "lib/Asapo/Raw/Producer.hsc" #-}
    let stream' = ((\hsc_ptr -> hsc_ptr `plusPtr` 1080)) ptr
{-# LINE 170 "lib/Asapo/Raw/Producer.hsc" #-}
    let apiVersion' = ((\hsc_ptr -> hsc_ptr `plusPtr` 2104)) ptr
{-# LINE 171 "lib/Asapo/Raw/Producer.hsc" #-}
    AsapoGenericRequestHeader
      <$> pure opCode
      <*> pure dataId
      <*> pure dataSize
      <*> pure metaSize
      <*> pure customData
      <*> pure message'
      <*> pure stream'
      <*> pure apiVersion'
  poke :: Ptr AsapoGenericRequestHeader -> AsapoGenericRequestHeader -> IO ()
poke Ptr AsapoGenericRequestHeader
_ = [Char] -> AsapoGenericRequestHeader -> IO ()
forall a. HasCallStack => [Char] -> a
error [Char]
"why was AsapoGenericRequestHeader poked? it's supposed to be read-only"


type AsapoRequestHandlerType = CInt

foreign import capi "asapo/producer_c.h value kTcp" kTcp :: AsapoRequestHandlerType

foreign import capi "asapo/producer_c.h value kFilesystem" kFilesystem :: AsapoRequestHandlerType

type AsapoIngestModeFlags = CInt

foreign import capi "asapo/producer_c.h value kTransferData" kTransferData :: AsapoIngestModeFlags

foreign import capi "asapo/producer_c.h value kTransferMetaDataOnly" kTransferMetaDataOnly :: AsapoIngestModeFlags

foreign import capi "asapo/producer_c.h value kStoreInFilesystem" kStoreInFilesystem :: AsapoIngestModeFlags

foreign import capi "asapo/producer_c.h value kStoreInDatabase" kStoreInDatabase :: AsapoIngestModeFlags

foreign import capi "asapo/producer_c.h value kDefaultIngestMode" kDefaultIngestMode :: AsapoIngestModeFlags

type AsapoMetaIngestOp = CInt

foreign import capi "asapo/producer_c.h value kInsert" kInsert :: AsapoMetaIngestOp

foreign import capi "asapo/producer_c.h value kReplace" kReplace :: AsapoMetaIngestOp

foreign import capi "asapo/producer_c.h value kUpdate" kUpdate :: AsapoMetaIngestOp

type AsapoLogLevel = CInt

foreign import capi "asapo/producer_c.h value None" asapoLogLevelNone :: AsapoLogLevel

foreign import capi "asapo/producer_c.h value Error" asapoLogLevelError :: AsapoLogLevel

foreign import capi "asapo/producer_c.h value Info" asapoLogLevelInfo :: AsapoLogLevel

foreign import capi "asapo/producer_c.h value Debug" asapoLogLevelDebug :: AsapoLogLevel

foreign import capi "asapo/producer_c.h value Warning" asapoLogLevelWarning :: AsapoLogLevel

foreign import capi "asapo/producer_c.h asapo_create_producer"
  asapo_create_producer ::
    -- endpoint
    CString ->
    -- processing threads
    CUChar ->
    AsapoRequestHandlerType ->
    AsapoSourceCredentialsHandle ->
    -- timeout_ms
    Word64 ->
    Ptr AsapoErrorHandle ->
    IO AsapoProducerHandle

foreign import capi "asapo/producer_c.h asapo_producer_get_version_info"
  asapo_producer_get_version_info ::
    AsapoProducerHandle ->
    -- client info
    AsapoStringHandle ->
    -- server info
    AsapoStringHandle ->
    -- supported
    Ptr AsapoBool ->
    Ptr AsapoErrorHandle ->
    IO CInt

foreign import capi "asapo/producer_c.h asapo_producer_get_stream_info"
  asapo_producer_get_stream_info ::
    AsapoProducerHandle ->
    -- stream
    ConstCString ->
    -- timeout ms
    Word64 ->
    Ptr AsapoErrorHandle ->
    IO AsapoStreamInfoHandle

foreign import capi "asapo/producer_c.h asapo_producer_get_stream_meta"
  asapo_producer_get_stream_meta ::
    AsapoProducerHandle ->
    -- stream
    ConstCString ->
    -- timeout_ms
    Word64 ->
    Ptr AsapoErrorHandle ->
    IO AsapoStringHandle

foreign import capi "asapo/producer_c.h asapo_producer_get_beamtime_meta"
  asapo_producer_get_beamtime_meta ::
    AsapoProducerHandle ->
    -- timeout_ms
    Word64 ->
    Ptr AsapoErrorHandle ->
    IO AsapoStringHandle

foreign import capi "asapo/producer_c.h asapo_producer_delete_stream"
  asapo_producer_delete_stream ::
    AsapoProducerHandle ->
    -- stream
    ConstCString ->
    -- timeout_ms
    Word64 ->
    -- delete meta
    AsapoBool ->
    -- error_on_not_exist
    AsapoBool ->
    Ptr AsapoErrorHandle ->
    IO CInt

foreign import capi "asapo/producer_c.h asapo_producer_get_last_stream"
  asapo_producer_get_last_stream ::
    AsapoProducerHandle ->
    -- timeout ms
    Word64 ->
    Ptr AsapoErrorHandle ->
    IO AsapoStreamInfoHandle

foreign import capi "asapo/producer_c.h asapo_create_message_header"
  asapo_create_message_header ::
    -- message ID
    Word64 ->
    -- data size
    Word64 ->
    -- file name
    ConstCString ->
    -- user metadata
    ConstCString ->
    -- dataset substream
    Word64 ->
    -- dataset size
    Word64 ->
    -- auto id
    AsapoBool ->
    IO AsapoMessageHeaderHandle

foreign import capi "asapo/producer_c.h asapo_producer_send"
  asapo_producer_send ::
    AsapoProducerHandle ->
    AsapoMessageHeaderHandle ->
    -- data
    Ptr () ->
    -- ingest mode
    Word64 ->
    -- stream
    ConstCString ->
    FunPtr AsapoRequestCallback ->
    Ptr AsapoErrorHandle ->
    IO CInt

foreign import capi "asapo/producer_c.h asapo_producer_send_file"
  asapo_producer_send_file ::
    AsapoProducerHandle ->
    AsapoMessageHeaderHandle ->
    -- file name
    ConstCString ->
    -- ingest mode
    Word64 ->
    -- stream
    ConstCString ->
    FunPtr AsapoRequestCallback ->
    Ptr AsapoErrorHandle ->
    IO CInt

foreign import capi "asapo/producer_c.h asapo_producer_send_stream_finished_flag"
  asapo_producer_send_stream_finished_flag ::
    AsapoProducerHandle ->
    -- stream
    ConstCString ->
    -- last ID
    Word64 ->
    -- next stream
    ConstCString ->
    FunPtr AsapoRequestCallback ->
    Ptr AsapoErrorHandle ->
    IO CInt

foreign import capi "asapo/producer_c.h asapo_producer_send_beamtime_metadata"
  asapo_producer_send_beamtime_metadata ::
    AsapoProducerHandle ->
    -- metadata
    ConstCString ->
    AsapoMetaIngestOp ->
    -- upsert
    AsapoBool ->
    FunPtr AsapoRequestCallback ->
    Ptr AsapoErrorHandle ->
    IO CInt

foreign import capi "asapo/producer_c.h asapo_producer_send_stream_metadata"
  asapo_producer_send_stream_metadata ::
    AsapoProducerHandle ->
    -- metadata
    ConstCString ->
    AsapoMetaIngestOp ->
    -- upsert
    AsapoBool ->
    -- stream
    ConstCString ->
    FunPtr AsapoRequestCallback ->
    Ptr AsapoErrorHandle ->
    IO CInt

foreign import capi "asapo/producer_c.h asapo_request_callback_payload_get_response"
  asapo_request_callback_payload_get_response :: AsapoRequestCallbackPayloadHandle -> IO AsapoStringHandle

foreign import capi "asapo/producer_c.h asapo_request_callback_payload_get_original_header"
  asapo_request_callback_payload_get_original_header :: AsapoRequestCallbackPayloadHandle -> IO (ConstPtr AsapoGenericRequestHeader)

foreign import capi "asapo/producer_c.h asapo_producer_set_log_level"
  asapo_producer_set_log_level :: AsapoProducerHandle -> AsapoLogLevel -> IO ()

foreign import capi "asapo/producer_c.h asapo_producer_enable_local_log"
  asapo_producer_enable_local_log :: AsapoProducerHandle -> AsapoBool -> IO ()

foreign import capi "asapo/producer_c.h asapo_producer_enable_remote_log"
  asapo_producer_enable_remote_log :: AsapoProducerHandle -> AsapoBool -> IO ()

foreign import capi "asapo/producer_c.h asapo_producer_set_credentials"
  asapo_producer_set_credentials ::
    AsapoProducerHandle ->
    AsapoSourceCredentialsHandle ->
    Ptr AsapoErrorHandle ->
    IO CInt

foreign import capi "asapo/producer_c.h asapo_producer_get_requests_queue_size"
  asapo_producer_get_requests_queue_size :: AsapoProducerHandle -> IO Word64

foreign import capi "asapo/producer_c.h asapo_producer_get_requests_queue_volume_mb"
  asapo_producer_get_requests_queue_volume_mb :: AsapoProducerHandle -> IO Word64

foreign import capi "asapo/producer_c.h asapo_producer_set_requests_queue_limits"
  asapo_producer_set_requests_queue_limits ::
    AsapoProducerHandle ->
    -- size
    Word64 ->
    -- volume
    Word64 ->
    IO ()

foreign import capi "asapo/producer_c.h asapo_producer_wait_requests_finished"
  asapo_producer_wait_requests_finished ::
    AsapoProducerHandle ->
    -- timeout ms
    Word64 ->
    -- error
    Ptr AsapoErrorHandle ->
    IO CInt