Adding enum support for method argument; need to emulate the same functionality for...
authorrtrimana <rtrimana@uci.edu>
Sat, 5 Nov 2016 22:56:32 +0000 (15:56 -0700)
committerrtrimana <rtrimana@uci.edu>
Sat, 5 Nov 2016 22:56:32 +0000 (15:56 -0700)
21 files changed:
iotjava/Makefile
iotjava/iotrmi/C++/sample/EnumC.cpp [new file with mode: 0644]
iotjava/iotrmi/C++/sample/EnumC.hpp [new file with mode: 0644]
iotjava/iotrmi/C++/sample/TestClass.hpp
iotjava/iotrmi/C++/sample/TestClassInterface.hpp
iotjava/iotrmi/C++/sample/TestClass_Skeleton.hpp
iotjava/iotrmi/C++/sample/TestClass_Stub.cpp
iotjava/iotrmi/C++/sample/TestClass_Stub.hpp
iotjava/iotrmi/Java/IoTRMICall.java
iotjava/iotrmi/Java/IoTRMIObject.java
iotjava/iotrmi/Java/IoTRMIUtil.java
iotjava/iotrmi/Java/sample/CallBack_CBSkeleton.java
iotjava/iotrmi/Java/sample/CallBack_CBStub.java
iotjava/iotrmi/Java/sample/CallBack_Skeleton.java
iotjava/iotrmi/Java/sample/CallBack_Stub.java
iotjava/iotrmi/Java/sample/EnumJ.java [new file with mode: 0644]
iotjava/iotrmi/Java/sample/EnumMain.java [new file with mode: 0644]
iotjava/iotrmi/Java/sample/TestClass.java
iotjava/iotrmi/Java/sample/TestClassInterface.java
iotjava/iotrmi/Java/sample/TestClass_Skeleton.java
iotjava/iotrmi/Java/sample/TestClass_Stub.java

index 267c006fcbf92dd85bf19ebcf3788306043cb50a..8df71423dff06cf128158444240ff392f67153d3 100644 (file)
@@ -31,8 +31,8 @@ runtime:
 PHONY += rmi
 rmi:
        mkdir -p $(BIN_DIR)
