decthings_api/client/rpc/persistent_launcher/
mod.rs1mod request;
2mod response;
3
4use crate::client::StateModification;
5
6pub use request::*;
7pub use response::*;
8
9pub struct PersistentLauncherRpc {
10 rpc: crate::client::DecthingsClientRpc,
11}
12
13impl PersistentLauncherRpc {
14 pub(crate) fn new(rpc: crate::client::DecthingsClientRpc) -> Self {
15 Self { rpc }
16 }
17
18 pub async fn create_persistent_launcher(
19 &self,
20 params: CreatePersistentLauncherParams<'_>,
21 ) -> Result<
22 CreatePersistentLauncherResult,
23 crate::client::DecthingsRpcError<CreatePersistentLauncherError>,
24 > {
25 let (tx, rx) = tokio::sync::oneshot::channel();
26 self.rpc
27 .raw_method_call::<_, _, &[u8]>(
28 "PersistentLauncher",
29 "createPersistentLauncher",
30 params,
31 &[],
32 crate::client::RpcProtocol::Http,
33 |x| {
34 tx.send(x).ok();
35 StateModification::empty()
36 },
37 )
38 .await;
39 rx.await
40 .unwrap()
41 .map_err(crate::client::DecthingsRpcError::Request)
42 .and_then(|x| {
43 let res: super::Response<
44 CreatePersistentLauncherResult,
45 CreatePersistentLauncherError,
46 > = serde_json::from_slice(&x.0)?;
47 match res {
48 super::Response::Result(val) => Ok(val),
49 super::Response::Error(val) => Err(crate::client::DecthingsRpcError::Rpc(val)),
50 }
51 })
52 }
53
54 pub async fn get_persistent_launchers(
55 &self,
56 params: GetPersistentLaunchersParams<'_, impl AsRef<str>>,
57 ) -> Result<
58 GetPersistentLaunchersResult,
59 crate::client::DecthingsRpcError<GetPersistentLaunchersError>,
60 > {
61 let (tx, rx) = tokio::sync::oneshot::channel();
62 self.rpc
63 .raw_method_call::<_, _, &[u8]>(
64 "PersistentLaunchers",
65 "getPersistentLaunchers",
66 params,
67 &[],
68 crate::client::RpcProtocol::Http,
69 |x| {
70 tx.send(x).ok();
71 StateModification::empty()
72 },
73 )
74 .await;
75 rx.await
76 .unwrap()
77 .map_err(crate::client::DecthingsRpcError::Request)
78 .and_then(|x| {
79 let res: super::Response<
80 GetPersistentLaunchersResult,
81 GetPersistentLaunchersError,
82 > = serde_json::from_slice(&x.0)?;
83 match res {
84 super::Response::Result(val) => Ok(val),
85 super::Response::Error(val) => Err(crate::client::DecthingsRpcError::Rpc(val)),
86 }
87 })
88 }
89
90 pub async fn get_sysinfo(
91 &self,
92 params: GetSysinfoParams<'_>,
93 ) -> Result<GetSysinfoResult, crate::client::DecthingsRpcError<GetSysinfoError>> {
94 let (tx, rx) = tokio::sync::oneshot::channel();
95 self.rpc
96 .raw_method_call::<_, _, &[u8]>(
97 "PersistentLaunchers",
98 "getSysinfo",
99 params,
100 &[],
101 crate::client::RpcProtocol::Http,
102 |x| {
103 tx.send(x).ok();
104 StateModification::empty()
105 },
106 )
107 .await;
108 rx.await
109 .unwrap()
110 .map_err(crate::client::DecthingsRpcError::Request)
111 .and_then(|x| {
112 let res: super::Response<GetSysinfoResult, GetSysinfoError> =
113 serde_json::from_slice(&x.0)?;
114 match res {
115 super::Response::Result(val) => Ok(val),
116 super::Response::Error(val) => Err(crate::client::DecthingsRpcError::Rpc(val)),
117 }
118 })
119 }
120
121 pub async fn delete_persistent_launcher(
122 &self,
123 params: DeletePersistentLauncherParams<'_>,
124 ) -> Result<
125 DeletePersistentLauncherResult,
126 crate::client::DecthingsRpcError<DeletePersistentLauncherError>,
127 > {
128 let (tx, rx) = tokio::sync::oneshot::channel();
129 self.rpc
130 .raw_method_call::<_, _, &[u8]>(
131 "PersistentLaunchers",
132 "deletePersistentLauncher",
133 params,
134 &[],
135 crate::client::RpcProtocol::Http,
136 |x| {
137 tx.send(x).ok();
138 StateModification::empty()
139 },
140 )
141 .await;
142 rx.await
143 .unwrap()
144 .map_err(crate::client::DecthingsRpcError::Request)
145 .and_then(|x| {
146 let res = serde_json::from_slice(&x.0)?;
147 match res {
148 super::Response::Result(val) => Ok(val),
149 super::Response::Error(val) => Err(crate::client::DecthingsRpcError::Rpc(val)),
150 }
151 })
152 }
153}