Commit 5da4b25db4b09799cf376d5565c43ae795a707db

Authored by perry.werneck@gmail.com
1 parent b9a695a9
Exists in master

Mais uma etapa na implementação do suporte a multiplas sessões: Callbacks de est…

…ado movidos para dentro da estrutura de controle de sessão
latest/src/gtk2/gui.h
... ... @@ -54,7 +54,7 @@
54 54 #define HAVE_DOCK 1
55 55 #endif
56 56  
57   - #include <lib3270/api.h>
  57 + #include <lib3270.h>
58 58 #include <lib3270/toggle.h>
59 59  
60 60 #define CURSOR_MODE_3270 (CURSOR_MODE_USER+9)
... ... @@ -244,7 +244,7 @@
244 244 {
245 245 POPUP_MENU_DEFAULT,
246 246 POPUP_MENU_SELECTION,
247   -
  247 +
248 248 POPUP_MENU_COUNT
249 249 };
250 250  
... ...
latest/src/gtk2/main.c
... ... @@ -76,7 +76,7 @@ static gchar * log_filename = NULL;
76 76 /*---[ Implement ]----------------------------------------------------------------------------------------------*/
77 77  
78 78 /* Callback for connection state changes. */
79   -static void connect_main(H3270 *session, int status)
  79 +static void connect_main(H3270 *session, int status, void *dunno)
80 80 {
81 81 gboolean online = (CONNECTED) ? TRUE : FALSE;
82 82  
... ... @@ -129,7 +129,7 @@ static void connect_main(H3270 *session, int status)
129 129  
130 130 }
131 131  
132   -static void connect_in3270(H3270 *session, int status)
  132 +static void connect_in3270(H3270 *session, int status, void *dunno)
133 133 {
134 134 #ifdef X3270_FT
135 135 action_group_set_sensitive(ACTION_GROUP_FT,status);
... ... @@ -622,8 +622,8 @@ int main(int argc, char *argv[])
622 622 return -1;
623 623 }
624 624  
625   - connect_main(hSession,0);
626   - connect_in3270(hSession,0);
  625 + connect_main(hSession,0,NULL);
  626 + connect_in3270(hSession,0,NULL);
627 627  
628 628 register_schange(ST_CONNECT, connect_main);
629 629 register_schange(ST_3270_MODE, connect_in3270);
... ...
latest/src/include/lib3270.h
... ... @@ -47,6 +47,30 @@
47 47 */
48 48 LIB3270_EXPORT void lib3270_get_screen_size(H3270 *h, int *r, int *c);
49 49  
  50 + /**
  51 + * Start a new session (INCOMPLETE).
  52 + *
  53 + * Initialize session structure, opens a new session.
  54 + * WARNING: Multi session ins't yet supported in lib3270, because of this
  55 + * this call always return the handle of the same session.
  56 + *
  57 + * @param model Terminal model.
  58 + *
  59 + * @return lib3270 internal session structure.
  60 + *
  61 + */
  62 + LIB3270_EXPORT H3270 * lib3270_session_new(const char *model);
  63 +
  64 + /**
  65 + * Register a state change callback
  66 + *
  67 + * @param h Session handle.
  68 + * @param tx State ID
  69 + * @param func Callback
  70 + * @param data Data
  71 + *
  72 + */
  73 + LIB3270_EXPORT void lib3270_register_schange(H3270 *h,LIB3270_STATE_CHANGE tx, void (*func)(H3270 *, int, void *),void *data);
50 74  
51   -#endif // LIB3270_H_INCLUDED
52 75  
  76 +#endif // LIB3270_H_INCLUDED
... ...
latest/src/include/lib3270/api.h
... ... @@ -118,6 +118,35 @@
118 118 #define FULL_MODEL_NAME_SIZE 13
119 119  
120 120  
  121 + /* State change IDs. */
  122 + typedef enum _lib3270_state
  123 + {
  124 + LIB3270_STATE_RESOLVING,
  125 + LIB3270_STATE_HALF_CONNECT,
  126 + LIB3270_STATE_CONNECT,
  127 + LIB3270_STATE_3270_MODE,
  128 + LIB3270_STATE_LINE_MODE,
  129 + LIB3270_STATE_REMODEL,
  130 + LIB3270_STATE_PRINTER,
  131 + LIB3270_STATE_EXITING,
  132 + LIB3270_STATE_CHARSET,
  133 +
  134 + N_ST // Always the last one
  135 + } LIB3270_STATE;
  136 +
  137 + #define ST_RESOLVING LIB3270_STATE_RESOLVING
  138 + #define ST_HALF_CONNECT LIB3270_STATE_HALF_CONNECT
  139 + #define ST_CONNECT LIB3270_STATE_CONNECT
  140 + #define ST_3270_MODE LIB3270_STATE_3270_MODE
  141 + #define ST_LINE_MODE LIB3270_STATE_LINE_MODE
  142 + #define ST_REMODEL LIB3270_STATE_REMODEL
  143 + #define ST_PRINTER LIB3270_STATE_PRINTER
  144 + #define ST_EXITING LIB3270_STATE_EXITING
  145 + #define ST_CHARSET LIB3270_STATE_CHARSET
  146 + #define LIB3270_STATE_CHANGE LIB3270_STATE
  147 +
  148 + struct lib3270_state_callback;
  149 +
