From 5da4b25db4b09799cf376d5565c43ae795a707db Mon Sep 17 00:00:00 2001 From: perry.werneck@gmail.com Date: Mon, 23 Jan 2012 10:17:45 +0000 Subject: [PATCH] Mais uma etapa na implementação do suporte a multiplas sessões: Callbacks de estado movidos para dentro da estrutura de controle de sessão --- latest/src/gtk2/gui.h | 4 ++-- latest/src/gtk2/main.c | 8 ++++---- latest/src/include/lib3270.h | 26 +++++++++++++++++++++++++- latest/src/include/lib3270/api.h | 69 +++++++++++++++++++++++++++++++++++++++++++++++++-------------------- latest/src/lib/ansi.c | 2 +- latest/src/lib/ctlr.c | 8 ++++---- latest/src/lib/ft.c | 8 ++++---- latest/src/lib/globals.h | 4 ++-- latest/src/lib/glue.c | 13 +------------ latest/src/lib/host.c | 47 +++++++++++++++++++++++++++++++++++++---------- latest/src/lib/hostc.h | 4 +++- latest/src/lib/kybd.c | 8 +++----- latest/src/lib/printer.c | 8 ++++---- latest/src/lib/screen.c | 16 ++++++++-------- 14 files changed, 147 insertions(+), 78 deletions(-) diff --git a/latest/src/gtk2/gui.h b/latest/src/gtk2/gui.h index 6cc4b7e..c4ec309 100644 --- a/latest/src/gtk2/gui.h +++ b/latest/src/gtk2/gui.h @@ -54,7 +54,7 @@ #define HAVE_DOCK 1 #endif - #include + #include #include #define CURSOR_MODE_3270 (CURSOR_MODE_USER+9) @@ -244,7 +244,7 @@ { POPUP_MENU_DEFAULT, POPUP_MENU_SELECTION, - + POPUP_MENU_COUNT }; diff --git a/latest/src/gtk2/main.c b/latest/src/gtk2/main.c index 042d10b..cb4bc63 100644 --- a/latest/src/gtk2/main.c +++ b/latest/src/gtk2/main.c @@ -76,7 +76,7 @@ static gchar * log_filename = NULL; /*---[ Implement ]----------------------------------------------------------------------------------------------*/ /* Callback for connection state changes. */ -static void connect_main(H3270 *session, int status) +static void connect_main(H3270 *session, int status, void *dunno) { gboolean online = (CONNECTED) ? TRUE : FALSE; @@ -129,7 +129,7 @@ static void connect_main(H3270 *session, int status) } -static void connect_in3270(H3270 *session, int status) +static void connect_in3270(H3270 *session, int status, void *dunno) { #ifdef X3270_FT action_group_set_sensitive(ACTION_GROUP_FT,status); @@ -622,8 +622,8 @@ int main(int argc, char *argv[]) return -1; } - connect_main(hSession,0); - connect_in3270(hSession,0); + connect_main(hSession,0,NULL); + connect_in3270(hSession,0,NULL); register_schange(ST_CONNECT, connect_main); register_schange(ST_3270_MODE, connect_in3270); diff --git a/latest/src/include/lib3270.h b/latest/src/include/lib3270.h index f724ba1..f4d1f70 100644 --- a/latest/src/include/lib3270.h +++ b/latest/src/include/lib3270.h @@ -47,6 +47,30 @@ */ LIB3270_EXPORT void lib3270_get_screen_size(H3270 *h, int *r, int *c); + /** + * Start a new session (INCOMPLETE). + * + * Initialize session structure, opens a new session. + * WARNING: Multi session ins't yet supported in lib3270, because of this + * this call always return the handle of the same session. + * + * @param model Terminal model. + * + * @return lib3270 internal session structure. + * + */ + LIB3270_EXPORT H3270 * lib3270_session_new(const char *model); + + /** + * Register a state change callback + * + * @param h Session handle. + * @param tx State ID + * @param func Callback + * @param data Data + * + */ + LIB3270_EXPORT void lib3270_register_schange(H3270 *h,LIB3270_STATE_CHANGE tx, void (*func)(H3270 *, int, void *),void *data); -#endif // LIB3270_H_INCLUDED +#endif // LIB3270_H_INCLUDED diff --git a/latest/src/include/lib3270/api.h b/latest/src/include/lib3270/api.h index 142e978..da14bd8 100644 --- a/latest/src/include/lib3270/api.h +++ b/latest/src/include/lib3270/api.h @@ -118,6 +118,35 @@ #define FULL_MODEL_NAME_SIZE 13 + /* State change IDs. */ + typedef enum _lib3270_state + { + LIB3270_STATE_RESOLVING, + LIB3270_STATE_HALF_CONNECT, + LIB3270_STATE_CONNECT, + LIB3270_STATE_3270_MODE, + LIB3270_STATE_LINE_MODE, + LIB3270_STATE_REMODEL, + LIB3270_STATE_PRINTER, + LIB3270_STATE_EXITING, + LIB3270_STATE_CHARSET, + + N_ST // Always the last one + } LIB3270_STATE; + + #define ST_RESOLVING LIB3270_STATE_RESOLVING + #define ST_HALF_CONNECT LIB3270_STATE_HALF_CONNECT + #define ST_CONNECT LIB3270_STATE_CONNECT + #define ST_3270_MODE LIB3270_STATE_3270_MODE + #define ST_LINE_MODE LIB3270_STATE_LINE_MODE + #define ST_REMODEL LIB3270_STATE_REMODEL + #define ST_PRINTER LIB3270_STATE_PRINTER + #define ST_EXITING LIB3270_STATE_EXITING + #define ST_CHARSET LIB3270_STATE_CHARSET + #define LIB3270_STATE_CHANGE LIB3270_STATE + + struct lib3270_state_callback; + typedef struct _h3270 { unsigned short sz; /**< Struct size */ @@ -138,10 +167,10 @@ char full_model_name[FULL_MODEL_NAME_SIZE+1]; char * model_name; int model_num; - char * termtype; + char * termtype; char * current_host; - unsigned short current_port; + unsigned short current_port; // screen info int ov_rows; @@ -149,9 +178,23 @@ int first_changed; int last_changed; + // Widget info + void * widget; + + /* State change callbacks. */ + struct lib3270_state_callback *st_callbacks[N_ST]; + struct lib3270_state_callback *st_last[N_ST]; } H3270; + struct lib3270_state_callback + { + struct lib3270_state_callback * next; /**< Next callback in chain */ + void * data; /**< User data */ + void (*func)(struct _h3270 *, int, void *); /**< Function to call */ + }; + + /** Type of dialog boxes */ typedef enum _PW3270_DIALOG { @@ -446,7 +489,7 @@ LIB3270_EXPORT int Register3270ScreenCallbacks(const struct lib3270_screen_callbacks *cbk); - LIB3270_EXPORT H3270 * new_3270_session(const char *model); + #define new_3270_session(m) lib3270_session_new(m) LIB3270_EXPORT const struct lib3270_option * get_3270_option_table(int sz); @@ -513,26 +556,12 @@ #include - /* Host connect/disconnect and state change. */ - typedef enum state_change - { - ST_RESOLVING, - ST_HALF_CONNECT, - ST_CONNECT, - ST_3270_MODE, - ST_LINE_MODE, - ST_REMODEL, - ST_PRINTER, - ST_EXITING, - ST_CHARSET, - - N_ST // Always the last one - } LIB3270_STATE_CHANGE; - LIB3270_EXPORT int host_connect(const char *n, int wait); LIB3270_EXPORT int host_reconnect(int wait); LIB3270_EXPORT void host_disconnect(H3270 *h, int disable); - LIB3270_EXPORT void register_schange(LIB3270_STATE_CHANGE tx, void (*func)(H3270 *, int)); + + #define register_schange(tx,func) lib3270_register_schange(NULL,tx,func,NULL) + LIB3270_EXPORT void lib3270_register_schange(H3270 *h,LIB3270_STATE tx, void (*func)(H3270 *, int, void *),void *user_data); /* Console/Trace window */ LIB3270_EXPORT HCONSOLE console_window_new(const char *title, const char *label); diff --git a/latest/src/lib/ansi.c b/latest/src/lib/ansi.c index d693734..ee6e8e2 100644 --- a/latest/src/lib/ansi.c +++ b/latest/src/lib/ansi.c @@ -1683,7 +1683,7 @@ ansi_scroll(void) /* Callback for when we enter ANSI mode. */ static void -ansi_in3270(H3270 *session, int in3270) +ansi_in3270(H3270 *session, int in3270, void *dunno) { if (!in3270) (void) ansi_reset(0, 0); diff --git a/latest/src/lib/ctlr.c b/latest/src/lib/ctlr.c index 3c43984..c9e6e82 100644 --- a/latest/src/lib/ctlr.c +++ b/latest/src/lib/ctlr.c @@ -99,8 +99,8 @@ static unsigned char default_bg; static unsigned char default_gr; static unsigned char default_cs; static unsigned char default_ic; -static void ctlr_half_connect(H3270 *session, int ignored); -static void ctlr_connect(H3270 *session, int ignored); +static void ctlr_half_connect(H3270 *session, int ignored, void *dunno); +static void ctlr_connect(H3270 *session, int ignored, void *dunno); static int sscp_start; static void ticking_stop(void); static void ctlr_add_ic(int baddr, unsigned char ic); @@ -282,7 +282,7 @@ set_formatted(void) * Called when a host is half connected. */ static void -ctlr_half_connect(H3270 *session, int ignored unused) +ctlr_half_connect(H3270 *session, int ignored unused, void *dunno) { ticking_start(True); } @@ -292,7 +292,7 @@ ctlr_half_connect(H3270 *session, int ignored unused) * Called when a host connects, disconnects, or changes ANSI/3270 modes. */ static void -ctlr_connect(H3270 *session, int ignored unused) +ctlr_connect(H3270 *session, int ignored unused, void *dunno) { ticking_stop(); status_untiming(); diff --git a/latest/src/lib/ft.c b/latest/src/lib/ft.c index 808ad2e..3cce6a3 100644 --- a/latest/src/lib/ft.c +++ b/latest/src/lib/ft.c @@ -57,8 +57,8 @@ #include "telnetc.h" #include "utilc.h" -static void ft_connected(H3270 *session, int ignored); -static void ft_in3270(H3270 *session, int ignored unused); +static void ft_connected(H3270 *session, int ignored, void *dunno); +static void ft_in3270(H3270 *session, int ignored unused, void *dunno); /* Macros. */ #define eos(s) strchr((s), '\0') @@ -372,14 +372,14 @@ ft_aborting(void) } /* Process a disconnect abort. */ -static void ft_connected(H3270 *session, int ignored) +static void ft_connected(H3270 *session, int ignored, void *dunno) { if (!CONNECTED && ft_state != FT_NONE) ft_complete(MSG_("ftDisconnected","Host disconnected, transfer cancelled")); } /* Process an abort from no longer being in 3270 mode. */ -static void ft_in3270(H3270 *session, int ignored) +static void ft_in3270(H3270 *session, int ignored, void *dunno) { if (!IN_3270 && ft_state != FT_NONE) ft_complete(MSG_("ftNot3270","Not in 3270 mode, transfer cancelled")); diff --git a/latest/src/lib/globals.h b/latest/src/lib/globals.h index 7feacce..8b10146 100644 --- a/latest/src/lib/globals.h +++ b/latest/src/lib/globals.h @@ -31,8 +31,8 @@ */ /* Autoconf settings. */ -#include /* autoconf settings */ -#include /* lib3270 API calls and defs */ +#include /* autoconf settings */ +#include /* lib3270 API calls and defs */ /* From glibconfig.h */ #if defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550) diff --git a/latest/src/lib/glue.c b/latest/src/lib/glue.c index fa829cb..1b8eca5 100644 --- a/latest/src/lib/glue.c +++ b/latest/src/lib/glue.c @@ -143,18 +143,7 @@ const char *toggle_names[N_TOGGLES] = "SmartPaste" }; -/** - * Create a new 3270 object (INCOMPLETE). - * - * This function will create and initialize a new 3270 session, but, now - * it just returns a static 3270 session structure. - * - * @param model Terminal model (Can be overrided by command-line options - * - * @return lib3270 internal session structure. - * - */ -H3270 * new_3270_session(const char *model) +H3270 * lib3270_session_new(const char *model) { static int configured = 0; diff --git a/latest/src/lib/host.c b/latest/src/lib/host.c index 33920f9..c55b2bb 100644 --- a/latest/src/lib/host.c +++ b/latest/src/lib/host.c @@ -972,18 +972,42 @@ save_recent(const char *hn) /* Support for state change callbacks. */ +/* struct st_callback { - struct st_callback * next; /**< Next callback in chain */ - H3270 * session; /**< Session owning this callback */ - void (*func)(H3270 *,int); /**< Callback method */ + struct st_callback * next; + H3270 * session; + void * data; + void (*func)(H3270 *, int, void *); }; + static struct st_callback *st_callbacks[N_ST]; static struct st_callback *st_last[N_ST]; +*/ /* Register a function interested in a state change. */ -void -register_schange(LIB3270_STATE_CHANGE tx, void (*func)(H3270 *, int)) +LIB3270_EXPORT void lib3270_register_schange(H3270 *h,LIB3270_STATE_CHANGE tx, void (*func)(H3270 *, int, void *),void *data) +{ + struct lib3270_state_callback *st; + + if(!h) + h = &h3270; + + st = (struct lib3270_state_callback *)Malloc(sizeof(*st)); + + st->func = func; + st->next = (struct lib3270_state_callback *)NULL; + + if (h->st_last[tx] != (struct lib3270_state_callback *)NULL) + h->st_last[tx]->next = st; + else + h->st_callbacks[tx] = st; + h->st_last[tx] = st; + +} + +/* +void register_schange(LIB3270_STATE_CHANGE tx, void (*func)(H3270 *, int)) { struct st_callback *st; @@ -998,16 +1022,19 @@ register_schange(LIB3270_STATE_CHANGE tx, void (*func)(H3270 *, int)) st_callbacks[tx] = st; st_last[tx] = st; } +*/ /* Signal a state change. */ -void -st_changed(int tx, int mode) +void lib3270_st_changed(H3270 *h, int tx, int mode) { - struct st_callback *st; + struct lib3270_state_callback *st; + + if(!h) + h = &h3270; - for (st = st_callbacks[tx];st != (struct st_callback *)NULL;st = st->next) + for (st = h->st_callbacks[tx];st != (struct lib3270_state_callback *)NULL;st = st->next) { - (*st->func)(&h3270,mode); + (*st->func)(h,mode,st->data); } } diff --git a/latest/src/lib/hostc.h b/latest/src/lib/hostc.h index 5054aba..8043ed5 100644 --- a/latest/src/lib/hostc.h +++ b/latest/src/lib/hostc.h @@ -35,7 +35,9 @@ extern void Disconnect_action(Widget w, XEvent *event, String *params, Cardinal *num_params); */ - LIB3270_INTERNAL void st_changed(int tx, int mode); + #define st_changed(tx,mode) lib3270_st_changed(NULL,tx,mode) + + LIB3270_INTERNAL void lib3270_st_changed(H3270 *h, int tx, int mode); LIB3270_INTERNAL void hostfile_init(void); LIB3270_INTERNAL void host_connected(void); LIB3270_INTERNAL void host_in3270(enum cstate); diff --git a/latest/src/lib/kybd.c b/latest/src/lib/kybd.c index 48dbb27..11d3203 100644 --- a/latest/src/lib/kybd.c +++ b/latest/src/lib/kybd.c @@ -404,8 +404,7 @@ kybd_inhibit(Boolean inhibit) /* * Called when a host connects or disconnects. */ -static void -kybd_connect(H3270 *session, int connected) +static void kybd_connect(H3270 *session, int connected, void *dunno) { if (kybdlock & KL_DEFERRED_UNLOCK) RemoveTimeOut(unlock_id); @@ -424,7 +423,7 @@ kybd_connect(H3270 *session, int connected) * Called when we switch between 3270 and ANSI modes. */ static void -kybd_in3270(H3270 *session, int in3270 unused) +kybd_in3270(H3270 *session, int in3270 unused, void *dunno) { if (kybdlock & KL_DEFERRED_UNLOCK) RemoveTimeOut(unlock_id); @@ -438,8 +437,7 @@ kybd_in3270(H3270 *session, int in3270 unused) /* * Called to initialize the keyboard logic. */ -void -kybd_init(void) +void kybd_init(void) { /* Register interest in connect and disconnect events. */ register_schange(ST_CONNECT, kybd_connect); diff --git a/latest/src/lib/printer.c b/latest/src/lib/printer.c index e4c98d0..2fa273e 100644 --- a/latest/src/lib/printer.c +++ b/latest/src/lib/printer.c @@ -101,8 +101,8 @@ static void printer_otimeout(H3270 *session); static void printer_etimeout(H3270 *session); static void printer_dump(struct pr3o *p, Boolean is_err, Boolean is_dead); #endif /*]*/ -static void printer_host_connect(H3270 *session, int connected unused); -static void printer_exiting(H3270 *session, int b unused); +static void printer_host_connect(H3270 *session, int connected unused, void *dunno); +static void printer_exiting(H3270 *session, int b unused, void *dunno); /* Globals */ @@ -657,7 +657,7 @@ printer_stop(void) /* The emulator is exiting. Make sure the printer session is cleaned up. */ static void -printer_exiting(H3270 *session, int b unused) +printer_exiting(H3270 *session, int b unused, void *dunno) { printer_stop(); } @@ -684,7 +684,7 @@ lu_callback(Widget w, XtPointer client_data, XtPointer call_data unused) /* Host connect/disconnect/3270-mode event. */ static void -printer_host_connect(H3270 *session, int connected unused) +printer_host_connect(H3270 *session, int connected unused, void *dunno) { if (IN_3270) { char *printer_lu = appres.printer_lu; diff --git a/latest/src/lib/screen.c b/latest/src/lib/screen.c index 3f139f3..72b59bd 100644 --- a/latest/src/lib/screen.c +++ b/latest/src/lib/screen.c @@ -89,12 +89,12 @@ enum ts { TS_AUTO, TS_ON, TS_OFF }; // int windows_cp = 0; -static void status_connect(H3270 *session, int ignored); -static void status_3270_mode(H3270 *session, int ignored); -static void status_printer(H3270 *session, int on); +static void status_connect(H3270 *session, int ignored, void *dunno); +static void status_3270_mode(H3270 *session, int ignored, void *dunno); +static void status_printer(H3270 *session, int on, void *dunno); static int color_from_fa(unsigned char fa); // static Boolean ts_value(const char *s, enum ts *tsp); -static void relabel(H3270 *session, int ignored); +static void relabel(H3270 *session, int ignored, void *dunno); void set_display_charset(char *dcs) { @@ -699,7 +699,7 @@ void status_lu(const char *lu) callbacks->lu(lu); } -static void status_connect(H3270 *session, int connected) +static void status_connect(H3270 *session, int connected, void *dunno) { STATUS_CODE id = STATUS_CODE_USER; @@ -727,7 +727,7 @@ static void status_connect(H3270 *session, int connected) } -static void status_3270_mode(H3270 *session, int ignored unused) +static void status_3270_mode(H3270 *session, int ignored unused, void *dunno) { Boolean oia_boxsolid = (IN_3270 && !IN_SSCP); if(oia_boxsolid) @@ -736,7 +736,7 @@ static void status_3270_mode(H3270 *session, int ignored unused) } -static void status_printer(H3270 *session, int on) +static void status_printer(H3270 *session, int on, void *dunno) { set(OIA_FLAG_PRINTER,on); } @@ -802,7 +802,7 @@ screen_title(char *text) } static void -relabel(H3270 *session, int ignored unused) +relabel(H3270 *session, int ignored unused, void *dunno) { #if defined(WC3270) /*[*/ if (appres.title != CN) -- libgit2 0.21.2