mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2024-12-17 17:20:21 +01:00
Instance template (#33)
* protocol instance template [WIP] * protocol instances template * add methods to check correctness of participant types in protocol TH * PushConfirm and and PushMsg implementation types * check Command type + doctest
This commit is contained in:
committed by
GitHub
parent
aa2ac80cf9
commit
bdec751725
@@ -1,62 +1,48 @@
|
||||
{-# OPTIONS_GHC -fno-warn-unticked-promoted-constructors #-}
|
||||
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
||||
-- {-# OPTIONS_GHC -ddump-splices #-}
|
||||
{-# LANGUAGE AllowAmbiguousTypes #-}
|
||||
{-# LANGUAGE DataKinds #-}
|
||||
{-# LANGUAGE FlexibleContexts #-}
|
||||
{-# LANGUAGE FlexibleInstances #-}
|
||||
{-# LANGUAGE GADTs #-}
|
||||
{-# LANGUAGE MultiParamTypeClasses #-}
|
||||
{-# LANGUAGE TemplateHaskell #-}
|
||||
{-# LANGUAGE TypeOperators #-}
|
||||
|
||||
module Simplex.Messaging.Client where
|
||||
|
||||
import ClassyPrelude
|
||||
import Data.Singletons.TH
|
||||
import Simplex.Messaging.Protocol
|
||||
import Simplex.Messaging.Types
|
||||
|
||||
|
||||
-- $(protocol Recipient [d|
|
||||
-- raCreateConn :: (--> Broker) CreateConn
|
||||
-- raSubscribe :: (--> Broker) Subscribe
|
||||
-- rcPushConfirm :: (<-- Broker) PushConfirm
|
||||
-- rcPushMsg :: (<-- Broker) PushMsg
|
||||
-- ...
|
||||
-- |]
|
||||
|
||||
instance Prf HasState Sender s
|
||||
=> ProtocolAction Recipient
|
||||
Broker
|
||||
CreateConnRequest CreateConnResponse
|
||||
(None <==> None <==| s)
|
||||
(New <==> New <==| s)
|
||||
Idle Idle 0 0
|
||||
where
|
||||
action = CreateConn
|
||||
protoAction = rCreateConn
|
||||
|
||||
instance ( (r /= None && r /= Disabled) ~ True
|
||||
, (b /= None && b /= Disabled) ~ True
|
||||
, Prf HasState Sender s )
|
||||
=> ProtocolAction Recipient
|
||||
Broker
|
||||
() ()
|
||||
(r <==> b <==| s)
|
||||
(r <==> b <==| s)
|
||||
Idle Subscribed n n
|
||||
where
|
||||
action = Subscribe
|
||||
protoAction = rSubscribe
|
||||
$(protocol Recipient [d|
|
||||
raCreateConn = CreateConn --> Broker
|
||||
raSubscribe = Subscribe --> Broker
|
||||
rcPushConfirm = PushConfirm <-- Broker
|
||||
rcPushMsg = PushMsg <-- Broker
|
||||
|])
|
||||
|
||||
|
||||
rCreateConn :: Connection Recipient None Idle
|
||||
-> CreateConnRequest
|
||||
-> Either String CreateConnResponse
|
||||
-> Either String (Connection Recipient New Idle)
|
||||
rCreateConn = protoActionStub
|
||||
raCreateConn :: Connection Recipient None Idle
|
||||
-> CreateConnRequest
|
||||
-> Either String CreateConnResponse
|
||||
-> Either String (Connection Recipient New Idle)
|
||||
raCreateConn = protoActionStub
|
||||
|
||||
rSubscribe :: Connection Recipient s Idle
|
||||
-> ()
|
||||
-> Either String ()
|
||||
-> Either String (Connection Recipient s Subscribed)
|
||||
rSubscribe = protoActionStub
|
||||
raSubscribe :: Connection Recipient s Idle
|
||||
-> ()
|
||||
-> Either String ()
|
||||
-> Either String (Connection Recipient s Subscribed)
|
||||
raSubscribe = protoActionStub
|
||||
|
||||
rcPushConfirm :: Connection Recipient Pending Subscribed
|
||||
-> SecureConnRequest
|
||||
-> Either String ((), Connection Recipient Confirmed Subscribed)
|
||||
rcPushConfirm = protoCmdStub
|
||||
|
||||
rcPushMsg :: Connection Recipient Secured Subscribed
|
||||
-> MessagesResponse -- TODO, has to be a single message
|
||||
-> Either String ((), Connection Recipient Secured Subscribed)
|
||||
rcPushMsg = protoCmdStub
|
||||
|
||||
Reference in New Issue
Block a user