diff --git a/configure.ac b/configure.ac index 531b7dd..4c0fb54 100644 --- a/configure.ac +++ b/configure.ac @@ -328,7 +328,7 @@ dnl --------------------------------------------------------------------------- AC_CONFIG_FILES(Makefile) AC_CONFIG_FILES(src/native/Makefile) AC_CONFIG_FILES(src/core/Makefile) -AC_CONFIG_FILES(src/core/tn3270-sharp.pc) +AC_CONFIG_FILES(src/core/mono-tn3270.pc) dnl --------------------------------------------------------------------------- dnl Output the generated config.status script. diff --git a/src/core/mono-tn3270.pc.in b/src/core/mono-tn3270.pc.in new file mode 100644 index 0000000..5b6b3b9 --- /dev/null +++ b/src/core/mono-tn3270.pc.in @@ -0,0 +1,11 @@ +prefix=${pcfiledir}/../.. +exec_prefix=${prefix} +libdir=${exec_prefix}/lib +gapidir=${prefix}/share/tn3270-sharp-@PACKAGE_MAJOR_VERSION@.@PACKAGE_MINOR_VERSION@ + + +Name: tn3270-sharp +Description: .NET Bindings for pw3270 +Version: @PACKAGE_MAJOR_VERSION@.@PACKAGE_MINOR_VERSION@ +Cflags: -I:${gapidir}/tn3270-sharp.xml +Libs: -r:${libdir}/mono/tn3270-sharp-@PACKAGE_MAJOR_VERSION@.@PACKAGE_MINOR_VERSION@/tn3270-sharp.dll diff --git a/src/core/tn3270-sharp.cs b/src/core/tn3270-sharp.cs deleted file mode 100644 index df7d9f9..0000000 --- a/src/core/tn3270-sharp.cs +++ /dev/null @@ -1,618 +0,0 @@ -/* - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a - * aplicativos mainframe. Registro no INPI sob o nome G3270. - * - * Copyright (C) <2008> - * - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela - * Free Software Foundation. - * - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para - * obter mais detalhes. - * - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin - * St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Este programa está nomeado como tn3270-sharp.cs e possui - linhas de código. - * - * Contatos: - * - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) - * - * Referências: - * - * https://msdn.microsoft.com/en-us/library/5ast78ax.aspx - * - */ - -using System; -using System.Text; -using System.Runtime.InteropServices; - -namespace pw3270 { - - /// - /// Session with 3270 HOST. - /// - public class Session { - - /// - /// lib3270 session handle - /// - private IntPtr hSession; - - [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] - extern static IntPtr tn3270_create_session(string name); - - [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] - extern static int tn3270_destroy_session(IntPtr session); - - [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] - extern static int tn3270_get_version(IntPtr session, StringBuilder str, int strlen); - - [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] - extern static int tn3270_get_revision(IntPtr session, StringBuilder str, int strlen); - - [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] - extern static int tn3270_connect(IntPtr Session, string host, int wait); - - [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] - extern static int tn3270_is_connected(IntPtr Session); - - [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] - extern static int tn3270_is_ready(IntPtr Session); - - [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] - extern static int tn3270_disconnect(IntPtr Session); - - [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] - extern static int tn3270_wait_for_ready(IntPtr Session, int seconds); - - [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] - extern static int tn3270_wait(IntPtr Session, int seconds); - - [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] - extern static int tn3270_get_cstate(IntPtr Session); - - [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] - extern static int tn3270_get_program_message(IntPtr Session); - - [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] - extern static int tn3270_get_secure(IntPtr Session); - - [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] - extern static int tn3270_get_contents(IntPtr Session, StringBuilder str, int strlen); - - [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] - extern static int tn3270_get_string(IntPtr Session, int addr, StringBuilder str, int strlen); - - [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] - extern static int tn3270_get_string_at(IntPtr Session, int row, int col, StringBuilder str, int strlen); - - [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] - extern static int tn3270_set_string_at(IntPtr Session, int row, int col, string str); - - [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] - extern static int tn3270_wait_for_string_at(IntPtr Session, int row, int col, string key, int timeout); - - [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] - extern static int tn3270_cmp_string_at(IntPtr Session, int row, int col, string str); - - [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] - extern static int tn3270_set_unlock_delay(IntPtr Session, int ms); - - [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] - extern static int tn3270_set_cursor_position(IntPtr Session, int row, int col); - - [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] - extern static int tn3270_set_cursor_addr(IntPtr Session, int addr); - - [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] - extern static int tn3270_get_cursor_addr(IntPtr Session); - - [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] - extern static int tn3270_enter(IntPtr Session); - - [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] - extern static int tn3270_pfkey(IntPtr Session, int key); - - [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] - extern static int tn3270_pakey(IntPtr Session, int key); - - [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] - extern static int tn3270_get_width(IntPtr Session); - - [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] - extern static int tn3270_get_height(IntPtr Session); - - [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] - extern static int tn3270_get_length(IntPtr Session); - - [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] - extern static int tn3270_set_charset(IntPtr Session, string str); - - [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] - extern static int tn3270_set_url(IntPtr Session, string str); - - [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] - extern static int tn3270_get_url(IntPtr Session, StringBuilder str, int strlen); - - [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] - extern static int tn3270_set_error_message(IntPtr Session, string str); - - [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] - extern static int tn3270_get_error_message(IntPtr Session, StringBuilder str, int strlen); - - /// - /// Create a new session with lib3270/pw3270 - /// - /// - /// Session name or empty string for a hidden session - /// - public Session(string name) { - hSession = tn3270_create_session(name); - tn3270_set_charset(hSession,"UTF-8"); - } - - /// - /// Disconnect from host, destroy session. - /// - /// - ~Session() { - tn3270_destroy_session(hSession); - } - - /// - /// Get lib3270/pw3270 Version identifier - /// - /// - /// - /// The version of the active instance. - /// - /// - public string GetVersion() { - StringBuilder str = new StringBuilder(10); - tn3270_get_version(hSession, str, 10); - return str.ToString(); - } - - /// - /// Lib3270 version. - /// - /// - /// - /// Lib3270 version string - /// - /// - public string Version { - get { - return GetVersion(); - } - } - - /// - /// Get lib3270/pw3270 Revision number - /// - /// - /// - /// The revision of the active instance. - /// - /// - public string GetRevision() { - StringBuilder str = new StringBuilder(10); - tn3270_get_revision(hSession, str, 10); - return str.ToString(); - } - - public string Revision { - get { - return GetRevision(); - } - } - - /// - /// Connect to 3270 host. - /// - /// - /// URL of the target host (tn3270://hostname:port) - /// How many seconds should the call wait for the connection becomes ready - /// - /// - /// - /// - public int Connect(string host, int wait) { - return tn3270_connect(hSession, host, wait); - } - - /// - /// Get connection state - /// - /// - /// - /// true if the session is connected to a remote host. - /// - /// - public bool IsConnected() { - return tn3270_is_connected(hSession) != 0; - } - - public bool Connected { - get { - return tn3270_is_connected(hSession) != 0; - } - } - - public bool IsReady() { - return tn3270_is_ready(hSession) != 0; - } - - public bool Ready { - get { - return tn3270_is_ready(hSession) != 0; - } - } - - /// - /// Disconnect from 3270 host. - /// - /// - public int Disconnect() { - return tn3270_disconnect(hSession); - } - - /// - /// Wait for network activity - /// - /// - /// Seconds to wait - /// - /// - /// - /// - /// - public int WaitForReady(int seconds) { - return tn3270_wait_for_ready(hSession, seconds); - } - - /// - /// "Sleep" keeping the network activity. - /// - /// - /// Number of seconds to wait - /// - /// - /// - /// - /// - public int Wait(int seconds) { - return tn3270_wait(hSession, seconds); - } - - /// - /// Get contents - /// - /// - /// - /// Contents from terminal screen. - /// - /// - public override string ToString() { - int strlen = (tn3270_get_width(hSession)+1) * (tn3270_get_height(hSession)+1); - StringBuilder str = new StringBuilder(strlen+1); - strlen = tn3270_get_contents(hSession, str, strlen); - return str.ToString(); - } - - - /// - /// Get contents at address - /// - /// - /// Address of text in the screen buffer - /// Number of characters to get - /// - /// - /// Contents from terminal screen. - /// - /// - public string GetString(int addr, int strlen) { - StringBuilder str = new StringBuilder(strlen+1); - tn3270_get_string(hSession, addr, str, strlen); - return str.ToString(); - } - - /// - /// Get contents at position. - /// - /// - /// Start row - /// Start col - /// Number of characters to get - /// - /// - /// Contents from terminal screen. - /// - /// - public string GetStringAt(int row, int col, int strlen) { - StringBuilder str = new StringBuilder(strlen+1); - tn3270_get_string_at(hSession, row, col, str, strlen); - return str.ToString(); - } - - /// - /// Set contents at position - /// - /// - /// Start row - /// Start col - /// Text to set - /// - public void SetStringAt(int row, int col, string str) { - tn3270_set_string_at(hSession, row, col, str); - } - - /// - /// Wait for text at position. - /// - /// - /// Start row - /// Start col - /// Text to wait - /// Seconds to wait - /// - /// - /// - /// - /// - public int WaitForStringAt(int row, int col, string str, int timeout) { - return tn3270_wait_for_string_at(hSession, row, col, str, timeout); - } - - /// - /// Compare contents at position - /// - /// - /// Start row - /// Start col - /// Text to compare - /// - /// - /// Result (0 = The strings are the same). - /// - /// - public int CmpStringAt(int row, int col, string str) { - return tn3270_cmp_string_at(hSession, row, col, str); - } - - /// - /// Set cursor position. - /// - /// - /// New cursor row - /// New cursor column - /// - public void SetCursorPosition(int row, int col) { - tn3270_set_cursor_position(hSession, row, col); - } - - /// - /// Set cursor position based on address. - /// - /// - /// Address of the new cursor position - /// - public void SetCursorPosition(int addr) { - tn3270_set_cursor_addr(hSession, addr); - } - - /// - /// Get cursor address - /// - /// - public int GetCursorPosition() { - return tn3270_get_cursor_addr(hSession); - } - - /// - /// Cursor address - /// - /// - public int CursorPosition { - set { - tn3270_set_cursor_addr(hSession, value); - } - get { - return tn3270_get_cursor_addr(hSession); - } - } - - /// - /// Set the "screen ready" delay - /// - /// - public int SetUnlockDelay(int ms) { - return tn3270_set_unlock_delay(hSession, ms); - } - - /// - /// Set the "screen ready" delay - /// - /// - public int UnlockDelay { - set { - tn3270_set_unlock_delay(hSession, value); - } - } - - - /// - /// Send "Enter" key - /// - /// - /// - /// - /// - /// - public int Enter() { - return tn3270_enter(hSession); - } - - /// - /// Send "PF" key - /// - /// - /// Key identifier 1=PF1, 2=PF2, ... - /// - /// - /// - /// - /// - public int PfKey(int key) { - return tn3270_pfkey(hSession, key); - } - - /// - /// Send "PA" key - /// - /// - /// Key identifier 1=PA1, 2=PA2, ... - /// - /// - /// - /// - /// - public int PaKey(int key) { - return tn3270_pakey(hSession, key); - } - - /// - /// Get screen width - /// - /// - /// - /// Screen width in characters (negative on error) - /// - /// - public int GetWidth() { - return tn3270_get_width(hSession); - } - - /// - /// Screen width in characters - /// - /// - /// - /// Screen width in characters (negative on error) - /// - /// - public int Width { - get { - return tn3270_get_width(hSession); - } - } - - /// - /// Get screen height - /// - /// - /// - /// Screen width in characters (negative on error) - /// - /// - public int GetHeight() { - return tn3270_get_height(hSession); - } - - /// - /// Screen height in characters - /// - /// - /// - /// Screen height in characters (negative on error) - /// - /// - public int Height { - get { - return tn3270_get_height(hSession); - } - } - - /// - /// Get length of terminal buffer (width * height) - /// - /// - /// - /// Terminal length in characters (negative on error) - /// - /// - public int GetLength() { - return tn3270_get_length(hSession); - } - - /// - /// Length of terminal buffer (width * height) - /// - /// - /// - /// Terminal length in characters (negative on error) - /// - /// - public int Length { - get { - return tn3270_get_length(hSession); - } - } - - public string CharSet { - set { - tn3270_set_charset(hSession,value); - } - } - - /// - /// 3270 host URL - /// - /// - /// - /// 3270 host URL - /// - /// - public string Url { - set { - tn3270_set_url(hSession,value); - } - get { - StringBuilder str = new StringBuilder(1025); - tn3270_get_url(hSession, str, 1024); - return str.ToString(); - } - } - - /// - /// Last lib3270 error message - /// - /// - /// - /// Last lib3270 error message - /// - /// - public string Error { - set { - tn3270_set_error_message(hSession,value); - } - get { - StringBuilder str = new StringBuilder(1025); - tn3270_get_error_message(hSession, str, 1024); - return str.ToString(); - } - } - - } - -} diff --git a/src/core/tn3270-sharp.pc.in b/src/core/tn3270-sharp.pc.in deleted file mode 100644 index 5b6b3b9..0000000 --- a/src/core/tn3270-sharp.pc.in +++ /dev/null @@ -1,11 +0,0 @@ -prefix=${pcfiledir}/../.. -exec_prefix=${prefix} -libdir=${exec_prefix}/lib -gapidir=${prefix}/share/tn3270-sharp-@PACKAGE_MAJOR_VERSION@.@PACKAGE_MINOR_VERSION@ - - -Name: tn3270-sharp -Description: .NET Bindings for pw3270 -Version: @PACKAGE_MAJOR_VERSION@.@PACKAGE_MINOR_VERSION@ -Cflags: -I:${gapidir}/tn3270-sharp.xml -Libs: -r:${libdir}/mono/tn3270-sharp-@PACKAGE_MAJOR_VERSION@.@PACKAGE_MINOR_VERSION@/tn3270-sharp.dll diff --git a/src/core/tn3270.cs b/src/core/tn3270.cs new file mode 100644 index 0000000..b408391 --- /dev/null +++ b/src/core/tn3270.cs @@ -0,0 +1,618 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como tn3270-sharp.cs e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + * Referências: + * + * https://msdn.microsoft.com/en-us/library/5ast78ax.aspx + * + */ + +using System; +using System.Text; +using System.Runtime.InteropServices; + +namespace tn3270 { + + /// + /// Session with 3270 HOST. + /// + public class Session { + + /// + /// lib3270 session handle + /// + private IntPtr hSession; + + [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] + extern static IntPtr tn3270_create_session(string name); + + [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] + extern static int tn3270_destroy_session(IntPtr session); + + [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] + extern static int tn3270_get_version(IntPtr session, StringBuilder str, int strlen); + + [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] + extern static int tn3270_get_revision(IntPtr session, StringBuilder str, int strlen); + + [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] + extern static int tn3270_connect(IntPtr Session, string host, int wait); + + [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] + extern static int tn3270_is_connected(IntPtr Session); + + [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] + extern static int tn3270_is_ready(IntPtr Session); + + [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] + extern static int tn3270_disconnect(IntPtr Session); + + [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] + extern static int tn3270_wait_for_ready(IntPtr Session, int seconds); + + [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] + extern static int tn3270_wait(IntPtr Session, int seconds); + + [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] + extern static int tn3270_get_cstate(IntPtr Session); + + [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] + extern static int tn3270_get_program_message(IntPtr Session); + + [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] + extern static int tn3270_get_secure(IntPtr Session); + + [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] + extern static int tn3270_get_contents(IntPtr Session, StringBuilder str, int strlen); + + [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] + extern static int tn3270_get_string(IntPtr Session, int addr, StringBuilder str, int strlen); + + [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] + extern static int tn3270_get_string_at(IntPtr Session, int row, int col, StringBuilder str, int strlen); + + [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] + extern static int tn3270_set_string_at(IntPtr Session, int row, int col, string str); + + [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] + extern static int tn3270_wait_for_string_at(IntPtr Session, int row, int col, string key, int timeout); + + [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] + extern static int tn3270_cmp_string_at(IntPtr Session, int row, int col, string str); + + [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] + extern static int tn3270_set_unlock_delay(IntPtr Session, int ms); + + [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] + extern static int tn3270_set_cursor_position(IntPtr Session, int row, int col); + + [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] + extern static int tn3270_set_cursor_addr(IntPtr Session, int addr); + + [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] + extern static int tn3270_get_cursor_addr(IntPtr Session); + + [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] + extern static int tn3270_enter(IntPtr Session); + + [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] + extern static int tn3270_pfkey(IntPtr Session, int key); + + [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] + extern static int tn3270_pakey(IntPtr Session, int key); + + [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] + extern static int tn3270_get_width(IntPtr Session); + + [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] + extern static int tn3270_get_height(IntPtr Session); + + [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] + extern static int tn3270_get_length(IntPtr Session); + + [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] + extern static int tn3270_set_charset(IntPtr Session, string str); + + [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] + extern static int tn3270_set_url(IntPtr Session, string str); + + [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] + extern static int tn3270_get_url(IntPtr Session, StringBuilder str, int strlen); + + [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] + extern static int tn3270_set_error_message(IntPtr Session, string str); + + [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] + extern static int tn3270_get_error_message(IntPtr Session, StringBuilder str, int strlen); + + /// + /// Create a new session with lib3270/pw3270 + /// + /// + /// Session name or empty string for a hidden session + /// + public Session(string name) { + hSession = tn3270_create_session(name); + tn3270_set_charset(hSession,"UTF-8"); + } + + /// + /// Disconnect from host, destroy session. + /// + /// + ~Session() { + tn3270_destroy_session(hSession); + } + + /// + /// Get lib3270/pw3270 Version identifier + /// + /// + /// + /// The version of the active instance. + /// + /// + public string GetVersion() { + StringBuilder str = new StringBuilder(10); + tn3270_get_version(hSession, str, 10); + return str.ToString(); + } + + /// + /// Lib3270 version. + /// + /// + /// + /// Lib3270 version string + /// + /// + public string Version { + get { + return GetVersion(); + } + } + + /// + /// Get lib3270/pw3270 Revision number + /// + /// + /// + /// The revision of the active instance. + /// + /// + public string GetRevision() { + StringBuilder str = new StringBuilder(10); + tn3270_get_revision(hSession, str, 10); + return str.ToString(); + } + + public string Revision { + get { + return GetRevision(); + } + } + + /// + /// Connect to 3270 host. + /// + /// + /// URL of the target host (tn3270://hostname:port) + /// How many seconds should the call wait for the connection becomes ready + /// + /// + /// + /// + public int Connect(string host, int wait) { + return tn3270_connect(hSession, host, wait); + } + + /// + /// Get connection state + /// + /// + /// + /// true if the session is connected to a remote host. + /// + /// + public bool IsConnected() { + return tn3270_is_connected(hSession) != 0; + } + + public bool Connected { + get { + return tn3270_is_connected(hSession) != 0; + } + } + + public bool IsReady() { + return tn3270_is_ready(hSession) != 0; + } + + public bool Ready { + get { + return tn3270_is_ready(hSession) != 0; + } + } + + /// + /// Disconnect from 3270 host. + /// + /// + public int Disconnect() { + return tn3270_disconnect(hSession); + } + + /// + /// Wait for network activity + /// + /// + /// Seconds to wait + /// + /// + /// + /// + /// + public int WaitForReady(int seconds) { + return tn3270_wait_for_ready(hSession, seconds); + } + + /// + /// "Sleep" keeping the network activity. + /// + /// + /// Number of seconds to wait + /// + /// + /// + /// + /// + public int Wait(int seconds) { + return tn3270_wait(hSession, seconds); + } + + /// + /// Get contents + /// + /// + /// + /// Contents from terminal screen. + /// + /// + public override string ToString() { + int strlen = (tn3270_get_width(hSession)+1) * (tn3270_get_height(hSession)+1); + StringBuilder str = new StringBuilder(strlen+1); + strlen = tn3270_get_contents(hSession, str, strlen); + return str.ToString(); + } + + + /// + /// Get contents at address + /// + /// + /// Address of text in the screen buffer + /// Number of characters to get + /// + /// + /// Contents from terminal screen. + /// + /// + public string GetString(int addr, int strlen) { + StringBuilder str = new StringBuilder(strlen+1); + tn3270_get_string(hSession, addr, str, strlen); + return str.ToString(); + } + + /// + /// Get contents at position. + /// + /// + /// Start row + /// Start col + /// Number of characters to get + /// + /// + /// Contents from terminal screen. + /// + /// + public string GetStringAt(int row, int col, int strlen) { + StringBuilder str = new StringBuilder(strlen+1); + tn3270_get_string_at(hSession, row, col, str, strlen); + return str.ToString(); + } + + /// + /// Set contents at position + /// + /// + /// Start row + /// Start col + /// Text to set + /// + public void SetStringAt(int row, int col, string str) { + tn3270_set_string_at(hSession, row, col, str); + } + + /// + /// Wait for text at position. + /// + /// + /// Start row + /// Start col + /// Text to wait + /// Seconds to wait + /// + /// + /// + /// + /// + public int WaitForStringAt(int row, int col, string str, int timeout) { + return tn3270_wait_for_string_at(hSession, row, col, str, timeout); + } + + /// + /// Compare contents at position + /// + /// + /// Start row + /// Start col + /// Text to compare + /// + /// + /// Result (0 = The strings are the same). + /// + /// + public int CmpStringAt(int row, int col, string str) { + return tn3270_cmp_string_at(hSession, row, col, str); + } + + /// + /// Set cursor position. + /// + /// + /// New cursor row + /// New cursor column + /// + public void SetCursorPosition(int row, int col) { + tn3270_set_cursor_position(hSession, row, col); + } + + /// + /// Set cursor position based on address. + /// + /// + /// Address of the new cursor position + /// + public void SetCursorPosition(int addr) { + tn3270_set_cursor_addr(hSession, addr); + } + + /// + /// Get cursor address + /// + /// + public int GetCursorPosition() { + return tn3270_get_cursor_addr(hSession); + } + + /// + /// Cursor address + /// + /// + public int CursorPosition { + set { + tn3270_set_cursor_addr(hSession, value); + } + get { + return tn3270_get_cursor_addr(hSession); + } + } + + /// + /// Set the "screen ready" delay + /// + /// + public int SetUnlockDelay(int ms) { + return tn3270_set_unlock_delay(hSession, ms); + } + + /// + /// Set the "screen ready" delay + /// + /// + public int UnlockDelay { + set { + tn3270_set_unlock_delay(hSession, value); + } + } + + + /// + /// Send "Enter" key + /// + /// + /// + /// + /// + /// + public int Enter() { + return tn3270_enter(hSession); + } + + /// + /// Send "PF" key + /// + /// + /// Key identifier 1=PF1, 2=PF2, ... + /// + /// + /// + /// + /// + public int PfKey(int key) { + return tn3270_pfkey(hSession, key); + } + + /// + /// Send "PA" key + /// + /// + /// Key identifier 1=PA1, 2=PA2, ... + /// + /// + /// + /// + /// + public int PaKey(int key) { + return tn3270_pakey(hSession, key); + } + + /// + /// Get screen width + /// + /// + /// + /// Screen width in characters (negative on error) + /// + /// + public int GetWidth() { + return tn3270_get_width(hSession); + } + + /// + /// Screen width in characters + /// + /// + /// + /// Screen width in characters (negative on error) + /// + /// + public int Width { + get { + return tn3270_get_width(hSession); + } + } + + /// + /// Get screen height + /// + /// + /// + /// Screen width in characters (negative on error) + /// + /// + public int GetHeight() { + return tn3270_get_height(hSession); + } + + /// + /// Screen height in characters + /// + /// + /// + /// Screen height in characters (negative on error) + /// + /// + public int Height { + get { + return tn3270_get_height(hSession); + } + } + + /// + /// Get length of terminal buffer (width * height) + /// + /// + /// + /// Terminal length in characters (negative on error) + /// + /// + public int GetLength() { + return tn3270_get_length(hSession); + } + + /// + /// Length of terminal buffer (width * height) + /// + /// + /// + /// Terminal length in characters (negative on error) + /// + /// + public int Length { + get { + return tn3270_get_length(hSession); + } + } + + public string CharSet { + set { + tn3270_set_charset(hSession,value); + } + } + + /// + /// 3270 host URL + /// + /// + /// + /// 3270 host URL + /// + /// + public string Url { + set { + tn3270_set_url(hSession,value); + } + get { + StringBuilder str = new StringBuilder(1025); + tn3270_get_url(hSession, str, 1024); + return str.ToString(); + } + } + + /// + /// Last lib3270 error message + /// + /// + /// + /// Last lib3270 error message + /// + /// + public string Error { + set { + tn3270_set_error_message(hSession,value); + } + get { + StringBuilder str = new StringBuilder(1025); + tn3270_get_error_message(hSession, str, 1024); + return str.ToString(); + } + } + + } + +} diff --git a/src/testprograms/sample.cs b/src/testprograms/sample.cs index c051e2e..9a4a591 100644 --- a/src/testprograms/sample.cs +++ b/src/testprograms/sample.cs @@ -27,13 +27,13 @@ * */ -using pw3270; +using tn3270; class sample { static void Main(string[] args) { - pw3270.Session host = new pw3270.Session(""); + tn3270.Session host = new tn3270.Session(""); System.Console.WriteLine("Using pw3270 version " + host.Version + " revision " + host.Revision); System.Console.WriteLine("Screen size is " + host.Width + "x" + host.Height + " (" + host.Length + ")"); -- libgit2 0.21.2