summaryrefslogtreecommitdiff
path: root/SmartDeviceLink/SDLProtocol.h
blob: 4f8954026727346cc6c5a1c183e2c4557478b8c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
//  SDLSmartDeviceLinkProtocol.h
//

#import <Foundation/Foundation.h>

#import "SDLTransportType.h"
#import "SDLProtocolConstants.h"
#import "SDLProtocolListener.h"
#import "SDLSecurityType.h"
#import "SDLTransportDelegate.h"

@class SDLEncryptionLifecycleManager;
@class SDLProtocolHeader;
@class SDLProtocolRecievedMessageRouter;
@class SDLRPCMessage;

NS_ASSUME_NONNULL_BEGIN

/**
 *  A protocol error type
 *
 *  - SDLProtocolErrorNoSecurityManager: No security manager was provided
 */
typedef NS_ENUM(NSUInteger, SDLProtocolError) {
    SDLProtocolErrorNoSecurityManager,
};

extern NSString *const SDLProtocolSecurityErrorDomain;


@interface SDLProtocol : NSObject <SDLProtocolListener, SDLTransportDelegate>

/**
 *  Deprecated debug logging tool.
 */
@property (strong, nonatomic) NSString *debugConsoleGroupName;

/**
 *  The transport layer for sending data between the app and Core
 */
@property (nullable, weak, nonatomic) id<SDLTransportType> transport;

/**
 *  A table for tracking all subscribers
 *
 *  If you update protocolDelegateTable while the protocol is running, please make sure to guard with @synchronized.
 */
@property (nullable, strong, nonatomic) NSHashTable<id<SDLProtocolListener>> *protocolDelegateTable;

/**
 *  A security manager for sending encrypted data.
 */
@property (nullable, nonatomic, strong) id<SDLSecurityType> securityManager;

/**
 *  The app's id
 */
@property (nonatomic, copy) NSString *appId;

/**
 *  The auth token, if any, returned with the `StartServiceACK` for the RPC service from the module.
 */
@property (strong, nonatomic, readonly, nullable) NSString *authToken;

#pragma mark - Init
/**
 *  Initialize the protocol with an encryption lifecycle manager.
 *
 *  @param encryptionLifecycleManager An encryption lifecycle manager.
 *
 *  @return An instance of SDLProtocol
 */
- (instancetype)initWithEncryptionLifecycleManager:(SDLEncryptionLifecycleManager *)encryptionLifecycleManager;

#pragma mark - Sending

/**
 *  Pre-configure protocol header for specified service type
 *
 *  This is used to initialize Session ID before starting a protocol.
 *
 *  @param header The header which is applied to the service type
 *  @param serviceType A SDLServiceType object
 *  @return YES if the header is successfully set, NO otherwise
 */
- (BOOL)storeHeader:(SDLProtocolHeader *)header forServiceType:(SDLServiceType)serviceType;

/**
 *  Sends a start service message to Core
 *
 *  @param serviceType A SDLServiceType object
 *  @param payload The data to send in the message
 */
- (void)startServiceWithType:(SDLServiceType)serviceType payload:(nullable NSData *)payload;

/**
 *  Sends a secure start service message to Core
 *
 *  @param serviceType A SDLServiceType object
 *  @param payload The data to send in the message
 *  @param tlsInitializationHandler Handler called when the app is authenticated via TLS handshake and a secure service has started. If a secure service can not be started an error message is returned.
 */
- (void)startSecureServiceWithType:(SDLServiceType)serviceType payload:(nullable NSData *)payload tlsInitializationHandler:(void (^)(BOOL success, NSError *error))tlsInitializationHandler;

/**
 *  Sends an end service message to Core
 *
 *  @param serviceType A SDLServiceType object
 */
- (void)endServiceWithType:(SDLServiceType)serviceType;

/**
 *  Sends a Register Secondary Transport control frame to Core
 */
- (void)registerSecondaryTransport;

/**
 *  Sends an unencrypted RPC to Core
 *
 *  @param message A SDLRPCMessage message
 */
- (void)sendRPC:(SDLRPCMessage *)message;

/**
 *  Sends an unencrypted message to Core
 *
 *  @param data The data to send
 *  @param serviceType A SDLServiceType object
 */
- (void)sendRawData:(NSData *)data withServiceType:(SDLServiceType)serviceType;

/**
 *  Sends an encrypted message to Core
 *
 *  @param data         The data to send
 *  @param serviceType  A SDLServiceType object
 */
- (void)sendEncryptedRawData:(NSData *)data onService:(SDLServiceType)serviceType;

#pragma mark - Recieving

/**
 *  Turns received bytes into message objects.
 *
 *  @param receivedData The data received from Core
 */
- (void)handleBytesFromTransport:(NSData *)receivedData;

@end

NS_ASSUME_NONNULL_END