module GI.Soup.Objects.Request
(
Request(..) ,
IsRequest ,
toRequest ,
noRequest ,
RequestGetContentLengthMethodInfo ,
requestGetContentLength ,
RequestGetContentTypeMethodInfo ,
requestGetContentType ,
RequestGetSessionMethodInfo ,
requestGetSession ,
RequestGetUriMethodInfo ,
requestGetUri ,
RequestSendMethodInfo ,
requestSend ,
RequestSendAsyncMethodInfo ,
requestSendAsync ,
RequestSendFinishMethodInfo ,
requestSendFinish ,
RequestSessionPropertyInfo ,
constructRequestSession ,
getRequestSession ,
requestSession ,
RequestUriPropertyInfo ,
constructRequestUri ,
getRequestUri ,
requestUri ,
) 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.GError as B.GError
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
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 GI.GObject.Objects.Object as GObject.Object
import qualified GI.Gio.Callbacks as Gio.Callbacks
import qualified GI.Gio.Interfaces.AsyncResult as Gio.AsyncResult
import qualified GI.Gio.Interfaces.Initable as Gio.Initable
import qualified GI.Gio.Objects.Cancellable as Gio.Cancellable
import qualified GI.Gio.Objects.InputStream as Gio.InputStream
import qualified GI.Soup.Objects.Session as Soup.Session
import qualified GI.Soup.Structs.URI as Soup.URI
newtype Request = Request (ManagedPtr Request)
foreign import ccall "soup_request_get_type"
c_soup_request_get_type :: IO GType
instance GObject Request where
gobjectType _ = c_soup_request_get_type
class GObject o => IsRequest o
#if MIN_VERSION_base(4,9,0)
instance (GObject a, O.UnknownAncestorError Request a) =>
IsRequest a
#endif
instance IsRequest Request
instance GObject.Object.IsObject Request
instance Gio.Initable.IsInitable Request
toRequest :: IsRequest o => o -> IO Request
toRequest = unsafeCastTo Request
noRequest :: Maybe Request
noRequest = Nothing
type family ResolveRequestMethod (t :: Symbol) (o :: *) :: * where
ResolveRequestMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
ResolveRequestMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
ResolveRequestMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
ResolveRequestMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
ResolveRequestMethod "init" o = Gio.Initable.InitableInitMethodInfo
ResolveRequestMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
ResolveRequestMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
ResolveRequestMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
ResolveRequestMethod "ref" o = GObject.Object.ObjectRefMethodInfo
ResolveRequestMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
ResolveRequestMethod "replaceData" o = GObject.Object.ObjectReplaceDataMethodInfo
ResolveRequestMethod "replaceQdata" o = GObject.Object.ObjectReplaceQdataMethodInfo
ResolveRequestMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
ResolveRequestMethod "send" o = RequestSendMethodInfo
ResolveRequestMethod "sendAsync" o = RequestSendAsyncMethodInfo
ResolveRequestMethod "sendFinish" o = RequestSendFinishMethodInfo
ResolveRequestMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
ResolveRequestMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
ResolveRequestMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
ResolveRequestMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
ResolveRequestMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
ResolveRequestMethod "getContentLength" o = RequestGetContentLengthMethodInfo
ResolveRequestMethod "getContentType" o = RequestGetContentTypeMethodInfo
ResolveRequestMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
ResolveRequestMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
ResolveRequestMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
ResolveRequestMethod "getSession" o = RequestGetSessionMethodInfo
ResolveRequestMethod "getUri" o = RequestGetUriMethodInfo
ResolveRequestMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
ResolveRequestMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
ResolveRequestMethod l o = O.MethodResolutionFailed l o
instance (info ~ ResolveRequestMethod t Request, O.MethodInfo info Request p) => O.IsLabelProxy t (Request -> p) where
fromLabelProxy _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#if MIN_VERSION_base(4,9,0)
instance (info ~ ResolveRequestMethod t Request, O.MethodInfo info Request p) => O.IsLabel t (Request -> p) where
fromLabel _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#endif
getRequestSession :: (MonadIO m, IsRequest o) => o -> m Soup.Session.Session
getRequestSession obj = liftIO $ checkUnexpectedNothing "getRequestSession" $ getObjectPropertyObject obj "session" Soup.Session.Session
constructRequestSession :: (IsRequest o, Soup.Session.IsSession a) => a -> IO (GValueConstruct o)
constructRequestSession val = constructObjectPropertyObject "session" (Just val)
data RequestSessionPropertyInfo
instance AttrInfo RequestSessionPropertyInfo where
type AttrAllowedOps RequestSessionPropertyInfo = '[ 'AttrConstruct, 'AttrGet, 'AttrClear]
type AttrSetTypeConstraint RequestSessionPropertyInfo = Soup.Session.IsSession
type AttrBaseTypeConstraint RequestSessionPropertyInfo = IsRequest
type AttrGetType RequestSessionPropertyInfo = Soup.Session.Session
type AttrLabel RequestSessionPropertyInfo = "session"
type AttrOrigin RequestSessionPropertyInfo = Request
attrGet _ = getRequestSession
attrSet _ = undefined
attrConstruct _ = constructRequestSession
attrClear _ = undefined
getRequestUri :: (MonadIO m, IsRequest o) => o -> m Soup.URI.URI
getRequestUri obj = liftIO $ checkUnexpectedNothing "getRequestUri" $ getObjectPropertyBoxed obj "uri" Soup.URI.URI
constructRequestUri :: (IsRequest o) => Soup.URI.URI -> IO (GValueConstruct o)
constructRequestUri val = constructObjectPropertyBoxed "uri" (Just val)
data RequestUriPropertyInfo
instance AttrInfo RequestUriPropertyInfo where
type AttrAllowedOps RequestUriPropertyInfo = '[ 'AttrConstruct, 'AttrGet, 'AttrClear]
type AttrSetTypeConstraint RequestUriPropertyInfo = (~) Soup.URI.URI
type AttrBaseTypeConstraint RequestUriPropertyInfo = IsRequest
type AttrGetType RequestUriPropertyInfo = Soup.URI.URI
type AttrLabel RequestUriPropertyInfo = "uri"
type AttrOrigin RequestUriPropertyInfo = Request
attrGet _ = getRequestUri
attrSet _ = undefined
attrConstruct _ = constructRequestUri
attrClear _ = undefined
instance O.HasAttributeList Request
type instance O.AttributeList Request = RequestAttributeList
type RequestAttributeList = ('[ '("session", RequestSessionPropertyInfo), '("uri", RequestUriPropertyInfo)] :: [(Symbol, *)])
requestSession :: AttrLabelProxy "session"
requestSession = AttrLabelProxy
requestUri :: AttrLabelProxy "uri"
requestUri = AttrLabelProxy
type instance O.SignalList Request = RequestSignalList
type RequestSignalList = ('[ '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])
foreign import ccall "soup_request_get_content_length" soup_request_get_content_length ::
Ptr Request ->
IO Int64
requestGetContentLength ::
(B.CallStack.HasCallStack, MonadIO m, IsRequest a) =>
a
-> m Int64
requestGetContentLength request = liftIO $ do
request' <- unsafeManagedPtrCastPtr request
result <- soup_request_get_content_length request'
touchManagedPtr request
return result
data RequestGetContentLengthMethodInfo
instance (signature ~ (m Int64), MonadIO m, IsRequest a) => O.MethodInfo RequestGetContentLengthMethodInfo a signature where
overloadedMethod _ = requestGetContentLength
foreign import ccall "soup_request_get_content_type" soup_request_get_content_type ::
Ptr Request ->
IO CString
requestGetContentType ::
(B.CallStack.HasCallStack, MonadIO m, IsRequest a) =>
a
-> m (Maybe T.Text)
requestGetContentType request = liftIO $ do
request' <- unsafeManagedPtrCastPtr request
result <- soup_request_get_content_type request'
maybeResult <- convertIfNonNull result $ \result' -> do
result'' <- cstringToText result'
return result''
touchManagedPtr request
return maybeResult
data RequestGetContentTypeMethodInfo
instance (signature ~ (m (Maybe T.Text)), MonadIO m, IsRequest a) => O.MethodInfo RequestGetContentTypeMethodInfo a signature where
overloadedMethod _ = requestGetContentType
foreign import ccall "soup_request_get_session" soup_request_get_session ::
Ptr Request ->
IO (Ptr Soup.Session.Session)
requestGetSession ::
(B.CallStack.HasCallStack, MonadIO m, IsRequest a) =>
a
-> m Soup.Session.Session
requestGetSession request = liftIO $ do
request' <- unsafeManagedPtrCastPtr request
result <- soup_request_get_session request'
checkUnexpectedReturnNULL "requestGetSession" result
result' <- (newObject Soup.Session.Session) result
touchManagedPtr request
return result'
data RequestGetSessionMethodInfo
instance (signature ~ (m Soup.Session.Session), MonadIO m, IsRequest a) => O.MethodInfo RequestGetSessionMethodInfo a signature where
overloadedMethod _ = requestGetSession
foreign import ccall "soup_request_get_uri" soup_request_get_uri ::
Ptr Request ->
IO (Ptr Soup.URI.URI)
requestGetUri ::
(B.CallStack.HasCallStack, MonadIO m, IsRequest a) =>
a
-> m Soup.URI.URI
requestGetUri request = liftIO $ do
request' <- unsafeManagedPtrCastPtr request
result <- soup_request_get_uri request'
checkUnexpectedReturnNULL "requestGetUri" result
result' <- (newBoxed Soup.URI.URI) result
touchManagedPtr request
return result'
data RequestGetUriMethodInfo
instance (signature ~ (m Soup.URI.URI), MonadIO m, IsRequest a) => O.MethodInfo RequestGetUriMethodInfo a signature where
overloadedMethod _ = requestGetUri
foreign import ccall "soup_request_send" soup_request_send ::
Ptr Request ->
Ptr Gio.Cancellable.Cancellable ->
Ptr (Ptr GError) ->
IO (Ptr Gio.InputStream.InputStream)
requestSend ::
(B.CallStack.HasCallStack, MonadIO m, IsRequest a, Gio.Cancellable.IsCancellable b) =>
a
-> Maybe (b)
-> m Gio.InputStream.InputStream
requestSend request cancellable = liftIO $ do
request' <- unsafeManagedPtrCastPtr request
maybeCancellable <- case cancellable of
Nothing -> return nullPtr
Just jCancellable -> do
jCancellable' <- unsafeManagedPtrCastPtr jCancellable
return jCancellable'
onException (do
result <- propagateGError $ soup_request_send request' maybeCancellable
checkUnexpectedReturnNULL "requestSend" result
result' <- (wrapObject Gio.InputStream.InputStream) result
touchManagedPtr request
whenJust cancellable touchManagedPtr
return result'
) (do
return ()
)
data RequestSendMethodInfo
instance (signature ~ (Maybe (b) -> m Gio.InputStream.InputStream), MonadIO m, IsRequest a, Gio.Cancellable.IsCancellable b) => O.MethodInfo RequestSendMethodInfo a signature where
overloadedMethod _ = requestSend
foreign import ccall "soup_request_send_async" soup_request_send_async ::
Ptr Request ->
Ptr Gio.Cancellable.Cancellable ->
FunPtr Gio.Callbacks.C_AsyncReadyCallback ->
Ptr () ->
IO ()
requestSendAsync ::
(B.CallStack.HasCallStack, MonadIO m, IsRequest a, Gio.Cancellable.IsCancellable b) =>
a
-> Maybe (b)
-> Maybe (Gio.Callbacks.AsyncReadyCallback)
-> m ()
requestSendAsync request cancellable callback = liftIO $ do
request' <- unsafeManagedPtrCastPtr request
maybeCancellable <- case cancellable of
Nothing -> return nullPtr
Just jCancellable -> do
jCancellable' <- unsafeManagedPtrCastPtr jCancellable
return jCancellable'
ptrcallback <- callocMem :: IO (Ptr (FunPtr Gio.Callbacks.C_AsyncReadyCallback))
maybeCallback <- case callback of
Nothing -> return (castPtrToFunPtr nullPtr)
Just jCallback -> do
jCallback' <- Gio.Callbacks.mk_AsyncReadyCallback (Gio.Callbacks.wrap_AsyncReadyCallback (Just ptrcallback) (Gio.Callbacks.drop_closures_AsyncReadyCallback jCallback))
poke ptrcallback jCallback'
return jCallback'
let userData = nullPtr
soup_request_send_async request' maybeCancellable maybeCallback userData
touchManagedPtr request
whenJust cancellable touchManagedPtr
return ()
data RequestSendAsyncMethodInfo
instance (signature ~ (Maybe (b) -> Maybe (Gio.Callbacks.AsyncReadyCallback) -> m ()), MonadIO m, IsRequest a, Gio.Cancellable.IsCancellable b) => O.MethodInfo RequestSendAsyncMethodInfo a signature where
overloadedMethod _ = requestSendAsync
foreign import ccall "soup_request_send_finish" soup_request_send_finish ::
Ptr Request ->
Ptr Gio.AsyncResult.AsyncResult ->
Ptr (Ptr GError) ->
IO (Ptr Gio.InputStream.InputStream)
requestSendFinish ::
(B.CallStack.HasCallStack, MonadIO m, IsRequest a, Gio.AsyncResult.IsAsyncResult b) =>
a
-> b
-> m Gio.InputStream.InputStream
requestSendFinish request result_ = liftIO $ do
request' <- unsafeManagedPtrCastPtr request
result_' <- unsafeManagedPtrCastPtr result_
onException (do
result <- propagateGError $ soup_request_send_finish request' result_'
checkUnexpectedReturnNULL "requestSendFinish" result
result' <- (wrapObject Gio.InputStream.InputStream) result
touchManagedPtr request
touchManagedPtr result_
return result'
) (do
return ()
)
data RequestSendFinishMethodInfo
instance (signature ~ (b -> m Gio.InputStream.InputStream), MonadIO m, IsRequest a, Gio.AsyncResult.IsAsyncResult b) => O.MethodInfo RequestSendFinishMethodInfo a signature where
overloadedMethod _ = requestSendFinish