Commit 1b8493c99dc263f4b76295ee1b102a89253305d2
1 parent
a9d34e0f
Exists in
master
and in
1 other branch
Implementing "hllapi_get_cursor_position"
Showing
4 changed files
with
46 additions
and
12 deletions
Show diff stats
src/core/controller.cc
... | ... | @@ -68,13 +68,16 @@ |
68 | 68 | hllapi_host = new TN3270::Host(*id ? id : nullptr, "UTF-8"); |
69 | 69 | #endif // _WIN32 |
70 | 70 | |
71 | + debug("Will set timeout to %d",120); | |
72 | + | |
71 | 73 | hllapi_host->setTimeout(120); |
72 | 74 | |
73 | - } | |
74 | - catch(std::exception &e) | |
75 | - { | |
75 | + } catch(const std::exception &e) { | |
76 | 76 | hllapi_lasterror = e.what(); |
77 | 77 | return HLLAPI_STATUS_SYSTEM_ERROR; |
78 | + } catch(...) { | |
79 | + hllapi_lasterror = "Unexpected error"; | |
80 | + return HLLAPI_STATUS_SYSTEM_ERROR; | |
78 | 81 | } |
79 | 82 | |
80 | 83 | debug("hllapi_host=%p",hllapi_host); | ... | ... |
src/core/cursor.cc
... | ... | @@ -63,7 +63,6 @@ |
63 | 63 | host.setCursor((unsigned short) pos -1); |
64 | 64 | }); |
65 | 65 | |
66 | - | |
67 | 66 | } |
68 | 67 | |
69 | 68 | HLLAPI_API_CALL hllapi_setcursor(WORD pos) { |
... | ... | @@ -98,6 +97,21 @@ |
98 | 97 | } |
99 | 98 | |
100 | 99 | HLLAPI_API_CALL hllapi_getcursor() { |
100 | + | |
101 | 101 | return hllapi_get_cursor_address(); |
102 | 102 | } |
103 | 103 | |
104 | + HLLAPI_API_CALL hllapi_get_cursor_position(WORD *row, WORD *col) { | |
105 | + | |
106 | + return set([row,col](TN3270::Host &host) { | |
107 | + | |
108 | + *row = *col = 0; | |
109 | + | |
110 | + auto position = host.getCursorPosition(); | |
111 | + | |
112 | + *row = (WORD) position.row; | |
113 | + *col = (WORD) position.col; | |
114 | + | |
115 | + }); | |
116 | + | |
117 | +} | ... | ... |
src/include/lib3270/hllapi.h
... | ... | @@ -359,6 +359,7 @@ |
359 | 359 | |
360 | 360 | HLLAPI_API_CALL hllapi_set_cursor_address(WORD pos); |
361 | 361 | HLLAPI_API_CALL hllapi_set_cursor_position(WORD row, WORD col); |
362 | + HLLAPI_API_CALL hllapi_get_cursor_position(WORD *row, WORD *col); | |
362 | 363 | |
363 | 364 | /** |
364 | 365 | * @brief Report event to system log | ... | ... |
src/testprogram/testprogram.cc
... | ... | @@ -50,7 +50,7 @@ |
50 | 50 | |
51 | 51 | int main(int argc, char **argv) { |
52 | 52 | |
53 | - printf("******\n"); | |
53 | + int rc; | |
54 | 54 | |
55 | 55 | char buffer[SCREEN_LENGTH+1]; |
56 | 56 | |
... | ... | @@ -89,15 +89,28 @@ |
89 | 89 | |
90 | 90 | #endif // ! defined(_MSC_VER) |
91 | 91 | |
92 | - int rc = hllapi_init((char *) session); | |
93 | - if(rc) { | |
94 | - cout << "hllapi_init returns with rc=" << rc << " (" << hllapi_get_last_error_as_cstring() << ")" << endl; | |
95 | - return rc; | |
96 | - } | |
92 | + try { | |
93 | + | |
94 | + rc = hllapi_init((char *) session); | |
95 | + if(rc) { | |
96 | + cout << "hllapi_init returns with rc=" << rc << " (" << hllapi_get_last_error_as_cstring() << ")" << endl; | |
97 | + return rc; | |
98 | + } | |
97 | 99 | |
98 | - cout << "TN3270 library revision is " << ((int) hllapi_get_revision()) << endl << ">"; | |
100 | + cout << "TN3270 library revision is " << ((int) hllapi_get_revision()) << endl << ">"; | |
99 | 101 | |
100 | - hllapi_set_timeout(10); | |
102 | + hllapi_set_timeout(10); | |
103 | + | |
104 | + } catch(const std::exception &e) { | |
105 | + | |
106 | + cerr << e.what() << endl; | |
107 | + return -1; | |
108 | + | |
109 | + } catch(...) { | |
110 | + | |
111 | + cerr << "Unexpected error" << endl; | |
112 | + return -1; | |
113 | + } | |
101 | 114 | |
102 | 115 | cout.flush(); |
103 | 116 | |
... | ... | @@ -168,7 +181,10 @@ |
168 | 181 | |
169 | 182 | cout << "Cursor address=" << addr << endl; |
170 | 183 | |
184 | + WORD row, col; | |
185 | + rc = hllapi_get_cursor_position(&row,&col); | |
171 | 186 | |
187 | + cout << "Cursor position=" << row << "," << col << endl; | |
172 | 188 | } |
173 | 189 | |
174 | 190 | ... | ... |