Commit 76e1e3fdf87ace980c4f21222a872f9407639f55
1 parent
9edc9bc3
Exists in
master
and in
1 other branch
Adding background task support.
Showing
1 changed file
with
48 additions
and
5 deletions
Show diff stats
src/v3270/iocallback.c
@@ -128,11 +128,53 @@ static void beep(G_GNUC_UNUSED H3270 *session) | @@ -128,11 +128,53 @@ static void beep(G_GNUC_UNUSED H3270 *session) | ||
128 | gdk_display_beep(gdk_display_get_default()); | 128 | gdk_display_beep(gdk_display_get_default()); |
129 | } | 129 | } |
130 | 130 | ||
131 | +struct bgParameter | ||
132 | +{ | ||
133 | + gboolean running; | ||
134 | + H3270 * hSession; | ||
135 | + int rc; | ||
136 | + int (*callback)(H3270 *session, void *parm); | ||
137 | + void * parm; | ||
138 | + | ||
139 | +}; | ||
140 | + | ||
141 | +gpointer BgCall(struct bgParameter *p) | ||
142 | +{ | ||
143 | + p->rc = p->callback(p->hSession,p->parm); | ||
144 | + p->running = FALSE; | ||
145 | + return 0; | ||
146 | +} | ||
147 | + | ||
148 | +static int static_RunTask(H3270 *hSession, int(*callback)(H3270 *, void *), void *parm) | ||
149 | +{ | ||
150 | + struct bgParameter p = { TRUE, hSession, -1, callback, parm }; | ||
151 | + | ||
152 | + p.running = TRUE; | ||
153 | + | ||
154 | + GThread *thread = g_thread_new(PACKAGE_NAME, (GThreadFunc) BgCall, &p); | ||
155 | + | ||
156 | + if(!thread) | ||
157 | + { | ||
158 | + g_error("Can't start background thread"); | ||
159 | + return -1; | ||
160 | + } | ||
161 | + | ||
162 | + while(p.running) | ||
163 | + { | ||
164 | + gtk_main_iteration(); | ||
165 | + } | ||
166 | + | ||
167 | + g_thread_join(thread); | ||
168 | + | ||
169 | + return p.rc; | ||
170 | + | ||
171 | +} | ||
172 | + | ||
131 | void v3270_register_io_handlers(G_GNUC_UNUSED v3270Class *cls) | 173 | void v3270_register_io_handlers(G_GNUC_UNUSED v3270Class *cls) |
132 | { | 174 | { |
133 | - static const struct lib3270_callbacks hdl = | 175 | + static LIB3270_IO_CONTROLLER hdl = |
134 | { | 176 | { |
135 | - sizeof(struct lib3270_callbacks), | 177 | + sizeof(LIB3270_IO_CONTROLLER), |
136 | 178 | ||
137 | static_AddTimeOut, | 179 | static_AddTimeOut, |
138 | static_RemoveTimeOut, | 180 | static_RemoveTimeOut, |
@@ -142,13 +184,14 @@ void v3270_register_io_handlers(G_GNUC_UNUSED v3270Class *cls) | @@ -142,13 +184,14 @@ void v3270_register_io_handlers(G_GNUC_UNUSED v3270Class *cls) | ||
142 | 184 | ||
143 | static_Sleep, | 185 | static_Sleep, |
144 | static_RunPendingEvents, | 186 | static_RunPendingEvents, |
145 | - beep | 187 | + beep, |
188 | + static_RunTask | ||
146 | 189 | ||
147 | }; | 190 | }; |
148 | 191 | ||
149 | - if(lib3270_register_handlers(&hdl)) | 192 | + if(lib3270_register_io_controller(&hdl)) |
150 | { | 193 | { |
151 | - g_error("%s",_( "Can't set lib3270 I/O handlers" ) ); | 194 | + g_error("%s",_( "Can't set lib3270 I/O controller" ) ); |
152 | } | 195 | } |
153 | 196 | ||
154 | } | 197 | } |