Commit f3a42a7074e512fe63976b226ddc4530e840c60b

Authored by perry.werneck@gmail.com
1 parent c15748bc

Atualizando GUI

src/include/lib3270.h
... ... @@ -685,14 +685,8 @@
685 685 void * (*AddTimeOut)(unsigned long interval_ms, H3270 *session, void (*proc)(H3270 *session));
686 686 void (*RemoveTimeOut)(void *timer);
687 687  
688   - void * (*AddInput)(int source, H3270 *session, void (*fn)(H3270 *session));
689   - void * (*AddOutput)(int source, H3270 *session, void (*fn)(H3270 *session));
690   -
691   - void (*RemoveSource)(void *id);
692   -
693   - void * (*AddExcept)(int source, H3270 *session, void (*fn)(H3270 *session));
694   -
695   -// int (*callthread)(int(*callback)(H3270 *, void *), H3270 *session, void *parm);
  688 + void * (*add_poll)(H3270 *session, int fd, LIB3270_IO_FLAG flag, void(*proc)(H3270 *, int, LIB3270_IO_FLAG, void *), void *userdata);
  689 + void (*remove_poll)(void *id);
696 690  
697 691 int (*Wait)(H3270 *hSession, int seconds);
698 692 int (*event_dispatcher)(H3270 *hSession, int wait);
... ... @@ -719,6 +713,8 @@
719 713 */
720 714 void LIB3270_EXPORT lib3270_register_time_handlers(void * (*add)(unsigned long interval_ms, H3270 *session, void (*proc)(H3270 *session)), void (*rm)(void *timer));
721 715  
  716 + void lib3270_register_fd_handlers(void * (*add)(H3270 *session, int fd, LIB3270_IO_FLAG flag, void(*proc)(H3270 *, int, LIB3270_IO_FLAG, void *), void *userdata), void (*rm)(void *id));
  717 +
