From d021aee617ab89dc04ebfacbdf6c387d845c142d Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Fri, 14 Dec 2018 16:31:15 -0200 Subject: [PATCH] Updating API definitions. --- lib3270.cbp | 9 +++++++++ src/include/lib3270++.h | 9 ++++----- src/include/lib3270.h | 15 ++++++++++++++- src/lib3270++/host.cc | 10 ++++++++++ src/lib3270++/local/session.cc | 15 +++++++-------- src/lib3270/kybd.c | 4 +++- src/lib3270/paste.c | 20 ++++++++++++++++++-- src/lib3270/selection.c | 23 ++++++++++++++++++----- 8 files changed, 83 insertions(+), 22 deletions(-) diff --git a/lib3270.cbp b/lib3270.cbp index 924aa0b..ccc8c0a 100644 --- a/lib3270.cbp +++ b/lib3270.cbp @@ -108,6 +108,15 @@ + + + + + + + + + diff --git a/src/include/lib3270++.h b/src/include/lib3270++.h index 61b35aa..dbcc695 100644 --- a/src/include/lib3270++.h +++ b/src/include/lib3270++.h @@ -297,8 +297,8 @@ return session->getProgramMessage(); } - inline bool isReady() const { - return getProgramMessage() == MESSAGE_NONE; + inline operator bool() const { + return isConnected() && isReady(); } inline operator ProgramMessage() const { @@ -309,9 +309,8 @@ return session->getConnectionState(); } - inline bool isConnected() const { - return getConnectionState() == CONNECTED_TN3270E; - } + bool isReady() const; + bool isConnected() const; inline operator ConnectionState() const { return getConnectionState(); diff --git a/src/include/lib3270.h b/src/include/lib3270.h index 18777af..0a17703 100644 --- a/src/include/lib3270.h +++ b/src/include/lib3270.h @@ -615,7 +615,20 @@ LIB3270_EXPORT int lib3270_set_string(H3270 *h, const unsigned char *str); #define lib3270_set_text_at(h,r,c,t) lib3270_set_string_at(h,r,c,t) - LIB3270_EXPORT int lib3270_set_string_at(H3270 *h, int row, int col, const unsigned char *str); + + /** + * @brief Set string at defined position. + * + * @param hSession Session handle. + * @param row Row for the first character. + * @param col Col for the first character. + * @param str String to set. + * + * @return Negative if error or number of processed characters. + * + */ + LIB3270_EXPORT int lib3270_set_string_at(H3270 *hSession, int row, int col, const unsigned char *str); + LIB3270_EXPORT int lib3270_input_string(H3270 *hSession, const unsigned char *str); /** diff --git a/src/lib3270++/host.cc b/src/lib3270++/host.cc index 9d6d720..d34f984 100644 --- a/src/lib3270++/host.cc +++ b/src/lib3270++/host.cc @@ -90,6 +90,16 @@ return *this; } + bool Host::isReady() const { + this->session->waitForReady(this->timeout); + return getProgramMessage() == MESSAGE_NONE; + } + + bool Host::isConnected() const { + this->session->waitForReady(this->timeout); + return getConnectionState() == CONNECTED_TN3270E; + } + std::string Host::toString() const { this->session->waitForReady(this->timeout); diff --git a/src/lib3270++/local/session.cc b/src/lib3270++/local/session.cc index 92f4f70..26c22d7 100644 --- a/src/lib3270++/local/session.cc +++ b/src/lib3270++/local/session.cc @@ -268,7 +268,9 @@ baddr = lib3270_get_next_unprotected(hSession,0); } - lib3270_set_cursor_address(hSession,baddr); + if(lib3270_set_cursor_address(hSession,baddr)) { + throw std::system_error(errno, std::system_category()); + } return *this; } @@ -278,12 +280,10 @@ /// @param addr Cursor address. void Local::Session::setCursorPosition(unsigned short addr) { - if(!lib3270_is_connected(hSession)) { - throw std::system_error(ENOTCONN, std::system_category()); + if(lib3270_set_cursor_address(hSession,addr) < 0) { + throw std::system_error(errno, std::system_category()); } - lib3270_set_cursor_address(hSession,baddr); - } /// @brief Set cursor position. @@ -292,11 +292,10 @@ /// @param col New cursor column. void Local::Session::setCursorPosition(unsigned short row, unsigned short col) { - if(!lib3270_is_connected(hSession)) { - throw std::system_error(ENOTCONN, std::system_category()); + if(lib3270_set_cursor_position(hSession,row,col)) { + throw std::system_error(errno, std::system_category()); } - lib3270_set_cursor_position(hSession,row,col); } diff --git a/src/lib3270/kybd.c b/src/lib3270/kybd.c index c5cf6dd..8911d7a 100644 --- a/src/lib3270/kybd.c +++ b/src/lib3270/kybd.c @@ -974,6 +974,8 @@ static Boolean key_Character(H3270 *hSession, int code, Boolean with_ge, Boolean LIB3270_EXPORT int lib3270_input_string(H3270 *hSession, const unsigned char *str) { + FAIL_IF_NOT_ONLINE(hSession); + while(*str) { key_ACharacter(hSession,(unsigned char)((*str) & 0xff), KT_STD, IA_KEY, NULL); @@ -986,7 +988,7 @@ LIB3270_EXPORT int lib3270_input_string(H3270 *hSession, const unsigned char *st } /** - * Handle an ordinary character key, given an ASCII code. + * @brief Handle an ordinary character key, given an ASCII code. * */ void key_ACharacter(H3270 *hSession, unsigned char c, enum keytype keytype, enum iaction cause,Boolean *skipped) diff --git a/src/lib3270/paste.c b/src/lib3270/paste.c index 4c2a772..c9ee83a 100644 --- a/src/lib3270/paste.c +++ b/src/lib3270/paste.c @@ -221,14 +221,29 @@ static int set_string(H3270 *hSession, const unsigned char *str) return data.qtd; } +/** + * @brief Set string at defined position. + * + * @param hSession Session handle. + * @param row Row for the first character. + * @param col Col for the first character. + * @param str String to set. + * + * @return -1 if error (sets errno) or number of processed characters. + * + */ LIB3270_EXPORT int lib3270_set_string_at(H3270 *hSession, int row, int col, const unsigned char *str) { int rc = 0; - CHECK_SESSION_HANDLE(hSession); + FAIL_IF_NOT_ONLINE(hSession); + // Is Keyboard locked ? if(hSession->kybdlock) - return -EINVAL; + { + errno = EPERM; + return -1; + } if(hSession->selected && !lib3270_get_toggle(hSession,LIB3270_TOGGLE_KEEP_SELECTED)) lib3270_unselect(hSession); @@ -247,6 +262,7 @@ LIB3270_EXPORT int lib3270_set_string_at(H3270 *hSession, int row, int col, cons } trace("%s rc=%d",__FUNCTION__,rc); + return rc; } diff --git a/src/lib3270/selection.c b/src/lib3270/selection.c index 14c6156..3400404 100644 --- a/src/lib3270/selection.c +++ b/src/lib3270/selection.c @@ -916,41 +916,54 @@ LIB3270_EXPORT int lib3270_move_cursor(H3270 *hSession, LIB3270_DIRECTION dir, u int maxlen = hSession->cols * hSession->rows; if(!lib3270_connected(hSession)) + { + errno = ENOTCONN; return -1; + } switch(dir) { case LIB3270_DIR_UP: + if(sel && cursor_addr <= hSession->cols) - return EINVAL; + return errno = EINVAL; + cursor_addr -= hSession->cols; break; case LIB3270_DIR_DOWN: + if(sel && cursor_addr >= (hSession->cols * (hSession->rows-1))) - return EINVAL; + return errno = EINVAL; + cursor_addr += hSession->cols; break; case LIB3270_DIR_LEFT: + if(sel && (cursor_addr % hSession->cols) < 1) - return EINVAL; + return errno = EINVAL; + cursor_addr--; break; case LIB3270_DIR_RIGHT: + if(sel && (cursor_addr % hSession->cols) >= (hSession->cols-1)) - return EINVAL; + return errno = EINVAL; + cursor_addr++; break; case LIB3270_DIR_END: + cursor_addr = lib3270_get_field_end(hSession,cursor_addr); if(cursor_addr == -1) - return EINVAL; + return errno = EINVAL; break; default: + errno = EINVAL; return -1; } -- libgit2 0.21.2