From 051581253e703805976bbe67bdc936b0f96845f3 Mon Sep 17 00:00:00 2001 From: Matthieu Lalonde Date: Fri, 3 Jun 2011 11:19:06 -0400 Subject: [PATCH] Added proper use of detected wan port, enabled status timer, modified license for CC BY-SH-NC --- DDWRT_MonitorAppDelegate.h | 4 ++-- DDWRT_MonitorAppDelegate.m | 21 +++++++++++++++------ WRTRequestParser.h | 17 ----------------- WRTRequestParser.m | 29 ----------------------------- WRTStatusClient.h | 22 ++++++++++++---------- WRTStatusClient.m | 26 ++++++++++++++++++++------ 6 files changed, 49 insertions(+), 70 deletions(-) delete mode 100644 WRTRequestParser.h delete mode 100644 WRTRequestParser.m diff --git a/DDWRT_MonitorAppDelegate.h b/DDWRT_MonitorAppDelegate.h index 7a4f2cf..86c275c 100644 --- a/DDWRT_MonitorAppDelegate.h +++ b/DDWRT_MonitorAppDelegate.h @@ -2,8 +2,8 @@ // DDWRT_MonitorAppDelegate.h // DDWRT-Monitor // -// Created by Matthieu Lalonde on 11-05-27. -// Copyright 2011 __MyCompanyName__. All rights reserved. +// Created by Matthieu Lalonde & Spike Grobstein on 11-05-27. +// Copyleft 2011 Spurf CC BY-SH-NC. Some rights reserved. // #import diff --git a/DDWRT_MonitorAppDelegate.m b/DDWRT_MonitorAppDelegate.m index 405fe51..a707037 100644 --- a/DDWRT_MonitorAppDelegate.m +++ b/DDWRT_MonitorAppDelegate.m @@ -2,8 +2,8 @@ // DDWRT_MonitorAppDelegate.m // DDWRT-Monitor // -// Created by Matthieu Lalonde on 11-05-27. -// Copyright 2011 __MyCompanyName__. All rights reserved. +// Created by Matthieu Lalonde & Spike Grobstein on 11-05-27. +// Copyleft 2011 Spurf CC BY-SH-NC. Some rights reserved. // #import "DDWRT_MonitorAppDelegate.h" @@ -36,8 +36,9 @@ wrt_client = [[WRTStatusClient alloc] initWithHostname:hostname port:port protocol:protocol username:username password:password]; [wrt_client getConnectionStatus]; - NSLog(@"Status %@ wan port: %@", ([wrt_client wrtReachable] ? @"Up" : @"Down"), [wrt_client wanPort]); - _readTimer = [NSTimer scheduledTimerWithTimeInterval:[[NSUserDefaults standardUserDefaults] integerForKey:@"refreshTime"] target:self selector:@selector(updateThroughput:) userInfo:nil repeats:NO]; + NSLog(@"Status %@ wan port: %@", ([wrt_client wrtReachable] ? @"Up" : @"Down"), [wrt_client getWanPort]); + _readTimer = [NSTimer scheduledTimerWithTimeInterval:[[NSUserDefaults standardUserDefaults] integerForKey:@"refreshTime"] target:self selector:@selector(updateThroughput:) userInfo:nil repeats:YES]; + [_readTimer fire]; //[self updateThroughput]; @@ -219,7 +220,7 @@ // [BandwidthViewer makeKeyAndOrderFront:nil]; - NSURLRequest *request = [[wrt_client requestForBandwidthViewerForInterface:@"ppp0"] retain]; + NSURLRequest *request = [[wrt_client requestForBandwidthViewerForInterface:[wrt_client getWanPort]] retain]; [ [BandwidthViewerWebView mainFrame] loadRequest: request ]; } @@ -324,7 +325,15 @@ - (void) updateThroughput:(NSTimer*)timer { - NSLog(@"Status %@ wan port: %@", ([wrt_client wrtReachable] ? @"Up" : @"Down"), [wrt_client wanPort]); + NSLog(@"Status %@ wan port: %@", ([wrt_client wrtReachable] ? @"Up" : @"Down"), [wrt_client getWanPort]); + if ([wrt_client wrtReachable] == true && _wrtReachable == false) { + _wrtReachable = true; + [self showMenubarIcon:true]; + } else if ([wrt_client wrtReachable] == false && _wrtReachable == true) { + _wrtReachable = false; + [self showMenubarIcon:false]; + } + //WRTRequest *wrtr = [[WRTRequest alloc] init]; //[wrtr doRequest:self requestSelector:@selector(throughputCallback:) uri:@"fetchif.cgi?ppp1"]; diff --git a/WRTRequestParser.h b/WRTRequestParser.h deleted file mode 100644 index d66e100..0000000 --- a/WRTRequestParser.h +++ /dev/null @@ -1,17 +0,0 @@ -// -// WRTRequestParser.h -// DDWRT-Monitor -// -// Created by Matthieu Lalonde on 11-06-02. -// Copyright 2011 __MyCompanyName__. All rights reserved. -// - -#import - - -@interface WRTRequestParser : NSObject { -@private - -} - -@end diff --git a/WRTRequestParser.m b/WRTRequestParser.m deleted file mode 100644 index 8a7b261..0000000 --- a/WRTRequestParser.m +++ /dev/null @@ -1,29 +0,0 @@ -// -// WRTRequestParser.m -// DDWRT-Monitor -// -// Created by Matthieu Lalonde on 11-06-02. -// Copyright 2011 __MyCompanyName__. All rights reserved. -// - -#import "WRTRequestParser.h" - - -@implementation WRTRequestParser - -- (id)init -{ - self = [super init]; - if (self) { - // Initialization code here. - } - - return self; -} - -- (void)dealloc -{ - [super dealloc]; -} - -@end diff --git a/WRTStatusClient.h b/WRTStatusClient.h index edf5ec6..ab90e58 100644 --- a/WRTStatusClient.h +++ b/WRTStatusClient.h @@ -2,17 +2,17 @@ // WRTStatusClient.h // DDWRT-Monitor // -// Created by Spike Grobstein on 5/30/11. -// Copyright 2011 Sadistech. All rights reserved. +// Created by Matthieu Lalonde & Spike Grobstein on 11-05-27. +// Copyleft 2011 Spurf CC BY-SH-NC. Some rights reserved. // #import @interface WRTStatusClient : NSObject { +@private BOOL wrtReachable; NSString *wanPort; -@private NSString *hostname; NSString *protocol; int port; @@ -23,18 +23,17 @@ NSURLRequest *theRequest; NSURLConnection *theConnection; - id delegate; - SEL callback; - SEL errorCallback; + id delegate; + SEL callback; + SEL errorCallback; } @property BOOL wrtReachable; -@property(nonatomic, retain) NSString *wanPort; @property(nonatomic, retain) NSMutableData *receivedData; -@property(nonatomic, retain) id delegate; -@property(nonatomic) SEL callback; -@property(nonatomic) SEL errorCallback; +@property(nonatomic, retain) id delegate; +@property(nonatomic) SEL callback; +@property(nonatomic) SEL errorCallback; - (id) initWithHostname:(NSString*)new_hostname port:(int)new_port protocol:(NSString*)new_protocol username:(NSString*)new_username password:(NSString*)new_password; @@ -45,6 +44,9 @@ -(NSString *)getKey:(NSString *)stringData key:(NSString *)key; +- (NSString*) getWanPort; +- (void) setWanPort:(NSString*)new_wanport; + - (NSString*) getHostname; - (void) setHostname:(NSString*)new_hostname; diff --git a/WRTStatusClient.m b/WRTStatusClient.m index 91663fd..5264c59 100644 --- a/WRTStatusClient.m +++ b/WRTStatusClient.m @@ -2,8 +2,8 @@ // WRTStatusClient.m // DDWRT-Monitor // -// Created by Spike Grobstein on 5/30/11. -// Copyright 2011 Sadistech. All rights reserved. +// Created by Matthieu Lalonde & Spike Grobstein on 11-05-27. +// Copyleft 2011 Spurf CC BY-SH-NC. Some rights reserved. // #import "WRTStatusClient.h" @@ -12,7 +12,6 @@ @implementation WRTStatusClient @synthesize wrtReachable; -@synthesize wanPort; @synthesize receivedData; @synthesize delegate; @@ -30,6 +29,7 @@ [self setPassword: new_password]; wrtReachable = false; + wanPort = nil; return self; } @@ -106,7 +106,10 @@ startRange = [stringData rangeOfString:key]; stringData = [stringData substringFromIndex:(startRange.location + [key length])]; NSRange endRange = [stringData rangeOfString:@"\""]; - wanPort = [stringData substringToIndex:endRange.location]; + [self setWanPort:[stringData substringToIndex:endRange.location]]; + } else { + wrtReachable = false; + wanPort = nil; } } } @@ -142,6 +145,19 @@ #pragma mark - #pragma mark Accessors: +- (NSString*) getWanPort +{ + return wanPort; +} + +- (void) setWanPort:(NSString*)new_wanport +{ + NSString *old_wanport = hostname; + wanPort = [new_wanport retain]; + [old_wanport autorelease]; +} + + - (NSString*) getHostname { return hostname; @@ -229,9 +245,7 @@ -(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { - NSLog(@"3 %lu", [data length]); [receivedData appendData:data]; - NSLog(@"3 %lu", [receivedData length]); } -(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error