nativeview_cli/pair/
host_reg.rs1use std::sync::Arc;
6
7use nativeview_abi::OwnedHostOps;
8use nativeview_clipboard::spec::wire::WireClipboardClient;
9use nativeview_clipboard::{box_clipboard_host_ops, NvModClipboardHostOps};
10use nativeview_linking::spec::wire::WireLinkingClient;
11use nativeview_linking::{box_linking_host_ops, NvModLinkingHostOps};
12use nativeview_system_env::spec::wire::WireSystemEnvClient;
13use nativeview_system_env::{box_system_env_host_ops, NvModSystemEnvHostOps};
14
15use crate::pair_host::PairByteTransport;
16
17pub struct PairHostRegistration {
23 transport: PairByteTransport,
24 clipboard: OwnedHostOps<NvModClipboardHostOps>,
25 linking: OwnedHostOps<NvModLinkingHostOps>,
26 system_env: OwnedHostOps<NvModSystemEnvHostOps>,
27}
28
29impl PairHostRegistration {
30 pub fn new(transport: PairByteTransport) -> Self {
33 Self {
34 clipboard: box_clipboard_host_ops(Arc::new(WireClipboardClient::new(
35 transport.clone(),
36 ))),
37 linking: box_linking_host_ops(Arc::new(WireLinkingClient::new(transport.clone()))),
38 system_env: box_system_env_host_ops(Arc::new(WireSystemEnvClient::new(
39 transport.clone(),
40 ))),
41 transport,
42 }
43 }
44
45 pub fn register_global(&self) -> Result<(), Vec<(&'static str, i32)>> {
48 let mut errs = Vec::new();
49 let mut check = |name: &'static str, status: nativeview_abi::NvModStatus| {
50 if !status.is_ok() {
51 errs.push((name, status as i32));
52 }
53 };
54 check("clipboard", self.clipboard.register_global());
55 check("linking", self.linking.register_global());
56 check("system-env", self.system_env.register_global());
57 if errs.is_empty() {
58 Ok(())
59 } else {
60 Err(errs)
61 }
62 }
63
64 pub fn transport(&self) -> &PairByteTransport {
65 &self.transport
66 }
67
68 pub fn clipboard_ops(&self) -> &OwnedHostOps<NvModClipboardHostOps> {
69 &self.clipboard
70 }
71
72 pub fn linking_ops(&self) -> &OwnedHostOps<NvModLinkingHostOps> {
73 &self.linking
74 }
75
76 pub fn system_env_ops(&self) -> &OwnedHostOps<NvModSystemEnvHostOps> {
77 &self.system_env
78 }
79}
80
81impl Drop for PairHostRegistration {
82 fn drop(&mut self) {
83 self.transport.shutdown();
84 }
85}