Commit 1a9aa4275cea4040d2e27b7cf63dff0f9c261dec

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

Trabalhando na interface hllapi

src/include/pw3270/hllapi.h
... ... @@ -58,9 +58,13 @@ extern "C" {
58 58  
59 59  
60 60 /* Result codes */
61   - #define HLLAPI_STATUS_SUCESS 0 /**< Good return code */
62   - #define HLLAPI_STATUS_BAD_PARAMETER 2 /**< Bad parameter or verb not supported */
63   - #define HLLAPI_STATUS_UNAVAILABLE 11 /**< Resource unavailable at this time */
  61 + #define HLLAPI_STATUS_SUCCESS 0 /**< Good return code */
  62 + #define HLLAPI_STATUS_DISCONNECTED 1 /**< The presentation space was not valid or not connected. */
  63 + #define HLLAPI_STATUS_BAD_PARAMETER 2 /**< An incorrect option was specified. */
  64 + #define HLLAPI_STATUS_TIMEOUT 4 /**< Timeout */
  65 + #define HLLAPI_STATUS_KEYBOARD_LOCKED 5 /**< The keyboard is locked. */
  66 + #define HLLAPI_STATUS_UNAVAILABLE 11 /**< Resource unavailable at this time */
  67 + #define HLLAPI_STATUS_SYSTEM_ERROR 9 /**< A system error occurred */
64 68  
65 69  
66 70 #ifdef _WIN32
... ...
src/plugins/hllapi/hllapi.c
... ... @@ -32,7 +32,8 @@
32 32 #include <string.h>
33 33 #include <errno.h>
34 34 #include <pw3270/hllapi.h>
35   - #include <stdio.h>
  35 + #include <stdio.h>
  36 + #include <time.h>
36 37 #include <lib3270/log.h>
37 38  
38 39 #undef trace
... ... @@ -44,6 +45,9 @@
44 45 static int disconnect_ps(char *buffer, unsigned short *length, unsigned short *rc);
45 46 static int get_library_revision(char *buffer, unsigned short *length, unsigned short *rc);
46 47 static int copy_ps_to_str(char *buffer, unsigned short *length, unsigned short *rc);
  48 + static int search_ps(char *buffer, unsigned short *length, unsigned short *rc);
  49 + static int copy_ps(char *buffer, unsigned short *length, unsigned short *rc);
  50 + static int wait_system(char *buffer, unsigned short *length, unsigned short *rc);
47 51  
48 52 static int get_cursor_position(char *buffer, unsigned short *length, unsigned short *rc);
49 53 static int set_cursor_position(char *buffer, unsigned short *length, unsigned short *rc);
... ... @@ -66,9 +70,9 @@
66 70 { HLLAPI_CMD_SETCURSOR, set_cursor_position },
67 71 { HLLAPI_CMD_COPYPSTOSTR, copy_ps_to_str },
68 72 { HLLAPI_CMD_INPUTSTRING, input_string },
69   - { HLLAPI_CMD_WAIT, invalid_request },
70   - { HLLAPI_CMD_COPYPS, invalid_request },
71   - { HLLAPI_CMD_SEARCHPS, invalid_request },
  73 + { HLLAPI_CMD_WAIT, wait_system },
  74 + { HLLAPI_CMD_COPYPS, copy_ps },
  75 + { HLLAPI_CMD_SEARCHPS, search_ps },
72 76 { HLLAPI_CMD_COPYSTRTOPS, invalid_request },
73 77 { HLLAPI_CMD_SENDFILE, invalid_request },
74 78 { HLLAPI_CMD_RECEIVEFILE, invalid_request },
... ... @@ -126,7 +130,7 @@ static int connect_ps(char *buffer, unsigned short *length, unsigned short *rc)
126 130 }
127 131  
128 132 if(hllapi_init(buffer) == 0)
129   - *rc = HLLAPI_STATUS_SUCESS;
  133 + *rc = HLLAPI_STATUS_SUCCESS;