722 718 /**
723 719 * Get program message.
724 720 *
... ...
src/lib3270/iocalls.c
... ... @@ -79,7 +79,7 @@ static void internal_ring_bell(H3270 *);
79 79 static void (*remove_poll)(void *id)
80 80 = internal_remove_poll;
81 81  
82   - static int (*wait)(H3270 *hSession, int seconds)
  82 + static int (*wait)(H3270 *hSession, int seconds)
83 83 = internal_wait;
84 84  
85 85 static int (*event_dispatcher)(H3270 *hSession,int wait)
... ... @@ -633,31 +633,6 @@ void RemoveTimeOut(void * timer)
633 633 return remove_timeout(timer);
634 634 }
635 635  
636   -/*
637   -void * AddInput(int source, H3270 *session, void (*fn)(H3270 *session))
638   -{
639   - CHECK_SESSION_HANDLE(session);
640   - return add_input(source,session,fn);
641   -}
642   -
643   -void * AddOutput(int source, H3270 *session, void (*fn)(H3270 *session))
644   -{
645   - CHECK_SESSION_HANDLE(session);
646   - return add_output(source,session,fn);
647   -}
648   -
649   -void * AddExcept(int source, H3270 *session, void (*fn)(H3270 *session))
650   -{
651   - CHECK_SESSION_HANDLE(session);
652   - return add_except(source,session,fn);
653   -}
654   -
655   -void RemoveSource(void * id)
656   -{
657   - remove_source(id);
658   -}
659   -*/
660   -
661 636 void x_except_on(H3270 *h)
662 637 {
663 638 if(h->excepting)
... ... @@ -709,7 +684,14 @@ LIB3270_EXPORT void lib3270_register_time_handlers(void * (*add)(unsigned long i
709 684  
710 685 }
711 686  
712   -/*
  687 +LIB3270_EXPORT void lib3270_register_fd_handlers(void * (*add)(H3270 *session, int fd, LIB3270_IO_FLAG flag, void(*proc)(H3270 *, int, LIB3270_IO_FLAG, void *), void *userdata), void (*rm)(void *id)) {
  688 + if(add)
  689 + add_poll = add;
  690 +
  691 + if(rm)
  692 + remove_poll = rm;
  693 +}
  694 +
713 695 LIB3270_EXPORT int lib3270_register_handlers(const struct lib3270_callbacks *cbk)
714 696 {
715 697 if(!cbk)
... ... @@ -719,18 +701,7 @@ LIB3270_EXPORT int lib3270_register_handlers(const struct lib3270_callbacks *cbk
719 701 return EINVAL;
720 702  
721 703 lib3270_register_time_handlers(cbk->AddTimeOut,cbk->RemoveTimeOut);
722   -
723   - if(cbk->AddInput)
724   - add_input = cbk->AddInput;
725   -
726   - if(cbk->AddOutput)
727   - add_output = cbk->AddOutput;
728   -
729   - if(cbk->RemoveSource)
730   - remove_source = cbk->RemoveSource;
731   -
732   - if(cbk->AddExcept)
733   - add_except = cbk->AddExcept;
  704 + lib3270_register_fd_handlers(cbk->add_poll,cbk->remove_poll);
734 705  
735 706 if(cbk->Wait)
736 707 wait = cbk->Wait;
... ... @@ -744,7 +715,7 @@ LIB3270_EXPORT int lib3270_register_handlers(const struct lib3270_callbacks *cbk
744 715 return 0;
745 716  
746 717 }
747   -*/
  718 +
748 719  
749 720 LIB3270_EXPORT void lib3270_iterate(int block) {
750 721 event_dispatcher(NULL,block);
... ...
src/plugins/dbus3270/iocallback.c
... ... @@ -351,6 +351,8 @@ void pw3270_dbus_register_io_handlers(void)
351 351  
352 352 };
353 353  
  354 + #error Need rewrite
  355 +
354 356 if(lib3270_register_handlers(&hdl))
355 357 {
356 358 g_error("%s","Can't set lib3270 I/O handlers");
... ...
src/pw3270/v3270/iocallback.c
... ... @@ -46,8 +46,8 @@
46 46 // static int static_CallAndWait(int(*callback)(H3270 *session, void *), H3270 *session, void *parm);
47 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 52 static void * static_AddTimeOut(unsigned long interval_ms, H3270 *session, void (*proc)(H3270 *session));
53 53 static void static_RemoveTimeOut(void * timer);
... ... @@ -66,16 +66,18 @@ static gboolean IO_closure(gpointer data);
66 66 {
67 67 GSource gsrc;
68 68 GPollFD poll;
69   - int source;
70   - void (*fn)(H3270 *session);
  69 + int fd;
  70 + void (*call)(H3270 *, int, LIB3270_IO_FLAG, void *);
71 71 H3270 *session;
  72 + void *userdata;
72 73 } IO_Source;
73 74  
74 75 typedef struct _timer
75 76 {
76 77 unsigned char remove;
77   - void (*fn)(H3270 *session);
78   - H3270 *session;
  78 + void * userdata;
  79 + void (*call)(H3270 *session);
  80 + H3270 * session;
79 81 } TIMER;
80 82  
81 83 static GSourceFuncs IOSources =
... ... @@ -90,22 +92,31 @@ static gboolean IO_closure(gpointer data);
90 92  
91 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 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 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 113 g_source_attach((GSource *) src,NULL);
104 114 g_source_add_poll((GSource *) src,&src->poll);
105 115  
106 116 return src;
107 117 }
108 118  
  119 +/*
109 120 static void * static_AddOutput(int source, H3270 *session, void (*fn)(H3270 *session))
110 121 {
111 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 127 {
117 128 return AddSource(source,session,G_IO_IN|G_IO_HUP|G_IO_ERR,fn);
118 129 }
  130 +*/
119 131  
120 132 static void static_RemoveSource(void *id)
121 133 {
... ... @@ -123,23 +135,25 @@ static void static_RemoveSource(void *id)
123 135 g_source_destroy((GSource *) id);
124 136 }
125 137  
  138 +/*
126 139 static void * static_AddExcept(int source, H3270 *session, void (*fn)(H3270 *session))
127 140 {
128 141 return AddSource(source,session,G_IO_HUP|G_IO_ERR,fn);
129 142 }
  143 +*/
130 144  
131 145 static gboolean do_timer(TIMER *t)
132 146 {
133 147 if(!t->remove)
134   - t->fn(t->session);
  148 + t->call(t->session);
135 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 154 TIMER *t = g_malloc0(sizeof(TIMER));
141 155  
142   - t->fn = proc;
  156 + t->call = call;
143 157 t->session = session;
144 158  
145 159 trace("Adding timeout with %ld ms",interval);
... ... @@ -232,7 +246,10 @@ static gboolean IO_dispatch(GSource *source, GSourceFunc callback, gpointer user
232 246 * should call the callback function with user_data and whatever additional
233 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 253 return TRUE;
237 254 }
238 255  
... ... @@ -304,20 +321,9 @@ void v3270_register_io_handlers(v3270Class *cls)
304 321 static_AddTimeOut,
305 322 static_RemoveTimeOut,
306 323  
307   - static_AddInput,
308   - static_AddOutput,
309   -
  324 + static_AddSource,
310 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 327 static_Sleep,
322 328 static_RunPendingEvents,
323 329 beep
... ...