forked from imkira/mobiledevice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_devices.m
52 lines (42 loc) · 901 Bytes
/
list_devices.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "cli.h"
static int64_t max_count = 0;
static int64_t count = 0;
static void on_device_connected(struct am_device *device)
{
NSString *udid = device_udid(device);
printfNS(@"%@\n", udid);
if ((max_count > 0) && (++count >= max_count))
{
device_unregister(0);
}
}
int list_devices(int argc, char *argv[])
{
int flag;
char *endptr;
int64_t timeout = -1;
while ((flag = getopt(argc, argv, "t:n:")) != -1)
{
switch (flag)
{
case 't':
timeout = strtoll(optarg, &endptr, 10);
break;
case 'n':
max_count = strtoll(optarg, &endptr, 10);
break;
default:
help(argc, argv);
return 1;
}
}
argc -= optind;
argv += optind;
if (argc != 0)
{
return invalid_usage(argc, argv);
}
device_delayed_unregister_status = 0;
device_register(on_device_connected, timeout);
return 1;
}