The information advertised by the remote endpoint might not be a human readable string. This CL adds an endpointInfo property to the GNCDiscoveredEndpointInfo object, which is used to get the raw byte array that was advertised.

For consistency with the Android API, `name` has also been renamed to `endpointName`.

PiperOrigin-RevId: 416347703
This commit is contained in:
bourdakos
2021-12-21 14:47:31 -08:00
committed by hai007
parent 2e316588f7
commit d29b05c367
2 changed files with 13 additions and 6 deletions
+5 -3
View File
@@ -48,10 +48,12 @@ typedef void (^GNCConnectionRequester)(
NSString *name, GNCDiscovererConnectionInitializationHandler connectionAuthorizationHandler,
GNCConnectionFailureHandler failureHandler);
/** This contains info about a discovered advertiser endpoint. */
/** Information about an endpoint when it's discovered. */
@protocol GNCDiscoveredEndpointInfo <NSObject>
/** This is a human readable name of the advertiser. */
@property(nonatomic, readonly, copy) NSString *name;
/** The human readable name of the remote endpoint. */
@property(nonatomic, readonly, copy) NSString *endpointName;
/** Information advertised by the remote endpoint. */
@property(nonatomic, readonly, copy) NSData *endpointInfo;
/** Call this block to request a connection with the advertiser. */
@property(nonatomic, readonly) GNCConnectionRequester requestConnection;
@end
@@ -62,17 +62,20 @@ using ::location::nearby::connections::Status;
/** This is a GNCDiscoveredEndpointInfo that provides storage for its properties. */
@interface GNCDiscoveredEndpointInfo : NSObject <GNCDiscoveredEndpointInfo>
@property(nonatomic, copy) NSString *name;
@property(nonatomic, copy) NSString *endpointName;
@property(nonatomic, copy) NSData *endpointInfo;
@end
@implementation GNCDiscoveredEndpointInfo
@synthesize requestConnection = _requestConnection;
+ (instancetype)infoWithName:(NSString *)name
+ (instancetype)infoWithName:(NSString *)endpointName
endpointInfo:(NSData *)endpointInfo
requestConnection:(GNCConnectionRequester)requestConnection {
GNCDiscoveredEndpointInfo *info = [[GNCDiscoveredEndpointInfo alloc] init];
info.name = name;
info.endpointName = endpointName;
info.endpointInfo = endpointInfo;
info->_requestConnection = requestConnection;
return info;
}
@@ -271,10 +274,12 @@ class GNCDiscoveryListener {
// TODO(b/169292092): endpointInfo is an advertisement byte array. Need to implement to
// extract the endpoint name not just force to cast string.
NSString *name = ObjCStringFromCppString(std::string(endpoint_info));
NSData *info = NSDataFromByteArray(endpoint_info);
GNCCore *core = discoverer.core; // don't capture |this| or |discoverer|
NSMapTable<GNCEndpointId, GNCDiscovererEndpointInfo *> *endpoints = discoverer.endpoints;
GNCDiscoveredEndpointInfo *discEndpointInfo = [GNCDiscoveredEndpointInfo
infoWithName:name
endpointInfo:info
requestConnection:^(NSString *name,
GNCDiscovererConnectionInitializationHandler connInitHandler,
GNCConnectionFailureHandler connFailureHandler) {