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
018
019// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
020// JDK Imports
021// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
022
023import javax.json.JsonObject;
024import javax.json.JsonValue;
025
026/**
027 * <SPAN CLASS=COPIEDJDK><B>The Tethering domain defines methods and events for browser port binding.</B></SPAN>
028 * <EMBED CLASS='external-html' DATA-FILE-ID=CDP.CODE_GEN_NOTE>
029 */
030@StaticFunctional@JDHeaderBackgroundImg(EmbedTagFileID="CDP.WOOD_PLANK_NOTE")
031public class Tethering
032{
033    // No Pubic Constructors
034    private Tethering() { }
035
036
037
038    // ********************************************************************************************
039    // ********************************************************************************************
040    // Event Types
041    // ********************************************************************************************
042    // ********************************************************************************************
043
044
045    /**
046     * Informs that port was successfully bound and got a specified connection id.
047     * 
048     * <EMBED CLASS=globalDefs DATA-DOMAIN=Tethering DATA-API=BrowserAPI>
049     */
050    @JDHeaderBackgroundImg(EmbedTagFileID="CDP.NESTED_EVENT_JDHBI")
051    public static class accepted
052        extends BrowserEvent<accepted>
053        implements java.io.Serializable
054    {
055        /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */
056        protected static final long serialVersionUID = 1;
057
058        private static final NestedHelper<Tethering.accepted> singleton =
059            Torello.Browser.BrowserAPI.NestedHelpers.Events.
060                Tethering$$accepted$$.singleton;
061
062        /** Port number that was successfully bound. */
063        public final int port;
064
065        /** Connection id to be used. */
066        public final String connectionId;
067
068        /** Constructor.  Please review this class' fields for documentation. */
069        public accepted(ReadOnlyList<Boolean> isPresent, int port, String connectionId)
070        {
071            super(singleton, Domains.Tethering, "accepted", 2);
072
073            this.port           = port;
074            this.connectionId   = connectionId;
075
076            this.isPresent = (isPresent == null)
077                ? singleton.generateIsPresentList(this)
078                : THROWS.check(isPresent, 2, "Tethering.accepted");
079        }
080
081        /** Creates an instance of this class from a {@link JsonObject}.*/
082        public static accepted fromJSON(JsonObject jo)
083        { return singleton.fromJSON(jo); }
084
085        /** Returns this class's {@link NestedDescriptor} singleton-instance. class / type.*/
086        public static NestedDescriptor<accepted> descriptor()
087        { return singleton.descriptor(); }
088    }
089
090
091
092
093    // ********************************************************************************************
094    // ********************************************************************************************
095    // Commands
096    // ********************************************************************************************
097    // ********************************************************************************************
098
099
100    /**
101     * Request browser port binding.
102     * 
103     * @param port Port number to bind.
104     * 
105     * @return An instance of <CODE>{@link Script}&lt;Void&gt;</CODE>
106     *
107     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
108     * browser receives the invocation-request.
109     *
110     * <BR /><BR /><DIV CLASS=JDHint>
111     * This Browser-Function <I>does not have</I> a return-value.  You may choose to
112     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <Void>} to ensure that
113     * the Browser Function has run to completion.
114     * </DIV>
115     */
116    public static Script<Void> bind(int port)
117    {
118        // Build the JSON Request-Object (as a String); only 1 Parameter is passed
119        final String requestJSON = WriteJSON.get
120            (CDPTypes.PRIMITIVE_INT, "port", false, "Tethering.bind", port);
121
122        return Script.NO_RET(Domains.Tethering, "bind", requestJSON);
123    }
124
125    /**
126     * Request browser port unbinding.
127     * 
128     * @param port Port number to unbind.
129     * 
130     * @return An instance of <CODE>{@link Script}&lt;Void&gt;</CODE>
131     *
132     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
133     * browser receives the invocation-request.
134     *
135     * <BR /><BR /><DIV CLASS=JDHint>
136     * This Browser-Function <I>does not have</I> a return-value.  You may choose to
137     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <Void>} to ensure that
138     * the Browser Function has run to completion.
139     * </DIV>
140     */
141    public static Script<Void> unbind(int port)
142    {
143        // Build the JSON Request-Object (as a String); only 1 Parameter is passed
144        final String requestJSON = WriteJSON.get
145            (CDPTypes.PRIMITIVE_INT, "port", false, "Tethering.unbind", port);
146
147        return Script.NO_RET(Domains.Tethering, "unbind", requestJSON);
148    }
149
150
151}