2 * Copyright (c) 2017-2018 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
25 * Modification History
27 * November 15, 2017 Allan Nathanson <ajn@apple.com>
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"
45 __log_Spectacles(void)
47 static os_log_t log = NULL;
50 log = os_log_create("com.apple.spectacles", "SystemConfiguration");
57 #pragma mark SystemConfiguratioin Network Event Factory
59 @interface EventFactory ()
60 @property NSDictionary<NSString *, SCLogParser *> *parserMap;
63 @implementation EventFactory
65 - (void)startWithLogSourceAttributes:(__unused NSDictionary<NSString *, NSObject *> *)attributes
67 NSMutableDictionary<NSString *, SCLogParser *> *newParserMap = [[NSMutableDictionary alloc] init];
70 parser = [[InterfaceNamerParser alloc] init];
71 newParserMap[parser.category] = parser;
73 parser = [[IPConfigurationParser alloc] init];
74 newParserMap[parser.category] = parser;
76 parser = [[IPMonitorParser alloc] init];
77 newParserMap[parser.category] = parser;
79 parser = [[KernelEventMonitorParser alloc] init];
80 newParserMap[parser.category] = parser;
82 parser = [[PreferencesMonitorParser alloc] init];
83 newParserMap[parser.category] = parser;
85 parser = [[StateDumpParser alloc] init];
86 newParserMap[parser.category] = parser;
88 _parserMap = [[NSDictionary alloc] initWithDictionary:newParserMap];
91 - (void)handleLogEvent:(EFLogEvent *)logEvent completionHandler:(void (^)(NSArray<EFEvent *> * _Nullable))completionHandler
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";
102 if (logEvent.category.length == 0) {
103 specs_log_debug("Skipped message without a category: %@", logEvent.eventMessage);
104 completionHandler(nil);
108 SCLogParser *parser = _parserMap[logEvent.category];
110 specs_log_debug("Skipped message with an unknown category (%@): %@", logEvent.category, logEvent.eventMessage);
111 completionHandler(nil);
115 NSArray<EFEvent *> *completeEvents = [parser.eventParser parseLogEventIntoMultipleEvents:logEvent];
116 completionHandler(completeEvents);
119 - (void)finishWithCompletionHandler:(void (^)(NSArray<EFEvent *> * _Nullable))completionHandler
121 specs_log_notice("Event factory is finishing");
122 completionHandler(nil);