130 134 else
131 135 *rc = HLLAPI_STATUS_UNAVAILABLE;
132 136  
... ... @@ -289,3 +293,102 @@ static int input_string(char *input, unsigned short *length, unsigned short *rc)
289 293 return 0;
290 294 }
291 295  
  296 +static int search_ps(char *buffer, unsigned short *length, unsigned short *ps)
  297 +{
  298 + /*
  299 + * Data String Target string for search.
  300 + * Length Length of the target data string. Overridden in EOT mode.
  301 + * PS Position Position within the host presentation space where the search is to begin (SRCHFRWD option) or to end
  302 + * (SRCHBKWD option). Overridden in SRCHALL (default) mode.
  303 + *
  304 + * Return in *ps:
  305 + *
  306 + * = 0 The string was not found.
  307 + * > 0 The string was found at the indicated host presentation space position.
  308 + *
  309 + * Return code:
  310 + *
  311 + * 0 The Search Presentation Space function was successful.
  312 + * 1 Your program is not connected to a host session.
  313 + * 2 An error was made in specifying parameters.
  314 + * 7 The host presentation space position is not valid.
  315 + * 9 A system error was encountered.
  316 + * 24 The search string was not found.
  317 + *
  318 + */
  319 + size_t szBuffer = strlen(buffer);
  320 +
  321 + if(*length < szBuffer)
  322 + szBuffer = *length;
  323 +
  324 +
  325 + #warning Implementar
  326 +
  327 + return HLLAPI_STATUS_SYSTEM_ERROR;
  328 +}
  329 +
  330 +static int copy_ps(char *buffer, unsigned short *length, unsigned short *rc)
  331 +{
  332 + /*
  333 + * Data String Preallocated target string the size of your host presentation space. This can vary depending on how your host presentation space is configured. When the Set Session Parameters (9) function with the EAB option is issued, the length of the data string must be at least twice the length of the presentation space.
  334 + * DBCS Only: When the EAD option is specified, the length of the data string must be at least three times the length of the presentation space. When both the EAB and EAD options are specified, the length of the data string must be at least four times the length of the presentation space.
  335 + *
  336 + * Length NA (the length of the host presentation space is implied).
  337 + * PS Position NA.
  338 + *
  339 + *
  340 + */
  341 +
  342 + #warning Implementar
  343 +
  344 + return HLLAPI_STATUS_SYSTEM_ERROR;
  345 +}
  346 +
  347 +static int wait_system(char *buffer, unsigned short *length, unsigned short *rc)
  348 +{
  349 + /*
  350 + * Checks the status of the host-connected presentation space. If the session is
  351 + * waiting for a host response (indicated by XCLOCK (X []) or XSYSTEM), the Wait
  352 + * function causes HLLAPI to wait up to 1 minute to see if the condition clears.
  353 + *
  354 + */
  355 +
  356 + /*
  357 + * Return Code Definition
  358 + *
  359 + * 0 The keyboard is unlocked and ready for input.
  360 + * 1 Your application program is not connected to a valid session.
  361 + * 4 Timeout while still in XCLOCK (X []) or XSYSTEM.
  362 + * 5 The keyboard is locked.
  363 + * 9 A system error was encountered.
  364 + *
  365 + */
  366 + time_t end = time(0) + 3600;
  367 +
  368 + while(time(0) < end)
  369 + {
  370 + switch(hllapi_get_message_id())
  371 + {
  372 + case LIB3270_MESSAGE_NONE: /* 0 - No message */
  373 + return HLLAPI_STATUS_SUCCESS;
  374 +
  375 + case LIB3270_MESSAGE_DISCONNECTED: /* 4 - Disconnected from host */
  376 + return HLLAPI_STATUS_DISCONNECTED;
  377 +
  378 + case LIB3270_MESSAGE_MINUS:
  379 + case LIB3270_MESSAGE_PROTECTED:
  380 + case LIB3270_MESSAGE_NUMERIC:
  381 + case LIB3270_MESSAGE_OVERFLOW:
  382 + case LIB3270_MESSAGE_INHIBIT:
  383 + case LIB3270_MESSAGE_KYBDLOCK:
  384 + return HLLAPI_STATUS_KEYBOARD_LOCKED;
  385 +
  386 + }
  387 +
  388 + if(hllapi_wait(1))
  389 + return HLLAPI_STATUS_SYSTEM_ERROR;
  390 +
  391 + }
  392 +
  393 + return HLLAPI_STATUS_TIMEOUT;
  394 +}
... ...