Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
quasar-wayland
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jens Nolte
quasar-wayland
Commits
0ed34ba9
Commit
0ed34ba9
authored
3 years ago
by
Jens Nolte
Browse files
Options
Downloads
Patches
Plain Diff
Use ProtocolAction type alias in all relevant places
parent
a9a97c1b
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Quasar/Wayland/Protocol/Core.hs
+11
-13
11 additions, 13 deletions
src/Quasar/Wayland/Protocol/Core.hs
with
11 additions
and
13 deletions
src/Quasar/Wayland/Protocol/Core.hs
+
11
−
13
View file @
0ed34ba9
...
@@ -324,7 +324,9 @@ data ProtocolException = ProtocolException String
...
@@ -324,7 +324,9 @@ data ProtocolException = ProtocolException String
type
ProtocolStep
s
m
a
=
ProtocolState
s
m
->
m
(
Either
SomeException
a
,
Maybe
BSL
.
ByteString
,
ProtocolState
s
m
)
type
ProtocolStep
s
m
a
=
ProtocolState
s
m
->
m
(
Either
SomeException
a
,
Maybe
BSL
.
ByteString
,
ProtocolState
s
m
)
protocolStep
::
forall
s
m
a
.
MonadCatch
m
=>
StateT
(
ProtocolState
s
m
)
m
a
->
ProtocolStep
s
m
a
type
ProtocolAction
s
m
a
=
StateT
(
ProtocolState
s
m
)
m
a
protocolStep
::
forall
s
m
a
.
MonadCatch
m
=>
ProtocolAction
s
m
a
->
ProtocolStep
s
m
a
protocolStep
action
inState
=
do
protocolStep
action
inState
=
do
mapM_
throwM
inState
.
protocolException
mapM_
throwM
inState
.
protocolException
(
result
,
(
outbox
,
outState
))
<-
fmap
takeOutbox
.
storeExceptionIfFailed
<$>
runStateT
(
try
action
)
inState
(
result
,
(
outbox
,
outState
))
<-
fmap
takeOutbox
.
storeExceptionIfFailed
<$>
runStateT
(
try
action
)
inState
...
@@ -374,6 +376,10 @@ feedInput bytes = protocolStep do
...
@@ -374,6 +376,10 @@ feedInput bytes = protocolStep do
inboxDecoder
=
pushChunk
st
.
inboxDecoder
bytes
inboxDecoder
=
pushChunk
st
.
inboxDecoder
bytes
}
}
setException
::
(
MonadCatch
m
,
Exception
e
)
=>
e
->
ProtocolStep
s
m
()
setException
ex
=
protocolStep
do
State
.
modify
\
st
->
st
{
protocolException
=
Just
(
toException
ex
)}
-- | Sends a message without checking any ids or creating proxy objects objects.
-- | Sends a message without checking any ids or creating proxy objects objects.
sendMessage
::
forall
s
m
i
.
(
IsInterfaceSide
s
i
,
MonadCatch
m
)
=>
Object
s
m
i
->
Up
s
i
->
ProtocolStep
s
m
()
sendMessage
::
forall
s
m
i
.
(
IsInterfaceSide
s
i
,
MonadCatch
m
)
=>
Object
s
m
i
->
Up
s
i
->
ProtocolStep
s
m
()
sendMessage
object
message
=
protocolStep
do
sendMessage
object
message
=
protocolStep
do
...
@@ -394,12 +400,6 @@ sendMessage object message = protocolStep do
...
@@ -394,12 +400,6 @@ sendMessage object message = protocolStep do
msgSizeInteger
::
Integer
msgSizeInteger
::
Integer
msgSizeInteger
=
8
+
fromIntegral
(
BSL
.
length
body
)
msgSizeInteger
=
8
+
fromIntegral
(
BSL
.
length
body
)
setException
::
(
MonadCatch
m
,
Exception
e
)
=>
e
->
ProtocolStep
s
m
()
setException
ex
=
protocolStep
do
State
.
modify
\
st
->
st
{
protocolException
=
Just
(
toException
ex
)}
-- * Internals
-- | Take data that has to be sent (if available)
-- | Take data that has to be sent (if available)
takeOutbox
::
ProtocolState
s
m
->
(
Maybe
BSL
.
ByteString
,
ProtocolState
s
m
)
takeOutbox
::
ProtocolState
s
m
->
(
Maybe
BSL
.
ByteString
,
ProtocolState
s
m
)
takeOutbox
st
=
(
maybeOutboxData
,
st
{
outbox
=
Nothing
,
bytesSent
=
st
.
bytesSent
+
outboxNumBytes
})
takeOutbox
st
=
(
maybeOutboxData
,
st
{
outbox
=
Nothing
,
bytesSent
=
st
.
bytesSent
+
outboxNumBytes
})
...
@@ -409,14 +409,14 @@ takeOutbox st = (maybeOutboxData, st{outbox = Nothing, bytesSent = st.bytesSent
...
@@ -409,14 +409,14 @@ takeOutbox st = (maybeOutboxData, st{outbox = Nothing, bytesSent = st.bytesSent
outboxNumBytes
=
maybe
0
BSL
.
length
maybeOutboxData
outboxNumBytes
=
maybe
0
BSL
.
length
maybeOutboxData
receiveMessages
::
(
IsSide
s
,
MonadCatch
m
)
=>
StateT
(
ProtocolState
s
m
)
m
()
receiveMessages
::
(
IsSide
s
,
MonadCatch
m
)
=>
ProtocolAction
s
m
()
receiveMessages
=
receiveRawMessage
>>=
\
case
receiveMessages
=
receiveRawMessage
>>=
\
case
Nothing
->
pure
()
Nothing
->
pure
()
Just
rawMessage
->
do
Just
rawMessage
->
do
handleRawMessage
rawMessage
handleRawMessage
rawMessage
receiveMessages
receiveMessages
handleRawMessage
::
forall
s
m
.
MonadCatch
m
=>
RawMessage
->
StateT
(
ProtocolState
s
m
)
m
()
handleRawMessage
::
forall
s
m
.
MonadCatch
m
=>
RawMessage
->
ProtocolAction
s
m
()
handleRawMessage
(
oId
,
opcode
,
body
)
=
do
handleRawMessage
(
oId
,
opcode
,
body
)
=
do
objects
<-
State
.
gets
(
.
objects
)
objects
<-
State
.
gets
(
.
objects
)
case
HM
.
lookup
oId
objects
of
case
HM
.
lookup
oId
objects
of
...
@@ -442,11 +442,9 @@ getMessageAction object@(Object _ objectHandler) opcode = do
...
@@ -442,11 +442,9 @@ getMessageAction object@(Object _ objectHandler) opcode = do
message
<-
getDown
object
opcode
message
<-
getDown
object
opcode
pure
$
handleMessage
objectHandler
object
message
pure
$
handleMessage
objectHandler
object
message
type
ProtocolAction
s
m
a
=
StateT
(
ProtocolState
s
m
)
m
a
type
RawMessage
=
(
ObjectId
,
Opcode
,
BSL
.
ByteString
)
type
RawMessage
=
(
ObjectId
,
Opcode
,
BSL
.
ByteString
)
receiveRawMessage
::
forall
s
m
.
MonadCatch
m
=>
StateT
(
ProtocolState
s
m
)
m
(
Maybe
RawMessage
)
receiveRawMessage
::
forall
s
m
.
MonadCatch
m
=>
ProtocolAction
s
m
(
Maybe
RawMessage
)
receiveRawMessage
=
do
receiveRawMessage
=
do
st
<-
State
.
get
st
<-
State
.
get
(
result
,
newDecoder
)
<-
checkDecoder
st
.
inboxDecoder
(
result
,
newDecoder
)
<-
checkDecoder
st
.
inboxDecoder
...
@@ -455,7 +453,7 @@ receiveRawMessage = do
...
@@ -455,7 +453,7 @@ receiveRawMessage = do
where
where
checkDecoder
checkDecoder
::
Decoder
RawMessage
::
Decoder
RawMessage
->
StateT
(
ProtocolState
s
m
)
m
(
Maybe
RawMessage
,
Decoder
RawMessage
)
->
ProtocolAction
s
m
(
Maybe
RawMessage
,
Decoder
RawMessage
)
checkDecoder
(
Fail
_
_
message
)
=
throwM
(
ParserFailed
"RawMessage"
message
)
checkDecoder
(
Fail
_
_
message
)
=
throwM
(
ParserFailed
"RawMessage"
message
)
checkDecoder
x
@
(
Partial
_
)
=
pure
(
Nothing
,
x
)
checkDecoder
x
@
(
Partial
_
)
=
pure
(
Nothing
,
x
)
checkDecoder
(
Done
leftovers
_
result
)
=
pure
(
Just
result
,
pushChunk
(
runGetIncremental
getRawMessage
)
leftovers
)
checkDecoder
(
Done
leftovers
_
result
)
=
pure
(
Just
result
,
pushChunk
(
runGetIncremental
getRawMessage
)
leftovers
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment