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/// # use google_cloud_devicestreaming_v1::client::DirectAccessService;
24/// use google_cloud_gax::paginator::ItemPaginator as _;
25/// async fn sample(
26/// parent: &str,
27/// ) -> anyhow::Result<()> {
28/// let client = DirectAccessService::builder().build().await?;
29/// let mut list = client.list_device_sessions()
30/// .set_parent(parent)
31/// .by_item();
32/// while let Some(item) = list.next().await.transpose()? {
33/// println!("{:?}", item);
34/// }
35/// Ok(())
36/// }
37/// ```
38///
39/// # Service Description
40///
41/// A service for allocating Android devices and interacting with the
42/// live-allocated devices.
43///
44/// Each Session will wait for available capacity, at a higher
45/// priority over Test Execution. When allocated, the session will be exposed
46/// through a stream for integration.
47///
48/// DirectAccessService is currently available as a preview to select developers.
49/// You can register today on behalf of you and your team at
50/// <https://developer.android.com/studio/preview/android-device-streaming>
51///
52/// # Configuration
53///
54/// To configure `DirectAccessService` use the `with_*` methods in the type returned
55/// by [builder()][DirectAccessService::builder]. The default configuration should
56/// work for most applications. Common configuration changes include
57///
58/// * [with_endpoint()]: by default this client uses the global default endpoint
59/// (`https://devicestreaming.googleapis.com`). Applications using regional
60/// endpoints or running in restricted networks (e.g. a network configured
61// with [Private Google Access with VPC Service Controls]) may want to
62/// override this default.
63/// * [with_credentials()]: by default this client uses
64/// [Application Default Credentials]. Applications using custom
65/// authentication may need to override this default.
66///
67/// [with_endpoint()]: super::builder::direct_access_service::ClientBuilder::with_endpoint
68/// [with_credentials()]: super::builder::direct_access_service::ClientBuilder::with_credentials
69/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
70/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
71///
72/// # Pooling and Cloning
73///
74/// `DirectAccessService` holds a connection pool internally, it is advised to
75/// create one and reuse it. You do not need to wrap `DirectAccessService` in
76/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
77/// already uses an `Arc` internally.
78#[derive(Clone, Debug)]
79pub struct DirectAccessService {
80 inner: std::sync::Arc<dyn super::stub::dynamic::DirectAccessService>,
81}
82
83impl DirectAccessService {
84 /// Returns a builder for [DirectAccessService].
85 ///
86 /// ```
87 /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
88 /// # use google_cloud_devicestreaming_v1::client::DirectAccessService;
89 /// let client = DirectAccessService::builder().build().await?;
90 /// # Ok(()) }
91 /// ```
92 pub fn builder() -> super::builder::direct_access_service::ClientBuilder {
93 crate::new_client_builder(super::builder::direct_access_service::client::Factory)
94 }
95
96 /// Creates a new client from the provided stub.
97 ///
98 /// The most common case for calling this function is in tests mocking the
99 /// client's behavior.
100 pub fn from_stub<T>(stub: impl Into<std::sync::Arc<T>>) -> Self
101 where
102 T: super::stub::DirectAccessService + 'static,
103 {
104 Self { inner: stub.into() }
105 }
106
107 pub(crate) async fn new(
108 config: gaxi::options::ClientConfig,
109 ) -> crate::ClientBuilderResult<Self> {
110 let inner = Self::build_inner(config).await?;
111 Ok(Self { inner })
112 }
113
114 async fn build_inner(
115 conf: gaxi::options::ClientConfig,
116 ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::DirectAccessService>>
117 {
118 if gaxi::options::tracing_enabled(&conf) {
119 return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
120 }
121 Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
122 }
123
124 async fn build_transport(
125 conf: gaxi::options::ClientConfig,
126 ) -> crate::ClientBuilderResult<impl super::stub::DirectAccessService> {
127 super::transport::DirectAccessService::new(conf).await
128 }
129
130 async fn build_with_tracing(
131 conf: gaxi::options::ClientConfig,
132 ) -> crate::ClientBuilderResult<impl super::stub::DirectAccessService> {
133 Self::build_transport(conf)
134 .await
135 .map(super::tracing::DirectAccessService::new)
136 }
137
138 /// Creates a DeviceSession.
139 ///
140 /// # Example
141 /// ```
142 /// # use google_cloud_devicestreaming_v1::client::DirectAccessService;
143 /// use google_cloud_devicestreaming_v1::model::DeviceSession;
144 /// use google_cloud_devicestreaming_v1::Result;
145 /// async fn sample(
146 /// client: &DirectAccessService, parent: &str
147 /// ) -> Result<()> {
148 /// let response = client.create_device_session()
149 /// .set_parent(parent)
150 /// .set_device_session(
151 /// DeviceSession::new()/* set fields */
152 /// )
153 /// .send().await?;
154 /// println!("response {:?}", response);
155 /// Ok(())
156 /// }
157 /// ```
158 pub fn create_device_session(
159 &self,
160 ) -> super::builder::direct_access_service::CreateDeviceSession {
161 super::builder::direct_access_service::CreateDeviceSession::new(self.inner.clone())
162 }
163
164 /// Lists DeviceSessions owned by the project user.
165 ///
166 /// # Example
167 /// ```
168 /// # use google_cloud_devicestreaming_v1::client::DirectAccessService;
169 /// use google_cloud_gax::paginator::ItemPaginator as _;
170 /// use google_cloud_devicestreaming_v1::Result;
171 /// async fn sample(
172 /// client: &DirectAccessService, parent: &str
173 /// ) -> Result<()> {
174 /// let mut list = client.list_device_sessions()
175 /// .set_parent(parent)
176 /// .by_item();
177 /// while let Some(item) = list.next().await.transpose()? {
178 /// println!("{:?}", item);
179 /// }
180 /// Ok(())
181 /// }
182 /// ```
183 pub fn list_device_sessions(
184 &self,
185 ) -> super::builder::direct_access_service::ListDeviceSessions {
186 super::builder::direct_access_service::ListDeviceSessions::new(self.inner.clone())
187 }
188
189 /// Gets a DeviceSession, which documents the allocation status and
190 /// whether the device is allocated. Clients making requests from this API
191 /// must poll GetDeviceSession.
192 ///
193 /// # Example
194 /// ```
195 /// # use google_cloud_devicestreaming_v1::client::DirectAccessService;
196 /// use google_cloud_devicestreaming_v1::Result;
197 /// async fn sample(
198 /// client: &DirectAccessService, project_id: &str, device_session_id: &str
199 /// ) -> Result<()> {
200 /// let response = client.get_device_session()
201 /// .set_name(format!("projects/{project_id}/deviceSessions/{device_session_id}"))
202 /// .send().await?;
203 /// println!("response {:?}", response);
204 /// Ok(())
205 /// }
206 /// ```
207 pub fn get_device_session(&self) -> super::builder::direct_access_service::GetDeviceSession {
208 super::builder::direct_access_service::GetDeviceSession::new(self.inner.clone())
209 }
210
211 /// Cancel a DeviceSession.
212 /// This RPC changes the DeviceSession to state FINISHED and terminates all
213 /// connections.
214 /// Canceled sessions are not deleted and can be retrieved or
215 /// listed by the user until they expire based on the 28 day deletion policy.
216 ///
217 /// # Example
218 /// ```
219 /// # use google_cloud_devicestreaming_v1::client::DirectAccessService;
220 /// use google_cloud_devicestreaming_v1::Result;
221 /// async fn sample(
222 /// client: &DirectAccessService
223 /// ) -> Result<()> {
224 /// client.cancel_device_session()
225 /// /* set fields */
226 /// .send().await?;
227 /// Ok(())
228 /// }
229 /// ```
230 pub fn cancel_device_session(
231 &self,
232 ) -> super::builder::direct_access_service::CancelDeviceSession {
233 super::builder::direct_access_service::CancelDeviceSession::new(self.inner.clone())
234 }
235
236 /// Updates the current DeviceSession to the fields described by the
237 /// update_mask.
238 ///
239 /// # Example
240 /// ```
241 /// # use google_cloud_devicestreaming_v1::client::DirectAccessService;
242 /// # extern crate wkt as google_cloud_wkt;
243 /// use google_cloud_wkt::FieldMask;
244 /// use google_cloud_devicestreaming_v1::model::DeviceSession;
245 /// use google_cloud_devicestreaming_v1::Result;
246 /// async fn sample(
247 /// client: &DirectAccessService, project_id: &str, device_session_id: &str
248 /// ) -> Result<()> {
249 /// let response = client.update_device_session()
250 /// .set_device_session(
251 /// DeviceSession::new().set_name(format!("projects/{project_id}/deviceSessions/{device_session_id}"))/* set fields */
252 /// )
253 /// .set_update_mask(FieldMask::default().set_paths(["updated.field.path1", "updated.field.path2"]))
254 /// .send().await?;
255 /// println!("response {:?}", response);
256 /// Ok(())
257 /// }
258 /// ```
259 pub fn update_device_session(
260 &self,
261 ) -> super::builder::direct_access_service::UpdateDeviceSession {
262 super::builder::direct_access_service::UpdateDeviceSession::new(self.inner.clone())
263 }
264}