6 #include "chimara-glk-private.h"
8 extern GPrivate *glk_data_key;
11 * glk_set_interrupt_handler:
12 * @func: A pointer to an interrupt handler function.
14 * Sets @func to be the interrupt handler. @func should be a pointer to a
15 * function which takes no argument and returns no result. If Glk receives an
16 * interrupt, and you have set an interrupt handler, your handler will be
17 * called, before the process is shut down.
19 * Initially there is no interrupt handler. You can reset to not having any by
20 * calling <code>#glk_set_interrupt_handler(%NULL)</code>.
22 * If you call glk_set_interrupt_handler() with a new handler function while an
23 * older one is set, the new one replaces the old one. Glk does not try to queue
26 * You should not try to interact with the player in your interrupt handler. Do
27 * not call glk_select() or glk_select_poll(). Anything you print to a window
28 * may not be visible to the player.
31 glk_set_interrupt_handler(void (*func)(void))
33 ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
34 glk_data->interrupt_handler = func;
37 /* Internal function: abort this Glk program, freeing resources and calling the
38 user's interrupt handler. */
42 ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
43 if(glk_data->interrupt_handler)
44 (*(glk_data->interrupt_handler))();
49 /* Internal function: check if the Glk program has been interrupted. */
53 ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
54 g_mutex_lock(glk_data->abort_lock);
55 if(glk_data->abort_signalled)
57 g_mutex_unlock(glk_data->abort_lock);
60 g_mutex_unlock(glk_data->abort_lock);
63 /* Internal function: do any cleanup for shutting down the Glk library. */
67 ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
69 if(!glk_data->in_startup)
70 g_signal_emit_by_name(glk_data->self, "stopped");
73 glk_request_timer_events(0);
75 /* Close any open resource files */
76 if(glk_data->resource_map != NULL) {
77 giblorb_destroy_map(glk_data->resource_map);
78 glk_stream_close(glk_data->resource_file, NULL);
81 /* Unref the input queues */
82 g_async_queue_unref(glk_data->char_input_queue);
83 g_async_queue_unref(glk_data->line_input_queue);