1
0
Fork 0

Added proper use of detected wan port, enabled status timer, modified license for CC BY-SH-NC

master
Matthieu Lalonde 14 years ago
parent f44983df4c
commit 051581253e

@ -2,8 +2,8 @@
// DDWRT_MonitorAppDelegate.h // DDWRT_MonitorAppDelegate.h
// DDWRT-Monitor // DDWRT-Monitor
// //
// Created by Matthieu Lalonde on 11-05-27. // Created by Matthieu Lalonde & Spike Grobstein on 11-05-27.
// Copyright 2011 __MyCompanyName__. All rights reserved. // Copyleft 2011 Spurf CC BY-SH-NC. Some rights reserved.
// //
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>

@ -2,8 +2,8 @@
// DDWRT_MonitorAppDelegate.m // DDWRT_MonitorAppDelegate.m
// DDWRT-Monitor // DDWRT-Monitor
// //
// Created by Matthieu Lalonde on 11-05-27. // Created by Matthieu Lalonde & Spike Grobstein on 11-05-27.
// Copyright 2011 __MyCompanyName__. All rights reserved. // Copyleft 2011 Spurf CC BY-SH-NC. Some rights reserved.
// //
#import "DDWRT_MonitorAppDelegate.h" #import "DDWRT_MonitorAppDelegate.h"
@ -36,8 +36,9 @@
wrt_client = [[WRTStatusClient alloc] initWithHostname:hostname port:port protocol:protocol username:username password:password]; wrt_client = [[WRTStatusClient alloc] initWithHostname:hostname port:port protocol:protocol username:username password:password];
[wrt_client getConnectionStatus]; [wrt_client getConnectionStatus];
NSLog(@"Status %@ wan port: %@", ([wrt_client wrtReachable] ? @"Up" : @"Down"), [wrt_client wanPort]); 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:NO]; _readTimer = [NSTimer scheduledTimerWithTimeInterval:[[NSUserDefaults standardUserDefaults] integerForKey:@"refreshTime"] target:self selector:@selector(updateThroughput:) userInfo:nil repeats:YES];
[_readTimer fire]; [_readTimer fire];
//[self updateThroughput]; //[self updateThroughput];
@ -219,7 +220,7 @@
// //
[BandwidthViewer makeKeyAndOrderFront:nil]; [BandwidthViewer makeKeyAndOrderFront:nil];
NSURLRequest *request = [[wrt_client requestForBandwidthViewerForInterface:@"ppp0"] retain]; NSURLRequest *request = [[wrt_client requestForBandwidthViewerForInterface:[wrt_client getWanPort]] retain];
[ [BandwidthViewerWebView mainFrame] loadRequest: request ]; [ [BandwidthViewerWebView mainFrame] loadRequest: request ];
} }
@ -324,7 +325,15 @@
- (void) updateThroughput:(NSTimer*)timer - (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]; //WRTRequest *wrtr = [[WRTRequest alloc] init];
//[wrtr doRequest:self requestSelector:@selector(throughputCallback:) uri:@"fetchif.cgi?ppp1"]; //[wrtr doRequest:self requestSelector:@selector(throughputCallback:) uri:@"fetchif.cgi?ppp1"];

@ -1,17 +0,0 @@
//
// WRTRequestParser.h
// DDWRT-Monitor
//
// Created by Matthieu Lalonde on 11-06-02.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface WRTRequestParser : NSObject {
@private
}
@end

@ -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

@ -2,17 +2,17 @@
// WRTStatusClient.h // WRTStatusClient.h
// DDWRT-Monitor // DDWRT-Monitor
// //
// Created by Spike Grobstein on 5/30/11. // Created by Matthieu Lalonde & Spike Grobstein on 11-05-27.
// Copyright 2011 Sadistech. All rights reserved. // Copyleft 2011 Spurf CC BY-SH-NC. Some rights reserved.
// //
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
@interface WRTStatusClient : NSObject { @interface WRTStatusClient : NSObject {
@private
BOOL wrtReachable; BOOL wrtReachable;
NSString *wanPort; NSString *wanPort;
@private
NSString *hostname; NSString *hostname;
NSString *protocol; NSString *protocol;
int port; int port;
@ -23,18 +23,17 @@
NSURLRequest *theRequest; NSURLRequest *theRequest;
NSURLConnection *theConnection; NSURLConnection *theConnection;
id delegate; id delegate;
SEL callback; SEL callback;
SEL errorCallback; SEL errorCallback;
} }
@property BOOL wrtReachable; @property BOOL wrtReachable;
@property(nonatomic, retain) NSString *wanPort;
@property(nonatomic, retain) NSMutableData *receivedData; @property(nonatomic, retain) NSMutableData *receivedData;
@property(nonatomic, retain) id delegate; @property(nonatomic, retain) id delegate;
@property(nonatomic) SEL callback; @property(nonatomic) SEL callback;
@property(nonatomic) SEL errorCallback; @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; - (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 *)getKey:(NSString *)stringData key:(NSString *)key;
- (NSString*) getWanPort;
- (void) setWanPort:(NSString*)new_wanport;
- (NSString*) getHostname; - (NSString*) getHostname;
- (void) setHostname:(NSString*)new_hostname; - (void) setHostname:(NSString*)new_hostname;

@ -2,8 +2,8 @@
// WRTStatusClient.m // WRTStatusClient.m
// DDWRT-Monitor // DDWRT-Monitor
// //
// Created by Spike Grobstein on 5/30/11. // Created by Matthieu Lalonde & Spike Grobstein on 11-05-27.
// Copyright 2011 Sadistech. All rights reserved. // Copyleft 2011 Spurf CC BY-SH-NC. Some rights reserved.
// //
#import "WRTStatusClient.h" #import "WRTStatusClient.h"
@ -12,7 +12,6 @@
@implementation WRTStatusClient @implementation WRTStatusClient
@synthesize wrtReachable; @synthesize wrtReachable;
@synthesize wanPort;
@synthesize receivedData; @synthesize receivedData;
@synthesize delegate; @synthesize delegate;
@ -30,6 +29,7 @@
[self setPassword: new_password]; [self setPassword: new_password];
wrtReachable = false; wrtReachable = false;
wanPort = nil;
return self; return self;
} }
@ -106,7 +106,10 @@
startRange = [stringData rangeOfString:key]; startRange = [stringData rangeOfString:key];
stringData = [stringData substringFromIndex:(startRange.location + [key length])]; stringData = [stringData substringFromIndex:(startRange.location + [key length])];
NSRange endRange = [stringData rangeOfString:@"\""]; 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 -
#pragma mark Accessors: #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 - (NSString*) getHostname
{ {
return hostname; return hostname;
@ -229,9 +245,7 @@
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data -(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{ {
NSLog(@"3 %lu", [data length]);
[receivedData appendData:data]; [receivedData appendData:data];
NSLog(@"3 %lu", [receivedData length]);
} }
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error -(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error

Loading…
Cancel
Save