121 150 typedef struct _h3270
122 151 {
123 152 unsigned short sz; /**< Struct size */
... ... @@ -138,10 +167,10 @@
138 167 char full_model_name[FULL_MODEL_NAME_SIZE+1];
139 168 char * model_name;
140 169 int model_num;
141   - char * termtype;
  170 + char * termtype;
142 171  
143 172 char * current_host;
144   - unsigned short current_port;
  173 + unsigned short current_port;
145 174  
146 175 // screen info
147 176 int ov_rows;
... ... @@ -149,9 +178,23 @@
149 178 int first_changed;
150 179 int last_changed;
151 180  
  181 + // Widget info
  182 + void * widget;
  183 +
  184 + /* State change callbacks. */
  185 + struct lib3270_state_callback *st_callbacks[N_ST];
  186 + struct lib3270_state_callback *st_last[N_ST];
152 187  
153 188 } H3270;
154 189  
  190 + struct lib3270_state_callback
  191 + {
  192 + struct lib3270_state_callback * next; /**< Next callback in chain */
  193 + void * data; /**< User data */
  194 + void (*func)(struct _h3270 *, int, void *); /**< Function to call */
  195 + };
  196 +
  197 +
155 198 /** Type of dialog boxes */
156 199 typedef enum _PW3270_DIALOG
157 200 {
... ... @@ -446,7 +489,7 @@
446 489  
447 490 LIB3270_EXPORT int Register3270ScreenCallbacks(const struct lib3270_screen_callbacks *cbk);
448 491  
449   - LIB3270_EXPORT H3270 * new_3270_session(const char *model);
  492 + #define new_3270_session(m) lib3270_session_new(m)
450 493  
451 494 LIB3270_EXPORT const struct lib3270_option * get_3270_option_table(int sz);
452 495  
... ... @@ -513,26 +556,12 @@
513 556  
514 557 #include <lib3270/actions.h>
515 558  
516   - /* Host connect/disconnect and state change. */
517   - typedef enum state_change
518   - {
519   - ST_RESOLVING,
520   - ST_HALF_CONNECT,
521   - ST_CONNECT,
522   - ST_3270_MODE,
523   - ST_LINE_MODE,
524   - ST_REMODEL,
525   - ST_PRINTER,
526   - ST_EXITING,
527   - ST_CHARSET,
528   -
529   - N_ST // Always the last one
530   - } LIB3270_STATE_CHANGE;
531   -
532 559 LIB3270_EXPORT int host_connect(const char *n, int wait);
533 560 LIB3270_EXPORT int host_reconnect(int wait);
534 561 LIB3270_EXPORT void host_disconnect(H3270 *h, int disable);
535   - LIB3270_EXPORT void register_schange(LIB3270_STATE_CHANGE tx, void (*func)(H3270 *, int));
  562 +
  563 + #define register_schange(tx,func) lib3270_register_schange(NULL,tx,func,NULL)
  564 + LIB3270_EXPORT void lib3270_register_schange(H3270 *h,LIB3270_STATE tx, void (*func)(H3270 *, int, void *),void *user_data);
536 565  
537 566 /* Console/Trace window */
538 567 LIB3270_EXPORT HCONSOLE console_window_new(const char *title, const char *label);
... ...
latest/src/lib/ansi.c
... ... @@ -1683,7 +1683,7 @@ ansi_scroll(void)
1683 1683  
1684 1684 /* Callback for when we enter ANSI mode. */
1685 1685 static void
1686   -ansi_in3270(H3270 *session, int in3270)
  1686 +ansi_in3270(H3270 *session, int in3270, void *dunno)
1687 1687 {
1688 1688 if (!in3270)
1689 1689 (void) ansi_reset(0, 0);
... ...
latest/src/lib/ctlr.c
... ... @@ -99,8 +99,8 @@ static unsigned char default_bg;
99 99 static unsigned char default_gr;
100 100 static unsigned char default_cs;
101 101 static unsigned char default_ic;
102   -static void ctlr_half_connect(H3270 *session, int ignored);
103   -static void ctlr_connect(H3270 *session, int ignored);
  102 +static void ctlr_half_connect(H3270 *session, int ignored, void *dunno);
  103 +static void ctlr_connect(H3270 *session, int ignored, void *dunno);
104 104 static int sscp_start;
105 105 static void ticking_stop(void);
106 106 static void ctlr_add_ic(int baddr, unsigned char ic);
... ... @@ -282,7 +282,7 @@ set_formatted(void)
282 282 * Called when a host is half connected.
283 283 */
284 284 static void
285   -ctlr_half_connect(H3270 *session, int ignored unused)
  285 +ctlr_half_connect(H3270 *session, int ignored unused, void *dunno)
286 286 {
287 287 ticking_start(True);
288 288 }
... ... @@ -292,7 +292,7 @@ ctlr_half_connect(H3270 *session, int ignored unused)
292 292 * Called when a host connects, disconnects, or changes ANSI/3270 modes.
293 293 */
294 294 static void
295   -ctlr_connect(H3270 *session, int ignored unused)
  295 +ctlr_connect(H3270 *session, int ignored unused, void *dunno)
296 296 {
297 297 ticking_stop();
298 298 status_untiming();
... ...
latest/src/lib/ft.c
... ... @@ -57,8 +57,8 @@
57 57 #include "telnetc.h"
58 58 #include "utilc.h"
59 59  
60   -static void ft_connected(H3270 *session, int ignored);
61   -static void ft_in3270(H3270 *session, int ignored unused);
  60 +static void ft_connected(H3270 *session, int ignored, void *dunno);
  61 +static void ft_in3270(H3270 *session, int ignored unused, void *dunno);
62 62  
63 63 /* Macros. */
64 64 #define eos(s) strchr((s), '\0')
... ... @@ -372,14 +372,14 @@ ft_aborting(void)
372 372 }
373 373  
374 374 /* Process a disconnect abort. */
375   -static void ft_connected(H3270 *session, int ignored)
  375 +static void ft_connected(H3270 *session, int ignored, void *dunno)
376 376 {
377 377 if (!CONNECTED && ft_state != FT_NONE)
378 378 ft_complete(MSG_("ftDisconnected","Host disconnected, transfer cancelled"));
379 379 }
380 380  
381 381 /* Process an abort from no longer being in 3270 mode. */
382   -static void ft_in3270(H3270 *session, int ignored)
  382 +static void ft_in3270(H3270 *session, int ignored, void *dunno)
383 383 {
384 384 if (!IN_3270 && ft_state != FT_NONE)
385 385 ft_complete(MSG_("ftNot3270","Not in 3270 mode, transfer cancelled"));
... ...
latest/src/lib/globals.h
... ... @@ -31,8 +31,8 @@
31 31 */
32 32  
33 33 /* Autoconf settings. */
34   -#include <lib3270/config.h> /* autoconf settings */
35   -#include <lib3270/api.h> /* lib3270 API calls and defs */
  34 +#include <lib3270/config.h> /* autoconf settings */
  35 +#include <lib3270.h> /* lib3270 API calls and defs */
36 36  
37 37 /* From glibconfig.h */
38 38 #if defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550)
... ...
latest/src/lib/glue.c
... ... @@ -143,18 +143,7 @@ const char *toggle_names[N_TOGGLES] =
143 143 "SmartPaste"
144 144 };
145 145  
146   -/**
147   - * Create a new 3270 object (INCOMPLETE).
148   - *
149   - * This function will create and initialize a new 3270 session, but, now
150   - * it just returns a static 3270 session structure.
151   - *
152   - * @param model Terminal model (Can be overrided by command-line options
153   - *
154   - * @return lib3270 internal session structure.
155   - *
156   - */
157   -H3270 * new_3270_session(const char *model)
  146 +H3270 * lib3270_session_new(const char *model)
158 147 {
159 148 static int configured = 0;
160 149  
... ...
latest/src/lib/host.c
... ... @@ -972,18 +972,42 @@ save_recent(const char *hn)
972 972  
973 973 /* Support for state change callbacks. */
974 974  
  975 +/*
975 976 struct st_callback
976 977 {
977   - struct st_callback * next; /**< Next callback in chain */
978   - H3270 * session; /**< Session owning this callback */
979   - void (*func)(H3270 *,int); /**< Callback method */
  978 + struct st_callback * next;
  979 + H3270 * session;
  980 + void * data;
  981 + void (*func)(H3270 *, int, void *);
980 982 };
  983 +
981 984 static struct st_callback *st_callbacks[N_ST];
982 985 static struct st_callback *st_last[N_ST];
  986 +*/
983 987  
984 988 /* Register a function interested in a state change. */
985   -void
986   -register_schange(LIB3270_STATE_CHANGE tx, void (*func)(H3270 *, int))
  989 +LIB3270_EXPORT void lib3270_register_schange(H3270 *h,LIB3270_STATE_CHANGE tx, void (*func)(H3270 *, int, void *),void *data)
  990 +{
  991 + struct lib3270_state_callback *st;
  992 +
  993 + if(!h)
  994 + h = &h3270;
  995 +
  996 + st = (struct lib3270_state_callback *)Malloc(sizeof(*st));
  997 +
  998 + st->func = func;
  999 + st->next = (struct lib3270_state_callback *)NULL;
  1000 +
  1001 + if (h->st_last[tx] != (struct lib3270_state_callback *)NULL)
  1002 + h->st_last[tx]->next = st;
  1003 + else
  1004 + h->st_callbacks[tx] = st;
  1005 + h->st_last[tx] = st;
  1006 +
  1007 +}
  1008 +
  1009 +/*
  1010 +void register_schange(LIB3270_STATE_CHANGE tx, void (*func)(H3270 *, int))
987 1011 {
988 1012 struct st_callback *st;
989 1013  
... ... @@ -998,16 +1022,19 @@ register_schange(LIB3270_STATE_CHANGE tx, void (*func)(H3270 *, int))
998 1022 st_callbacks[tx] = st;
999 1023 st_last[tx] = st;
1000 1024 }
  1025 +*/
1001 1026  
1002 1027 /* Signal a state change. */
1003   -void
1004   -st_changed(int tx, int mode)
  1028 +void lib3270_st_changed(H3270 *h, int tx, int mode)
1005 1029 {
1006   - struct st_callback *st;
  1030 + struct lib3270_state_callback *st;
  1031 +
  1032 + if(!h)
  1033 + h = &h3270;
1007 1034  
1008   - for (st = st_callbacks[tx];st != (struct st_callback *)NULL;st = st->next)
  1035 + for (st = h->st_callbacks[tx];st != (struct lib3270_state_callback *)NULL;st = st->next)
1009 1036 {
1010   - (*st->func)(&h3270,mode);
  1037 + (*st->func)(h,mode,st->data);
1011 1038 }
1012 1039 }
1013 1040  
... ...
latest/src/lib/hostc.h
... ... @@ -35,7 +35,9 @@
35 35 extern void Disconnect_action(Widget w, XEvent *event, String *params, Cardinal *num_params);
36 36 */
37 37  
38   - LIB3270_INTERNAL void st_changed(int tx, int mode);
  38 + #define st_changed(tx,mode) lib3270_st_changed(NULL,tx,mode)
  39 +
  40 + LIB3270_INTERNAL void lib3270_st_changed(H3270 *h, int tx, int mode);
39 41 LIB3270_INTERNAL void hostfile_init(void);
40 42 LIB3270_INTERNAL void host_connected(void);
41 43 LIB3270_INTERNAL void host_in3270(enum cstate);
... ...
latest/src/lib/kybd.c
... ... @@ -404,8 +404,7 @@ kybd_inhibit(Boolean inhibit)
404 404 /*
405 405 * Called when a host connects or disconnects.
406 406 */
407   -static void
408   -kybd_connect(H3270 *session, int connected)
  407 +static void kybd_connect(H3270 *session, int connected, void *dunno)
409 408 {
410 409 if (kybdlock & KL_DEFERRED_UNLOCK)
411 410 RemoveTimeOut(unlock_id);
... ... @@ -424,7 +423,7 @@ kybd_connect(H3270 *session, int connected)
424 423 * Called when we switch between 3270 and ANSI modes.
425 424 */
426 425 static void
427   -kybd_in3270(H3270 *session, int in3270 unused)
  426 +kybd_in3270(H3270 *session, int in3270 unused, void *dunno)
428 427 {
429 428 if (kybdlock & KL_DEFERRED_UNLOCK)
430 429 RemoveTimeOut(unlock_id);
... ... @@ -438,8 +437,7 @@ kybd_in3270(H3270 *session, int in3270 unused)
438 437 /*
439 438 * Called to initialize the keyboard logic.
440 439 */
441   -void
442   -kybd_init(void)
  440 +void kybd_init(void)
443 441 {
444 442 /* Register interest in connect and disconnect events. */
445 443 register_schange(ST_CONNECT, kybd_connect);
... ...
latest/src/lib/printer.c
... ... @@ -101,8 +101,8 @@ static void printer_otimeout(H3270 *session);
101 101 static void printer_etimeout(H3270 *session);
102 102 static void printer_dump(struct pr3o *p, Boolean is_err, Boolean is_dead);
103 103 #endif /*]*/
104   -static void printer_host_connect(H3270 *session, int connected unused);
105   -static void printer_exiting(H3270 *session, int b unused);
  104 +static void printer_host_connect(H3270 *session, int connected unused, void *dunno);
  105 +static void printer_exiting(H3270 *session, int b unused, void *dunno);
106 106  
107 107 /* Globals */
108 108  
... ... @@ -657,7 +657,7 @@ printer_stop(void)
657 657  
658 658 /* The emulator is exiting. Make sure the printer session is cleaned up. */
659 659 static void
660   -printer_exiting(H3270 *session, int b unused)
  660 +printer_exiting(H3270 *session, int b unused, void *dunno)
661 661 {
662 662 printer_stop();
663 663 }
... ... @@ -684,7 +684,7 @@ lu_callback(Widget w, XtPointer client_data, XtPointer call_data unused)
684 684  
685 685 /* Host connect/disconnect/3270-mode event. */
686 686 static void
687   -printer_host_connect(H3270 *session, int connected unused)
  687 +printer_host_connect(H3270 *session, int connected unused, void *dunno)
688 688 {
689 689 if (IN_3270) {
690 690 char *printer_lu = appres.printer_lu;
... ...
latest/src/lib/screen.c
... ... @@ -89,12 +89,12 @@ enum ts { TS_AUTO, TS_ON, TS_OFF };
89 89  
90 90 // int windows_cp = 0;
91 91  
92   -static void status_connect(H3270 *session, int ignored);
93   -static void status_3270_mode(H3270 *session, int ignored);
94   -static void status_printer(H3270 *session, int on);
  92 +static void status_connect(H3270 *session, int ignored, void *dunno);
  93 +static void status_3270_mode(H3270 *session, int ignored, void *dunno);
  94 +static void status_printer(H3270 *session, int on, void *dunno);
95 95 static int color_from_fa(unsigned char fa);
96 96 // static Boolean ts_value(const char *s, enum ts *tsp);
97   -static void relabel(H3270 *session, int ignored);
  97 +static void relabel(H3270 *session, int ignored, void *dunno);
98 98  
99 99 void set_display_charset(char *dcs)
100 100 {
... ... @@ -699,7 +699,7 @@ void status_lu(const char *lu)
699 699 callbacks->lu(lu);
700 700 }
701 701  
702   -static void status_connect(H3270 *session, int connected)
  702 +static void status_connect(H3270 *session, int connected, void *dunno)
703 703 {
704 704 STATUS_CODE id = STATUS_CODE_USER;
705 705  
... ... @@ -727,7 +727,7 @@ static void status_connect(H3270 *session, int connected)
727 727  
728 728 }
729 729  
730   -static void status_3270_mode(H3270 *session, int ignored unused)
  730 +static void status_3270_mode(H3270 *session, int ignored unused, void *dunno)
731 731 {
732 732 Boolean oia_boxsolid = (IN_3270 && !IN_SSCP);
733 733 if(oia_boxsolid)
... ... @@ -736,7 +736,7 @@ static void status_3270_mode(H3270 *session, int ignored unused)
736 736  
737 737 }
738 738  
739   -static void status_printer(H3270 *session, int on)
  739 +static void status_printer(H3270 *session, int on, void *dunno)
740 740 {
741 741 set(OIA_FLAG_PRINTER,on);
742 742 }
... ... @@ -802,7 +802,7 @@ screen_title(char *text)
802 802 }
803 803  
804 804 static void
805   -relabel(H3270 *session, int ignored unused)
  805 +relabel(H3270 *session, int ignored unused, void *dunno)
806 806 {
807 807 #if defined(WC3270) /*[*/
808 808 if (appres.title != CN)
... ...