diff options
author | Justin Dickow <jjdickow@gmail.com> | 2016-03-03 15:26:16 -0500 |
---|---|---|
committer | Justin Dickow <jjdickow@gmail.com> | 2016-03-03 15:26:16 -0500 |
commit | 5907c3160de279293017ea79784f17bf882d0c0b (patch) | |
tree | 597a37a3ec80adcfa49db51bb55bc1cd291ca943 | |
parent | aeeecb6d0129324b22d4462c321d1c0fa86da8b9 (diff) | |
download | sdl_ios-5907c3160de279293017ea79784f17bf882d0c0b.tar.gz |
Handle System Request type HTTP according to PTU
based on implementation described in integration guidelines for updating policy table according to GENIVI implementation
Signed-off-by: Justin Dickow <jjdickow@gmail.com>
-rw-r--r-- | SmartDeviceLink-iOS/SmartDeviceLink/SDLProxy.m | 47 | ||||
-rw-r--r-- | SmartDeviceLink-iOS/SmartDeviceLink/SDLV2ProtocolMessage.m | 3 |
2 files changed, 49 insertions, 1 deletions
diff --git a/SmartDeviceLink-iOS/SmartDeviceLink/SDLProxy.m b/SmartDeviceLink-iOS/SmartDeviceLink/SDLProxy.m index 1f49b6eeb..095b63cbb 100644 --- a/SmartDeviceLink-iOS/SmartDeviceLink/SDLProxy.m +++ b/SmartDeviceLink-iOS/SmartDeviceLink/SDLProxy.m @@ -322,6 +322,8 @@ const int POLICIES_CORRELATION_ID = 65535; [self handleSystemRequestProprietary:systemRequest]; } else if (requestType == [SDLRequestType LOCK_SCREEN_ICON_URL]) { [self handleSystemRequestLockScreenIconURL:systemRequest]; + } else if (requestType == [SDLRequestType HTTP]) { + [self handleSystemRequestHttp:systemRequest]; } } @@ -427,6 +429,51 @@ const int POLICIES_CORRELATION_ID = 65535; }]; } +- (void)handleSystemRequestHttp:(SDLOnSystemRequest *)request { + if (nil == request.bulkData) { + // TODO: not sure how we want to handle http requests that don't have bulk data (maybe as GET?) + return; + } + + NSError *error = nil; + NSDictionary *body = [NSJSONSerialization JSONObjectWithData:request.bulkData options:kNilOptions error:&error]; + if (error) { + NSLog(@"error creating body from bulk data: %@", error.localizedDescription); + return; + } + + [self uploadForBodyDataDictionary:body + URLString:request.url + completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { + NSString *logMessage = nil; + if (error) { + logMessage = [NSString stringWithFormat:@"OnSystemRequest (HTTP response) = ERROR: %@", error]; + [SDLDebugTool logInfo:logMessage withType:SDLDebugType_RPC toOutput:SDLDebugOutput_All toGroup:self.debugConsoleGroupName]; + return; + } + + if (data == nil || data.length == 0) { + [SDLDebugTool logInfo:@"OnSystemRequest (HTTP response) failure: no data returned" withType:SDLDebugType_RPC toOutput:SDLDebugOutput_All toGroup:self.debugConsoleGroupName]; + return; + } + + // Show the HTTP response + [SDLDebugTool logInfo:@"OnSystemRequest (HTTP response)" withType:SDLDebugType_RPC toOutput:SDLDebugOutput_All toGroup:self.debugConsoleGroupName]; + + // Create the SystemRequest RPC to send to module. + SDLPutFile *putFile = [[SDLPutFile alloc] init]; + putFile.fileType = [SDLFileType JSON]; + putFile.correlationID = [NSNumber numberWithInt:POLICIES_CORRELATION_ID]; + putFile.syncFileName = @"pt.json"; + putFile.bulkData = data; + + // Send and log RPC Request + logMessage = [NSString stringWithFormat:@"SystemRequest (request)\n%@\nData length=%lu", [request serializeAsDictionary:2], (unsigned long)data.length]; + [SDLDebugTool logInfo:logMessage withType:SDLDebugType_RPC toOutput:SDLDebugOutput_All toGroup:self.debugConsoleGroupName]; + [self sendRPC:putFile]; + }]; +} + /** * Determine if the System Request is valid and return it's JSON dictionary, if available. * diff --git a/SmartDeviceLink-iOS/SmartDeviceLink/SDLV2ProtocolMessage.m b/SmartDeviceLink-iOS/SmartDeviceLink/SDLV2ProtocolMessage.m index 80d06898c..e148d74df 100644 --- a/SmartDeviceLink-iOS/SmartDeviceLink/SDLV2ProtocolMessage.m +++ b/SmartDeviceLink-iOS/SmartDeviceLink/SDLV2ProtocolMessage.m @@ -21,8 +21,9 @@ // Convert RPC payload to dictionary (for consumption by RPC layer) - (NSDictionary *)rpcDictionary { + // Only applicable to RPCs - if (self.header.serviceType != SDLServiceType_RPC) { + if (self.header.serviceType != SDLServiceType_RPC && self.header.serviceType != SDLServiceType_BulkData) { return nil; } |