EQUIP2 and ContextPhone

Chris Greenhalgh, 2006-06-26; last update 2006-06-26

Introduction

ContextPhone is a "mobile context-aware prototyping platform" running on Nokia Series 60 smart phones, developed at the University of Helsinki. It is available under GPL and MIT licenses, http://www.cs.helsinki.fi/group/context/latest/. It is built around a tuplespace/blackboard service which runs on the phone, which is used to manage configuration of the platform and to share "sensor" data obtained from various sources (e.g. current phone cell id, phone application activity, alarms, battery status, attached bluetooth GPS, bluetooth addresses in range).

ContextPhone has a (currently read-only) XML socket-based interface which allows J2ME and other non-native applications to read the information in the contextphone tuplespace. By default, this uses TCP on port 2000. A sample of the datastream obtained is contextphone-sample-onphone4.xml.

I have created an XML unmarshaller in EQUIP2's general marshalling framework to read this (kind of) XML stream and generate corresponding Java objects. This document describes this and the initial test/demo applications constructed for interfacing to ContextPhone.

Note: this unmarshalling-based interface gives access to the full information in the contextphone tuplespace in an object form, which can also be shadowed in an EQUIP2 dataspace. However, if an application only requires access to a small subset of contextphone's information (e.g. current cell id) then it would be simpler, more efficient and less fragile (to changes in the XML marshalling) to use a standard XML parser and just look for the particular elements of interest in the XML stream (there are other examples of doing this from J2ME - contact the ContextPhone team).

Code

Building

The top-level build.xml file has some build targets specifically for the contextphone related code (which is not compiled by default):

data types

The objects in the contextphone tuplespace are mapped in Java to a combination of java.util.Vector (for lists),  java.util.Hashtable (default for compound records with no specific mapping) and custom JavaBeans defined specifically to correspond to key objecst in the context phone tuple space. Currently these are (defined using Simple Bean Generator XML schema):
In general, each sensor publishes a Tuple, with a particular TupleName, in the tuple space. This tuple contains data which is an Event, and the event contains data which is specific to the kind of event, e.g. a CellId, a NetworkStatus, a Vector of Devices.

Unmarshalling

The unmarshaller is equip2.contextphone.marshall.ContextPhoneXmlUnmarshaller, which in turn depends on information built into equip2.contextphone.marshall.TypeMappingFactory to map contextphone objects (identified by various XML attributes) into corresponding Java object classes. This mapping is defined using a standard EQUIP2 XML serialisation of an array of equip2.contextphone.marshall.TypeMapping objects.

The unmarshaller has various default rules, e.g. to use Hashtables for unknown classes. But these rules will fail under certain circumstances, e.g. unknown event data object which is not compound, or event data object which has unknown sub-objects. In these cases an exception will be raised and the type mapping will need to be fixed/updated accordingly.

The unmarshaller will also search for some EQUIP2 helpers automatically which may not exist, in which cases ERROR/WARNING messages will be generated; these can be avoided by specifying explicit mappings for those contextphone types, even if it is just to a Hashtable (which is the fallback in any case).

The standard helper class equip2.core.marshall.impl.XmlObjectInputStream can be used with context phone unmarshaller (or the default EQUIP2 XML unmarshaller) to simplify reading a sequence of objects from an XML-encoded stream.

There is also an example of wrapping the contextphone connection to extracted only limited information via callback(s): equip2.contextphone.test.j2me.ContextPhoneClient (listener interface equip2.contextphone.test.j2me.ContextPhoneListener)

Sample applications

The following J2SE applications are currently provided, under the test/ source tree:
There is currently one J2ME test MIDLet, equip2.contextphone.test.j2me.ContextPhoneTest, which combines a number of examples and facilities:
Note, in general only one of these options can be used each time the MIDlet is run; quit and restart to try a different one.

Future plans/options

To a large extent this is dependent on projects explicitly adopting/making use of this facility. It also depends on the progress/status of the native Symbian version/auto-port of EQUIP2, which is currently incomplete.

Possibilities include:

Change log

2006-06-26