- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / common / extensions / api / sockets_tcp_server.idl
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Use the <code>chrome.sockets.tcpServer</code> API to create server
6 // applications using TCP connections. This API supersedes the TCP functionality
7 // previously found in the <code>chrome.socket</code> API. Note that the socket
8 // ids created from this namespace are not compatible with ids created in other
9 // namespaces.
10 namespace sockets.tcpServer {
11   // The socket properties specified in the <code>create</code> or
12   // <code>update</code> function. Each property is optional. If a property
13   // value is not specified, a default value is used when calling
14   // <code>create</code>, or the existing value if preserved when calling
15   // <code>update</code>.
16   dictionary SocketProperties {
17     // Flag indicating if the socket remains open when the event page of the
18     // application is unloaded (see
19     // <a href="http://developer.chrome.com/apps/app_lifecycle.html">Manage App
20     // Lifecycle</a>). The default value is "false." When the application is
21     // loaded, any sockets previously opened with persistent=true can be fetched
22     // with <code>getSockets</code>.
23     boolean? persistent;
24
25     // An application-defined string associated with the socket.
26     DOMString? name;
27   };
28
29   // Result of <code>create</code> call.
30   dictionary CreateInfo {
31     // The ID of the newly created server socket.
32     long socketId;
33   };
34
35   // Callback from the <code>create</code> method.
36   // |createInfo| : The result of the socket creation.
37   callback CreateCallback = void (CreateInfo createInfo);
38
39   // Callback from the <code>listen</code> method.
40   // |result| : The result code returned from the underlying network call.
41   // A negative value indicates an error.
42   callback ListenCallback = void (long result);
43
44   // Callback from the <code>disconnect</code> method.
45   callback DisconnectCallback = void ();
46
47   // Callback from the <code>close<code> method.
48   callback CloseCallback = void ();
49
50   // Callback from the <code>update</code> method.
51   callback UpdateCallback = void ();
52
53   // Callback from the <code>setPaused<code> method.
54   callback SetPausedCallback = void ();
55
56   // Result of the <code>getInfo</code> method.
57   dictionary SocketInfo {
58     // The socket identifier.
59     long socketId;
60
61     // Flag indicating if the socket remains open when the event page of the
62     // application is unloaded (see <code>SocketProperties.persistent</code>).
63     // The default value is "false".
64     boolean persistent;
65
66     // Application-defined string associated with the socket.
67     DOMString? name;
68
69     // Flag indicating whether connection requests on a listening socket are
70     // dispatched through the <code>onAccept<code> event or queued up in the
71     // listen queue backlog.
72     // See <code>setPaused<code>. The default value is "false".
73     boolean paused;
74
75     // If the socket is listening, contains its local IPv4/6 address.
76     DOMString? localAddress;
77
78     // If the socket is listening, contains its local port.
79     long? localPort;
80   };
81
82   // Callback from the <code>getInfo</code> method.
83   // |socketInfo| : Object containing the socket information.
84   callback GetInfoCallback = void (SocketInfo socketInfo);
85
86   // Callback from the <code>getSockets</code> method.
87   // |socketInfos| : Array of object containing socket information.
88   callback GetSocketsCallback = void (SocketInfo[] socketInfos);
89
90   // Data from an <code>onAccept</code> event.
91   dictionary AcceptInfo {
92     // The server socket identifier.
93     long socketId;
94
95     // The client socket identifier, i.e. the socket identifier of the newly
96     // established connection. This socket identifier should be used only with
97     // functions from the <code>chrome.sockets.tcp<code> namespace.
98     long clientSocketId;
99   };
100
101   // Data from an <code>onAcceptError</code> event.
102   dictionary AcceptErrorInfo {
103     // The server socket identifier.
104     long socketId;
105
106     // The result code returned from the underlying network call.
107     long resultCode;
108   };
109
110   interface Functions {
111     // Creates a TCP server socket.
112     // |properties| : The socket properties (optional).
113     // |callback| : Called when the socket has been created.
114     static void create(optional SocketProperties properties,
115                        CreateCallback callback);
116
117     // Updates the socket properties.
118     // |socketId| : The socket identifier.
119     // |properties| : The properties to update.
120     // |callback| : Called when the properties are updated.
121     static void update(long socketId,
122                        SocketProperties properties,
123                        optional UpdateCallback callback);
124
125     // Enables or disables a listening socket from accepting new connections.
126     // When paused, a listening socket accepts new connections until its backlog
127     // (see <code>listen<code> function) is full then refuses additional
128     // connection requests. <code>onAccept<code> events are raised only when
129     // the socket is un-paused.
130     static void setPaused(long socketId,
131                           boolean paused,
132                           optional SetPausedCallback callback);
133
134     // Listens for connections on the specified port and address.
135     // If the port/address is in use, the callback indicates a failure.
136     // |socketId| : The socket identifier.
137     // |address| : The address of the local machine.
138     // |port| : The port of the local machine.
139     // |backlog| : Length of the socket's listen queue. The default value
140     // depends on the Operating System (SOMAXCONN), which ensures a reasonable
141     // queue length for most applications.
142     // |callback| : Called when listen operation completes.
143     static void listen(long socketId,
144                        DOMString address,
145                        long port,
146                        optional long backlog,
147                        ListenCallback callback);
148
149     // Disconnects the listening socket, i.e. stops accepting new connections
150     // and releases the address/port the socket is bound to. The socket
151     // identifier remains valid, e.g. it can be used with <code>listen<code> to
152     // accept connections on a new port and address.
153     // |socketId| : The socket identifier.
154     // |callback| : Called when the disconnect attempt is complete.
155     static void disconnect(long socketId,
156                            optional DisconnectCallback callback);
157
158     // Disconnects and destroys the socket. Each socket created should be
159     // closed after use. The socket id is no longer valid as soon at the
160     // function is called. However, the socket is guaranteed to be closed only
161     // when the callback is invoked.
162     // |socketId| : The socket identifier.
163     // |callback| : Called when the <code>close</code> operation completes.
164     static void close(long socketId,
165                       optional CloseCallback callback);
166
167     // Retrieves the state of the given socket.
168     // |socketId| : The socket identifier.
169     // |callback| : Called when the socket state is available.
170     static void getInfo(long socketId,
171                         GetInfoCallback callback);
172
173     // Retrieves the list of currently opened sockets owned by the application.
174     // |callback| : Called when the list of sockets is available.
175     static void getSockets(GetSocketsCallback callback);
176   };
177
178   interface Events {
179     // Event raised when a connection has been made to the server socket.
180     // |info| : The event data.
181     static void onAccept(AcceptInfo info);
182
183     // Event raised when a network error occured while the runtime was waiting
184     // for new connections on the socket address and port. Once this event is
185     // raised, the socket is set to <code>paused</code> and no more
186     // <code>onAccept</code> events are raised for this socket until the socket
187     // is resumed.
188     // |info| : The event data.
189     static void onAcceptError(AcceptErrorInfo info);
190   };
191 };