Adjusting setLocationMode for global-variable conflict detection.
authorrtrimana <rtrimana@uci.edu>
Thu, 8 Aug 2019 19:52:42 +0000 (12:52 -0700)
committerrtrimana <rtrimana@uci.edu>
Thu, 8 Aug 2019 19:52:42 +0000 (12:52 -0700)
Extractor/Extractor.groovy
Location/LocationVar.groovy
Methods/setLocationMode.groovy
Runner.py

index 16038e3b078f450b6f02b7e9b7d182de96ad8751..4607b7c89cd7916f2848fcbd776cd788fa792cec 100644 (file)
@@ -81,7 +81,7 @@ import Momentary.Momentaries
 import Timer.SimulatedTimer
 
 //GlobalVariables
 import Timer.SimulatedTimer
 
 //GlobalVariables
-@Field def location = new LocationVar()
+@Field def location = new LocationVar({}, true)
 //Settings variable defined to settings on purpose
 @Field def settings = [app: "app"]
 //Global variable for state[mode]
 //Settings variable defined to settings on purpose
 @Field def settings = [app: "app"]
 //Global variable for state[mode]
@@ -402,6 +402,8 @@ def input(LinkedHashMap metaData, String name, String type, Closure Input) {
        find(Input)
 }
 
        find(Input)
 }
 
