Added subscribers handling to generate the right events.
authorrtrimana <rtrimana@uci.edu>
Sat, 20 Jul 2019 23:47:06 +0000 (16:47 -0700)
committerrtrimana <rtrimana@uci.edu>
Sat, 20 Jul 2019 23:47:06 +0000 (16:47 -0700)
Extractor/ExtractorScript.py
eventSimulator/eventAppTouch.groovy [new file with mode: 0644]
eventSimulator/eventContactClosed.groovy [new file with mode: 0644]
eventSimulator/eventContactOpen.groovy [new file with mode: 0644]
eventSimulator/eventLocked.groovy [new file with mode: 0644]
eventSimulator/eventNfcTouch.groovy [new file with mode: 0644]
eventSimulator/eventUnlocked.groovy [new file with mode: 0644]

index 1588235..40fa93d 100644 (file)
@@ -1,6 +1,7 @@
 import os
 readyToReturn = 0
 ToReturn = ""
+eventMap = []
 
 def GetToken(f):
        global readyToReturn
@@ -33,6 +34,7 @@ def GetToken(f):
                        return "EOF"
 
 def ExtractFunctions(F, appName):
+       global eventMap
        Temp = GetToken(F)
        while (Temp != "EOF"):
                if (Temp == "def" or Temp == "private"):
@@ -47,10 +49,64 @@ def ExtractFunctions(F, appName):
                                        extractedFunctionsApp2.write("//Global Object for functions in subscribe method!\n")    
                                        extractedFunctionsApp2.write("def %s = this.&" % NameofFunc)
                                        extractedFunctionsApp2.write("%s\n" % NameofFunc)
+
+               if (Temp == "subscribe"):
+                       counter = 0
+                       while (counter < 5 and Temp != "\""):
+                               Temp = GetToken(F)
+                               counter = counter + 1
+                       Temp = GetToken(F)
+                       #If counter >= 5 that means it is not found, so it must be appTouch
+                       if (counter >= 5):
+                               Temp = "appTouch"
+                       eventMap.append(Temp)
                Temp = GetToken(F)
                
-
-
+def ExtractEvents(extractedEvents):
+       global eventMap
+       extractedEvents.write("Random random = new Random(42)\n")
+       extractedEvents.write("counter = 1000\n")
+       extractedEvents.write("while(counter > 0) {\n")
+       extractedEvents.write("\tdef eventNumber = random.nextInt(%d)\n" % (len(eventMap) - 1))
+       extractedEvents.write("\tswitch(eventNumber) {\n")
+       for i in range(len(eventMap)):
+               extractedEvents.write("\t\tcase %d:\n" % i)
+               if eventMap[i] == "lock":
+                       event = open("eventSimulator/eventLocked.groovy", "r")
+                       for line in event:
+                               extractedEvents.write(line)
+                       event.close()
+               elif eventMap[i] == "unlock":
+                       event = open("eventSimulator/eventUnlocked.groovy", "r")
+                       for line in event:
+                               extractedEvents.write(line)
+                       event.close()
+               elif eventMap[i] == "contact.open":
+                       event = open("eventSimulator/eventContactOpen.groovy", "r")
+                       for line in event:
+                               extractedEvents.write(line)
+                       event.close()
+               elif eventMap[i] == "contact.closed":
+                       event = open("eventSimulator/eventContactClosed.groovy", "r")
+                       for line in event:
+                               extractedEvents.write(line)
+                       event.close()
+               elif eventMap[i] == "nfcTouch":
+                       event = open("eventSimulator/eventNfcTouch.groovy", "r")
+                       for line in event:
+                               extractedEvents.write(line)
+                       event.close()
+               elif eventMap[i] == "appTouch":
+                       event = open("eventSimulator/eventAppTouch.groovy", "r")
+                       for line in event:
+                               extractedEvents.write(line)
+                       event.close()
+               ###TODO: Add more events later
+               extractedEvents.write("\n\t\t\tbreak\n")
+       extractedEvents.write("\t}\n")
+       extractedEvents.write("\tcounter--\n")
+       extractedEvents.write("}\n")
+               
 #Extract objects to call functions from App1
 F1 = open("Extractor/App1/App1.groovy", "r")
 extractedFunctionsApp1 = open("Extractor/App1/extractedFunctionsApp1.groovy", "w+")
@@ -63,6 +119,10 @@ extractedFunctionsApp2 = open("Extractor/App2/extractedFunctionsApp2.groovy", "w
 ExtractFunctions(F2, "App2")
 F2.close()
 
+#Prepare eventSimulator file while parsing the App1 and App2 files
+extractedEvents = open("eventSimulator/eventSimulator.groovy", "w+")
+ExtractEvents(extractedEvents)
+extractedEvents.close()
 
 #Save the extracted methods and app1 in a same file to extract information
 extractorFile = open("Extractor/extractorFile.groovy", "w+")
diff --git a/eventSimulator/eventAppTouch.groovy b/eventSimulator/eventAppTouch.groovy
new file mode 100644 (file)
index 0000000..15589c3
--- /dev/null
@@ -0,0 +1,2 @@
+      appObject.setValue([name: "Touched", value: "Touched", deviceId: 0, descriptionText: "",
+                                       displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
\ No newline at end of file
diff --git a/eventSimulator/eventContactClosed.groovy b/eventSimulator/eventContactClosed.groovy
new file mode 100644 (file)
index 0000000..8f5e73c
--- /dev/null
@@ -0,0 +1,2 @@
+      contactObject.setValue([name: "contact0", value: "closed", deviceId: 0, descriptionText: "",
+                                       displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
\ No newline at end of file
diff --git a/eventSimulator/eventContactOpen.groovy b/eventSimulator/eventContactOpen.groovy
new file mode 100644 (file)
index 0000000..6aa2110
--- /dev/null
@@ -0,0 +1,2 @@
+                       contactObject.setValue([name: "contact0", value: "open", deviceId: 0, descriptionText: "",
+                                       displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
\ No newline at end of file
diff --git a/eventSimulator/eventLocked.groovy b/eventSimulator/eventLocked.groovy
new file mode 100644 (file)
index 0000000..c58dd0c
--- /dev/null
@@ -0,0 +1,2 @@
+                       lockObject.setValue([name: "lock0", value: "locked", deviceId: 0, descriptionText: "",
+                                       displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
\ No newline at end of file
diff --git a/eventSimulator/eventNfcTouch.groovy b/eventSimulator/eventNfcTouch.groovy
new file mode 100644 (file)
index 0000000..cd05147
--- /dev/null
@@ -0,0 +1,2 @@
+      appObject.setValue([name: "NfcTouch", value: "NfcTouch", deviceId: 0, descriptionText: "",
+                                       displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
\ No newline at end of file
diff --git a/eventSimulator/eventUnlocked.groovy b/eventSimulator/eventUnlocked.groovy
new file mode 100644 (file)
index 0000000..56dfdbc
--- /dev/null
@@ -0,0 +1,2 @@
+                       lockObject.setValue([name: "lock0", value: "unlocked", deviceId: 0, descriptionText: "",
+                                       displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
\ No newline at end of file