Skip to content

Commit

Permalink
API review (#556)
Browse files Browse the repository at this point in the history
  • Loading branch information
GLinnik21 committed Sep 6, 2024
1 parent 78687d5 commit 85d4eb5
Show file tree
Hide file tree
Showing 35 changed files with 244 additions and 540 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ extension ReportConfig {
guard let store = KSCrash.shared.reportStore else {
return
}
store.sink = CrashReportFilterPipeline(filtersArray: [
store.sink = CrashReportFilterPipeline(filters: [
CrashReportFilterAppleFmt(),
DirectorySink(url),
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public extension CrashReportStore {
}

func logToConsole() {
sink = CrashReportSinkConsole.filter().defaultCrashReportFilterSet()
sink = CrashReportSinkConsole().defaultCrashReportFilterSet
sendAllReports { reports, error in
if let reports {
Self.logger.info("Logged \(reports.count) reports")
Expand All @@ -68,7 +68,7 @@ public extension CrashReportStore {
}

func logWithAlert() {
sink = CrashReportFilterPipeline(filtersArray: [
sink = CrashReportFilterPipeline(filters: [
CrashReportFilterAlert(title: "Sample Alert", message: "Do you want to log?", yesAnswer: "Yes", noAnswer: "No"),
CrashReportFilterAppleFmt(),
CrashReportSinkConsole(),
Expand All @@ -77,7 +77,7 @@ public extension CrashReportStore {
}

func sampleLogToConsole() {
sink = CrashReportFilterPipeline(filtersArray: [
sink = CrashReportFilterPipeline(filters: [
CrashReportFilterDemangle(),
SampleFilter(),
SampleSink(),
Expand Down
8 changes: 0 additions & 8 deletions Sources/KSCrashFilters/KSCrashReportFilterAlert.m
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,6 @@ @interface KSCrashReportFilterAlert ()

@implementation KSCrashReportFilterAlert

+ (instancetype)filterWithTitle:(NSString *)title
message:(nullable NSString *)message
yesAnswer:(NSString *)yesAnswer
noAnswer:(nullable NSString *)noAnswer;
{
return [[self alloc] initWithTitle:title message:message yesAnswer:yesAnswer noAnswer:noAnswer];
}

- (instancetype)initWithTitle:(NSString *)title
message:(nullable NSString *)message
yesAnswer:(NSString *)yesAnswer
Expand Down
10 changes: 5 additions & 5 deletions Sources/KSCrashFilters/KSCrashReportFilterAppleFmt.m
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,6 @@ + (void)initialize
x86Order, @"i686", x86_64Order, @"x86_64", nil];
}

+ (instancetype)filterWithReportStyle:(KSAppleReportStyle)reportStyle
{
return [[self alloc] initWithReportStyle:reportStyle];
}

- (instancetype)initWithReportStyle:(KSAppleReportStyle)reportStyle
{
if ((self = [super init])) {
Expand All @@ -179,6 +174,11 @@ - (instancetype)initWithReportStyle:(KSAppleReportStyle)reportStyle
return self;
}

- (instancetype)init
{
return [self initWithReportStyle:KSAppleReportStyleSymbolicated];
}

- (int)majorVersion:(NSDictionary *)report
{
NSDictionary *info = [self infoReport:report];
Expand Down
140 changes: 9 additions & 131 deletions Sources/KSCrashFilters/KSCrashReportFilterBasic.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@

@implementation KSCrashReportFilterPassthrough

+ (instancetype)filter
{
return [[self alloc] init];
}

- (void)filterReports:(NSArray<id<KSCrashReport>> *)reports onCompletion:(KSCrashReportFilterCompletion)onCompletion
{
kscrash_callCompletion(onCompletion, reports, nil);
Expand All @@ -49,70 +44,22 @@ - (void)filterReports:(NSArray<id<KSCrashReport>> *)reports onCompletion:(KSCras

@interface KSCrashReportFilterCombine ()

@property(nonatomic, readwrite, copy) NSArray *filters;
@property(nonatomic, readwrite, copy) NSArray *keys;
@property(nonatomic, readwrite, copy) NSArray<id<KSCrashReportFilter>> *filters;
@property(nonatomic, readwrite, copy) NSArray<NSString *> *keys;

@end

@implementation KSCrashReportFilterCombine

- (instancetype)initWithFilters:(NSArray *)filters keys:(NSArray<NSString *> *)keys
- (instancetype)initWithFilters:(NSDictionary<NSString *, id<KSCrashReportFilter>> *)filterDictionary
{
if ((self = [super init])) {
_filters = [filters copy];
_keys = [keys copy];
_filters = [filterDictionary.allValues copy];
_keys = [filterDictionary.allKeys copy];
}
return self;
}

+ (KSVA_Block)argBlockWithFilters:(NSMutableArray *)filters andKeys:(NSMutableArray *)keys
{
__block BOOL isKey = FALSE;
KSVA_Block block = ^(id entry) {
if (isKey) {
if (entry == nil) {
KSLOG_ERROR(@"key entry was nil");
} else {
[keys addObject:entry];
}
} else {
if ([entry isKindOfClass:[NSArray class]]) {
entry = [KSCrashReportFilterPipeline filterWithFilters:entry, nil];
}
if (![entry conformsToProtocol:@protocol(KSCrashReportFilter)]) {
KSLOG_ERROR(@"Not a filter: %@", entry);
// Cause next key entry to fail as well.
return;
} else {
[filters addObject:entry];
}
}
isKey = !isKey;
};
return [block copy];
}

+ (instancetype)filterWithFiltersAndKeys:(id)firstFilter, ...
{
NSMutableArray *filters = [NSMutableArray array];
NSMutableArray *keys = [NSMutableArray array];
ksva_iterate_list(firstFilter, [self argBlockWithFilters:filters andKeys:keys]);
return [[self class] filterWithFilters:filters keys:keys];
}

+ (instancetype)filterWithFilters:(NSArray *)filters keys:(NSArray<NSString *> *)keys
{
return [[self alloc] initWithFilters:filters keys:keys];
}

- (instancetype)initWithFiltersAndKeys:(id)firstFilter, ...
{
NSMutableArray *filters = [NSMutableArray array];
NSMutableArray *keys = [NSMutableArray array];
ksva_iterate_list(firstFilter, [[self class] argBlockWithFilters:filters andKeys:keys]);
return [self initWithFilters:filters keys:keys];
}

- (void)filterReports:(NSArray<id<KSCrashReport>> *)reports onCompletion:(KSCrashReportFilterCompletion)onCompletion
{
NSArray *filters = self.filters;
Expand Down Expand Up @@ -204,35 +151,10 @@ @interface KSCrashReportFilterPipeline ()

@implementation KSCrashReportFilterPipeline

+ (instancetype)filterWithFilters:(id)firstFilter, ...
{
ksva_list_to_nsarray(firstFilter, filters);
return [[self class] filterWithFiltersArray:filters];
}

+ (instancetype)filterWithFiltersArray:(NSArray *)filters
{
return [[self alloc] initWithFiltersArray:filters];
}

- (instancetype)initWithFilters:(id)firstFilter, ...
{
ksva_list_to_nsarray(firstFilter, filters);
return [self initWithFiltersArray:filters];
}

- (instancetype)initWithFiltersArray:(NSArray *)filters
- (instancetype)initWithFilters:(NSArray<id<KSCrashReportFilter>> *)filters
{
if ((self = [super init])) {
NSMutableArray *expandedFilters = [NSMutableArray array];
for (id<KSCrashReportFilter> filter in filters) {
if ([filter isKindOfClass:[NSArray class]]) {
[expandedFilters addObjectsFromArray:(NSArray *)filter];
} else {
[expandedFilters addObject:filter];
}
}
_filters = [expandedFilters copy];
_filters = [filters copy];
}
return self;
}
Expand Down Expand Up @@ -305,24 +227,7 @@ @interface KSCrashReportFilterConcatenate ()

@implementation KSCrashReportFilterConcatenate

+ (instancetype)filterWithSeparatorFmt:(NSString *)separatorFmt keys:(id)firstKey, ...
{
ksva_list_to_nsarray(firstKey, keys);
return [[self class] filterWithSeparatorFmt:separatorFmt keysArray:keys];
}

+ (instancetype)filterWithSeparatorFmt:(NSString *)separatorFmt keysArray:(NSArray<NSString *> *)keys
{
return [[self alloc] initWithSeparatorFmt:separatorFmt keysArray:keys];
}

- (instancetype)initWithSeparatorFmt:(NSString *)separatorFmt keys:(id)firstKey, ...
{
ksva_list_to_nsarray(firstKey, keys);
return [self initWithSeparatorFmt:separatorFmt keysArray:keys];
}

- (instancetype)initWithSeparatorFmt:(NSString *)separatorFmt keysArray:(NSArray<NSString *> *)keys
- (instancetype)initWithSeparatorFmt:(NSString *)separatorFmt keys:(NSArray<NSString *> *)keys
{
if ((self = [super init])) {
NSMutableArray *realKeys = [NSMutableArray array];
Expand Down Expand Up @@ -374,24 +279,7 @@ @interface KSCrashReportFilterSubset ()

@implementation KSCrashReportFilterSubset

+ (instancetype)filterWithKeys:(id)firstKeyPath, ...
{
ksva_list_to_nsarray(firstKeyPath, keyPaths);
return [[self class] filterWithKeysArray:keyPaths];
}

+ (instancetype)filterWithKeysArray:(NSArray<NSString *> *)keyPaths
{
return [[self alloc] initWithKeysArray:keyPaths];
}

- (instancetype)initWithKeys:(id)firstKeyPath, ...
{
ksva_list_to_nsarray(firstKeyPath, keyPaths);
return [self initWithKeysArray:keyPaths];
}

- (instancetype)initWithKeysArray:(NSArray<NSString *> *)keyPaths
- (instancetype)initWithKeys:(NSArray<NSString *> *)keyPaths
{
if ((self = [super init])) {
NSMutableArray *realKeyPaths = [NSMutableArray array];
Expand Down Expand Up @@ -439,11 +327,6 @@ - (void)filterReports:(NSArray<id<KSCrashReport>> *)reports onCompletion:(KSCras

@implementation KSCrashReportFilterDataToString

+ (instancetype)filter
{
return [[self alloc] init];
}

- (void)filterReports:(NSArray<id<KSCrashReport>> *)reports onCompletion:(KSCrashReportFilterCompletion)onCompletion
{
NSMutableArray<id<KSCrashReport>> *filteredReports = [NSMutableArray arrayWithCapacity:[reports count]];
Expand All @@ -468,11 +351,6 @@ - (void)filterReports:(NSArray<id<KSCrashReport>> *)reports onCompletion:(KSCras

@implementation KSCrashReportFilterStringToData

+ (instancetype)filter
{
return [[self alloc] init];
}

- (void)filterReports:(NSArray<id<KSCrashReport>> *)reports onCompletion:(KSCrashReportFilterCompletion)onCompletion
{
NSMutableArray<id<KSCrashReport>> *filteredReports = [NSMutableArray arrayWithCapacity:[reports count]];
Expand Down
10 changes: 0 additions & 10 deletions Sources/KSCrashFilters/KSCrashReportFilterGZip.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ @interface KSCrashReportFilterGZipCompress ()

@implementation KSCrashReportFilterGZipCompress

+ (instancetype)filterWithCompressionLevel:(NSInteger)compressionLevel
{
return [[self alloc] initWithCompressionLevel:compressionLevel];
}

- (instancetype)initWithCompressionLevel:(NSInteger)compressionLevel
{
if ((self = [super init])) {
Expand Down Expand Up @@ -80,11 +75,6 @@ - (void)filterReports:(NSArray<id<KSCrashReport>> *)reports onCompletion:(KSCras

@implementation KSCrashReportFilterGZipDecompress

+ (instancetype)filter
{
return [[self alloc] init];
}

- (void)filterReports:(NSArray<id<KSCrashReport>> *)reports onCompletion:(KSCrashReportFilterCompletion)onCompletion
{
NSMutableArray<id<KSCrashReport>> *filteredReports = [NSMutableArray arrayWithCapacity:[reports count]];
Expand Down
20 changes: 10 additions & 10 deletions Sources/KSCrashFilters/KSCrashReportFilterJSON.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ @interface KSCrashReportFilterJSONEncode ()

@implementation KSCrashReportFilterJSONEncode

+ (instancetype)filterWithOptions:(KSJSONEncodeOption)options
{
return [[self alloc] initWithOptions:options];
}

- (instancetype)initWithOptions:(KSJSONEncodeOption)options
{
if ((self = [super init])) {
Expand All @@ -51,6 +46,11 @@ - (instancetype)initWithOptions:(KSJSONEncodeOption)options
return self;
}

- (instancetype)init
{
return [self initWithOptions:KSJSONEncodeOptionNone];
}

- (void)filterReports:(NSArray<id<KSCrashReport>> *)reports onCompletion:(KSCrashReportFilterCompletion)onCompletion
{
NSMutableArray<id<KSCrashReport>> *filteredReports = [NSMutableArray arrayWithCapacity:[reports count]];
Expand Down Expand Up @@ -83,11 +83,6 @@ @interface KSCrashReportFilterJSONDecode ()

@implementation KSCrashReportFilterJSONDecode

+ (instancetype)filterWithOptions:(KSJSONDecodeOption)options
{
return [[self alloc] initWithOptions:options];
}

- (instancetype)initWithOptions:(KSJSONDecodeOption)options
{
if ((self = [super init])) {
Expand All @@ -96,6 +91,11 @@ - (instancetype)initWithOptions:(KSJSONDecodeOption)options
return self;
}

- (instancetype)init
{
return [self initWithOptions:KSJSONDecodeOptionNone];
}

- (void)filterReports:(NSArray<id<KSCrashReport>> *)reports onCompletion:(KSCrashReportFilterCompletion)onCompletion
{
NSMutableArray<id<KSCrashReport>> *filteredReports = [NSMutableArray arrayWithCapacity:[reports count]];
Expand Down
Loading

0 comments on commit 85d4eb5

Please sign in to comment.