b9b9b3b26690bf12ea1a8b46d29b0b3c47c1bdf6
[iot2.git] / benchmarks / drivers / Java / AudioRoom / Room_Skeleton.java
1 package iotcode.AudioRoom;
2
3 import java.io.IOException;
4 import java.util.List;
5 import java.util.ArrayList;
6 import java.util.Arrays;
7 import iotrmi.Java.IoTRMICall;
8 import iotrmi.Java.IoTRMIObject;
9
10 import iotcode.interfaces.Room;
11
12 public class Room_Skeleton implements Room {
13
14         private Room mainObj;
15         private IoTRMIObject rmiObj;
16
17         private String callbackAddress;
18         private final static int object0Id = 0; //RoomSmart
19         private static Integer[] object0Permission = { 0 };
20         private static List<Integer> set0Allowed;
21         
22
23         public Room_Skeleton(Room _mainObj, String _callbackAddress, int _port) throws Exception {
24                 mainObj = _mainObj;
25                 callbackAddress = _callbackAddress;
26                 rmiObj = new IoTRMIObject(_port);
27                 set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
28                 ___waitRequestInvokeMethod();
29         }
30
31         public int getRoomID() {
32                 return mainObj.getRoomID();
33         }
34
35         public void ___getRoomID() throws IOException {
36                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
37                 new Class<?>[] {  });
38                 Object retObj = getRoomID();
39                 rmiObj.sendReturnObj(retObj);
40         }
41
42         private void ___waitRequestInvokeMethod() throws IOException {
43                 while (true) {
44                         rmiObj.getMethodBytes();
45                         int _objectId = rmiObj.getObjectId();
46                         int methodId = rmiObj.getMethodId();
47                         if (_objectId == object0Id) {
48                                 if (!set0Allowed.contains(methodId)) {
49                                         throw new Error("Object with object Id: " + _objectId + "  is not allowed to access method: " + methodId);
50                                 }
51                         }
52                         else {
53                                 throw new Error("Object Id: " + _objectId + " not recognized!");
54                         }
55                         switch (methodId) {
56                                 case 0: ___getRoomID(); break;
57                                 default: 
58                                 throw new Error("Method Id " + methodId + " not recognized!");
59                         }
60                 }
61         }
62
63 }