reflect http status updates

master
Jordan Orelli 8 years ago
parent 9ce7bcefe6
commit fd612c80d3

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