morena middleware2012
TRANSCRIPT
MORENA: A Middleware for Programming NFC-enabled Android Applications as Distributed Object-Oriented Programs
Andoni Lombide CarretonKevin PinteWolfgang De Meuter
ACM/IFIP/USENIX 13th International Conference on Middleware 2012December 5 2012Montreal, Canada
Monday 28 January 13
• NFC (touch range).
• Callback on activities to detect RFID tags with subscribed MIME-type in memory.
• File access abstraction
RFID in Android
NdefMessage: { , , }
NdefRecord byte array
read write
Monday 28 January 13
Drawbacks of the Android NFC API
• Manual failure handling (and NFC causes A LOT of failures because of its hardware characteristics).
• Blocking communication (Android documentation recommends to use a separate thread for many RFID operations).
• Manual data conversion
• Tight coupling with activity-based architecture
Monday 28 January 13
Lessons Learnt from Previous Ambient-Oriented Programming Research
• Using objects as first class software representations for RFID-tagged “things” is a nice abstraction.
• These objects can be directly stored in the RFID tags’ memory to minimize data conversion.
• Event-driven discovery (fortunately built-in into Android).
• Asynchronous reads and writes.
Monday 28 January 13
Application
Middleware Architecture
Android
Tag level
Thing level One middlewarefor Android 4.0
or higher
Monday 28 January 13
Evaluation: WiFi Sharing Application
Monday 28 January 13
Evaluation: WiFi Sharing Application
Monday 28 January 13
Things
public class WifiConfig extends Thing {
public String ssid_; public String key_;
public WifiConfig(ThingActivity<WifiConfig> activity, String ssid, String key) { super(activity); ssid_ = ssid; key_ = key; } public boolean connect(WifiManager wm) {
// Connect to ssid_ with password key_ };}
From now on, we don’t have to worry about the
activity anymore.
Supported serialization: - JSON-serializable fields. - Skipping transient fields. - Deep serialization, no cycles.
Monday 28 January 13
Initializing Things
@Overridepublic void whenDiscovered(EmptyRecord empty) { empty.initialize( myWifiThing, new ThingSavedListener<WifiConfig>() { @Override public void signal(WifiConfig thing) { toast("WiFi joiner created!"); } }, new ThingSaveFailedListener() { @Override public void signal() { toast("Creating WiFi joiner failed, try again."); } });}
As soon as an empty tag is detected
Monday 28 January 13
Discovering and Reading Things
@Overridepublic void whenDiscovered(WifiConfig wc) { toast("Joining Wifi network " + wc.ssid_); wc.connect();}
As soon as a WifiConfig tag is detected
Contains cached fields for synchronous access.
Physical reads must be asynchronous.
Monday 28 January 13
Saving Modified Things
myWifiConfig.ssid_ = "MyNewWifiName";myWifiConfig.key_ = "MyNewWifiPassword";
myWifiConfig.saveAsync( new ThingSavedListener<WifiConfig>() { @Override public void signal(WifiConfig wc) { toast("WiFi joiner saved!"); } }, new ThingSaveFailedListener() { @Override public void signal() { toast("Saving WiFi joiner failed, try again."); } });
Monday 28 January 13
Broadcasting Things to Other Phones
myWifiConfig.broadcast( new ThingBroadcastSuccessListener<WifiConfig>() { @Override public void signal(WifiConfig wc) { toast("WiFi joiner shared!"); } }, new ThingBroadcastFailedListener<WifiConfig>() { @Override public void signal(WifiConfig wc) { toast("Failed to share WiFi joiner, try again."); } });
Will trigger whenDiscovered on the receiving phone with the broadcasted thing
Monday 28 January 13
Evaluation: WiFi Sharing Application
Monday 28 January 13
Middleware Architecture
Android
Tag level
Thing level One middlewarefor Android 4.0
or higher
Application
Monday 28 January 13
Detecting RFID Tags
new MyTagDiscoverer(this, THING_TYPE, new NdefMessageToStringConverter(), new StringToNdefMessageConverter());
private class MyTagDiscoverer extends TagDiscoverer { @Override public void onTagDetected(TagReference tagReference) { readTagAndUpdateUI(tagReference); } @Override public void onTagRedetected(TagReference tagReference) { readTagAndUpdateUI(tagReference); }}
Monday 28 January 13
The Tag Reference Abstraction
Monday 28 January 13
Reading RFID Tags
tagReference.read( new TagReadListener() { @Override public void signal(TagReference tagReference) { // tagReference.getCachedData() } }, new TagReadFailedListener() { @Override public void signal(TagReference tagReference) { // Deal with failure } });
Monday 28 January 13
Writing RFID Tags
tagReference.write( toWrite, new TagWrittenListener() { @Override public void signal(TagReference tagReference) { // Handle write success } }, new TagWriteFailedListener() { @Override public void signal(TagReference tagReference) { // Deal with failure } });
Monday 28 January 13
Fine-grained Filtering
private class MyTagDiscoverer extends TagDiscoverer { @Override public void onTagDetected(TagReference tagReference) { readTagAndUpdateUI(tagReference); } @Override public void onTagRedetected(TagReference tagReference) { readTagAndUpdateUI(tagReference); }
@Override public boolean checkCondition(TagReference tagReference) { // Can be used to apply a predicate // on tagReference.getCachedData() }}
Monday 28 January 13
Conclusion
• Event-driven discovery.
• Non-blocking communication:
• Things: cached copy, asynchronous saving of cached data.
• TagReferences: first class references to RFID tags offering asynchronous reads and writes.
• Automatic data conversion
• Looser coupling from activity-based architecture
• Data structures over several tags, stronger consistency guarantees?
Monday 28 January 13
MORENA: A Middleware for Programming NFC-enabled Android Applications as Distributed Object-Oriented Programs
Andoni Lombide CarretonKevin PinteWolfgang De Meuter
ACM/IFIP/USENIX 13th International Conference on Middleware 2012December 5 2012Montreal, Canada
Monday 28 January 13