Class NativeSubprocessTransport

java.lang.Object
com.codename1.bluetooth.helper.NativeSubprocessTransport
All Implemented Interfaces:
HelperTransport

public abstract class NativeSubprocessTransport extends Object implements HelperTransport
A HelperTransport over a native child process, for the ports that have no java.lang.ProcessBuilder (the native Win32 and Linux desktop ports). This class owns the line framing -- assembling readLine() from raw byte reads and UTF-8-encoding writeLine() with a trailing newline -- over a handful of raw process primitives each port implements with its own posix_spawn/CreateProcess native bridge. The subclass supplies only those raw calls; all protocol/threading logic lives above this in HelperBleBackend.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Releases the transport and terminates the child process.
    boolean
    True while the child process is running.
    protected abstract void
    rawClose(long handle)
    Terminates the child, closes pipes and frees the handle.
    protected abstract void
    rawCloseStdin(long handle)
    Closes the child's stdin (EOF) without terminating it.
    protected abstract int
    rawIsAlive(long handle)
    1 when the child is still running, 0 when it has exited.
    protected abstract int
    rawRead(long handle, byte[] buf, int off, int len)
    Blocking read of up to len bytes from the child's stdout into buf at off; returns bytes read, 0 on EOF, -1 on error.
    protected abstract long
    rawSpawn(String[] argv)
    Spawns argv[0] with argv as arguments and its stdin/stdout wired to pipes; returns an opaque handle, or 0 on failure.
    protected abstract int
    rawWrite(long handle, byte[] buf, int off, int len)
    Writes len bytes from buf at off to the child's stdin; returns bytes written or -1.
    Reads one line of the helper's standard output, blocking until a line is available.
    void
    start(List<String> command)
    Launches the helper.
    void
    Writes one command line to the helper's standard input.

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • NativeSubprocessTransport

      protected NativeSubprocessTransport(List<String> configuredCommand)
      Parameters:
      configuredCommand - the helper launch command this transport runs when start(List) is passed null (the resolved helper path + args)
  • Method Details

    • rawSpawn

      protected abstract long rawSpawn(String[] argv)
      Spawns argv[0] with argv as arguments and its stdin/stdout wired to pipes; returns an opaque handle, or 0 on failure.
    • rawRead

      protected abstract int rawRead(long handle, byte[] buf, int off, int len)
      Blocking read of up to len bytes from the child's stdout into buf at off; returns bytes read, 0 on EOF, -1 on error.
    • rawWrite

      protected abstract int rawWrite(long handle, byte[] buf, int off, int len)
      Writes len bytes from buf at off to the child's stdin; returns bytes written or -1.
    • rawCloseStdin

      protected abstract void rawCloseStdin(long handle)
      Closes the child's stdin (EOF) without terminating it.
    • rawClose

      protected abstract void rawClose(long handle)
      Terminates the child, closes pipes and frees the handle.
    • rawIsAlive

      protected abstract int rawIsAlive(long handle)
      1 when the child is still running, 0 when it has exited.
    • start

      public void start(List<String> command) throws IOException
      Description copied from interface: HelperTransport
      Launches the helper. command is the launch command line (the resolved helper binary path, optionally with arguments). A transport that was pre-configured with its own command by its factory may ignore a null argument and launch that instead.
      Specified by:
      start in interface HelperTransport
      Parameters:
      command - the launch command line, or null to use the transport's pre-configured command
      Throws:
      IOException - when the child process cannot be started
    • readLine

      public String readLine() throws IOException
      Description copied from interface: HelperTransport
      Reads one line of the helper's standard output, blocking until a line is available.
      Specified by:
      readLine in interface HelperTransport
      Returns:
      the next line without its terminator, or null at end of stream (the helper closed stdout / exited)
      Throws:
      IOException - when the pipe fails
    • writeLine

      public void writeLine(String line) throws IOException
      Description copied from interface: HelperTransport
      Writes one command line to the helper's standard input. The line terminator is appended by the transport and the stream is flushed.
      Specified by:
      writeLine in interface HelperTransport
      Parameters:
      line - the single-line JSON command, without a terminator
      Throws:
      IOException - when the pipe fails
    • close

      public void close()
      Description copied from interface: HelperTransport
      Releases the transport and terminates the child process.
      Specified by:
      close in interface HelperTransport
    • isAlive

      public boolean isAlive()
      Description copied from interface: HelperTransport
      True while the child process is running.
      Specified by:
      isAlive in interface HelperTransport