Commit 2c632cd705c8a6d647b1972fa53f7d020d75bcff
1 parent
52be7baf
Exists in
master
and in
1 other branch
Refactoring HLLAPI.
Showing
8 changed files
with
215 additions
and
121 deletions
Show diff stats
hllapi.cbp
@@ -35,6 +35,8 @@ | @@ -35,6 +35,8 @@ | ||
35 | <Unit filename="src/core/actions.cc" /> | 35 | <Unit filename="src/core/actions.cc" /> |
36 | <Unit filename="src/core/calls.cc" /> | 36 | <Unit filename="src/core/calls.cc" /> |
37 | <Unit filename="src/core/controller.cc" /> | 37 | <Unit filename="src/core/controller.cc" /> |
38 | + <Unit filename="src/core/cursor.cc" /> | ||
39 | + <Unit filename="src/core/get.cc" /> | ||
38 | <Unit filename="src/core/hllapi.cc" /> | 40 | <Unit filename="src/core/hllapi.cc" /> |
39 | <Unit filename="src/core/private.h" /> | 41 | <Unit filename="src/core/private.h" /> |
40 | <Unit filename="src/core/windows/resources.rc" /> | 42 | <Unit filename="src/core/windows/resources.rc" /> |
src/core/actions.cc
@@ -74,25 +74,30 @@ | @@ -74,25 +74,30 @@ | ||
74 | return action(TN3270::ERASE_INPUT); | 74 | return action(TN3270::ERASE_INPUT); |
75 | } | 75 | } |
76 | 76 | ||
77 | -/* | ||
78 | - | ||
79 | - HLLAPI_API_CALL hllapi_reset(void) | ||
80 | - { | ||
81 | - return HLLAPI_STATUS_SUCCESS; | 77 | + HLLAPI_API_CALL hllapi_kybdreset(void) { |
78 | + return action(TN3270::KYBD_RESET); | ||
82 | } | 79 | } |
83 | 80 | ||
84 | - HLLAPI_API_CALL hllapi_action(LPSTR buffer) { | ||
85 | - try | ||
86 | - { | ||
87 | - session::get_default()->action((const char *) buffer); | ||
88 | - } | ||
89 | - catch(std::exception &e) | ||
90 | - { | ||
91 | - return HLLAPI_STATUS_SYSTEM_ERROR; | 81 | + HLLAPI_API_CALL hllapi_action(LPSTR action_name) { |
82 | + | ||
83 | + try { | ||
84 | + | ||
85 | + getSession().action((const char *) action_name); | ||
86 | + | ||
87 | + return HLLAPI_STATUS_SUCCESS; | ||
88 | + | ||
89 | + } catch(std::exception &e) { | ||
90 | + | ||
91 | + hllapi_lasterror = e.what(); | ||
92 | + | ||
92 | } | 93 | } |
93 | - return HLLAPI_STATUS_SUCCESS; | 94 | + |
95 | + return HLLAPI_STATUS_SYSTEM_ERROR; | ||
96 | + | ||
94 | } | 97 | } |
95 | 98 | ||
99 | +/* | ||
100 | + | ||
96 | HLLAPI_API_CALL hllapi_print(void) | 101 | HLLAPI_API_CALL hllapi_print(void) |
97 | { | 102 | { |
98 | return session::get_default()->print(); | 103 | return session::get_default()->print(); |
src/core/calls.cc
@@ -237,29 +237,6 @@ | @@ -237,29 +237,6 @@ | ||
237 | return hllapi_get_state(); | 237 | return hllapi_get_state(); |
238 | } | 238 | } |
239 | 239 | ||
240 | - HLLAPI_API_CALL hllapi_get_screen_at(WORD row, WORD col, LPSTR buffer) | ||
241 | - { | ||
242 | - if(!hllapi_is_connected()) | ||
243 | - return HLLAPI_STATUS_DISCONNECTED; | ||
244 | - | ||
245 | - if(!(buffer && *buffer)) | ||
246 | - return HLLAPI_STATUS_SYSTEM_ERROR; | ||
247 | - | ||
248 | - try | ||
249 | - { | ||
250 | - size_t sz = strlen(buffer); | ||
251 | - string str = session::get_default()->get_string_at(row,col,sz); | ||
252 | - strncpy(buffer,str.c_str(),sz); | ||
253 | - } | ||
254 | - catch(std::exception &e) | ||
255 | - { | ||
256 | - return HLLAPI_STATUS_SYSTEM_ERROR; | ||
257 | - } | ||
258 | - | ||
259 | - return HLLAPI_STATUS_SUCCESS; | ||
260 | - } | ||
261 | - | ||
262 | - | ||
263 | HLLAPI_API_CALL hllapi_set_text_at(WORD row, WORD col, LPSTR text) | 240 | HLLAPI_API_CALL hllapi_set_text_at(WORD row, WORD col, LPSTR text) |
264 | { | 241 | { |
265 | if(!hllapi_is_connected()) | 242 | if(!hllapi_is_connected()) |
@@ -347,88 +324,6 @@ | @@ -347,88 +324,6 @@ | ||
347 | return *datadir; | 324 | return *datadir; |
348 | } | 325 | } |
349 | 326 | ||
350 | - HLLAPI_API_CALL hllapi_setcursor(WORD pos) | ||
351 | - { | ||
352 | - if(!hllapi_is_connected()) | ||
353 | - return HLLAPI_STATUS_DISCONNECTED; | ||
354 | - | ||
355 | - session::get_default()->set_cursor_addr(pos-1); | ||
356 | - | ||
357 | - return HLLAPI_STATUS_SUCCESS; | ||
358 | - | ||
359 | - } | ||
360 | - | ||
361 | - HLLAPI_API_CALL hllapi_set_cursor_address(WORD pos) | ||
362 | - { | ||
363 | - if(!hllapi_is_connected()) | ||
364 | - return HLLAPI_STATUS_DISCONNECTED; | ||
365 | - | ||
366 | - session::get_default()->set_cursor_addr(pos-1); | ||
367 | - | ||
368 | - return HLLAPI_STATUS_SUCCESS; | ||
369 | - | ||
370 | - } | ||
371 | - | ||
372 | - HLLAPI_API_CALL hllapi_get_cursor_address() | ||
373 | - { | ||
374 | - return session::get_default()->get_cursor_addr()+1; | ||
375 | - } | ||
376 | - | ||
377 | - HLLAPI_API_CALL hllapi_getcursor() | ||
378 | - { | ||
379 | - return session::get_default()->get_cursor_addr()+1; | ||
380 | - } | ||
381 | - | ||
382 | - HLLAPI_API_CALL hllapi_get_screen(WORD offset, LPSTR buffer, WORD len) | ||
383 | - { | ||
384 | - if(!hllapi_is_connected()) | ||
385 | - return HLLAPI_STATUS_DISCONNECTED; | ||
386 | - | ||
387 | - int rc = HLLAPI_STATUS_SYSTEM_ERROR; | ||
388 | - | ||
389 | - if(offset < 1) | ||
390 | - { | ||
391 | - return HLLAPI_STATUS_BAD_PARAMETER; | ||
392 | - } | ||
393 | - | ||
394 | - offset--; | ||
395 | - | ||
396 | - if(!session::has_default()) | ||
397 | - { | ||
398 | - return HLLAPI_STATUS_DISCONNECTED; | ||
399 | - } | ||
400 | - | ||
401 | - if(!(buffer && *buffer)) { | ||
402 | - return HLLAPI_STATUS_BAD_PARAMETER; | ||
403 | - } | ||
404 | - | ||
405 | - try | ||
406 | - { | ||
407 | - size_t szBuffer; | ||
408 | - | ||
409 | - if(len > 0) | ||
410 | - { | ||
411 | - szBuffer = (size_t) len; | ||
412 | - } | ||
413 | - else | ||
414 | - { | ||
415 | - return HLLAPI_STATUS_BAD_PARAMETER; | ||
416 | - } | ||
417 | - | ||
418 | - memset(buffer,' ',szBuffer); | ||
419 | - | ||
420 | - string str = session::get_default()->get_string(offset,szBuffer,false); | ||
421 | - strncpy(buffer,str.c_str(),szBuffer); | ||
422 | - rc = HLLAPI_STATUS_SUCCESS; | ||
423 | - } | ||
424 | - catch(std::exception &e) | ||
425 | - { | ||
426 | - rc = HLLAPI_STATUS_SYSTEM_ERROR; | ||
427 | - } | ||
428 | - | ||
429 | - return rc; | ||
430 | - } | ||
431 | - | ||
432 | HLLAPI_API_CALL hllapi_emulate_input(const LPSTR buffer, WORD len, WORD pasting) | 327 | HLLAPI_API_CALL hllapi_emulate_input(const LPSTR buffer, WORD len, WORD pasting) |
433 | { | 328 | { |
434 | if(!hllapi_is_connected()) | 329 | if(!hllapi_is_connected()) |
@@ -0,0 +1,85 @@ | @@ -0,0 +1,85 @@ | ||
1 | +/* | ||
2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | ||
3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | ||
4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | ||
5 | + * | ||
6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | ||
7 | + * | ||
8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | ||
9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | ||
10 | + * Free Software Foundation. | ||
11 | + * | ||
12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | ||
13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | ||
14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | ||
15 | + * obter mais detalhes. | ||
16 | + * | ||
17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | ||
18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple | ||
19 | + * Place, Suite 330, Boston, MA, 02111-1307, USA | ||
20 | + * | ||
21 | + * Este programa está nomeado como - e possui - linhas de código. | ||
22 | + * | ||
23 | + * Contatos: | ||
24 | + * | ||
25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | ||
26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | ||
27 | + * | ||
28 | + */ | ||
29 | + | ||
30 | + #include "private.h" | ||
31 | + | ||
32 | +/*--[ Implement ]------------------------------------------------------------------------------------*/ | ||
33 | + | ||
34 | + HLLAPI_API_CALL hllapi_set_cursor_address(WORD pos) { | ||
35 | + | ||
36 | + try { | ||
37 | + | ||
38 | + TN3270::Host &host = getSession(); | ||
39 | + | ||
40 | + if(!host.isConnected()) | ||
41 | + return HLLAPI_STATUS_DISCONNECTED; | ||
42 | + | ||
43 | + host.setCursorPosition((unsigned short) pos -1); | ||
44 | + | ||
45 | + return 0; | ||
46 | + | ||
47 | + } catch(std::exception &e) { | ||
48 | + | ||
49 | + hllapi_lasterror = e.what(); | ||
50 | + | ||
51 | + } | ||
52 | + | ||
53 | + return HLLAPI_STATUS_SYSTEM_ERROR; | ||
54 | + | ||
55 | + } | ||
56 | + | ||
57 | + HLLAPI_API_CALL hllapi_setcursor(WORD pos) { | ||
58 | + return hllapi_set_cursor_address(pos); | ||
59 | + } | ||
60 | + | ||
61 | + HLLAPI_API_CALL hllapi_get_cursor_address() { | ||
62 | + | ||
63 | + try { | ||
64 | + | ||
65 | + TN3270::Host &host = getSession(); | ||
66 | + | ||
67 | + if(!host.isConnected()) | ||
68 | + return 0; | ||
69 | + | ||
70 | + return (DWORD) (host.getCursorPosition()+1); | ||
71 | + | ||
72 | + } catch(std::exception &e) { | ||
73 | + | ||
74 | + hllapi_lasterror = e.what(); | ||
75 | + return -1; | ||
76 | + | ||
77 | + } | ||
78 | + | ||
79 | + return -1; | ||
80 | + } | ||
81 | + | ||
82 | + HLLAPI_API_CALL hllapi_getcursor() { | ||
83 | + return hllapi_get_cursor_address(); | ||
84 | + } | ||
85 | + |
@@ -0,0 +1,92 @@ | @@ -0,0 +1,92 @@ | ||
1 | +/* | ||
2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | ||
3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | ||
4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | ||
5 | + * | ||
6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | ||
7 | + * | ||
8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | ||
9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | ||
10 | + * Free Software Foundation. | ||
11 | + * | ||
12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | ||
13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | ||
14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | ||
15 | + * obter mais detalhes. | ||
16 | + * | ||
17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | ||
18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple | ||
19 | + * Place, Suite 330, Boston, MA, 02111-1307, USA | ||
20 | + * | ||
21 | + * Este programa está nomeado como - e possui - linhas de código. | ||
22 | + * | ||
23 | + * Contatos: | ||
24 | + * | ||
25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | ||
26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | ||
27 | + * | ||
28 | + */ | ||
29 | + | ||
30 | + #include "private.h" | ||
31 | + | ||
32 | +/*--[ Implement ]------------------------------------------------------------------------------------*/ | ||
33 | + | ||
34 | + HLLAPI_API_CALL hllapi_get_screen_at(WORD row, WORD col, LPSTR buffer) { | ||
35 | + | ||
36 | + try { | ||
37 | + | ||
38 | + TN3270::Host &host = getSession(); | ||
39 | + | ||
40 | + if(!host.isConnected()) | ||
41 | + return HLLAPI_STATUS_DISCONNECTED; | ||
42 | + | ||
43 | + if(!(buffer && *buffer)) | ||
44 | + return HLLAPI_STATUS_BAD_PARAMETER; | ||
45 | + | ||
46 | + size_t length = strlen(buffer); | ||
47 | + string contents = host.toString( (int) row, (int) col, length); | ||
48 | + | ||
49 | + strncpy((char *) buffer, contents.c_str(), std::min(length,contents.size())); | ||
50 | + | ||
51 | + } catch(std::exception &e) { | ||
52 | + | ||
53 | + hllapi_lasterror = e.what(); | ||
54 | + return HLLAPI_STATUS_SYSTEM_ERROR; | ||
55 | + | ||
56 | + } | ||
57 | + | ||
58 | + return HLLAPI_STATUS_SUCCESS; | ||
59 | + | ||
60 | + } | ||
61 | + | ||
62 | + HLLAPI_API_CALL hllapi_get_screen(WORD offset, LPSTR buffer, WORD len) { | ||
63 | + | ||
64 | + try { | ||
65 | + | ||
66 | + TN3270::Host &host = getSession(); | ||
67 | + | ||
68 | + if(!host.isConnected()) | ||
69 | + return HLLAPI_STATUS_DISCONNECTED; | ||
70 | + | ||
71 | + if(!(buffer && *buffer)) | ||
72 | + return HLLAPI_STATUS_BAD_PARAMETER; | ||
73 | + | ||
74 | + if(len == 0) | ||
75 | + return HLLAPI_STATUS_BAD_PARAMETER; | ||
76 | + | ||
77 | + string contents = host.toString((int) offset, (size_t) len); | ||
78 | + | ||
79 | + memset(buffer,' ',len); | ||
80 | + strncpy((char *) buffer, contents.c_str(), std::min((size_t) len,contents.size())); | ||
81 | + | ||
82 | + } catch(std::exception &e) { | ||
83 | + | ||
84 | + hllapi_lasterror = e.what(); | ||
85 | + return HLLAPI_STATUS_SYSTEM_ERROR; | ||
86 | + | ||
87 | + } | ||
88 | + | ||
89 | + return HLLAPI_STATUS_SUCCESS; | ||
90 | + | ||
91 | + } | ||
92 | + |
src/core/private.h
src/include/lib3270/hllapi.h
@@ -170,7 +170,7 @@ | @@ -170,7 +170,7 @@ | ||
170 | HLLAPI_API_CALL hllapi_deinit(void); | 170 | HLLAPI_API_CALL hllapi_deinit(void); |
171 | HLLAPI_API_CALL hllapi_get_revision(void); | 171 | HLLAPI_API_CALL hllapi_get_revision(void); |
172 | 172 | ||
173 | - HLLAPI_API_CALL hllapi_reset(void); | 173 | + HLLAPI_API_CALL hllapi_kybdreset(void); |
174 | 174 | ||
175 | /** | 175 | /** |
176 | * @brief Connect to host. | 176 | * @brief Connect to host. |
@@ -211,7 +211,7 @@ | @@ -211,7 +211,7 @@ | ||
211 | HLLAPI_API_CALL hllapi_erase_eol(void); | 211 | HLLAPI_API_CALL hllapi_erase_eol(void); |
212 | HLLAPI_API_CALL hllapi_erase_input(void); | 212 | HLLAPI_API_CALL hllapi_erase_input(void); |
213 | 213 | ||
214 | - HLLAPI_API_CALL hllapi_action(LPSTR buffer); | 214 | + HLLAPI_API_CALL hllapi_action(LPSTR action_name); |
215 | 215 | ||
216 | HLLAPI_API_CALL hllapi_print(void); | 216 | HLLAPI_API_CALL hllapi_print(void); |
217 | 217 |
src/testprogram/testprogram.cc
@@ -82,6 +82,20 @@ | @@ -82,6 +82,20 @@ | ||
82 | return rc; | 82 | return rc; |
83 | } | 83 | } |
84 | 84 | ||
85 | + rc = hllapi_wait_for_ready(10); | ||
86 | + if(rc) { | ||
87 | + cout << "hllapi_wait_for_ready returns with rc=" << rc << " (" << hllapi_get_last_error() << ")" << endl; | ||
88 | + return rc; | ||
89 | + } | ||
90 | + | ||
91 | + cout << "Host is " << (hllapi_is_connected() ? "connected" : "not connected") << endl; | ||
92 | + | ||
93 | + rc = hllapi_disconnect(); | ||
94 | + if(rc) { | ||
95 | + cout << "hllapi_disconnect returns with rc=" << rc << " (" << hllapi_get_last_error() << ")" << endl; | ||
96 | + return rc; | ||
97 | + } | ||
98 | + | ||
85 | cout << "HLLAPI Last error was \"" << hllapi_get_last_error() << "\"" << endl; | 99 | cout << "HLLAPI Last error was \"" << hllapi_get_last_error() << "\"" << endl; |
86 | 100 | ||
87 | /* | 101 | /* |