Commit 11f040b864a9c4bff8ae881beb7e84d53f4d7050
1 parent
b2a6f0d2
Exists in
master
and in
5 other branches
Melhorando tratamento de erros no hllapi
Showing
5 changed files
with
53 additions
and
20 deletions
Show diff stats
src/include/pw3270/hllapi.h
... | ... | @@ -42,7 +42,7 @@ extern "C" { |
42 | 42 | #define HLLAPI_MAXLENGTH 32768 |
43 | 43 | |
44 | 44 | #define HLLAPI_CMD_CONNECTPS 1 /**< connect presentation space */ |
45 | - #define HLLAPI_CMD_SENDSTRING 3 /**< send string */ | |
45 | + #define HLLAPI_CMD_INPUTSTRING 3 /**< send string */ | |
46 | 46 | #define HLLAPI_CMD_COPYPSTOSTR 8 /**< copy presentation space to string */ |
47 | 47 | #define HLLAPI_CMD_SETCURSOR 40 /**< set cursor */ |
48 | 48 | #define HLLAPI_CMD_GETREVISION 2000 /**< Get lib3270 revision */ | ... | ... |
src/plugins/remotectl/hllapi.c
... | ... | @@ -63,6 +63,8 @@ |
63 | 63 | DWORD cbSize = sizeof(HLLAPI_DATA) + length; |
64 | 64 | HLLAPI_DATA *data = malloc(cbSize+1); |
65 | 65 | |
66 | + memset(buffer,0,HLLAPI_MAXLENGTH); | |
67 | + | |
66 | 68 | data->id = HLLAPI_REQUEST_ID; |
67 | 69 | data->func = func; |
68 | 70 | data->rc = *rc; |
... | ... | @@ -71,15 +73,18 @@ |
71 | 73 | if(string && length > 0) |
72 | 74 | memcpy(data->string,string,length); |
73 | 75 | |
74 | - if(!CallNamedPipe(PipeName,(LPVOID)data,cbSize,buffer,HLLAPI_MAXLENGTH,&cbSize,NMPWAIT_USE_DEFAULT_WAIT)) | |
76 | + memset(buffer,0,HLLAPI_MAXLENGTH); if(!CallNamedPipe(PipeName,(LPVOID)data,cbSize,buffer,HLLAPI_MAXLENGTH,&cbSize,NMPWAIT_USE_DEFAULT_WAIT)) | |
75 | 77 | { |
76 | 78 | result = GetLastError(); |
77 | 79 | } |
78 | 80 | else |
79 | 81 | { |
80 | 82 | int sz = length < buffer->len ? length : buffer->len; |
83 | + | |
81 | 84 | *rc = buffer->rc; |
82 | 85 | |
86 | + trace("%s: Query rc=%d",__FUNCTION__,(int) buffer->rc); | |
87 | + | |
83 | 88 | if(string && sz > 0) |
84 | 89 | memcpy(string,buffer->string,sz); |
85 | 90 | |
... | ... | @@ -120,7 +125,7 @@ |
120 | 125 | default: |
121 | 126 | if(!session_name) |
122 | 127 | { |
123 | - if(set_session_name("pw3270")) | |
128 | + if(set_session_name("pw3270A")) | |
124 | 129 | return ENOENT; |
125 | 130 | } |
126 | 131 | result = run_query(func, str, length, rc); | ... | ... |
src/plugins/remotectl/pipesource.c
... | ... | @@ -74,13 +74,13 @@ static void wait_for_client(pipe_source *source) |
74 | 74 | { |
75 | 75 | // The overlapped connection in progress. |
76 | 76 | case ERROR_IO_PENDING: |
77 | - trace("%s: ERROR_IO_PENDING",__FUNCTION__); | |
77 | + // trace("%s: ERROR_IO_PENDING",__FUNCTION__); | |
78 | 78 | source->state = PIPE_STATE_WAITING; |
79 | 79 | break; |
80 | 80 | |
81 | 81 | // Client is already connected, so signal an event. |
82 | 82 | case ERROR_PIPE_CONNECTED: |
83 | - trace("%s: ERROR_PIPE_CONNECTED",__FUNCTION__); | |
83 | + // trace("%s: ERROR_PIPE_CONNECTED",__FUNCTION__); | |
84 | 84 | if(SetEvent(source->overlap.hEvent)) |
85 | 85 | break; |
86 | 86 | |
... | ... | @@ -108,7 +108,7 @@ static void wait_for_client(pipe_source *source) |
108 | 108 | */ |
109 | 109 | if(WaitForSingleObject(((pipe_source *) source)->overlap.hEvent,0) == WAIT_OBJECT_0) |
110 | 110 | { |
111 | - trace("%s: source=%p",__FUNCTION__,source); | |
111 | + // trace("%s: source=%p",__FUNCTION__,source); | |
112 | 112 | return TRUE; |
113 | 113 | } |
114 | 114 | |
... | ... | @@ -142,6 +142,9 @@ static void wait_for_client(pipe_source *source) |
142 | 142 | DWORD wrote; |
143 | 143 | data->rc = run_hllapi(data->func,data->string,data->len,data->rc); |
144 | 144 | wrote = sizeof(HLLAPI_DATA)+data->len; |
145 | + | |
146 | + trace("%s rc=%d",__FUNCTION__,(int) data->rc); | |
147 | + | |
145 | 148 | WriteFile(source->hPipe,data,wrote,&wrote,NULL); |
146 | 149 | } |
147 | 150 | |
... | ... | @@ -157,18 +160,21 @@ static void wait_for_client(pipe_source *source) |
157 | 160 | // The read operation is still pending. |
158 | 161 | switch(GetLastError()) |
159 | 162 | { |
163 | + case 0: | |
164 | + break; | |
165 | + | |
160 | 166 | case ERROR_IO_PENDING: |
161 | - trace("%s: PIPE_STATE_PENDING_READ",__FUNCTION__); | |
167 | + // trace("%s: PIPE_STATE_PENDING_READ",__FUNCTION__); | |
162 | 168 | source->state = PIPE_STATE_PENDING_READ; |
163 | 169 | break; |
164 | 170 | |
165 | 171 | case ERROR_PIPE_LISTENING: |
166 | - trace("%s: ERROR_PIPE_LISTENING",__FUNCTION__); | |
172 | + // trace("%s: ERROR_PIPE_LISTENING",__FUNCTION__); | |
167 | 173 | source->state = PIPE_STATE_READ; |
168 | 174 | break; |
169 | 175 | |
170 | 176 | case ERROR_BROKEN_PIPE: |
171 | - trace("%s: ERROR_BROKEN_PIPE",__FUNCTION__); | |
177 | + // trace("%s: ERROR_BROKEN_PIPE",__FUNCTION__); | |
172 | 178 | if(!DisconnectNamedPipe(source->hPipe)) |
173 | 179 | popup_lasterror("%s",_( "Error in DisconnectNamedPipe" )); |
174 | 180 | else |
... | ... | @@ -176,7 +182,7 @@ static void wait_for_client(pipe_source *source) |
176 | 182 | break; |
177 | 183 | |
178 | 184 | case ERROR_PIPE_NOT_CONNECTED: |
179 | - trace("%s: ERROR_PIPE_NOT_CONNECTED",__FUNCTION__); | |
185 | + // trace("%s: ERROR_PIPE_NOT_CONNECTED",__FUNCTION__); | |
180 | 186 | break; |
181 | 187 | |
182 | 188 | default: |
... | ... | @@ -203,14 +209,14 @@ static void wait_for_client(pipe_source *source) |
203 | 209 | |
204 | 210 | fSuccess = GetOverlappedResult(((pipe_source *) source)->hPipe,&((pipe_source *) source)->overlap,&cbRead,FALSE ); |
205 | 211 | |
206 | - trace("%s: source=%p data=%p Result=%s cbRead=%d",__FUNCTION__,source,data,fSuccess ? "Success" : "Unsuccess",(int) cbRead); | |
212 | + // trace("%s: source=%p data=%p Result=%s cbRead=%d",__FUNCTION__,source,data,fSuccess ? "Success" : "Unsuccess",(int) cbRead); | |
207 | 213 | |
208 | 214 | switch(((pipe_source *) source)->state) |
209 | 215 | { |
210 | 216 | case PIPE_STATE_WAITING: |
211 | 217 | if(fSuccess) |
212 | 218 | { |
213 | - trace("Pipe connected (cbRet=%d)",(int) cbRead); | |
219 | + // trace("Pipe connected (cbRet=%d)",(int) cbRead); | |
214 | 220 | ((pipe_source *) source)->state = PIPE_STATE_READ; |
215 | 221 | } |
216 | 222 | else |
... | ... | @@ -220,7 +226,7 @@ static void wait_for_client(pipe_source *source) |
220 | 226 | break; |
221 | 227 | |
222 | 228 | case PIPE_STATE_READ: |
223 | - trace("Reading pipe (cbRead=%d)",(int) cbRead); | |
229 | + // trace("Reading pipe (cbRead=%d)",(int) cbRead); | |
224 | 230 | read_input_pipe( (pipe_source *) source); |
225 | 231 | break; |
226 | 232 | |
... | ... | @@ -230,10 +236,10 @@ static void wait_for_client(pipe_source *source) |
230 | 236 | ((pipe_source *) source)->state = PIPE_STATE_READ; |
231 | 237 | break; |
232 | 238 | |
233 | -#ifdef DEBUG | |
234 | - default: | |
235 | - trace("%s: source=%p data=%p Unexpected mode %d",__FUNCTION__,source,data,((pipe_source *) source)->state); | |
236 | -#endif | |
239 | +//#ifdef DEBUG | |
240 | +// default: | |
241 | +// trace("%s: source=%p data=%p Unexpected mode %d",__FUNCTION__,source,data,((pipe_source *) source)->state); | |
242 | +//#endif | |
237 | 243 | } |
238 | 244 | |
239 | 245 | return TRUE; |
... | ... | @@ -241,7 +247,7 @@ static void wait_for_client(pipe_source *source) |
241 | 247 | |
242 | 248 | static void IO_finalize(GSource *source) |
243 | 249 | { |
244 | - trace("%s: source=%p",__FUNCTION__,source); | |
250 | +// trace("%s: source=%p",__FUNCTION__,source); | |
245 | 251 | |
246 | 252 | if( ((pipe_source *) source)->hPipe != INVALID_HANDLE_VALUE) |
247 | 253 | { |
... | ... | @@ -253,7 +259,7 @@ static void wait_for_client(pipe_source *source) |
253 | 259 | |
254 | 260 | static gboolean IO_closure(gpointer data) |
255 | 261 | { |
256 | - trace("%s: data=%p",__FUNCTION__,data); | |
262 | +// trace("%s: data=%p",__FUNCTION__,data); | |
257 | 263 | return 0; |
258 | 264 | } |
259 | 265 | ... | ... |
src/plugins/remotectl/remotectl.c
... | ... | @@ -150,6 +150,18 @@ |
150 | 150 | return 0; |
151 | 151 | } |
152 | 152 | |
153 | + static int cmd_sendstring(unsigned short rc, char *string, unsigned short length) | |
154 | + { | |
155 | + H3270 *hSession = lib3270_get_default_session_handle(); | |
156 | + | |
157 | + if(!lib3270_connected(hSession)) | |
158 | + return ENOTCONN; | |
159 | + | |
160 | + #warning Converter formato da string e incluir no buffer | |
161 | + | |
162 | + return 0; | |
163 | + } | |
164 | + | |
153 | 165 | int run_hllapi(unsigned long function, char *string, unsigned short length, unsigned short rc) |
154 | 166 | { |
155 | 167 | static const struct _cmd |
... | ... | @@ -159,16 +171,20 @@ |
159 | 171 | } cmd[] = |
160 | 172 | { |
161 | 173 | { HLLAPI_CMD_SETCURSOR, cmd_setcursor }, |
174 | + { HLLAPI_CMD_INPUTSTRING, cmd_sendstring }, | |
162 | 175 | { HLLAPI_CMD_GETREVISION, cmd_getrevision } |
163 | 176 | }; |
164 | 177 | int f; |
165 | 178 | |
179 | + trace("HLLAPI function %d",(int) function); | |
180 | + | |
166 | 181 | for(f=0;f<G_N_ELEMENTS(cmd);f++) |
167 | 182 | { |
168 | 183 | if(cmd[f].function == function) |
169 | 184 | return cmd[f].exec(rc,string,length); |
170 | 185 | } |
171 | 186 | |
187 | + g_warning("Unexpected HLLAPI function %d",(int) function); | |
172 | 188 | return EINVAL; |
173 | 189 | } |
174 | 190 | ... | ... |
src/plugins/remotectl/testprogram.c
... | ... | @@ -39,12 +39,18 @@ |
39 | 39 | unsigned short rc; |
40 | 40 | |
41 | 41 | // Set session name |
42 | - strcpy(buffer,"pw3270"); | |
42 | + strcpy(buffer,"pw3270A"); | |
43 | 43 | printf("ConnectPS exits with %d\n[%s]\n",hllapi(HLLAPI_CMD_CONNECTPS,buffer,1024,&rc),buffer); |
44 | 44 | |
45 | 45 | // Test for GetRevision call |
46 | 46 | *buffer = 0; |
47 | 47 | printf("GetRevision exits with %d\n[%s]\n",hllapi(HLLAPI_CMD_GETREVISION,buffer,1024,&rc),buffer); |
48 | + printf("query rc=%d\n\n",rc); | |
49 | + | |
50 | + // Test for string input | |
51 | + strcpy(buffer,"test"); | |
52 | + printf("InputString exits with %d\n[%s]\n",hllapi(HLLAPI_CMD_INPUTSTRING,buffer,1024,&rc),buffer); | |
53 | + printf("query rc=%d\n\n",rc); | |
48 | 54 | |
49 | 55 | return 0; |
50 | 56 | } | ... | ... |