Example #1
0
  public void onLocalDeviceComplete(@Observes @Phase.Complete LocalDeviceDiscovery discovery) {
    LocalDevice device = discovery.getDevice();

    String[] labels =
        new String[] {
          device.getDetails().getFriendlyName(),
          device.getDisplayString(),
          "(LOCAL) " + device.getType().getDisplayString()
        };

    final DeviceItem deviceItem = new DeviceItem(device, labels);

    Icon usableIcon = findUsableIcon(device);
    if (usableIcon != null) {
      ImageIcon imageIcon = new ImageIcon(usableIcon.getData());
      deviceItem.setIcon(imageIcon);
    } else {
      deviceItem.setIcon(getUnknownDeviceIcon(deviceItem.getLabel()[0]));
    }

    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            view.addDeviceItem(deviceItem);
          }
        });
  }
Example #2
0
 public void onLocalDeviceRemoved(@Observes @Phase.Byebye LocalDeviceDiscovery discovery) {
   LocalDevice device = discovery.getDevice();
   final DeviceItem deviceItem = new DeviceItem(device, device.getDisplayString());
   SwingUtilities.invokeLater(
       new Runnable() {
         public void run() {
           view.removeDeviceItem(deviceItem);
         }
       });
 }
  public LocalDevice getLocalDevice(String UDN) {

    for (LocalDevice device : m_upnpService.getRegistry().getLocalDevices()) {
      Log.i(
          TAG,
          "Local device:"
              + device.getDetails().getFriendlyName()
              + ","
              + device.getIdentity().getUdn().toString());
      if (device.getIdentity().getUdn().toString().compareTo(UDN) == 0) return device;
    }
    return null;
  }
Example #4
0
  protected List<OutgoingSearchResponse> createDeviceMessages(
      LocalDevice device, NetworkAddress activeStreamServer) {
    List<OutgoingSearchResponse> msgs = new ArrayList<OutgoingSearchResponse>();

    // See the tables in UDA 1.0 section 1.1.2

    if (device.isRoot()) {
      msgs.add(
          new OutgoingSearchResponseRootDevice(
              getInputMessage(), getDescriptorLocation(activeStreamServer, device), device));
    }

    msgs.add(
        new OutgoingSearchResponseUDN(
            getInputMessage(), getDescriptorLocation(activeStreamServer, device), device));

    msgs.add(
        new OutgoingSearchResponseDeviceType(
            getInputMessage(), getDescriptorLocation(activeStreamServer, device), device));

    for (OutgoingSearchResponse msg : msgs) {
      prepareOutgoingSearchResponse(msg);
    }

    return msgs;
  }
Example #5
0
  @Test(dataProvider = "devices")
  public void validateBinding(LocalDevice device) {

    LocalService svc = device.getServices()[0];

    assertEquals(svc.getStateVariables().length, 1);
    assertEquals(
        svc.getStateVariables()[0].getTypeDetails().getDatatype().getBuiltin(),
        Datatype.Builtin.STRING);

    assertEquals(svc.getActions().length, 3); // Has 2 actions plus QueryStateVariableAction!

    assertEquals(svc.getAction("GetColor").getArguments().length, 1);
    assertEquals(svc.getAction("GetColor").getArguments()[0].getName(), "Out");
    assertEquals(
        svc.getAction("GetColor").getArguments()[0].getDirection(), ActionArgument.Direction.OUT);
    assertEquals(
        svc.getAction("GetColor").getArguments()[0].getRelatedStateVariableName(), "Color");

    assertEquals(svc.getAction("SetColor").getArguments().length, 1);
    assertEquals(svc.getAction("SetColor").getArguments()[0].getName(), "In");
    assertEquals(
        svc.getAction("SetColor").getArguments()[0].getDirection(), ActionArgument.Direction.IN);
    assertEquals(
        svc.getAction("SetColor").getArguments()[0].getRelatedStateVariableName(), "Color");
  }
  @Test
  public void sendMessageToTV() throws Exception {

    final boolean[] tests = new boolean[1];

    UpnpService upnpService = new MockUpnpService();

    LocalDevice device = MessageBoxSampleData.createDevice(MyTV.class);
    upnpService.getRegistry().addDevice(device);

    MessageSMS msg =
        new MessageSMS(
            new DateTime("2010-06-21", "16:34:12"),
            new NumberName("1234", "The Receiver"),
            new NumberName("5678", "The Sender"),
            "Hello World!");

    LocalService service =
        device.findService(new ServiceId("samsung.com", "MessageBoxService")); // DOC: S1

    upnpService
        .getControlPoint()
        .execute(
            new AddMessage(service, msg) {

              @Override
              public void success(ActionInvocation invocation) {
                // All OK
                tests[0] = true; // DOC: EXC1
              }

              @Override
              public void failure(
                  ActionInvocation invocation, UpnpResponse operation, String defaultMsg) {
                // Something is wrong
              }
            }); // DOC: S1

    for (boolean test : tests) {
      assert test;
    }
    for (boolean test : ((LocalService<MyTV>) service).getManager().getImplementation().tests) {
      assert test;
    }
  }
