mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 14:46:12 -04:00
Replace GTMLogger with GNCLogger
PiperOrigin-RevId: 766419599
This commit is contained in:
committed by
Copybara-Service
parent
c7cfe3ead4
commit
46d7270fdc
@@ -74,7 +74,7 @@ objc_library(
|
||||
"//internal/platform/implementation:types",
|
||||
"//internal/platform/implementation/apple/Mediums",
|
||||
"//internal/platform/implementation/shared:file",
|
||||
"//third_party/objective_c/google_toolbox_for_mac:GTM_Logger",
|
||||
"//internal/platform/implementation/apple/Log:GNCLogger",
|
||||
] + select({
|
||||
"@platforms//os:platform_ios": [
|
||||
"//third_party/apple_frameworks:UIKit",
|
||||
@@ -120,12 +120,12 @@ objc_library(
|
||||
"//internal/platform:uuid",
|
||||
"//internal/platform/implementation:comm",
|
||||
"//internal/platform/implementation/apple/Flags",
|
||||
"//internal/platform/implementation/apple/Log:GNCLogger",
|
||||
"//internal/platform/implementation/apple/Mediums",
|
||||
"//internal/platform/implementation/apple/Mediums/Ble/Sockets:Central",
|
||||
"//internal/platform/implementation/apple/Mediums/Ble/Sockets:Peripheral",
|
||||
"//third_party/apple_frameworks:CoreBluetooth",
|
||||
"//third_party/apple_frameworks:Foundation",
|
||||
"//third_party/objective_c/google_toolbox_for_mac:GTM_Logger",
|
||||
"@com_google_absl//absl/container:flat_hash_map",
|
||||
"@com_google_absl//absl/functional:any_invocable",
|
||||
"@com_google_absl//absl/strings",
|
||||
@@ -158,8 +158,8 @@ objc_library(
|
||||
"//internal/platform:base",
|
||||
"//internal/platform:cancellation_flag",
|
||||
"//internal/platform/implementation:comm",
|
||||
"//internal/platform/implementation/apple/Log:GNCLogger",
|
||||
"//internal/platform/implementation/apple/Mediums",
|
||||
"//third_party/objective_c/google_toolbox_for_mac:GTM_Logger",
|
||||
"@com_google_absl//absl/functional:any_invocable",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -18,12 +18,12 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "internal/platform/implementation/apple/Flags/GNCFeatureFlags.h"
|
||||
#import "internal/platform/implementation/apple/Log/GNCLogger.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/BLEv2/GNCBLEError.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/BLEv2/GNCBLEGATTCharacteristic.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/BLEv2/GNCPeripheralManager.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/BLEv2/NSData+GNCBase85.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/BLEv2/NSData+GNCWebSafeBase64.h"
|
||||
#import "GoogleToolboxForMac/GTMLogger.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@@ -316,7 +316,7 @@ static char *const kGNCBLEGATTServerQueueLabel = "com.nearby.GNCBLEGATTServer";
|
||||
error:(nullable NSError *)error {
|
||||
dispatch_assert_queue(_queue);
|
||||
if (error) {
|
||||
GTMLoggerError(@"Failed to start advertising: %@", error);
|
||||
GNCLoggerError(@"Failed to start advertising: %@", error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -325,7 +325,7 @@ static char *const kGNCBLEGATTServerQueueLabel = "com.nearby.GNCBLEGATTServer";
|
||||
error:(nullable NSError *)error {
|
||||
dispatch_assert_queue(_queue);
|
||||
if (error) {
|
||||
GTMLoggerError(@"Failed to add service %@: %@", service, error);
|
||||
GNCLoggerError(@"Failed to add service %@: %@", service, error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,10 +17,10 @@
|
||||
#import <CoreBluetooth/CoreBluetooth.h>
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "internal/platform/implementation/apple/Log/GNCLogger.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/BLEv2/GNCBLEError.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/BLEv2/GNCBLEL2CAPStream.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/BLEv2/GNCPeripheral.h"
|
||||
#import "GoogleToolboxForMac/GTMLogger.h"
|
||||
|
||||
static char *const kGNCBLEL2CAPClientQueueLabel = "com.google.nearby.GNCBLEL2CAPClient";
|
||||
|
||||
@@ -59,7 +59,7 @@ static char *const kGNCBLEL2CAPClientQueueLabel = "com.google.nearby.GNCBLEL2CAP
|
||||
- (void)openL2CAPChannelWithPSM:(uint16_t)PSM
|
||||
peripheral:(id<GNCPeripheral>)peripheral
|
||||
completionHandler:(GNCOpenL2CAPStreamCompletionHandler)completionHandler {
|
||||
GTMLoggerInfo(@"[NEARBY] openL2CAPChannelWithPSM = %d", PSM);
|
||||
GNCLoggerInfo(@"[NEARBY] openL2CAPChannelWithPSM = %d", PSM);
|
||||
_peripheral = peripheral;
|
||||
_peripheral.peripheralDelegate = self;
|
||||
_completionHandler = [completionHandler copy];
|
||||
@@ -81,7 +81,7 @@ static char *const kGNCBLEL2CAPClientQueueLabel = "com.google.nearby.GNCBLEL2CAP
|
||||
didOpenL2CAPChannel:(CBL2CAPChannel *)channel
|
||||
error:(NSError *)error {
|
||||
dispatch_assert_queue(_queue);
|
||||
GTMLoggerDebug(
|
||||
GNCLoggerDebug(
|
||||
@"[NEARBY] didOpenL2CAPChannel, channel: %@, inputStream: %@, outputStream: %@, error: %@",
|
||||
channel, channel.inputStream, channel.outputStream, error);
|
||||
// TODO: b/399815436 - channel.inputStream is null when doing testing. Refactor tests in the
|
||||
|
||||
@@ -16,11 +16,11 @@
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "internal/platform/implementation/apple/Log/GNCLogger.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/BLEv2/GNCBLEL2CAPStream.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/Ble/GNCMBleUtils.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/GNCLeaks.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/GNCMConnection.h"
|
||||
#import "GoogleToolboxForMac/GTMLogger.h"
|
||||
|
||||
enum { kL2CAPPacketLength = 4 };
|
||||
static const CGFloat kRequestDataConnectionDelayInSeconds = 0.0;
|
||||
@@ -101,7 +101,7 @@ static NSData *PrefixLengthData(NSData *data) {
|
||||
// Prefix the service ID hash.
|
||||
packet = PrefixLengthData(PrefixDataWithServiceIDHash(_serviceIDHash, data));
|
||||
if (_verboseLoggingEnabled) {
|
||||
GTMLoggerDebug(@"[NEARBY] GNCBLEL2CAPConnection data to be sent: %@", [packet description]);
|
||||
GNCLoggerDebug(@"[NEARBY] GNCBLEL2CAPConnection data to be sent: %@", [packet description]);
|
||||
}
|
||||
[_stream sendData:packet
|
||||
completionBlock:^(BOOL result) {
|
||||
@@ -113,7 +113,7 @@ static NSData *PrefixLengthData(NSData *data) {
|
||||
}
|
||||
|
||||
- (void)requestDataConnectionWithCompletion:(void (^)(BOOL))completion {
|
||||
GTMLoggerInfo(@"[NEARBY] Sending l2cap packet request data connection");
|
||||
GNCLoggerInfo(@"[NEARBY] Sending l2cap packet request data connection");
|
||||
// TODO b/399815436 - A bug is causing channel has written to the socket but the remote does not
|
||||
// receive it. Add a delay to make sure the data is written to the socket. Remove the delay once
|
||||
// the bug is fixed.
|
||||
@@ -141,7 +141,7 @@ static NSData *PrefixLengthData(NSData *data) {
|
||||
|
||||
- (void)stream:(GNCBLEL2CAPStream *)stream didReceiveData:(NSData *)data {
|
||||
if (_verboseLoggingEnabled) {
|
||||
GTMLoggerDebug(@"[NEARBY] BLEL2CAPConnection didReceiveData, data: %@, length: %lu",
|
||||
GNCLoggerDebug(@"[NEARBY] BLEL2CAPConnection didReceiveData, data: %@, length: %lu",
|
||||
[data debugDescription], data.length);
|
||||
}
|
||||
if (!data.length) {
|
||||
@@ -214,7 +214,7 @@ static NSData *PrefixLengthData(NSData *data) {
|
||||
// Extract the service ID prefix from each data packet and validate it.
|
||||
NSUInteger prefixLength = _serviceIDHash.length;
|
||||
if (![[realData subdataWithRange:NSMakeRange(0, prefixLength)] isEqual:_serviceIDHash]) {
|
||||
GTMLoggerError(@"[NEARBY]: Received wrong data packet and discarded");
|
||||
GNCLoggerError(@"[NEARBY]: Received wrong data packet and discarded");
|
||||
return bytesProcessed;
|
||||
}
|
||||
|
||||
@@ -234,7 +234,7 @@ static NSData *PrefixLengthData(NSData *data) {
|
||||
// Store the expected data length if it is not set yet.
|
||||
if (!_expectedDataLength) {
|
||||
if (data.length < kL2CAPPacketLength) {
|
||||
GTMLoggerError(@"[NEARBY] Data length mismatch. Expected: > %d, Actual: %lu",
|
||||
GNCLoggerError(@"[NEARBY] Data length mismatch. Expected: > %d, Actual: %lu",
|
||||
kL2CAPPacketLength, data.length);
|
||||
return nil;
|
||||
}
|
||||
@@ -314,9 +314,9 @@ static NSData *PrefixLengthData(NSData *data) {
|
||||
NSData *serviceIDHash = GNCMParseBLEFramesIntroductionPacket(data);
|
||||
if ([serviceIDHash isEqual:_serviceIDHash]) {
|
||||
_handledReceivedBLEIntroPacket = YES;
|
||||
GTMLoggerInfo(@"[NEARBY]: Received BLE intro packet and handled.");
|
||||
GNCLoggerInfo(@"[NEARBY]: Received BLE intro packet and handled.");
|
||||
} else {
|
||||
GTMLoggerInfo(@"[NEARBY]: Received wrong BLE intro packet and discarded.");
|
||||
GNCLoggerInfo(@"[NEARBY]: Received wrong BLE intro packet and discarded.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,10 +17,10 @@
|
||||
#import <CoreBluetooth/CoreBluetooth.h>
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "internal/platform/implementation/apple/Log/GNCLogger.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/BLEv2/GNCBLEError.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/BLEv2/GNCBLEL2CAPStream.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/BLEv2/GNCPeripheralManager.h"
|
||||
#import "GoogleToolboxForMac/GTMLogger.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@@ -91,7 +91,7 @@ static char *const kGNCBLEL2CAPServerQueueLabel = "com.google.nearby.GNCBLEL2CAP
|
||||
// insufficient authentication errors due to initialization order.
|
||||
[_peripheralManager publishL2CAPChannelWithEncryption:NO];
|
||||
} else {
|
||||
GTMLoggerInfo(@"[NEARBY] Peripheral must be on to start, waiting.");
|
||||
GNCLoggerInfo(@"[NEARBY] Peripheral must be on to start, waiting.");
|
||||
_alreadyStartedWhenPeripheralPoweredOff = YES;
|
||||
}
|
||||
}
|
||||
@@ -124,9 +124,9 @@ static char *const kGNCBLEL2CAPServerQueueLabel = "com.google.nearby.GNCBLEL2CAP
|
||||
didPublishL2CAPChannel:(CBL2CAPPSM)PSM
|
||||
error:(nullable NSError *)error {
|
||||
dispatch_assert_queue(_queue);
|
||||
GTMLoggerDebug(@"[NEARBY] didPublishL2CAPChannel with PSM: %@", @(PSM));
|
||||
GNCLoggerDebug(@"[NEARBY] didPublishL2CAPChannel with PSM: %@", @(PSM));
|
||||
if (error) {
|
||||
GTMLoggerError(@"[NEARBY] Failed to publish L2CAP channel: %@", error);
|
||||
GNCLoggerError(@"[NEARBY] Failed to publish L2CAP channel: %@", error);
|
||||
if (_psmPublishedCompletionHandler) {
|
||||
_psmPublishedCompletionHandler(0, error);
|
||||
}
|
||||
@@ -142,9 +142,9 @@ static char *const kGNCBLEL2CAPServerQueueLabel = "com.google.nearby.GNCBLEL2CAP
|
||||
didUnpublishL2CAPChannel:(CBL2CAPPSM)PSM
|
||||
error:(NSError *)error {
|
||||
dispatch_assert_queue(_queue);
|
||||
GTMLoggerDebug(@"[NEARBY] didUnpublishL2CAPChannel on PSM %@", @(PSM));
|
||||
GNCLoggerDebug(@"[NEARBY] didUnpublishL2CAPChannel on PSM %@", @(PSM));
|
||||
if (error) {
|
||||
GTMLoggerError(@"[NEARBY] Failed to unpublish L2CAP channel: %@", error);
|
||||
GNCLoggerError(@"[NEARBY] Failed to unpublish L2CAP channel: %@", error);
|
||||
}
|
||||
[_l2CAPStream tearDown];
|
||||
_l2CAPStream = nil;
|
||||
@@ -155,7 +155,7 @@ static char *const kGNCBLEL2CAPServerQueueLabel = "com.google.nearby.GNCBLEL2CAP
|
||||
didOpenL2CAPChannel:(nullable CBL2CAPChannel *)channel
|
||||
error:(nullable NSError *)error {
|
||||
dispatch_assert_queue(_queue);
|
||||
GTMLoggerDebug(
|
||||
GNCLoggerDebug(
|
||||
@"[NEARBY] didOpenL2CAPChannel, channel: %@, inputStream: %@, outputStream: %@, error: %@",
|
||||
channel, channel.inputStream, channel.outputStream, error);
|
||||
// TODO: edwinwu - channel.inputStream is null when doing testing. Refactor tests in the future.
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
#import "internal/platform/implementation/apple/Mediums/BLEv2/GNCBLEL2CAPStream.h"
|
||||
|
||||
#import "GoogleToolboxForMac/GTMLogger.h"
|
||||
#import "internal/platform/implementation/apple/Log/GNCLogger.h"
|
||||
|
||||
enum { READ_BUFFER_SIZE = 409600 };
|
||||
|
||||
@@ -101,13 +101,13 @@ enum { READ_BUFFER_SIZE = 409600 };
|
||||
|
||||
- (void)tearDown {
|
||||
dispatch_async(_streamQueue, ^{
|
||||
GTMLoggerDebug(@"[NEARBY] Closing inputStream %@ by tearDown", self.inputStream);
|
||||
GNCLoggerDebug(@"[NEARBY] Closing inputStream %@ by tearDown", self.inputStream);
|
||||
[self.inputStream close];
|
||||
self.inputStream.delegate = nil;
|
||||
self.inputStream = nil;
|
||||
|
||||
@synchronized(self->_writeBufferArray) {
|
||||
GTMLoggerDebug(@"[NEARBY] Closing outputStream %@ by tearDown", self.outputStream);
|
||||
GNCLoggerDebug(@"[NEARBY] Closing outputStream %@ by tearDown", self.outputStream);
|
||||
[self.outputStream close];
|
||||
self.outputStream.delegate = nil;
|
||||
self.outputStream = nil;
|
||||
@@ -126,7 +126,7 @@ enum { READ_BUFFER_SIZE = 409600 };
|
||||
NSStream *inputStream = _inputStream;
|
||||
NSStream *outputStream = _outputStream;
|
||||
dispatch_async(_streamQueue, ^{
|
||||
GTMLoggerDebug(@"[NEARBY] Closing streams inputStream %@ outputStream %@ by deallocation",
|
||||
GNCLoggerDebug(@"[NEARBY] Closing streams inputStream %@ outputStream %@ by deallocation",
|
||||
inputStream, outputStream);
|
||||
[inputStream close];
|
||||
inputStream.delegate = nil;
|
||||
@@ -138,7 +138,7 @@ enum { READ_BUFFER_SIZE = 409600 };
|
||||
|
||||
- (void)sendData:(NSData *)data completionBlock:(void (^)(BOOL))completionBlock {
|
||||
if (!data || data.length == 0) {
|
||||
GTMLoggerError(@"[NEARBY] Sending data cannot be nil or empty");
|
||||
GNCLoggerError(@"[NEARBY] Sending data cannot be nil or empty");
|
||||
}
|
||||
|
||||
GNCBLEL2CAPStreamWriteOperation *write =
|
||||
@@ -157,7 +157,7 @@ enum { READ_BUFFER_SIZE = 409600 };
|
||||
|
||||
- (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode {
|
||||
if (_verboseLoggingEnabled) {
|
||||
GTMLoggerDebug(@"[NEARBY] Stream event %@ for stream %@",
|
||||
GNCLoggerDebug(@"[NEARBY] Stream event %@ for stream %@",
|
||||
[[self class] stringFromStreamEventCode:eventCode], stream);
|
||||
}
|
||||
if ([stream isEqual:self.inputStream]) {
|
||||
@@ -173,7 +173,7 @@ enum { READ_BUFFER_SIZE = 409600 };
|
||||
case NSStreamEventHasSpaceAvailable:
|
||||
case NSStreamEventNone:
|
||||
default:
|
||||
GTMLoggerInfo(@"[NEARBY] Received event %@ for stream %@",
|
||||
GNCLoggerInfo(@"[NEARBY] Received event %@ for stream %@",
|
||||
[[self class] stringFromStreamEventCode:eventCode], stream);
|
||||
break;
|
||||
}
|
||||
@@ -198,7 +198,7 @@ enum { READ_BUFFER_SIZE = 409600 };
|
||||
case NSStreamEventEndEncountered:
|
||||
case NSStreamEventNone:
|
||||
default:
|
||||
GTMLoggerInfo(@"[NEARBY] Received event %@ for stream %@",
|
||||
GNCLoggerInfo(@"[NEARBY] Received event %@ for stream %@",
|
||||
[[self class] stringFromStreamEventCode:eventCode], stream);
|
||||
break;
|
||||
}
|
||||
@@ -235,21 +235,21 @@ enum { READ_BUFFER_SIZE = 409600 };
|
||||
self.outputStream = outputStream;
|
||||
|
||||
if (inputStream.delegate) {
|
||||
GTMLoggerError(@"[NEARBY] Should not have a delegate.");
|
||||
GNCLoggerError(@"[NEARBY] Should not have a delegate.");
|
||||
return;
|
||||
}
|
||||
if (outputStream.delegate) {
|
||||
GTMLoggerError(@"[NEARBY] Should not have a delegate.");
|
||||
GNCLoggerError(@"[NEARBY] Should not have a delegate.");
|
||||
return;
|
||||
}
|
||||
|
||||
inputStream.delegate = self;
|
||||
outputStream.delegate = self;
|
||||
|
||||
GTMLoggerDebug(@"[NEARBY] streams inputStream %@ outputStream %@", inputStream, outputStream);
|
||||
GNCLoggerDebug(@"[NEARBY] streams inputStream %@ outputStream %@", inputStream, outputStream);
|
||||
|
||||
if (!_streamQueue) {
|
||||
GTMLoggerError(@"[NEARBY] Stream queue must be initialized.");
|
||||
GNCLoggerError(@"[NEARBY] Stream queue must be initialized.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -266,7 +266,7 @@ enum { READ_BUFFER_SIZE = 409600 };
|
||||
/// Must be called after synchronizing on |_writeBufferArray|.
|
||||
- (void)sendWriteBufferData {
|
||||
if (!_writeBufferArray.count) {
|
||||
GTMLoggerError(@"[NEARBY] sendWriteBufferData should not be called with empty buffer");
|
||||
GNCLoggerError(@"[NEARBY] sendWriteBufferData should not be called with empty buffer");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -275,18 +275,18 @@ enum { READ_BUFFER_SIZE = 409600 };
|
||||
[self.outputStream write:(const uint8_t *)_writeBufferArray.firstObject.remainingData.bytes
|
||||
maxLength:totalBytesToWrite];
|
||||
if (result < 0) {
|
||||
GTMLoggerError(@"[NEARBY] Stream write error %@", self.outputStream.streamError);
|
||||
GNCLoggerError(@"[NEARBY] Stream write error %@", self.outputStream.streamError);
|
||||
return;
|
||||
}
|
||||
|
||||
if (result < 0) {
|
||||
GTMLoggerError(@"[NEARBY] Write result should not be negative.");
|
||||
GNCLoggerError(@"[NEARBY] Write result should not be negative.");
|
||||
return;
|
||||
}
|
||||
NSUInteger totalBytesWritten = (NSUInteger)result;
|
||||
|
||||
if (_verboseLoggingEnabled) {
|
||||
GTMLoggerInfo(@"[NEARBY] Wrote %@/%@ bytes to stream", @(totalBytesWritten),
|
||||
GNCLoggerInfo(@"[NEARBY] Wrote %@/%@ bytes to stream", @(totalBytesWritten),
|
||||
@(totalBytesToWrite));
|
||||
}
|
||||
|
||||
@@ -297,7 +297,7 @@ enum { READ_BUFFER_SIZE = 409600 };
|
||||
} else {
|
||||
[_writeBufferArray.firstObject consumeBytes:totalBytesWritten];
|
||||
if (_writeBufferArray.firstObject.remainingData.length == 0) {
|
||||
GTMLoggerError(@"[NEARBY] Remaining data cannot be empty.");
|
||||
GNCLoggerError(@"[NEARBY] Remaining data cannot be empty.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -314,16 +314,16 @@ enum { READ_BUFFER_SIZE = 409600 };
|
||||
[data appendBytes:readBuffer length:(NSUInteger)bytesRead];
|
||||
|
||||
if (_verboseLoggingEnabled) {
|
||||
GTMLoggerDebug(@"[NEARBY] Stream data from device of length %@", @(data.length));
|
||||
GNCLoggerDebug(@"[NEARBY] Stream data from device of length %@", @(data.length));
|
||||
}
|
||||
|
||||
dispatch_async(_receivedDataQueue, ^{
|
||||
[_delegate stream:self didReceiveData:data];
|
||||
});
|
||||
} else if (bytesRead < 0) {
|
||||
GTMLoggerError(@"[NEARBY] Stream read error: %@", self.inputStream.streamError);
|
||||
GNCLoggerError(@"[NEARBY] Stream read error: %@", self.inputStream.streamError);
|
||||
} else if (bytesRead == 0) {
|
||||
GTMLoggerDebug(@"[NEARBY] End of stream reached. Disconnecting");
|
||||
GNCLoggerDebug(@"[NEARBY] End of stream reached. Disconnecting");
|
||||
// This indicates the L2CAP socket is closed. Notifying the owner so that it can tear down this
|
||||
// stream and update its own state.
|
||||
[_delegate stream:self didDisconnectWithError:nil];
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "internal/platform/implementation/apple/Flags/GNCFeatureFlags.h"
|
||||
#import "internal/platform/implementation/apple/Log/GNCLogger.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/BLEv2/GNCBLEError.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/BLEv2/GNCBLEGATTClient.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/BLEv2/GNCBLEGATTServer.h"
|
||||
@@ -27,7 +28,6 @@
|
||||
#import "internal/platform/implementation/apple/Mediums/BLEv2/GNCPeripheral.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/BLEv2/NSData+GNCBase85.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/BLEv2/NSData+GNCWebSafeBase64.h"
|
||||
#import "GoogleToolboxForMac/GTMLogger.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@@ -228,7 +228,7 @@ static GNCBLEL2CAPServer *_Nonnull CreateL2CapServer(
|
||||
dispatch_async(_queue, ^{
|
||||
__strong __typeof__(self) strongSelf = weakSelf;
|
||||
if (!strongSelf) {
|
||||
GTMLoggerDebug(@"GNCBLEMedium instance no longer exists when connect to gatt server.");
|
||||
GNCLoggerDebug(@"GNCBLEMedium instance no longer exists when connect to gatt server.");
|
||||
return;
|
||||
}
|
||||
strongSelf->_gattDisconnectionHandlers[remotePeripheral.identifier] = disconnectionHandler;
|
||||
@@ -273,7 +273,7 @@ static GNCBLEL2CAPServer *_Nonnull CreateL2CapServer(
|
||||
dispatch_async(_queue, ^{
|
||||
__strong __typeof__(self) strongSelf = weakSelf;
|
||||
if (!strongSelf) {
|
||||
GTMLoggerDebug(@"GNCBLEMedium instance no longer exists when open L2CAP channel.");
|
||||
GNCLoggerDebug(@"GNCBLEMedium instance no longer exists when open L2CAP channel.");
|
||||
return;
|
||||
}
|
||||
if (!strongSelf->_l2capClient) {
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
#include "internal/encoding/base85.h"
|
||||
|
||||
#import "GoogleToolboxForMac/GTMLogger.h"
|
||||
#import "internal/platform/implementation/apple/Log/GNCLogger.h"
|
||||
|
||||
@implementation NSData (GNCBase85)
|
||||
|
||||
|
||||
@@ -82,6 +82,7 @@ objc_library(
|
||||
"//internal/encoding:base85",
|
||||
"//internal/platform/implementation/apple:Shared",
|
||||
"//internal/platform/implementation/apple/Flags",
|
||||
"//internal/platform/implementation/apple/Log:GNCLogger",
|
||||
"//internal/platform/implementation/apple/Mediums/Ble/Sockets:Shared",
|
||||
"//proto/mediums:ble_frames_cc_proto",
|
||||
"//third_party/apple_frameworks:CoreBluetooth",
|
||||
@@ -92,6 +93,5 @@ objc_library(
|
||||
"//third_party/apple_frameworks:ObjectiveC",
|
||||
"//third_party/apple_frameworks:Security",
|
||||
"//third_party/apple_frameworks:SystemConfiguration",
|
||||
"//third_party/objective_c/google_toolbox_for_mac:GTM_Logger",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -14,11 +14,11 @@
|
||||
|
||||
#import "internal/platform/implementation/apple/Mediums/Ble/GNCMBleConnection.h"
|
||||
|
||||
#import "internal/platform/implementation/apple/Log/GNCLogger.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/Ble/GNCMBleUtils.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/Ble/Sockets/Source/Shared/GNSSocket.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/GNCLeaks.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/GNCMConnection.h"
|
||||
#import "GoogleToolboxForMac/GTMLogger.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@@ -86,7 +86,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
#pragma mark GNSSocketDelegate
|
||||
|
||||
- (void)socketDidConnect:(GNSSocket *)socket {
|
||||
GTMLoggerError(@"Unexpected -socketDidConnect: call; should've already happened");
|
||||
GNCLoggerError(@"Unexpected -socketDidConnect: call; should've already happened");
|
||||
}
|
||||
|
||||
- (void)socket:(GNSSocket *)socket didDisconnectWithError:(NSError *)error {
|
||||
@@ -113,21 +113,21 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
_serviceIDHash = serviceIDHash;
|
||||
_receivedIntroPacket = YES;
|
||||
} else {
|
||||
GTMLoggerInfo(@"[NEARBY] Input stream: Received wrong intro packet and discarded");
|
||||
GNCLoggerInfo(@"[NEARBY] Input stream: Received wrong intro packet and discarded");
|
||||
}
|
||||
} else {
|
||||
NSData *introData = GNCMGenerateBLEFramesIntroductionPacket(_serviceIDHash);
|
||||
if ([data isEqual:introData]) {
|
||||
_receivedIntroPacket = YES;
|
||||
} else {
|
||||
GTMLoggerInfo(@"[NEARBY] Input stream: Received wrong intro packet and discarded");
|
||||
GNCLoggerInfo(@"[NEARBY] Input stream: Received wrong intro packet and discarded");
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (![[data subdataWithRange:NSMakeRange(0, prefixLength)] isEqual:_serviceIDHash]) {
|
||||
GTMLoggerInfo(@"[NEARBY] Input stream: Received wrong data packet and discarded");
|
||||
GNCLoggerInfo(@"[NEARBY] Input stream: Received wrong data packet and discarded");
|
||||
return;
|
||||
}
|
||||
packet = [NSMutableData
|
||||
|
||||
@@ -19,9 +19,9 @@
|
||||
#include <vector>
|
||||
|
||||
#import "internal/platform/implementation/apple/GNCUtils.h"
|
||||
#import "internal/platform/implementation/apple/Log/GNCLogger.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/Ble/Sockets/Source/Shared/GNSSocket.h"
|
||||
#include "proto/mediums/ble_frames.pb.h"
|
||||
#import "GoogleToolboxForMac/GTMLogger.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@@ -116,7 +116,7 @@ NSData *GNCMGenerateBLEFramesDisconnectionPacket(NSData *serviceIDHash) {
|
||||
// TODO: b/399815436 - Add unit tests for this function.
|
||||
GNCMBLEL2CAPPacket *_Nullable GNCMParseBLEL2CAPPacket(NSData *data) {
|
||||
if (data.length < 1) {
|
||||
GTMLoggerError(@"[NEARBY] Invalid packet length: %@", @(data.length));
|
||||
GNCLoggerError(@"[NEARBY] Invalid packet length: %@", @(data.length));
|
||||
return nil;
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ GNCMBLEL2CAPPacket *_Nullable GNCMParseBLEL2CAPPacket(NSData *data) {
|
||||
NSUInteger receivedDataLength = [data length];
|
||||
GNCMBLEL2CAPCommand command = (GNCMBLEL2CAPCommand)bytes[0];
|
||||
if (!IsSupportedCommand(command)) {
|
||||
GTMLoggerError(@"[NEARBY] Invalid command: %lu", command);
|
||||
GNCLoggerError(@"[NEARBY] Invalid command: %lu", command);
|
||||
return nil;
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ GNCMBLEL2CAPPacket *_Nullable GNCMParseBLEL2CAPPacket(NSData *data) {
|
||||
|
||||
// Validate data length
|
||||
if (dataLength != (int)(receivedDataLength - 3)) {
|
||||
GTMLoggerError(@"[NEARBY] Data length mismatch. Expected: %d, Actual: %lu", dataLength,
|
||||
GNCLoggerError(@"[NEARBY] Data length mismatch. Expected: %d, Actual: %lu", dataLength,
|
||||
receivedDataLength - 3);
|
||||
return nil;
|
||||
}
|
||||
@@ -153,7 +153,7 @@ GNCMBLEL2CAPPacket *_Nullable GNCMParseBLEL2CAPPacket(NSData *data) {
|
||||
// TODO: b/399815436 - Add unit tests for this function.
|
||||
NSData *_Nullable GNCMGenerateBLEL2CAPPacket(GNCMBLEL2CAPCommand command, NSData *_Nullable data) {
|
||||
if (!IsSupportedCommand(command)) {
|
||||
GTMLoggerError(@"[NEARBY] Invalid command to generate packet: %lu", command);
|
||||
GNCLoggerError(@"[NEARBY] Invalid command to generate packet: %lu", command);
|
||||
return nil;
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ NSData *_Nullable GNCMGenerateBLEL2CAPPacket(GNCMBLEL2CAPCommand command, NSData
|
||||
packet.push_back((uint8_t)command);
|
||||
if (data != nil) {
|
||||
if (data.length > 65535) {
|
||||
GTMLoggerError(@"[NEARBY] Data length is too large: %lu", data.length);
|
||||
GNCLoggerError(@"[NEARBY] Data length is too large: %lu", data.length);
|
||||
return nil;
|
||||
}
|
||||
// Prepare length bytes
|
||||
@@ -205,7 +205,7 @@ NSData *_Nullable GNCMGenerateBLEL2CAPPacket(GNCMBLEL2CAPCommand command, NSData
|
||||
}
|
||||
|
||||
- (void)socket:(GNSSocket *)socket didReceiveData:(NSData *)data {
|
||||
GTMLoggerError(@"Unexpected -didReceiveData: call");
|
||||
GNCLoggerError(@"Unexpected -didReceiveData: call");
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -34,9 +34,9 @@ objc_library(
|
||||
],
|
||||
deps = [
|
||||
":Shared",
|
||||
"//internal/platform/implementation/apple/Log:GNCLogger",
|
||||
"//third_party/apple_frameworks:CoreBluetooth",
|
||||
"//third_party/apple_frameworks:Foundation",
|
||||
"//third_party/objective_c/google_toolbox_for_mac:GTM_Logger",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -55,11 +55,11 @@ objc_library(
|
||||
],
|
||||
deps = [
|
||||
":Shared",
|
||||
"//internal/platform/implementation/apple/Log:GNCLogger",
|
||||
"//third_party/apple_frameworks:CoreBluetooth",
|
||||
"//third_party/apple_frameworks:CoreFoundation",
|
||||
"//third_party/apple_frameworks:Foundation",
|
||||
"//third_party/apple_frameworks:QuartzCore",
|
||||
"//third_party/objective_c/google_toolbox_for_mac:GTM_Logger",
|
||||
] + select({
|
||||
"@platforms//os:platform_ios": [
|
||||
"//third_party/apple_frameworks:UIKit",
|
||||
@@ -79,11 +79,11 @@ objc_library(
|
||||
"Source/GNSShared.h",
|
||||
],
|
||||
deps = [
|
||||
"//internal/platform/implementation/apple/Log:GNCLogger",
|
||||
"//third_party/apple_frameworks:CoreBluetooth",
|
||||
"//third_party/apple_frameworks:CoreFoundation",
|
||||
"//third_party/apple_frameworks:Foundation",
|
||||
"//third_party/apple_frameworks:QuartzCore",
|
||||
"//third_party/objective_c/google_toolbox_for_mac:GTM_Logger",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
+2
-2
@@ -21,7 +21,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
@class GNSCentralManager;
|
||||
@class GNSCentralPeerManager;
|
||||
|
||||
@protocol GNSCentralManagerDelegate<NSObject>
|
||||
@protocol GNSCentralManagerDelegate <NSObject>
|
||||
|
||||
/**
|
||||
* Called while scanning when a new peer is found.
|
||||
@@ -70,7 +70,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
* [centralPeer socketWithPairingCharacteristic:shouldAddPairingCharacteristics
|
||||
* completion:^(GNSSocket *mySocket, NSError *error) {
|
||||
* if (error) {
|
||||
* GTMLoggerInfo(@"Error to get the socket %@", error);
|
||||
* GNCLoggerInfo(@"Error to get the socket %@", error);
|
||||
* return;
|
||||
* }
|
||||
* mySocket.delegate = mySocketDelegate;
|
||||
|
||||
+26
-25
@@ -15,9 +15,9 @@
|
||||
#import "internal/platform/implementation/apple/Mediums/Ble/Sockets/Source/Central/GNSCentralManager.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/Ble/Sockets/Source/Central/GNSCentralManager+Private.h"
|
||||
|
||||
#import "internal/platform/implementation/apple/Log/GNCLogger.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/Ble/Sockets/Source/Central/GNSCentralPeerManager+Private.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/Ble/Sockets/Source/Central/GNSCentralPeerManager.h"
|
||||
#import "GoogleToolboxForMac/GTMLogger.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@@ -71,10 +71,10 @@ static NSString *CentralManagerStateString(CBCentralManagerState state) {
|
||||
if (self) {
|
||||
_socketServiceUUID = socketServiceUUID;
|
||||
_queue = queue;
|
||||
_cbCentralManager = [[self class]
|
||||
centralManagerWithDelegate:self
|
||||
queue:queue
|
||||
options:@{CBCentralManagerOptionShowPowerAlertKey : @NO}];
|
||||
_cbCentralManager =
|
||||
[[self class] centralManagerWithDelegate:self
|
||||
queue:queue
|
||||
options:@{CBCentralManagerOptionShowPowerAlertKey : @NO}];
|
||||
_centralPeerManagers = [NSMapTable strongToWeakObjectsMapTable];
|
||||
}
|
||||
return self;
|
||||
@@ -134,7 +134,7 @@ static NSString *CentralManagerStateString(CBCentralManagerState state) {
|
||||
- (void)retrievePeripheralWithIdentifier:(NSUUID *)identifier
|
||||
advertisementData:(nonnull NSDictionary<NSString *, id> *)advertisementData {
|
||||
NSArray<CBPeripheral *> *peripherals =
|
||||
[_cbCentralManager retrievePeripheralsWithIdentifiers:@[identifier]];
|
||||
[_cbCentralManager retrievePeripheralsWithIdentifiers:@[ identifier ]];
|
||||
if (peripherals.count > 0) {
|
||||
[self centralManager:_cbCentralManager
|
||||
didDiscoverPeripheral:peripherals[0]
|
||||
@@ -152,8 +152,8 @@ static NSString *CentralManagerStateString(CBCentralManagerState state) {
|
||||
NSAssert(identifier, @"Should have an identifier, self: %@", self);
|
||||
GNSCentralPeerManager *peerManager = [_centralPeerManagers objectForKey:identifier];
|
||||
if (peerManager) {
|
||||
GTMLoggerAssert(@"Previous GNSCentralPeerManager still alive, self: %@, peer manager: %@", self,
|
||||
peerManager);
|
||||
GNCLoggerFatal(@"Previous GNSCentralPeerManager still alive, self: %@, peer manager: %@", self,
|
||||
peerManager);
|
||||
return nil;
|
||||
}
|
||||
NSArray<CBPeripheral *> *peripherals =
|
||||
@@ -165,7 +165,7 @@ static NSString *CentralManagerStateString(CBCentralManagerState state) {
|
||||
return peerManager;
|
||||
}
|
||||
}
|
||||
GTMLoggerError(@"CBPeripheral not found, self: %@, identifier %@, peripherals %@", self,
|
||||
GNCLoggerError(@"CBPeripheral not found, self: %@, identifier %@, peripherals %@", self,
|
||||
identifier, peripherals);
|
||||
return nil;
|
||||
}
|
||||
@@ -200,7 +200,7 @@ static NSString *CentralManagerStateString(CBCentralManagerState state) {
|
||||
// The drawback is the same CBPeripheral is discovered several times per second.
|
||||
NSDictionary<NSString *, id> *options = @{CBCentralManagerScanOptionAllowDuplicatesKey : @YES};
|
||||
if (_advertisedName) {
|
||||
GTMLoggerInfo(@"Start scanning for all peripherals. Filter peripherals with advertised "
|
||||
GNCLoggerInfo(@"Start scanning for all peripherals. Filter peripherals with advertised "
|
||||
"service UUID %@ or advertised name %@.",
|
||||
[_socketServiceUUID UUIDString], _advertisedName);
|
||||
[_cbCentralManager scanForPeripheralsWithServices:nil options:options];
|
||||
@@ -211,7 +211,7 @@ static NSString *CentralManagerStateString(CBCentralManagerState state) {
|
||||
// Not logging this case to avoid spamming the logs.
|
||||
[_cbCentralManager scanForPeripheralsWithServices:_advertisedServiceUUIDs options:options];
|
||||
} else {
|
||||
GTMLoggerInfo(@"Start scanning for all peripherals.");
|
||||
GNCLoggerInfo(@"Start scanning for all peripherals.");
|
||||
[_cbCentralManager scanForPeripheralsWithServices:nil options:options];
|
||||
}
|
||||
}
|
||||
@@ -235,20 +235,20 @@ static NSString *CentralManagerStateString(CBCentralManagerState state) {
|
||||
|
||||
- (void)connectPeripheralForPeer:(GNSCentralPeerManager *)peer
|
||||
options:(nullable NSDictionary<NSString *, id> *)options {
|
||||
GTMLoggerInfo(@"Connect peer %@ options %@", peer, options);
|
||||
GNCLoggerInfo(@"Connect peer %@ options %@", peer, options);
|
||||
[_cbCentralManager connectPeripheral:peer.cbPeripheral options:options];
|
||||
}
|
||||
|
||||
- (void)cancelPeripheralConnectionForPeer:(GNSCentralPeerManager *)peer {
|
||||
GTMLoggerInfo(@"Cancel peer connection %@", peer);
|
||||
GNCLoggerInfo(@"Cancel peer connection %@", peer);
|
||||
[_cbCentralManager cancelPeripheralConnection:peer.cbPeripheral];
|
||||
}
|
||||
|
||||
- (void)centralPeerManagerDidDisconnect:(GNSCentralPeerManager *)peer {
|
||||
GTMLoggerInfo(@"Central manager removing central peer manager, central manager: %@, peer %@",
|
||||
GNCLoggerInfo(@"Central manager removing central peer manager, central manager: %@, peer %@",
|
||||
self, peer);
|
||||
if (peer.cbPeripheral.state != CBPeripheralStateDisconnected) {
|
||||
GTMLoggerInfo(@"Unexpected peripheral state %@", peer.cbPeripheral);
|
||||
GNCLoggerInfo(@"Unexpected peripheral state %@", peer.cbPeripheral);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -257,21 +257,22 @@ static NSString *CentralManagerStateString(CBCentralManagerState state) {
|
||||
}
|
||||
|
||||
- (GNSCentralPeerManager *)createCentralPeerManagerWithPeripheral:(CBPeripheral *)peripheral {
|
||||
return [[GNSCentralPeerManager alloc]
|
||||
initWithPeripheral:peripheral centralManager:self queue:_queue];
|
||||
return [[GNSCentralPeerManager alloc] initWithPeripheral:peripheral
|
||||
centralManager:self
|
||||
queue:_queue];
|
||||
}
|
||||
|
||||
- (GNSCentralPeerManager *)centralPeerForPeripheral:(CBPeripheral *)peripheral {
|
||||
NSParameterAssert(peripheral);
|
||||
GNSCentralPeerManager *peerManager = [_centralPeerManagers objectForKey:peripheral.identifier];
|
||||
if (!peerManager) {
|
||||
GTMLoggerDebug(@"No peer manager found for peripheral %@", peripheral);
|
||||
GNCLoggerDebug(@"No peer manager found for peripheral %@", peripheral);
|
||||
return nil;
|
||||
}
|
||||
if (peerManager.cbPeripheral != peripheral) {
|
||||
// There is a peer manager with a different peripheral object than |peripheral|, but with the
|
||||
// same identifier. Something really wrong happened in CoreBluetooth here.
|
||||
GTMLoggerError(@"Peer Manager %@ has a different peripheral than %@ [CentralManager = %@]",
|
||||
GNCLoggerError(@"Peer Manager %@ has a different peripheral than %@ [CentralManager = %@]",
|
||||
peerManager, peripheral, self);
|
||||
return nil;
|
||||
}
|
||||
@@ -282,7 +283,7 @@ static NSString *CentralManagerStateString(CBCentralManagerState state) {
|
||||
|
||||
- (void)centralManagerDidUpdateState:(CBCentralManager *)central {
|
||||
NSAssert(central == _cbCentralManager, @"Wrong peripheral manager.");
|
||||
GTMLoggerInfo(@"CoreBluetooth state: %@",
|
||||
GNCLoggerInfo(@"CoreBluetooth state: %@",
|
||||
CentralManagerStateString([self cbCentralManagerState]));
|
||||
switch (central.state) {
|
||||
case CBCentralManagerStatePoweredOn: {
|
||||
@@ -319,7 +320,7 @@ static NSString *CentralManagerStateString(CBCentralManagerState state) {
|
||||
NSUUID *identifier = peripheral.identifier;
|
||||
GNSCentralPeerManager *peerManager = [_centralPeerManagers objectForKey:identifier];
|
||||
if (!peerManager) {
|
||||
GTMLoggerInfo(@"Discovered peer peripheral %@", peripheral);
|
||||
GNCLoggerInfo(@"Discovered peer peripheral %@", peripheral);
|
||||
peerManager = [self createCentralPeerManagerWithPeripheral:peripheral];
|
||||
[_centralPeerManagers setObject:peerManager forKey:identifier];
|
||||
[_delegate centralManager:self
|
||||
@@ -331,10 +332,10 @@ static NSString *CentralManagerStateString(CBCentralManagerState state) {
|
||||
|
||||
- (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral {
|
||||
NSAssert(central == _cbCentralManager, @"Unexpected central manager");
|
||||
GTMLoggerInfo(@"Connected to %@", peripheral);
|
||||
GNCLoggerInfo(@"Connected to %@", peripheral);
|
||||
GNSCentralPeerManager *peerManager = [self centralPeerForPeripheral:peripheral];
|
||||
if (!peerManager) {
|
||||
GTMLoggerError(
|
||||
GNCLoggerError(
|
||||
@"No peer manager found for connected peripheral %@. Cancel peripheral connection",
|
||||
peripheral);
|
||||
[_cbCentralManager cancelPeripheralConnection:peripheral];
|
||||
@@ -347,7 +348,7 @@ static NSString *CentralManagerStateString(CBCentralManagerState state) {
|
||||
didFailToConnectPeripheral:(CBPeripheral *)peripheral
|
||||
error:(nullable NSError *)error {
|
||||
NSAssert(central == _cbCentralManager, @"Unexpected central manager");
|
||||
GTMLoggerInfo(@"Fail to connect to %@, error %@", peripheral, error);
|
||||
GNCLoggerInfo(@"Fail to connect to %@, error %@", peripheral, error);
|
||||
[self peripheralDisconnected:peripheral withError:error];
|
||||
}
|
||||
|
||||
@@ -355,7 +356,7 @@ static NSString *CentralManagerStateString(CBCentralManagerState state) {
|
||||
didDisconnectPeripheral:(CBPeripheral *)peripheral
|
||||
error:(nullable NSError *)error {
|
||||
NSAssert(central == _cbCentralManager, @"Unexpected central manager");
|
||||
GTMLoggerInfo(@"Did disconnect %@, error %@", peripheral, error);
|
||||
GNCLoggerInfo(@"Did disconnect %@, error %@", peripheral, error);
|
||||
[self peripheralDisconnected:peripheral withError:error];
|
||||
}
|
||||
|
||||
|
||||
+87
-72
@@ -15,14 +15,14 @@
|
||||
#import "internal/platform/implementation/apple/Mediums/Ble/Sockets/Source/Central/GNSCentralPeerManager.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/Ble/Sockets/Source/Central/GNSCentralPeerManager+Private.h"
|
||||
|
||||
#import "internal/platform/implementation/apple/Log/GNCLogger.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/Ble/Sockets/Source/Central/GNSCentralManager+Private.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/Ble/Sockets/Source/Central/GNSCentralManager.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/Ble/Sockets/Source/Shared/GNSSocket.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/Ble/Sockets/Source/Shared/GNSSocket+Private.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/Ble/Sockets/Source/Shared/GNSUtils.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/Ble/Sockets/Source/Shared/GNSSocket.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/Ble/Sockets/Source/Shared/GNSUtils+Private.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/Ble/Sockets/Source/Shared/GNSUtils.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/Ble/Sockets/Source/Shared/GNSWeavePacket.h"
|
||||
#import "GoogleToolboxForMac/GTMLogger.h"
|
||||
|
||||
static const NSTimeInterval kMaxConnectionConfirmWaitTimeInSeconds = 2;
|
||||
static const NSTimeInterval kPeripheralFailedToConnectTimeout = 10.0;
|
||||
@@ -85,7 +85,7 @@ static NSString *PeripheralStateString(CBPeripheralState state) {
|
||||
return [NSString stringWithFormat:@"CBPeripheralState Unknown (%ld)", (long)state];
|
||||
}
|
||||
|
||||
@interface GNSCentralPeerManager ()<GNSWeavePacketHandler>
|
||||
@interface GNSCentralPeerManager () <GNSWeavePacketHandler>
|
||||
@property(nonatomic) GNSCentralPeerManagerState state;
|
||||
@property(nonatomic) GNSCentralManager *centralManager;
|
||||
@property(nonatomic) dispatch_queue_t queue;
|
||||
@@ -139,7 +139,7 @@ static NSString *PeripheralStateString(CBPeripheralState state) {
|
||||
_queue = queue;
|
||||
_socketMaximumUpdateValueLength = gGNSCentralPeerManagerMaximumUpdateValue;
|
||||
_state = GNSCentralPeerManagerStateNotConnected;
|
||||
GTMLoggerInfo(@"Peripheral %@", _cbPeripheral);
|
||||
GNCLoggerInfo(@"Peripheral %@", _cbPeripheral);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@@ -152,7 +152,7 @@ static NSString *PeripheralStateString(CBPeripheralState state) {
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
GTMLoggerDebug(@"Dealloc CentralPeerManager with _cbPeripheral %@", _cbPeripheral);
|
||||
GNCLoggerDebug(@"Dealloc CentralPeerManager with _cbPeripheral %@", _cbPeripheral);
|
||||
_cbPeripheral.delegate = nil;
|
||||
if (_cbPeripheral.state != CBPeripheralStateDisconnected) {
|
||||
[_centralManager cancelPeripheralConnectionForPeer:self];
|
||||
@@ -169,9 +169,9 @@ static NSString *PeripheralStateString(CBPeripheralState state) {
|
||||
|
||||
- (void)socketWithPairingCharacteristic:(BOOL)shouldAddPairingCharacteristics
|
||||
completion:(GNSCentralSocketCompletion)completion {
|
||||
GTMLoggerInfo(@"Request socket %@", self);
|
||||
GNCLoggerInfo(@"Request socket %@", self);
|
||||
if (_state != GNSCentralPeerManagerStateNotConnected) {
|
||||
GTMLoggerInfo(@"There is a pending socket request");
|
||||
GNCLoggerInfo(@"There is a pending socket request");
|
||||
if (completion) {
|
||||
dispatch_async(_queue, ^{
|
||||
completion(nil, GNSErrorWithCode(GNSErrorOperationInProgress));
|
||||
@@ -186,10 +186,10 @@ static NSString *PeripheralStateString(CBPeripheralState state) {
|
||||
|
||||
- (void)cancelPendingSocket {
|
||||
if (_discoveringServiceSocketCompletion == nil) {
|
||||
GTMLoggerInfo(@"No pending socket, current socket: %@", _socket);
|
||||
GNCLoggerInfo(@"No pending socket, current socket: %@", _socket);
|
||||
return;
|
||||
}
|
||||
GTMLoggerInfo(@"Cancelling pending socket");
|
||||
GNCLoggerInfo(@"Cancelling pending socket");
|
||||
NSError *cancelPendingSocketRequested = GNSErrorWithCode(GNSErrorCancelPendingSocketRequested);
|
||||
[self disconnectingWithError:cancelPendingSocketRequested];
|
||||
}
|
||||
@@ -210,7 +210,9 @@ static NSString *PeripheralStateString(CBPeripheralState state) {
|
||||
NSAssert(completion, @"Completion cannot be nil");
|
||||
if (![self isBLEConnected]) {
|
||||
NSAssert(!_readRSSIValueCompletions, @"Should not have pending RSSI completions.");
|
||||
dispatch_async(_queue, ^{ completion(nil, GNSErrorWithCode(GNSErrorNoConnection)); });
|
||||
dispatch_async(_queue, ^{
|
||||
completion(nil, GNSErrorWithCode(GNSErrorNoConnection));
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (!_readRSSIValueCompletions) {
|
||||
@@ -231,7 +233,7 @@ static NSString *PeripheralStateString(CBPeripheralState state) {
|
||||
#pragma mark - Private
|
||||
|
||||
- (void)bleConnect {
|
||||
GTMLoggerInfo(@"BLE connection started.");
|
||||
GNCLoggerInfo(@"BLE connection started.");
|
||||
_startConnectionTime = [NSDate date];
|
||||
|
||||
_state = GNSCentralPeerManagerStateBleConnecting;
|
||||
@@ -249,37 +251,39 @@ static NSString *PeripheralStateString(CBPeripheralState state) {
|
||||
// -didFailToConnectPeripheral should be called at this point, but sometimes neither is called.
|
||||
// In this case, report a timeout error.
|
||||
__weak __typeof__(self) weakSelf = self;
|
||||
dispatch_after(
|
||||
dispatch_time(DISPATCH_TIME_NOW, (int64_t)(kPeripheralFailedToConnectTimeout * NSEC_PER_SEC)),
|
||||
_queue, ^{
|
||||
__typeof__(self) strongSelf = weakSelf;
|
||||
if (!strongSelf) return;
|
||||
if (strongSelf.state == GNSCentralPeerManagerStateBleConnecting) {
|
||||
GTMLoggerInfo(@"Timed out trying to connect to peripheral: %@", strongSelf.cbPeripheral);
|
||||
[strongSelf.centralManager cancelPeripheralConnectionForPeer:self];
|
||||
[strongSelf bleDisconnectedWithError:GNSErrorWithCode(GNSErrorConnectionTimedOut)];
|
||||
}
|
||||
});
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW,
|
||||
(int64_t)(kPeripheralFailedToConnectTimeout * NSEC_PER_SEC)),
|
||||
_queue, ^{
|
||||
__typeof__(self) strongSelf = weakSelf;
|
||||
if (!strongSelf) return;
|
||||
if (strongSelf.state == GNSCentralPeerManagerStateBleConnecting) {
|
||||
GNCLoggerInfo(@"Timed out trying to connect to peripheral: %@",
|
||||
strongSelf.cbPeripheral);
|
||||
[strongSelf.centralManager cancelPeripheralConnectionForPeer:self];
|
||||
[strongSelf
|
||||
bleDisconnectedWithError:GNSErrorWithCode(GNSErrorConnectionTimedOut)];
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
- (void)bleConnected {
|
||||
if (_cbPeripheral.state != CBPeripheralStateConnected) {
|
||||
GTMLoggerInfo(@"Unexpected peripheral state: %ld", (long)_cbPeripheral.state);
|
||||
GNCLoggerInfo(@"Unexpected peripheral state: %ld", (long)_cbPeripheral.state);
|
||||
}
|
||||
GTMLoggerInfo(@"BLE connected. Elapsed time: %f",
|
||||
GNCLoggerInfo(@"BLE connected. Elapsed time: %f",
|
||||
[[NSDate date] timeIntervalSinceDate:_startConnectionTime]);
|
||||
if (_state != GNSCentralPeerManagerStateBleConnecting) {
|
||||
GTMLoggerInfo(@"Should not be connected with %@ when in %@ state", _cbPeripheral,
|
||||
GNCLoggerInfo(@"Should not be connected with %@ when in %@ state", _cbPeripheral,
|
||||
StateDescription(_state));
|
||||
return;
|
||||
}
|
||||
GTMLoggerInfo(@"BLE connected, peripheral: %@", _cbPeripheral);
|
||||
GNCLoggerInfo(@"BLE connected, peripheral: %@", _cbPeripheral);
|
||||
[self discoverService];
|
||||
}
|
||||
|
||||
- (void)bleDisconnectedWithError:(NSError *)error {
|
||||
GTMLoggerInfo(@"BLE disconnected, peripheral: %@", _cbPeripheral);
|
||||
GNCLoggerInfo(@"BLE disconnected, peripheral: %@", _cbPeripheral);
|
||||
if (_state == GNSCentralPeerManagerStateNotConnected) {
|
||||
return;
|
||||
} else {
|
||||
@@ -301,9 +305,9 @@ static NSString *PeripheralStateString(CBPeripheralState state) {
|
||||
|
||||
- (void)disconnectingWithError:(NSError *)error {
|
||||
if (error) {
|
||||
GTMLoggerInfo(@"Disconnected with error: %@, peripheral: %@", error, _cbPeripheral);
|
||||
GNCLoggerInfo(@"Disconnected with error: %@, peripheral: %@", error, _cbPeripheral);
|
||||
} else {
|
||||
GTMLoggerInfo(@"Disconnected from peripheral: %@", _cbPeripheral);
|
||||
GNCLoggerInfo(@"Disconnected from peripheral: %@", _cbPeripheral);
|
||||
}
|
||||
[_connectionConfirmTimer invalidate];
|
||||
_connectionConfirmTimer = nil;
|
||||
@@ -323,9 +327,9 @@ static NSString *PeripheralStateString(CBPeripheralState state) {
|
||||
}
|
||||
|
||||
- (void)bleDisconnected {
|
||||
GTMLoggerInfo(@"BLE Disconnected %@", _cbPeripheral);
|
||||
GNCLoggerInfo(@"BLE Disconnected %@", _cbPeripheral);
|
||||
if (_cbPeripheral.state != CBPeripheralStateDisconnected) {
|
||||
GTMLoggerInfo(@"Unexpected peripheral state: %ld", (long)_cbPeripheral.state);
|
||||
GNCLoggerInfo(@"Unexpected peripheral state: %ld", (long)_cbPeripheral.state);
|
||||
}
|
||||
NSAssert(_cbPeripheral.delegate == self, @"Self = %@ should be the delegate of %@", self,
|
||||
_cbPeripheral);
|
||||
@@ -346,7 +350,9 @@ static NSString *PeripheralStateString(CBPeripheralState state) {
|
||||
}
|
||||
GNSCentralSocketCompletion completion = _discoveringServiceSocketCompletion;
|
||||
_discoveringServiceSocketCompletion = nil;
|
||||
dispatch_async(_queue, ^{ completion(nil, _disconnectedError); });
|
||||
dispatch_async(_queue, ^{
|
||||
completion(nil, _disconnectedError);
|
||||
});
|
||||
} else if (currentSocket) {
|
||||
[currentSocket didDisconnectWithError:_disconnectedError];
|
||||
}
|
||||
@@ -355,14 +361,14 @@ static NSString *PeripheralStateString(CBPeripheralState state) {
|
||||
- (void)discoverService {
|
||||
_state = GNSCentralPeerManagerStateDiscoveringService;
|
||||
CBUUID *serviceUUID = _centralManager.socketServiceUUID;
|
||||
GTMLoggerInfo(@"Discover service %@ on peripheral: %@", serviceUUID, _cbPeripheral);
|
||||
GNCLoggerInfo(@"Discover service %@ on peripheral: %@", serviceUUID, _cbPeripheral);
|
||||
NSArray<CBUUID *> *servicesToDiscover = @[ serviceUUID ];
|
||||
[_cbPeripheral discoverServices:servicesToDiscover];
|
||||
}
|
||||
|
||||
- (void)discoverCharacteristics {
|
||||
if (_cbPeripheral.services.count == 0) return;
|
||||
GTMLoggerInfo(@"Discover characteristics, peer manager %@", self);
|
||||
GNCLoggerInfo(@"Discover characteristics, peer manager %@", self);
|
||||
NSMutableArray<CBUUID *> *characteristics = [NSMutableArray
|
||||
arrayWithObjects:[CBUUID UUIDWithString:kGNSWeaveToPeripheralCharUUIDString],
|
||||
[CBUUID UUIDWithString:kGNSWeaveFromPeripheralCharUUIDString], nil];
|
||||
@@ -421,7 +427,9 @@ static NSString *PeripheralStateString(CBPeripheralState state) {
|
||||
NSArray<GNSReadRRSIValueCompletion> *completions = _readRSSIValueCompletions;
|
||||
_readRSSIValueCompletions = nil;
|
||||
for (GNSReadRRSIValueCompletion completion in completions) {
|
||||
dispatch_async(_queue, ^{ completion(rssiValue, error); });
|
||||
dispatch_async(_queue, ^{
|
||||
completion(rssiValue, error);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -443,7 +451,7 @@ static NSString *PeripheralStateString(CBPeripheralState state) {
|
||||
- (void)timeOutConnectionForTimer:(NSTimer *)timer {
|
||||
NSAssert(_state == GNSCentralPeerManagerStateSocketCommunication,
|
||||
@"Timer (%@) fired on the wrong state. [self = %@]", _connectionConfirmTimer, self);
|
||||
GTMLoggerInfo(@"Timing out %@ socket connection [self = %@].", _socket, self);
|
||||
GNCLoggerInfo(@"Timing out %@ socket connection [self = %@].", _socket, self);
|
||||
_connectionConfirmTimer = nil;
|
||||
NSError *error = GNSErrorWithCode(GNSErrorConnectionTimedOut);
|
||||
[self disconnectingWithError:error];
|
||||
@@ -453,21 +461,23 @@ static NSString *PeripheralStateString(CBPeripheralState state) {
|
||||
if (_dataWriteCompletion) {
|
||||
GNSErrorHandler dataWriteCompletion = _dataWriteCompletion; // tail call for reentrancy
|
||||
_dataWriteCompletion = nil;
|
||||
dispatch_async(_queue, ^{ dataWriteCompletion(error); });
|
||||
dispatch_async(_queue, ^{
|
||||
dataWriteCompletion(error);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - CBPeripheralDelegate
|
||||
|
||||
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error {
|
||||
GTMLoggerInfo(@"BLE services discovered. Elapsed time: %f",
|
||||
GNCLoggerInfo(@"BLE services discovered. Elapsed time: %f",
|
||||
[[NSDate date] timeIntervalSinceDate:_startConnectionTime]);
|
||||
if (_state != GNSCentralPeerManagerStateDiscoveringService) {
|
||||
GTMLoggerInfo(@"Ignoring services discovered from %@ when in %@ state", _cbPeripheral,
|
||||
GNCLoggerInfo(@"Ignoring services discovered from %@ when in %@ state", _cbPeripheral,
|
||||
StateDescription(_state));
|
||||
return;
|
||||
}
|
||||
GTMLoggerInfo(@"Service discovered for %@, error: %@", self, error);
|
||||
GNCLoggerInfo(@"Service discovered for %@, error: %@", self, error);
|
||||
if (error) {
|
||||
[self disconnectingWithError:error];
|
||||
return;
|
||||
@@ -483,17 +493,17 @@ static NSString *PeripheralStateString(CBPeripheralState state) {
|
||||
- (void)peripheral:(CBPeripheral *)peripheral
|
||||
didDiscoverCharacteristicsForService:(CBService *)service
|
||||
error:(NSError *)error {
|
||||
GTMLoggerInfo(@"BLE characteristics discovered. Elapsed time: %f",
|
||||
GNCLoggerInfo(@"BLE characteristics discovered. Elapsed time: %f",
|
||||
[[NSDate date] timeIntervalSinceDate:_startConnectionTime]);
|
||||
if (_state != GNSCentralPeerManagerStateDiscoveringCharacteristic) {
|
||||
GTMLoggerInfo(@"Ignoring characteristics discovered from %@ when in %@ state", _cbPeripheral,
|
||||
GNCLoggerInfo(@"Ignoring characteristics discovered from %@ when in %@ state", _cbPeripheral,
|
||||
StateDescription(_state));
|
||||
return;
|
||||
}
|
||||
GTMLoggerInfo(@"Characteristics discovered for service: %@, error: %@", service, error);
|
||||
GNCLoggerInfo(@"Characteristics discovered for service: %@, error: %@", service, error);
|
||||
CBService *serviceBeingChecked = _cbPeripheral.services[_indexOfServiceToCheck];
|
||||
NSAssert([service.UUID isEqual:serviceBeingChecked.UUID], @"Unknown service %@ %@",
|
||||
service, serviceBeingChecked.UUID);
|
||||
NSAssert([service.UUID isEqual:serviceBeingChecked.UUID], @"Unknown service %@ %@", service,
|
||||
serviceBeingChecked.UUID);
|
||||
if (error) {
|
||||
[self disconnectingWithError:error];
|
||||
return;
|
||||
@@ -531,7 +541,7 @@ static NSString *PeripheralStateString(CBPeripheralState state) {
|
||||
didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic
|
||||
error:(NSError *)error {
|
||||
if (_state != GNSCentralPeerManagerStateSocketCommunication) {
|
||||
GTMLoggerInfo(@"Ignoring data received from %@ when in %@ state", _cbPeripheral,
|
||||
GNCLoggerInfo(@"Ignoring data received from %@ when in %@ state", _cbPeripheral,
|
||||
StateDescription(_state));
|
||||
return;
|
||||
}
|
||||
@@ -539,7 +549,10 @@ static NSString *PeripheralStateString(CBPeripheralState state) {
|
||||
if ([characteristic.UUID isEqual:_pairingChar.UUID]) {
|
||||
GNSPairingCompletion completion = _pairingCompletion;
|
||||
_pairingCompletion = nil;
|
||||
if (completion) dispatch_async(_queue, ^{ completion(error == nil, error); });
|
||||
if (completion)
|
||||
dispatch_async(_queue, ^{
|
||||
completion(error == nil, error);
|
||||
});
|
||||
return;
|
||||
}
|
||||
NSAssert(characteristic == _incomingChar, @"Should read only from the incoming characteristic.");
|
||||
@@ -549,19 +562,19 @@ static NSString *PeripheralStateString(CBPeripheralState state) {
|
||||
// |socket.packetSize| for the rest.
|
||||
NSUInteger truncatedSize = MIN(_socket.packetSize, charValue.length);
|
||||
if (truncatedSize != charValue.length) {
|
||||
GTMLoggerInfo(@"Packet with %ld bytes trucanted to %ld", (long)charValue.length,
|
||||
GNCLoggerInfo(@"Packet with %ld bytes trucanted to %ld", (long)charValue.length,
|
||||
(long)truncatedSize);
|
||||
}
|
||||
NSData *packetData = [charValue subdataWithRange:NSMakeRange(0, truncatedSize)];
|
||||
NSError *parsingError = nil;
|
||||
GNSWeavePacket *packet = [GNSWeavePacket parseData:packetData error:&parsingError];
|
||||
if (!packet) {
|
||||
GTMLoggerError(@"Error parsing Weave packet (error = %@).", parsingError);
|
||||
GNCLoggerError(@"Error parsing Weave packet (error = %@).", parsingError);
|
||||
[self handleWeaveError:GNSErrorParsingWeavePacket socket:_socket];
|
||||
return;
|
||||
}
|
||||
if (packet.packetCounter != _socket.receivePacketCounter) {
|
||||
GTMLoggerError(@"Wrong packet counter, [received %d, expected %d].", packet.packetCounter,
|
||||
GNCLoggerError(@"Wrong packet counter, [received %d, expected %d].", packet.packetCounter,
|
||||
_socket.receivePacketCounter);
|
||||
[self handleWeaveError:GNSErrorWrongWeavePacketCounter socket:_socket];
|
||||
return;
|
||||
@@ -575,10 +588,10 @@ static NSString *PeripheralStateString(CBPeripheralState state) {
|
||||
error:(NSError *)error {
|
||||
// Note: Avoid using |characteristic.value| here as it seems it is always nil.
|
||||
if (error) {
|
||||
GTMLoggerInfo(@"Characteristic write failed with error: %@", error);
|
||||
GNCLoggerInfo(@"Characteristic write failed with error: %@", error);
|
||||
[self disconnectingWithError:error];
|
||||
} else {
|
||||
GTMLoggerInfo(@"Characteristic write succeeded");
|
||||
GNCLoggerInfo(@"Characteristic write succeeded");
|
||||
}
|
||||
[self callDataWriteCompletionWithError:error];
|
||||
}
|
||||
@@ -586,7 +599,7 @@ static NSString *PeripheralStateString(CBPeripheralState state) {
|
||||
// This method sends |packet| fitting a single characteristic write to |socket|. All packets sent by
|
||||
// this class (not the socket) must use this method.
|
||||
- (void)sendPacket:(GNSWeavePacket *)packet {
|
||||
GTMLoggerInfo(@"Writing value to characteristic (internal)");
|
||||
GNCLoggerInfo(@"Writing value to characteristic (internal)");
|
||||
NSAssert(packet.packetCounter == _socket.sendPacketCounter, @"Wrong packet counter.");
|
||||
[_cbPeripheral writeValue:[packet serialize]
|
||||
forCharacteristic:_outgoingChar
|
||||
@@ -597,14 +610,14 @@ static NSString *PeripheralStateString(CBPeripheralState state) {
|
||||
- (void)peripheral:(CBPeripheral *)peripheral
|
||||
didUpdateNotificationStateForCharacteristic:(CBCharacteristic *)characteristic
|
||||
error:(NSError *)error {
|
||||
GTMLoggerInfo(@"BLE characteristic notifications started. Elapsed time: %f",
|
||||
GNCLoggerInfo(@"BLE characteristic notifications started. Elapsed time: %f",
|
||||
[[NSDate date] timeIntervalSinceDate:_startConnectionTime]);
|
||||
if (_state != GNSCentralPeerManagerStateSettingNotifications) {
|
||||
GTMLoggerInfo(@"Ignoring notification status change for %@ when in %@ state", _cbPeripheral,
|
||||
GNCLoggerInfo(@"Ignoring notification status change for %@ when in %@ state", _cbPeripheral,
|
||||
StateDescription(_state));
|
||||
return;
|
||||
}
|
||||
GTMLoggerInfo(@"Characteristic notification update: %@, error: %@", characteristic, error);
|
||||
GNCLoggerInfo(@"Characteristic notification update: %@, error: %@", characteristic, error);
|
||||
if (error) {
|
||||
[self disconnectingWithError:error];
|
||||
return;
|
||||
@@ -612,18 +625,21 @@ static NSString *PeripheralStateString(CBPeripheralState state) {
|
||||
NSAssert([characteristic.UUID isEqual:_incomingChar.UUID], @"Wrong characteristic");
|
||||
NSAssert(_state == GNSCentralPeerManagerStateSettingNotifications, @"Wrong state");
|
||||
_state = GNSCentralPeerManagerStateSocketCommunication;
|
||||
GTMLoggerInfo(@"Socket ready %@", self);
|
||||
GNSSocket *socket =
|
||||
[[GNSSocket alloc] initWithOwner:self peripheralPeer:_cbPeripheral queue:_queue];
|
||||
GNCLoggerInfo(@"Socket ready %@", self);
|
||||
GNSSocket *socket = [[GNSSocket alloc] initWithOwner:self
|
||||
peripheralPeer:_cbPeripheral
|
||||
queue:_queue];
|
||||
GNSCentralSocketCompletion completion = _discoveringServiceSocketCompletion;
|
||||
_discoveringServiceSocketCompletion = nil;
|
||||
_socket = socket;
|
||||
dispatch_async(_queue, ^{ completion(socket, nil); });
|
||||
dispatch_async(_queue, ^{
|
||||
completion(socket, nil);
|
||||
});
|
||||
if (!_socket) {
|
||||
[self disconnectingWithError:nil];
|
||||
return;
|
||||
}
|
||||
GTMLoggerInfo(@"Sending connection request packet.");
|
||||
GNCLoggerInfo(@"Sending connection request packet.");
|
||||
// On iOS/OS X the central (client) doesn't have access to the negotiated BLE connection MTU. So,
|
||||
// according to the Weave BLE protocol specs, it should send 0. The peripheral will then choose
|
||||
// the appropriated value for the packet size and send it back on the connection confirm packet.
|
||||
@@ -643,7 +659,7 @@ static NSString *PeripheralStateString(CBPeripheralState state) {
|
||||
|
||||
- (void)peripheral:(CBPeripheral *)peripheral didReadRSSI:(NSNumber *)RSSI error:(NSError *)error {
|
||||
if (error) {
|
||||
GTMLoggerError(@"Error to read RSSI %@", error);
|
||||
GNCLoggerError(@"Error to read RSSI %@", error);
|
||||
}
|
||||
[self callRSSICompletionWithRSSIValue:RSSI error:error];
|
||||
}
|
||||
@@ -655,11 +671,11 @@ static NSString *PeripheralStateString(CBPeripheralState state) {
|
||||
}
|
||||
|
||||
- (void)sendData:(NSData *)data socket:(GNSSocket *)socket completion:(GNSErrorHandler)completion {
|
||||
GTMLoggerInfo(@"Writing value to characteristic");
|
||||
GNCLoggerInfo(@"Writing value to characteristic");
|
||||
if (_dataWriteCompletion != nil) {
|
||||
// This shouldn't happen because writes should be serialized by the socket code. But log it
|
||||
// in case there's a bug that causes it to happen.
|
||||
GTMLoggerInfo(@"Previous characteristic data write didn't complete");
|
||||
GNCLoggerInfo(@"Previous characteristic data write didn't complete");
|
||||
}
|
||||
|
||||
// Sometimes -didWriteValueForCharacteristic: isn't called, leaving the write operation hanging.
|
||||
@@ -668,7 +684,7 @@ static NSString *PeripheralStateString(CBPeripheralState state) {
|
||||
dispatch_block_t dataWriteTimeoutBlock = dispatch_block_create(0, ^{
|
||||
__typeof__(self) strongSelf = weakSelf;
|
||||
if (!strongSelf || !socket.isConnected) return;
|
||||
GTMLoggerInfo(@"Characteristic data write timed out");
|
||||
GNCLoggerInfo(@"Characteristic data write timed out");
|
||||
[strongSelf callDataWriteCompletionWithError:GNSErrorWithCode(GNSErrorConnectionTimedOut)];
|
||||
});
|
||||
_dataWriteCompletion = ^(NSError *error) {
|
||||
@@ -678,8 +694,7 @@ static NSString *PeripheralStateString(CBPeripheralState state) {
|
||||
};
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW,
|
||||
(int64_t)(kChracteristicWriteTimeoutInSeconds * NSEC_PER_SEC)),
|
||||
_queue,
|
||||
dataWriteTimeoutBlock);
|
||||
_queue, dataWriteTimeoutBlock);
|
||||
|
||||
[_cbPeripheral writeValue:data
|
||||
forCharacteristic:_outgoingChar
|
||||
@@ -695,7 +710,7 @@ static NSString *PeripheralStateString(CBPeripheralState state) {
|
||||
_state == GNSCentralPeerManagerStateBleDisconnecting) {
|
||||
return;
|
||||
}
|
||||
GTMLoggerInfo(@"Disconnect socket %@", socket);
|
||||
GNCLoggerInfo(@"Disconnect socket %@", socket);
|
||||
[self disconnectingWithError:nil];
|
||||
}
|
||||
|
||||
@@ -714,7 +729,7 @@ static NSString *PeripheralStateString(CBPeripheralState state) {
|
||||
|
||||
- (void)handleConnectionRequestPacket:(GNSWeaveConnectionRequestPacket *)packet
|
||||
context:(id)context {
|
||||
GTMLoggerError(@"Unexpected connection request packet received.");
|
||||
GNCLoggerError(@"Unexpected connection request packet received.");
|
||||
[self handleWeaveError:GNSErrorUnexpectedWeaveControlPacket socket:_socket];
|
||||
}
|
||||
|
||||
@@ -748,13 +763,13 @@ static NSString *PeripheralStateString(CBPeripheralState state) {
|
||||
}
|
||||
|
||||
- (void)handleErrorPacket:(GNSWeaveErrorPacket *)packet context:(id)context {
|
||||
GTMLoggerInfo(@"Error packet received.");
|
||||
GNCLoggerInfo(@"Error packet received.");
|
||||
[self handleWeaveError:GNSErrorWeaveErrorPacketReceived socket:_socket];
|
||||
}
|
||||
|
||||
- (void)handleDataPacket:(GNSWeaveDataPacket *)packet context:(id)context {
|
||||
if (packet.isFirstPacket && _socket.waitingForIncomingData) {
|
||||
GTMLoggerError(@"There is already a receive operation in progress");
|
||||
GNCLoggerError(@"There is already a receive operation in progress");
|
||||
[self handleWeaveError:GNSErrorWeaveDataTransferInProgress socket:_socket];
|
||||
return;
|
||||
}
|
||||
|
||||
+27
-27
@@ -14,9 +14,9 @@
|
||||
|
||||
#import "internal/platform/implementation/apple/Mediums/Ble/Sockets/Source/Peripheral/GNSPeripheralManager+Private.h"
|
||||
|
||||
#import "internal/platform/implementation/apple/Log/GNCLogger.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/Ble/Sockets/Source/Peripheral/GNSPeripheralServiceManager+Private.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/Ble/Sockets/Source/Shared/GNSSocket+Private.h"
|
||||
#import "GoogleToolboxForMac/GTMLogger.h"
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
#import <UIKit/UIKit.h>
|
||||
@@ -134,7 +134,7 @@ static NSTimeInterval gKBTCrashLoopMaxTimeBetweenResetting = 15.f;
|
||||
|
||||
- (void)start {
|
||||
if (_started) {
|
||||
GTMLoggerInfo(@"Peripheral manager already started.");
|
||||
GNCLoggerInfo(@"Peripheral manager already started.");
|
||||
return;
|
||||
}
|
||||
NSMutableDictionary<NSString *, id> *options =
|
||||
@@ -146,7 +146,7 @@ static NSTimeInterval gKBTCrashLoopMaxTimeBetweenResetting = 15.f;
|
||||
}
|
||||
#endif
|
||||
_cbPeripheralManager = [self cbPeripheralManagerWithDelegate:self queue:_queue options:options];
|
||||
GTMLoggerInfo(@"Peripheral manager started.");
|
||||
GNCLoggerInfo(@"Peripheral manager started.");
|
||||
_started = YES;
|
||||
// From Apple documentation |-[GNSPeripheralManager peripheralManagerDidUpdateState:]| will be
|
||||
// called no matter the current bluetooth state. Also, if the CBPeripheralManager is being
|
||||
@@ -158,10 +158,10 @@ static NSTimeInterval gKBTCrashLoopMaxTimeBetweenResetting = 15.f;
|
||||
|
||||
- (void)stop {
|
||||
if (!_started) {
|
||||
GTMLoggerInfo(@"Peripheral manager already stopped.");
|
||||
GNCLoggerInfo(@"Peripheral manager already stopped.");
|
||||
return;
|
||||
}
|
||||
GTMLoggerInfo(@"Peripheral manager stopped.");
|
||||
GNCLoggerInfo(@"Peripheral manager stopped.");
|
||||
_started = NO;
|
||||
[self removeAllBleServicesAndStopAdvertising];
|
||||
_cbPeripheralManager.delegate = nil;
|
||||
@@ -190,17 +190,17 @@ static NSTimeInterval gKBTCrashLoopMaxTimeBetweenResetting = 15.f;
|
||||
// http://b/28875581 Adding new service when Bluetooth is powered off may be the reason for
|
||||
// the Bluetooth Daemon crash loop. Avoid adding any BLE services here and wait for the next
|
||||
// state change of the |_cbPeripheralManager|.
|
||||
GTMLoggerError(@"Bluetooth Daemon crash loop detected crashing. Avoid adding BLE services.");
|
||||
GNCLoggerError(@"Bluetooth Daemon crash loop detected crashing. Avoid adding BLE services.");
|
||||
return;
|
||||
}
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
if (_backgroundTaskId == UIBackgroundTaskInvalid) {
|
||||
GTMLoggerInfo(@"Start background task to add BLE services and start advertising.");
|
||||
GNCLoggerInfo(@"Start background task to add BLE services and start advertising.");
|
||||
_backgroundTaskId = [[UIApplication sharedApplication]
|
||||
beginBackgroundTaskWithName:@"Add BLE services and start advertising"
|
||||
expirationHandler:^{
|
||||
GTMLoggerError(@"Application was suspended before add BLE services and start "
|
||||
GNCLoggerError(@"Application was suspended before add BLE services and start "
|
||||
@"advertising finished.");
|
||||
[[UIApplication sharedApplication] endBackgroundTask:_backgroundTaskId];
|
||||
_backgroundTaskId = UIBackgroundTaskInvalid;
|
||||
@@ -238,15 +238,15 @@ static NSTimeInterval gKBTCrashLoopMaxTimeBetweenResetting = 15.f;
|
||||
|
||||
CBManagerState cbState = _cbPeripheralManager.state;
|
||||
if ((cbState != CBManagerStatePoweredOn) && (cbState != CBManagerStatePoweredOff)) {
|
||||
GTMLoggerInfo(@"Do not start advertising on state %@", CBManagerStateString(cbState));
|
||||
GNCLoggerInfo(@"Do not start advertising on state %@", CBManagerStateString(cbState));
|
||||
return;
|
||||
}
|
||||
if (_advertisementInProgressData) {
|
||||
GTMLoggerInfo(@"Another start advertising operation is in progress.");
|
||||
GNCLoggerInfo(@"Another start advertising operation is in progress.");
|
||||
return;
|
||||
}
|
||||
if (!_cbPeripheralManager.isAdvertising) {
|
||||
GTMLoggerInfo(@"Reset the advertiment data as the peripheral is not advertising.");
|
||||
GNCLoggerInfo(@"Reset the advertiment data as the peripheral is not advertising.");
|
||||
_advertisementData = nil;
|
||||
}
|
||||
|
||||
@@ -263,7 +263,7 @@ static NSTimeInterval gKBTCrashLoopMaxTimeBetweenResetting = 15.f;
|
||||
}
|
||||
}
|
||||
if (!allServicesAdded) {
|
||||
GTMLoggerInfo(@"Do not start advertising as not all bluetooth services are added.");
|
||||
GNCLoggerInfo(@"Do not start advertising as not all bluetooth services are added.");
|
||||
return;
|
||||
}
|
||||
NSMutableDictionary<NSString *, id> *advertisementData = [NSMutableDictionary dictionary];
|
||||
@@ -272,7 +272,7 @@ static NSTimeInterval gKBTCrashLoopMaxTimeBetweenResetting = 15.f;
|
||||
advertisementData[CBAdvertisementDataLocalNameKey] = _advertisedName;
|
||||
}
|
||||
if ([advertisementData isEqual:_advertisementData]) {
|
||||
GTMLoggerInfo(
|
||||
GNCLoggerInfo(
|
||||
@"Finished adding BLE services and starting advertising (advertisement data = %@).",
|
||||
_advertisementData);
|
||||
#if TARGET_OS_IPHONE
|
||||
@@ -282,7 +282,7 @@ static NSTimeInterval gKBTCrashLoopMaxTimeBetweenResetting = 15.f;
|
||||
return;
|
||||
}
|
||||
|
||||
GTMLoggerInfo(@"Start advertising: %@", advertisementData);
|
||||
GNCLoggerInfo(@"Start advertising: %@", advertisementData);
|
||||
_advertisementInProgressData = [advertisementData copy];
|
||||
}
|
||||
|
||||
@@ -296,27 +296,27 @@ static NSTimeInterval gKBTCrashLoopMaxTimeBetweenResetting = 15.f;
|
||||
if (handler()) return;
|
||||
handlerQueue = [NSMutableArray array];
|
||||
_handlerQueuePerSocketIdentifier[socketIdentifier] = handlerQueue;
|
||||
GTMLoggerInfo(@"Queueing value for socket: %@", socketIdentifier);
|
||||
GNCLoggerInfo(@"Queueing value for socket: %@", socketIdentifier);
|
||||
}
|
||||
[handlerQueue addObject:[handler copy]];
|
||||
}
|
||||
|
||||
- (void)processUpdateValueBlocks {
|
||||
GTMLoggerInfo(@"About to send values for sockets: %@", _handlerQueuePerSocketIdentifier.allKeys);
|
||||
GNCLoggerInfo(@"About to send values for sockets: %@", _handlerQueuePerSocketIdentifier.allKeys);
|
||||
for (NSUUID *socketIdentifier in _handlerQueuePerSocketIdentifier.allKeys) {
|
||||
NSMutableArray<GNSUpdateValueHandler> *handlerQueue =
|
||||
_handlerQueuePerSocketIdentifier[socketIdentifier];
|
||||
GTMLoggerInfo(@"%lu queued values to send.", (unsigned long)handlerQueue.count);
|
||||
GNCLoggerInfo(@"%lu queued values to send.", (unsigned long)handlerQueue.count);
|
||||
while (handlerQueue.count > 0) {
|
||||
GNSUpdateValueHandler handler = handlerQueue[0];
|
||||
if (!handler()) {
|
||||
GTMLoggerInfo(@"Value failed to be send, still in the queue to try later.");
|
||||
GNCLoggerInfo(@"Value failed to be send, still in the queue to try later.");
|
||||
break;
|
||||
}
|
||||
GTMLoggerInfo(@"Value sent successfully.");
|
||||
GNCLoggerInfo(@"Value sent successfully.");
|
||||
[handlerQueue removeObjectAtIndex:0];
|
||||
if (handlerQueue.count == 0) {
|
||||
GTMLoggerInfo(@"Removing pending value queue for socket: %@", socketIdentifier);
|
||||
GNCLoggerInfo(@"Removing pending value queue for socket: %@", socketIdentifier);
|
||||
[_handlerQueuePerSocketIdentifier removeObjectForKey:socketIdentifier];
|
||||
}
|
||||
}
|
||||
@@ -376,7 +376,7 @@ static NSTimeInterval gKBTCrashLoopMaxTimeBetweenResetting = 15.f;
|
||||
willRestoreState:(NSDictionary<NSString *, id> *)dict {
|
||||
#if TARGET_OS_IPHONE
|
||||
// Restored API only supported on iOS.
|
||||
GTMLoggerInfo(@"Restore bluetooth services");
|
||||
GNCLoggerInfo(@"Restore bluetooth services");
|
||||
_advertisementData = dict[CBPeripheralManagerRestoredStateAdvertisementDataKey];
|
||||
for (CBMutableService *service in dict[CBPeripheralManagerRestoredStateServicesKey]) {
|
||||
GNSPeripheralServiceManager *serviceManager =
|
||||
@@ -384,7 +384,7 @@ static NSTimeInterval gKBTCrashLoopMaxTimeBetweenResetting = 15.f;
|
||||
if (serviceManager) {
|
||||
[serviceManager restoredCBService:service];
|
||||
} else {
|
||||
GTMLoggerError(@"restoreFromCBService %@", service);
|
||||
GNCLoggerError(@"restoreFromCBService %@", service);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -392,7 +392,7 @@ static NSTimeInterval gKBTCrashLoopMaxTimeBetweenResetting = 15.f;
|
||||
|
||||
- (void)peripheralManagerDidUpdateState:(CBPeripheralManager *)peripheralManager {
|
||||
NSAssert(peripheralManager == _cbPeripheralManager, @"Wrong peripheral manager.");
|
||||
GTMLoggerInfo(@"Peripheral manager state updated: %@",
|
||||
GNCLoggerInfo(@"Peripheral manager state updated: %@",
|
||||
CBManagerStateString(_cbPeripheralManager.state));
|
||||
switch (_cbPeripheralManager.state) {
|
||||
case CBManagerStatePoweredOn:
|
||||
@@ -439,7 +439,7 @@ static NSTimeInterval gKBTCrashLoopMaxTimeBetweenResetting = 15.f;
|
||||
_advertisementData = _advertisementInProgressData;
|
||||
_advertisementInProgressData = nil;
|
||||
if (error) {
|
||||
GTMLoggerError(@"Start advertisment failed with error %@. Will retry to start advertising on "
|
||||
GNCLoggerError(@"Start advertisment failed with error %@. Will retry to start advertising on "
|
||||
"the next BLE state change notification. ",
|
||||
error);
|
||||
_advertisementData = nil;
|
||||
@@ -447,7 +447,7 @@ static NSTimeInterval gKBTCrashLoopMaxTimeBetweenResetting = 15.f;
|
||||
}
|
||||
|
||||
NSAssert(peripheral.isAdvertising, @"Peripheral should be advertising.");
|
||||
GTMLoggerInfo(@"Peripheral did start advertising %@", _advertisementData);
|
||||
GNCLoggerInfo(@"Peripheral did start advertising %@", _advertisementData);
|
||||
|
||||
// Once an advertisment operation is over, check if the advertised data is up-to-date.
|
||||
[self updateAdvertisedServices];
|
||||
@@ -459,7 +459,7 @@ static NSTimeInterval gKBTCrashLoopMaxTimeBetweenResetting = 15.f;
|
||||
GNSPeripheralServiceManager *peripheralServiceManager =
|
||||
[_peripheralServiceManagers objectForKey:service.UUID];
|
||||
if (!peripheralServiceManager) {
|
||||
GTMLoggerError(@"Unknown service %@ with %@", service, self);
|
||||
GNCLoggerError(@"Unknown service %@ with %@", service, self);
|
||||
return;
|
||||
}
|
||||
[peripheralServiceManager didAddCBServiceWithError:error];
|
||||
@@ -532,7 +532,7 @@ static NSTimeInterval gKBTCrashLoopMaxTimeBetweenResetting = 15.f;
|
||||
}
|
||||
|
||||
- (void)peripheralManagerIsReadyToUpdateSubscribers:(CBPeripheralManager *)peripheral {
|
||||
GTMLoggerInfo(@"Ready to update subscribers.");
|
||||
GNCLoggerInfo(@"Ready to update subscribers.");
|
||||
[self processUpdateValueBlocks];
|
||||
}
|
||||
|
||||
|
||||
+65
-53
@@ -14,11 +14,11 @@
|
||||
|
||||
#import "internal/platform/implementation/apple/Mediums/Ble/Sockets/Source/Peripheral/GNSPeripheralServiceManager+Private.h"
|
||||
|
||||
#import "internal/platform/implementation/apple/Log/GNCLogger.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/Ble/Sockets/Source/Peripheral/GNSPeripheralManager+Private.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/Ble/Sockets/Source/Shared/GNSSocket+Private.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/Ble/Sockets/Source/Shared/GNSUtils.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/Ble/Sockets/Source/Shared/GNSWeavePacket.h"
|
||||
#import "GoogleToolboxForMac/GTMLogger.h"
|
||||
|
||||
// The Weave BLE protocol has only one valid version.
|
||||
static const UInt16 kWeaveVersionSupported = 1;
|
||||
@@ -36,7 +36,7 @@ static NSString *GetBluetoothServiceStateDescription(GNSBluetoothServiceState st
|
||||
return @"";
|
||||
}
|
||||
|
||||
@interface GNSPeripheralServiceManager ()<GNSWeavePacketHandler> {
|
||||
@interface GNSPeripheralServiceManager () <GNSWeavePacketHandler> {
|
||||
GNSPeripheralManager *_peripheralManager;
|
||||
BOOL _addPairingCharacteristic;
|
||||
CBMutableService *_cbService;
|
||||
@@ -145,22 +145,22 @@ static CBMutableCharacteristic *CreatePairingCharacteristic() {
|
||||
} else {
|
||||
_cbService.characteristics = @[ _weaveIncomingChar, _weaveOutgoingChar ];
|
||||
}
|
||||
GTMLoggerInfo(@"Will add BLE service: %@", _cbService);
|
||||
GNCLoggerInfo(@"Will add BLE service: %@", _cbService);
|
||||
}
|
||||
|
||||
- (void)didAddCBServiceWithError:(NSError *)error {
|
||||
if (_cbServiceState == GNSBluetoothServiceStateNotAdded) {
|
||||
// Ignored as the service was probably removed while the add CBService operation was in
|
||||
// progress.
|
||||
GTMLoggerError(@"Ignore adding BLE service %@ result (error = %@) %@", _cbService, error, self);
|
||||
GNCLoggerError(@"Ignore adding BLE service %@ result (error = %@) %@", _cbService, error, self);
|
||||
return;
|
||||
}
|
||||
|
||||
if (error) {
|
||||
GTMLoggerError(@"Failed adding BLE service %@ (error = %@) %@", _cbService, error, self);
|
||||
GNCLoggerError(@"Failed adding BLE service %@ (error = %@) %@", _cbService, error, self);
|
||||
[self didRemoveCBService];
|
||||
} else {
|
||||
GTMLoggerInfo(@"Finished adding BLE service %@", _cbService);
|
||||
GNCLoggerInfo(@"Finished adding BLE service %@", _cbService);
|
||||
_cbServiceState = GNSBluetoothServiceStateAdded;
|
||||
}
|
||||
if (_bleServiceAddedCompletion) {
|
||||
@@ -178,7 +178,7 @@ static CBMutableCharacteristic *CreatePairingCharacteristic() {
|
||||
|
||||
- (void)restoredCBService:(CBMutableService *)service {
|
||||
if (![service.UUID isEqual:_serviceUUID]) {
|
||||
GTMLoggerError(@"Cannot restore from bluetooth service %@.", service);
|
||||
GNCLoggerError(@"Cannot restore from bluetooth service %@.", service);
|
||||
return;
|
||||
}
|
||||
for (CBMutableCharacteristic *characteristic in service.characteristics) {
|
||||
@@ -200,7 +200,7 @@ static CBMutableCharacteristic *CreatePairingCharacteristic() {
|
||||
NSAssert(_pairingChar || !_addPairingCharacteristic, @"Pairing characteristic missing");
|
||||
_cbService = service;
|
||||
_cbServiceState = GNSBluetoothServiceStateAdded;
|
||||
GTMLoggerInfo(@"Service restored: %@", _cbService);
|
||||
GNCLoggerInfo(@"Service restored: %@", _cbService);
|
||||
}
|
||||
|
||||
- (void)setAdvertising:(BOOL)advertising {
|
||||
@@ -284,12 +284,14 @@ static CBMutableCharacteristic *CreatePairingCharacteristic() {
|
||||
}
|
||||
// Only send the error if no error packet was previously received.
|
||||
if (errorCode != GNSErrorWeaveErrorPacketReceived) {
|
||||
GTMLoggerInfo(@"Sending error packet for socket: %@", socket);
|
||||
GNCLoggerInfo(@"Sending error packet for socket: %@", socket);
|
||||
GNSWeaveErrorPacket *errorPacket =
|
||||
[[GNSWeaveErrorPacket alloc] initWithPacketCounter:socket.sendPacketCounter];
|
||||
[self sendPacket:errorPacket toSocket:socket completion:^{
|
||||
GTMLoggerInfo(@"Error packet sent to socket: %@", socket);
|
||||
}];
|
||||
[self sendPacket:errorPacket
|
||||
toSocket:socket
|
||||
completion:^{
|
||||
GNCLoggerInfo(@"Error packet sent to socket: %@", socket);
|
||||
}];
|
||||
}
|
||||
NSError *error = GNSErrorWithCode(errorCode);
|
||||
[self removeSocket:socket withError:error];
|
||||
@@ -297,7 +299,7 @@ static CBMutableCharacteristic *CreatePairingCharacteristic() {
|
||||
|
||||
- (void)processWeaveWriteRequest:(CBATTRequest *)request {
|
||||
if (![request.characteristic.UUID isEqual:_weaveIncomingChar.UUID]) {
|
||||
GTMLoggerError(@"Cannot process %@ on characteristic %@ (%@)", request,
|
||||
GNCLoggerError(@"Cannot process %@ on characteristic %@ (%@)", request,
|
||||
request.characteristic.UUID,
|
||||
GNSCharacteristicName(request.characteristic.UUID.UUIDString));
|
||||
return;
|
||||
@@ -308,25 +310,26 @@ static CBMutableCharacteristic *CreatePairingCharacteristic() {
|
||||
NSUInteger truncatedSize =
|
||||
MIN(socket ? socket.packetSize : kGNSMinSupportedPacketSize, request.value.length);
|
||||
if (truncatedSize != request.value.length) {
|
||||
GTMLoggerInfo(@"Packet with %ld bytes truncated to %ld.", (long)request.value.length,
|
||||
GNCLoggerInfo(@"Packet with %ld bytes truncated to %ld.", (long)request.value.length,
|
||||
(long)truncatedSize);
|
||||
}
|
||||
NSData *packetData = [request.value subdataWithRange:NSMakeRange(0, truncatedSize)];
|
||||
NSError *parsingError = nil;
|
||||
GNSWeavePacket *packet = [GNSWeavePacket parseData:packetData error:&parsingError];
|
||||
if (!packet) {
|
||||
GTMLoggerError(@"Error parsing weave packet (error = %@).", parsingError);
|
||||
GNCLoggerError(@"Error parsing weave packet (error = %@).", parsingError);
|
||||
[self handleWeaveError:GNSErrorParsingWeavePacket socket:socket];
|
||||
return;
|
||||
}
|
||||
if (!socket && ![packet isKindOfClass:[GNSWeaveConnectionRequestPacket class]]) {
|
||||
GTMLoggerInfo(@"Non-request weave packet received when no socket exists -- ignoring");
|
||||
GNCLoggerInfo(@"Non-request weave packet received when no socket exists -- ignoring");
|
||||
return;
|
||||
}
|
||||
UInt8 expectedCounter = [packet isKindOfClass:[GNSWeaveConnectionRequestPacket class]] ?
|
||||
0 : socket.receivePacketCounter;
|
||||
UInt8 expectedCounter = [packet isKindOfClass:[GNSWeaveConnectionRequestPacket class]]
|
||||
? 0
|
||||
: socket.receivePacketCounter;
|
||||
if (packet.packetCounter != expectedCounter) {
|
||||
GTMLoggerError(@"Wrong packet counter, [received %d, expected %d].", packet.packetCounter,
|
||||
GNCLoggerError(@"Wrong packet counter, [received %d, expected %d].", packet.packetCounter,
|
||||
expectedCounter);
|
||||
[self handleWeaveError:GNSErrorWrongWeavePacketCounter socket:socket];
|
||||
return;
|
||||
@@ -344,12 +347,12 @@ static CBMutableCharacteristic *CreatePairingCharacteristic() {
|
||||
|
||||
- (void)processWriteRequest:(CBATTRequest *)request {
|
||||
if (![request.characteristic.UUID isEqual:_weaveIncomingChar.UUID]) {
|
||||
GTMLoggerError(@"Cannot process %@ on characteristic %@ (%@)", request,
|
||||
GNCLoggerError(@"Cannot process %@ on characteristic %@ (%@)", request,
|
||||
request.characteristic.UUID,
|
||||
GNSCharacteristicName(request.characteristic.UUID.UUIDString));
|
||||
return;
|
||||
}
|
||||
GTMLoggerInfo(@"Write request on Weave characteristic.");
|
||||
GNCLoggerInfo(@"Write request on Weave characteristic.");
|
||||
[self processWeaveWriteRequest:request];
|
||||
}
|
||||
|
||||
@@ -368,9 +371,9 @@ static CBMutableCharacteristic *CreatePairingCharacteristic() {
|
||||
}
|
||||
|
||||
- (void)sendData:(NSData *)data
|
||||
toSocket:(GNSSocket *)socket
|
||||
checkConnected:(BOOL)checkConnected
|
||||
completion:(void (^)(void))completion {
|
||||
toSocket:(GNSSocket *)socket
|
||||
checkConnected:(BOOL)checkConnected
|
||||
completion:(void (^)(void))completion {
|
||||
__weak __typeof__(self) weakSelf = self;
|
||||
[_peripheralManager
|
||||
updateOutgoingCharOnSocket:socket
|
||||
@@ -382,11 +385,13 @@ static CBMutableCharacteristic *CreatePairingCharacteristic() {
|
||||
}
|
||||
if (![strongSelf.peripheralManager updateOutgoingCharacteristic:data
|
||||
onSocket:socket]) {
|
||||
GTMLoggerInfo(@"Failed to update characteristic value; reschedule");
|
||||
GNCLoggerInfo(@"Failed to update characteristic value; reschedule");
|
||||
return NO;
|
||||
}
|
||||
if (completion) {
|
||||
dispatch_async(_queue, ^{ completion(); });
|
||||
dispatch_async(_queue, ^{
|
||||
completion();
|
||||
});
|
||||
}
|
||||
return YES;
|
||||
}];
|
||||
@@ -398,9 +403,9 @@ static CBMutableCharacteristic *CreatePairingCharacteristic() {
|
||||
|
||||
- (void)removeSocket:(GNSSocket *)socket withError:(NSError *)error {
|
||||
if (error) {
|
||||
GTMLoggerInfo(@"Socket disconnected with error, socket: %@, error: %@", socket, error);
|
||||
GNCLoggerInfo(@"Socket disconnected with error, socket: %@, error: %@", socket, error);
|
||||
} else {
|
||||
GTMLoggerInfo(@"Socket disconnected %@", socket);
|
||||
GNCLoggerInfo(@"Socket disconnected %@", socket);
|
||||
}
|
||||
[_sockets removeObjectForKey:socket.peerIdentifier];
|
||||
[socket didDisconnectWithError:error];
|
||||
@@ -424,7 +429,7 @@ static CBMutableCharacteristic *CreatePairingCharacteristic() {
|
||||
if (socket && [characteristic.UUID isEqual:_weaveOutgoingChar.UUID]) {
|
||||
// Disconnect signal is optional. If the central unsubscribe to _outgoingChar, the socket
|
||||
// is disconnected.
|
||||
GTMLoggerInfo(@"%@ unsubscribe to outgoing characteristic", central);
|
||||
GNCLoggerInfo(@"%@ unsubscribe to outgoing characteristic", central);
|
||||
[self removeSocket:socket withError:nil];
|
||||
}
|
||||
}
|
||||
@@ -436,17 +441,22 @@ static CBMutableCharacteristic *CreatePairingCharacteristic() {
|
||||
}
|
||||
|
||||
- (void)sendData:(NSData *)data socket:(GNSSocket *)socket completion:(GNSErrorHandler)completion {
|
||||
GTMLoggerInfo(@"Updating value in characteristic");
|
||||
[_peripheralManager updateOutgoingCharOnSocket:socket withHandler:^{
|
||||
BOOL wasSent = [_peripheralManager updateOutgoingCharacteristic:data onSocket:socket];
|
||||
if (wasSent) {
|
||||
GTMLoggerInfo(@"Successfully updated value in characteristic");
|
||||
dispatch_async(_queue, ^{ completion(nil); });
|
||||
} else {
|
||||
GTMLoggerInfo(@"Failed to update characteristic value; reschedule");
|
||||
}
|
||||
return wasSent;
|
||||
}];
|
||||
GNCLoggerInfo(@"Updating value in characteristic");
|
||||
[_peripheralManager
|
||||
updateOutgoingCharOnSocket:socket
|
||||
withHandler:^{
|
||||
BOOL wasSent = [_peripheralManager updateOutgoingCharacteristic:data
|
||||
onSocket:socket];
|
||||
if (wasSent) {
|
||||
GNCLoggerInfo(@"Successfully updated value in characteristic");
|
||||
dispatch_async(_queue, ^{
|
||||
completion(nil);
|
||||
});
|
||||
} else {
|
||||
GNCLoggerInfo(@"Failed to update characteristic value; reschedule");
|
||||
}
|
||||
return wasSent;
|
||||
}];
|
||||
}
|
||||
|
||||
- (NSUUID *)socketServiceIdentifier:(GNSSocket *)socket {
|
||||
@@ -466,7 +476,7 @@ static CBMutableCharacteristic *CreatePairingCharacteristic() {
|
||||
toSocket:socket
|
||||
completion:^{
|
||||
if (weakSelf) {
|
||||
GTMLoggerInfo(@"Error packet sent (to force the central to disconnect).");
|
||||
GNCLoggerInfo(@"Error packet sent (to force the central to disconnect).");
|
||||
[weakSelf removeSocket:socket withError:nil];
|
||||
}
|
||||
}];
|
||||
@@ -482,7 +492,7 @@ static CBMutableCharacteristic *CreatePairingCharacteristic() {
|
||||
NSAssert([request isKindOfClass:[CBATTRequest class]], @"The context should be a request.");
|
||||
GNSSocket *socket = _sockets[((CBATTRequest *)request).central.identifier];
|
||||
if (socket) {
|
||||
GTMLoggerInfo(@"Receiving a connection request from an already connected socket %@.", socket);
|
||||
GNCLoggerInfo(@"Receiving a connection request from an already connected socket %@.", socket);
|
||||
// The peripheral considers the previous socket as being disconnected.
|
||||
NSError *error = GNSErrorWithCode(GNSErrorNewInviteToConnectReceived);
|
||||
[self removeSocket:socket withError:error];
|
||||
@@ -492,7 +502,7 @@ static CBMutableCharacteristic *CreatePairingCharacteristic() {
|
||||
centralPeer:((CBATTRequest *)request).central
|
||||
queue:_queue];
|
||||
if (packet.maxVersion < kWeaveVersionSupported || packet.minVersion > kWeaveVersionSupported) {
|
||||
GTMLoggerError(@"Unsupported Weave version range: [%d, %d].", packet.minVersion,
|
||||
GNCLoggerError(@"Unsupported Weave version range: [%d, %d].", packet.minVersion,
|
||||
packet.maxVersion);
|
||||
[self handleWeaveError:GNSErrorUnsupportedWeaveProtocolVersion socket:socket];
|
||||
return;
|
||||
@@ -506,18 +516,20 @@ static CBMutableCharacteristic *CreatePairingCharacteristic() {
|
||||
_sockets[socket.peerIdentifier] = socket;
|
||||
|
||||
dispatch_async(_queue, ^{
|
||||
GTMLoggerInfo(@"Sending connection confirm packet.");
|
||||
GNCLoggerInfo(@"Sending connection confirm packet.");
|
||||
GNSWeaveConnectionConfirmPacket *confirm =
|
||||
[[GNSWeaveConnectionConfirmPacket alloc] initWithVersion:kWeaveVersionSupported
|
||||
packetSize:socket.packetSize
|
||||
data:nil];
|
||||
__weak __typeof__(self) weakSelf = self;
|
||||
[self sendPacket:confirm toSocket:socket completion:^{
|
||||
if (weakSelf) {
|
||||
GTMLoggerInfo(@"Connection confirm packet sent.");
|
||||
[weakSelf socketReady:socket];
|
||||
}
|
||||
}];
|
||||
[self sendPacket:confirm
|
||||
toSocket:socket
|
||||
completion:^{
|
||||
if (weakSelf) {
|
||||
GNCLoggerInfo(@"Connection confirm packet sent.");
|
||||
[weakSelf socketReady:socket];
|
||||
}
|
||||
}];
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -526,14 +538,14 @@ static CBMutableCharacteristic *CreatePairingCharacteristic() {
|
||||
context:(id)request {
|
||||
NSAssert([request isKindOfClass:[CBATTRequest class]], @"The context should be a request.");
|
||||
GNSSocket *socket = _sockets[((CBATTRequest *)request).central.identifier];
|
||||
GTMLoggerError(@"Unexpected connection confirm packet received.");
|
||||
GNCLoggerError(@"Unexpected connection confirm packet received.");
|
||||
[self handleWeaveError:GNSErrorUnexpectedWeaveControlPacket socket:socket];
|
||||
}
|
||||
|
||||
- (void)handleErrorPacket:(GNSWeaveErrorPacket *)packet context:(id)request {
|
||||
NSAssert([request isKindOfClass:[CBATTRequest class]], @"The context should be a request.");
|
||||
GNSSocket *socket = _sockets[((CBATTRequest *)request).central.identifier];
|
||||
GTMLoggerInfo(@"Error packet received.");
|
||||
GNCLoggerInfo(@"Error packet received.");
|
||||
[self handleWeaveError:GNSErrorWeaveErrorPacketReceived socket:socket];
|
||||
}
|
||||
|
||||
@@ -541,7 +553,7 @@ static CBMutableCharacteristic *CreatePairingCharacteristic() {
|
||||
NSAssert([request isKindOfClass:[CBATTRequest class]], @"The context should be a request.");
|
||||
GNSSocket *socket = _sockets[((CBATTRequest *)request).central.identifier];
|
||||
if (packet.isFirstPacket && socket.waitingForIncomingData) {
|
||||
GTMLoggerError(@"There is already a receive operation in progress");
|
||||
GNCLoggerError(@"There is already a receive operation in progress");
|
||||
[self handleWeaveError:GNSErrorWeaveDataTransferInProgress socket:socket];
|
||||
return;
|
||||
}
|
||||
|
||||
+4
-4
@@ -69,16 +69,16 @@ typedef void (^GNSProgressHandler)(float progress);
|
||||
*
|
||||
* * To receive data:
|
||||
* - (void)socket:(GNSSocket *)socket didReceiveData:(NSData *)data {
|
||||
* GTMLoggerInfo(@"Data received from central %@", data);
|
||||
* GNCLoggerInfo(@"Data received from central %@", data);
|
||||
* ...
|
||||
* }
|
||||
*
|
||||
* * To send data:
|
||||
* GNSErrorHandler completionHandler = ^(NSError *error) {
|
||||
* if (error) {
|
||||
* GTMLoggerInfo(@"Failed to send data")
|
||||
* GNCLoggerInfo(@"Failed to send data")
|
||||
* } else {
|
||||
* GTMLoggerInfo(@"data has been sent");
|
||||
* GNCLoggerInfo(@"data has been sent");
|
||||
* }
|
||||
* }
|
||||
* [socket sendData:dataToSend
|
||||
@@ -89,7 +89,7 @@ typedef void (^GNSProgressHandler)(float progress);
|
||||
*
|
||||
* * Once the socket is disconnected (by -[GNSSocket disconnect] or by the peer):
|
||||
* - (void)socket:(GNSSocket *)socket didDisconnectWithError:(NSError *)error {
|
||||
* GTMLoggerInfo(@"Socket disconnected, by peer");
|
||||
* GNCLoggerInfo(@"Socket disconnected, by peer");
|
||||
* ...
|
||||
* }
|
||||
*/
|
||||
|
||||
+35
-28
@@ -14,8 +14,8 @@
|
||||
|
||||
#import "internal/platform/implementation/apple/Mediums/Ble/Sockets/Source/Shared/GNSSocket+Private.h"
|
||||
|
||||
#import "internal/platform/implementation/apple/Log/GNCLogger.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/Ble/Sockets/Source/Shared/GNSWeavePacket.h"
|
||||
#import "GoogleToolboxForMac/GTMLogger.h"
|
||||
|
||||
typedef void (^GNSIncomingChunkReceivedBlock)(NSData *incomingData);
|
||||
|
||||
@@ -55,17 +55,20 @@ typedef void (^GNSIncomingChunkReceivedBlock)(NSData *incomingData);
|
||||
progressHandler:(GNSProgressHandler)progressHandler
|
||||
completion:(GNSErrorHandler)completion {
|
||||
void (^callCompletion)(NSError *) = ^(NSError *error) {
|
||||
if (completion) dispatch_async(_queue, ^{ completion(error); });
|
||||
if (completion)
|
||||
dispatch_async(_queue, ^{
|
||||
completion(error);
|
||||
});
|
||||
};
|
||||
|
||||
if (self.sendChunkCallback) {
|
||||
GTMLoggerInfo(@"Send operation already in progress");
|
||||
GNCLoggerInfo(@"Send operation already in progress");
|
||||
callCompletion(GNSErrorWithCode(GNSErrorOperationInProgress));
|
||||
return;
|
||||
}
|
||||
data = [data copy];
|
||||
NSUInteger totalDataSize = data.length;
|
||||
GTMLoggerInfo(@"Sending data with size %lu", (unsigned long)totalDataSize);
|
||||
GNCLoggerInfo(@"Sending data with size %lu", (unsigned long)totalDataSize);
|
||||
|
||||
// Capture self for the duration of the send operation, to ensure it is completely sent.
|
||||
// If the connection is lost, the block will be deleted and the retain cycle broken.
|
||||
@@ -92,34 +95,38 @@ typedef void (^GNSIncomingChunkReceivedBlock)(NSData *incomingData);
|
||||
offset:&newOffset];
|
||||
[self incrementSendPacketCounter];
|
||||
|
||||
GTMLoggerInfo(@"Sending chunk with size %ld", (long)(newOffset - offset));
|
||||
[self.owner sendData:[dataPacket serialize] socket:self completion:^(NSError *_Nullable error) {
|
||||
if (error) {
|
||||
GTMLoggerInfo(@"Error sending chunk");
|
||||
self.sendChunkCallback = nil;
|
||||
callCompletion(error);
|
||||
} else {
|
||||
if (newOffset < totalDataSize) {
|
||||
// Dispatch async to avoid stack overflow on large payloads.
|
||||
dispatch_async(self.queue, ^{ self.sendChunkCallback(newOffset); });
|
||||
} else {
|
||||
GTMLoggerInfo(@"Finished sending payload");
|
||||
self.sendChunkCallback = nil;
|
||||
callCompletion(nil);
|
||||
}
|
||||
}
|
||||
}];
|
||||
GNCLoggerInfo(@"Sending chunk with size %ld", (long)(newOffset - offset));
|
||||
[self.owner sendData:[dataPacket serialize]
|
||||
socket:self
|
||||
completion:^(NSError *_Nullable error) {
|
||||
if (error) {
|
||||
GNCLoggerInfo(@"Error sending chunk");
|
||||
self.sendChunkCallback = nil;
|
||||
callCompletion(error);
|
||||
} else {
|
||||
if (newOffset < totalDataSize) {
|
||||
// Dispatch async to avoid stack overflow on large payloads.
|
||||
dispatch_async(self.queue, ^{
|
||||
self.sendChunkCallback(newOffset);
|
||||
});
|
||||
} else {
|
||||
GNCLoggerInfo(@"Finished sending payload");
|
||||
self.sendChunkCallback = nil;
|
||||
callCompletion(nil);
|
||||
}
|
||||
}
|
||||
}];
|
||||
};
|
||||
self.sendChunkCallback(0);
|
||||
}
|
||||
|
||||
- (void)disconnect {
|
||||
if (!_connected) {
|
||||
GTMLoggerInfo(@"Socket already disconnected, socket: %@, delegate %@, owner %@", self,
|
||||
GNCLoggerInfo(@"Socket already disconnected, socket: %@, delegate %@, owner %@", self,
|
||||
_delegate, _owner);
|
||||
return;
|
||||
}
|
||||
GTMLoggerInfo(@"Disconnect");
|
||||
GNCLoggerInfo(@"Disconnect");
|
||||
[_owner disconnectSocket:self];
|
||||
}
|
||||
|
||||
@@ -174,12 +181,12 @@ typedef void (^GNSIncomingChunkReceivedBlock)(NSData *incomingData);
|
||||
|
||||
- (void)incrementReceivePacketCounter {
|
||||
_receivePacketCounter = (_receivePacketCounter + 1) % kGNSMaxPacketCounterValue;
|
||||
GTMLoggerDebug(@"New receive packet counter %d", _receivePacketCounter);
|
||||
GNCLoggerDebug(@"New receive packet counter %d", _receivePacketCounter);
|
||||
}
|
||||
|
||||
- (void)incrementSendPacketCounter {
|
||||
_sendPacketCounter = (_sendPacketCounter + 1) % kGNSMaxPacketCounterValue;
|
||||
GTMLoggerDebug(@"New send packet counter %d", _sendPacketCounter);
|
||||
GNCLoggerDebug(@"New send packet counter %d", _sendPacketCounter);
|
||||
}
|
||||
|
||||
- (void)didConnect {
|
||||
@@ -196,19 +203,19 @@ typedef void (^GNSIncomingChunkReceivedBlock)(NSData *incomingData);
|
||||
|
||||
- (void)didReceiveIncomingWeaveDataPacket:(GNSWeaveDataPacket *)dataPacket {
|
||||
if (!_connected) {
|
||||
GTMLoggerError(@"Cannot receive incoming data packet while not being connected");
|
||||
GNCLoggerError(@"Cannot receive incoming data packet while not being connected");
|
||||
return;
|
||||
}
|
||||
if (dataPacket.isFirstPacket) {
|
||||
NSAssert(!_incomingBuffer, @"There should not be a receive operation in progress.");
|
||||
_incomingBuffer = [NSMutableData data];
|
||||
}
|
||||
GTMLoggerInfo(@"Received chunk with size %lu", (unsigned long)dataPacket.data.length);
|
||||
GNCLoggerInfo(@"Received chunk with size %lu", (unsigned long)dataPacket.data.length);
|
||||
[_incomingBuffer appendData:dataPacket.data];
|
||||
if (dataPacket.isLastPacket) {
|
||||
NSData *incomingData = _incomingBuffer;
|
||||
_incomingBuffer = nil;
|
||||
GTMLoggerInfo(@"Finished receiving payload with size %lu", (unsigned long)incomingData.length);
|
||||
GNCLoggerInfo(@"Finished receiving payload with size %lu", (unsigned long)incomingData.length);
|
||||
[self.delegate socket:self didReceiveData:incomingData];
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -47,21 +47,21 @@ typedef NS_ENUM(UInt8, GNSWeaveControlCommand) {
|
||||
* - (void)didReceivedData:(NSData *)data {
|
||||
* GNSWeavePacket *packet = [GNSWeavePacket parseData:data error:nil];
|
||||
* if ([packet visitWithHandler:self context:nil]) {
|
||||
* GTMLoggerInfo(@"This class can handle this packet.");
|
||||
* GNCLoggerInfo(@"This class can handle this packet.");
|
||||
* } else {
|
||||
* GTMLoggerInfo(@"Unexpected packet received.");
|
||||
* GNCLoggerInfo(@"Unexpected packet received.");
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* - (void)handleConnectionRequestPacket:(GNSWeaveConnectionRequestPacket *)packet
|
||||
* context:(nullable id)context {
|
||||
* GTMLoggerInfo(@"Connection request packet received.");
|
||||
* GNCLoggerInfo(@"Connection request packet received.");
|
||||
* ...
|
||||
* }
|
||||
* @end
|
||||
*
|
||||
**/
|
||||
@protocol GNSWeavePacketHandler<NSObject>
|
||||
@protocol GNSWeavePacketHandler <NSObject>
|
||||
@optional
|
||||
|
||||
- (void)handleConnectionRequestPacket:(GNSWeaveConnectionRequestPacket *)packet
|
||||
|
||||
+2
-2
@@ -14,12 +14,12 @@
|
||||
|
||||
#import <XCTest/XCTest.h>
|
||||
|
||||
#import "internal/platform/implementation/apple/Log/GNCLogger.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/ble/Sockets/Source/Peripheral/GNSPeripheralManager+Private.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/ble/Sockets/Source/Peripheral/GNSPeripheralServiceManager+Private.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/ble/Sockets/Source/Shared/GNSSocket+Private.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/ble/Sockets/Source/Shared/GNSUtils.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/ble/Sockets/Source/Shared/GNSWeavePacket.h"
|
||||
#import "GoogleToolboxForMac/GTMLogger.h"
|
||||
#import "third_party/objective_c/ocmock/v3/Source/OCMock/OCMock.h"
|
||||
|
||||
@interface GNSPeripheralServiceManagerTest : XCTestCase {
|
||||
@@ -518,7 +518,7 @@
|
||||
XCTAssertNotNil(packet);
|
||||
XCTAssertTrue([packet isKindOfClass:[GNSWeaveDataPacket class]]);
|
||||
GNSWeaveDataPacket *dataPacket = (GNSWeaveDataPacket *)packet;
|
||||
GTMLoggerInfo(@"packetCounter = %d", dataPacket.packetCounter);
|
||||
GNCLoggerInfo(@"packetCounter = %d", dataPacket.packetCounter);
|
||||
XCTAssertEqual(dataPacket.packetCounter, sendPacketCounter);
|
||||
sendPacketCounter = (sendPacketCounter + 1) % kGNSMaxPacketCounterValue;
|
||||
if (i == 0) {
|
||||
|
||||
@@ -13,13 +13,13 @@
|
||||
// limitations under the License.
|
||||
|
||||
#import "internal/platform/implementation/apple/Mediums/GNCLeaks.h"
|
||||
#import "GoogleToolboxForMac/GTMLogger.h"
|
||||
#import "internal/platform/implementation/apple/Log/GNCLogger.h"
|
||||
|
||||
void GNCVerifyDealloc(id object, NSTimeInterval timeInterval) {
|
||||
#if DEBUG
|
||||
__weak id weakObj = object;
|
||||
NSCAssert(weakObj != nil, @"Pointer to %@ is already nil", weakObj);
|
||||
GTMLoggerInfo(@"Verifying deallocation of %@", NSStringFromClass([weakObj class]));
|
||||
GNCLoggerInfo(@"Verifying deallocation of %@", NSStringFromClass([weakObj class]));
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(timeInterval * NSEC_PER_SEC)),
|
||||
dispatch_get_main_queue(), ^{
|
||||
NSCAssert(weakObj == nil, @"%@ not deallocated.", weakObj);
|
||||
|
||||
@@ -22,10 +22,10 @@
|
||||
#endif // TARGET_OS_IOS
|
||||
#import <SystemConfiguration/CaptiveNetwork.h>
|
||||
|
||||
#import "internal/platform/implementation/apple/Log/GNCLogger.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/Hotspot/GNCHotspotSocket.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/WiFiCommon/GNCIPv4Address.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/WiFiCommon/GNCNWFrameworkError.h"
|
||||
#import "GoogleToolboxForMac/GTMLogger.h"
|
||||
|
||||
#if TARGET_OS_IOS
|
||||
// The maximum number of retries for connecting to the Hotspot.
|
||||
@@ -59,36 +59,36 @@ static const UInt8 kConnectionToHostTimeoutInSeconds = 10;
|
||||
if (error) {
|
||||
if ([error.domain isEqualToString:NEHotspotConfigurationErrorDomain] &&
|
||||
error.code == NEHotspotConfigurationErrorAlreadyAssociated) {
|
||||
GTMLoggerInfo(@"Already connected to %@", ssid);
|
||||
GNCLoggerInfo(@"Already connected to %@", ssid);
|
||||
connected = YES;
|
||||
} else {
|
||||
GTMLoggerError(@"Failed to connect: %@ (%@)", ssid, error.localizedDescription);
|
||||
GNCLoggerError(@"Failed to connect: %@ (%@)", ssid, error.localizedDescription);
|
||||
}
|
||||
} else {
|
||||
GTMLoggerInfo(@"Successfully connected to %@", ssid);
|
||||
GNCLoggerInfo(@"Successfully connected to %@", ssid);
|
||||
connected = YES;
|
||||
}
|
||||
dispatch_semaphore_signal(semaphore_internal);
|
||||
}];
|
||||
if (dispatch_semaphore_wait(semaphore_internal, timeout) != 0) {
|
||||
GTMLoggerError(@"Connecting to %@ timeout in %d seconds", ssid, kConnectionTimeoutInSeconds);
|
||||
GNCLoggerError(@"Connecting to %@ timeout in %d seconds", ssid, kConnectionTimeoutInSeconds);
|
||||
}
|
||||
if (connected) {
|
||||
NSString * currentSSID = [self getCurrentWifiSSID];
|
||||
NSString *currentSSID = [self getCurrentWifiSSID];
|
||||
if ([currentSSID isEqualToString:ssid]) {
|
||||
GTMLoggerDebug(@"Connected to %@ successfully", ssid);
|
||||
GNCLoggerDebug(@"Connected to %@ successfully", ssid);
|
||||
break;
|
||||
} else {
|
||||
GTMLoggerError(@"Connected to wrong SSID: %@", currentSSID);
|
||||
GNCLoggerError(@"Connected to wrong SSID: %@", currentSSID);
|
||||
connected = NO;
|
||||
}
|
||||
} else {
|
||||
[[NEHotspotConfigurationManager sharedManager] removeConfigurationForSSID:ssid];
|
||||
[[NEHotspotConfigurationManager sharedManager] removeConfigurationForSSID:ssid];
|
||||
}
|
||||
}
|
||||
return connected;
|
||||
#else
|
||||
GTMLoggerError(@"Not implemented for macOS");
|
||||
GNCLoggerError(@"Not implemented for macOS");
|
||||
return NO;
|
||||
#endif // TARGET_OS_IOS
|
||||
}
|
||||
@@ -97,7 +97,7 @@ static const UInt8 kConnectionToHostTimeoutInSeconds = 10;
|
||||
#if TARGET_OS_IOS
|
||||
[[NEHotspotConfigurationManager sharedManager] removeConfigurationForSSID:ssid];
|
||||
#else
|
||||
GTMLoggerError(@"Not implemented for macOS");
|
||||
GNCLoggerError(@"Not implemented for macOS");
|
||||
#endif // TARGET_OS_IOS
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ static const UInt8 kConnectionToHostTimeoutInSeconds = 10;
|
||||
code:GNCNWFrameworkErrorUnknown
|
||||
userInfo:nil];
|
||||
}
|
||||
GTMLoggerError(@"Invalid host address");
|
||||
GNCLoggerError(@"Invalid host address");
|
||||
return nil;
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ static const UInt8 kConnectionToHostTimeoutInSeconds = 10;
|
||||
- (GNCHotspotSocket *)connectToEndpoint:(nw_endpoint_t)endpoint
|
||||
includePeerToPeer:(BOOL)includePeerToPeer
|
||||
error:(NSError **)error {
|
||||
GTMLoggerInfo(@"connectToEndpoint: %@ includePeerToPeer: %d", endpoint.debugDescription,
|
||||
GNCLoggerInfo(@"connectToEndpoint: %@ includePeerToPeer: %d", endpoint.debugDescription,
|
||||
includePeerToPeer);
|
||||
|
||||
dispatch_semaphore_t semaphore_internal = dispatch_semaphore_create(0);
|
||||
@@ -141,13 +141,13 @@ static const UInt8 kConnectionToHostTimeoutInSeconds = 10;
|
||||
|
||||
nw_connection_set_state_changed_handler(
|
||||
connection, ^(nw_connection_state_t state, nw_error_t error) {
|
||||
GTMLoggerDebug(@"connectToEndpoint state changed to: %d", state);
|
||||
GNCLoggerDebug(@"connectToEndpoint state changed to: %d", state);
|
||||
|
||||
// Ignore the preparing state and waiting state, because it is not a final state.
|
||||
if ((state != nw_connection_state_preparing) && (state != nw_connection_state_waiting)) {
|
||||
blockResult = state;
|
||||
if (error != nil) {
|
||||
GTMLoggerError(@"connectToEndpoint Error: %@", error.debugDescription);
|
||||
GNCLoggerError(@"connectToEndpoint Error: %@", error.debugDescription);
|
||||
blockError = (__bridge_transfer NSError *)nw_error_copy_cf_error(error);
|
||||
}
|
||||
dispatch_semaphore_signal(semaphore_internal);
|
||||
@@ -158,7 +158,7 @@ static const UInt8 kConnectionToHostTimeoutInSeconds = 10;
|
||||
dispatch_time_t timeout =
|
||||
dispatch_time(DISPATCH_TIME_NOW, kConnectionToHostTimeoutInSeconds * NSEC_PER_SEC);
|
||||
if (dispatch_semaphore_wait(semaphore_internal, timeout) != 0) {
|
||||
GTMLoggerError(@"Connecting to %@ timeout in %d seconds", endpoint.debugDescription,
|
||||
GNCLoggerError(@"Connecting to %@ timeout in %d seconds", endpoint.debugDescription,
|
||||
kConnectionToHostTimeoutInSeconds);
|
||||
nw_connection_set_state_changed_handler(connection, nil); // Prevent callback issues
|
||||
nw_connection_cancel(connection);
|
||||
@@ -180,7 +180,7 @@ static const UInt8 kConnectionToHostTimeoutInSeconds = 10;
|
||||
case nw_connection_state_preparing:
|
||||
case nw_connection_state_failed:
|
||||
case nw_connection_state_cancelled:
|
||||
GTMLoggerError(@"connectToEndpoint failed with result: %d", blockResult);
|
||||
GNCLoggerError(@"connectToEndpoint failed with result: %d", blockResult);
|
||||
return nil;
|
||||
case nw_connection_state_ready:
|
||||
return [[GNCHotspotSocket alloc] initWithConnection:connection];
|
||||
@@ -192,7 +192,7 @@ static const UInt8 kConnectionToHostTimeoutInSeconds = 10;
|
||||
// Request permission
|
||||
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
|
||||
[locationManager requestWhenInUseAuthorization];
|
||||
GTMLoggerDebug(@"Request Location permission");
|
||||
GNCLoggerDebug(@"Request Location permission");
|
||||
dispatch_semaphore_t semaphore_internal = dispatch_semaphore_create(0);
|
||||
__block NSString *networkSSID = nil;
|
||||
|
||||
@@ -204,9 +204,9 @@ static const UInt8 kConnectionToHostTimeoutInSeconds = 10;
|
||||
fetchCurrentWithCompletionHandler:^(NEHotspotNetwork *_Nullable network) {
|
||||
if (network) {
|
||||
networkSSID = network.SSID;
|
||||
GTMLoggerDebug(@"iOS 14+ Current Wi-Fi SSID: %@", networkSSID);
|
||||
GNCLoggerDebug(@"iOS 14+ Current Wi-Fi SSID: %@", networkSSID);
|
||||
} else {
|
||||
GTMLoggerError(@"Failed to get current Wifi SSID");
|
||||
GNCLoggerError(@"Failed to get current Wifi SSID");
|
||||
}
|
||||
dispatch_semaphore_signal(semaphore_internal);
|
||||
}];
|
||||
@@ -216,7 +216,7 @@ static const UInt8 kConnectionToHostTimeoutInSeconds = 10;
|
||||
id info =
|
||||
CFBridgingRelease(CNCopyCurrentNetworkInfo((__bridge CFStringRef)(interface)));
|
||||
networkSSID = [info valueForKey:@"SSID"];
|
||||
GTMLoggerDebug(@"Current Wi-Fi SSID: %@", networkSSID);
|
||||
GNCLoggerDebug(@"Current Wi-Fi SSID: %@", networkSSID);
|
||||
}
|
||||
dispatch_semaphore_signal(semaphore_internal);
|
||||
}
|
||||
@@ -224,16 +224,15 @@ static const UInt8 kConnectionToHostTimeoutInSeconds = 10;
|
||||
dispatch_time_t timeout =
|
||||
dispatch_time(DISPATCH_TIME_NOW, kConnectionToHostTimeoutInSeconds * NSEC_PER_SEC);
|
||||
if (dispatch_semaphore_wait(semaphore_internal, timeout) != 0) {
|
||||
GTMLoggerError(@"Getting current Wifi SSID timeout in %d seconds",
|
||||
GNCLoggerError(@"Getting current Wifi SSID timeout in %d seconds",
|
||||
kConnectionToHostTimeoutInSeconds);
|
||||
}
|
||||
|
||||
return networkSSID;
|
||||
#else
|
||||
GTMLoggerError(@"Not implemented for macOS");
|
||||
GNCLoggerError(@"Not implemented for macOS");
|
||||
return nil;
|
||||
#endif // TARGET_OS_IOS
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <Network/Network.h>
|
||||
|
||||
#import "GoogleToolboxForMac/GTMLogger.h"
|
||||
#import "internal/platform/implementation/apple/Log/GNCLogger.h"
|
||||
|
||||
@interface GNCHotspotSocket ()
|
||||
|
||||
|
||||
@@ -17,13 +17,13 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <Network/Network.h>
|
||||
|
||||
#import "internal/platform/implementation/apple/Log/GNCLogger.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/WiFiCommon/GNCIPv4Address.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/WiFiCommon/GNCNWFrameworkError.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/WiFiCommon/GNCNWFrameworkServerSocket+Internal.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/WiFiCommon/GNCNWFrameworkServerSocket.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/WiFiCommon/GNCNWFrameworkSocket.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/WiFiCommon/GNCNWParameters.h"
|
||||
#import "GoogleToolboxForMac/GTMLogger.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@@ -125,7 +125,7 @@ static GNCNWFramework *gInstance = nil;
|
||||
- (nullable GNCNWFrameworkServerSocket *)listenForServiceOnPort:(NSInteger)port
|
||||
includePeerToPeer:(BOOL)includePeerToPeer
|
||||
error:(NSError **)error {
|
||||
GTMLoggerInfo(@"[GNCNWFramework] Listen on port: %ld with includePeerToPeer: %@.", (long)port,
|
||||
GNCLoggerInfo(@"[GNCNWFramework] Listen on port: %ld with includePeerToPeer: %@.", (long)port,
|
||||
(includePeerToPeer ? @"true" : @"false"));
|
||||
GNCNWFrameworkServerSocket *serverSocket = [[GNCNWFrameworkServerSocket alloc] initWithPort:port];
|
||||
_includePeerToPeer = includePeerToPeer;
|
||||
@@ -143,7 +143,7 @@ static GNCNWFramework *gInstance = nil;
|
||||
includePeerToPeer:(BOOL)includePeerToPeer
|
||||
error:
|
||||
(NSError **_Nullable)error {
|
||||
GTMLoggerInfo(
|
||||
GNCLoggerInfo(
|
||||
@"[GNCNWFramework] Listen on port: %ld with includePeerToPeer: %@, and PSKIdentity: %@.",
|
||||
(long)port, (includePeerToPeer ? @"true" : @"false"), PSKIdentity);
|
||||
GNCNWFrameworkServerSocket *serverSocket = [[GNCNWFrameworkServerSocket alloc] initWithPort:port];
|
||||
@@ -194,7 +194,7 @@ static GNCNWFramework *gInstance = nil;
|
||||
_includePeerToPeer = includePeerToPeer;
|
||||
nw_parameters_t parameters = GNCBuildNonTLSParameters(/*includePeerToPeer=*/_includePeerToPeer);
|
||||
if (!parameters) {
|
||||
GTMLoggerError(@"[GNCNWFramework] Failed to create NW parameters.");
|
||||
GNCLoggerError(@"[GNCNWFramework] Failed to create NW parameters.");
|
||||
return NO;
|
||||
}
|
||||
nw_browse_descriptor_t descriptor =
|
||||
@@ -218,7 +218,7 @@ static GNCNWFramework *gInstance = nil;
|
||||
// advertisement, so we ignore it.
|
||||
BOOL hasLoopback = GNCHasLoopbackInterface(new_result);
|
||||
if (hasLoopback) {
|
||||
GTMLoggerInfo(@"Ignoring a service discovered with loopback interface.");
|
||||
GNCLoggerInfo(@"Ignoring a service discovered with loopback interface.");
|
||||
break;
|
||||
}
|
||||
nw_endpoint_t endpoint = nw_browse_result_copy_endpoint(new_result);
|
||||
@@ -233,7 +233,7 @@ static GNCNWFramework *gInstance = nil;
|
||||
BOOL oldHasLoopback = GNCHasLoopbackInterface(old_result);
|
||||
BOOL newHasLoopback = GNCHasLoopbackInterface(new_result);
|
||||
if (oldHasLoopback || newHasLoopback) {
|
||||
GTMLoggerInfo(@"Ignoring a service change with loopback interface.");
|
||||
GNCLoggerInfo(@"Ignoring a service change with loopback interface.");
|
||||
break;
|
||||
}
|
||||
nw_endpoint_t old_endpoint = nw_browse_result_copy_endpoint(old_result);
|
||||
@@ -254,7 +254,7 @@ static GNCNWFramework *gInstance = nil;
|
||||
// we ignore it.
|
||||
BOOL hasLoopback = GNCHasLoopbackInterface(old_result);
|
||||
if (hasLoopback) {
|
||||
GTMLoggerInfo(@"Ignoring a service lost with loopback interface.");
|
||||
GNCLoggerInfo(@"Ignoring a service lost with loopback interface.");
|
||||
break;
|
||||
}
|
||||
nw_endpoint_t endpoint = nw_browse_result_copy_endpoint(old_result);
|
||||
@@ -324,7 +324,7 @@ static GNCNWFramework *gInstance = nil;
|
||||
- (nullable GNCNWFrameworkSocket *)connectToServiceName:(NSString *)serviceName
|
||||
serviceType:(NSString *)serviceType
|
||||
error:(NSError **)error {
|
||||
GTMLoggerInfo(@"[GNCNWFramework] Connect to service {serviceName:%@, serviceType:%@, "
|
||||
GNCLoggerInfo(@"[GNCNWFramework] Connect to service {serviceName:%@, serviceType:%@, "
|
||||
@"includePeerToPeer:%@}.",
|
||||
serviceName, serviceType, (_includePeerToPeer ? @"true" : @"false"));
|
||||
nw_endpoint_t endpoint = nw_endpoint_create_bonjour_service([serviceName UTF8String],
|
||||
@@ -341,7 +341,7 @@ static GNCNWFramework *gInstance = nil;
|
||||
PSKIdentity:(NSData *)PSKIdentity
|
||||
PSKSharedSecret:(NSData *)PSKSharedSecret
|
||||
error:(NSError **_Nullable)error {
|
||||
GTMLoggerInfo(@"[GNCNWFramework] Connect to service {serviceName:%@, serviceType:%@, "
|
||||
GNCLoggerInfo(@"[GNCNWFramework] Connect to service {serviceName:%@, serviceType:%@, "
|
||||
@"includePeerToPeer:%@}.",
|
||||
serviceName, serviceType, (_includePeerToPeer ? @"true" : @"false"));
|
||||
nw_endpoint_t endpoint = nw_endpoint_create_bonjour_service([serviceName UTF8String],
|
||||
@@ -357,7 +357,7 @@ static GNCNWFramework *gInstance = nil;
|
||||
port:(NSInteger)port
|
||||
includePeerToPeer:(BOOL)includePeerToPeer
|
||||
error:(NSError **)error {
|
||||
GTMLoggerInfo(@"[GNCNWFramework] Connect to host {host:%s, port:%ld}.",
|
||||
GNCLoggerInfo(@"[GNCNWFramework] Connect to host {host:%s, port:%ld}.",
|
||||
host.dottedRepresentation.UTF8String, (long)port);
|
||||
nw_endpoint_t endpoint =
|
||||
nw_endpoint_create_host(host.dottedRepresentation.UTF8String, @(port).stringValue.UTF8String);
|
||||
@@ -388,7 +388,7 @@ static GNCNWFramework *gInstance = nil;
|
||||
: GNCBuildTLSParameters(/*PSK=*/PSKSharedSecret, /*identity=*/PSKIdentity,
|
||||
/*includePeerToPeer=*/_includePeerToPeer);
|
||||
if (!parameters) {
|
||||
GTMLoggerError(@"[GNCNWFramework] Failed to create NW parameters.");
|
||||
GNCLoggerError(@"[GNCNWFramework] Failed to create NW parameters.");
|
||||
return nil;
|
||||
}
|
||||
nw_connection_t connection = nw_connection_create(endpoint, parameters);
|
||||
@@ -427,7 +427,7 @@ static GNCNWFramework *gInstance = nil;
|
||||
*error = blockError;
|
||||
}
|
||||
|
||||
GTMLoggerInfo(@"[GNCNWFramework] Connect to endpoint result %@", @(blockResult));
|
||||
GNCLoggerInfo(@"[GNCNWFramework] Connect to endpoint result %@", @(blockResult));
|
||||
switch (blockResult) {
|
||||
case nw_connection_state_invalid:
|
||||
case nw_connection_state_waiting:
|
||||
|
||||
+7
-7
@@ -22,12 +22,12 @@
|
||||
#include <netdb.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#import "internal/platform/implementation/apple/Log/GNCLogger.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/WiFiCommon/GNCIPv4Address.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/WiFiCommon/GNCNWFrameworkError.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/WiFiCommon/GNCNWFrameworkServerSocket+Internal.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/WiFiCommon/GNCNWFrameworkSocket.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/WiFiCommon/GNCNWParameters.h"
|
||||
#import "GoogleToolboxForMac/GTMLogger.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@@ -140,7 +140,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
- (void)startAdvertisingServiceName:(NSString *)serviceName
|
||||
serviceType:(NSString *)serviceType
|
||||
txtRecords:(NSDictionary<NSString *, NSString *> *)txtRecords {
|
||||
GTMLoggerInfo(@"[GNCNWFrameworkServerSocket] Start advertising {serviceName:%@, "
|
||||
GNCLoggerInfo(@"[GNCNWFrameworkServerSocket] Start advertising {serviceName:%@, "
|
||||
@"serviceType: %@}",
|
||||
serviceName, serviceType);
|
||||
|
||||
@@ -152,11 +152,11 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
NSData *encodedRecord = [recordValue dataUsingEncoding:NSUTF8StringEncoding];
|
||||
if (!nw_txt_record_set_key(txtRecord, [key UTF8String], encodedRecord.bytes,
|
||||
encodedRecord.length)) {
|
||||
GTMLoggerError(@"[GNCNWFrameworkServerSocket] Failed to set text record key: %@, value: %@",
|
||||
GNCLoggerError(@"[GNCNWFrameworkServerSocket] Failed to set text record key: %@, value: %@",
|
||||
key, recordValue);
|
||||
continue;
|
||||
}
|
||||
GTMLoggerDebug(@"[GNCNWFrameworkServerSocket] Text record {key: "
|
||||
GNCLoggerDebug(@"[GNCNWFrameworkServerSocket] Text record {key: "
|
||||
@"%@, value: %@}",
|
||||
key, recordValue);
|
||||
}
|
||||
@@ -216,7 +216,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
: GNCBuildTLSParameters(/*PSK=*/PSKSharedSecret, /*identity=*/PSKIdentify,
|
||||
/*includePeerToPeer=*/includePeerToPeer);
|
||||
if (!parameters) {
|
||||
GTMLoggerError(@"[GNCNWFrameworkServerSocket] Failed to create NW parameters.");
|
||||
GNCLoggerError(@"[GNCNWFrameworkServerSocket] Failed to create NW parameters.");
|
||||
return NO;
|
||||
}
|
||||
|
||||
@@ -305,12 +305,12 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
case nw_listener_state_waiting:
|
||||
case nw_listener_state_failed:
|
||||
case nw_listener_state_cancelled:
|
||||
GTMLoggerError(@"[GNCNWFrameworkServerSocket] Listen state: %u", _listenerState);
|
||||
GNCLoggerError(@"[GNCNWFrameworkServerSocket] Listen state: %u", _listenerState);
|
||||
[self close];
|
||||
return NO;
|
||||
case nw_listener_state_ready:
|
||||
_port = nw_listener_get_port(_listener);
|
||||
GTMLoggerInfo(@"[GNCNWFrameworkServerSocket] Listen on port: %ld", (long)_port);
|
||||
GNCLoggerInfo(@"[GNCNWFrameworkServerSocket] Listen on port: %ld", (long)_port);
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <Network/Network.h>
|
||||
|
||||
#import "GoogleToolboxForMac/GTMLogger.h"
|
||||
#import "internal/platform/implementation/apple/Log/GNCLogger.h"
|
||||
|
||||
@interface GNCNWFrameworkSocket ()
|
||||
|
||||
|
||||
@@ -18,18 +18,18 @@
|
||||
#import <Network/Network.h>
|
||||
#import <Security/SecProtocolOptions.h>
|
||||
|
||||
#import "GoogleToolboxForMac/GTMLogger.h"
|
||||
#import "internal/platform/implementation/apple/Log/GNCLogger.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
BOOL GNCConfigureTLSOptions(sec_protocol_options_t options, NSData *PSK, NSData *identity) {
|
||||
if (!options) {
|
||||
GTMLoggerError(@"[GNCNWParameters] Invalid parameter of options.");
|
||||
GNCLoggerError(@"[GNCNWParameters] Invalid parameter of options.");
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (PSK.length == 0 || identity.length == 0) {
|
||||
GTMLoggerError(@"[GNCNWParameters] Invalid parameter of psk or identity.");
|
||||
GNCLoggerError(@"[GNCNWParameters] Invalid parameter of psk or identity.");
|
||||
return NO;
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ BOOL GNCConfigureTLSOptions(sec_protocol_options_t options, NSData *PSK, NSData
|
||||
[identity bytes], [identity length], nil, DISPATCH_DATA_DESTRUCTOR_DEFAULT);
|
||||
|
||||
if (!psk_secret_dispatch_data || !psk_identity_dispatch_data) {
|
||||
GTMLoggerError(@"[GNCNWParameters] Failed to create dispatch_data_t for PSK.");
|
||||
GNCLoggerError(@"[GNCNWParameters] Failed to create dispatch_data_t for PSK.");
|
||||
return NO;
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ BOOL GNCConfigureTLSOptions(sec_protocol_options_t options, NSData *PSK, NSData
|
||||
sec_protocol_options_add_pre_shared_key(options, psk_secret_dispatch_data,
|
||||
psk_identity_dispatch_data);
|
||||
|
||||
GTMLoggerInfo(@"[GNCNWParameters] Successfully configured TLS options.");
|
||||
GNCLoggerInfo(@"[GNCNWParameters] Successfully configured TLS options.");
|
||||
return YES;
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ nw_parameters_t _Nullable GNCBuildTLSParameters(NSData *PSK, NSData *identity,
|
||||
},
|
||||
/*tcp*/ NW_PARAMETERS_DEFAULT_CONFIGURATION);
|
||||
if (!TLSWasConfigured) {
|
||||
GTMLoggerError(@"[GNCNWParameters] Failed to configure TLS options.");
|
||||
GNCLoggerError(@"[GNCNWParameters] Failed to configure TLS options.");
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,12 +19,12 @@
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#import "internal/platform/implementation/apple/Log/GNCLogger.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/WiFiCommon/GNCIPv4Address.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/WiFiCommon/GNCNWFramework.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/WiFiCommon/GNCNWFrameworkServerSocket.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/WiFiCommon/GNCNWFrameworkSocket.h"
|
||||
#import "internal/platform/implementation/apple/network_utils.h"
|
||||
#import "GoogleToolboxForMac/GTMLogger.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace apple {
|
||||
@@ -37,7 +37,7 @@ ExceptionOr<ByteArray> AwdlInputStream::Read(std::int64_t size) {
|
||||
NSError* error = nil;
|
||||
NSData* data = [socket_ readMaxLength:size error:&error];
|
||||
if (data == nil) {
|
||||
GTMLoggerError(@"Error reading socket: %@", error);
|
||||
GNCLoggerError(@"Error reading socket: %@", error);
|
||||
return {Exception::kIo};
|
||||
}
|
||||
return ExceptionOr<ByteArray>{ByteArray((const char*)data.bytes, data.length)};
|
||||
@@ -57,7 +57,7 @@ Exception AwdlOutputStream::Write(const ByteArray& data) {
|
||||
NSError* error = nil;
|
||||
BOOL result = [socket_ write:[NSData dataWithBytes:data.data() length:data.size()] error:&error];
|
||||
if (!result) {
|
||||
GTMLoggerError(@"Error writing socket: %@", error);
|
||||
GNCLoggerError(@"Error writing socket: %@", error);
|
||||
return {Exception::kIo};
|
||||
}
|
||||
return {Exception::kSuccess};
|
||||
@@ -110,7 +110,7 @@ std::unique_ptr<api::AwdlSocket> AwdlServerSocket::Accept() {
|
||||
return std::make_unique<AwdlSocket>(socket);
|
||||
}
|
||||
if (error != nil) {
|
||||
GTMLoggerError(@"Error accepting socket: %@", error);
|
||||
GNCLoggerError(@"Error accepting socket: %@", error);
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
@@ -24,9 +24,9 @@
|
||||
#include "internal/platform/implementation/ble_v2.h"
|
||||
|
||||
#import "internal/platform/implementation/apple/Flags/GNCFeatureFlags.h"
|
||||
#import "internal/platform/implementation/apple/Log/GNCLogger.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/BLEv2/GNCBLEGATTClient.h"
|
||||
#import "internal/platform/implementation/apple/ble_utils.h"
|
||||
#import "GoogleToolboxForMac/GTMLogger.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace apple {
|
||||
@@ -49,7 +49,7 @@ bool GattClient::DiscoverServiceAndCharacteristics(const Uuid &service_uuid,
|
||||
completionHandler:^(NSError *error) {
|
||||
[condition lock];
|
||||
if (error != nil) {
|
||||
GTMLoggerError(@"Error discovering characteristics: %@", error);
|
||||
GNCLoggerError(@"Error discovering characteristics: %@", error);
|
||||
}
|
||||
blockError = error;
|
||||
[condition signal];
|
||||
@@ -74,7 +74,7 @@ std::optional<api::ble_v2::GattCharacteristic> GattClient::GetCharacteristic(
|
||||
completionHandler:^(GNCBLEGATTCharacteristic *characteristic, NSError *error) {
|
||||
[condition lock];
|
||||
if (error != nil) {
|
||||
GTMLoggerError(@"Error retrieving characteristic: %@", error);
|
||||
GNCLoggerError(@"Error retrieving characteristic: %@", error);
|
||||
}
|
||||
blockCharacteristic = characteristic;
|
||||
blockError = error;
|
||||
@@ -99,7 +99,7 @@ std::optional<std::string> GattClient::ReadCharacteristic(
|
||||
completionHandler:^(NSData *value, NSError *error) {
|
||||
[condition lock];
|
||||
if (error != nil) {
|
||||
GTMLoggerError(@"Error reading characteristic: %@", error);
|
||||
GNCLoggerError(@"Error reading characteristic: %@", error);
|
||||
}
|
||||
blockValue = value;
|
||||
blockError = error;
|
||||
|
||||
@@ -19,10 +19,10 @@
|
||||
|
||||
#include "internal/platform/implementation/ble_v2.h"
|
||||
|
||||
#import "internal/platform/implementation/apple/Log/GNCLogger.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/BLEv2/GNCBLEGATTServer.h"
|
||||
#import "internal/platform/implementation/apple/ble_utils.h"
|
||||
#import "internal/platform/implementation/apple/utils.h"
|
||||
#import "GoogleToolboxForMac/GTMLogger.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace apple {
|
||||
@@ -49,7 +49,7 @@ std::optional<api::ble_v2::GattCharacteristic> GattServer::CreateCharacteristic(
|
||||
NSError *error) {
|
||||
[condition lock];
|
||||
if (error != nil) {
|
||||
GTMLoggerError(@"Error creating characteristic: %@", error);
|
||||
GNCLoggerError(@"Error creating characteristic: %@", error);
|
||||
}
|
||||
blockCharacteristic = characteristic;
|
||||
[condition signal];
|
||||
@@ -73,7 +73,7 @@ bool GattServer::UpdateCharacteristic(const api::ble_v2::GattCharacteristic &cha
|
||||
completionHandler:^(NSError *error) {
|
||||
[condition lock];
|
||||
if (error != nil) {
|
||||
GTMLoggerError(@"Error updating characteristic: %@", error);
|
||||
GNCLoggerError(@"Error updating characteristic: %@", error);
|
||||
}
|
||||
blockError = error;
|
||||
[condition signal];
|
||||
@@ -91,9 +91,7 @@ absl::Status GattServer::NotifyCharacteristicChanged(
|
||||
return absl::UnimplementedError("");
|
||||
}
|
||||
|
||||
void GattServer::Stop() {
|
||||
[gatt_server_ stop];
|
||||
}
|
||||
void GattServer::Stop() { [gatt_server_ stop]; }
|
||||
|
||||
} // namespace apple
|
||||
} // namespace nearby
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#import "internal/platform/implementation/apple/Log/GNCLogger.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/BLEv2/GNCBLEL2CAPServer.h"
|
||||
#import "GoogleToolboxForMac/GTMLogger.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace apple {
|
||||
|
||||
@@ -14,10 +14,10 @@
|
||||
|
||||
#import "internal/platform/implementation/apple/ble_l2cap_socket.h"
|
||||
|
||||
#include "internal/platform/implementation/ble_v2.h"
|
||||
#import "internal/platform/implementation/apple/Log/GNCLogger.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/BLEv2/GNCBLEL2CAPConnection.h"
|
||||
#import "internal/platform/implementation/apple/utils.h"
|
||||
#import "GoogleToolboxForMac/GTMLogger.h"
|
||||
#include "internal/platform/implementation/ble_v2.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace apple {
|
||||
@@ -151,7 +151,7 @@ Exception BleL2capOutputStream::Flush() {
|
||||
}
|
||||
|
||||
Exception BleL2capOutputStream::Close() {
|
||||
GTMLoggerInfo(@"[NEARBY] BleL2capOutputStream Closing");
|
||||
GNCLoggerInfo(@"[NEARBY] BleL2capOutputStream Closing");
|
||||
// Unblock pending write operation.
|
||||
[condition_ lock];
|
||||
connection_ = nil;
|
||||
@@ -188,7 +188,7 @@ Exception BleL2capSocket::Close() {
|
||||
}
|
||||
|
||||
void BleL2capSocket::DoClose() {
|
||||
GTMLoggerInfo(@"[NEARBY] BleL2capSocket DoClose");
|
||||
GNCLoggerInfo(@"[NEARBY] BleL2capSocket DoClose");
|
||||
if (!closed_) {
|
||||
input_stream_->Close();
|
||||
output_stream_->Close();
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#import "internal/platform/implementation/apple/Mediums/BLEv2/GNCBLEMedium.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/BLEv2/GNCPeripheral.h"
|
||||
|
||||
#import "internal/platform/implementation/apple/Log/GNCLogger.h"
|
||||
// TODO(b/293336684): Old Weave imports that need to be deleted once shared Weave is complete.
|
||||
#import "internal/platform/implementation/apple/Mediums/Ble/GNCMBleConnection.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/Ble/GNCMBleUtils.h"
|
||||
@@ -51,7 +52,6 @@
|
||||
#import "internal/platform/implementation/apple/ble_socket.h"
|
||||
#import "internal/platform/implementation/apple/bluetooth_adapter_v2.h"
|
||||
#import "internal/platform/implementation/apple/utils.h"
|
||||
#import "GoogleToolboxForMac/GTMLogger.h"
|
||||
|
||||
static NSString *const kWeaveServiceUUID = @"FEF3";
|
||||
static const UInt8 kRequestConnectionTimeoutInSeconds = 12;
|
||||
@@ -117,7 +117,7 @@ bool BleMedium::StartAdvertising(const api::ble_v2::BleAdvertisementData &advert
|
||||
[medium_ startAdvertisingData:serviceData
|
||||
completionHandler:^(NSError *error) {
|
||||
if (error != nil) {
|
||||
GTMLoggerError(@"Failed to start advertising: %@", error);
|
||||
GNCLoggerError(@"Failed to start advertising: %@", error);
|
||||
}
|
||||
blockError = error;
|
||||
dispatch_semaphore_signal(semaphore);
|
||||
@@ -133,7 +133,7 @@ bool BleMedium::StopAdvertising() {
|
||||
__block NSError *blockError = nil;
|
||||
[medium_ stopAdvertisingWithCompletionHandler:^(NSError *error) {
|
||||
if (error != nil) {
|
||||
GTMLoggerError(@"Failed to stop advertising: %@", error);
|
||||
GNCLoggerError(@"Failed to stop advertising: %@", error);
|
||||
}
|
||||
blockError = error;
|
||||
dispatch_semaphore_signal(semaphore);
|
||||
@@ -168,7 +168,7 @@ void BleMedium::HandleAdvertisementFound(id<GNCPeripheral> peripheral,
|
||||
|
||||
#if DEBUG
|
||||
for (NSData *service_data in serviceData.allValues) {
|
||||
GTMLoggerDebug(@"Reporting the advertisement packet to upper layer for unique_id: %llu, %@, "
|
||||
GNCLoggerDebug(@"Reporting the advertisement packet to upper layer for unique_id: %llu, %@, "
|
||||
@"advertisement_data: %@.",
|
||||
unique_id, peripheral, ConvertDataToHexString(service_data));
|
||||
}
|
||||
@@ -238,7 +238,7 @@ bool BleMedium::StartScanning(const Uuid &service_uuid, api::ble_v2::TxPowerLeve
|
||||
}
|
||||
completionHandler:^(NSError *error) {
|
||||
if (error != nil) {
|
||||
GTMLoggerError(@"Failed to start scanning: %@", error);
|
||||
GNCLoggerError(@"Failed to start scanning: %@", error);
|
||||
}
|
||||
blockError = error;
|
||||
dispatch_semaphore_signal(semaphore);
|
||||
@@ -251,7 +251,7 @@ bool BleMedium::StartMultipleServicesScanning(const std::vector<Uuid> &service_u
|
||||
api::ble_v2::TxPowerLevel tx_power_level,
|
||||
api::ble_v2::BleMedium::ScanCallback callback) {
|
||||
if (service_uuids.empty()) {
|
||||
GTMLoggerError(@"No service UUIDs provided");
|
||||
GNCLoggerError(@"No service UUIDs provided");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -280,7 +280,7 @@ bool BleMedium::StartMultipleServicesScanning(const std::vector<Uuid> &service_u
|
||||
}
|
||||
completionHandler:^(NSError *error) {
|
||||
if (error != nil) {
|
||||
GTMLoggerError(@"Failed to start scanning for multiple services: %@", error);
|
||||
GNCLoggerError(@"Failed to start scanning for multiple services: %@", error);
|
||||
blockError = error;
|
||||
}
|
||||
dispatch_semaphore_signal(semaphore);
|
||||
@@ -296,7 +296,7 @@ bool BleMedium::StopScanning() {
|
||||
__block NSError *blockError = nil;
|
||||
[medium_ stopScanningWithCompletionHandler:^(NSError *error) {
|
||||
if (error != nil) {
|
||||
GTMLoggerError(@"Failed to stop scanning: %@", error);
|
||||
GNCLoggerError(@"Failed to stop scanning: %@", error);
|
||||
}
|
||||
blockError = error;
|
||||
dispatch_semaphore_signal(semaphore);
|
||||
@@ -312,7 +312,7 @@ bool BleMedium::ResumeMediumScanning() {
|
||||
__block NSError *blockError = nil;
|
||||
[medium_ resumeMediumScanning:^(NSError *error) {
|
||||
if (error != nil) {
|
||||
GTMLoggerError(@"Failed to start scanning for multiple services: %@", error);
|
||||
GNCLoggerError(@"Failed to start scanning for multiple services: %@", error);
|
||||
blockError = error;
|
||||
}
|
||||
dispatch_semaphore_signal(semaphore);
|
||||
@@ -328,7 +328,7 @@ std::unique_ptr<api::ble_v2::GattServer> BleMedium::StartGattServer(
|
||||
__block GNCBLEGATTServer *blockServer = nil;
|
||||
[medium_ startGATTServerWithCompletionHandler:^(GNCBLEGATTServer *server, NSError *error) {
|
||||
if (error != nil) {
|
||||
GTMLoggerError(@"Error starting GATT server: %@", error);
|
||||
GNCLoggerError(@"Error starting GATT server: %@", error);
|
||||
}
|
||||
blockServer = server;
|
||||
dispatch_semaphore_signal(semaphore);
|
||||
@@ -345,7 +345,7 @@ std::unique_ptr<api::ble_v2::GattClient> BleMedium::ConnectToGattServer(
|
||||
api::ble_v2::ClientGattConnectionCallback callback) {
|
||||
id<GNCPeripheral> peripheral = peripherals_.Get(peripheral_id);
|
||||
if (!peripheral) {
|
||||
GTMLoggerError(@"[NEARBY] Failed to connect to Gatt server: peripheral is not found.");
|
||||
GNCLoggerError(@"[NEARBY] Failed to connect to Gatt server: peripheral is not found.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -359,7 +359,7 @@ std::unique_ptr<api::ble_v2::GattClient> BleMedium::ConnectToGattServer(
|
||||
}
|
||||
completionHandler:^(GNCBLEGATTClient *client, NSError *error) {
|
||||
if (error != nil) {
|
||||
GTMLoggerError(@"Error connecting to GATT server: %@", error);
|
||||
GNCLoggerError(@"Error connecting to GATT server: %@", error);
|
||||
}
|
||||
blockClient = client;
|
||||
dispatch_semaphore_signal(semaphore);
|
||||
@@ -405,7 +405,7 @@ std::unique_ptr<api::ble_v2::BleServerSocket> BleMedium::OpenServerSocket(
|
||||
[socketPeripheralManager_ addPeripheralServiceManager:socketPeripheralServiceManager_
|
||||
bleServiceAddedCompletion:^(NSError *error) {
|
||||
if (error != nil) {
|
||||
GTMLoggerError(@"Failed to add Weave service: %@", error);
|
||||
GNCLoggerError(@"Failed to add Weave service: %@", error);
|
||||
}
|
||||
blockError = error;
|
||||
dispatch_semaphore_signal(semaphore);
|
||||
@@ -450,7 +450,7 @@ std::unique_ptr<api::ble_v2::BleL2capServerSocket> BleMedium::OpenL2capServerSoc
|
||||
channelOpenedCompletionHandler:^(GNCBLEL2CAPStream *_Nullable stream,
|
||||
NSError *_Nullable error) {
|
||||
if (error != nil) {
|
||||
GTMLoggerError(@"Error opening L2CAP channel in L2CAP server: %@", error);
|
||||
GNCLoggerError(@"Error opening L2CAP channel in L2CAP server: %@", error);
|
||||
return;
|
||||
}
|
||||
GNCBLEL2CAPConnection *connection =
|
||||
@@ -481,7 +481,7 @@ std::unique_ptr<api::ble_v2::BleSocket> BleMedium::Connect(
|
||||
api::ble_v2::BlePeripheral::UniqueId peripheral_id, CancellationFlag *cancellation_flag) {
|
||||
id<GNCPeripheral> peripheral = peripherals_.Get(peripheral_id);
|
||||
if (!peripheral) {
|
||||
GTMLoggerError(@"[NEARBY] Failed to connect to Gatt server: peripheral is not found.");
|
||||
GNCLoggerError(@"[NEARBY] Failed to connect to Gatt server: peripheral is not found.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -532,7 +532,7 @@ std::unique_ptr<api::ble_v2::BleL2capSocket> BleMedium::ConnectOverL2cap(
|
||||
api::ble_v2::BlePeripheral::UniqueId peripheral_id, CancellationFlag *cancellation_flag) {
|
||||
id<GNCPeripheral> peripheral = peripherals_.Get(peripheral_id);
|
||||
if (!peripheral) {
|
||||
GTMLoggerError(@"[NEARBY] Failed to connect over L2CAP: peripheral is not found.");
|
||||
GNCLoggerError(@"[NEARBY] Failed to connect over L2CAP: peripheral is not found.");
|
||||
return nullptr;
|
||||
}
|
||||
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
|
||||
@@ -561,18 +561,18 @@ std::unique_ptr<api::ble_v2::BleL2capSocket> BleMedium::ConnectOverL2cap(
|
||||
if (result) {
|
||||
socket = std::make_unique<BleL2capSocket>(connection, peripheral_id);
|
||||
}
|
||||
GTMLoggerInfo(result ? @"[NEARBY] Request data connection is ok"
|
||||
GNCLoggerInfo(result ? @"[NEARBY] Request data connection is ok"
|
||||
: @"[NEARBY] Request data connection is not ok");
|
||||
dispatch_semaphore_signal(semaphore);
|
||||
}];
|
||||
}];
|
||||
if (dispatch_semaphore_wait(semaphore, timeout) != 0) {
|
||||
GTMLoggerError(@"[NEARBY] Failed to connect over L2CAP: timeout.");
|
||||
GNCLoggerError(@"[NEARBY] Failed to connect over L2CAP: timeout.");
|
||||
return nullptr;
|
||||
}
|
||||
if (socket == nullptr) {
|
||||
if (openError != nil) {
|
||||
GTMLoggerError(@"[NEARBY] Failed to connect over L2CAP:%@.", openError);
|
||||
GNCLoggerError(@"[NEARBY] Failed to connect over L2CAP:%@.", openError);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
#include "internal/base/file_path.h"
|
||||
#include "internal/platform/implementation/device_info.h"
|
||||
|
||||
#import "GoogleToolboxForMac/GTMLogger.h"
|
||||
#import "internal/platform/implementation/apple/Log/GNCLogger.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace apple {
|
||||
@@ -88,7 +88,7 @@ std::optional<FilePath> DeviceInfo::GetDownloadPath() const {
|
||||
create:YES
|
||||
error:&error];
|
||||
if (!downloadsURL) {
|
||||
GTMLoggerError(@"Failed to get download path: %@", error);
|
||||
GNCLoggerError(@"Failed to get download path: %@", error);
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
@@ -105,16 +105,14 @@ std::optional<FilePath> DeviceInfo::GetLocalAppDataPath() const {
|
||||
create:YES
|
||||
error:&error];
|
||||
if (!applicationSupportURL) {
|
||||
GTMLoggerError(@"Failed to get application support path: %@", error);
|
||||
GNCLoggerError(@"Failed to get application support path: %@", error);
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return FilePath(absl::string_view([applicationSupportURL.path cString]));
|
||||
}
|
||||
|
||||
std::optional<FilePath> DeviceInfo::GetCommonAppDataPath() const {
|
||||
return GetLocalAppDataPath();
|
||||
}
|
||||
std::optional<FilePath> DeviceInfo::GetCommonAppDataPath() const { return GetLocalAppDataPath(); }
|
||||
|
||||
std::optional<FilePath> DeviceInfo::GetTemporaryPath() const {
|
||||
return FilePath(absl::string_view([NSTemporaryDirectory() cString]));
|
||||
@@ -130,7 +128,7 @@ std::optional<FilePath> DeviceInfo::GetLogPath() const {
|
||||
create:YES
|
||||
error:&error];
|
||||
if (!applicationSupportURL) {
|
||||
GTMLoggerError(@"Failed to get application support path: %@", error);
|
||||
GNCLoggerError(@"Failed to get application support path: %@", error);
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
@@ -152,7 +150,7 @@ std::optional<FilePath> DeviceInfo::GetCrashDumpPath() const {
|
||||
create:YES
|
||||
error:&error];
|
||||
if (!applicationSupportURL) {
|
||||
GTMLoggerError(@"Failed to get application support path: %@", error);
|
||||
GNCLoggerError(@"Failed to get application support path: %@", error);
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,10 +16,10 @@
|
||||
#include "internal/platform/nsd_service_info.h"
|
||||
|
||||
#include "internal/platform/cancellation_flag.h"
|
||||
#import "internal/platform/implementation/apple/Log/GNCLogger.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/WiFiCommon/GNCIPv4Address.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/WiFiCommon/GNCNWFramework.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/WiFiCommon/GNCNWFrameworkSocket.h"
|
||||
#import "GoogleToolboxForMac/GTMLogger.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace apple {
|
||||
@@ -51,7 +51,7 @@ bool StopAdvertising(GNCNWFramework* medium, const NsdServiceInfo& nsd_service_i
|
||||
bool StartDiscovery(GNCNWFramework* medium, const std::string& service_type,
|
||||
NetworkDiscoveredServiceCallback callback, bool include_peer_to_peer) {
|
||||
if (medium.isDiscoveringAnyService) {
|
||||
GTMLoggerError(@"Error already discovering for service");
|
||||
GNCLoggerError(@"Error already discovering for service");
|
||||
return false;
|
||||
}
|
||||
__block NSString* serviceType = @(service_type.c_str());
|
||||
@@ -84,7 +84,7 @@ bool StartDiscovery(GNCNWFramework* medium, const std::string& service_type,
|
||||
includePeerToPeer:include_peer_to_peer
|
||||
error:&error];
|
||||
if (error != nil) {
|
||||
GTMLoggerError(@"Error starting discovery for service type<%@>: %@", serviceType, error);
|
||||
GNCLoggerError(@"Error starting discovery for service type<%@>: %@", serviceType, error);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -108,7 +108,7 @@ GNCNWFrameworkSocket* ConnectToService(GNCNWFramework* medium,
|
||||
return socket;
|
||||
}
|
||||
if (error != nil) {
|
||||
GTMLoggerError(@"Error connecting to service name<%@> type<%@>: %@", serviceName, serviceType,
|
||||
GNCLoggerError(@"Error connecting to service name<%@> type<%@>: %@", serviceName, serviceType,
|
||||
error);
|
||||
}
|
||||
return nil;
|
||||
@@ -134,7 +134,7 @@ GNCNWFrameworkSocket* ConnectToService(GNCNWFramework* medium,
|
||||
return socket;
|
||||
}
|
||||
if (error != nil) {
|
||||
GTMLoggerError(@"Error connecting to service name<%@> type<%@>: %@", serviceName, serviceType,
|
||||
GNCLoggerError(@"Error connecting to service name<%@> type<%@>: %@", serviceName, serviceType,
|
||||
error);
|
||||
}
|
||||
return nil;
|
||||
@@ -145,7 +145,7 @@ GNCNWFrameworkSocket* ConnectToService(GNCNWFramework* medium, const std::string
|
||||
CancellationFlag* cancellation_flag) {
|
||||
NSError* error = nil;
|
||||
if (ip_address.size() != 4) {
|
||||
GTMLoggerError(@"Error IP address must be 4 bytes, but is %lu bytes", ip_address.size());
|
||||
GNCLoggerError(@"Error IP address must be 4 bytes, but is %lu bytes", ip_address.size());
|
||||
return nil;
|
||||
}
|
||||
NSData* hostData = [NSData dataWithBytes:ip_address.data() length:ip_address.size()];
|
||||
@@ -158,7 +158,7 @@ GNCNWFrameworkSocket* ConnectToService(GNCNWFramework* medium, const std::string
|
||||
return socket;
|
||||
}
|
||||
if (error != nil) {
|
||||
GTMLoggerError(@"Error connecting to %@:%d: %@", host, port, error);
|
||||
GNCLoggerError(@"Error connecting to %@:%d: %@", host, port, error);
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
@@ -166,7 +166,7 @@ GNCNWFrameworkSocket* ConnectToService(GNCNWFramework* medium, const std::string
|
||||
GNCNWFrameworkServerSocket* ListenForService(GNCNWFramework* medium, int port,
|
||||
bool include_peer_to_peer) {
|
||||
if (medium.isListeningForAnyService) {
|
||||
GTMLoggerError(@"Error already listening for service");
|
||||
GNCLoggerError(@"Error already listening for service");
|
||||
return nil;
|
||||
}
|
||||
NSError* error = nil;
|
||||
@@ -177,7 +177,7 @@ GNCNWFrameworkServerSocket* ListenForService(GNCNWFramework* medium, int port,
|
||||
return serverSocket;
|
||||
}
|
||||
if (error != nil) {
|
||||
GTMLoggerError(@"Error listening for service: %@", error);
|
||||
GNCLoggerError(@"Error listening for service: %@", error);
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
@@ -185,7 +185,7 @@ GNCNWFrameworkServerSocket* ListenForService(GNCNWFramework* medium, int port,
|
||||
GNCNWFrameworkServerSocket* ListenForService(GNCNWFramework* medium, const api::PskInfo& psk_info,
|
||||
int port, bool include_peer_to_peer) {
|
||||
if (medium.isListeningForAnyService) {
|
||||
GTMLoggerError(@"Error already listening for service");
|
||||
GNCLoggerError(@"Error already listening for service");
|
||||
return nil;
|
||||
}
|
||||
NSError* error = nil;
|
||||
@@ -203,7 +203,7 @@ GNCNWFrameworkServerSocket* ListenForService(GNCNWFramework* medium, const api::
|
||||
return serverSocket;
|
||||
}
|
||||
if (error != nil) {
|
||||
GTMLoggerError(@"Error listening for service: %@", error);
|
||||
GNCLoggerError(@"Error listening for service: %@", error);
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
#include <utility>
|
||||
|
||||
#import "internal/platform/implementation/apple/Log/GNCLogger.h"
|
||||
#include "internal/platform/implementation/timer.h"
|
||||
#import "GoogleToolboxForMac/GTMLogger.h"
|
||||
|
||||
// The leeway parameter is a hint from the application as to the amount of time, in nanoseconds, up
|
||||
// to which the system can defer the timer to align with other system activity for improved system
|
||||
@@ -33,12 +33,12 @@ Timer::~Timer() { Stop(); }
|
||||
|
||||
bool Timer::Create(int delay, int interval, absl::AnyInvocable<void()> callback) {
|
||||
if (delay < 0 || interval < 0) {
|
||||
GTMLoggerError(@"Delay and interval must be positive or zero.");
|
||||
GNCLoggerError(@"Delay and interval must be positive or zero.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (timer_ != nil) {
|
||||
GTMLoggerError(@"Timer has already started.");
|
||||
GNCLoggerError(@"Timer has already started.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,12 +20,11 @@
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#import "internal/platform/implementation/apple/Mediums/WiFiCommon/GNCIPv4Address.h"
|
||||
#include <arpa/inet.h>
|
||||
#import "internal/platform/implementation/apple/Log/GNCLogger.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/Hotspot/GNCHotspotMedium.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/Hotspot/GNCHotspotSocket.h"
|
||||
#import "GoogleToolboxForMac/GTMLogger.h"
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#import "internal/platform/implementation/apple/Mediums/WiFiCommon/GNCIPv4Address.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace apple {
|
||||
@@ -38,7 +37,7 @@ ExceptionOr<ByteArray> WifiHotspotInputStream::Read(std::int64_t size) {
|
||||
NSError* error = nil;
|
||||
NSData* data = [socket_ readMaxLength:size error:&error];
|
||||
if (data == nil) {
|
||||
GTMLoggerError(@"Error reading socket: %@", error);
|
||||
GNCLoggerError(@"Error reading socket: %@", error);
|
||||
return {Exception::kIo};
|
||||
}
|
||||
return ExceptionOr<ByteArray>{ByteArray((const char*)data.bytes, data.length)};
|
||||
@@ -58,7 +57,7 @@ Exception WifiHotspotOutputStream::Write(const ByteArray& data) {
|
||||
NSError* error = nil;
|
||||
BOOL result = [socket_ write:[NSData dataWithBytes:data.data() length:data.size()] error:&error];
|
||||
if (!result) {
|
||||
GTMLoggerError(@"Error writing socket: %@", error);
|
||||
GNCLoggerError(@"Error writing socket: %@", error);
|
||||
return {Exception::kIo};
|
||||
}
|
||||
return {Exception::kSuccess};
|
||||
@@ -94,31 +93,28 @@ Exception WifiHotspotSocket::Close() {
|
||||
|
||||
#pragma mark - WifiHotspotMedium
|
||||
|
||||
WifiHotspotMedium::WifiHotspotMedium() : medium_([[GNCHotspotMedium alloc] init]) {} // NOLINT
|
||||
WifiHotspotMedium::~WifiHotspotMedium() {
|
||||
DisconnectWifiHotspot();
|
||||
}
|
||||
WifiHotspotMedium::WifiHotspotMedium() : medium_([[GNCHotspotMedium alloc] init]) {} // NOLINT
|
||||
WifiHotspotMedium::~WifiHotspotMedium() { DisconnectWifiHotspot(); }
|
||||
|
||||
bool WifiHotspotMedium::ConnectWifiHotspot(HotspotCredentials* hotspot_credentials_) {
|
||||
NSString* ssid = [[NSString alloc] initWithUTF8String:hotspot_credentials_->GetSSID().c_str()];
|
||||
NSString* password =
|
||||
[[NSString alloc] initWithUTF8String:hotspot_credentials_->GetPassword().c_str()];
|
||||
|
||||
GTMLoggerInfo(@"ConnectWifiHotspot SSID: %@ Password: %@", ssid, password);
|
||||
bool result = [medium_ connectToWifiNetworkWithSSID:ssid
|
||||
password:password];
|
||||
GNCLoggerInfo(@"ConnectWifiHotspot SSID: %@ Password: %@", ssid, password);
|
||||
bool result = [medium_ connectToWifiNetworkWithSSID:ssid password:password];
|
||||
if (result) {
|
||||
GTMLoggerInfo(@"Successfully connected to %@", ssid);
|
||||
GNCLoggerInfo(@"Successfully connected to %@", ssid);
|
||||
hotspot_ssid_ = ssid;
|
||||
} else {
|
||||
GTMLoggerError(@"Failed to connect to %@", ssid);
|
||||
GNCLoggerError(@"Failed to connect to %@", ssid);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool WifiHotspotMedium::DisconnectWifiHotspot() {
|
||||
GTMLoggerInfo(@"DisconnectWifiHotspot SSID: %@", hotspot_ssid_);
|
||||
GNCLoggerInfo(@"DisconnectWifiHotspot SSID: %@", hotspot_ssid_);
|
||||
if (hotspot_ssid_) {
|
||||
[medium_ disconnectToWifiNetworkWithSSID:hotspot_ssid_];
|
||||
hotspot_ssid_ = nil;
|
||||
@@ -143,19 +139,19 @@ std::unique_ptr<api::WifiHotspotSocket> WifiHotspotMedium::ConnectToService(
|
||||
host_ip_address.s_addr = inet_addr(ip_address.data());
|
||||
|
||||
if (host_ip_address.s_addr == INADDR_NONE) {
|
||||
GTMLoggerError(@"Invalid IP address: %.*s\n", (int)ip_address.size(), ip_address.data());
|
||||
return nil;
|
||||
GNCLoggerError(@"Invalid IP address: %.*s\n", (int)ip_address.size(), ip_address.data());
|
||||
return nil;
|
||||
}
|
||||
host = [GNCIPv4Address addressFromFourByteInt:host_ip_address.s_addr];
|
||||
}
|
||||
GTMLoggerInfo(@"Connect to Hotspot host server: %@", [host dottedRepresentation]);
|
||||
GNCLoggerInfo(@"Connect to Hotspot host server: %@", [host dottedRepresentation]);
|
||||
|
||||
GNCHotspotSocket* socket = [medium_ connectToHost:host port:port error:&error];
|
||||
if (socket != nil) {
|
||||
return std::make_unique<WifiHotspotSocket>(socket);
|
||||
}
|
||||
if (error != nil) {
|
||||
GTMLoggerError(@"Error connecting to %@:%d: %@", host, port, error);
|
||||
GNCLoggerError(@"Error connecting to %@:%d: %@", host, port, error);
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
@@ -19,12 +19,12 @@
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#import "internal/platform/implementation/apple/Log/GNCLogger.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/WiFiCommon/GNCIPv4Address.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/WiFiCommon/GNCNWFramework.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/WiFiCommon/GNCNWFrameworkServerSocket.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/WiFiCommon/GNCNWFrameworkSocket.h"
|
||||
#import "internal/platform/implementation/apple/network_utils.h"
|
||||
#import "GoogleToolboxForMac/GTMLogger.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace apple {
|
||||
@@ -37,7 +37,7 @@ ExceptionOr<ByteArray> WifiLanInputStream::Read(std::int64_t size) {
|
||||
NSError* error = nil;
|
||||
NSData* data = [socket_ readMaxLength:size error:&error];
|
||||
if (data == nil) {
|
||||
GTMLoggerError(@"Error reading socket: %@", error);
|
||||
GNCLoggerError(@"Error reading socket: %@", error);
|
||||
return {Exception::kIo};
|
||||
}
|
||||
return ExceptionOr<ByteArray>{ByteArray((const char*)data.bytes, data.length)};
|
||||
@@ -57,7 +57,7 @@ Exception WifiLanOutputStream::Write(const ByteArray& data) {
|
||||
NSError* error = nil;
|
||||
BOOL result = [socket_ write:[NSData dataWithBytes:data.data() length:data.size()] error:&error];
|
||||
if (!result) {
|
||||
GTMLoggerError(@"Error writing socket: %@", error);
|
||||
GNCLoggerError(@"Error writing socket: %@", error);
|
||||
return {Exception::kIo};
|
||||
}
|
||||
return {Exception::kSuccess};
|
||||
@@ -110,7 +110,7 @@ std::unique_ptr<api::WifiLanSocket> WifiLanServerSocket::Accept() {
|
||||
return std::make_unique<WifiLanSocket>(socket);
|
||||
}
|
||||
if (error != nil) {
|
||||
GTMLoggerError(@"Error accepting socket: %@", error);
|
||||
GNCLoggerError(@"Error accepting socket: %@", error);
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user