Software Framework for Building Context-Aware Applications using multiFacet Items Anca Rarau, Kalman Pusztai, Ioan Salomie Computer Science Department, Technical University of Cluj-Napoca {anca.rarau, kalman.pusztai, ioan.salomie}@cs.utcluj.ro Abstract development of the context-aware applications is described in [1]. They use conditional rules to describe While on the move, the surrounding environment of the behavior of the application in different context. a mobile application may change quite often. The Cooltown [7] resorts to the web programming model. mobile applications have to be able to properly react Each real world entity has a web presence represented to the context changes. The common approach to deal by a web page. These pages are automatically updated with the application adaptation is based on rules. For when new information is collected about the entity that each action one must specify the set of rules that it represents. In [2] they use reflection in order to triggers the action when the context changes. In this achieve the application adaptation to the context approach the conflictive situations (two or more changes. contradictory actions being simultaneously performed) The common approach to deal with the application have to be considered explicitly. The goal of this paper adaptation is based on the rules [6, 8, 9]. For each is to present a software framework for building action one must specify the set of the conditions that context-aware applications. The adaptation triggers the action when the context changes. In this mechanism proposed by the framework successfully approach the conflictive situations, when two or more manages the conflictive situations without requiring contradictory actions are simultaneously performed, the explicit description of the situations. have to be explicitly considered. The goal of this paper is to present a software framework for building context-aware applications. 1. Introduction The adaptation mechanism proposed by the framework successfully manages the conflictive situations without Nowadays people expect their mobile applications requiring their explicit description. to always provide useful information or relevant The rest of the paper is organized as follows. In services within the current context. Location, nearby Section 2 we discuss the disadvantages of the classical resources, social environment, etc may give current if-then rule approach. In Section 3 we present the context. While on the move, the surrounding multiFacet abstraction. Section 4 presents the proposed environment of a mobile application may change quite software framework. In Section 5 we shortly discuss often. The mobile applications have to be able to the infrastructure that deals with the context properly react to the context changes, i.e. the management. In Section 6 we discuss the performance application has to be context-aware. Therefore while a issues. Section 7 concludes the paper. context-aware application is being built, the application has to be trained how to behave in different 2. Motivation contexts. So far, the development of the context-aware The common approach for the application applications, with few exceptions, has been done in an adaptation is the use of either explicit or implicit ‘IF ad-hoc manner. The approach taken by ContextToolkit condition THEN action’ rules. The condition specifies [5] is worthy of notice as they built a general the state of the context. The action leads to a change in architecture designed to support context-aware the state of an entity. Therefore the if-then rule can be applications. The application consists of acquire, rewritten as follows: ‘IF condition THEN change the collect, transform, deliver and act-on-context state of the entity’. components. A systematic approach for the The disadvantage of using classical if-then rules is the lack of implicit support for keeping the state of the Rule1: IF tom_in_living entity. It would be useful to memorize the entity state THEN tv_switch = off when the condition becomes false and to restore the Rule2: IF john_in_living state next time when the condition is true. THEN tv_switch = on The following set of rules illustrates the situation. The conflictive situation occurs when both John Rule1: IF tom_in_living and Tom are in the living room as the actions THEN light_setting = tom_light_setting requested by the two rules are opposite. A possible Rule 2: IF john_in_living solution is to add a new rule that explicitly considers THEN light_seting = john_light_setting the contradiction. The rules describe a situation in which the light Rule3: IF tom_in_living and john_in_living level is automatically adjusted based on John’s or THEN tv_switch = off Tom’s preferences whenever they enter the living room. What happens if Tom while being in the room This approach becomes more and more intractable changes his light level setting? Is the new level when the number of people increases. For the rule memorized and used next time Tom enters the room? designer the situation may become unmanageable as As a matter of fact, the set of rules does not the number of situations that have to be covered by successfully deal with this situation. To overcome this, rules increases. It seems that we need some kind of the set must include rules that capture the moment mechanism to place all the rules regarding the when someone enters or leaves the room. The previous tv_switch entity together. This mechanism should be two rules can be replaced by four rules: able either to work with priorities assigned to the individual rules or to take into account the first rule Rule1: IF tom_enter whose condition becomes true and neglect the other THEN light_setting = tom_light_setting rules even if their conditions become true. Rule2: IF tom_exit We continue illustrating the conflictive rules by the THEN tom_light_setting = light_setting following example: Rule3: IF john_enter THEN light_setting = john_light_setting Rule1: IF tom_in_office Rule4: IF john_exit THEN music_player_state=play_on THEN john_light_setting = light_setting Rule2: IF boss_in_tom’s_office and working_hours THEN music_player_state=play_off What happens if while John is in the room Tom enters the room? What will be the light level? Again, Again the two rules can be true at the same time the set of rules do not consider this situation. At least that leads to some on/off opposite actions. In this case, two solutions can be imagined. The luminosity may be the solution does not imply adding a new rule, but adjusted based to John’s (first person who enters) rather assigning priorities to each rule. By assigning preference and it stays like that as long as John is in the highest priority to the second rule, the player the room regardless of Tom (second person) presence device will be quiet during working hours as long as in the room. Another approach is to use priorities in the boss is in the office regardless of Tom presence. order to decide upon the light level. E.g. people are The above examples clearly show the given priorities based on their age and luminosity is disadvantages of the classical if-then rule approach. In always adjusted based on the preference of the eldest order to overcome these disadvantages all the rules person in the room. What happens if both John and concerning the same entity must be put together. In Tom are in the room and the luminosity is set this paper we discuss the multiFacet item abstraction according to John’s wish, but John leaves the room? that introduces a control mechanism for all the rules The set of rules does not cover this particular situation. regarding an entity. Therefore we have to improve the set by adding some new rules. Thus the designer of the collection of rules 3. multiFacet item abstraction must take into account every possible situation at design time. The context for an application running on a mobile Another shortcoming of classical if-then rules is the device is changing all the time. The application must inability to deal with conflictive rules. In the following adjust to the ever-changing circumstances by exposing example both conditions can be true simultaneously. and hiding parts of its functionality. An application consists of both components that are context sensitive and components that do not depend on the context. A Table 1. Features of the exposing strategies context sensitive component can be seen as an item No of maximum What facet is Strategy with many facets, or a multiFacet item. A facet is exposed facets exposed? aware only of some part of the item functionality. A Oldest facet having Exclusive 1 facet has a condition that behaves like a switch, in the true condition. sense that if the condition is true the facet is exposed otherwise the facet is hidden. When a facet is exposed Highest priority facet Priority-based having true condition. the associated functionality is available to be used by exclusive 1 In case there are many another application or user. When a facet is hidden the the oldest one is taken. associated functionality is not available to be used by another application or user. Non-exclusive all Any facet having true The multiFacet item is notified whenever the condition. context changes. The multiFacet item reacts by changing the currently exposed facets. At a given accordingly adjust the light and temperature to increase moment, the functionality of the item as a whole is their comfort. Let John and Tom be the two persons given by the sum of the functionality of every exposed the room is aware about. The central module can be facet. Thus, by the facets exposing and hiding, the designed as an exclusive strategy 2-facet item. One functionality of the item goes dynamically richer or facet (FJ) knows John’s preferences while the other poorer. one (FT) knows Tom’s light and temperature What happens if the conditions associated to the preferences. If Tom enters the room first, the 2-facet various facets become true simultaneously? Which of item will expose FT so the environmental conditions them will be exposed? All facets? Just a part of them? will be set according to Tom’s wish. Tom can modify In the following paragraph we describe three exposure the environmental conditions and the intelligent room strategies. will store them for later use. If John enters the room while Tom is in the room the setting does not change 3.1. Exposure strategy because the exclusive strategy has been chosen at design time. If Tom leaves the room, FT is hidden and The strategies for exposure specify not only the FJ is exposed so the temperature and light values are maximum number of facets that can be exposed at a changed to fit John’s wish. certain moment, but also which facet(s) is currently exposed. Actually, the exposing strategies specify the 3.1.2. Priority based exclusive strategy. Priority behavior of the set of rules in the case two or more based exclusive strategy allows at most one facet to be rules have their condition true. First option (exclusive exposed at a given time, namely the highest priority strategy) is to trigger the oldest rule having the facet having the condition true. If, while a facet is condition true. Second option (priority based exclusive exposed, the condition for another facet becomes true, strategy) is to trigger the highest priority rule having the priority of the latter facet is verified. If the priority the condition true. Third option (non-exclusive is higher than the priority of the currently exposed strategy) is to trigger any rule whenever its condition facet, then the current facet will be hidden while the becomes true. latter facet will be exposed. When the condition of the Table 1 summarizes the features of the exposing exposed facet becomes false, it verifies if there are strategies. some other facets to be exposed (i.e. with true conditions). If there is just one facet, that facet will be 3.1.1. Exclusive strategy. Exclusive strategy allows at exposed. If there are more facets the one with the most one facet to be exposed at a given moment. If, highest priority is chosen to be exposed. If there is while the facet is exposed, the conditions for some more then one facet with the highest priority, the one other facets become true, these facets will not be whose condition became true first will be exposed. exposed. When the condition of the exposed facet Here is an example for priority based exclusive becomes false, it verifies if there are some other facets strategy. A service that controls how a music player to be exposed (i.e. with true conditions). If there is just works can be modeled using a priority based exclusive one facet, the facet will be exposed. If there are two or strategy 2-facet item. For the sake of simplicity, we more facets the one whose condition became true first assume that the music player has only the two basic will be exposed. functions: play on and play off. One facet Ton exposes Below is an example for the exclusive strategy. and automatically triggers ‘play on’ function when Imagine an intelligent room having a central module Tom is in the office. The other facet Toff exposes and able to detect the occupants of the room and to automatically triggers ‘play off’ when during the AbstractMultiFacetItem AbstractFacetCollection CustomizableItem MultiFacetItem AbstractStrategy AbstractFacet MultifunctionalItem ExclusiveStrategy NonExclusiveStrategy Facet PriorityBasedExclusiveStrategy EnterListenerForMI ExitListenerForMI CAClass Identifier AbstractListener Listener CATypedClass CAIntConstant CAIntVariable CAVoidFunction Figure 1. UML class diagram of the framework and its instances working hours the boss is in the office. The conflictive manner. A notable exception is ContextToolkit [5]. An situation that occurs when both facets should be ad-hoc manner comes with an important disadvantage: exposed is successfully overcome by assigning a the lack of reusability. In order to help the field of the higher priority to Toff. context-aware systems become mature, it is compulsory to provide the right tools to the application 3.1.3. Non exclusive strategy. Non exclusive strategy developers. A software framework is a mechanism that permits any number of facets to be exposed at a given promotes the reuse of the architectural design and moment. All facets having true conditions are exposed. code. Consequently, the effort and time involved in the Here is an example for non exclusive strategy. development of the context-aware applications is Sometimes it is useful for the participants to a meeting, significantly reduced. to get a warning before meeting starts. More and more In the previous section we gave the rationale for the people carry with them mobile devices on which a need of using the multiFacet item as a mechanism to warning service can be easily installed. The warning coordinate all the rules concerning an entity. Having service takes the time when the meeting starts from a the multiFacet abstraction as a starting point, we put scheduler application and produces a sound alarm 10 forward a software framework for the development of minutes before starting off the meeting. If the level of context-aware applications. This section describes the the noise in the environment is high, the level of the components of the framework as well as the sound alarm also increases. If the level of noise is very relationships among them. We also present a collection high, a vibration alarm will also be triggered. We have of various types of multiFacet items that can be designed the warning system as a 3-facet non exclusive successfully used for developing context-aware strategy item having the following facets: applications. F1: IF noise_level < high 4.1. Framework components THEN set the alarm at normal level F2: IF noise_level ≥ high The abstract classes AbstractMultiFacetItem and THEN set the alarm at high level AbstractFacet model the essential elements of the F3: IF noise_level > very_high THEN enhance the alarm by vibration multiFacet abstraction and the relationship between them. These are superclasses for the main components In case the level of noise overtakes the high level, of the framework, MultiFacetItem and Facet. These both F2 and F3 facets are exposed. The alarm will be main components encapsulate the behaviour that is set at high level and will be enhanced by vibration. common for all the multiFacet items. The ExclusiveStrategy, PriorityBasedExclusiveStrategy and NonExclusiveStrategy are concrete classes that 4. Software framework for context-aware implement the three exposure strategies. The selection applications of the strategy is done when the item is created and cannot be modified later. A notification procedure may So far, the development of the context-aware be triggered when a facet changes its state from the applications mostly has been done in an ad-hoc exposed to hidden or conversely. The abstract class Thus, given a context, the multiFacet identifier exposes AbstractListener is the superclass for all listeners exactly one value/behavior. We could say that given a involved in the notification procedure. In figure 1, context, a multiFacet identifier is similar to a common which illustrates the UML class diagram of the identifier. As soon as the context changes the framework and its instances, the classes that belong to value/behaviour of the multiFacet identifier also the framework are shaded. changes in order to accommodate to the new context. In order to implement the multiFacet identifier we 4.2. Types of multiFacet items used a multiFacet item having the exclusive strategy as an intrinsic feature. By instantiating the framework one can build A multiFacet constant is an identifier having a various multiFacet items each with its specific name, a type and a collection of values, one value for behavior. The instantiation process involves one or each facet. As for any common constant, the value may more of the following steps: not be changed by assignment operation. In the 1) extend MultiFacetItem and AbstractListener following example we declare an integer constant classes; having two facets and two values, 10 and 100, one for 2) make a decision about listeners’ availability. The each facet. listeners may be available or not to the application developer. The listeners should be made CAIntConstant ctxMaxParkingTime; unavailable to the application developer when they ctxMaxParkingTime = new CAIntConstant(0); ctxMaxParkingTime.Attach(dayCondition, 10); hold predefined bevahiour, which does not have to ctxMaxParkingTime.Attach(nightCondition, 100); be altered. 3) decide upon the notification granularity. The The overall value of the constant is given by the notification may happen at the item level or the value associated to the current exposed facet. If for the notification may take place at the facet level. The current context no facet has been defined, then the granularity is an intrinsic feature of the item type. overall value takes the default value (0 in the example Therefore the granularity is not a choice of the above) specified at the creation time. application developer who uses the item, but it is a A multiFacet variable is an identifier having a decision of the developer who creates the type of name, a type and a collection of values, one for each the item by instantiating the framework. facet. The values may be changed by assignment 4) decide upon the suitable exposing strategy. For operation. In the following example we declare an some item types the strategy is an intrinsic feature integer variable having two facets. The initial value for of the item, while for some other items it can be the case johnCondition is true will be 10, while for the chosen by the application developer, when the case tomCondition is true will be 20. item is created. One of our research goals has been to provide CAIntVariable ctxLightSettings; context-awareness at the programming language level. ctxLightSettings = new CAIntVariable(0); In order to achieve this goal we took a first step by ctxLightSettings.Attach(johnCondition, 10); developing a framework that provide us with context- ctxLightSettings.Attach(tomCondition, 20); aware identifiers and objects. The second step is to extend the C# language with context-aware identifiers In a certain context, the overall value of the and objects. As the focus of this paper is to discuss the variable is given by the value associated with the proposed software framework for developing context- current exposed facet. If for the current context no aware applications we will not consider for discussion facet has been defined, then the overall value initially the extension of the C# language. takes the default value (0 in the example above) Another research goal has been to discover and specified at the creation time. While a facet is exposed, provide ready-made multiFacet items that can be the overall value may be changed. Therefore, when the useful in various context-aware applications. We have current exposed facet gets hidden the value assigned not overlooked the situation in which peculiar with the facet is updated to the overall value. applications need customizable items. For a common function different calls may trigger different behaviours for various lists of the actual 4.2.1 multiFacet identifiers: constant, variable, parameters. For a multiFacet function the behaviour is function (CAIntConstant, CAIntVariable and specified not only by the set of parameters, but also by CAVoidFunction classes). In contrast with a common the current context. A multiFacet function behaves identifier, a multiFacet identifier holds more than one depending of the context, but it has the same signature value/behavior, each defined for a certain context. in every context. To illustrate a multiFacet function we define a contextual alarm. During the afternoon the be of a certain type. The latter means that no type alarm behaves as a sound alarm, while during the night checking is done when an object is linked to a facet. the alarm behaves as a light alarm. With a 2-facet A default object is mandatory to be specified at the function we can easily implement this alarm, by multiFacet object creation. The default object is linking one function to each facet. twofold: - the set of the default object methods actually gives CAFunction ctxAlarm; the set of the multiFacet object methods i.e. it ctxAlarm = new CAFunction( defines the multiFacet object interface new VoidDelegate(NoAlarm)); - if for the current context no facet has been ctxAlarm.Attach(afternoonCondition, defined, the overall behaviour of the multiFacet new VoidDelegate(Sound)); ctxAlarm.Attach(nightCondition, object is given by the default object new VoidDelegate(Light)); In order to determine the actual method called on a multiFacet item we use a lookup algorithm. void NoAlarm(int p_Time, int p_Strength) { … } void Sound(int p_Time, int p_Strength) { … } The lookup algorithm for strongly typed objects: void Light(int p_Time, int p_Strength) { … } 1. check if the default object has the called method. Yes: go to step 2. No: raise an exception. At a given moment, the overall behavior is given 2. call the method on the object linked to the current by the function linked to the current exposed facet. If exposed facet for the current context no facet has been defined, then the overall behavior is given by a default function The lookup algorithm for weakly typed objects: (NoAlarm in the example above) specified at the 1. check if the default object has the called method. creation time. Yes: go to step 2. No: raise an exception. 2. check if the object linked to the current exposed 4.2.2. multiFacet objects (CATypedClass and facet has the called method. Yes: call the method. CAClass classes). Does it make any sense to create No: go to step 3 multiFacet objects? In order to answer this question we 3. call the method on the default object. put forward the case of an object having a data member that takes different values in different A weakly typed multiFacet object is an instance of contexts. This object is responsible for adjusting the CAClass library class while a strongly typed subtitles on a screen. If the user is less than 1 meter multiFacet object is an instance of CATypedClass. away from the screen the font size is set to SMALL. If The 3-facet object responsible with the subtitle the user is somewhere between 1 meter and 3 meters adjustment will be an instance of CATypedClass, the font size increases at MEDIUM, while if the having objects of type FontSize and distance between the user and the screen is greater than SpecializedFontSize on the facets. 3 meters but smaller than 5 meters the font size is LARGE. It seems useful to have the object knowing SpecializedFontSize underone = the three font sizes. The object also has a method new SpecializedFontSize(SMALL, form); called change() that actually modifies the font size. FontSize undertwo = new FontSize(MEDIUM, form); The method is automatically triggered when the FontSize underThree = new FontSize(LARGE, form); CATypedClass subtitle = distance to the screen changes. Moreover the method new CATypedClass(typeof(FontSize), generates a sound warning when the user is less than new FontSize(form)); 1 meter close to the screen. Both the member data and subtitle.Attach(oneMeterCondition, underone); the method depend on the context. The context-aware subtitle.Attach(underThreeMetersCondition, underthree); application developer might easily implement this subtitle.Attach(underFiveMetersCondition, underfive); scenario if a three-facet object was made available. We have implemented the multiFacet object as a If the user is around 1 meter away from the screen container of objects, an object for each facet. Given a underone gives the subtitle object behavior. If there are context, the overall behavior of the multiFacet object is more than 1m but less than 3 meters between the user given by the behavior of the object linked to the and the screen then subtitle object behaves as current exposed facet. underthree. If the distance is between 3 meters and We have implemented two categories of multiFacet 5 meters underfive specifies the overall behaviour of objects: strongly typed and weakly typed. The former subtitle. Otherwise the subtitle behaves as the default means that all the objects attached to the facets have to object. The following examples illustrate how to use situations the application developer has to be able to various multiFacet identifiers and objects. insert code to be executed on the expose or hide events provided that the code is not able to modify the //the usage of ctxMaxParkingTime constant predefined behaviour of the listeners. Therefore we if(parkingTime > ctxMaxParkingTime) { … } provide a notification mechanism accessible to the developer. There are two notifiers, one for exposing //assign a value to ctxLightSettings variable the facet and the other for hiding the facet. A notifier is ctxLightSettings.Assign(25); a function that returns void and takes no parameter. The notifier is called post event in the following sense: //the use of ctxLightSettings variable int settings = ctxLightSettings + 3; on exposing a facet, first the facet is exposed then the notifier code is called. On hiding a facet, first the facet //call ctxAlarm function with two parameters is hidden then the notifier code is called. ctxAlarm.Call(10, 20); We will consider again the light settings scenario. It would be nice to be able not only to adjust the light //call GetString method on subtitle object according to the people preferences, but also to display subtitle.InvokeMethod(“GetString”); the preferences and the people name. For this we resort to the notification mechanism. EnterShowLightSettings Our intention was to provide a way of using and ExitShowLightSettings are the two notifiers called multiFacet identifiers and objects as close as possible when a facet is being exposed and hidden respectively. to the way common identifiers and objects are used. Sometimes the gap between the usage of the CAIntVariable ctxLightSettings; multiFacet and common identifiers / objects could not Change inNotify = be filled entirely. One case we came across was the new Change(EnterShowLightSettings); Change outNotify = assignment operator for a multiFacet identifier. We new Change(ExitShowLightSettings); have developed the framework in C# which does not ctxLightSettings = support the overloading of the assignment operator. new CAIntVariable(inNotify, outNotify); Therefore we had to come with another solution for ctxLightSettings.Attach("john", johnCondition); assigning a value to a multiFacet variable, i.e. Assign ctxLightSettings.Attach("tom", tomCondition); method for assigning values to the multiFacet variables. We used the InvokeMethod for calling a public void EnterShowLightSettings() method on a multiFacet object. { From the programmer point of view, the // display who is in the room: description of the reaction to the context changes is // display the light settings } done only once at the declaration or creation time. Later in the code the identifiers and objects expose and public void ExitShowLightSettings() hide their facets automatically, without any explicit { action done by the application developer. When the //display ‘none’ to indicate that none is time comes for the multiFacet identifiers and objects to //in the room be used, they will be ready with the right facet //display the default light settings exposed. } Notification 4.2.3. Multifunctional item (MultifunctionalItem Besides knowing the context in which a multiFacet class). In this paragraph another instance of the item runs it is also important to know the moment framework, called multifunctional item, is presented. when the item ‘enters’ or ‘leaves’ the context. In order For this item a facet can be seen as a gate to a set of to catch these moments two listeners are attached to services. If the facet is exposed then the gate is opened every facet. One listener catches the moment when the that makes the services to be available. If the facet is item enters a context, i.e. when the facet is being hidden then the gate is closed subsequently the exposed. The other listener catches the moment when services are unavailable. the item leaves the context, i.e. the facet is being We suppose that there is a mechanism for uniquely hidden. These listeners may or may not be available to identifying each service. the application developer. For multiFacet identifiers and objects, we have Let S = { s1, s2, …, sn } be the set of services provided forbidden the application developer to modify the be the multifunctional item and let F = { F1, F2, …, predefined behavior of the listeners. Though in some Fm } be the set of its facets. Property 1 Each facet has a non-empty collection of services public MultifunctionalItem(AbstractStrategy p_Strategy) ; public MultifunctionalItem(AbstractStrategy p_Strategy, ∀ Fi ∃ S i = { si1, si2, … } Change p_Enter, Change p_Exit); where S i ⊆ S , i ∈ {1, ...,m} and S i ≠ φ public MultifunctionalItem(AbstractStrategy p_Strategy, Change p_Enter, Change p_Exit, Change p_ UpdateExposedServices); Property 2 Every service is exposed on at least one facet. There are two options for attaching services to a ∀ sk ∃ Fi so that sk ∈ S i facet: either a whole collection at once or individual where k ∈ {1, …,n} and i ∈ {1, …,m} services. We provide APIs to support both options. For the first option, the call not only attaches the services Property 3 to the facet, but also creates the facet having the The same service may be exposed on two or more context condition provided as first parameter. In case facets. the facet already exists, the call fails. ∃ sk so that sk ∈ S i and sk ∈ S j public int Attach(ILogicalCondition p_Condition, where k ∈ {1, …,n} and i, j ∈ {1, …,m} i≠j AbstractServiceCollection p_Services); public int Attach(ILogicalCondition p_Condition, Property 4 AbstractServiceCollection p_Services, int p_Priority); Two facets may not expose the same set of services. public int Attach(string p_Description, ILogicalCondition p_Condition, ∃/ Fi, Fj so that S i = S j AbstractServiceCollection p_Services); where i, j ∈ {1,...,m} and i≠j public int Attach(string p_Description, ILogicalCondition p_Condition, AbstractServiceCollection p_Services, Notification int m_Priority); The listener mechanism of the multifunctional items is similar to the mechanism used by the For the second option, attaching individual multiFacet identifiers. But unlike identifiers, which call services, the approach is opposite. The API call does the same listener Listener both for exposing and hiding not have the power to create facets, therefore an a facet, multifunctional items need two listeners. individual service may be attached only to an existing EnterListenerForMI is triggered when a facet is facet. exposed, while hide facet event calls ExitListenerForMI. These listeners perform an extra public int Attach(ILogicalCondition p_Condition, step before calling the notifiers. They update the AbstractService p_Service); collection of the current exposed services. The notifiers are defined at the item level, bot at the facet For the items we have presented, the application level. The developer has the freedom to choose the developer cannot directly access the listeners, but she exposing strategy. may access the notifiers. The notifiers are weaker than In order to create a useful instance of a software listeners in the sense that they cannot change the framework the instance usage must be carefully predefined behavior triggered when a facet turns considered. Several master students built a number of on/off, but they can add new behaviour to the applications, which among other items also contain predefined behaviour. multifunctional items. Reviewing the way they used A service is currently exposed (consequently can the items it helped us to better understand their usage. be called by the user or other application) if there is at We have reached the conclusion that often the least one currently exposed facet and the service has exposing and hiding notifiers are identical. This clearly been attached to that facet. What happens when the shows that what really matter is not to catch the facet is being hidden while the service is still in use? ‘moment’ when a facet turns on/off, but the ‘moment’ The proper behaviour depends at a great extent on the when the collection of current exposed services is service itself. The solution involves both the updated. Therefore the constructor for the framework and the service developer. The service multifunctional item allows specifying an updating provides a callback that contains customized behavior notifier in addition to the exposing and hiding notifiers for stopping an in use service. The callback is called and strategy. when the facet is being exposed or hidden. Table 2. Types of items and their features Notification Listener Item type Exposing strategy granularity availability multiFacet identifier Exclusive Item level No multiFacet object Exclusive Item level No Exclusive, Priority based Multifunctional item Item level No exclusive, Non exclusive Exclusive, Priority based Customizable item Facet level Yes exclusive, Non exclusive 4.2.4. Customizable item (CustomizableItem class). The applications build with the proposed software Some context-aware situations can be dealt with only framework need a support infrastructure that notifies if the developer holds full control over the multiFacet the multiFacet items when the context changes. item. The developer has to be in charge for choosing Actually, an item gets notified only if one of its context the exposing strategy while creating the item. conditions changes. If this is the case, the item is Moreover, the developer may design the listeners from signaled about the modified context condition and the the scratch. The listeners having finer granularity may new truth-value. Having the condition, the item be specified at the facet level, not at the item level. identifies the facet and having the truth-value the item Thus, the API for creating a facet specifies a context knows if the facet is to be exposed or hidden. An condition, an object that will be available when the application may consist of context-aware as well as facet is exposed and two listeners. non-context-aware components. Various context-aware components may have facets whose conditions are public int Attach(ILogicalCondition p_Condition, identical. It would be ineffective to check the same Object p_Value, condition more than once. We use a publisher- AbstractListener p_EnterListener, subscriber architecture for building the dissemination AbstractListener p_ExitListener); mechanism of the messages about context changes. Both the publisher and the subscriber are multiFacet 4.2.5. Summary. The exposing strategy is preset and items. The subscribers are those items that have to be cannot be changed for the multiFacet identifiers and notified when the context changes. objects, but it is the developer’s choice for both the While a multiFacet item subscribes to the publisher multifunctional and customizable items. However once links are created between item facets and publisher the decision on the strategy is made it cannot be facets. A link connects a facet from the item to the changed later. The granularity of the listeners / facet of the publisher having the same context notificators is either coarse (at the item level) for condition. identificators, objects and multifunctional items or fine In the current version of our infrastructure the (at the facet level) for customizable items. publisher is the dissemination point for the messages Table 2 illustrates the relationship between the types of about the context changes. When the context changes items, the exposing strategies, the notification the publisher reacts by requesting each facet to re- granularity and the availability of the listeners. evaluate its truth-value. If the truth-value for a facet F of the publisher has been modified the fact is 5. Infrastructure propagated to every item having a link to F. Thus a context condition is checked just once no matter how The context-aware applications require an many items use it. infrastructure able to collect and process context related information. The infrastructure disseminates 6. Experiments the context information to the subscribing applications while dealing with scalability, security and privacy [4]. Both context-aware components (i.e. multiFacet The decoupling of application from the context items) and non-context-aware components can be management relieves the application developer from found in a context-aware application. The latter come having to know about a specific context format [3]. with the overhead of the updating the current facet(s) of the items. We measured this overhead using a HP 8. References iPAQ rx3700 at 400MHz and 152MB. We made the measurements for three cases: (1) the context-aware [1] G. Biegel, V. Cahill, A Framework for Developing components are 1-facet items, (2) the context-aware Mobile, Context-aware Applications, 2nd IEEE Conference components are 2-facet items, (3) the context-aware on Pervasive Computing and Communications, Orlando, FL, components are 4-facet items. For each case we varied March 14-17 the number of items up to 30 and consider a repository of 30 context messages. The measurements, illustrated [2] L. Capra, W. Emmerich, C. Mascolo, CARISMA: Context-Aware Reflective mIddleware System for Mobile in figure 2, show an overhead of around 19ms for the Applications, IEEE Transactions on Software Engineering, case the collection of the context-aware components Vol. 29, No. 10, October 2003, pp. 929-945 contains only one multiFacet item. The overhead goes up to 68ms for the case the collection of context-aware [3] G. Chen, D. Kotz, A Survey of Context-Aware Mobile components contains 30 multiFacet items each with 4 Computing Research, Technical Report: TR2000-381, facets. Dartmouth College, 2000 [4] G. Chen, D. Kotz, Context Aggregation and Dissemination in Ubiquitous Computing Systems, 4th IEEE Int. Workshop on Mobile Computing Systems and Applications, 2002 [5] A.K. Dey, Providing Architectural Support for Building Context-Aware Applications, PhD thesis, College of Computing, Georgia Institute of Technology, December 2000 [6] T. Gu, K. Pung, D.Q. Zhang, A service-oriented middleware for building context-aware services, Journal of Network and Computer Applications, Volume 28, Issue 1, January 2005, pp.1-18 [7] T. Kindberg, J. Barton, J. Morgan, G. Becker, D. Caswell, P. Debaty, G. Gopal, M. Frid, V. Krishnan, H. Morris, J. Schettino, B. Serra, People, Places, Things: Web Presence for Real World, IEEE Workshop on Mobile Figure 2. The overhead introduced by the multiFacet Computing Systems and Applications, Monterey CA, items December 2000 [8] B.N. Schilit, N. Adams, R. Want, Context-Aware 7. Conclusions Computing Applications, Workshop on Mobile Computing Systems and Applications, Santa Cruz, CA, December 1994, As the context-aware systems become more pp. 85-90. mature, the ad-hoc developing of these systems need to be replaced by systematic approaches. In this paper we [9] S.S. Yau, F. Karim, An Adaptive Middleware for presented a reusable approach for creating context- Context-Sensitive Communications for Real-time aware applications. The multiFacet abstraction and the Applications in Ubiquitous Computing Environments, Real- software framework build upon the abstraction provide Time Systems, Volume 26, Issue 1, January 2004, pp. 29-61 support for the development of the applications able to adapt to the context. The adaptation mechanism proposed by the framework works out the conflictive situations without requiring the explicit description of these situations. Thus, simplifying the task of creating context-aware applications. Those parts of the application that are context-sensitive will be modeled as multiFacet items. We introduced various types of items each with specific behavior.