Ejemplo n.º 1
0
 public static List<String> getServiceNames(Device d) {
   ArrayList<String> services = new ArrayList<>();
   for (Service s : d.getServices()) {
     services.add(s.getServiceId().getId());
   }
   return services;
 }
 protected void hydrateBasic(MutableService descriptor, Service undescribedService) {
   descriptor.serviceId = undescribedService.getServiceId();
   descriptor.serviceType = undescribedService.getServiceType();
   if (undescribedService instanceof RemoteService) {
     RemoteService rs = (RemoteService) undescribedService;
     descriptor.controlURI = rs.getControlURI();
     descriptor.eventSubscriptionURI = rs.getEventSubscriptionURI();
     descriptor.descriptorURI = rs.getDescriptorURI();
   }
 }
Ejemplo n.º 3
0
 public URI getPath(Service service) {
   if (service.getServiceId() == null) {
     throw new IllegalStateException("Can't generate local URI prefix without service ID");
   }
   StringBuilder s = new StringBuilder();
   s.append(SERVICE);
   s.append("/");
   s.append(service.getServiceId().getNamespace());
   s.append("/");
   s.append(service.getServiceId().getId());
   return URI.create(getPath(service.getDevice()).toString() + s.toString());
 }
 private void generateSpecVersion(Service serviceModel, Document descriptor, Element rootElement) {
   Element specVersionElement = appendNewElement(descriptor, rootElement, ELEMENT.specVersion);
   appendNewElementIfNotNull(
       descriptor,
       specVersionElement,
       ELEMENT.major,
       serviceModel.getDevice().getVersion().getMajor());
   appendNewElementIfNotNull(
       descriptor,
       specVersionElement,
       ELEMENT.minor,
       serviceModel.getDevice().getVersion().getMinor());
 }
Ejemplo n.º 5
0
 @SuppressWarnings("unchecked")
 @Override
 public ActionInvocation<RemoteService> getActionInvocation() {
   final Action<RemoteService> action = service.getAction(actionName);
   if (action == null) {
     throw new ClingRouterException(
         "No action found for name '"
             + actionName
             + "'. Available actions: "
             + Arrays.toString(service.getActions()));
   }
   @SuppressWarnings("rawtypes")
   final ActionArgumentValue[] argumentArray = getArguments(action);
   return new ActionInvocation<RemoteService>(action, argumentArray);
 }
  void executeAction(UpnpService upnpService, Service NodoTemp) {

    Action getStatusAction = NodoTemp.getAction("GetStatus");
    ActionInvocation getStatusInvocation = new ActionInvocation(getStatusAction);

    ActionCallback getStatusCallback =
        new ActionCallback(getStatusInvocation) {

          @Override
          public void success(ActionInvocation invocation) {
            ActionArgumentValue status = invocation.getOutput("ResultStatus");

            assert status != null;

            System.out.println(status.toString());
          }

          @Override
          public void failure(
              ActionInvocation invocation, UpnpResponse operation, String defaultMsg) {
            System.err.println(defaultMsg);
          }
        };

    upnpService.getControlPoint().execute(getStatusCallback);
  }
Ejemplo n.º 7
0
 protected void subscribeAll(Device d, String uuid) {
   String name = getFriendlyName(d);
   int ctrl = 0;
   for (Service s : d.getServices()) {
     String sid = s.getServiceId().getId();
     LOGGER.debug("Subscribing to " + sid + " service on " + name);
     if (sid.contains("AVTransport")) {
       ctrl |= AVT;
     } else if (sid.contains("RenderingControl")) {
       ctrl |= RC;
     }
     upnpService.getControlPoint().execute(new SubscriptionCB(s));
   }
   rendererMap.mark(uuid, RENEW, false);
   rendererMap.mark(uuid, CONTROLS, ctrl);
 }
