Typedefs | |
typedef struct _MicrofeedMain | MicrofeedMain |
Opaque data type representing a main loop. | |
typedef struct _MicrofeedTimeout | MicrofeedTimeout |
Opaque data type representing a timeout in the main loop. | |
typedef struct _MicrofeedWatch | MicrofeedWatch |
Opaque data type representing a file descriptor to watch in the main loop. | |
typedef void(* | MicrofeedTimeoutCallback )(MicrofeedMain *microfeed_main, void *user_data) |
A function that is called when a timeout has occurred. | |
typedef void(* | MicrofeedWatchCallback )(MicrofeedMain *microfeed_main, int fd, MicrofeedWatchType type, void *user_data) |
A function that is called when a watched file descriptor has something to read or/and write. | |
Enumerations | |
enum | MicrofeedWatchType { MICROFEED_WATCH_TYPE_NONE = 0, MICROFEED_WATCH_TYPE_READ = 1, MICROFEED_WATCH_TYPE_WRITE = 2, MICROFEED_WATCH_TYPE_READ_WRITE = 3 } |
Possible watch types of a watched file descriptor. More... | |
Functions | |
MicrofeedMain * | microfeed_main_new () |
Instantiates a new main loop with a shared session-wide DBus connection. | |
MicrofeedMain * | microfeed_main_new_with_dbus_connection (DBusConnection *connection) |
Instantiates a new main loop with a given DBus connection. | |
void | microfeed_main_free (MicrofeedMain *microfeed_main) |
Frees the resources allocated for the main loop. | |
DBusConnection * | microfeed_main_get_dbus_connection (MicrofeedMain *microfeed_main) |
Returns the DBus connection used in the main loop. | |
void | microfeed_main_loop (MicrofeedMain *microfeed_main) |
Executes a main loop repeatedly until a microfeed_main_exit is called. | |
void | microfeed_main_exit (MicrofeedMain *microfeed_main) |
Asks the main loop to stop. | |
MicrofeedTimeout * | microfeed_main_add_timeout (MicrofeedMain *microfeed_main, unsigned long int milliseconds, MicrofeedTimeoutCallback callback, void *user_data) |
Adds a new timeout into the main loop. | |
MicrofeedWatch * | microfeed_main_add_watch (MicrofeedMain *microfeed_main, int fd, MicrofeedWatchType type, MicrofeedWatchCallback callback, void *user_data) |
Adds a new file descriptor to watch into the main loop. | |
void | microfeed_main_remove_timeout (MicrofeedMain *microfeed_main, MicrofeedTimeout *timeout) |
Removes a previously added timeout from the main loop. | |
void | microfeed_main_remove_watch (MicrofeedMain *microfeed_main, MicrofeedWatch *watch) |
Removes a previously added file descriptor watch from the main loop. |
This module is usually used only in the provider side, when the subscriber side is using some other main loop, such as GTK+/GLib.
MicrofeedMain is thread-aware, because it implements internal lock. All callbacks are called without locks being held.
typedef struct _MicrofeedMain MicrofeedMain |
typedef struct _MicrofeedTimeout MicrofeedTimeout |
Opaque data type representing a timeout in the main loop.
Definition at line 31 of file microfeedmain.h.
typedef void(* MicrofeedTimeoutCallback)(MicrofeedMain *microfeed_main, void *user_data) |
A function that is called when a timeout has occurred.
The timeout is removed automatically, so if you want to call the functin repeatedly, you have to add a new timeout here.
microfeed_main | The main loop where the timeout occurred. | |
user_data | The user data given when the timeout was added. |
Definition at line 57 of file microfeedmain.h.
typedef struct _MicrofeedWatch MicrofeedWatch |
Opaque data type representing a file descriptor to watch in the main loop.
Definition at line 36 of file microfeedmain.h.
typedef void(* MicrofeedWatchCallback)(MicrofeedMain *microfeed_main, int fd, MicrofeedWatchType type, void *user_data) |
A function that is called when a watched file descriptor has something to read or/and write.
microfeed_main | The main loop where the timeout occurred. | |
fd | The file descriptor that is ready. | |
type | Specifies if the file descriptor is ready to be read, written or both. | |
user_data | The user data given when the watch was added. |
Definition at line 67 of file microfeedmain.h.
enum MicrofeedWatchType |
Possible watch types of a watched file descriptor.
MICROFEED_WATCH_TYPE_NONE | |
MICROFEED_WATCH_TYPE_READ | |
MICROFEED_WATCH_TYPE_WRITE | |
MICROFEED_WATCH_TYPE_READ_WRITE |
Definition at line 41 of file microfeedmain.h.
MicrofeedTimeout* microfeed_main_add_timeout | ( | MicrofeedMain * | microfeed_main, | |
unsigned long int | milliseconds, | |||
MicrofeedTimeoutCallback | callback, | |||
void * | user_data | |||
) |
Adds a new timeout into the main loop.
The callback is called after the specified time - not before - with the given user data.
microfeed_main | Instantiated MicrofeedMain. | |
milliseconds | A specified time in milliseconds. | |
callback | A function to be called after the specified time. | |
user_data | A pointer to user data that is given as a parameter when the callback function is called. |
Definition at line 316 of file microfeedmain.c.
References _MicrofeedTimeout::callback, _MicrofeedTimeout::main, microfeed_memory_allocate, microfeed_mutex_lock(), microfeed_mutex_unlock(), _MicrofeedTimeout::milliseconds, _MicrofeedMain::mutex, _MicrofeedTimeout::next, _MicrofeedTimeout::previous, _MicrofeedMain::timeouts, and _MicrofeedTimeout::user_data.
MicrofeedWatch* microfeed_main_add_watch | ( | MicrofeedMain * | microfeed_main, | |
int | fd, | |||
MicrofeedWatchType | type, | |||
MicrofeedWatchCallback | callback, | |||
void * | user_data | |||
) |
Adds a new file descriptor to watch into the main loop.
The main loop will monitor the given file if it is ready to be read, written or both, and call the given function with the given user data when the file is ready.
microfeed_main | Instantiated MicrofeedMain. | |
fd | an Unix file descriptor. | |
type | The event that should be monitored. | |
callback | A fucntion to be called when the file is ready. | |
user_data | A pointer to user data that is given as a parameter when the callback function is called. |
Definition at line 376 of file microfeedmain.c.
References _MicrofeedWatch::callback, _MicrofeedWatch::fd, _MicrofeedWatch::main, microfeed_memory_allocate, microfeed_memory_free(), microfeed_mutex_lock(), microfeed_mutex_unlock(), _MicrofeedMain::mutex, _MicrofeedWatch::next, _MicrofeedMain::poll_fds, _MicrofeedWatch::pollfd, _MicrofeedWatch::previous, _MicrofeedWatch::type, _MicrofeedWatch::user_data, _MicrofeedMain::watches, and _MicrofeedMain::watches_count.
void microfeed_main_exit | ( | MicrofeedMain * | microfeed_main | ) |
Asks the main loop to stop.
microfeed_main | Instantiated MicrofeedMain. |
Definition at line 296 of file microfeedmain.c.
References _MicrofeedMain::exit_requested, microfeed_mutex_lock(), microfeed_mutex_unlock(), and _MicrofeedMain::mutex.
void microfeed_main_free | ( | MicrofeedMain * | microfeed_main | ) |
Frees the resources allocated for the main loop.
Note that the DBus connection callbacks are not unset. If the DBus connection is still active, a new functions must be set by the application itself.
microfeed_main | Instantiated MicrofeedMain. |
Definition at line 129 of file microfeedmain.c.
References _MicrofeedMain::connection, _MicrofeedWatch::main, _MicrofeedTimeout::main, microfeed_memory_free(), microfeed_mutex_free(), _MicrofeedMain::mutex, _MicrofeedWatch::next, _MicrofeedTimeout::next, _MicrofeedMain::poll_fds, _MicrofeedMain::timeouts, _MicrofeedMain::watches, and _MicrofeedMain::watches_count.
DBusConnection* microfeed_main_get_dbus_connection | ( | MicrofeedMain * | microfeed_main | ) |
Returns the DBus connection used in the main loop.
Instantiated | MicrofeedMain. |
Definition at line 162 of file microfeedmain.c.
References _MicrofeedMain::connection.
void microfeed_main_loop | ( | MicrofeedMain * | microfeed_main | ) |
Executes a main loop repeatedly until a microfeed_main_exit is called.
microfeed_main | Instantiated MicrofeedMain. |
Definition at line 172 of file microfeedmain.c.
References _MicrofeedWatch::callback, _MicrofeedTimeout::callback, _MicrofeedMain::connection, _MicrofeedMain::exit_requested, _MicrofeedWatch::fd, microfeed_main_remove_timeout(), microfeed_memory_allocate_bytes(), microfeed_mutex_lock(), microfeed_mutex_unlock(), MICROFEED_WATCH_TYPE_NONE, MICROFEED_WATCH_TYPE_READ, MICROFEED_WATCH_TYPE_READ_WRITE, MICROFEED_WATCH_TYPE_WRITE, _MicrofeedTimeout::milliseconds, _MicrofeedMain::mutex, _MicrofeedWatch::next, _MicrofeedMain::poll_fds, _MicrofeedWatch::pollfd, _MicrofeedMain::polling, _MicrofeedMain::timeouts, _MicrofeedWatch::type, _MicrofeedWatch::user_data, _MicrofeedTimeout::user_data, _MicrofeedMain::wakeup_pipe, _MicrofeedMain::watch_iterator, _MicrofeedMain::watches, and _MicrofeedMain::watches_count.
MicrofeedMain* microfeed_main_new | ( | ) |
Instantiates a new main loop with a shared session-wide DBus connection.
Note that this function uses dbus_bus_get() to get a DBus connection, and then initializes its callbacks. See microfeed_main_new_with_dbus_connection for details.
This is the preferred way to initialize a main loop.
Definition at line 68 of file microfeedmain.c.
References microfeed_main_new_with_dbus_connection().
MicrofeedMain* microfeed_main_new_with_dbus_connection | ( | DBusConnection * | connection | ) |
Instantiates a new main loop with a given DBus connection.
This function binds the DBus connection into the main loop with the following functions: dbus_connection_set_dispatch_status_function, dbus_connection_set_timeout_functions, dbus_connection_set_watch_functions, and dbus_connection_set_wakeup_main_function. Do not call those functions in your application.
This function should be only called, if the shared session-wide DBus connection is not used, but an application wants to use, say, system-wide DBus connection.
connection | A DBus connection to use in the main loop. |
Definition at line 96 of file microfeedmain.c.
References _MicrofeedMain::connection, microfeed_memory_allocate, microfeed_mutex_new(), _MicrofeedMain::mutex, _MicrofeedMain::poll_fds, _MicrofeedMain::polling, _MicrofeedMain::timeouts, _MicrofeedMain::wakeup_pipe, _MicrofeedMain::watches, and _MicrofeedMain::watches_count.
Referenced by microfeed_main_new().
void microfeed_main_remove_timeout | ( | MicrofeedMain * | microfeed_main, | |
MicrofeedTimeout * | timeout | |||
) |
Removes a previously added timeout from the main loop.
TODO: There might be sitations when a timeout is already removed by the main loop itself, and thus the application crashes when using this function.
microfeed_main | Instantiated MicrofeedMain. | |
timeout | A timeout previously added but not yet removed. |
Definition at line 414 of file microfeedmain.c.
References _MicrofeedTimeout::main, microfeed_memory_free(), microfeed_mutex_lock(), microfeed_mutex_unlock(), _MicrofeedMain::mutex, _MicrofeedTimeout::next, _MicrofeedTimeout::previous, and _MicrofeedMain::timeouts.
Referenced by microfeed_main_loop().
void microfeed_main_remove_watch | ( | MicrofeedMain * | microfeed_main, | |
MicrofeedWatch * | watch | |||
) |
Removes a previously added file descriptor watch from the main loop.
microfeed_main | Instantiated MicrofeedMain. | |
watch | A watch previously added but not yet removed. |
Definition at line 438 of file microfeedmain.c.
References _MicrofeedWatch::main, microfeed_memory_free(), microfeed_mutex_lock(), microfeed_mutex_unlock(), _MicrofeedMain::mutex, _MicrofeedWatch::next, _MicrofeedMain::poll_fds, _MicrofeedWatch::previous, _MicrofeedMain::watch_iterator, _MicrofeedMain::watches, and _MicrofeedMain::watches_count.