Commit 7345680734dc36ec3f33f8ebe671828c42c5515e

Authored by perry.werneck@gmail.com
1 parent 9892e254

Remodelando interface hllapi para ficar mais compatível com scripts antigos

src/include/pw3270/hllapi.h
@@ -38,8 +38,9 @@ @@ -38,8 +38,9 @@
38 extern "C" { 38 extern "C" {
39 #endif 39 #endif
40 40
41 - #define HLLAPI_MAXLENGTH 4096 41 + #define HLLAPI_MAXLENGTH 4096
42 42
  43 + /* Function codes */
43 #define HLLAPI_CMD_CONNECTPS 1 /**< connect presentation space */ 44 #define HLLAPI_CMD_CONNECTPS 1 /**< connect presentation space */
44 #define HLLAPI_CMD_DISCONNECTPS 2 /**< disconnect presentation space */ 45 #define HLLAPI_CMD_DISCONNECTPS 2 /**< disconnect presentation space */
45 #define HLLAPI_CMD_INPUTSTRING 3 /**< send string */ 46 #define HLLAPI_CMD_INPUTSTRING 3 /**< send string */
@@ -54,6 +55,14 @@ extern &quot;C&quot; { @@ -54,6 +55,14 @@ extern &quot;C&quot; {
54 #define HLLAPI_CMD_RECEIVEFILE 91 /**< Receive a file from the host */ 55 #define HLLAPI_CMD_RECEIVEFILE 91 /**< Receive a file from the host */
55 56
56 #define HLLAPI_CMD_GETREVISION 2000 /**< Get lib3270 revision */ 57 #define HLLAPI_CMD_GETREVISION 2000 /**< Get lib3270 revision */
  58 +
  59 +
  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 */
  64 +
  65 +
57 66
58 typedef enum _hllapi_packet 67 typedef enum _hllapi_packet
59 { 68 {
src/plugins/remotectl/hllapi.c
@@ -35,9 +35,24 @@ @@ -35,9 +35,24 @@
35 #include <stdio.h> 35 #include <stdio.h>
36 #include <lib3270/log.h> 36 #include <lib3270/log.h>
37 37
  38 +/*--[ Prototipes ]-----------------------------------------------------------------------------------*/
  39 +
  40 + static int connect_ps(char *buffer, unsigned short *length, unsigned short *rc);
  41 + static int disconnect_ps(char *buffer, unsigned short *length, unsigned short *rc);
  42 + static int get_library_revision(char *buffer, unsigned short *length, unsigned short *rc);
  43 +
38 /*--[ Globals ]--------------------------------------------------------------------------------------*/ 44 /*--[ Globals ]--------------------------------------------------------------------------------------*/
39 45
40 -// static HANDLE hPipe = INVALID_HANDLE_VALUE; 46 + static const struct _hllapi_call
  47 + {
  48 + unsigned long func;
  49 + int (*exec)(char *buffer, unsigned short *length, unsigned short *rc);
  50 + } hllapi_call[] =
  51 + {
  52 + { HLLAPI_CMD_CONNECTPS, connect_ps },
  53 + { HLLAPI_CMD_DISCONNECTPS, disconnect_ps },
  54 + { HLLAPI_CMD_GETREVISION, get_library_revision },
  55 + };
41 56
42 /*--[ Implement ]------------------------------------------------------------------------------------*/ 57 /*--[ Implement ]------------------------------------------------------------------------------------*/
43 58
@@ -46,56 +61,41 @@ @@ -46,56 +61,41 @@
46 #else 61 #else
47 LIB3270_EXPORT int hllapi(const unsigned long *func, char *buffer, unsigned short *length, unsigned short *rc) 62 LIB3270_EXPORT int hllapi(const unsigned long *func, char *buffer, unsigned short *length, unsigned short *rc)
48 #endif // _WIN32 63 #endif // _WIN32
49 -{  
50 - switch(*func)  
51 - {  
52 - case HLLAPI_CMD_CONNECTPS:  
53 - break;  
54 -  
55 - case HLLAPI_CMD_DISCONNECTPS:  
56 - break;  
57 -  
58 - case HLLAPI_CMD_INPUTSTRING:  
59 - break;  
60 -  
61 - case HLLAPI_CMD_WAIT:  
62 - break;  
63 -  
64 - case HLLAPI_CMD_COPYPS:  
65 - break;  
66 -  
67 - case HLLAPI_CMD_SEARCHPS:  
68 - break;  
69 -  
70 - case HLLAPI_CMD_QUERYCURSOR:  
71 - break;  
72 -  
73 - case HLLAPI_CMD_COPYPSTOSTR:  
74 - break;  
75 -  
76 - case HLLAPI_CMD_COPYSTRTOPS:  
77 - break;  
78 -  
79 - case HLLAPI_CMD_SETCURSOR:  
80 - break;  
81 -  
82 - case HLLAPI_CMD_SENDFILE:  
83 - break;  
84 -  
85 - case HLLAPI_CMD_RECEIVEFILE:  
86 - break;  
87 -  
88 - case HLLAPI_CMD_GETREVISION:  
89 - break;  
90 -  
91 - default:  
92 - *rc = EINVAL;  
93 - return EINVAL; 64 +{
  65 + int f;
  66 +
  67 + for(f=0;f< (sizeof (hllapi_call) / sizeof ((hllapi_call)[0])));f++)
  68 + {
  69 + if(hllapi_call[f].func == *func)
  70 + return hllapi_call[f].exec(buffer,length,rc);
94 } 71 }
95 72
  73 + *rc = HLLAPI_STATUS_BAD_PARAMETER;
96 74
97 - return 0; 75 + return *rc;
98 } 76 }
  77 +
  78 +static int connect_ps(char *buffer, unsigned short *length, unsigned short *rc)
  79 +{
  80 + if(hllapi_init(buffer) == 0)
  81 + *rc = HLLAPI_STATUS_SUCESS;
  82 + else
  83 + *rc = HLLAPI_STATUS_UNAVAILABLE;
  84 + return 0;
  85 +}
  86 +
  87 +static int disconnect_ps(char *buffer, unsigned short *length, unsigned short *rc)
  88 +{
  89 + *rc = hllapi_deinit();
  90 + return 0;
  91 +}
  92 +
  93 +static int get_library_revision(char *buffer, unsigned short *length, unsigned short *rc)
  94 +{
  95 + *rc = hllapi_get_revision();
  96 + return 0;
  97 +}
  98 +
99 99
100 /* 100 /*
101 static int cmd_connect_ps(const char *name) 101 static int cmd_connect_ps(const char *name)