- // Open a new file to write into
- String intface = _intface;
- FileWriter fw = new FileWriter(dir + "/" + intface + ".java");
- pw = new PrintWriter(new BufferedWriter(fw));
- // Pass in set of methods and get import classes
- List<String> methods = intDecl.getMethods();
- Set<String> importClasses = getImportClasses(methods);
- printImportStatements(importClasses);
- // Write interface header
- println("");
- println("public interface " + intface + " {");
- // Write methods
- for (String method : methods) {
-
- List<String> methParams = intDecl.getMethodParams(method);
- List<String> methPrmTypes = intDecl.getMethodParamTypes(method);
- print("public " + intDecl.getMethodType(method) + " " +
- intDecl.getMethodId(method) + "(");
- for (int i = 0; i < methParams.size(); i++) {
- // Check for params with driver class types and exchange it
- // with its remote interface
- String paramType = checkAndGetParamClass(methPrmTypes.get(i));
- print(paramType + " " + methParams.get(i));
- // Check if this is the last element (don't print a comma)
- if (i != methParams.size() - 1) {
- print(", ");
- }
- }
- println(");");
- }
- println("}");
- pw.close();
- System.out.println("IoTCompiler: Generated local interface " + intface + ".java...");
- }
-
-
- /**
- * generateCplusLocalInterface() writes the local interface to provide type-checking
- * <p>
- * It needs to rewrite and exchange USERDEFINED types in input parameters of stub
- * and original interfaces, e.g. exchange Camera and CameraWithVideoAndRecording.
- * The local interface has to be the input parameter for the stub and the stub
- * interface has to be the input parameter for the local class.
- */
- public void generateCplusLocalInterface(String _intface) throws IOException {
-
- // Create a new directory
- createDirectory(dir);
- // Open a new file to write into
- String intface = _intface;
- FileWriter fw = new FileWriter(dir + "/" + intface + ".hpp");
- pw = new PrintWriter(new BufferedWriter(fw));
- // Write file headers
- println("#include <iostream>");
- // Pass in set of methods and get import classes
- List<String> methods = intDecl.getMethods();
- Set<String> includeClasses = getIncludeClasses(methods);
- printIncludeStatements(includeClasses);
- println("");
- println("using namespace std;");
- println("");
- println("class " + intface);
- println("{");
- println("public:");
- // Write methods
- for (String method : methods) {
-
- List<String> methParams = intDecl.getMethodParams(method);
- List<String> methPrmTypes = intDecl.getMethodParamTypes(method);
- print("virtual " + convertType(intDecl.getMethodType(method)) + " " +
- intDecl.getMethodId(method) + "(");
- for (int i = 0; i < methParams.size(); i++) {
- // Check for params with driver class types and exchange it
- // with its remote interface
- String paramType = checkAndGetParamClass(methPrmTypes.get(i));
- paramType = checkAndGetCplusType(paramType);
- print(paramType + " " + methParams.get(i));
- // Check if this is the last element (don't print a comma)
- if (i != methParams.size() - 1) {
- print(", ");
- }
- }
- println(") = 0;");
- }
- print("}");
- println(";");
- pw.close();
- System.out.println("IoTCompiler: Generated local interface " + intface + ".hpp...");
- }
-
-
- /**
- * generateJavaInterfaces() generate stub interfaces based on the methods list in Java
- */
- public void generateJavaInterfaces() throws IOException {
-
- // Create a new directory
- createDirectories(dir, subdir);
- for (Map.Entry<String,Set<String>> intMeth : mapCapabMethods.entrySet()) {
-