summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2019-05-22 11:32:11 +0200
committerGravatar Nikias Bassen2019-05-22 11:32:11 +0200
commita6b542b389d0536d2730c1721164a712ec2f020e (patch)
tree52d7010bcf314c1969b0be12f1e49765f2200c77 /include
parent9efb1745bf0eb68064a670b297d4ec7fc98caa02 (diff)
downloadlibusbmuxd-a6b542b389d0536d2730c1721164a712ec2f020e.tar.gz
libusbmuxd-a6b542b389d0536d2730c1721164a712ec2f020e.tar.bz2
Add new usbmuxd_events_subscribe/unsubscribe functions with a context so it can be used in different threads
Diffstat (limited to 'include')
-rw-r--r--include/usbmuxd.h46
1 files changed, 42 insertions, 4 deletions
diff --git a/include/usbmuxd.h b/include/usbmuxd.h
index 6d035a2..9323717 100644
--- a/include/usbmuxd.h
+++ b/include/usbmuxd.h
@@ -80,19 +80,57 @@ typedef struct {
typedef void (*usbmuxd_event_cb_t) (const usbmuxd_event_t *event, void *user_data);
/**
- * Subscribe a callback function so that applications get to know about
- * device add/remove events.
+ * Subscription context type.
+ */
+typedef struct usbmuxd_subscription_context* usbmuxd_subscription_context_t;
+
+/**
+ * Subscribe a callback function to be called upon device add/remove events.
+ * This method can be called multiple times to register multiple callbacks
+ * since every subscription will have its own context (returned in the
+ * first parameter).
+ *
+ * @param context A pointer to a usbmuxd_subscription_context_t that will be
+ * set upon creation of the subscription. The returned context must be
+ * passed to usbmuxd_events_unsubscribe() to unsubscribe the callback.
+ * @param callback A callback function that is executed when an event occurs.
+ * @param user_data Custom data passed on to the callback function. The data
+ * needs to be kept available until the callback function is unsubscribed.
+ *
+ * @return 0 on success or a negative errno value.
+ */
+int usbmuxd_events_subscribe(usbmuxd_subscription_context_t *context, usbmuxd_event_cb_t callback, void *user_data);
+
+/**
+ * Unsubscribe callback function
+ *
+ * @param context A valid context as returned from usbmuxd_events_subscribe().
+ *
+ * @return 0 on success or a negative errno value.
+ */
+int usbmuxd_events_unsubscribe(usbmuxd_subscription_context_t context);
+
+/**
+ * Subscribe a callback (deprecated)
*
* @param callback A callback function that is executed when an event occurs.
+ * @param user_data Custom data passed on to the callback function. The data
+ * needs to be kept available until the callback function is unsubscribed.
*
* @return 0 on success or negative on error.
+ *
+ * @note Deprecated. Use usbmuxd_events_subscribe and usbmuxd_events_unsubscribe instead.
+ * @see usbmuxd_events_subscribe
*/
int usbmuxd_subscribe(usbmuxd_event_cb_t callback, void *user_data);
/**
- * Unsubscribe callback.
+ * Unsubscribe callback (deprecated)
+ *
+ * @return 0 on success or negative on error.
*
- * @return only 0 for now.
+ * @note Deprecated. Use usbmuxd_events_subscribe and usbmuxd_events_unsubscribe instead.
+ * @see usbmuxd_events_unsubscribe
*/
int usbmuxd_unsubscribe();