-#      $(JAVAC) -cp .:../$(BIN_DIR) -d $(BIN_DIR) iotrmi/Java/*.java
-#      $(JAVAC) -cp .:../$(BIN_DIR) -d $(BIN_DIR) iotrmi/Java/sample/*.java
+       $(JAVAC) -cp .:../$(BIN_DIR) -d $(BIN_DIR) iotrmi/Java/*.java
+       $(JAVAC) -cp .:../$(BIN_DIR) -d $(BIN_DIR) iotrmi/Java/sample/*.java
 #      mkdir -p $(BIN_DIR)/iotrmi/C++
        #$(G++) iotrmi/C++/IoTSocketServer.cpp -o $(BIN_DIR)/iotrmi/C++/IoTSocketServer.out
        #$(G++) iotrmi/C++/IoTSocketClient.cpp -o $(BIN_DIR)/iotrmi/C++/IoTSocketClient.out
@@ -41,16 +41,17 @@ rmi:
        mkdir -p $(BIN_DIR)/iotrmi/C++/sample
        #$(G++) iotrmi/C++/sample/CallBackInterface.hpp -o $(BIN_DIR)/iotrmi/C++/sample/CallBackInterface.out --std=c++11
        #$(G++) iotrmi/C++/sample/CallBack.hpp -o $(BIN_DIR)/iotrmi/C++/sample/CallBack.out --std=c++11
-       $(G++) iotrmi/C++/sample/CallBack_CBStub.hpp -o $(BIN_DIR)/iotrmi/C++/sample/CallBack_CBStub.out --std=c++11
-       $(G++) iotrmi/C++/sample/CallBack_CBSkeleton.hpp -o $(BIN_DIR)/iotrmi/C++/sample/CallBack_CBSkeleton.out --std=c++11
-       $(G++) iotrmi/C++/sample/CallBack_Stub.cpp -o $(BIN_DIR)/iotrmi/C++/sample/CallBack_Stub.out --std=c++11
-       $(G++) iotrmi/C++/sample/CallBack_Skeleton.cpp -o $(BIN_DIR)/iotrmi/C++/sample/CallBack_Skeleton.out --std=c++11
+#      $(G++) iotrmi/C++/sample/CallBack_CBStub.hpp -o $(BIN_DIR)/iotrmi/C++/sample/CallBack_CBStub.out --std=c++11
+#      $(G++) iotrmi/C++/sample/CallBack_CBSkeleton.hpp -o $(BIN_DIR)/iotrmi/C++/sample/CallBack_CBSkeleton.out --std=c++11
+#      $(G++) iotrmi/C++/sample/CallBack_Stub.cpp -o $(BIN_DIR)/iotrmi/C++/sample/CallBack_Stub.out --std=c++11
+#      $(G++) iotrmi/C++/sample/CallBack_Skeleton.cpp -o $(BIN_DIR)/iotrmi/C++/sample/CallBack_Skeleton.out --std=c++11
        #$(G++) iotrmi/C++/sample/TestClass.cpp -o $(BIN_DIR)/iotrmi/C++/sample/TestClass.out --std=c++11
-       $(G++) iotrmi/C++/sample/TestClass_Stub.cpp -o $(BIN_DIR)/iotrmi/C++/sample/TestClass_Stub.out --std=c++11 -pthread
-       $(G++) iotrmi/C++/sample/TestClass_Skeleton.cpp -o $(BIN_DIR)/iotrmi/C++/sample/TestClass_Skeleton.out --std=c++11 -pthread
+#      $(G++) iotrmi/C++/sample/TestClass_Stub.cpp -o $(BIN_DIR)/iotrmi/C++/sample/TestClass_Stub.out --std=c++11 -pthread
+#      $(G++) iotrmi/C++/sample/TestClass_Skeleton.cpp -o $(BIN_DIR)/iotrmi/C++/sample/TestClass_Skeleton.out --std=c++11 -pthread
        #$(G++) iotrmi/C++/sample/Test.cpp -o ../bin/iotrmi/C++/sample/Test.out --std=c++11 -lpthread
        #$(G++) iotrmi/C++/sample/Test2.cpp -o ../bin/iotrmi/C++/sample/Test2.out --std=c++11 -pthread -pg
 #      $(G++) iotrmi/C++/sample/StructC.cpp -o ../bin/iotrmi/C++/sample/StructC.out --std=c++11
+#      $(G++) iotrmi/C++/sample/EnumC.cpp -o ../bin/iotrmi/C++/sample/EnumC.out --std=c++11
 
 
 PHONY += run-rmiserver
diff --git a/iotjava/iotrmi/C++/sample/EnumC.cpp b/iotjava/iotrmi/C++/sample/EnumC.cpp
new file mode 100644 (file)
index 0000000..089a145
--- /dev/null
@@ -0,0 +1,24 @@
+#include <iostream>
+#include <vector>
+#include "EnumC.hpp"
+
+int main(int argc, char *argv[]) {
+
+       // Enum to integer
+       EnumC en = APPLE;
+       int enum1 = (int) en;
+       cout << "Enum 1: " << enum1 << endl;
+       EnumC en2 = ORANGE;
+       int enum2 = (int) en2;
+       cout << "Enum 2: " << enum2 << endl;
+       EnumC en3 = GRAPE;
+       int enum3 = (int) en3;
+       cout << "Enum 3: " << enum3 << endl;
+
+       // Integer to enum
+       cout << "Enum 1: " << (EnumC) enum1 << endl;
+       cout << "Enum 2: " << (EnumC) enum2 << endl;
+       cout << "Enum 3: " << (EnumC) enum3 << endl;
+
+       return 0;
+}
diff --git a/iotjava/iotrmi/C++/sample/EnumC.hpp b/iotjava/iotrmi/C++/sample/EnumC.hpp
new file mode 100644 (file)
index 0000000..529ae73
--- /dev/null
@@ -0,0 +1,13 @@
+#ifndef _ENUMC_HPP__
+#define _ENUMC_HPP__
+
+using namespace std;
+
+enum EnumC {
+       APPLE,
+       ORANGE,
+       GRAPE
+} enumC;
+
+#endif
+
index f8b9ffb154d7d26b135b059978c5bd93cd6652f8..3bb8f933d42d706bbd5758cee78285d537037a18 100644 (file)
@@ -24,6 +24,7 @@ class TestClass : public TestClassInterface {
                void                            registerCallback(vector<CallBackInterface*> _cb);
                int                                     callBack();
                void                            handleStruct(vector<data> vecData);
+               void                            handleEnum(vector<EnumC> vecEn);
 
        private:                
                int                                                     intA;
@@ -136,6 +137,14 @@ void TestClass::handleStruct(vector<data> vecData) {
 }
 
 
+void TestClass::handleEnum(vector<EnumC> vecEn) {
+
+       for (EnumC en : vecEn) {
+               cout << "Enum: " << en << endl;
+       }
+}
+
+
 //int TestClass::callBack() {
 //     return cb.printInt();
 //}
index ed73f1e32886d6d870142b135cbca6980a72147e..86dd37bdc190591a4f168513fa9bb4fce1beff59 100644 (file)
@@ -5,6 +5,7 @@
 #include <vector>
 #include "CallBackInterface.hpp"
 #include "StructC.hpp"
+#include "EnumC.hpp"
 
 using namespace std;
 
@@ -21,6 +22,7 @@ class TestClassInterface {
                virtual void    registerCallback(vector<CallBackInterface*> _cb) = 0;
                virtual int             callBack() = 0;
                virtual void    handleStruct(vector<data> vecData) = 0;
+               virtual void    handleEnum(vector<EnumC> vecEn) = 0;
 };
 
 #endif
index f8bf9bf0a293a1ba82f77598317ffcaa14422e0b..28bf1570c6288d18883db1a6f2393d4dd6aa7850 100644 (file)
@@ -26,6 +26,7 @@ class TestClass_Skeleton : public TestClassInterface {
                void                    registerCallback(vector<CallBackInterface*> _cb);
                int                             callBack();
                void                    handleStruct(vector<data> vecData);
+               void                    handleEnum(vector<EnumC> vecEn);
                
                void                    ___setA();
                void                    ___setB();
@@ -42,6 +43,8 @@ class TestClass_Skeleton : public TestClassInterface {
                // For array of structs
                int                             ___structSize();
                void                    ___handleStruct(int structsize1);
+               int                             ___enumSize();
+               void                    ___handleEnum(int enumsize1);
 
                const static int        size = 12;
                const static string methodSignatures[size];
@@ -286,6 +289,12 @@ void TestClass_Skeleton::___callBack() {
 }
 
 
+void TestClass_Skeleton::handleStruct(vector<data> vecData) {
+
+       tc->handleStruct(vecData);
+}
+
+
 int TestClass_Skeleton::___structSize() {
 
        string paramCls[] = { "int" };
@@ -297,12 +306,6 @@ int TestClass_Skeleton::___structSize() {
 }
 
 
-void TestClass_Skeleton::handleStruct(vector<data> vecData) {
-
-       tc->handleStruct(vecData);
-}
-
-
 void TestClass_Skeleton::___handleStruct(int structsize1) {
 
        string paramCls[3*structsize1];
@@ -333,9 +336,47 @@ void TestClass_Skeleton::___handleStruct(int structsize1) {
 }
 
 
+void TestClass_Skeleton::handleEnum(vector<EnumC> vecEn) {
+
+       tc->handleEnum(vecEn);
+}
+
+
+int TestClass_Skeleton::___enumSize() {
+
+       string paramCls[] = { "int" };
+       int numParam = 1;
+       int param1 = 0;
+       void* paramObj[] = { &param1 };
+       rmiObj->getMethodParams(paramCls, numParam, paramObj);
+       return param1;
+}
+
+
+void TestClass_Skeleton::___handleEnum(int enumsize1) {
+
+       string paramCls[enumsize1];
+       void* paramObj[enumsize1];
+       int numParam = enumsize1;
+       // define array of everything
+       int param1[enumsize1];
+       for(int i=0; i < enumsize1; i++) {
+               paramCls[i] = "int";
+               paramObj[i] = &param1[i];
+       }
+       rmiObj->getMethodParams(paramCls, numParam, paramObj);
+       vector<EnumC> en(enumsize1);
+       for (int i=0; i < enumsize1; i++) {
+               en[i] = (EnumC) param1[i];
+       }
+       handleEnum(en);
+}
+
+
 void TestClass_Skeleton::___waitRequestInvokeMethod() {
 
        int structsize1 = 0;
+       int enumsize1 = 0;
        // Loop continuously waiting for incoming bytes
        while (true) {
 
@@ -357,6 +398,8 @@ void TestClass_Skeleton::___waitRequestInvokeMethod() {
                        // Handle struct
                        case 10: ___handleStruct(structsize1); break;
                        case 11: structsize1 = ___structSize(); break;
+                       case 12: ___handleEnum(enumsize1); break;
+                       case 13: enumsize1 = ___enumSize(); break;
                        default:
                                string error = "Method Id not recognized!";
                                throw error;
index 4067dcb66fd9ca533cd5ab602db82ac9a6debef2..1d5049b2e83476ef00e9a6113c72c2f6a481cad7 100644 (file)
@@ -30,7 +30,7 @@ int main(int argc, char *argv[])
 
        cout << "Return value: " << tcStub->sumArray(input) << endl;
        
-       CallBackInterface *cb1 = new CallBack(23);
+       /*CallBackInterface *cb1 = new CallBack(23);
        CallBackInterface *cb2 = new CallBack(33);
        CallBackInterface *cb3 = new CallBack(43);
        vector<CallBackInterface*> cb;
@@ -60,7 +60,14 @@ int main(int argc, char *argv[])
        delete tcStub;
        delete cb1;
        delete cb2;
-       delete cb3;
+       delete cb3;*/
+
+       vector<EnumC> vecEn;
+       vecEn.push_back(APPLE);
+       vecEn.push_back(ORANGE);
+       vecEn.push_back(APPLE);
+       vecEn.push_back(GRAPE);
+       tcStub->handleEnum(vecEn);
 
        return 0;
 }
