diff --git a/src/core/controller.cc b/src/core/controller.cc index ad3ec2e..062b19b 100644 --- a/src/core/controller.cc +++ b/src/core/controller.cc @@ -68,13 +68,16 @@ hllapi_host = new TN3270::Host(*id ? id : nullptr, "UTF-8"); #endif // _WIN32 + debug("Will set timeout to %d",120); + hllapi_host->setTimeout(120); - } - catch(std::exception &e) - { + } catch(const std::exception &e) { hllapi_lasterror = e.what(); return HLLAPI_STATUS_SYSTEM_ERROR; + } catch(...) { + hllapi_lasterror = "Unexpected error"; + return HLLAPI_STATUS_SYSTEM_ERROR; } debug("hllapi_host=%p",hllapi_host); diff --git a/src/core/cursor.cc b/src/core/cursor.cc index fe95e3f..c3cf6a2 100644 --- a/src/core/cursor.cc +++ b/src/core/cursor.cc @@ -63,7 +63,6 @@ host.setCursor((unsigned short) pos -1); }); - } HLLAPI_API_CALL hllapi_setcursor(WORD pos) { @@ -98,6 +97,21 @@ } HLLAPI_API_CALL hllapi_getcursor() { + return hllapi_get_cursor_address(); } + HLLAPI_API_CALL hllapi_get_cursor_position(WORD *row, WORD *col) { + + return set([row,col](TN3270::Host &host) { + + *row = *col = 0; + + auto position = host.getCursorPosition(); + + *row = (WORD) position.row; + *col = (WORD) position.col; + + }); + +} diff --git a/src/include/lib3270/hllapi.h b/src/include/lib3270/hllapi.h index 5b6b82d..b988c57 100644 --- a/src/include/lib3270/hllapi.h +++ b/src/include/lib3270/hllapi.h @@ -359,6 +359,7 @@ HLLAPI_API_CALL hllapi_set_cursor_address(WORD pos); HLLAPI_API_CALL hllapi_set_cursor_position(WORD row, WORD col); + HLLAPI_API_CALL hllapi_get_cursor_position(WORD *row, WORD *col); /** * @brief Report event to system log diff --git a/src/testprogram/testprogram.cc b/src/testprogram/testprogram.cc index bb55f6a..ec3e599 100644 --- a/src/testprogram/testprogram.cc +++ b/src/testprogram/testprogram.cc @@ -50,7 +50,7 @@ int main(int argc, char **argv) { - printf("******\n"); + int rc; char buffer[SCREEN_LENGTH+1]; @@ -89,15 +89,28 @@ #endif // ! defined(_MSC_VER) - int rc = hllapi_init((char *) session); - if(rc) { - cout << "hllapi_init returns with rc=" << rc << " (" << hllapi_get_last_error_as_cstring() << ")" << endl; - return rc; - } + try { + + rc = hllapi_init((char *) session); + if(rc) { + cout << "hllapi_init returns with rc=" << rc << " (" << hllapi_get_last_error_as_cstring() << ")" << endl; + return rc; + } - cout << "TN3270 library revision is " << ((int) hllapi_get_revision()) << endl << ">"; + cout << "TN3270 library revision is " << ((int) hllapi_get_revision()) << endl << ">"; - hllapi_set_timeout(10); + hllapi_set_timeout(10); + + } catch(const std::exception &e) { + + cerr << e.what() << endl; + return -1; + + } catch(...) { + + cerr << "Unexpected error" << endl; + return -1; + } cout.flush(); @@ -168,7 +181,10 @@ cout << "Cursor address=" << addr << endl; + WORD row, col; + rc = hllapi_get_cursor_position(&row,&col); + cout << "Cursor position=" << row << "," << col << endl; } -- libgit2 0.21.2