#![allow(unused_imports)]
use crate::dm::conformance::{Clause, Condition, Conform, Conformance};
use crate::dm::meta::{EventPriority, Reporting};
use crate::dm::spec::{Attribute, Cluster, Command, Event, Feature};
use crate::dm::{Access, AccessQualities, AttributeQualities, Privilege};
use crate::error::Result;
use crate::im::{AttributeId, ClusterId, CommandId, EventId};
use crate::tlv::{
ContainerKind, Element, FromTlv, Nullable, Tag, TlvList, TlvReader, TlvWriter, ToTlv, Value,
};
pub const ID: ClusterId = 0x0507;
pub const REVISION: u16 = 1;
pub const PICS: &str = "MEDIAINPUT";
pub mod feature {
pub const NAME_UPDATES: u32 = 1 << 0;
}
pub const FEATURES: &[Feature] = &[Feature {
bit: 0,
code: "NU",
name: "NameUpdates",
conform: Conform::OPTIONAL,
}];
pub mod attribute {
use crate::im::AttributeId;
pub const INPUT_LIST: AttributeId = 0x00;
pub const CURRENT_INPUT: AttributeId = 0x01;
}
pub mod command {
use crate::im::CommandId;
pub const SELECT_INPUT: CommandId = 0x00;
pub const SHOW_INPUT_STATUS: CommandId = 0x01;
pub const HIDE_INPUT_STATUS: CommandId = 0x02;
pub const RENAME_INPUT: CommandId = 0x03;
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u8)]
pub enum InputTypeEnum {
Internal = 0,
Aux = 1,
Coax = 2,
Composite = 3,
HDMI = 4,
Input = 5,
Line = 6,
Optical = 7,
Video = 8,
SCART = 9,
USB = 10,
Other = 11,
}
impl InputTypeEnum {
#[must_use]
pub const fn from_value(value: u8) -> Option<Self> {
match value {
0 => Some(Self::Internal),
1 => Some(Self::Aux),
2 => Some(Self::Coax),
3 => Some(Self::Composite),
4 => Some(Self::HDMI),
5 => Some(Self::Input),
6 => Some(Self::Line),
7 => Some(Self::Optical),
8 => Some(Self::Video),
9 => Some(Self::SCART),
10 => Some(Self::USB),
11 => Some(Self::Other),
_ => None,
}
}
#[must_use]
pub const fn value(self) -> u8 {
self as u8
}
}
impl ToTlv for InputTypeEnum {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
self.value().to_tlv(w, tag)
}
}
impl<'a> FromTlv<'a> for InputTypeEnum {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct InputInfoStruct<'a> {
pub index: u8,
pub input_type: InputTypeEnum,
pub name: &'a str,
pub description: &'a str,
}
impl<'a> ToTlv for InputInfoStruct<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.index.to_tlv(w, Tag::Context(0))?;
self.input_type.to_tlv(w, Tag::Context(1))?;
self.name.to_tlv(w, Tag::Context(2))?;
self.description.to_tlv(w, Tag::Context(3))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for InputInfoStruct<'a> {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut index = None;
let mut input_type = None;
let mut name = None;
let mut description = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => index = Some(<u8>::from_tlv(reader, &field)?),
Some(1) => input_type = Some(<InputTypeEnum>::from_tlv(reader, &field)?),
Some(2) => name = Some(<&'a str>::from_tlv(reader, &field)?),
Some(3) => description = Some(<&'a str>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
index: index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
input_type: input_type.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
name: name.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
description: description.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct SelectInputFields {
pub index: u8,
}
impl ToTlv for SelectInputFields {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.index.to_tlv(w, Tag::Context(0))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for SelectInputFields {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut index = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => index = Some(<u8>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
index: index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct RenameInputFields<'a> {
pub index: u8,
pub name: &'a str,
}
impl<'a> ToTlv for RenameInputFields<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.index.to_tlv(w, Tag::Context(0))?;
self.name.to_tlv(w, Tag::Context(1))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for RenameInputFields<'a> {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut index = None;
let mut name = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => index = Some(<u8>::from_tlv(reader, &field)?),
Some(1) => name = Some(<&'a str>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
index: index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
name: name.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
pub const ATTRIBUTES: &[Attribute] = &[
Attribute {
id: 0x0000,
name: "InputList",
kind: "list[InputInfoStruct]",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::empty(),
reporting: Reporting::OnChange,
conform: Conform::MANDATORY,
},
Attribute {
id: 0x0001,
name: "CurrentInput",
kind: "uint8",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::empty(),
reporting: Reporting::OnChange,
conform: Conform::MANDATORY,
},
];
pub const COMMANDS: &[Command] = &[
Command {
id: 0x00,
name: "SelectInput",
to_server: true,
response: None,
access: Access::invoke(Privilege::Operate),
conform: Conform::MANDATORY,
},
Command {
id: 0x01,
name: "ShowInputStatus",
to_server: true,
response: None,
access: Access::invoke(Privilege::Operate),
conform: Conform::MANDATORY,
},
Command {
id: 0x02,
name: "HideInputStatus",
to_server: true,
response: None,
access: Access::invoke(Privilege::Operate),
conform: Conform::MANDATORY,
},
Command {
id: 0x03,
name: "RenameInput",
to_server: true,
response: None,
access: Access::invoke(Privilege::Manage),
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Mandatory,
when: Condition::Feature(0),
}],
},
},
];
pub const EVENTS: &[Event] = &[];
pub const CLUSTER: Cluster = Cluster {
id: ID,
name: "Media Input",
revision: REVISION,
pics: "MEDIAINPUT",
derived_from: None,
features: FEATURES,
attributes: ATTRIBUTES,
commands: COMMANDS,
events: EVENTS,
};