Upgrade capnp 0.20 → 0.25, capnp-rpc 0.20 → 0.25
RPC trait methods changed from &mut self to self: Rc<Self> and return types from Promise<(), Error> to impl Future<Output = Result<...>>. Updated all Server impls across 6 files: DaemonImpl (rpc.rs), NotifyForwarder (channels.rs), and ChannelServerImpl in all channel crates (irc, telegram, tmux, socat). Local pry! macro replaces capnp_rpc::pry to match the new impl Future return type. Warning-clean workspace build. Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
parent
382ebc95aa
commit
a421c3c9f3
12 changed files with 221 additions and 192 deletions
|
|
@ -7,7 +7,6 @@
|
|||
use super::idle;
|
||||
use crate::thalamus::{daemon_capnp, notify};
|
||||
use daemon_capnp::daemon;
|
||||
use capnp::capability::Promise;
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
use log::info;
|
||||
|
|
@ -24,112 +23,112 @@ impl DaemonImpl {
|
|||
|
||||
impl daemon::Server for DaemonImpl {
|
||||
fn user(
|
||||
&mut self,
|
||||
self: Rc<Self>,
|
||||
params: daemon::UserParams,
|
||||
_results: daemon::UserResults,
|
||||
) -> Promise<(), capnp::Error> {
|
||||
) -> impl std::future::Future<Output = Result<(), capnp::Error>> {
|
||||
let pane = pry!(pry!(pry!(params.get()).get_pane()).to_str()).to_string();
|
||||
self.state.borrow_mut().handle_user(&pane);
|
||||
Promise::ok(())
|
||||
std::future::ready(Ok(()))
|
||||
}
|
||||
|
||||
fn response(
|
||||
&mut self,
|
||||
self: Rc<Self>,
|
||||
params: daemon::ResponseParams,
|
||||
_results: daemon::ResponseResults,
|
||||
) -> Promise<(), capnp::Error> {
|
||||
) -> impl std::future::Future<Output = Result<(), capnp::Error>> {
|
||||
let pane = pry!(pry!(pry!(params.get()).get_pane()).to_str()).to_string();
|
||||
self.state.borrow_mut().handle_response(&pane);
|
||||
Promise::ok(())
|
||||
std::future::ready(Ok(()))
|
||||
}
|
||||
|
||||
fn sleep(
|
||||
&mut self,
|
||||
self: Rc<Self>,
|
||||
params: daemon::SleepParams,
|
||||
_results: daemon::SleepResults,
|
||||
) -> Promise<(), capnp::Error> {
|
||||
) -> impl std::future::Future<Output = Result<(), capnp::Error>> {
|
||||
let until = pry!(params.get()).get_until();
|
||||
self.state.borrow_mut().handle_sleep(until);
|
||||
Promise::ok(())
|
||||
std::future::ready(Ok(()))
|
||||
}
|
||||
|
||||
fn wake(
|
||||
&mut self,
|
||||
self: Rc<Self>,
|
||||
_params: daemon::WakeParams,
|
||||
_results: daemon::WakeResults,
|
||||
) -> Promise<(), capnp::Error> {
|
||||
) -> impl std::future::Future<Output = Result<(), capnp::Error>> {
|
||||
self.state.borrow_mut().handle_wake();
|
||||
Promise::ok(())
|
||||
std::future::ready(Ok(()))
|
||||
}
|
||||
|
||||
fn quiet(
|
||||
&mut self,
|
||||
self: Rc<Self>,
|
||||
params: daemon::QuietParams,
|
||||
_results: daemon::QuietResults,
|
||||
) -> Promise<(), capnp::Error> {
|
||||
) -> impl std::future::Future<Output = Result<(), capnp::Error>> {
|
||||
let secs = pry!(params.get()).get_seconds();
|
||||
self.state.borrow_mut().handle_quiet(secs);
|
||||
Promise::ok(())
|
||||
std::future::ready(Ok(()))
|
||||
}
|
||||
|
||||
fn consolidating(
|
||||
&mut self,
|
||||
self: Rc<Self>,
|
||||
_params: daemon::ConsolidatingParams,
|
||||
_results: daemon::ConsolidatingResults,
|
||||
) -> Promise<(), capnp::Error> {
|
||||
) -> impl std::future::Future<Output = Result<(), capnp::Error>> {
|
||||
self.state.borrow_mut().consolidating = true;
|
||||
info!("consolidation started");
|
||||
Promise::ok(())
|
||||
std::future::ready(Ok(()))
|
||||
}
|
||||
|
||||
fn consolidated(
|
||||
&mut self,
|
||||
self: Rc<Self>,
|
||||
_params: daemon::ConsolidatedParams,
|
||||
_results: daemon::ConsolidatedResults,
|
||||
) -> Promise<(), capnp::Error> {
|
||||
) -> impl std::future::Future<Output = Result<(), capnp::Error>> {
|
||||
self.state.borrow_mut().consolidating = false;
|
||||
info!("consolidation ended");
|
||||
Promise::ok(())
|
||||
std::future::ready(Ok(()))
|
||||
}
|
||||
|
||||
fn dream_start(
|
||||
&mut self,
|
||||
self: Rc<Self>,
|
||||
_params: daemon::DreamStartParams,
|
||||
_results: daemon::DreamStartResults,
|
||||
) -> Promise<(), capnp::Error> {
|
||||
) -> impl std::future::Future<Output = Result<(), capnp::Error>> {
|
||||
let mut s = self.state.borrow_mut();
|
||||
s.dreaming = true;
|
||||
s.dream_start = crate::thalamus::now();
|
||||
info!("dream started");
|
||||
Promise::ok(())
|
||||
std::future::ready(Ok(()))
|
||||
}
|
||||
|
||||
fn dream_end(
|
||||
&mut self,
|
||||
self: Rc<Self>,
|
||||
_params: daemon::DreamEndParams,
|
||||
_results: daemon::DreamEndResults,
|
||||
) -> Promise<(), capnp::Error> {
|
||||
) -> impl std::future::Future<Output = Result<(), capnp::Error>> {
|
||||
let mut s = self.state.borrow_mut();
|
||||
s.dreaming = false;
|
||||
s.dream_start = 0.0;
|
||||
info!("dream ended");
|
||||
Promise::ok(())
|
||||
std::future::ready(Ok(()))
|
||||
}
|
||||
|
||||
fn afk(
|
||||
&mut self,
|
||||
self: Rc<Self>,
|
||||
_params: daemon::AfkParams,
|
||||
_results: daemon::AfkResults,
|
||||
) -> Promise<(), capnp::Error> {
|
||||
) -> impl std::future::Future<Output = Result<(), capnp::Error>> {
|
||||
self.state.borrow_mut().handle_afk();
|
||||
Promise::ok(())
|
||||
std::future::ready(Ok(()))
|
||||
}
|
||||
|
||||
fn test_nudge(
|
||||
&mut self,
|
||||
self: Rc<Self>,
|
||||
_params: daemon::TestNudgeParams,
|
||||
mut results: daemon::TestNudgeResults,
|
||||
) -> Promise<(), capnp::Error> {
|
||||
) -> impl std::future::Future<Output = Result<(), capnp::Error>> {
|
||||
let mut state = self.state.borrow_mut();
|
||||
let ctx = state.build_context(true);
|
||||
let extra = if ctx.is_empty() {
|
||||
|
|
@ -144,85 +143,85 @@ impl daemon::Server for DaemonImpl {
|
|||
let ok = state.send(&msg);
|
||||
results.get().set_sent(ok);
|
||||
results.get().set_message(&msg);
|
||||
Promise::ok(())
|
||||
std::future::ready(Ok(()))
|
||||
}
|
||||
|
||||
fn session_timeout(
|
||||
&mut self,
|
||||
self: Rc<Self>,
|
||||
params: daemon::SessionTimeoutParams,
|
||||
_results: daemon::SessionTimeoutResults,
|
||||
) -> Promise<(), capnp::Error> {
|
||||
) -> impl std::future::Future<Output = Result<(), capnp::Error>> {
|
||||
let secs = pry!(params.get()).get_seconds();
|
||||
self.state.borrow_mut().handle_session_timeout(secs);
|
||||
Promise::ok(())
|
||||
std::future::ready(Ok(()))
|
||||
}
|
||||
|
||||
fn idle_timeout(
|
||||
&mut self,
|
||||
self: Rc<Self>,
|
||||
params: daemon::IdleTimeoutParams,
|
||||
_results: daemon::IdleTimeoutResults,
|
||||
) -> Promise<(), capnp::Error> {
|
||||
) -> impl std::future::Future<Output = Result<(), capnp::Error>> {
|
||||
let secs = pry!(params.get()).get_seconds();
|
||||
self.state.borrow_mut().handle_idle_timeout(secs);
|
||||
Promise::ok(())
|
||||
std::future::ready(Ok(()))
|
||||
}
|
||||
|
||||
fn notify_timeout(
|
||||
&mut self,
|
||||
self: Rc<Self>,
|
||||
params: daemon::NotifyTimeoutParams,
|
||||
_results: daemon::NotifyTimeoutResults,
|
||||
) -> Promise<(), capnp::Error> {
|
||||
) -> impl std::future::Future<Output = Result<(), capnp::Error>> {
|
||||
let secs = pry!(params.get()).get_seconds();
|
||||
self.state.borrow_mut().handle_notify_timeout(secs);
|
||||
Promise::ok(())
|
||||
std::future::ready(Ok(()))
|
||||
}
|
||||
|
||||
fn save(
|
||||
&mut self,
|
||||
self: Rc<Self>,
|
||||
_params: daemon::SaveParams,
|
||||
_results: daemon::SaveResults,
|
||||
) -> Promise<(), capnp::Error> {
|
||||
) -> impl std::future::Future<Output = Result<(), capnp::Error>> {
|
||||
self.state.borrow().save();
|
||||
info!("state saved");
|
||||
Promise::ok(())
|
||||
std::future::ready(Ok(()))
|
||||
}
|
||||
|
||||
fn debug(
|
||||
&mut self,
|
||||
self: Rc<Self>,
|
||||
_params: daemon::DebugParams,
|
||||
mut results: daemon::DebugResults,
|
||||
) -> Promise<(), capnp::Error> {
|
||||
) -> impl std::future::Future<Output = Result<(), capnp::Error>> {
|
||||
let json = self.state.borrow().debug_json();
|
||||
results.get().set_json(&json);
|
||||
Promise::ok(())
|
||||
std::future::ready(Ok(()))
|
||||
}
|
||||
|
||||
fn ewma(
|
||||
&mut self,
|
||||
self: Rc<Self>,
|
||||
params: daemon::EwmaParams,
|
||||
mut results: daemon::EwmaResults,
|
||||
) -> Promise<(), capnp::Error> {
|
||||
) -> impl std::future::Future<Output = Result<(), capnp::Error>> {
|
||||
let value = pry!(params.get()).get_value();
|
||||
let current = self.state.borrow_mut().handle_ewma(value);
|
||||
results.get().set_current(current);
|
||||
Promise::ok(())
|
||||
std::future::ready(Ok(()))
|
||||
}
|
||||
|
||||
fn stop(
|
||||
&mut self,
|
||||
self: Rc<Self>,
|
||||
_params: daemon::StopParams,
|
||||
_results: daemon::StopResults,
|
||||
) -> Promise<(), capnp::Error> {
|
||||
) -> impl std::future::Future<Output = Result<(), capnp::Error>> {
|
||||
self.state.borrow_mut().running = false;
|
||||
info!("stopping");
|
||||
Promise::ok(())
|
||||
std::future::ready(Ok(()))
|
||||
}
|
||||
|
||||
fn status(
|
||||
&mut self,
|
||||
self: Rc<Self>,
|
||||
_params: daemon::StatusParams,
|
||||
mut results: daemon::StatusResults,
|
||||
) -> Promise<(), capnp::Error> {
|
||||
) -> impl std::future::Future<Output = Result<(), capnp::Error>> {
|
||||
let s = self.state.borrow();
|
||||
let mut status = results.get().init_status();
|
||||
|
||||
|
|
@ -255,14 +254,14 @@ impl daemon::Server for DaemonImpl {
|
|||
status.set_block_reason(s.block_reason());
|
||||
status.set_activity_ewma(s.activity_ewma);
|
||||
|
||||
Promise::ok(())
|
||||
std::future::ready(Ok(()))
|
||||
}
|
||||
|
||||
fn notify(
|
||||
&mut self,
|
||||
self: Rc<Self>,
|
||||
params: daemon::NotifyParams,
|
||||
mut results: daemon::NotifyResults,
|
||||
) -> Promise<(), capnp::Error> {
|
||||
) -> impl std::future::Future<Output = Result<(), capnp::Error>> {
|
||||
let params = pry!(params.get());
|
||||
let notif = pry!(params.get_notification());
|
||||
let ntype = pry!(pry!(notif.get_type()).to_str()).to_string();
|
||||
|
|
@ -275,14 +274,14 @@ impl daemon::Server for DaemonImpl {
|
|||
.notifications
|
||||
.submit(ntype, urgency, message);
|
||||
results.get().set_interrupt(interrupt);
|
||||
Promise::ok(())
|
||||
std::future::ready(Ok(()))
|
||||
}
|
||||
|
||||
fn get_notifications(
|
||||
&mut self,
|
||||
self: Rc<Self>,
|
||||
params: daemon::GetNotificationsParams,
|
||||
mut results: daemon::GetNotificationsResults,
|
||||
) -> Promise<(), capnp::Error> {
|
||||
) -> impl std::future::Future<Output = Result<(), capnp::Error>> {
|
||||
let min_urgency = pry!(params.get()).get_min_urgency();
|
||||
let mut s = self.state.borrow_mut();
|
||||
|
||||
|
|
@ -304,14 +303,14 @@ impl daemon::Server for DaemonImpl {
|
|||
entry.set_timestamp(n.timestamp);
|
||||
}
|
||||
|
||||
Promise::ok(())
|
||||
std::future::ready(Ok(()))
|
||||
}
|
||||
|
||||
fn get_types(
|
||||
&mut self,
|
||||
self: Rc<Self>,
|
||||
_params: daemon::GetTypesParams,
|
||||
mut results: daemon::GetTypesResults,
|
||||
) -> Promise<(), capnp::Error> {
|
||||
) -> impl std::future::Future<Output = Result<(), capnp::Error>> {
|
||||
let s = self.state.borrow();
|
||||
let types = &s.notifications.types;
|
||||
|
||||
|
|
@ -325,14 +324,14 @@ impl daemon::Server for DaemonImpl {
|
|||
entry.set_threshold(info.threshold.map_or(-1, |t| t as i8));
|
||||
}
|
||||
|
||||
Promise::ok(())
|
||||
std::future::ready(Ok(()))
|
||||
}
|
||||
|
||||
fn set_threshold(
|
||||
&mut self,
|
||||
self: Rc<Self>,
|
||||
params: daemon::SetThresholdParams,
|
||||
_results: daemon::SetThresholdResults,
|
||||
) -> Promise<(), capnp::Error> {
|
||||
) -> impl std::future::Future<Output = Result<(), capnp::Error>> {
|
||||
let params = pry!(params.get());
|
||||
let ntype = pry!(pry!(params.get_type()).to_str()).to_string();
|
||||
let level = params.get_level();
|
||||
|
|
@ -341,14 +340,14 @@ impl daemon::Server for DaemonImpl {
|
|||
.borrow_mut()
|
||||
.notifications
|
||||
.set_threshold(&ntype, level);
|
||||
Promise::ok(())
|
||||
std::future::ready(Ok(()))
|
||||
}
|
||||
|
||||
fn module_command(
|
||||
&mut self,
|
||||
self: Rc<Self>,
|
||||
params: daemon::ModuleCommandParams,
|
||||
mut results: daemon::ModuleCommandResults,
|
||||
) -> Promise<(), capnp::Error> {
|
||||
) -> impl std::future::Future<Output = Result<(), capnp::Error>> {
|
||||
let params = pry!(params.get());
|
||||
let module = pry!(pry!(params.get_module()).to_str()).to_string();
|
||||
let _command = pry!(pry!(params.get_command()).to_str()).to_string();
|
||||
|
|
@ -364,7 +363,7 @@ impl daemon::Server for DaemonImpl {
|
|||
results
|
||||
.get()
|
||||
.set_result(&format!("unknown module: {module}"));
|
||||
Promise::ok(())
|
||||
std::future::ready(Ok(()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -375,7 +374,7 @@ macro_rules! pry {
|
|||
($e:expr) => {
|
||||
match $e {
|
||||
Ok(v) => v,
|
||||
Err(e) => return Promise::err(e.into()),
|
||||
Err(e) => return std::future::ready(Err(e.into())),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@ use tokio::net::UnixStream;
|
|||
use tokio_util::compat::TokioAsyncReadCompatExt;
|
||||
use log::{info, warn};
|
||||
|
||||
use std::rc::Rc;
|
||||
use crate::channel_capnp::{channel_client, channel_server};
|
||||
use capnp::capability::Promise;
|
||||
|
||||
// ── Channel notifications ───────────────────────────────────────
|
||||
|
||||
|
|
@ -33,10 +33,10 @@ struct NotifyForwarder {
|
|||
|
||||
impl channel_client::Server for NotifyForwarder {
|
||||
fn notify(
|
||||
&mut self,
|
||||
self: Rc<Self>,
|
||||
params: channel_client::NotifyParams,
|
||||
_results: channel_client::NotifyResults,
|
||||
) -> Promise<(), capnp::Error> {
|
||||
) -> impl std::future::Future<Output = Result<(), capnp::Error>> {
|
||||
if let Ok(params) = params.get() {
|
||||
if let Ok(notifications) = params.get_notifications() {
|
||||
for n in notifications.iter() {
|
||||
|
|
@ -57,7 +57,7 @@ impl channel_client::Server for NotifyForwarder {
|
|||
}
|
||||
}
|
||||
}
|
||||
Promise::ok(())
|
||||
std::future::ready(Ok(()))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue