Interleaving events.
authorrtrimana <rtrimana@uci.edu>
Sat, 3 Aug 2019 18:18:02 +0000 (11:18 -0700)
committerrtrimana <rtrimana@uci.edu>
Sat, 3 Aug 2019 18:18:02 +0000 (11:18 -0700)
Extractor/ExtractorScript.py

index eb7fa99..2c53c56 100644 (file)
@@ -2,6 +2,7 @@ import os
 readyToReturn = 0
 ToReturn = ""
 eventList = []
+eventAppList = [] # This list maps App1 or App2 to a specific event
 eventVarMap = {}
 eventVarCounterMap = {}
 capabilityMap = {}
@@ -103,6 +104,7 @@ def GetToken(f):
 
 def ExtractFunctions(F, appName):
        global eventList
+       global eventAppList
        global app1Subscribe
        global app2Subscribe
        Temp = GetToken(F)
@@ -154,11 +156,19 @@ def ExtractFunctions(F, appName):
                        if Temp == "app" or Temp == "location":
                                if Temp not in eventList:
                                        eventList.append(Temp)
+                                       if (appName == "App1"):
+                                               eventAppList.append("App1")
+                                       else:
+                                               eventAppList.append("App2")
                        elif Temp not in eventList or (variable in capabilityMap.keys() and capabilityMap[variable] not in capabilityList):
                                # We do not repeat the same capability twice
                                capability = capabilityMap[variable]
                                capabilityList.append(capability)
                                eventList.append(Temp)
+                               if (appName == "App1"):
+                                       eventAppList.append("App1")
+                               else:
+                                       eventAppList.append("App2")
                                if Temp in eventVarMap.keys():
                                        listOfEvents = eventVarMap[Temp]
                                        listOfEvents.append(variable)
@@ -235,6 +245,7 @@ def CountEvents():
 
 def ExtractEvents(extractedEvents):
        global eventList
+       global eventAppList
        global eventVarMap
        global capabilityMap
        global eventVarCounterMap
@@ -244,7 +255,26 @@ def ExtractEvents(extractedEvents):
        extractedEvents.write("\tdef eventNumber = Verify.getInt(0,%d)\n" % (numOfActualEvents - 1))
        extractedEvents.write("\tswitch(eventNumber) {\n")
        counter = 0
-       for i in range(len(eventList)):
+       indexApp1 = 0
+       indexApp2 = eventAppList.index("App2")
+       indexApp2Start = indexApp2
+       #print "DEBUG: App1: %d" % indexApp1
+       #print "DEBUG: App2: %d" % indexApp2
+       #print "DEBUG: eventList: %d" % len(eventList)
+       isApp1 = True
+       while counter < len(eventList):
+               # Interleave events from App1 and App2
+               if isApp1 is True:
+                       i = indexApp1
+                       indexApp1 = indexApp1 + 1
+                       if indexApp2 < len(eventList):
+                               isApp1 = False
+               else:
+                       i = indexApp2
+                       indexApp2 = indexApp2 + 1
+                       if indexApp1 < indexApp2Start:
+                               isApp1 = True
+               print "DEBUG: i: %d" % i
                extractedEvents.write("\t\tcase %d:\n" % counter)
                if eventList[i] == "lock":
                        #Write two events subsequently