1
0
Fork 0

Initial data updating

master
Matthieu Lalonde 14 years ago
parent 80656b2fb1
commit 2209a88b42

@ -114,7 +114,6 @@
- (void) updateThroughput:(NSTimer*)timer; - (void) updateThroughput:(NSTimer*)timer;
- (void) throughputCallback:(NSData *)data; - (void) throughputCallback:(NSData *)data;
- (void) doUpdateStatus:(NSData *)data; - (void) doUpdateStatus:(NSData *)data;
- (void) configSaveRequestCallback:(NSData *)data;
- (NSString *) stringFromFileSize:(unsigned long long)theSize; - (NSString *) stringFromFileSize:(unsigned long long)theSize;
//@property (assign) IBOutlet NSWindow *window; //@property (assign) IBOutlet NSWindow *window;

@ -37,7 +37,7 @@
[wrt_client getConnectionStatus]; [wrt_client getConnectionStatus];
NSLog(@"Status %@ wan port: %@", ([wrt_client wrtReachable] ? @"Up" : @"Down"), [wrt_client getWanPort]); NSLog(@"Status %@ wan port: %@", ([wrt_client wrtReachable] ? @"Up" : @"Down"), [wrt_client getWanPort]);
_readTimer = [NSTimer scheduledTimerWithTimeInterval:[[NSUserDefaults standardUserDefaults] integerForKey:@"refreshTime"]+1 target:self selector:@selector(updateThroughput:) userInfo:nil repeats:YES]; _readTimer = [NSTimer scheduledTimerWithTimeInterval:refreshTime+1 target:self selector:@selector(updateThroughput:) userInfo:nil repeats:YES];
[_readTimer fire]; [_readTimer fire];
@ -213,16 +213,23 @@
- (void) showBandwidthViewer:(id)sender - (void) showBandwidthViewer:(id)sender
{ {
// NSString *urlAddress = [NSString stringWithFormat:@"https://%@:%d/graph_if.svg?ppp1", //NSURLRequest *request = [[wrt_client requestForBandwidthViewerForInterface:[wrt_client getWanPort]] retain];
// [[NSUserDefaults standardUserDefaults] stringForKey:@"hostname"], NSString *urlAddress = [NSString stringWithFormat:@"%@://%@:%@@%@:%d/graph_if.svg?%@",
// [[NSUserDefaults standardUserDefaults] integerForKey:@"port"]]; protocol,
// NSLog(@"%@", urlAddress); username,
// password,
[BandwidthViewer makeKeyAndOrderFront:nil]; hostname,
port,
[wrt_client getWanPort]];
NSLog(@"Building request form %@", urlAddress);
NSURLRequest *request = [[wrt_client requestForBandwidthViewerForInterface:[wrt_client getWanPort]] retain]; NSURL *url = [NSURL URLWithString:urlAddress];
[ [BandwidthViewerWebView mainFrame] loadRequest: request ]; NSURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: url];
[ [BandwidthViewerWebView mainFrame] loadRequest: [request autorelease] ];
[BandwidthViewer makeKeyAndOrderFront:nil];
} }
- (void) hideBandwidthViewer:(id)sender - (void) hideBandwidthViewer:(id)sender
@ -280,12 +287,6 @@
//WRTRequest *wrtr = [[WRTRequest alloc] init]; //WRTRequest *wrtr = [[WRTRequest alloc] init];
//[wrtr doRequest:self requestSelector:@selector(configSaveRequestCallback:) uri:@"Status_Router.live.asp"];
[self configSaveRequestCallback:nil];
}
-(void)configSaveRequestCallback:(NSData *)data
{
// TODO check that the request is actually successful // TODO check that the request is actually successful
hostname = [configFieldHostname stringValue]; hostname = [configFieldHostname stringValue];
@ -301,6 +302,12 @@
refreshTime = [configFieldRefresh integerValue]; refreshTime = [configFieldRefresh integerValue];
[defaults setInteger:refreshTime forKey:@"refreshTime"]; [defaults setInteger:refreshTime forKey:@"refreshTime"];
[_readTimer invalidate];
_readTimer = nil;
_readTimer = [NSTimer scheduledTimerWithTimeInterval:refreshTime+1 target:self selector:@selector(updateThroughput:) userInfo:nil repeats:YES];
[_readTimer fire];
useBytes = ([configFieldUseBytes state] == 1 ? true: false); useBytes = ([configFieldUseBytes state] == 1 ? true: false);
[defaults setBool:useBytes forKey:@"useBytes"]; [defaults setBool:useBytes forKey:@"useBytes"];
@ -318,8 +325,6 @@
[defaults synchronize]; [defaults synchronize];
//[self doUpdateStatus:data];
[self hideConfigPanel:nil]; [self hideConfigPanel:nil];
} }
@ -347,6 +352,8 @@
- (void) throughputCallback:(NSData *)data - (void) throughputCallback:(NSData *)data
{ {
[wrt_client getStatusUpdate:@"Status_Router.live.asp" delegate:self callback:@selector(doUpdateStatus:)];
NSString *stringData = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]; NSString *stringData = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
NSString *key = [NSString stringWithFormat:@"%@:", [wrt_client getWanPort]]; NSString *key = [NSString stringWithFormat:@"%@:", [wrt_client getWanPort]];
@ -377,8 +384,6 @@
_lastDateThroughput = [NSDate timeIntervalSinceReferenceDate]; _lastDateThroughput = [NSDate timeIntervalSinceReferenceDate];
_lastInThroughput = ifIn; _lastInThroughput = ifIn;
_lastOutThroughput = ifOut; _lastOutThroughput = ifOut;
NSLog(@"In %llu Out %llu", ifIn, ifOut);
} }
-(void)doUpdateStatus:(NSData *)data -(void)doUpdateStatus:(NSData *)data
@ -403,6 +408,8 @@
[menuLoad setTitle:load]; [menuLoad setTitle:load];
[menuLoad setHidden:false]; [menuLoad setHidden:false];
[menuConnections setTitle:[NSString stringWithFormat:@"Connections: %@", ipconn]]; [menuConnections setTitle:[NSString stringWithFormat:@"Connections: %@", ipconn]];
[wrt_client getStatusUpdate:@"Status_Internet.live.asp" delegate:self callback:@selector(wanRequestCallback:)];
} }
- (void) refreshMenu:(id)sender - (void) refreshMenu:(id)sender
@ -421,6 +428,7 @@
//WRTRequest *wrtr = [[WRTRequest alloc] init]; //WRTRequest *wrtr = [[WRTRequest alloc] init];
//[wrtr doRequest:self requestSelector:@selector(wanRequestCallback:) uri:@"Status_Internet.live.asp"]; //[wrtr doRequest:self requestSelector:@selector(wanRequestCallback:) uri:@"Status_Internet.live.asp"];
} }
- (void) wanRequestCallback:(NSData *)data - (void) wanRequestCallback:(NSData *)data
@ -498,7 +506,7 @@
- (void) refreshClientsMenu:(id)sender - (void) refreshClientsMenu:(id)sender
{ {
[self updateThroughput:nil]; //[self updateThroughput:nil];
} }
- (NSString *) stringFromFileSize:(unsigned long long)theSize - (NSString *) stringFromFileSize:(unsigned long long)theSize

