Copyright | (c) 2017 Quixoftic LLC |
---|---|
License | BSD3 |
Maintainer | Drew Hess <dhess-src@quixoftic.com> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | Safe |
Language | Haskell2010 |
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.
- data Device d = Device {
- lockDevice :: IO ()
- unlockDevice :: IO ()
- data MockLock
- mockLock :: MonadIO m => m MockLock
- data MockLockEvent
- lockMockLock :: MonadIO m => MockLock -> m ()
- unlockMockLock :: MonadIO m => MockLock -> m ()
- events :: MonadIO m => MockLock -> m [MockLockEvent]
- mockLockDevice :: MockLock -> Device MockLock
The mellon-core device type
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]
Device | |
|
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 MockLockEvent Source #
Events logged by MockLock
are of this type.
lockMockLock :: MonadIO m => MockLock -> m () Source #
Lock the mock lock.
unlockMockLock :: MonadIO m => MockLock -> m () Source #
Unlock the mock lock.