index 1a623f165cc83c63ff9ea2d5cb8834dafac78723..63457fe69fefa006d51499c91da0c911c1d8b35f 100644 (file)
@@ -28,6 +28,7 @@ class TestClass_Stub : public TestClassInterface {
                void                            registerCallback(vector<CallBackInterface*>_cb);
                int                                     callBack();
                void                            handleStruct(vector<data> vecData);
+               void                            handleEnum(vector<EnumC> vecEn);
                void                            ____init_CallBack();    // thread
                void                            ____registerCallBack(); // tell the other side that we are ready
 
@@ -298,9 +299,37 @@ void TestClass_Stub::handleStruct(vector<data> vecData) {
                paramObj2[pos] = &vecData[i].year; pos++;
        }
        void* retObj2 = NULL;
-       cout << "In handle struct 3!" << endl;
        rmiCall->remoteCall(objectId, methodId2, retType2, paramCls2, paramObj2, numParam2, retObj2);
 }
 
 
+void TestClass_Stub::handleEnum(vector<EnumC> vecEn) {
+
+       int numParam = 1;
+       int methodId = 13;
+       string retType = "void";
+       string paramCls[] = { "int" };
+       int enumsize = vecEn.size();
+       void* paramObj[] = { &enumsize };
+       void* retObj = NULL;
+       rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
+
+       int numParam2 = vecEn.size();
+       int methodId2 = 12;
+       string retType2 = "void";
+       string paramCls2[numParam2];
+       // Need to define this container for integer version of enum
+       int paramEnum[numParam2];
+       void* paramObj2[numParam2];
+       for(int i = 0; i < vecEn.size(); i++) {
+               paramCls2[i] = "int";
+               paramEnum[i] = (int) vecEn[i]; // cast enum to integer
+               paramObj2[i] = &paramEnum[i];
+       }
+       void* retObj2 = NULL;
+       rmiCall->remoteCall(objectId, methodId2, retType2, paramCls2, paramObj2, numParam2, retObj2);
+}
+
+
+
 #endif
