google_cloud_devicestreaming_v1/
client.rs

1// Copyright 2025 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// Code generated by sidekick. DO NOT EDIT.
16#![allow(rustdoc::redundant_explicit_links)]
17#![allow(rustdoc::broken_intra_doc_links)]
18
19/// Implements a client for the Device Streaming API.
20///
21/// # Example
22/// ```
23/// # tokio_test::block_on(async {
24/// # use google_cloud_devicestreaming_v1::client::DirectAccessService;
25/// let client = DirectAccessService::builder().build().await?;
26/// // use `client` to make requests to the Device Streaming API.
27/// # gax::client_builder::Result::<()>::Ok(()) });
28/// ```
29///
30/// # Service Description
31///
32/// A service for allocating Android devices and interacting with the
33/// live-allocated devices.
34///
35/// Each Session will wait for available capacity, at a higher
36/// priority over Test Execution. When allocated, the session will be exposed
37/// through a stream for integration.
38///
39/// DirectAccessService is currently available as a preview to select developers.
40/// You can register today on behalf of you and your team at
41/// <https://developer.android.com/studio/preview/android-device-streaming>
42///
43/// # Configuration
44///
45/// To configure `DirectAccessService` use the `with_*` methods in the type returned
46/// by [builder()][DirectAccessService::builder]. The default configuration should
47/// work for most applications. Common configuration changes include
48///
49/// * [with_endpoint()]: by default this client uses the global default endpoint
50///   (`https://devicestreaming.googleapis.com`). Applications using regional
51///   endpoints or running in restricted networks (e.g. a network configured
52//    with [Private Google Access with VPC Service Controls]) may want to
53///   override this default.
54/// * [with_credentials()]: by default this client uses
55///   [Application Default Credentials]. Applications using custom
56///   authentication may need to override this default.
57///
58/// [with_endpoint()]: super::builder::direct_access_service::ClientBuilder::with_endpoint
59/// [with_credentials()]: super::builder::direct_access_service::ClientBuilder::credentials
60/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
61/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
62///
63/// # Pooling and Cloning
64///
65/// `DirectAccessService` holds a connection pool internally, it is advised to
66/// create one and the reuse it.  You do not need to wrap `DirectAccessService` in
67/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
68/// already uses an `Arc` internally.
69#[derive(Clone, Debug)]
70pub struct DirectAccessService {
71    inner: std::sync::Arc<dyn super::stub::dynamic::DirectAccessService>,
72}
73
74impl DirectAccessService {
75    /// Returns a builder for [DirectAccessService].
76    ///
77    /// ```
78    /// # tokio_test::block_on(async {
79    /// # use google_cloud_devicestreaming_v1::client::DirectAccessService;
80    /// let client = DirectAccessService::builder().build().await?;
81    /// # gax::client_builder::Result::<()>::Ok(()) });
82    /// ```
83    pub fn builder() -> super::builder::direct_access_service::ClientBuilder {
84        gax::client_builder::internal::new_builder(
85            super::builder::direct_access_service::client::Factory,
86        )
87    }
88
89    /// Creates a new client from the provided stub.
90    ///
91    /// The most common case for calling this function is in tests mocking the
92    /// client's behavior.
93    pub fn from_stub<T>(stub: T) -> Self
94    where
95        T: super::stub::DirectAccessService + 'static,
96    {
97        Self {
98            inner: std::sync::Arc::new(stub),
99        }
100    }
101
102    pub(crate) async fn new(
103        config: gaxi::options::ClientConfig,
104    ) -> gax::client_builder::Result<Self> {
105        let inner = Self::build_inner(config).await?;
106        Ok(Self { inner })
107    }
108
109    async fn build_inner(
110        conf: gaxi::options::ClientConfig,
111    ) -> gax::client_builder::Result<std::sync::Arc<dyn super::stub::dynamic::DirectAccessService>>
112    {
113        if gaxi::options::tracing_enabled(&conf) {
114            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
115        }
116        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
117    }
118
119    async fn build_transport(
120        conf: gaxi::options::ClientConfig,
121    ) -> gax::client_builder::Result<impl super::stub::DirectAccessService> {
122        super::transport::DirectAccessService::new(conf).await
123    }
124
125    async fn build_with_tracing(
126        conf: gaxi::options::ClientConfig,
127    ) -> gax::client_builder::Result<impl super::stub::DirectAccessService> {
128        Self::build_transport(conf)
129            .await
130            .map(super::tracing::DirectAccessService::new)
131    }
132
133    /// Creates a DeviceSession.
134    pub fn create_device_session(
135        &self,
136    ) -> super::builder::direct_access_service::CreateDeviceSession {
137        super::builder::direct_access_service::CreateDeviceSession::new(self.inner.clone())
138    }
139
140    /// Lists DeviceSessions owned by the project user.
141    pub fn list_device_sessions(
142        &self,
143    ) -> super::builder::direct_access_service::ListDeviceSessions {
144        super::builder::direct_access_service::ListDeviceSessions::new(self.inner.clone())
145    }
146
147    /// Gets a DeviceSession, which documents the allocation status and
148    /// whether the device is allocated. Clients making requests from this API
149    /// must poll GetDeviceSession.
150    pub fn get_device_session(&self) -> super::builder::direct_access_service::GetDeviceSession {
151        super::builder::direct_access_service::GetDeviceSession::new(self.inner.clone())
152    }
153
154    /// Cancel a DeviceSession.
155    /// This RPC changes the DeviceSession to state FINISHED and terminates all
156    /// connections.
157    /// Canceled sessions are not deleted and can be retrieved or
158    /// listed by the user until they expire based on the 28 day deletion policy.
159    pub fn cancel_device_session(
160        &self,
161    ) -> super::builder::direct_access_service::CancelDeviceSession {
162        super::builder::direct_access_service::CancelDeviceSession::new(self.inner.clone())
163    }
164
165    /// Updates the current DeviceSession to the fields described by the
166    /// update_mask.
167    pub fn update_device_session(
168        &self,
169    ) -> super::builder::direct_access_service::UpdateDeviceSession {
170        super::builder::direct_access_service::UpdateDeviceSession::new(self.inner.clone())
171    }
172}