5 #include "chimara-glk-private.h"
7 extern GPrivate *glk_data_key;
10 * glk_set_interrupt_handler:
11 * @func: A pointer to an interrupt handler function.
13 * Sets @func to be the interrupt handler. @func should be a pointer to a
14 * function which takes no argument and returns no result. If Glk receives an
15 * interrupt, and you have set an interrupt handler, your handler will be
16 * called, before the process is shut down.
18 * Initially there is no interrupt handler. You can reset to not having any by
19 * calling <code>#glk_set_interrupt_handler(%NULL)</code>.
21 * If you call glk_set_interrupt_handler() with a new handler function while an
22 * older one is set, the new one replaces the old one. Glk does not try to queue
25 * You should not try to interact with the player in your interrupt handler. Do
26 * not call glk_select() or glk_select_poll(). Anything you print to a window
27 * may not be visible to the player.
30 glk_set_interrupt_handler(void (*func)(void))
32 ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
33 glk_data->interrupt_handler = func;
36 /* Internal function: abort this Glk program, freeing resources and calling the
37 user's interrupt handler. */
41 ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
42 if(glk_data->interrupt_handler)
43 (*(glk_data->interrupt_handler))();
44 g_signal_emit_by_name(glk_data->self, "stopped");
48 /* Internal function: check if the Glk program has been interrupted. */
52 ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
53 g_mutex_lock(glk_data->abort_lock);
54 if(glk_data->abort_signalled)
56 g_mutex_unlock(glk_data->abort_lock);
59 g_mutex_unlock(glk_data->abort_lock);