summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Kinney <michaelakinney@comcast.net>2021-02-23 11:50:54 -0500
committerMichael Kinney <michaelakinney@comcast.net>2021-02-23 11:50:54 -0500
commit0ce9ec69ce0eb0c3e8ab3bece4615f4950d48d55 (patch)
tree01dbf993f49db80a1b39b632d040b566e5aa558a
parent918e39c7cd9ea2535bd83f20501a040ccb4dede7 (diff)
downloadsdl_ios-0ce9ec69ce0eb0c3e8ab3bece4615f4950d48d55.tar.gz
update sdlisapsession class per style requirements
-rw-r--r--SmartDeviceLink/private/SDLIAPSession.h19
-rw-r--r--SmartDeviceLink/private/SDLIAPSession.m27
2 files changed, 20 insertions, 26 deletions
diff --git a/SmartDeviceLink/private/SDLIAPSession.h b/SmartDeviceLink/private/SDLIAPSession.h
index 8bc667a12..87ab2d244 100644
--- a/SmartDeviceLink/private/SDLIAPSession.h
+++ b/SmartDeviceLink/private/SDLIAPSession.h
@@ -17,10 +17,14 @@ NS_ASSUME_NONNULL_BEGIN
- (void)streamHasBytesAvailable:(NSInputStream *)inputStream;
@end
+/**
+ * Responsible for opening a connection with the accessory and transmitting data to and from the accessory. When the accessory disconnects, the connection is closed.
+ * Once the connection with the accessory is closed, the connection can not be reopened; instead, a new `SDLIAPSession` must be created.
+ */
@interface SDLIAPSession : NSObject <NSStreamDelegate>
/**
- * Convenience initializer for setting an accessory and protocol string.
+ * Starts a session with the accessory.
*
* @param accessory The accessory with which to open a session
* @param protocol The unique protocol string used to create the session with the accessory
@@ -36,13 +40,10 @@ NS_ASSUME_NONNULL_BEGIN
/**
* @returns True if both inputStream and outputStream are open
*/
-@property(readonly) BOOL bothStreamsOpen;
+@property(nonatomic, assign, readonly) BOOL bothStreamsOpen;
/**
- * Closes the EASession inputStream and the outputStream.
- * Sets bothStreamsOpen flag to false.
- * Stops SDLIAPSesssion operation by removing streams from the run loop
- * By design a SDLIAPSession instance cannot be reopened.
+ * Closes the session's input and output streams. Once closed, the session can not be reopened.
*/
- (void)closeSession;
@@ -54,12 +55,12 @@ NS_ASSUME_NONNULL_BEGIN
/**
* @returns True if the outputStream has space available to write data
*/
-@property(readonly) BOOL hasSpaceAvailable;
+@property(nonatomic, assign, readonly) BOOL hasSpaceAvailable;
/**
* @returns True if the sessions EAAccessory is connected
*/
-@property(readonly) BOOL isConnected;
+@property(nonatomic, assign, readonly) BOOL isConnected;
/**
* @returns True if either the inputStream or the outputStream is open
@@ -77,7 +78,7 @@ NS_ASSUME_NONNULL_BEGIN
* @param length The number of data bytes to write
* @param completionHandler The number of data bytes actually written
*/
-- (void)write:(NSMutableData *) data length: (NSUInteger) length withCompletionHandler:(void (^)(NSInteger bytesWritten))completionHandler;
+- (void)write:(NSMutableData *)data length:(NSUInteger)length withCompletionHandler:(void (^)(NSInteger bytesWritten))completionHandler;
@end
diff --git a/SmartDeviceLink/private/SDLIAPSession.m b/SmartDeviceLink/private/SDLIAPSession.m
index 8d6826323..ee64b7f1b 100644
--- a/SmartDeviceLink/private/SDLIAPSession.m
+++ b/SmartDeviceLink/private/SDLIAPSession.m
@@ -99,10 +99,10 @@ NS_ASSUME_NONNULL_BEGIN
- (void)sdl_close:(NSStream *)stream {
if (stream.streamStatus == NSStreamStatusClosed) {
- if ([self isInputStream:stream]) {
+ if ([self sdl_isInputStream:stream]) {
SDLLogD(@"EASession inputstream already closed for EASession %@", self.eaSession);
}
- if ([self isOutputStream:stream]) {
+ if ([self sdl_isOutputStream:stream]) {
SDLLogD(@"EASession outputstream already closed for EASession %@", self.eaSession);
}
return;
@@ -112,11 +112,11 @@ NS_ASSUME_NONNULL_BEGIN
[stream removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[stream setDelegate:nil];
- if ([self isInputStream:stream]) {
+ if ([self sdl_isInputStream:stream]) {
self.inputStreamOpen = NO;
SDLLogD(@"EASession closed input stream for EASession %@", self.eaSession);
}
- if ([self isOutputStream:stream]) {
+ if ([self sdl_isOutputStream:stream]) {
self.outputStreamOpen = NO;
SDLLogD(@"EASession closed output stream for EASession %@", self.eaSession);
}
@@ -191,10 +191,10 @@ NS_ASSUME_NONNULL_BEGIN
* @param stream The stream that got the event code.
*/
- (void)sdl_streamDidOpen:(NSStream *)stream {
- if ([self isInputStream:stream]) {
+ if ([self sdl_isInputStream:stream]) {
self.inputStreamOpen = YES;
}
- if ([self isOutputStream: stream]) {
+ if ([self sdl_isOutputStream: stream]) {
self.outputStreamOpen = YES;
}
if (self.bothStreamsOpen) {
@@ -237,10 +237,10 @@ NS_ASSUME_NONNULL_BEGIN
* Called when the session gets a `NSStreamEventErrorOccurred` event code. The current session is closed and a new session is attempted.
*/
- (void)sdl_streamDidError:(NSStream *)stream {
- if ([self isInputStream:stream]) {
+ if ([self sdl_isInputStream:stream]) {
SDLLogE(@"EASession input stream errored");
}
- if ([self isOutputStream:stream]) {
+ if ([self sdl_isOutputStream:stream]) {
SDLLogE(@"EASession output stream errored");
}
[self closeSession];
@@ -258,13 +258,6 @@ NS_ASSUME_NONNULL_BEGIN
return NO;
}
-- (BOOL)bothStreamsClosed {
- if (self.inputStreamOpen || self.outputStreamOpen) {
- return NO;
- }
- return YES;
-}
-
- (NSUInteger)connectionID {
return self.eaSession.accessory.connectionID;
}
@@ -277,14 +270,14 @@ NS_ASSUME_NONNULL_BEGIN
return self.accessory.isConnected;
}
-- (BOOL)isInputStream:(NSStream *)stream {
+- (BOOL)sdl_isInputStream:(NSStream *)stream {
if (stream == self.eaSession.inputStream) {
return YES;
}
return NO;
}
-- (BOOL)isOutputStream:(NSStream *)stream {
+- (BOOL)sdl_isOutputStream:(NSStream *)stream {
if (stream == self.eaSession.outputStream) {
return YES;
}