// Generate array of parameter types
print("Class<?>[] paramCls = new Class<?>[] { ");
for (int i = 0; i < methParams.size(); i++) {
- print(getSimpleType(methPrmTypes.get(i)) + ".class");
+ String paramType = checkAndGetArray(methPrmTypes.get(i), methParams.get(i));
+ print(getSimpleType(paramType) + ".class");
// Check if this is the last element (don't print a comma)
if (i != methParams.size() - 1) {
print(", ");
// Generate array of parameter types
print("string paramCls[] = { ");
for (int i = 0; i < methParams.size(); i++) {
- print("\"" + checkAndGetCplusType(methPrmTypes.get(i)) + "\"");
+ String paramType = checkAndGetArray(methPrmTypes.get(i), methParams.get(i));
+ print("\"" + getSimpleType(paramType) + "\"");
// Check if this is the last element (don't print a comma)
if (i != methParams.size() - 1) {
print(", ");
}
+ // Detect array declaration, e.g. int A[],
+ // then generate type "int[]"
+ private String checkAndGetArray(String paramType, String param) {
+
+ String paramTypeRet = null;
+ // Check for array declaration
+ if (param.contains("[]")) {
+ paramTypeRet = paramType + "[]";
+ } else
+ // Just return it as is if it's not an array
+ paramTypeRet = paramType;
+
+ return paramTypeRet;
+ }
+
+
// Get simple types, e.g. HashSet for HashSet<...>
// Basically strip off the "<...>"
private String checkAndGetParamClass(String paramType, boolean needPtr) {
}
+ /**
+ * static version of getMethodId()
+ */
+ public static int getMethodId(byte[] methodBytes) {
+
+ // Get method Id bytes
+ byte[] methodIdBytes = new byte[IoTRMIUtil.METHOD_ID_LEN];
+ // Method Id is positioned after object Id in the byte array
+ System.arraycopy(methodBytes, IoTRMIUtil.OBJECT_ID_LEN, methodIdBytes, 0, IoTRMIUtil.METHOD_ID_LEN);
+ // Get method Id
+ int methodId = IoTRMIUtil.byteArrayToInt(methodIdBytes);
+ // Get method Id
+ return methodId;
+ }
+
+
/**
* getMethodParams() gets method params based on byte array received
* <p>
public class CallBack_CBSkeleton implements CallBackInterface {
private int objectId = 0; // Default value is 0
- private final static String[] methodSignatures = {
-
- "intprintInt()",
- "voidsetInt(int)"
- };
private CallBackInterface cb;
}
- // Return method signatures
- public static String[] getMethodSignatures() {
-
- return methodSignatures;
- }
-
-
public static void main(String[] args) throws Exception {
}
private IoTRMICall rmiCall;
private int objectId = 0; // Default value is 0
- private final static String[] methodSignatures = {
-
- "intprintInt()",
- "voidsetInt(int)"
- };
/**
* Constructors
}
- // Return method signatures
- public static String[] getMethodSignatures() {
-
- return methodSignatures;
- }
-
-
public int printInt() {
int methodId = 0;
import java.util.Map;
import java.util.HashMap;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Collections;
+
import iotrmi.Java.IoTRMIObject;
import iotrmi.Java.IoTRMICall;
/**
* Class Constants
*/
- private int objectId = 0; // Default value is 0
private static int objIdCnt = 0; // Counter for callback object Ids
private TestClassInterface tc;
private int port;
private IoTRMICall rmiCall;
private CallBackInterface cbstub;
+ // Object permission
+ private int object0Id = 0;
+ private static Integer[] object0Permission = { 0, 1, 2, 3, 4, 5 };
+ private List<Integer> set0Allowed;
+
/**
* Constructors
tc = _tc;
port = _port;
rmiObj = new IoTRMIObject(_port);
+ set0Allowed = Arrays.asList(object0Permission);
___waitRequestInvokeMethod();
}
rmiObj.getMethodBytes();
int _objectId = rmiObj.getObjectId();
- if (_objectId == objectId) {
+ int methodId = rmiObj.getMethodId();
+ if (_objectId == object0Id) {
// Multiplex based on object Id
- int methodId = rmiObj.getMethodId();
- switch (methodId) {
+ // Complain if the method is not allowed
+ if (!set0Allowed.contains(methodId))
+ throw new Error("TestClass_Skeleton: This object is not allowed to access method " + methodId);
+ // If we have more than 1 object Id...
+ //else if (_objectId == object1Id) {
+
+ } else
+ throw new Error("TestClass_Skeleton: Unrecognizable object Id: " + _objectId);
- case 0: ___setA(); break;
- case 1: ___setB(); break;
- case 2: ___setC(); break;
- case 3: ___sumArray(); break;
- case 4: ___setAndGetA(); break;
- case 5: ___setACAndGetA(); break;
- case 6: ___callBack(); break;
- case 7: ___registerCallback(); break;
- case 8: ____registerCallback(); break;
- // 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 12: ___handleEnum(); break;
- default:
- throw new Error("Method Id not recognized!");
- }
+ switch (methodId) {
+
+ case 0: ___setA(); break;
+ case 1: ___setB(); break;
+ case 2: ___setC(); break;
+ case 3: ___sumArray(); break;
+ case 4: ___setAndGetA(); break;
+ case 5: ___setACAndGetA(); break;
+ case 6: ___callBack(); break;
+ case 7: ___registerCallback(); break;
+ case 8: ____registerCallback(); break;
+ // 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 12: ___handleEnum(); break;
+ default:
+ throw new Error("Method Id not recognized!");
}
+
}
}
* Class Constants
*/
private int objectId = 0; // Default value is 0
-
+ // This is permission system for callback objects
+ private static Integer[] object0Permission = { 0, 1 }; // object0 is the callback object
+ private List<Integer> set0Allowed;
/**
* Properties and constants for Callbacks!
ports = _ports;
rmiCall = new IoTRMICall(_port, _address, _rev);
+ set0Allowed = Arrays.asList(object0Permission);
+
// Only for callbacks!!!
listCBObj = new ArrayList<CallBackInterface>();
___initCallBack();
Object retObj = null;
while (true) {
byte[] method = rmiObj.getMethodBytes();
+ // Permission checking
+ int methId = IoTRMIObject.getMethodId(method);
+ if (!set0Allowed.contains(methId))
+ throw new Error("CallBack_CBSkeleton: This object is not allowed to access method " + methId);
+
int objId = IoTRMIObject.getObjectId(method);
CallBack_CBSkeleton skel = (CallBack_CBSkeleton) listCBObj.get(objId);
if (skel != null) {