diff options
| -rw-r--r-- | src/ideviceinstaller.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/ideviceinstaller.c b/src/ideviceinstaller.c index 2be92d3..d1fcfc1 100644 --- a/src/ideviceinstaller.c +++ b/src/ideviceinstaller.c | |||
| @@ -68,6 +68,7 @@ int remove_archive_mode = 0; | |||
| 68 | char *last_status = NULL; | 68 | char *last_status = NULL; |
| 69 | int wait_for_op_complete = 0; | 69 | int wait_for_op_complete = 0; |
| 70 | int notification_expected = 0; | 70 | int notification_expected = 0; |
| 71 | int is_device_connected = 0; | ||
| 71 | int op_completed = 0; | 72 | int op_completed = 0; |
| 72 | int err_occured = 0; | 73 | int err_occured = 0; |
| 73 | int notified = 0; | 74 | int notified = 0; |
| @@ -234,25 +235,38 @@ static int zip_get_app_directory(struct zip* zf, char** path) | |||
| 234 | return 0; | 235 | return 0; |
| 235 | } | 236 | } |
| 236 | 237 | ||
| 238 | static void idevice_event_callback(const idevice_event_t* event, void* userdata) | ||
| 239 | { | ||
| 240 | if (event->event == IDEVICE_DEVICE_REMOVE) { | ||
| 241 | is_device_connected = 0; | ||
| 242 | } | ||
| 243 | } | ||
| 244 | |||
| 237 | static void idevice_wait_for_operation_to_complete() | 245 | static void idevice_wait_for_operation_to_complete() |
| 238 | { | 246 | { |
| 239 | int i = 0; | 247 | int i = 0; |
| 240 | struct timespec ts; | 248 | struct timespec ts; |
| 241 | ts.tv_sec = 0; | 249 | ts.tv_sec = 0; |
| 242 | ts.tv_nsec = 500000000; | 250 | ts.tv_nsec = 500000000; |
| 251 | is_device_connected = 1; | ||
| 252 | |||
| 253 | /* subscribe to make sure to exit on device removal */ | ||
| 254 | idevice_event_subscribe(idevice_event_callback, NULL); | ||
| 243 | 255 | ||
| 244 | /* wait for operation to complete */ | 256 | /* wait for operation to complete */ |
| 245 | while (wait_for_op_complete && !op_completed && !err_occured | 257 | while (wait_for_op_complete && !op_completed && !err_occured |
| 246 | && !notified && (i < 60)) { | 258 | && !notified && (i < 60) && is_device_connected) { |
| 247 | nanosleep(&ts, NULL); | 259 | nanosleep(&ts, NULL); |
| 248 | i++; | 260 | i++; |
| 249 | } | 261 | } |
| 250 | 262 | ||
| 251 | /* wait some time if a notification is expected */ | 263 | /* wait some time if a notification is expected */ |
| 252 | while (notification_expected && !notified && !err_occured && (i < 10)) { | 264 | while (notification_expected && !notified && !err_occured && (i < 10) && is_device_connected) { |
| 253 | nanosleep(&ts, NULL); | 265 | nanosleep(&ts, NULL); |
| 254 | i++; | 266 | i++; |
| 255 | } | 267 | } |
| 268 | |||
| 269 | idevice_event_unsubscribe(); | ||
| 256 | } | 270 | } |
| 257 | 271 | ||
| 258 | static void print_usage(int argc, char **argv) | 272 | static void print_usage(int argc, char **argv) |
