diff options
| -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 { | |||
| 1853 | 1853 | ||
| 1854 | struct irecv_usb_device_info { | 1854 | struct irecv_usb_device_info { |
| 1855 | struct irecv_device_info device_info; | 1855 | struct irecv_device_info device_info; |
| 1856 | enum irecv_mode mode; | ||
| 1856 | uint32_t location; | 1857 | uint32_t location; |
| 1857 | int alive; | 1858 | int alive; |
| 1858 | }; | 1859 | }; |
| @@ -2044,6 +2045,7 @@ static void* _irecv_handle_device_add(void *userdata) | |||
| 2044 | memcpy(&(usb_dev_info->device_info), &(client_loc.device_info), sizeof(struct irecv_device_info)); | 2045 | memcpy(&(usb_dev_info->device_info), &(client_loc.device_info), sizeof(struct irecv_device_info)); |
| 2045 | usb_dev_info->location = location; | 2046 | usb_dev_info->location = location; |
| 2046 | usb_dev_info->alive = 1; | 2047 | usb_dev_info->alive = 1; |
| 2048 | usb_dev_info->mode = client_loc.mode; | ||
| 2047 | 2049 | ||
| 2048 | collection_add(&devices, usb_dev_info); | 2050 | collection_add(&devices, usb_dev_info); |
| 2049 | 2051 | ||
| @@ -2434,9 +2436,9 @@ irecv_error_t irecv_device_event_subscribe(irecv_device_event_context_t *context | |||
| 2434 | 2436 | ||
| 2435 | mutex_lock(&listener_mutex); | 2437 | mutex_lock(&listener_mutex); |
| 2436 | collection_add(&listeners, _context); | 2438 | collection_add(&listeners, _context); |
| 2437 | mutex_unlock(&listener_mutex); | ||
| 2438 | 2439 | ||
| 2439 | if (th_event_handler == THREAD_T_NULL || !thread_alive(th_event_handler)) { | 2440 | if (th_event_handler == THREAD_T_NULL || !thread_alive(th_event_handler)) { |
| 2441 | mutex_unlock(&listener_mutex); | ||
| 2440 | struct _irecv_event_handler_info info; | 2442 | struct _irecv_event_handler_info info; |
| 2441 | cond_init(&info.startup_cond); | 2443 | cond_init(&info.startup_cond); |
| 2442 | mutex_init(&info.startup_mutex); | 2444 | mutex_init(&info.startup_mutex); |
| @@ -2454,6 +2456,18 @@ irecv_error_t irecv_device_event_subscribe(irecv_device_event_context_t *context | |||
| 2454 | mutex_unlock(&info.startup_mutex); | 2456 | mutex_unlock(&info.startup_mutex); |
| 2455 | cond_destroy(&info.startup_cond); | 2457 | cond_destroy(&info.startup_cond); |
| 2456 | mutex_destroy(&info.startup_mutex); | 2458 | mutex_destroy(&info.startup_mutex); |
| 2459 | } else { | ||
| 2460 | /* send DEVICE_ADD events to the new listener */ | ||
| 2461 | FOREACH(struct irecv_usb_device_info *devinfo, &devices) { | ||
| 2462 | if (devinfo && devinfo->alive) { | ||
| 2463 | irecv_device_event_t ev; | ||
| 2464 | ev.type = IRECV_DEVICE_ADD; | ||
| 2465 | ev.mode = devinfo->mode; | ||
| 2466 | ev.device_info = &(devinfo->device_info); | ||
| 2467 | _context->callback(&ev, _context->user_data); | ||
| 2468 | } | ||
| 2469 | } ENDFOREACH | ||
| 2470 | mutex_unlock(&listener_mutex); | ||
| 2457 | } | 2471 | } |
| 2458 | 2472 | ||
| 2459 | *context = _context; | 2473 | *context = _context; |
