• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * ConnectBot: simple, powerful, open-source SSH client for Android
3  * Copyright 2007 Kenny Root, Jeffrey Sharkey
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 package org.connectbot.transport;
19 
20 import org.connectbot.service.TerminalBridge;
21 import org.connectbot.service.TerminalManager;
22 
23 import java.io.IOException;
24 
25 /**
26  * @author Kenny Root
27  * @author modified by raaar
28  */
29 public abstract class AbsTransport {
30 
31   TerminalBridge bridge;
32   TerminalManager manager;
33 
34   /**
35    * Causes transport to connect to the target host. After connecting but before a session is
36    * started, must call back to {@link TerminalBridge#onConnected()}. After that call a session may
37    * be opened.
38    */
connect()39   public abstract void connect();
40 
41   /**
42    * Reads from the transport. Transport must support reading into a the byte array
43    * <code>buffer</code> at the start of <code>offset</code> and a maximum of <code>length</code>
44    * bytes. If the remote host disconnects, throw an {@link IOException}.
45    *
46    * @param buffer
47    *          byte buffer to store read bytes into
48    * @param offset
49    *          where to start writing in the buffer
50    * @param length
51    *          maximum number of bytes to read
52    * @return number of bytes read
53    * @throws IOException
54    *           when remote host disconnects
55    */
read(byte[] buffer, int offset, int length)56   public abstract int read(byte[] buffer, int offset, int length) throws IOException;
57 
58   /**
59    * Writes to the transport. If the host is not yet connected, simply return without doing
60    * anything. An {@link IOException} should be thrown if there is an error after connection.
61    *
62    * @param buffer
63    *          bytes to write to transport
64    * @throws IOException
65    *           when there is a problem writing after connection
66    */
write(byte[] buffer)67   public abstract void write(byte[] buffer) throws IOException;
68 
69   /**
70    * Writes to the transport. See {@link #write(byte[])} for behavior details.
71    *
72    * @param c
73    *          character to write to the transport
74    * @throws IOException
75    *           when there is a problem writing after connection
76    */
write(int c)77   public abstract void write(int c) throws IOException;
78 
79   /**
80    * Flushes the write commands to the transport.
81    *
82    * @throws IOException
83    *           when there is a problem writing after connection
84    */
flush()85   public abstract void flush() throws IOException;
86 
87   /**
88    * Closes the connection to the terminal. Note that the resulting failure to read should call
89    * {@link TerminalBridge#dispatchDisconnect(boolean)}.
90    */
close()91   public abstract void close();
92 
93   /**
94    * Tells the transport what dimensions the display is currently
95    *
96    * @param columns
97    *          columns of text
98    * @param rows
99    *          rows of text
100    * @param width
101    *          width in pixels
102    * @param height
103    *          height in pixels
104    */
setDimensions(int columns, int rows, int width, int height)105   public abstract void setDimensions(int columns, int rows, int width, int height);
106 
setBridge(TerminalBridge bridge)107   public void setBridge(TerminalBridge bridge) {
108     this.bridge = bridge;
109   }
110 
setManager(TerminalManager manager)111   public void setManager(TerminalManager manager) {
112     this.manager = manager;
113   }
114 
isConnected()115   public abstract boolean isConnected();
116 
isSessionOpen()117   public abstract boolean isSessionOpen();
118 
119 }
120