Updating the first benchmark with new stubs/skeletons; somehow motion detection is...
[iot2.git] / benchmarks / drivers / Java / AmcrestCamera / CameraSmartCallback_Stub.java
1 package iotcode.AmcrestCamera;
2
3 import java.io.IOException;
4 import java.util.List;
5 import java.util.ArrayList;
6 import java.util.Arrays;
7 import java.util.Map;
8 import java.util.HashMap;
9 import java.util.concurrent.atomic.AtomicBoolean;
10 import iotrmi.Java.IoTRMIComm;
11 import iotrmi.Java.IoTRMICommClient;
12 import iotrmi.Java.IoTRMICommServer;
13 import iotrmi.Java.IoTRMIUtil;
14
15 import iotcode.interfaces.*;
16
17 public class CameraSmartCallback_Stub implements CameraSmartCallback {
18
19         private int objectId = 0;
20         private IoTRMIComm rmiComm;
21         // Synchronization variables
22         
23
24         public CameraSmartCallback_Stub(int _localPortSend, int _localPortRecv, int _portSend, int _portRecv, String _skeletonAddress, int _rev) throws Exception {
25                 if (_localPortSend != 0 && _localPortRecv != 0) {
26                         rmiComm = new IoTRMICommClient(_localPortSend, _localPortRecv, _portSend, _portRecv, _skeletonAddress, _rev);
27                 } else
28                 {
29                         rmiComm = new IoTRMICommClient(_portSend, _portRecv, _skeletonAddress, _rev);
30                 }
31                 IoTRMIUtil.mapStub.put(objectId, this);
32         }
33
34         public CameraSmartCallback_Stub(IoTRMIComm _rmiComm, int _objectId) throws Exception {
35                 rmiComm = _rmiComm;
36                 objectId = _objectId;
37         }
38
39         public void newCameraFrameAvailable(Camera _camera) {
40                 int[] objIdSent0 = new int[1];
41                 try {
42                         if (!IoTRMIUtil.mapSkel.containsKey(_camera)) {
43                                 int newObjIdSent = rmiComm.getObjectIdCounter();
44                                 objIdSent0[0] = newObjIdSent;
45                                 rmiComm.decrementObjectIdCounter();
46                                 Camera_Skeleton skel0 = new Camera_Skeleton(_camera, rmiComm, newObjIdSent);
47                                 IoTRMIUtil.mapSkel.put(_camera, skel0);
48                                 IoTRMIUtil.mapSkelId.put(_camera, newObjIdSent);
49                                 Thread thread = new Thread() {
50                                         public void run() {
51                                                 try {
52                                                         skel0.___waitRequestInvokeMethod();
53                                                         } catch (Exception ex) {
54                                                         ex.printStackTrace();
55                                                         throw new Error("Exception when trying to run ___waitRequestInvokeMethod() for Camera_Skeleton!");
56                                                 }
57                                         }
58                                 };
59                                 thread.start();
60                                 while(!skel0.didAlreadyInitWaitInvoke());
61                         }
62                         else
63                         {
64                                 int newObjIdSent = IoTRMIUtil.mapSkelId.get(_camera);
65                                 objIdSent0[0] = newObjIdSent;
66                         }
67                 } catch (Exception ex) {
68                         ex.printStackTrace();
69                         throw new Error("Exception when generating skeleton objects!");
70                 }
71
72                 int methodId = 0;
73                 Class<?> retType = void.class;
74                 Class<?>[] paramCls = new Class<?>[] { int[].class };
75                 Object[] paramObj = new Object[] { objIdSent0 };
76                 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
77         }
78
79 }