1 //Create a class for lock device
3 import Timer.SimulatedTimer
6 import gov.nasa.jpf.vm.Verify
14 //When we have only one device
15 private String id = "lockID0"
16 private String label = "lock0"
17 private String displayName = "lock0"
18 private String lockState = "locked"
19 private String currentLock = "locked"
20 private String lockLatestValue = "locked"
22 Locks(Closure sendEvent, int deviceNumbers) {
23 this.sendEvent = sendEvent
24 this.timers = new SimulatedTimer()
25 this.deviceNumbers = deviceNumbers
28 def init = Verify.getBoolean()
30 this.lockState = "locked"
31 this.lockLatestValue = "locked"
33 this.lockState = "unlocked"
34 this.lockLatestValue = "unlocked"
36 locks.add(new Lock(sendEvent,id, label, displayName, this.lockState, this.lockLatestValue))
41 if (lockState != "locked") {
42 lockLatestValue = lockState
44 currentLock = "locked"
49 def lock(LinkedHashMap metaData) {
50 if (lockState != "locked") {
51 def task = timers.runAfter(metaData["delay"]) {
52 lockLatestValue = lockState
54 currentLock = "locked"
61 if (lockState != "unlocked") {
62 lockLatestValue = lockState
63 lockState = "unlocked"
64 currentLock = "unlocked"
70 def unlock(LinkedHashMap metaData) {
71 if (lockState != "unlocked") {
72 def task = timers.runAfter(metaData["delay"]) {
73 lockLatestValue = lockState
74 lockState = "unlocked"
75 currentLock = "unlocked"
81 //Methods for closures
82 def count(Closure Input) {
88 def each(Closure Input) {
91 def find(Closure Input) {
94 def collect(Closure Input) {
99 def setValue(LinkedHashMap eventDataMap) {
100 if (eventDataMap["value"] != locks[0].lockState) {
101 locks[0].setValue(eventDataMap["value"])
102 this.lockState = locks[0].lockState
103 this.currentLock = locks[0].lockState
104 this.lockLatestValue = locks[0].lockLatestValue
105 sendEvent(eventDataMap)
109 def currentValue(String deviceFeature) {
110 locks[0].currentValue(deviceFeature)
113 def latestValue(String deviceFeature) {
114 locks[0].latestValue(deviceFeature)