1 / 17

Introducing the universAAL Utility API

Introducing the universAAL Utility API. Madrid, Spain 08/01/2013 Alvaro Fides (UPVLC). How universAAL works. Let´s assume by now you know (more or less) how universAAL works. How universAAL works. In a nutshell, in universAAL you can do 6 things:. Send and Receive Context Events.

Download Presentation

Introducing the universAAL Utility API

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introducing the universAAL Utility API Madrid, Spain 08/01/2013 Alvaro Fides (UPVLC)

  2. How universAAL works Let´s assume by now you know (more or less) how universAAL works universAAL Training – Utility API

  3. How universAAL works In a nutshell, in universAAL you can do 6 things: Send and Receive Context Events Call and Provide Services Give Output to the user and Get Input in response universAAL Training – Utility API

  4. How universAAL works Why not do just that? universAAL Training – Utility API

  5. The Utility API • The Utility API lets you interact with universAAL in this simplified way (it can do many other things but this is the most flashy) • It is just a library layered on top of universAAL native middleware, so it is seamlessly compatible universAAL Training – Utility API

  6. The Utility API • Source: http://forge.universaal.org/svn/support/trunk/utilities/uAAL.utils/ • Binary: http://depot.universaal.org/nexus/index.html#view-repositories;snapshots • Maven ID:org.universAAL.support/uAAL.utils/2.0.1-SNAPSHOT • Wiki:http://forge.universaal.org/wiki/support:Utility_API • Javadoc: http://depot.universaal.org/hudson/job/support/site/support.pom/apidocs/index.html universAAL Training – Utility API

  7. Using the Utility API • Let´s make a uAAL App with the Utility API that: • Sends a Context Event about a user´s position • Receives that same Context Event • Provides Services to edit a user • Calls one of those Services • Outputs a User Interface with a button • With the native uAAL MW you would need several classes and quite a bit of code • With the Utility API we´ll do this within the Activator in about 100 lines universAAL Training – Utility API

  8. Using the Utility API • Create an empty uAAL project • Setup the POM to use the API: • In addition to the basic uAAL dependencies we will add: <dependencies> ... <dependency> <groupId>org.universAAL.ontology</groupId> <artifactId>ont.phWorld</artifactId> <version>2.0.0</version> </dependency> <dependency> <groupId>org.universAAL.ontology</groupId> <artifactId>ont.profile</artifactId> <version>2.0.0</version> </dependency> <dependency> <groupId>org.universAAL.support</groupId> <artifactId>uAAL.utils</artifactId> <version>2.0.1-SNAPSHOT</version> </dependency> </dependencies> To use “Things” To use “Users” To use the Utility API universAAL Training – Utility API

  9. Using the Utility API • Modify the Activator to: • Initialize public class Activator implements BundleActivator { public static BundleContextosgiContext = null; public static ModuleContext context = null; private static String NAMESPACE = "http://ontology.itaca.upv.es/Test.owl#"; private UAAL u; public void start(BundleContextbcontext) throws Exception { Activator.osgiContext = bcontext; Activator.context = uAALBundleContainer.THE_CONTAINER .registerModule(new Object[] { bcontext }); u = new UAAL(context); ... The OSGi Context and the uAAL Context The Namespace of this App Initialize uAAL Helper class The uAAL Helper class Initialize Context universAAL Training – Utility API

  10. Using the Utility API • Modify the Activator to: • Subscribe for Context Events: public class Activator implements BundleActivator { ... public void start(BundleContextbcontext) throws Exception { ... Pattern cep = new Pattern(User.MY_URI, User.PROP_PHYSICAL_LOCATION, null); u.subscribeC(new ContextEventPattern[] { cep }, new ICListener() { public void handleContextEvent(ContextEvent event) { System.out.println(">>> Received Event: " + event.toString()); } }); ... This is what we do when we receive a matching event Instead of using a Context Subscriber, create a simple Listener Describe the event pattern as usual or with Utility API universAAL Training – Utility API

  11. Using the Utility API • Modify the Activator to: • Send a Context Event: public class Activator implements BundleActivator { ... public void start(BundleContextbcontext) throws Exception { ... User user1 = new User(Constants.uAAL_MIDDLEWARE_LOCAL_ID_PREFIX + "saied") user1.setLocation(new Location(NAMESPACE + "loc1")); ContextEvent e = new ContextEvent(user1, User.PROP_PHYSICAL_LOCATION); u.sendC(e); ... ... and send it Create an event as usual universAAL Training – Utility API

  12. Using the Utility API • Modify the Activator to: • Provide a Service: public class Activator implements BundleActivator { ... public void start(BundleContextbcontext) throws Exception { ... ServiceProfile[] sp=UtilEditor.getServiceProfiles(NAMESPACE, ProfilingService.MY_URI, Path.at(ProfilingService.PROP_CONTROLS).path, User.MY_URI); u.provideS(sp,newISListener() { public ServiceResponsehandleCall(ServiceCall s) { System.out.println(">>> Received Service Call: "+ s.toString()); return new ServiceResponse(CallStatus.succeeded); } }); ... This gives you the typical get/set/change/remove service profiles This is what we do when we receive a matching call. Notice you must return the response. Instead of using a Service Callee, create a simple Listener Declare service profiles as usual or with Utility API universAAL Training – Utility API

  13. Using the Utility API • Modify the Activator to: • Call a Service: public class Activator implements BundleActivator { ... public void start(BundleContextbcontext) throws Exception { ... ServiceRequestsr=UtilEditor.requestRemove( ProfilingService.MY_URI, Path.at(ProfilingService.PROP_CONTROLS).path, user1); ServiceResponse r = u.callS(sr); System.out.println(">>> Received Service Response: “+ r.getCallStatus()); ... This gives you the typical “remove” service request ... and call the service ... and do something with the response Declare service request as usual or with Utility API universAAL Training – Utility API

  14. Using the Utility API • Modify the Activator to: • Manage the User Interface: public class Activator implements BundleActivator { ... public void start(BundleContextbcontext) throws Exception { ... Dialog d = new Dialog(user1,"UI example"); d.add(Forms.out("Result:", "Successfully reached UI test")); d.addSubmit(Forms.submit(NAMESPACE + "button1", "OK")); u.requestUI(d, new IUIListener() { public void handleUIResponse(UIResponse r) { System.out.println(">>> Received UI Response: “ + r.getSubmissionID()); } }); } Instead of using a UICaller, create a simple Listener In Utility API you can create forms like this This is what we do when we receive the user input Create a dialog as usual or with Utility API universAAL Training – Utility API

  15. Using the Utility API • Modify the Activator to: • … don´t forget to close properly: public class Activator implements BundleActivator { ... public void stop(BundleContext arg0) throws Exception { u.terminate(); } } universAAL Training – Utility API

  16. publicclassActivatorimplementsBundleActivator { publicstaticBundleContextosgiContext = null; publicstaticModuleContextcontext = null; privatestaticStringNAMESPACE = "http://ontology.itaca.upv.es/Test.owl#"; private UAAL u; publicvoidstart(BundleContextbcontext) throwsException { Activator.osgiContext = bcontext; Activator.context = uAALBundleContainer.THE_CONTAINER .registerModule(newObject[] { bcontext }); u = new UAAL(context); Patterncep = newPattern(User.MY_URI, User.PROP_PHYSICAL_LOCATION, null); u.subscribeC(newContextEventPattern[] { cep }, newICListener() { publicvoidhandleContextEvent(ContextEventevent) { System.out.println(">>> ReceivedEvent: " + event.toString()); } }); User user1 = newUser(Constants.uAAL_MIDDLEWARE_LOCAL_ID_PREFIX + "saied") user1.setLocation(newLocation(NAMESPACE + "loc1")); ContextEvent e = newContextEvent(user1, User.PROP_PHYSICAL_LOCATION); u.sendC(e); u.provideS(UtilEditor.getServiceProfiles(NAMESPACE, ProfilingService.MY_URI, Path.at(ProfilingService.PROP_CONTROLS).path, User.MY_URI), newISListener() { publicServiceResponsehandleCall(ServiceCall s) { System.out.println(">>> ReceivedServiceCall: " + s.toString()); returnnewServiceResponse(CallStatus.succeeded); } }); ServiceResponse r = u.callS(UtilEditor.requestRemove( ProfilingService.MY_URI, Path.at(ProfilingService.PROP_CONTROLS).path, user1)); System.out.println(">>> ReceivedService Response: "+ r.getCallStatus()); Dialog d = newDialog(user1,"UI example"); d.add(Forms.out("Result:", "Successfullyreached UI test")); d.addSubmit(Forms.submit(NAMESPACE + "button1", "OK")); u.requestUI(d, newIUIListener() { publicvoidhandleUIResponse(UIResponse r) { System.out.println(">>> Received UI Response: " + r.getSubmissionID()); } }); } publicvoid stop(BundleContext arg0) throwsException { u.terminate(); } } Using the Utility API That´s pretty much it. Build, run, try... universAAL Training – Utility API

  17. There is more… • There are other layers beneath this simplification and uAAL Helper Class which can help you make: • Event Patterns, Publisher Info, Publishers • Service Profiles, Requests, Property Paths, Process Parameters, Typical Callees and Profiles • UI Dialogs, UI Form Elements, Typical UICallers • More… universAAL Training – Utility API

More Related