libkeepalive
|
Provides common base for locking and reference counting. More...
#include <stdarg.h>
#include <stdbool.h>
#include <glib.h>
#include <dbus/dbus.h>
Go to the source code of this file.
Data Structures | |
struct | keepalive_object_t |
Typedefs | |
typedef struct keepalive_object_t | keepalive_object_t |
Provides common base for locking and reference counting.
typedef struct keepalive_object_t keepalive_object_t |
Base object used for locking and reference counting
NOTE: Pointers to keepalive_object_t are assumed to be also pointers to containing object i.e. keepalive_object_t must be the 1st member in containing object structure.
Basic assumptions:
Notable exceptions:
Rough object life cycle:
void keepalive_object_ctor | ( | keepalive_object_t * | self, |
const char * | identity, | ||
GDestroyNotify | shutdown_locked_cb, | ||
GDestroyNotify | delete_cb ) |
Object constructor
self | Object pointer |
identity | Human readable type identification string |
shutdown_locked_cb | Shutdown notification callback function |
delete_cb | Destroy notification callback function |
void keepalive_object_dtor | ( | keepalive_object_t * | self | ) |
Object destructor
self | Object pointer |
void keepalive_object_lock | ( | keepalive_object_t * | self | ) |
Lock object
Attempt to lock already locked object is a logic fault and must be expected to cause a deadlock.
Attempt to lock invalid object is logic fault and must be expected to cause crash or abort.
self | Object pointer |
void keepalive_object_unlock | ( | keepalive_object_t * | self | ) |
Unlock object
Attempt to unlock invalid or already unlocked object is a logic fault and must expected to crash or abort.
self | Object pointer |
void * keepalive_object_ref_external_locked | ( | keepalive_object_t * | self | ) |
Add external reference to object
Implies strong reference, which blocks both object shutdown and destroy.
Attempt to add external references after external reference count has already dropped to zero is a logic fault and will cause an abort.
self | Object pointer |
void * keepalive_object_ref_internal_locked | ( | keepalive_object_t * | self | ) |
Add interal reference to object
Implies weak reference, which blocks object destruction, but not logical shutdown.
Attempt to add internal references after external and external reference counts have already dropped to zero is a logic fault and will cause an abort.
self | Object pointer |
void keepalive_object_unref_external_locked | ( | keepalive_object_t * | self | ) |
Remove external reference to object
Attempt to remove external reference when external reference count is already zero causes an abort.
self | Object pointer |
void keepalive_object_unref_internal_locked | ( | keepalive_object_t * | self | ) |
Remove internal reference to object
Attempt to remove internal reference when internal reference count is already zero causes an abort.
self | Object pointer |
void keepalive_object_unref_internal_cb | ( | void * | aptr | ) |
Callback function for removing internal reference to object
Meant to be used as destroy notification for glib timeouts, dbus pending calls, etc.
Locks object, decrements internal reference count and unlocks the object again.
self | Object pointer |
void keepalive_object_timer_start_locked | ( | keepalive_object_t * | self, |
guint * | timer_id, | ||
guint | interval, | ||
GSourceFunc | notify_cb ) |
Add timer
Add glib timer, bind it to object in such manner that object is not deleted until the timer is either cancelled or finalized.
If timer_id already contains non-zero value, it is canceled 1st.
self | Object pointer |
timer_id | Where timer id is stored |
interval | Timer delay in ms; use zero for idle callback |
notify_cb | Timer trigger callback |
void keepalive_object_timer_stop_locked | ( | keepalive_object_t * | self, |
guint * | timer_id ) |
Remove timer
Cancel glib timer and unbind it from object.
self | Object pointer |
timer_id | Where timer id is stored |
bool keepalive_object_in_shutdown_locked | ( | keepalive_object_t * | self | ) |
Predicate for: object is being shut down
self | Object pointer |
void keepalive_object_ipc_start_locked_va | ( | keepalive_object_t * | self, |
DBusPendingCall ** | where, | ||
DBusPendingCallNotifyFunction | notify_cb, | ||
DBusConnection * | connection, | ||
const char * | service, | ||
const char * | object, | ||
const char * | interface, | ||
const char * | method, | ||
int | arg_type, | ||
va_list | va ) |
Start D-Bus method call
Construct D-Bus method call message. Send it using the specified connection. Bind reply handler to object in such manner that object is not deleted until the pending call is either cancelled or finalized.
If where already contains non-zero value, it is canceled 1st.
self | Object pointer |
where | Where pending call ref is stored |
notify_cb | Notify callback for finished call |
connection | D-Bus connection to use |
service | D-Bus service name |
object | D-Bus object path |
interface | D-Bus interface name |
method | D-Bus method name |
arg_type | The 1st argument type |
va | Further arguments as va-list |
void keepalive_object_ipc_cancel_locked | ( | keepalive_object_t * | self, |
DBusPendingCall ** | where ) |
Cancel D-Bus method call
Cancel D-Bus pending call and unbind it from object.
self | Object pointer |
where | Where pending call ref is stored |
bool keepalive_object_ipc_finish_locked | ( | keepalive_object_t * | self, |
DBusPendingCall ** | where, | ||
DBusPendingCall * | what ) |
Finish D-Bus method call
Unbind D-Bus pending call from object.
self | Object pointer |
where | Where pending call ref is stored |
what | Pending call we are expecting reply to |
void keepalive_object_iowatch_start_locked | ( | keepalive_object_t * | self, |
guint * | iowatch_id, | ||
int | fd, | ||
GIOCondition | cnd, | ||
GIOFunc | io_cb ) |
Add iowatch
Add glib io watch, bind it to object in such manner that object is not deleted until the io watch is removed.
If watch_id already contains non-zero value, it is canceled 1st.
self | Object pointer |
watch_id | Where io watch id is stored |
fd | File descriptor to watch |
cnd | Conditions that trigger notification |
io_cb | Notification callback |
void keepalive_object_iowatch_stop_locked | ( | keepalive_object_t * | self, |
guint * | iowatch_id ) |
Remove iowatch
Cancel glib io watch and unbind it from object.
self | Object pointer |
watch_id | Where io watch id is stored |