Adjusting the compiler to generate stubs and skeletons with the correct package and...
authorrtrimana <rtrimana@uci.edu>
Tue, 3 Apr 2018 21:49:10 +0000 (14:49 -0700)
committerrtrimana <rtrimana@uci.edu>
Tue, 3 Apr 2018 21:49:10 +0000 (14:49 -0700)
iotjava/Makefile
iotjava/iotpolicy/IoTCompiler.java
iotjava/iotpolicy/tree/DeclarationHandler.java
localconfig/iotpolicy/BlossomSprinkler/blossomsprinkler.pol [new file with mode: 0644]
localconfig/iotpolicy/BlossomSprinkler/smartsprinkler.req [new file with mode: 0644]
localconfig/iotpolicy/DlinkAlarm/dlinkalarm.pol [new file with mode: 0644]
localconfig/iotpolicy/DlinkAlarm/smartalarm.req [new file with mode: 0644]
localconfig/iotpolicy/EspAlarm/espalarm.pol [deleted file]
localconfig/iotpolicy/EspAlarm/smartalarm.req [deleted file]
localconfig/iotpolicy/EspSprinkler/espsprinkler.pol [deleted file]
localconfig/iotpolicy/EspSprinkler/smartsprinkler.req [deleted file]

index a54c835eb4aaa2111faef5842cce42747168269d..ff1fac246848ff2663ecbc7cb898548d964f406d 100644 (file)
@@ -74,7 +74,7 @@ PHONY += run-compiler-lbtest
 run-compiler-lbtest:
        cp ../localconfig/iotpolicy/LifxLightBulb/*.pol $(BIN_DIR)/iotpolicy/
        cp ../localconfig/iotpolicy/LifxLightBulb/*.req $(BIN_DIR)/iotpolicy/
-       cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler lifxlightbulb.pol lifxtest.req -java Java
+       cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler -cont Lifxtest lifxlightbulb.pol lifxtest.req -drv LifxLightBulb -java Java
        #cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler lifxlightbulb.pol lifxtest.req -cplus Cplus
 
 # SmartLightsController
@@ -82,102 +82,118 @@ PHONY += run-compiler-smartlight
 run-compiler-smartlight:
        cp ../localconfig/iotpolicy/LifxLightBulb/*.pol $(BIN_DIR)/iotpolicy/
        cp ../localconfig/iotpolicy/LifxLightBulb/*.req $(BIN_DIR)/iotpolicy/
-       cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler lifxlightbulb.pol smartlightsbulb.req amcrestcamera.pol smartlightscam.req motiondetection.pol motiondetection.req room.pol roomsmart.req -java Java
+       cp ../localconfig/iotpolicy/AmcrestCamera/*.pol $(BIN_DIR)/iotpolicy/
+       cp ../localconfig/iotpolicy/AmcrestCamera/*.req $(BIN_DIR)/iotpolicy/
+       cp ../localconfig/iotpolicy/Room/*.pol $(BIN_DIR)/iotpolicy/
+       cp ../localconfig/iotpolicy/Room/*.req $(BIN_DIR)/iotpolicy/
+       cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler -cont SmartLightsController lifxlightbulb.pol smartlightsbulb.req -drv LifxLightBulb amcrestcamera.pol smartlightscam.req -drv AmcrestCamera motiondetection.pol motiondetection.req -drv AmcrestCamera room.pol roomsmart.req -drv LabRoom -java Java
 
 PHONY += run-compiler-lifx
 run-compiler-lifx:
        cp ../localconfig/iotpolicy/LifxLightBulb/*.pol $(BIN_DIR)/iotpolicy/
        cp ../localconfig/iotpolicy/LifxLightBulb/*.req $(BIN_DIR)/iotpolicy/
-       cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler lifxlightbulb.pol smartlightsbulb.req -java Java
+       cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler -cont SmartLightsController lifxlightbulb.pol smartlightsbulb.req -drv LifxLightBulb -java Java
        #cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler lifxlightbulb.pol smartlightsbulb.req -cplus C++
 
 PHONY += run-compiler-room
 run-compiler-room:
        cp ../localconfig/iotpolicy/Room/*.pol $(BIN_DIR)/iotpolicy/
        cp ../localconfig/iotpolicy/Room/*.req $(BIN_DIR)/iotpolicy/
-       cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler room.pol roomsmart.req -java Java
+       cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler -cont SmartLightsController room.pol roomsmart.req -drv LabRoom -java Java
        #cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler room.pol roomsmart.req -cplus C++
 
 PHONY += run-compiler-cam
 run-compiler-cam:
        cp ../localconfig/iotpolicy/AmcrestCamera/*.pol $(BIN_DIR)/iotpolicy/
        cp ../localconfig/iotpolicy/AmcrestCamera/*.req $(BIN_DIR)/iotpolicy/
-       cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler amcrestcamera.pol smartlightscam.req motiondetection.pol motiondetection.req -drv AmcrestCamera -cont SmartLightsController -java Java
+       cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler -cont SmartLightsController amcrestcamera.pol smartlightscam.req -drv AmcrestCamera motiondetection.pol motiondetection.req -drv AmcrestCamera -java Java
        #cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler
 
 # IrrigationController
 PHONY += run-compiler-irrigation
 run-compiler-irrigation:
-       cp ../localconfig/iotpolicy/LifxLightBulb/*.pol $(BIN_DIR)/iotpolicy/
-       cp ../localconfig/iotpolicy/LifxLightBulb/*.req $(BIN_DIR)/iotpolicy/
-       cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler greenlawn.pol smartlawn.req espsprinkler.pol smartsprinkler.req  weatherphonegateway.pol smartweathergateway.req weathergatewaycallback.pol smartweathergatewaycallback.req sprucesensor.pol smartsensor.req moisturesensorcallback.pol moisturesensorcallback.req -java Java
+       cp ../localconfig/iotpolicy/GreenLawn/*.pol $(BIN_DIR)/iotpolicy/
+       cp ../localconfig/iotpolicy/GreenLawn/*.req $(BIN_DIR)/iotpolicy/
+       cp ../localconfig/iotpolicy/BlossomSprinkler/*.pol $(BIN_DIR)/iotpolicy/
+       cp ../localconfig/iotpolicy/BlossomSprinkler/*.req $(BIN_DIR)/iotpolicy/
+       cp ../localconfig/iotpolicy/WeatherPhoneGateway/*.pol $(BIN_DIR)/iotpolicy/
+       cp ../localconfig/iotpolicy/WeatherPhoneGateway/*.req $(BIN_DIR)/iotpolicy/
+       cp ../localconfig/iotpolicy/SpruceSensor/*.pol $(BIN_DIR)/iotpolicy/
+       cp ../localconfig/iotpolicy/SpruceSensor/*.req $(BIN_DIR)/iotpolicy/
+       cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler -cont IrrigationController greenlawn.pol smartlawn.req -drv GreenLawn blossomsprinkler.pol smartsprinkler.req -drv BlossomSprinkler weatherphonegateway.pol smartweathergateway.req -drv WeatherPhoneGateway weathergatewaycallback.pol smartweathergatewaycallback.req -drv WeatherPhoneGateway sprucesensor.pol smartsensor.req -drv SpruceSensor moisturesensorcallback.pol moisturesensorcallback.req -drv SpruceSensor -java Java
 
 PHONY += run-compiler-lawn
 run-compiler-lawn:
        cp ../localconfig/iotpolicy/GreenLawn/*.pol $(BIN_DIR)/iotpolicy/
        cp ../localconfig/iotpolicy/GreenLawn/*.req $(BIN_DIR)/iotpolicy/
-       cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler greenlawn.pol smartlawn.req -java Java
+       cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler -cont IrrigationController greenlawn.pol smartlawn.req -drv GreenLawn -java Java
 
 PHONY += run-compiler-sprk
 run-compiler-sprk:
-       cp ../localconfig/iotpolicy/EspSprinkler/*.pol $(BIN_DIR)/iotpolicy/
-       cp ../localconfig/iotpolicy/EspSprinkler/*.req $(BIN_DIR)/iotpolicy/
-       cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler espsprinkler.pol smartsprinkler.req -java Java
+       cp ../localconfig/iotpolicy/BlossomSprinkler/*.pol $(BIN_DIR)/iotpolicy/
+       cp ../localconfig/iotpolicy/BlossomSprinkler/*.req $(BIN_DIR)/iotpolicy/
+       cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler -cont IrrigationController blossomsprinkler.pol smartsprinkler.req -drv BlossomSprinkler -java Java
 
 PHONY += run-compiler-wgw
 run-compiler-wgw:
        cp ../localconfig/iotpolicy/WeatherPhoneGateway/*.pol $(BIN_DIR)/iotpolicy/
        cp ../localconfig/iotpolicy/WeatherPhoneGateway/*.req $(BIN_DIR)/iotpolicy/
-       cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler weatherphonegateway.pol smartweathergateway.req weathergatewaycallback.pol smartweathergatewaycallback.req -java Java
+       cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler -cont IrrigationController weatherphonegateway.pol smartweathergateway.req -drv WeatherPhoneGateway weathergatewaycallback.pol smartweathergatewaycallback.req -drv WeatherPhoneGateway -java Java
 
 PHONY += run-compiler-moist
 run-compiler-moist:
        cp ../localconfig/iotpolicy/SpruceSensor/*.pol $(BIN_DIR)/iotpolicy/
        cp ../localconfig/iotpolicy/SpruceSensor/*.req $(BIN_DIR)/iotpolicy/
-       cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler sprucesensor.pol smartsensor.req moisturesensorcallback.pol moisturesensorcallback.req -java Java
+       cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler -cont IrrigationController sprucesensor.pol smartsensor.req -drv SpruceSensor moisturesensorcallback.pol moisturesensorcallback.req -drv SpruceSensor -java Java
 
 # SpeakerController
 PHONY += run-compiler-speaker
 run-compiler-speaker:
-       cp ../localconfig/iotpolicy/LifxLightBulb/*.pol $(BIN_DIR)/iotpolicy/
-       cp ../localconfig/iotpolicy/LifxLightBulb/*.req $(BIN_DIR)/iotpolicy/
-       cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler ihome.pol smartspeaker.req speakercallback.pol smartspeakercallback.req gpsphonegateway.pol smartgpsgateway.req gpsgatewaycallback.pol smartgpsgatewaycallback.req -java Java
+       cp ../localconfig/iotpolicy/IHome/*.pol $(BIN_DIR)/iotpolicy/
+       cp ../localconfig/iotpolicy/IHome/*.req $(BIN_DIR)/iotpolicy/
+       cp ../localconfig/iotpolicy/GPSPhoneGateway/*.pol $(BIN_DIR)/iotpolicy/
+       cp ../localconfig/iotpolicy/GPSPhoneGateway/*.req $(BIN_DIR)/iotpolicy/
+       cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler -cont SpeakerController ihome.pol smartspeaker.req -drv IHome speakercallback.pol smartspeakercallback.req -drv IHome gpsphonegateway.pol smartgpsgateway.req -drv GPSPhoneGateway gpsgatewaycallback.pol smartgpsgatewaycallback.req -drv GPSPhoneGateway -java Java
 
 PHONY += run-compiler-spkr
 run-compiler-spkr:
        cp ../localconfig/iotpolicy/IHome/*.pol $(BIN_DIR)/iotpolicy/
        cp ../localconfig/iotpolicy/IHome/*.req $(BIN_DIR)/iotpolicy/
-       cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler ihome.pol smartspeaker.req speakercallback.pol smartspeakercallback.req -java Java
+       cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler -cont SpeakerController ihome.pol smartspeaker.req -drv IHome speakercallback.pol smartspeakercallback.req -drv IHome -java Java
 
 PHONY += run-compiler-ggw
 run-compiler-ggw:
        cp ../localconfig/iotpolicy/GPSPhoneGateway/*.pol $(BIN_DIR)/iotpolicy/
        cp ../localconfig/iotpolicy/GPSPhoneGateway/*.req $(BIN_DIR)/iotpolicy/
-       cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler gpsphonegateway.pol smartgpsgateway.req gpsgatewaycallback.pol smartgpsgatewaycallback.req -java Java
+       cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler -drv GPSPhoneGateway gpsphonegateway.pol smartgpsgateway.req -drv GPSPhoneGateway gpsgatewaycallback.pol smartgpsgatewaycallback.req -drv GPSPhoneGateway -java Java
 
 # HomeSecurityController
 PHONY += run-compiler-homesec
 run-compiler-homesec:
-       cp ../localconfig/iotpolicy/LifxLightBulb/*.pol $(BIN_DIR)/iotpolicy/
-       cp ../localconfig/iotpolicy/LifxLightBulb/*.req $(BIN_DIR)/iotpolicy/
-       cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler espalarm.pol smartalarm.req smartthingssensor.pol smartthingssensor.req smartthingssensorcallback.pol smartthingssensorcallback.req -java Java
+       cp ../localconfig/iotpolicy/DlinkAlarm/*.pol $(BIN_DIR)/iotpolicy/
+       cp ../localconfig/iotpolicy/DlinkAlarm/*.req $(BIN_DIR)/iotpolicy/
+       cp ../localconfig/iotpolicy/SmartthingsSensor/*.pol $(BIN_DIR)/iotpolicy/
+       cp ../localconfig/iotpolicy/SmartthingsSensor/*.req $(BIN_DIR)/iotpolicy/
+       cp ../localconfig/iotpolicy/SmartthingsActuator/*.pol $(BIN_DIR)/iotpolicy/
+       cp ../localconfig/iotpolicy/SmartthingsActuator/*.req $(BIN_DIR)/iotpolicy/
+       cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler -cont HomeSecurityController dlinkalarm.pol smartalarm.req -drv DlinkAlarm smartthingssensor.pol smartthingssensor.req -drv MotionSensor smartthingssensorcallback.pol smartthingssensorcallback.req -drv MotionSensor smartthingssensor.pol smartthingssensor.req -drv MultipurposeSensor smartthingssensorcallback.pol smartthingssensorcallback.req -drv MultipurposeSensor smartthingssensor.pol smartthingssensor.req -drv WaterLeakSensor smartthingssensorcallback.pol smartthingssensorcallback.req -drv WaterLeakSensor -java Java
 
 PHONY += run-compiler-alarm
 run-compiler-alarm:
-       cp ../localconfig/iotpolicy/EspAlarm/*.pol $(BIN_DIR)/iotpolicy/
-       cp ../localconfig/iotpolicy/EspAlarm/*.req $(BIN_DIR)/iotpolicy/
-       cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler espalarm.pol smartalarm.req -java Java
+       cp ../localconfig/iotpolicy/DlinkAlarm/*.pol $(BIN_DIR)/iotpolicy/
+       cp ../localconfig/iotpolicy/DlinkAlarm/*.req $(BIN_DIR)/iotpolicy/
+       cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler -cont HomeSecurityController dlinkalarm.pol smartalarm.req -drv DlinkAlarm -java Java
 
 PHONY += run-compiler-smart
 run-compiler-smart:
        cp ../localconfig/iotpolicy/SmartthingsSensor/*.pol $(BIN_DIR)/iotpolicy/
        cp ../localconfig/iotpolicy/SmartthingsSensor/*.req $(BIN_DIR)/iotpolicy/
-       cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler smartthingssensor.pol smartthingssensor.req smartthingssensorcallback.pol smartthingssensorcallback.req -java Java
+       cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler -cont HomeSecurityController smartthingssensor.pol smartthingssensor.req -drv MotionSensor smartthingssensorcallback.pol smartthingssensorcallback.req -drv MotionSensor -java Java
 
 PHONY += run-compiler-actuate
 run-compiler-actuate:
        cp ../localconfig/iotpolicy/SmartthingsActuator/*.pol $(BIN_DIR)/iotpolicy/
        cp ../localconfig/iotpolicy/SmartthingsActuator/*.req $(BIN_DIR)/iotpolicy/
-       cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler smartthingsactuator.pol smartthingsactuator.req smartthingsactuatorcallback.pol smartthingsactuatorcallback.req -java Java
+       cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler -cont HomeSecurityController smartthingsactuator.pol smartthingsactuator.req -drv DoorlockActuator smartthingsactuatorcallback.pol smartthingsactuatorcallback.req -drv DoorlockActuator -java Java
 
 .PHONY: $(PHONY)
index a5825a9141d835f9b9cae0424bc342417dda5765..d3db3f82a18065164fdcd698390e8831d35118f9 100644 (file)
@@ -49,6 +49,7 @@ public class IoTCompiler {
        private Map<String,DeclarationHandler> mapIntDeclHand;
        private Map<String,Map<String,Set<String>>> mapInt2NewInts;
        private Map<String,String> mapInt2NewIntName;
+       private Map<String,String> mapInt2Drv;
        // Data structure to store our types (primitives and non-primitives) for compilation
        private Map<String,String> mapPrimitives;
        private Map<String,String> mapNonPrimitivesJava;
@@ -63,7 +64,6 @@ public class IoTCompiler {
        private static int portCount = 0;
        private static int countObjId = 1;                      // Always increment object Id for a new stub/skeleton
        private String mainClass;
-       private String driverClass;
        private String controllerClass;
 
 
@@ -94,6 +94,7 @@ public class IoTCompiler {
                mapIntDeclHand = new HashMap<String,DeclarationHandler>();
                mapInt2NewInts = new HashMap<String,Map<String,Set<String>>>();
                mapInt2NewIntName = new HashMap<String,String>();
+               mapInt2Drv = new HashMap<String,String>();
                mapIntfaceObjId = new HashMap<String,Integer>();
                mapNewIntfaceObjId = new HashMap<String,Integer>();
                mapPrimitives = new HashMap<String,String>();
@@ -107,7 +108,6 @@ public class IoTCompiler {
                dir = OUTPUT_DIRECTORY;
                subdir = null;
                mainClass = null;
-               driverClass = null;
                controllerClass = null;
        }
 
@@ -115,9 +115,17 @@ public class IoTCompiler {
        /**
         * setDriverClass() sets the name of the driver class.
         */
