{- |
Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
License    : LGPL-2.1
Maintainer : Iñaki García Etxebarria (inaki@blueleaf.cc)

This 'GI.Gio.Objects.SocketControlMessage.SocketControlMessage' contains a 'GI.Gio.Objects.Credentials.Credentials' instance.  It
may be sent using 'GI.Gio.Objects.Socket.socketSendMessage' and received using
'GI.Gio.Objects.Socket.socketReceiveMessage' over UNIX sockets (ie: sockets in the
'GI.Gio.Enums.SocketFamilyUnix' family).

For an easier way to send and receive credentials over
stream-oriented UNIX sockets, see
'GI.Gio.Objects.UnixConnection.unixConnectionSendCredentials' and
'GI.Gio.Objects.UnixConnection.unixConnectionReceiveCredentials'. To receive credentials of
a foreign process connected to a socket, use
'GI.Gio.Objects.Socket.socketGetCredentials'.

/Since: 2.26/
-}

#define ENABLE_OVERLOADING (MIN_VERSION_haskell_gi_overloading(1,0,0) \
       && !defined(__HADDOCK_VERSION__))

module GI.Gio.Objects.UnixCredentialsMessage
    (

-- * Exported types
    UnixCredentialsMessage(..)              ,
    IsUnixCredentialsMessage                ,
    toUnixCredentialsMessage                ,
    noUnixCredentialsMessage                ,


 -- * Methods
-- ** getCredentials #method:getCredentials#

#if ENABLE_OVERLOADING
    UnixCredentialsMessageGetCredentialsMethodInfo,
#endif
    unixCredentialsMessageGetCredentials    ,


-- ** isSupported #method:isSupported#

    unixCredentialsMessageIsSupported       ,


-- ** new #method:new#

    unixCredentialsMessageNew               ,


-- ** newWithCredentials #method:newWithCredentials#

    unixCredentialsMessageNewWithCredentials,




 -- * Properties
-- ** credentials #attr:credentials#
{- | The credentials stored in the message.

/Since: 2.26/
-}
#if ENABLE_OVERLOADING
    UnixCredentialsMessageCredentialsPropertyInfo,
#endif
    constructUnixCredentialsMessageCredentials,
    getUnixCredentialsMessageCredentials    ,
#if ENABLE_OVERLOADING
    unixCredentialsMessageCredentials       ,
#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.ManagedPtr as B.ManagedPtr
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.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 GI.GObject.Objects.Object as GObject.Object
import {-# SOURCE #-} qualified GI.Gio.Objects.Credentials as Gio.Credentials
import {-# SOURCE #-} qualified GI.Gio.Objects.SocketControlMessage as Gio.SocketControlMessage

-- | Memory-managed wrapper type.
newtype UnixCredentialsMessage = UnixCredentialsMessage (ManagedPtr UnixCredentialsMessage)
foreign import ccall "g_unix_credentials_message_get_type"
    c_g_unix_credentials_message_get_type :: IO GType

instance GObject UnixCredentialsMessage where
    gobjectType = c_g_unix_credentials_message_get_type


-- | Type class for types which can be safely cast to `UnixCredentialsMessage`, for instance with `toUnixCredentialsMessage`.
class (GObject o, O.IsDescendantOf UnixCredentialsMessage o) => IsUnixCredentialsMessage o
instance (GObject o, O.IsDescendantOf UnixCredentialsMessage o) => IsUnixCredentialsMessage o

instance O.HasParentTypes UnixCredentialsMessage
type instance O.ParentTypes UnixCredentialsMessage = '[Gio.SocketControlMessage.SocketControlMessage, GObject.Object.Object]

-- | Cast to `UnixCredentialsMessage`, for types for which this is known to be safe. For general casts, use `Data.GI.Base.ManagedPtr.castTo`.
toUnixCredentialsMessage :: (MonadIO m, IsUnixCredentialsMessage o) => o -> m UnixCredentialsMessage
toUnixCredentialsMessage = liftIO . unsafeCastTo UnixCredentialsMessage

-- | A convenience alias for `Nothing` :: `Maybe` `UnixCredentialsMessage`.
noUnixCredentialsMessage :: Maybe UnixCredentialsMessage
noUnixCredentialsMessage = Nothing

#if ENABLE_OVERLOADING
type family ResolveUnixCredentialsMessageMethod (t :: Symbol) (o :: *) :: * where
    ResolveUnixCredentialsMessageMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveUnixCredentialsMessageMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveUnixCredentialsMessageMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveUnixCredentialsMessageMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveUnixCredentialsMessageMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
    ResolveUnixCredentialsMessageMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveUnixCredentialsMessageMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveUnixCredentialsMessageMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveUnixCredentialsMessageMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveUnixCredentialsMessageMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveUnixCredentialsMessageMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveUnixCredentialsMessageMethod "serialize" o = Gio.SocketControlMessage.SocketControlMessageSerializeMethodInfo
    ResolveUnixCredentialsMessageMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveUnixCredentialsMessageMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveUnixCredentialsMessageMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveUnixCredentialsMessageMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveUnixCredentialsMessageMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveUnixCredentialsMessageMethod "getCredentials" o = UnixCredentialsMessageGetCredentialsMethodInfo
    ResolveUnixCredentialsMessageMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveUnixCredentialsMessageMethod "getLevel" o = Gio.SocketControlMessage.SocketControlMessageGetLevelMethodInfo
    ResolveUnixCredentialsMessageMethod "getMsgType" o = Gio.SocketControlMessage.SocketControlMessageGetMsgTypeMethodInfo
    ResolveUnixCredentialsMessageMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveUnixCredentialsMessageMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveUnixCredentialsMessageMethod "getSize" o = Gio.SocketControlMessage.SocketControlMessageGetSizeMethodInfo
    ResolveUnixCredentialsMessageMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveUnixCredentialsMessageMethod "setDataFull" o = GObject.Object.ObjectSetDataFullMethodInfo
    ResolveUnixCredentialsMessageMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveUnixCredentialsMessageMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveUnixCredentialsMessageMethod t UnixCredentialsMessage, O.MethodInfo info UnixCredentialsMessage p) => OL.IsLabel t (UnixCredentialsMessage -> p) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#else
    fromLabel _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#endif

#endif

-- VVV Prop "credentials"
   -- Type: TInterface (Name {namespace = "Gio", name = "Credentials"})
   -- Flags: [PropertyReadable,PropertyWritable,PropertyConstructOnly]
   -- Nullable: (Just False,Nothing)

{- |
Get the value of the “@credentials@” property.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.get' unixCredentialsMessage #credentials
@
-}
getUnixCredentialsMessageCredentials :: (MonadIO m, IsUnixCredentialsMessage o) => o -> m Gio.Credentials.Credentials
getUnixCredentialsMessageCredentials obj = liftIO $ checkUnexpectedNothing "getUnixCredentialsMessageCredentials" $ B.Properties.getObjectPropertyObject obj "credentials" Gio.Credentials.Credentials

{- |
Construct a `GValueConstruct` with valid value for the “@credentials@” property. This is rarely needed directly, but it is used by `Data.GI.Base.Constructible.new`.
-}
constructUnixCredentialsMessageCredentials :: (IsUnixCredentialsMessage o, Gio.Credentials.IsCredentials a) => a -> IO (GValueConstruct o)
constructUnixCredentialsMessageCredentials val = B.Properties.constructObjectPropertyObject "credentials" (Just val)

#if ENABLE_OVERLOADING
data UnixCredentialsMessageCredentialsPropertyInfo
instance AttrInfo UnixCredentialsMessageCredentialsPropertyInfo where
    type AttrAllowedOps UnixCredentialsMessageCredentialsPropertyInfo = '[ 'AttrConstruct, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint UnixCredentialsMessageCredentialsPropertyInfo = Gio.Credentials.IsCredentials
    type AttrBaseTypeConstraint UnixCredentialsMessageCredentialsPropertyInfo = IsUnixCredentialsMessage
    type AttrGetType UnixCredentialsMessageCredentialsPropertyInfo = Gio.Credentials.Credentials
    type AttrLabel UnixCredentialsMessageCredentialsPropertyInfo = "credentials"
    type AttrOrigin UnixCredentialsMessageCredentialsPropertyInfo = UnixCredentialsMessage
    attrGet _ = getUnixCredentialsMessageCredentials
    attrSet _ = undefined
    attrConstruct _ = constructUnixCredentialsMessageCredentials
    attrClear _ = undefined
#endif

#if ENABLE_OVERLOADING
instance O.HasAttributeList UnixCredentialsMessage
type instance O.AttributeList UnixCredentialsMessage = UnixCredentialsMessageAttributeList
type UnixCredentialsMessageAttributeList = ('[ '("credentials", UnixCredentialsMessageCredentialsPropertyInfo)] :: [(Symbol, *)])
#endif

#if ENABLE_OVERLOADING
unixCredentialsMessageCredentials :: AttrLabelProxy "credentials"
unixCredentialsMessageCredentials = AttrLabelProxy

#endif

#if ENABLE_OVERLOADING
type instance O.SignalList UnixCredentialsMessage = UnixCredentialsMessageSignalList
type UnixCredentialsMessageSignalList = ('[ '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

#endif

-- method UnixCredentialsMessage::new
-- method type : Constructor
-- Args : []
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gio", name = "UnixCredentialsMessage"}))
-- throws : False
-- Skip return : False

foreign import ccall "g_unix_credentials_message_new" g_unix_credentials_message_new ::
    IO (Ptr UnixCredentialsMessage)

{- |
Creates a new 'GI.Gio.Objects.UnixCredentialsMessage.UnixCredentialsMessage' with credentials matching the current processes.

/Since: 2.26/
-}
unixCredentialsMessageNew ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    m UnixCredentialsMessage
    {- ^ __Returns:__ a new 'GI.Gio.Objects.UnixCredentialsMessage.UnixCredentialsMessage' -}
unixCredentialsMessageNew  = liftIO $ do
    result <- g_unix_credentials_message_new
    checkUnexpectedReturnNULL "unixCredentialsMessageNew" result
    result' <- (wrapObject UnixCredentialsMessage) result
    return result'

#if ENABLE_OVERLOADING
#endif

-- method UnixCredentialsMessage::new_with_credentials
-- method type : Constructor
-- Args : [Arg {argCName = "credentials", argType = TInterface (Name {namespace = "Gio", name = "Credentials"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "A #GCredentials object.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gio", name = "UnixCredentialsMessage"}))
-- throws : False
-- Skip return : False

foreign import ccall "g_unix_credentials_message_new_with_credentials" g_unix_credentials_message_new_with_credentials ::
    Ptr Gio.Credentials.Credentials ->      -- credentials : TInterface (Name {namespace = "Gio", name = "Credentials"})
    IO (Ptr UnixCredentialsMessage)

{- |
Creates a new 'GI.Gio.Objects.UnixCredentialsMessage.UnixCredentialsMessage' holding /@credentials@/.

/Since: 2.26/
-}
unixCredentialsMessageNewWithCredentials ::
    (B.CallStack.HasCallStack, MonadIO m, Gio.Credentials.IsCredentials a) =>
    a
    {- ^ /@credentials@/: A 'GI.Gio.Objects.Credentials.Credentials' object. -}
    -> m UnixCredentialsMessage
    {- ^ __Returns:__ a new 'GI.Gio.Objects.UnixCredentialsMessage.UnixCredentialsMessage' -}
unixCredentialsMessageNewWithCredentials credentials = liftIO $ do
    credentials' <- unsafeManagedPtrCastPtr credentials
    result <- g_unix_credentials_message_new_with_credentials credentials'
    checkUnexpectedReturnNULL "unixCredentialsMessageNewWithCredentials" result
    result' <- (wrapObject UnixCredentialsMessage) result
    touchManagedPtr credentials
    return result'

#if ENABLE_OVERLOADING
#endif

-- method UnixCredentialsMessage::get_credentials
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "message", argType = TInterface (Name {namespace = "Gio", name = "UnixCredentialsMessage"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "A #GUnixCredentialsMessage.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gio", name = "Credentials"}))
-- throws : False
-- Skip return : False

foreign import ccall "g_unix_credentials_message_get_credentials" g_unix_credentials_message_get_credentials ::
    Ptr UnixCredentialsMessage ->           -- message : TInterface (Name {namespace = "Gio", name = "UnixCredentialsMessage"})
    IO (Ptr Gio.Credentials.Credentials)

{- |
Gets the credentials stored in /@message@/.

/Since: 2.26/
-}
unixCredentialsMessageGetCredentials ::
    (B.CallStack.HasCallStack, MonadIO m, IsUnixCredentialsMessage a) =>
    a
    {- ^ /@message@/: A 'GI.Gio.Objects.UnixCredentialsMessage.UnixCredentialsMessage'. -}
    -> m Gio.Credentials.Credentials
    {- ^ __Returns:__ A 'GI.Gio.Objects.Credentials.Credentials' instance. Do not free, it is owned by /@message@/. -}
unixCredentialsMessageGetCredentials message = liftIO $ do
    message' <- unsafeManagedPtrCastPtr message
    result <- g_unix_credentials_message_get_credentials message'
    checkUnexpectedReturnNULL "unixCredentialsMessageGetCredentials" result
    result' <- (newObject Gio.Credentials.Credentials) result
    touchManagedPtr message
    return result'

#if ENABLE_OVERLOADING
data UnixCredentialsMessageGetCredentialsMethodInfo
instance (signature ~ (m Gio.Credentials.Credentials), MonadIO m, IsUnixCredentialsMessage a) => O.MethodInfo UnixCredentialsMessageGetCredentialsMethodInfo a signature where
    overloadedMethod _ = unixCredentialsMessageGetCredentials

#endif

-- method UnixCredentialsMessage::is_supported
-- method type : MemberFunction
-- Args : []
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "g_unix_credentials_message_is_supported" g_unix_credentials_message_is_supported ::
    IO CInt

{- |
Checks if passing 'GI.Gio.Objects.Credentials.Credentials' on a 'GI.Gio.Objects.Socket.Socket' is supported on this platform.

/Since: 2.26/
-}
unixCredentialsMessageIsSupported ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    m Bool
    {- ^ __Returns:__ 'True' if supported, 'False' otherwise -}
unixCredentialsMessageIsSupported  = liftIO $ do
    result <- g_unix_credentials_message_is_supported
    let result' = (/= 0) result
    return result'

#if ENABLE_OVERLOADING
#endif