rate_core/actors/provider_session/
link.rs1use super::ProviderSession;
2use crate::actors::client_session::ClientSender;
3use anyhow::Error;
4use derive_more::From;
5use meio::{Action, Address, Interaction, InteractionTask};
6use rill_protocol::io::client::ClientReqId;
7use rill_protocol::io::provider::{Path, ProviderReqId, RecorderAction};
8
9#[derive(Debug, From, Clone)]
10pub struct ProviderLink {
11 address: Address<ProviderSession>,
12}
13
14pub struct SubscribeToPath {
15 pub path: Path,
16 pub direct_id: ClientReqId,
17 pub sender: ClientSender,
18}
19
20impl Interaction for SubscribeToPath {
21 type Output = SubscriptionLink;
22}
23
24impl ProviderLink {
25 pub fn subscribe(
26 &mut self,
27 path: Path,
28 direct_id: ClientReqId,
29 sender: ClientSender,
30 ) -> InteractionTask<SubscribeToPath> {
31 let msg = SubscribeToPath {
32 path,
33 direct_id,
34 sender,
35 };
36 self.address.interact(msg)
37 }
38}
39
40pub struct ActionOnPath {
41 pub path: Path,
42 pub direct_id: ClientReqId,
43 pub sender: ClientSender,
44 pub action: RecorderAction,
45}
46
47impl Action for ActionOnPath {}
48
49impl ProviderLink {
50 pub async fn action_on_path(
51 &mut self,
52 path: Path,
53 direct_id: ClientReqId,
54 sender: ClientSender,
55 action: RecorderAction,
56 ) -> Result<(), Error> {
57 let msg = ActionOnPath {
58 path: path.clone(),
59 direct_id,
60 sender,
61 action,
62 };
63 self.address.act(msg).await
64 }
65}
66
67#[derive(Debug)]
68pub struct SubscriptionLink {
69 pub(super) address: Address<ProviderSession>,
70 pub(super) path: Path,
71 pub(super) req_id: ProviderReqId,
72}
73
74pub struct UnsubscribeFromPath {
75 pub path: Path,
76 pub req_id: ProviderReqId,
77}
78
79impl Interaction for UnsubscribeFromPath {
80 type Output = ();
81}
82
83impl SubscriptionLink {
84 pub fn unsubscribe(self) -> InteractionTask<UnsubscribeFromPath> {
85 let msg = UnsubscribeFromPath {
86 path: self.path,
87 req_id: self.req_id,
88 };
89 self.address.interact(msg)
90 }
91}