91 lines
3.1 KiB
Java
91 lines
3.1 KiB
Java
package haus.nightmare.lib3270j;
|
|
|
|
/**
|
|
* Connection state machine states.
|
|
* Mirrors the cstate enum from globals.h in x3270.
|
|
*/
|
|
public enum ConnectionState {
|
|
NOT_CONNECTED, // No socket, unknown mode
|
|
RECONNECTING, // Delay before automatic reconnect
|
|
RESOLVING, // Resolving hostname
|
|
TCP_PENDING, // Socket connection pending
|
|
TLS_PENDING, // TLS negotiation pending
|
|
PROXY_PENDING, // Proxy negotiation pending
|
|
TELNET_PENDING, // Telnet negotiation pending
|
|
CONNECTED_NVT, // Connected in NVT line mode
|
|
CONNECTED_NVT_CHAR, // Connected in NVT character-at-a-time mode
|
|
CONNECTED_3270, // Connected in RFC 1576 TN3270 mode
|
|
CONNECTED_UNBOUND, // Connected in TN3270E mode, unbound
|
|
CONNECTED_E_NVT, // Connected in TN3270E NVT mode
|
|
CONNECTED_SSCP, // Connected in TN3270E SSCP-LU mode
|
|
CONNECTED_TN3270E; // Connected in TN3270E 3270 mode
|
|
|
|
/** True if any kind of connection exists (even half-connected). */
|
|
public boolean isConnected() {
|
|
return this.ordinal() > NOT_CONNECTED.ordinal();
|
|
}
|
|
|
|
/** True if in a half-connected state (resolving through telnet pending). */
|
|
public boolean isHalfConnected() {
|
|
return this.ordinal() >= RESOLVING.ordinal() && this.ordinal() < CONNECTED_NVT.ordinal();
|
|
}
|
|
|
|
/** True if fully connected (past TCP pending). */
|
|
public boolean isFullyConnected() {
|
|
return this.ordinal() > TCP_PENDING.ordinal();
|
|
}
|
|
|
|
/** True if in NVT mode (any flavor). */
|
|
public boolean isNvt() {
|
|
return this == CONNECTED_NVT || this == CONNECTED_NVT_CHAR || this == CONNECTED_E_NVT;
|
|
}
|
|
|
|
/** True if in 3270 mode (any flavor). */
|
|
public boolean is3270() {
|
|
return this == CONNECTED_3270 || this == CONNECTED_TN3270E || this == CONNECTED_SSCP;
|
|
}
|
|
|
|
/** True if in SSCP-LU mode. */
|
|
public boolean isSscp() {
|
|
return this == CONNECTED_SSCP;
|
|
}
|
|
|
|
/** True if in TN3270E mode (any submode). */
|
|
public boolean isTn3270e() {
|
|
return this.ordinal() >= CONNECTED_UNBOUND.ordinal();
|
|
}
|
|
|
|
/** True if in a full data session (NVT or 3270). */
|
|
public boolean isFullSession() {
|
|
return isNvt() || is3270();
|
|
}
|
|
|
|
/**
|
|
* Map to IBM Host On-Demand ECL connection state integer codes.
|
|
* 0 = Disconnected, 1 = Connecting/Resolving, 2 = Connected (NVT/Unbound), 3 = Bound (Full 3270 session).
|
|
*/
|
|
public int toHoDStateCode() {
|
|
switch (this) {
|
|
case NOT_CONNECTED:
|
|
return 0;
|
|
case RECONNECTING:
|
|
case RESOLVING:
|
|
case TCP_PENDING:
|
|
case TLS_PENDING:
|
|
case PROXY_PENDING:
|
|
case TELNET_PENDING:
|
|
return 1;
|
|
case CONNECTED_NVT:
|
|
case CONNECTED_NVT_CHAR:
|
|
case CONNECTED_UNBOUND:
|
|
case CONNECTED_E_NVT:
|
|
case CONNECTED_SSCP:
|
|
return 2;
|
|
case CONNECTED_3270:
|
|
case CONNECTED_TN3270E:
|
|
default:
|
|
return 3;
|
|
}
|
|
}
|
|
}
|