#![deny(missing_docs)]
extern crate bindgen;
extern crate cc;
mod generator;
pub use generator::Generator;
pub struct Provider {
name: String,
classes: Vec<EventClass>,
}
impl Provider {
pub fn new<S: Into<String>>(name: S) -> Provider {
Provider {
name: name.into(),
classes: Vec::new(),
}
}
pub fn create_class<S: Into<String>>(&mut self, class_name: S) -> &mut EventClass {
self.classes.push(EventClass::new(class_name.into()));
let cls_len = self.classes.len();
&mut self.classes[cls_len - 1]
}
}
pub struct EventClass {
class_name: String,
fields: Vec<Field>,
instances: Vec<EventInstance>,
}
impl EventClass {
fn new(class_name: String) -> Self {
EventClass {
class_name,
fields: Vec::new(),
instances: Vec::new(),
}
}
pub fn add_field<S: Into<String>>(&mut self, field_name: S, ty: CTFType) -> &mut Self {
self.fields.push(Field::new(
field_name.into(), ty
));
self
}
pub fn instantiate<S: Into<String>>(&mut self, instance_name: S) -> &mut Self {
self.instantiate_with_level(instance_name, LogLevel::DebugLine)
}
pub fn instantiate_with_level<S: Into<String>>(&mut self,
instance_name: S,
level: LogLevel) -> &mut Self {
self.instances.push(EventInstance::new(
instance_name.into(),
level
));
self
}
}
pub struct Field {
ctf_type: CTFType,
name: String,
}
impl Field {
fn new(name: String, ctf_type: CTFType) -> Self {
Self {
ctf_type, name,
}
}
}
pub struct EventInstance {
name: String,
level: LogLevel,
}
impl EventInstance {
fn new(name: String, level: LogLevel) -> Self {
EventInstance {
name, level,
}
}
}
pub enum LogLevel {
Emergency,
Alert,
Critical,
Error,
Warning,
Notice,
Info,
DebugSystem,
DebugProgram,
DebugProcess,
DebugModule,
DebugUnit,
DebugFunction,
DebugLine,
Debug
}
impl LogLevel {
fn lttng_level(&self) -> &'static str {
use LogLevel::*;
match *self {
Emergency => "TRACE_EMERG",
Alert => "TRACE_ALERT",
Critical => "TRACE_CRIT",
Error => "TRACE_ERR",
Warning => "TRACE_WARNING",
Notice => "TRACE_NOTICE",
Info => "TRACE_INFO",
DebugSystem => "TRACE_DEBUG_SYSTEM",
DebugProgram => "TRACE_DEBUG_PROGRAM",
DebugProcess => "TRACE_DEBUG_PROCESS",
DebugModule => "TRACE_DEBUG_MODULE",
DebugUnit => "TRACE_DEBUG_UNIT",
DebugFunction => "TRACE_DEBUG_FUNCTION",
DebugLine => "TRACE_DEBUG_LINE",
Debug => "TRACE_DEBUG",
}
}
}
#[derive(Copy,Clone,PartialEq,Eq,Debug)]
#[allow(missing_docs)]
pub enum CIntegerType {
I8, I16, I32, I64,
U8, U16, U32, U64,
}
impl CIntegerType {
fn c_type(&self) -> &'static str {
match *self {
CIntegerType::I8 => "int8_t",
CIntegerType::U8 => "uint8_t",
CIntegerType::I16 => "int16_t",
CIntegerType::U16 => "uint16_t",
CIntegerType::I32 => "int32_t",
CIntegerType::U32 => "uint32_t",
CIntegerType::I64 => "int64_t",
CIntegerType::U64 => "uint64_t"
}
}
fn c_pointer_type(&self) -> &'static str {
match *self {
CIntegerType::I8 => "int8_t *",
CIntegerType::U8 => "uint8_t *",
CIntegerType::I16 => "int16_t *",
CIntegerType::U16 => "uint16_t *",
CIntegerType::I32 => "int32_t *",
CIntegerType::U32 => "uint32_t *",
CIntegerType::I64 => "int64_t *",
CIntegerType::U64 => "uint64_t *"
}
}
fn rust_type(&self) -> &'static str {
match *self {
CIntegerType::I8 => "i8",
CIntegerType::U8 => "u8",
CIntegerType::I16 => "i16",
CIntegerType::U16 => "u16",
CIntegerType::I32 => "i32",
CIntegerType::U32 => "u32",
CIntegerType::I64 => "i64",
CIntegerType::U64 => "u64",
}
}
}
#[derive(Copy,Clone,PartialEq,Eq,Debug)]
#[allow(missing_docs)]
pub enum CFloatType {
Single, Double
}
impl CFloatType {
fn c_type(&self) -> &'static str {
match *self {
CFloatType::Single => "float",
CFloatType::Double => "double",
}
}
fn rust_type(&self) -> &'static str {
match *self {
CFloatType::Single => "f32",
CFloatType::Double => "f64",
}
}
}
#[derive(Copy,Clone,PartialEq,Eq,Debug)]
pub enum CTFType {
Integer(CIntegerType),
IntegerNoWrite(CIntegerType),
IntegerHex(CIntegerType),
IntegerNetwork(CIntegerType),
IntegerNetworkHex(CIntegerType),
Float(CFloatType),
FloatNoWrite(CFloatType),
String,
StringNoWrite,
Array(CIntegerType, i32),
ArrayText(i32),
ArrayNoWrite(CIntegerType, i32),
Sequence(CIntegerType),
SequenceNoWrite(CIntegerType),
SequenceText,
SequenceTextNoWrite,
Enum,
EnumNoWrite,
}
impl CTFType {
fn is_sequence(&self) -> bool {
match *self {
CTFType::Sequence(_) |
CTFType::SequenceNoWrite(_) |
CTFType::SequenceText |
CTFType::SequenceTextNoWrite => true,
_ => false,
}
}
}