Commit 953f5b57cde6ccc40574ec2e00a5587bfd3ccf74
1 parent
36eda0f8
Exists in
master
and in
3 other branches
popup and trace handlers are now set by session instead of global.
Showing
6 changed files
with
38 additions
and
33 deletions
Show diff stats
src/include/lib3270/popup.h
| ... | ... | @@ -51,6 +51,8 @@ |
| 51 | 51 | LIB3270_NOTIFY_USER /**< Reserved, always the last one */ |
| 52 | 52 | } LIB3270_NOTIFY; |
| 53 | 53 | |
| 54 | + LIB3270_EXPORT void lib3270_set_popup_handler(H3270 *session, int (*handler)(H3270 *, LIB3270_NOTIFY, const char *, const char *, const char *, va_list)); | |
| 55 | + | |
| 54 | 56 | /** |
| 55 | 57 | * Pop up an error dialog, based on an error number. |
| 56 | 58 | * | ... | ... |
src/include/lib3270/session.h
| ... | ... | @@ -76,8 +76,10 @@ |
| 76 | 76 | void (*autostart)(H3270 *session); |
| 77 | 77 | int (*print)(H3270 *session); |
| 78 | 78 | |
| 79 | + | |
| 79 | 80 | void (*message)(H3270 *session, LIB3270_NOTIFY id , const char *title, const char *message, const char *text); |
| 80 | 81 | void (*popup)(H3270 *session, LIB3270_NOTIFY id, const char *title, const char *msg, const char *fmt, va_list); |
| 82 | + void (*trace)(H3270 *session, const char *fmt, va_list args); | |
| 81 | 83 | |
| 82 | 84 | #ifdef HAVE_LIBSSL |
| 83 | 85 | void (*set_peer_certificate)(const X509 *cert); | ... | ... |
src/include/lib3270/trace.h
| ... | ... | @@ -53,7 +53,7 @@ |
| 53 | 53 | * |
| 54 | 54 | * @return Current trace handler |
| 55 | 55 | */ |
| 56 | - LIB3270_EXPORT LIB3270_TRACE_HANDLER lib3270_set_trace_handler( LIB3270_TRACE_HANDLER handler); | |
| 56 | + LIB3270_EXPORT LIB3270_TRACE_HANDLER lib3270_set_trace_handler(H3270 *session, LIB3270_TRACE_HANDLER handler); | |
| 57 | 57 | |
| 58 | 58 | /** |
| 59 | 59 | * Write on trace file. | ... | ... |
src/lib3270/session.c
| ... | ... | @@ -44,6 +44,8 @@ |
| 44 | 44 | #include "kybdc.h" |
| 45 | 45 | #include "3270ds.h" |
| 46 | 46 | #include "popupsc.h" |
| 47 | +#include <lib3270/trace.h> | |
| 48 | + | |
| 47 | 49 | |
| 48 | 50 | /*---[ Globals ]--------------------------------------------------------------------------------------------------------------*/ |
| 49 | 51 | |
| ... | ... | @@ -163,7 +165,7 @@ static void message(H3270 *session, LIB3270_NOTIFY id , const char *title, const |
| 163 | 165 | #endif // ANDROID |
| 164 | 166 | } |
| 165 | 167 | |
| 166 | -static int popup(H3270 *session, LIB3270_NOTIFY type, const char *title, const char *msg, const char *fmt, va_list arg) | |
| 168 | +static int def_popup(H3270 *session, LIB3270_NOTIFY type, const char *title, const char *msg, const char *fmt, va_list arg) | |
| 167 | 169 | { |
| 168 | 170 | #ifdef ANDROID |
| 169 | 171 | char *mask = xs_buffer("%s\n",fmt); |
| ... | ... | @@ -177,6 +179,12 @@ static int popup(H3270 *session, LIB3270_NOTIFY type, const char *title, const c |
| 177 | 179 | return 0; |
| 178 | 180 | } |
| 179 | 181 | |
| 182 | +static void def_trace(H3270 *session, const char *fmt, va_list args) | |
| 183 | +{ | |
| 184 | + vfprintf(stdout,fmt,args); | |
| 185 | + fflush(stdout); | |
| 186 | +} | |
| 187 | + | |
| 180 | 188 | static void update_ssl(H3270 *session, LIB3270_SSL_STATE state) |
| 181 | 189 | { |
| 182 | 190 | } |
| ... | ... | @@ -233,7 +241,8 @@ static void lib3270_session_init(H3270 *hSession, const char *model, const char |
| 233 | 241 | hSession->cbk.update_selection = update_selection; |
| 234 | 242 | hSession->cbk.cursor = set_cursor; |
| 235 | 243 | hSession->cbk.message = message; |
| 236 | - hSession->cbk.popup = popup; | |
| 244 | + hSession->cbk.trace = def_trace; | |
| 245 | + hSession->cbk.popup = def_popup; | |
| 237 | 246 | hSession->cbk.update_ssl = update_ssl; |
| 238 | 247 | hSession->cbk.display = screen_disp; |
| 239 | 248 | hSession->cbk.set_width = nop_int; |
| ... | ... | @@ -282,6 +291,17 @@ static void lib3270_session_init(H3270 *hSession, const char *model, const char |
| 282 | 291 | |
| 283 | 292 | } |
| 284 | 293 | |
| 294 | +LIB3270_EXPORT LIB3270_TRACE_HANDLER lib3270_set_trace_handler(H3270 *session, LIB3270_TRACE_HANDLER handler) | |
| 295 | +{ | |
| 296 | + void (*ret)(H3270 *session, const char *fmt, va_list args) = session->cbk.trace; | |
| 297 | + session->cbk.trace = handler ? handler : def_trace; | |
| 298 | + return ret; | |
| 299 | +} | |
| 300 | + | |
| 301 | +LIB3270_EXPORT void lib3270_set_popup_handler(H3270 *session, int (*handler)(H3270 *, LIB3270_NOTIFY, const char *, const char *, const char *, va_list)) { | |
| 302 | + session->cbk.popup = handler ? handler : def_popup; | |
| 303 | +} | |
| 304 | + | |
| 285 | 305 | H3270 * lib3270_session_new(const char *model) |
| 286 | 306 | { |
| 287 | 307 | H3270 * hSession; | ... | ... |
src/lib3270/trace_ds.c
| ... | ... | @@ -69,18 +69,10 @@ |
| 69 | 69 | #define MAX_HEADER_SIZE (10*1024) |
| 70 | 70 | |
| 71 | 71 | |
| 72 | +#undef trace | |
| 73 | + | |
| 72 | 74 | /* Statics */ |
| 73 | -static void __vwtrace(H3270 *session, const char *fmt, va_list args); | |
| 74 | 75 | static void wtrace(H3270 *session, const char *fmt, ...); |
| 75 | -static void (*vwtrace)(H3270 *session, const char *fmt, va_list args) = __vwtrace; | |
| 76 | - | |
| 77 | - | |
| 78 | -LIB3270_EXPORT LIB3270_TRACE_HANDLER lib3270_set_trace_handler( LIB3270_TRACE_HANDLER handler ) | |
| 79 | -{ | |
| 80 | - void (*ret)(H3270 *session, const char *fmt, va_list args) = vwtrace; | |
| 81 | - vwtrace = handler ? handler : __vwtrace; | |
| 82 | - return ret; | |
| 83 | -} | |
| 84 | 76 | |
| 85 | 77 | /* display a (row,col) */ |
| 86 | 78 | const char * rcba(H3270 *hSession, int baddr) |
| ... | ... | @@ -169,36 +161,25 @@ void trace_ds_nb(H3270 *hSession, const char *fmt, ...) |
| 169 | 161 | } |
| 170 | 162 | |
| 171 | 163 | /* Conditional data stream trace, without line splitting. */ |
| 172 | -void trace_dsn(H3270 *hSession, const char *fmt, ...) | |
| 164 | +void trace_dsn(H3270 *session, const char *fmt, ...) | |
| 173 | 165 | { |
| 174 | 166 | va_list args; |
| 175 | 167 | |
| 176 | - if (!lib3270_get_toggle(hSession,DS_TRACE)) | |
| 168 | + if (!lib3270_get_toggle(session,DS_TRACE)) | |
| 177 | 169 | return; |
| 178 | 170 | |
| 179 | 171 | /* print out message */ |
| 180 | 172 | va_start(args, fmt); |
| 181 | - vwtrace(hSession,fmt, args); | |
| 173 | + session->cbk.trace(session,fmt, args); | |
| 182 | 174 | va_end(args); |
| 183 | 175 | } |
| 184 | 176 | |
| 185 | -/* | |
| 186 | - * Write to the trace file, varargs style. | |
| 187 | - * This is the only function that actually does output to the trace file -- | |
| 188 | - * all others are wrappers around this function. | |
| 189 | - */ | |
| 190 | -static void __vwtrace(H3270 *session, const char *fmt, va_list args) | |
| 191 | -{ | |
| 192 | - vfprintf(stdout,fmt,args); | |
| 193 | - fflush(stdout); | |
| 194 | -} | |
| 195 | - | |
| 196 | 177 | /* Write to the trace file. */ |
| 197 | -static void wtrace(H3270 *hSession, const char *fmt, ...) | |
| 178 | +static void wtrace(H3270 *session, const char *fmt, ...) | |
| 198 | 179 | { |
| 199 | 180 | va_list args; |
| 200 | 181 | va_start(args, fmt); |
| 201 | - vwtrace(hSession,fmt, args); | |
| 182 | + session->cbk.trace(session,fmt, args); | |
| 202 | 183 | va_end(args); |
| 203 | 184 | } |
| 204 | 185 | |
| ... | ... | @@ -210,7 +191,7 @@ LIB3270_EXPORT void lib3270_write_dstrace(H3270 *session, const char *fmt, ...) |
| 210 | 191 | return; |
| 211 | 192 | |
| 212 | 193 | va_start(args, fmt); |
| 213 | - vwtrace(session,fmt, args); | |
| 194 | + session->cbk.trace(session,fmt, args); | |
| 214 | 195 | va_end(args); |
| 215 | 196 | } |
| 216 | 197 | |
| ... | ... | @@ -222,7 +203,7 @@ LIB3270_EXPORT void lib3270_write_nettrace(H3270 *session, const char *fmt, ...) |
| 222 | 203 | return; |
| 223 | 204 | |
| 224 | 205 | va_start(args, fmt); |
| 225 | - vwtrace(session,fmt, args); | |
| 206 | + session->cbk.trace(session,fmt, args); | |
| 226 | 207 | va_end(args); |
| 227 | 208 | } |
| 228 | 209 | |
| ... | ... | @@ -235,7 +216,7 @@ LIB3270_EXPORT void lib3270_trace_event(H3270 *session, const char *fmt, ...) |
| 235 | 216 | return; |
| 236 | 217 | |
| 237 | 218 | va_start(args, fmt); |
| 238 | - vwtrace(session,fmt, args); | |
| 219 | + session->cbk.trace(session,fmt, args); | |
| 239 | 220 | va_end(args); |
| 240 | 221 | } |
| 241 | 222 | ... | ... |
src/testprogram/testprogram.c