Commit a1115f2267c8a0fb97d2ad828d50560f77a35b09
1 parent
5ba60f6d
Exists in
master
Vinculando ativação de funções em thread separada à estrutura de sessão
Showing
5 changed files
with
30 additions
and
13 deletions
Show diff stats
latest/src/gtk2/iocallback.c
@@ -51,7 +51,7 @@ | @@ -51,7 +51,7 @@ | ||
51 | #include "oia.h" | 51 | #include "oia.h" |
52 | 52 | ||
53 | #ifdef G_THREADS_ENABLED | 53 | #ifdef G_THREADS_ENABLED |
54 | - static int static_CallAndWait(int(*callback)(void *), H3270 *session, void *parm); | 54 | + static int static_CallAndWait(int(*callback)(H3270 *session, void *), H3270 *session, void *parm); |
55 | #endif | 55 | #endif |
56 | 56 | ||
57 | static unsigned long static_AddInput(int source, H3270 *session, void (*fn)(H3270 *session)); | 57 | static unsigned long static_AddInput(int source, H3270 *session, void (*fn)(H3270 *session)); |
@@ -288,8 +288,9 @@ static gboolean IO_closure(gpointer data) | @@ -288,8 +288,9 @@ static gboolean IO_closure(gpointer data) | ||
288 | struct bgParameter | 288 | struct bgParameter |
289 | { | 289 | { |
290 | gboolean running; | 290 | gboolean running; |
291 | + H3270 *session; | ||
291 | int rc; | 292 | int rc; |
292 | - int(*callback)(void *); | 293 | + int(*callback)(H3270 *session, void *); |
293 | void *parm; | 294 | void *parm; |
294 | 295 | ||
295 | }; | 296 | }; |
@@ -297,15 +298,15 @@ struct bgParameter | @@ -297,15 +298,15 @@ struct bgParameter | ||
297 | gpointer BgCall(struct bgParameter *p) | 298 | gpointer BgCall(struct bgParameter *p) |
298 | { | 299 | { |
299 | Trace("%s starts",__FUNCTION__); | 300 | Trace("%s starts",__FUNCTION__); |
300 | - p->rc = p->callback(p->parm); | 301 | + p->rc = p->callback(p->session,p->parm); |
301 | p->running = FALSE; | 302 | p->running = FALSE; |
302 | Trace("%s ends",__FUNCTION__); | 303 | Trace("%s ends",__FUNCTION__); |
303 | return 0; | 304 | return 0; |
304 | } | 305 | } |
305 | 306 | ||
306 | -static int static_CallAndWait(int(*callback)(void *), H3270 *session, void *parm) | 307 | +static int static_CallAndWait(int(*callback)(H3270 *session, void *), H3270 *session, void *parm) |
307 | { | 308 | { |
308 | - struct bgParameter p = { TRUE, -1, callback, parm }; | 309 | + struct bgParameter p = { TRUE, session, -1, callback, parm }; |
309 | GThread *thread; | 310 | GThread *thread; |
310 | 311 | ||
311 | Trace("Starting auxiliary thread for callback %p",callback); | 312 | Trace("Starting auxiliary thread for callback %p",callback); |
latest/src/include/lib3270.h
@@ -292,4 +292,18 @@ | @@ -292,4 +292,18 @@ | ||
292 | LIB3270_EXPORT int lib3270_in_tn3270e(H3270 *h); | 292 | LIB3270_EXPORT int lib3270_in_tn3270e(H3270 *h); |
293 | LIB3270_EXPORT int lib3270_in_e(H3270 *h); | 293 | LIB3270_EXPORT int lib3270_in_e(H3270 *h); |
294 | 294 | ||
295 | + /** | ||
296 | + * Call non gui function. | ||
297 | + * | ||
298 | + * Call informed function in a separate thread, keep gui main loop running until | ||
299 | + * the function returns. | ||
300 | + * | ||
301 | + * @param callback Function to call. | ||
302 | + * @param h Related session (for timer indicator) | ||
303 | + * @param parm Parameter to be passed to the function. | ||
304 | + * | ||
305 | + */ | ||
306 | + LIB3270_EXPORT int lib3270_call_thread(int(*callback)(H3270 *h, void *), H3270 *h, void *parm); | ||
307 | + | ||
308 | + | ||
295 | #endif // LIB3270_H_INCLUDED | 309 | #endif // LIB3270_H_INCLUDED |
latest/src/include/lib3270/api.h
@@ -435,7 +435,7 @@ | @@ -435,7 +435,7 @@ | ||
435 | unsigned long (*AddOutput)(int source, H3270 *session, void (*fn)(H3270 *session)); | 435 | unsigned long (*AddOutput)(int source, H3270 *session, void (*fn)(H3270 *session)); |
436 | #endif /*]*/ | 436 | #endif /*]*/ |
437 | 437 | ||
438 | - int (*CallAndWait)(int(*callback)(void *), H3270 *session, void *parm); | 438 | + int (*callthread)(int(*callback)(H3270 *, void *), H3270 *session, void *parm); |
439 | 439 | ||
440 | int (*Wait)(int seconds); | 440 | int (*Wait)(int seconds); |
441 | int (*RunPendingEvents)(int wait); | 441 | int (*RunPendingEvents)(int wait); |
@@ -593,8 +593,8 @@ | @@ -593,8 +593,8 @@ | ||
593 | LIB3270_EXPORT SCRIPT_STATE status_script(SCRIPT_STATE state); | 593 | LIB3270_EXPORT SCRIPT_STATE status_script(SCRIPT_STATE state); |
594 | 594 | ||
595 | #define Toggled(ix) lib3270_get_toogle(NULL,ix) | 595 | #define Toggled(ix) lib3270_get_toogle(NULL,ix) |
596 | + #define CallAndWait(c,h,p) lib3270_call_thread(c,h,p) | ||
596 | 597 | ||
597 | - LIB3270_EXPORT int CallAndWait(int(*callback)(void *), H3270 *session, void *parm); | ||
598 | LIB3270_EXPORT void RunPendingEvents(int wait); | 598 | LIB3270_EXPORT void RunPendingEvents(int wait); |
599 | LIB3270_EXPORT int Wait(int seconds); | 599 | LIB3270_EXPORT int Wait(int seconds); |
600 | 600 |
latest/src/lib/XtGlue.c
@@ -957,12 +957,14 @@ LIB3270_EXPORT int lib3270_in_e(H3270 *h) | @@ -957,12 +957,14 @@ LIB3270_EXPORT int lib3270_in_e(H3270 *h) | ||
957 | return (h->cstate >= CONNECTED_INITIAL_E); | 957 | return (h->cstate >= CONNECTED_INITIAL_E); |
958 | } | 958 | } |
959 | 959 | ||
960 | -int CallAndWait(int(*callback)(void *), H3270 *session, void *parm) | 960 | +LIB3270_EXPORT int lib3270_call_thread(int(*callback)(H3270 *h, void *), H3270 *h, void *parm) |
961 | { | 961 | { |
962 | - if(callbacks->CallAndWait) | ||
963 | - return callbacks->CallAndWait(callback,session,parm); | 962 | + CHECK_SESSION_HANDLE(h); |
963 | + | ||
964 | + if(callbacks->callthread) | ||
965 | + return callbacks->callthread(callback,h,parm); | ||
964 | else | 966 | else |
965 | - return callback(parm); | 967 | + return callback(h,parm); |
966 | } | 968 | } |
967 | 969 | ||
968 | void RunPendingEvents(int wait) | 970 | void RunPendingEvents(int wait) |
latest/src/lib/resolver.c
@@ -84,7 +84,7 @@ struct parms | @@ -84,7 +84,7 @@ struct parms | ||
84 | * Returns 0 for success, -1 for fatal error (name resolution impossible), | 84 | * Returns 0 for success, -1 for fatal error (name resolution impossible), |
85 | * -2 for simple error (cannot resolve the name). | 85 | * -2 for simple error (cannot resolve the name). |
86 | */ | 86 | */ |
87 | -static int cresolve_host_and_port(struct parms *p) | 87 | +static int cresolve_host_and_port(H3270 *h, struct parms *p) |
88 | { | 88 | { |
89 | #ifdef AF_INET6 | 89 | #ifdef AF_INET6 |
90 | 90 | ||
@@ -183,7 +183,7 @@ int resolve_host_and_port(const char *host, char *portname, unsigned short *ppor | @@ -183,7 +183,7 @@ int resolve_host_and_port(const char *host, char *portname, unsigned short *ppor | ||
183 | 183 | ||
184 | Trace("Calling resolver for %s", p.host); | 184 | Trace("Calling resolver for %s", p.host); |
185 | 185 | ||
186 | - rc = CallAndWait((int (*)(void *)) cresolve_host_and_port,&h3270,&p); | 186 | + rc = CallAndWait((int (*)(H3270 *, void *)) cresolve_host_and_port,&h3270,&p); |
187 | 187 | ||
188 | Trace("Calling resolver for %s exits with %d", p.host, rc); | 188 | Trace("Calling resolver for %s exits with %d", p.host, rc); |
189 | 189 |