+@Field chooseMode = 0
+
 //input linkedHashMap
 def input(LinkedHashMap metaData) {
        if (metaData.containsKey('title')) {
 //input linkedHashMap
 def input(LinkedHashMap metaData) {
        if (metaData.containsKey('title')) {
@@ -1639,7 +1641,13 @@ def input(LinkedHashMap metaData) {
                case "mode":
                        //def randomVariable = Math.abs(new Random().nextInt() % 3)
                        def modes = ["away", "home", "night"]
                case "mode":
                        //def randomVariable = Math.abs(new Random().nextInt() % 3)
                        def modes = ["away", "home", "night"]
-                       def userInput = modes[1]
+                       // Always assign a different mode to each app
+                       //def userInput = modes[1]
+                       def userInput = modes[chooseMode]
+                       if (chooseMode < 3)
+                               chooseMode++;
+                       else
+                               chooseMode = chooseMode%3
 
                        if (modeVariables == 0) {
                                mode0 = metaData['name']
 
                        if (modeVariables == 0) {
                                mode0 = metaData['name']
@@ -2105,7 +2113,7 @@ def preferences(Closure inputData) {
                GlobalVariablesBothApps.write("")
                GlobalVariablesBothApps.append("//Creating Global variables for both apps\n")
                GlobalVariablesBothApps.append("@Field def sendEvent = {eventDataMap -> eventHandler(eventDataMap)}\n")
                GlobalVariablesBothApps.write("")
                GlobalVariablesBothApps.append("//Creating Global variables for both apps\n")
                GlobalVariablesBothApps.append("@Field def sendEvent = {eventDataMap -> eventHandler(eventDataMap)}\n")
-               GlobalVariablesBothApps.append("@Field def locationObject = new LocationVar(sendEvent)\n")
+               GlobalVariablesBothApps.append("@Field def locationObject = new LocationVar(sendEvent, init)\n")
                GlobalVariablesBothApps.append("@Field def appObject = new Touched(sendEvent, 0)\n")
                
                globalObjects.withReader { reader ->
                GlobalVariablesBothApps.append("@Field def appObject = new Touched(sendEvent, 0)\n")
                
                globalObjects.withReader { reader ->
index 3f28a0bfbe2100dc105cb8968a0fb2238211af80..a114c1f019bf02ee1b8a29beacdf566e62a0b519 100644 (file)
@@ -15,18 +15,34 @@ class LocationVar {
        
        private Phrase helloHome
 
        
        private Phrase helloHome
 
-       LocationVar(Closure sendEvent) {
-               this.hubs = [[id:0, localIP:"128.195.204.105"]]
-               this.modes = [[name: "home"],[name: "away"],[name: "night"]]
-               this.mode = "home"
-               this.helloHome = new Phrase()
-               this.contactBookEnabled = 1
-               this.contacts = ['AJ']
-               this.phoneNumbers = [9495379373]
-               this.sendEvent = sendEvent
-               this.timeZone = TimeZone.getTimeZone("America/New_York")
-               this.name = "hub0"
-               this.temperatureScale = "F"
+       LocationVar(Closure sendEvent, boolean init) {
+       
+                       if (init) {
+                               this.hubs = [[id:0, localIP:"128.195.204.105"]]
+                               this.modes = [[name: "home"],[name: "away"],[name: "night"]]
+                               this.mode = "away"
+                               this.helloHome = new Phrase()
+                               this.contactBookEnabled = 1
+                               this.contacts = ['AJ']
+                               this.phoneNumbers = [9495379373]
+                               this.sendEvent = sendEvent
+                               this.timeZone = TimeZone.getTimeZone("America/New_York")
+                               this.name = "hub0"
+                               this.temperatureScale = "F"
+                       } else {
+                               this.hubs = [[id:0, localIP:"128.195.204.105"]]
+                               this.modes = [[name: "home"],[name: "away"],[name: "night"]]
+                               this.mode = "home"
+                               this.helloHome = new Phrase()
+                               this.contactBookEnabled = 1
+                               this.contacts = ['AJ']
+                               this.phoneNumbers = [9495379373]
+                               this.sendEvent = sendEvent
+                               this.timeZone = TimeZone.getTimeZone("America/New_York")
+                               this.name = "hub0"
+                               this.temperatureScale = "F"
+                       
+                       }
        }
 
        //By Model Checker
        }
 
        //By Model Checker
index aa7424bf19130ccb1c59b1b9502e85da011d27ab..12433ab5d15e08fefea8e4fde9c44dd5c2f95849 100644 (file)
@@ -1,8 +1,10 @@
 /////////////////////////////////////////////////////////////////////
 def setLocationMode(String mode) {
 /////////////////////////////////////////////////////////////////////
 def setLocationMode(String mode) {
+       log.debug "DEBUG: setLocationMode is called. Current mode is: ${location_mode} and new mode is: ${mode}"
        location.setValue([name: "Location", value: "$mode", deviceId: "locationID0", descriptionText: "",
                           displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
        location.setValue([name: "mode", value: "$mode", deviceId: "locationID0", descriptionText: "",
                           displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
        location.setValue([name: "Location", value: "$mode", deviceId: "locationID0", descriptionText: "",
                           displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
        location.setValue([name: "mode", value: "$mode", deviceId: "locationID0", descriptionText: "",
                           displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+       location_mode = mode
 }
 
 }
 
index ad8dff0f2b1822585889000a5eac41d034a27a1d..81efa7a0c02eaf42b82d09542635651ba4940dfe 100644 (file)
--- a/Runner.py
+++ b/Runner.py
@@ -142,6 +142,8 @@ Out.write("//Application #1\n")
 Out.write("class App1 {\n")
 Out.write("\tdef reference\n")
 Out.write("\tdef location\n")
 Out.write("class App1 {\n")
 Out.write("\tdef reference\n")
 Out.write("\tdef location\n")
+Out.write("\t// A local variable added for conflict detection tool\n")
+Out.write("\tdef location_mode\n")
 Out.write("\tdef app\n")
 Out.write("\n")
 Out.write("\t//Extracted objects for App1\n")
 Out.write("\tdef app\n")
 Out.write("\n")
 Out.write("\t//Extracted objects for App1\n")
@@ -251,6 +253,8 @@ Out.write("//Application #2\n")
 Out.write("class App2 {\n")
 Out.write("\tdef reference\n")
 Out.write("\tdef location\n")
 Out.write("class App2 {\n")
 Out.write("\tdef reference\n")
 Out.write("\tdef location\n")
+Out.write("\t// A local variable added for conflict detection tool\n")
+Out.write("\tdef location_mode\n")
 Out.write("\tdef app\n")
 Out.write("\n")
 Out.write("\t//Extracted objects for App2\n")
 Out.write("\tdef app\n")
 Out.write("\n")
 Out.write("\t//Extracted objects for App2\n")