mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 22:56:12 -04:00
Add all options to GNCAdvertisingOptions, GNCDiscoveryOptions, and GNCConnectionOptions.
PiperOrigin-RevId: 515153199
This commit is contained in:
@@ -36,6 +36,7 @@ objc_library(
|
||||
"//internal/platform/implementation/apple", # buildcleaner: keep
|
||||
"//third_party/apple_frameworks:Foundation",
|
||||
"//third_party/apple_frameworks:ObjectiveC",
|
||||
"//third_party/objective_c/google_toolbox_for_mac:GTM_Logger",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
+14
-4
@@ -12,14 +12,13 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#import "connections/swift/NearbyCoreAdapter/Sources/Public/NearbyCoreAdapter/GNCAdvertisingOptions.h"
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "connections/swift/NearbyCoreAdapter/Sources/GNCAdvertisingOptions+CppConversions.h"
|
||||
|
||||
#include "connections/advertising_options.h"
|
||||
|
||||
#import "connections/swift/NearbyCoreAdapter/Sources/GNCAdvertisingOptions+CppConversions.h"
|
||||
#import "connections/swift/NearbyCoreAdapter/Sources/GNCStrategy+Internal.h"
|
||||
#import "connections/swift/NearbyCoreAdapter/Sources/GNCSupportedMediums+CppConversions.h"
|
||||
#import "GoogleToolboxForMac/GTMLogger.h"
|
||||
|
||||
using ::nearby::connections::AdvertisingOptions;
|
||||
using ::nearby::connections::CppStrategyFromGNCStrategy;
|
||||
@@ -28,7 +27,18 @@ using ::nearby::connections::CppStrategyFromGNCStrategy;
|
||||
|
||||
- (AdvertisingOptions)toCpp {
|
||||
AdvertisingOptions advertising_options;
|
||||
|
||||
advertising_options.strategy = CppStrategyFromGNCStrategy(self.strategy);
|
||||
advertising_options.allowed = [self.mediums toCpp];
|
||||
|
||||
advertising_options.auto_upgrade_bandwidth = self.autoUpgradeBandwidth;
|
||||
advertising_options.low_power = self.lowPower;
|
||||
advertising_options.enforce_topology_constraints = self.enforceTopologyConstraints;
|
||||
if (self.enforceTopologyConstraints) {
|
||||
GTMLoggerError(@"WARNING: Creating ConnectionOptions with enforceTopologyConstraints = true. "
|
||||
"Make sure you know what you're doing!");
|
||||
}
|
||||
|
||||
return advertising_options;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,8 +14,7 @@
|
||||
|
||||
#import "connections/swift/NearbyCoreAdapter/Sources/Public/NearbyCoreAdapter/GNCAdvertisingOptions.h"
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "connections/swift/NearbyCoreAdapter/Sources/Public/NearbyCoreAdapter/GNCSupportedMediums.h"
|
||||
#import "connections/swift/NearbyCoreAdapter/Sources/Public/NearbyCoreAdapter/GNCStrategy.h"
|
||||
|
||||
@implementation GNCAdvertisingOptions
|
||||
@@ -24,6 +23,8 @@
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_strategy = strategy;
|
||||
_autoUpgradeBandwidth = YES;
|
||||
_mediums = [[GNCSupportedMediums alloc] initWithAllMediumsEnabled];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@@ -12,8 +12,6 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "connections/swift/NearbyCoreAdapter/Sources/Public/NearbyCoreAdapter/GNCConnectionOptions.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -12,20 +12,38 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#import "connections/swift/NearbyCoreAdapter/Sources/Public/NearbyCoreAdapter/GNCConnectionOptions.h"
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "connections/swift/NearbyCoreAdapter/Sources/GNCConnectionOptions+CppConversions.h"
|
||||
|
||||
#include "connections/connection_options.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
|
||||
#import "connections/swift/NearbyCoreAdapter/Sources/GNCConnectionOptions+CppConversions.h"
|
||||
#import "connections/swift/NearbyCoreAdapter/Sources/GNCSupportedMediums+CppConversions.h"
|
||||
#import "GoogleToolboxForMac/GTMLogger.h"
|
||||
|
||||
using ::nearby::connections::ConnectionOptions;
|
||||
|
||||
@implementation GNCConnectionOptions (CppConversions)
|
||||
|
||||
- (ConnectionOptions)toCpp {
|
||||
return ConnectionOptions{};
|
||||
ConnectionOptions connection_options;
|
||||
|
||||
connection_options.allowed = [self.mediums toCpp];
|
||||
|
||||
connection_options.auto_upgrade_bandwidth = self.autoUpgradeBandwidth;
|
||||
connection_options.low_power = self.lowPower;
|
||||
connection_options.enforce_topology_constraints = self.enforceTopologyConstraints;
|
||||
if (self.enforceTopologyConstraints) {
|
||||
GTMLoggerError(@"WARNING: Creating ConnectionOptions with enforceTopologyConstraints = true. "
|
||||
"Make sure you know what you're doing!");
|
||||
}
|
||||
|
||||
connection_options.keep_alive_interval_millis = self.keepAliveIntervalInSeconds * 1000;
|
||||
connection_options.keep_alive_timeout_millis = self.keepAliveTimeoutInSeconds * 1000;
|
||||
|
||||
connection_options.remote_bluetooth_mac_address = nearby::ByteArray(
|
||||
(char *)[self.remoteBluetoothMACAddress bytes], [self.remoteBluetoothMACAddress length]);
|
||||
|
||||
return connection_options;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -14,8 +14,17 @@
|
||||
|
||||
#import "connections/swift/NearbyCoreAdapter/Sources/Public/NearbyCoreAdapter/GNCConnectionOptions.h"
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "connections/swift/NearbyCoreAdapter/Sources/Public/NearbyCoreAdapter/GNCSupportedMediums.h"
|
||||
|
||||
@implementation GNCConnectionOptions
|
||||
|
||||
- (instancetype)init {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_autoUpgradeBandwidth = YES;
|
||||
_mediums = [[GNCSupportedMediums alloc] initWithAllMediumsEnabled];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -12,14 +12,12 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#import "connections/swift/NearbyCoreAdapter/Sources/Public/NearbyCoreAdapter/GNCDiscoveryOptions.h"
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "connections/swift/NearbyCoreAdapter/Sources/GNCDiscoveryOptions+CppConversions.h"
|
||||
|
||||
#include "connections/discovery_options.h"
|
||||
|
||||
#import "connections/swift/NearbyCoreAdapter/Sources/GNCDiscoveryOptions+CppConversions.h"
|
||||
#import "connections/swift/NearbyCoreAdapter/Sources/GNCStrategy+Internal.h"
|
||||
#import "connections/swift/NearbyCoreAdapter/Sources/GNCSupportedMediums+CppConversions.h"
|
||||
|
||||
using ::nearby::connections::CppStrategyFromGNCStrategy;
|
||||
using ::nearby::connections::DiscoveryOptions;
|
||||
@@ -28,7 +26,13 @@ using ::nearby::connections::DiscoveryOptions;
|
||||
|
||||
- (DiscoveryOptions)toCpp {
|
||||
DiscoveryOptions discovery_options;
|
||||
|
||||
discovery_options.strategy = CppStrategyFromGNCStrategy(self.strategy);
|
||||
discovery_options.allowed = [self.mediums toCpp];
|
||||
|
||||
discovery_options.enforce_topology_constraints = self.enforceTopologyConstraints;
|
||||
discovery_options.low_power = self.lowPower;
|
||||
|
||||
return discovery_options;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,8 +14,7 @@
|
||||
|
||||
#import "connections/swift/NearbyCoreAdapter/Sources/Public/NearbyCoreAdapter/GNCDiscoveryOptions.h"
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "connections/swift/NearbyCoreAdapter/Sources/Public/NearbyCoreAdapter/GNCSupportedMediums.h"
|
||||
#import "connections/swift/NearbyCoreAdapter/Sources/Public/NearbyCoreAdapter/GNCStrategy.h"
|
||||
|
||||
@implementation GNCDiscoveryOptions
|
||||
@@ -24,6 +23,7 @@
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_strategy = strategy;
|
||||
_mediums = [[GNCSupportedMediums alloc] initWithAllMediumsEnabled];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
// Copyright 2022 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#import "connections/swift/NearbyCoreAdapter/Sources/Public/NearbyCoreAdapter/GNCSupportedMediums.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
namespace nearby {
|
||||
namespace connections {
|
||||
|
||||
template <typename T>
|
||||
class MediumSelector;
|
||||
|
||||
using BooleanMediumSelector = MediumSelector<bool>;
|
||||
|
||||
} // namespace connections
|
||||
} // namespace nearby
|
||||
|
||||
#endif
|
||||
|
||||
@interface GNCSupportedMediums (CppConversions)
|
||||
|
||||
#ifdef __cplusplus
|
||||
- (nearby::connections::BooleanMediumSelector)toCpp;
|
||||
#endif
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,38 @@
|
||||
// Copyright 2022 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#import "connections/swift/NearbyCoreAdapter/Sources/GNCSupportedMediums+CppConversions.h"
|
||||
|
||||
#include "connections/medium_selector.h"
|
||||
|
||||
#import "connections/swift/NearbyCoreAdapter/Sources/GNCStrategy+Internal.h"
|
||||
|
||||
using ::nearby::connections::BooleanMediumSelector;
|
||||
|
||||
@implementation GNCSupportedMediums (CppConversions)
|
||||
|
||||
- (BooleanMediumSelector)toCpp {
|
||||
BooleanMediumSelector selector;
|
||||
|
||||
selector.ble = self.ble;
|
||||
selector.bluetooth = self.bluetooth;
|
||||
selector.web_rtc = self.webRTC;
|
||||
selector.wifi_lan = self.wifiLAN;
|
||||
selector.wifi_hotspot = self.wifiHotspot;
|
||||
selector.wifi_direct = self.wifiDirect;
|
||||
|
||||
return selector;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,41 @@
|
||||
// Copyright 2022 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#import "connections/swift/NearbyCoreAdapter/Sources/Public/NearbyCoreAdapter/GNCSupportedMediums.h"
|
||||
|
||||
@implementation GNCSupportedMediums
|
||||
|
||||
- (instancetype)initWithAllMediumsEnabled {
|
||||
return [self initWithBluetooth:YES ble:YES webRTC:YES wifiLAN:YES wifiHotspot:YES wifiDirect:YES];
|
||||
}
|
||||
|
||||
- (instancetype)initWithBluetooth:(BOOL)bluetooth
|
||||
ble:(BOOL)ble
|
||||
webRTC:(BOOL)webRTC
|
||||
wifiLAN:(BOOL)wifiLAN
|
||||
wifiHotspot:(BOOL)wifiHotspot
|
||||
wifiDirect:(BOOL)wifiDirect {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_bluetooth = bluetooth;
|
||||
_ble = ble;
|
||||
_webRTC = webRTC;
|
||||
_wifiLAN = wifiLAN;
|
||||
_wifiHotspot = wifiHotspot;
|
||||
_wifiDirect = wifiDirect;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
+24
-10
@@ -14,23 +14,35 @@
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@class GNCSupportedMediums;
|
||||
|
||||
typedef NS_CLOSED_ENUM(NSInteger, GNCStrategy);
|
||||
|
||||
// TODO(b/239609583): Current sdk only exposes `strategy`, but we should add full support.
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
/**
|
||||
* A @c GNCAdvertisingOptions object represents the configuration for local endpoint advertisement.
|
||||
* A @c GNCAdvertisingOptions object represents the configuration for local
|
||||
* endpoint advertisement.
|
||||
*/
|
||||
@interface GNCAdvertisingOptions : NSObject
|
||||
|
||||
/**
|
||||
* The connection strategy.
|
||||
*/
|
||||
/** The @c GNCStrategy advertising strategy. */
|
||||
@property(nonatomic, readonly) GNCStrategy strategy;
|
||||
|
||||
/**
|
||||
* @remark init is not an available initializer.
|
||||
*/
|
||||
- (nonnull instancetype)init NS_UNAVAILABLE;
|
||||
/** Defines which mediums are supported for advertising. */
|
||||
@property(nonatomic) GNCSupportedMediums* mediums;
|
||||
|
||||
/** Whether bandwidth should automatically upgrade. */
|
||||
@property(nonatomic) BOOL autoUpgradeBandwidth;
|
||||
|
||||
/** Whether topology constraints should be enforced. */
|
||||
@property(nonatomic) BOOL enforceTopologyConstraints;
|
||||
|
||||
/** Whether low power should be used. */
|
||||
@property(nonatomic) BOOL lowPower;
|
||||
|
||||
/** @remark init is not an available initializer. */
|
||||
- (instancetype)init NS_UNAVAILABLE;
|
||||
|
||||
/**
|
||||
* Creates an advertising options object.
|
||||
@@ -39,6 +51,8 @@ typedef NS_CLOSED_ENUM(NSInteger, GNCStrategy);
|
||||
*
|
||||
* @return The initialized options object, or nil if an error occurs.
|
||||
*/
|
||||
- (nonnull instancetype)initWithStrategy:(GNCStrategy)strategy NS_DESIGNATED_INITIALIZER;
|
||||
- (instancetype)initWithStrategy:(GNCStrategy)strategy NS_DESIGNATED_INITIALIZER;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
+35
-2
@@ -14,10 +14,43 @@
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
// TODO(b/239610255): Current sdk doesn't expose anything, but we should add full support.
|
||||
@class GNCSupportedMediums;
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
/**
|
||||
* A @c GNCConnectionOptions object represents the configuration for connecting to remote endpoints.
|
||||
* A @c GNCConnectionOptions object represents the configuration for connecting
|
||||
* to remote endpoints.
|
||||
*/
|
||||
@interface GNCConnectionOptions : NSObject
|
||||
|
||||
/** The @c GNCStrategy advertising strategy. */
|
||||
@property(nonatomic) GNCSupportedMediums* mediums;
|
||||
|
||||
/** Whether bandwidth should automatically upgrade. */
|
||||
@property(nonatomic) BOOL autoUpgradeBandwidth;
|
||||
|
||||
/** Whether topology constraints should be enforced. */
|
||||
@property(nonatomic) BOOL enforceTopologyConstraints;
|
||||
|
||||
/** Whether low power should be used. */
|
||||
@property(nonatomic) BOOL lowPower;
|
||||
|
||||
/** The remote bluetooth MAC address for this connection. */
|
||||
@property(nonatomic, nullable) NSData* remoteBluetoothMACAddress;
|
||||
|
||||
/** How often to send a keep alive message, in seconds. */
|
||||
@property(nonatomic) NSTimeInterval keepAliveIntervalInSeconds;
|
||||
|
||||
/**
|
||||
* How long to wait without receiving a keep alive message before timing out,
|
||||
* in seconds.
|
||||
*/
|
||||
@property(nonatomic) NSTimeInterval keepAliveTimeoutInSeconds;
|
||||
|
||||
/** @remark create a connection options class. */
|
||||
- (instancetype)init NS_DESIGNATED_INITIALIZER;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
+21
-10
@@ -14,23 +14,32 @@
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@class GNCSupportedMediums;
|
||||
|
||||
typedef NS_CLOSED_ENUM(NSInteger, GNCStrategy);
|
||||
|
||||
// TODO(b/239610253): Current sdk only exposes `strategy`, but we should add full support.
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
/**
|
||||
* A @c GNCDiscoveryOptions object represents the configuration for remote endpoint discovery.
|
||||
* A @c GNCDiscoveryOptions object represents the configuration for remote
|
||||
* endpoint discovery.
|
||||
*/
|
||||
@interface GNCDiscoveryOptions : NSObject
|
||||
|
||||
/**
|
||||
* The connection strategy.
|
||||
*/
|
||||
/** The @c GNCStrategy advertising strategy. */
|
||||
@property(nonatomic, readonly) GNCStrategy strategy;
|
||||
|
||||
/**
|
||||
* @remark init is not an available initializer.
|
||||
*/
|
||||
- (nonnull instancetype)init NS_UNAVAILABLE;
|
||||
/** Defines which mediums are supported for advertising.*/
|
||||
@property(nonatomic) GNCSupportedMediums* mediums;
|
||||
|
||||
/** Whether topology constraints should be enforced. */
|
||||
@property(nonatomic) BOOL enforceTopologyConstraints;
|
||||
|
||||
/** Whether low power should be used. */
|
||||
@property(nonatomic) BOOL lowPower;
|
||||
|
||||
/** @remark init is not an available initializer. */
|
||||
- (instancetype)init NS_UNAVAILABLE;
|
||||
|
||||
/**
|
||||
* Creates a discovery options object.
|
||||
@@ -39,6 +48,8 @@ typedef NS_CLOSED_ENUM(NSInteger, GNCStrategy);
|
||||
*
|
||||
* @return The initialized options object, or nil if an error occurs.
|
||||
*/
|
||||
- (nonnull instancetype)initWithStrategy:(GNCStrategy)strategy NS_DESIGNATED_INITIALIZER;
|
||||
- (instancetype)initWithStrategy:(GNCStrategy)strategy NS_DESIGNATED_INITIALIZER;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
// Copyright 2022 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface GNCSupportedMediums : NSObject
|
||||
- (instancetype)init NS_UNAVAILABLE;
|
||||
|
||||
/** Initializes with all mediums being supported. */
|
||||
- (instancetype)initWithAllMediumsEnabled;
|
||||
|
||||
/** Initializes, setting properties to the provided values. */
|
||||
- (instancetype)initWithBluetooth:(BOOL)bluetooth
|
||||
ble:(BOOL)ble
|
||||
webRTC:(BOOL)webRTC
|
||||
wifiLAN:(BOOL)wifiLAN
|
||||
wifiHotspot:(BOOL)wifiHotspot
|
||||
wifiDirect:(BOOL)wifiDirect NS_DESIGNATED_INITIALIZER;
|
||||
|
||||
@property(nonatomic) BOOL bluetooth;
|
||||
@property(nonatomic) BOOL ble;
|
||||
@property(nonatomic) BOOL webRTC;
|
||||
@property(nonatomic) BOOL wifiLAN;
|
||||
@property(nonatomic) BOOL wifiHotspot;
|
||||
@property(nonatomic) BOOL wifiDirect;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
+1
@@ -22,3 +22,4 @@
|
||||
#import "GNCPayload.h"
|
||||
#import "GNCPayloadDelegate.h"
|
||||
#import "GNCStrategy.h"
|
||||
#import "GNCSupportedMediums.h"
|
||||
|
||||
Reference in New Issue
Block a user