Skip to content

Commit

Permalink
simplified cloning
Browse files Browse the repository at this point in the history
  • Loading branch information
teodly committed Aug 30, 2024
1 parent 5904a4e commit b5c339a
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions statime-linux/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,20 @@ use tokio::{
time::Sleep,
};

trait PortClock: Clock<Error = <LinuxClock as Clock>::Error> + PortTimestampToTime {}
impl PortClock for LinuxClock {}
impl PortClock for SharedClock<OverlayClock<LinuxClock>> {}
type BoxedClock = Box<dyn PortClock + Send + Sync>;
trait PortClock: Clock<Error = <LinuxClock as Clock>::Error> + PortTimestampToTime + Send + Sync {
fn clone_box(&self) -> Box<dyn PortClock>;
}
impl PortClock for LinuxClock {
fn clone_box(&self) -> Box<dyn PortClock> {
Box::new(self.clone())
}
}
impl PortClock for SharedClock<OverlayClock<LinuxClock>> {
fn clone_box(&self) -> Box<dyn PortClock> {
Box::new(self.clone())
}
}
type BoxedClock = Box<dyn PortClock>;
type SharedOverlayClock = SharedClock<OverlayClock<LinuxClock>>;

#[derive(Parser, Debug)]
Expand Down Expand Up @@ -302,7 +312,7 @@ async fn actual_main() {
for port_config in config.ports {
let interface = port_config.interface;
let network_mode = port_config.network_mode;
let (port_clock, port_clock2, timestamping) = match port_config.hardware_clock {
let (port_clock, timestamping) = match port_config.hardware_clock {
Some(idx) => {
let clock = LinuxClock::open_idx(idx).expect("Unable to open clock");
if let Some(id) = clock_name_map.get(&idx) {
Expand All @@ -315,15 +325,13 @@ async fn actual_main() {
.push(start_clock_task(clock.clone(), system_clock.clone()));
}
(
Box::new(clock.clone()) as BoxedClock,
Box::new(clock) as BoxedClock,
InterfaceTimestampMode::HardwarePTPAll,
)
}
None => {
clock_port_map.push(None);
(
system_clock.clone_boxed(),
system_clock.clone_boxed(),
InterfaceTimestampMode::SoftwareAll,
)
Expand All @@ -335,7 +343,7 @@ async fn actual_main() {
let port = instance.add_port(
port_config.into(),
KalmanConfiguration::default(),
port_clock2,
port_clock.clone_box(),
rng,
);

Expand Down

0 comments on commit b5c339a

Please sign in to comment.