capnp-0.17.0.0: Cap'n Proto for Haskell
Safe HaskellSafe-Inferred
LanguageHaskell2010

Capnp.Rpc.Server

Description

The term server in this context refers to a thread that handles method calls for a particular capability (The capnproto rpc protocol itself has no concept of clients and servers).

Synopsis

Documentation

class Server a where Source #

Base class for things that can act as capnproto servers.

Minimal complete definition

Nothing

Methods

shutdown :: a -> IO () Source #

Called when the last live reference to a server is dropped.

unwrap :: Typeable b => a -> Maybe b Source #

Try to extract a value of a given type. The default implementation always fails (returns Nothing). If an instance chooses to implement this, it will be possible to use "reflection" on clients that point at local servers to dynamically unwrap the server value. A typical implementation will just call Typeable's cast method, but this needn't be the case -- a server may wish to allow local peers to unwrap some value that is not exactly the data the server has access to.

data ServerOps Source #

The operations necessary to receive and handle method calls, i.e. to implement an object. It is parametrized over the monadic context in which methods are serviced.

Constructors

ServerOps 

Fields

data CallInfo Source #

A CallInfo contains information about a method call.

Constructors

CallInfo 

Fields

runServer :: Q CallInfo -> ServerOps -> IO () Source #

Handle incoming messages for a given object.

Accepts a queue of messages to handle, and ServerOps used to handle them. returns when it receives a Stop message.

Handling methods

data MethodHandler p r Source #

a MethodHandler p r handles a method call with parameters p and return type r.

The library represents method handlers via an abstract type MethodHandler, parametrized over parameter (p) and return (r) types, and the monadic context in which it runs (m). This allows us to provide different strategies for actually handling methods; there are various helper functions which construct these handlers.

At some point we will likely additionally provide handlers affording:

  • Working directly with the low-level data types.
  • Replying to the method call asynchronously, allowing later method calls to be serviced before the current one is finished.

type UntypedMethodHandler = MethodHandler (Maybe (Ptr 'Const)) (Maybe (Ptr 'Const)) Source #

Alias for a MethodHandler whose parameter and return types are untyped pointers.

Working with untyped data

untypedHandler :: (Maybe (Ptr 'Const) -> Fulfiller (Maybe (Ptr 'Const)) -> IO ()) -> MethodHandler (Maybe (Ptr 'Const)) (Maybe (Ptr 'Const)) Source #

Construct a method handler from a function accepting an untyped pointer for the method's parameter, and a Fulfiller which accepts an untyped pointer for the method's return value.

toUntypedHandler :: MethodHandler p r -> UntypedMethodHandler Source #

Convert a MethodHandler for any parameter and return types into one that deals with untyped pointers.