index 842547df8f5ff1b3ca956026b00bfc5d599ed43e..b84b10a5a0d3d8703dced5229813d9bc8457992e 100644 (file)
@@ -47,7 +47,7 @@ public class IoTRMICall {
        /**
         * remoteCall() calls a method remotely by passing in parameters and getting a return Object
         */
-       public synchronized Object remoteCall(int objectId, int methodId, Class<?> retType, Class<?> retGenTypeKey, 
+       public synchronized Object remoteCall(int objectId, int methodId, Class<?> retType, 
                        Class<?> retGenTypeVal, Class<?>[] paramCls, Object[] paramObj) {
 
                // Send method info
@@ -69,7 +69,7 @@ public class IoTRMICall {
                                throw new Error("IoTRMICall: Error when receiving bytes - rmiClient.receiveBytes()");
                        }
                        System.out.println("Return object bytes: " + Arrays.toString(retObjBytes));
-                       retObj = IoTRMIUtil.getParamObject(retType, retGenTypeKey, retGenTypeVal, retObjBytes);
+                       retObj = IoTRMIUtil.getParamObject(retType, retGenTypeVal, retObjBytes);
                }
                return retObj;
        }
@@ -142,19 +142,6 @@ public class IoTRMICall {
                Boolean[] c2 = (Boolean[]) IoTRMIUtil.getParamObjectArray(Boolean[].class, b2);
                System.out.println(Arrays.toString(c2));
 
-               // Set
-               /*Set<String> set = new HashSet<String>();
-               set.add("1234");
-               set.add("5678");
-
-               byte[] objBytes = IoTRMIUtil.getObjectBytes(set);
-               System.out.println(Arrays.toString(objBytes));
-               Object obj = IoTRMIUtil.getParamObject(Set.class, null, String.class, objBytes);
-
-               @SuppressWarnings("unchecked")
-               Set<String> setStr = (Set<String>) obj;
-               System.out.println("Set: " + setStr.toString());*/
-
                // List
                /*List<Long> list = new ArrayList<Long>();
                list.add(12345678l);
@@ -169,19 +156,6 @@ public class IoTRMICall {
                List<Long> listStr = (List<Long>) obj;
                System.out.println("List: " + listStr.toString());*/
 
-               // Map
-               Map<Long,Integer> map = new HashMap<Long,Integer>();
-               map.put(12345678l, 1234);
-               map.put(23455432l, 5678);
-               map.put(34566543l, 4321);
-
-               byte[] objBytes = IoTRMIUtil.getObjectBytes(map);
-               System.out.println(Arrays.toString(objBytes));
-               Object obj = IoTRMIUtil.getParamObject(Map.class, Long.class, Integer.class, objBytes);
-
-               map = (Map<Long,Integer>) obj;
-               System.out.println("Received map: " + map.toString());
-
                //@SuppressWarnings("unchecked")
                //List<Long> listStr = (List<Long>) obj;
                //System.out.println("List: " + listStr.toString());
index e801e44530bcf59de21bb1e8c147f20c474bcb5e..42e778b849943373b8402aac3b2817494148fb66 100644 (file)
@@ -132,7 +132,7 @@ public class IoTRMIObject {
         * | 32-bit object ID | 32-bit method ID | 32-bit length | n-bit actual data | ...
         * 
         */
-       public Object[] getMethodParams(Class<?>[] arrCls, Class<?>[] arrGenKeyCls, Class<?>[] arrGenValCls) {
+       public Object[] getMethodParams(Class<?>[] arrCls, Class<?>[] arrGenValCls) {
 
                // Byte scanning position
                int pos = IoTRMIUtil.OBJECT_ID_LEN + IoTRMIUtil.METHOD_ID_LEN;
@@ -152,8 +152,7 @@ public class IoTRMIObject {
                        byte[] paramBytes = new byte[paramSize];
                        System.arraycopy(methodBytes, pos, paramBytes, 0, paramSize);
                        pos = pos + paramSize;
-                       paramObj[i] = IoTRMIUtil.getParamObject(arrCls[i], arrGenKeyCls[i], 
-                               arrGenValCls[i], paramBytes);
+                       paramObj[i] = IoTRMIUtil.getParamObject(arrCls[i], arrGenValCls[i], paramBytes);
                }
 
                return paramObj;
index e1c1be8cc40c58db06f370d693e545b88b3f9157..bcb2975298134d3a4f933104f3c6e10d281bcb05 100644 (file)
@@ -162,7 +162,7 @@ public class IoTRMIUtil {
        /**
         * getParamObject() converts byte array of certain object type into Object
         */
-       public static Object getParamObject(Class<?> type, Class<?> genTypeKey, Class<?> genTypeVal, byte[] paramBytes) {
+       public static Object getParamObject(Class<?> type, Class<?> genTypeVal, byte[] paramBytes) {
                
                Object retObj = null;
                if (type == byte.class ||
@@ -194,17 +194,9 @@ public class IoTRMIUtil {
                // Array
                } else if (type.isArray()) {
                        retObj = getParamObjectArray(type, paramBytes);
-               // Set
-               // e.g. Set<String> - type = Set.class, genTypeVal = String.class
-               /*} else if (type == Set.class) {
-                       retObj = getParamSetObject(genTypeVal, paramBytes);*/
                // List
                } else if (type == List.class) {
                        retObj = getParamListObject(genTypeVal, paramBytes);
-               // Map
-               // e.g. Map<String,Integer> - type = Map.class, genTypeKey = String.class, genTypeVal = Integer.class
-               /*} else if (type == Map.class) {
-                       retObj = getParamMapObject(genTypeKey, genTypeVal, paramBytes);*/
                } else
                        throw new Error("IoTRMIUtil: Unrecognizable type: " + type.getName());
                
index cb6b9d8f390453fde903be2d396434d6503c3a0b..0e01eba2619aac8d3f2a37f9c9be46a90324fd6b 100644 (file)
@@ -47,7 +47,7 @@ public class CallBack_CBSkeleton implements CallBackInterface {
        
        public void ___setInt(IoTRMIObject rmiObj) {
                Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class }, 
-                       new Class<?>[] { null }, new Class<?>[] { null });
+                       new Class<?>[] { null });
                setInt((int) paramObj[0]);
        }
        
index 9c733e56b0439b70773e2313111b6ea9da32477b..1278d6ec7f99ec9a79c5403736707b73d2fafddc 100644 (file)
@@ -40,7 +40,7 @@ public class CallBack_CBStub implements CallBackInterface {
                Class<?> retType = int.class;
                Class<?>[] paramCls = new Class<?>[] { };
                Object[] paramObj = new Object[] { };
-               Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, null, paramCls, paramObj);
+               Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
                return (int)retObj;
        }
 
@@ -51,7 +51,7 @@ public class CallBack_CBStub implements CallBackInterface {
                Class<?> retType = void.class;
                Class<?>[] paramCls = new Class<?>[] { int.class };
                Object[] paramObj = new Object[] { _i };
-               rmiCall.remoteCall(objectId, methodId, retType, null, null, paramCls, paramObj);
+               rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
        }
 
 
index 3d540f194821e81ecc425c6202c45fb630cb7ad1..77a3c815f452fb9d5aabb4a4b393789fea45bc75 100644 (file)
@@ -44,7 +44,7 @@ public class CallBack_Skeleton implements CallBackInterface {
        
        public void ___setInt() {
                Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class }, 
-                       new Class<?>[] { null }, new Class<?>[] { null });
+                       new Class<?>[] { null });
                setInt((int) paramObj[0]);
        }
        
index 04dc0d97c2cbe48bd20f95bcd0c99b2d15ba5926..8eb2acb6b643af2165141bade2bd8338876c3c08 100644 (file)
@@ -27,7 +27,7 @@ public class CallBack_Stub implements CallBackInterface {
                Class<?> retType = int.class;
                Class<?>[] paramCls = new Class<?>[] { };
                Object[] paramObj = new Object[] { };
-               Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, null, paramCls, paramObj);
+               Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
                return (int)retObj;
        }
 
@@ -38,7 +38,7 @@ public class CallBack_Stub implements CallBackInterface {
                Class<?> retType = void.class;
                Class<?>[] paramCls = new Class<?>[] { int.class };
                Object[] paramObj = new Object[] { _i };
-               rmiCall.remoteCall(objectId, methodId, retType, null, null, paramCls, paramObj);
+               rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
        }
 
 
diff --git a/iotjava/iotrmi/Java/sample/EnumJ.java b/iotjava/iotrmi/Java/sample/EnumJ.java
new file mode 100644 (file)
index 0000000..2601c3d
--- /dev/null
@@ -0,0 +1,8 @@
+package iotrmi.Java.sample;
+
+public enum EnumJ {
+
+       APPLE,
+       ORANGE,
+       GRAPE
+}
diff --git a/iotjava/iotrmi/Java/sample/EnumMain.java b/iotjava/iotrmi/Java/sample/EnumMain.java
new file mode 100644 (file)
index 0000000..7fcdc49
--- /dev/null
@@ -0,0 +1,21 @@
+package iotrmi.Java.sample;
+
+public class EnumMain {
+
+       public static void main (String[] args) {
+
+               // Enum to int
+               int enum1 = EnumJ.APPLE.ordinal();
+               System.out.println("Enum 1: " + enum1);
+               int enum2 = EnumJ.ORANGE.ordinal();
+               System.out.println("Enum 2: " + enum2);
+               int enum3 = EnumJ.GRAPE.ordinal();
+               System.out.println("Enum 3: " + enum3);
+
+               // Int to enum
+               EnumJ[] enumJ = EnumJ.values();
+               System.out.println("Enum 1: " + enumJ[enum1]);
+               System.out.println("Enum 1: " + enumJ[enum2]);
+               System.out.println("Enum 1: " + enumJ[enum3]);
+       }
+}
index c1c397f5792de1dbde1a5b19a7833059e8781b81..95dbb1b7ea4f343809746e46a8c99e1f6a3f6884 100644 (file)
@@ -155,6 +155,14 @@ public class TestClass implements TestClassInterface {
        }
 
 
+       public void handleEnum(EnumJ[] en) {
+
+               for (EnumJ e : en) {
+                       System.out.println("Enum: " + e);
+               }
+       }
+
+
        public static void main(String[] args) {
 
                //TestClass tc = new TestClass();
index 9d46df586a2faef70e3e6f12dd225d99c9457be7..aa76ea03205a696b0e490b0d0c71979c32f9de2e 100644 (file)
@@ -14,4 +14,5 @@ public interface TestClassInterface {
        public void registerCallback(CallBackInterface[] _cb);
        public int callBack();
        public void handleStruct(StructJ[] data);
+       public void handleEnum(EnumJ[] en);
 }
index ce2b1b78691b9874d5cf108908cd079d30911339..9ff3b1833a83ac4e173c935ef637ec771bbfe618 100644 (file)
@@ -46,7 +46,7 @@ public class TestClass_Skeleton implements TestClassInterface {
        public void ___setA() {
 
                Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class }, 
-                       new Class<?>[] { null }, new Class<?>[] { null });
+                       new Class<?>[] { null });
                setA((int) paramObj[0]);
        }
        
@@ -60,7 +60,7 @@ public class TestClass_Skeleton implements TestClassInterface {
        public void ___setB() {
 
                Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { float.class }, 
-                       new Class<?>[] { null }, new Class<?>[] { null });
+                       new Class<?>[] { null });
                setB((float) paramObj[0]);
        }
        
@@ -74,7 +74,7 @@ public class TestClass_Skeleton implements TestClassInterface {
        public void ___setC() {
                
                Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { String.class }, 
-                       new Class<?>[] { null }, new Class<?>[] { null });
+                       new Class<?>[] { null });
                setC((String) paramObj[0]);
        }
        
