use crate::native::etw_types::DecodingSource;
use crate::native::tdh::TraceEventInfo;
use crate::native::tdh_types::{Property, PropertyError};
use once_cell::sync::OnceCell;
pub struct Schema {
te_info: TraceEventInfo,
cached_properties: OnceCell<Result<Vec<Property>, PropertyError>>,
}
impl Schema {
pub(crate) fn new(te_info: TraceEventInfo) -> Self {
Schema {
te_info,
cached_properties: OnceCell::new()
}
}
pub fn decoding_source(&self) -> DecodingSource {
self.te_info.decoding_source()
}
pub fn provider_name(&self) -> String {
self.te_info.provider_name()
}
pub fn task_name(&self) -> String {
self.te_info.task_name()
}
pub fn opcode_name(&self) -> String {
self.te_info.opcode_name()
}
pub(crate) fn properties(&self) -> &[Property] {
let cache = self.cached_properties.get_or_init(|| {
let mut cache = Vec::new();
for property in self.te_info.properties() {
cache.push(property?)
}
Ok(cache)
});
match cache {
Err(PropertyError::UnimplementedType) => {
log::error!("Unable to list properties: a type is not implemented");
&[]
}
Ok(cache) => cache.as_slice()
}
}
}
impl PartialEq for Schema {
fn eq(&self, other: &Self) -> bool {
self.te_info.event_id() == other.te_info.event_id()
&& self.te_info.provider_guid() == other.te_info.provider_guid()
&& self.te_info.event_version() == other.te_info.event_version()
}
}
impl Eq for Schema {}