First benchmark working with capability-based RMI; adjustments in callbacks, etc.
[iot2.git] / benchmarks / SmartLightsController / SmartLightsController.java
index f073df8f24a7b17ce5118ac5c1f97d8bc861446d..9f3ad93dd23864cbafb3752e2da2794a063633b8 100644 (file)
@@ -44,26 +44,25 @@ public class SmartLightsController {
        @config private IoTSet<LightBulbSmart> mainRoomLightBulbs;
        @config private IoTSet<CameraSmart> cameras;
 
-
        /*
         *  IoT Sets of Things that are not devices such as rooms
         */
-       @config private IoTSet<Room> rooms;
+       @config private IoTSet<RoomSmart> rooms;
 
        /*
         *  IoT Relations
         */
-       @config private IoTRelation<Room,CameraSmart> roomCameraRel;
-       @config private IoTRelation<Room,LightBulbSmart> roomMainBulbRel;
+       @config private IoTRelation<RoomSmart,CameraSmart> roomCameraRel;
+       @config private IoTRelation<RoomSmart,LightBulbSmart> roomMainBulbRel;
 
 
        /*
         *  The state that the room main lights are supposed to be in
         */
-       Map<Room, Boolean> roomLightOnOffStatus =
-               new HashMap<Room, Boolean>();
-       Map<Room, ColorTemperature> roomLightColorTemperature =
-               new HashMap<Room, ColorTemperature>();
+       Map<RoomSmart, Boolean> roomLightOnOffStatus =
+               new HashMap<RoomSmart, Boolean>();
+       Map<RoomSmart, ColorTemperature> roomLightColorTemperature =
+               new HashMap<RoomSmart, ColorTemperature>();
 
        /*
         *  Motion detectors that are bound to specific cameras
@@ -94,13 +93,13 @@ public class SmartLightsController {
        /** Method to detect if a room has seen motion within the last few seconds (time specified as parameter).
         *   Checks all the motion detectors for the given room
         *
-        *   @param _room            [Room] , Room of interest.
+        *   @param _room            [RoomSmart] , RoomSmart of interest.
         *   @param _numberOfSeconds [int]  , Number of seconds in the past that we consider recent.
         *   @param _upperThreshold  [int]  , Number of seconds as an upper bound before we turn off.
         *
         *   @return [boolean] if motion was detected recently.
         */
-       private boolean roomDidHaveMotionRecently(Room _room, int _numberOfSeconds) {
+       private boolean roomDidHaveMotionRecently(RoomSmart _room, int _numberOfSeconds) {
                long currentTimeSeconds = (new Date()).getTime() / 1000;
 
                // Loop through all the motion sensors in the room
@@ -144,7 +143,7 @@ public class SmartLightsController {
 
                long secondsSinceStartOfDay = currentTimeSeconds - (beginningOfToday.getTime() / 1000);
 
-               for (Room room : rooms.values()) {
+               for (RoomSmart room : rooms.values()) {
 
                        // before 8:30 am
                        if (secondsSinceStartOfDay <= 30600) {
@@ -249,7 +248,7 @@ public class SmartLightsController {
         */
        private void setMainBulbs() throws RemoteException {
 
-               for (Room room : rooms.values()) {
+               for (RoomSmart room : rooms.values()) {
 
                        // Lights in room should be turned off
                        if (!roomLightOnOffStatus.get(room)) {
@@ -328,9 +327,9 @@ public class SmartLightsController {
         */
        public void init() throws RemoteException, InterruptedException {
 
-
+               System.out.println("Initialized init()!");
                // Initialize the rooms
-               for (Room room : rooms.values()) {
+               for (RoomSmart room : rooms.values()) {
 
                        // All rooms start with the lights turned off
                        roomLightOnOffStatus.put(room, false);
@@ -338,7 +337,7 @@ public class SmartLightsController {
                        // All rooms have a default color and temperature
                        roomLightColorTemperature.put(room, new ColorTemperature(0, 0, 100, 2500));
                }
-
+               System.out.println("Initialized rooms!");
 
                // Setup the cameras, start them all and assign each one a motion detector
                for (CameraSmart cam : cameras.values()) {
@@ -362,13 +361,16 @@ public class SmartLightsController {
                        // Remember which motion detector is for what camera
                        camMotionDetect.put(cam, mo);
                }
-
+               System.out.println("Initialized cameras!");
 
                //Initialize the light-bulbs, will turn off the bulb
                for (LightBulbSmart bulb : mainRoomLightBulbs.values()) {
+                       System.out.println("Trying to init bulb?");
                        bulb.init();
+                       System.out.println("Done init!");
                        Thread.sleep(1000);
                }
+               System.out.println("Initialized bulbs!");
 
                // Run the main loop that will keep check the bulbs and rooms periodically
                while (true) {
@@ -379,7 +381,7 @@ public class SmartLightsController {
                                lastTimeChecked = currentTimeSeconds;
 
                                // Check for motion in rooms and if there is motion then turn on the lights
-                               for (Room room : rooms.values()) {
+                               for (RoomSmart room : rooms.values()) {
 
                                        if (roomDidHaveMotionRecently(room, MOTION_TIME_THRESHOLD)) {