Class NativeSubprocessTransport
java.lang.Object
com.codename1.bluetooth.helper.NativeSubprocessTransport
- All Implemented Interfaces:
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
ConstructorsModifierConstructorDescriptionprotectedNativeSubprocessTransport(List<String> configuredCommand) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Releases the transport and terminates the child process.booleanisAlive()True while the child process is running.protected abstract voidrawClose(long handle) Terminates the child, closes pipes and frees the handle.protected abstract voidrawCloseStdin(long handle) Closes the child's stdin (EOF) without terminating it.protected abstract intrawIsAlive(long handle) 1when the child is still running,0when it has exited.protected abstract intrawRead(long handle, byte[] buf, int off, int len) Blocking read of up tolenbytes from the child's stdout intobufatoff; returns bytes read,0on EOF,-1on error.protected abstract longSpawnsargv[0]withargvas arguments and its stdin/stdout wired to pipes; returns an opaque handle, or0on failure.protected abstract intrawWrite(long handle, byte[] buf, int off, int len) Writeslenbytes frombufatoffto the child's stdin; returns bytes written or-1.readLine()Reads one line of the helper's standard output, blocking until a line is available.voidLaunches the helper.voidWrites one command line to the helper's standard input.
-
Constructor Details
-
NativeSubprocessTransport
- Parameters:
configuredCommand- the helper launch command this transport runs whenstart(List)is passednull(the resolved helper path + args)
-
-
Method Details
-
rawSpawn
Spawnsargv[0]withargvas arguments and its stdin/stdout wired to pipes; returns an opaque handle, or0on failure. -
rawRead
protected abstract int rawRead(long handle, byte[] buf, int off, int len) Blocking read of up tolenbytes from the child's stdout intobufatoff; returns bytes read,0on EOF,-1on error. -
rawWrite
protected abstract int rawWrite(long handle, byte[] buf, int off, int len) Writeslenbytes frombufatoffto 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) 1when the child is still running,0when it has exited. -
start
Description copied from interface:HelperTransportLaunches the helper.commandis 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 anullargument and launch that instead.- Specified by:
startin interfaceHelperTransport- Parameters:
command- the launch command line, ornullto use the transport's pre-configured command- Throws:
IOException- when the child process cannot be started
-
readLine
Description copied from interface:HelperTransportReads one line of the helper's standard output, blocking until a line is available.- Specified by:
readLinein interfaceHelperTransport- Returns:
- the next line without its terminator, or
nullat end of stream (the helper closed stdout / exited) - Throws:
IOException- when the pipe fails
-
writeLine
Description copied from interface:HelperTransportWrites one command line to the helper's standard input. The line terminator is appended by the transport and the stream is flushed.- Specified by:
writeLinein interfaceHelperTransport- Parameters:
line- the single-line JSON command, without a terminator- Throws:
IOException- when the pipe fails
-
close
public void close()Description copied from interface:HelperTransportReleases the transport and terminates the child process.- Specified by:
closein interfaceHelperTransport
-
isAlive
public boolean isAlive()Description copied from interface:HelperTransportTrue while the child process is running.- Specified by:
isAlivein interfaceHelperTransport
-