Commit 52892e7f008b05d18571bfb055b8d957728b6d84
1 parent
59e8fd70
Exists in
master
and in
1 other branch
Updating HLLAPI support library.
Showing
8 changed files
with
182 additions
and
100 deletions
Show diff stats
src/core/calls.cc
... | ... | @@ -128,23 +128,15 @@ |
128 | 128 | |
129 | 129 | try { |
130 | 130 | |
131 | - TN3270::Host & session = getSession(); | |
132 | - | |
133 | - if(!session.isConnected()) { | |
134 | - hllapi_lasterror = strerror(ENOTCONN); | |
135 | - return HLLAPI_STATUS_DISCONNECTED; | |
136 | - } | |
137 | - | |
138 | - return (DWORD) session.getProgramMessage(); | |
131 | + return (DWORD) getSession().getProgramMessage(); | |
139 | 132 | |
140 | 133 | } catch(std::exception &e) { |
141 | 134 | |
142 | 135 | hllapi_lasterror = e.what(); |
143 | - return HLLAPI_STATUS_SYSTEM_ERROR; | |
144 | 136 | |
145 | 137 | } |
146 | 138 | |
147 | - return HLLAPI_STATUS_SUCCESS; | |
139 | + return -1; | |
148 | 140 | |
149 | 141 | } |
150 | 142 | |
... | ... | @@ -251,14 +243,7 @@ |
251 | 243 | |
252 | 244 | try { |
253 | 245 | |
254 | - TN3270::Host &host = getSession(); | |
255 | - | |
256 | - if(!host.isConnected()) | |
257 | - return HLLAPI_STATUS_DISCONNECTED; | |
258 | - | |
259 | - string contents = host.toString(row, col, strlen(text), 0); | |
260 | - | |
261 | - return strncmp(contents.c_str(),text,strlen(text)); | |
246 | + return getSession().compare((unsigned int) row, (unsigned int) col, text); | |
262 | 247 | |
263 | 248 | } catch(std::exception &e) { |
264 | 249 | |
... | ... | @@ -270,27 +255,34 @@ |
270 | 255 | |
271 | 256 | } |
272 | 257 | |
273 | - HLLAPI_API_CALL hllapi_find_text(LPSTR text) { | |
258 | + HLLAPI_API_CALL hllapi_cmp_text_at_address(WORD addr, LPSTR text) { | |
274 | 259 | |
275 | 260 | try { |
276 | 261 | |
277 | - TN3270::Host &host = getSession(); | |
262 | + return getSession().compare((int) addr, text); | |
278 | 263 | |
279 | - if(!host.isConnected()) { | |
280 | - hllapi_lasterror = "Not connected"; | |
281 | - return -1; | |
282 | - } | |
264 | + } catch(std::exception &e) { | |
283 | 265 | |
284 | - string contents = host.toString(0,-1,'\0'); | |
266 | + hllapi_lasterror = e.what(); | |
285 | 267 | |
286 | - size_t pos = contents.find(text); | |
268 | + } | |
287 | 269 | |
288 | - if(pos == string::npos) { | |
289 | - hllapi_lasterror = "Not found"; | |
290 | - return -1; | |
291 | - } | |
270 | + return HLLAPI_STATUS_SYSTEM_ERROR; | |
271 | + | |
272 | + } | |
273 | + | |
274 | + | |
275 | + HLLAPI_API_CALL hllapi_find_text(const LPSTR text) { | |
276 | + | |
277 | + try { | |
278 | + | |
279 | + if(text && *text) { | |
280 | + | |
281 | + size_t pos = getSession().find(text); | |
282 | + if(pos != string::npos) | |
283 | + return pos; | |
292 | 284 | |
293 | - return pos; | |
285 | + } | |
294 | 286 | |
295 | 287 | } catch(std::exception &e) { |
296 | 288 | ... | ... |
src/core/get.cc
... | ... | @@ -167,36 +167,6 @@ |
167 | 167 | |
168 | 168 | }); |
169 | 169 | |
170 | - /* | |
171 | - try { | |
172 | - | |
173 | - TN3270::Host &host = getSession(); | |
174 | - | |
175 | - if(!host.isConnected()) | |
176 | - return HLLAPI_STATUS_DISCONNECTED; | |
177 | - | |
178 | - if(!(buffer && *buffer)) | |
179 | - return HLLAPI_STATUS_BAD_PARAMETER; | |
180 | - | |
181 | - | |
182 | - if(len == 0) | |
183 | - return HLLAPI_STATUS_BAD_PARAMETER; | |
184 | - | |
185 | - string luname = host.getLUName(); | |
186 | - memset(buffer,' ',len); | |
187 | - strncpy((char *) buffer, luname.c_str(), std::min((size_t) len,luname.size())); | |
188 | - | |
189 | - } catch(std::exception &e) { | |
190 | - | |
191 | - hllapi_lasterror = e.what(); | |
192 | - return HLLAPI_STATUS_SYSTEM_ERROR; | |
193 | - | |
194 | - } | |
195 | - | |
196 | - return HLLAPI_STATUS_SUCCESS; | |
197 | - | |
198 | - */ | |
199 | - | |
200 | 170 | } |
201 | 171 | |
202 | 172 | ... | ... |
src/core/hllapi.cc
... | ... | @@ -245,17 +245,17 @@ static int search_ps(char *buffer, unsigned short *length, unsigned short *ps) { |
245 | 245 | |
246 | 246 | try { |
247 | 247 | |
248 | - TN3270::Host &host = getSession(); | |
248 | + size_t pos = string::npos; | |
249 | 249 | |
250 | - if(!host.isConnected()) | |
251 | - return HLLAPI_STATUS_DISCONNECTED; | |
250 | + if(length > 0) { | |
252 | 251 | |
253 | - string contents = host.toString(0,-1, '\0'); | |
252 | + pos = getSession().find(string((const char *) buffer,(size_t) length).c_str()); | |
254 | 253 | |
255 | - if( ((size_t) *ps) >= contents.size()) | |
256 | - return HLLAPI_STATUS_BAD_POSITION; | |
254 | + } else { | |
257 | 255 | |
258 | - size_t pos = contents.find(buffer, ((size_t) *ps)); | |
256 | + pos = getSession().find(buffer); | |
257 | + | |
258 | + } | |
259 | 259 | |
260 | 260 | if(pos == string::npos) { |
261 | 261 | *ps = 0; |
... | ... | @@ -266,6 +266,10 @@ static int search_ps(char *buffer, unsigned short *length, unsigned short *ps) { |
266 | 266 | |
267 | 267 | return HLLAPI_STATUS_SUCCESS; |
268 | 268 | |
269 | + } catch(const std::system_error &e) { | |
270 | + | |
271 | + return hllapi_translate_error(e); | |
272 | + | |
269 | 273 | } catch(std::exception &e) { |
270 | 274 | |
271 | 275 | hllapi_lasterror = e.what(); |
... | ... | @@ -323,6 +327,7 @@ static int copy_ps(char *buffer, unsigned short *length, unsigned short *rc) { |
323 | 327 | return HLLAPI_STATUS_SYSTEM_ERROR; |
324 | 328 | |
325 | 329 | /* |
330 | + | |
326 | 331 | size_t szBuffer = strlen(buffer); |
327 | 332 | char * text; |
328 | 333 | |
... | ... | @@ -339,9 +344,11 @@ static int copy_ps(char *buffer, unsigned short *length, unsigned short *rc) { |
339 | 344 | hllapi_free(text); |
340 | 345 | |
341 | 346 | return hllapi_get_state(); |
342 | - */ | |
343 | 347 | |
344 | 348 | return HLLAPI_STATUS_SYSTEM_ERROR; |
349 | + | |
350 | + */ | |
351 | + | |
345 | 352 | } |
346 | 353 | |
347 | 354 | static int wait_system(char *buffer, unsigned short *length, unsigned short *rc) { |
... | ... | @@ -388,35 +395,8 @@ static int copy_str_to_ps(char *text, unsigned short *length, unsigned short *ps |
388 | 395 | // HLLAPI_STATUS_SYSTEM_ERROR 9 A system error was encountered. |
389 | 396 | // |
390 | 397 | // |
391 | - size_t szText = strlen(text); | |
392 | - | |
393 | - if(*length < szText) | |
394 | - szText = *length; | |
395 | - | |
396 | - if(!szText) | |
397 | - return HLLAPI_STATUS_BAD_PARAMETER; | |
398 | - | |
399 | - switch(hllapi_get_message_id()) | |
400 | - { | |
401 | - case LIB3270_MESSAGE_NONE: | |
402 | - break; | |
403 | - | |
404 | - case LIB3270_MESSAGE_DISCONNECTED: | |
405 | - return HLLAPI_STATUS_DISCONNECTED; | |
406 | - | |
407 | - case LIB3270_MESSAGE_MINUS: | |
408 | - case LIB3270_MESSAGE_PROTECTED: | |
409 | - case LIB3270_MESSAGE_NUMERIC: | |
410 | - case LIB3270_MESSAGE_OVERFLOW: | |
411 | - case LIB3270_MESSAGE_INHIBIT: | |
412 | - case LIB3270_MESSAGE_KYBDLOCK: | |
413 | - return HLLAPI_STATUS_KEYBOARD_LOCKED; | |
414 | - | |
415 | - default: | |
416 | - return HLLAPI_STATUS_SYSTEM_ERROR; | |
417 | - } | |
418 | - | |
419 | - return hllapi_emulate_input(text,szText,0); | |
398 | + *ps = 0; | |
399 | + return hllapi_emulate_input(text,*length,0); | |
420 | 400 | } |
421 | 401 | |
422 | 402 | static int reset_system(char *buffer, unsigned short *length, unsigned short *rc) { | ... | ... |
src/core/private.h
... | ... | @@ -54,6 +54,7 @@ |
54 | 54 | TN3270_PRIVATE TN3270::Host & getSession(); |
55 | 55 | |
56 | 56 | TN3270_PRIVATE DWORD hllapi_translate_error(LIB3270_KEYBOARD_LOCK_STATE state); |
57 | + TN3270_PRIVATE DWORD hllapi_translate_error(LIB3270_MESSAGE state); | |
57 | 58 | TN3270_PRIVATE DWORD hllapi_translate_error(const std::system_error &error); |
58 | 59 | |
59 | 60 | #endif // PRIVATE_H_INCLUDED | ... | ... |
src/core/set.cc
... | ... | @@ -56,6 +56,7 @@ |
56 | 56 | } catch(const std::exception &e) { |
57 | 57 | |
58 | 58 | // Worker has failed! |
59 | + | |
59 | 60 | hllapi_lasterror = e.what(); |
60 | 61 | } |
61 | 62 | |
... | ... | @@ -106,7 +107,7 @@ |
106 | 107 | if(!(text && *text)) |
107 | 108 | return HLLAPI_STATUS_BAD_PARAMETER; |
108 | 109 | |
109 | - if(!length) | |
110 | + if(length < 1) | |
110 | 111 | length = strlen(text); |
111 | 112 | |
112 | 113 | return set([text,length](TN3270::Host &host) { | ... | ... |
src/core/tools.cc
... | ... | @@ -107,3 +107,26 @@ |
107 | 107 | |
108 | 108 | } |
109 | 109 | |
110 | + DWORD hllapi_translate_error(LIB3270_MESSAGE state) { | |
111 | + | |
112 | + switch(state) { | |
113 | + case LIB3270_MESSAGE_NONE: | |
114 | + return HLLAPI_STATUS_SUCCESS; | |
115 | + | |
116 | + case LIB3270_MESSAGE_DISCONNECTED: | |
117 | + return HLLAPI_STATUS_DISCONNECTED; | |
118 | + | |
119 | + case LIB3270_MESSAGE_MINUS: | |
120 | + case LIB3270_MESSAGE_PROTECTED: | |
121 | + case LIB3270_MESSAGE_NUMERIC: | |
122 | + case LIB3270_MESSAGE_OVERFLOW: | |
123 | + case LIB3270_MESSAGE_INHIBIT: | |
124 | + case LIB3270_MESSAGE_KYBDLOCK: | |
125 | + return HLLAPI_STATUS_KEYBOARD_LOCKED; | |
126 | + | |
127 | + default: | |
128 | + return HLLAPI_STATUS_SYSTEM_ERROR; | |
129 | + } | |
130 | + | |
131 | + return HLLAPI_STATUS_SYSTEM_ERROR; | |
132 | + } | ... | ... |
src/include/lib3270/hllapi.h
... | ... | @@ -206,16 +206,122 @@ |
206 | 206 | */ |
207 | 207 | HLLAPI_API_CALL hllapi_disconnect(void); |
208 | 208 | |
209 | + /** | |
210 | + * @brief Get program message. | |
211 | + * | |
212 | + * @return Current program message or -1 on error. | |
213 | + * | |
214 | + */ | |
209 | 215 | HLLAPI_API_CALL hllapi_get_message_id(void); |
216 | + | |
210 | 217 | HLLAPI_API_CALL hllapi_is_connected(void); |
211 | 218 | HLLAPI_API_CALL hllapi_get_state(void); |
212 | 219 | HLLAPI_API_CALL hllapi_get_screen_at(WORD row, WORD col, LPSTR buffer); |
213 | 220 | HLLAPI_API_CALL hllapi_get_screen(WORD pos, LPSTR buffer, WORD len); |
214 | 221 | HLLAPI_API_CALL hllapi_set_text_at(WORD row, WORD col, LPSTR text); |
222 | + | |
223 | + /** | |
224 | + * @brief Compare contents at position. | |
225 | + * | |
226 | + * @param row | |
227 | + * @param col | |
228 | + * @param text | |
229 | + * | |
230 | + * @return Result of the strcmp of the string and the contents of position. | |
231 | + * | |
232 | + * @retval HLLAPI_STATUS_SYSTEM_ERROR The query has failed. | |
233 | + * @retval 0 The string at the position is the same. | |
234 | + * @retval -1 | |
235 | + * @retval 1 | |
236 | + * | |
237 | + */ | |
215 | 238 | HLLAPI_API_CALL hllapi_cmp_text_at(WORD row, WORD col, LPSTR text); |
216 | - HLLAPI_API_CALL hllapi_find_text(LPSTR text); | |
239 | + | |
240 | + /** | |
241 | + * @brief Compare contents at position. | |
242 | + * | |
243 | + * @param row | |
244 | + * @param col | |
245 | + * @param text | |
246 | + * | |
247 | + * @return Result of the strcmp of the string and the contents of position. | |
248 | + * | |
249 | + * @retval HLLAPI_STATUS_SYSTEM_ERROR The query has failed. | |
250 | + * @retval 0 The string at the position is the same. | |
251 | + * @retval -1 | |
252 | + * @retval 1 | |
253 | + * | |
254 | + */ | |
255 | + HLLAPI_API_CALL hllapi_cmp_text_at_address(WORD addr, LPSTR text); | |
256 | + | |
257 | + /** | |
258 | + * @brief Find string in the screen. | |
259 | + * | |
260 | + * @return Position of the text inside the screen or -1 if failed. | |
261 | + * | |
262 | + */ | |
263 | + HLLAPI_API_CALL hllapi_find_text(const LPSTR text); | |
264 | + | |
265 | + /** | |
266 | + * @brief Interpret string with action codes prefixed by '@'. | |
267 | + * | |
268 | + * Insert string parsing the action codes prefixed with '@' character. | |
269 | + * | |
270 | + * Value | Action | Description | | |
271 | + * :----:|:------------|:-----------------------------------------------------------| | |
272 | + * @@P | - | Print the screen contents (if available) | | |
273 | + * @@@@ | - | Input the @@ char. | | |
274 | + * @@E | ENTER | - | | |
275 | + * @@F | ERASE_EOF | - | | |
276 | + * @@1 | PF1 | Send the PF1 key. | | |
277 | + * @@2 | PF2 | Send the PF2 key. | | |
278 | + * @@3 | PF3 | Send the PF3 key. | | |
279 | + * @@4 | PF4 | Send the PF4 key. | | |
280 | + * @@5 | PF5 | Send the PF5 key. | | |
281 | + * @@6 | PF6 | Send the PF6 key. | | |
282 | + * @@7 | PF7 | Send the PF7 key. | | |
283 | + * @@8 | PF8 | Send the PF8 key. | | |
284 | + * @@9 | PF9 | Send the PF9 key. | | |
285 | + * @@a | PF10 | Send the PF10 key. | | |
286 | + * @@b | PF11 | Send the PF11 key. | | |
287 | + * @@c | PF12 | Send the PF12 key. | | |
288 | + * @@d | PF13 | Send the PF13 key. | | |
289 | + * @@e | PF14 | Send the PF14 key. | | |
290 | + * @@f | PF15 | Send the PF15 key. | | |
291 | + * @@g | PF16 | Send the PF16 key. | | |
292 | + * @@h | PF17 | Send the PF17 key. | | |
293 | + * @@u | PF18 | Send the PF18 key. | | |
294 | + * @@j | PF19 | Send the PF19 key. | | |
295 | + * @@k | PF20 | Send the PF20 key. | | |
296 | + * @@l | PF21 | Send the PF21 key. | | |
297 | + * @@m | PF22 | Send the PF22 key. | | |
298 | + * @@n | PF23 | Send the PF23 key. | | |
299 | + * @@o | PF24 | Send the PF24 key. | | |
300 | + * @@x | PA1 | Send the PA1 key. | | |
301 | + * @@y | PA2 | Send the PA2 key. | | |
302 | + * @@z | PA3 | Send the PA3 key. | | |
303 | + * @@D | CHAR_DELETE | | | |
304 | + * @@N | NEWLINE | | | |
305 | + * @@C | CLEAR | | | |
306 | + * @@R | KYBD_RESET | | | |
307 | + * @@< | BACKSPACE | | | |
308 | + * | |
309 | + * @param text Text to input. | |
310 | + * @param length Length of the text (-1 to use the string length). | |
311 | + * @param pasting Unused (kept for compatibility). | |
312 | + * | |
313 | + */ | |
217 | 314 | HLLAPI_API_CALL hllapi_emulate_input(const LPSTR text, WORD length, WORD pasting); |
315 | + | |
316 | + /** | |
317 | + * @brief Input string. | |
318 | + * | |
319 | + * @param buffer String to input. | |
320 | + * @param length Length of the string (-1 ou 0 to auto detect). | |
321 | + * | |
322 | + */ | |
218 | 323 | HLLAPI_API_CALL hllapi_input_string(LPSTR buffer, WORD len); |
324 | + | |
219 | 325 | HLLAPI_API_CALL hllapi_wait_for_ready(WORD seconds); |
220 | 326 | HLLAPI_API_CALL hllapi_wait_for_change(WORD seconds); |
221 | 327 | HLLAPI_API_CALL hllapi_wait(WORD seconds); | ... | ... |
src/testprogram/testprogram.cc
... | ... | @@ -192,6 +192,15 @@ |
192 | 192 | |
193 | 193 | rc = hllapi_input_string((LPSTR) cmdline.c_str()+6,0); |
194 | 194 | |
195 | + } else if(strncasecmp(cmdline.c_str(),"wait ",5) == 0) { | |
196 | + | |
197 | + rc = hllapi_wait_for_ready(5); | |
198 | + | |
199 | + } else if(strncasecmp(cmdline.c_str(),"find ",5) == 0) { | |
200 | + | |
201 | + cout << "Searching for \"" << (cmdline.c_str()+5) << "\"" << endl; | |
202 | + rc = hllapi_find_text(cmdline.c_str()+5); | |
203 | + | |
195 | 204 | } else { |
196 | 205 | |
197 | 206 | cout << "Unknown command \"" << cmdline << "\""<< endl; | ... | ... |