Commit 08e1c4dd3fb62a4751f3328ae711e1b87acef760

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

Implementando novo mecanismo de conexao

src/classlib/remote.cc
... ... @@ -653,31 +653,64 @@
653 653  
654 654 int connect(bool wait)
655 655 {
  656 + int rc;
  657 +
656 658 #if defined(WIN32)
657 659  
658   - size_t cbSize = sizeof(struct hllapi_packet_connect)+strlen(uri);
  660 + size_t cbSize = sizeof(struct hllapi_packet_connect);
659 661 struct hllapi_packet_connect * pkt = (struct hllapi_packet_connect *) malloc(cbSize);
660 662  
661 663 pkt->packet_id = HLLAPI_PACKET_CONNECT;
662 664 pkt->wait = (unsigned char) wait;
663 665  
664   - return query_intval((void *) pkt,cbSize,true);
  666 + rc = query_intval((void *) pkt,cbSize,true);
665 667  
666 668 #elif defined(HAVE_DBUS)
667 669  
668 670 int rc = query_intval("connect", DBUS_TYPE_STRING, &uri, DBUS_TYPE_INVALID);
669 671  
  672 +#else
  673 + rc = -1;
  674 +
  675 +#endif
  676 +
670 677 if(!rc && wait)
671 678 return wait_for_ready(120);
672 679  
673 680 return rc;
674 681  
675   -#else
  682 + }
  683 +
  684 + int set_host(const char *uri)
  685 + {
  686 + int rc;
  687 +
  688 +#if defined(WIN32)
  689 +
  690 + size_t cbSize = sizeof(struct hllapi_packet_text)+strlen(uri);
  691 + struct hllapi_packet_text * pkt = (struct hllapi_packet_text *) malloc(cbSize);
  692 +
  693 + pkt->packet_id = HLLAPI_PACKET_SET_HOST;
  694 + strcpy(pkt->text,uri);
  695 +
  696 + rc = query_intval((void *) pkt,cbSize,true);
  697 +
  698 +#elif defined(HAVE_DBUS)
  699 +
  700 + #warning Implementar
676 701 return -1;
677 702  
  703 +#else
  704 +
  705 + rc = -1;
  706 +
678 707 #endif
  708 +
  709 + return rc;
  710 +
679 711 }
680 712  
  713 +
681 714 int wait_for_ready(int seconds)
682 715 {
683 716 #if defined(WIN32)
... ...
src/classlib/session.cc
... ... @@ -469,6 +469,19 @@
469 469 return EINVAL;
470 470 }
471 471  
  472 + int session::connect(const char *host, bool wait)
  473 + {
  474 + int rc = 0;
  475 +
  476 + if(host && *host)
  477 + rc = set_host(host);
  478 +
  479 + if(!rc)
  480 + rc = connect(wait);
  481 +
  482 + return rc;
  483 + }
  484 +
472 485 #ifdef WIN32
473 486 string session::win32_strerror(int e)
474 487 {
... ...
src/include/pw3270/class.h
... ... @@ -128,6 +128,7 @@
128 128 virtual string * get_display_charset(void);
129 129  
130 130 // Connection & Network
  131 + int connect(const char *host, bool wait = true);
131 132 virtual int connect(bool wait = true) = 0;
132 133 virtual int set_host(const char *hostname) = 0;
133 134 virtual int disconnect(void) = 0;
... ...
src/plugins/hllapi/calls.cc
... ... @@ -100,9 +100,7 @@
100 100  
101 101 try
102 102 {
103   - if(uri && *uri)
104   - session::get_default()->set_host(uri);
105   - rc = session::get_default()->connect(wait);
  103 + rc = session::get_default()->connect(uri,wait);
106 104 }
107 105 catch(std::exception &e)
108 106 {
... ...
src/plugins/rx3270/pluginmain.cc
... ... @@ -89,6 +89,7 @@
89 89 const string get_version(void);
90 90 LIB3270_CSTATE get_cstate(void);
91 91 int disconnect(void);
  92 + int set_host(const char *uri);
92 93 int connect(bool wait = true);
93 94 bool is_connected(void);
94 95 bool is_ready(void);
... ... @@ -778,6 +779,11 @@ const char * plugin::asc2ebc(unsigned char *str, int sz)
778 779 return lib3270_asc2ebc(hSession,str,sz);
779 780 }
780 781  
  782 +int plugin::set_host(const char *uri)
  783 +{
  784 + return lib3270_set_host(hSession,uri) != NULL;
  785 +}
  786 +
781 787 const char * plugin::ebc2asc(unsigned char *str, int sz)
782 788 {
783 789 return lib3270_ebc2asc(hSession,str,sz);
... ...
src/plugins/rx3270/rexx_methods.cc
... ... @@ -101,10 +101,7 @@ RexxMethod3(int, rx3270_method_connect, CSELF, sessionPtr, CSTRING, uri, OPTIONA
101 101 if(!hSession)
102 102 return -1;
103 103  
104   - if(uri)
105   - hSession->set_hostname(uri);
106   -
107   - return hSession->connect(wait != 0);
  104 + return hSession->connect(uri,wait != 0);
108 105 }
109 106  
110 107 RexxMethod1(int, rx3270_method_disconnect, CSELF, sessionPtr)
... ...
src/plugins/rx3270/typed_routines.cc
... ... @@ -93,12 +93,7 @@ RexxRoutine0(int, rx3270Disconnect)
93 93  
94 94 RexxRoutine2(int, rx3270Connect, CSTRING, hostname, int, wait)
95 95 {
96   - session * hSession = session::get_default();
97   -
98   - if(hostname && *hostname)
99   - hSession->set_hostname(hostname);
100   -
101   - return hSession->connect(wait);
  96 + return session::get_default()->connect(hostname,wait);
102 97 }
103 98  
104 99 RexxRoutine0(int, rx3270isConnected)
... ...