My favorites | Sign in
Logo
                
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
/**
* BlueCove - Java library for Bluetooth
* Copyright (C) 2006-2007 Vlad Skarzhevskyy
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
* @author vlads
* @version $Id$
*/
package net.sf.bluecove;

import java.util.Enumeration;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;

import net.sf.bluecove.util.StorageRMS;

import org.bluecove.tester.log.Logger;
import org.bluecove.tester.me.LoggerCanvas;
import org.bluecove.tester.util.ThreadUtils;
import org.bluecove.tester.util.TimeUtils;

public class BlueCoveTestCanvas extends LoggerCanvas implements CommandListener {

static final Command exitCommand = new Command("Exit", Command.EXIT, 0);

static final Command printStatsCommand = new Command("1-Print Stats", Command.ITEM, 1);

static final Command startDiscoveryCommand = new Command("*-Discovery", Command.ITEM, 2);

static final Command startServicesSearchCommand = new Command("7-Services Search", Command.ITEM, 2);

static final Command startClientCommand = new Command("2-Client Start", Command.ITEM, 2);

static final Command stopClientCommand = new Command("3-Client Stop", Command.ITEM, 3);

static final Command startServerCommand = new Command("5-Server Start", Command.ITEM, 4);

static final Command stopServerCommand = new Command("6-Server Stop", Command.ITEM, 5);

static final Command startSwitcherCommand = new Command("8-Switcher Start", Command.ITEM, 6);

static final Command stopSwitcherCommand = new Command("9-Switcher Stop", Command.ITEM, 7);

static final Command clearCommand = new Command("#-Clear", Command.ITEM, 8);

static final Command printFailureLogCommand = new Command("4-Print FailureLog", Command.ITEM, 8);

static final Command startClientStressCommand = new Command("Client Stress Start", Command.ITEM, 9);

static final Command startClientLastServiceCommand = new Command("Client Last service Start", Command.ITEM, 10);

static final Command startClientLastDeviceCommand = new Command("Client Last device Start", Command.ITEM, 11);

static final Command startTCKAgentCommand = new Command("TCK Agent", Command.ITEM, 12);

static final Command configurationCommand = new Command("Options...", Command.ITEM, 13);

static final Command obexPutCommand = new Command("ObexPut", Command.ITEM, 14);

private Switcher switcher;

private int errorCount = 0;

public BlueCoveTestCanvas() {
super();
super.setTitle("BlueCoveT");

addCommand(exitCommand);
addCommand(startDiscoveryCommand);
addCommand(startServicesSearchCommand);
addCommand(startClientCommand);
addCommand(stopClientCommand);
addCommand(startServerCommand);
addCommand(stopServerCommand);
addCommand(printStatsCommand);
addCommand(startSwitcherCommand);
addCommand(stopSwitcherCommand);
addCommand(printFailureLogCommand);
addCommand(clearCommand);
addCommand(startClientStressCommand);
addCommand(startClientLastServiceCommand);
addCommand(startClientLastDeviceCommand);
if (Configuration.likedTCKAgent) {
addCommand(startTCKAgentCommand);
}
addCommand(configurationCommand);
if (TestOBEXCilent.obexEnabled) {
addCommand(obexPutCommand);
}
setCommandListener(this);

Configuration.storage = new StorageRMS();
}

protected String getCanvasTitleText() {
return "BlueCove Tester";
}

protected String getCanvasStatusText() {
StringBuffer msg = new StringBuffer();
msg.append("(");
msg.append("srv:").append((Switcher.isRunningServer()) ? "ON" : "off").append(" ").append(
Switcher.serverStartCount);
msg.append(" cli:").append((Switcher.isRunningClient()) ? "ON" : "off").append(" ").append(
Switcher.clientStartCount);
msg.append(" X:").append((Switcher.isRunning()) ? "ON" : "off");
msg.append(" dc:").append(TestResponderClient.discoveryCount);
msg.append(" er:").append(errorCount);
msg.append(")");
return msg.toString();
}

protected void keyPressed(int keyCode) {
switch (keyCode) {
case '1':
printStats();
break;
case '4':
printFailureLog();
break;
case '0':
logScrollBottom();
break;
case '*':
Switcher.startDiscovery();
break;
case '7':
Switcher.startServicesSearch();
break;
case '2':
Switcher.startClient();
break;
case '3':
Switcher.clientShutdown();
break;
case '5':
Switcher.startServer();
break;
case '6':
Switcher.serverShutdown();
break;
case '8':
startSwitcher();
break;
case '9':
stopSwitcher();
break;
case '#':
clear();
break;
default:
logLinesMove(getGameAction(keyCode));
}
repaint();
}

protected void keyRepeated(int keyCode) {
logLinesMove(getGameAction(keyCode));
}

private void stopSwitcher() {
if (switcher != null) {
switcher.shutdown();
switcher = null;
}
}

private void printStats() {
Logger.info("--- discovery stats ---");
int deviceCnt = 0;
int deviceActiveCnt = 0;
long activeDeadline = System.currentTimeMillis() - 1000 * 60 * 4;
for (Enumeration iter = RemoteDeviceInfo.devices.elements(); iter.hasMoreElements();) {
RemoteDeviceInfo dev = (RemoteDeviceInfo) iter.nextElement();
deviceCnt++;
StringBuffer buf = new StringBuffer();
buf.append(TestResponderClient.niceDeviceName(dev.remoteDevice.getBluetoothAddress()));
buf.append(" dc:").append(dev.serviceDiscovered.count);
buf.append(" first:"); TimeUtils.appendTime(buf, dev.serviceDiscoveredFirstTime, false);
buf.append(" last:"); TimeUtils.appendTime(buf, dev.serviceDiscoveredLastTime, false);
Logger.info(buf.toString());
buf = new StringBuffer();
buf.append(" avg ddf:").append(dev.avgDiscoveryFrequencySec());
buf.append(" sdf:").append(dev.avgServiceDiscoveryFrequencySec());
buf.append(" ss:").append(dev.avgServiceSearchDurationSec());
buf.append(" sss:").append(dev.serviceSearchSuccessPrc()).append("%");
if (dev.serviceDiscoveredLastTime > activeDeadline) {
deviceActiveCnt++;
buf.append(" Active");
} else {
buf.append(" Down");
}
if (dev.variableData == 0) {
buf.append(" No VarAttr");
} else {
buf.append(" srv:").append(dev.variableData);
if (dev.variableDataUpdated) {
buf.append(" var.OK");
}
}
Logger.info(buf.toString());
}
StringBuffer buf = new StringBuffer();
buf.append("all avg");
buf.append(" srv:").append(TestResponderServer.avgServerDurationSec());
buf.append(" di:").append(RemoteDeviceInfo.allAvgDeviceInquiryDurationSec());
buf.append(" ss:").append(RemoteDeviceInfo.allAvgServiceSearchDurationSec());
Logger.info(buf.toString());

buf = new StringBuffer();
buf.append("all max");
buf.append(" srv:").append(TestResponderServer.allServerDuration.durationMaxSec());
buf.append(" di:").append(RemoteDeviceInfo.deviceInquiryDuration.durationMaxSec());
buf.append(" ss:").append(RemoteDeviceInfo.allServiceSearch.durationMaxSec());
Logger.info(buf.toString());

buf = new StringBuffer();
buf.append("devices:").append(deviceCnt).append(" active:").append(deviceActiveCnt);
buf.append(" threads:").append(Thread.activeCount());
Logger.info(buf.toString());
Logger.info("-----------------------");
Logger.info("*Client Success:" + TestResponderClient.countSuccess + " Failure:"
+ TestResponderClient.failure.countFailure);
Logger.info("*Server Success:" + TestResponderServer.countSuccess + " Failure:"
+ TestResponderServer.failure.countFailure);
logScrollBottom();
}

private void printFailureLog() {
Logger.info("*Client Success:" + TestResponderClient.countSuccess + " Failure:"
+ TestResponderClient.failure.countFailure);
Logger.debug("Client avg conn concurrent " + TestResponderClient.concurrentStatistic.avg());
Logger.debug("Client max conn concurrent " + TestResponderClient.concurrentStatistic.max());
Logger.debug("Client avg conn time " + TestResponderClient.connectionDuration.avg() + " msec");
Logger.debug("Client avg conn retry " + TestResponderClient.connectionRetyStatistic.avgPrc());

TestResponderClient.failure.writeToLog();
Logger.info("*Server Success:" + TestResponderServer.countSuccess + " Failure:"
+ TestResponderServer.failure.countFailure);
Logger.debug("Server avg conn concurrent " + TestResponderServer.concurrentStatistic.avg());
Logger.debug("Server avg conn time " + TestResponderServer.connectionDuration.avg() + " msec");

TestResponderServer.failure.writeToLog();
logScrollBottom();
}

private void clear() {
clearLog();
TestResponderClient.clear();
TestResponderServer.clear();
Switcher.clear();
RemoteDeviceInfo.clear();
repaint();
Logger.runGarbageCollector();
}

private void startSwitcher() {
if (switcher == null) {
switcher = new Switcher();
}
if (!switcher.isRunning) {
(switcher.thread = new Thread(switcher)).start();
} else {
BlueCoveTestMIDlet.message("Warn", "Switcher isRunning");
}
}

public void commandAction(final Command c, Displayable d) {
Runnable r = new Runnable() {
public void run() {
if (c == exitCommand) {
Switcher.clientShutdown();
Switcher.serverShutdownOnExit();
BlueCoveTestMIDlet.exit();
return;
} else if (c == printStatsCommand) {
printStats();
} else if (c == printFailureLogCommand) {
printFailureLog();
} else if (c == clearCommand) {
clear();
} else if (c == startDiscoveryCommand) {
Switcher.startDiscovery();
} else if (c == startServicesSearchCommand) {
Switcher.startServicesSearch();
} else if (c == startClientCommand) {
Switcher.startClient();
} else if (c == startClientStressCommand) {
Switcher.startClientStress();
} else if (c == startClientLastServiceCommand) {
Switcher.startClientLastURl();
} else if (c == startClientLastDeviceCommand) {
Switcher.startClientLastDevice();
} else if (c == stopClientCommand) {
Switcher.clientShutdown();
} else if (c == stopServerCommand) {
Switcher.serverShutdown();
} else if (c == startServerCommand) {
Switcher.startServer();
} else if (c == startSwitcherCommand) {
startSwitcher();
} else if (c == stopSwitcherCommand) {
stopSwitcher();
} else if (c == configurationCommand) {
try {
BlueCoveTestMIDlet.setCurrentDisplayable(new BlueCoveTestConfigurationForm());
} catch (Throwable e) {
Logger.error("Internal error", e);
}
} else if ((Configuration.likedTCKAgent) && (c == startTCKAgentCommand)) {
Switcher.startTCKAgent();
} else if ((TestOBEXCilent.obexEnabled) && (c == obexPutCommand)) {
TestOBEXCilent.obexPut();
} else {
if (c != null) {
Logger.info("Command " + c.getLabel() + " not found");
}
}
}
};
ThreadUtils.invokeLater(r, c.getLabel());
}

}
Show details Hide details

Change log

r2655 by skarzhevskyy on Dec 24, 2008   Diff
minimize memory usage
Go to: 
Project members, sign in to write a code review

Older revisions

r2652 by skarzhevskyy on Dec 23, 2008   Diff
log memory
r2607 by skarzhevskyy on Dec 17, 2008   Diff
OBEX tests in J2ME
r2471 by skarzhevskyy on Nov 30, 2008   Diff
Change license to Apache License,
Version 2.0, Update headers
All revisions of this file

File info

Size: 11575 bytes, 342 lines

File properties

svn:mime-type
text/plain
svn:eol-style
native
svn:keywords
Date Author Id Revision
Hosted by Google Code