From 3554b4096206b564083a0ef116779aa03aa33d31 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Thu, 23 Oct 2014 23:41:07 -0400 Subject: [PATCH] Display status messages for failed app launch --- Limelight/Network/HttpManager.h | 1 + Limelight/Network/HttpManager.m | 25 +++++++++++++++++++ Limelight/Stream/Connection.h | 2 +- Limelight/Stream/StreamManager.m | 20 +++++++++------ .../StreamFrameViewController.m | 4 +-- 5 files changed, 42 insertions(+), 10 deletions(-) diff --git a/Limelight/Network/HttpManager.h b/Limelight/Network/HttpManager.h index efd4547..d24f6b4 100644 --- a/Limelight/Network/HttpManager.h +++ b/Limelight/Network/HttpManager.h @@ -11,6 +11,7 @@ @interface HttpManager : NSObject + (NSString*) getStringFromXML:(NSData*)xml tag:(NSString*)tag; ++ (NSString*) getStatusStringFromXML:(NSData*)xml; - (id) initWithHost:(NSString*) host uniqueId:(NSString*) uniqueId deviceName:(NSString*) deviceName cert:(NSData*) cert; - (NSURLRequest*) newPairRequest:(NSData*)salt; diff --git a/Limelight/Network/HttpManager.m b/Limelight/Network/HttpManager.m index 98ef1df..76f9a8f 100644 --- a/Limelight/Network/HttpManager.m +++ b/Limelight/Network/HttpManager.m @@ -25,6 +25,24 @@ static const NSString* PORT = @"47984"; ++ (NSString*) getStatusStringFromXML:(NSData*)xml { + xmlDocPtr docPtr = xmlParseMemory([xml bytes], (int)[xml length]); + + if (docPtr == NULL) { + NSLog(@"ERROR: An error occured trying to parse xml."); + return NULL; + } + + NSString* string; + xmlNodePtr rootNode = xmlDocGetRootElement(docPtr); + + string = [HttpManager getStatusMessage: rootNode]; + xmlFree(rootNode); + xmlFree(docPtr); + + return string; +} + + (NSString*) getStringFromXML:(NSData*)xml tag:(NSString*)tag { xmlDocPtr docPtr = xmlParseMemory([xml bytes], (int)[xml length]); @@ -60,6 +78,13 @@ static const NSString* PORT = @"47984"; return value; } + ++ (NSString*) getStatusMessage:(xmlNodePtr)docRoot { + xmlChar* statusMsgXml = xmlGetProp(docRoot, (const xmlChar*)"status_message"); + NSString* statusMsg = [NSString stringWithUTF8String:(const char*)statusMsgXml]; + xmlFree(statusMsgXml); + return statusMsg; +} + (bool) verifyStatus:(xmlNodePtr)docRoot { xmlChar* statusStr = xmlGetProp(docRoot, (const xmlChar*)"status_code"); diff --git a/Limelight/Stream/Connection.h b/Limelight/Stream/Connection.h index 05a1384..ae11364 100644 --- a/Limelight/Stream/Connection.h +++ b/Limelight/Stream/Connection.h @@ -17,7 +17,7 @@ - (void) stageStarting:(char*)stageName; - (void) stageComplete:(char*)stageName; - (void) stageFailed:(char*)stageName withError:(long)errorCode; -- (void) launchFailed; +- (void) launchFailed:(NSString*)message; - (void) displayMessage:(char*)message; - (void) displayTransientMessage:(char*)message; diff --git a/Limelight/Stream/StreamManager.m b/Limelight/Stream/StreamManager.m index 1265bb9..d35d19f 100644 --- a/Limelight/Stream/StreamManager.m +++ b/Limelight/Stream/StreamManager.m @@ -43,27 +43,25 @@ NSString* currentGame = [HttpManager getStringFromXML:serverInfoResp tag:@"currentgame"]; NSString* pairStatus = [HttpManager getStringFromXML:serverInfoResp tag:@"PairStatus"]; if (currentGame == NULL || pairStatus == NULL) { - [_callbacks launchFailed]; + [_callbacks launchFailed:@"Failed to connect to PC"]; return; } if (![pairStatus isEqualToString:@"1"]) { // Not paired - // TODO: Display better error message - [_callbacks launchFailed]; + [_callbacks launchFailed:@"Device not paired to PC"]; return; } + // resumeApp and launchApp handle calling launchFailed if (![currentGame isEqualToString:@"0"]) { // App already running, resume it if (![self resumeApp:hMan]) { - [_callbacks launchFailed]; return; } } else { // Start app if (![self launchApp:hMan]) { - [_callbacks launchFailed]; return; } } @@ -88,7 +86,11 @@ rikey:[Utils bytesToHex:_config.riKey] rikeyid:_config.riKeyId]]; NSString *gameSession = [HttpManager getStringFromXML:launchResp tag:@"gamesession"]; - if (gameSession == NULL || [gameSession isEqualToString:@"0"]) { + if (launchResp == NULL) { + [_callbacks launchFailed:@"Failed to launch app"]; + return FALSE; + } else if (gameSession == NULL || [gameSession isEqualToString:@"0"]) { + [_callbacks launchFailed:[HttpManager getStatusStringFromXML:launchResp]]; return FALSE; } @@ -100,7 +102,11 @@ [hMan newResumeRequestWithRiKey:[Utils bytesToHex:_config.riKey] riKeyId:_config.riKeyId]]; NSString *resume = [HttpManager getStringFromXML:resumeResp tag:@"resume"]; - if (resume == NULL || [resume isEqualToString:@"0"]) { + if (resumeResp == NULL) { + [_callbacks launchFailed:@"Failed to resume app"]; + return FALSE; + } else if (resume == NULL || [resume isEqualToString:@"0"]) { + [_callbacks launchFailed:[HttpManager getStatusStringFromXML:resumeResp]]; return FALSE; } diff --git a/Limelight/ViewControllers/StreamFrameViewController.m b/Limelight/ViewControllers/StreamFrameViewController.m index 3dd9b75..588bee9 100644 --- a/Limelight/ViewControllers/StreamFrameViewController.m +++ b/Limelight/ViewControllers/StreamFrameViewController.m @@ -91,9 +91,9 @@ [self presentViewController:alert animated:YES completion:nil]; } -- (void) launchFailed { +- (void) launchFailed:(NSString*)message { UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Connection Failed" - message:@"Failed to start app" + message:message preferredStyle:UIAlertControllerStyleAlert]; [alert addAction:[UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDestructive handler:^(UIAlertAction* action){ [self performSegueWithIdentifier:@"returnToMainFrame" sender:self];