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
25f00dfb
Commit
25f00dfb
authored
3 years ago
by
Jens Nolte
Browse files
Options
Downloads
Patches
Plain Diff
Implement object lookup
parent
95e9525c
No related branches found
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
+38
-4
38 additions, 4 deletions
src/Quasar/Wayland/Protocol/Core.hs
with
38 additions
and
4 deletions
src/Quasar/Wayland/Protocol/Core.hs
+
38
−
4
View file @
25f00dfb
...
...
@@ -41,6 +41,7 @@ module Quasar.Wayland.Protocol.Core (
newObject
,
newObjectFromId
,
getObject
,
lookupObject
,
-- * Protocol exceptions
WireCallbackFailed
(
..
),
...
...
@@ -70,6 +71,7 @@ import Data.HashMap.Strict (HashMap)
import
Data.HashMap.Strict
qualified
as
HM
import
Data.Proxy
import
Data.String
(
IsString
(
..
))
import
Data.Typeable
(
Typeable
,
cast
)
import
Data.Void
(
absurd
)
import
GHC.Conc
(
unsafeIOToSTM
)
import
GHC.TypeLits
...
...
@@ -183,7 +185,8 @@ instance WireFormat Void where
class
(
IsMessage
(
WireRequest
i
),
IsMessage
(
WireEvent
i
),
KnownSymbol
(
InterfaceName
i
)
KnownSymbol
(
InterfaceName
i
),
Typeable
i
)
=>
IsInterface
i
where
type
RequestHandler
i
...
...
@@ -195,7 +198,7 @@ class (
interfaceName
::
forall
i
.
IsInterface
i
=>
String
interfaceName
=
symbolVal
@
(
InterfaceName
i
)
Proxy
class
IsSide
(
s
::
Side
)
where
class
Typeable
s
=>
IsSide
(
s
::
Side
)
where
type
MessageHandler
s
i
type
WireUp
s
i
type
WireDown
s
i
...
...
@@ -241,6 +244,7 @@ class IsInterfaceSide s i => IsInterfaceHandler s i a where
-- | Data kind
data
Side
=
Client
|
Server
deriving
stock
(
Eq
,
Show
,
Typeable
)
-- | An object belonging to a wayland connection.
...
...
@@ -249,6 +253,8 @@ data Object s i = IsInterfaceSide s i => Object {
objectId
::
ObjectId
(
InterfaceName
i
),
messageHandler
::
TVar
(
Maybe
(
MessageHandler
s
i
))
}
deriving
stock
Typeable
getMessageHandler
::
Object
s
i
->
STM
(
MessageHandler
s
i
)
getMessageHandler
object
=
maybe
retry
pure
=<<
readTVar
object
.
messageHandler
...
...
@@ -359,6 +365,10 @@ data ServerError = ServerError Word32 String
deriving
stock
Show
deriving
anyclass
Exception
data
InvalidObject
=
InvalidObject
String
deriving
stock
Show
deriving
anyclass
Exception
-- * Protocol state and monad plumbing
-- | Top-level protocol handle (used e.g. to send/receive data)
...
...
@@ -550,11 +560,35 @@ newObjectFromId messageHandler (NewId oId) = do
pure
object
fromSomeObject
::
forall
s
i
m
.
IsInterfaceSide
s
i
=>
SomeObject
s
->
Either
String
(
Object
s
i
)
fromSomeObject
(
UnknownObject
interface
_
)
=
Left
$
mconcat
[
"Object is of unknown interface "
,
interface
]
fromSomeObject
(
SomeObject
someObject
)
=
case
cast
someObject
of
Nothing
->
Left
$
mconcat
[
"Expected object for interface "
,
interfaceName
@
i
,
", but object is "
,
objectInterfaceName
someObject
]
Just
object
->
pure
object
lookupObject
::
forall
s
i
.
IsInterfaceSide
s
i
=>
ObjectId
(
InterfaceName
i
)
->
ProtocolM
s
(
Either
String
(
Object
s
i
))
lookupObject
oId
=
do
objects
<-
readProtocolVar
(
.
objectsVar
)
pure
case
HM
.
lookup
(
toGenericObjectId
oId
)
objects
of
Nothing
->
Left
$
mconcat
[
"No object with id "
,
show
oId
,
" is registered"
]
Just
someObject
->
case
fromSomeObject
someObject
of
Left
err
->
Left
err
Right
object
->
pure
object
getObject
::
IsInterfaceSide
s
i
::
forall
s
i
.
IsInterfaceSide
s
i
=>
ObjectId
(
InterfaceName
i
)
->
ProtocolM
s
(
Object
s
i
)
getObject
=
undefine
d
getObject
oId
=
either
(
throwM
.
InvalidObject
)
pure
=<<
lookupObject
oI
d
...
...
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