X-Git-Url: http://plrg.eecs.uci.edu/git/?p=smartthings-infrastructure.git;a=blobdiff_plain;f=Extractor%2FExtractorScript.py;h=d495d0fa6b23ffbcd7d163a6fff57a870b44e103;hp=eb7fa99acd981613151cb2f299b0490496be2558;hb=c6d7cb10d039c15b8c0ba0e5ef8cd9abbf2cc3ae;hpb=7f8ab7f9e2833a5682d07a34701153dbe752461a diff --git a/Extractor/ExtractorScript.py b/Extractor/ExtractorScript.py index eb7fa99..d495d0f 100644 --- a/Extractor/ExtractorScript.py +++ b/Extractor/ExtractorScript.py @@ -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 @@ -260,10 +290,8 @@ def ExtractEvents(extractedEvents): extractedEvents.write(line) event.close() elif eventList[i] == "unlock": - event = open("eventSimulator/unlockEvent.groovy", "r") - for line in event: - extractedEvents.write(line) - event.close() + #Don't do anything for this case + counter = counter - 1 elif eventList[i] == "contact.open": event = open("eventSimulator/contactOpenEvent.groovy", "r") for line in event: @@ -368,8 +396,6 @@ def ExtractEvents(extractedEvents): event.close() elif eventList[i] == "doorState": #Write two events subsequently - extractedEvents.write("\t\t\tdef event = Verify.getInt(0,1)\n") - extractedEvents.write("\t\t\tif (event == 0) {\n") event = open("eventSimulator/doorOpenEvent.groovy", "r") for line in event: extractedEvents.write(line)