diff options
Diffstat (limited to 'platform/darwin/src')
-rw-r--r-- | platform/darwin/src/MGLEventsManager.h | 22 | ||||
-rw-r--r-- | platform/darwin/src/MGLEventsManager.m | 27 | ||||
-rw-r--r-- | platform/darwin/src/MGLEventsManager_Private.h | 11 | ||||
-rw-r--r-- | platform/darwin/src/MGLMetricsManager.h | 32 | ||||
-rw-r--r-- | platform/darwin/src/MGLMetricsManager.m | 45 | ||||
-rw-r--r-- | platform/darwin/src/MGLMetricsManager_Private.h | 13 | ||||
-rw-r--r-- | platform/darwin/src/MGLNetworkConfiguration.m | 6 |
7 files changed, 93 insertions, 63 deletions
diff --git a/platform/darwin/src/MGLEventsManager.h b/platform/darwin/src/MGLEventsManager.h deleted file mode 100644 index a8d92ebd77..0000000000 --- a/platform/darwin/src/MGLEventsManager.h +++ /dev/null @@ -1,22 +0,0 @@ -#import <Foundation/Foundation.h> -#import "MGLFoundation.h" - -NS_ASSUME_NONNULL_BEGIN - -typedef void (^MGLEventHandler)(NSString *eventName, NSDictionary *attributes); - -MGL_EXPORT -@interface MGLEventsManager : NSObject - -/** - Returns the shared logging object. - */ -@property (class, nonatomic, readonly) MGLEventsManager *sharedManager; - -@property (nonatomic, copy, nullable) MGLEventHandler handler; - -@property (nonatomic, assign) BOOL shouldHandleEvents; - -@end - -NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/MGLEventsManager.m b/platform/darwin/src/MGLEventsManager.m deleted file mode 100644 index 3790f55c26..0000000000 --- a/platform/darwin/src/MGLEventsManager.m +++ /dev/null @@ -1,27 +0,0 @@ -#import "MGLEventsManager_Private.h" -#if TARGET_OS_IOS -#import "MGLMapboxEvents.h" -#endif - -@implementation MGLEventsManager - -+ (instancetype)sharedManager -{ - static dispatch_once_t once; - static id sharedConfiguration; - dispatch_once(&once, ^{ - sharedConfiguration = [[self alloc] init]; - }); - return sharedConfiguration; -} - -- (void)handleEvent:(NSString *)eventName withAttributes:(NSDictionary *)attributes { -#if TARGET_OS_IOS - [MGLMapboxEvents pushEvent:eventName withAttributes:attributes]; -#endif - if (self.shouldHandleEvents && self.handler) { - self.handler(eventName, attributes); - } -} - -@end diff --git a/platform/darwin/src/MGLEventsManager_Private.h b/platform/darwin/src/MGLEventsManager_Private.h deleted file mode 100644 index f51768ecb1..0000000000 --- a/platform/darwin/src/MGLEventsManager_Private.h +++ /dev/null @@ -1,11 +0,0 @@ -#import "MGLEventsManager.h" - -NS_ASSUME_NONNULL_BEGIN - -@interface MGLEventsManager (Private) - -- (void)handleEvent:(NSString *)eventName withAttributes:(NSDictionary *)attributes; - -@end - -NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/MGLMetricsManager.h b/platform/darwin/src/MGLMetricsManager.h new file mode 100644 index 0000000000..73756cebed --- /dev/null +++ b/platform/darwin/src/MGLMetricsManager.h @@ -0,0 +1,32 @@ +#import <Foundation/Foundation.h> +#import "MGLFoundation.h" + +NS_ASSUME_NONNULL_BEGIN + +typedef NS_ENUM(NSUInteger, MGLMetricType) { + MGLMetricTypePerformance = 0, +}; + +@protocol MGLMetricsDelegate <NSObject> + +- (BOOL)shouldHandleMetric:(MGLMetricType)metricType; +- (void)didCollectMetric:(MGLMetricType)metricType withAttributes:(NSDictionary *)attributes; + +@end + +typedef void (^MGLEventHandler)(NSString *eventName, NSDictionary *attributes); + +MGL_EXPORT +@interface MGLMetricsManager : NSObject + +@property (class, nonatomic, readonly) MGLMetricsManager *sharedManager; + +@property (nonatomic, weak) id<MGLMetricsDelegate> delegate; + +#if TARGET_OS_IOS +- (void)pushMetric:(MGLMetricType)metricType withAttributes:(NSDictionary *)attributes; +#endif + +@end + +NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/MGLMetricsManager.m b/platform/darwin/src/MGLMetricsManager.m new file mode 100644 index 0000000000..75dc593aa7 --- /dev/null +++ b/platform/darwin/src/MGLMetricsManager.m @@ -0,0 +1,45 @@ +#import "MGLMetricsManager_Private.h" +#if TARGET_OS_IOS +#import "MGLMapboxEvents.h" +#endif + +NSString * const kMGLPerformanceMetric = @"mobile.performance_trace"; + +@implementation MGLMetricsManager + ++ (instancetype)sharedManager +{ + static dispatch_once_t once; + static id sharedConfiguration; + dispatch_once(&once, ^{ + sharedConfiguration = [[self alloc] init]; + }); + return sharedConfiguration; +} + +- (void)handleMetricEvent:(MGLMetricType)metricType withAttributes:(NSDictionary *)attributes { + if ([self.delegate shouldHandleMetric:metricType]) { + [self.delegate didCollectMetric:metricType withAttributes:attributes]; + } +} + +#if TARGET_OS_IOS +- (void)pushMetric:(MGLMetricType)metricType withAttributes:(NSDictionary *)attributes { + + NSString *eventName; + + switch (metricType) { + case MGLMetricTypePerformance: + eventName = kMGLPerformanceMetric; + break; + + default: + break; + } + + [MGLMapboxEvents pushEvent:eventName withAttributes:attributes]; + +} +#endif + +@end diff --git a/platform/darwin/src/MGLMetricsManager_Private.h b/platform/darwin/src/MGLMetricsManager_Private.h new file mode 100644 index 0000000000..4a32710925 --- /dev/null +++ b/platform/darwin/src/MGLMetricsManager_Private.h @@ -0,0 +1,13 @@ +#import "MGLMetricsManager.h" + +NS_ASSUME_NONNULL_BEGIN + +extern NSString *const kMGLPerformanceMetric; + +@interface MGLMetricsManager (Private) + +- (void)handleMetricEvent:(MGLMetricType)metricType withAttributes:(NSDictionary *)attributes; + +@end + +NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/MGLNetworkConfiguration.m b/platform/darwin/src/MGLNetworkConfiguration.m index 5a62a7497b..5682e0bc1e 100644 --- a/platform/darwin/src/MGLNetworkConfiguration.m +++ b/platform/darwin/src/MGLNetworkConfiguration.m @@ -1,5 +1,5 @@ #import "MGLNetworkConfiguration_Private.h" -#import "MGLEventsManager_Private.h" +#import "MGLMetricsManager_Private.h" NSString * const kMGLDownloadPerformanceEvent = @"mobile.performance_trace"; static NSString * const MGLStartTime = @"start_time"; @@ -73,7 +73,7 @@ static NSString * const MGLResourceType = @"resource_type"; { if (urlString && [self.events objectForKey:urlString]) { NSDictionary *eventAttributes = [self eventAttributesForURL:urlString withAction:action]; - [[MGLEventsManager sharedManager] handleEvent:kMGLDownloadPerformanceEvent withAttributes:eventAttributes]; + [[MGLMetricsManager sharedManager] handleMetricEvent:MGLMetricTypePerformance withAttributes:eventAttributes]; [self.events removeObjectForKey:urlString]; } } @@ -96,7 +96,7 @@ static NSString * const MGLResourceType = @"resource_type"; } return @{ - @"event" : kMGLDownloadPerformanceEvent, + @"event" : kMGLPerformanceMetric, @"created" : createdDate, @"sessionId" : [NSUUID UUID].UUIDString, @"counters" : @[ @{ @"name" : @"elapsed_time" , @"value" : @(elapsedTime) } ], |