@@ -88,7 +88,7 @@ public class TestClass_Skeleton implements TestClassInterface {
        public void ___sumArray() throws IOException {
                
                Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { String[].class }, 
-                       new Class<?>[] { null }, new Class<?>[] { null });
+                       new Class<?>[] { null });
                Object retObj = sumArray((String[]) paramObj[0]);
                rmiObj.sendReturnObj(retObj);
        }
@@ -103,7 +103,7 @@ public class TestClass_Skeleton implements TestClassInterface {
        public void ___setAndGetA() throws IOException {
                
                Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class }, 
-                       new Class<?>[] { null }, new Class<?>[] { null });
+                       new Class<?>[] { null });
                Object retObj = setAndGetA((int) paramObj[0]);
                rmiObj.sendReturnObj(retObj);
        }
@@ -118,7 +118,7 @@ public class TestClass_Skeleton implements TestClassInterface {
        public void ___setACAndGetA() throws IOException {
                
                Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { String.class, int.class }, 
-                       new Class<?>[] { null, null }, new Class<?>[] { null, null });
+                       new Class<?>[] { null, null });
                Object retObj = setACAndGetA((String) paramObj[0], (int) paramObj[1]);
                rmiObj.sendReturnObj(retObj);
        }
@@ -133,7 +133,7 @@ public class TestClass_Skeleton implements TestClassInterface {
        public void ___registerCallback() throws IOException {
                
                Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class, String.class, int.class }, 
-                       new Class<?>[] { null, null, null }, new Class<?>[] { null, null, null });
+                       new Class<?>[] { null, null, null });
                CallBackInterface cbstub = new CallBack_Stub((int) paramObj[0], (String) paramObj[1], (int) paramObj[2]);
                registerCallback((CallBackInterface) cbstub);
        }
