{-# LANGUAGE FlexibleContexts      #-}
{-# LANGUAGE MultiParamTypeClasses #-}
module Network.MessagePack.Server (
  -- * RPC method types
    Method
  , MethodType (..)
  , MethodDocs (..)
  , MethodVal (..)
  , ServerT (..)
  , Server

  -- * Build a method
  , method
  , methodName
  , methodDocs

  -- * Start RPC server
  , serve
  , runServer
  ) where

import           Control.Monad.Catch              (MonadCatch)
import           Control.Monad.IO.Unlift          (MonadUnliftIO)
import           Control.Monad.Trans              (MonadIO)
import           Control.Monad.Trans.Control      (MonadBaseControl)

import           Network.MessagePack.Protocol     (protocolMethods)
import           Network.MessagePack.Server.Basic


-- | Start RPC server with a set of RPC methods.
runServer
  :: (MonadBaseControl IO m, MonadIO m, MonadCatch m, MonadUnliftIO m)
  => Int        -- ^ Port number
  -> [Method m] -- ^ list of methods
  -> m ()
runServer :: Int -> [Method m] -> m ()
runServer Int
port [Method m]
methods =
  Int -> [Method m] -> m ()
forall (m :: * -> *).
(MonadBaseControl IO m, MonadIO m, MonadCatch m,
 MonadUnliftIO m) =>
Int -> [Method m] -> m ()
serve Int
port ([Method m] -> [Method m]
forall (m :: * -> *).
(MonadBaseControl IO m, MonadIO m, MonadCatch m) =>
[Method m] -> [Method m]
protocolMethods [Method m]
methods)