Skip to content

Commit

Permalink
remove the Timer trait and associated (out of date) docs
Browse files Browse the repository at this point in the history
  • Loading branch information
folkertdev committed Aug 3, 2023
1 parent 6786412 commit fa73776
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 122 deletions.
12 changes: 1 addition & 11 deletions statime-linux/src/clock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::path::Path;

use clock_steering::unix::UnixClock;
use statime::{Clock, Duration, Time, TimePropertiesDS, Timer};
use statime::{Clock, Duration, Time, TimePropertiesDS};

#[derive(Debug, Clone)]
pub struct LinuxClock {
Expand Down Expand Up @@ -81,16 +81,6 @@ impl Clock for LinuxClock {
}
}

pub struct LinuxTimer;

impl Timer for LinuxTimer {
type F = tokio::time::Sleep;

fn after(&self, duration: Duration) -> Self::F {
tokio::time::sleep(duration.into())
}
}

pub fn libc_timespec_into_instant(spec: libc::timespec) -> Time {
Time::from_fixed_nanos(spec.tv_sec as i128 * 1_000_000_000i128 + spec.tv_nsec as i128)
}
15 changes: 0 additions & 15 deletions statime/src/clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,3 @@ pub trait Clock {
time_properties_ds: &TimePropertiesDS,
) -> Result<(), Self::Error>;
}

/// Async timer trait for waiting an interval
///
/// The Timer trait is the primary way the ptp futures wait for time to pass.
/// The after future should provide waiting for multpile timers.
///
/// Note: the timer need not use a high precision time source. The only
/// requirement is that the underlying definition of a second is the same
/// between the [Clock] and timers.
pub trait Timer {
/// Wait for a given amount of time
type F: core::future::Future + Send + 'static;

fn after(&self, duration: Duration) -> Self::F;
}
99 changes: 3 additions & 96 deletions statime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
//! clock and to access the network. That needs to be provided by the user of
//! the library.
//!
//! For this purpose, `statime` defines two sets of interfaces. [`Clock`] and
//! [Timer] provide access to the system clock, and allow `statime` to wait for
//! various time intervals. The [`NetworkRuntime`] and [`NetworkPort`]
//! The `statime` crate defines a [`Clock`] interface that provide access to the
//! system clock. The [`NetworkRuntime`] and [`NetworkPort`]
//! abstractions provide the needed glue to access the network.
//!
//! On modern linux kernels, the `statime-linux` crate provides ready to use
Expand All @@ -31,98 +30,6 @@
//! storing it in the first six bytes of the clock identifier, setting the
//! remaining bytes to 0. For more details on the exact specification of the
//! generation procedure, see IEEE1588-2019 section 7.5.2.2.2
//!
//! # Ordinary clock example
//! Assuming we already have a network runtime and clock runtime, an ordinary
//! clock can be run by first creating all the datasets, then creating the port,
//! then finally setting up the instance and starting it:
//!
//! ```ignore
//! let default_ds = DefaultDS::new_ordinary_clock(
//! clock_identity,
//! 128,
//! 128,
//! 0,
//! false,
//! SdoId::new(0).unwrap(),
//! );
//! let time_properties_ds =
//! TimePropertiesDS::new_arbitrary_time(false, false, TimeSource::InternalOscillator);
//! let port_ds = PortDS::new(
//! PortIdentity {
//! clock_identity,
//! port_number: 1,
//! },
//! 1,
//! 1,
//! 3,
//! 0,
//! DelayMechanism::E2E,
//! 1,
//! );
//! let port = Port::new(port_ds, &mut network_runtime, interface_name).await;
//! let mut instance = PtpInstance::new_ordinary_clock(
//! default_ds,
//! time_properties_ds,
//! port,
//! local_clock,
//! BasicFilter::new(0.25),
//! );
//!
//! instance.run(&TimerImpl).await;
//! ```
//!
//! # Boundary clock
//! Setting up a boundary clock is a similar process. However, instead of
//! creating a single port, multiple ports need to be created. For example:
//!
//! ```ignore
//! let default_ds = DefaultDS::new_ordinary_clock(
//! clock_identity,
//! 128,
//! 128,
//! 0,
//! false,
//! SdoId::new(0).unwrap(),
//! );
//! let time_properties_ds =
//! TimePropertiesDS::new_arbitrary_time(false, false, TimeSource::InternalOscillator);
//! let port_1_ds = PortDS::new(
//! PortIdentity {
//! clock_identity,
//! port_number: 1,
//! },
//! 1,
//! 1,
//! 3,
//! 0,
//! DelayMechanism::E2E,
//! 1,
//! );
//! let port_1 = Port::new(port_1_ds, &mut network_runtime, interface_name_1).await;
//! let port_2_ds = PortDS::new(
//! PortIdentity {
//! clock_identity,
//! port_number: 2,
//! },
//! 1,
//! 1,
//! 3,
//! 0,
//! DelayMechanism::E2E,
//! 1,
//! );
//! let port_2 = Port::new(port_2_ds, &mut network_runtime, interface_name_2).await;
//! let mut instance = PtpInstance::new_boundary_clock(
//! default_ds,
//! time_properties_ds,
//! [port_1, port_2],
//! local_clock,
//! BasicFilter::new(0.25),
//! );
//!
//! instance.run(&TimerImpl).await;
//! ```

#![no_std]

Expand All @@ -138,7 +45,7 @@ mod port;
mod ptp_instance;
mod time;

pub use clock::{Clock, Timer};
pub use clock::Clock;
pub use config::{DelayMechanism, InstanceConfig, PortConfig};
#[cfg(feature = "fuzz")]
pub use datastructures::messages::Message;
Expand Down

0 comments on commit fa73776

Please sign in to comment.