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
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)
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;
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;
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>();
dir = OUTPUT_DIRECTORY;
subdir = null;
mainClass = null;
- driverClass = null;
controllerClass = null;
}
/**
* 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);
}
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
// 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
}
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
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) {
}
+
import java.util.HashMap;
import java.util.Map;
+import java.util.Set;
/** Abstract class Declaration is a parent class of InterfaceDecl,
* CapabilityDecl, and RequiresDecl
--- /dev/null
+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;
+ }
+}
+
+
--- /dev/null
+
+requires Sprinkler with Initialize, Zone as interface SprinklerSmart;
+
--- /dev/null
+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;
+ }
+}
+
+
--- /dev/null
+
+requires Alarm with Initialize, Zone as interface AlarmSmart;
+
+++ /dev/null
-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;
- }
-}
-
-
+++ /dev/null
-
-requires Alarm with Initialize, Zone as interface AlarmSmart;
-
+++ /dev/null
-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;
- }
-}
-
-
+++ /dev/null
-
-requires Sprinkler with Initialize, Zone as interface SprinklerSmart;
-