From 0db14366630e4a3c160486aa75467ba79defae29 Mon Sep 17 00:00:00 2001 From: rtrimana Date: Tue, 3 Apr 2018 14:49:10 -0700 Subject: [PATCH] Adjusting the compiler to generate stubs and skeletons with the correct package and import class names. --- iotjava/Makefile | 70 +++++++---- iotjava/iotpolicy/IoTCompiler.java | 118 ++++++++++++------ .../iotpolicy/tree/DeclarationHandler.java | 1 + .../blossomsprinkler.pol} | 0 .../smartsprinkler.req | 0 .../dlinkalarm.pol} | 0 .../{EspAlarm => DlinkAlarm}/smartalarm.req | 0 7 files changed, 124 insertions(+), 65 deletions(-) rename localconfig/iotpolicy/{EspSprinkler/espsprinkler.pol => BlossomSprinkler/blossomsprinkler.pol} (100%) rename localconfig/iotpolicy/{EspSprinkler => BlossomSprinkler}/smartsprinkler.req (100%) rename localconfig/iotpolicy/{EspAlarm/espalarm.pol => DlinkAlarm/dlinkalarm.pol} (100%) rename localconfig/iotpolicy/{EspAlarm => DlinkAlarm}/smartalarm.req (100%) diff --git a/iotjava/Makefile b/iotjava/Makefile index a54c835..ff1fac2 100644 --- a/iotjava/Makefile +++ b/iotjava/Makefile @@ -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) diff --git a/iotjava/iotpolicy/IoTCompiler.java b/iotjava/iotpolicy/IoTCompiler.java index a5825a9..d3db3f8 100644 --- a/iotjava/iotpolicy/IoTCompiler.java +++ b/iotjava/iotpolicy/IoTCompiler.java @@ -49,6 +49,7 @@ public class IoTCompiler { private Map mapIntDeclHand; private Map>> mapInt2NewInts; private Map mapInt2NewIntName; + private Map mapInt2Drv; // Data structure to store our types (primitives and non-primitives) for compilation private Map mapPrimitives; private Map 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(); mapInt2NewInts = new HashMap>>(); mapInt2NewIntName = new HashMap(); + mapInt2Drv = new HashMap(); mapIntfaceObjId = new HashMap(); mapNewIntfaceObjId = new HashMap(); mapPrimitives = new HashMap(); @@ -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 stdImportClasses = getStandardJavaImportClasses(); List allImportClasses = getAllLibClasses(stdImportClasses, importClasses); // Find out if there are callback objects - Set callbackClasses = getCallbackClasses(methods, intDecl); + Set 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 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 intfaceSet = mapIntDeclHand.keySet(); + for(String intface : intfaceSet) { + + DeclarationHandler decHandler = mapIntDeclHand.get(intface); + InterfaceDecl intDecl = (InterfaceDecl) decHandler.getInterfaceDecl(intface); + Map> mapNewIntMethods = mapInt2NewInts.get(intface); + for (Map.Entry> intMeth : mapNewIntMethods.entrySet()) { + Set methods = intMeth.getValue(); + for (String method : methods) { + + List methPrmTypes = intDecl.getMethodParamTypes(method); + List 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 { } + diff --git a/iotjava/iotpolicy/tree/DeclarationHandler.java b/iotjava/iotpolicy/tree/DeclarationHandler.java index 48856ca..b67de73 100644 --- a/iotjava/iotpolicy/tree/DeclarationHandler.java +++ b/iotjava/iotpolicy/tree/DeclarationHandler.java @@ -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/EspSprinkler/espsprinkler.pol b/localconfig/iotpolicy/BlossomSprinkler/blossomsprinkler.pol similarity index 100% rename from localconfig/iotpolicy/EspSprinkler/espsprinkler.pol rename to localconfig/iotpolicy/BlossomSprinkler/blossomsprinkler.pol diff --git a/localconfig/iotpolicy/EspSprinkler/smartsprinkler.req b/localconfig/iotpolicy/BlossomSprinkler/smartsprinkler.req similarity index 100% rename from localconfig/iotpolicy/EspSprinkler/smartsprinkler.req rename to localconfig/iotpolicy/BlossomSprinkler/smartsprinkler.req diff --git a/localconfig/iotpolicy/EspAlarm/espalarm.pol b/localconfig/iotpolicy/DlinkAlarm/dlinkalarm.pol similarity index 100% rename from localconfig/iotpolicy/EspAlarm/espalarm.pol rename to localconfig/iotpolicy/DlinkAlarm/dlinkalarm.pol diff --git a/localconfig/iotpolicy/EspAlarm/smartalarm.req b/localconfig/iotpolicy/DlinkAlarm/smartalarm.req similarity index 100% rename from localconfig/iotpolicy/EspAlarm/smartalarm.req rename to localconfig/iotpolicy/DlinkAlarm/smartalarm.req -- 2.34.1