diff options
author | David Switzer <dswitzer@xevo.com> | 2017-04-13 11:23:28 -0700 |
---|---|---|
committer | David Switzer <dswitzer@xevo.com> | 2017-04-13 11:23:28 -0700 |
commit | 5d6b00d031dc6ec100f359144218f73f088aceb4 (patch) | |
tree | cd3fdae000a9eac0218850d84b9cc95185102a1e | |
parent | 6908e5d4bf208d44e3867a44ad7088504baa86c4 (diff) | |
download | sdl_ios-5d6b00d031dc6ec100f359144218f73f088aceb4.tar.gz |
Review feedback incorporated into SDLIAPSession class.
-rw-r--r-- | SmartDeviceLink/SDLIAPSession.h | 1 | ||||
-rw-r--r-- | SmartDeviceLink/SDLIAPSession.m | 35 |
2 files changed, 22 insertions, 14 deletions
diff --git a/SmartDeviceLink/SDLIAPSession.h b/SmartDeviceLink/SDLIAPSession.h index c4ecf5f86..751d10086 100644 --- a/SmartDeviceLink/SDLIAPSession.h +++ b/SmartDeviceLink/SDLIAPSession.h @@ -17,6 +17,7 @@ typedef void (^SessionCompletionHandler)(BOOL success); @property (strong, atomic) EASession *easession; @property (weak) id<SDLIAPSessionDelegate> delegate; @property (strong, atomic) SDLStreamDelegate *streamDelegate; +@property (assign, readonly, getter=isStopped) BOOL stopped; - (instancetype)initWithAccessory:(EAAccessory *)accessory forProtocol:(NSString *)protocol; diff --git a/SmartDeviceLink/SDLIAPSession.m b/SmartDeviceLink/SDLIAPSession.m index dc4c4c7b6..781398c0f 100644 --- a/SmartDeviceLink/SDLIAPSession.m +++ b/SmartDeviceLink/SDLIAPSession.m @@ -65,7 +65,7 @@ NSTimeInterval const streamThreadWaitSecs = 1.0; strongSelf.streamDelegate.streamErrorHandler = [self streamErroredHandler]; strongSelf.streamDelegate.streamOpenHandler = [self streamOpenedHandler]; if (self.isDataSession) { - self.streamDelegate.streamHasSpaceHandler = [self streamHasSpaceHandler]; + self.streamDelegate.streamHasSpaceHandler = [self sdl_streamHasSpaceHandler]; // Start I/O event loop processing events in iAP channel self.ioStreamThread = [[NSThread alloc] initWithTarget:self selector:@selector(sdl_accessoryEventLoop) object:nil]; [self.ioStreamThread setName:IOStreamThreadName]; @@ -103,6 +103,10 @@ NSTimeInterval const streamThreadWaitSecs = 1.0; self.easession = nil; } +- (BOOL)isStopped { + return !self.isOutputStreamOpen && !self.isInputStreamOpen; +} + # pragma mark - data send methods - (void)sendData:(NSData *)data { @@ -140,7 +144,7 @@ NSTimeInterval const streamThreadWaitSecs = 1.0; if (self.easession == nil || self.easession.outputStream == nil || self.easession.outputStream.streamStatus != NSStreamStatusOpen) { - [self.sendDataQueue flush]; + [self.sendDataQueue removeAllObjects]; } } @@ -184,12 +188,11 @@ NSTimeInterval const streamThreadWaitSecs = 1.0; return; } - NSLog(@"Close EASession: %tu", self.easession.accessory.connectionID); - NSInputStream *inStream = [self.easession inputStream]; - NSOutputStream *outStream = [self.easession outputStream]; + NSString *closeSessionString = [NSString stringWithFormat:@"Close EASession: %tu", self.easession.accessory.connectionID]; + [SDLDebugTool logInfo:closeSessionString]; - [self stopStream:inStream]; - [self stopStream:outStream]; + [self stopStream:[self.easession inputStream]]; + [self stopStream:[self.easession outputStream]]; } @@ -221,8 +224,10 @@ NSTimeInterval const streamThreadWaitSecs = 1.0; if (status2 == NSStreamStatusClosed) { if (stream == [self.easession inputStream]) { [SDLDebugTool logInfo:@"Input Stream Closed"]; + self.isInputStreamOpen = NO; } else if (stream == [self.easession outputStream]) { [SDLDebugTool logInfo:@"Output Stream Closed"]; + self.isOutputStreamOpen = NO; } } } @@ -262,18 +267,20 @@ NSTimeInterval const streamThreadWaitSecs = 1.0; }; } -- (SDLStreamHasSpaceHandler)streamHasSpaceHandler { +- (SDLStreamHasSpaceHandler)sdl_streamHasSpaceHandler { __weak typeof(self) weakSelf = self; return ^(NSStream *stream) { __strong typeof(weakSelf) strongSelf = weakSelf; - if (strongSelf.isDataSession) { - NSError *sendErr = nil; - - if (![strongSelf sdl_dequeueAndWriteToOutputStream:&sendErr] && sendErr != nil) { - [strongSelf sdl_handleOutputStreamWriteError:sendErr]; - } + if (!strongSelf.isDataSession){ + return; + } + + NSError *sendErr = nil; + + if (![strongSelf sdl_dequeueAndWriteToOutputStream:&sendErr] && sendErr != nil) { + [strongSelf sdl_handleOutputStreamWriteError:sendErr]; } }; } |