From 1d213a96f7e2e314660233beefe7abeab34f6d83 Mon Sep 17 00:00:00 2001 From: perry.werneck@gmail.com Date: Mon, 23 Jan 2012 12:51:07 +0000 Subject: [PATCH] Movendo indicador do estado da conexao para a estrutura de sessao --- latest/src/gtk2/actions1.c | 4 ++-- latest/src/include/lib3270.h | 11 +++++++++++ latest/src/include/lib3270/api.h | 36 +++++++++++++++++++----------------- latest/src/lib/XtGlue.c | 7 +++++-- latest/src/lib/globals.h | 18 +++++++++--------- latest/src/lib/glue.c | 1 + latest/src/lib/host.c | 22 +++++++--------------- latest/src/lib/telnet.c | 4 ++-- 8 files changed, 56 insertions(+), 47 deletions(-) diff --git a/latest/src/gtk2/actions1.c b/latest/src/gtk2/actions1.c index 9a2bfb0..813e6e1 100644 --- a/latest/src/gtk2/actions1.c +++ b/latest/src/gtk2/actions1.c @@ -756,7 +756,7 @@ gtk_action_group_set_sensitive(action_group[id],status); } - static void set_ft_action_state(H3270 *session,int state) + static void set_ft_action_state(H3270 *session,int state,void *dunno) { gtk_action_group_set_sensitive(action_group[ACTION_GROUP_FT],state); } @@ -790,7 +790,7 @@ action_by_id[f] = dunno; #ifdef X3270_FT - set_ft_action_state(hSession,0); + set_ft_action_state(hSession,0,NULL); register_schange(ST_3270_MODE, set_ft_action_state); #else gtk_action_group_set_sensitive(ft_actions,FALSE); diff --git a/latest/src/include/lib3270.h b/latest/src/include/lib3270.h index 7d83310..fed1b96 100644 --- a/latest/src/include/lib3270.h +++ b/latest/src/include/lib3270.h @@ -95,5 +95,16 @@ */ LIB3270_EXPORT int lib3270_reconnect(H3270 *h,int wait); + /** + * Get connection state. + * + * @param h Session handle. + * + * @return Connection state. + * + */ + LIB3270_EXPORT enum cstate lib3270_get_connection_state(H3270 *h); + + #endif // LIB3270_H_INCLUDED diff --git a/latest/src/include/lib3270/api.h b/latest/src/include/lib3270/api.h index 6cc5847..75fd35c 100644 --- a/latest/src/include/lib3270/api.h +++ b/latest/src/include/lib3270/api.h @@ -145,6 +145,21 @@ #define ST_CHARSET LIB3270_STATE_CHARSET #define LIB3270_STATE_CHANGE LIB3270_STATE + /** connection state */ + enum cstate + { + NOT_CONNECTED, /**< no socket, unknown mode */ + RESOLVING, /**< resolving hostname */ + PENDING, /**< connection pending */ + CONNECTED_INITIAL, /**< connected, no mode yet */ + CONNECTED_ANSI, /**< connected in NVT ANSI mode */ + CONNECTED_3270, /**< connected in old-style 3270 mode */ + CONNECTED_INITIAL_E, /**< connected in TN3270E mode, unnegotiated */ + CONNECTED_NVT, /**< connected in TN3270E mode, NVT mode */ + CONNECTED_SSCP, /**< connected in TN3270E mode, SSCP-LU mode */ + CONNECTED_TN3270E /**< connected in TN3270E mode, 3270 mode */ + }; + struct lib3270_state_callback; typedef struct _h3270 @@ -154,6 +169,7 @@ // Connection info int secure_connection; int sock; /**< Network socket */ + enum cstate cstate; #if defined(_WIN32) /*[*/ HANDLE sock_handle; @@ -216,22 +232,6 @@ KT_GE }; - /** connection state */ - enum cstate - { - NOT_CONNECTED, /**< no socket, unknown mode */ - RESOLVING, /**< resolving hostname */ - PENDING, /**< connection pending */ - CONNECTED_INITIAL, /**< connected, no mode yet */ - CONNECTED_ANSI, /**< connected in NVT ANSI mode */ - CONNECTED_3270, /**< connected in old-style 3270 mode */ - CONNECTED_INITIAL_E, /**< connected in TN3270E mode, unnegotiated */ - CONNECTED_NVT, /**< connected in TN3270E mode, NVT mode */ - CONNECTED_SSCP, /**< connected in TN3270E mode, SSCP-LU mode */ - CONNECTED_TN3270E /**< connected in TN3270E mode, 3270 mode */ - }; - - /** extended attributes */ struct ea { @@ -312,9 +312,11 @@ LIB3270_EXPORT int RegisterFTCallbacks(const struct filetransfer_callbacks *cbk); + #define QueryCstate() lib3270_get_connection_state(NULL) + #ifndef LIB3270 - LIB3270_EXPORT enum cstate QueryCstate(void); + LIB3270_EXPORT enum ft_state QueryFTstate(void); #define PCONNECTED ((int) QueryCstate() >= (int)RESOLVING) diff --git a/latest/src/lib/XtGlue.c b/latest/src/lib/XtGlue.c index 063f2de..12d9979 100644 --- a/latest/src/lib/XtGlue.c +++ b/latest/src/lib/XtGlue.c @@ -893,9 +893,12 @@ int Register3270IOCallbacks(const struct lib3270_io_callbacks *cbk) } -LIB3270_EXPORT enum cstate QueryCstate(void) +LIB3270_EXPORT enum cstate lib3270_get_connection_state(H3270 *h) { - return cstate; + if(!h) + h = &h3270; + + return h->cstate; } int CallAndWait(int(*callback)(void *),void *parm) diff --git a/latest/src/lib/globals.h b/latest/src/lib/globals.h index 8b10146..349aaa5 100644 --- a/latest/src/lib/globals.h +++ b/latest/src/lib/globals.h @@ -245,15 +245,15 @@ LIB3270_INTERNAL int *xtra_width; LIB3270_INTERNAL enum ft_state ft_state; LIB3270_INTERNAL enum cstate cstate; -#define PCONNECTED ((int)cstate >= (int)RESOLVING) -#define HALF_CONNECTED (cstate == RESOLVING || cstate == PENDING) -#define CONNECTED ((int)cstate >= (int)CONNECTED_INITIAL) -#define IN_NEITHER (cstate == CONNECTED_INITIAL) -#define IN_ANSI (cstate == CONNECTED_ANSI || cstate == CONNECTED_NVT) -#define IN_3270 (cstate == CONNECTED_3270 || cstate == CONNECTED_TN3270E || cstate == CONNECTED_SSCP) -#define IN_SSCP (cstate == CONNECTED_SSCP) -#define IN_TN3270E (cstate == CONNECTED_TN3270E) -#define IN_E (cstate >= CONNECTED_INITIAL_E) +#define PCONNECTED ((int)h3270.cstate >= (int)RESOLVING) +#define HALF_CONNECTED (h3270.cstate == RESOLVING || h3270.cstate == PENDING) +#define CONNECTED ((int)h3270.cstate >= (int)CONNECTED_INITIAL) +#define IN_NEITHER (h3270.cstate == CONNECTED_INITIAL) +#define IN_ANSI (h3270.cstate == CONNECTED_ANSI || h3270.cstate == CONNECTED_NVT) +#define IN_3270 (h3270.cstate == CONNECTED_3270 || h3270.cstate == CONNECTED_TN3270E || h3270.cstate == CONNECTED_SSCP) +#define IN_SSCP (h3270.cstate == CONNECTED_SSCP) +#define IN_TN3270E (h3270.cstate == CONNECTED_TN3270E) +#define IN_E (h3270.cstate >= CONNECTED_INITIAL_E) /* keyboard modifer bitmap */ #define ShiftKeyDown 0x01 diff --git a/latest/src/lib/glue.c b/latest/src/lib/glue.c index 1b8eca5..7868387 100644 --- a/latest/src/lib/glue.c +++ b/latest/src/lib/glue.c @@ -169,6 +169,7 @@ H3270 * lib3270_session_new(const char *model) hSession->model_num = -1; hSession->first_changed = -1; hSession->last_changed = -1; + hSession->cstate = NOT_CONNECTED; strncpy(hSession->full_model_name,"IBM-",FULL_MODEL_NAME_SIZE); hSession->model_name = &hSession->full_model_name[4]; diff --git a/latest/src/lib/host.c b/latest/src/lib/host.c index 9072012..7c290a8 100644 --- a/latest/src/lib/host.c +++ b/latest/src/lib/host.c @@ -59,7 +59,7 @@ #define MAX_RECENT 5 -enum cstate cstate = NOT_CONNECTED; +// enum cstate cstate = NOT_CONNECTED; Boolean std_ds_host = False; Boolean no_login_host = False; Boolean non_tn3270e_host = False; @@ -620,7 +620,7 @@ static int do_connect(H3270 *hSession, const char *n) /* Still thinking about it? */ if (resolving) { - cstate = RESOLVING; + h3270.cstate = RESOLVING; st_changed(ST_RESOLVING, True); return 0; } @@ -639,10 +639,10 @@ static int do_connect(H3270 *hSession, const char *n) /* Set state and tell the world. */ if (pending) { - cstate = PENDING; + h3270.cstate = PENDING; st_changed(ST_HALF_CONNECT, True); } else { - cstate = CONNECTED_INITIAL; + h3270.cstate = CONNECTED_INITIAL; st_changed(ST_CONNECT, True); #if defined(X3270_DISPLAY) /*[*/ if (toggled(RECONNECT) && error_popup_visible()) @@ -737,7 +737,7 @@ void host_disconnect(H3270 *h, int failed) trace_ansi_disc(); #endif /*]*/ - cstate = NOT_CONNECTED; + h3270.cstate = NOT_CONNECTED; /* Propagate the news to everyone else. */ st_changed(ST_CONNECT, False); @@ -752,7 +752,7 @@ host_in3270(enum cstate new_cstate) new_cstate == CONNECTED_SSCP || new_cstate == CONNECTED_TN3270E); - cstate = new_cstate; + h3270.cstate = new_cstate; ever_3270 = now3270; st_changed(ST_3270_MODE, now3270); } @@ -760,7 +760,7 @@ host_in3270(enum cstate new_cstate) void host_connected(void) { - cstate = CONNECTED_INITIAL; + h3270.cstate = CONNECTED_INITIAL; st_changed(ST_CONNECT, True); #if defined(X3270_DISPLAY) /*[*/ @@ -1058,14 +1058,6 @@ LIB3270_EXPORT int lib3270_reconnect(H3270 *h,int wait) return rc; } - /* - * If called from a script and the connection was successful (or - * half-successful), pause the script until we are connected and - * we have identified the host type. - if (!w && (CONNECTED || HALF_CONNECTED)) - sms_connect_wait(); - */ - return 0; } diff --git a/latest/src/lib/telnet.c b/latest/src/lib/telnet.c index a83612c..e915e74 100644 --- a/latest/src/lib/telnet.c +++ b/latest/src/lib/telnet.c @@ -2418,14 +2418,14 @@ check_in3270(void) hisopts[TELOPT_BINARY] && hisopts[TELOPT_EOR]) { new_cstate = CONNECTED_3270; - } else if (cstate == CONNECTED_INITIAL) { + } else if (h3270.cstate == CONNECTED_INITIAL) { /* Nothing has happened, yet. */ return; } else { new_cstate = CONNECTED_ANSI; } - if (new_cstate != cstate) { + if (new_cstate != h3270.cstate) { #if defined(X3270_TN3270E) /*[*/ int was_in_e = IN_E; #endif /*]*/ -- libgit2 0.21.2