{-# LINE 1 "src/Database/EJDB2/WAL.hsc" #-}
{-# LANGUAGE CPP #-}

module Database.EJDB2.WAL (Options(..), zero) where


import           Foreign
import           Foreign.C.String
import           Foreign.C.Types

import Database.EJDB2.Result



-- | Write ahead log (WAL) options.
data Options = Options { enabled :: !Bool -- ^ WAL enabled
                             , checkCRCOnCheckpoint :: !Bool -- ^ Check CRC32 sum of data blocks during checkpoint. Default: false
                             , savepointTimeoutSec :: !Word32 -- ^ Savepoint timeout seconds. Default: 10 sec
                             , checkpointTimeoutSec :: !Word32 -- ^ Checkpoint timeout seconds. Default: 300 sec (5 min);
                             , walBufferSz :: !Word64 -- ^ WAL file intermediate buffer size. Default: 8Mb
                             , checkpointBufferSz :: !Word8 -- ^ Checkpoint buffer size in bytes. Default: 1Gb
                             , walLockInterceptor :: !(FunPtr (CBool -> Ptr () -> IO RC)) -- ^ Optional function called before acquiring and after releasing.
-- exclusive database lock byAL checkpoint thread.
-- In the case of 'before loc first argument will be set to true
                             , walLockInterceptorOpaque :: !(Ptr ()) -- ^ Opaque data for 'walLockInterceptor'
                             }

-- | Create default Options
zero :: Options
zero = Options { enabled = False
                   , checkCRCOnCheckpoint = False
                   , savepointTimeoutSec = 0
                   , checkpointTimeoutSec = 0
                   , walBufferSz = 0
                   , checkpointBufferSz = 0
                   , walLockInterceptor = nullFunPtr
                   , walLockInterceptorOpaque = nullPtr
                   }

instance Storable Options where
        sizeOf _ = (48)
{-# LINE 41 "src/Database/EJDB2/WAL.hsc" #-}
        alignment _  = 8
{-# LINE 42 "src/Database/EJDB2/WAL.hsc" #-}
        peek ptr = do
          enabled <- (\hsc_ptr -> peekByteOff hsc_ptr 0) ptr
{-# LINE 44 "src/Database/EJDB2/WAL.hsc" #-}
          check_crc_on_checkpoint <- (\hsc_ptr -> peekByteOff hsc_ptr 1) ptr
{-# LINE 45 "src/Database/EJDB2/WAL.hsc" #-}
          savepoint_timeout_sec <- (\hsc_ptr -> peekByteOff hsc_ptr 4) ptr
{-# LINE 46 "src/Database/EJDB2/WAL.hsc" #-}
          checkpoint_timeout_sec <- (\hsc_ptr -> peekByteOff hsc_ptr 8) ptr
{-# LINE 47 "src/Database/EJDB2/WAL.hsc" #-}
          wal_buffer_sz <- (\hsc_ptr -> peekByteOff hsc_ptr 16) ptr
{-# LINE 48 "src/Database/EJDB2/WAL.hsc" #-}
          checkpoint_buffer_sz <- (\hsc_ptr -> peekByteOff hsc_ptr 24) ptr
{-# LINE 49 "src/Database/EJDB2/WAL.hsc" #-}
          wal_lock_interceptor <- (\hsc_ptr -> peekByteOff hsc_ptr 32) ptr
{-# LINE 50 "src/Database/EJDB2/WAL.hsc" #-}
          wal_lock_interceptor_opaque <- (\hsc_ptr -> peekByteOff hsc_ptr 40) ptr
{-# LINE 51 "src/Database/EJDB2/WAL.hsc" #-}
          return $ Options enabled check_crc_on_checkpoint savepoint_timeout_sec checkpoint_timeout_sec wal_buffer_sz checkpoint_buffer_sz wal_lock_interceptor wal_lock_interceptor_opaque
        poke ptr (Options enabled check_crc_on_checkpoint savepoint_timeout_sec checkpoint_timeout_sec wal_buffer_sz checkpoint_buffer_sz wal_lock_interceptor wal_lock_interceptor_opaque) = do
          (\hsc_ptr -> pokeByteOff hsc_ptr 0) ptr enabled
{-# LINE 54 "src/Database/EJDB2/WAL.hsc" #-}
          (\hsc_ptr -> pokeByteOff hsc_ptr 1) ptr check_crc_on_checkpoint
{-# LINE 55 "src/Database/EJDB2/WAL.hsc" #-}
          (\hsc_ptr -> pokeByteOff hsc_ptr 4) ptr savepoint_timeout_sec
{-# LINE 56 "src/Database/EJDB2/WAL.hsc" #-}
          (\hsc_ptr -> pokeByteOff hsc_ptr 8) ptr checkpoint_timeout_sec
{-# LINE 57 "src/Database/EJDB2/WAL.hsc" #-}
          (\hsc_ptr -> pokeByteOff hsc_ptr 16) ptr wal_buffer_sz
{-# LINE 58 "src/Database/EJDB2/WAL.hsc" #-}
          (\hsc_ptr -> pokeByteOff hsc_ptr 24) ptr checkpoint_buffer_sz
{-# LINE 59 "src/Database/EJDB2/WAL.hsc" #-}
          (\hsc_ptr -> pokeByteOff hsc_ptr 32) ptr wal_lock_interceptor
{-# LINE 60 "src/Database/EJDB2/WAL.hsc" #-}
          (\hsc_ptr -> pokeByteOff hsc_ptr 40) ptr wal_lock_interceptor_opaque
{-# LINE 61 "src/Database/EJDB2/WAL.hsc" #-}