1 //! D-Bus proxy implementations of the APIs.
2 
3 use btstack::suspend::{ISuspend, ISuspendCallback, SuspendType};
4 use btstack::RPCProxy;
5 use dbus::nonblock::SyncConnection;
6 use dbus_macros::{dbus_method, generate_dbus_exporter, generate_dbus_interface_client};
7 use dbus_projection::prelude::*;
8 use num_traits::{FromPrimitive, ToPrimitive};
9 use std::sync::Arc;
10 
11 use crate::dbus_arg::{DBusArg, DBusArgError};
12 
13 impl_dbus_arg_enum!(SuspendType);
14 
15 #[derive(Clone)]
16 pub struct SuspendDBusRPC {
17     client_proxy: ClientDBusProxy,
18 }
19 
20 pub struct SuspendDBus {
21     client_proxy: ClientDBusProxy,
22     pub rpc: SuspendDBusRPC,
23 }
24 
25 impl SuspendDBus {
make_client_proxy(conn: Arc<SyncConnection>, path: dbus::Path<'static>) -> ClientDBusProxy26     fn make_client_proxy(conn: Arc<SyncConnection>, path: dbus::Path<'static>) -> ClientDBusProxy {
27         ClientDBusProxy::new(
28             conn.clone(),
29             String::from("org.chromium.bluetooth"),
30             path,
31             String::from("org.chromium.bluetooth.Suspend"),
32         )
33     }
34 
new(conn: Arc<SyncConnection>, path: dbus::Path<'static>) -> SuspendDBus35     pub(crate) fn new(conn: Arc<SyncConnection>, path: dbus::Path<'static>) -> SuspendDBus {
36         SuspendDBus {
37             client_proxy: Self::make_client_proxy(conn.clone(), path.clone()),
38             rpc: SuspendDBusRPC {
39                 client_proxy: Self::make_client_proxy(conn.clone(), path.clone()),
40             },
41         }
42     }
43 }
44 
45 #[generate_dbus_interface_client(SuspendDBusRPC)]
46 impl ISuspend for SuspendDBus {
47     #[dbus_method("RegisterCallback", DBusLog::Disable)]
register_callback(&mut self, callback: Box<dyn ISuspendCallback + Send>) -> bool48     fn register_callback(&mut self, callback: Box<dyn ISuspendCallback + Send>) -> bool {
49         dbus_generated!()
50     }
51 
52     #[dbus_method("UnregisterCallback")]
unregister_callback(&mut self, callback_id: u32) -> bool53     fn unregister_callback(&mut self, callback_id: u32) -> bool {
54         dbus_generated!()
55     }
56 
57     #[dbus_method("Suspend")]
suspend(&mut self, _suspend_type: SuspendType, suspend_id: i32)58     fn suspend(&mut self, _suspend_type: SuspendType, suspend_id: i32) {
59         dbus_generated!()
60     }
61 
62     #[dbus_method("Resume")]
resume(&mut self) -> bool63     fn resume(&mut self) -> bool {
64         dbus_generated!()
65     }
66 }
67 
68 #[allow(dead_code)]
69 struct ISuspendCallbackDBus {}
70 
71 impl RPCProxy for ISuspendCallbackDBus {}
72 
73 #[generate_dbus_exporter(
74     export_suspend_callback_dbus_intf,
75     "org.chromium.bluetooth.SuspendCallback"
76 )]
77 impl ISuspendCallback for ISuspendCallbackDBus {
78     #[dbus_method("OnCallbackRegistered")]
on_callback_registered(&mut self, callback_id: u32)79     fn on_callback_registered(&mut self, callback_id: u32) {}
80     #[dbus_method("OnSuspendReady")]
on_suspend_ready(&mut self, suspend_id: i32)81     fn on_suspend_ready(&mut self, suspend_id: i32) {}
82     #[dbus_method("OnResumed")]
on_resumed(&mut self, suspend_id: i32)83     fn on_resumed(&mut self, suspend_id: i32) {}
84 }
85