mellon-core-0.8.0.4: Control physical access devices

Copyright(c) 2017 Quixoftic LLC
LicenseBSD3
MaintainerDrew Hess <dhess-src@quixoftic.com>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellSafe
LanguageHaskell2010

Mellon.Device

Contents

Description

This module provides both a parameterized type for adapting a device-specific interface to the generic interface expected by a Controller, and a "mock lock" device implementation, which is useful for testing.

Synopsis

The mellon-core device type

data Device d Source #

A parametric device type which provides two "methods," one to lock the device, and the other to unlock it.

The parameter d is the concrete device type and is used during construction to create the two methods by binding them to actions on the specific device.

For example, the implementation of the mockLockDevice function, which wraps a MockLock in a Device d, looks like this:

mockLockDevice :: MockLock -> Device MockLock
mockLockDevice l =
  Device (liftIO $ lockMockLock l)
         (liftIO $ unlockMockLock l)

A program can construct such a device and use it like so:

>>> ml <- mockLock
>>> let mld = mockLockDevice ml
>>> events ml
[]
>>> lockDevice mld
>>> events ml
[LockEvent ... UTC]
>>> unlockDevice mld
>>> events ml
[LockEvent ... UTC,UnlockEvent ... UTC]

Constructors

Device 

Fields

A mock lock implementation

The mock lock type provided here logs lock / unlock events along with a timestamp. It is useful for testing but doesn't have any facility to control an actual physical access device.

data MockLock Source #

A mock lock device that logs lock / unlock events.

No constructor is exported. Use mockLock to create a new instance and events to extract the log.

Instances

mockLock :: MonadIO m => m MockLock Source #

Construct a new mock lock with an empty event log.

data MockLockEvent Source #

Events logged by MockLock are of this type.

Instances

Eq MockLockEvent Source # 
Data MockLockEvent Source # 

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> MockLockEvent -> c MockLockEvent #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c MockLockEvent #

toConstr :: MockLockEvent -> Constr #

dataTypeOf :: MockLockEvent -> DataType #

dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c MockLockEvent) #

dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c MockLockEvent) #

gmapT :: (forall b. Data b => b -> b) -> MockLockEvent -> MockLockEvent #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> MockLockEvent -> r #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> MockLockEvent -> r #

gmapQ :: (forall d. Data d => d -> u) -> MockLockEvent -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> MockLockEvent -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> MockLockEvent -> m MockLockEvent #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> MockLockEvent -> m MockLockEvent #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> MockLockEvent -> m MockLockEvent #

Read MockLockEvent Source # 
Show MockLockEvent Source # 
Generic MockLockEvent Source # 

Associated Types

type Rep MockLockEvent :: * -> * #

type Rep MockLockEvent Source # 
type Rep MockLockEvent = D1 * (MetaData "MockLockEvent" "Mellon.Device" "mellon-core-0.8.0.4-B2p7JK1pvHSHCgXThbddhL" False) ((:+:) * (C1 * (MetaCons "LockEvent" PrefixI False) (S1 * (MetaSel (Nothing Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 * UTCTime))) (C1 * (MetaCons "UnlockEvent" PrefixI False) (S1 * (MetaSel (Nothing Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 * UTCTime))))

lockMockLock :: MonadIO m => MockLock -> m () Source #

Lock the mock lock.

unlockMockLock :: MonadIO m => MockLock -> m () Source #

Unlock the mock lock.

events :: MonadIO m => MockLock -> m [MockLockEvent] Source #

Extract the current log of events from the mock lock.

mockLockDevice :: MockLock -> Device MockLock Source #

Wrap a MockLock value with a Device value, for use with a mellon-core controller.