-
Notifications
You must be signed in to change notification settings - Fork 25
Log #61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
YruamaLairba
wants to merge
26
commits into
RustAudio:develop
Choose a base branch
from
YruamaLairba:log
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Log #61
Changes from 5 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
b0fce0c
init lv2-log crate
YruamaLairba 79e0864
implement feature part of log
YruamaLairba 101d936
impl Uribound and LogURIDcollection for type of log
YruamaLairba 875153c
usable but unsafe draft
YruamaLairba 3d3a31e
avoid '%' be interpreted, Format code
YruamaLairba 862fa63
check for null string terminator for safety
YruamaLairba 92691a4
create and use LogError enum
YruamaLairba eca5acd
Copy as supertrait for entry urid
YruamaLairba 40ea7b7
add some doc
YruamaLairba 36bf4fe
restrict log feature to the instantiation threading class
YruamaLairba fe6d8d7
WIP
YruamaLairba 575a626
Merge branch 'develop' into log
YruamaLairba 0eff4b0
fix the code after merge
YruamaLairba 5eb55ab
apply prokopyl suggestion to refactor code
YruamaLairba d278053
forbid log feature only in the audio threading class
YruamaLairba a5c2d6f
change print to print_cstr
YruamaLairba 5226867
remove println, it's not needed and almost useless
YruamaLairba 97c4175
fix EntryType marker trait
YruamaLairba f6fd9ee
use a custom type to not have function pointer inside Option
YruamaLairba 30656af
replace LogError by PrintError
YruamaLairba 6e0ee4a
shorten the name and redocument URID marker
YruamaLairba 826aeb0
ooops, log is not rt-safe but is valid in any threading class
YruamaLairba f0a47aa
oops, forgot to remove some _class suffix
YruamaLairba 99e12cc
use a pointer replacement.
YruamaLairba ed9613b
complete and rework the log crate doc
YruamaLairba 5134b89
fix example test (missing dev dependencie)
YruamaLairba File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| [package] | ||
| name = "lv2-log" | ||
| version = "0.1.0" | ||
| authors = ["Yruama_Lairba <[email protected]>"] | ||
| edition = "2018" | ||
|
|
||
| # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
|
||
| [dependencies] | ||
| lv2-sys = "1.0.0" | ||
| lv2-core = "1.0.0" | ||
| urid = "0.1.0" |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| use lv2_core::feature::*; | ||
| //use std::ffi::CString; | ||
| use std::fmt; | ||
| use std::os::raw::*; //get all common c_type | ||
| use urid::*; | ||
|
|
||
| pub struct EntryClass; | ||
| unsafe impl UriBound for EntryClass { | ||
YruamaLairba marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const URI: &'static [u8] = lv2_sys::LV2_LOG__Entry; | ||
| } | ||
|
|
||
| pub struct ErrorClass; | ||
| unsafe impl UriBound for ErrorClass { | ||
| const URI: &'static [u8] = lv2_sys::LV2_LOG__Error; | ||
| } | ||
|
|
||
| pub struct NoteClass; | ||
| unsafe impl UriBound for NoteClass { | ||
| const URI: &'static [u8] = lv2_sys::LV2_LOG__Note; | ||
| } | ||
|
|
||
| pub struct TraceClass; | ||
| unsafe impl UriBound for TraceClass { | ||
| const URI: &'static [u8] = lv2_sys::LV2_LOG__Trace; | ||
| } | ||
|
|
||
| pub struct WarningClass; | ||
| unsafe impl UriBound for WarningClass { | ||
| const URI: &'static [u8] = lv2_sys::LV2_LOG__Warning; | ||
| } | ||
|
|
||
| /// Marker for URID representing the nature of a log message | ||
| // Note : it's may be better to have a URID trait to define a common interface | ||
| pub unsafe trait EntryType { | ||
| fn get(self) -> u32; | ||
| } | ||
|
|
||
| unsafe impl EntryType for URID<ErrorClass> { | ||
YruamaLairba marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| fn get(self) -> u32 { | ||
| URID::<ErrorClass>::get(self) | ||
| } | ||
| } | ||
| unsafe impl EntryType for URID<NoteClass> { | ||
| fn get(self) -> u32 { | ||
| URID::<NoteClass>::get(self) | ||
| } | ||
| } | ||
| unsafe impl EntryType for URID<TraceClass> { | ||
| fn get(self) -> u32 { | ||
| URID::<TraceClass>::get(self) | ||
| } | ||
| } | ||
| unsafe impl EntryType for URID<WarningClass> { | ||
| fn get(self) -> u32 { | ||
| URID::<WarningClass>::get(self) | ||
| } | ||
| } | ||
|
|
||
| /// The Log feature | ||
| #[repr(transparent)] | ||
| pub struct Log<'a> { | ||
| internal: &'a lv2_sys::LV2_Log_Log, | ||
| } | ||
|
|
||
| unsafe impl<'a> UriBound for Log<'a> { | ||
| const URI: &'static [u8] = lv2_sys::LV2_LOG__log; | ||
| } | ||
|
|
||
| unsafe impl<'a> Feature for Log<'a> { | ||
| // Note: this feature can be used in any threading class and doesn't seems to have thready | ||
| // unsafty | ||
| unsafe fn from_feature_ptr(feature: *const c_void, _class: ThreadingClass) -> Option<Self> { | ||
| (feature as *const lv2_sys::LV2_Log_Log) | ||
| .as_ref() | ||
| .map(|internal| Self { internal }) | ||
| } | ||
| } | ||
|
|
||
| impl<'a> Log<'a> { | ||
| pub fn print(&self, entry_type: impl EntryType, message: &[u8]) -> Result<(), ()> { | ||
YruamaLairba marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| let printf = if let Some(printf) = self.internal.printf { | ||
| printf | ||
| } else { | ||
| return Err(()); | ||
| }; | ||
| let res = unsafe { | ||
| (printf)( | ||
| self.internal.handle, | ||
| entry_type.get(), | ||
| b"%s\0" as *const _ as *const c_char, | ||
| message as *const _ as *const c_char, | ||
| ) | ||
| }; | ||
| if res > 0 { | ||
| Ok(()) | ||
| } else { | ||
| Err(()) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// A URID cache containing all time properties. | ||
| #[derive(URIDCollection, Debug)] | ||
| pub struct LogURIDCollection { | ||
| pub entry_class: URID<EntryClass>, | ||
| pub error_class: URID<ErrorClass>, | ||
| pub note_class: URID<NoteClass>, | ||
| pub trace_class: URID<TraceClass>, | ||
| pub warning_class: URID<WarningClass>, | ||
| //pub log: URID<Log<'a>>, | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
YruamaLairba marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #[test] | ||
| fn it_works() { | ||
| assert_eq!(2 + 2, 4); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think having the entry types in a submodule (
entriesfor instance) would be a cleaner, although it's not a lot of code, it'll show up as quite a few types in the rustdoc and might be a bit overwhelming for new users that might want to focus elsewhere (mainly theLogfeature, or the entry type trait).