Skip to main content

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() -> Result<(), Box<dyn std::error::Error>> {
26///     let client = DirectAccessService::builder().build().await?;
27///     let parent = "parent_value";
28///     let mut list = client.list_device_sessions()
29///         .set_parent(parent)
30///         .by_item();
31///     while let Some(item) = list.next().await.transpose()? {
32///         println!("{:?}", item);
33///     }
34/// # Ok(()) }
35/// ```
36///
37/// # Service Description
38///
39/// A service for allocating Android devices and interacting with the
40/// live-allocated devices.
41///
42/// Each Session will wait for available capacity, at a higher
43/// priority over Test Execution. When allocated, the session will be exposed
44/// through a stream for integration.
45///
46/// DirectAccessService is currently available as a preview to select developers.
47/// You can register today on behalf of you and your team at
48/// <https://developer.android.com/studio/preview/android-device-streaming>
49///
50/// # Configuration
51///
52/// To configure `DirectAccessService` use the `with_*` methods in the type returned
53/// by [builder()][DirectAccessService::builder]. The default configuration should
54/// work for most applications. Common configuration changes include
55///
56/// * [with_endpoint()]: by default this client uses the global default endpoint
57///   (`https://devicestreaming.googleapis.com`). Applications using regional
58///   endpoints or running in restricted networks (e.g. a network configured
59//    with [Private Google Access with VPC Service Controls]) may want to
60///   override this default.
61/// * [with_credentials()]: by default this client uses
62///   [Application Default Credentials]. Applications using custom
63///   authentication may need to override this default.
64///
65/// [with_endpoint()]: super::builder::direct_access_service::ClientBuilder::with_endpoint
66/// [with_credentials()]: super::builder::direct_access_service::ClientBuilder::with_credentials
67/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
68/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
69///
70/// # Pooling and Cloning
71///
72/// `DirectAccessService` holds a connection pool internally, it is advised to
73/// create one and reuse it. You do not need to wrap `DirectAccessService` in
74/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
75/// already uses an `Arc` internally.
76#[derive(Clone, Debug)]
77pub struct DirectAccessService {
78    inner: std::sync::Arc<dyn super::stub::dynamic::DirectAccessService>,
79}
80
81impl DirectAccessService {
82    /// Returns a builder for [DirectAccessService].
83    ///
84    /// ```
85    /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
86    /// # use google_cloud_devicestreaming_v1::client::DirectAccessService;
87    /// let client = DirectAccessService::builder().build().await?;
88    /// # Ok(()) }
89    /// ```
90    pub fn builder() -> super::builder::direct_access_service::ClientBuilder {
91        crate::new_client_builder(super::builder::direct_access_service::client::Factory)
92    }
93
94    /// Creates a new client from the provided stub.
95    ///
96    /// The most common case for calling this function is in tests mocking the
97    /// client's behavior.
98    pub fn from_stub<T>(stub: T) -> Self
99    where
100        T: super::stub::DirectAccessService + 'static,
101    {
102        Self {
103            inner: std::sync::Arc::new(stub),
104        }
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, name: &str
199    /// ) -> Result<()> {
200    ///     let response = client.get_device_session()
201    ///         .set_name(name)
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, name: &str
248    /// ) -> Result<()> {
249    ///     let response = client.update_device_session()
250    ///         .set_device_session(
251    ///             DeviceSession::new().set_name(name)/* 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}