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/// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
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/// # 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    /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
79    /// # use google_cloud_devicestreaming_v1::client::DirectAccessService;
80    /// let client = DirectAccessService::builder().build().await?;
81    /// # Ok(()) }
82    /// ```
83    pub fn builder() -> super::builder::direct_access_service::ClientBuilder {
84        crate::new_client_builder(super::builder::direct_access_service::client::Factory)
85    }
86
87    /// Creates a new client from the provided stub.
88    ///
89    /// The most common case for calling this function is in tests mocking the
90    /// client's behavior.
91    pub fn from_stub<T>(stub: T) -> Self
92    where
93        T: super::stub::DirectAccessService + 'static,
94    {
95        Self {
96            inner: std::sync::Arc::new(stub),
97        }
98    }
99
100    pub(crate) async fn new(
101        config: gaxi::options::ClientConfig,
102    ) -> crate::ClientBuilderResult<Self> {
103        let inner = Self::build_inner(config).await?;
104        Ok(Self { inner })
105    }
106
107    async fn build_inner(
108        conf: gaxi::options::ClientConfig,
109    ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::DirectAccessService>>
110    {
111        if gaxi::options::tracing_enabled(&conf) {
112            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
113        }
114        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
115    }
116
117    async fn build_transport(
118        conf: gaxi::options::ClientConfig,
119    ) -> crate::ClientBuilderResult<impl super::stub::DirectAccessService> {
120        super::transport::DirectAccessService::new(conf).await
121    }
122
123    async fn build_with_tracing(
124        conf: gaxi::options::ClientConfig,
125    ) -> crate::ClientBuilderResult<impl super::stub::DirectAccessService> {
126        Self::build_transport(conf)
127            .await
128            .map(super::tracing::DirectAccessService::new)
129    }
130
131    /// Creates a DeviceSession.
132    pub fn create_device_session(
133        &self,
134    ) -> super::builder::direct_access_service::CreateDeviceSession {
135        super::builder::direct_access_service::CreateDeviceSession::new(self.inner.clone())
136    }
137
138    /// Lists DeviceSessions owned by the project user.
139    pub fn list_device_sessions(
140        &self,
141    ) -> super::builder::direct_access_service::ListDeviceSessions {
142        super::builder::direct_access_service::ListDeviceSessions::new(self.inner.clone())
143    }
144
145    /// Gets a DeviceSession, which documents the allocation status and
146    /// whether the device is allocated. Clients making requests from this API
147    /// must poll GetDeviceSession.
148    pub fn get_device_session(&self) -> super::builder::direct_access_service::GetDeviceSession {
149        super::builder::direct_access_service::GetDeviceSession::new(self.inner.clone())
150    }
151
152    /// Cancel a DeviceSession.
153    /// This RPC changes the DeviceSession to state FINISHED and terminates all
154    /// connections.
155    /// Canceled sessions are not deleted and can be retrieved or
156    /// listed by the user until they expire based on the 28 day deletion policy.
157    pub fn cancel_device_session(
158        &self,
159    ) -> super::builder::direct_access_service::CancelDeviceSession {
160        super::builder::direct_access_service::CancelDeviceSession::new(self.inner.clone())
161    }
162
163    /// Updates the current DeviceSession to the fields described by the
164    /// update_mask.
165    pub fn update_device_session(
166        &self,
167    ) -> super::builder::direct_access_service::UpdateDeviceSession {
168        super::builder::direct_access_service::UpdateDeviceSession::new(self.inner.clone())
169    }
170}