0
|
1 |
// Session.java
|
|
2 |
//
|
|
3 |
// Copyright (c) Symbian Software Ltd 2003 - 2004. All rights reserved.
|
|
4 |
//
|
|
5 |
package com.symbian.tools.j2me.sei.emulator.session;
|
|
6 |
|
|
7 |
import java.util.*;
|
|
8 |
import java.io.*;
|
|
9 |
import java.net.*;
|
|
10 |
|
|
11 |
import com.symbian.tools.j2me.sei.emulator.commands.*;
|
|
12 |
import com.symbian.tools.j2me.sei.preferences.*;
|
|
13 |
import com.symbian.utils.*;
|
|
14 |
import com.symbian.io.*;
|
|
15 |
import com.symbian.vm.*;
|
|
16 |
|
|
17 |
/**
|
|
18 |
* <p>Title: </p>
|
|
19 |
* <p>Description: </p>
|
|
20 |
* <p>Copyright: Copyright (c) 2004</p>
|
|
21 |
* <p>Company: </p>
|
|
22 |
* @author not attributable
|
|
23 |
* @version 1.0
|
|
24 |
*/
|
|
25 |
|
|
26 |
public abstract class Session {
|
|
27 |
|
|
28 |
//
|
|
29 |
// Constants
|
|
30 |
//
|
|
31 |
|
|
32 |
/**
|
|
33 |
* Mapping of device names to Session classes
|
|
34 |
*/
|
|
35 |
private static final String SESSION_MAP_FILE = "device2session.properties";
|
|
36 |
|
|
37 |
/**
|
|
38 |
* Default session class to use, if the IDE did not specify device name.
|
|
39 |
*/
|
|
40 |
private static final String DEFAULT_SESSION = "default";
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
//
|
|
45 |
// Statics
|
|
46 |
//
|
|
47 |
|
|
48 |
/**
|
|
49 |
* Device 2 sessions
|
|
50 |
*/
|
|
51 |
private static final Properties sDevices2Sessions = new Properties();
|
|
52 |
|
|
53 |
|
|
54 |
//
|
|
55 |
// Members
|
|
56 |
//
|
|
57 |
|
|
58 |
/**
|
|
59 |
* Map of suite info -> VM Process
|
|
60 |
* This member might be needed for MVM technology where a suites can run
|
|
61 |
* isolated in a single VM.
|
|
62 |
*/
|
|
63 |
protected Map iSuiteInfo2Process = new HashMap();
|
|
64 |
|
|
65 |
/**
|
|
66 |
* Session name (mapped to device name)
|
|
67 |
*/
|
|
68 |
private String iName;
|
|
69 |
|
|
70 |
/**
|
|
71 |
* Session preferences
|
|
72 |
*/
|
|
73 |
protected SessionPreferences iPrefs;
|
|
74 |
|
|
75 |
|
|
76 |
|
|
77 |
//
|
|
78 |
// Life cycle
|
|
79 |
//
|
|
80 |
|
|
81 |
/**
|
|
82 |
* Static init
|
|
83 |
*
|
|
84 |
* Load mapping from device names to session implementation
|
|
85 |
* (done here to enable test/customized sessions)
|
|
86 |
*/
|
|
87 |
static
|
|
88 |
{
|
|
89 |
try
|
|
90 |
{
|
|
91 |
sDevices2Sessions.load(Session.class.getResourceAsStream(SESSION_MAP_FILE));
|
|
92 |
}
|
|
93 |
catch(Exception e){
|
|
94 |
Debug.printStackTrace(Session.class.getName(), e);
|
|
95 |
}
|
|
96 |
}
|
|
97 |
|
|
98 |
/**
|
|
99 |
* SessionImpl factory method
|
|
100 |
*
|
|
101 |
* @param aName Session name
|
|
102 |
* @return Session concrete SessionImpl
|
|
103 |
*/
|
|
104 |
public static final Session create(String aName) throws Exception{
|
|
105 |
Debug.println(Session.class.getName(), "SEI device: " + aName);
|
|
106 |
if(aName == null){
|
|
107 |
aName = sDevices2Sessions.getProperty(DEFAULT_SESSION);
|
|
108 |
}
|
|
109 |
final Session session = (Session)
|
|
110 |
Class.forName(sDevices2Sessions.getProperty(aName)).newInstance();
|
|
111 |
session.iName = aName;
|
|
112 |
return session;
|
|
113 |
}
|
|
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
|
118 |
//
|
|
119 |
// Operations
|
|
120 |
//
|
|
121 |
|
|
122 |
/**
|
|
123 |
* Maps KVM (possibly, handset) port number to local port.
|
|
124 |
*
|
|
125 |
* @param aVmPort the port to map.
|
|
126 |
* @return possibly different port number than can be used within this VM
|
|
127 |
*/
|
|
128 |
public int mapVmPort(int aVmPort) {
|
|
129 |
return aVmPort; // no mapping by default
|
|
130 |
}
|
|
131 |
|
|
132 |
/**
|
|
133 |
* Gets the session name (the name of the debug configuration)
|
|
134 |
* @return the session name.
|
|
135 |
*/
|
|
136 |
public String getName() {
|
|
137 |
return iName;
|
|
138 |
}
|
|
139 |
|
|
140 |
/**
|
|
141 |
* Initialize the session.
|
|
142 |
* The intialization code shouldnt be in the constructor to allow shutdown
|
|
143 |
* during initialization, coming from the user.
|
|
144 |
*
|
|
145 |
* @param aUserPrefs user preferences used for initializing the connection
|
|
146 |
*
|
|
147 |
* @throws Exception if some error occured
|
|
148 |
*/
|
|
149 |
public synchronized void initialize(UserPreferences aUserPrefs) throws Exception{
|
|
150 |
iPrefs = aUserPrefs.getKDPPreferences().getSessionPreferences(iName);
|
|
151 |
Debug.println(this, "SEI session: " + getClass());
|
|
152 |
Debug.println(this, "session prefs: " + iPrefs.toString());
|
|
153 |
}
|
|
154 |
|
|
155 |
|
|
156 |
|
|
157 |
/**
|
|
158 |
* Get a free port on the device
|
|
159 |
*
|
|
160 |
* @return int free port
|
|
161 |
*
|
|
162 |
* @throws Exception if some error occured
|
|
163 |
*/
|
1
|
164 |
//public abstract int getFreePort() throws Exception;
|
0
|
165 |
|
|
166 |
|
|
167 |
|
|
168 |
/**
|
|
169 |
* Start the MIDlet
|
|
170 |
*
|
|
171 |
* @param aMIDletInfo MIDlet to start
|
|
172 |
*
|
|
173 |
* @return VM process
|
|
174 |
*
|
|
175 |
* @throws Exception if some error occured
|
|
176 |
*/
|
|
177 |
public abstract VMProcess startMIDlet(VMLaunchArguments aVMLaunchArguments, boolean aDefered) throws Exception;
|
|
178 |
|
|
179 |
|
|
180 |
/**
|
|
181 |
* Start another MIDlet in the same suite VM which must be already running
|
|
182 |
*
|
|
183 |
* @param aMIDletInfo MIDlet info
|
|
184 |
*
|
|
185 |
* @throws Exception if some error occured
|
|
186 |
*/
|
|
187 |
public abstract void startMIDlet(MIDletInfo aMIDletInfo) throws Exception;
|
|
188 |
|
|
189 |
|
|
190 |
/**
|
|
191 |
* Install the MIDlet suite
|
|
192 |
*
|
|
193 |
* @param aJar MIDlet suite Jar file
|
|
194 |
* @param aJad MIDlet suite Jad file
|
|
195 |
* @param aTrusted trust mode indicator
|
|
196 |
*
|
|
197 |
* @return MIDletSuiteInfo MIDlet suite information
|
|
198 |
*
|
|
199 |
* @throws Exception if some error occured
|
|
200 |
*/
|
|
201 |
public abstract MIDletSuiteInfo installMIDletSuite
|
|
202 |
(JARFile aJar, JADFile aJad, boolean aTrusted) throws Exception;
|
|
203 |
|
|
204 |
|
|
205 |
/**
|
|
206 |
* Remove the MIDlet suite
|
|
207 |
*
|
|
208 |
* @param aSuiteInfo removed MIDlet suite info
|
|
209 |
*
|
|
210 |
* @throws Exception if some error occured
|
|
211 |
*/
|
|
212 |
public abstract void removeMIDletSuite(MIDletSuiteInfo aSuiteInfo) throws Exception;
|
|
213 |
|
|
214 |
|
|
215 |
/**
|
|
216 |
* Remove all MIDlet suites
|
|
217 |
*
|
|
218 |
* @throws IOException if some error occured
|
|
219 |
*/
|
|
220 |
public synchronized void removeAll() throws Exception {
|
|
221 |
//un-install suites
|
|
222 |
//for each running VM
|
|
223 |
for (Iterator iter = iSuiteInfo2Process.keySet().iterator(); iter.hasNext(); )
|
|
224 |
{
|
|
225 |
removeMIDletSuite((MIDletSuiteInfo)iter.next());
|
|
226 |
}
|
|
227 |
}
|
|
228 |
|
|
229 |
/**
|
|
230 |
* Get the list of installed MIDlet suites
|
|
231 |
*
|
|
232 |
* @return list of installed MIDlet suites
|
|
233 |
*
|
|
234 |
* @throws Exception if some error occured
|
|
235 |
*/
|
1
|
236 |
//public abstract MIDletSuiteInfo[] getInstalledMIDletSuitesInfo() throws Exception;
|
0
|
237 |
|
|
238 |
|
|
239 |
/**
|
|
240 |
* Get the MIDlet VM process
|
|
241 |
*
|
|
242 |
* @param aMIDletInfo MIDlet info
|
|
243 |
*
|
|
244 |
* @return MIDlet VM process
|
|
245 |
*/
|
|
246 |
public synchronized VMProcess getProcess(MIDletInfo aMIDletInfo){
|
|
247 |
return (VMProcess)iSuiteInfo2Process.get(aMIDletInfo.getMIDletSuiteInfo());
|
|
248 |
}
|
|
249 |
|
|
250 |
/**
|
|
251 |
* Brute force terminate the sessions
|
|
252 |
*/
|
|
253 |
public abstract void terminate();
|
|
254 |
|
|
255 |
/**
|
|
256 |
* Get SEI-Slave TCP Inet address
|
|
257 |
*
|
|
258 |
* @return SEI-Slave TCP Inet address
|
|
259 |
*
|
|
260 |
* @exception UnknownHostException if failed to resolve the host name
|
|
261 |
*/
|
|
262 |
public abstract InetAddress getSlaveInetAddress() throws UnknownHostException;
|
|
263 |
|
|
264 |
}
|
|
265 |
|
|
266 |
|
|
267 |
|
|
268 |
|
|
269 |
|
|
270 |
|
|
271 |
|
|
272 |
|
|
273 |
|