diff options
Diffstat (limited to 'src')
-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; |