diff options
author | Nikias Bassen | 2023-05-07 16:11:31 +0200 |
---|---|---|
committer | Nikias Bassen | 2023-05-07 16:11:31 +0200 |
commit | 386c174736e3085745f9249b4a2d83b2e527d62f (patch) | |
tree | d6f1d3f13cbc8efd94434b70d18ab3d3d4505464 /src/libirecovery.c | |
parent | 4aad1bcdd9d9f499be5ed65b017965cbb54b8f3a (diff) | |
download | libirecovery-386c174736e3085745f9249b4a2d83b2e527d62f.tar.gz libirecovery-386c174736e3085745f9249b4a2d83b2e527d62f.tar.bz2 |
Make sure DEVICE_ADD events are sent to additional event listeners
Thanks to @parov0z for the suggestion.
Diffstat (limited to 'src/libirecovery.c')
-rw-r--r-- | src/libirecovery.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/libirecovery.c b/src/libirecovery.c index 6edb948..5b70c08 100644 --- a/src/libirecovery.c +++ b/src/libirecovery.c @@ -1853,6 +1853,7 @@ struct irecv_device_event_context { struct irecv_usb_device_info { struct irecv_device_info device_info; + enum irecv_mode mode; uint32_t location; int alive; }; @@ -2044,6 +2045,7 @@ static void* _irecv_handle_device_add(void *userdata) memcpy(&(usb_dev_info->device_info), &(client_loc.device_info), sizeof(struct irecv_device_info)); usb_dev_info->location = location; usb_dev_info->alive = 1; + usb_dev_info->mode = client_loc.mode; collection_add(&devices, usb_dev_info); @@ -2434,9 +2436,9 @@ irecv_error_t irecv_device_event_subscribe(irecv_device_event_context_t *context mutex_lock(&listener_mutex); collection_add(&listeners, _context); - mutex_unlock(&listener_mutex); if (th_event_handler == THREAD_T_NULL || !thread_alive(th_event_handler)) { + mutex_unlock(&listener_mutex); struct _irecv_event_handler_info info; cond_init(&info.startup_cond); mutex_init(&info.startup_mutex); @@ -2454,6 +2456,18 @@ irecv_error_t irecv_device_event_subscribe(irecv_device_event_context_t *context mutex_unlock(&info.startup_mutex); cond_destroy(&info.startup_cond); mutex_destroy(&info.startup_mutex); + } else { + /* send DEVICE_ADD events to the new listener */ + FOREACH(struct irecv_usb_device_info *devinfo, &devices) { + if (devinfo && devinfo->alive) { + irecv_device_event_t ev; + ev.type = IRECV_DEVICE_ADD; + ev.mode = devinfo->mode; + ev.device_info = &(devinfo->device_info); + _context->callback(&ev, _context->user_data); + } + } ENDFOREACH + mutex_unlock(&listener_mutex); } *context = _context; |