Example #1
1
  @Override
  public Object[] callMethod(
      IComputerAccess computer, ILuaContext context, int method, Object[] arguments)
      throws LuaException, InterruptedException {
    if (method == 0) {
      // Open
      int channel = Modem.parseChannel(arguments, 0);
      this.open(channel);
    } else if (method == 1) {
      // Is open
      int channel = Modem.parseChannel(arguments, 0);
      return new Object[] {new Boolean(this.isOpen(channel))};
    } else if (method == 2) {
      // Close
      int channel = Modem.parseChannel(arguments, 0);
      this.close(channel);
    } else if (method == 3) {
      // Close all
      this.closeAll();
    } else if (method == 4) {
      // Transmit
      int channel = Modem.parseChannel(arguments, 0);
      int replyChannel = Modem.parseChannel(arguments, 1);
      Object message = arguments.length >= 3 ? arguments[2] : null;
      this.transmit(message, channel, replyChannel);
    } else if (method == 5) {
      // Is wireless
      return new Object[] {new Boolean(true)};
    }

    return new Object[] {};
  }
Example #2
0
 /**
  * Receive file <br>
  * This method support correct thread interruption, when thread is interrupted "cancel of
  * transmission" will be send. So you can move long transmission to other thread and interrupt it
  * according to your algorithm.
  *
  * @param file file path for storing
  * @throws java.io.IOException
  */
 public void receive(Path file) throws IOException {
   modem.receive(file, false);
 }
Example #3
0
 /**
  * Send a file. <br>
  * This method support correct thread interruption, when thread is interrupted "cancel of
  * transmission" will be send. So you can move long transmission to other thread and interrupt it
  * according to your algorithm.
  *
  * @param file
  * @throws java.io.IOException
  */
 public void send(Path file) throws IOException, InterruptedException {
   modem.send(file, true);
 }