From: rtrimana Date: Wed, 7 Dec 2016 19:51:07 +0000 (-0800) Subject: Testing complex callbacks invocation; fixing subtle bugs X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=8daaec4f96717f5ac88d7158a0955ac194647800;p=iot2.git Testing complex callbacks invocation; fixing subtle bugs --- diff --git a/config/iotpolicy/testclasspolicy_advanced.pol b/config/iotpolicy/testclasspolicy_advanced.pol index c5fcfd2..ad43279 100644 --- a/config/iotpolicy/testclasspolicy_advanced.pol +++ b/config/iotpolicy/testclasspolicy_advanced.pol @@ -15,6 +15,7 @@ public interface TestClassInterface { public void registerCallback(CallBackInterface _cb); public void registerCallbackArray(CallBackInterface _cb[]); public void registerCallbackList(List _cb); + public void registerCallbackComplex(int in, List _cb, double db); public int callBack(); capability EnumsStructs { @@ -39,6 +40,7 @@ public interface TestClassInterface { method = "registerCallback(CallBackInterface _cb)"; method = "registerCallbackArray(CallBackInterface _cb[])"; method = "registerCallbackList(List _cb)"; + method = "registerCallbackComplex(int in, List _cb, double db)"; method = "callBack()"; } diff --git a/iotjava/iotpolicy/IoTCompiler.java b/iotjava/iotpolicy/IoTCompiler.java index 9eafffb..8242bfc 100644 --- a/iotjava/iotpolicy/IoTCompiler.java +++ b/iotjava/iotpolicy/IoTCompiler.java @@ -1363,7 +1363,6 @@ public class IoTCompiler { for (int i = 0; i < methParams.size(); i++) { String paramType = methPrmTypes.get(i); String param = methParams.get(i); - //if (callbackType.equals(paramType)) { if (checkCallbackType(paramType, callbackType)) { // Check if this has callback object println("try {"); String exchParamType = checkAndGetParamClass(getGenericType(paramType)); @@ -1674,8 +1673,9 @@ public class IoTCompiler { checkAndWriteEnumTypeJavaSkeleton(methParams, methPrmTypes); Map mapStubParam = null; - if (isCallbackMethod) + if (isCallbackMethod) { mapStubParam = writeCallbackJavaStubGeneration(methParams, methPrmTypes, callbackType); + } // Check if this is "void" String retType = intDecl.getMethodType(method); if (retType.equals("void")) { @@ -1689,14 +1689,15 @@ public class IoTCompiler { } for (int i = 0; i < methParams.size(); i++) { - if (isCallbackMethod) { + String paramType = methPrmTypes.get(i); + if (isCallbackMethod && checkCallbackType(paramType, callbackType)) { print(mapStubParam.get(i)); // Get the callback parameter - } else if (isEnumClass(getGenericType(methPrmTypes.get(i)))) { // Enum class - print(getEnumParam(methPrmTypes.get(i), methParams.get(i), i)); - } else if (isStructClass(getGenericType(methPrmTypes.get(i)))) { + } else if (isEnumClass(getGenericType(paramType))) { // Enum class + print(getEnumParam(paramType, methParams.get(i), i)); + } else if (isStructClass(getGenericType(paramType))) { print("paramStruct" + i); } else { - String prmType = checkAndGetArray(methPrmTypes.get(i), methParams.get(i)); + String prmType = checkAndGetArray(paramType, methParams.get(i)); if (isStructMethod) print("(" + prmType + ") paramObj[offset" + i + "]"); else @@ -2676,7 +2677,7 @@ public class IoTCompiler { if (checkCallbackType(paramType, callbackType)) { // Check if this has callback object print("&___paramCB"); } else - print(getSimpleIdentifier(methParams.get(i))); + print("&" + getSimpleIdentifier(methParams.get(i))); if (i != methParams.size() - 1) print(", "); } diff --git a/iotjava/iotrmi/C++/basics/TestClass.hpp b/iotjava/iotrmi/C++/basics/TestClass.hpp index 9c46644..fa9b877 100644 --- a/iotjava/iotrmi/C++/basics/TestClass.hpp +++ b/iotjava/iotrmi/C++/basics/TestClass.hpp @@ -42,6 +42,7 @@ class TestClass : public TestClassInterface { void registerCallback(CallBackInterfaceWithCallBack* _cb); void registerCallbackArray(vector _cb); void registerCallbackList(vector _cb); + void registerCallbackComplex(int in, vector _cb, double db); int callBack(); // Enum @@ -117,6 +118,18 @@ void TestClass::registerCallbackList(vector _cb) } +void TestClass::registerCallbackComplex(int in, vector _cb, double db) { + + for (CallBackInterfaceWithCallBack* cb : _cb) { + cbvec.push_back(cb); + cout << "Registering callback object in list!" << endl; + } + + cout << "Integer: " << in << endl; + cout << "Double: " << db << endl; +} + + int TestClass::callBack() { int sum = 0; diff --git a/iotjava/iotrmi/C++/basics/TestClassAdvanced_Stub.cpp b/iotjava/iotrmi/C++/basics/TestClassAdvanced_Stub.cpp index f70573e..2d82478 100644 --- a/iotjava/iotrmi/C++/basics/TestClassAdvanced_Stub.cpp +++ b/iotjava/iotrmi/C++/basics/TestClassAdvanced_Stub.cpp @@ -43,7 +43,7 @@ int main(int argc, char *argv[]) }*/ - cout << "==== STRUCT ====" << endl; +/* cout << "==== STRUCT ====" << endl; Struct str; str.name = "Rahmadi"; str.value = 0.123; @@ -63,7 +63,7 @@ int main(int argc, char *argv[]) vector vecStr; vecStr.push_back(str); vecStr.push_back(str2); -/* vector vecRetStr = tcStub->handleStructArray(vecStr); + vector vecRetStr = tcStub->handleStructArray(vecStr); for (Struct st : vecRetStr) { cout << "Name: " << st.name << endl; cout << "Value:" << st.value << endl; @@ -74,16 +74,16 @@ int main(int argc, char *argv[]) cout << "Name: " << st.name << endl; cout << "Value:" << st.value << endl; cout << "Year" << st.year << endl; - }*/ + } vector vecRetStr3 = tcStub->handleStructComplex2(23, 'c', vecStr); for (Struct st : vecRetStr3) { cout << "Name: " << st.name << endl; cout << "Value:" << st.value << endl; cout << "Year" << st.year << endl; - } + }*/ -/* cout << "==== CALLBACK ====" << endl; - CallBackInterface *cbSingle = new CallBack(2354); + cout << "==== CALLBACK ====" << endl; +/* CallBackInterface *cbSingle = new CallBack(2354); tcStub->registerCallback(cbSingle); cout << "Return value from callback: " << tcStub->callBack() << endl; CallBackInterface *cb1 = new CallBack(23); @@ -94,7 +94,7 @@ int main(int argc, char *argv[]) cb.push_back(cb2); cb.push_back(cb3); tcStub->registerCallbackArray(cb); - cout << "Return value from callback: " << tcStub->callBack() << endl; + cout << "Return value from callback: " << tcStub->callBack() << endl;*/ CallBackInterface *cb4 = new CallBack(53); CallBackInterface *cb5 = new CallBack(63); CallBackInterface *cb6 = new CallBack(73); @@ -102,19 +102,10 @@ int main(int argc, char *argv[]) cblist.push_back(cb4); cblist.push_back(cb5); cblist.push_back(cb6); - tcStub->registerCallbackList(cblist); +// tcStub->registerCallbackList(cblist); +// cout << "Return value from callback: " << tcStub->callBack() << endl; + tcStub->registerCallbackComplex(23, cblist, 0.1234); cout << "Return value from callback: " << tcStub->callBack() << endl; - cout << "==== OTHERS ====" << endl; - cout << "Return value: " << tcStub->getA() << endl; - cout << "Return value: " << tcStub->setAndGetA(123) << endl; - cout << "Return value: " << tcStub->setACAndGetA("string", 123) << endl; - vector input; - input.push_back("123"); - input.push_back("456"); - input.push_back("987"); - - cout << "Return value: " << tcStub->sumArray(input) << endl; -*/ return 0; } diff --git a/iotjava/iotrmi/C++/basics/TestClass_Debug.cpp b/iotjava/iotrmi/C++/basics/TestClass_Debug.cpp deleted file mode 100644 index 8771d55..0000000 --- a/iotjava/iotrmi/C++/basics/TestClass_Debug.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include -#include "TestClassComplete_Stub.hpp" -#include "CallBack.hpp" -#include "IoTRMICall.hpp" - -using namespace std; - -int main(int argc, char *argv[]) -{ - - int _port = 50044; - const char* _address = "localhost"; - //const char* address = "128.195.136.170"; // dc-9.calit2.uci.edu - int _rev = 0; - bool bResult = false; - - IoTRMICall *rmiCall = new IoTRMICall(_port, _address, _rev, &bResult); - cout << "Successfully connecting!" << endl << endl; - delete rmiCall; - - return 0; -} diff --git a/iotjava/iotrmi/Java/basics/TestClass.java b/iotjava/iotrmi/Java/basics/TestClass.java index 42e53c2..89baf94 100644 --- a/iotjava/iotrmi/Java/basics/TestClass.java +++ b/iotjava/iotrmi/Java/basics/TestClass.java @@ -61,6 +61,18 @@ public class TestClass implements TestClassInterface { } + public void registerCallbackComplex(int in, List _cb, double db) { + + for (CallBackInterfaceWithCallBack cb : _cb) { + cblist.add(cb); + System.out.println("Registering callback objects in list!"); + } + + System.out.println("Integer: " + in); + System.out.println("Double: " + db); + } + + public int callBack() { int sum = 0; diff --git a/iotjava/iotrmi/Java/basics/TestClassAdvanced_Stub.java b/iotjava/iotrmi/Java/basics/TestClassAdvanced_Stub.java index 8261225..46143fa 100644 --- a/iotjava/iotrmi/Java/basics/TestClassAdvanced_Stub.java +++ b/iotjava/iotrmi/Java/basics/TestClassAdvanced_Stub.java @@ -17,8 +17,8 @@ public class TestClassAdvanced_Stub { int rev = 0; TestClassComplete_Stub tcstub = new TestClassComplete_Stub(port, address, rev, ports); - System.out.println("==== ENUM ===="); -/* Enum en = Enum.APPLE; +/* System.out.println("==== ENUM ===="); + Enum en = Enum.APPLE; Enum res = tcstub.handleEnum(en); System.out.println("Enum member: " + res); Enum resComp = tcstub.handleEnumComplex(en, 23, 'c'); @@ -34,25 +34,25 @@ public class TestClassAdvanced_Stub { System.out.println("Enum members: " + Arrays.toString(resArr3));*/ - System.out.println("==== STRUCT ===="); +/* System.out.println("==== STRUCT ===="); Struct str = new Struct(); str.name = "Rahmadi"; str.value = 0.123f; str.year = 2016; -/* Struct strRes = tcstub.handleStruct(str); + Struct strRes = tcstub.handleStruct(str); System.out.println("Name: " + strRes.name); System.out.println("Value: " + strRes.value); System.out.println("Year: " + strRes.year); Struct strRes2 = tcstub.handleStructComplex(23, 'c', str); System.out.println("Name: " + strRes2.name); System.out.println("Value: " + strRes2.value); - System.out.println("Year: " + strRes2.year);*/ + System.out.println("Year: " + strRes2.year); Struct str2 = new Struct(); str2.name = "Trimananda"; str2.value = 0.124f; str2.year = 2017; Struct[] arrStr = { str, str2 }; -/* Struct[] arrRet = tcstub.handleStructArray(arrStr); + Struct[] arrRet = tcstub.handleStructArray(arrStr); for(Struct st : arrRet) { System.out.println("Name: " + st.name); System.out.println("Value: " + st.value); @@ -64,16 +64,16 @@ public class TestClassAdvanced_Stub { System.out.println("Name: " + st.name); System.out.println("Value: " + st.value); System.out.println("Year: " + st.year); - }*/ + } List stRetList2 = tcstub.handleStructComplex2(23, 'c', arrStr); for(Struct st : stRetList2) { System.out.println("Name: " + st.name); System.out.println("Value: " + st.value); System.out.println("Year: " + st.year); - } + }*/ - /*System.out.println("==== CALLBACKS ===="); - CallBackInterface cbSingle = new CallBack(2354); + System.out.println("==== CALLBACKS ===="); +/* CallBackInterface cbSingle = new CallBack(2354); tcstub.registerCallback(cbSingle); System.out.println("Return value from callback: " + tcstub.callBack()); CallBackInterface cb1 = new CallBack(23); @@ -81,13 +81,16 @@ public class TestClassAdvanced_Stub { CallBackInterface cb3 = new CallBack(43); CallBackInterface[] cb = { cb1, cb2, cb3 }; tcstub.registerCallbackArray(cb); - System.out.println("Return value from callback: " + tcstub.callBack()); + System.out.println("Return value from callback: " + tcstub.callBack());*/ List cblist = new ArrayList(); CallBackInterface cb4 = new CallBack(53); cblist.add(cb4); CallBackInterface cb5 = new CallBack(63); cblist.add(cb5); CallBackInterface cb6 = new CallBack(73); cblist.add(cb6); - tcstub.registerCallbackList(cblist); - System.out.println("Return value from callback: " + tcstub.callBack());*/ +// tcstub.registerCallbackList(cblist); +// System.out.println("Return value from callback: " + tcstub.callBack()); + + tcstub.registerCallbackComplex(23, cblist, 0.1234); + System.out.println("Return value from callback: " + tcstub.callBack()); } } diff --git a/iotjava/iotrmi/Java/basics/TestClass_Debug.java b/iotjava/iotrmi/Java/basics/TestClass_Debug.java deleted file mode 100644 index 6ab13ea..0000000 --- a/iotjava/iotrmi/Java/basics/TestClass_Debug.java +++ /dev/null @@ -1,23 +0,0 @@ -import java.util.Arrays; -import java.util.List; -import java.util.ArrayList; -import iotrmi.Java.IoTRMICall; -import iotruntime.master.CommunicationHandler; - -public class TestClass_Debug { - - public static void main(String[] args) throws Exception { - - CommunicationHandler comHan = new CommunicationHandler(true); - int numOfPorts = 1; - int[] ports = comHan.getCallbackPorts(numOfPorts); - - int _port = 56205; - String _address = "localhost"; - //String address = "128.195.136.170"; // dc-9.calit2.uci.edu - int _rev = 0; - - IoTRMICall rmiCall = new IoTRMICall(_port, _address, _rev); - System.out.println("Creating a new connection!!!"); - } -}