コード例 #1
0
  public void activate(String client_id) throws UPnPException {

    UPnPAction act = service.getAction("Activate");

    if (act == null) {

      throw (new UPnPException("Activate not supported"));

    } else {

      UPnPActionInvocation inv = act.getInvocation();

      inv.addArgument("NewClientID", client_id);

      UPnPActionArgument[] args = inv.invoke();

      for (int i = 0; i < args.length; i++) {

        UPnPActionArgument arg = args[i];

        String name = arg.getName();

        if (name.equalsIgnoreCase("NewStatus")) {

          return;
        }
      }

      throw (new UPnPException("status not found"));
    }
  }
コード例 #2
0
  public long getFreeSpace(String client_id) throws UPnPException {

    UPnPAction act = service.getAction("GetFreeSpace");

    if (act == null) {

      throw (new UPnPException("GetFreeSpace not supported"));

    } else {

      UPnPActionInvocation inv = act.getInvocation();

      inv.addArgument("NewClientID", client_id);

      UPnPActionArgument[] args = inv.invoke();

      for (int i = 0; i < args.length; i++) {

        UPnPActionArgument arg = args[i];

        String name = arg.getName();

        if (name.equalsIgnoreCase("NewFreeSpace")) {

          return (Long.parseLong(arg.getValue()));
        }
      }

      throw (new UPnPException("result not found"));
    }
  }
コード例 #3
0
  public String addDownload(String client_id, String hash, String torrent) throws UPnPException {

    UPnPAction act = service.getAction("AddDownload");

    if (act == null) {

      throw (new UPnPException("AddDownload not supported"));

    } else {

      UPnPActionInvocation inv = act.getInvocation();

      inv.addArgument("NewClientID", client_id);
      inv.addArgument("NewTorrentHash", hash);
      inv.addArgument("NewTorrentData", torrent);

      UPnPActionArgument[] args = inv.invoke();

      for (int i = 0; i < args.length; i++) {

        UPnPActionArgument arg = args[i];

        String name = arg.getName();

        if (name.equalsIgnoreCase("NewStatus")) {

          return (arg.getValue());
        }
      }

      throw (new UPnPException("result not found"));
    }
  }
コード例 #4
0
  public String[] updateDownload(String client_id, String hash, String required_map)
      throws UPnPException {
    UPnPAction act = service.getAction("UpdateDownload");

    if (act == null) {

      throw (new UPnPException("UpdateDownload not supported"));

    } else {

      UPnPActionInvocation inv = act.getInvocation();

      inv.addArgument("NewClientID", client_id);
      inv.addArgument("NewTorrentHash", hash);
      inv.addArgument("NewPieceRequiredMap", required_map);

      UPnPActionArgument[] args = inv.invoke();

      String have = null;
      String status = null;

      for (int i = 0; i < args.length; i++) {

        UPnPActionArgument arg = args[i];

        String name = arg.getName();

        if (name.equalsIgnoreCase("NewPieceHaveMap")) {

          have = arg.getValue();

        } else if (name.equalsIgnoreCase("NewStatus")) {

          status = arg.getValue();
        }
      }

      if (have != null && status != null) {

        return (new String[] {have, status});
      }

      throw (new UPnPException("have or status not found"));
    }
  }
コード例 #5
0
  public String[] startDownload(String client_id, String hash) throws UPnPException {

    UPnPAction act = service.getAction("StartDownload");

    if (act == null) {

      throw (new UPnPException("StartDownload not supported"));

    } else {

      UPnPActionInvocation inv = act.getInvocation();

      inv.addArgument("NewClientID", client_id);
      inv.addArgument("NewTorrentHash", hash);

      UPnPActionArgument[] args = inv.invoke();

      String status = null;
      String data_port = null;

      for (int i = 0; i < args.length; i++) {

        UPnPActionArgument arg = args[i];

        String name = arg.getName();

        if (name.equalsIgnoreCase("NewStatus")) {

          status = arg.getValue();

        } else if (name.equalsIgnoreCase("NewDataPort")) {

          data_port = arg.getValue();
        }
      }

      if (status != null && data_port != null) {

        return (new String[] {data_port, status});
      }

      throw (new UPnPException("status or data port not found"));
    }
  }
コード例 #6
0
  public String[] setDownloads(String client_id, String hash_list) throws UPnPException {

    UPnPAction act = service.getAction("SetDownloads");

    if (act == null) {

      throw (new UPnPException("SetDownloads not supported"));

    } else {

      UPnPActionInvocation inv = act.getInvocation();

      inv.addArgument("NewClientID", client_id);
      inv.addArgument("NewTorrentHashList", hash_list);

      UPnPActionArgument[] args = inv.invoke();

      String result = null;
      String status = null;

      for (int i = 0; i < args.length; i++) {

        UPnPActionArgument arg = args[i];

        String name = arg.getName();

        if (name.equalsIgnoreCase("NewSetDownloadsResultList")) {

          result = arg.getValue();

        } else if (name.equalsIgnoreCase("NewStatus")) {

          status = arg.getValue();
        }
      }

      if (result != null && status != null) {

        return (new String[] {result, status});
      }

      throw (new UPnPException("result or status not found"));
    }
  }