|
navit 0.5.8
|
Go to the source code of this file.
Data Structures | |
| struct | event_methods |
Enumerations | |
| enum | event_watch_cond { event_watch_cond_read = 1 , event_watch_cond_write , event_watch_cond_except } |
Functions | |
| void | event_main_loop_run (void) |
| Starts the main event loop. | |
| void | event_main_loop_quit (void) |
| Stops the main event loop. | |
| int | event_main_loop_has_quit (void) |
| Returns whether the main event loop has quit. | |
| void | event_signal_notify (void) |
| Notifies the event loop that a signal has arrived. | |
| int | event_get_signal_fd (void) |
Returns a file descriptor that becomes readable when event_signal_notify() is called. | |
| struct event_watch * | event_add_watch (int fd, enum event_watch_cond cond, struct callback *cb) |
| Adds a watch event which will fire whenever a certain condition occurs on a file descriptor. | |
| void | event_remove_watch (struct event_watch *ev) |
| Removes a previously added watch event. | |
| struct event_timeout * | event_add_timeout (int timeout, int multi, struct callback *cb) |
| Adds an event which will fire when the specified timeout expires. | |
| void | event_remove_timeout (struct event_timeout *ev) |
| Removes a previously added timeout event. | |
| struct event_idle * | event_add_idle (int priority, struct callback *cb) |
| Adds an event which will run repeatedly when the event system is idle. | |
| void | event_remove_idle (struct event_idle *ev) |
| Removes a previously added idle event. | |
| void | event_call_callback (struct callback_list *cb) |
| Calls a list of callbacks. | |
| char const * | event_system (void) |
| Returns the current event system. | |
| int | event_request_system (const char *system, const char *requestor) |
| Initializes a new event system. | |
| enum event_watch_cond |
| struct event_idle * event_add_idle | ( | int | priority, |
| struct callback * | cb | ||
| ) |
Adds an event which will run repeatedly when the event system is idle.
The null and OpenGL backends are stubs: they return NULL and never invoke the callback.
This is typically done to run long loops in the background without blocking the UI: the loop is wrapped into a callback and exits after a certain time or number of runs. Upon its next invocation, it takes up where it interrupted its work. Each invocation should complete in a period of time short enough to not cause a significant delay to the UI. After the last run of the loop, the callback removes its event.
This can be seen as a lightweight alternative to multithreading. It is available even on platforms without multithreading support, and synchronization is easier as the idle callback has full control over when it yields to other tasks, and can ensure all data is in a consistent state before doing so. However, idle events are not suited to all tasks, and poorly written callbacks can cause the UI to become unresponsive. As they run on the main thread, they cannot benefit from multi-processor systems.
| priority | The priority for the event, if multiple idle events are present at the same time |
| cb | The callback to call when the event fires |
References event_methods::add_idle, event_idle::cb, and require_method2.
Referenced by command_saved_attr_new(), command_saved_evaluate(), graphics_load_mapset(), gui_internal_search_idle_start(), j1850_idle(), navigation_update(), pedestrian_cmd_pedestrian_rocket(), route_graph_build(), start_search(), traffic_get_map(), traffic_loop(), and traffic_process_messages().
| struct event_timeout * event_add_timeout | ( | int | timeout, |
| int | multi, | ||
| struct callback * | cb | ||
| ) |
Adds an event which will fire when the specified timeout expires.
The null and OpenGL backends are stubs: they return NULL and never invoke the callback.
A one-shot event (multi = 0) fires only once and becomes invalid afterwards. Cleanup after firing is backend-specific: the glib, Win32 and SDL (event.c) backends free the handle on fire, so calling event_remove_timeout(struct event_timeout *) afterwards would be a double-free. The SDL (event_sdl.c, graphics_sdl.c), Android and Qt backends require the caller to remove the handle to release it. For portable code, do not call event_remove_timeout() after a one-shot has fired. A pending one-shot can be cancelled with event_remove_timeout() on all backends.
A multi-shot event (multi = 1) fires repeatedly until removed by calling event_remove_timeout(struct event_timeout *).
| timeout | Timeout in msec |
| multi | Whether the event should fire repeatedly (at the interval specified by timeout) |
| cb | The callback to call when timeout expires |
References event_methods::add_timeout, event_timeout::cb, event_timeout::multi, and require_method2.
Referenced by event_sdl_main_loop_run(), graphics_qt5_disable_suspend(), graphics_sdl_idle(), gui_internal_motion(), gui_internal_setup(), j1850_init_serial_port(), log_new(), messagelist_init(), navit_handle_button(), navit_handle_motion(), osd_cmd_interface_init(), osd_j1850_init(), osd_odometer_init(), osd_stopwatch_init(), pedestrian_setup_tilt(), request_navit_quit(), script_set_attr_int(), traffic_new(), vehicle_demo_new(), vehicle_demo_set_attr_do(), vehicle_file_enable_watch(), vehicle_file_new_file(), vehicle_file_parse(), vehicle_file_restart_fix_timeout(), vehicle_gpsd_open(), vehicle_set_cursor(), and vehicle_wince_restart_fix_timeout().
| struct event_watch * event_add_watch | ( | int | fd, |
| enum event_watch_cond | cond, | ||
| struct callback * | cb | ||
| ) |
Adds a watch event which will fire whenever a certain condition occurs on a file descriptor.
The null and OpenGL backends are stubs: they return NULL and never invoke the callback.
| fd | The file descriptor to watch |
| cond | The condition to watch for |
| cb | The callback to call when the event fires |
References event_methods::add_watch, event_watch::cb, event_watch::fd, and require_method2.
Referenced by graphics_opengl_x11_new(), pedestrian_setup_tilt(), vehicle_file_enable_watch(), and vehicle_gpsd_try_open().
| void event_call_callback | ( | struct callback_list * | cb | ) |
Calls a list of callbacks.
Whether the callbacks are actually dispatched is backend-specific. The SDL and Win32 backends dispatch them; the glib, null, OpenGL and Android backends currently provide no-op implementations, so calls on those backends have no effect.
References event_methods::call_callback, event_idle::cb, and require_method.
Referenced by wince_reader_thread().
| int event_get_signal_fd | ( | void | ) |
Returns a file descriptor that becomes readable when event_signal_notify() is called.
The descriptor is valid on non-Win32 platforms; on Win32 this returns -1. It should be watched with event_add_watch() to integrate signal handling into the event loop.
References sig_pipe_fds.
Referenced by event_glib_main_loop_run().
| int event_main_loop_has_quit | ( | void | ) |
Returns whether the main event loop has quit.
References has_quit.
Referenced by gui_internal_button(), and gui_internal_keypress().
| void event_main_loop_quit | ( | void | ) |
Stops the main event loop.
References has_quit, and event_methods::main_loop_quit.
Referenced by event_glib_signal_cb(), gui_gtk_delete(), gui_internal_cmd2_quit(), NGQProxyNavit::quit(), quit_action(), and request_navit_quit().
| void event_main_loop_run | ( | void | ) |
Starts the main event loop.
References event_methods::main_loop_run, and require_method.
Referenced by main_real().
| void event_remove_idle | ( | struct event_idle * | ev | ) |
Removes a previously added idle event.
| ev | The event, as returned by event_add_idle() |
References event_methods::remove_idle, and require_method.
Referenced by android_search_end(), command_saved_callbacks_changed(), command_saved_cancel_idle(), command_saved_evaluate_idle(), do_draw(), gui_internal_search_idle_end(), navigation_update_done(), pedestrian_rocket_idle(), route_graph_build_done(), traffic_loop(), traffic_process_messages(), and traffic_process_messages_int().
| void event_remove_timeout | ( | struct event_timeout * | ev | ) |
Removes a previously added timeout event.
Doing so will prevent a multi-shot timeout event from firing another time.
Cancelling a one-shot before it fires is supported. Do not remove a one-shot after it has fired: on some backends the handle is already freed at that point.
| ev | The event, as returned by event_add_timeout() |
References event_methods::remove_timeout, and require_method.
Referenced by event_sdl_main_loop_run(), graphics_destroy(), graphics_sdl_idle(), j1850_idle(), log_destroy(), navit_handle_button(), navit_handle_motion(), osd_remove_timeout(), script_destroy(), script_set_attr_int(), vehicle_demo_destroy(), vehicle_demo_set_attr_do(), vehicle_destroy(), vehicle_file_disable_watch(), vehicle_file_restart_fix_timeout(), vehicle_gpsd_close(), vehicle_gpsd_try_open(), vehicle_set_cursor(), and vehicle_wince_restart_fix_timeout().
| void event_remove_watch | ( | struct event_watch * | ev | ) |
Removes a previously added watch event.
| ev | The event, as returned by event_add_watch() |
References event_methods::remove_watch, and require_method.
Referenced by graphics_opengl_x11_destroy(), vehicle_file_disable_watch(), and vehicle_gpsd_close().
| int event_request_system | ( | const char * | system, |
| const char * | requestor | ||
| ) |
Initializes a new event system.
This call will fail if an event system other than the one requested has already been initialized, or if system does not match a supported event system.
| system | The event system to initialize. |
| requestor | A string identifying the requestor, which can be freely chosen by the caller. The string is stored by pointer and must remain valid for the lifetime of the process. |
References dbg, e_requestor, e_system, event_type_new(), lvl_error, and meth.
Referenced by graphics_android_new(), graphics_cocoa_new(), graphics_gd_new(), graphics_gtk_drawing_area_new(), graphics_null_new(), graphics_opengl_new(), graphics_opengl_new(), graphics_opengl_x11_new(), graphics_qt5_new(), graphics_qt_qpainter_new(), graphics_sdl_new(), graphics_svg_debug_new(), graphics_win32_new(), and gui_gtk_new().
| void event_signal_notify | ( | void | ) |
Notifies the event loop that a signal has arrived.
On Win32 this stops the main loop directly. On other platforms it writes to an internal pipe; callers should watch the descriptor returned by event_get_signal_fd() to handle the signal.
References c, and sig_pipe_fds.
Referenced by config_terminate().
| char const * event_system | ( | void | ) |