-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from Xila-Project/Feature/Time
Feature/Time
- Loading branch information
Showing
19 changed files
with
390 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,45 @@ | ||
use std::time::SystemTime; | ||
use std::time::{SystemTime, UNIX_EPOCH}; | ||
|
||
pub struct Time_driver_type { | ||
Start_time: SystemTime, | ||
} | ||
use File_system::{Device_trait, Error_type, Result_type, Size_type}; | ||
use Shared::Duration_type; | ||
|
||
pub struct Time_driver_type; | ||
|
||
impl Time_driver_type { | ||
pub fn New() -> Self { | ||
Self { | ||
Start_time: SystemTime::now(), | ||
} | ||
Self {} | ||
} | ||
} | ||
|
||
impl Time::Driver_trait for Time_driver_type { | ||
fn Get_instant_since_startup(&self) -> Time::Duration_type { | ||
self.Start_time | ||
.elapsed() | ||
.expect("Failed to get elapsed time") | ||
impl Device_trait for Time_driver_type { | ||
fn Read(&self, Buffer: &mut [u8]) -> Result_type<Size_type> { | ||
let Duration = SystemTime::now() | ||
.duration_since(UNIX_EPOCH) | ||
.map_err(|_| Error_type::Internal_error)?; | ||
|
||
let Duration = Duration_type::New(Duration.as_secs(), Duration.subsec_nanos()); | ||
|
||
Buffer.copy_from_slice(Duration.as_ref()); | ||
|
||
Ok(Buffer.len().into()) | ||
} | ||
|
||
fn Write(&self, _: &[u8]) -> Result_type<File_system::Size_type> { | ||
Err(Error_type::Unsupported_operation) | ||
} | ||
|
||
fn Get_size(&self) -> File_system::Result_type<File_system::Size_type> { | ||
Ok(size_of::<Duration_type>().into()) | ||
} | ||
|
||
fn Set_position( | ||
&self, | ||
_: &File_system::Position_type, | ||
) -> File_system::Result_type<File_system::Size_type> { | ||
Err(Error_type::Unsupported_operation) | ||
} | ||
|
||
fn Get_current_time(&self) -> Time::Duration_type { | ||
SystemTime::now() | ||
.duration_since(SystemTime::UNIX_EPOCH) | ||
.expect("Failed to get current time") | ||
fn Flush(&self) -> File_system::Result_type<()> { | ||
Err(Error_type::Unsupported_operation) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.