summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicoleYarroch <nicole@livio.io>2019-05-22 16:51:06 -0400
committerNicoleYarroch <nicole@livio.io>2019-05-22 16:51:06 -0400
commitad27ed061f08bd675d605f72c848c171d94f1fa0 (patch)
treefa7c1a4829a492ee2b255b7735b3d5c7f01d4a2f
parent494e196d0d0d5233699b4a60faf63198bb78a159 (diff)
downloadsdl_ios-ad27ed061f08bd675d605f72c848c171d94f1fa0.tar.gz
Cleaned up the control and data session classes
-rw-r--r--SmartDeviceLink/SDLIAPControlSession.h2
-rw-r--r--SmartDeviceLink/SDLIAPControlSession.m29
-rw-r--r--SmartDeviceLink/SDLIAPDataSession.h2
-rw-r--r--SmartDeviceLink/SDLIAPDataSession.m27
4 files changed, 29 insertions, 31 deletions
diff --git a/SmartDeviceLink/SDLIAPControlSession.h b/SmartDeviceLink/SDLIAPControlSession.h
index c01df91c9..03940ef98 100644
--- a/SmartDeviceLink/SDLIAPControlSession.h
+++ b/SmartDeviceLink/SDLIAPControlSession.h
@@ -32,7 +32,7 @@ NS_ASSUME_NONNULL_BEGIN
* @param delegate The control session delegate
* @return A SDLIAPControlSession object
*/
-- (instancetype)initWithAccessory:(EAAccessory *)accessory delegate:(id<SDLIAPControlSessionDelegate>)delegate;
+- (instancetype)initWithAccessory:(nullable EAAccessory *)accessory delegate:(id<SDLIAPControlSessionDelegate>)delegate;
@end
diff --git a/SmartDeviceLink/SDLIAPControlSession.m b/SmartDeviceLink/SDLIAPControlSession.m
index 75e79693f..1309f7288 100644
--- a/SmartDeviceLink/SDLIAPControlSession.m
+++ b/SmartDeviceLink/SDLIAPControlSession.m
@@ -44,13 +44,11 @@ int const ProtocolIndexTimeoutSeconds = 10;
@implementation SDLIAPControlSession
-- (instancetype)initWithAccessory:(EAAccessory *)accessory delegate:(id<SDLIAPControlSessionDelegate>)delegate {
+- (instancetype)initWithAccessory:(nullable EAAccessory *)accessory delegate:(id<SDLIAPControlSessionDelegate>)delegate {
SDLLogV(@"SDLIAPControlSession init");
self = [super initWithAccessory:accessory forProtocol:ControlProtocolString];
- if (!self) {
- return nil;
- }
+ if (!self) { return nil; }
_protocolIndexTimer = nil;
_delegate = delegate;
@@ -59,8 +57,6 @@ int const ProtocolIndexTimeoutSeconds = 10;
}
- (void)startSession {
- [super startSession];
-
if (self.accessory == nil) {
SDLLogW(@"There is no control session in progress, attempting to create a new control session.");
if (self.delegate == nil) { return; }
@@ -109,9 +105,7 @@ int const ProtocolIndexTimeoutSeconds = 10;
self.eaSession = nil;
}
-- (void)destroySession {
- [super destroySession];
-
+- (void)destroySession {
if (self.accessory == nil) {
SDLLogV(@"Attempting to stop the control session but the accessory is nil");
return;
@@ -129,7 +123,7 @@ int const ProtocolIndexTimeoutSeconds = 10;
[self.protocolIndexTimer start];
}
-#pragma mark - SDLSessionDelegate
+#pragma mark - NSStreamDelegate
- (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode {
switch (eventCode) {
@@ -157,12 +151,17 @@ int const ProtocolIndexTimeoutSeconds = 10;
}
}
+/**
+ * Called when the session gets a `NSStreamEventOpenCompleted`. When both the input and output streams open, start a timer to get data from Core within a certain timeframe.
+ *
+ * @param stream The stream that got the event code.
+ */
- (void)streamDidOpen:(NSStream *)stream {
if (stream == [self.eaSession outputStream]) {
- SDLLogD(@"Output Stream Opened");
+ SDLLogD(@"Control session output stream opened");
self.isOutputStreamOpen = YES;
} else if (stream == [self.eaSession inputStream]) {
- SDLLogD(@"Input Stream Opened");
+ SDLLogD(@"Control session input stream opened");
self.isInputStreamOpen = YES;
}
@@ -174,7 +173,7 @@ int const ProtocolIndexTimeoutSeconds = 10;
}
/**
- * Handler called when the session gets a `NSStreamEventEndEncountered` event code. The current session is closed and a new session is attempted.
+ * Called when the session gets a `NSStreamEventEndEncountered` event code. The current session is closed and a new session is attempted.
*/
- (void)streamDidEnd:(NSStream *)stream {
SDLLogD(@"Control stream ended");
@@ -188,7 +187,7 @@ int const ProtocolIndexTimeoutSeconds = 10;
}
/**
- * Handler called when the session gets a `NSStreamEventHasBytesAvailable` event code. A protocol string is created from the received data. Since a new session needs to be established with the protocol string, the current session is closed and a new session is created.
+ * Called when the session gets a `NSStreamEventHasBytesAvailable` event code. A protocol string is created from the received data. Since a new session needs to be established with the protocol string, the current session is closed and a new session is created.
*/
- (void)streamHasBytesAvailable:(NSInputStream *)inputStream {
SDLLogV(@"Control stream received data");
@@ -217,7 +216,7 @@ int const ProtocolIndexTimeoutSeconds = 10;
}
/**
- * Handler called when the session gets a `NSStreamEventErrorOccurred` event code. The current session is closed and a new session is attempted.
+ * Called when the session gets a `NSStreamEventErrorOccurred` event code. The current session is closed and a new session is attempted.
*/
- (void)streamDidError:(NSStream *)stream {
SDLLogE(@"Control stream error");
diff --git a/SmartDeviceLink/SDLIAPDataSession.h b/SmartDeviceLink/SDLIAPDataSession.h
index 336f31e14..e53953bae 100644
--- a/SmartDeviceLink/SDLIAPDataSession.h
+++ b/SmartDeviceLink/SDLIAPDataSession.h
@@ -27,7 +27,7 @@ NS_ASSUME_NONNULL_BEGIN
* @param delegate The data session delegate
* @return A SDLIAPSession object
*/
-- (instancetype)initWithAccessory:(EAAccessory *)accessory delegate:(id<SDLIAPDataSessionDelegate>)delegate forProtocol:(NSString *)protocol;
+- (instancetype)initWithAccessory:(nullable EAAccessory *)accessory delegate:(id<SDLIAPDataSessionDelegate>)delegate forProtocol:(NSString *)protocol;
/**
* Sends data to Core via the data session.
diff --git a/SmartDeviceLink/SDLIAPDataSession.m b/SmartDeviceLink/SDLIAPDataSession.m
index 0d61f7e13..ac0225875 100644
--- a/SmartDeviceLink/SDLIAPDataSession.m
+++ b/SmartDeviceLink/SDLIAPDataSession.m
@@ -44,13 +44,11 @@ NS_ASSUME_NONNULL_BEGIN
@implementation SDLIAPDataSession
-- (instancetype)initWithAccessory:(EAAccessory *)accessory delegate:(id<SDLIAPDataSessionDelegate>)delegate forProtocol:(NSString *)protocol; {
+- (instancetype)initWithAccessory:(nullable EAAccessory *)accessory delegate:(id<SDLIAPDataSessionDelegate>)delegate forProtocol:(NSString *)protocol; {
SDLLogV(@"SDLIAPDataSession init");
self = [super initWithAccessory:accessory forProtocol:protocol];
- if (!self) {
- return nil;
- }
+ if (!self) { return nil; }
_delegate = delegate;
_sendDataQueue = [[SDLMutableDataQueue alloc] init];
@@ -60,8 +58,6 @@ NS_ASSUME_NONNULL_BEGIN
}
- (void)startSession {
- [super startSession];
-
if (self.accessory == nil) {
SDLLogW(@"Failed to setup data session");
if (self.delegate == nil) { return; }
@@ -114,8 +110,6 @@ NS_ASSUME_NONNULL_BEGIN
}
- (void)destroySession {
- [super destroySession];
-
if (self.accessory == nil) {
SDLLogV(@"Attempting to stop the data session but the session is nil");
return;
@@ -195,7 +189,7 @@ NS_ASSUME_NONNULL_BEGIN
}
}
-#pragma mark - Data Stream Handlers
+#pragma mark - NSStreamDelegate
- (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode {
switch (eventCode) {
@@ -226,12 +220,17 @@ NS_ASSUME_NONNULL_BEGIN
}
}
+/**
+ * Called when the session gets a `NSStreamEventOpenCompleted`. When both the input and output streams open, notify the lifecycle manager that a connection has been established with the accessory.
+ *
+ * @param stream The stream that got the event code.
+ */
- (void)streamDidOpen:(NSStream *)stream {
if (stream == [self.eaSession outputStream]) {
- SDLLogD(@"Output Stream Opened");
+ SDLLogD(@"Data session output stream opened");
self.isOutputStreamOpen = YES;
} else if (stream == [self.eaSession inputStream]) {
- SDLLogD(@"Input Stream Opened");
+ SDLLogD(@"Data session input stream opened");
self.isInputStreamOpen = YES;
}
@@ -244,7 +243,7 @@ NS_ASSUME_NONNULL_BEGIN
}
/**
- * Handler called when the session gets a `NSStreamEventEndEncountered` event code. The current session is closed and a new session is attempted.
+ * Called when the session gets a `NSStreamEventEndEncountered` event code. The current session is closed and a new session is attempted.
*/
- (void)streamDidEnd:(NSStream *)stream {
NSAssert(!NSThread.isMainThread, @"%@ should only be called on the IO thread", NSStringFromSelector(_cmd));
@@ -267,7 +266,7 @@ NS_ASSUME_NONNULL_BEGIN
}
/**
- * Handler called when the session gets a `NSStreamEventHasBytesAvailable` event code. The data is passed to the listener.
+ * Called when the session gets a `NSStreamEventHasBytesAvailable` event code. The data is passed to the listener.
*/
- (void)streamHasBytesAvailable:(NSInputStream *)inputStream {
NSAssert(!NSThread.isMainThread, @"%@ should only be called on the IO thread", NSStringFromSelector(_cmd));
@@ -297,7 +296,7 @@ NS_ASSUME_NONNULL_BEGIN
}
/**
- * Handler called when the session gets a `NSStreamEventErrorOccurred` event code. The current session is closed and a new session is attempted.
+ * Called when the session gets a `NSStreamEventErrorOccurred` event code. The current session is closed and a new session is attempted.
*/
- (void)streamDidError:(NSStream *)stream {
NSAssert(!NSThread.isMainThread, @"%@ should only be called on the IO thread", NSStringFromSelector(_cmd));