mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Separation of ConnectionOptions into a header and an implementation file.
PiperOrigin-RevId: 403486468
This commit is contained in:
committed by
Copybara-Service
parent
f20e7de4e7
commit
d7f0f1b635
+6
-46
@@ -103,67 +103,27 @@ struct DLL_API ConnectionOptions {
|
||||
int keep_alive_timeout_millis = 0;
|
||||
|
||||
// Verify if ConnectionOptions is in a not-initialized (Empty) state.
|
||||
bool Empty() const { return strategy.IsNone(); }
|
||||
bool Empty() const;
|
||||
|
||||
// Bring ConnectionOptions to a not-initialized (Empty) state.
|
||||
void Clear() { strategy.Clear(); }
|
||||
void Clear();
|
||||
|
||||
// Returns a copy and normalizes allowed mediums:
|
||||
// (1) If is_out_of_band_connection is true, verifies that there is only one
|
||||
// medium allowed, defaulting to only Bluetooth if unspecified.
|
||||
// (2) If no mediums are allowed, allow all mediums.
|
||||
ConnectionOptions CompatibleOptions() const {
|
||||
ConnectionOptions result = *this;
|
||||
ConnectionOptions CompatibleOptions() const;
|
||||
|
||||
// Out-of-band connections initiate connections via an injected endpoint
|
||||
// rather than through the normal discovery flow. These types of connections
|
||||
// can only be injected via a single medium.
|
||||
if (is_out_of_band_connection) {
|
||||
int num_enabled = result.allowed.Count(true);
|
||||
|
||||
// Default to allow only Bluetooth if no single medium is specified.
|
||||
if (num_enabled != 1) {
|
||||
result.allowed.SetAll(false);
|
||||
result.allowed.bluetooth = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Normal connections (i.e., not out-of-band) connections can specify
|
||||
// multiple mediums. If none are specified, default to allowing all mediums.
|
||||
if (!allowed.Any(true)) result.allowed.SetAll(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<Medium> GetMediums() const { return allowed.GetMediums(true); }
|
||||
std::vector<Medium> GetMediums() const;
|
||||
|
||||
// This call follows the standard Microsoft calling pattern of calling first
|
||||
// to get the size of the array. Caller then allocates memory for the array,
|
||||
// and makes this call again to copy the array into the provided location.
|
||||
void GetMediums(location::nearby::proto::connections::Medium* mediums,
|
||||
uint32_t* mediumsSize) {
|
||||
auto size = GetMediums().size();
|
||||
|
||||
// Caller is seeking the size of mediums
|
||||
if (mediums == nullptr) {
|
||||
*mediumsSize = size;
|
||||
return;
|
||||
}
|
||||
|
||||
// Caller has not specified enough memory
|
||||
if (*mediumsSize < size) {
|
||||
mediums = nullptr; // ensure nullptr return
|
||||
*mediumsSize = size; // update the size to indicate the correct size
|
||||
return;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < size; i++) {
|
||||
// Construct an array at the given location
|
||||
mediums[i] = GetMediums().at(i);
|
||||
}
|
||||
}
|
||||
uint32_t* mediumsSize);
|
||||
};
|
||||
|
||||
|
||||
// Metadata injected to facilitate out-of-band connections. The medium field is
|
||||
// required, and the other fields are only specified for a specific medium.
|
||||
// Currently, Bluetooth is the only supported medium for out-of-band
|
||||
|
||||
Reference in New Issue
Block a user