use crate::source::SourceRange;
use crate::types::{Access, AccessKeyword, BaseType, Status};
use super::oid::OidAssignment;
use super::syntax::{DefVal, TypeSyntax};
#[derive(Debug, Clone)]
pub enum Definition {
ObjectType(ObjectType),
ModuleIdentity(ModuleIdentity),
ObjectIdentity(ObjectIdentity),
Notification(Notification),
TypeDef(TypeDef),
ValueAssignment(ValueAssignment),
ObjectGroup(ObjectGroup),
NotificationGroup(NotificationGroup),
ModuleCompliance(ModuleCompliance),
AgentCapabilities(AgentCapabilities),
}
impl Definition {
pub fn name(&self) -> &str {
match self {
Definition::ObjectType(d) => &d.name,
Definition::ModuleIdentity(d) => &d.name,
Definition::ObjectIdentity(d) => &d.name,
Definition::Notification(d) => &d.name,
Definition::TypeDef(d) => &d.name,
Definition::ValueAssignment(d) => &d.name,
Definition::ObjectGroup(d) => &d.name,
Definition::NotificationGroup(d) => &d.name,
Definition::ModuleCompliance(d) => &d.name,
Definition::AgentCapabilities(d) => &d.name,
}
}
pub fn range(&self) -> SourceRange {
match self {
Definition::ObjectType(d) => d.range,
Definition::ModuleIdentity(d) => d.range,
Definition::ObjectIdentity(d) => d.range,
Definition::Notification(d) => d.range,
Definition::TypeDef(d) => d.range,
Definition::ValueAssignment(d) => d.range,
Definition::ObjectGroup(d) => d.range,
Definition::NotificationGroup(d) => d.range,
Definition::ModuleCompliance(d) => d.range,
Definition::AgentCapabilities(d) => d.range,
}
}
pub fn oid(&self) -> Option<&OidAssignment> {
match self {
Definition::ObjectType(d) => Some(&d.oid),
Definition::ModuleIdentity(d) => Some(&d.oid),
Definition::ObjectIdentity(d) => Some(&d.oid),
Definition::Notification(d) => d.oid.as_ref(),
Definition::TypeDef(_) => None,
Definition::ValueAssignment(d) => Some(&d.oid),
Definition::ObjectGroup(d) => Some(&d.oid),
Definition::NotificationGroup(d) => Some(&d.oid),
Definition::ModuleCompliance(d) => Some(&d.oid),
Definition::AgentCapabilities(d) => Some(&d.oid),
}
}
}
#[derive(Debug, Clone)]
pub struct ObjectType {
pub name: String,
pub range: SourceRange,
pub syntax: TypeSyntax,
pub units: String,
pub access: Access,
pub access_keyword: AccessKeyword,
pub status: Status,
pub description: String,
pub has_description: bool,
pub reference: String,
pub index: Vec<IndexItem>,
pub augments: String,
pub defval: Option<DefVal>,
pub oid: OidAssignment,
pub syntax_range: Option<SourceRange>,
pub access_range: Option<SourceRange>,
pub status_range: Option<SourceRange>,
pub description_range: Option<SourceRange>,
pub units_range: Option<SourceRange>,
pub reference_range: Option<SourceRange>,
pub index_range: Option<SourceRange>,
pub augments_range: Option<SourceRange>,
pub defval_range: Option<SourceRange>,
}
#[derive(Debug, Clone)]
pub struct IndexItem {
pub implied: bool,
pub object: String,
pub range: SourceRange,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct NameRef {
pub name: String,
pub range: SourceRange,
}
#[derive(Debug, Clone)]
pub struct ModuleIdentity {
pub name: String,
pub range: SourceRange,
pub last_updated: String,
pub organization: String,
pub contact_info: String,
pub description: String,
pub revisions: Vec<Revision>,
pub oid: OidAssignment,
}
#[derive(Debug, Clone)]
pub struct Revision {
pub date: String,
pub description: String,
pub range: SourceRange,
}
#[derive(Debug, Clone)]
pub struct ObjectIdentity {
pub name: String,
pub range: SourceRange,
pub status: Status,
pub description: String,
pub reference: String,
pub oid: OidAssignment,
}
#[derive(Debug, Clone)]
pub struct Notification {
pub name: String,
pub range: SourceRange,
pub objects: Vec<String>,
pub status: Status,
pub description: String,
pub has_description: bool,
pub reference: String,
pub trap_info: Option<TrapInfo>,
pub oid: Option<OidAssignment>,
}
#[derive(Debug, Clone)]
pub struct TrapInfo {
pub enterprise: String,
pub trap_number: u32,
}
#[derive(Debug, Clone)]
pub struct TypeDef {
pub name: String,
pub range: SourceRange,
pub syntax: TypeSyntax,
pub base_type: Option<BaseType>,
pub display_hint: String,
pub status: Status,
pub description: String,
pub reference: String,
pub is_textual_convention: bool,
pub syntax_range: SourceRange,
pub status_range: Option<SourceRange>,
pub description_range: Option<SourceRange>,
pub reference_range: Option<SourceRange>,
pub display_hint_range: Option<SourceRange>,
}
#[derive(Debug, Clone)]
pub struct ValueAssignment {
pub name: String,
pub range: SourceRange,
pub oid: OidAssignment,
pub description: String,
pub reference: String,
}
#[derive(Debug, Clone)]
pub struct ObjectGroup {
pub name: String,
pub range: SourceRange,
pub objects: Vec<NameRef>,
pub status: Status,
pub description: String,
pub reference: String,
pub oid: OidAssignment,
}
#[derive(Debug, Clone)]
pub struct NotificationGroup {
pub name: String,
pub range: SourceRange,
pub notifications: Vec<NameRef>,
pub status: Status,
pub description: String,
pub reference: String,
pub oid: OidAssignment,
}
#[derive(Debug, Clone)]
pub struct ModuleCompliance {
pub name: String,
pub range: SourceRange,
pub status: Status,
pub description: String,
pub reference: String,
pub modules: Vec<ComplianceModule>,
pub oid: OidAssignment,
}
#[derive(Debug, Clone)]
pub struct ComplianceModule {
pub module_name: String,
pub mandatory_groups: Vec<String>,
pub groups: Vec<ComplianceGroup>,
pub objects: Vec<ComplianceObject>,
pub range: SourceRange,
}
#[derive(Debug, Clone)]
pub struct ComplianceGroup {
pub group: String,
pub description: String,
pub range: SourceRange,
}
#[derive(Debug, Clone)]
pub struct ComplianceObject {
pub object: String,
pub syntax: Option<TypeSyntax>,
pub write_syntax: Option<TypeSyntax>,
pub min_access: Option<Access>,
pub description: String,
pub range: SourceRange,
}
#[derive(Debug, Clone)]
pub struct AgentCapabilities {
pub name: String,
pub range: SourceRange,
pub product_release: String,
pub status: Status,
pub description: String,
pub reference: String,
pub supports: Vec<SupportsModule>,
pub oid: OidAssignment,
}
#[derive(Debug, Clone)]
pub struct SupportsModule {
pub module_name: String,
pub includes: Vec<NameRef>,
pub variations: Vec<Variation>,
pub range: SourceRange,
}
#[derive(Debug, Clone)]
pub struct Variation {
pub name: String,
pub syntax: Option<TypeSyntax>,
pub write_syntax: Option<TypeSyntax>,
pub access: Option<Access>,
pub creation_requires: Vec<NameRef>,
pub defval: Option<DefVal>,
pub description: String,
pub range: SourceRange,
}