Map<String,Set<String>> mapNewIntMethods = mapInt2NewInts.get(intface);
for (Map.Entry<String,Set<String>> intMeth : mapNewIntMethods.entrySet()) {
String newIntface = intMeth.getKey();
- int newObjectId = mapNewIntfaceObjId.get(newIntface);
+ int newObjectId = getNewIntfaceObjectId(newIntface);
println("private final static int object" + newObjectId + "Id = " +
newObjectId + ";\t//" + newIntface);
Set<String> methodIds = intMeth.getValue();
Map<String,Set<String>> mapNewIntMethods = mapInt2NewInts.get(intface);
for (Map.Entry<String,Set<String>> intMeth : mapNewIntMethods.entrySet()) {
String newIntface = intMeth.getKey();
- int newObjectId = mapNewIntfaceObjId.get(newIntface);
+ int newObjectId = getNewIntfaceObjectId(newIntface);
println("set" + newObjectId + "Allowed = Arrays.asList(object" + newObjectId +"Permission);");
}
}
Map<String,Set<String>> mapNewIntMethods = mapInt2NewInts.get(intface);
for (Map.Entry<String,Set<String>> intMeth : mapNewIntMethods.entrySet()) {
String newIntface = intMeth.getKey();
- int newObjectId = mapNewIntfaceObjId.get(newIntface);
+ int newObjectId = getNewIntfaceObjectId(newIntface);
println("if (!set" + newObjectId + "Allowed.contains(methodId)) {");
println("throw new Error(\"Callback object for " + intface + " is not allowed to access method: \" + methodId);");
println("}");
Map<String,Set<String>> mapNewIntMethods = mapInt2NewInts.get(intface);
for (Map.Entry<String,Set<String>> intMeth : mapNewIntMethods.entrySet()) {
String newIntface = intMeth.getKey();
- int newObjectId = mapNewIntfaceObjId.get(newIntface);
+ int newObjectId = getNewIntfaceObjectId(newIntface);
println("if (_objectId == object" + newObjectId + "Id) {");
println("if (!set" + newObjectId + "Allowed.contains(methodId)) {");
println("throw new Error(\"Object with object Id: \" + _objectId + \" is not allowed to access method: \" + methodId);");
Map<String,Set<String>> mapNewIntMethods = mapInt2NewInts.get(intface);
for (Map.Entry<String,Set<String>> intMeth : mapNewIntMethods.entrySet()) {
String newIntface = intMeth.getKey();
- int newObjectId = mapNewIntfaceObjId.get(newIntface);
+ int newObjectId = getNewIntfaceObjectId(newIntface);
println("const static int object" + newObjectId + "Id = " + newObjectId + ";");
println("const static set<int> set" + newObjectId + "Allowed;");
}
Map<String,Set<String>> mapNewIntMethods = mapInt2NewInts.get(intface);
for (Map.Entry<String,Set<String>> intMeth : mapNewIntMethods.entrySet()) {
String newIntface = intMeth.getKey();
- int newObjectId = mapNewIntfaceObjId.get(newIntface);
+ int newObjectId = getNewIntfaceObjectId(newIntface);
println("if (set" + newObjectId + "Allowed.find(methodId) == set" + newObjectId + "Allowed.end()) {");
println("cerr << \"Callback object for " + intface + " is not allowed to access method: \" << methodId;");
println("exit(-1);");
Map<String,Set<String>> mapNewIntMethods = mapInt2NewInts.get(intface);
for (Map.Entry<String,Set<String>> intMeth : mapNewIntMethods.entrySet()) {
String newIntface = intMeth.getKey();
- int newObjectId = mapNewIntfaceObjId.get(newIntface);
+ int newObjectId = getNewIntfaceObjectId(newIntface);
print("const set<int> " + newSkelClass + "::set" + newObjectId + "Allowed {");
Set<String> methodIds = intMeth.getValue();
int i = 0;
Map<String,Set<String>> mapNewIntMethods = mapInt2NewInts.get(intface);
for (Map.Entry<String,Set<String>> intMeth : mapNewIntMethods.entrySet()) {
String newIntface = intMeth.getKey();
- int newObjectId = mapNewIntfaceObjId.get(newIntface);
+ int newObjectId = getNewIntfaceObjectId(newIntface);
println("if (_objectId == object" + newObjectId + "Id) {");
println("if (set" + newObjectId + "Allowed.find(methodId) == set" + newObjectId + "Allowed.end()) {");
println("cerr << \"Object with object Id: \" << _objectId << \" is not allowed to access method: \" << methodId << endl;");
pn = (ParseNode) parse.parse().value;
} catch (Exception e) {
e.printStackTrace();
- throw new Error("IoTCompiler: ERROR parsing policy file or wrong command line option: " + file);
+ throw new Error("IoTCompiler: ERROR parsing policy file or wrong command line option: " + file + "\n");
}
return pn;
}
+ // Check and find object Id for new interface in mapNewIntfaceObjId (callbacks)
+ // Throw an error if the new interface is not found!
+ // Basically the compiler needs to parse the policy (and requires) files for callback class first
+ private int getNewIntfaceObjectId(String newIntface) {
+
+ if (!mapNewIntfaceObjId.containsKey(newIntface)) {
+ throw new Error("IoTCompiler: Need to parse policy and requires files for callback class first! " +
+ "Please place the two files for callback class in front...\n");
+ } else {
+ int retObjId = mapNewIntfaceObjId.get(newIntface);
+ return retObjId;
+ }
+ }
+
+
// Return parameter category, i.e. PRIMITIVES, NONPRIMITIVES, USERDEFINED, ENUM, or STRUCT
private ParamCategory getParamCategory(String paramType) {
} else {
throw new Error("IoTCompiler: Ambiguous stub interfaces: " + setExchInt.toString() +
". Only one new interface can be declared if the object " + intface +
- " needs to be passed in as an input parameter!");
+ " needs to be passed in as an input parameter!\n");
}
} else {
// NULL value - this means policy files missing
" If this is an array please type the brackets after the variable name," +
" e.g. \"String str[]\", not \"String[] str\"." +
" If this is a Collections (Java) / STL (C++) type, this compiler only" +
- " supports List/ArrayList (Java) or list (C++).");
+ " supports List/ArrayList (Java) or list (C++).\n");
}
}
// Error checking
if (!args[i].equals("-java") &&
!args[i].equals("-cplus")) {
- throw new Error("IoTCompiler: ERROR - unrecognized command line option: " + args[i]);
+ throw new Error("IoTCompiler: ERROR - unrecognized command line option: " + args[i] + "\n");
} else {
if (i + 1 < args.length) {
comp.setDirectory(args[i+1]);
} else
- throw new Error("IoTCompiler: ERROR - please provide <directory> after option: " + args[i]);
+ throw new Error("IoTCompiler: ERROR - please provide <directory> after option: " + args[i] + "\n");
if (args[i].equals("-java")) {
comp.generateEnumJava();
} else {
// Need to at least have exactly 2 parameters, i.e. main policy file and requires file
IoTCompiler.printUsage();
- throw new Error("IoTCompiler: At least two arguments (main and requires policy files) have to be provided!");
+ throw new Error("IoTCompiler: At least two arguments (main and requires policy files) have to be provided!\n");
}
}
}