Example #7
0
 protected List<OutgoingSearchResponse> createServiceTypeMessages(
     LocalDevice device, NetworkAddress activeStreamServer) {
   List<OutgoingSearchResponse> msgs = new ArrayList<OutgoingSearchResponse>();
   for (ServiceType serviceType : device.findServiceTypes()) {
     OutgoingSearchResponse message =
         new OutgoingSearchResponseServiceType(
             getInputMessage(),
             getDescriptorLocation(activeStreamServer, device),
             device,
             serviceType);
     prepareOutgoingSearchResponse(message);
     msgs.add(message);
   }
   return msgs;
 }
Example #8
0
  protected void sendSearchResponseAll(NetworkAddress activeStreamServer) throws RouterException {
    log.fine("Responding to 'all' search with advertisement messages for all local devices");
    for (LocalDevice localDevice : getUpnpService().getRegistry().getLocalDevices()) {

      if (isAdvertisementDisabled(localDevice)) continue;

      // We are re-using the regular notification messages here but override the NT with the ST
      // header
      log.finer("Sending root device messages: " + localDevice);
      List<OutgoingSearchResponse> rootDeviceMsgs =
          createDeviceMessages(localDevice, activeStreamServer);
      for (OutgoingSearchResponse upnpMessage : rootDeviceMsgs) {
        getUpnpService().getRouter().send(upnpMessage);
      }

      if (localDevice.hasEmbeddedDevices()) {
        for (LocalDevice embeddedDevice : localDevice.findEmbeddedDevices()) {
          log.finer("Sending embedded device messages: " + embeddedDevice);
          List<OutgoingSearchResponse> embeddedDeviceMsgs =
              createDeviceMessages(embeddedDevice, activeStreamServer);
          for (OutgoingSearchResponse upnpMessage : embeddedDeviceMsgs) {
            getUpnpService().getRouter().send(upnpMessage);
          }
        }
      }

      List<OutgoingSearchResponse> serviceTypeMsgs =
          createServiceTypeMessages(localDevice, activeStreamServer);
      if (serviceTypeMsgs.size() > 0) {
        log.finer("Sending service type messages");
        for (OutgoingSearchResponse upnpMessage : serviceTypeMsgs) {
          getUpnpService().getRouter().send(upnpMessage);
        }
      }
    }
  }
Example #9
0
  @Test(dataProvider = "devices")
  public void invokeActions(LocalDevice device) {
    LocalService svc = device.getServices()[0];

    ActionInvocation setColor = new ActionInvocation(svc.getAction("SetColor"));
    setColor.setInput("In", MyServiceWithEnum.Color.Blue);
    svc.getExecutor(setColor.getAction()).execute(setColor);
    assertEquals(setColor.getFailure(), null);
    assertEquals(setColor.getOutput().length, 0);

    ActionInvocation getColor = new ActionInvocation(svc.getAction("GetColor"));
    svc.getExecutor(getColor.getAction()).execute(getColor);
    assertEquals(getColor.getFailure(), null);
    assertEquals(getColor.getOutput().length, 1);
    assertEquals(getColor.getOutput()[0].toString(), MyServiceWithEnum.Color.Blue.name());
  }
Example #10
0
 protected boolean isAdvertisementDisabled(LocalDevice device) {
   DiscoveryOptions options =
       getUpnpService().getRegistry().getDiscoveryOptions(device.getIdentity().getUdn());
   return options != null && !options.isAdvertised();
 }
