Skip to content

UniDA BasicGUI: Implementation Guide

Victor Sonora Pombo edited this page Mar 12, 2014 · 35 revisions

About

This document explains the implementation of UniDA BasicGUI application, showing how to use the UniDA library API that allows the development of applications that handle hardware devices with independence of the technologies used in each device and their particular characteristics.

BasicGUI estructure

BasicGUI is a simple Java application based on Swing that uses the UniDA library. Its use is documented in its Use Guide, suffice it to say here that the GUI shows information about the detected UniDA gateways and its devices, and allows to compose and send UniDA messages to them.

The unida_java_basicgui project contains the full implementation of BasicGUI. Because of the simplicity of this implementation, the controllers for this application are coded in the classes that act as main frame and dialog windows.

The UNIDALibraryBasicGUI class is a JFrame that acts as main window and entry point. For each kind of UniDA "request" message that can be edited and sent there is a JDialog class:

  • CommandsDialog
  • OnOffCommandsDialog
  • DeviceStatesDialog
  • DeviceStateDialog
  • DeviceWriteStateDialog
  • DeviceStateSubscriptionDialog
  • AutonomousBehaviourDialog

Every one of these dialogs are launched from UNIDALibraryBasicGUI to act on a selected UniDA device, with the exception of AutonomousBehaviourDialog that manages the rules contained in an UniDA gateway.

BasicGUI design

The following class diagram shows the most importante relations and responsibilities that form BasicGUI. For the sake of clarity, only one kind of dialog is showed (CommandDialog).

Different colors are used, to distinguish between:

  • UniDA API usages (in green).
  • Java Swing and AWT dependencies (in grey).
  • BasicGUI own classes (in orange).

uml BasicGUI

As the diagram shows, there is a single entry point to access the information about the detected UniDA devices (and gateways) as well as the methods to handle UniDA messages: InMemoryUniDAInstantiationFacade.

Accessing UniDA devices

When the InMemoryUniDAInstantiationFacade instance is initialized, any gateway announce message received is processed to build and update the in-memory database with all the information about the gateway and the UniDA devices it handles.

InMemoryUniDAInstantiationFacade provides an implementation for the interface IUniDAManagementFacade, which grant access to that database. To retrieve the detected UniDA gateways:

:::java Collection gateways = instantiationFacade.getDeviceManageFacade().findAllDeviceGateways(0, Integer.MAX_VALUE);

Each Gateway object contains the information of all the UniDA devices the gateway handles.

Sending UniDA messages

A different facade is provided by InMemoryUniDAInstantiationFacade in order to allow the user to send UniDA "request" messages: an implementation of IDeviceOperationFacade.

To send one of those messages, the only needed objects are:

  • An IDevice (obtained using the IUniDAManagementFacade previously shown) that represents the UniDA device which is the destination of the message
  • The metadata (based on the UniDA DOGONT ontology) that identifies the action of the message (for example, sending one command that belongs to a control functionality).
  • Aditional parameters that depend on the nature of the message (for example, values for the parameters in an UniDA command message).

As an example, this snippet shows an UniDA command message being built and sent:

IDevice device = instantiationFacade.getDeviceManageFacade().findById(deviceId); ControlCommandMetadata commandMetadata = new ControlCommandMetadata(DomoParsing.instance().getDefaultOntologyNamespace() + commandId, 0); ControlFunctionalityMetadata functionalityMetadata = new ControlFunctionalityMetadata(DomoParsing.instance().getDefaultOntologyNamespace() + funcId, new ControlCommandMetadata[0]); instantiationFacade.getDeviceOperationFacade().asyncSendCommand( device, functionalityMetadata, commandMetadata, DomoParsing.valuesInStringToArray(values), new CommandsDialog.OpCback());