-
Notifications
You must be signed in to change notification settings - Fork 166
/
ESPProvisioner.m
94 lines (81 loc) · 3.04 KB
/
ESPProvisioner.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//
// ESPProvisioner.m
// EspTouchDemo
//
// Created by fanbaoying on 2019/12/10.
// Copyright © 2019 Espressif. All rights reserved.
//
#import "ESPProvisioner.h"
@interface ESPProvisioner()
@end
@implementation ESPProvisioner
+ (instancetype)share {
static ESPProvisioner *share = nil;
static dispatch_once_t oneToken;
dispatch_once(&oneToken, ^{
share = [[ESPProvisioner alloc] init];
});
return share;
}
- (void)startSyncWithDelegate:(id<ESPProvisionerDelegate> _Nullable)delegate {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
ESPSyncStartCB startCB = delegate && [delegate respondsToSelector:@selector(onSyncStart)] ? ^{
if (delegate) {
[delegate onSyncStart];
}
} : nil;
ESPSyncStopCB stopCB = delegate && [delegate respondsToSelector:@selector(onSyncStop)] ? ^{
if (delegate) {
[delegate onSyncStop];
}
} : nil;
ESPSyncErrorCB errorCB = delegate && [delegate respondsToSelector:@selector(onSyncError:)] ? ^(NSException * _Nonnull exception) {
if (delegate) {
[delegate onSyncError:exception];
}
} : nil;
[[ESPProvisioningUDP share] startSyncOnStart:startCB onStop:stopCB onError:errorCB];
});
}
- (void)stopSync {
[[ESPProvisioningUDP share] stopSync];
}
- (BOOL)isSyncing {
return [[ESPProvisioningUDP share] isSyncing];
}
- (void)startProvisioning:(ESPProvisioningRequest *)request withDelegate:(id<ESPProvisionerDelegate> _Nullable)delegate {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
ESPProvisionStartCB startCB = delegate && [delegate respondsToSelector:@selector(onProvisioningStart)] ? ^{
// OnStart
if (delegate) {
[delegate onProvisioningStart];
}
} : nil;
ESPProvisionStopCB stopCB = delegate && [delegate respondsToSelector:@selector(onProvisioningStop)] ? ^{
// OnStop
if (delegate) {
[delegate onProvisioningStop];
}
} : nil;
ESPProvisionResultCB resultCB = delegate && [delegate respondsToSelector:@selector(onProvisoningScanResult:)] ? ^(ESPProvisioningResult * _Nonnull result) {
// onResult
if (delegate) {
[delegate onProvisoningScanResult:result];
}
} : nil;
ESPProvisionErrorCB errorCB = delegate && [delegate respondsToSelector:@selector(onProvisioningError:)] ? ^(NSException * _Nonnull exception) {
// onError
if (delegate) {
[delegate onProvisioningError:exception];
}
} : nil;
[[ESPProvisioningUDP share] startProvision:request onStart:startCB onStop:stopCB onResult:resultCB onError: errorCB];
});
}
- (void)stopProvisioning {
[[ESPProvisioningUDP share] stopProvision];
}
- (BOOL)isProvisioning {
return [[ESPProvisioningUDP share] isProvisioning];
}
@end