## 4 Handling Context in FamiWare
### Putting into Practice the Mapping of Contexts in an AAL Case Study
Figure 6: (**a**) AAL feature model configuration; (**b**) Features of a sensor device. To take advantage of the benefits of reusing the FamiWare platform, the new composite context situation will be incorporated to the family. The application developer will model this context using ContextUML, and through our mapping the new context will be automatically added to FamiWare. Figure 7(a) shows the definition of this composite context (_CReduceHabits_). This context is made up of several atomic contexts, each one with its own context source service: _CTime_ (current time), _CLightDay_ (hours with light collected by a sensor along a day), _CAcc_ (accelerometer angle of the user badge) and _CAccDay_ (number of position changes, detected by the accelerometer, accumulated in a day), _CMov_ (movement detection) and _CMovWeek_ (amount of movement detected by a sensor over the last week), and _CPres_ (capability of the camera to detect the presence of a person), _CPresWeek_ and _CPresDay_ (time of person presence detection for a week or a day, respectively). The composite context also has context triggering that contains the actions to be executed when some constraints are satisfied. In our scenario, the constraints (Figure 7(a)) are considered to be true if: the current time is between _\"00h\"_ and _\"06h\"_, the user badge position is horizontal (_i.e._, the patient is lying down), the bedroom's sensor does not detect any movement, and the bedroom's camera detects the presence of a person in the room, and all these constraints detect whether the user is sleeping in the bedroom at that moment. If this happens, constraints for both the day before and weekly habits are evaluated. These constraints are the following: (1) the movement frequency of the user badge accelerometer is less than 50% with respect to the usual movement; (2) the daily hours with light detected and different sensors are below 80% of the usual hours; (3) the sensor placed just outside the bedroom detects less than 50% of the usual movements over the last week (_i.e._, user leaving the bedroom has fallen); (4) the bedroom camera detects the patient's presence in the bedroom as more than normal in a week; and (5) the rest of the cameras detect less presence frequency than the day before. When this happens some actions must be performed to reconfigure the system. Firstly, in order to save resources such as energy, some sensors (those on the floor that not correspond to the bedroom)  
Figure 7: Modeling contexts in our AAL scenario. must be in sleep mode, the frequency of the monitoring services (related to the sensors on the floor where the bedroom is) must be reduced, and the cameras located outside the bedroom must also be in sleep. Secondly, as many devices will not be sending data, the network will be extremely reduced, so the routing protocol must be exchanged for another more efficient one for a few devices, like Direct Diffusion. Finally, to control the patient correctly, the frequency of sending data from the bedroom's camera to the health center must be tripled, and a new video-conference service must be installed in the _Smartphone01_. All these elements are automatically mapped into the FamiWare feature model, by increasing the family. For every new atomic context (with its corresponding context service) that previously did not exist in the feature model, we add a new context feature, a new monitor feature, and a usage dependency between them, as seen in Figure 7(b). As FamiWare does not take into account a presence monitoring algorithm for the cameras, the _CPres_ and _Pres_ features, together with the dependency (_CPres implies Pres_) are included. The same process happens for other new contexts which did not previously exist in the feature model, such as _CAccDay_, _CMovWeek_, and so on. Therefore, all the context data values that appear in the constraints and were not contemplated in the feature model must be added under their corresponding _xor_-group (e.g., _TimeLT06 or PresTrue_).