Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In the Extra bundle the class org.apache.felix.upnp.extra.util.UPnPSubscriber can be instantiated to subscribe one or more services. The constructor takes two parameters a BundleContext reference and a UPnPEventListener reference. In this class the method subscribe(Filter aFilter) is a general and powerful way to subscribe to any service by using an LDAP filter. For example by using the string :

...

we would subscribe to the SwitchPower service offered by any device implementing the BinaryLight profile. Looking at the Felix UPnP TV sample code, the UPnPSubscriber class is used in the file org.apache.felix.upnp.sample.tv.TVDevice to subscribe to the different service types offered by the Cyberlink sample devices. However, in this case, the utility method subscribeEveryServiceType is used to provide just the device and service types.

Code Block
private final static String CLOCK_DEVICE_TYPE = "urn:schemas-upnp-org:device:clock:1";
private final static String TIME_SERVICE_TYPE = "urn:schemas-upnp-org:service:timer:1";

private final static String LIGHT_DEVICE_TYPE = "urn:schemas-upnp-org:device:light:1";
private final static String POWER_SERVICE_TYPE = "urn:schemas-upnp-org:service:power:1";

private final static String AIRCON_DEVICE_TYPE = "urn:schemas-upnp-org:device:aircon:1";
private final static String TEMP_SERVICE_TYPE = "urn:schemas-upnp-org:service:temp:1";

private final static String WASHER_DEVICE_TYPE = "urn:schemas-upnp-org:device:washer:1";
private final static String STATUS_SERVICE_TYPE = "urn:schemas-upnp-org:service:state:1";

public void doSubscribe() {
  subscriber = new UPnPSubscriber(Activator.context, this);
  subscriber.subscribeEveryServiceType(CLOCK_DEVICE_TYPE, TIME_SERVICE_TYPE);
  subscriber.subscribeEveryServiceType(AIRCON_DEVICE_TYPE, TEMP_SERVICE_TYPE);
  subscriber.subscribeEveryServiceType(LIGHT_DEVICE_TYPE, POWER_SERVICE_TYPE);
  subscriber.subscribeEveryServiceType(WASHER_DEVICE_TYPE, STATUS_SERVICE_TYPE);
}

public void undoSubscribe(){
       subscriber.unsubscribeAll();}

The class org.apache.felix.upnp.extra.util.UPnPEventNotifier is a utility class that manages the delivery of notifications for you. There are two constructors. The first one takes a BundleContext, a UPnPDevice , and a UPnPServicereference UPnPService reference. They are internally used to keep trace of all the registered UPnPEvenListener that are interested in monitoring events generated by your UPnP service. UPnPEventNotifierimplements UPnPEventNotifier implements the java beans PropertyChangeListener interface; once changes of the service state variables occurs you should call the method propertyChange(PropertyChangeEvent evt). Alternatively, you may use the second constructor to pass a reference to a model implementing the interface: EventSourcedefined EventSource defined in the Extra bundle. This model should use the PropertyChangeSupport to keep trace of PropertyChangeListener, and the related method firePropertyChange to notify changes. The EventSource interface is used internally by the UPnPEventNotifier to register itself as propertychangeListener of the model. Thus, in this case, you don't have to call propertyChange()directly: it is a duty of your model. As an example, take a look at LightModelclass LightModel class in the BinaryLight bundle.

The Felix UPnP base driver registers a non standard service implementing two interfaces:

org.apache.felix.upnp.basedriver.controller.DevicesInfo;
org.apache.felix.upnp.basedriver.controller.DriverController;

The former can be used to retrieve the XML description of both devices and services. Other than be used for debugging purpose, it allows access to the UPnP schema extensions defined by UPnP Vendors. According to the UDA 1.0 they consist of elements inserted in different points of the XML description and by convention starting with the prefix "X_". This interface is used by the context menu handler of the UPnP Tester bundle.

...