summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2009-08-26 02:08:00 +0200
committerGravatar Nikias Bassen2009-08-26 02:08:00 +0200
commit8e86e652fbaea2b163f2a5f62ec85fbf1ce0141e (patch)
tree3d0f97521f2bfe269012c7b66b4a70c5d2eb3f29
parenta9712a41ca2324cfa4e275453299772bee662726 (diff)
downloadusbmuxd-8e86e652fbaea2b163f2a5f62ec85fbf1ce0141e.tar.gz
usbmuxd-8e86e652fbaea2b163f2a5f62ec85fbf1ce0141e.tar.bz2
Allow passing user_data to the callback function.
-rw-r--r--libusbmuxd/libusbmuxd.c18
-rw-r--r--libusbmuxd/usbmuxd.h4
2 files changed, 11 insertions, 11 deletions
diff --git a/libusbmuxd/libusbmuxd.c b/libusbmuxd/libusbmuxd.c
index 6a54765..2fbe139 100644
--- a/libusbmuxd/libusbmuxd.c
+++ b/libusbmuxd/libusbmuxd.c
@@ -88,7 +88,7 @@ static int usbmuxd_get_result(int sfd, uint32_t tag, uint32_t * result)
* A reference to a populated usbmuxd_event_t with information about the event
* and the corresponding device will be passed to the callback function.
*/
-static void generate_event(usbmuxd_event_cb_t callback, const usbmuxd_device_info_t *dev, enum usbmuxd_device_event event)
+static void generate_event(usbmuxd_event_cb_t callback, const usbmuxd_device_info_t *dev, enum usbmuxd_device_event event, void *user_data)
{
usbmuxd_event_t ev;
@@ -101,7 +101,7 @@ static void generate_event(usbmuxd_event_cb_t callback, const usbmuxd_device_inf
printf("%s: event=%d, handle=%d\n", __func__, ev.event, ev.device.handle);
- callback(&ev);
+ callback(&ev, user_data);
}
/**
@@ -157,7 +157,7 @@ static int usbmuxd_listen()
* Waits for an event to occur, i.e. a packet coming from usbmuxd.
* Calls generate_event to pass the event via callback to the client program.
*/
-int get_next_event(int sfd, usbmuxd_event_cb_t callback)
+int get_next_event(int sfd, usbmuxd_event_cb_t callback, void *user_data)
{
int recv_len;
struct usbmuxd_listen_request req;
@@ -173,7 +173,7 @@ int get_next_event(int sfd, usbmuxd_event_cb_t callback)
// is still present so applications know about it
// TODO: is this behaviour correct?
FOREACH(usbmuxd_device_info_t *dev, &devices) {
- generate_event(callback, dev, UE_DEVICE_REMOVE);
+ generate_event(callback, dev, UE_DEVICE_REMOVE, user_data);
} ENDFOREACH
collection_free(&devices);
return recv_len;
@@ -201,7 +201,7 @@ int get_next_event(int sfd, usbmuxd_event_cb_t callback)
memcpy(devinfo->uuid, dev.serial_number, sizeof(devinfo->uuid));
collection_add(&devices, devinfo);
- generate_event(callback, devinfo, UE_DEVICE_ADD);
+ generate_event(callback, devinfo, UE_DEVICE_ADD, user_data);
} else if (hdr.message == MESSAGE_DEVICE_REMOVE) {
uint32_t handle;
usbmuxd_device_info_t *dev;
@@ -219,7 +219,7 @@ int get_next_event(int sfd, usbmuxd_event_cb_t callback)
if (!dev) {
fprintf(stderr, "WARNING: got device remove message for handle %d, but couldn't find the corresponding handle in the device list. This event will be ignored.\n", handle);
} else {
- generate_event(callback, dev, UE_DEVICE_REMOVE);
+ generate_event(callback, dev, UE_DEVICE_REMOVE, user_data);
collection_remove(&devices, dev);
}
} else {
@@ -250,7 +250,7 @@ static void *device_monitor(void *data)
while (event_cb) {
printf("waiting for events\n");
- int res = get_next_event(listenfd, event_cb);
+ int res = get_next_event(listenfd, event_cb, data);
if (res < 0) {
fprintf(stderr, "%s: closing connection (code %d)\n", __func__, res);
break;
@@ -264,7 +264,7 @@ static void *device_monitor(void *data)
return NULL;
}
-int usbmuxd_subscribe(usbmuxd_event_cb_t callback)
+int usbmuxd_subscribe(usbmuxd_event_cb_t callback, void *user_data)
{
int res;
@@ -273,7 +273,7 @@ int usbmuxd_subscribe(usbmuxd_event_cb_t callback)
}
event_cb = callback;
- res = pthread_create(&devmon, NULL, device_monitor, NULL);
+ res = pthread_create(&devmon, NULL, device_monitor, user_data);
if (res != 0) {
fprintf(stderr, "ERROR: Could not start device watcher thread!\n");
return res;
diff --git a/libusbmuxd/usbmuxd.h b/libusbmuxd/usbmuxd.h
index f12ae39..5d88348 100644
--- a/libusbmuxd/usbmuxd.h
+++ b/libusbmuxd/usbmuxd.h
@@ -34,7 +34,7 @@ typedef struct {
/**
* Callback function prototype.
*/
-typedef void (*usbmuxd_event_cb_t) (const usbmuxd_event_t *event);
+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
@@ -44,7 +44,7 @@ typedef void (*usbmuxd_event_cb_t) (const usbmuxd_event_t *event);
*
* @return 0 on success or negative on error.
*/
-int usbmuxd_subscribe(usbmuxd_event_cb_t callback);
+int usbmuxd_subscribe(usbmuxd_event_cb_t callback, void *user_data);
/**
* Unsubscribe callback.