From: rtrimana Date: Mon, 5 Dec 2016 23:20:13 +0000 (-0800) Subject: Fixing problem with array/list of callbacks; Java static variables persist across... X-Git-Url: http://plrg.eecs.uci.edu/git/?p=iot2.git;a=commitdiff_plain;h=3c4fd177d5f1eec65478dee1d16f7eb0ad31bcf6 Fixing problem with array/list of callbacks; Java static variables persist across multiple objects of the same type that are instantiated at the same instance - needed to make objectId non-static to mark different callback objects --- diff --git a/iotjava/iotpolicy/IoTCompiler.java b/iotjava/iotpolicy/IoTCompiler.java index e461706..d056fe4 100644 --- a/iotjava/iotpolicy/IoTCompiler.java +++ b/iotjava/iotpolicy/IoTCompiler.java @@ -1119,7 +1119,7 @@ public class IoTCompiler { println("private String address;"); println("private int[] ports;\n"); // Get the object Id - println("private static int objectId = 0;"); + println("private int objectId = 0;"); if (callbackExist) { // We assume that each class only has one callback interface for now Iterator it = callbackClasses.iterator(); @@ -2172,7 +2172,7 @@ public class IoTCompiler { println("private " + intface + " mainObj;"); // For callback skeletons, this is its own object Id - println("private static int objectId = 0;"); + println("private int objectId = 0;"); // Callback if (callbackExist) { println("private static int objIdCnt = 0;"); diff --git a/iotjava/iotrmi/C++/basics/TestClass_Stub.cpp b/iotjava/iotrmi/C++/basics/TestClass_Stub.cpp index 207eb8b..d3c4e1d 100644 --- a/iotjava/iotrmi/C++/basics/TestClass_Stub.cpp +++ b/iotjava/iotrmi/C++/basics/TestClass_Stub.cpp @@ -142,9 +142,9 @@ int main(int argc, char *argv[]) cb.push_back(cb3); tcStub->registerCallbackArray(cb); cout << "Return value from callback: " << tcStub->callBack() << endl; - CallBackInterface *cb4 = new CallBack(23); - CallBackInterface *cb5 = new CallBack(33); - CallBackInterface *cb6 = new CallBack(43); + CallBackInterface *cb4 = new CallBack(53); + CallBackInterface *cb5 = new CallBack(63); + CallBackInterface *cb6 = new CallBack(73); vector cblist; cblist.push_back(cb4); cblist.push_back(cb5); diff --git a/iotjava/iotrmi/Java/basics/TestClass_Stub.java b/iotjava/iotrmi/Java/basics/TestClass_Stub.java index d82c905..7a6b277 100644 --- a/iotjava/iotrmi/Java/basics/TestClass_Stub.java +++ b/iotjava/iotrmi/Java/basics/TestClass_Stub.java @@ -106,16 +106,16 @@ public class TestClass_Stub { //CallBackInterface cbSingle2 = new CallBack(2355); //tcstub.registerCallback(cbSingle2); //System.out.println("Return value from callback: " + tcstub.callBack()); - /*CallBackInterface cb1 = new CallBack(23); + CallBackInterface cb1 = new CallBack(23); CallBackInterface cb2 = new CallBack(33); 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 cb1 = new CallBack(23); cblist.add(cb1); - CallBackInterface cb2 = new CallBack(33); cblist.add(cb2); - CallBackInterface cb3 = new CallBack(43); cblist.add(cb3); + 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()); @@ -124,5 +124,7 @@ public class TestClass_Stub { System.out.println("Return value: " + tcstub.setAndGetA(123)); System.out.println("Return value: " + tcstub.setACAndGetA("string", 123)); System.out.println("Return value: " + tcstub.sumArray(new String[] { "123", "456", "987" })); + + } }