@ -22,7 +22,9 @@
NSMutableData *receivedData; NSMutableData *receivedData;
NSURLRequest *theRequest; NSURLRequest *theRequest;
NSURLConnection *theConnection; NSURLConnection *theConnection;
NSMutableArray *requestQueue;
id delegate; id delegate;
SEL callback; SEL callback;
SEL errorCallback; SEL errorCallback;

@ -38,10 +38,8 @@
- (NSMutableURLRequest*) buildRequest:(NSString*)uri - (NSMutableURLRequest*) buildRequest:(NSString*)uri
{ {
NSString *urlAddress = [NSString stringWithFormat:@"%@://%@:%@@%@:%d/%@", NSString *urlAddress = [NSString stringWithFormat:@"%@://%@:%d/%@",
protocol, protocol,
username,
password,
hostname, hostname,
port, port,
uri]; uri];
@ -59,9 +57,21 @@
- (NSMutableURLRequest*) requestForBandwidthViewerForInterface:(NSString*)interface - (NSMutableURLRequest*) requestForBandwidthViewerForInterface:(NSString*)interface
{ {
NSString *endpoint = [NSString stringWithFormat:@"graph_if.svg?%@", interface]; NSString *urlAddress = [NSString stringWithFormat:@"%@://%@:%@@%@:%d/graph_if.svg?%@",
protocol,
return [self buildRequest:endpoint]; username,
password,
hostname,
port,
wanPort];
NSLog(@"Building request form %@", urlAddress);
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: url];
return [request autorelease];
} }
- (void) getStatusUpdate:(NSString*)uri delegate:(id)requestDelegate callback:(SEL)requestSelector - (void) getStatusUpdate:(NSString*)uri delegate:(id)requestDelegate callback:(SEL)requestSelector
@ -233,6 +243,7 @@
[[challenge sender] useCredential:newCredential forAuthenticationChallenge:challenge]; [[challenge sender] useCredential:newCredential forAuthenticationChallenge:challenge];
} else { } else {
NSLog(@"1.2"); NSLog(@"1.2");
wrtReachable = false;
[[challenge sender] cancelAuthenticationChallenge:challenge]; [[challenge sender] cancelAuthenticationChallenge:challenge];
// TODO Pop up authentication error // TODO Pop up authentication error
NSLog(@"Invalid Username or Password"); NSLog(@"Invalid Username or Password");
@ -241,7 +252,7 @@
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response -(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{ {
NSLog(@"2"); //NSLog(@"2");
[receivedData setLength:0]; [receivedData setLength:0];
} }
@ -260,6 +271,8 @@
//TODO Return alert //TODO Return alert
NSLog(@"Connection failed! Error - %@ %@", [error localizedDescription], [[error userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey]); NSLog(@"Connection failed! Error - %@ %@", [error localizedDescription], [[error userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey]);
wrtReachable = false;
if (errorCallback) { if (errorCallback) {
[delegate performSelector:errorCallback withObject:error]; [delegate performSelector:errorCallback withObject:error];
} else if (delegate && callback) { } else if (delegate && callback) {
@ -271,7 +284,7 @@
-(void)connectionDidFinishLoading:(NSURLConnection *)connection -(void)connectionDidFinishLoading:(NSURLConnection *)connection
{ {
NSLog(@"5"); //NSLog(@"5");
// TODO: Return the data // TODO: Return the data
if (delegate && callback) { if (delegate && callback) {
if ([delegate respondsToSelector:self.callback]) { if ([delegate respondsToSelector:self.callback]) {

Loading…
Cancel
Save