Commit 11f040b864a9c4bff8ae881beb7e84d53f4d7050

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

Melhorando tratamento de erros no hllapi

src/include/pw3270/hllapi.h
@@ -42,7 +42,7 @@ extern "C" { @@ -42,7 +42,7 @@ extern "C" {
42 #define HLLAPI_MAXLENGTH 32768 42 #define HLLAPI_MAXLENGTH 32768
43 43
44 #define HLLAPI_CMD_CONNECTPS 1 /**< connect presentation space */ 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 #define HLLAPI_CMD_COPYPSTOSTR 8 /**< copy presentation space to string */ 46 #define HLLAPI_CMD_COPYPSTOSTR 8 /**< copy presentation space to string */
47 #define HLLAPI_CMD_SETCURSOR 40 /**< set cursor */ 47 #define HLLAPI_CMD_SETCURSOR 40 /**< set cursor */
48 #define HLLAPI_CMD_GETREVISION 2000 /**< Get lib3270 revision */ 48 #define HLLAPI_CMD_GETREVISION 2000 /**< Get lib3270 revision */
src/plugins/remotectl/hllapi.c
@@ -63,6 +63,8 @@ @@ -63,6 +63,8 @@
63 DWORD cbSize = sizeof(HLLAPI_DATA) + length; 63 DWORD cbSize = sizeof(HLLAPI_DATA) + length;
64 HLLAPI_DATA *data = malloc(cbSize+1); 64 HLLAPI_DATA *data = malloc(cbSize+1);
65 65
  66 + memset(buffer,0,HLLAPI_MAXLENGTH);
  67 +
66 data->id = HLLAPI_REQUEST_ID; 68 data->id = HLLAPI_REQUEST_ID;
67 data->func = func; 69 data->func = func;
68 data->rc = *rc; 70 data->rc = *rc;
@@ -71,15 +73,18 @@ @@ -71,15 +73,18 @@
71 if(string && length > 0) 73 if(string && length > 0)
72 memcpy(data->string,string,length); 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 result = GetLastError(); 78 result = GetLastError();
77 } 79 }
78 else 80 else
79 { 81 {
80 int sz = length < buffer->len ? length : buffer->len; 82 int sz = length < buffer->len ? length : buffer->len;
  83 +
81 *rc = buffer->rc; 84 *rc = buffer->rc;
82 85
  86 + trace("%s: Query rc=%d",__FUNCTION__,(int) buffer->rc);
  87 +
83 if(string && sz > 0) 88 if(string && sz > 0)
84 memcpy(string,buffer->string,sz); 89 memcpy(string,buffer->string,sz);
85 90
@@ -120,7 +125,7 @@ @@ -120,7 +125,7 @@
120 default: 125 default:
121 if(!session_name) 126 if(!session_name)
122 { 127 {
123 - if(set_session_name("pw3270")) 128 + if(set_session_name("pw3270A"))
124 return ENOENT; 129 return ENOENT;
125 } 130 }
126 result = run_query(func, str, length, rc); 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,13 +74,13 @@ static void wait_for_client(pipe_source *source)
74 { 74 {
75 // The overlapped connection in progress. 75 // The overlapped connection in progress.
76 case ERROR_IO_PENDING: 76 case ERROR_IO_PENDING:
77 - trace("%s: ERROR_IO_PENDING",__FUNCTION__); 77 + // trace("%s: ERROR_IO_PENDING",__FUNCTION__);
78 source->state = PIPE_STATE_WAITING; 78 source->state = PIPE_STATE_WAITING;
79 break; 79 break;
80 80
81 // Client is already connected, so signal an event. 81 // Client is already connected, so signal an event.
82 case ERROR_PIPE_CONNECTED: 82 case ERROR_PIPE_CONNECTED:
83 - trace("%s: ERROR_PIPE_CONNECTED",__FUNCTION__); 83 + // trace("%s: ERROR_PIPE_CONNECTED",__FUNCTION__);
84 if(SetEvent(source->overlap.hEvent)) 84 if(SetEvent(source->overlap.hEvent))
85 break; 85 break;
86 86
@@ -108,7 +108,7 @@ static void wait_for_client(pipe_source *source) @@ -108,7 +108,7 @@ static void wait_for_client(pipe_source *source)
108 */ 108 */
109 if(WaitForSingleObject(((pipe_source *) source)->overlap.hEvent,0) == WAIT_OBJECT_0) 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 return TRUE; 112 return TRUE;
113 } 113 }
114 114
@@ -142,6 +142,9 @@ static void wait_for_client(pipe_source *source) @@ -142,6 +142,9 @@ static void wait_for_client(pipe_source *source)
142 DWORD wrote; 142 DWORD wrote;
143 data->rc = run_hllapi(data->func,data->string,data->len,data->rc); 143 data->rc = run_hllapi(data->func,data->string,data->len,data->rc);
144 wrote = sizeof(HLLAPI_DATA)+data->len; 144 wrote = sizeof(HLLAPI_DATA)+data->len;
  145 +
  146 + trace("%s rc=%d",__FUNCTION__,(int) data->rc);
  147 +
145 WriteFile(source->hPipe,data,wrote,&wrote,NULL); 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,18 +160,21 @@ static void wait_for_client(pipe_source *source)
157 // The read operation is still pending. 160 // The read operation is still pending.
158 switch(GetLastError()) 161 switch(GetLastError())
159 { 162 {
  163 + case 0:
  164 + break;
  165 +
160 case ERROR_IO_PENDING: 166 case ERROR_IO_PENDING:
161 - trace("%s: PIPE_STATE_PENDING_READ",__FUNCTION__); 167 + // trace("%s: PIPE_STATE_PENDING_READ",__FUNCTION__);
162 source->state = PIPE_STATE_PENDING_READ; 168 source->state = PIPE_STATE_PENDING_READ;
163 break; 169 break;
164 170
165 case ERROR_PIPE_LISTENING: 171 case ERROR_PIPE_LISTENING:
166 - trace("%s: ERROR_PIPE_LISTENING",__FUNCTION__); 172 + // trace("%s: ERROR_PIPE_LISTENING",__FUNCTION__);
167 source->state = PIPE_STATE_READ; 173 source->state = PIPE_STATE_READ;
168 break; 174 break;
169 175
170 case ERROR_BROKEN_PIPE: 176 case ERROR_BROKEN_PIPE:
171 - trace("%s: ERROR_BROKEN_PIPE",__FUNCTION__); 177 + // trace("%s: ERROR_BROKEN_PIPE",__FUNCTION__);
172 if(!DisconnectNamedPipe(source->hPipe)) 178 if(!DisconnectNamedPipe(source->hPipe))
173 popup_lasterror("%s",_( "Error in DisconnectNamedPipe" )); 179 popup_lasterror("%s",_( "Error in DisconnectNamedPipe" ));
174 else 180 else
@@ -176,7 +182,7 @@ static void wait_for_client(pipe_source *source) @@ -176,7 +182,7 @@ static void wait_for_client(pipe_source *source)
176 break; 182 break;
177 183
178 case ERROR_PIPE_NOT_CONNECTED: 184 case ERROR_PIPE_NOT_CONNECTED:
179 - trace("%s: ERROR_PIPE_NOT_CONNECTED",__FUNCTION__); 185 + // trace("%s: ERROR_PIPE_NOT_CONNECTED",__FUNCTION__);
180 break; 186 break;
181 187
182 default: 188 default:
@@ -203,14 +209,14 @@ static void wait_for_client(pipe_source *source) @@ -203,14 +209,14 @@ static void wait_for_client(pipe_source *source)
203 209
204 fSuccess = GetOverlappedResult(((pipe_source *) source)->hPipe,&((pipe_source *) source)->overlap,&cbRead,FALSE ); 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 switch(((pipe_source *) source)->state) 214 switch(((pipe_source *) source)->state)
209 { 215 {
210 case PIPE_STATE_WAITING: 216 case PIPE_STATE_WAITING:
211 if(fSuccess) 217 if(fSuccess)
212 { 218 {
213 - trace("Pipe connected (cbRet=%d)",(int) cbRead); 219 + // trace("Pipe connected (cbRet=%d)",(int) cbRead);
214 ((pipe_source *) source)->state = PIPE_STATE_READ; 220 ((pipe_source *) source)->state = PIPE_STATE_READ;
215 } 221 }
216 else 222 else
@@ -220,7 +226,7 @@ static void wait_for_client(pipe_source *source) @@ -220,7 +226,7 @@ static void wait_for_client(pipe_source *source)
220 break; 226 break;
221 227
222 case PIPE_STATE_READ: 228 case PIPE_STATE_READ:
223 - trace("Reading pipe (cbRead=%d)",(int) cbRead); 229 + // trace("Reading pipe (cbRead=%d)",(int) cbRead);
224 read_input_pipe( (pipe_source *) source); 230 read_input_pipe( (pipe_source *) source);
225 break; 231 break;
226 232
@@ -230,10 +236,10 @@ static void wait_for_client(pipe_source *source) @@ -230,10 +236,10 @@ static void wait_for_client(pipe_source *source)
230 ((pipe_source *) source)->state = PIPE_STATE_READ; 236 ((pipe_source *) source)->state = PIPE_STATE_READ;
231 break; 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 return TRUE; 245 return TRUE;
@@ -241,7 +247,7 @@ static void wait_for_client(pipe_source *source) @@ -241,7 +247,7 @@ static void wait_for_client(pipe_source *source)
241 247
242 static void IO_finalize(GSource *source) 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 if( ((pipe_source *) source)->hPipe != INVALID_HANDLE_VALUE) 252 if( ((pipe_source *) source)->hPipe != INVALID_HANDLE_VALUE)
247 { 253 {
@@ -253,7 +259,7 @@ static void wait_for_client(pipe_source *source) @@ -253,7 +259,7 @@ static void wait_for_client(pipe_source *source)
253 259
254 static gboolean IO_closure(gpointer data) 260 static gboolean IO_closure(gpointer data)
255 { 261 {
256 - trace("%s: data=%p",__FUNCTION__,data); 262 +// trace("%s: data=%p",__FUNCTION__,data);
257 return 0; 263 return 0;
258 } 264 }
259 265
src/plugins/remotectl/remotectl.c
@@ -150,6 +150,18 @@ @@ -150,6 +150,18 @@
150 return 0; 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 int run_hllapi(unsigned long function, char *string, unsigned short length, unsigned short rc) 165 int run_hllapi(unsigned long function, char *string, unsigned short length, unsigned short rc)
154 { 166 {
155 static const struct _cmd 167 static const struct _cmd
@@ -159,16 +171,20 @@ @@ -159,16 +171,20 @@
159 } cmd[] = 171 } cmd[] =
160 { 172 {
161 { HLLAPI_CMD_SETCURSOR, cmd_setcursor }, 173 { HLLAPI_CMD_SETCURSOR, cmd_setcursor },
  174 + { HLLAPI_CMD_INPUTSTRING, cmd_sendstring },
162 { HLLAPI_CMD_GETREVISION, cmd_getrevision } 175 { HLLAPI_CMD_GETREVISION, cmd_getrevision }
163 }; 176 };
164 int f; 177 int f;
165 178
  179 + trace("HLLAPI function %d",(int) function);
  180 +
166 for(f=0;f<G_N_ELEMENTS(cmd);f++) 181 for(f=0;f<G_N_ELEMENTS(cmd);f++)
167 { 182 {
168 if(cmd[f].function == function) 183 if(cmd[f].function == function)
169 return cmd[f].exec(rc,string,length); 184 return cmd[f].exec(rc,string,length);
170 } 185 }
171 186
  187 + g_warning("Unexpected HLLAPI function %d",(int) function);
172 return EINVAL; 188 return EINVAL;
173 } 189 }
174 190
src/plugins/remotectl/testprogram.c
@@ -39,12 +39,18 @@ @@ -39,12 +39,18 @@
39 unsigned short rc; 39 unsigned short rc;
40 40
41 // Set session name 41 // Set session name
42 - strcpy(buffer,"pw3270"); 42 + strcpy(buffer,"pw3270A");
43 printf("ConnectPS exits with %d\n[%s]\n",hllapi(HLLAPI_CMD_CONNECTPS,buffer,1024,&rc),buffer); 43 printf("ConnectPS exits with %d\n[%s]\n",hllapi(HLLAPI_CMD_CONNECTPS,buffer,1024,&rc),buffer);
44 44
45 // Test for GetRevision call 45 // Test for GetRevision call
46 *buffer = 0; 46 *buffer = 0;
47 printf("GetRevision exits with %d\n[%s]\n",hllapi(HLLAPI_CMD_GETREVISION,buffer,1024,&rc),buffer); 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 return 0; 55 return 0;
50 } 56 }