コード例 #1
0
  /**
   * Arrival event as a NetworkMonitorEventListener
   *
   * @param nme NetworkMonitorEvent add
   */
  public void deviceArrival(DeviceMonitorEvent event) {

    int count = event.getDeviceCount();
    for (int i = 0; i < count; i++) {

      String address = event.getAddressAsStringAt(i);

      // Search all the implemented Container interfaces
      OneWireContainer owc = event.getContainerAt(i);

      if (owc instanceof ADContainer) {
        registeredProducers.put(address, new OneWireADVoltageProducer(context, owc, pollInterval));
      }
      if (owc instanceof HumidityContainer) {
        registeredProducers.put(address, new OneWireHumidityProducer(context, owc, pollInterval));
      }
      if (owc instanceof SwitchContainer) {
        // TODO org.osgi.util.measurement.State
        // one producer per channel ???
        // ((SwitchContainer)owc).getNumberChannels()
        /*
         * TODO registeredProducers.put( nme.getAddressAsString(), new
         * OneWireStateProducer(context,owc) );
         */
      }
      if (owc instanceof TemperatureContainer) {
        registeredProducers.put(
            address, new OneWireTemperatureProducer(context, owc, pollInterval));
      }
    }
  }
コード例 #2
0
  /**
   * Depart event as a NetworkMonitorEventListener
   *
   * @param nme NetworkMonitorEvent depart
   */
  public void deviceDeparture(DeviceMonitorEvent event) {

    int count = event.getDeviceCount();
    for (int i = 0; i < count; i++) {
      String address = event.getAddressAsStringAt(i);
      OneWireAbstractProducer owp = (OneWireAbstractProducer) registeredProducers.remove(address);
      owp.end();
    }
  }