projects
/
iot2.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
f4d0e87
)
Cleaning up callback code generation; Fixing a few minor issues, e.g. indentation...
author
rtrimana
<rtrimana@uci.edu>
Tue, 29 Nov 2016 18:40:16 +0000
(10:40 -0800)
committer
rtrimana
<rtrimana@uci.edu>
Tue, 29 Nov 2016 18:40:16 +0000
(10:40 -0800)
iotjava/iotpolicy/IoTCompiler.java
patch
|
blob
|
history
iotjava/iotrmi/C++/basics/TestClass.hpp
patch
|
blob
|
history
iotjava/iotrmi/Java/basics/TestClass.java
patch
|
blob
|
history
iotjava/iotrmi/Java/sample/TestClass_Stub.java
patch
|
blob
|
history
diff --git
a/iotjava/iotpolicy/IoTCompiler.java
b/iotjava/iotpolicy/IoTCompiler.java
index 5af3c5ea6c98860e979ed268aa4a41fcb601dcce..857199833799691896a5153f3e01c368d18319ec 100644
(file)
--- a/
iotjava/iotpolicy/IoTCompiler.java
+++ b/
iotjava/iotpolicy/IoTCompiler.java
@@
-508,11
+508,13
@@
public class IoTCompiler {
println(intface + "_CallbackSkeleton skel = (" + intface + "_CallbackSkeleton) listCallbackObj.get(objId);");
println("if (skel != null) {");
println("skel.invokeMethod(rmiObj);");
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("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("ex.printStackTrace();");
println("throw new Error(\"Error instantiating class " + intface + "_CallbackSkeleton!\");");
println("}");
@@
-936,7
+938,8
@@
public class IoTCompiler {
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("ex.printStackTrace();");
println("throw new Error(\"Exception when generating skeleton objects!\");");
println("}\n");
@@
-1642,7
+1645,8
@@
public class IoTCompiler {
println("rmiObj.sendReturnObj(retObj);");
}
if (isCallbackMethod) { // Catch exception if this is callback
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("}");
println("ex.printStackTrace();");
println("throw new Error(\"Exception from callback object instantiation!\");");
println("}");
@@
-2972,7
+2976,7
@@
public class IoTCompiler {
for (Map.Entry<String,Set<String>> intMeth : mapNewIntMethods.entrySet()) {
String newIntface = intMeth.getKey();
int newObjectId = getNewIntfaceObjectId(newIntface);
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("const static set<int> set" + newObjectId + "Allowed;");
}
}
@@
-3017,7
+3021,6
@@
public class IoTCompiler {
println("ports = _ports;");
println("rmiCall = new IoTRMICall(_port, _address, _rev, _bResult);");
if (callbackExist) {
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);");
Iterator it = callbackClasses.iterator();
String callbackType = (String) it.next();
println("thread th1 (&" + newStubClass + "::___initCallBack, this);");
@@
-3091,7
+3094,8
@@
public class IoTCompiler {
println(intface + "_CallbackSkeleton* skel = dynamic_cast<" + intface +
"_CallbackSkeleton*> (vecCallbackObj.at(objId));");
println("skel->invokeMethod(rmiObj);");
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);");
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);");
@@
-3164,6
+3168,7
@@
public class IoTCompiler {
print("}"); println(";");
if (callbackExist)
writePermissionInitializationCplus(intface, newStubClass, intDecl);
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("#endif");
pw.close();
System.out.println("IoTCompiler: Generated stub class " + newStubClass + ".hpp...");
@@
-3179,7
+3184,7
@@
public class IoTCompiler {
println("IoTRMICall *rmiCall;");
// Get the object Id
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();
if (callbackExist) {
// We assume that each class only has one callback interface for now
Iterator it = callbackClasses.iterator();
@@
-3259,6
+3264,7
@@
public class IoTCompiler {
println("};");
if (callbackExist)
writePermissionInitializationCplus(intface, newStubClass, intDecl);
println("};");
if (callbackExist)
writePermissionInitializationCplus(intface, newStubClass, intDecl);
+ writeObjectIdCountInitializationCplus(newStubClass, callbackExist);
println("#endif");
pw.close();
System.out.println("IoTCompiler: Generated callback stub class " + newIntface + ".hpp...");
println("#endif");
pw.close();
System.out.println("IoTCompiler: Generated callback stub class " + newIntface + ".hpp...");
@@
-3290,6
+3296,16
@@
public class IoTCompiler {
}
}
+ /**
+ * 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
*/
/**
* HELPER: writePermissionInitializationCplus() writes the initialization of permission set
*/
@@
-3326,11
+3342,6
@@
public class IoTCompiler {
println("bool _bResult = false;");
println("mainObj = _mainObj;");
println("rmiObj = new IoTRMIObject(_port, &_bResult);");
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("___waitRequestInvokeMethod();");
println("}\n");
}
@@
-3400,7
+3411,9
@@
public class IoTCompiler {
println("int param1 = 0;");
println("string param2 = \"\";");
println("int param3 = 0;");
println("int param1 = 0;");
println("string param2 = \"\";");
println("int param3 = 0;");
+ println("string paramCls[] = { \"int\", \"string\", \"int\" };");
println("void* paramObj[] = { ¶m1, ¶m2, ¶m3 };");
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");
println("bool bResult = false;");
println("rmiCall = new IoTRMICall(param1, param2.c_str(), param3, &bResult);");
println("}\n");
@@
-4116,6
+4129,7
@@
public class IoTCompiler {
writeCplusWaitRequestInvokeMethod(methods, intDecl, callbackExist, intface);
println("};");
writePermissionInitializationCplus(intface, newSkelClass, intDecl);
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("#endif");
pw.close();
System.out.println("IoTCompiler: Generated skeleton class " + newSkelClass + ".hpp...");
@@
-4130,7
+4144,7
@@
public class IoTCompiler {
println(intface + " *mainObj;");
// Keep track of object Ids of all stubs registered to this interface
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();
// Callback
if (callbackExist) {
Iterator it = callbackClasses.iterator();
@@
-4153,10
+4167,6
@@
public class IoTCompiler {
println(newSkelClass + "(" + intface + " *_mainObj, int _objectId) {");
println("mainObj = _mainObj;");
println("objectId = _objectId;");
println(newSkelClass + "(" + intface + " *_mainObj, int _objectId) {");
println("mainObj = _mainObj;");
println("objectId = _objectId;");
- // Callback
- if (callbackExist) {
- println("objIdCnt = 0;");
- }
println("}\n");
}
println("}\n");
}
@@
-4338,6
+4348,7
@@
public class IoTCompiler {
// Write waitRequestInvokeMethod() - main loop
writeCplusCallbackWaitRequestInvokeMethod(methods, intDecl, callbackExist);
println("};");
// 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...");
println("#endif");
pw.close();
System.out.println("IoTCompiler: Generated callback skeleton class " + newSkelClass + ".hpp...");
diff --git
a/iotjava/iotrmi/C++/basics/TestClass.hpp
b/iotjava/iotrmi/C++/basics/TestClass.hpp
index e5c38980f07cd15c42c2d018e1d65fb1e5714f8f..492d3d996dc59fa26d4f780bab6706d3b8fc3983 100644
(file)
--- a/
iotjava/iotrmi/C++/basics/TestClass.hpp
+++ b/
iotjava/iotrmi/C++/basics/TestClass.hpp
@@
-5,6
+5,7
@@
#include <thread>
#include <chrono>
#include "TestClassInterface.hpp"
#include <thread>
#include <chrono>
#include "TestClassInterface.hpp"
+#include "CallBackInterfaceWithCallBack.hpp"
using namespace std;
using namespace std;
@@
-38,8
+39,8
@@
class TestClass : public TestClassInterface {
vector<char> getCharList(vector<char> in);
// Callbacks
vector<char> getCharList(vector<char> in);
// Callbacks
- void registerCallback(CallBackInterface* _cb);
- //void registerCallback(vector<CallBackInterface*> _cb);
+ void registerCallback(CallBackInterface
WithCallBack
* _cb);
+ //void registerCallback(vector<CallBackInterface
WithCallBack
*> _cb);
int callBack();
int getA();
int callBack();
int getA();
@@
-51,10
+52,10
@@
class TestClass : public TestClassInterface {
int setACAndGetA(string newC, int newA);
private:
int setACAndGetA(string newC, int newA);
private:
- int intA;
- float floatB;
- string stringC;
- vector<CallBackInterface
*>
cbvec;
+ int
intA;
+ float
floatB;
+ string
stringC;
+ vector<CallBackInterface
WithCallBack*>
cbvec;
};
};
@@
-76,14
+77,14
@@
TestClass::TestClass(int _int, float _float, string _string) {
}
}
-void TestClass::registerCallback(CallBackInterface* _cb) {
+void TestClass::registerCallback(CallBackInterface
WithCallBack
* _cb) {
cbvec.push_back(_cb);
cout << "Registering callback object!" << endl;
}
cbvec.push_back(_cb);
cout << "Registering callback object!" << endl;
}
-/*void TestClass::registerCallback(vector<CallBackInterface*> _cb) {
+/*void TestClass::registerCallback(vector<CallBackInterface
WithCallBack
*> _cb) {
for (CallBackInterface* cb : _cb) {
cbvec.push_back(cb);
for (CallBackInterface* cb : _cb) {
cbvec.push_back(cb);
@@
-95,7
+96,7
@@
void TestClass::registerCallback(CallBackInterface* _cb) {
int TestClass::callBack() {
int sum = 0;
int TestClass::callBack() {
int sum = 0;
- for (CallBackInterface* cb : cbvec) {
+ for (CallBackInterface
WithCallBack
* cb : cbvec) {
sum = sum + cb->printInt();
}
sum = sum + cb->printInt();
}
diff --git
a/iotjava/iotrmi/Java/basics/TestClass.java
b/iotjava/iotrmi/Java/basics/TestClass.java
index 616606d573adc6dc4764ec53cd22496e15060fbd..2de5bb7df02a47541035e88171e8db8573878fec 100644
(file)
--- a/
iotjava/iotrmi/Java/basics/TestClass.java
+++ b/
iotjava/iotrmi/Java/basics/TestClass.java
@@
-10,7
+10,7
@@
public class TestClass implements TestClassInterface {
private int intA;
private float floatB;
private String stringC;
private int intA;
private float floatB;
private String stringC;
- private List<CallBackInterface> cblist;
+ private List<CallBackInterface
WithCallBack
> cblist;
/**
* Constructors
/**
* Constructors
@@
-32,16
+32,17
@@
public class TestClass implements TestClassInterface {
// Callback
// Callback
- public void registerCallback(CallBackInterface _cb) {
+ //public void registerCallback(CallBackInterface _cb) {
+ public void registerCallback(CallBackInterfaceWithCallBack _cb) {
- cblist.add(cb);
+ cblist.add(
_
cb);
System.out.println("Registering callback object!");
}
System.out.println("Registering callback object!");
}
- /*public void registerCallback(CallBackInterface[] _cb) {
+ /*public void registerCallback(CallBackInterface
WithCallBack
[] _cb) {
- for (CallBackInterface cb : _cb) {
+ for (CallBackInterface
WithCallBack
cb : _cb) {
cblist.add(cb);
System.out.println("Registering callback object!");
}
cblist.add(cb);
System.out.println("Registering callback object!");
}
@@
-51,7
+52,7
@@
public class TestClass implements TestClassInterface {
public int callBack() {
int sum = 0;
public int callBack() {
int sum = 0;
- for (CallBackInterface cb : cblist) {
+ for (CallBackInterface
WithCallBack
cb : cblist) {
sum = sum + cb.printInt();
}
return sum;
sum = sum + cb.printInt();
}
return sum;
diff --git
a/iotjava/iotrmi/Java/sample/TestClass_Stub.java
b/iotjava/iotrmi/Java/sample/TestClass_Stub.java
index 2a45396eed3b0303b670031248be1438116031a0..a08ce6282871d19f54a61fa19aa80db801b3e3b4 100644
(file)
--- a/
iotjava/iotrmi/Java/sample/TestClass_Stub.java
+++ b/
iotjava/iotrmi/Java/sample/TestClass_Stub.java
@@
-68,9
+68,7
@@
public class TestClass_Stub implements TestClassInterface {
Thread thread = new Thread() {
public void run() {
try{
Thread thread = new Thread() {
public void run() {
try{
- System.out.println("Created server with port: " + ports[0]);
rmiObj = new IoTRMIObject(ports[0]);
rmiObj = new IoTRMIObject(ports[0]);
- Object retObj = null;
while (true) {
byte[] method = rmiObj.getMethodBytes();
// Permission checking
while (true) {
byte[] method = rmiObj.getMethodBytes();
// Permission checking