Commit ae1ce6b4a060709f52b61b4504dfc62b972ddc30
1 parent
2426310f
Exists in
master
work in progress
Showing
7 changed files
with
80 additions
and
52 deletions
Show diff stats
latest/src/include/lib3270.h
... | ... | @@ -99,6 +99,14 @@ |
99 | 99 | LIB3270_EXPORT H3270 * lib3270_session_new(const char *model); |
100 | 100 | |
101 | 101 | /** |
102 | + * Destroy session, release memory | |
103 | + * | |
104 | + * @param h Session handle. | |
105 | + * | |
106 | + */ | |
107 | + LIB3270_EXPORT void lib3270_session_free(H3270 *h); | |
108 | + | |
109 | + /** | |
102 | 110 | * Register a state change callback |
103 | 111 | * |
104 | 112 | * @param h Session handle. | ... | ... |
latest/src/lib/ctlr.c
... | ... | @@ -148,13 +148,12 @@ static unsigned char code_table[64] = { |
148 | 148 | /* |
149 | 149 | * Initialize the emulated 3270 hardware. |
150 | 150 | */ |
151 | -void | |
152 | -ctlr_init(unsigned cmask unused) | |
151 | +void ctlr_init(H3270 *session, unsigned cmask unused) | |
153 | 152 | { |
154 | 153 | /* Register callback routines. */ |
155 | - register_schange(ST_HALF_CONNECT, ctlr_half_connect); | |
156 | - register_schange(ST_CONNECT, ctlr_connect); | |
157 | - register_schange(ST_3270_MODE, ctlr_connect); | |
154 | + lib3270_register_schange(session,ST_HALF_CONNECT, ctlr_half_connect, 0); | |
155 | + lib3270_register_schange(session,ST_CONNECT, ctlr_connect, 0); | |
156 | + lib3270_register_schange(session,ST_3270_MODE, ctlr_connect, 0); | |
158 | 157 | } |
159 | 158 | /* |
160 | 159 | * Reinitialize the emulated 3270 hardware. | ... | ... |
latest/src/lib/ctlrc.h
... | ... | @@ -37,7 +37,7 @@ LIB3270_INTERNAL void ctlr_bcopy(int baddr_from, int baddr_to, int count, int mo |
37 | 37 | // LIB3270_INTERNAL void ctlr_changed(int bstart, int bend); |
38 | 38 | LIB3270_INTERNAL void ctlr_clear(H3270 *session, Boolean can_snap); |
39 | 39 | LIB3270_INTERNAL void ctlr_erase_all_unprotected(void); |
40 | -LIB3270_INTERNAL void ctlr_init(unsigned cmask); | |
40 | +LIB3270_INTERNAL void ctlr_init(H3270 *session, unsigned cmask); | |
41 | 41 | LIB3270_INTERNAL void ctlr_read_buffer(unsigned char aid_byte); |
42 | 42 | LIB3270_INTERNAL void ctlr_read_modified(unsigned char aid_byte, Boolean all); |
43 | 43 | LIB3270_INTERNAL void ctlr_reinit(H3270 *session, unsigned cmask); | ... | ... |
latest/src/lib/glue.c
... | ... | @@ -143,25 +143,16 @@ const char *toggle_names[N_TOGGLES] = |
143 | 143 | "SmartPaste" |
144 | 144 | }; |
145 | 145 | |
146 | -H3270 * lib3270_session_new(const char *model) | |
146 | +void lib3270_session_free(H3270 *h) | |
147 | 147 | { |
148 | - static int configured = 0; | |
149 | - | |
150 | - H3270 *hSession = &h3270; | |
151 | - int ovc, ovr; | |
152 | - int model_number; | |
153 | - char junk; | |
154 | 148 | |
155 | - Trace("%s - configured=%d",__FUNCTION__,configured); | |
156 | - | |
157 | - if(configured) | |
158 | - { | |
159 | - // TODO (perry#5#): Allocate a new structure. | |
160 | - errno = EBUSY; | |
161 | - return hSession; | |
162 | - } | |
149 | +} | |
163 | 150 | |
164 | - configured = 1; | |
151 | +void lib3270_session_init(H3270 *hSession, const char *model) | |
152 | +{ | |
153 | + int ovc, ovr; | |
154 | + char junk; | |
155 | + int model_number; | |
165 | 156 | |
166 | 157 | memset(hSession,0,sizeof(H3270)); |
167 | 158 | hSession->sz = sizeof(H3270); |
... | ... | @@ -175,18 +166,6 @@ H3270 * lib3270_session_new(const char *model) |
175 | 166 | strncpy(hSession->full_model_name,"IBM-",FULL_MODEL_NAME_SIZE); |
176 | 167 | hSession->model_name = &hSession->full_model_name[4]; |
177 | 168 | |
178 | -#if defined(_WIN32) | |
179 | - | |
180 | - (void) get_version_info(); | |
181 | - | |
182 | - Trace("%s (init_calls: %d)",__FUNCTION__,init_calls); | |
183 | - | |
184 | -#else | |
185 | - | |
186 | - Trace("%s (init_calls: %d)",__FUNCTION__,init_calls); | |
187 | - | |
188 | -#endif | |
189 | - | |
190 | 169 | /* |
191 | 170 | * Sort out model and color modes, based on the model number resource. |
192 | 171 | */ |
... | ... | @@ -243,6 +222,29 @@ H3270 * lib3270_session_new(const char *model) |
243 | 222 | if (appres.apl_mode) |
244 | 223 | appres.charset = Apl; |
245 | 224 | |
225 | +} | |
226 | + | |
227 | +H3270 * lib3270_session_new(const char *model) | |
228 | +{ | |
229 | + static int configured = 0; | |
230 | + | |
231 | + H3270 *hSession = &h3270; | |
232 | + | |
233 | + Trace("%s - configured=%d",__FUNCTION__,configured); | |
234 | + | |
235 | + if(configured) | |
236 | + { | |
237 | + // TODO (perry#5#): Allocate a new structure. | |
238 | + errno = EBUSY; | |
239 | + return hSession; | |
240 | + } | |
241 | + | |
242 | + configured = 1; | |
243 | + | |
244 | + lib3270_session_init(hSession, model); | |
245 | + | |
246 | + if(screen_init(hSession)) | |
247 | + return NULL; | |
246 | 248 | |
247 | 249 | Trace("Charset: %s",appres.charset); |
248 | 250 | if (charset_init(appres.charset) != CS_OKAY) |
... | ... | @@ -251,9 +253,6 @@ H3270 * lib3270_session_new(const char *model) |
251 | 253 | (void) charset_init(CN); |
252 | 254 | } |
253 | 255 | |
254 | - if(screen_init(hSession)) | |
255 | - return NULL; | |
256 | - | |
257 | 256 | kybd_init(); |
258 | 257 | // hostfile_init(); |
259 | 258 | // hostfile_init(); |
... | ... | @@ -287,6 +286,12 @@ static void initialize(void) |
287 | 286 | |
288 | 287 | initialize_toggles(); |
289 | 288 | |
289 | +#if defined(_WIN32) | |
290 | + (void) get_version_info(); | |
291 | +#endif | |
292 | + | |
293 | + Trace("%s (init_calls: %d)",__FUNCTION__,init_calls); | |
294 | + | |
290 | 295 | /* Set the defaults. */ |
291 | 296 | appres.mono = False; |
292 | 297 | appres.extended = True; | ... | ... |
latest/src/lib/macros.c
... | ... | @@ -66,7 +66,7 @@ |
66 | 66 | return strdup(buffer); |
67 | 67 | } |
68 | 68 | |
69 | - static const char * get_state(void) | |
69 | + static const char * get_state(H3270 *h) | |
70 | 70 | { |
71 | 71 | #define DECLARE_XLAT_STATE(x) { x, #x } |
72 | 72 | static const struct _xlat_state |
... | ... | @@ -89,7 +89,7 @@ |
89 | 89 | |
90 | 90 | int f; |
91 | 91 | |
92 | - enum cstate state = QueryCstate(); | |
92 | + enum cstate state = lib3270_get_connection_state(h); | |
93 | 93 | |
94 | 94 | for(f=0;f < (sizeof(xlat_state)/sizeof(struct _xlat_state)); f++) |
95 | 95 | { |
... | ... | @@ -214,14 +214,14 @@ |
214 | 214 | if(str) |
215 | 215 | Input_String((unsigned char *) str); |
216 | 216 | |
217 | - return strdup(get_state()); | |
217 | + return strdup(get_state(hSession)); | |
218 | 218 | } |
219 | 219 | |
220 | 220 | LIB3270_MACRO( status ) |
221 | 221 | { |
222 | - const char * luname = get_connected_lu(0); | |
223 | - const char * cstate = get_state(); | |
224 | - const char * host = get_current_host(0); | |
222 | + const char * luname = (const char *) get_connected_lu(hSession); | |
223 | + const char * cstate = get_state(hSession); | |
224 | + const char * host = (const char *) get_current_host(hSession); | |
225 | 225 | char * rsp; |
226 | 226 | size_t sz; |
227 | 227 | |
... | ... | @@ -239,12 +239,12 @@ |
239 | 239 | |
240 | 240 | LIB3270_MACRO( cstate ) |
241 | 241 | { |
242 | - return strdup(get_state()); | |
242 | + return strdup(get_state(hSession)); | |
243 | 243 | } |
244 | 244 | |
245 | 245 | LIB3270_MACRO( luname ) |
246 | 246 | { |
247 | - const char * luname = get_connected_lu(hSession); | |
247 | + const char * luname = (const char *) get_connected_lu(hSession); | |
248 | 248 | return strdup(luname ? luname : "none" ); |
249 | 249 | } |
250 | 250 | ... | ... |
latest/src/lib/screen.c
... | ... | @@ -132,13 +132,13 @@ int screen_init(H3270 *session) |
132 | 132 | } |
133 | 133 | |
134 | 134 | /* Set up callbacks for state changes. */ |
135 | - register_schange(ST_CONNECT, status_connect); | |
136 | - register_schange(ST_3270_MODE, status_3270_mode); | |
137 | - register_schange(ST_PRINTER, status_printer); | |
135 | + lib3270_register_schange(session,ST_CONNECT, status_connect,0); | |
136 | + lib3270_register_schange(session,ST_3270_MODE, status_3270_mode,0); | |
137 | + lib3270_register_schange(session,ST_PRINTER, status_printer,0); | |
138 | 138 | |
139 | - register_schange(ST_HALF_CONNECT, relabel); | |
140 | - register_schange(ST_CONNECT, relabel); | |
141 | - register_schange(ST_3270_MODE, relabel); | |
139 | + lib3270_register_schange(session,ST_HALF_CONNECT, relabel,0); | |
140 | + lib3270_register_schange(session,ST_CONNECT, relabel,0); | |
141 | + lib3270_register_schange(session,ST_3270_MODE, relabel,0); | |
142 | 142 | |
143 | 143 | /* See about all-bold behavior. */ |
144 | 144 | // if (appres.all_bold_on) |
... | ... | @@ -149,7 +149,7 @@ int screen_init(H3270 *session) |
149 | 149 | // ab_mode = appres.m3279? TS_ON: TS_OFF; |
150 | 150 | |
151 | 151 | /* Set up the controller. */ |
152 | - ctlr_init(-1); | |
152 | + ctlr_init(session,-1); | |
153 | 153 | ctlr_reinit(session,-1); |
154 | 154 | |
155 | 155 | /* Set the window label. */ | ... | ... |