Skip to main content

matter_kit/clusters/generated/
application_launcher.rs

1// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
2//
3// Application Launcher — cluster 0x050C.
4//
5// Regenerate with `cargo xtask clusters --dm <checkout>/data_model/1.6`; `cargo xtask check`
6// is the CI gate that keeps this file honest. The XML itself is not vendored here — it
7// carries the CSA's own copyright notice and is not redistributable.
8
9//! Application Launcher (cluster `0x050C`, revision 2).
10//!
11//! 6 identifiers, 1 feature bits, and the specification's own conformance for
12//! every element. `CLUSTER` is the whole table.
13
14#![allow(unused_imports)]
15
16use crate::dm::conformance::{Clause, Condition, Conform, Conformance};
17use crate::dm::meta::{EventPriority, Reporting};
18use crate::dm::spec::{Attribute, Cluster, Command, Event, Feature};
19use crate::dm::{Access, AccessQualities, AttributeQualities, Privilege};
20use crate::error::Result;
21use crate::im::{AttributeId, ClusterId, CommandId, EventId};
22use crate::tlv::{
23    ContainerKind, Element, FromTlv, Nullable, Tag, TlvList, TlvReader, TlvWriter, ToTlv, Value,
24};
25
26/// The cluster id.
27pub const ID: ClusterId = 0x050C;
28
29/// The highest revision the specification's history defines — what `ClusterRevision`
30/// must report (Core §7.13.1).
31pub const REVISION: u16 = 2;
32
33/// The PICS code, which a certification declaration names the cluster by.
34pub const PICS: &str = "APPLAUNCHER";
35
36/// The `FeatureMap` bits (Core §7.13.2).
37///
38/// A feature has conformance of its own: a device may not claim one the
39/// specification forbids it alongside another.
40pub mod feature {
41    /// Support for attributes and commands required for endpoint to support launching any application within the supported application catalogs
42    ///
43    /// Code `AP`, bit 0.
44    pub const APPLICATION_PLATFORM: u32 = 1 << 0;
45}
46
47/// Every feature bit, with its conformance.
48pub const FEATURES: &[Feature] = &[Feature {
49    bit: 0,
50    code: "AP",
51    name: "ApplicationPlatform",
52    conform: Conform::OPTIONAL,
53}];
54
55/// The attribute ids.
56pub mod attribute {
57    use crate::im::AttributeId;
58
59    /// `CatalogList`.
60    pub const CATALOG_LIST: AttributeId = 0x00;
61    /// `CurrentApp`.
62    pub const CURRENT_APP: AttributeId = 0x01;
63}
64
65/// The command ids.
66pub mod command {
67    use crate::im::CommandId;
68
69    /// `LaunchApp`.
70    pub const LAUNCH_APP: CommandId = 0x00;
71    /// `StopApp`.
72    pub const STOP_APP: CommandId = 0x01;
73    /// `HideApp`.
74    pub const HIDE_APP: CommandId = 0x02;
75    /// `LauncherResponse`.
76    pub const LAUNCHER_RESPONSE: CommandId = 0x03;
77}
78
79/// `StatusEnum`.
80#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
81#[repr(u8)]
82pub enum StatusEnum {
83    /// Command succeeded
84    Success = 0,
85    /// Requested app is not available
86    AppNotAvailable = 1,
87    /// Video platform unable to honor command
88    SystemBusy = 2,
89    /// User approval for app download is pending
90    PendingUserApproval = 3,
91    /// Downloading the requested app
92    Downloading = 4,
93    /// Installing the requested app
94    Installing = 5,
95}
96
97impl StatusEnum {
98    /// Reads a wire value, or `None` for one this revision does not define.
99    #[must_use]
100    pub const fn from_value(value: u8) -> Option<Self> {
101        match value {
102            0 => Some(Self::Success),
103            1 => Some(Self::AppNotAvailable),
104            2 => Some(Self::SystemBusy),
105            3 => Some(Self::PendingUserApproval),
106            4 => Some(Self::Downloading),
107            5 => Some(Self::Installing),
108            _ => None,
109        }
110    }
111
112    /// Its wire value.
113    #[must_use]
114    pub const fn value(self) -> u8 {
115        self as u8
116    }
117}
118
119impl ToTlv for StatusEnum {
120    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
121        self.value().to_tlv(w, tag)
122    }
123}
124
125impl<'a> FromTlv<'a> for StatusEnum {
126    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
127        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
128        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
129    }
130}
131
132/// `ApplicationEPStruct`.
133#[derive(Debug, Clone, Copy, PartialEq)]
134pub struct ApplicationEPStruct<'a> {
135    /// `Application`, field 0.
136    pub application: ApplicationStruct<'a>,
137    /// `Endpoint`, field 1.
138    pub endpoint: Option<u16>,
139}
140
141impl<'a> ToTlv for ApplicationEPStruct<'a> {
142    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
143        w.start_structure(tag)?;
144        self.application.to_tlv(w, Tag::Context(0))?;
145        if let Some(value) = &self.endpoint {
146            value.to_tlv(w, Tag::Context(1))?;
147        }
148        w.end_container()
149    }
150}
151
152impl<'a> FromTlv<'a> for ApplicationEPStruct<'a> {
153    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
154        if element.value.container() != Some(ContainerKind::Structure) {
155            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
156        }
157        let mut application = None;
158        let mut endpoint = None;
159        loop {
160            let Some(field) = reader.next_element()? else {
161                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
162            };
163            if field.value == Value::EndOfContainer {
164                break;
165            }
166            match field.tag.context() {
167                Some(0) => application = Some(<ApplicationStruct<'a>>::from_tlv(reader, &field)?),
168                Some(1) => endpoint = Some(<u16>::from_tlv(reader, &field)?),
169                // A field this revision does not define. §7.19.2: a receiver
170                // ignores what it does not know rather than refusing the whole
171                // structure, which is what lets a newer peer talk to an older one.
172                _ => reader.skip_value(&field)?,
173            }
174        }
175        Ok(Self {
176            application: application.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
177            endpoint,
178        })
179    }
180}
181
182/// `ApplicationStruct`.
183#[derive(Debug, Clone, Copy, PartialEq)]
184pub struct ApplicationStruct<'a> {
185    /// `CatalogVendorID`, field 0.
186    pub catalog_vendor_id: u16,
187    /// `ApplicationID`, field 1.
188    pub application_id: &'a str,
189}
190
191impl<'a> ToTlv for ApplicationStruct<'a> {
192    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
193        w.start_structure(tag)?;
194        self.catalog_vendor_id.to_tlv(w, Tag::Context(0))?;
195        self.application_id.to_tlv(w, Tag::Context(1))?;
196        w.end_container()
197    }
198}
199
200impl<'a> FromTlv<'a> for ApplicationStruct<'a> {
201    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
202        if element.value.container() != Some(ContainerKind::Structure) {
203            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
204        }
205        let mut catalog_vendor_id = None;
206        let mut application_id = None;
207        loop {
208            let Some(field) = reader.next_element()? else {
209                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
210            };
211            if field.value == Value::EndOfContainer {
212                break;
213            }
214            match field.tag.context() {
215                Some(0) => catalog_vendor_id = Some(<u16>::from_tlv(reader, &field)?),
216                Some(1) => application_id = Some(<&'a str>::from_tlv(reader, &field)?),
217                // A field this revision does not define. §7.19.2: a receiver
218                // ignores what it does not know rather than refusing the whole
219                // structure, which is what lets a newer peer talk to an older one.
220                _ => reader.skip_value(&field)?,
221            }
222        }
223        Ok(Self {
224            catalog_vendor_id: catalog_vendor_id
225                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
226            application_id: application_id
227                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
228        })
229    }
230}
231
232/// The fields of `LaunchApp` (command `0x00`).
233#[derive(Debug, Clone, Copy, PartialEq)]
234pub struct LaunchAppFields<'a> {
235    /// `Application`, field 0.
236    pub application: Option<ApplicationStruct<'a>>,
237    /// `Data`, field 1.
238    pub data: Option<&'a [u8]>,
239}
240
241impl<'a> ToTlv for LaunchAppFields<'a> {
242    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
243        w.start_structure(tag)?;
244        if let Some(value) = &self.application {
245            value.to_tlv(w, Tag::Context(0))?;
246        }
247        if let Some(value) = &self.data {
248            value.to_tlv(w, Tag::Context(1))?;
249        }
250        w.end_container()
251    }
252}
253
254impl<'a> FromTlv<'a> for LaunchAppFields<'a> {
255    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
256        if element.value.container() != Some(ContainerKind::Structure) {
257            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
258        }
259        let mut application = None;
260        let mut data = None;
261        loop {
262            let Some(field) = reader.next_element()? else {
263                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
264            };
265            if field.value == Value::EndOfContainer {
266                break;
267            }
268            match field.tag.context() {
269                Some(0) => application = Some(<ApplicationStruct<'a>>::from_tlv(reader, &field)?),
270                Some(1) => data = Some(<&'a [u8]>::from_tlv(reader, &field)?),
271                // A field this revision does not define. §7.19.2: a receiver
272                // ignores what it does not know rather than refusing the whole
273                // structure, which is what lets a newer peer talk to an older one.
274                _ => reader.skip_value(&field)?,
275            }
276        }
277        Ok(Self { application, data })
278    }
279}
280
281/// The fields of `StopApp` (command `0x01`).
282#[derive(Debug, Clone, Copy, PartialEq)]
283pub struct StopAppFields<'a> {
284    /// `Application`, field 0.
285    pub application: Option<ApplicationStruct<'a>>,
286}
287
288impl<'a> ToTlv for StopAppFields<'a> {
289    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
290        w.start_structure(tag)?;
291        if let Some(value) = &self.application {
292            value.to_tlv(w, Tag::Context(0))?;
293        }
294        w.end_container()
295    }
296}
297
298impl<'a> FromTlv<'a> for StopAppFields<'a> {
299    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
300        if element.value.container() != Some(ContainerKind::Structure) {
301            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
302        }
303        let mut application = None;
304        loop {
305            let Some(field) = reader.next_element()? else {
306                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
307            };
308            if field.value == Value::EndOfContainer {
309                break;
310            }
311            match field.tag.context() {
312                Some(0) => application = Some(<ApplicationStruct<'a>>::from_tlv(reader, &field)?),
313                // A field this revision does not define. §7.19.2: a receiver
314                // ignores what it does not know rather than refusing the whole
315                // structure, which is what lets a newer peer talk to an older one.
316                _ => reader.skip_value(&field)?,
317            }
318        }
319        Ok(Self { application })
320    }
321}
322
323/// The fields of `HideApp` (command `0x02`).
324#[derive(Debug, Clone, Copy, PartialEq)]
325pub struct HideAppFields<'a> {
326    /// `Application`, field 0.
327    pub application: Option<ApplicationStruct<'a>>,
328}
329
330impl<'a> ToTlv for HideAppFields<'a> {
331    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
332        w.start_structure(tag)?;
333        if let Some(value) = &self.application {
334            value.to_tlv(w, Tag::Context(0))?;
335        }
336        w.end_container()
337    }
338}
339
340impl<'a> FromTlv<'a> for HideAppFields<'a> {
341    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
342        if element.value.container() != Some(ContainerKind::Structure) {
343            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
344        }
345        let mut application = None;
346        loop {
347            let Some(field) = reader.next_element()? else {
348                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
349            };
350            if field.value == Value::EndOfContainer {
351                break;
352            }
353            match field.tag.context() {
354                Some(0) => application = Some(<ApplicationStruct<'a>>::from_tlv(reader, &field)?),
355                // A field this revision does not define. §7.19.2: a receiver
356                // ignores what it does not know rather than refusing the whole
357                // structure, which is what lets a newer peer talk to an older one.
358                _ => reader.skip_value(&field)?,
359            }
360        }
361        Ok(Self { application })
362    }
363}
364
365/// The fields of `LauncherResponse` (command `0x03`).
366#[derive(Debug, Clone, Copy, PartialEq)]
367pub struct LauncherResponseFields<'a> {
368    /// `Status`, field 0.
369    pub status: StatusEnum,
370    /// `Data`, field 1.
371    pub data: Option<&'a [u8]>,
372}
373
374impl<'a> ToTlv for LauncherResponseFields<'a> {
375    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
376        w.start_structure(tag)?;
377        self.status.to_tlv(w, Tag::Context(0))?;
378        if let Some(value) = &self.data {
379            value.to_tlv(w, Tag::Context(1))?;
380        }
381        w.end_container()
382    }
383}
384
385impl<'a> FromTlv<'a> for LauncherResponseFields<'a> {
386    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
387        if element.value.container() != Some(ContainerKind::Structure) {
388            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
389        }
390        let mut status = None;
391        let mut data = None;
392        loop {
393            let Some(field) = reader.next_element()? else {
394                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
395            };
396            if field.value == Value::EndOfContainer {
397                break;
398            }
399            match field.tag.context() {
400                Some(0) => status = Some(<StatusEnum>::from_tlv(reader, &field)?),
401                Some(1) => data = Some(<&'a [u8]>::from_tlv(reader, &field)?),
402                // A field this revision does not define. §7.19.2: a receiver
403                // ignores what it does not know rather than refusing the whole
404                // structure, which is what lets a newer peer talk to an older one.
405                _ => reader.skip_value(&field)?,
406            }
407        }
408        Ok(Self {
409            status: status.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
410            data,
411        })
412    }
413}
414
415/// Every attribute the specification defines, with its conformance.
416pub const ATTRIBUTES: &[Attribute] = &[
417    Attribute {
418        id: 0x0000,
419        name: "CatalogList",
420        kind: "list[uint16]",
421        access: Access::read_only(Privilege::View),
422        qualities: AttributeQualities::NON_VOLATILE,
423        reporting: Reporting::OnChange,
424        conform: Conform {
425            clauses: &[Clause {
426                verdict: Conformance::Mandatory,
427                when: Condition::Feature(0),
428            }],
429        },
430    },
431    Attribute {
432        id: 0x0001,
433        name: "CurrentApp",
434        kind: "ApplicationEPStruct",
435        access: Access::read_only(Privilege::View),
436        qualities: AttributeQualities::NULLABLE,
437        reporting: Reporting::OnChange,
438        conform: Conform::OPTIONAL,
439    },
440];
441
442/// Every command, with its conformance.
443pub const COMMANDS: &[Command] = &[
444    Command {
445        id: 0x00,
446        name: "LaunchApp",
447        to_server: true,
448        response: Some(0x03),
449        access: Access::invoke(Privilege::Operate),
450        conform: Conform::MANDATORY,
451    },
452    Command {
453        id: 0x01,
454        name: "StopApp",
455        to_server: true,
456        response: Some(0x03),
457        access: Access::invoke(Privilege::Operate),
458        conform: Conform::MANDATORY,
459    },
460    Command {
461        id: 0x02,
462        name: "HideApp",
463        to_server: true,
464        response: Some(0x03),
465        access: Access::invoke(Privilege::Operate),
466        conform: Conform::MANDATORY,
467    },
468    Command {
469        id: 0x03,
470        name: "LauncherResponse",
471        to_server: false,
472        response: None,
473        access: Access::invoke(Privilege::Operate),
474        conform: Conform::MANDATORY,
475    },
476];
477
478/// Every event, with its conformance.
479pub const EVENTS: &[Event] = &[];
480
481/// The whole cluster, as the specification defines it.
482pub const CLUSTER: Cluster = Cluster {
483    id: ID,
484    name: "Application Launcher",
485    revision: REVISION,
486    pics: "APPLAUNCHER",
487    derived_from: None,
488    features: FEATURES,
489    attributes: ATTRIBUTES,
490    commands: COMMANDS,
491    events: EVENTS,
492};