-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Abstract Protocol Loop
--   
--   Embeddable Application Protocol Loop
@package n2o
@version 0.11.1


-- | Basic types
module Network.N2O.Types

-- | An HTTP header
type Header = (ByteString, ByteString)

-- | An HTTP request
data Req
Req :: ByteString -> ByteString -> ByteString -> [Header] -> Req
[reqPath] :: Req -> ByteString
[reqMeth] :: Req -> ByteString
[reqVers] :: Req -> ByteString
[reqHead] :: Req -> [Header]

-- | The N2O context data type This is the key data type of the N2O. <tt>(f
--   :: * -&gt; *)</tt> - type constructor for the protocol handler's input
--   type. <tt>(a :: *)</tt> - base type for the event handler's input
--   type. I.e. <tt>(f a)</tt> gives input type for the protocol handler.
--   <tt>(Event a)</tt> gives input type for the event handler.
data Context (f :: * -> *) a
Context :: (Event a -> N2O f a (Result a)) -> Req -> [Context f a -> Context f a] -> [Proto f a] -> (ByteString -> Maybe a) -> (a -> ByteString) -> Map ByteString ByteString -> Context a
[cxHandler] :: Context a -> Event a -> N2O f a (Result a)
[cxReq] :: Context a -> Req
[cxMiddleware] :: Context a -> [Context f a -> Context f a]
[cxProtos] :: Context a -> [Proto f a]
[cxDePickle] :: Context a -> ByteString -> Maybe a
[cxPickle] :: Context a -> a -> ByteString
[cxState] :: Context a -> Map ByteString ByteString

-- | Result of the message processing
data Result a
Reply :: a -> Result a
Ok :: Result a
Unknown :: Result a
Empty :: Result a

-- | N2O protocol handler
newtype Proto f a
Proto :: (f a -> N2O f a (Result (f a))) -> Proto f a
[protoInfo] :: Proto f a -> f a -> N2O f a (Result (f a))

-- | Event data type
data Event a
Init :: Event a
Message :: a -> Event a
Terminate :: Event a

-- | Local mutable state
type State f a = IORef (Context f a)

-- | <a>N2OT</a> over <a>IO</a> with <tt>N2OState</tt> as env
type N2O f a = N2OT (State f a) IO

-- | Reader monad transformer
newtype N2OT state m a
N2OT :: (state -> m a) -> N2OT state m a
[runN2O] :: N2OT state m a -> state -> m a
instance GHC.Classes.Eq a => GHC.Classes.Eq (Network.N2O.Types.Result a)
instance GHC.Show.Show a => GHC.Show.Show (Network.N2O.Types.Result a)
instance GHC.Base.Functor m => GHC.Base.Functor (Network.N2O.Types.N2OT state m)
instance GHC.Base.Applicative m => GHC.Base.Applicative (Network.N2O.Types.N2OT state m)
instance GHC.Base.Monad m => GHC.Base.Monad (Network.N2O.Types.N2OT state m)


-- | Core functions
module Network.N2O.Core

-- | Lift underlying monad to the N2O monad
lift :: m a -> N2OT state m a

-- | Get current state (env)
ask :: Monad m => N2OT state m state

-- | Put data to the local state
put :: Binary bin => ByteString -> bin -> N2O f a ()

-- | Get data from the local state
get :: Binary bin => ByteString -> N2O f a (Maybe bin)

-- | <a>Context</a> constructor
mkCx :: () => Context f a

-- | <a>Req</a> constructor
mkReq :: Req

-- | N2O protocol loop
protoRun :: f a -> [Proto f a] -> N2O f a (Result (f a))


-- | This module defines basic types and functions for the N2O Framework.
--   
--   One of the trickiest part of the client-server applications is the
--   communication protocol between client and server. This package aims to
--   provide scalable application level infrastructure for protocols and
--   services.
--   
--   Logically, this package consists of two parts:
--   
--   <ul>
--   <li>the <a>N2O</a> monad for local state management;</li>
--   <li>the <a>protoRun</a> function, that allows to perform abstract
--   protocol loop.</li>
--   </ul>
--   
--   For basic usage see <a>N2O sample app</a>
module Network.N2O
