aboutsummaryrefslogtreecommitdiffstats
blob: ac9e3841b9a01b38bde00d56d94b930e668fd3a9 (plain)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/********************************************************************************
 * 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:
 * Otavio Ferranti - Eldorado Research Institute - Bug 255255 [tml][proctools] Add extension points 
 ********************************************************************************/

package org.eclipse.tml.linuxtools.tools.memorymap;

import java.io.IOException;
import java.util.List;

import org.eclipse.tml.linuxtools.network.IConnectionProvider;
import org.eclipse.tml.linuxtools.network.IConstants.EventCode;
import org.eclipse.tml.linuxtools.network.IConstants.OperationCode;
import org.eclipse.tml.linuxtools.tools.AbstractNotifier;
import org.eclipse.tml.linuxtools.tools.IListener;
import org.eclipse.tml.linuxtools.tools.INotifier;
import org.eclipse.tml.linuxtools.tools.ITool;
import org.eclipse.tml.linuxtools.utilities.Extensions;
import org.eclipse.tml.linuxtools.utilities.ProtocolDescriptor;

/**
 * @author Otavio Ferranti
 */
public class MemoryMapTool extends AbstractNotifier implements IListener, ITool {

	private IConnectionProvider connectionProvider = null;
	private MemoryMapProcessor processor = null;

	private String[] requiredCapabilities = {"GET_FILE"}; //$NON-NLS-1$
	
	/* (non-Javadoc)
	 * @see org.eclipse.tml.linuxtools.tools.memorymap.iTool#createInstance(java.lang.String, int, java.lang.String)
	 */
	public void connect (String host,
								int port,
								ProtocolDescriptor protocol) {
	
		Class<IConnectionProvider> connectionProviderClass =
			protocol.getConnectionProviderClass();

		try {
			Object aux = connectionProviderClass.newInstance();
			connectionProvider = (IConnectionProvider) aux;
		} catch (InstantiationException ie) {
		} catch (IllegalAccessException iae) {
		} catch (ClassCastException cce) {
		}
	
		connectionProvider.addListener(this);
		try {
			connectionProvider.connect(host, port);
		} catch (IOException ie) { }
		processor = new MemoryMapProcessor(connectionProvider);

		processor.addListener(this);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.tml.linuxtools.tools.ITool#closeConnection()
	 */
	public void disconnect() {
		if (null != connectionProvider) {
			try {
				connectionProvider.disconnect();
			} catch (IOException ie) {
			}
			connectionProvider = null;
		}
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.tml.linuxtools.tools.memorymap.iTool#login(java.lang.String, java.lang.String)
	 */
	public void login (String user, String password) {
		try {
			connectionProvider.login(user, password);
		} catch (IOException ie) {
			//TODO: Nothing ?
		}
	}
	
	public List<ProtocolDescriptor> getProtocolsDescriptors() {
		List <ProtocolDescriptor> pdList = Extensions.findProcotols(requiredCapabilities);
		return pdList;
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.tml.linuxtools.tools.IListener#notify(org.eclipse.tml.linuxtools.tools.INotifier, org.eclipse.tml.linuxtools.network.IConstants.EventCode, java.lang.Object)
	 */
	public void notify(INotifier notifier, EventCode event, Object result) {
		try {
			if (notifier == connectionProvider) {
				switch (event) {
					case EVT_PROVIDER_CONNECT_FINISHED:
						if (OperationCode.SUCCESS == result) {
							processor.gatherData();
						}
						this.notifyListeners(
								EventCode.EVT_TOOL_CONNECT_FINISHED,
								result);
					break;
					case EVT_PROVIDER_CONNECT_ERROR:
					break;
					case EVT_PROVIDER_LOGIN_FINISHED:
						if (OperationCode.SUCCESS == result) {
							processor.gatherData();
						}
						this.notifyListeners(
								EventCode.EVT_TOOL_LOGIN_FINISHED,
								result);
					break;
					case EVT_PROVIDER_SENDCOMMAND_FINISHED:
					break;
					case EVT_PROVIDER_SENDCOMMAND_ERROR:
					break;
					case EVT_PROVIDER_SENDDATA_FINISHED:
					break;
					case EVT_PROVIDER_SENDDATA_ERROR:
					break;
					case EVT_PROVIDER_DISCONNECT_FINISHED:
						this.notifyListeners(
								EventCode.EVT_TOOL_DISCONNECT_FINISHED,
								result);
					break;	
				}
			}
			if (notifier == processor) {
				switch (event) {
					case EVT_PROCESSOR_GATHERDATA_FINISHED:
						notifyListeners(EventCode.EVT_TOOL_REFRESH_VIEW,
										result);
					break;
					case EVT_PROCESSOR_GATHERDATA_ERROR:
					break;
				}
			}
		} catch (IOException ie) {
		}
	}

	/**
	 * 
	 */
	public void refresh() {
		try {
			if (null != processor) {
				processor.gatherData();
			}
		} catch (IOException ie) {
			//TODO: Nothing ?
		}
	}

	/* (non-Javadoc)
	 * @see org.eclipse.tml.linuxtools.tools.ITool#getRefreshDelay()
	 */
	public int getRefreshDelay() {
		// TODO Auto-generated method stub
		return 0;
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.tml.linuxtools.tools.ITool#setRefreshDelay(int)
	 */
	public void setRefreshDelay(int delay) {
		// TODO Auto-generated method stub
	}

	public void start() {
		// TODO Auto-generated method stub
	}

	public void stop() {
		// TODO Auto-generated method stub
	}
}