1use std::collections::BTreeMap;
2use std::io::Cursor;
3use std::sync::Arc;
4
5use rmpv::Value;
6use rpc_runtime_core::{InstanceId, MethodId};
7use rpc_runtime_errors::{RuntimeError, RuntimeErrorCode};
8use rpc_runtime_server::{
9 FactoryFuture, HandlerFuture, RpcCallContext, RpcServerBuilder, RpcServiceFactory,
10 RpcServiceHandler,
11};
12
13use super::activation::*;
14use super::services::*;
15use super::types::*;
16
17pub type ArchiveServiceZipFuture<'a> =
18 std::pin::Pin<Box<dyn std::future::Future<Output = Result<Empty, RuntimeError>> + Send + 'a>>;
19pub type ArchiveServiceUnzipFuture<'a> =
20 std::pin::Pin<Box<dyn std::future::Future<Output = Result<Empty, RuntimeError>> + Send + 'a>>;
21
22pub trait ArchiveServiceService: Send + Sync {
23 fn zip(&self, ctx: RpcCallContext, request: ZipRequest) -> ArchiveServiceZipFuture<'_>;
24 fn unzip(&self, ctx: RpcCallContext, request: UnzipRequest) -> ArchiveServiceUnzipFuture<'_>;
25}
26
27pub struct ArchiveServiceHandler<T: ?Sized> {
28 inner: Arc<T>,
29}
30impl<T: ?Sized> ArchiveServiceHandler<T> {
31 pub fn new(inner: Arc<T>) -> Self {
32 Self { inner }
33 }
34}
35impl<T: ArchiveServiceService + ?Sized + 'static> RpcServiceHandler for ArchiveServiceHandler<T> {
36 fn call(
37 &self,
38 ctx: RpcCallContext,
39 method_id: MethodId,
40 payload: rmpv::Value,
41 ) -> HandlerFuture {
42 let inner = Arc::clone(&self.inner);
43 match method_id.get() {
44 1 => Box::pin(async move {
45 let request = decode_zip_request(&payload)?;
46 let response = inner.zip(ctx, request).await?;
47 Ok(encode_empty(&response))
48 }),
49 2 => Box::pin(async move {
50 let request = decode_unzip_request(&payload)?;
51 let response = inner.unzip(ctx, request).await?;
52 Ok(encode_empty(&response))
53 }),
54 _ => Box::pin(async move {
55 Err(RuntimeError::runtime(
56 RuntimeErrorCode::MethodNotFound,
57 "unknown generated method id",
58 ))
59 }),
60 }
61 }
62}
63
64pub fn register_archive_service_named<T: ArchiveServiceService + 'static>(
65 builder: &mut RpcServerBuilder,
66 name: impl Into<String>,
67 service: Arc<T>,
68) -> InstanceId {
69 builder.register_named_instance(
70 name,
71 archive_service_service_guid(),
72 archive_service_method_ids(),
73 Arc::new(ArchiveServiceHandler::new(service)),
74 )
75}
76
77pub fn register_archive_service_singleton<T: ArchiveServiceService + 'static>(
78 builder: &mut RpcServerBuilder,
79 service: Arc<T>,
80) -> InstanceId {
81 builder.register_singleton(
82 archive_service_service_guid(),
83 archive_service_method_ids(),
84 Arc::new(ArchiveServiceHandler::new(service)),
85 )
86}
87
88pub fn register_archive_service_factory<TFactory: ArchiveServiceFactory + 'static>(
89 builder: &mut RpcServerBuilder,
90 factory: Arc<TFactory>,
91) {
92 builder.register_factory(
93 archive_service_service_guid(),
94 archive_service_method_ids(),
95 Arc::new(ArchiveServiceFactoryAdapter { inner: factory }),
96 );
97}
98
99pub type ArchiveServiceFactoryFuture<'a> = std::pin::Pin<
100 Box<
101 dyn std::future::Future<Output = Result<Arc<dyn ArchiveServiceService>, RuntimeError>>
102 + Send
103 + 'a,
104 >,
105>;
106pub trait ArchiveServiceFactory: Send + Sync {
107 fn create(
108 &self,
109 ctx: RpcCallContext,
110 create_payload: Option<Vec<u8>>,
111 options: BTreeMap<String, String>,
112 ) -> ArchiveServiceFactoryFuture<'_>;
113}
114
115struct ArchiveServiceFactoryAdapter<TFactory> {
116 inner: Arc<TFactory>,
117}
118impl<TFactory: ArchiveServiceFactory + 'static> RpcServiceFactory
119 for ArchiveServiceFactoryAdapter<TFactory>
120{
121 fn create(
122 &self,
123 ctx: RpcCallContext,
124 create_payload: Option<Vec<u8>>,
125 options: BTreeMap<String, String>,
126 ) -> FactoryFuture {
127 let inner = Arc::clone(&self.inner);
128 Box::pin(async move {
129 let service = inner.create(ctx, create_payload, options).await?;
130 let handler: Arc<dyn RpcServiceHandler> = Arc::new(ArchiveServiceHandler::new(service));
131 Ok(handler)
132 })
133 }
134}
135
136pub type FileSystemServiceReadFileFuture<'a> = std::pin::Pin<
137 Box<dyn std::future::Future<Output = Result<BinaryPayload, RuntimeError>> + Send + 'a>,
138>;
139pub type FileSystemServiceWriteFileFuture<'a> =
140 std::pin::Pin<Box<dyn std::future::Future<Output = Result<Empty, RuntimeError>> + Send + 'a>>;
141pub type FileSystemServiceAppendFileFuture<'a> =
142 std::pin::Pin<Box<dyn std::future::Future<Output = Result<Empty, RuntimeError>> + Send + 'a>>;
143pub type FileSystemServiceMkdirFuture<'a> =
144 std::pin::Pin<Box<dyn std::future::Future<Output = Result<Empty, RuntimeError>> + Send + 'a>>;
145pub type FileSystemServiceReadDirFuture<'a> = std::pin::Pin<
146 Box<dyn std::future::Future<Output = Result<Vec<DirEntry>, RuntimeError>> + Send + 'a>,
147>;
148pub type FileSystemServiceStatFuture<'a> = std::pin::Pin<
149 Box<dyn std::future::Future<Output = Result<FileStat, RuntimeError>> + Send + 'a>,
150>;
151pub type FileSystemServiceExistsFuture<'a> =
152 std::pin::Pin<Box<dyn std::future::Future<Output = Result<bool, RuntimeError>> + Send + 'a>>;
153pub type FileSystemServiceRemoveFuture<'a> =
154 std::pin::Pin<Box<dyn std::future::Future<Output = Result<Empty, RuntimeError>> + Send + 'a>>;
155pub type FileSystemServiceRenameFuture<'a> =
156 std::pin::Pin<Box<dyn std::future::Future<Output = Result<Empty, RuntimeError>> + Send + 'a>>;
157pub type FileSystemServiceCopyFileFuture<'a> =
158 std::pin::Pin<Box<dyn std::future::Future<Output = Result<Empty, RuntimeError>> + Send + 'a>>;
159pub type FileSystemServiceOpenFileFuture<'a> = std::pin::Pin<
160 Box<dyn std::future::Future<Output = Result<ResourceHandle, RuntimeError>> + Send + 'a>,
161>;
162pub type FileSystemServiceFileReadFuture<'a> = std::pin::Pin<
163 Box<dyn std::future::Future<Output = Result<BinaryPayload, RuntimeError>> + Send + 'a>,
164>;
165pub type FileSystemServiceFileWriteFuture<'a> =
166 std::pin::Pin<Box<dyn std::future::Future<Output = Result<Empty, RuntimeError>> + Send + 'a>>;
167pub type FileSystemServiceFileFlushFuture<'a> =
168 std::pin::Pin<Box<dyn std::future::Future<Output = Result<Empty, RuntimeError>> + Send + 'a>>;
169pub type FileSystemServiceFileSeekFuture<'a> = std::pin::Pin<
170 Box<dyn std::future::Future<Output = Result<FileSeekResult, RuntimeError>> + Send + 'a>,
171>;
172pub type FileSystemServiceFileSetLenFuture<'a> =
173 std::pin::Pin<Box<dyn std::future::Future<Output = Result<Empty, RuntimeError>> + Send + 'a>>;
174pub type FileSystemServiceFileCloseFuture<'a> =
175 std::pin::Pin<Box<dyn std::future::Future<Output = Result<Empty, RuntimeError>> + Send + 'a>>;
176
177pub trait FileSystemServiceService: Send + Sync {
178 fn read_file(
179 &self,
180 ctx: RpcCallContext,
181 request: PathRequest,
182 ) -> FileSystemServiceReadFileFuture<'_>;
183 fn write_file(
184 &self,
185 ctx: RpcCallContext,
186 request: WriteFileRequest,
187 ) -> FileSystemServiceWriteFileFuture<'_>;
188 fn append_file(
189 &self,
190 ctx: RpcCallContext,
191 request: WriteFileRequest,
192 ) -> FileSystemServiceAppendFileFuture<'_>;
193 fn mkdir(&self, ctx: RpcCallContext, request: MkdirRequest)
194 -> FileSystemServiceMkdirFuture<'_>;
195 fn read_dir(
196 &self,
197 ctx: RpcCallContext,
198 request: PathRequest,
199 ) -> FileSystemServiceReadDirFuture<'_>;
200 fn stat(&self, ctx: RpcCallContext, request: PathRequest) -> FileSystemServiceStatFuture<'_>;
201 fn exists(
202 &self,
203 ctx: RpcCallContext,
204 request: PathRequest,
205 ) -> FileSystemServiceExistsFuture<'_>;
206 fn remove(
207 &self,
208 ctx: RpcCallContext,
209 request: RemoveRequest,
210 ) -> FileSystemServiceRemoveFuture<'_>;
211 fn rename(
212 &self,
213 ctx: RpcCallContext,
214 request: RenameRequest,
215 ) -> FileSystemServiceRenameFuture<'_>;
216 fn copy_file(
217 &self,
218 ctx: RpcCallContext,
219 request: RenameRequest,
220 ) -> FileSystemServiceCopyFileFuture<'_>;
221 fn open_file(
222 &self,
223 ctx: RpcCallContext,
224 request: OpenFileRequest,
225 ) -> FileSystemServiceOpenFileFuture<'_>;
226 fn file_read(
227 &self,
228 ctx: RpcCallContext,
229 request: FileReadRequest,
230 ) -> FileSystemServiceFileReadFuture<'_>;
231 fn file_write(
232 &self,
233 ctx: RpcCallContext,
234 request: FileWriteRequest,
235 ) -> FileSystemServiceFileWriteFuture<'_>;
236 fn file_flush(
237 &self,
238 ctx: RpcCallContext,
239 request: ResourceHandle,
240 ) -> FileSystemServiceFileFlushFuture<'_>;
241 fn file_seek(
242 &self,
243 ctx: RpcCallContext,
244 request: FileSeekRequest,
245 ) -> FileSystemServiceFileSeekFuture<'_>;
246 fn file_set_len(
247 &self,
248 ctx: RpcCallContext,
249 request: FileSetLenRequest,
250 ) -> FileSystemServiceFileSetLenFuture<'_>;
251 fn file_close(
252 &self,
253 ctx: RpcCallContext,
254 request: ResourceHandle,
255 ) -> FileSystemServiceFileCloseFuture<'_>;
256}
257
258pub struct FileSystemServiceHandler<T: ?Sized> {
259 inner: Arc<T>,
260}
261impl<T: ?Sized> FileSystemServiceHandler<T> {
262 pub fn new(inner: Arc<T>) -> Self {
263 Self { inner }
264 }
265}
266impl<T: FileSystemServiceService + ?Sized + 'static> RpcServiceHandler
267 for FileSystemServiceHandler<T>
268{
269 fn call(
270 &self,
271 ctx: RpcCallContext,
272 method_id: MethodId,
273 payload: rmpv::Value,
274 ) -> HandlerFuture {
275 let inner = Arc::clone(&self.inner);
276 match method_id.get() {
277 1 => Box::pin(async move {
278 let request = decode_path_request(&payload)?;
279 let response = inner.read_file(ctx, request).await?;
280 Ok(encode_binary_payload(&response))
281 }),
282 2 => Box::pin(async move {
283 let request = decode_write_file_request(&payload)?;
284 let response = inner.write_file(ctx, request).await?;
285 Ok(encode_empty(&response))
286 }),
287 3 => Box::pin(async move {
288 let request = decode_write_file_request(&payload)?;
289 let response = inner.append_file(ctx, request).await?;
290 Ok(encode_empty(&response))
291 }),
292 4 => Box::pin(async move {
293 let request = decode_mkdir_request(&payload)?;
294 let response = inner.mkdir(ctx, request).await?;
295 Ok(encode_empty(&response))
296 }),
297 5 => Box::pin(async move {
298 let request = decode_path_request(&payload)?;
299 let response = inner.read_dir(ctx, request).await?;
300 Ok(Value::Array(
301 response
302 .iter()
303 .map(|item| encode_dir_entry(&item))
304 .collect(),
305 ))
306 }),
307 6 => Box::pin(async move {
308 let request = decode_path_request(&payload)?;
309 let response = inner.stat(ctx, request).await?;
310 Ok(encode_file_stat(&response))
311 }),
312 7 => Box::pin(async move {
313 let request = decode_path_request(&payload)?;
314 let response = inner.exists(ctx, request).await?;
315 Ok(Value::Boolean(response))
316 }),
317 8 => Box::pin(async move {
318 let request = decode_remove_request(&payload)?;
319 let response = inner.remove(ctx, request).await?;
320 Ok(encode_empty(&response))
321 }),
322 9 => Box::pin(async move {
323 let request = decode_rename_request(&payload)?;
324 let response = inner.rename(ctx, request).await?;
325 Ok(encode_empty(&response))
326 }),
327 10 => Box::pin(async move {
328 let request = decode_rename_request(&payload)?;
329 let response = inner.copy_file(ctx, request).await?;
330 Ok(encode_empty(&response))
331 }),
332 11 => Box::pin(async move {
333 let request = decode_open_file_request(&payload)?;
334 let response = inner.open_file(ctx, request).await?;
335 Ok(encode_resource_handle(&response))
336 }),
337 12 => Box::pin(async move {
338 let request = decode_file_read_request(&payload)?;
339 let response = inner.file_read(ctx, request).await?;
340 Ok(encode_binary_payload(&response))
341 }),
342 13 => Box::pin(async move {
343 let request = decode_file_write_request(&payload)?;
344 let response = inner.file_write(ctx, request).await?;
345 Ok(encode_empty(&response))
346 }),
347 14 => Box::pin(async move {
348 let request = decode_resource_handle(&payload)?;
349 let response = inner.file_flush(ctx, request).await?;
350 Ok(encode_empty(&response))
351 }),
352 15 => Box::pin(async move {
353 let request = decode_file_seek_request(&payload)?;
354 let response = inner.file_seek(ctx, request).await?;
355 Ok(encode_file_seek_result(&response))
356 }),
357 16 => Box::pin(async move {
358 let request = decode_file_set_len_request(&payload)?;
359 let response = inner.file_set_len(ctx, request).await?;
360 Ok(encode_empty(&response))
361 }),
362 17 => Box::pin(async move {
363 let request = decode_resource_handle(&payload)?;
364 let response = inner.file_close(ctx, request).await?;
365 Ok(encode_empty(&response))
366 }),
367 _ => Box::pin(async move {
368 Err(RuntimeError::runtime(
369 RuntimeErrorCode::MethodNotFound,
370 "unknown generated method id",
371 ))
372 }),
373 }
374 }
375}
376
377pub fn register_file_system_service_named<T: FileSystemServiceService + 'static>(
378 builder: &mut RpcServerBuilder,
379 name: impl Into<String>,
380 service: Arc<T>,
381) -> InstanceId {
382 builder.register_named_instance(
383 name,
384 file_system_service_service_guid(),
385 file_system_service_method_ids(),
386 Arc::new(FileSystemServiceHandler::new(service)),
387 )
388}
389
390pub fn register_file_system_service_singleton<T: FileSystemServiceService + 'static>(
391 builder: &mut RpcServerBuilder,
392 service: Arc<T>,
393) -> InstanceId {
394 builder.register_singleton(
395 file_system_service_service_guid(),
396 file_system_service_method_ids(),
397 Arc::new(FileSystemServiceHandler::new(service)),
398 )
399}
400
401pub fn register_file_system_service_factory<TFactory: FileSystemServiceFactory + 'static>(
402 builder: &mut RpcServerBuilder,
403 factory: Arc<TFactory>,
404) {
405 builder.register_factory(
406 file_system_service_service_guid(),
407 file_system_service_method_ids(),
408 Arc::new(FileSystemServiceFactoryAdapter { inner: factory }),
409 );
410}
411
412pub type FileSystemServiceFactoryFuture<'a> = std::pin::Pin<
413 Box<
414 dyn std::future::Future<Output = Result<Arc<dyn FileSystemServiceService>, RuntimeError>>
415 + Send
416 + 'a,
417 >,
418>;
419pub trait FileSystemServiceFactory: Send + Sync {
420 fn create(
421 &self,
422 ctx: RpcCallContext,
423 create_payload: Option<Vec<u8>>,
424 options: BTreeMap<String, String>,
425 ) -> FileSystemServiceFactoryFuture<'_>;
426}
427
428struct FileSystemServiceFactoryAdapter<TFactory> {
429 inner: Arc<TFactory>,
430}
431impl<TFactory: FileSystemServiceFactory + 'static> RpcServiceFactory
432 for FileSystemServiceFactoryAdapter<TFactory>
433{
434 fn create(
435 &self,
436 ctx: RpcCallContext,
437 create_payload: Option<Vec<u8>>,
438 options: BTreeMap<String, String>,
439 ) -> FactoryFuture {
440 let inner = Arc::clone(&self.inner);
441 Box::pin(async move {
442 let service = inner.create(ctx, create_payload, options).await?;
443 let handler: Arc<dyn RpcServiceHandler> =
444 Arc::new(FileSystemServiceHandler::new(service));
445 Ok(handler)
446 })
447 }
448}
449
450pub type RuntimeServiceGetInfoFuture<'a> = std::pin::Pin<
451 Box<dyn std::future::Future<Output = Result<RuntimeInfo, RuntimeError>> + Send + 'a>,
452>;
453pub type RuntimeServiceListCapabilitiesFuture<'a> = std::pin::Pin<
454 Box<dyn std::future::Future<Output = Result<Vec<String>, RuntimeError>> + Send + 'a>,
455>;
456pub type RuntimeServiceDisposeResourcesFuture<'a> =
457 std::pin::Pin<Box<dyn std::future::Future<Output = Result<Empty, RuntimeError>> + Send + 'a>>;
458
459pub trait RuntimeServiceService: Send + Sync {
460 fn get_info(&self, ctx: RpcCallContext, request: Empty) -> RuntimeServiceGetInfoFuture<'_>;
461 fn list_capabilities(
462 &self,
463 ctx: RpcCallContext,
464 request: Empty,
465 ) -> RuntimeServiceListCapabilitiesFuture<'_>;
466 fn dispose_resources(
467 &self,
468 ctx: RpcCallContext,
469 request: Empty,
470 ) -> RuntimeServiceDisposeResourcesFuture<'_>;
471}
472
473pub struct RuntimeServiceHandler<T: ?Sized> {
474 inner: Arc<T>,
475}
476impl<T: ?Sized> RuntimeServiceHandler<T> {
477 pub fn new(inner: Arc<T>) -> Self {
478 Self { inner }
479 }
480}
481impl<T: RuntimeServiceService + ?Sized + 'static> RpcServiceHandler for RuntimeServiceHandler<T> {
482 fn call(
483 &self,
484 ctx: RpcCallContext,
485 method_id: MethodId,
486 payload: rmpv::Value,
487 ) -> HandlerFuture {
488 let inner = Arc::clone(&self.inner);
489 match method_id.get() {
490 1 => Box::pin(async move {
491 let request = decode_empty(&payload)?;
492 let response = inner.get_info(ctx, request).await?;
493 Ok(encode_runtime_info(&response))
494 }),
495 2 => Box::pin(async move {
496 let request = decode_empty(&payload)?;
497 let response = inner.list_capabilities(ctx, request).await?;
498 Ok(Value::Array(
499 response
500 .iter()
501 .map(|item| Value::from(item.as_str()))
502 .collect(),
503 ))
504 }),
505 3 => Box::pin(async move {
506 let request = decode_empty(&payload)?;
507 let response = inner.dispose_resources(ctx, request).await?;
508 Ok(encode_empty(&response))
509 }),
510 _ => Box::pin(async move {
511 Err(RuntimeError::runtime(
512 RuntimeErrorCode::MethodNotFound,
513 "unknown generated method id",
514 ))
515 }),
516 }
517 }
518}
519
520pub fn register_runtime_service_named<T: RuntimeServiceService + 'static>(
521 builder: &mut RpcServerBuilder,
522 name: impl Into<String>,
523 service: Arc<T>,
524) -> InstanceId {
525 builder.register_named_instance(
526 name,
527 runtime_service_service_guid(),
528 runtime_service_method_ids(),
529 Arc::new(RuntimeServiceHandler::new(service)),
530 )
531}
532
533pub fn register_runtime_service_singleton<T: RuntimeServiceService + 'static>(
534 builder: &mut RpcServerBuilder,
535 service: Arc<T>,
536) -> InstanceId {
537 builder.register_singleton(
538 runtime_service_service_guid(),
539 runtime_service_method_ids(),
540 Arc::new(RuntimeServiceHandler::new(service)),
541 )
542}
543
544pub fn register_runtime_service_factory<TFactory: RuntimeServiceFactory + 'static>(
545 builder: &mut RpcServerBuilder,
546 factory: Arc<TFactory>,
547) {
548 builder.register_factory(
549 runtime_service_service_guid(),
550 runtime_service_method_ids(),
551 Arc::new(RuntimeServiceFactoryAdapter { inner: factory }),
552 );
553}
554
555pub type RuntimeServiceFactoryFuture<'a> = std::pin::Pin<
556 Box<
557 dyn std::future::Future<Output = Result<Arc<dyn RuntimeServiceService>, RuntimeError>>
558 + Send
559 + 'a,
560 >,
561>;
562pub trait RuntimeServiceFactory: Send + Sync {
563 fn create(
564 &self,
565 ctx: RpcCallContext,
566 create_payload: Option<Vec<u8>>,
567 options: BTreeMap<String, String>,
568 ) -> RuntimeServiceFactoryFuture<'_>;
569}
570
571struct RuntimeServiceFactoryAdapter<TFactory> {
572 inner: Arc<TFactory>,
573}
574impl<TFactory: RuntimeServiceFactory + 'static> RpcServiceFactory
575 for RuntimeServiceFactoryAdapter<TFactory>
576{
577 fn create(
578 &self,
579 ctx: RpcCallContext,
580 create_payload: Option<Vec<u8>>,
581 options: BTreeMap<String, String>,
582 ) -> FactoryFuture {
583 let inner = Arc::clone(&self.inner);
584 Box::pin(async move {
585 let service = inner.create(ctx, create_payload, options).await?;
586 let handler: Arc<dyn RpcServiceHandler> = Arc::new(RuntimeServiceHandler::new(service));
587 Ok(handler)
588 })
589 }
590}
591
592pub type SqliteServiceOpenFuture<'a> = std::pin::Pin<
593 Box<dyn std::future::Future<Output = Result<ResourceHandle, RuntimeError>> + Send + 'a>,
594>;
595pub type SqliteServiceCloseFuture<'a> =
596 std::pin::Pin<Box<dyn std::future::Future<Output = Result<Empty, RuntimeError>> + Send + 'a>>;
597pub type SqliteServiceExecuteBatchFuture<'a> =
598 std::pin::Pin<Box<dyn std::future::Future<Output = Result<Empty, RuntimeError>> + Send + 'a>>;
599pub type SqliteServiceRunFuture<'a> = std::pin::Pin<
600 Box<dyn std::future::Future<Output = Result<SqliteRunResult, RuntimeError>> + Send + 'a>,
601>;
602pub type SqliteServiceQueryOneFuture<'a> = std::pin::Pin<
603 Box<dyn std::future::Future<Output = Result<Option<SqliteRow>, RuntimeError>> + Send + 'a>,
604>;
605pub type SqliteServiceQueryAllFuture<'a> = std::pin::Pin<
606 Box<dyn std::future::Future<Output = Result<Vec<SqliteRow>, RuntimeError>> + Send + 'a>,
607>;
608pub type SqliteServiceTransactionFuture<'a> =
609 std::pin::Pin<Box<dyn std::future::Future<Output = Result<Empty, RuntimeError>> + Send + 'a>>;
610
611pub trait SqliteServiceService: Send + Sync {
612 fn open(&self, ctx: RpcCallContext, request: SqliteOpenRequest) -> SqliteServiceOpenFuture<'_>;
613 fn close(&self, ctx: RpcCallContext, request: ResourceHandle) -> SqliteServiceCloseFuture<'_>;
614 fn execute_batch(
615 &self,
616 ctx: RpcCallContext,
617 request: SqliteStatementRequest,
618 ) -> SqliteServiceExecuteBatchFuture<'_>;
619 fn run(
620 &self,
621 ctx: RpcCallContext,
622 request: SqliteStatementRequest,
623 ) -> SqliteServiceRunFuture<'_>;
624 fn query_one(
625 &self,
626 ctx: RpcCallContext,
627 request: SqliteStatementRequest,
628 ) -> SqliteServiceQueryOneFuture<'_>;
629 fn query_all(
630 &self,
631 ctx: RpcCallContext,
632 request: SqliteStatementRequest,
633 ) -> SqliteServiceQueryAllFuture<'_>;
634 fn transaction(
635 &self,
636 ctx: RpcCallContext,
637 request: SqliteTransactionRequest,
638 ) -> SqliteServiceTransactionFuture<'_>;
639}
640
641pub struct SqliteServiceHandler<T: ?Sized> {
642 inner: Arc<T>,
643}
644impl<T: ?Sized> SqliteServiceHandler<T> {
645 pub fn new(inner: Arc<T>) -> Self {
646 Self { inner }
647 }
648}
649impl<T: SqliteServiceService + ?Sized + 'static> RpcServiceHandler for SqliteServiceHandler<T> {
650 fn call(
651 &self,
652 ctx: RpcCallContext,
653 method_id: MethodId,
654 payload: rmpv::Value,
655 ) -> HandlerFuture {
656 let inner = Arc::clone(&self.inner);
657 match method_id.get() {
658 1 => Box::pin(async move {
659 let request = decode_sqlite_open_request(&payload)?;
660 let response = inner.open(ctx, request).await?;
661 Ok(encode_resource_handle(&response))
662 }),
663 2 => Box::pin(async move {
664 let request = decode_resource_handle(&payload)?;
665 let response = inner.close(ctx, request).await?;
666 Ok(encode_empty(&response))
667 }),
668 3 => Box::pin(async move {
669 let request = decode_sqlite_statement_request(&payload)?;
670 let response = inner.execute_batch(ctx, request).await?;
671 Ok(encode_empty(&response))
672 }),
673 4 => Box::pin(async move {
674 let request = decode_sqlite_statement_request(&payload)?;
675 let response = inner.run(ctx, request).await?;
676 Ok(encode_sqlite_run_result(&response))
677 }),
678 5 => Box::pin(async move {
679 let request = decode_sqlite_statement_request(&payload)?;
680 let response = inner.query_one(ctx, request).await?;
681 Ok(match &response {
682 Some(value) => encode_sqlite_row(value),
683 None => Value::Nil,
684 })
685 }),
686 6 => Box::pin(async move {
687 let request = decode_sqlite_statement_request(&payload)?;
688 let response = inner.query_all(ctx, request).await?;
689 Ok(Value::Array(
690 response
691 .iter()
692 .map(|item| encode_sqlite_row(&item))
693 .collect(),
694 ))
695 }),
696 7 => Box::pin(async move {
697 let request = decode_sqlite_transaction_request(&payload)?;
698 let response = inner.transaction(ctx, request).await?;
699 Ok(encode_empty(&response))
700 }),
701 _ => Box::pin(async move {
702 Err(RuntimeError::runtime(
703 RuntimeErrorCode::MethodNotFound,
704 "unknown generated method id",
705 ))
706 }),
707 }
708 }
709}
710
711pub fn register_sqlite_service_named<T: SqliteServiceService + 'static>(
712 builder: &mut RpcServerBuilder,
713 name: impl Into<String>,
714 service: Arc<T>,
715) -> InstanceId {
716 builder.register_named_instance(
717 name,
718 sqlite_service_service_guid(),
719 sqlite_service_method_ids(),
720 Arc::new(SqliteServiceHandler::new(service)),
721 )
722}
723
724pub fn register_sqlite_service_singleton<T: SqliteServiceService + 'static>(
725 builder: &mut RpcServerBuilder,
726 service: Arc<T>,
727) -> InstanceId {
728 builder.register_singleton(
729 sqlite_service_service_guid(),
730 sqlite_service_method_ids(),
731 Arc::new(SqliteServiceHandler::new(service)),
732 )
733}
734
735pub fn register_sqlite_service_factory<TFactory: SqliteServiceFactory + 'static>(
736 builder: &mut RpcServerBuilder,
737 factory: Arc<TFactory>,
738) {
739 builder.register_factory(
740 sqlite_service_service_guid(),
741 sqlite_service_method_ids(),
742 Arc::new(SqliteServiceFactoryAdapter { inner: factory }),
743 );
744}
745
746pub type SqliteServiceFactoryFuture<'a> = std::pin::Pin<
747 Box<
748 dyn std::future::Future<Output = Result<Arc<dyn SqliteServiceService>, RuntimeError>>
749 + Send
750 + 'a,
751 >,
752>;
753pub trait SqliteServiceFactory: Send + Sync {
754 fn create(
755 &self,
756 ctx: RpcCallContext,
757 create_payload: Option<Vec<u8>>,
758 options: BTreeMap<String, String>,
759 ) -> SqliteServiceFactoryFuture<'_>;
760}
761
762struct SqliteServiceFactoryAdapter<TFactory> {
763 inner: Arc<TFactory>,
764}
765impl<TFactory: SqliteServiceFactory + 'static> RpcServiceFactory
766 for SqliteServiceFactoryAdapter<TFactory>
767{
768 fn create(
769 &self,
770 ctx: RpcCallContext,
771 create_payload: Option<Vec<u8>>,
772 options: BTreeMap<String, String>,
773 ) -> FactoryFuture {
774 let inner = Arc::clone(&self.inner);
775 Box::pin(async move {
776 let service = inner.create(ctx, create_payload, options).await?;
777 let handler: Arc<dyn RpcServiceHandler> = Arc::new(SqliteServiceHandler::new(service));
778 Ok(handler)
779 })
780 }
781}
782
783pub type SystemServiceGetPowerCapabilitiesFuture<'a> = std::pin::Pin<
784 Box<dyn std::future::Future<Output = Result<Vec<String>, RuntimeError>> + Send + 'a>,
785>;
786pub type SystemServiceShutdownFuture<'a> =
787 std::pin::Pin<Box<dyn std::future::Future<Output = Result<Empty, RuntimeError>> + Send + 'a>>;
788pub type SystemServiceRebootFuture<'a> =
789 std::pin::Pin<Box<dyn std::future::Future<Output = Result<Empty, RuntimeError>> + Send + 'a>>;
790
791pub trait SystemServiceService: Send + Sync {
792 fn get_power_capabilities(
793 &self,
794 ctx: RpcCallContext,
795 request: Empty,
796 ) -> SystemServiceGetPowerCapabilitiesFuture<'_>;
797 fn shutdown(
798 &self,
799 ctx: RpcCallContext,
800 request: PowerOptions,
801 ) -> SystemServiceShutdownFuture<'_>;
802 fn reboot(&self, ctx: RpcCallContext, request: PowerOptions) -> SystemServiceRebootFuture<'_>;
803}
804
805pub struct SystemServiceHandler<T: ?Sized> {
806 inner: Arc<T>,
807}
808impl<T: ?Sized> SystemServiceHandler<T> {
809 pub fn new(inner: Arc<T>) -> Self {
810 Self { inner }
811 }
812}
813impl<T: SystemServiceService + ?Sized + 'static> RpcServiceHandler for SystemServiceHandler<T> {
814 fn call(
815 &self,
816 ctx: RpcCallContext,
817 method_id: MethodId,
818 payload: rmpv::Value,
819 ) -> HandlerFuture {
820 let inner = Arc::clone(&self.inner);
821 match method_id.get() {
822 1 => Box::pin(async move {
823 let request = decode_empty(&payload)?;
824 let response = inner.get_power_capabilities(ctx, request).await?;
825 Ok(Value::Array(
826 response
827 .iter()
828 .map(|item| Value::from(item.as_str()))
829 .collect(),
830 ))
831 }),
832 2 => Box::pin(async move {
833 let request = decode_power_options(&payload)?;
834 let response = inner.shutdown(ctx, request).await?;
835 Ok(encode_empty(&response))
836 }),
837 3 => Box::pin(async move {
838 let request = decode_power_options(&payload)?;
839 let response = inner.reboot(ctx, request).await?;
840 Ok(encode_empty(&response))
841 }),
842 _ => Box::pin(async move {
843 Err(RuntimeError::runtime(
844 RuntimeErrorCode::MethodNotFound,
845 "unknown generated method id",
846 ))
847 }),
848 }
849 }
850}
851
852pub fn register_system_service_named<T: SystemServiceService + 'static>(
853 builder: &mut RpcServerBuilder,
854 name: impl Into<String>,
855 service: Arc<T>,
856) -> InstanceId {
857 builder.register_named_instance(
858 name,
859 system_service_service_guid(),
860 system_service_method_ids(),
861 Arc::new(SystemServiceHandler::new(service)),
862 )
863}
864
865pub fn register_system_service_singleton<T: SystemServiceService + 'static>(
866 builder: &mut RpcServerBuilder,
867 service: Arc<T>,
868) -> InstanceId {
869 builder.register_singleton(
870 system_service_service_guid(),
871 system_service_method_ids(),
872 Arc::new(SystemServiceHandler::new(service)),
873 )
874}
875
876pub fn register_system_service_factory<TFactory: SystemServiceFactory + 'static>(
877 builder: &mut RpcServerBuilder,
878 factory: Arc<TFactory>,
879) {
880 builder.register_factory(
881 system_service_service_guid(),
882 system_service_method_ids(),
883 Arc::new(SystemServiceFactoryAdapter { inner: factory }),
884 );
885}
886
887pub type SystemServiceFactoryFuture<'a> = std::pin::Pin<
888 Box<
889 dyn std::future::Future<Output = Result<Arc<dyn SystemServiceService>, RuntimeError>>
890 + Send
891 + 'a,
892 >,
893>;
894pub trait SystemServiceFactory: Send + Sync {
895 fn create(
896 &self,
897 ctx: RpcCallContext,
898 create_payload: Option<Vec<u8>>,
899 options: BTreeMap<String, String>,
900 ) -> SystemServiceFactoryFuture<'_>;
901}
902
903struct SystemServiceFactoryAdapter<TFactory> {
904 inner: Arc<TFactory>,
905}
906impl<TFactory: SystemServiceFactory + 'static> RpcServiceFactory
907 for SystemServiceFactoryAdapter<TFactory>
908{
909 fn create(
910 &self,
911 ctx: RpcCallContext,
912 create_payload: Option<Vec<u8>>,
913 options: BTreeMap<String, String>,
914 ) -> FactoryFuture {
915 let inner = Arc::clone(&self.inner);
916 Box::pin(async move {
917 let service = inner.create(ctx, create_payload, options).await?;
918 let handler: Arc<dyn RpcServiceHandler> = Arc::new(SystemServiceHandler::new(service));
919 Ok(handler)
920 })
921 }
922}
923
924pub type TcpServiceConnectFuture<'a> = std::pin::Pin<
925 Box<dyn std::future::Future<Output = Result<ResourceHandle, RuntimeError>> + Send + 'a>,
926>;
927pub type TcpServiceSocketWriteFuture<'a> =
928 std::pin::Pin<Box<dyn std::future::Future<Output = Result<Empty, RuntimeError>> + Send + 'a>>;
929pub type TcpServiceSocketEndFuture<'a> =
930 std::pin::Pin<Box<dyn std::future::Future<Output = Result<Empty, RuntimeError>> + Send + 'a>>;
931pub type TcpServiceSocketCloseFuture<'a> =
932 std::pin::Pin<Box<dyn std::future::Future<Output = Result<Empty, RuntimeError>> + Send + 'a>>;
933pub type TcpServiceServerListenFuture<'a> = std::pin::Pin<
934 Box<dyn std::future::Future<Output = Result<ListenResult, RuntimeError>> + Send + 'a>,
935>;
936pub type TcpServiceServerCloseFuture<'a> =
937 std::pin::Pin<Box<dyn std::future::Future<Output = Result<Empty, RuntimeError>> + Send + 'a>>;
938
939pub trait TcpServiceService: Send + Sync {
940 fn connect(
941 &self,
942 ctx: RpcCallContext,
943 request: SocketConnectRequest,
944 ) -> TcpServiceConnectFuture<'_>;
945 fn socket_write(
946 &self,
947 ctx: RpcCallContext,
948 request: SocketWriteRequest,
949 ) -> TcpServiceSocketWriteFuture<'_>;
950 fn socket_end(
951 &self,
952 ctx: RpcCallContext,
953 request: ResourceHandle,
954 ) -> TcpServiceSocketEndFuture<'_>;
955 fn socket_close(
956 &self,
957 ctx: RpcCallContext,
958 request: ResourceHandle,
959 ) -> TcpServiceSocketCloseFuture<'_>;
960 fn server_listen(
961 &self,
962 ctx: RpcCallContext,
963 request: SocketListenRequest,
964 ) -> TcpServiceServerListenFuture<'_>;
965 fn server_close(
966 &self,
967 ctx: RpcCallContext,
968 request: ResourceHandle,
969 ) -> TcpServiceServerCloseFuture<'_>;
970}
971
972pub struct TcpServiceHandler<T: ?Sized> {
973 inner: Arc<T>,
974}
975impl<T: ?Sized> TcpServiceHandler<T> {
976 pub fn new(inner: Arc<T>) -> Self {
977 Self { inner }
978 }
979}
980impl<T: TcpServiceService + ?Sized + 'static> RpcServiceHandler for TcpServiceHandler<T> {
981 fn call(
982 &self,
983 ctx: RpcCallContext,
984 method_id: MethodId,
985 payload: rmpv::Value,
986 ) -> HandlerFuture {
987 let inner = Arc::clone(&self.inner);
988 match method_id.get() {
989 1 => Box::pin(async move {
990 let request = decode_socket_connect_request(&payload)?;
991 let response = inner.connect(ctx, request).await?;
992 Ok(encode_resource_handle(&response))
993 }),
994 2 => Box::pin(async move {
995 let request = decode_socket_write_request(&payload)?;
996 let response = inner.socket_write(ctx, request).await?;
997 Ok(encode_empty(&response))
998 }),
999 3 => Box::pin(async move {
1000 let request = decode_resource_handle(&payload)?;
1001 let response = inner.socket_end(ctx, request).await?;
1002 Ok(encode_empty(&response))
1003 }),
1004 4 => Box::pin(async move {
1005 let request = decode_resource_handle(&payload)?;
1006 let response = inner.socket_close(ctx, request).await?;
1007 Ok(encode_empty(&response))
1008 }),
1009 5 => Box::pin(async move {
1010 let request = decode_socket_listen_request(&payload)?;
1011 let response = inner.server_listen(ctx, request).await?;
1012 Ok(encode_listen_result(&response))
1013 }),
1014 6 => Box::pin(async move {
1015 let request = decode_resource_handle(&payload)?;
1016 let response = inner.server_close(ctx, request).await?;
1017 Ok(encode_empty(&response))
1018 }),
1019 _ => Box::pin(async move {
1020 Err(RuntimeError::runtime(
1021 RuntimeErrorCode::MethodNotFound,
1022 "unknown generated method id",
1023 ))
1024 }),
1025 }
1026 }
1027}
1028
1029pub fn register_tcp_service_named<T: TcpServiceService + 'static>(
1030 builder: &mut RpcServerBuilder,
1031 name: impl Into<String>,
1032 service: Arc<T>,
1033) -> InstanceId {
1034 builder.register_named_instance(
1035 name,
1036 tcp_service_service_guid(),
1037 tcp_service_method_ids(),
1038 Arc::new(TcpServiceHandler::new(service)),
1039 )
1040}
1041
1042pub fn register_tcp_service_singleton<T: TcpServiceService + 'static>(
1043 builder: &mut RpcServerBuilder,
1044 service: Arc<T>,
1045) -> InstanceId {
1046 builder.register_singleton(
1047 tcp_service_service_guid(),
1048 tcp_service_method_ids(),
1049 Arc::new(TcpServiceHandler::new(service)),
1050 )
1051}
1052
1053pub fn register_tcp_service_factory<TFactory: TcpServiceFactory + 'static>(
1054 builder: &mut RpcServerBuilder,
1055 factory: Arc<TFactory>,
1056) {
1057 builder.register_factory(
1058 tcp_service_service_guid(),
1059 tcp_service_method_ids(),
1060 Arc::new(TcpServiceFactoryAdapter { inner: factory }),
1061 );
1062}
1063
1064pub type TcpServiceFactoryFuture<'a> = std::pin::Pin<
1065 Box<
1066 dyn std::future::Future<Output = Result<Arc<dyn TcpServiceService>, RuntimeError>>
1067 + Send
1068 + 'a,
1069 >,
1070>;
1071pub trait TcpServiceFactory: Send + Sync {
1072 fn create(
1073 &self,
1074 ctx: RpcCallContext,
1075 create_payload: Option<Vec<u8>>,
1076 options: BTreeMap<String, String>,
1077 ) -> TcpServiceFactoryFuture<'_>;
1078}
1079
1080struct TcpServiceFactoryAdapter<TFactory> {
1081 inner: Arc<TFactory>,
1082}
1083impl<TFactory: TcpServiceFactory + 'static> RpcServiceFactory
1084 for TcpServiceFactoryAdapter<TFactory>
1085{
1086 fn create(
1087 &self,
1088 ctx: RpcCallContext,
1089 create_payload: Option<Vec<u8>>,
1090 options: BTreeMap<String, String>,
1091 ) -> FactoryFuture {
1092 let inner = Arc::clone(&self.inner);
1093 Box::pin(async move {
1094 let service = inner.create(ctx, create_payload, options).await?;
1095 let handler: Arc<dyn RpcServiceHandler> = Arc::new(TcpServiceHandler::new(service));
1096 Ok(handler)
1097 })
1098 }
1099}
1100
1101pub type WebSocketServiceConnectFuture<'a> = std::pin::Pin<
1102 Box<dyn std::future::Future<Output = Result<ResourceHandle, RuntimeError>> + Send + 'a>,
1103>;
1104pub type WebSocketServiceSendTextFuture<'a> =
1105 std::pin::Pin<Box<dyn std::future::Future<Output = Result<Empty, RuntimeError>> + Send + 'a>>;
1106pub type WebSocketServiceSendBinaryFuture<'a> =
1107 std::pin::Pin<Box<dyn std::future::Future<Output = Result<Empty, RuntimeError>> + Send + 'a>>;
1108pub type WebSocketServiceCloseFuture<'a> =
1109 std::pin::Pin<Box<dyn std::future::Future<Output = Result<Empty, RuntimeError>> + Send + 'a>>;
1110pub type WebSocketServiceServerListenFuture<'a> = std::pin::Pin<
1111 Box<dyn std::future::Future<Output = Result<ListenResult, RuntimeError>> + Send + 'a>,
1112>;
1113pub type WebSocketServiceServerCloseFuture<'a> =
1114 std::pin::Pin<Box<dyn std::future::Future<Output = Result<Empty, RuntimeError>> + Send + 'a>>;
1115
1116pub trait WebSocketServiceService: Send + Sync {
1117 fn connect(
1118 &self,
1119 ctx: RpcCallContext,
1120 request: WebSocketConnectRequest,
1121 ) -> WebSocketServiceConnectFuture<'_>;
1122 fn send_text(
1123 &self,
1124 ctx: RpcCallContext,
1125 request: WebSocketSendTextRequest,
1126 ) -> WebSocketServiceSendTextFuture<'_>;
1127 fn send_binary(
1128 &self,
1129 ctx: RpcCallContext,
1130 request: SocketWriteRequest,
1131 ) -> WebSocketServiceSendBinaryFuture<'_>;
1132 fn close(
1133 &self,
1134 ctx: RpcCallContext,
1135 request: ResourceHandle,
1136 ) -> WebSocketServiceCloseFuture<'_>;
1137 fn server_listen(
1138 &self,
1139 ctx: RpcCallContext,
1140 request: SocketListenRequest,
1141 ) -> WebSocketServiceServerListenFuture<'_>;
1142 fn server_close(
1143 &self,
1144 ctx: RpcCallContext,
1145 request: ResourceHandle,
1146 ) -> WebSocketServiceServerCloseFuture<'_>;
1147}
1148
1149pub struct WebSocketServiceHandler<T: ?Sized> {
1150 inner: Arc<T>,
1151}
1152impl<T: ?Sized> WebSocketServiceHandler<T> {
1153 pub fn new(inner: Arc<T>) -> Self {
1154 Self { inner }
1155 }
1156}
1157impl<T: WebSocketServiceService + ?Sized + 'static> RpcServiceHandler
1158 for WebSocketServiceHandler<T>
1159{
1160 fn call(
1161 &self,
1162 ctx: RpcCallContext,
1163 method_id: MethodId,
1164 payload: rmpv::Value,
1165 ) -> HandlerFuture {
1166 let inner = Arc::clone(&self.inner);
1167 match method_id.get() {
1168 1 => Box::pin(async move {
1169 let request = decode_web_socket_connect_request(&payload)?;
1170 let response = inner.connect(ctx, request).await?;
1171 Ok(encode_resource_handle(&response))
1172 }),
1173 2 => Box::pin(async move {
1174 let request = decode_web_socket_send_text_request(&payload)?;
1175 let response = inner.send_text(ctx, request).await?;
1176 Ok(encode_empty(&response))
1177 }),
1178 3 => Box::pin(async move {
1179 let request = decode_socket_write_request(&payload)?;
1180 let response = inner.send_binary(ctx, request).await?;
1181 Ok(encode_empty(&response))
1182 }),
1183 4 => Box::pin(async move {
1184 let request = decode_resource_handle(&payload)?;
1185 let response = inner.close(ctx, request).await?;
1186 Ok(encode_empty(&response))
1187 }),
1188 5 => Box::pin(async move {
1189 let request = decode_socket_listen_request(&payload)?;
1190 let response = inner.server_listen(ctx, request).await?;
1191 Ok(encode_listen_result(&response))
1192 }),
1193 6 => Box::pin(async move {
1194 let request = decode_resource_handle(&payload)?;
1195 let response = inner.server_close(ctx, request).await?;
1196 Ok(encode_empty(&response))
1197 }),
1198 _ => Box::pin(async move {
1199 Err(RuntimeError::runtime(
1200 RuntimeErrorCode::MethodNotFound,
1201 "unknown generated method id",
1202 ))
1203 }),
1204 }
1205 }
1206}
1207
1208pub fn register_web_socket_service_named<T: WebSocketServiceService + 'static>(
1209 builder: &mut RpcServerBuilder,
1210 name: impl Into<String>,
1211 service: Arc<T>,
1212) -> InstanceId {
1213 builder.register_named_instance(
1214 name,
1215 web_socket_service_service_guid(),
1216 web_socket_service_method_ids(),
1217 Arc::new(WebSocketServiceHandler::new(service)),
1218 )
1219}
1220
1221pub fn register_web_socket_service_singleton<T: WebSocketServiceService + 'static>(
1222 builder: &mut RpcServerBuilder,
1223 service: Arc<T>,
1224) -> InstanceId {
1225 builder.register_singleton(
1226 web_socket_service_service_guid(),
1227 web_socket_service_method_ids(),
1228 Arc::new(WebSocketServiceHandler::new(service)),
1229 )
1230}
1231
1232pub fn register_web_socket_service_factory<TFactory: WebSocketServiceFactory + 'static>(
1233 builder: &mut RpcServerBuilder,
1234 factory: Arc<TFactory>,
1235) {
1236 builder.register_factory(
1237 web_socket_service_service_guid(),
1238 web_socket_service_method_ids(),
1239 Arc::new(WebSocketServiceFactoryAdapter { inner: factory }),
1240 );
1241}
1242
1243pub type WebSocketServiceFactoryFuture<'a> = std::pin::Pin<
1244 Box<
1245 dyn std::future::Future<Output = Result<Arc<dyn WebSocketServiceService>, RuntimeError>>
1246 + Send
1247 + 'a,
1248 >,
1249>;
1250pub trait WebSocketServiceFactory: Send + Sync {
1251 fn create(
1252 &self,
1253 ctx: RpcCallContext,
1254 create_payload: Option<Vec<u8>>,
1255 options: BTreeMap<String, String>,
1256 ) -> WebSocketServiceFactoryFuture<'_>;
1257}
1258
1259struct WebSocketServiceFactoryAdapter<TFactory> {
1260 inner: Arc<TFactory>,
1261}
1262impl<TFactory: WebSocketServiceFactory + 'static> RpcServiceFactory
1263 for WebSocketServiceFactoryAdapter<TFactory>
1264{
1265 fn create(
1266 &self,
1267 ctx: RpcCallContext,
1268 create_payload: Option<Vec<u8>>,
1269 options: BTreeMap<String, String>,
1270 ) -> FactoryFuture {
1271 let inner = Arc::clone(&self.inner);
1272 Box::pin(async move {
1273 let service = inner.create(ctx, create_payload, options).await?;
1274 let handler: Arc<dyn RpcServiceHandler> =
1275 Arc::new(WebSocketServiceHandler::new(service));
1276 Ok(handler)
1277 })
1278 }
1279}