File: characteristic_list_item.js

package info (click to toggle)
chromium 138.0.7204.157-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,864 kB
  • sloc: cpp: 34,936,859; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,967; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (145 lines) | stat: -rw-r--r-- 5,408 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import './descriptor_list.js';
import './expandable_list_item.js';
import './object_fieldset.js';
import './value_control.js';

import {CustomElement} from 'chrome://resources/js/custom_element.js';

import {getTemplate} from './characteristic_list_item.html.js';
import {Property} from './device.mojom-webui.js';

/** Property names for the CharacteristicInfo fieldset */
const INFO_PROPERTY_NAMES = {
  id: 'ID',
  'uuid.uuid': 'UUID',
};

/** Property names for the Properties fieldset. */
const PROPERTIES_PROPERTY_NAMES = {
  broadcast: 'Broadcast',
  read: 'Read',
  write_without_response: 'Write Without Response',
  write: 'Write',
  notify: 'Notify',
  indicate: 'Indicate',
  authenticated_signed_writes: 'Authenticated Signed Writes',
  extended_properties: 'Extended Properties',
  reliable_write: 'Reliable Write',
  writable_auxiliaries: 'Writable Auxiliaries',
  read_encrypted: 'Read Encrypted',
  write_encrypted: 'Write Encrypted',
  read_encrypted_authenticated: 'Read Encrypted Authenticated',
  write_encrypted_authenticated: 'Write Encrypted Authenticated',
};

/**
 * A list item that displays the properties of a CharacteristicInfo object.
 * Two fieldsets are created within the element: one for the primitive
 * properties, 'id' and 'uuid', and one for the 'properties' bitfield in the
 * CharacteristicInfo object.
 */
export class CharacteristicListItemElement extends CustomElement {
  static get template() {
    return getTemplate();
  }

  constructor() {
    super();

    /** @type {?CharacteristicInfo} */
    this.info = null;
    /** @private {string} */
    this.deviceAddress_ = '';
    /** @private {string} */
    this.serviceId_ = '';
  }

  connectedCallback() {
    this.classList.add('characteristic-list-item');
    this.shadowRoot.querySelector('expandable-list-item')
        .addEventListener('list-item-expanded', () => {
          const list = this.shadowRoot.querySelector('descriptor-list');
          list.load(this.deviceAddress_, this.serviceId_, this.info.id);
        });

    const propertiesBtn = this.shadowRoot.querySelector('.show-all-properties');
    const propertiesFieldSet =
        this.shadowRoot.querySelector('object-field-set.properties');
    propertiesBtn.addEventListener('click', () => {
      propertiesFieldSet.toggleAttribute(
          'show-all', !propertiesFieldSet.showAll);
      propertiesBtn.textContent =
          propertiesFieldSet.showAll ? 'Hide' : 'Show all';
    });
  }

  /**
   * @param {!CharacteristicInfo} characteristicInfo
   * @param {string} deviceAddress
   * @param {string} serviceId
   */
  initialize(characteristicInfo, deviceAddress, serviceId) {
    this.info = characteristicInfo;
    this.deviceAddress_ = deviceAddress;
    this.serviceId_ = serviceId;

    this.shadowRoot.querySelector('.header-value').textContent =
        this.info.uuid.uuid;

    // Create content for display in expanded content container.
    const characteristicFieldSet =
        this.shadowRoot.querySelector('object-field-set.characteristics');
    characteristicFieldSet.dataset.nameMap =
        JSON.stringify(INFO_PROPERTY_NAMES);
    characteristicFieldSet.dataset.value = JSON.stringify({
      id: this.info.id,
      'uuid.uuid': this.info.uuid.uuid,
    });
    characteristicFieldSet.hidden = false;

    const propertiesFieldSet =
        this.shadowRoot.querySelector('object-field-set.properties');
    propertiesFieldSet.dataset.nameMap =
        JSON.stringify(PROPERTIES_PROPERTY_NAMES);
    propertiesFieldSet.dataset.value = JSON.stringify({
      broadcast: (this.info.properties & Property.BROADCAST) > 0,
      read: (this.info.properties & Property.READ) > 0,
      write_without_response:
          (this.info.properties & Property.WRITE_WITHOUT_RESPONSE) > 0,
      write: (this.info.properties & Property.WRITE) > 0,
      notify: (this.info.properties & Property.NOTIFY) > 0,
      indicate: (this.info.properties & Property.INDICATE) > 0,
      authenticated_signed_writes:
          (this.info.properties & Property.AUTHENTICATED_SIGNED_WRITES) > 0,
      extended_properties:
          (this.info.properties & Property.EXTENDED_PROPERTIES) > 0,
      reliable_write: (this.info.properties & Property.RELIABLE_WRITE) > 0,
      writable_auxiliaries:
          (this.info.properties & Property.WRITABLE_AUXILIARIES) > 0,
      read_encrypted: (this.info.properties & Property.READ_ENCRYPTED) > 0,
      write_encrypted: (this.info.properties & Property.WRITE_ENCRYPTED) > 0,
      read_encrypted_authenticated:
          (this.info.properties & Property.READ_ENCRYPTED_AUTHENTICATED) > 0,
      write_encrypted_authenticated:
          (this.info.properties & Property.WRITE_ENCRYPTED_AUTHENTICATED) > 0,
    });
    propertiesFieldSet.hidden = false;

    const valueControl = this.shadowRoot.querySelector('value-control');
    valueControl.dataset.options = JSON.stringify({
      deviceAddress: this.deviceAddress_,
      serviceId: this.serviceId_,
      characteristicId: this.info.id,
      properties: this.info.properties,
    });
    valueControl.dataset.value = JSON.stringify(this.info.lastKnownValue);
    valueControl.hidden = false;
  }
}

customElements.define(
    'characteristic-list-item', CharacteristicListItemElement);