Example #11
0
  @Test
  public void getInitialEventRenderingControl() throws Exception {

    MockUpnpService upnpService = new MockUpnpService();

    final List<Boolean> testAssertions = new ArrayList();

    LocalDevice device = MediaRendererSampleData.createDevice();
    upnpService.getRegistry().addDevice(device);

    LocalService service = device.getServices()[1];

    SubscriptionCallback callback =
        new SubscriptionCallback(service, 600) {

          @Override
          public void established(GENASubscription sub) {}

          @Override
          protected void failed(
              GENASubscription subscription,
              UpnpResponse responseStatus,
              Exception exception,
              String defaultMsg) {
            throw new RuntimeException(defaultMsg, exception);
          }

          @Override
          public void ended(GENASubscription sub, CancelReason reason, UpnpResponse response) {}

          public void eventReceived(GENASubscription sub) {

            Map<String, StateVariableValue> values = sub.getCurrentValues();
            String lastChangeString = values.get("LastChange").toString();

            try {
              LastChange lastChange =
                  new LastChange(new RenderingControlLastChangeParser(), lastChangeString);
              assertEquals(lastChange.getInstanceIDs().length, 1);
              assertEquals(
                  lastChange
                      .getEventedValue(0, RenderingControlVariable.Mute.class)
                      .getValue()
                      .getChannel(),
                  Channel.Master);
              assertEquals(
                  lastChange
                      .getEventedValue(0, RenderingControlVariable.Mute.class)
                      .getValue()
                      .getMute(),
                  Boolean.FALSE);
              assertEquals(
                  lastChange
                      .getEventedValue(0, RenderingControlVariable.Loudness.class)
                      .getValue()
                      .getChannel(),
                  Channel.Master);
              assertEquals(
                  lastChange
                      .getEventedValue(0, RenderingControlVariable.Loudness.class)
                      .getValue()
                      .getLoudness(),
                  Boolean.FALSE);
              assertEquals(
                  lastChange
                      .getEventedValue(0, RenderingControlVariable.Volume.class)
                      .getValue()
                      .getChannel(),
                  Channel.Master);
              assertEquals(
                  lastChange
                      .getEventedValue(0, RenderingControlVariable.Volume.class)
                      .getValue()
                      .getVolume(),
                  new Integer(50));
              assertEquals(
                  lastChange
                      .getEventedValue(0, RenderingControlVariable.VolumeDB.class)
                      .getValue()
                      .getChannel(),
                  Channel.Master);
              assertEquals(
                  lastChange
                      .getEventedValue(0, RenderingControlVariable.VolumeDB.class)
                      .getValue()
                      .getVolumeDB(),
                  new Integer(0));

              testAssertions.add(true);

            } catch (Exception ex) {
              throw new RuntimeException(ex);
            }
          }

          public void eventsMissed(GENASubscription sub, int numberOfMissedEvents) {}
        };

    upnpService.getControlPoint().execute(callback);

    assertEquals(testAssertions.size(), 1);
    for (Boolean testAssertion : testAssertions) {
      assert testAssertion;
    }
  }
