println(intface + "_CallbackSkeleton skel = (" + intface + "_CallbackSkeleton) listCallbackObj.get(objId);");
println("if (skel != null) {");
println("skel.invokeMethod(rmiObj);");
- println("} else {");
+ print("}");
+ println(" else {");
println("throw new Error(\"" + intface + ": Object with Id \" + objId + \" not found!\");");
println("}");
println("}");
- println("} catch (Exception ex) {");
+ print("}");
+ println(" catch (Exception ex) {");
println("ex.printStackTrace();");
println("throw new Error(\"Error instantiating class " + intface + "_CallbackSkeleton!\");");
println("}");
println("}");
}
}
- println("} catch (Exception ex) {");
+ print("}");
+ println(" catch (Exception ex) {");
println("ex.printStackTrace();");
println("throw new Error(\"Exception when generating skeleton objects!\");");
println("}\n");
println("rmiObj.sendReturnObj(retObj);");
}
if (isCallbackMethod) { // Catch exception if this is callback
- println("} catch(Exception ex) {");
+ print("}");
+ println(" catch(Exception ex) {");
println("ex.printStackTrace();");
println("throw new Error(\"Exception from callback object instantiation!\");");
println("}");
for (Map.Entry<String,Set<String>> intMeth : mapNewIntMethods.entrySet()) {
String newIntface = intMeth.getKey();
int newObjectId = getNewIntfaceObjectId(newIntface);
- println("const static int object" + newObjectId + "Id = " + newObjectId + ";");
+ println("const static int object" + newObjectId + "Id = " + newObjectId + ";\t//" + newIntface);
println("const static set<int> set" + newObjectId + "Allowed;");
}
}
println("ports = _ports;");
println("rmiCall = new IoTRMICall(_port, _address, _rev, _bResult);");
if (callbackExist) {
- println("objIdCnt = 0;");
Iterator it = callbackClasses.iterator();
String callbackType = (String) it.next();
println("thread th1 (&" + newStubClass + "::___initCallBack, this);");
println(intface + "_CallbackSkeleton* skel = dynamic_cast<" + intface +
"_CallbackSkeleton*> (vecCallbackObj.at(objId));");
println("skel->invokeMethod(rmiObj);");
- println("} else {");
+ print("}");
+ println(" else {");
println("cerr << \"Illegal object Id: \" << to_string(objId);");
// TODO: perhaps need to change this into "throw" to make it cleaner (allow stack unfolding)
println("exit(-1);");
print("}"); println(";");
if (callbackExist)
writePermissionInitializationCplus(intface, newStubClass, intDecl);
+ writeObjectIdCountInitializationCplus(newStubClass, callbackExist);
println("#endif");
pw.close();
System.out.println("IoTCompiler: Generated stub class " + newStubClass + ".hpp...");
println("IoTRMICall *rmiCall;");
// Get the object Id
- println("static int objectId;");
+ println("int objectId;");
if (callbackExist) {
// We assume that each class only has one callback interface for now
Iterator it = callbackClasses.iterator();
println("};");
if (callbackExist)
writePermissionInitializationCplus(intface, newStubClass, intDecl);
+ writeObjectIdCountInitializationCplus(newStubClass, callbackExist);
println("#endif");
pw.close();
System.out.println("IoTCompiler: Generated callback stub class " + newIntface + ".hpp...");
}
+ /**
+ * HELPER: writeObjectIdCountInitializationCplus() writes the initialization of objIdCnt variable
+ */
+ private void writeObjectIdCountInitializationCplus(String newSkelClass, boolean callbackExist) {
+
+ if (callbackExist)
+ println("int " + newSkelClass + "::objIdCnt = 0;");
+ }
+
+
/**
* HELPER: writePermissionInitializationCplus() writes the initialization of permission set
*/
println("bool _bResult = false;");
println("mainObj = _mainObj;");
println("rmiObj = new IoTRMIObject(_port, &_bResult);");
- // Callback
- if (callbackExist) {
- println("objIdCnt = 0;");
- }
- //println("set0Allowed = Arrays.asList(object0Permission);");
println("___waitRequestInvokeMethod();");
println("}\n");
}
println("int param1 = 0;");
println("string param2 = \"\";");
println("int param3 = 0;");
+ println("string paramCls[] = { \"int\", \"string\", \"int\" };");
println("void* paramObj[] = { ¶m1, ¶m2, ¶m3 };");
+ println("rmiObj->getMethodParams(paramCls, numParam, paramObj);");
println("bool bResult = false;");
println("rmiCall = new IoTRMICall(param1, param2.c_str(), param3, &bResult);");
println("}\n");
writeCplusWaitRequestInvokeMethod(methods, intDecl, callbackExist, intface);
println("};");
writePermissionInitializationCplus(intface, newSkelClass, intDecl);
+ writeObjectIdCountInitializationCplus(newSkelClass, callbackExist);
println("#endif");
pw.close();
System.out.println("IoTCompiler: Generated skeleton class " + newSkelClass + ".hpp...");
println(intface + " *mainObj;");
// Keep track of object Ids of all stubs registered to this interface
- println("static int objectId;");
+ println("int objectId;");
// Callback
if (callbackExist) {
Iterator it = callbackClasses.iterator();
println(newSkelClass + "(" + intface + " *_mainObj, int _objectId) {");
println("mainObj = _mainObj;");
println("objectId = _objectId;");
- // Callback
- if (callbackExist) {
- println("objIdCnt = 0;");
- }
println("}\n");
}
// Write waitRequestInvokeMethod() - main loop
writeCplusCallbackWaitRequestInvokeMethod(methods, intDecl, callbackExist);
println("};");
+ writeObjectIdCountInitializationCplus(newSkelClass, callbackExist);
println("#endif");
pw.close();
System.out.println("IoTCompiler: Generated callback skeleton class " + newSkelClass + ".hpp...");
#include <thread>
#include <chrono>
#include "TestClassInterface.hpp"
+#include "CallBackInterfaceWithCallBack.hpp"
using namespace std;
vector<char> getCharList(vector<char> in);
// Callbacks
- void registerCallback(CallBackInterface* _cb);
- //void registerCallback(vector<CallBackInterface*> _cb);
+ void registerCallback(CallBackInterfaceWithCallBack* _cb);
+ //void registerCallback(vector<CallBackInterfaceWithCallBack*> _cb);
int callBack();
int getA();
int setACAndGetA(string newC, int newA);
private:
- int intA;
- float floatB;
- string stringC;
- vector<CallBackInterface*> cbvec;
+ int intA;
+ float floatB;
+ string stringC;
+ vector<CallBackInterfaceWithCallBack*> cbvec;
};
}
-void TestClass::registerCallback(CallBackInterface* _cb) {
+void TestClass::registerCallback(CallBackInterfaceWithCallBack* _cb) {
cbvec.push_back(_cb);
cout << "Registering callback object!" << endl;
}
-/*void TestClass::registerCallback(vector<CallBackInterface*> _cb) {
+/*void TestClass::registerCallback(vector<CallBackInterfaceWithCallBack*> _cb) {
for (CallBackInterface* cb : _cb) {
cbvec.push_back(cb);
int TestClass::callBack() {
int sum = 0;
- for (CallBackInterface* cb : cbvec) {
+ for (CallBackInterfaceWithCallBack* cb : cbvec) {
sum = sum + cb->printInt();
}