{-# LANGUAGE TypeApplications #-}
#if (MIN_VERSION_haskell_gi_overloading(1,0,0) && !defined(__HADDOCK_VERSION__))
#define ENABLE_OVERLOADING
#endif
module GI.GLib.Structs.TimeVal
(
TimeVal(..) ,
newZeroTimeVal ,
#if defined(ENABLE_OVERLOADING)
ResolveTimeValMethod ,
#endif
#if defined(ENABLE_OVERLOADING)
TimeValAddMethodInfo ,
#endif
timeValAdd ,
timeValFromIso8601 ,
#if defined(ENABLE_OVERLOADING)
TimeValToIso8601MethodInfo ,
#endif
timeValToIso8601 ,
getTimeValTvSec ,
setTimeValTvSec ,
#if defined(ENABLE_OVERLOADING)
timeVal_tvSec ,
#endif
getTimeValTvUsec ,
setTimeValTvUsec ,
#if defined(ENABLE_OVERLOADING)
timeVal_tvUsec ,
#endif
) where
import Data.GI.Base.ShortPrelude
import qualified Data.GI.Base.ShortPrelude as SP
import qualified Data.GI.Base.Overloading as O
import qualified Prelude as P
import qualified Data.GI.Base.Attributes as GI.Attributes
import qualified Data.GI.Base.BasicTypes as B.Types
import qualified Data.GI.Base.ManagedPtr as B.ManagedPtr
import qualified Data.GI.Base.GArray as B.GArray
import qualified Data.GI.Base.GClosure as B.GClosure
import qualified Data.GI.Base.GError as B.GError
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GValue as B.GValue
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
import qualified Data.GI.Base.Properties as B.Properties
import qualified Data.GI.Base.Signals as B.Signals
import qualified Control.Monad.IO.Class as MIO
import qualified Data.Coerce as Coerce
import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import qualified Foreign.Ptr as FP
import qualified GHC.OverloadedLabels as OL
import qualified GHC.Records as R
newtype TimeVal = TimeVal (SP.ManagedPtr TimeVal)
deriving (TimeVal -> TimeVal -> Bool
(TimeVal -> TimeVal -> Bool)
-> (TimeVal -> TimeVal -> Bool) -> Eq TimeVal
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TimeVal -> TimeVal -> Bool
$c/= :: TimeVal -> TimeVal -> Bool
== :: TimeVal -> TimeVal -> Bool
$c== :: TimeVal -> TimeVal -> Bool
Eq)
instance SP.ManagedPtrNewtype TimeVal where
toManagedPtr :: TimeVal -> ManagedPtr TimeVal
toManagedPtr (TimeVal ManagedPtr TimeVal
p) = ManagedPtr TimeVal
p
instance BoxedPtr TimeVal where
boxedPtrCopy :: TimeVal -> IO TimeVal
boxedPtrCopy = \TimeVal
p -> TimeVal -> (Ptr TimeVal -> IO TimeVal) -> IO TimeVal
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
B.ManagedPtr.withManagedPtr TimeVal
p (Int -> Ptr TimeVal -> IO (Ptr TimeVal)
forall a. (HasCallStack, CallocPtr a) => Int -> Ptr a -> IO (Ptr a)
copyBytes Int
16 (Ptr TimeVal -> IO (Ptr TimeVal))
-> (Ptr TimeVal -> IO TimeVal) -> Ptr TimeVal -> IO TimeVal
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> (ManagedPtr TimeVal -> TimeVal) -> Ptr TimeVal -> IO TimeVal
forall a.
(HasCallStack, BoxedPtr a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
B.ManagedPtr.wrapPtr ManagedPtr TimeVal -> TimeVal
TimeVal)
boxedPtrFree :: TimeVal -> IO ()
boxedPtrFree = \TimeVal
x -> TimeVal -> (Ptr TimeVal -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
SP.withManagedPtr TimeVal
x Ptr TimeVal -> IO ()
forall a. Ptr a -> IO ()
SP.freeMem
instance CallocPtr TimeVal where
boxedPtrCalloc :: IO (Ptr TimeVal)
boxedPtrCalloc = Int -> IO (Ptr TimeVal)
forall a. Int -> IO (Ptr a)
callocBytes Int
16
newZeroTimeVal :: MonadIO m => m TimeVal
newZeroTimeVal :: forall (m :: * -> *). MonadIO m => m TimeVal
newZeroTimeVal = IO TimeVal -> m TimeVal
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO TimeVal -> m TimeVal) -> IO TimeVal -> m TimeVal
forall a b. (a -> b) -> a -> b
$ IO (Ptr TimeVal)
forall a. CallocPtr a => IO (Ptr a)
boxedPtrCalloc IO (Ptr TimeVal) -> (Ptr TimeVal -> IO TimeVal) -> IO TimeVal
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (ManagedPtr TimeVal -> TimeVal) -> Ptr TimeVal -> IO TimeVal
forall a.
(HasCallStack, BoxedPtr a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
wrapPtr ManagedPtr TimeVal -> TimeVal
TimeVal
instance tag ~ 'AttrSet => Constructible TimeVal tag where
new :: forall (m :: * -> *).
MonadIO m =>
(ManagedPtr TimeVal -> TimeVal)
-> [AttrOp TimeVal tag] -> m TimeVal
new ManagedPtr TimeVal -> TimeVal
_ [AttrOp TimeVal tag]
attrs = do
TimeVal
o <- m TimeVal
forall (m :: * -> *). MonadIO m => m TimeVal
newZeroTimeVal
TimeVal -> [AttrOp TimeVal 'AttrSet] -> m ()
forall o (m :: * -> *).
MonadIO m =>
o -> [AttrOp o 'AttrSet] -> m ()
GI.Attributes.set TimeVal
o [AttrOp TimeVal tag]
[AttrOp TimeVal 'AttrSet]
attrs
TimeVal -> m TimeVal
forall (m :: * -> *) a. Monad m => a -> m a
return TimeVal
o
getTimeValTvSec :: MonadIO m => TimeVal -> m CLong
getTimeValTvSec :: forall (m :: * -> *). MonadIO m => TimeVal -> m CLong
getTimeValTvSec TimeVal
s = IO CLong -> m CLong
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO CLong -> m CLong) -> IO CLong -> m CLong
forall a b. (a -> b) -> a -> b
$ TimeVal -> (Ptr TimeVal -> IO CLong) -> IO CLong
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr TimeVal
s ((Ptr TimeVal -> IO CLong) -> IO CLong)
-> (Ptr TimeVal -> IO CLong) -> IO CLong
forall a b. (a -> b) -> a -> b
$ \Ptr TimeVal
ptr -> do
CLong
val <- Ptr CLong -> IO CLong
forall a. Storable a => Ptr a -> IO a
peek (Ptr TimeVal
ptr Ptr TimeVal -> Int -> Ptr CLong
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
0) :: IO CLong
CLong -> IO CLong
forall (m :: * -> *) a. Monad m => a -> m a
return CLong
val
setTimeValTvSec :: MonadIO m => TimeVal -> CLong -> m ()
setTimeValTvSec :: forall (m :: * -> *). MonadIO m => TimeVal -> CLong -> m ()
setTimeValTvSec TimeVal
s CLong
val = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ TimeVal -> (Ptr TimeVal -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr TimeVal
s ((Ptr TimeVal -> IO ()) -> IO ())
-> (Ptr TimeVal -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr TimeVal
ptr -> do
Ptr CLong -> CLong -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (Ptr TimeVal
ptr Ptr TimeVal -> Int -> Ptr CLong
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
0) (CLong
val :: CLong)
#if defined(ENABLE_OVERLOADING)
data TimeValTvSecFieldInfo
instance AttrInfo TimeValTvSecFieldInfo where
type AttrBaseTypeConstraint TimeValTvSecFieldInfo = (~) TimeVal
type AttrAllowedOps TimeValTvSecFieldInfo = '[ 'AttrSet, 'AttrGet]
type AttrSetTypeConstraint TimeValTvSecFieldInfo = (~) CLong
type AttrTransferTypeConstraint TimeValTvSecFieldInfo = (~)CLong
type AttrTransferType TimeValTvSecFieldInfo = CLong
type AttrGetType TimeValTvSecFieldInfo = CLong
type AttrLabel TimeValTvSecFieldInfo = "tv_sec"
type AttrOrigin TimeValTvSecFieldInfo = TimeVal
attrGet = getTimeValTvSec
attrSet = setTimeValTvSec
attrConstruct = undefined
attrClear = undefined
attrTransfer _ v = do
return v
dbgAttrInfo = P.Just (O.ResolvedSymbolInfo {
O.resolvedSymbolName = "GI.GLib.Structs.TimeVal.tvSec"
, O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-glib-2.0.26/docs/GI-GLib-Structs-TimeVal.html#g:attr:tvSec"
})
timeVal_tvSec :: AttrLabelProxy "tvSec"
timeVal_tvSec = AttrLabelProxy
#endif
getTimeValTvUsec :: MonadIO m => TimeVal -> m CLong
getTimeValTvUsec :: forall (m :: * -> *). MonadIO m => TimeVal -> m CLong
getTimeValTvUsec TimeVal
s = IO CLong -> m CLong
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO CLong -> m CLong) -> IO CLong -> m CLong
forall a b. (a -> b) -> a -> b
$ TimeVal -> (Ptr TimeVal -> IO CLong) -> IO CLong
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr TimeVal
s ((Ptr TimeVal -> IO CLong) -> IO CLong)
-> (Ptr TimeVal -> IO CLong) -> IO CLong
forall a b. (a -> b) -> a -> b
$ \Ptr TimeVal
ptr -> do
CLong
val <- Ptr CLong -> IO CLong
forall a. Storable a => Ptr a -> IO a
peek (Ptr TimeVal
ptr Ptr TimeVal -> Int -> Ptr CLong
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
8) :: IO CLong
CLong -> IO CLong
forall (m :: * -> *) a. Monad m => a -> m a
return CLong
val
setTimeValTvUsec :: MonadIO m => TimeVal -> CLong -> m ()
setTimeValTvUsec :: forall (m :: * -> *). MonadIO m => TimeVal -> CLong -> m ()
setTimeValTvUsec TimeVal
s CLong
val = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ TimeVal -> (Ptr TimeVal -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr TimeVal
s ((Ptr TimeVal -> IO ()) -> IO ())
-> (Ptr TimeVal -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr TimeVal
ptr -> do
Ptr CLong -> CLong -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (Ptr TimeVal
ptr Ptr TimeVal -> Int -> Ptr CLong
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
8) (CLong
val :: CLong)
#if defined(ENABLE_OVERLOADING)
data TimeValTvUsecFieldInfo
instance AttrInfo TimeValTvUsecFieldInfo where
type AttrBaseTypeConstraint TimeValTvUsecFieldInfo = (~) TimeVal
type AttrAllowedOps TimeValTvUsecFieldInfo = '[ 'AttrSet, 'AttrGet]
type AttrSetTypeConstraint TimeValTvUsecFieldInfo = (~) CLong
type AttrTransferTypeConstraint TimeValTvUsecFieldInfo = (~)CLong
type AttrTransferType TimeValTvUsecFieldInfo = CLong
type AttrGetType TimeValTvUsecFieldInfo = CLong
type AttrLabel TimeValTvUsecFieldInfo = "tv_usec"
type AttrOrigin TimeValTvUsecFieldInfo = TimeVal
attrGet = getTimeValTvUsec
attrSet = setTimeValTvUsec
attrConstruct = undefined
attrClear = undefined
attrTransfer _ v = do
return v
dbgAttrInfo = P.Just (O.ResolvedSymbolInfo {
O.resolvedSymbolName = "GI.GLib.Structs.TimeVal.tvUsec"
, O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-glib-2.0.26/docs/GI-GLib-Structs-TimeVal.html#g:attr:tvUsec"
})
timeVal_tvUsec :: AttrLabelProxy "tvUsec"
timeVal_tvUsec = AttrLabelProxy
#endif
#if defined(ENABLE_OVERLOADING)
instance O.HasAttributeList TimeVal
type instance O.AttributeList TimeVal = TimeValAttributeList
type TimeValAttributeList = ('[ '("tvSec", TimeValTvSecFieldInfo), '("tvUsec", TimeValTvUsecFieldInfo)] :: [(Symbol, *)])
#endif
foreign import ccall "g_time_val_add" g_time_val_add ::
Ptr TimeVal ->
CLong ->
IO ()
{-# DEPRECATED timeValAdd ["(Since version 2.62)","t'GI.GLib.Structs.TimeVal.TimeVal' is not year-2038-safe. Use @guint64@ for"," representing microseconds since the epoch, or use t'GI.GLib.Structs.DateTime.DateTime'."] #-}
timeValAdd ::
(B.CallStack.HasCallStack, MonadIO m) =>
TimeVal
-> CLong
-> m ()
timeValAdd :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
TimeVal -> CLong -> m ()
timeValAdd TimeVal
time_ CLong
microseconds = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
Ptr TimeVal
time_' <- TimeVal -> IO (Ptr TimeVal)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr TimeVal
time_
Ptr TimeVal -> CLong -> IO ()
g_time_val_add Ptr TimeVal
time_' CLong
microseconds
TimeVal -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr TimeVal
time_
() -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
#if defined(ENABLE_OVERLOADING)
data TimeValAddMethodInfo
instance (signature ~ (CLong -> m ()), MonadIO m) => O.OverloadedMethod TimeValAddMethodInfo TimeVal signature where
overloadedMethod = timeValAdd
instance O.OverloadedMethodInfo TimeValAddMethodInfo TimeVal where
overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
O.resolvedSymbolName = "GI.GLib.Structs.TimeVal.timeValAdd",
O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-glib-2.0.26/docs/GI-GLib-Structs-TimeVal.html#v:timeValAdd"
})
#endif
foreign import ccall "g_time_val_to_iso8601" g_time_val_to_iso8601 ::
Ptr TimeVal ->
IO CString
{-# DEPRECATED timeValToIso8601 ["(Since version 2.62)","t'GI.GLib.Structs.TimeVal.TimeVal' is not year-2038-safe. Use"," g_date_time_format_iso8601(dt) instead."] #-}
timeValToIso8601 ::
(B.CallStack.HasCallStack, MonadIO m) =>
TimeVal
-> m (Maybe T.Text)
timeValToIso8601 :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
TimeVal -> m (Maybe Text)
timeValToIso8601 TimeVal
time_ = IO (Maybe Text) -> m (Maybe Text)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe Text) -> m (Maybe Text))
-> IO (Maybe Text) -> m (Maybe Text)
forall a b. (a -> b) -> a -> b
$ do
Ptr TimeVal
time_' <- TimeVal -> IO (Ptr TimeVal)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr TimeVal
time_
CString
result <- Ptr TimeVal -> IO CString
g_time_val_to_iso8601 Ptr TimeVal
time_'
Maybe Text
maybeResult <- CString -> (CString -> IO Text) -> IO (Maybe Text)
forall a b. Ptr a -> (Ptr a -> IO b) -> IO (Maybe b)
convertIfNonNull CString
result ((CString -> IO Text) -> IO (Maybe Text))
-> (CString -> IO Text) -> IO (Maybe Text)
forall a b. (a -> b) -> a -> b
$ \CString
result' -> do
Text
result'' <- HasCallStack => CString -> IO Text
CString -> IO Text
cstringToText CString
result'
CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
result'
Text -> IO Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
result''
TimeVal -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr TimeVal
time_
Maybe Text -> IO (Maybe Text)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Text
maybeResult
#if defined(ENABLE_OVERLOADING)
data TimeValToIso8601MethodInfo
instance (signature ~ (m (Maybe T.Text)), MonadIO m) => O.OverloadedMethod TimeValToIso8601MethodInfo TimeVal signature where
overloadedMethod = timeValToIso8601
instance O.OverloadedMethodInfo TimeValToIso8601MethodInfo TimeVal where
overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
O.resolvedSymbolName = "GI.GLib.Structs.TimeVal.timeValToIso8601",
O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-glib-2.0.26/docs/GI-GLib-Structs-TimeVal.html#v:timeValToIso8601"
})
#endif
foreign import ccall "g_time_val_from_iso8601" g_time_val_from_iso8601 ::
CString ->
Ptr TimeVal ->
IO CInt
{-# DEPRECATED timeValFromIso8601 ["(Since version 2.62)","t'GI.GLib.Structs.TimeVal.TimeVal' is not year-2038-safe. Use"," 'GI.GLib.Structs.DateTime.dateTimeNewFromIso8601' instead."] #-}
timeValFromIso8601 ::
(B.CallStack.HasCallStack, MonadIO m) =>
T.Text
-> m ((Bool, TimeVal))
timeValFromIso8601 :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
Text -> m (Bool, TimeVal)
timeValFromIso8601 Text
isoDate = IO (Bool, TimeVal) -> m (Bool, TimeVal)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Bool, TimeVal) -> m (Bool, TimeVal))
-> IO (Bool, TimeVal) -> m (Bool, TimeVal)
forall a b. (a -> b) -> a -> b
$ do
CString
isoDate' <- Text -> IO CString
textToCString Text
isoDate
Ptr TimeVal
time_ <- Int -> IO (Ptr TimeVal)
forall a. Int -> IO (Ptr a)
SP.callocBytes Int
16 :: IO (Ptr TimeVal)
CInt
result <- CString -> Ptr TimeVal -> IO CInt
g_time_val_from_iso8601 CString
isoDate' Ptr TimeVal
time_
let result' :: Bool
result' = (CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
/= CInt
0) CInt
result
TimeVal
time_' <- ((ManagedPtr TimeVal -> TimeVal) -> Ptr TimeVal -> IO TimeVal
forall a.
(HasCallStack, BoxedPtr a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
wrapPtr ManagedPtr TimeVal -> TimeVal
TimeVal) Ptr TimeVal
time_
CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
isoDate'
(Bool, TimeVal) -> IO (Bool, TimeVal)
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool
result', TimeVal
time_')
#if defined(ENABLE_OVERLOADING)
#endif
#if defined(ENABLE_OVERLOADING)
type family ResolveTimeValMethod (t :: Symbol) (o :: *) :: * where
ResolveTimeValMethod "add" o = TimeValAddMethodInfo
ResolveTimeValMethod "toIso8601" o = TimeValToIso8601MethodInfo
ResolveTimeValMethod l o = O.MethodResolutionFailed l o
instance (info ~ ResolveTimeValMethod t TimeVal, O.OverloadedMethod info TimeVal p) => OL.IsLabel t (TimeVal -> p) where
#if MIN_VERSION_base(4,10,0)
fromLabel = O.overloadedMethod @info
#else
fromLabel _ = O.overloadedMethod @info
#endif
#if MIN_VERSION_base(4,13,0)
instance (info ~ ResolveTimeValMethod t TimeVal, O.OverloadedMethod info TimeVal p, R.HasField t TimeVal p) => R.HasField t TimeVal p where
getField = O.overloadedMethod @info
#endif
instance (info ~ ResolveTimeValMethod t TimeVal, O.OverloadedMethodInfo info TimeVal) => OL.IsLabel t (O.MethodProxy info TimeVal) where
#if MIN_VERSION_base(4,10,0)
fromLabel = O.MethodProxy
#else
fromLabel _ = O.MethodProxy
#endif
#endif