blob: aaca00809c4584414ffdc32c4ca25ab3d3e17534 (
plain)
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
|
#import "MWMTrafficManager.h"
#import "MWMCommon.h"
#include "Framework.h"
#include "map/traffic_manager.hpp"
namespace
{
using Observer = id<MWMTrafficManagerObserver>;
using Observers = NSHashTable<Observer>;
} // namespace
@interface MWMTrafficManager ()
@property(nonatomic) Observers * observers;
@property(nonatomic) TrafficManager::TrafficState state;
@end
@implementation MWMTrafficManager
#pragma mark - Instance
+ (MWMTrafficManager *)manager
{
static MWMTrafficManager * manager;
static dispatch_once_t onceToken = 0;
dispatch_once(&onceToken, ^{
manager = [[super alloc] initManager];
});
return manager;
}
- (instancetype)initManager
{
self = [super init];
if (self)
{
_observers = [Observers weakObjectsHashTable];
auto & m = GetFramework().GetTrafficManager();
m.SetStateListener([self](TrafficManager::TrafficState state) {
self.state = state;
for (Observer observer in self.observers)
[observer onTrafficStateUpdated];
});
}
return self;
}
#pragma mark - Add/Remove Observers
+ (void)addObserver:(Observer)observer
{
[[MWMTrafficManager manager].observers addObject:observer];
}
+ (void)removeObserver:(Observer)observer
{
[[MWMTrafficManager manager].observers removeObject:observer];
}
+ (MWMTrafficManagerState)state
{
switch ([MWMTrafficManager manager].state)
{
case TrafficManager::TrafficState::Disabled: return MWMTrafficManagerStateDisabled;
case TrafficManager::TrafficState::Enabled: return MWMTrafficManagerStateEnabled;
case TrafficManager::TrafficState::WaitingData: return MWMTrafficManagerStateWaitingData;
case TrafficManager::TrafficState::Outdated: return MWMTrafficManagerStateOutdated;
case TrafficManager::TrafficState::NoData: return MWMTrafficManagerStateNoData;
case TrafficManager::TrafficState::NetworkError: return MWMTrafficManagerStateNetworkError;
case TrafficManager::TrafficState::ExpiredData: return MWMTrafficManagerStateExpiredData;
case TrafficManager::TrafficState::ExpiredApp: return MWMTrafficManagerStateExpiredApp;
}
}
+ (void)enableTraffic:(BOOL)enable
{
auto & f = GetFramework();
f.GetTrafficManager().SetEnabled(enable);
f.SaveTrafficEnabled(enable);
}
@end
|