@@ -149,7 +149,7 @@ public class TestClass_Skeleton implements TestClassInterface {
        public void ____registerCallback() throws IOException {
                
                Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class }, 
-                       new Class<?>[] { null }, new Class<?>[] { null });
+                       new Class<?>[] { null });
                int numStubs = (int) paramObj[0];
                CallBackInterface[] stub = new CallBackInterface[numStubs];
                for (int objId = 0; objId < numStubs; objId++) {
@@ -163,7 +163,7 @@ public class TestClass_Skeleton implements TestClassInterface {
        public void ___regCB() throws IOException {
                
                Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class, String.class, int.class }, 
-                       new Class<?>[] { null, null, null }, new Class<?>[] { null, null, null });
+                       new Class<?>[] { null, null, null });
                //String[] methodSignatures = CallBack_CBStub.getMethodSignatures();
                rmiCall = new IoTRMICall((int) paramObj[0], (String) paramObj[1], (int) paramObj[2]);
                System.out.println("Creating a new IoTRMICall object");
@@ -192,7 +192,7 @@ public class TestClass_Skeleton implements TestClassInterface {
        public int ___structSize() {
                
                Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class }, 
-                       new Class<?>[] { null }, new Class<?>[] { null });
+                       new Class<?>[] { null });
                return (int) paramObj[0];
        }
        
