diff --git a/latest/src/include/lib3270.h b/latest/src/include/lib3270.h index 6f7ea7d..785fc7e 100644 --- a/latest/src/include/lib3270.h +++ b/latest/src/include/lib3270.h @@ -99,6 +99,14 @@ LIB3270_EXPORT H3270 * lib3270_session_new(const char *model); /** + * Destroy session, release memory + * + * @param h Session handle. + * + */ + LIB3270_EXPORT void lib3270_session_free(H3270 *h); + + /** * Register a state change callback * * @param h Session handle. diff --git a/latest/src/lib/ctlr.c b/latest/src/lib/ctlr.c index 85b1e63..1e98eed 100644 --- a/latest/src/lib/ctlr.c +++ b/latest/src/lib/ctlr.c @@ -148,13 +148,12 @@ static unsigned char code_table[64] = { /* * Initialize the emulated 3270 hardware. */ -void -ctlr_init(unsigned cmask unused) +void ctlr_init(H3270 *session, unsigned cmask unused) { /* Register callback routines. */ - register_schange(ST_HALF_CONNECT, ctlr_half_connect); - register_schange(ST_CONNECT, ctlr_connect); - register_schange(ST_3270_MODE, ctlr_connect); + lib3270_register_schange(session,ST_HALF_CONNECT, ctlr_half_connect, 0); + lib3270_register_schange(session,ST_CONNECT, ctlr_connect, 0); + lib3270_register_schange(session,ST_3270_MODE, ctlr_connect, 0); } /* * Reinitialize the emulated 3270 hardware. diff --git a/latest/src/lib/ctlrc.h b/latest/src/lib/ctlrc.h index f8c6e0c..60da827 100644 --- a/latest/src/lib/ctlrc.h +++ b/latest/src/lib/ctlrc.h @@ -37,7 +37,7 @@ LIB3270_INTERNAL void ctlr_bcopy(int baddr_from, int baddr_to, int count, int mo // LIB3270_INTERNAL void ctlr_changed(int bstart, int bend); LIB3270_INTERNAL void ctlr_clear(H3270 *session, Boolean can_snap); LIB3270_INTERNAL void ctlr_erase_all_unprotected(void); -LIB3270_INTERNAL void ctlr_init(unsigned cmask); +LIB3270_INTERNAL void ctlr_init(H3270 *session, unsigned cmask); LIB3270_INTERNAL void ctlr_read_buffer(unsigned char aid_byte); LIB3270_INTERNAL void ctlr_read_modified(unsigned char aid_byte, Boolean all); LIB3270_INTERNAL void ctlr_reinit(H3270 *session, unsigned cmask); diff --git a/latest/src/lib/glue.c b/latest/src/lib/glue.c index 212b582..7006374 100644 --- a/latest/src/lib/glue.c +++ b/latest/src/lib/glue.c @@ -143,25 +143,16 @@ const char *toggle_names[N_TOGGLES] = "SmartPaste" }; -H3270 * lib3270_session_new(const char *model) +void lib3270_session_free(H3270 *h) { - static int configured = 0; - - H3270 *hSession = &h3270; - int ovc, ovr; - int model_number; - char junk; - Trace("%s - configured=%d",__FUNCTION__,configured); - - if(configured) - { - // TODO (perry#5#): Allocate a new structure. - errno = EBUSY; - return hSession; - } +} - configured = 1; +void lib3270_session_init(H3270 *hSession, const char *model) +{ + int ovc, ovr; + char junk; + int model_number; memset(hSession,0,sizeof(H3270)); hSession->sz = sizeof(H3270); @@ -175,18 +166,6 @@ H3270 * lib3270_session_new(const char *model) strncpy(hSession->full_model_name,"IBM-",FULL_MODEL_NAME_SIZE); hSession->model_name = &hSession->full_model_name[4]; -#if defined(_WIN32) - - (void) get_version_info(); - - Trace("%s (init_calls: %d)",__FUNCTION__,init_calls); - -#else - - Trace("%s (init_calls: %d)",__FUNCTION__,init_calls); - -#endif - /* * Sort out model and color modes, based on the model number resource. */ @@ -243,6 +222,29 @@ H3270 * lib3270_session_new(const char *model) if (appres.apl_mode) appres.charset = Apl; +} + +H3270 * lib3270_session_new(const char *model) +{ + static int configured = 0; + + H3270 *hSession = &h3270; + + Trace("%s - configured=%d",__FUNCTION__,configured); + + if(configured) + { + // TODO (perry#5#): Allocate a new structure. + errno = EBUSY; + return hSession; + } + + configured = 1; + + lib3270_session_init(hSession, model); + + if(screen_init(hSession)) + return NULL; Trace("Charset: %s",appres.charset); if (charset_init(appres.charset) != CS_OKAY) @@ -251,9 +253,6 @@ H3270 * lib3270_session_new(const char *model) (void) charset_init(CN); } - if(screen_init(hSession)) - return NULL; - kybd_init(); // hostfile_init(); // hostfile_init(); @@ -287,6 +286,12 @@ static void initialize(void) initialize_toggles(); +#if defined(_WIN32) + (void) get_version_info(); +#endif + + Trace("%s (init_calls: %d)",__FUNCTION__,init_calls); + /* Set the defaults. */ appres.mono = False; appres.extended = True; diff --git a/latest/src/lib/macros.c b/latest/src/lib/macros.c index 17ce44e..6a85ada 100644 --- a/latest/src/lib/macros.c +++ b/latest/src/lib/macros.c @@ -66,7 +66,7 @@ return strdup(buffer); } - static const char * get_state(void) + static const char * get_state(H3270 *h) { #define DECLARE_XLAT_STATE(x) { x, #x } static const struct _xlat_state @@ -89,7 +89,7 @@ int f; - enum cstate state = QueryCstate(); + enum cstate state = lib3270_get_connection_state(h); for(f=0;f < (sizeof(xlat_state)/sizeof(struct _xlat_state)); f++) { @@ -214,14 +214,14 @@ if(str) Input_String((unsigned char *) str); - return strdup(get_state()); + return strdup(get_state(hSession)); } LIB3270_MACRO( status ) { - const char * luname = get_connected_lu(0); - const char * cstate = get_state(); - const char * host = get_current_host(0); + const char * luname = (const char *) get_connected_lu(hSession); + const char * cstate = get_state(hSession); + const char * host = (const char *) get_current_host(hSession); char * rsp; size_t sz; @@ -239,12 +239,12 @@ LIB3270_MACRO( cstate ) { - return strdup(get_state()); + return strdup(get_state(hSession)); } LIB3270_MACRO( luname ) { - const char * luname = get_connected_lu(hSession); + const char * luname = (const char *) get_connected_lu(hSession); return strdup(luname ? luname : "none" ); } diff --git a/latest/src/lib/screen.c b/latest/src/lib/screen.c index 71a3068..334c7d3 100644 --- a/latest/src/lib/screen.c +++ b/latest/src/lib/screen.c @@ -132,13 +132,13 @@ int screen_init(H3270 *session) } /* Set up callbacks for state changes. */ - register_schange(ST_CONNECT, status_connect); - register_schange(ST_3270_MODE, status_3270_mode); - register_schange(ST_PRINTER, status_printer); + lib3270_register_schange(session,ST_CONNECT, status_connect,0); + lib3270_register_schange(session,ST_3270_MODE, status_3270_mode,0); + lib3270_register_schange(session,ST_PRINTER, status_printer,0); - register_schange(ST_HALF_CONNECT, relabel); - register_schange(ST_CONNECT, relabel); - register_schange(ST_3270_MODE, relabel); + lib3270_register_schange(session,ST_HALF_CONNECT, relabel,0); + lib3270_register_schange(session,ST_CONNECT, relabel,0); + lib3270_register_schange(session,ST_3270_MODE, relabel,0); /* See about all-bold behavior. */ // if (appres.all_bold_on) @@ -149,7 +149,7 @@ int screen_init(H3270 *session) // ab_mode = appres.m3279? TS_ON: TS_OFF; /* Set up the controller. */ - ctlr_init(-1); + ctlr_init(session,-1); ctlr_reinit(session,-1); /* Set the window label. */ diff --git a/latest/src/lib/tesprogram.c b/latest/src/lib/tesprogram.c new file mode 100644 index 0000000..cd95032 --- /dev/null +++ b/latest/src/lib/tesprogram.c @@ -0,0 +1,16 @@ + +#include + +int main(int numpar, char *param[]) +{ + H3270 *h; + + h = lib3270_session_new(""); + + + + + lib3270_session_free(h); + + return 0; +} -- libgit2 0.21.2