this repo has no description
at fixPythonPipStalling 127 lines 3.8 kB view raw
1/* 2 * Copyright (c) 2017-2018 Apple Inc. All rights reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23 24/* 25 * Modification History 26 * 27 * November 15, 2017 Allan Nathanson <ajn@apple.com> 28 * - initial revision 29 */ 30 31#import <os/log.h> 32#import "EventFactory.h" 33#import "SCLogParser.h" 34#import "InterfaceNamerParser.h" 35#import "IPMonitorParser.h" 36#import "KernelEventMonitorParser.h" 37#import "PreferencesMonitorParser.h" 38#import "StateDumpParser.h" 39#import "IPConfigurationParser.h" 40 41#pragma mark - 42#pragma mark Logging 43 44os_log_t 45__log_Spectacles(void) 46{ 47 static os_log_t log = NULL; 48 49 if (log == NULL) { 50 log = os_log_create("com.apple.spectacles", "SystemConfiguration"); 51 } 52 53 return log; 54} 55 56#pragma mark - 57#pragma mark SystemConfiguratioin Network Event Factory 58 59@interface EventFactory () 60@property NSDictionary<NSString *, SCLogParser *> *parserMap; 61@end 62 63@implementation EventFactory 64 65- (void)startWithLogSourceAttributes:(__unused NSDictionary<NSString *, NSObject *> *)attributes 66{ 67 NSMutableDictionary<NSString *, SCLogParser *> *newParserMap = [[NSMutableDictionary alloc] init]; 68 SCLogParser *parser; 69 70 parser = [[InterfaceNamerParser alloc] init]; 71 newParserMap[parser.category] = parser; 72 73 parser = [[IPConfigurationParser alloc] init]; 74 newParserMap[parser.category] = parser; 75 76 parser = [[IPMonitorParser alloc] init]; 77 newParserMap[parser.category] = parser; 78 79 parser = [[KernelEventMonitorParser alloc] init]; 80 newParserMap[parser.category] = parser; 81 82 parser = [[PreferencesMonitorParser alloc] init]; 83 newParserMap[parser.category] = parser; 84 85 parser = [[StateDumpParser alloc] init]; 86 newParserMap[parser.category] = parser; 87 88 _parserMap = [[NSDictionary alloc] initWithDictionary:newParserMap]; 89} 90 91- (void)handleLogEvent:(EFLogEvent *)logEvent completionHandler:(void (^)(NSArray<EFEvent *> * _Nullable))completionHandler 92{ 93 NSString *category = nil; 94 if ([logEvent.eventType isEqualToString:@"stateEvent"]) { 95 category = @"StateDump"; 96 logEvent.subsystem = @"com.apple.SystemConfiguration"; 97 logEvent.category = category; 98 } else if ([logEvent.subsystem isEqualToString:@"com.apple.IPConfiguration"]) { 99 logEvent.category = @"IPConfiguration"; 100 } 101 102 if (logEvent.category.length == 0) { 103 specs_log_debug("Skipped message without a category: %@", logEvent.eventMessage); 104 completionHandler(nil); 105 return; 106 } 107 108 SCLogParser *parser = _parserMap[logEvent.category]; 109 if (parser == nil) { 110 specs_log_debug("Skipped message with an unknown category (%@): %@", logEvent.category, logEvent.eventMessage); 111 completionHandler(nil); 112 return; 113 } 114 115 NSArray<EFEvent *> *completeEvents = [parser.eventParser parseLogEventIntoMultipleEvents:logEvent]; 116 completionHandler(completeEvents); 117} 118 119- (void)finishWithCompletionHandler:(void (^)(NSArray<EFEvent *> * _Nullable))completionHandler 120{ 121 specs_log_notice("Event factory is finishing"); 122 completionHandler(nil); 123} 124 125@end 126 127