Adding exception generation when there is a Direct-Direct interaction case.
[smartthings-infrastructure.git] / Extractor / ExtractorScript.py
index 11486bc7301702d1bc5b901f27af3cd275d015e6..65c5cd75c40e302c044d005d1d7cc24d49af58ad 100644 (file)
@@ -4,6 +4,8 @@ ToReturn = ""
 eventMap = []
 app1Capabilities = []
 app2Capabilities = []
+app1Subscribe = False
+app2Subscribe = False
 
 def GetToken(f):
        global readyToReturn
@@ -37,6 +39,8 @@ def GetToken(f):
 
 def ExtractFunctions(F, appName):
        global eventMap
+       global app1Subscribe
+       global app2Subscribe
        Temp = GetToken(F)
        while (Temp != "EOF"):
                if (Temp == "def" or Temp == "private"):
@@ -54,6 +58,10 @@ def ExtractFunctions(F, appName):
                
                #Check subscribed events
                if (Temp == "subscribe"):
+                       if (appName == "App1"):
+                               app1Subscribe = True
+                       else:
+                               app2Subscribe = True
                        while (Temp != "\"" and Temp != "app" and Temp != "location"):
                                Temp = GetToken(F)
                        if Temp == "\"":
@@ -111,8 +119,7 @@ def AnalyzePhysicalInteraction(app1Capab, app2Capab):
 
 def ExtractEvents(extractedEvents):
        global eventMap
-       #extractedEvents.write("while(true) {\n")
-       extractedEvents.write("for(int i=0; i<100; i++) {\n")
+       extractedEvents.write("while(true) {\n")
        extractedEvents.write("\tdef eventNumber = Verify.getInt(0,%d)\n" % (len(eventMap) - 1))
        extractedEvents.write("\tswitch(eventNumber) {\n")
        for i in range(len(eventMap)):
@@ -314,6 +321,16 @@ def ExtractEvents(extractedEvents):
        extractedEvents.write("\t}\n")
        #extractedEvents.write("\tcounter--\n")
        extractedEvents.write("}\n")
+       
+def CheckIfOnlyTouchEvents():
+       #Check and throw an error if it is all touch events
+       #This is called Direct-Direct interaction and we do not model-check for this case
+       onlyTouchEvents = True
+       for item in eventMap:
+               if item != "nfcTouch" and item != "app":
+                       onlyTouchEvents = False
+       if onlyTouchEvents is True and app1Subscribe is True and app2Subscribe is True:
+               raise Exception("\n\nDirect-Direct Interaction detected: we are skipping this pair...\n\n")
                
 #Extract objects to call functions from App1
 F1 = open("Extractor/App1/App1.groovy", "r")
@@ -329,6 +346,7 @@ F2.close()
 
 #Prepare eventSimulator file while parsing the App1 and App2 files
 extractedEvents = open("eventSimulator/eventSimulator.groovy", "w+")
+CheckIfOnlyTouchEvents()
 ExtractEvents(extractedEvents)
 extractedEvents.close()