Ejemplo n.º 8
0
  // Convenience functions for sending various upnp service requests
  public static ActionInvocation send(
      final Device dev, String instanceID, String service, String action, String... args) {
    Service svc = dev.findService(ServiceId.valueOf("urn:upnp-org:serviceId:" + service));
    final String uuid = getUUID(dev);
    if (svc != null) {
      Action x = svc.getAction(action);
      String name = getFriendlyName(dev);
      boolean log = !action.equals("GetPositionInfo");
      if (x != null) {
        ActionInvocation a = new ActionInvocation(x);
        a.setInput("InstanceID", instanceID);
        for (int i = 0; i < args.length; i += 2) {
          a.setInput(args[i], args[i + 1]);
        }
        if (log) {
          LOGGER.debug("Sending upnp {}.{} {} to {}[{}]", service, action, args, name, instanceID);
        }
        new ActionCallback(a, upnpService.getControlPoint()) {
          @Override
          public void success(ActionInvocation invocation) {
            rendererMap.mark(uuid, ACTIVE, true);
          }

          @Override
          public void failure(
              ActionInvocation invocation, UpnpResponse operation, String defaultMsg) {
            LOGGER.debug("Action failed: {}", defaultMsg);
            rendererMap.mark(uuid, ACTIVE, false);
          }
        }.run();

        if (log) {
          for (ActionArgumentValue arg : a.getOutput()) {
            LOGGER.debug(
                "Received from {}[{}]: {}={}",
                name,
                instanceID,
                arg.getArgument().getName(),
                arg.toString());
          }
        }
        return a;
      }
    }
    return null;
  }
Ejemplo n.º 9
0
 public ContentItem(Container container, Service service) {
   this.service = service;
   this.device = service.getDevice();
   this.content = container;
   this.id = container.getId();
   this.isContainer = true;
   this.subtitle = "Folder";
   this.defaultResource = R.drawable.ic_folder;
 }
  private void generateActionList(Service serviceModel, Document descriptor, Element scpdElement) {

    Element actionListElement = appendNewElement(descriptor, scpdElement, ELEMENT.actionList);

    for (Action action : serviceModel.getActions()) {
      if (!action.getName().equals(QueryStateVariableAction.ACTION_NAME))
        generateAction(action, descriptor, actionListElement);
    }
  }
  private void generateServiceStateTable(
      Service serviceModel, Document descriptor, Element scpdElement) {

    Element serviceStateTableElement =
        appendNewElement(descriptor, scpdElement, ELEMENT.serviceStateTable);

    for (StateVariable stateVariable : serviceModel.getStateVariables()) {
      generateStateVariable(stateVariable, descriptor, serviceStateTableElement);
    }
  }
Ejemplo n.º 12
0
  public void init(Service service) {
    this.service = service;

    view.setPresenter(this);
    view.setTitle(
        "WAN IP Connection on " + service.getDevice().getRoot().getDetails().getFriendlyName());

    portMappingPresenter.init(
        view.getPortMappingListView(), view.getPortMappingEditView(), service, this);

    updateConnectionInfo();
  }
  private void generateScpd(Service serviceModel, Document descriptor) {

    Element scpdElement =
        descriptor.createElementNS(Descriptor.Service.NAMESPACE_URI, ELEMENT.scpd.toString());
    descriptor.appendChild(scpdElement);

    generateSpecVersion(serviceModel, descriptor, scpdElement);
    if (serviceModel.hasActions()) {
      generateActionList(serviceModel, descriptor, scpdElement);
    }
    generateServiceStateTable(serviceModel, descriptor, scpdElement);
  }
Ejemplo n.º 14
0
  /** @param maxResults Can be <code>null</code>, then {@link #getDefaultMaxResults()} is used. */
  public Browse(
      Service service,
      String objectID,
      BrowseFlag flag,
      String filter,
      long firstResult,
      Long maxResults,
      SortCriterion... orderBy) {

    super(new ActionInvocation(service.getAction("Browse")));

    log.fine("Creating browse action for object ID: " + objectID);

    getActionInvocation().setInput("ObjectID", objectID);
    getActionInvocation().setInput("BrowseFlag", flag.toString());
    getActionInvocation().setInput("Filter", filter);
    getActionInvocation().setInput("StartingIndex", new UnsignedIntegerFourBytes(firstResult));
    getActionInvocation()
        .setInput(
            "RequestedCount",
            new UnsignedIntegerFourBytes(maxResults == null ? getDefaultMaxResults() : maxResults));
    getActionInvocation().setInput("SortCriteria", SortCriterion.toString(orderBy));
  }
Ejemplo n.º 15
0
 public SubscriptionCB(Service s) {
   super(s);
   uuid = getUUID(s.getDevice());
 }