diff options
Diffstat (limited to 'libusbmuxd/libusbmuxd.c')
| -rw-r--r-- | libusbmuxd/libusbmuxd.c | 18 |
1 files changed, 9 insertions, 9 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) | |||
| 88 | * A reference to a populated usbmuxd_event_t with information about the event | 88 | * A reference to a populated usbmuxd_event_t with information about the event |
| 89 | * and the corresponding device will be passed to the callback function. | 89 | * and the corresponding device will be passed to the callback function. |
| 90 | */ | 90 | */ |
| 91 | static void generate_event(usbmuxd_event_cb_t callback, const usbmuxd_device_info_t *dev, enum usbmuxd_device_event event) | 91 | static void generate_event(usbmuxd_event_cb_t callback, const usbmuxd_device_info_t *dev, enum usbmuxd_device_event event, void *user_data) |
| 92 | { | 92 | { |
| 93 | usbmuxd_event_t ev; | 93 | usbmuxd_event_t ev; |
| 94 | 94 | ||
| @@ -101,7 +101,7 @@ static void generate_event(usbmuxd_event_cb_t callback, const usbmuxd_device_inf | |||
| 101 | 101 | ||
| 102 | printf("%s: event=%d, handle=%d\n", __func__, ev.event, ev.device.handle); | 102 | printf("%s: event=%d, handle=%d\n", __func__, ev.event, ev.device.handle); |
| 103 | 103 | ||
| 104 | callback(&ev); | 104 | callback(&ev, user_data); |
| 105 | } | 105 | } |
| 106 | 106 | ||
| 107 | /** | 107 | /** |
| @@ -157,7 +157,7 @@ static int usbmuxd_listen() | |||
| 157 | * Waits for an event to occur, i.e. a packet coming from usbmuxd. | 157 | * Waits for an event to occur, i.e. a packet coming from usbmuxd. |
| 158 | * Calls generate_event to pass the event via callback to the client program. | 158 | * Calls generate_event to pass the event via callback to the client program. |
| 159 | */ | 159 | */ |
| 160 | int get_next_event(int sfd, usbmuxd_event_cb_t callback) | 160 | int get_next_event(int sfd, usbmuxd_event_cb_t callback, void *user_data) |
| 161 | { | 161 | { |
| 162 | int recv_len; | 162 | int recv_len; |
| 163 | struct usbmuxd_listen_request req; | 163 | struct usbmuxd_listen_request req; |
| @@ -173,7 +173,7 @@ int get_next_event(int sfd, usbmuxd_event_cb_t callback) | |||
| 173 | // is still present so applications know about it | 173 | // is still present so applications know about it |
| 174 | // TODO: is this behaviour correct? | 174 | // TODO: is this behaviour correct? |
| 175 | FOREACH(usbmuxd_device_info_t *dev, &devices) { | 175 | FOREACH(usbmuxd_device_info_t *dev, &devices) { |
| 176 | generate_event(callback, dev, UE_DEVICE_REMOVE); | 176 | generate_event(callback, dev, UE_DEVICE_REMOVE, user_data); |
| 177 | } ENDFOREACH | 177 | } ENDFOREACH |
| 178 | collection_free(&devices); | 178 | collection_free(&devices); |
| 179 | return recv_len; | 179 | return recv_len; |
| @@ -201,7 +201,7 @@ int get_next_event(int sfd, usbmuxd_event_cb_t callback) | |||
| 201 | memcpy(devinfo->uuid, dev.serial_number, sizeof(devinfo->uuid)); | 201 | memcpy(devinfo->uuid, dev.serial_number, sizeof(devinfo->uuid)); |
| 202 | 202 | ||
| 203 | collection_add(&devices, devinfo); | 203 | collection_add(&devices, devinfo); |
| 204 | generate_event(callback, devinfo, UE_DEVICE_ADD); | 204 | generate_event(callback, devinfo, UE_DEVICE_ADD, user_data); |
| 205 | } else if (hdr.message == MESSAGE_DEVICE_REMOVE) { | 205 | } else if (hdr.message == MESSAGE_DEVICE_REMOVE) { |
| 206 | uint32_t handle; | 206 | uint32_t handle; |
| 207 | usbmuxd_device_info_t *dev; | 207 | usbmuxd_device_info_t *dev; |
| @@ -219,7 +219,7 @@ int get_next_event(int sfd, usbmuxd_event_cb_t callback) | |||
| 219 | if (!dev) { | 219 | if (!dev) { |
| 220 | 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); | 220 | 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); |
| 221 | } else { | 221 | } else { |
| 222 | generate_event(callback, dev, UE_DEVICE_REMOVE); | 222 | generate_event(callback, dev, UE_DEVICE_REMOVE, user_data); |
| 223 | collection_remove(&devices, dev); | 223 | collection_remove(&devices, dev); |
| 224 | } | 224 | } |
| 225 | } else { | 225 | } else { |
| @@ -250,7 +250,7 @@ static void *device_monitor(void *data) | |||
| 250 | 250 | ||
| 251 | while (event_cb) { | 251 | while (event_cb) { |
| 252 | printf("waiting for events\n"); | 252 | printf("waiting for events\n"); |
| 253 | int res = get_next_event(listenfd, event_cb); | 253 | int res = get_next_event(listenfd, event_cb, data); |
| 254 | if (res < 0) { | 254 | if (res < 0) { |
| 255 | fprintf(stderr, "%s: closing connection (code %d)\n", __func__, res); | 255 | fprintf(stderr, "%s: closing connection (code %d)\n", __func__, res); |
| 256 | break; | 256 | break; |
| @@ -264,7 +264,7 @@ static void *device_monitor(void *data) | |||
| 264 | return NULL; | 264 | return NULL; |
| 265 | } | 265 | } |
| 266 | 266 | ||
| 267 | int usbmuxd_subscribe(usbmuxd_event_cb_t callback) | 267 | int usbmuxd_subscribe(usbmuxd_event_cb_t callback, void *user_data) |
| 268 | { | 268 | { |
| 269 | int res; | 269 | int res; |
| 270 | 270 | ||
| @@ -273,7 +273,7 @@ int usbmuxd_subscribe(usbmuxd_event_cb_t callback) | |||
| 273 | } | 273 | } |
| 274 | event_cb = callback; | 274 | event_cb = callback; |
| 275 | 275 | ||
| 276 | res = pthread_create(&devmon, NULL, device_monitor, NULL); | 276 | res = pthread_create(&devmon, NULL, device_monitor, user_data); |
| 277 | if (res != 0) { | 277 | if (res != 0) { |
| 278 | fprintf(stderr, "ERROR: Could not start device watcher thread!\n"); | 278 | fprintf(stderr, "ERROR: Could not start device watcher thread!\n"); |
| 279 | return res; | 279 | return res; |
