Exemplo n.º 1
0
  public void success(ActionInvocation invocation) {
    log.fine("Successful browse action, reading output argument values");

    BrowseResult result =
        new BrowseResult(
            invocation.getOutput("Result").getValue().toString(),
            (UnsignedIntegerFourBytes) invocation.getOutput("NumberReturned").getValue(),
            (UnsignedIntegerFourBytes) invocation.getOutput("TotalMatches").getValue(),
            (UnsignedIntegerFourBytes) invocation.getOutput("UpdateID").getValue());

    boolean proceed = receivedRaw(invocation, result);

    if (proceed && result.getCountLong() > 0 && result.getResult().length() > 0) {

      try {

        DIDLParser didlParser = new DIDLParser();
        DIDLContent didl = didlParser.parse(result.getResult());
        received(invocation, didl);
        updateStatus(Status.OK);

      } catch (Exception ex) {
        invocation.setFailure(
            new ActionException(
                ErrorCode.ACTION_FAILED, "Can't parse DIDL XML response: " + ex, ex));
        failure(invocation, null);
      }

    } else {
      received(invocation, new DIDLContent());
      updateStatus(Status.NO_CONTENT);
    }
  }
Exemplo n.º 2
0
  @Override
  public void getSourceCode(DeviceWrapper wrapper, String agentId, IAgentUPnPListener listener) {
    final DeviceWrapper refDevice = wrapper;
    final IAgentUPnPListener callback = listener;

    if (_upnpService != null) {
      Service service = wrapper.getDevice().findService(upnpAgentService);
      Action getAgentSourceAction = service.getAction("GetAgentSource");

      ActionInvocation getAgentSourceInvocation = new ActionInvocation(getAgentSourceAction);
      getAgentSourceInvocation.setInput("AgentId", agentId);

      ActionCallback getAgentSourceCallback =
          new ActionCallback(getAgentSourceInvocation) {

            @Override
            public void success(ActionInvocation invocation) {
              AgentScript networkScript = null;

              ActionArgumentValue agents = invocation.getOutput("Agent");
              if (agents != null) {
                if (agents.getDatatype().getBuiltin() == Datatype.Builtin.STRING) {
                  String encodedJsonArray = String.valueOf(agents.getValue());

                  try {
                    JSONObject agentObject = new JSONObject(encodedJsonArray);
                    networkScript = new AgentNetworkScript(refDevice, agentObject);

                  } catch (JSONException e) {
                    e.printStackTrace();
                  }
                }
              }

              callback.setAgentSourceCode(refDevice, networkScript);
            }

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

      _upnpService.getControlPoint().execute(getAgentSourceCallback);
    }
  }