• 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  */
27 public abstract class AbsTransport {
28 
29   TerminalBridge bridge;
30   TerminalManager manager;
31 
32   /**
33    * Causes transport to connect to the target host. After connecting but before a session is
34    * started, must call back to {@link TerminalBridge#onConnected()}. After that call a session may
35    * be opened.
36    */
connect()37   public abstract void connect();
38 
39   /**
40    * Reads from the transport. Transport must support reading into a the byte array
41    * <code>buffer</code> at the start of <code>offset</code> and a maximum of <code>length</code>
42    * bytes. If the remote host disconnects, throw an {@link IOException}.
43    *
44    * @param buffer
45    *          byte buffer to store read bytes into
46    * @param offset
47    *          where to start writing in the buffer
48    * @param length
49    *          maximum number of bytes to read
50    * @return number of bytes read
51    * @throws IOException
52    *           when remote host disconnects
53    */
read(byte[] buffer, int offset, int length)54   public abstract int read(byte[] buffer, int offset, int length) throws IOException;
55 
56   /**
57    * Writes to the transport. If the host is not yet connected, simply return without doing
58    * anything. An {@link IOException} should be thrown if there is an error after connection.
59    *
60    * @param buffer
61    *          bytes to write to transport
62    * @throws IOException
63    *           when there is a problem writing after connection
64    */
write(byte[] buffer)65   public abstract void write(byte[] buffer) throws IOException;
66 
67   /**
68    * Writes to the transport. See {@link #write(byte[])} for behavior details.
69    *
70    * @param c
71    *          character to write to the transport
72    * @throws IOException
73    *           when there is a problem writing after connection
74    */
write(int c)75   public abstract void write(int c) throws IOException;
76 
77   /**
78    * Flushes the write commands to the transport.
79    *
80    * @throws IOException
81    *           when there is a problem writing after connection
82    */
flush()83   public abstract void flush() throws IOException;
84 
85   /**
86    * Closes the connection to the terminal. Note that the resulting failure to read should call
87    * {@link TerminalBridge#dispatchDisconnect(boolean)}.
88    */
close()89   public abstract void close();
90 
91   /**
92    * Tells the transport what dimensions the display is currently
93    *
94    * @param columns
95    *          columns of text
96    * @param rows
97    *          rows of text
98    * @param width
99    *          width in pixels
100    * @param height
101    *          height in pixels
102    */
setDimensions(int columns, int rows, int width, int height)103   public abstract void setDimensions(int columns, int rows, int width, int height);
104 
setBridge(TerminalBridge bridge)105   public void setBridge(TerminalBridge bridge) {
106     this.bridge = bridge;
107   }
108 
setManager(TerminalManager manager)109   public void setManager(TerminalManager manager) {
110     this.manager = manager;
111   }
112 
isConnected()113   public abstract boolean isConnected();
114 
isSessionOpen()115   public abstract boolean isSessionOpen();
116 
117 }
118