Example #12
0
  @Test
  public void getInitialEventAVTransport() throws Exception {

    MockUpnpService upnpService = new MockUpnpService();

    final List<Boolean> testAssertions = new ArrayList();

    LocalDevice device = MediaRendererSampleData.createDevice();
    upnpService.getRegistry().addDevice(device);

    LocalService service = device.getServices()[0];

    SubscriptionCallback callback =
        new SubscriptionCallback(service, 600) {

          @Override
          public void established(GENASubscription sub) {}

          @Override
          protected void failed(
              GENASubscription subscription,
              UpnpResponse responseStatus,
              Exception exception,
              String defaultMsg) {
            throw new RuntimeException(defaultMsg, exception);
          }

          @Override
          public void ended(GENASubscription sub, CancelReason reason, UpnpResponse response) {}

          public void eventReceived(GENASubscription sub) {

            Map<String, StateVariableValue> values = sub.getCurrentValues();
            String lastChangeString = values.get("LastChange").toString();

            try {
              LastChange lastChange =
                  new LastChange(new AVTransportLastChangeParser(), lastChangeString);
              assertEquals(lastChange.getInstanceIDs().length, 1);
              assertEquals(
                  lastChange
                      .getEventedValue(0, AVTransportVariable.AVTransportURI.class)
                      .getValue(),
                  null);
              assertEquals(
                  lastChange
                      .getEventedValue(0, AVTransportVariable.AVTransportURIMetaData.class)
                      .getValue(),
                  null);
              assertEquals(
                  lastChange
                      .getEventedValue(0, AVTransportVariable.CurrentMediaDuration.class)
                      .getValue(),
                  "00:00:00");
              assertEquals(
                  lastChange
                      .getEventedValue(0, AVTransportVariable.CurrentPlayMode.class)
                      .getValue(),
                  PlayMode.NORMAL);
              assertEquals(
                  lastChange
                      .getEventedValue(0, AVTransportVariable.CurrentRecordQualityMode.class)
                      .getValue(),
                  RecordQualityMode.NOT_IMPLEMENTED);
              assertEquals(
                  lastChange.getEventedValue(0, AVTransportVariable.CurrentTrack.class).getValue(),
                  new UnsignedIntegerFourBytes(0));
              assertEquals(
                  lastChange
                      .getEventedValue(0, AVTransportVariable.CurrentTrackDuration.class)
                      .getValue(),
                  "00:00:00");
              assertEquals(
                  lastChange
                      .getEventedValue(0, AVTransportVariable.CurrentTrackMetaData.class)
                      .getValue(),
                  "NOT_IMPLEMENTED");
              assertEquals(
                  lastChange
                      .getEventedValue(0, AVTransportVariable.CurrentTrackURI.class)
                      .getValue(),
                  null);
              assertEquals(
                  lastChange
                      .getEventedValue(0, AVTransportVariable.CurrentTransportActions.class)
                      .getValue(),
                  new TransportAction[] {TransportAction.Stop});
              assertEquals(
                  lastChange
                      .getEventedValue(0, AVTransportVariable.NextAVTransportURI.class)
                      .getValue()
                      .toString(),
                  "NOT_IMPLEMENTED"); // TODO: That's weird
              assertEquals(
                  lastChange
                      .getEventedValue(0, AVTransportVariable.NumberOfTracks.class)
                      .getValue(),
                  new UnsignedIntegerFourBytes(0));
              assertEquals(
                  lastChange
                      .getEventedValue(0, AVTransportVariable.PossiblePlaybackStorageMedia.class)
                      .getValue(),
                  new StorageMedium[] {StorageMedium.NETWORK});
              assertEquals(
                  lastChange
                      .getEventedValue(0, AVTransportVariable.PossibleRecordQualityModes.class)
                      .getValue(),
                  new RecordQualityMode[] {RecordQualityMode.NOT_IMPLEMENTED});
              assertEquals(
                  lastChange
                      .getEventedValue(0, AVTransportVariable.PossibleRecordStorageMedia.class)
                      .getValue(),
                  new StorageMedium[] {StorageMedium.NOT_IMPLEMENTED});
              assertEquals(
                  lastChange
                      .getEventedValue(0, AVTransportVariable.RecordMediumWriteStatus.class)
                      .getValue(),
                  RecordMediumWriteStatus.NOT_IMPLEMENTED);
              assertEquals(
                  lastChange
                      .getEventedValue(0, AVTransportVariable.RecordStorageMedium.class)
                      .getValue(),
                  StorageMedium.NOT_IMPLEMENTED);
              assertEquals(
                  lastChange
                      .getEventedValue(0, AVTransportVariable.TransportPlaySpeed.class)
                      .getValue(),
                  "1");
              assertEquals(
                  lastChange
                      .getEventedValue(0, AVTransportVariable.TransportState.class)
                      .getValue(),
                  TransportState.NO_MEDIA_PRESENT);
              assertEquals(
                  lastChange
                      .getEventedValue(0, AVTransportVariable.TransportStatus.class)
                      .getValue(),
                  TransportStatus.OK);

              testAssertions.add(true);

            } catch (Exception ex) {
              throw new RuntimeException(ex);
            }
          }

          public void eventsMissed(GENASubscription sub, int numberOfMissedEvents) {}
        };

    upnpService.getControlPoint().execute(callback);

    assertEquals(testAssertions.size(), 1);
    for (Boolean testAssertion : testAssertions) {
      assert testAssertion;
    }
  }