-////subscribe(obj, string, func, hashmap)
-def subscribe(Object Obj, String S, Closure Input, LinkedHashMap LHM) {
- ObjectList.add(Obj)
- EventList.add(S)
- FunctionList.add(Input)
-}
-/////////////////////////////////////////////////////////////////////
-def EventHandler() {
- while(true) {
- List evt = []
- print "Waiting for an event...\n"
- def EVENT = System.in.newReader().readLine()
- SepLine = EVENT.split()
- for (int i = 0; i < EventList.size(); i++) {
- if (EventList[i] == SepLine[0]) {
- println("The following effect: \n")
- evt.add(new Event())
- switch(SepLine[0]) {
- case "Touched":
- ObjectList[i].touched = 1
- evt[-1].value = "Touched"
- evt[-1].linkText = "touched by user"
- evt[-1].name = "TouchSensor"
- evt[-1].descriptionText = "Touching"
- break
- case "lock":
- if (SepLine[1] == "0") {
- ObjectList[i][0].lock()
- evt[-1].deviceId = 0
- evt[-1].value = "locked"
- evt[-1].linkText = "lock0"
- evt[-1].displayName = "lock0"
- evt[-1].name = "lock"
- evt[-1].descriptionText = "locking"
- } else if (SepLine[1] == "1") {
- ObjectList[i][1].lock()
- evt[-1].deviceId = 1
- evt[-1].value = "locked"
- evt[-1].linkText = "lock1"
- evt[-1].displayName = "lock1"
- evt[-1].name = "lock"
- evt[-1].descriptionText = "locking"
- } else if (SepLine[1] == "2") {
- ObjectList[i][2].lock()
- evt[-1].deviceId = 2
- evt[-1].value = "locked"
- evt[-1].linkText = "lock2"
- evt[-1].displayName = "lock2"
- evt[-1].name = "lock"
- evt[-1].descriptionText = "locking"
- }
- break
- case "unlock":
- if (SepLine[1] == "0") {
- ObjectList[i][0].unlock()
- evt[-1].deviceId = 0
- evt[-1].value = "unlocked"
- evt[-1].linkText = "lock0"
- evt[-1].displayName = "lock0"
- evt[-1].name = "lock"
- evt[-1].descriptionText = "unlocking"
- } else if (SepLine[1] == "1") {
- ObjectList[i][1].unlock()
- evt[-1].deviceId = 0
- evt[-1].value = "unlocked"
- evt[-1].linkText = "lock1"
- evt[-1].displayName = "lock1"
- evt[-1].name = "lock"
- evt[-1].descriptionText = "unlocking"
- } else if (SepLine[1] == "2") {
- ObjectList[i][2].unlock()
- evt[-1].deviceId = 2
- evt[-1].value = "unlocked"
- evt[-1].linkText = "lock2"
- evt[-1].displayName = "lock2"
- evt[-1].name = "lock"
- evt[-1].descriptionText = "unlocking"
- }
- break
- case "contact.open":
- if (SepLine[1] == "0") {
- ObjectList[i][0].contactLatestValue = ObjectList[i].currentContact
- ObjectList[i][0].currentContact = "open"
- evt[-1].deviceId = 0
- evt[-1].value = "contact.open"
- evt[-1].linkText = "contact0"
- evt[-1].displayName = "contact0"
- evt[-1].name = "ContactSensor"
- evt[-1].descriptionText = "opening"
- } else if (SepLine[1] == "1") {
- ObjectList[i][1].contactLatestValue = ObjectList[i].currentContact
- ObjectList[i][1].currentContact = "open"
- evt[-1].deviceId = 1
- evt[-1].value = "contact.open"
- evt[-1].linkText = "contact1"
- evt[-1].displayName = "contact1"
- evt[-1].name = "ContactSensor"
- evt[-1].descriptionText = "opening"
- } else if (SepLine[1] == "2") {
- ObjectList[i][2].contactLatestValue = ObjectList[i].currentContact
- ObjectList[i][2].currentContact = "open"
- evt[-1].deviceId = 2
- evt[-1].value = "contact.open"
- evt[-1].linkText = "contact2"
- evt[-1].displayName = "contact2"
- evt[-1].name = "ContactSensor"
- evt[-1].descriptionText = "opening"
- }
- break
- case "contact.closed":
- if (SepLine[1] == "0") {
- ObjectList[i][0].contactLatestValue = ObjectList[i].currentContact
- ObjectList[i][0].currentContact = "closed"
- evt[-1].deviceId = 0
- evt[-1].value = "contact.closed"
- evt[-1].linkText = "contact0"
- evt[-1].displayName = "contact0"
- evt[-1].name = "ContactSensor"
- evt[-1].descriptionText = "closing"
- } else if (SepLine[1] == "1") {
- ObjectList[i][1].contactLatestValue = ObjectList[i].currentContact
- ObjectList[i][1].currentContact = "closed"
- evt[-1].deviceId = 1
- evt[-1].value = "contact.closed"
- evt[-1].linkText = "contact1"
- evt[-1].displayName = "contact1"
- evt[-1].name = "ContactSensor"
- evt[-1].descriptionText = "closing"
- } else if (SepLine[1] == "2") {
- ObjectList[i][2].contactLatestValue = ObjectList[i].currentContact
- ObjectList[i][2].currentContact = "closed"
- evt[-1].deviceId = 2
- evt[-1].value = "contact.closed"
- evt[-1].linkText = "contact2"
- evt[-1].displayName = "contact2"
- evt[-1].name = "ContactSensor"
- evt[-1].descriptionText = "closing"
- }
- break
- default:
- break
- }
- FunctionList[i](evt[-1])
- }
- }
- }