Commit d021aee617ab89dc04ebfacbdf6c387d845c142d
1 parent
aee80d5f
Exists in
master
and in
3 other branches
Updating API definitions.
Showing
8 changed files
with
83 additions
and
22 deletions
Show diff stats
lib3270.cbp
| ... | ... | @@ -108,6 +108,15 @@ |
| 108 | 108 | <Unit filename="src/include/winversc.h" /> |
| 109 | 109 | <Unit filename="src/include/xioc.h" /> |
| 110 | 110 | <Unit filename="src/include/xl.h" /> |
| 111 | + <Unit filename="src/lib3270++/abstract.cc" /> | |
| 112 | + <Unit filename="src/lib3270++/events.cc" /> | |
| 113 | + <Unit filename="src/lib3270++/host.cc" /> | |
| 114 | + <Unit filename="src/lib3270++/local/events.cc" /> | |
| 115 | + <Unit filename="src/lib3270++/local/session.cc" /> | |
| 116 | + <Unit filename="src/lib3270++/private.h" /> | |
| 117 | + <Unit filename="src/lib3270++/session.cc" /> | |
| 118 | + <Unit filename="src/lib3270++/testprogram/testprogram.cc" /> | |
| 119 | + <Unit filename="src/lib3270++/windows/resources.rc" /> | |
| 111 | 120 | <Unit filename="src/lib3270/actions.c"> |
| 112 | 121 | <Option compilerVar="CC" /> |
| 113 | 122 | </Unit> | ... | ... |
src/include/lib3270++.h
| ... | ... | @@ -297,8 +297,8 @@ |
| 297 | 297 | return session->getProgramMessage(); |
| 298 | 298 | } |
| 299 | 299 | |
| 300 | - inline bool isReady() const { | |
| 301 | - return getProgramMessage() == MESSAGE_NONE; | |
| 300 | + inline operator bool() const { | |
| 301 | + return isConnected() && isReady(); | |
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | inline operator ProgramMessage() const { |
| ... | ... | @@ -309,9 +309,8 @@ |
| 309 | 309 | return session->getConnectionState(); |
| 310 | 310 | } |
| 311 | 311 | |
| 312 | - inline bool isConnected() const { | |
| 313 | - return getConnectionState() == CONNECTED_TN3270E; | |
| 314 | - } | |
| 312 | + bool isReady() const; | |
| 313 | + bool isConnected() const; | |
| 315 | 314 | |
| 316 | 315 | inline operator ConnectionState() const { |
| 317 | 316 | return getConnectionState(); | ... | ... |
src/include/lib3270.h
| ... | ... | @@ -615,7 +615,20 @@ |
| 615 | 615 | LIB3270_EXPORT int lib3270_set_string(H3270 *h, const unsigned char *str); |
| 616 | 616 | |
| 617 | 617 | #define lib3270_set_text_at(h,r,c,t) lib3270_set_string_at(h,r,c,t) |
| 618 | - LIB3270_EXPORT int lib3270_set_string_at(H3270 *h, int row, int col, const unsigned char *str); | |
| 618 | + | |
| 619 | + /** | |
| 620 | + * @brief Set string at defined position. | |
| 621 | + * | |
| 622 | + * @param hSession Session handle. | |
| 623 | + * @param row Row for the first character. | |
| 624 | + * @param col Col for the first character. | |
| 625 | + * @param str String to set. | |
| 626 | + * | |
| 627 | + * @return Negative if error or number of processed characters. | |
| 628 | + * | |
| 629 | + */ | |
| 630 | + LIB3270_EXPORT int lib3270_set_string_at(H3270 *hSession, int row, int col, const unsigned char *str); | |
| 631 | + | |
| 619 | 632 | LIB3270_EXPORT int lib3270_input_string(H3270 *hSession, const unsigned char *str); |
| 620 | 633 | |
| 621 | 634 | /** | ... | ... |
src/lib3270++/host.cc
| ... | ... | @@ -90,6 +90,16 @@ |
| 90 | 90 | return *this; |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | + bool Host::isReady() const { | |
| 94 | + this->session->waitForReady(this->timeout); | |
| 95 | + return getProgramMessage() == MESSAGE_NONE; | |
| 96 | + } | |
| 97 | + | |
| 98 | + bool Host::isConnected() const { | |
| 99 | + this->session->waitForReady(this->timeout); | |
| 100 | + return getConnectionState() == CONNECTED_TN3270E; | |
| 101 | + } | |
| 102 | + | |
| 93 | 103 | std::string Host::toString() const { |
| 94 | 104 | |
| 95 | 105 | this->session->waitForReady(this->timeout); | ... | ... |
src/lib3270++/local/session.cc
| ... | ... | @@ -268,7 +268,9 @@ |
| 268 | 268 | baddr = lib3270_get_next_unprotected(hSession,0); |
| 269 | 269 | } |
| 270 | 270 | |
| 271 | - lib3270_set_cursor_address(hSession,baddr); | |
| 271 | + if(lib3270_set_cursor_address(hSession,baddr)) { | |
| 272 | + throw std::system_error(errno, std::system_category()); | |
| 273 | + } | |
| 272 | 274 | |
| 273 | 275 | return *this; |
| 274 | 276 | } |
| ... | ... | @@ -278,12 +280,10 @@ |
| 278 | 280 | /// @param addr Cursor address. |
| 279 | 281 | void Local::Session::setCursorPosition(unsigned short addr) { |
| 280 | 282 | |
| 281 | - if(!lib3270_is_connected(hSession)) { | |
| 282 | - throw std::system_error(ENOTCONN, std::system_category()); | |
| 283 | + if(lib3270_set_cursor_address(hSession,addr) < 0) { | |
| 284 | + throw std::system_error(errno, std::system_category()); | |
| 283 | 285 | } |
| 284 | 286 | |
| 285 | - lib3270_set_cursor_address(hSession,baddr); | |
| 286 | - | |
| 287 | 287 | } |
| 288 | 288 | |
| 289 | 289 | /// @brief Set cursor position. |
| ... | ... | @@ -292,11 +292,10 @@ |
| 292 | 292 | /// @param col New cursor column. |
| 293 | 293 | void Local::Session::setCursorPosition(unsigned short row, unsigned short col) { |
| 294 | 294 | |
| 295 | - if(!lib3270_is_connected(hSession)) { | |
| 296 | - throw std::system_error(ENOTCONN, std::system_category()); | |
| 295 | + if(lib3270_set_cursor_position(hSession,row,col)) { | |
| 296 | + throw std::system_error(errno, std::system_category()); | |
| 297 | 297 | } |
| 298 | 298 | |
| 299 | - lib3270_set_cursor_position(hSession,row,col); | |
| 300 | 299 | } |
| 301 | 300 | |
| 302 | 301 | ... | ... |
src/lib3270/kybd.c
| ... | ... | @@ -974,6 +974,8 @@ static Boolean key_Character(H3270 *hSession, int code, Boolean with_ge, Boolean |
| 974 | 974 | |
| 975 | 975 | LIB3270_EXPORT int lib3270_input_string(H3270 *hSession, const unsigned char *str) |
| 976 | 976 | { |
| 977 | + FAIL_IF_NOT_ONLINE(hSession); | |
| 978 | + | |
| 977 | 979 | while(*str) |
| 978 | 980 | { |
| 979 | 981 | 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 |
| 986 | 988 | } |
| 987 | 989 | |
| 988 | 990 | /** |
| 989 | - * Handle an ordinary character key, given an ASCII code. | |
| 991 | + * @brief Handle an ordinary character key, given an ASCII code. | |
| 990 | 992 | * |
| 991 | 993 | */ |
| 992 | 994 | void key_ACharacter(H3270 *hSession, unsigned char c, enum keytype keytype, enum iaction cause,Boolean *skipped) | ... | ... |
src/lib3270/paste.c
| ... | ... | @@ -221,14 +221,29 @@ static int set_string(H3270 *hSession, const unsigned char *str) |
| 221 | 221 | return data.qtd; |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | +/** | |
| 225 | + * @brief Set string at defined position. | |
| 226 | + * | |
| 227 | + * @param hSession Session handle. | |
| 228 | + * @param row Row for the first character. | |
| 229 | + * @param col Col for the first character. | |
| 230 | + * @param str String to set. | |
| 231 | + * | |
| 232 | + * @return -1 if error (sets errno) or number of processed characters. | |
| 233 | + * | |
| 234 | + */ | |
| 224 | 235 | LIB3270_EXPORT int lib3270_set_string_at(H3270 *hSession, int row, int col, const unsigned char *str) |
| 225 | 236 | { |
| 226 | 237 | int rc = 0; |
| 227 | 238 | |
| 228 | - CHECK_SESSION_HANDLE(hSession); | |
| 239 | + FAIL_IF_NOT_ONLINE(hSession); | |
| 229 | 240 | |
| 241 | + // Is Keyboard locked ? | |
| 230 | 242 | if(hSession->kybdlock) |
| 231 | - return -EINVAL; | |
| 243 | + { | |
| 244 | + errno = EPERM; | |
| 245 | + return -1; | |
| 246 | + } | |
| 232 | 247 | |
| 233 | 248 | if(hSession->selected && !lib3270_get_toggle(hSession,LIB3270_TOGGLE_KEEP_SELECTED)) |
| 234 | 249 | lib3270_unselect(hSession); |
| ... | ... | @@ -247,6 +262,7 @@ LIB3270_EXPORT int lib3270_set_string_at(H3270 *hSession, int row, int col, cons |
| 247 | 262 | } |
| 248 | 263 | |
| 249 | 264 | trace("%s rc=%d",__FUNCTION__,rc); |
| 265 | + | |
| 250 | 266 | return rc; |
| 251 | 267 | } |
| 252 | 268 | ... | ... |
src/lib3270/selection.c
| ... | ... | @@ -916,41 +916,54 @@ LIB3270_EXPORT int lib3270_move_cursor(H3270 *hSession, LIB3270_DIRECTION dir, u |
| 916 | 916 | int maxlen = hSession->cols * hSession->rows; |
| 917 | 917 | |
| 918 | 918 | if(!lib3270_connected(hSession)) |
| 919 | + { | |
| 920 | + errno = ENOTCONN; | |
| 919 | 921 | return -1; |
| 922 | + } | |
| 920 | 923 | |
| 921 | 924 | switch(dir) |
| 922 | 925 | { |
| 923 | 926 | case LIB3270_DIR_UP: |
| 927 | + | |
| 924 | 928 | if(sel && cursor_addr <= hSession->cols) |
| 925 | - return EINVAL; | |
| 929 | + return errno = EINVAL; | |
| 930 | + | |
| 926 | 931 | cursor_addr -= hSession->cols; |
| 927 | 932 | break; |
| 928 | 933 | |
| 929 | 934 | case LIB3270_DIR_DOWN: |
| 935 | + | |
| 930 | 936 | if(sel && cursor_addr >= (hSession->cols * (hSession->rows-1))) |
| 931 | - return EINVAL; | |
| 937 | + return errno = EINVAL; | |
| 938 | + | |
| 932 | 939 | cursor_addr += hSession->cols; |
| 933 | 940 | break; |
| 934 | 941 | |
| 935 | 942 | case LIB3270_DIR_LEFT: |
| 943 | + | |
| 936 | 944 | if(sel && (cursor_addr % hSession->cols) < 1) |
| 937 | - return EINVAL; | |
| 945 | + return errno = EINVAL; | |
| 946 | + | |
| 938 | 947 | cursor_addr--; |
| 939 | 948 | break; |
| 940 | 949 | |
| 941 | 950 | case LIB3270_DIR_RIGHT: |
| 951 | + | |
| 942 | 952 | if(sel && (cursor_addr % hSession->cols) >= (hSession->cols-1)) |
| 943 | - return EINVAL; | |
| 953 | + return errno = EINVAL; | |
| 954 | + | |
| 944 | 955 | cursor_addr++; |
| 945 | 956 | break; |
| 946 | 957 | |
| 947 | 958 | case LIB3270_DIR_END: |
| 959 | + | |
| 948 | 960 | cursor_addr = lib3270_get_field_end(hSession,cursor_addr); |
| 949 | 961 | if(cursor_addr == -1) |
| 950 | - return EINVAL; | |
| 962 | + return errno = EINVAL; | |
| 951 | 963 | break; |
| 952 | 964 | |
| 953 | 965 | default: |
| 966 | + errno = EINVAL; | |
| 954 | 967 | return -1; |
| 955 | 968 | } |
| 956 | 969 | ... | ... |