Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: dab2d5d776d6d60cb0ec2cabf8f1807b1dcde778 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/********************************************************************************
 * Copyright (c) 2008 Motorola Inc. All rights reserved.
 * This program and the accompanying materials are made available under the terms
 * of the Eclipse Public License v1.0 which accompanies this distribution, and is
 * available at http://www.eclipse.org/legal/epl-v10.html
 *
 * Initial Contributor:
 * Otavio Ferranti (Motorola)
 *
 * Contributors:
 * {Name} (company) - description of contribution.
 ********************************************************************************/

package org.eclipse.sequoyah.device.linuxtools.network.tcf;

import java.io.IOException;
import java.io.InputStream;

import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.rse.core.IRSECoreRegistry;
import org.eclipse.rse.core.IRSESystemType;
import org.eclipse.rse.core.RSECorePlugin;
import org.eclipse.rse.core.model.IHost;
import org.eclipse.rse.core.model.ISystemRegistry;
import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
import org.eclipse.rse.subsystems.files.core.model.RemoteFileUtility;
import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem;
import org.eclipse.sequoyah.device.linuxtools.network.IConstants.OperationCode;

public class TCFWrapper {

	private StringBuffer lastResponse = null;
	private IHost rseHost = null;
	
	public void connect(String host, int port) throws IOException {
		ISystemRegistry rseSystemRegistry = RSECorePlugin.getTheSystemRegistry();
		IRSECoreRegistry rseCoreRegistry = RSECorePlugin.getTheCoreRegistry();
		IRSESystemType tcfSystemType = rseCoreRegistry.getSystemTypeById("org.eclipse.tm.tcf.rse.systemType");
		try {
			rseHost = rseSystemRegistry.createHost(tcfSystemType, host, host, host);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void disconnect() throws IOException {
		// TODO Auto-generated method stub

	}

	public StringBuffer getLastResponde() {
		return lastResponse;
	}

	public OperationCode login(String user, String password) throws IOException {
		// TODO Auto-generated method stub
		return OperationCode.SUCCESS;
	}

	public String fetchFile(String path, String fileName) throws IOException {
		IRemoteFileSubSystem remoteFileSubSystem =
				RemoteFileUtility.getFileSubSystem(rseHost);
		InputStream inputStream = null;

		try {
			remoteFileSubSystem.connect(new NullProgressMonitor(), false);
			inputStream = remoteFileSubSystem.getInputStream(path, fileName,
					false, new NullProgressMonitor());
		} catch (SystemMessageException sme) {
			// TODO Auto-generated catch block
			sme.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		lastResponse = new StringBuffer();

		byte[] b = new byte[16];
		char[] c = new char[16];
		while (inputStream.read(b) >= 0) {
			for (int i = 0; i < b.length; i++) {
				c[i] = (char) b[i];
			}
			lastResponse.append(c);
		}
		return "OK"; 
	}

	public void sendData(String out) {
		// TODO Auto-generated method stub

	}

	public void setResponseLength(int maxLength) {
		// TODO Auto-generated method stub		
	}
}

Back to the top