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) throughputCallback:(NSData *)data;
- (void) doUpdateStatus:(NSData *)data;
- (void) configSaveRequestCallback:(NSData *)data;
- (NSString *) stringFromFileSize:(unsigned long long)theSize;
//@property (assign) IBOutlet NSWindow *window;

@ -37,7 +37,7 @@
[wrt_client getConnectionStatus];
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];
@ -213,16 +213,23 @@
- (void) showBandwidthViewer:(id)sender
{
// NSString *urlAddress = [NSString stringWithFormat:@"https://%@:%d/graph_if.svg?ppp1",
// [[NSUserDefaults standardUserDefaults] stringForKey:@"hostname"],
// [[NSUserDefaults standardUserDefaults] integerForKey:@"port"]];
// NSLog(@"%@", urlAddress);
//
[BandwidthViewer makeKeyAndOrderFront:nil];
//NSURLRequest *request = [[wrt_client requestForBandwidthViewerForInterface:[wrt_client getWanPort]] retain];
NSString *urlAddress = [NSString stringWithFormat:@"%@://%@:%@@%@:%d/graph_if.svg?%@",
protocol,
username,
password,
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
@ -280,12 +287,6 @@
//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
hostname = [configFieldHostname stringValue];
@ -301,6 +302,12 @@
refreshTime = [configFieldRefresh integerValue];
[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);
[defaults setBool:useBytes forKey:@"useBytes"];
@ -318,8 +325,6 @@
[defaults synchronize];
//[self doUpdateStatus:data];
[self hideConfigPanel:nil];
}
@ -347,6 +352,8 @@
- (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 *key = [NSString stringWithFormat:@"%@:", [wrt_client getWanPort]];
@ -377,8 +384,6 @@
_lastDateThroughput = [NSDate timeIntervalSinceReferenceDate];
_lastInThroughput = ifIn;
_lastOutThroughput = ifOut;
NSLog(@"In %llu Out %llu", ifIn, ifOut);
}
-(void)doUpdateStatus:(NSData *)data
@ -403,6 +408,8 @@
[menuLoad setTitle:load];
[menuLoad setHidden:false];
[menuConnections setTitle:[NSString stringWithFormat:@"Connections: %@", ipconn]];
[wrt_client getStatusUpdate:@"Status_Internet.live.asp" delegate:self callback:@selector(wanRequestCallback:)];
}
- (void) refreshMenu:(id)sender
@ -421,6 +428,7 @@
//WRTRequest *wrtr = [[WRTRequest alloc] init];
//[wrtr doRequest:self requestSelector:@selector(wanRequestCallback:) uri:@"Status_Internet.live.asp"];
}
- (void) wanRequestCallback:(NSData *)data
@ -498,7 +506,7 @@
- (void) refreshClientsMenu:(id)sender
{
[self updateThroughput:nil];
//[self updateThroughput:nil];
}
- (NSString *) stringFromFileSize:(unsigned long long)theSize

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

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

Loading…
Cancel
Save