From: amiraj Date: Tue, 9 Jul 2019 20:31:06 +0000 (-0700) Subject: Commit #7: eventHandler and event queue are unique between two apps now. (Similar... X-Git-Url: http://plrg.eecs.uci.edu/git/?p=smartthings-infrastructure.git;a=commitdiff_plain;h=2fe09aaa7c08a73e2a626ad12d012018340b72a9 Commit #7: eventHandler and event queue are unique between two apps now. (Similar to the samsung architecture for smartthings.) --- diff --git a/Extractor/extractedObjectsApp1.groovy b/Extractor/extractedObjectsApp1.groovy index c3e09ad..d205217 100644 --- a/Extractor/extractedObjectsApp1.groovy +++ b/Extractor/extractedObjectsApp1.groovy @@ -5,7 +5,7 @@ def contact //Global variable for number! def minutesLater = 1 //Global variable for number! -def secondsLater = 2 +def secondsLater = 1 //Global variable for recipients! def recipients = ['AJ'] //Global variable for phone number! diff --git a/Extractor/extractedObjectsApp2.groovy b/Extractor/extractedObjectsApp2.groovy index 4363a18..77277fe 100644 --- a/Extractor/extractedObjectsApp2.groovy +++ b/Extractor/extractedObjectsApp2.groovy @@ -7,7 +7,7 @@ def lock1 //Global variable for mode! def newMode = "away" //Global variable for number! -def waitfor = 10 +def waitfor = 1 //Global Object for functions in subscribe method! def installed = this.&installed //Global Object for functions in subscribe method! diff --git a/Extractor/outGlobal.groovy b/Extractor/outGlobal.groovy index b22c362..c1c0918 100644 --- a/Extractor/outGlobal.groovy +++ b/Extractor/outGlobal.groovy @@ -3,4 +3,4 @@ //Global Object for class contactSensor! @Field def contactObject = new Contacting(sendEvent, 1) //Global Object for class Switch! -@Field def switchObject = new Switching(sendEvent, 2) +@Field def switchObject = new Switching(sendEvent, 1) diff --git a/GlobalVariables/GlobalVariablesBothApps.groovy b/GlobalVariables/GlobalVariablesBothApps.groovy index dea126a..0c6751b 100644 --- a/GlobalVariables/GlobalVariablesBothApps.groovy +++ b/GlobalVariables/GlobalVariablesBothApps.groovy @@ -1,9 +1,10 @@ //Create a global variable for send event @Field def sendEvent = {eventDataMap -> - app1.eventHandler(eventDataMap) - app2.eventHandler(eventDataMap) + eventHandler(eventDataMap) } //Object for location @Field def locationObject = new LocationVar() //Object for touch @Field def appObject = new Touched(sendEvent, 0) +//Create a global list for events +@Field def evt = [] diff --git a/GlobalVariables/GlobalVariablesEachApp.groovy b/GlobalVariables/GlobalVariablesEachApp.groovy index 7d44e0c..2b6544c 100644 --- a/GlobalVariables/GlobalVariablesEachApp.groovy +++ b/GlobalVariables/GlobalVariablesEachApp.groovy @@ -14,5 +14,3 @@ def eventList = [] def timersFuncList = [] //Create a global list for timer schedulers def timersList = [] -//Create a global list for events -def evt = [] diff --git a/Methods/eventHandler.groovy b/Methods/eventHandler.groovy index eee7a25..5c8fc2d 100644 --- a/Methods/eventHandler.groovy +++ b/Methods/eventHandler.groovy @@ -9,9 +9,23 @@ def eventHandler(LinkedHashMap eventDataMap) { def isStateChange = eventDataMap["isStateChange"] def unit = eventDataMap["unit"] def data = eventDataMap["data"] - - for (int i = 0;i < eventList.size();i++) { - if (eventList[i] == name) { + def minSize + def smallest + + //make search efficient + if (app1.eventList.size() == app2.eventList.size()) { + minSize = app1.eventList.size() + smallest = "equal" + } else if (app1.eventList.size() < app2.eventList.size()) { + minSize = app1.eventList.size() + smallest = "app1" + } else { + minSize = app2.eventList.size() + smallest = "app2" + } + + for (int i = 0;i < minSize;i++) { + if (app1.eventList[i] == name) { evt.add(new Event()) evt[-1].value = value evt[-1].name = name @@ -23,7 +37,57 @@ def eventHandler(LinkedHashMap eventDataMap) { evt[-1].isStateChange = isStateChange evt[-1].unit = unit evt[-1].data = data - functionList[i](evt[-1]) + app1.functionList[i](evt[-1]) + } + if (app2.eventList[i] == name) { + evt.add(new Event()) + evt[-1].value = value + evt[-1].name = name + evt[-1].deviceId = deviceId + evt[-1].descriptionText = descriptionText + evt[-1].displayed = displayed + evt[-1].linkText = linkText + evt[-1].displayName = linkText + evt[-1].isStateChange = isStateChange + evt[-1].unit = unit + evt[-1].data = data + app2.functionList[i](evt[-1]) } } + + if (smallest == "app1") { + for (int i = minSize;i < app2.eventList.size();i++) { + if (app2.eventList[i] == name) { + evt.add(new Event()) + evt[-1].value = value + evt[-1].name = name + evt[-1].deviceId = deviceId + evt[-1].descriptionText = descriptionText + evt[-1].displayed = displayed + evt[-1].linkText = linkText + evt[-1].displayName = linkText + evt[-1].isStateChange = isStateChange + evt[-1].unit = unit + evt[-1].data = data + app2.functionList[i](evt[-1]) + } + } + } else if (smallest == "app2") { + for (int i = minSize;i < app1.eventList.size();i++) { + if (app1.eventList[i] == name) { + evt.add(new Event()) + evt[-1].value = value + evt[-1].name = name + evt[-1].deviceId = deviceId + evt[-1].descriptionText = descriptionText + evt[-1].displayed = displayed + evt[-1].linkText = linkText + evt[-1].displayName = linkText + evt[-1].isStateChange = isStateChange + evt[-1].unit = unit + evt[-1].data = data + app1.functionList[i](evt[-1]) + } + } + } } diff --git a/Runner.py b/Runner.py index 2d32581..0514c39 100644 --- a/Runner.py +++ b/Runner.py @@ -42,6 +42,10 @@ Out.write("import Location.Phrase\n") Out.write("import appTouch.Touched\n") Out.write("import Event.Event\n") Out.write("\n") +Out.write("//Global eventHandler\n") +for line in eventHandler: + Out.write(line) +Out.write("\n") Out.write("//GlobalVariables for both Apps\n") for line in GlobalVariablesBothApps: Out.write(line) @@ -84,8 +88,6 @@ for line in sendNotificationToContacts: Out.write("\t"+line) for line in sendSms: Out.write("\t"+line) -for line in eventHandler: - Out.write("\t"+line) Out.write("\n") Start = 0 for line in App1: @@ -145,8 +147,6 @@ for line in sendNotificationToContacts: Out.write("\t"+line) for line in sendSms: Out.write("\t"+line) -for line in eventHandler: - Out.write("\t"+line) Out.write("\n") Start = 0 for line in App2: diff --git a/bin/main/App1.class b/bin/main/App1.class new file mode 100644 index 0000000..796d062 Binary files /dev/null and b/bin/main/App1.class differ diff --git a/bin/main/App2.class b/bin/main/App2.class new file mode 100644 index 0000000..22dbf9b Binary files /dev/null and b/bin/main/App2.class differ diff --git a/bin/main/ContactSensor/Contacting.class b/bin/main/ContactSensor/Contacting.class new file mode 100644 index 0000000..5f5e0b1 Binary files /dev/null and b/bin/main/ContactSensor/Contacting.class differ diff --git a/bin/main/ContactSensor/Contacts.class b/bin/main/ContactSensor/Contacts.class new file mode 100644 index 0000000..51bed71 Binary files /dev/null and b/bin/main/ContactSensor/Contacts.class differ diff --git a/bin/main/Event/Event.class b/bin/main/Event/Event.class new file mode 100644 index 0000000..2f7f0e2 Binary files /dev/null and b/bin/main/Event/Event.class differ diff --git a/bin/main/Location/LocationVar.class b/bin/main/Location/LocationVar.class new file mode 100644 index 0000000..6b600fd Binary files /dev/null and b/bin/main/Location/LocationVar.class differ diff --git a/bin/main/Location/Phrase.class b/bin/main/Location/Phrase.class new file mode 100644 index 0000000..9c29d56 Binary files /dev/null and b/bin/main/Location/Phrase.class differ diff --git a/bin/main/Lock/Locking$_lock_closure1.class b/bin/main/Lock/Locking$_lock_closure1.class new file mode 100644 index 0000000..516079e Binary files /dev/null and b/bin/main/Lock/Locking$_lock_closure1.class differ diff --git a/bin/main/Lock/Locking$_unlock_closure2.class b/bin/main/Lock/Locking$_unlock_closure2.class new file mode 100644 index 0000000..90197ad Binary files /dev/null and b/bin/main/Lock/Locking$_unlock_closure2.class differ diff --git a/bin/main/Lock/Locking.class b/bin/main/Lock/Locking.class new file mode 100644 index 0000000..9e966cf Binary files /dev/null and b/bin/main/Lock/Locking.class differ diff --git a/bin/main/Lock/Locks$_lock_closure1.class b/bin/main/Lock/Locks$_lock_closure1.class new file mode 100644 index 0000000..ca70ed1 Binary files /dev/null and b/bin/main/Lock/Locks$_lock_closure1.class differ diff --git a/bin/main/Lock/Locks$_unlock_closure2.class b/bin/main/Lock/Locks$_unlock_closure2.class new file mode 100644 index 0000000..6a77013 Binary files /dev/null and b/bin/main/Lock/Locks$_unlock_closure2.class differ diff --git a/bin/main/Lock/Locks.class b/bin/main/Lock/Locks.class new file mode 100644 index 0000000..93aa14a Binary files /dev/null and b/bin/main/Lock/Locks.class differ diff --git a/bin/main/Logger/Logger.class b/bin/main/Logger/Logger.class new file mode 100644 index 0000000..492d200 Binary files /dev/null and b/bin/main/Logger/Logger.class differ diff --git a/bin/main/Switch/Switches$_off_closure2.class b/bin/main/Switch/Switches$_off_closure2.class new file mode 100644 index 0000000..973337d Binary files /dev/null and b/bin/main/Switch/Switches$_off_closure2.class differ diff --git a/bin/main/Switch/Switches$_on_closure1.class b/bin/main/Switch/Switches$_on_closure1.class new file mode 100644 index 0000000..cd4028c Binary files /dev/null and b/bin/main/Switch/Switches$_on_closure1.class differ diff --git a/bin/main/Switch/Switches.class b/bin/main/Switch/Switches.class new file mode 100644 index 0000000..d246380 Binary files /dev/null and b/bin/main/Switch/Switches.class differ diff --git a/bin/main/Switch/Switching$_off_closure2.class b/bin/main/Switch/Switching$_off_closure2.class new file mode 100644 index 0000000..7fdefd3 Binary files /dev/null and b/bin/main/Switch/Switching$_off_closure2.class differ diff --git a/bin/main/Switch/Switching$_on_closure1.class b/bin/main/Switch/Switching$_on_closure1.class new file mode 100644 index 0000000..29e4146 Binary files /dev/null and b/bin/main/Switch/Switching$_on_closure1.class differ diff --git a/bin/main/Switch/Switching.class b/bin/main/Switch/Switching.class new file mode 100644 index 0000000..60f69f8 Binary files /dev/null and b/bin/main/Switch/Switching.class differ diff --git a/bin/main/appTouch/Touched.class b/bin/main/appTouch/Touched.class new file mode 100644 index 0000000..563a7e4 Binary files /dev/null and b/bin/main/appTouch/Touched.class differ diff --git a/bin/main/main$_closure1.class b/bin/main/main$_closure1.class new file mode 100644 index 0000000..b5c9a14 Binary files /dev/null and b/bin/main/main$_closure1.class differ diff --git a/bin/main/main.class b/bin/main/main.class new file mode 100644 index 0000000..c1a6055 Binary files /dev/null and b/bin/main/main.class differ diff --git a/main.groovy b/main.groovy index 299e6e4..b08146d 100644 --- a/main.groovy +++ b/main.groovy @@ -15,16 +15,112 @@ import Location.Phrase import appTouch.Touched import Event.Event +//Global eventHandler +///////////////////////////////////////////////////////////////////// +def eventHandler(LinkedHashMap eventDataMap) { + def value = eventDataMap["value"] + def name = eventDataMap["name"] + def deviceId = eventDataMap["deviceId"] + def descriptionText = eventDataMap["descriptionText"] + def displayed = eventDataMap["displayed"] + def linkText = eventDataMap["linkText"] + def isStateChange = eventDataMap["isStateChange"] + def unit = eventDataMap["unit"] + def data = eventDataMap["data"] + def minSize + def smallest + + //make search efficient + if (app1.eventList.size() == app2.eventList.size()) { + minSize = app1.eventList.size() + smallest = "equal" + } else if (app1.eventList.size() < app2.eventList.size()) { + minSize = app1.eventList.size() + smallest = "app1" + } else { + minSize = app2.eventList.size() + smallest = "app2" + } + + for (int i = 0;i < minSize;i++) { + if (app1.eventList[i] == name) { + evt.add(new Event()) + evt[-1].value = value + evt[-1].name = name + evt[-1].deviceId = deviceId + evt[-1].descriptionText = descriptionText + evt[-1].displayed = displayed + evt[-1].linkText = linkText + evt[-1].displayName = linkText + evt[-1].isStateChange = isStateChange + evt[-1].unit = unit + evt[-1].data = data + app1.functionList[i](evt[-1]) + } + if (app2.eventList[i] == name) { + evt.add(new Event()) + evt[-1].value = value + evt[-1].name = name + evt[-1].deviceId = deviceId + evt[-1].descriptionText = descriptionText + evt[-1].displayed = displayed + evt[-1].linkText = linkText + evt[-1].displayName = linkText + evt[-1].isStateChange = isStateChange + evt[-1].unit = unit + evt[-1].data = data + app2.functionList[i](evt[-1]) + } + } + + if (smallest == "app1") { + for (int i = minSize;i < app2.eventList.size();i++) { + if (app2.eventList[i] == name) { + evt.add(new Event()) + evt[-1].value = value + evt[-1].name = name + evt[-1].deviceId = deviceId + evt[-1].descriptionText = descriptionText + evt[-1].displayed = displayed + evt[-1].linkText = linkText + evt[-1].displayName = linkText + evt[-1].isStateChange = isStateChange + evt[-1].unit = unit + evt[-1].data = data + app2.functionList[i](evt[-1]) + } + } + } else if (smallest == "app2") { + for (int i = minSize;i < app1.eventList.size();i++) { + if (app1.eventList[i] == name) { + evt.add(new Event()) + evt[-1].value = value + evt[-1].name = name + evt[-1].deviceId = deviceId + evt[-1].descriptionText = descriptionText + evt[-1].displayed = displayed + evt[-1].linkText = linkText + evt[-1].displayName = linkText + evt[-1].isStateChange = isStateChange + evt[-1].unit = unit + evt[-1].data = data + app1.functionList[i](evt[-1]) + } + } + } +} + //GlobalVariables for both Apps //Create a global variable for send event @Field def sendEvent = {eventDataMap -> - app1.eventHandler(eventDataMap) - app2.eventHandler(eventDataMap) + eventHandler(eventDataMap) } //Object for location @Field def locationObject = new LocationVar() //Object for touch @Field def appObject = new Touched(sendEvent, 0) +//Create a global list for events +@Field def evt = [] //Extracted global objects for both Apps //Global Object for class lock! @@ -32,7 +128,7 @@ import Event.Event //Global Object for class contactSensor! @Field def contactObject = new Contacting(sendEvent, 1) //Global Object for class Switch! -@Field def switchObject = new Switching(sendEvent, 2) +@Field def switchObject = new Switching(sendEvent, 1) //Application #1 class App1 { @@ -48,7 +144,7 @@ class App1 { //Global variable for number! def minutesLater = 1 //Global variable for number! - def secondsLater = 2 + def secondsLater = 1 //Global variable for recipients! def recipients = ['AJ'] //Global variable for phone number! @@ -90,8 +186,6 @@ class App1 { def timersFuncList = [] //Create a global list for timer schedulers def timersList = [] - //Create a global list for events - def evt = [] //Methods ///////////////////////////////////////////////////////////////////// @@ -150,35 +244,6 @@ class App1 { def sendSms(long phoneNumber, String text) { println("Sending \""+text+"\" to "+phoneNumber.toString()) } - ///////////////////////////////////////////////////////////////////// - def eventHandler(LinkedHashMap eventDataMap) { - def value = eventDataMap["value"] - def name = eventDataMap["name"] - def deviceId = eventDataMap["deviceId"] - def descriptionText = eventDataMap["descriptionText"] - def displayed = eventDataMap["displayed"] - def linkText = eventDataMap["linkText"] - def isStateChange = eventDataMap["isStateChange"] - def unit = eventDataMap["unit"] - def data = eventDataMap["data"] - - for (int i = 0;i < eventList.size();i++) { - if (eventList[i] == name) { - evt.add(new Event()) - evt[-1].value = value - evt[-1].name = name - evt[-1].deviceId = deviceId - evt[-1].descriptionText = descriptionText - evt[-1].displayed = displayed - evt[-1].linkText = linkText - evt[-1].displayName = linkText - evt[-1].isStateChange = isStateChange - evt[-1].unit = unit - evt[-1].data = data - functionList[i](evt[-1]) - } - } - } def installed(){ initialize() @@ -284,7 +349,7 @@ class App2 { //Global variable for mode! def newMode = "away" //Global variable for number! - def waitfor = 10 + def waitfor = 1 //Global Object for functions in subscribe method! def installed = this.&installed //Global Object for functions in subscribe method! @@ -317,8 +382,6 @@ class App2 { def timersFuncList = [] //Create a global list for timer schedulers def timersList = [] - //Create a global list for events - def evt = [] //Methods ///////////////////////////////////////////////////////////////////// @@ -377,35 +440,6 @@ class App2 { def sendSms(long phoneNumber, String text) { println("Sending \""+text+"\" to "+phoneNumber.toString()) } - ///////////////////////////////////////////////////////////////////// - def eventHandler(LinkedHashMap eventDataMap) { - def value = eventDataMap["value"] - def name = eventDataMap["name"] - def deviceId = eventDataMap["deviceId"] - def descriptionText = eventDataMap["descriptionText"] - def displayed = eventDataMap["displayed"] - def linkText = eventDataMap["linkText"] - def isStateChange = eventDataMap["isStateChange"] - def unit = eventDataMap["unit"] - def data = eventDataMap["data"] - - for (int i = 0;i < eventList.size();i++) { - if (eventList[i] == name) { - evt.add(new Event()) - evt[-1].value = value - evt[-1].name = name - evt[-1].deviceId = deviceId - evt[-1].descriptionText = descriptionText - evt[-1].displayed = displayed - evt[-1].linkText = linkText - evt[-1].displayName = linkText - evt[-1].isStateChange = isStateChange - evt[-1].unit = unit - evt[-1].data = data - functionList[i](evt[-1]) - } - } - } def installed() { @@ -443,3 +477,6 @@ class App2 { @Field def app2 = new App2(this) app1.installed() app2.installed() +appObject.setValue([name: "Touched", value: "Touched", deviceId: 0, descriptionText: "", + displayed: true, linkText: "", isStateChange: false, unit: "", data: []]) +