001package Torello.Browser.BrowserAPI;
002
003// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
004// Java-HTML Imports
005// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
006
007import Torello.Browser.*;
008import Torello.Browser.helper.*;
009import Torello.Browser.JavaScriptAPI.*;
010import Torello.JSON.*;
011
012import Torello.Java.ReadOnly.ReadOnlyList;
013import Torello.Java.ReadOnly.ReadOnlyArrayList;
014
015import Torello.JavaDoc.Annotations.StaticFunctional;
016import Torello.JavaDoc.Annotations.JDHeaderBackgroundImg;
017
018import Torello.Browser.BrowserAPI.NestedHelpers.Commands.BluetoothEmulation$$Commands;
019
020
021// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
022// JDK Imports
023// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
024
025import javax.json.JsonObject;
026import javax.json.JsonValue;
027
028/**
029 * <SPAN CLASS=COPIEDJDK><B>This domain allows configuring virtual Bluetooth devices to test
030 * the web-bluetooth API.</B></SPAN>
031 * <EMBED CLASS='external-html' DATA-FILE-ID=CDP.CODE_GEN_NOTE>
032 */
033@StaticFunctional@JDHeaderBackgroundImg(EmbedTagFileID="CDP.WOOD_PLANK_NOTE")
034public class BluetoothEmulation
035{
036    // No Pubic Constructors
037    private BluetoothEmulation() { }
038
039
040    // ********************************************************************************************
041    // ********************************************************************************************
042    // Enumerated String Constants Lists
043    // ********************************************************************************************
044    // ********************************************************************************************
045
046
047    /**
048     * Indicates the various states of Central.
049     * <BR /><BR /><B CLASS=StrEnumType>String-Enumeration Type</B>
050     */
051    public static final ReadOnlyList<String> CentralState = new ReadOnlyArrayList<>
052        (String.class, "absent", "powered-off", "powered-on");
053
054    /**
055     * Indicates the various types of characteristic operation.
056     * <BR /><BR /><B CLASS=StrEnumType>String-Enumeration Type</B>
057     */
058    public static final ReadOnlyList<String> CharacteristicOperationType = new ReadOnlyArrayList<>(
059        String.class, 
060        "read", "subscribe-to-notifications", "unsubscribe-from-notifications", "write"
061    );
062
063    /**
064     * Indicates the various types of characteristic write.
065     * <BR /><BR /><B CLASS=StrEnumType>String-Enumeration Type</B>
066     */
067    public static final ReadOnlyList<String> CharacteristicWriteType = new ReadOnlyArrayList<>
068        (String.class, "write-default-deprecated", "write-with-response", "write-without-response");
069
070    /**
071     * Indicates the various types of descriptor operation.
072     * <BR /><BR /><B CLASS=StrEnumType>String-Enumeration Type</B>
073     */
074    public static final ReadOnlyList<String> DescriptorOperationType = new ReadOnlyArrayList<>
075        (String.class, "read", "write");
076
077    /**
078     * Indicates the various types of GATT event.
079     * <BR /><BR /><B CLASS=StrEnumType>String-Enumeration Type</B>
080     */
081    public static final ReadOnlyList<String> GATTOperationType = new ReadOnlyArrayList<>
082        (String.class, "connection", "discovery");
083
084
085
086    // ********************************************************************************************
087    // ********************************************************************************************
088    // Basic Types
089    // ********************************************************************************************
090    // ********************************************************************************************
091
092
093    /**
094     * Describes the properties of a characteristic. This follows Bluetooth Core
095     * Specification BT 4.2 Vol 3 Part G 3.3.1. Characteristic Properties.
096     * 
097     * <EMBED CLASS=globalDefs DATA-DOMAIN=BluetoothEmulation DATA-API=BrowserAPI>
098     */
099    @JDHeaderBackgroundImg(EmbedTagFileID="CDP.NESTED_TYPE_JDHBI")
100    public static class CharacteristicProperties
101        extends BaseType<CharacteristicProperties>
102        implements java.io.Serializable
103    {
104        /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */
105        protected static final long serialVersionUID = 1;
106
107        private static final NestedHelper<BluetoothEmulation.CharacteristicProperties> singleton =
108            Torello.Browser.BrowserAPI.NestedHelpers.Types.
109                BluetoothEmulation$$CharacteristicProperties$$.singleton;
110
111        /**
112         * <CODE>[No Description Provided by Google]</CODE>
113         * <BR /><B CLASS=Opt-Top>OPTIONAL</B>
114         */
115        public final Boolean broadcast;
116
117        /**
118         * <CODE>[No Description Provided by Google]</CODE>
119         * <BR /><B CLASS=Opt-Top>OPTIONAL</B>
120         */
121        public final Boolean read;
122
123        /**
124         * <CODE>[No Description Provided by Google]</CODE>
125         * <BR /><B CLASS=Opt-Top>OPTIONAL</B>
126         */
127        public final Boolean writeWithoutResponse;
128
129        /**
130         * <CODE>[No Description Provided by Google]</CODE>
131         * <BR /><B CLASS=Opt-Top>OPTIONAL</B>
132         */
133        public final Boolean write;
134
135        /**
136         * <CODE>[No Description Provided by Google]</CODE>
137         * <BR /><B CLASS=Opt-Top>OPTIONAL</B>
138         */
139        public final Boolean notify;
140
141        /**
142         * <CODE>[No Description Provided by Google]</CODE>
143         * <BR /><B CLASS=Opt-Top>OPTIONAL</B>
144         */
145        public final Boolean indicate;
146
147        /**
148         * <CODE>[No Description Provided by Google]</CODE>
149         * <BR /><B CLASS=Opt-Top>OPTIONAL</B>
150         */
151        public final Boolean authenticatedSignedWrites;
152
153        /**
154         * <CODE>[No Description Provided by Google]</CODE>
155         * <BR /><B CLASS=Opt-Top>OPTIONAL</B>
156         */
157        public final Boolean extendedProperties;
158
159        /** Constructor.  Please review this class' fields for documentation. */
160        public CharacteristicProperties(
161                ReadOnlyList<Boolean> isPresent, Boolean broadcast, Boolean read,
162                Boolean writeWithoutResponse, Boolean write, Boolean notify, Boolean indicate,
163                Boolean authenticatedSignedWrites, Boolean extendedProperties
164            )
165        {
166            super(singleton, Domains.BluetoothEmulation, "CharacteristicProperties", 8);
167
168            this.broadcast                  = broadcast;
169            this.read                       = read;
170            this.writeWithoutResponse       = writeWithoutResponse;
171            this.write                      = write;
172            this.notify                     = notify;
173            this.indicate                   = indicate;
174            this.authenticatedSignedWrites  = authenticatedSignedWrites;
175            this.extendedProperties         = extendedProperties;
176
177            this.isPresent = (isPresent == null)
178                ? singleton.generateIsPresentList(this)
179                : THROWS.check(isPresent, 8, "BluetoothEmulation.CharacteristicProperties");
180        }
181
182        /** Creates an instance of this class from a {@link JsonObject}.*/
183        public static CharacteristicProperties fromJSON(JsonObject jo)
184        { return singleton.fromJSON(jo); }
185
186        /** Returns this class's {@link NestedDescriptor} singleton-instance. class / type.*/
187        public static NestedDescriptor<CharacteristicProperties> descriptor()
188        { return singleton.descriptor(); }
189    }
190
191    /**
192     * Stores the manufacturer data
193     * 
194     * <EMBED CLASS=globalDefs DATA-DOMAIN=BluetoothEmulation DATA-API=BrowserAPI>
195     */
196    @JDHeaderBackgroundImg(EmbedTagFileID="CDP.NESTED_TYPE_JDHBI")
197    public static class ManufacturerData
198        extends BaseType<ManufacturerData>
199        implements java.io.Serializable
200    {
201        /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */
202        protected static final long serialVersionUID = 1;
203
204        private static final NestedHelper<BluetoothEmulation.ManufacturerData> singleton =
205            Torello.Browser.BrowserAPI.NestedHelpers.Types.
206                BluetoothEmulation$$ManufacturerData$$.singleton;
207
208        /**
209         * Company identifier
210         * https://bitbucket.org/bluetooth-SIG/public/src/main/assigned_numbers/company_identifiers/company_identifiers.yaml
211         * https://usb.org/developers
212         */
213        public final int key;
214
215        /** Manufacturer-specific data (Encoded as a base64 string when passed over JSON) */
216        public final String data;
217
218        /** Constructor.  Please review this class' fields for documentation. */
219        public ManufacturerData(ReadOnlyList<Boolean> isPresent, int key, String data)
220        {
221            super(singleton, Domains.BluetoothEmulation, "ManufacturerData", 2);
222
223            this.key    = key;
224            this.data   = data;
225
226            this.isPresent = (isPresent == null)
227                ? singleton.generateIsPresentList(this)
228                : THROWS.check(isPresent, 2, "BluetoothEmulation.ManufacturerData");
229        }
230
231        /** Creates an instance of this class from a {@link JsonObject}.*/
232        public static ManufacturerData fromJSON(JsonObject jo)
233        { return singleton.fromJSON(jo); }
234
235        /** Returns this class's {@link NestedDescriptor} singleton-instance. class / type.*/
236        public static NestedDescriptor<ManufacturerData> descriptor()
237        { return singleton.descriptor(); }
238    }
239
240    /**
241     * Stores the advertisement packet information that is sent by a Bluetooth device.
242     * 
243     * <EMBED CLASS=globalDefs DATA-DOMAIN=BluetoothEmulation DATA-API=BrowserAPI>
244     */
245    @JDHeaderBackgroundImg(EmbedTagFileID="CDP.NESTED_TYPE_JDHBI")
246    public static class ScanEntry
247        extends BaseType<ScanEntry>
248        implements java.io.Serializable
249    {
250        /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */
251        protected static final long serialVersionUID = 1;
252
253        private static final NestedHelper<BluetoothEmulation.ScanEntry> singleton =
254            Torello.Browser.BrowserAPI.NestedHelpers.Types.
255                BluetoothEmulation$$ScanEntry$$.singleton;
256
257        /** <CODE>[No Description Provided by Google]</CODE> */
258        public final String deviceAddress;
259
260        /** <CODE>[No Description Provided by Google]</CODE> */
261        public final int rssi;
262
263        /** <CODE>[No Description Provided by Google]</CODE> */
264        public final BluetoothEmulation.ScanRecord scanRecord;
265
266        /** Constructor.  Please review this class' fields for documentation. */
267        public ScanEntry(
268                ReadOnlyList<Boolean> isPresent, String deviceAddress, int rssi,
269                ScanRecord scanRecord
270            )
271        {
272            super(singleton, Domains.BluetoothEmulation, "ScanEntry", 3);
273
274            this.deviceAddress  = deviceAddress;
275            this.rssi           = rssi;
276            this.scanRecord     = scanRecord;
277
278            this.isPresent = (isPresent == null)
279                ? singleton.generateIsPresentList(this)
280                : THROWS.check(isPresent, 3, "BluetoothEmulation.ScanEntry");
281        }
282
283        /** Creates an instance of this class from a {@link JsonObject}.*/
284        public static ScanEntry fromJSON(JsonObject jo)
285        { return singleton.fromJSON(jo); }
286
287        /** Returns this class's {@link NestedDescriptor} singleton-instance. class / type.*/
288        public static NestedDescriptor<ScanEntry> descriptor()
289        { return singleton.descriptor(); }
290    }
291
292    /**
293     * Stores the byte data of the advertisement packet sent by a Bluetooth device.
294     * 
295     * <EMBED CLASS=globalDefs DATA-DOMAIN=BluetoothEmulation DATA-API=BrowserAPI>
296     */
297    @JDHeaderBackgroundImg(EmbedTagFileID="CDP.NESTED_TYPE_JDHBI")
298    public static class ScanRecord
299        extends BaseType<ScanRecord>
300        implements java.io.Serializable
301    {
302        /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */
303        protected static final long serialVersionUID = 1;
304
305        private static final NestedHelper<BluetoothEmulation.ScanRecord> singleton =
306            Torello.Browser.BrowserAPI.NestedHelpers.Types.
307                BluetoothEmulation$$ScanRecord$$.singleton;
308
309        /**
310         * <CODE>[No Description Provided by Google]</CODE>
311         * <BR /><B CLASS=Opt-Top>OPTIONAL</B>
312         */
313        public final String name;
314
315        /**
316         * <CODE>[No Description Provided by Google]</CODE>
317         * <BR /><B CLASS=Opt-Top>OPTIONAL</B>
318         */
319        public final String[] uuids;
320
321        /**
322         * Stores the external appearance description of the device.
323         * <BR /><B CLASS=Opt-Top>OPTIONAL</B>
324         */
325        public final Integer appearance;
326
327        /**
328         * Stores the transmission power of a broadcasting device.
329         * <BR /><B CLASS=Opt-Top>OPTIONAL</B>
330         */
331        public final Integer txPower;
332
333        /**
334         * Key is the company identifier and the value is an array of bytes of
335         * manufacturer specific data.
336         * <BR /><B CLASS=Opt-Top>OPTIONAL</B>
337         */
338        public final BluetoothEmulation.ManufacturerData[] manufacturerData;
339
340        /** Constructor.  Please review this class' fields for documentation. */
341        public ScanRecord(
342                ReadOnlyList<Boolean> isPresent, String name, String[] uuids, Integer appearance,
343                Integer txPower, ManufacturerData[] manufacturerData
344            )
345        {
346            super(singleton, Domains.BluetoothEmulation, "ScanRecord", 5);
347
348            this.name               = name;
349            this.uuids              = uuids;
350            this.appearance         = appearance;
351            this.txPower            = txPower;
352            this.manufacturerData   = manufacturerData;
353
354            this.isPresent = (isPresent == null)
355                ? singleton.generateIsPresentList(this)
356                : THROWS.check(isPresent, 5, "BluetoothEmulation.ScanRecord");
357        }
358
359        /** Creates an instance of this class from a {@link JsonObject}.*/
360        public static ScanRecord fromJSON(JsonObject jo)
361        { return singleton.fromJSON(jo); }
362
363        /** Returns this class's {@link NestedDescriptor} singleton-instance. class / type.*/
364        public static NestedDescriptor<ScanRecord> descriptor()
365        { return singleton.descriptor(); }
366    }
367
368
369    // ********************************************************************************************
370    // ********************************************************************************************
371    // Event Types
372    // ********************************************************************************************
373    // ********************************************************************************************
374
375
376    /**
377     * Event for when a characteristic operation of |type| to the characteristic
378     * respresented by |characteristicId| happened. |data| and |writeType| is
379     * expected to exist when |type| is write.
380     * 
381     * <EMBED CLASS=globalDefs DATA-DOMAIN=BluetoothEmulation DATA-API=BrowserAPI>
382     */
383    @JDHeaderBackgroundImg(EmbedTagFileID="CDP.NESTED_EVENT_JDHBI")
384    public static class characteristicOperationReceived
385        extends BrowserEvent<characteristicOperationReceived>
386        implements java.io.Serializable
387    {
388        /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */
389        protected static final long serialVersionUID = 1;
390
391        private static final NestedHelper<BluetoothEmulation.characteristicOperationReceived> singleton =
392            Torello.Browser.BrowserAPI.NestedHelpers.Events.
393                BluetoothEmulation$$characteristicOperationReceived$$.singleton;
394
395        /** <CODE>[No Description Provided by Google]</CODE> */
396        public final String characteristicId;
397
398        /**
399         * <CODE>[No Description Provided by Google]</CODE>
400         * <EMBED CLASS='external-html' DATA-D=BluetoothEmulation DATA-C=CharacteristicOperationType DATA-F=type DATA-FILE-ID=CDP.EL2>
401         * @see BaseType#enumStrList(String)
402         */
403        public final String type;
404
405        /**
406         * <CODE>[No Description Provided by Google]</CODE>
407         * <BR /><B CLASS=Opt-Top>OPTIONAL</B>
408         */
409        public final String data;
410
411        /**
412         * <CODE>[No Description Provided by Google]</CODE>
413         * <BR /><B CLASS=Opt-Top>OPTIONAL</B>
414         * <EMBED CLASS='external-html' DATA-D=BluetoothEmulation DATA-C=CharacteristicWriteType DATA-F=writeType DATA-FILE-ID=CDP.EL2>
415         * @see BaseType#enumStrList(String)
416         */
417        public final String writeType;
418
419        /** Constructor.  Please review this class' fields for documentation. */
420        public characteristicOperationReceived(
421                ReadOnlyList<Boolean> isPresent, String characteristicId, String type, String data,
422                String writeType
423            )
424        {
425            super(singleton, Domains.BluetoothEmulation, "characteristicOperationReceived", 4);
426
427            this.characteristicId   = characteristicId;
428            this.type               = type;
429            this.data               = data;
430            this.writeType          = writeType;
431
432            this.isPresent = (isPresent == null)
433                ? singleton.generateIsPresentList(this)
434                : THROWS.check(isPresent, 4, "BluetoothEmulation.characteristicOperationReceived");
435        }
436
437        /** Creates an instance of this class from a {@link JsonObject}.*/
438        public static characteristicOperationReceived fromJSON(JsonObject jo)
439        { return singleton.fromJSON(jo); }
440
441        /** Returns this class's {@link NestedDescriptor} singleton-instance. class / type.*/
442        public static NestedDescriptor<characteristicOperationReceived> descriptor()
443        { return singleton.descriptor(); }
444    }
445
446    /**
447     * Event for when a descriptor operation of |type| to the descriptor
448     * respresented by |descriptorId| happened. |data| is expected to exist when
449     * |type| is write.
450     * 
451     * <EMBED CLASS=globalDefs DATA-DOMAIN=BluetoothEmulation DATA-API=BrowserAPI>
452     */
453    @JDHeaderBackgroundImg(EmbedTagFileID="CDP.NESTED_EVENT_JDHBI")
454    public static class descriptorOperationReceived
455        extends BrowserEvent<descriptorOperationReceived>
456        implements java.io.Serializable
457    {
458        /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */
459        protected static final long serialVersionUID = 1;
460
461        private static final NestedHelper<BluetoothEmulation.descriptorOperationReceived> singleton =
462            Torello.Browser.BrowserAPI.NestedHelpers.Events.
463                BluetoothEmulation$$descriptorOperationReceived$$.singleton;
464
465        /** <CODE>[No Description Provided by Google]</CODE> */
466        public final String descriptorId;
467
468        /**
469         * <CODE>[No Description Provided by Google]</CODE>
470         * <EMBED CLASS='external-html' DATA-D=BluetoothEmulation DATA-C=DescriptorOperationType DATA-F=type DATA-FILE-ID=CDP.EL2>
471         * @see BaseType#enumStrList(String)
472         */
473        public final String type;
474
475        /**
476         * <CODE>[No Description Provided by Google]</CODE>
477         * <BR /><B CLASS=Opt-Top>OPTIONAL</B>
478         */
479        public final String data;
480
481        /** Constructor.  Please review this class' fields for documentation. */
482        public descriptorOperationReceived
483            (ReadOnlyList<Boolean> isPresent, String descriptorId, String type, String data)
484        {
485            super(singleton, Domains.BluetoothEmulation, "descriptorOperationReceived", 3);
486
487            this.descriptorId   = descriptorId;
488            this.type           = type;
489            this.data           = data;
490
491            this.isPresent = (isPresent == null)
492                ? singleton.generateIsPresentList(this)
493                : THROWS.check(isPresent, 3, "BluetoothEmulation.descriptorOperationReceived");
494        }
495
496        /** Creates an instance of this class from a {@link JsonObject}.*/
497        public static descriptorOperationReceived fromJSON(JsonObject jo)
498        { return singleton.fromJSON(jo); }
499
500        /** Returns this class's {@link NestedDescriptor} singleton-instance. class / type.*/
501        public static NestedDescriptor<descriptorOperationReceived> descriptor()
502        { return singleton.descriptor(); }
503    }
504
505    /**
506     * Event for when a GATT operation of |type| to the peripheral with |address|
507     * happened.
508     * 
509     * <EMBED CLASS=globalDefs DATA-DOMAIN=BluetoothEmulation DATA-API=BrowserAPI>
510     */
511    @JDHeaderBackgroundImg(EmbedTagFileID="CDP.NESTED_EVENT_JDHBI")
512    public static class gattOperationReceived
513        extends BrowserEvent<gattOperationReceived>
514        implements java.io.Serializable
515    {
516        /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */
517        protected static final long serialVersionUID = 1;
518
519        private static final NestedHelper<BluetoothEmulation.gattOperationReceived> singleton =
520            Torello.Browser.BrowserAPI.NestedHelpers.Events.
521                BluetoothEmulation$$gattOperationReceived$$.singleton;
522
523        /** <CODE>[No Description Provided by Google]</CODE> */
524        public final String address;
525
526        /**
527         * <CODE>[No Description Provided by Google]</CODE>
528         * <EMBED CLASS='external-html' DATA-D=BluetoothEmulation DATA-C=GATTOperationType DATA-F=type DATA-FILE-ID=CDP.EL2>
529         * @see BaseType#enumStrList(String)
530         */
531        public final String type;
532
533        /** Constructor.  Please review this class' fields for documentation. */
534        public gattOperationReceived(ReadOnlyList<Boolean> isPresent, String address, String type)
535        {
536            super(singleton, Domains.BluetoothEmulation, "gattOperationReceived", 2);
537
538            this.address    = address;
539            this.type       = type;
540
541            this.isPresent = (isPresent == null)
542                ? singleton.generateIsPresentList(this)
543                : THROWS.check(isPresent, 2, "BluetoothEmulation.gattOperationReceived");
544        }
545
546        /** Creates an instance of this class from a {@link JsonObject}.*/
547        public static gattOperationReceived fromJSON(JsonObject jo)
548        { return singleton.fromJSON(jo); }
549
550        /** Returns this class's {@link NestedDescriptor} singleton-instance. class / type.*/
551        public static NestedDescriptor<gattOperationReceived> descriptor()
552        { return singleton.descriptor(); }
553    }
554
555
556
557
558    // ********************************************************************************************
559    // ********************************************************************************************
560    // Commands
561    // ********************************************************************************************
562    // ********************************************************************************************
563
564
565    /**
566     * Adds a characteristic with |characteristicUuid| and |properties| to the
567     * service represented by |serviceId|.
568     * 
569     * @param serviceId -
570     * 
571     * @param characteristicUuid -
572     * 
573     * @param properties -
574     * 
575     * @return An instance of <CODE>{@link Script}&lt;String&gt;</CODE>
576     * 
577     * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using
578     * {@link Script#exec(WebSocketSender) Script.exec}, and afterwards, a {@link Promise}
579     * <CODE>&lt;String&gt;</CODE> will be returned
580     *
581     * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>,
582     * using {@link Promise#await()}, <I>and the returned result of this Browser Function may
583     * be retrieved.</I>
584     *
585     * <BR /><BR /><DIV CLASS=JDHint>
586     * This Browser Function's {@code Promise} returns:
587     * <CODE>String (<B>characteristicId</B>)</CODE>
588     * <BR />
589     * An identifier that uniquely represents this characteristic.
590     * </DIV>
591     */
592    public static Script<String> addCharacteristic
593        (String serviceId, String characteristicUuid, CharacteristicProperties properties)
594    {
595        // Convert all Method Parameters into a JSON Request-Object (as a String)
596        final String requestJSON = WriteJSON.get(
597            BluetoothEmulation$$Commands.addCharacteristic$$,
598            "BluetoothEmulation.addCharacteristic",
599            serviceId, characteristicUuid, properties
600        );
601
602        return new Script<>(
603            Domains.BluetoothEmulation, "addCharacteristic", requestJSON,
604            jo -> ReadJSON.getString(jo, "characteristicId", true, false),
605            String.class
606        );
607    }
608
609    /**
610     * Adds a descriptor with |descriptorUuid| to the characteristic respresented
611     * by |characteristicId|.
612     * 
613     * @param characteristicId -
614     * 
615     * @param descriptorUuid -
616     * 
617     * @return An instance of <CODE>{@link Script}&lt;String&gt;</CODE>
618     * 
619     * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using
620     * {@link Script#exec(WebSocketSender) Script.exec}, and afterwards, a {@link Promise}
621     * <CODE>&lt;String&gt;</CODE> will be returned
622     *
623     * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>,
624     * using {@link Promise#await()}, <I>and the returned result of this Browser Function may
625     * be retrieved.</I>
626     *
627     * <BR /><BR /><DIV CLASS=JDHint>
628     * This Browser Function's {@code Promise} returns:
629     * <CODE>String (<B>descriptorId</B>)</CODE>
630     * <BR />
631     * An identifier that uniquely represents this descriptor.
632     * </DIV>
633     */
634    public static Script<String> addDescriptor(String characteristicId, String descriptorUuid)
635    {
636        // Convert all Method Parameters into a JSON Request-Object (as a String)
637        final String requestJSON = WriteJSON.get(
638            BluetoothEmulation$$Commands.addDescriptor$$, "BluetoothEmulation.addDescriptor",
639            characteristicId, descriptorUuid
640        );
641
642        return new Script<>(
643            Domains.BluetoothEmulation, "addDescriptor", requestJSON,
644            jo -> ReadJSON.getString(jo, "descriptorId", true, false),
645            String.class
646        );
647    }
648
649    /**
650     * Adds a service with |serviceUuid| to the peripheral with |address|.
651     * 
652     * @param address -
653     * 
654     * @param serviceUuid -
655     * 
656     * @return An instance of <CODE>{@link Script}&lt;String&gt;</CODE>
657     * 
658     * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using
659     * {@link Script#exec(WebSocketSender) Script.exec}, and afterwards, a {@link Promise}
660     * <CODE>&lt;String&gt;</CODE> will be returned
661     *
662     * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>,
663     * using {@link Promise#await()}, <I>and the returned result of this Browser Function may
664     * be retrieved.</I>
665     *
666     * <BR /><BR /><DIV CLASS=JDHint>
667     * This Browser Function's {@code Promise} returns:
668     * <CODE>String (<B>serviceId</B>)</CODE>
669     * <BR />
670     * An identifier that uniquely represents this service.
671     * </DIV>
672     */
673    public static Script<String> addService(String address, String serviceUuid)
674    {
675        // Convert all Method Parameters into a JSON Request-Object (as a String)
676        final String requestJSON = WriteJSON.get(
677            BluetoothEmulation$$Commands.addService$$, "BluetoothEmulation.addService",
678            address, serviceUuid
679        );
680
681        return new Script<>(
682            Domains.BluetoothEmulation, "addService", requestJSON,
683            jo -> ReadJSON.getString(jo, "serviceId", true, false),
684            String.class
685        );
686    }
687
688    /**
689     * Disable the BluetoothEmulation domain.
690     * 
691     * @return An instance of <CODE>{@link Script}&lt;Void&gt;</CODE>
692     *
693     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
694     * browser receives the invocation-request.
695     *
696     * <BR /><BR /><DIV CLASS=JDHint>
697     * This Browser-Function <I>does not have</I> a return-value.  You may choose to
698     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <Void>} to ensure that
699     * the Browser Function has run to completion.
700     * </DIV>
701     */
702    public static Script<Void> disable()
703    {
704        // Ultra-Simple Request JSON - Because this method has no parameters
705        final String requestJSON = "{\"method\":\"BluetoothEmulation.disable\"}";
706
707        return Script.NO_RET(Domains.BluetoothEmulation, "disable", requestJSON);
708    }
709
710    /**
711     * Enable the BluetoothEmulation domain.
712     * 
713     * @param state State of the simulated central.
714     * 
715     * @param leSupported If the simulated central supports low-energy.
716     * 
717     * @return An instance of <CODE>{@link Script}&lt;Void&gt;</CODE>
718     *
719     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
720     * browser receives the invocation-request.
721     *
722     * <BR /><BR /><DIV CLASS=JDHint>
723     * This Browser-Function <I>does not have</I> a return-value.  You may choose to
724     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <Void>} to ensure that
725     * the Browser Function has run to completion.
726     * </DIV>
727     */
728    public static Script<Void> enable(String state, boolean leSupported)
729    {
730        // Convert all Method Parameters into a JSON Request-Object (as a String)
731        final String requestJSON = WriteJSON.get(
732            BluetoothEmulation$$Commands.enable$$, "BluetoothEmulation.enable",
733            state, leSupported
734        );
735
736        return Script.NO_RET(Domains.BluetoothEmulation, "enable", requestJSON);
737    }
738
739    /**
740     * Removes the characteristic respresented by |characteristicId| from the
741     * simulated central.
742     * 
743     * @param characteristicId -
744     * 
745     * @return An instance of <CODE>{@link Script}&lt;Void&gt;</CODE>
746     *
747     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
748     * browser receives the invocation-request.
749     *
750     * <BR /><BR /><DIV CLASS=JDHint>
751     * This Browser-Function <I>does not have</I> a return-value.  You may choose to
752     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <Void>} to ensure that
753     * the Browser Function has run to completion.
754     * </DIV>
755     */
756    public static Script<Void> removeCharacteristic(String characteristicId)
757    {
758        // Build the JSON Request-Object (as a String); only 1 Parameter is passed
759        final String requestJSON = WriteJSON.get(
760            CDPTypes.STRING, "characteristicId", false,
761            "BluetoothEmulation.removeCharacteristic", characteristicId
762        );
763
764        return Script.NO_RET(Domains.BluetoothEmulation, "removeCharacteristic", requestJSON);
765    }
766
767    /**
768     * Removes the descriptor with |descriptorId| from the simulated central.
769     * 
770     * @param descriptorId -
771     * 
772     * @return An instance of <CODE>{@link Script}&lt;Void&gt;</CODE>
773     *
774     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
775     * browser receives the invocation-request.
776     *
777     * <BR /><BR /><DIV CLASS=JDHint>
778     * This Browser-Function <I>does not have</I> a return-value.  You may choose to
779     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <Void>} to ensure that
780     * the Browser Function has run to completion.
781     * </DIV>
782     */
783    public static Script<Void> removeDescriptor(String descriptorId)
784    {
785        // Build the JSON Request-Object (as a String); only 1 Parameter is passed
786        final String requestJSON = WriteJSON.get(
787            CDPTypes.STRING, "descriptorId", false, "BluetoothEmulation.removeDescriptor",
788            descriptorId
789        );
790
791        return Script.NO_RET(Domains.BluetoothEmulation, "removeDescriptor", requestJSON);
792    }
793
794    /**
795     * Removes the service respresented by |serviceId| from the simulated central.
796     * 
797     * @param serviceId -
798     * 
799     * @return An instance of <CODE>{@link Script}&lt;Void&gt;</CODE>
800     *
801     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
802     * browser receives the invocation-request.
803     *
804     * <BR /><BR /><DIV CLASS=JDHint>
805     * This Browser-Function <I>does not have</I> a return-value.  You may choose to
806     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <Void>} to ensure that
807     * the Browser Function has run to completion.
808     * </DIV>
809     */
810    public static Script<Void> removeService(String serviceId)
811    {
812        // Build the JSON Request-Object (as a String); only 1 Parameter is passed
813        final String requestJSON = WriteJSON.get
814            (CDPTypes.STRING, "serviceId", false, "BluetoothEmulation.removeService", serviceId);
815
816        return Script.NO_RET(Domains.BluetoothEmulation, "removeService", requestJSON);
817    }
818
819    /**
820     * Set the state of the simulated central.
821     * 
822     * @param state State of the simulated central.
823     * 
824     * @return An instance of <CODE>{@link Script}&lt;Void&gt;</CODE>
825     *
826     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
827     * browser receives the invocation-request.
828     *
829     * <BR /><BR /><DIV CLASS=JDHint>
830     * This Browser-Function <I>does not have</I> a return-value.  You may choose to
831     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <Void>} to ensure that
832     * the Browser Function has run to completion.
833     * </DIV>
834     */
835    public static Script<Void> setSimulatedCentralState(String state)
836    {
837        // Build the JSON Request-Object (as a String); only 1 Parameter is passed
838        final String requestJSON = WriteJSON.get(
839            CDPTypes.STRING, "state", false, "BluetoothEmulation.setSimulatedCentralState",
840            state
841        );
842
843        return Script.NO_RET(Domains.BluetoothEmulation, "setSimulatedCentralState", requestJSON);
844    }
845
846    /**
847     * Simulates an advertisement packet described in |entry| being received by
848     * the central.
849     * 
850     * @param entry -
851     * 
852     * @return An instance of <CODE>{@link Script}&lt;Void&gt;</CODE>
853     *
854     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
855     * browser receives the invocation-request.
856     *
857     * <BR /><BR /><DIV CLASS=JDHint>
858     * This Browser-Function <I>does not have</I> a return-value.  You may choose to
859     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <Void>} to ensure that
860     * the Browser Function has run to completion.
861     * </DIV>
862     */
863    public static Script<Void> simulateAdvertisement(ScanEntry entry)
864    {
865        // Build the JSON Request-Object (as a String); only 1 Parameter is passed
866        final String requestJSON = WriteJSON.get(
867            CDPTypes.CDP_TYPE, "entry", false, "BluetoothEmulation.simulateAdvertisement", entry
868        );
869
870        return Script.NO_RET(Domains.BluetoothEmulation, "simulateAdvertisement", requestJSON);
871    }
872
873    /**
874     * Simulates the response from the characteristic with |characteristicId| for a
875     * characteristic operation of |type|. The |code| value follows the Error
876     * Codes from Bluetooth Core Specification Vol 3 Part F 3.4.1.1 Error Response.
877     * The |data| is expected to exist when simulating a successful read operation
878     * response.
879     * 
880     * @param characteristicId -
881     * 
882     * @param type -
883     * 
884     * @param code -
885     * 
886     * @param data -
887     * <BR /><B CLASS=Opt-Top>OPTIONAL</B>
888     * 
889     * @return An instance of <CODE>{@link Script}&lt;Void&gt;</CODE>
890     *
891     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
892     * browser receives the invocation-request.
893     *
894     * <BR /><BR /><DIV CLASS=JDHint>
895     * This Browser-Function <I>does not have</I> a return-value.  You may choose to
896     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <Void>} to ensure that
897     * the Browser Function has run to completion.
898     * </DIV>
899     */
900    public static Script<Void> simulateCharacteristicOperationResponse
901        (String characteristicId, String type, int code, String data)
902    {
903        // Convert all Method Parameters into a JSON Request-Object (as a String)
904        final String requestJSON = WriteJSON.get(
905            BluetoothEmulation$$Commands.simulateCharacteristicOperationResponse$$,
906            "BluetoothEmulation.simulateCharacteristicOperationResponse",
907            characteristicId, type, code, data
908        );
909
910        return Script.NO_RET(Domains.BluetoothEmulation, "simulateCharacteristicOperationResponse", requestJSON);
911    }
912
913    /**
914     * Simulates the response from the descriptor with |descriptorId| for a
915     * descriptor operation of |type|. The |code| value follows the Error
916     * Codes from Bluetooth Core Specification Vol 3 Part F 3.4.1.1 Error Response.
917     * The |data| is expected to exist when simulating a successful read operation
918     * response.
919     * 
920     * @param descriptorId -
921     * 
922     * @param type -
923     * 
924     * @param code -
925     * 
926     * @param data -
927     * <BR /><B CLASS=Opt-Top>OPTIONAL</B>
928     * 
929     * @return An instance of <CODE>{@link Script}&lt;Void&gt;</CODE>
930     *
931     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
932     * browser receives the invocation-request.
933     *
934     * <BR /><BR /><DIV CLASS=JDHint>
935     * This Browser-Function <I>does not have</I> a return-value.  You may choose to
936     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <Void>} to ensure that
937     * the Browser Function has run to completion.
938     * </DIV>
939     */
940    public static Script<Void> simulateDescriptorOperationResponse
941        (String descriptorId, String type, int code, String data)
942    {
943        // Convert all Method Parameters into a JSON Request-Object (as a String)
944        final String requestJSON = WriteJSON.get(
945            BluetoothEmulation$$Commands.simulateDescriptorOperationResponse$$,
946            "BluetoothEmulation.simulateDescriptorOperationResponse",
947            descriptorId, type, code, data
948        );
949
950        return Script.NO_RET(Domains.BluetoothEmulation, "simulateDescriptorOperationResponse", requestJSON);
951    }
952
953    /**
954     * Simulates a GATT disconnection from the peripheral with |address|.
955     * 
956     * @param address -
957     * 
958     * @return An instance of <CODE>{@link Script}&lt;Void&gt;</CODE>
959     *
960     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
961     * browser receives the invocation-request.
962     *
963     * <BR /><BR /><DIV CLASS=JDHint>
964     * This Browser-Function <I>does not have</I> a return-value.  You may choose to
965     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <Void>} to ensure that
966     * the Browser Function has run to completion.
967     * </DIV>
968     */
969    public static Script<Void> simulateGATTDisconnection(String address)
970    {
971        // Build the JSON Request-Object (as a String); only 1 Parameter is passed
972        final String requestJSON = WriteJSON.get(
973            CDPTypes.STRING, "address", false, "BluetoothEmulation.simulateGATTDisconnection",
974            address
975        );
976
977        return Script.NO_RET(Domains.BluetoothEmulation, "simulateGATTDisconnection", requestJSON);
978    }
979
980    /**
981     * Simulates the response code from the peripheral with |address| for a
982     * GATT operation of |type|. The |code| value follows the HCI Error Codes from
983     * Bluetooth Core Specification Vol 2 Part D 1.3 List Of Error Codes.
984     * 
985     * @param address -
986     * 
987     * @param type -
988     * 
989     * @param code -
990     * 
991     * @return An instance of <CODE>{@link Script}&lt;Void&gt;</CODE>
992     *
993     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
994     * browser receives the invocation-request.
995     *
996     * <BR /><BR /><DIV CLASS=JDHint>
997     * This Browser-Function <I>does not have</I> a return-value.  You may choose to
998     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <Void>} to ensure that
999     * the Browser Function has run to completion.
1000     * </DIV>
1001     */
1002    public static Script<Void> simulateGATTOperationResponse(String address, String type, int code)
1003    {
1004        // Convert all Method Parameters into a JSON Request-Object (as a String)
1005        final String requestJSON = WriteJSON.get(
1006            BluetoothEmulation$$Commands.simulateGATTOperationResponse$$,
1007            "BluetoothEmulation.simulateGATTOperationResponse",
1008            address, type, code
1009        );
1010
1011        return Script.NO_RET(Domains.BluetoothEmulation, "simulateGATTOperationResponse", requestJSON);
1012    }
1013
1014    /**
1015     * Simulates a peripheral with |address|, |name| and |knownServiceUuids|
1016     * that has already been connected to the system.
1017     * 
1018     * @param address -
1019     * 
1020     * @param name -
1021     * 
1022     * @param manufacturerData -
1023     * 
1024     * @param knownServiceUuids -
1025     * 
1026     * @return An instance of <CODE>{@link Script}&lt;Void&gt;</CODE>
1027     *
1028     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
1029     * browser receives the invocation-request.
1030     *
1031     * <BR /><BR /><DIV CLASS=JDHint>
1032     * This Browser-Function <I>does not have</I> a return-value.  You may choose to
1033     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <Void>} to ensure that
1034     * the Browser Function has run to completion.
1035     * </DIV>
1036     */
1037    public static Script<Void> simulatePreconnectedPeripheral(
1038            String address, String name, ManufacturerData[] manufacturerData,
1039            String[] knownServiceUuids
1040        )
1041    {
1042        // Convert all Method Parameters into a JSON Request-Object (as a String)
1043        final String requestJSON = WriteJSON.get(
1044            BluetoothEmulation$$Commands.simulatePreconnectedPeripheral$$,
1045            "BluetoothEmulation.simulatePreconnectedPeripheral",
1046            address, name, manufacturerData, knownServiceUuids
1047        );
1048
1049        return Script.NO_RET(Domains.BluetoothEmulation, "simulatePreconnectedPeripheral", requestJSON);
1050    }
1051
1052
1053}