summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicoleYarroch <nicole@livio.io>2019-05-30 15:52:32 -0400
committerNicoleYarroch <nicole@livio.io>2019-05-30 15:52:32 -0400
commit6e83a5642afe817dca4d0011737f384cac13c6b8 (patch)
treedfb673a6fcfabcba5bcedd535e75d702bbb40e1d
parent3779a2ba32cc38ed047341eb15393b86a5b2787a (diff)
downloadsdl_ios-6e83a5642afe817dca4d0011737f384cac13c6b8.tar.gz
Cleaned up the IAP classes private methods
-rw-r--r--SmartDeviceLink/SDLIAPControlSession.m16
-rw-r--r--SmartDeviceLink/SDLIAPDataSession.m23
-rw-r--r--SmartDeviceLink/SDLIAPSession.h37
-rw-r--r--SmartDeviceLink/SDLIAPSession.m13
-rw-r--r--SmartDeviceLinkTests/TransportSpecs/iAP/SDLIAPSessionSpec.m7
5 files changed, 44 insertions, 52 deletions
diff --git a/SmartDeviceLink/SDLIAPControlSession.m b/SmartDeviceLink/SDLIAPControlSession.m
index 534a3c614..e941c8a36 100644
--- a/SmartDeviceLink/SDLIAPControlSession.m
+++ b/SmartDeviceLink/SDLIAPControlSession.m
@@ -28,18 +28,6 @@ int const ProtocolIndexTimeoutSeconds = 10;
@end
-@interface SDLIAPSession (exposeIAPSessionPrivateMethods)
-
-@property (nonatomic, assign) BOOL isInputStreamOpen;
-@property (nonatomic, assign) BOOL isOutputStreamOpen;
-
-- (BOOL)start;
-- (void)startStream:(NSStream *)stream;
-- (void)stopStream:(NSStream *)stream;
-- (void)closeSession;
-
-@end
-
@implementation SDLIAPControlSession
#pragma mark - Session lifecycle
@@ -79,7 +67,7 @@ int const ProtocolIndexTimeoutSeconds = 10;
}
- (BOOL)sdl_startStreams {
- if (![super start]) { return NO; }
+ if (![super createSession]) { return NO; }
// No need for its own thread as only a small amount of data will be transmitted before control session is destroyed
SDLLogD(@"Created the control session successfully");
@@ -117,7 +105,7 @@ int const ProtocolIndexTimeoutSeconds = 10;
[super stopStream:self.eaSession.outputStream];
[super stopStream:self.eaSession.inputStream];
- [super closeSession];
+ [super cleanupClosedSession];
}
diff --git a/SmartDeviceLink/SDLIAPDataSession.m b/SmartDeviceLink/SDLIAPDataSession.m
index 16a6bdbff..1c046dd38 100644
--- a/SmartDeviceLink/SDLIAPDataSession.m
+++ b/SmartDeviceLink/SDLIAPDataSession.m
@@ -29,18 +29,6 @@ NS_ASSUME_NONNULL_BEGIN
@end
-@interface SDLIAPSession (exposeIAPSessionPrivateMethods)
-
-@property (nonatomic, assign) BOOL isInputStreamOpen;
-@property (nonatomic, assign) BOOL isOutputStreamOpen;
-
-- (BOOL)start;
-- (void)startStream:(NSStream *)stream;
-- (void)stopStream:(NSStream *)stream;
-- (void)closeSession;
-
-@end
-
@implementation SDLIAPDataSession
#pragma mark - Session lifecycle
@@ -68,7 +56,7 @@ NS_ASSUME_NONNULL_BEGIN
} else {
SDLLogD(@"Starting data session with accessory: %@, using protocol: %@", self.accessory.name, self.protocolString);
- if (![super start]) {
+ if (![super createSession]) {
SDLLogW(@"Data session failed to setup with accessory: %@. Retrying...", self.accessory);
[self destroySession];
if (self.delegate == nil) { return; }
@@ -110,7 +98,7 @@ NS_ASSUME_NONNULL_BEGIN
if (self.ioStreamThread == nil) {
SDLLogV(@"Stopping data session but no thread established.");
- [super closeSession];
+ [super cleanupClosedSession];
return;
}
@@ -122,7 +110,7 @@ NS_ASSUME_NONNULL_BEGIN
SDLLogE(@"Destroying thread (IOStreamThread) for data session when I/O streams have not yet closed.");
}
self.ioStreamThread = nil;
- [super closeSession];
+ [super cleanupClosedSession];
}];
}
@@ -146,8 +134,6 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - Sending data
- (void)sendData:(NSData *)data {
- SDLLogV(@"Sending data %lu. I/O streams open? %s", (unsigned long)data.length, self.isStopped ? "no" : "yes");
-
// Enqueue the data for transmission on the IO thread
[self.sendDataQueue enqueueBuffer:data.mutableCopy];
@@ -178,8 +164,6 @@ NS_ASSUME_NONNULL_BEGIN
NSUInteger bytesRemaining = remainder.length;
NSInteger bytesWritten = [ostream write:remainder.bytes maxLength:bytesRemaining];
- SDLLogV(@"%ld bytes written to data session output stream", (long)bytesWritten);
-
if (bytesWritten < 0) {
if (ostream.streamError != nil) {
[self sdl_handleOutputStreamWriteError:ostream.streamError];
@@ -324,7 +308,6 @@ NS_ASSUME_NONNULL_BEGIN
* Called when the session gets a `NSStreamEventHasSpaceAvailable` event code. Send any queued data to Core.
*/
- (void)sdl_streamHasSpaceToWrite {
- SDLLogV(@"NSStreamEventHasSpaceAvailable");
[self sdl_dequeueAndWriteToOutputStream];
}
diff --git a/SmartDeviceLink/SDLIAPSession.h b/SmartDeviceLink/SDLIAPSession.h
index 0f0be80c8..75b1f6d55 100644
--- a/SmartDeviceLink/SDLIAPSession.h
+++ b/SmartDeviceLink/SDLIAPSession.h
@@ -32,6 +32,16 @@ NS_ASSUME_NONNULL_BEGIN
@property (assign, readonly, getter=isStopped) BOOL stopped;
/**
+ * The input stream for the session is open when a `NSStreamEventOpenCompleted` event is received for the input stream. The input stream is closed when the stream status is `NSStreamStatusClosed`.
+ */
+@property (nonatomic, assign) BOOL isInputStreamOpen;
+
+/**
+ * The output stream for the session is open when a `NSStreamEventOpenCompleted` event is received for the output stream. The output stream has been closed when the stream status is `NSStreamStatusClosed`.
+ */
+@property (nonatomic, assign) BOOL isOutputStreamOpen;
+
+/**
* The unique ID assigned to the session between the app and accessory. If no session exists the value will be 0.
*/
@property (assign, nonatomic, readonly) NSUInteger connectionID;
@@ -60,6 +70,33 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (void)destroySession;
+/**
+ * Creates a session with the accessory.
+ *
+ * @return Whether or not the session was created successfully
+ */
+- (BOOL)createSession;
+
+/**
+ * Starts a session input or output stream.
+ *
+ * @param stream The stream to be started.
+ */
+- (void)startStream:(NSStream *)stream;
+
+/**
+ * Stops a session input or output stream.
+ *
+ * @param stream The stream to be stopped.
+ */
+- (void)stopStream:(NSStream *)stream;
+
+/**
+ * Cleans up a closed session
+ */
+- (void)cleanupClosedSession;
+
+
@end
NS_ASSUME_NONNULL_END
diff --git a/SmartDeviceLink/SDLIAPSession.m b/SmartDeviceLink/SDLIAPSession.m
index dd5ad2936..96844b3a7 100644
--- a/SmartDeviceLink/SDLIAPSession.m
+++ b/SmartDeviceLink/SDLIAPSession.m
@@ -10,15 +10,6 @@
NS_ASSUME_NONNULL_BEGIN
@interface SDLIAPSession ()
-/**
- * The input stream for the session is open when a `NSStreamEventOpenCompleted` event is received for the input stream. The input stream is closed when the stream status is `NSStreamStatusClosed`.
- */
-@property (nonatomic, assign) BOOL isInputStreamOpen;
-
-/**
- * The output stream for the session is open when a `NSStreamEventOpenCompleted` event is received for the output stream. The output stream has been closed when the stream status is `NSStreamStatusClosed`.
- */
-@property (nonatomic, assign) BOOL isOutputStreamOpen;
@property (nullable, strong, nonatomic, readwrite) EASession *eaSession;
@property (nullable, strong, nonatomic, readwrite) EAAccessory *accessory;
@@ -52,7 +43,7 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - Private Stream Lifecycle Helpers
-- (BOOL)start {
+- (BOOL)createSession {
SDLLogD(@"Opening EASession with accessory: %@", self.accessory.name);
self.eaSession = [[EASession alloc] initWithAccessory:self.accessory forProtocol:self.protocolString];
return (self.eaSession != nil);
@@ -88,7 +79,7 @@ NS_ASSUME_NONNULL_BEGIN
}
}
-- (void)closeSession {
+- (void)cleanupClosedSession {
if (self.eaSession == nil) {
SDLLogD(@"Attempting to close session with accessory: %@, but it is already closed", self.accessory.name);
return;
diff --git a/SmartDeviceLinkTests/TransportSpecs/iAP/SDLIAPSessionSpec.m b/SmartDeviceLinkTests/TransportSpecs/iAP/SDLIAPSessionSpec.m
index 17984383f..f253a1d44 100644
--- a/SmartDeviceLinkTests/TransportSpecs/iAP/SDLIAPSessionSpec.m
+++ b/SmartDeviceLinkTests/TransportSpecs/iAP/SDLIAPSessionSpec.m
@@ -14,13 +14,6 @@
#import "SDLIAPSession.h"
#import "SDLIAPConstants.h"
-@interface SDLIAPSession ()
-
-@property (nonatomic, assign) BOOL isInputStreamOpen;
-@property (nonatomic, assign) BOOL isOutputStreamOpen;
-
-@end
-
QuickSpecBegin(SDLIAPSessionSpec)