Commit e609d27751f842d428073251802a8b3fd144ad5e

Authored by perry.werneck@gmail.com
1 parent c35dcdd0

Trabalhando na interface HLLAPI

src/include/lib3270.h
... ... @@ -533,6 +533,16 @@
533 533 LIB3270_EXPORT int lib3270_get_cursor_address(H3270 *h);
534 534  
535 535 /**
  536 + * Print page
  537 + *
  538 + * @param h Session Handle.
  539 + *
  540 + * @return 0 if ok, error code if not.
  541 + *
  542 + */
  543 + LIB3270_EXPORT int lib3270_print(H3270 *h);
  544 +
  545 + /**
536 546 * Get buffer contents.
537 547 *
538 548 * @param h Session handle.
... ...
src/lib3270/util.c
... ... @@ -1018,3 +1018,7 @@ int gettimeofday(struct timeval *tv, void *ignored)
1018 1018  
1019 1019 #endif
1020 1020  
  1021 + LIB3270_EXPORT int lib3270_print(H3270 *h)
  1022 + {
  1023 + return -1;
  1024 + }
... ...
src/plugins/hllapi/calls.c
... ... @@ -44,6 +44,7 @@
44 44  
45 45 HMODULE hModule = NULL;
46 46 void * hSession = NULL;
  47 +
47 48  
48 49 static void * (*session_new)(const char *model) = NULL;
49 50 static void (*session_free)(void *h) = NULL;
... ... @@ -67,6 +68,7 @@
67 68 static int (*setcursor)(void *hSession, int baddr) = NULL;
68 69 static int (*emulate_input)(void *hSession, const char *s, int len, int pasting) = NULL;
69 70 static int (*erase_eof)(void *hSession) = NULL;
  71 + static int (*do_print)(void *h) = NULL;
70 72  
71 73 static const struct _entry_point
72 74 {
... ... @@ -95,7 +97,9 @@
95 97 { (void **) &getcursor, (void *) hllapi_pipe_getcursor, "lib3270_get_cursor_address" },
96 98 { (void **) &get_text_at_offset, (void *) hllapi_pipe_get_text, "lib3270_get_text" },
97 99 { (void **) &emulate_input, (void *) hllapi_pipe_emulate_input, "lib3270_emulate_input" },
98   - { (void **) &erase_eof, (void *) hllapi_pipe_erase_eof, "lib3270_eraseeof" },
  100 + { (void **) &erase_eof, (void *) hllapi_pipe_erase_eof, "lib3270_eraseeof" },
  101 + { (void **) &do_print, (void *) hllapi_pipe_print, "lib3270_print" },
  102 +
99 103 { NULL, NULL, NULL }
100 104 };
101 105  
... ... @@ -409,33 +413,22 @@
409 413 return getcursor(hSession)+1;
410 414 }
411 415  
412   - __declspec (dllexport) DWORD __stdcall hllapi_get_screen(WORD pos, LPSTR buffer, WORD len)
413   - {
414   - char *text;
415   -
416   - trace("%s(%d,%d)",__FUNCTION__,pos,len);
417   -
418   - if(len < 0)
419   - len = strlen(buffer);
420   -
421   - if(!(get_text_at_offset && hSession))
422   - return EINVAL;
423   -
424   - if(len > strlen(buffer))
425   - len = strlen(buffer);
426   -
427   - trace("len=%d",len);
428   - text = get_text_at_offset(hSession,pos-1,len);
429   -
430   - trace("text=\n%s\n",text);
431   -
432   - if(!text)
433   - return -1;
434   -
435   - memcpy(buffer,text,len);
436   -
437   - release_memory(text);
438   -
  416 + __declspec (dllexport) DWORD __stdcall hllapi_get_screen(WORD offset, LPSTR buffer, WORD len)
  417 + {
  418 + size_t szBuffer = strlen(buffer);
  419 + char * text;
  420 +
  421 + if(len < szBuffer && len > 0)
  422 + szBuffer = len;
  423 +
  424 + text = hllapi_get_string(offset, szBuffer);
  425 + if(!text)
  426 + return HLLAPI_STATUS_SYSTEM_ERROR;
  427 +
  428 + memcpy(buffer,text,len);
  429 +
  430 + hllapi_free(text);
  431 +
439 432 return 0;
440 433 }
441 434  
... ... @@ -458,8 +451,10 @@
458 451  
459 452 __declspec (dllexport) DWORD __stdcall hllapi_print(void)
460 453 {
461   - #warning Implementar
462   - return -1;
  454 + if(!(do_print && hSession))
  455 + return EINVAL;
  456 +
  457 + return do_print(hSession);
463 458 }
464 459  
465 460 char * hllapi_get_string(int offset, size_t len)
... ...
src/plugins/hllapi/client.h
... ... @@ -59,6 +59,7 @@
59 59 int hllapi_pipe_getcursor(void *h);
60 60 int hllapi_pipe_setcursor(void *h, int baddr);
61 61 int hllapi_pipe_emulate_input(void *hSession, const char *s, int len, int pasting);
  62 + int hllapi_pipe_print(void *h);
62 63  
63 64 char * hllapi_get_string(int offset, size_t len);
64 65 void hllapi_free(void *p);
... ...
src/plugins/hllapi/hllapi.c
... ... @@ -35,6 +35,7 @@
35 35 #include <stdio.h>
36 36 #include <time.h>
37 37 #include <lib3270/log.h>
  38 + #include "client.h"
38 39  
39 40 #undef trace
40 41 #define trace( fmt, ... ) { FILE *out = fopen("c:\\Users\\Perry\\hllapi.log","a"); if(out) { fprintf(out, "%s(%d) " fmt "\n", __FILE__, __LINE__, __VA_ARGS__ ); fclose(out); } }
... ...
src/plugins/hllapi/packets.h
... ... @@ -46,7 +46,8 @@
46 46 HLLAPI_PACKET_SET_CURSOR,
47 47 HLLAPI_PACKET_GET_CURSOR,
48 48 HLLAPI_PACKET_EMULATE_INPUT,
49   - HLLAPI_PACKET_ERASE_EOF,
  49 + HLLAPI_PACKET_ERASE_EOF,
  50 + HLLAPI_PACKET_PRINT,
50 51  
51 52 HLLAPI_PACKET_INVALID
52 53  
... ...
src/plugins/hllapi/pluginmain.c
... ... @@ -195,6 +195,10 @@
195 195 send_result(source,lib3270_enter(lib3270_get_default_session_handle()));
196 196 break;
197 197  
  198 + case HLLAPI_PACKET_PRINT:
  199 + send_result(source,lib3270_print(lib3270_get_default_session_handle()));
  200 + break;
  201 +
198 202 case HLLAPI_PACKET_ERASE_EOF:
199 203 send_result(source,lib3270_eraseeof(lib3270_get_default_session_handle()));
200 204 break;
... ...
src/plugins/hllapi/remote.c
... ... @@ -361,3 +361,12 @@
361 361  
362 362 return response.rc;
363 363 }
  364 +
  365 + int hllapi_pipe_print(void *h)
  366 + {
  367 + static const struct hllapi_packet_query query = { HLLAPI_PACKET_PRINT };
  368 + struct hllapi_packet_result response;
  369 + DWORD cbSize = sizeof(query);
  370 + TransactNamedPipe((HANDLE) h,(LPVOID) &query, cbSize, &response, sizeof(response), &cbSize,NULL);
  371 + return response.rc;
  372 + }
... ...