|
1 // Copyright (c) 2009 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 package org.chromium.sdk.internal.transport; |
|
6 |
|
7 import java.io.IOException; |
|
8 |
|
9 /** |
|
10 * An interface to be implemented by an agent performing the communications with |
|
11 * the debugged browser instance. |
|
12 */ |
|
13 public interface Connection { |
|
14 |
|
15 /** |
|
16 * An interface to be used for notification of messages coming in from the |
|
17 * browser. |
|
18 */ |
|
19 public interface NetListener { |
|
20 |
|
21 /** |
|
22 * Gets invoked whenever a message from the browser arrives. |
|
23 * Invoked from DispatchThread. |
|
24 * @param message from the browser instance the connection is associated |
|
25 * with |
|
26 */ |
|
27 void messageReceived(Message message); |
|
28 |
|
29 /** |
|
30 * Gets invoked from DispatchThread whenever EOS message arrives. This method |
|
31 * must not be called more than once. Method {@link #messageReceived} must |
|
32 * not be called after it. |
|
33 */ |
|
34 void eosReceived(); |
|
35 |
|
36 /** |
|
37 * Gets invoked when the physical connection has been terminated. |
|
38 * Called from whatever thread that connection is terminated from. |
|
39 */ |
|
40 void connectionClosed(); |
|
41 } |
|
42 |
|
43 /** |
|
44 * Sets a listener that will be notified of network events. The listener must |
|
45 * be set before calling {@link #start()} and cannot be changed over the |
|
46 * connection lifetime. |
|
47 * |
|
48 * @param netListener to set |
|
49 */ |
|
50 void setNetListener(NetListener netListener); |
|
51 |
|
52 /** |
|
53 * Sends the specified message to the associated browser instance. |
|
54 * |
|
55 * @param message to send |
|
56 */ |
|
57 void send(Message message); |
|
58 |
|
59 /** |
|
60 * Starts up the transport and acquire all needed resources. Does nothing if |
|
61 * the connection has already been started. |
|
62 * |
|
63 * @throws IOException |
|
64 */ |
|
65 void start() throws IOException; |
|
66 |
|
67 /** |
|
68 * Shuts down the transport freeing all acquired resources. Does nothing if |
|
69 * the connection has already been shut down. |
|
70 */ |
|
71 void close(); |
|
72 |
|
73 /** |
|
74 * Determines the connection state. |
|
75 * |
|
76 * @return whether start() has been successfully invoked and close() has not |
|
77 * been invoked yet |
|
78 */ |
|
79 boolean isConnected(); |
|
80 } |