mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-15 07:06:11 -04:00
Start adding basic types for the Swift layer
PiperOrigin-RevId: 489559926
This commit is contained in:
committed by
Copybara-Service
parent
fcacb61b7c
commit
9020f528ff
@@ -25,6 +25,7 @@ swift_library(
|
||||
module_name = "NearbyConnections",
|
||||
deps = [
|
||||
"//connections/clients/swift/NearbyCoreAdapter",
|
||||
"//third_party/apple_frameworks:Foundation",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
// 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 NearbyCoreAdapter
|
||||
|
||||
/// Token used to cancel a transfer.
|
||||
public class CancellationToken {
|
||||
internal let payloadID: Int64
|
||||
|
||||
internal init(_ payloadID: Int64) {
|
||||
self.payloadID = payloadID
|
||||
}
|
||||
|
||||
/// Cancel the ongoing transfer.
|
||||
public func cancel() {
|
||||
// TODO(b/257824412): Handle errors from completion handler.
|
||||
GNCCoreAdapter.shared.cancelPayload(payloadID)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// 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.
|
||||
|
||||
/// Indicates the current status of the connection between a local and remote endpoint.
|
||||
public enum ConnectionState {
|
||||
/// A connection to the remote endpoint is currently being established.
|
||||
case connecting
|
||||
/// The local endpoint is currently connected to the remote endpoint.
|
||||
case connected
|
||||
/// The remote endpoint is no longer connected.
|
||||
case disconnected
|
||||
/// The local or remote endpoint has rejected the connection request.
|
||||
case rejected
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// 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.
|
||||
|
||||
/// Used to represent an enpoint.
|
||||
public typealias EndpointID = String
|
||||
@@ -0,0 +1,25 @@
|
||||
// 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 NearbyCoreAdapter
|
||||
|
||||
/// Used to represent a payload.
|
||||
public typealias PayloadID = Int64
|
||||
|
||||
extension PayloadID {
|
||||
/// A convenience method for generating a unique payload ID.
|
||||
public static func unique() -> PayloadID {
|
||||
return GNCPayload.generateID()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
// 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 NearbyCoreAdapter
|
||||
|
||||
/// Indicates the connection strategy and restrictions for advertisement or discovery.
|
||||
///
|
||||
/// - Note: Only a subset of mediums are supported by certain strategies as depicted in the table
|
||||
/// below. Generally, more restrictive strategies have better medium support.
|
||||
///
|
||||
/// | | BT Classic | BLE | LAN | Aware | NFC | USB | Hotspot | Direct | 5GHz WiFi |
|
||||
/// |--------------|:----------:|:---:|:---:|:-----:|:---:|:---:|:-------:|:------:|:---------:|
|
||||
/// | cluster | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | × | × | × |
|
||||
/// | star | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | × |
|
||||
/// | pointToPoint | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||
///
|
||||
/// - Important: In order to discover another endpoint, the remote endpoint must be advertising
|
||||
/// using the same strategy.
|
||||
public enum Strategy {
|
||||
/// No restrictions on the amount of incoming and outgoing connections.
|
||||
case cluster
|
||||
/// Restricts the discoverer to a single connection, while advertisers have no restrictions on
|
||||
/// amount of connections.
|
||||
case star
|
||||
/// Restricts both adverisers and discoverers to a single connection.
|
||||
case pointToPoint
|
||||
|
||||
internal var objc: NearbyCoreAdapter.Strategy {
|
||||
switch self {
|
||||
case .cluster: return .cluster
|
||||
case .star: return .star
|
||||
case .pointToPoint: return .pointToPoint
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// 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
|
||||
|
||||
/// Indicates the current status of the transfer.
|
||||
public enum TransferUpdate {
|
||||
/// The remote endpoint has successfully received the full transfer.
|
||||
case success
|
||||
/// Either the local or remote endpoint has canceled the transfer.
|
||||
case canceled
|
||||
/// The remote endpoint failed to receive the transfer with the associated error.
|
||||
case failure(Error)
|
||||
/// The the transfer is currently in progress with an associated progress value.
|
||||
case progress(Progress)
|
||||
}
|
||||
Reference in New Issue
Block a user