Commit 5d217772d17e64e86c91b5eb23730f73549422fd
1 parent
4a6475a4
Exists in
master
and in
1 other branch
Atualizando GUI
Showing
1 changed file
with
33 additions
and
27 deletions
Show diff stats
iocallback.c
| @@ -46,8 +46,8 @@ | @@ -46,8 +46,8 @@ | ||
| 46 | // static int static_CallAndWait(int(*callback)(H3270 *session, void *), H3270 *session, void *parm); | 46 | // static int static_CallAndWait(int(*callback)(H3270 *session, void *), H3270 *session, void *parm); |
| 47 | static void static_RemoveSource(void *id); | 47 | static void static_RemoveSource(void *id); |
| 48 | 48 | ||
| 49 | -static void * static_AddInput(int source, H3270 *session, void (*fn)(H3270 *session)); | ||
| 50 | -static void * static_AddExcept(int source, H3270 *session, void (*fn)(H3270 *session)); | 49 | +static void * static_AddSource(H3270 *session, int fd, LIB3270_IO_FLAG flag, void(*proc)(H3270 *, int, LIB3270_IO_FLAG, void *), void *userdata); |
| 50 | +static void static_RemoveSource(void *id); | ||
| 51 | 51 | ||
| 52 | static void * static_AddTimeOut(unsigned long interval_ms, H3270 *session, void (*proc)(H3270 *session)); | 52 | static void * static_AddTimeOut(unsigned long interval_ms, H3270 *session, void (*proc)(H3270 *session)); |
| 53 | static void static_RemoveTimeOut(void * timer); | 53 | static void static_RemoveTimeOut(void * timer); |
| @@ -66,16 +66,18 @@ static gboolean IO_closure(gpointer data); | @@ -66,16 +66,18 @@ static gboolean IO_closure(gpointer data); | ||
| 66 | { | 66 | { |
| 67 | GSource gsrc; | 67 | GSource gsrc; |
| 68 | GPollFD poll; | 68 | GPollFD poll; |
| 69 | - int source; | ||
| 70 | - void (*fn)(H3270 *session); | 69 | + int fd; |
| 70 | + void (*call)(H3270 *, int, LIB3270_IO_FLAG, void *); | ||
| 71 | H3270 *session; | 71 | H3270 *session; |
| 72 | + void *userdata; | ||
| 72 | } IO_Source; | 73 | } IO_Source; |
| 73 | 74 | ||
| 74 | typedef struct _timer | 75 | typedef struct _timer |
| 75 | { | 76 | { |
| 76 | unsigned char remove; | 77 | unsigned char remove; |
| 77 | - void (*fn)(H3270 *session); | ||
| 78 | - H3270 *session; | 78 | + void * userdata; |
| 79 | + void (*call)(H3270 *session); | ||
| 80 | + H3270 * session; | ||
| 79 | } TIMER; | 81 | } TIMER; |
| 80 | 82 | ||
| 81 | static GSourceFuncs IOSources = | 83 | static GSourceFuncs IOSources = |
| @@ -90,22 +92,31 @@ static gboolean IO_closure(gpointer data); | @@ -90,22 +92,31 @@ static gboolean IO_closure(gpointer data); | ||
| 90 | 92 | ||
| 91 | /*---[ Implement ]-----------------------------------------------------------------------------------------*/ | 93 | /*---[ Implement ]-----------------------------------------------------------------------------------------*/ |
| 92 | 94 | ||
| 93 | -static void * AddSource(int source, H3270 *session, gushort events, void (*fn)(H3270 *session)) | 95 | +static void * static_AddSource(H3270 *session, int fd, LIB3270_IO_FLAG flag, void(*call)(H3270 *, int, LIB3270_IO_FLAG, void *), void *userdata) |
| 94 | { | 96 | { |
| 95 | IO_Source *src = (IO_Source *) g_source_new(&IOSources,sizeof(IO_Source)); | 97 | IO_Source *src = (IO_Source *) g_source_new(&IOSources,sizeof(IO_Source)); |
| 96 | 98 | ||
| 97 | - src->source = source; | ||
| 98 | - src->fn = fn; | ||
| 99 | - src->poll.fd = (int) source; | ||
| 100 | - src->poll.events = events; | 99 | + src->fd = fd; |
| 100 | + src->call = call; | ||
| 101 | + src->userdata = userdata; | ||
| 101 | src->session = session; | 102 | src->session = session; |
| 102 | 103 | ||
| 104 | + src->poll.fd = (int) fd; | ||
| 105 | + src->poll.events = G_IO_HUP|G_IO_ERR; | ||
| 106 | + | ||
| 107 | + if(flag & LIB3270_IO_FLAG_READ) | ||
| 108 | + src->poll.events |= G_IO_IN; | ||
| 109 | + | ||
| 110 | + if(flag & LIB3270_IO_FLAG_WRITE) | ||
| 111 | + src->poll.events |= G_IO_OUT; | ||
| 112 | + | ||
| 103 | g_source_attach((GSource *) src,NULL); | 113 | g_source_attach((GSource *) src,NULL); |
| 104 | g_source_add_poll((GSource *) src,&src->poll); | 114 | g_source_add_poll((GSource *) src,&src->poll); |
| 105 | 115 | ||
| 106 | return src; | 116 | return src; |
| 107 | } | 117 | } |
| 108 | 118 | ||
| 119 | +/* | ||
| 109 | static void * static_AddOutput(int source, H3270 *session, void (*fn)(H3270 *session)) | 120 | static void * static_AddOutput(int source, H3270 *session, void (*fn)(H3270 *session)) |
| 110 | { | 121 | { |
| 111 | return AddSource(source,session,G_IO_OUT|G_IO_HUP|G_IO_ERR,fn); | 122 | return AddSource(source,session,G_IO_OUT|G_IO_HUP|G_IO_ERR,fn); |
| @@ -116,6 +127,7 @@ static void * static_AddInput(int source, H3270 *session, void (*fn)(H3270 *sess | @@ -116,6 +127,7 @@ static void * static_AddInput(int source, H3270 *session, void (*fn)(H3270 *sess | ||
| 116 | { | 127 | { |
| 117 | return AddSource(source,session,G_IO_IN|G_IO_HUP|G_IO_ERR,fn); | 128 | return AddSource(source,session,G_IO_IN|G_IO_HUP|G_IO_ERR,fn); |
| 118 | } | 129 | } |
| 130 | +*/ | ||
| 119 | 131 | ||
| 120 | static void static_RemoveSource(void *id) | 132 | static void static_RemoveSource(void *id) |
| 121 | { | 133 | { |
| @@ -123,23 +135,25 @@ static void static_RemoveSource(void *id) | @@ -123,23 +135,25 @@ static void static_RemoveSource(void *id) | ||
| 123 | g_source_destroy((GSource *) id); | 135 | g_source_destroy((GSource *) id); |
| 124 | } | 136 | } |
| 125 | 137 | ||
| 138 | +/* | ||
| 126 | static void * static_AddExcept(int source, H3270 *session, void (*fn)(H3270 *session)) | 139 | static void * static_AddExcept(int source, H3270 *session, void (*fn)(H3270 *session)) |
| 127 | { | 140 | { |
| 128 | return AddSource(source,session,G_IO_HUP|G_IO_ERR,fn); | 141 | return AddSource(source,session,G_IO_HUP|G_IO_ERR,fn); |
| 129 | } | 142 | } |
| 143 | +*/ | ||
| 130 | 144 | ||
| 131 | static gboolean do_timer(TIMER *t) | 145 | static gboolean do_timer(TIMER *t) |
| 132 | { | 146 | { |
| 133 | if(!t->remove) | 147 | if(!t->remove) |
| 134 | - t->fn(t->session); | 148 | + t->call(t->session); |
| 135 | return FALSE; | 149 | return FALSE; |
| 136 | } | 150 | } |
| 137 | 151 | ||
| 138 | -static void * static_AddTimeOut(unsigned long interval, H3270 *session, void (*proc)(H3270 *session)) | 152 | +static void * static_AddTimeOut(unsigned long interval, H3270 *session, void (*call)(H3270 *session)) |
| 139 | { | 153 | { |
| 140 | TIMER *t = g_malloc0(sizeof(TIMER)); | 154 | TIMER *t = g_malloc0(sizeof(TIMER)); |
| 141 | 155 | ||
| 142 | - t->fn = proc; | 156 | + t->call = call; |
| 143 | t->session = session; | 157 | t->session = session; |
| 144 | 158 | ||
| 145 | trace("Adding timeout with %ld ms",interval); | 159 | trace("Adding timeout with %ld ms",interval); |
| @@ -232,7 +246,10 @@ static gboolean IO_dispatch(GSource *source, GSourceFunc callback, gpointer user | @@ -232,7 +246,10 @@ static gboolean IO_dispatch(GSource *source, GSourceFunc callback, gpointer user | ||
| 232 | * should call the callback function with user_data and whatever additional | 246 | * should call the callback function with user_data and whatever additional |
| 233 | * parameters are needed for this type of event source. | 247 | * parameters are needed for this type of event source. |
| 234 | */ | 248 | */ |
| 235 | - ((IO_Source *) source)->fn(((IO_Source *) source)->session); | 249 | + IO_Source *obj = (IO_Source *) source; |
| 250 | + | ||
| 251 | + obj->call(obj->session,obj->fd,0,obj->userdata); | ||
| 252 | + | ||
| 236 | return TRUE; | 253 | return TRUE; |
| 237 | } | 254 | } |
| 238 | 255 | ||
| @@ -304,20 +321,9 @@ void v3270_register_io_handlers(v3270Class *cls) | @@ -304,20 +321,9 @@ void v3270_register_io_handlers(v3270Class *cls) | ||
| 304 | static_AddTimeOut, | 321 | static_AddTimeOut, |
| 305 | static_RemoveTimeOut, | 322 | static_RemoveTimeOut, |
| 306 | 323 | ||
| 307 | - static_AddInput, | ||
| 308 | - static_AddOutput, | ||
| 309 | - | 324 | + static_AddSource, |
| 310 | static_RemoveSource, | 325 | static_RemoveSource, |
| 311 | 326 | ||
| 312 | - static_AddExcept, | ||
| 313 | - | ||
| 314 | -/* | ||
| 315 | -#ifdef G_THREADS_ENABLED | ||
| 316 | - static_CallAndWait, | ||
| 317 | -#else | ||
| 318 | - NULL, | ||
| 319 | -#endif | ||
| 320 | -*/ | ||
| 321 | static_Sleep, | 327 | static_Sleep, |
| 322 | static_RunPendingEvents, | 328 | static_RunPendingEvents, |
| 323 | beep | 329 | beep |