Skip to content

Commit dad3bed

Browse files
committed
feat(dvc): expose dynamic channel accessors
Add mutable dynamic channel lookup APIs for drdynvc server. Signed-off-by: uchouT <i@uchout.moe>
1 parent 9046144 commit dad3bed

3 files changed

Lines changed: 67 additions & 1 deletion

File tree

crates/ironrdp-dvc/src/client.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ impl DrdynvcClient {
161161
self.dynamic_channels.get_by_channel_id(channel_id)
162162
}
163163

164+
pub fn get_dvc_by_channel_id_mut(&mut self, channel_id: u32) -> Option<&mut DynamicVirtualChannel> {
165+
self.dynamic_channels.get_by_channel_id_mut(channel_id)
166+
}
167+
164168
fn create_capabilities_response(&mut self, server_version: CapsVersion) -> SvcMessage {
165169
let caps_response = DrdynvcClientPdu::Capabilities(CapabilitiesResponsePdu::new(server_version));
166170
debug!("Send DVC Capabilities Response PDU: {caps_response:?}");

crates/ironrdp-dvc/src/lib.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,5 +163,53 @@ impl DynamicVirtualChannel {
163163
}
164164
}
165165

166+
#[derive(Debug, Clone, Copy)]
167+
pub struct DynamicChannelRef<'a, T> {
168+
channel_id: DynamicChannelId,
169+
processor: &'a T,
170+
}
171+
172+
impl<T> DynamicChannelRef<'_, T> {
173+
pub fn channel_id(&self) -> DynamicChannelId {
174+
self.channel_id
175+
}
176+
}
177+
178+
impl<'a, T: DvcProcessor> DynamicChannelRef<'a, T> {
179+
fn new(channel_id: u32, processor: &'a T) -> Self {
180+
Self { channel_id, processor }
181+
}
182+
183+
pub fn processor(&self) -> &T {
184+
self.processor
185+
}
186+
}
187+
188+
#[derive(Debug)]
189+
pub struct DynamicChannelMut<'a, T> {
190+
channel_id: DynamicChannelId,
191+
processor: &'a mut T,
192+
}
193+
194+
impl<T> DynamicChannelMut<'_, T> {
195+
pub fn channel_id(&self) -> DynamicChannelId {
196+
self.channel_id
197+
}
198+
}
199+
200+
impl<'a, T: DvcProcessor> DynamicChannelMut<'a, T> {
201+
fn new(channel_id: u32, processor: &'a mut T) -> Self {
202+
Self { channel_id, processor }
203+
}
204+
205+
pub fn processor(&self) -> &T {
206+
self.processor
207+
}
208+
209+
pub fn processor_mut(&mut self) -> &mut T {
210+
self.processor
211+
}
212+
}
213+
166214
pub type DynamicChannelName = String;
167215
pub type DynamicChannelId = u32;

crates/ironrdp-dvc/src/server.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use tracing::debug;
1414
use crate::pdu::{
1515
CapabilitiesRequestPdu, CapsVersion, ClosePdu, CreateRequestPdu, CreationStatus, DrdynvcClientPdu, DrdynvcServerPdu,
1616
};
17-
use crate::{CompleteData, DvcProcessor, encode_dvc_messages};
17+
use crate::{CompleteData, DvcProcessor, DynamicChannelMut, DynamicChannelRef, encode_dvc_messages};
1818

1919
pub trait DvcServerProcessor: DvcProcessor {}
2020

@@ -186,6 +186,20 @@ impl DrdynvcServer {
186186
.ok_or_else(|| invalid_field_err!("DRDYNVC", "", "invalid channel id"))
187187
}
188188

189+
pub fn dvc_by_id<T: DvcServerProcessor>(&self, id: u32) -> Option<DynamicChannelRef<'_, T>> {
190+
self.dynamic_channels
191+
.get(id)
192+
.and_then(|w| w.processor.as_any().downcast_ref())
193+
.map(|p| DynamicChannelRef::new(id, p))
194+
}
195+
196+
pub fn dvc_by_id_mut<T: DvcServerProcessor>(&mut self, id: u32) -> Option<DynamicChannelMut<'_, T>> {
197+
self.dynamic_channels
198+
.get_mut(id)
199+
.and_then(|c| c.processor.as_any_mut().downcast_mut())
200+
.map(|p| DynamicChannelMut::new(id, p))
201+
}
202+
189203
/// Creates a new DVC, returns CreateRequest PDU to send to client.
190204
///
191205
/// # Panics

0 commit comments

Comments
 (0)