@@ -200,22 +200,18 @@ public class TestClass_Skeleton implements TestClassInterface {
        public void ___handleStruct(int structsize1) {
 
                Class<?>[] paramCls = new Class<?>[3*structsize1];
-               Class<?>[] paramClsTyp1 = new Class<?>[3*structsize1];
-               Class<?>[] paramClsTyp2 = new Class<?>[3*structsize1];
+               Class<?>[] paramClsVal = new Class<?>[3*structsize1];
                int pos = 0;
                for(int i=0; i < structsize1; i++) {
                        paramCls[pos] = String.class;
-                       paramClsTyp1[pos] = null;
-                       paramClsTyp2[pos++] = null;
+                       paramClsVal[pos++] = null;
                        paramCls[pos] = float.class;
-                       paramClsTyp1[pos] = null;
-                       paramClsTyp2[pos++] = null;
+                       paramClsVal[pos++] = null;
                        paramCls[pos] = int.class;
-                       paramClsTyp1[pos] = null;
-                       paramClsTyp2[pos++] = null;
+                       paramClsVal[pos++] = null;
                }
                Object[] paramObj = rmiObj.getMethodParams(paramCls, 
-                       paramClsTyp1, paramClsTyp2);
+                       paramClsVal);
                StructJ[] data = new StructJ[structsize1];
                for (int i=0; i < structsize1; i++) {
                        data[i] = new StructJ();
@@ -228,12 +224,47 @@ public class TestClass_Skeleton implements TestClassInterface {
                }
                tc.handleStruct(data);
        }
+
+
+       public void handleEnum(EnumJ[] en) {
+
+               tc.handleEnum(en);
+       }
+
+
+       public int ___enumSize() {
+               
+               Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class }, 
+                       new Class<?>[] { null });
+               return (int) paramObj[0];
+       }
+
+
+       public void ___handleEnum(int enumSize1) {
+
+               Class<?>[] paramCls = new Class<?>[enumSize1];
+               Class<?>[] paramClsVal = new Class<?>[enumSize1];
+               for(int i=0; i < enumSize1; i++) {
+                       paramCls[i] = int.class;
+                       paramClsVal[i] = null;
+               }
+               Object[] paramObj = rmiObj.getMethodParams(paramCls, 
+                       paramClsVal);
+               // Encoder/decoder
+               EnumJ[] enumJ = EnumJ.values();
+               EnumJ[] data = new EnumJ[enumSize1];
+               for (int i=0; i < enumSize1; i++) {
+                       data[i] = enumJ[(int) paramObj[i]];
+               }
+               tc.handleEnum(data);
+       }
        
 
        private void ___waitRequestInvokeMethod() throws IOException {
 
                // Struct size
-               int structsize1 = 0;
+               int structSize1 = 0;
+               int enumSize1 = 0;
                // Loop continuously waiting for incoming bytes
                while (true) {
 
@@ -256,8 +287,10 @@ public class TestClass_Skeleton implements TestClassInterface {
                                        // Special option to register callback
                                        case 9: ___regCB(); break;
                                        // Struct handling (3 is the size of the struct)
-                                       case 10: ___handleStruct(structsize1); break;
-                                       case 11: structsize1 = ___structSize(); break;
+                                       case 10: ___handleStruct(structSize1); break;
+                                       case 11: structSize1 = ___structSize(); break;
+                                       case 12: ___handleEnum(enumSize1); break;
+                                       case 13: enumSize1 = ___enumSize(); break;
                                        default:
                                                throw new Error("Method Id not recognized!");
                                }
index c1f03c60701668dea9c9e0ab7f7e66516e070f17..a907ff7a5d37e9f73d81af61d7549aa1cb253186 100644 (file)
@@ -85,7 +85,7 @@ public class TestClass_Stub implements TestClassInterface {
                Class<?>[] paramCls = new Class<?>[] { int.class, String.class, int.class };
                Object[] paramObj = new Object[] { ports[0], address, 0 };
                //rmiCall.remoteCall(objectId, sign, retType, null, null, paramCls, paramObj);
-               rmiCall.remoteCall(objectId, methodId, retType, null, null, paramCls, paramObj);
+               rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
        }
 
 
@@ -133,7 +133,7 @@ public class TestClass_Stub implements TestClassInterface {
                Class<?>[] paramCls = new Class<?>[] { int.class };
                Object[] paramObj = new Object[] { _cb.length };
                //rmiCall.remoteCall(objectId, sign, retType, null, null, paramCls, paramObj);
-               rmiCall.remoteCall(objectId, methodId, retType, null, null, paramCls, paramObj);
+               rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
        }
 
 
@@ -144,7 +144,7 @@ public class TestClass_Stub implements TestClassInterface {
                Class<?> retType = void.class;
                Class<?>[] paramCls = new Class<?>[] { int.class };
                Object[] paramObj = new Object[] { _int };
-               rmiCall.remoteCall(objectId, methodId, retType, null, null, paramCls, paramObj);
+               rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
        }
 
 
@@ -154,7 +154,7 @@ public class TestClass_Stub implements TestClassInterface {
                Class<?> retType = void.class;
                Class<?>[] paramCls = new Class<?>[] { float.class };
                Object[] paramObj = new Object[] { _float };
-               rmiCall.remoteCall(objectId, methodId, retType, null, null, paramCls, paramObj);
+               rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
        }
 
 
@@ -164,7 +164,7 @@ public class TestClass_Stub implements TestClassInterface {
                Class<?> retType = void.class;
                Class<?>[] paramCls = new Class<?>[] { String.class };
                Object[] paramObj = new Object[] { _string };
-               rmiCall.remoteCall(objectId, methodId, retType, null, null, paramCls, paramObj);
+               rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
        }
 
 
@@ -175,7 +175,7 @@ public class TestClass_Stub implements TestClassInterface {
                Class<?> retType = String.class;
                Class<?>[] paramCls = new Class<?>[] { String[].class };
                Object[] paramObj = new Object[] { newA };
-               Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, null, paramCls, paramObj);
+               Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
                return (String)retObj;
        }
 
@@ -185,7 +185,7 @@ public class TestClass_Stub implements TestClassInterface {
                Class<?> retType = int.class;
                Class<?>[] paramCls = new Class<?>[] { int.class };
                Object[] paramObj = new Object[] { newA };
-               Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, null, paramCls, paramObj);
+               Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
                return (int)retObj;
        }
 
