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