001: /*
002: * SSHTools - Java SSH2 API
003: *
004: * Copyright (C) 2002-2003 Lee David Painter and Contributors.
005: *
006: * Contributions made by:
007: *
008: * Brett Smith
009: * Richard Pernavas
010: * Erwin Bolwidt
011: *
012: * This program is free software; you can redistribute it and/or
013: * modify it under the terms of the GNU General Public License
014: * as published by the Free Software Foundation; either version 2
015: * of the License, or (at your option) any later version.
016: *
017: * This program is distributed in the hope that it will be useful,
018: * but WITHOUT ANY WARRANTY; without even the implied warranty of
019: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
020: * GNU General Public License for more details.
021: *
022: * You should have received a copy of the GNU General Public License
023: * along with this program; if not, write to the Free Software
024: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
025: */
026: package com.sshtools.daemon.platform;
027:
028: import com.sshtools.daemon.configuration.PlatformConfiguration;
029:
030: import com.sshtools.j2ssh.configuration.ConfigurationLoader;
031:
032: import org.apache.commons.logging.Log;
033: import org.apache.commons.logging.LogFactory;
034:
035: import java.io.IOException;
036: import java.io.InputStream;
037: import java.io.OutputStream;
038:
039: import java.util.Map;
040:
041: /**
042: *
043: *
044: * @author $author$
045: * @version $Revision: 1.14 $
046: */
047: public abstract class NativeProcessProvider { //implements SessionDataProvider {
048:
049: private static Log log = LogFactory
050: .getLog(NativeProcessProvider.class);
051: private static Class provider;
052:
053: static {
054: try {
055: if (ConfigurationLoader
056: .isConfigurationAvailable(PlatformConfiguration.class)) {
057: provider = ConfigurationLoader
058: .getExtensionClass(((PlatformConfiguration) ConfigurationLoader
059: .getConfiguration(PlatformConfiguration.class))
060: .getNativeProcessProvider());
061: }
062: } catch (Exception e) {
063: log.error("Failed to load native process provider", e);
064: provider = null;
065: }
066: }
067:
068: /**
069: *
070: *
071: * @return
072: *
073: * @throws IOException
074: */
075: public static NativeProcessProvider newInstance()
076: throws IOException {
077: try {
078: return (NativeProcessProvider) provider.newInstance();
079: } catch (Exception e) {
080: throw new IOException(
081: "The process provider failed to create a new instance: "
082: + e.getMessage());
083: }
084: }
085:
086: /**
087: *
088: *
089: * @param provider
090: */
091: public static void setProvider(Class provider) {
092: NativeProcessProvider.provider = provider;
093: }
094:
095: /**
096: *
097: *
098: * @return
099: *
100: * @throws IOException
101: */
102: public abstract InputStream getInputStream() throws IOException;
103:
104: /**
105: *
106: *
107: * @return
108: *
109: * @throws IOException
110: */
111: public abstract OutputStream getOutputStream() throws IOException;
112:
113: /**
114: *
115: *
116: * @return
117: */
118: public abstract InputStream getStderrInputStream()
119: throws IOException;
120:
121: /**
122: *
123: */
124: public abstract void kill();
125:
126: /**
127: *
128: *
129: * @return
130: */
131: public abstract boolean stillActive();
132:
133: /**
134: *
135: *
136: * @return
137: */
138: public abstract int waitForExitCode();
139:
140: /**
141: *
142: *
143: * @return
144: */
145: public abstract String getDefaultTerminalProvider();
146:
147: /**
148: *
149: *
150: * @param command
151: * @param environment
152: *
153: * @return
154: *
155: * @throws IOException
156: */
157: public abstract boolean createProcess(String command,
158: Map environment) throws IOException;
159:
160: /**
161: *
162: *
163: * @throws IOException
164: */
165: public abstract void start() throws IOException;
166:
167: /**
168: *
169: *
170: * @param term
171: *
172: * @return
173: */
174: public abstract boolean supportsPseudoTerminal(String term);
175:
176: /**
177: *
178: *
179: * @param term
180: * @param cols
181: * @param rows
182: * @param width
183: * @param height
184: * @param modes
185: *
186: * @return
187: */
188: public abstract boolean allocatePseudoTerminal(String term,
189: int cols, int rows, int width, int height, String modes);
190: }
|