@@ -196,7 +196,7 @@ public class TestClass_Stub implements TestClassInterface {
                Class<?> retType = int.class;
                Class<?>[] paramCls = new Class<?>[] { String.class, int.class };
                Object[] paramObj = new Object[] { newC, newA };
-               Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, null, paramCls, paramObj);
+               Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
                return (int)retObj;
        }
 
@@ -207,7 +207,7 @@ public class TestClass_Stub implements TestClassInterface {
                Class<?> retType = int.class;
                Class<?>[] paramCls = new Class<?>[] { };
                Object[] paramObj = new Object[] { };
-               Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, null, paramCls, paramObj);
+               Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
                return (int)retObj;
 
        }
@@ -219,7 +219,7 @@ public class TestClass_Stub implements TestClassInterface {
                Class<?> retType = void.class;
                Class<?>[] paramCls = new Class<?>[] { int.class };
                Object[] paramObj = new Object[] { data.length };
-               rmiCall.remoteCall(objectId, methodId, retType, null, null, paramCls, paramObj);
+               rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
 
                int methodId2 = 10;
                Class<?> retType2 = void.class;
@@ -237,7 +237,31 @@ public class TestClass_Stub implements TestClassInterface {
                        paramObj2[pos++] = data[i].year;
                }
                System.out.println(Arrays.toString(paramObj2));
-               rmiCall.remoteCall(objectId, methodId2, retType2, null, null, paramCls2, paramObj2);
+               rmiCall.remoteCall(objectId, methodId2, retType2, null, paramCls2, paramObj2);
+       }
+
+
+       public void handleEnum(EnumJ[] en) {
+
+               // Send length info first
+               int methodId = 13;
+               Class<?> retType = void.class;
+               Class<?>[] paramCls = new Class<?>[] { int.class };
+               Object[] paramObj = new Object[] { en.length };
+               rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
+
+               int methodId2 = 12;
+               Class<?> retType2 = void.class;
+               // Calculate the size of the array
+               Class<?>[] paramCls2 = new Class<?>[en.length];
+               Object[] paramObj2 = new Object[en.length];
+               // Handle with for loop
+               for(int i = 0; i < en.length; i++) {
+                       paramCls2[i] = int.class;
+                       paramObj2[i] = en[i].ordinal();
+               }
+               System.out.println(Arrays.toString(paramObj2));
+               rmiCall.remoteCall(objectId, methodId2, retType2, null, paramCls2, paramObj2);          
        }
 
 
@@ -287,8 +311,11 @@ public class TestClass_Stub implements TestClassInterface {
                        System.out.println("Value: " + str.value);
                        System.out.println("Year: " + str.year);
                }
-
                tcstub.handleStruct(data);
+
+               EnumJ[] en = { EnumJ.APPLE, EnumJ.ORANGE, EnumJ.APPLE, EnumJ.GRAPE };
+               tcstub.handleEnum(en);
+
        }
 }