Commit d0eceea1d5ee273eef11c7bd7b1bb038c9a33e58

Authored by perry.werneck@gmail.com
1 parent 012921c0

Implementando return codes e funções que faltavam no módulo hllapi

src/include/pw3270/hllapi.h
... ... @@ -66,6 +66,7 @@ extern "C" {
66 66 #define HLLAPI_STATUS_UNAVAILABLE 11 /**< Resource unavailable at this time */
67 67 #define HLLAPI_STATUS_SYSTEM_ERROR 9 /**< A system error occurred */
68 68  
  69 + #define HLLAPI_STATUS_WAITING HLLAPI_STATUS_TIMEOUT
69 70  
70 71 #ifdef _WIN32
71 72 // http://www.mingw.org/wiki/Visual_Basic_DLL
... ... @@ -81,6 +82,7 @@ extern &quot;C&quot; {
81 82 __declspec (dllexport) DWORD __stdcall hllapi_disconnect(void);
82 83 __declspec (dllexport) DWORD __stdcall hllapi_get_message_id(void);
83 84 __declspec (dllexport) DWORD __stdcall hllapi_is_connected(void);
  85 + __declspec (dllexport) DWORD __stdcall hllapi_get_state(void);
84 86 __declspec (dllexport) DWORD __stdcall hllapi_get_screen_at(WORD row, WORD col, LPSTR buffer);
85 87 __declspec (dllexport) DWORD __stdcall hllapi_get_screen(WORD pos, LPSTR buffer, WORD len);
86 88 __declspec (dllexport) DWORD __stdcall hllapi_enter(void);
... ...
src/plugins/hllapi/calls.c
... ... @@ -117,7 +117,7 @@
117 117 __declspec (dllexport) DWORD __stdcall hllapi_init(LPSTR mode)
118 118 {
119 119 if(!mode)
120   - return EINVAL;
  120 + return HLLAPI_STATUS_SYSTEM_ERROR;
121 121  
122 122 trace("%s(%s)",__FUNCTION__,(char *) mode);
123 123  
... ... @@ -264,7 +264,7 @@
264 264 __declspec (dllexport) DWORD __stdcall hllapi_connect(LPSTR uri, WORD wait)
265 265 {
266 266 if(!(host_connect && hSession && uri))
267   - return EINVAL;
  267 + return HLLAPI_STATUS_SYSTEM_ERROR;
268 268  
269 269 return host_connect(hSession,uri,wait);
270 270 }
... ... @@ -272,15 +272,45 @@
272 272 __declspec (dllexport) DWORD __stdcall hllapi_is_connected(void)
273 273 {
274 274 if(!(host_is_connected && hSession))
275   - return EINVAL;
  275 + return HLLAPI_STATUS_SYSTEM_ERROR;
276 276  
277 277 return host_is_connected(hSession);
278 278 }
  279 +
  280 + __declspec (dllexport) DWORD __stdcall hllapi_get_state(void)
  281 + {
  282 + switch(hllapi_get_message_id())
  283 + {
  284 + case LIB3270_MESSAGE_NONE: /* 0 - No message */
  285 + return HLLAPI_STATUS_SUCCESS;
  286 +
  287 + case LIB3270_MESSAGE_DISCONNECTED: /* 4 - Disconnected from host */
  288 + return HLLAPI_STATUS_DISCONNECTED;
  289 +
  290 + case LIB3270_MESSAGE_MINUS:
  291 + case LIB3270_MESSAGE_PROTECTED:
  292 + case LIB3270_MESSAGE_NUMERIC:
  293 + case LIB3270_MESSAGE_OVERFLOW:
  294 + case LIB3270_MESSAGE_INHIBIT:
  295 + case LIB3270_MESSAGE_KYBDLOCK:
  296 + return HLLAPI_STATUS_KEYBOARD_LOCKED;
  297 +
  298 + case LIB3270_MESSAGE_SYSWAIT:
  299 + case LIB3270_MESSAGE_TWAIT:
  300 + case LIB3270_MESSAGE_AWAITING_FIRST:
  301 + case LIB3270_MESSAGE_X:
  302 + case LIB3270_MESSAGE_RESOLVING:
  303 + case LIB3270_MESSAGE_CONNECTING:
  304 + return HLLAPI_STATUS_WAITING;
  305 + }
  306 +
  307 + return HLLAPI_STATUS_SYSTEM_ERROR;
  308 + }
279 309  
280 310 __declspec (dllexport) DWORD __stdcall hllapi_disconnect(void)
281 311 {
282 312 if(!(host_disconnect && hSession))
283   - return EINVAL;
  313 + return HLLAPI_STATUS_SYSTEM_ERROR;
284 314  
285 315 host_disconnect(hSession);
286 316  
... ... @@ -290,7 +320,7 @@
290 320 __declspec (dllexport) DWORD __stdcall hllapi_wait_for_ready(WORD seconds)
291 321 {
292 322 if(!(wait_for_ready && hSession))
293   - return EINVAL;
  323 + return HLLAPI_STATUS_SYSTEM_ERROR;
294 324  
295 325 trace("%s seconds=%d\n", __FUNCTION__, (int) seconds);
296 326  
... ... @@ -300,7 +330,7 @@
300 330 __declspec (dllexport) DWORD __stdcall hllapi_wait(WORD seconds)
301 331 {
302 332 if(!(script_sleep && hSession))
303   - return EINVAL;
  333 + return HLLAPI_STATUS_SYSTEM_ERROR;
304 334  
305 335 return (DWORD) script_sleep(hSession,(int) seconds);
306 336 }
... ... @@ -308,7 +338,7 @@
308 338 __declspec (dllexport) DWORD __stdcall hllapi_get_message_id(void)
309 339 {
310 340 if(!(get_message && hSession))
311   - return EINVAL;
  341 + return HLLAPI_STATUS_SYSTEM_ERROR;
312 342 return (DWORD) get_message(hSession);
313 343 }
314 344  
... ... @@ -318,7 +348,7 @@
318 348 int len;
319 349  
320 350 if(!(get_text && release_memory && hSession))
321   - return EINVAL;
  351 + return HLLAPI_STATUS_SYSTEM_ERROR;
322 352  
323 353 trace("%s row=%d col=%d buffer=%p",__FUNCTION__,row,col,buffer);
324 354 len = strlen(buffer);
... ... @@ -330,7 +360,7 @@
330 360 trace(" text=%p errno=%d %s\n",text,errno,strerror(errno));
331 361  
332 362 if(!text)
333   - return EINVAL;
  363 + return HLLAPI_STATUS_SYSTEM_ERROR;
334 364  
335 365 strncpy(buffer,text,len);
336 366 release_memory(text);
... ... @@ -343,7 +373,7 @@
343 373 __declspec (dllexport) DWORD __stdcall hllapi_enter(void)
344 374 {
345 375 if(!(action_enter && hSession))
346   - return EINVAL;
  376 + return HLLAPI_STATUS_SYSTEM_ERROR;
347 377  
348 378 return (DWORD) action_enter(hSession);
349 379 }
... ... @@ -351,7 +381,7 @@
351 381 __declspec (dllexport) DWORD __stdcall hllapi_set_text_at(WORD row, WORD col, LPSTR text)
352 382 {
353 383 if(!(set_text_at && hSession))
354   - return EINVAL;
  384 + return HLLAPI_STATUS_SYSTEM_ERROR;
355 385  
356 386 return (DWORD) set_text_at(hSession,row,col,(const unsigned char *) text);
357 387 }
... ... @@ -359,7 +389,7 @@
359 389 __declspec (dllexport) DWORD __stdcall hllapi_cmp_text_at(WORD row, WORD col, LPSTR text)
360 390 {
361 391 if(!(cmp_text_at && hSession))
362   - return EINVAL;
  392 + return HLLAPI_STATUS_SYSTEM_ERROR;
363 393  
364 394 return (DWORD) cmp_text_at(hSession,row,col,(const char *) text);
365 395 }
... ... @@ -367,7 +397,7 @@
367 397 __declspec (dllexport) DWORD __stdcall hllapi_pfkey(WORD key)
368 398 {
369 399 if(!(pfkey && hSession))
370   - return EINVAL;
  400 + return HLLAPI_STATUS_SYSTEM_ERROR;
371 401  
372 402 return (DWORD) pfkey(hSession,key);
373 403 }
... ... @@ -375,7 +405,7 @@
375 405 __declspec (dllexport) DWORD __stdcall hllapi_pakey(WORD key)
376 406 {
377 407 if(!(pfkey && hSession))
378   - return EINVAL;
  408 + return HLLAPI_STATUS_SYSTEM_ERROR;
379 409  
380 410 return (DWORD) pakey(hSession,key);
381 411 }
... ... @@ -401,7 +431,7 @@
401 431 __declspec (dllexport) DWORD __stdcall hllapi_setcursor(WORD pos)
402 432 {
403 433 if(!(setcursor && hSession))
404   - return EINVAL;
  434 + return HLLAPI_STATUS_SYSTEM_ERROR;
405 435 trace("%s(%d)",__FUNCTION__,pos);
406 436 return setcursor(hSession,pos-1);
407 437 }
... ... @@ -446,7 +476,7 @@
446 476 __declspec (dllexport) DWORD __stdcall hllapi_erase_eof(void)
447 477 {
448 478 if(!erase_eof && hSession)
449   - return EINVAL;
  479 + return HLLAPI_STATUS_SYSTEM_ERROR;
450 480 trace("%s",__FUNCTION__);
451 481 return erase_eof(hSession);
452 482 }
... ... @@ -454,7 +484,7 @@
454 484 __declspec (dllexport) DWORD __stdcall hllapi_print(void)
455 485 {
456 486 if(!(do_print && hSession))
457   - return EINVAL;
  487 + return HLLAPI_STATUS_SYSTEM_ERROR;
458 488  
459 489 return do_print(hSession);
460 490 }
... ...
src/plugins/hllapi/hllapi.c
... ... @@ -366,15 +366,22 @@ static int copy_ps(char *buffer, unsigned short *length, unsigned short *rc)
366 366 * 9 A system error was encountered.
367 367 *
368 368 */
369   - size_t szBuffer = strlen(buffer);
370   -
371   - if(*length < szBuffer)
372   - szBuffer = *length;
  369 + size_t szBuffer = strlen(buffer);
  370 + char * text;
373 371  
374   -
375   - #warning Implementar
376   -
377   - return HLLAPI_STATUS_SYSTEM_ERROR;
  372 + if(!hllapi_is_connected())
  373 + return HLLAPI_STATUS_DISCONNECTED;
  374 +
  375 + text = hllapi_get_string(1, szBuffer);
  376 +
  377 + if(!text)
  378 + return HLLAPI_STATUS_SYSTEM_ERROR;
  379 +
  380 + memcpy(buffer,text,szBuffer);
  381 +
  382 + hllapi_free(text);
  383 +
  384 + return hllapi_get_state();
378 385 }
379 386  
380 387 static int wait_system(char *buffer, unsigned short *length, unsigned short *rc)
... ... @@ -399,25 +406,12 @@ static int wait_system(char *buffer, unsigned short *length, unsigned short *rc)
399 406 time_t end = time(0) + 3600;
400 407  
401 408 while(time(0) < end)
402   - {
403   - switch(hllapi_get_message_id())
404   - {
405   - case LIB3270_MESSAGE_NONE: /* 0 - No message */
406   - return HLLAPI_STATUS_SUCCESS;
407   -
408   - case LIB3270_MESSAGE_DISCONNECTED: /* 4 - Disconnected from host */
409   - return HLLAPI_STATUS_DISCONNECTED;
410   -
411   - case LIB3270_MESSAGE_MINUS:
412   - case LIB3270_MESSAGE_PROTECTED:
413   - case LIB3270_MESSAGE_NUMERIC:
414   - case LIB3270_MESSAGE_OVERFLOW:
415   - case LIB3270_MESSAGE_INHIBIT:
416   - case LIB3270_MESSAGE_KYBDLOCK:
417   - return HLLAPI_STATUS_KEYBOARD_LOCKED;
418   -
419   - }
420   -
  409 + {
  410 + int state = hllapi_get_state();
  411 +
  412 + if(state != HLLAPI_STATUS_WAITING)
  413 + return state;
  414 +
421 415 if(hllapi_wait(1))
422 416 return HLLAPI_STATUS_SYSTEM_ERROR;
423 417  
... ...