reflect http status updates

master
Jordan Orelli 7 years ago
parent 9ce7bcefe6
commit fd612c80d3

@ -1,4 +1,5 @@
#import "RequestHistory.h"
#import "RequestHistoryItem.h"
@interface RequestHistory ()
@property (strong) NSMutableArray *items;
@ -20,19 +21,21 @@
- (id) tableView:(NSTableView *)view objectValueForTableColumn:(NSTableColumn *)column row:(NSInteger) row {
NSLog(@"[RequestHistory] objectValueForTableColumn: %@ row: %zd", column, row);
NSValue *val = [[self items] objectAtIndex:row];
if (!val) {
RequestHistoryItem *item = [[self items] objectAtIndex:row];
if (!item) {
return nil;
}
RequestMeta meta;
[val getValue:&meta];
if ([[column identifier] isEqualToString:@"id"]) {
return [NSNumber numberWithInt:meta.seq];
return [NSNumber numberWithInt:[item seq]];
} else if ([[column identifier] isEqualToString:@"status"]) {
return @"???";
if ([item status] == 0) {
return @"???";
} else {
return [NSNumber numberWithInt:[item status]];
}
} else if ([[column identifier] isEqualToString:@"path"]) {
return [NSString stringWithUTF8String:meta.path];
return [item path];
} else {
return @"fuck";
}
@ -40,11 +43,13 @@
- (void) addRequestItem:(RequestMeta *)meta {
NSLog(@"[RequestHistory] add request item");
[[self items] addObject:[NSValue valueWithBytes:meta objCType:@encode(RequestMeta)]];
[[self items] addObject:[RequestHistoryItem itemWithRequestMeta:meta]];
}
- (void) addResponseItem:(ResponseMeta *)meta {
NSLog(@"[RequestHistory] add response item");
id item = [[self items] objectAtIndex:meta->seq-1];
[item updateWithResponseMeta:meta];
}
@end

@ -0,0 +1,15 @@
#import <Cocoa/Cocoa.h>
#import "ui_darwin.h"
@interface RequestHistoryItem : NSObject
@property (readonly) int seq;
@property (readonly, strong) NSString *path;
@property (readonly) int status;
@property (readonly) int bytes;
+ (instancetype) itemWithRequestMeta:(RequestMeta *)meta;
- (instancetype) initWithRequestMeta:(RequestMeta *)meta;
- (void) updateWithResponseMeta:(ResponseMeta *)meta;
@end

@ -0,0 +1,26 @@
#import "RequestHistoryItem.h"
@implementation RequestHistoryItem
+ (instancetype) itemWithRequestMeta:(RequestMeta *)meta {
return [[self alloc] initWithRequestMeta:meta];
}
- (instancetype) initWithRequestMeta:(RequestMeta *)meta {
self = [super init];
if (self) {
_seq = meta->seq;
_path = [NSString stringWithUTF8String:meta->path];
}
return self;
}
- (void) updateWithResponseMeta:(ResponseMeta *)meta {
if (meta->seq != self.seq) {
return;
}
_status = meta->status;
_bytes = meta->bytes;
}
@end
Loading…
Cancel
Save