Skip to content

Commit 32f35f8

Browse files
committed
WIP
1 parent 2dcb1ba commit 32f35f8

File tree

1 file changed

+31
-15
lines changed

1 file changed

+31
-15
lines changed

log/src/lib.rs

+31-15
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ unsafe impl<'a> Feature for Log<'a> {
9595
// So, at this time, i just giving access to it instanciation class
9696
unsafe fn from_feature_ptr(feature: *const c_void, class: ThreadingClass) -> Option<Self> {
9797
if class == ThreadingClass::Instantiation {
98-
(feature as *const lv2_sys::LV2_Log_Log)
99-
.as_ref()
100-
.map(|internal| Self { internal })
98+
(feature as *const lv2_sys::LV2_Log_Log)
99+
.as_ref()
100+
.map(|internal| Self { internal })
101101
} else {
102102
panic!("The log feature is only allowed in the indtantiation threading class");
103103
}
@@ -107,7 +107,7 @@ unsafe impl<'a> Feature for Log<'a> {
107107
impl<'a> Log<'a> {
108108
/// Send a log message to the host.
109109
///
110-
/// the `entry_type` parameter is an URID representing the kind of log message. There are four
110+
/// The `entry_type` parameter is an URID representing the kind of log message. There are four
111111
/// kind of message:
112112
/// * **note:** an informative message.
113113
/// * **warning:** a warning message.
@@ -122,24 +122,40 @@ impl<'a> Log<'a> {
122122
} else {
123123
return Err(LogError::NoCallback);
124124
};
125-
//checking for null terminator
126-
let mut have_null = false;
127-
for b in message.bytes() {
128-
if b == b'\0' {
129-
have_null = true;
130-
break;
131-
}
132-
}
133-
if !have_null {
134-
return Err(LogError::NoNullTerminator);
125+
let message = String::from(message) + "\0";
126+
127+
let res = unsafe {
128+
(printf)(
129+
self.internal.handle,
130+
entry_type.get(),
131+
"%s\0" as *const _ as *const c_char,
132+
message.as_str() as *const _ as *const c_char,
133+
)
134+
};
135+
if res > 0 {
136+
Ok(())
137+
} else {
138+
Err(LogError::PrintError)
135139
}
140+
}
141+
/// Send a message to the host with a new line at the end.
142+
///
143+
/// It same as [print](struct.Log.html#method.print) but add a newline a the end of message.
144+
/// See [print](struct.Log.html#method.print) documentation for details.
145+
pub fn println(&self, entry_type: impl EntryType, message: &str) -> Result<(), LogError> {
146+
let printf = if let Some(printf) = self.internal.printf {
147+
printf
148+
} else {
149+
return Err(LogError::NoCallback);
150+
};
151+
let message = String::from(message) + "\n\0";
136152

137153
let res = unsafe {
138154
(printf)(
139155
self.internal.handle,
140156
entry_type.get(),
141157
"%s\0" as *const _ as *const c_char,
142-
message as *const _ as *const c_char,
158+
message.as_str() as *const _ as *const c_char,
143159
)
144160
};
145161
if res > 0 {

0 commit comments

Comments
 (0)