introducing the universaal utility api n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Introducing the universAAL Utility API PowerPoint Presentation
Download Presentation
Introducing the universAAL Utility API

Loading in 2 Seconds...

play fullscreen
1 / 17

Introducing the universAAL Utility API - PowerPoint PPT Presentation


  • 80 Views
  • Uploaded on

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.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Introducing the universAAL Utility API' - clayton-ayala


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
introducing the universaal utility api

Introducing the universAAL Utility API

Madrid, Spain 08/01/2013

Alvaro Fides (UPVLC)

how universaal works
How universAAL works

Let´s assume by now you know (more or less) how universAAL works

universAAL Training – Utility API

how universaal works1
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

how universaal works2
How universAAL works

Why not do just that?

universAAL Training – Utility API

the utility api
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

the utility api1
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

using the utility api
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

using the utility api1
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

using the utility api2
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

using the utility api3
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

using the utility api4
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

using the utility api5
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

using the utility api6
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

using the utility api7
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

using the utility api8
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

using the utility api9

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

there is more
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