1#![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
26pub const ID: ClusterId = 0x050C;
28
29pub const REVISION: u16 = 2;
32
33pub const PICS: &str = "APPLAUNCHER";
35
36pub mod feature {
41 pub const APPLICATION_PLATFORM: u32 = 1 << 0;
45}
46
47pub const FEATURES: &[Feature] = &[Feature {
49 bit: 0,
50 code: "AP",
51 name: "ApplicationPlatform",
52 conform: Conform::OPTIONAL,
53}];
54
55pub mod attribute {
57 use crate::im::AttributeId;
58
59 pub const CATALOG_LIST: AttributeId = 0x00;
61 pub const CURRENT_APP: AttributeId = 0x01;
63}
64
65pub mod command {
67 use crate::im::CommandId;
68
69 pub const LAUNCH_APP: CommandId = 0x00;
71 pub const STOP_APP: CommandId = 0x01;
73 pub const HIDE_APP: CommandId = 0x02;
75 pub const LAUNCHER_RESPONSE: CommandId = 0x03;
77}
78
79#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
81#[repr(u8)]
82pub enum StatusEnum {
83 Success = 0,
85 AppNotAvailable = 1,
87 SystemBusy = 2,
89 PendingUserApproval = 3,
91 Downloading = 4,
93 Installing = 5,
95}
96
97impl StatusEnum {
98 #[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 #[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#[derive(Debug, Clone, Copy, PartialEq)]
134pub struct ApplicationEPStruct<'a> {
135 pub application: ApplicationStruct<'a>,
137 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 _ => 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#[derive(Debug, Clone, Copy, PartialEq)]
184pub struct ApplicationStruct<'a> {
185 pub catalog_vendor_id: u16,
187 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 _ => 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#[derive(Debug, Clone, Copy, PartialEq)]
234pub struct LaunchAppFields<'a> {
235 pub application: Option<ApplicationStruct<'a>>,
237 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 _ => reader.skip_value(&field)?,
275 }
276 }
277 Ok(Self { application, data })
278 }
279}
280
281#[derive(Debug, Clone, Copy, PartialEq)]
283pub struct StopAppFields<'a> {
284 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 _ => reader.skip_value(&field)?,
317 }
318 }
319 Ok(Self { application })
320 }
321}
322
323#[derive(Debug, Clone, Copy, PartialEq)]
325pub struct HideAppFields<'a> {
326 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 _ => reader.skip_value(&field)?,
359 }
360 }
361 Ok(Self { application })
362 }
363}
364
365#[derive(Debug, Clone, Copy, PartialEq)]
367pub struct LauncherResponseFields<'a> {
368 pub status: StatusEnum,
370 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 _ => 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
415pub 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
442pub 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
478pub const EVENTS: &[Event] = &[];
480
481pub 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};