Commit 2db930f17fc683e2b78b38d19f813c6a95c88529
1 parent
3c059582
Exists in
master
and in
5 other branches
Issue #2 - Ajustando timer HLLAPI
Modificando processo de IPC para permitir a configuração do tempo de espera pela PIPE e mudar o default para 1 segundo evitando a grande demora quando o aplicativo principal não está disponível.
Showing
5 changed files
with
78 additions
and
30 deletions
Show diff stats
src/classlib/remote.cc
| @@ -408,6 +408,34 @@ | @@ -408,6 +408,34 @@ | ||
| 408 | } | 408 | } |
| 409 | #endif // HAVE_DBUS | 409 | #endif // HAVE_DBUS |
| 410 | 410 | ||
| 411 | +#if defined(WIN32) | ||
| 412 | + | ||
| 413 | + static string getRegistryKey(const char *name) throw (std::exception) | ||
| 414 | + { | ||
| 415 | + char buffer[4096]; | ||
| 416 | + HKEY hKey = 0; | ||
| 417 | + unsigned long datalen = sizeof(buffer); | ||
| 418 | + | ||
| 419 | + *buffer = 0; | ||
| 420 | + if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\pw3270",0,KEY_QUERY_VALUE,&hKey) != ERROR_SUCCESS) | ||
| 421 | + { | ||
| 422 | + throw exception("Can't open key %s","HKLM\\Software\\pw3270"); | ||
| 423 | + } | ||
| 424 | + else | ||
| 425 | + { | ||
| 426 | + unsigned long datatype; // #defined in winnt.h (predefined types 0-11) | ||
| 427 | + | ||
| 428 | + if(RegQueryValueExA(hKey,name,NULL,&datatype,(LPBYTE) buffer,&datalen) != ERROR_SUCCESS) | ||
| 429 | + *buffer = 0; | ||
| 430 | + RegCloseKey(hKey); | ||
| 431 | + } | ||
| 432 | + | ||
| 433 | + return string(buffer); | ||
| 434 | + | ||
| 435 | + } | ||
| 436 | + | ||
| 437 | +#endif // defined | ||
| 438 | + | ||
| 411 | remote(const char *session) throw (std::exception) | 439 | remote(const char *session) throw (std::exception) |
| 412 | { | 440 | { |
| 413 | #if defined(WIN32) | 441 | #if defined(WIN32) |
| @@ -415,51 +443,36 @@ | @@ -415,51 +443,36 @@ | ||
| 415 | char buffer[4096]; | 443 | char buffer[4096]; |
| 416 | char * str; | 444 | char * str; |
| 417 | char * ptr; | 445 | char * ptr; |
| 418 | - time_t timer; | 446 | + time_t timer = time(0)+1; |
| 419 | 447 | ||
| 420 | hPipe = INVALID_HANDLE_VALUE; | 448 | hPipe = INVALID_HANDLE_VALUE; |
| 421 | 449 | ||
| 422 | if(strcasecmp(session,"start") == 0 || strcasecmp(session,"new") == 0) | 450 | if(strcasecmp(session,"start") == 0 || strcasecmp(session,"new") == 0) |
| 423 | { | 451 | { |
| 424 | // Start a new session | 452 | // Start a new session |
| 453 | + string appName = getRegistryKey("appName"); | ||
| 425 | char buffer[80]; | 454 | char buffer[80]; |
| 426 | - char appName[4096]; | ||
| 427 | - HKEY hKey = 0; | ||
| 428 | - unsigned long datalen = 4096; | ||
| 429 | STARTUPINFO si; | 455 | STARTUPINFO si; |
| 430 | PROCESS_INFORMATION pi; | 456 | PROCESS_INFORMATION pi; |
| 431 | 457 | ||
| 432 | // Get application path | 458 | // Get application path |
| 433 | - *appName = 0; | ||
| 434 | - if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\pw3270",0,KEY_QUERY_VALUE,&hKey) != ERROR_SUCCESS) | ||
| 435 | - { | ||
| 436 | - throw exception("Can't open key %s","HKLM\\Software\\pw3270"); | ||
| 437 | - return; | ||
| 438 | - } | ||
| 439 | - else | ||
| 440 | - { | ||
| 441 | - unsigned long datatype; // #defined in winnt.h (predefined types 0-11) | ||
| 442 | - if(RegQueryValueExA(hKey,"appName",NULL,&datatype,(LPBYTE) appName,&datalen) != ERROR_SUCCESS) | ||
| 443 | - *appName = 0; | ||
| 444 | - RegCloseKey(hKey); | ||
| 445 | - } | ||
| 446 | 459 | ||
| 447 | - if(!*appName) | 460 | + if(!appName.size()) |
| 448 | { | 461 | { |
| 449 | throw exception("key %s\\appName is invalid","HKLM\\Software\\pw3270"); | 462 | throw exception("key %s\\appName is invalid","HKLM\\Software\\pw3270"); |
| 450 | return; | 463 | return; |
| 451 | } | 464 | } |
| 452 | 465 | ||
| 453 | - trace("%s appname=%s\n",__FUNCTION__,appName); | 466 | + trace("%s appname=%s\n",__FUNCTION__,appName.c_str()); |
| 454 | 467 | ||
| 455 | - snprintf(buffer,79,"%s --session=\"H%06d\"",appName,getpid()); | 468 | + snprintf(buffer,79,"%s --session=\"H%06d\"",appName.c_str(),getpid()); |
| 456 | 469 | ||
| 457 | ZeroMemory( &si, sizeof(si) ); | 470 | ZeroMemory( &si, sizeof(si) ); |
| 458 | si.cb = sizeof(si); | 471 | si.cb = sizeof(si); |
| 459 | ZeroMemory( &pi, sizeof(pi) ); | 472 | ZeroMemory( &pi, sizeof(pi) ); |
| 460 | 473 | ||
| 461 | // si.dwFlags = STARTF_PREVENTPINNING; | 474 | // si.dwFlags = STARTF_PREVENTPINNING; |
| 462 | - trace("App: %s",appName); | 475 | + trace("App: %s",appName.c_str()); |
| 463 | trace("CmdLine: %s",buffer); | 476 | trace("CmdLine: %s",buffer); |
| 464 | 477 | ||
| 465 | if(CreateProcess(NULL,buffer,NULL,NULL,0,NORMAL_PRIORITY_CLASS,NULL,NULL,&si,&pi)) | 478 | if(CreateProcess(NULL,buffer,NULL,NULL,0,NORMAL_PRIORITY_CLASS,NULL,NULL,&si,&pi)) |
| @@ -469,13 +482,16 @@ | @@ -469,13 +482,16 @@ | ||
| 469 | } | 482 | } |
| 470 | else | 483 | else |
| 471 | { | 484 | { |
| 472 | - throw exception("Can't start %s",appName); | 485 | + throw exception("Can't start %s",appName.c_str()); |
| 473 | return; | 486 | return; |
| 474 | } | 487 | } |
| 475 | 488 | ||
| 476 | snprintf(buffer,4095,"H%06d_a",getpid()); | 489 | snprintf(buffer,4095,"H%06d_a",getpid()); |
| 477 | str = strdup(buffer); | 490 | str = strdup(buffer); |
| 478 | 491 | ||
| 492 | + // Até 20 segundos para o processo iniciar. | ||
| 493 | + timer = time(0)+20; | ||
| 494 | + | ||
| 479 | } | 495 | } |
| 480 | else | 496 | else |
| 481 | { | 497 | { |
| @@ -490,6 +506,15 @@ | @@ -490,6 +506,15 @@ | ||
| 490 | else | 506 | else |
| 491 | *ptr = tolower(*ptr); | 507 | *ptr = tolower(*ptr); |
| 492 | } | 508 | } |
| 509 | + | ||
| 510 | + // Wait? | ||
| 511 | + int delay = atoi(getRegistryKey("hllapiWait").c_str()); | ||
| 512 | + | ||
| 513 | + if(delay) { | ||
| 514 | + timer = time(0) + delay; | ||
| 515 | + } | ||
| 516 | + | ||
| 517 | + | ||
| 493 | } | 518 | } |
| 494 | 519 | ||
| 495 | snprintf(buffer,4095,"\\\\.\\pipe\\%s",str); | 520 | snprintf(buffer,4095,"\\\\.\\pipe\\%s",str); |
| @@ -502,11 +527,11 @@ | @@ -502,11 +527,11 @@ | ||
| 502 | 527 | ||
| 503 | if(hPipe == INVALID_HANDLE_VALUE) | 528 | if(hPipe == INVALID_HANDLE_VALUE) |
| 504 | { | 529 | { |
| 505 | - timer = time(0)+20; | 530 | + // Cant get session, wait. |
| 506 | while(hPipe == INVALID_HANDLE_VALUE && time(0) < timer) | 531 | while(hPipe == INVALID_HANDLE_VALUE && time(0) < timer) |
| 507 | { | 532 | { |
| 508 | hPipe = CreateFile(buffer,GENERIC_WRITE|GENERIC_READ,0,NULL,OPEN_EXISTING,0,NULL); | 533 | hPipe = CreateFile(buffer,GENERIC_WRITE|GENERIC_READ,0,NULL,OPEN_EXISTING,0,NULL); |
| 509 | - Sleep(10); | 534 | + Sleep(1); |
| 510 | } | 535 | } |
| 511 | } | 536 | } |
| 512 | 537 |
src/include/pw3270/hllapi.h
| @@ -33,6 +33,7 @@ | @@ -33,6 +33,7 @@ | ||
| 33 | 33 | ||
| 34 | #define HLLAPI_H_INCLUDED 1 | 34 | #define HLLAPI_H_INCLUDED 1 |
| 35 | #include <lib3270.h> | 35 | #include <lib3270.h> |
| 36 | + #include <stdint.h> | ||
| 36 | 37 | ||
| 37 | #ifdef __cplusplus | 38 | #ifdef __cplusplus |
| 38 | extern "C" { | 39 | extern "C" { |
| @@ -101,12 +102,21 @@ extern "C" { | @@ -101,12 +102,21 @@ extern "C" { | ||
| 101 | 102 | ||
| 102 | #define HLLAPI_STATUS_WAITING HLLAPI_STATUS_TIMEOUT | 103 | #define HLLAPI_STATUS_WAITING HLLAPI_STATUS_TIMEOUT |
| 103 | 104 | ||
| 104 | - #ifdef WIN32 | 105 | + #if defined(WIN32) |
| 106 | + | ||
| 105 | #include <windows.h> | 107 | #include <windows.h> |
| 106 | 108 | ||
| 107 | // http://www.mingw.org/wiki/Visual_Basic_DLL | 109 | // http://www.mingw.org/wiki/Visual_Basic_DLL |
| 108 | #define HLLAPI_API_CALL __declspec (dllexport) DWORD __stdcall | 110 | #define HLLAPI_API_CALL __declspec (dllexport) DWORD __stdcall |
| 109 | 111 | ||
| 112 | + #else | ||
| 113 | + | ||
| 114 | + #define HLLAPI_API_CALL __attribute__((visibility("default"))) extern | ||
| 115 | + #define WORD uint32_t | ||
| 116 | + #define LPWORD uint32_t * | ||
| 117 | + #define LPSTR char * | ||
| 118 | + #define HANDLE int | ||
| 119 | + | ||
| 110 | #endif // WIN32 | 120 | #endif // WIN32 |
| 111 | 121 | ||
| 112 | HLLAPI_API_CALL hllapi(const LPWORD func, LPSTR str, LPWORD length, LPWORD rc); | 122 | HLLAPI_API_CALL hllapi(const LPWORD func, LPSTR str, LPWORD length, LPWORD rc); |
src/plugins/hllapi/Makefile.in
| @@ -29,7 +29,7 @@ | @@ -29,7 +29,7 @@ | ||
| 29 | #---[ Sources ]---------------------------------------------------------------- | 29 | #---[ Sources ]---------------------------------------------------------------- |
| 30 | 30 | ||
| 31 | MODULE_NAME=hllapi | 31 | MODULE_NAME=hllapi |
| 32 | -DEPENDS=*.h ../../include/*.h ../../include/lib3270/*.h Makefile | 32 | +DEPENDS=*.h ../../include/*.h ../../include/lib3270/*.h Makefile ../../classlib/*.cc |
| 33 | PLUGIN_SRC=pluginmain.c | 33 | PLUGIN_SRC=pluginmain.c |
| 34 | EXTAPI_SRC=calls.c hllapi.c | 34 | EXTAPI_SRC=calls.c hllapi.c |
| 35 | 35 | ||
| @@ -64,5 +64,11 @@ $(BINDBG)/$(PLUGIN_NAME): $(foreach SRC, $(basename $(PLUGIN_SRC)), $(OBJDBG)/$( | @@ -64,5 +64,11 @@ $(BINDBG)/$(PLUGIN_NAME): $(foreach SRC, $(basename $(PLUGIN_SRC)), $(OBJDBG)/$( | ||
| 64 | $(BINDBG)$(DLL_NAME).$(VERSION): $(foreach SRC, $(basename $(EXTAPI_SRC)), $(OBJDBG)/$(SRC)@OBJEXT@) $(CLASS_DEBUG_OBJECTS) | 64 | $(BINDBG)$(DLL_NAME).$(VERSION): $(foreach SRC, $(basename $(EXTAPI_SRC)), $(OBJDBG)/$(SRC)@OBJEXT@) $(CLASS_DEBUG_OBJECTS) |
| 65 | @echo " CCLD `basename $@`" | 65 | @echo " CCLD `basename $@`" |
| 66 | @$(MKDIR) `dirname $@` | 66 | @$(MKDIR) `dirname $@` |
| 67 | - @$(CXX) $(SYSDLL_FLAGS) $(LDFLAGS) @LDSOFLAGS@ @DBGRPATH@ -o $@ $^ $(CLASS_LIBS) | 67 | + @$(CXX) $(SYSDLL_FLAGS) $(LDFLAGS) @LDSOFLAGS@ @DBGRPATH@ -L../../../.bin/Debug -o $@ $^ $(CLASS_LIBS) |
| 68 | 68 | ||
| 69 | +test: $(BINDBG)/test@EXEEXT@ | ||
| 70 | + | ||
| 71 | +$(BINDBG)/test@EXEEXT@: $(BINDBG)$(DLL_NAME).$(VERSION) $(OBJDBG)/testprogram.o | ||
| 72 | + @echo " CCLD `basename $@`" | ||
| 73 | + @$(MKDIR) `dirname $@` | ||
| 74 | + @$(LD) -o $@ $^ $(LIBS) $(BINDBG)$(DLL_NAME).$(VERSION) |
src/plugins/hllapi/hllapi.cbp
| @@ -62,6 +62,12 @@ | @@ -62,6 +62,12 @@ | ||
| 62 | <Compiler> | 62 | <Compiler> |
| 63 | <Add option="-Wall" /> | 63 | <Add option="-Wall" /> |
| 64 | </Compiler> | 64 | </Compiler> |
| 65 | + <Unit filename="../../classlib/exception.cc" /> | ||
| 66 | + <Unit filename="../../classlib/local.cc" /> | ||
| 67 | + <Unit filename="../../classlib/module.cc" /> | ||
| 68 | + <Unit filename="../../classlib/remote.cc" /> | ||
| 69 | + <Unit filename="../../classlib/session.cc" /> | ||
| 70 | + <Unit filename="../../include/lib3270.h" /> | ||
| 65 | <Unit filename="Makefile.in" /> | 71 | <Unit filename="Makefile.in" /> |
| 66 | <Unit filename="calls.cc" /> | 72 | <Unit filename="calls.cc" /> |
| 67 | <Unit filename="client.h" /> | 73 | <Unit filename="client.h" /> |
| @@ -71,9 +77,6 @@ | @@ -71,9 +77,6 @@ | ||
| 71 | <Unit filename="pluginmain.c"> | 77 | <Unit filename="pluginmain.c"> |
| 72 | <Option compilerVar="CC" /> | 78 | <Option compilerVar="CC" /> |
| 73 | </Unit> | 79 | </Unit> |
| 74 | - <Unit filename="remote.c"> | ||
| 75 | - <Option compilerVar="CC" /> | ||
| 76 | - </Unit> | ||
| 77 | <Unit filename="remotectl.h" /> | 80 | <Unit filename="remotectl.h" /> |
| 78 | <Unit filename="server.h" /> | 81 | <Unit filename="server.h" /> |
| 79 | <Unit filename="testprogram.c"> | 82 | <Unit filename="testprogram.c"> |
src/plugins/hllapi/pluginmain.c
| @@ -32,7 +32,11 @@ | @@ -32,7 +32,11 @@ | ||
| 32 | */ | 32 | */ |
| 33 | 33 | ||
| 34 | #include "server.h" | 34 | #include "server.h" |
| 35 | + | ||
| 36 | +#ifdef _WIN32 | ||
| 35 | #include <windows.h> | 37 | #include <windows.h> |
| 38 | +#endif // _WIN32 | ||
| 39 | + | ||
| 36 | #include <pw3270/plugin.h> | 40 | #include <pw3270/plugin.h> |
| 37 | #include <pw3270/v3270.h> | 41 | #include <pw3270/v3270.h> |
| 38 | #include <pw3270/ipcpackets.h> | 42 | #include <pw3270/ipcpackets.h> |