-       public void setDriverClass(String _driverClass) {
+       public void setDriverClass(String _driverClass, String _intface) {
                
-               driverClass = _driverClass;
+               mapInt2Drv.put(_driverClass, _intface);
+       }
+       
+       /**
+        * getDriverClass() sets the name of the driver class.
+        */
+       public String getDriverClass(String _intface) {
+               
+               return mapInt2Drv.get(_intface);
        }
 
 
@@ -1152,12 +1160,13 @@ public class IoTCompiler {
                                List<String> stdImportClasses = getStandardJavaImportClasses();
                                List<String> allImportClasses = getAllLibClasses(stdImportClasses, importClasses);
                                // Find out if there are callback objects
-                               Set<String> callbackClasses = getCallbackClasses(methods, intDecl);
+                               Set<String> callbackClasses = getCallbackClasses(methods, intDecl);                     
                                boolean callbackExist = !callbackClasses.isEmpty();
-                               if (callbackExist)
-                                       println("package " + controllerClass + ";\n");
+                               // Check if this interface is a callback class
+                               if(isCallbackClass(intface))
+                                       println("package " + CODE_PREFIX + "." + mapInt2Drv.get(intface) + ";\n");
                                else
-                                   println("package " + CODE_PREFIX + "." + driverClass + ";\n");
+                                       println("package " + controllerClass + ";\n");
                                printImportStatements(allImportClasses); 
                                println("\nimport " + INTERFACE_PACKAGE + ".*;\n");
                                // Write class header
@@ -2270,10 +2279,10 @@ public class IoTCompiler {
                        // Find out if there are callback objects
                        Set<String> callbackClasses = getCallbackClasses(methods, intDecl);
                        boolean callbackExist = !callbackClasses.isEmpty();
-                       if (callbackExist)
-                   println("package " + CODE_PREFIX + "." + driverClass + ";\n");
-               else
-                       println("package " + controllerClass + ";\n");
+                       if(isCallbackClass(intface))
+                               println("package " + controllerClass + ";\n");
+                       else
+                               println("package " + CODE_PREFIX + "." + mapInt2Drv.get(intface) + ";\n");
                        printImportStatements(allImportClasses);
                        println("\nimport " + INTERFACE_PACKAGE + ".*;\n");
                        // Write class header
@@ -4904,6 +4913,45 @@ public class IoTCompiler {
                }
                return callbackClasses;
        }
+       
+
+       // Check if this is a callback class
+       private boolean isCallbackClass(String className) {
+
+               Set<String> intfaceSet = mapIntDeclHand.keySet();
+               for(String intface : intfaceSet) {
+
+                       DeclarationHandler decHandler = mapIntDeclHand.get(intface);
+                       InterfaceDecl intDecl = (InterfaceDecl) decHandler.getInterfaceDecl(intface);
+                       Map<String,Set<String>> mapNewIntMethods = mapInt2NewInts.get(intface);
+                       for (Map.Entry<String,Set<String>> intMeth : mapNewIntMethods.entrySet()) {
+                               Set<String> methods = intMeth.getValue();
+                               for (String method : methods) {
+
+                                       List<String> methPrmTypes = intDecl.getMethodParamTypes(method);
+                                       List<String> methParams = intDecl.getMethodParams(method);
+                                       for (int i = 0; i < methPrmTypes.size(); i++) {
+
+                                               String type = methPrmTypes.get(i);
+                                               if (getParamCategory(type) == ParamCategory.USERDEFINED) {
+                                                       // Final check to see if this is the searched class
+                                                       if (type.equals(className))
+                                                               return true;
+                                               } else if (getParamCategory(type) == ParamCategory.NONPRIMITIVES) {
+                                               // Can be a List<...> of callback objects ...
+                                                       String genericType = getTypeOfGeneric(type)[0];
+                                                       if (getParamCategory(type) == ParamCategory.USERDEFINED) {
+                                                               if (type.equals(className))
+                                                                       return true;
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+               }
+
+               return false;
+       }
 
 
        // Print import statements into file
@@ -5219,43 +5267,36 @@ public class IoTCompiler {
 
                        IoTCompiler comp = new IoTCompiler();
                        int i = 0;
-                       boolean driverDefined = false;
+                       //boolean driverDefined = false;
                        boolean controllerDefined = false;
                        do {
-                           // Look for "-drv" and "-cont"
-                           // These two need to be defined to complete the stub/skeleton generation
-                           //  with the appropriate headers
-                               if (args[i].equals("-drv")) {
-                                       comp.setDriverClass(args[i+1]);
-                                       driverDefined = true;
-                               } else if (args[i].equals("-cont")) {
-                                       System.out.println("DEBUG: Controller: " + args[i+1]);
+                               if (!controllerDefined && args[i].equals("-cont")) {
                                        comp.setControllerClass(args[i+1]);
                                        controllerDefined = true;
-                               } else {
-                                   // Parse main policy file
-                                   ParseNode pnPol = IoTCompiler.parseFile(args[i]);
-                                   // Parse "requires" policy file
-                                   ParseNode pnReq = IoTCompiler.parseFile(args[i+1]);
-                                   // Get interface name
-                                   String intface = ParseTreeHandler.getOrigIntface(pnPol);
-                                   comp.setDataStructures(intface, pnPol, pnReq);
-                                   comp.getMethodsForIntface(intface);
+                                       i = i + 2;
                                }
+                           // Parse main policy file
+                           ParseNode pnPol = IoTCompiler.parseFile(args[i]);
+                           // Parse "requires" policy file
+                           ParseNode pnReq = IoTCompiler.parseFile(args[i+1]);
+                           // Get interface name
+                           String intface = ParseTreeHandler.getOrigIntface(pnPol);
+                           comp.setDataStructures(intface, pnPol, pnReq);
+                           comp.getMethodsForIntface(intface);
                                i = i + 2;
+                               if (args[i].equals("-drv")) {
+                                       comp.setDriverClass(intface, args[i+1]);
+                                       i = i + 2;
+                               } else
+                                       throw new Error("IoTCompiler: ERROR - driver class name is needed for the interface: " + intface + "\n");
                        // 1) Check if this is the last option before "-java" or "-cplus"
                        // 2) Check if this is really the last option
                        } while(!args[i].equals("-java") &&
                                        !args[i].equals("-cplus") &&
                                        (i < args.length));
-
-                       // Generate error if we haven't seen -drv and -cont at this point
-                       if (!driverDefined || !controllerDefined) {
-                               String error = "IoTCompiler: ERROR - please provide arguments -drv and -cont " +
-                                               "to specify both driver and controller class names.\n" +
-                                               "Note: The two options have to come before -java and -cplus.\n";
-                               throw new Error(error);
-                       }
+                       // Controller class name needs to be defined at least once
+                       if (!controllerDefined)
+                               throw new Error("IoTCompiler: ERROR - controller class name has not been specified!\n");
 
                        // Generate everything if we don't see "-java" or "-cplus"
                        if (i == args.length) {
@@ -5316,3 +5357,4 @@ public class IoTCompiler {
 }
 
 
+
index 48856cad3f95ad6553d8efbbbdc2a0049b540849..b67de7373def909a5ff048e491f22382fe04836f 100644 (file)
@@ -2,6 +2,7 @@ package iotpolicy.tree;
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Set;
 
 /** Abstract class Declaration is a parent class of InterfaceDecl,
  *  CapabilityDecl, and RequiresDecl
diff --git a/localconfig/iotpolicy/BlossomSprinkler/blossomsprinkler.pol b/localconfig/iotpolicy/BlossomSprinkler/blossomsprinkler.pol
new file mode 100644 (file)
index 0000000..e2c83b6
--- /dev/null
@@ -0,0 +1,29 @@
+public interface Sprinkler {
+
+       public void init();
+       public void setZone(int _zone, boolean _onOff, int _onDurationSeconds);
+       public List<ZoneState> getZoneStates();
+       public int getNumberOfZones();
+       public boolean doesHaveZoneTimers();
+
+       capability Initialize {
+               description = "Initialize object";
+               method = "init()";
+       }
+
+       capability Zone {
+               description = "Manage zones";
+               method = "setZone(int _zone, boolean _onOff, int _onDurationSeconds)";
+               method = "getZoneStates()";
+               method = "getNumberOfZones()";
+               method = "doesHaveZoneTimers()";
+       }
+
+       struct ZoneState {
+               int zoneNumber;
+               boolean onOffState;
+               int duration;
+       }
+}
+
+
diff --git a/localconfig/iotpolicy/BlossomSprinkler/smartsprinkler.req b/localconfig/iotpolicy/BlossomSprinkler/smartsprinkler.req
new file mode 100644 (file)
index 0000000..826f227
--- /dev/null
@@ -0,0 +1,3 @@
+
+requires Sprinkler with Initialize, Zone as interface SprinklerSmart;
+
diff --git a/localconfig/iotpolicy/DlinkAlarm/dlinkalarm.pol b/localconfig/iotpolicy/DlinkAlarm/dlinkalarm.pol
new file mode 100644 (file)
index 0000000..ce7742f
--- /dev/null
@@ -0,0 +1,29 @@
+public interface Alarm {
+
+       public void init();
+       public void setZone(int _zone, boolean _onOff, int _onDurationSeconds);
+       public List<ZoneState> getZoneStates();
+       public int getNumberOfZones();
+       public boolean doesHaveZoneTimers();
+
+       capability Initialize {
+               description = "Initialize object";
+               method = "init()";
+       }
+
+       capability Zone {
+               description = "Manage zones";
+               method = "setZone(int _zone, boolean _onOff, int _onDurationSeconds)";
+               method = "getZoneStates()";
+               method = "getNumberOfZones()";
+               method = "doesHaveZoneTimers()";
+       }
+
+       struct ZoneState {
+               int zoneNumber;
+               boolean onOffState;
+               int duration;
+       }
+}
+
+
diff --git a/localconfig/iotpolicy/DlinkAlarm/smartalarm.req b/localconfig/iotpolicy/DlinkAlarm/smartalarm.req
new file mode 100644 (file)
index 0000000..f703a43
--- /dev/null
@@ -0,0 +1,3 @@
+
+requires Alarm with Initialize, Zone as interface AlarmSmart;
+
diff --git a/localconfig/iotpolicy/EspAlarm/espalarm.pol b/localconfig/iotpolicy/EspAlarm/espalarm.pol
deleted file mode 100644 (file)
index ce7742f..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-public interface Alarm {
-
-       public void init();
-       public void setZone(int _zone, boolean _onOff, int _onDurationSeconds);
-       public List<ZoneState> getZoneStates();
-       public int getNumberOfZones();
-       public boolean doesHaveZoneTimers();
-
-       capability Initialize {
-               description = "Initialize object";
-               method = "init()";
-       }
-
-       capability Zone {
-               description = "Manage zones";
-               method = "setZone(int _zone, boolean _onOff, int _onDurationSeconds)";
-               method = "getZoneStates()";
-               method = "getNumberOfZones()";
-               method = "doesHaveZoneTimers()";
-       }
-
-       struct ZoneState {
-               int zoneNumber;
-               boolean onOffState;
-               int duration;
-       }
-}
-
-
diff --git a/localconfig/iotpolicy/EspAlarm/smartalarm.req b/localconfig/iotpolicy/EspAlarm/smartalarm.req
deleted file mode 100644 (file)
index f703a43..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-
-requires Alarm with Initialize, Zone as interface AlarmSmart;
-
diff --git a/localconfig/iotpolicy/EspSprinkler/espsprinkler.pol b/localconfig/iotpolicy/EspSprinkler/espsprinkler.pol
deleted file mode 100644 (file)
index e2c83b6..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-public interface Sprinkler {
-
-       public void init();
-       public void setZone(int _zone, boolean _onOff, int _onDurationSeconds);
-       public List<ZoneState> getZoneStates();
-       public int getNumberOfZones();
-       public boolean doesHaveZoneTimers();
-
-       capability Initialize {
-               description = "Initialize object";
-               method = "init()";
-       }
-
-       capability Zone {
-               description = "Manage zones";
-               method = "setZone(int _zone, boolean _onOff, int _onDurationSeconds)";
-               method = "getZoneStates()";
-               method = "getNumberOfZones()";
-               method = "doesHaveZoneTimers()";
-       }
-
-       struct ZoneState {
-               int zoneNumber;
-               boolean onOffState;
-               int duration;
-       }
-}
-
-
diff --git a/localconfig/iotpolicy/EspSprinkler/smartsprinkler.req b/localconfig/iotpolicy/EspSprinkler/smartsprinkler.req
deleted file mode 100644 (file)
index 826f227..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-
-requires Sprinkler with Initialize, Zone as interface SprinklerSmart;
-