зеркало из https://github.com/mozilla/pluotsorbet.git
Merge branch 'master' into batch-compiled-method-writes
This commit is contained in:
Коммит
22a15eaae6
|
@ -44,14 +44,15 @@ java/midp/javax/microedition/lcdui/MMHelperImpl.java
|
|||
java/midp/javax/wireless/messaging/MessageConnection.java
|
||||
java/midp/com/sun/amms/DirectSoundSource3D.java
|
||||
java/midp/com/sun/amms/GlobalMgrImpl.java
|
||||
java/midp/com/sun/jsr082/bluetooth/BCC.java
|
||||
java/midp/com/sun/jsr082/bluetooth/JavacallBluetoothStack.java
|
||||
java/midp/com/sun/jsr082/bluetooth/SDDB.java
|
||||
java/midp/com/sun/jsr082/bluetooth/ServiceDiscovererFactory.java
|
||||
java/midp/com/sun/jsr082/bluetooth/btl2cap/L2CAPNotifierImpl.java
|
||||
java/midp/com/sun/jsr082/bluetooth/btspp/BTSPPNotifierImpl.java
|
||||
java/jsr-082/com/sun/jsr082/bluetooth/BCC.java
|
||||
java/jsr-082/com/sun/jsr082/bluetooth/JavacallBluetoothStack.java
|
||||
java/jsr-082/com/sun/jsr082/bluetooth/SDDB.java
|
||||
java/jsr-082/com/sun/jsr082/bluetooth/ServiceDiscovererFactory.java
|
||||
java/jsr-082/com/sun/jsr082/bluetooth/btl2cap/L2CAPNotifierImpl.java
|
||||
java/jsr-082/com/sun/jsr082/bluetooth/btspp/BTSPPNotifierImpl.java
|
||||
java/custom/javax/microedition/lcdui/Display.java
|
||||
|
||||
# These files are generated by java_cup
|
||||
tools/jasmin-2.4/src/jasmin/parser.java
|
||||
tools/jasmin-2.4/src/jasmin/sym.java
|
||||
tools/closure.jar
|
||||
|
|
|
@ -22,3 +22,5 @@ cache:
|
|||
directories:
|
||||
- node_modules
|
||||
- /tmp/j2me.js
|
||||
notifications:
|
||||
irc: "irc.mozilla.org#j2mejs"
|
||||
|
|
18
Makefile
18
Makefile
|
@ -6,11 +6,19 @@ RELEASE ?= 0
|
|||
VERSION ?=$(shell date +%s)
|
||||
PROFILE ?= 0
|
||||
|
||||
# Sensor support
|
||||
JSR_256 ?= 1
|
||||
export JSR_256
|
||||
|
||||
# Bluetooth support
|
||||
JSR_082 ?= 1
|
||||
export JSR_082
|
||||
|
||||
# Create a checksum file to monitor the changes of the Makefile configuration.
|
||||
# If the configuration has changed, we update the checksum file to let the files
|
||||
# which depend on it to regenerate.
|
||||
|
||||
CHECKSUM := "$(RELEASE)$(PROFILE)"
|
||||
CHECKSUM := "$(RELEASE)$(PROFILE)$(JSR_256)"
|
||||
OLD_CHECKSUM := "$(shell [ -f .checksum ] && cat .checksum)"
|
||||
$(shell [ $(CHECKSUM) != $(OLD_CHECKSUM) ] && echo $(CHECKSUM) > .checksum)
|
||||
|
||||
|
@ -18,6 +26,7 @@ toBool = $(if $(findstring 1,$(1)),true,false)
|
|||
PREPROCESS = python tools/preprocess-1.1.0/lib/preprocess.py -s \
|
||||
-D RELEASE=$(call toBool,$(RELEASE)) \
|
||||
-D PROFILE=$(call toBool,$(PROFILE)) \
|
||||
-D JSR_256=$(JSR_256) \
|
||||
-D VERSION=$(VERSION)
|
||||
PREPROCESS_SRCS = $(shell find . -name "*.in" -not -path config/build.js.in)
|
||||
PREPROCESS_DESTS = $(PREPROCESS_SRCS:.in=)
|
||||
|
@ -61,8 +70,11 @@ build/tests.jar.js: tests/tests.jar build/jsc.js aot-methods.txt
|
|||
build/program.jar.js: program.jar build/jsc.js aot-methods.txt
|
||||
js build/jsc.js -cp java/classes.jar program.jar -d -jf program.jar -mff aot-methods.txt > build/program.jar.js
|
||||
|
||||
closure: build/classes.jar.js build/j2me.js
|
||||
java -jar tools/closure.jar --language_in ECMASCRIPT5 -O SHUMWAY_OPTIMIZATIONS build/j2me.js > build/j2me.cc.js \
|
||||
tools/closure.jar:
|
||||
wget -O $@ https://github.com/mykmelez/closure-compiler/releases/download/v0.1/closure.jar
|
||||
|
||||
closure: build/classes.jar.js build/j2me.js tools/closure.jar
|
||||
java -jar tools/closure.jar --language_in ECMASCRIPT5 -O J2ME_OPTIMIZATIONS build/j2me.js > build/j2me.cc.js \
|
||||
&& mv build/j2me.cc.js build/j2me.js
|
||||
java -jar tools/closure.jar --language_in ECMASCRIPT5 -O SIMPLE build/classes.jar.js > build/classes.jar.cc.js \
|
||||
&& mv build/classes.jar.cc.js build/classes.jar.js
|
||||
|
|
10
README.md
10
README.md
|
@ -1,4 +1,4 @@
|
|||
# j2me.js [![Build Status](https://travis-ci.org/andreasgal/j2me.js.svg)](https://travis-ci.org/andreasgal/j2me.js)
|
||||
# j2me.js [![Build Status](https://travis-ci.org/mozilla/j2me.js.svg)](https://travis-ci.org/mozilla/j2me.js)
|
||||
|
||||
j2me.js is a J2ME virtual machine in JavaScript.
|
||||
|
||||
|
@ -11,9 +11,9 @@ The current goals of j2me.js are:
|
|||
|
||||
Make sure you have a [JRE](http://www.oracle.com/technetwork/java/javase/downloads/jre7-downloads-1880261.html) installed
|
||||
|
||||
Get the [j2me.js repo](https://github.com/andreasgal/j2me.js) if you don't have it already
|
||||
Get the [j2me.js repo](https://github.com/mozilla/j2me.js) if you don't have it already
|
||||
|
||||
git clone https://github.com/andreasgal/j2me.js
|
||||
git clone https://github.com/mozilla/j2me.js
|
||||
|
||||
Build using make:
|
||||
|
||||
|
@ -205,8 +205,8 @@ To use it, first install a recent version of the
|
|||
|
||||
`make closure` compiles some JavaScript code with the Closure compiler.
|
||||
|
||||
To use it, first download Shumway's version of the compiler to tools/closure.jar:
|
||||
To use it, first download this custom version of the compiler to tools/closure.jar:
|
||||
|
||||
```
|
||||
wget https://github.com/mozilla/shumway/raw/master/utils/closure.jar -P tools/
|
||||
wget https://github.com/mykmelez/closure-compiler/releases/download/v0.1/closure.jar -P tools/
|
||||
```
|
||||
|
|
103
bindings.ts
103
bindings.ts
|
@ -33,6 +33,37 @@ module J2ME {
|
|||
}
|
||||
}
|
||||
},
|
||||
"com/sun/javame/sensor/ChannelModel": {
|
||||
fields: {
|
||||
instanceSymbols: {
|
||||
"scale.I": "scale",
|
||||
"name.Ljava/lang/String;": "name",
|
||||
"unit.Ljava/lang/String;": "unit",
|
||||
"dataType.I": "dataType",
|
||||
"accuracy.I": "accuracy",
|
||||
"mrangeCount.I": "mrangeCount",
|
||||
"mrageArray.[J": "mrageArray"
|
||||
}
|
||||
}
|
||||
},
|
||||
"com/sun/javame/sensor/SensorModel": {
|
||||
fields: {
|
||||
instanceSymbols: {
|
||||
"description.Ljava/lang/String;": "description",
|
||||
"model.Ljava/lang/String;": "model",
|
||||
"quantity.Ljava/lang/String;": "quantity",
|
||||
"contextType.Ljava/lang/String;": "contextType",
|
||||
"connectionType.I": "connectionType",
|
||||
"maxBufferSize.I": "maxBufferSize",
|
||||
"availabilityPush.Z": "availabilityPush",
|
||||
"conditionPush.Z": "conditionPush",
|
||||
"channelCount.I": "channelCount",
|
||||
"errorCodes.[I": "errorCodes",
|
||||
"errorMsgs.[Ljava/lang/String;": "errorMsgs",
|
||||
"properties.[Ljava/lang/String;": "properties"
|
||||
}
|
||||
}
|
||||
},
|
||||
"com/nokia/mid/ui/DirectGraphicsImp": {
|
||||
fields: {
|
||||
instanceSymbols: {
|
||||
|
@ -56,6 +87,43 @@ module J2ME {
|
|||
"height.I": "height"
|
||||
}
|
||||
}
|
||||
},
|
||||
"com/sun/midp/events/Event": {
|
||||
fields: {
|
||||
instanceSymbols: {
|
||||
"type.I": "type",
|
||||
"next.Lcom/sun/midp/events/Event;": "next",
|
||||
}
|
||||
}
|
||||
},
|
||||
"com/sun/midp/events/NativeEvent": {
|
||||
fields: {
|
||||
instanceSymbols: {
|
||||
"intParam1.I": "intParam1",
|
||||
"intParam2.I": "intParam2",
|
||||
"intParam3.I": "intParam3",
|
||||
"intParam4.I": "intParam4",
|
||||
"intParam5.I": "intParam5",
|
||||
"intParam6.I": "intParam6",
|
||||
"intParam7.I": "intParam7",
|
||||
"intParam8.I": "intParam8",
|
||||
"intParam9.I": "intParam9",
|
||||
"intParam10.I": "intParam10",
|
||||
"intParam11.I": "intParam11",
|
||||
"intParam12.I": "intParam12",
|
||||
"intParam13.I": "intParam13",
|
||||
"intParam14.I": "intParam14",
|
||||
"intParam15.I": "intParam15",
|
||||
"intParam16.I": "intParam16",
|
||||
"floatParam1.F": "floatParam1",
|
||||
"stringParam1.Ljava/lang/String;": "stringParam1",
|
||||
"stringParam2.Ljava/lang/String;": "stringParam2",
|
||||
"stringParam3.Ljava/lang/String;": "stringParam3",
|
||||
"stringParam4.Ljava/lang/String;": "stringParam4",
|
||||
"stringParam5.Ljava/lang/String;": "stringParam5",
|
||||
"stringParam6.Ljava/lang/String;": "stringParam6",
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -76,8 +144,6 @@ module J2ME {
|
|||
*/
|
||||
_lock: Lock;
|
||||
|
||||
waiting: Context [];
|
||||
|
||||
clone(): java.lang.Object;
|
||||
equals(obj: java.lang.Object): boolean;
|
||||
finalize(): void;
|
||||
|
@ -228,5 +294,38 @@ module J2ME {
|
|||
graphics: javax.microedition.lcdui.Graphics;
|
||||
}
|
||||
}
|
||||
|
||||
export module com.sun.midp.events {
|
||||
export interface Event {
|
||||
type: number;
|
||||
next: com.sun.midp.events.Event;
|
||||
}
|
||||
|
||||
export interface NativeEvent extends com.sun.midp.events.Event {
|
||||
intParam1: number;
|
||||
intParam2: number;
|
||||
intParam3: number;
|
||||
intParam4: number;
|
||||
intParam5: number;
|
||||
intParam6: number;
|
||||
intParam7: number;
|
||||
intParam8: number;
|
||||
intParam9: number;
|
||||
intParam10: number;
|
||||
intParam11: number;
|
||||
intParam12: number;
|
||||
intParam13: number;
|
||||
intParam14: number;
|
||||
intParam15: number;
|
||||
intParam16: number;
|
||||
floatParam1: number;
|
||||
stringParam1: java.lang.String;
|
||||
stringParam2: java.lang.String;
|
||||
stringParam3: java.lang.String;
|
||||
stringParam4: java.lang.String;
|
||||
stringParam5: java.lang.String;
|
||||
stringParam6: java.lang.String;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
56
context.ts
56
context.ts
|
@ -21,8 +21,9 @@ module J2ME {
|
|||
Load = 0x10,
|
||||
JIT = 0x20,
|
||||
Code = 0x40,
|
||||
Thread = 0x80,
|
||||
|
||||
All = Trace | Link | Init | Perf | Load | JIT | Code
|
||||
All = Trace | Link | Init | Perf | Load | JIT | Code | Thread
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -381,6 +382,7 @@ module J2ME {
|
|||
jitWriter = writers & WriterFlags.JIT ? writer : null;
|
||||
codeWriter = writers & WriterFlags.Code ? writer : null;
|
||||
initWriter = writers & WriterFlags.Init ? writer : null;
|
||||
threadWriter = writers & WriterFlags.Thread ? writer : null;
|
||||
loadWriter = writers & WriterFlags.Load ? writer : null;
|
||||
}
|
||||
|
||||
|
@ -551,7 +553,6 @@ module J2ME {
|
|||
}
|
||||
|
||||
execute() {
|
||||
var start = performance.now();
|
||||
this.setAsCurrentContext();
|
||||
do {
|
||||
VM.execute();
|
||||
|
@ -561,23 +562,16 @@ module J2ME {
|
|||
this.bailoutFrames = [];
|
||||
}
|
||||
var frames = this.frames;
|
||||
if (windingWriter) {
|
||||
windingWriter.enter("Unwound");
|
||||
frames.map(function (f) {
|
||||
if (Frame.isMarker(f)) {
|
||||
windingWriter.writeLn("- marker -");
|
||||
} else {
|
||||
windingWriter.writeLn((f.methodInfo.state === MethodState.Compiled ? "C" : "I") + " " + f.toString());
|
||||
}
|
||||
});
|
||||
windingWriter.leave("");
|
||||
}
|
||||
switch (U) {
|
||||
case VMState.Yielding:
|
||||
this.resume();
|
||||
break;
|
||||
case VMState.Pausing:
|
||||
break;
|
||||
case VMState.Stopping:
|
||||
this.clearCurrentContext();
|
||||
this.kill();
|
||||
return;
|
||||
}
|
||||
U = VMState.Running;
|
||||
this.clearCurrentContext();
|
||||
|
@ -592,16 +586,14 @@ module J2ME {
|
|||
}
|
||||
|
||||
block(obj, queue, lockLevel) {
|
||||
if (!obj[queue])
|
||||
obj[queue] = [];
|
||||
obj[queue].push(this);
|
||||
obj._lock[queue].push(this);
|
||||
this.lockLevel = lockLevel;
|
||||
$.pause("block");
|
||||
}
|
||||
|
||||
unblock(obj, queue, notifyAll) {
|
||||
while (obj[queue] && obj[queue].length) {
|
||||
var ctx = obj[queue].pop();
|
||||
while (obj._lock[queue].length) {
|
||||
var ctx = obj._lock[queue].pop();
|
||||
if (!ctx)
|
||||
continue;
|
||||
ctx.wakeup(obj)
|
||||
|
@ -615,14 +607,12 @@ module J2ME {
|
|||
window.clearTimeout(this.lockTimeout);
|
||||
this.lockTimeout = null;
|
||||
}
|
||||
if (obj._lock) {
|
||||
if (!obj.ready)
|
||||
obj.ready = [];
|
||||
obj.ready.push(this);
|
||||
if (obj._lock.level !== 0) {
|
||||
obj._lock.ready.push(this);
|
||||
} else {
|
||||
while (this.lockLevel-- > 0) {
|
||||
this.monitorEnter(obj);
|
||||
if (U === VMState.Pausing) {
|
||||
if (U === VMState.Pausing || U === VMState.Stopping) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -632,6 +622,11 @@ module J2ME {
|
|||
|
||||
monitorEnter(object: java.lang.Object) {
|
||||
var lock = object._lock;
|
||||
if (lock && lock.level === 0) {
|
||||
lock.thread = this.thread;
|
||||
lock.level = 1;
|
||||
return;
|
||||
}
|
||||
if (!lock) {
|
||||
object._lock = new Lock(this.thread, 1);
|
||||
return;
|
||||
|
@ -645,12 +640,15 @@ module J2ME {
|
|||
|
||||
monitorExit(object: java.lang.Object) {
|
||||
var lock = object._lock;
|
||||
if (lock.level === 1 && lock.ready.length === 0) {
|
||||
lock.level = 0;
|
||||
return;
|
||||
}
|
||||
if (lock.thread !== this.thread)
|
||||
throw $.newIllegalMonitorStateException();
|
||||
if (--lock.level > 0) {
|
||||
return;
|
||||
}
|
||||
object._lock = null;
|
||||
this.unblock(object, "ready", false);
|
||||
}
|
||||
|
||||
|
@ -661,17 +659,19 @@ module J2ME {
|
|||
if (!lock || lock.thread !== this.thread)
|
||||
throw $.newIllegalMonitorStateException();
|
||||
var lockLevel = lock.level;
|
||||
while (lock.level > 0)
|
||||
for (var i = lockLevel; i > 0; i--) {
|
||||
this.monitorExit(object);
|
||||
}
|
||||
if (timeout) {
|
||||
var self = this;
|
||||
this.lockTimeout = window.setTimeout(function () {
|
||||
object.waiting.forEach(function (ctx, n) {
|
||||
for (var i = 0; i < lock.waiting.length; i++) {
|
||||
var ctx = lock.waiting[i];
|
||||
if (ctx === self) {
|
||||
object.waiting[n] = null;
|
||||
lock.waiting[i] = null;
|
||||
ctx.wakeup(object);
|
||||
}
|
||||
});
|
||||
}
|
||||
}, timeout);
|
||||
} else {
|
||||
this.lockTimeout = null;
|
||||
|
|
|
@ -83,12 +83,12 @@ module J2ME {
|
|||
function checkReturnValue(methodInfo: MethodInfo, returnValue: any) {
|
||||
if (U) {
|
||||
if (typeof returnValue !== "undefined") {
|
||||
assert(false, "Expected undefined return value during unwind, got " + returnValue);
|
||||
assert(false, "Expected undefined return value during unwind, got " + returnValue + " in " + methodInfo.implKey);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!(getKindCheck(methodInfo.getReturnKind())(returnValue))) {
|
||||
assert(false, "Expected " + Kind[methodInfo.getReturnKind()] + " return value, got " + returnValue);
|
||||
assert(false, "Expected " + Kind[methodInfo.getReturnKind()] + " return value, got " + returnValue + " in " + methodInfo.implKey);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -178,12 +178,13 @@ module J2ME {
|
|||
|
||||
if (ctx.current() === Frame.Start) {
|
||||
ctx.kill();
|
||||
if (ctx.thread && ctx.thread.waiting && ctx.thread.waiting.length > 0) {
|
||||
if (ctx.thread && ctx.thread._lock.waiting && ctx.thread._lock.waiting.length > 0) {
|
||||
console.error(buildExceptionLog(e, stackTrace));
|
||||
ctx.thread.waiting.forEach(function(waitingCtx, n) {
|
||||
ctx.thread.waiting[n] = null;
|
||||
for (var i = 0; i < ctx.thread._lock.waiting.length; i++) {
|
||||
var waitingCtx = ctx.thread._lock.waiting[i];
|
||||
ctx.thread._lock.waiting[i] = null;
|
||||
waitingCtx.wakeup(ctx.thread);
|
||||
});
|
||||
}
|
||||
}
|
||||
throw new Error(buildExceptionLog(e, stackTrace));
|
||||
} else {
|
||||
|
@ -1051,7 +1052,7 @@ module J2ME {
|
|||
case Bytecodes.MONITORENTER:
|
||||
object = stack.pop();
|
||||
ctx.monitorEnter(object);
|
||||
if (U === VMState.Pausing) {
|
||||
if (U === VMState.Pausing || U === VMState.Stopping) {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
@ -1196,7 +1197,7 @@ module J2ME {
|
|||
: frame.getLocal(0);
|
||||
}
|
||||
ctx.monitorEnter(calleeFrame.lockObject);
|
||||
if (U === VMState.Pausing) {
|
||||
if (U === VMState.Pausing || U === VMState.Stopping) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,21 @@
|
|||
SRCS=$(shell find ./cldc1.1.1 -name *.java) $(shell find ./vm -name *.java) $(shell find ./midp -name *.java) $(shell find ./jsr-075 -name *.java) $(shell find ./custom -name *.java)
|
||||
SRC_DIRS=cldc1.1.1/. vm/. midp/. jsr-075/. custom/.
|
||||
JPP_DEFS=-DENABLE_JSR_205 -DENABLE_SSL -DENABLE_PUBLICKEYSTORE -DENABLE_JSR_211 -DENABLE_MULTIPLE_ISOLATES -DRECORD -DUSE_FILE_CONNECTION -DENABLE_JSR_234
|
||||
JPP_SRCS=$(shell find . -name *.jpp)
|
||||
JPP_SRCS=$(shell find ./cldc1.1.1 -name *.jpp) $(shell find ./vm -name *.jpp) $(shell find ./midp -name *.jpp) $(shell find ./jsr-075 -name *.jpp) $(shell find ./custom -name *.jpp)
|
||||
|
||||
ifeq ($(JSR_256),1)
|
||||
SRCS += $(shell find ./jsr-256 -name *.java)
|
||||
SRC_DIRS += jsr-256/.
|
||||
JPP_DEFS += -DENABLE_JSR_256
|
||||
JPP_SRCS += $(shell find ./jsr-256 -name *.jpp)
|
||||
endif
|
||||
|
||||
ifeq ($(JSR_082),1)
|
||||
SRCS += $(shell find ./jsr-082 -name *.java)
|
||||
SRC_DIRS += jsr-082/.
|
||||
JPP_SRCS += $(shell find ./jsr-082 -name *.jpp)
|
||||
endif
|
||||
|
||||
JPP_DESTS=$(JPP_SRCS:.jpp=.java)
|
||||
EXTRA=$(shell find . -name *.png) $(shell find . -name *.bin) $(shell find . -name *.xml)
|
||||
|
||||
|
@ -9,8 +24,7 @@ VPATH=./cldc1.1.1 ./vm ./midp ./custom
|
|||
classes.jar: $(SRCS) $(JPP_DESTS)
|
||||
rm -rf build build-src
|
||||
mkdir build build-src
|
||||
cp -a cldc1.1.1/. vm/. midp/. jsr-075/. build-src/
|
||||
cp -a custom/. build-src/
|
||||
cp -a $(SRC_DIRS) build-src/
|
||||
javac -cp build-src -g:none -source 1.3 -target 1.3 -bootclasspath "" -extdirs "" -d ./build `find ./build-src -name *.java` > /dev/null
|
||||
cd build && jar cvf0 ../classes.jar *
|
||||
jar uvf0 classes.jar $(EXTRA)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.nokia.mid.ui.lcdui;
|
||||
|
||||
import javax.microedition.lcdui.Display;
|
||||
import javax.microedition.lcdui.Displayable;
|
||||
import com.nokia.mid.ui.lcdui.DisplayStateListener;
|
||||
|
||||
public class LCDUIUtils {
|
||||
|
@ -22,4 +23,8 @@ public class LCDUIUtils {
|
|||
static void setDisplayStateListener(Display display, DisplayStateListener listener) {
|
||||
System.out.println("LCDUIUtils::setDisplayStateListener(Dispay,DisplayStateListener) not implemented");
|
||||
}
|
||||
|
||||
static void setCurrent(Display display, Displayable displayable, String str) {
|
||||
System.out.println("LCDUIUtil::setCurrent no implemente.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
/*
|
||||
*
|
||||
*
|
||||
* Copyright 1990-2009 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
|
||||
*
|
||||
|
@ -24,21 +22,22 @@
|
|||
* information or have any questions.
|
||||
*/
|
||||
|
||||
package com.sun.midp.appmanager;
|
||||
package com.sun.javame.sensor;
|
||||
|
||||
import javax.microedition.sensor.SensorInfo;
|
||||
|
||||
/**
|
||||
* Consumes events from AMS Services.
|
||||
* Object which implements this interface is able to receive notifications on
|
||||
* each SensorInfo availability change.
|
||||
*/
|
||||
interface AMSServicesEventConsumer {
|
||||
interface AvailabilityListener {
|
||||
|
||||
/**
|
||||
* Processes RESTART_MIDLET_EVENT.
|
||||
* Notify listener that the SensorInfo state changed. Multiple notifications
|
||||
* with the same SensorInfo and availability value could be emitted.
|
||||
*
|
||||
* @param externalAppId application ID assigned by externall App Manager;
|
||||
* not used if there is no external manager
|
||||
* @param suiteId ID of the midlet suite
|
||||
* @param className class name of the midlet to restart
|
||||
* @param displayName display name of the midlet to restart
|
||||
* @param info SensorInfo which state changed
|
||||
* @param available new availability value
|
||||
*/
|
||||
public void handleRestartMIDletEvent(int externalAppId, int suiteId,
|
||||
String className, String displayName);
|
||||
void notifyAvailability(SensorInfo info, boolean available);
|
||||
}
|
|
@ -1,6 +1,4 @@
|
|||
/*
|
||||
*
|
||||
*
|
||||
* Copyright 1990-2009 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
|
||||
*
|
||||
|
@ -24,29 +22,25 @@
|
|||
* information or have any questions.
|
||||
*/
|
||||
|
||||
package com.sun.midp.appmanager;
|
||||
package com.sun.javame.sensor;
|
||||
|
||||
/**
|
||||
* This class is Selector that exits after launching the selected MIDlet.
|
||||
* Object which implements this interface notifies AvailabilityListener on each
|
||||
* SensorInfo availability change.
|
||||
*/
|
||||
public class Selector extends SelectorBase {
|
||||
interface AvailabilityNotifier {
|
||||
|
||||
/**
|
||||
* Destroys this Selector midlet and exits after scheduling
|
||||
* an execution of the next midlet in SVM, do nothing in MVM.
|
||||
* Inform notifier to start sending availability informations.
|
||||
*
|
||||
* @param listener which will receive the notifications
|
||||
*/
|
||||
protected void yieldToNextMidlet() {
|
||||
try {
|
||||
// Give the create MIDlet notification 1 second to get to AMS.
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException ie) {
|
||||
// ignore the exception
|
||||
}
|
||||
void startMonitoringAvailability(AvailabilityListener listener);
|
||||
|
||||
// exit
|
||||
destroyApp(false);
|
||||
notifyDestroyed();
|
||||
|
||||
return;
|
||||
}
|
||||
/**
|
||||
* Inform notifier to stop sending availability informations.
|
||||
*
|
||||
* @param listener which will receive the notifications
|
||||
*/
|
||||
void stopMonitoringAvailability(AvailabilityListener listener);
|
||||
}
|
||||
|
|
@ -0,0 +1,304 @@
|
|||
/*
|
||||
* Copyright 1990-2009 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version
|
||||
* 2 only, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License version 2 for more details (a copy is
|
||||
* included at /legal/license.txt).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* version 2 along with this work; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA
|
||||
*
|
||||
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
||||
* Clara, CA 95054 or visit www.sun.com if you need additional
|
||||
* information or have any questions.
|
||||
*/
|
||||
|
||||
package com.sun.javame.sensor;
|
||||
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Vector;
|
||||
|
||||
import javax.microedition.sensor.SensorInfo;
|
||||
import javax.microedition.sensor.SensorListener;
|
||||
|
||||
import com.sun.javame.sensor.helper.IdentityWrapper;
|
||||
|
||||
/**
|
||||
* This class is responsible for callbacks to SensorListener registered with
|
||||
* SensorInfo.
|
||||
*/
|
||||
class AvailabilityPoller implements AvailabilityListener {
|
||||
|
||||
/**
|
||||
* Holds Vector of SensorListener-s for each SensorInfo.
|
||||
* <i>@GuardedBy("infoListenerMap")</i>
|
||||
*/
|
||||
private final Hashtable infoListenerMap = new Hashtable();
|
||||
|
||||
/**
|
||||
* Stores the last SensorInfo availability state. The value updated during
|
||||
* each notification call.
|
||||
* <i>@GuardedBy("infoListenerMap")</i>
|
||||
*/
|
||||
private final Hashtable lastAvailable = new Hashtable();
|
||||
|
||||
/**
|
||||
* Stores the current SensorInfo availability state which is used if there
|
||||
* are more SensorListener-s for one SensorInfo. The value is also updated
|
||||
* by the {@link #notifyAvailability(SensorInfo, boolean)} called from
|
||||
* {@link AvailabilityNotifier}. The content is erased on each poller loop.
|
||||
* <i>@GuardedBy("infoListenerMap")</i>
|
||||
*/
|
||||
private final Hashtable cachedAvailability = new Hashtable();
|
||||
|
||||
/** Lock used to sleep in each poller loop. */
|
||||
private final Object sleepLock = new Object();
|
||||
|
||||
/**
|
||||
* The polling worker thread.
|
||||
* <i>@GuardedBy("infoListenerMap")</i>
|
||||
*/
|
||||
private PollerWorker pollingThread;
|
||||
|
||||
/** Executor used to fire SensorListener notifications. */
|
||||
private final GuardedExecutor executor = new GuardedExecutor();
|
||||
|
||||
/** Time in milliseconds the poller sleeps between runs. */
|
||||
private final int pollerSleep;
|
||||
|
||||
/**
|
||||
* Create availability poller with specific delay.
|
||||
*
|
||||
* @param pollerSleep time in milliseconds the poller will sleep between
|
||||
* runs
|
||||
*/
|
||||
AvailabilityPoller(int pollerSleep) {
|
||||
this.pollerSleep = pollerSleep;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set SensorInfo cached availability and notify the sleep lock.
|
||||
*/
|
||||
public void notifyAvailability(SensorInfo info, boolean available) {
|
||||
synchronized (infoListenerMap) {
|
||||
IdentityWrapper infoWrap = new IdentityWrapper(info);
|
||||
cachedAvailability.put(infoWrap, available ? Boolean.TRUE
|
||||
: Boolean.FALSE);
|
||||
}
|
||||
synchronized (sleepLock) {
|
||||
sleepLock.notify();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If not present add listener and call appropriate callback method. This
|
||||
* will also call {@link AvailabilityNotifier#startMonitoringAvailability()}
|
||||
* if the {@link SensorInfo} implements it and the first SensorListener is
|
||||
* registered.
|
||||
*
|
||||
* @param listener SensorListener which is registered
|
||||
* @param info SensorInfo which changes the listener listens to
|
||||
*/
|
||||
void addListener(SensorListener listener, SensorInfo info) {
|
||||
IdentityWrapper infoWrap = new IdentityWrapper(info);
|
||||
IdentityWrapper listenWrap = new IdentityWrapper(listener);
|
||||
synchronized (infoListenerMap) {
|
||||
// Get or create listeners container
|
||||
Vector listeners = (Vector) infoListenerMap.get(infoWrap);
|
||||
if (listeners == null) {
|
||||
listeners = new Vector();
|
||||
infoListenerMap.put(infoWrap, listeners);
|
||||
}
|
||||
if (listeners.size() == 0 && info instanceof AvailabilityNotifier) {
|
||||
// If the device supports notifications enable them
|
||||
((AvailabilityNotifier) info).startMonitoringAvailability(this);
|
||||
listeners.addElement(listenWrap);
|
||||
} else if (!listeners.contains(listenWrap)) {
|
||||
listeners.addElement(listenWrap);
|
||||
} else {
|
||||
listener = null;
|
||||
}
|
||||
// Must be in synchronized block because poller can call us
|
||||
// immediately and that will result in double call
|
||||
if (listener != null) {
|
||||
final Boolean available = info.isAvailable() ? Boolean.TRUE
|
||||
: Boolean.FALSE;
|
||||
lastAvailable.put(infoWrap, available);
|
||||
if (available.booleanValue()) {
|
||||
listener.sensorAvailable(info);
|
||||
} else {
|
||||
listener.sensorUnavailable(info);
|
||||
}
|
||||
ensureStarted();
|
||||
infoListenerMap.notify();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the SensorListener from every SensorInfo to which it is
|
||||
* registered. This will also call
|
||||
* {@link AvailabilityNotifier#stopMonitoringAvailability()}, if the
|
||||
* {@link SensorInfo} implements it and the last SensorListener is
|
||||
* unregistered.
|
||||
*
|
||||
* @param listener SensorListener which is unregistered
|
||||
*/
|
||||
void removeListener(SensorListener listener) {
|
||||
synchronized (infoListenerMap) {
|
||||
IdentityWrapper listenWrap = new IdentityWrapper(listener);
|
||||
Enumeration enumeration = infoListenerMap.keys();
|
||||
Vector infosToRemove = new Vector();
|
||||
while (enumeration.hasMoreElements()) {
|
||||
IdentityWrapper key = (IdentityWrapper) enumeration
|
||||
.nextElement();
|
||||
Vector listeners = (Vector) infoListenerMap.get(key);
|
||||
if (listeners.contains(listenWrap)) {
|
||||
listeners.removeElement(listenWrap);
|
||||
if (listeners.isEmpty()) {
|
||||
infosToRemove.addElement(key);
|
||||
SensorInfo info = (SensorInfo) key.getWrapped();
|
||||
if (info instanceof AvailabilityNotifier) {
|
||||
((AvailabilityNotifier) info)
|
||||
.stopMonitoringAvailability(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < infosToRemove.size(); i++) {
|
||||
infoListenerMap.remove(infosToRemove.elementAt(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that the worker thread is running. If it does not exist (null) or
|
||||
* died for some reason (isAlive == false), then we create new and start it.
|
||||
*/
|
||||
private void ensureStarted() {
|
||||
if (pollingThread == null || !pollingThread.isAlive()) {
|
||||
pollingThread = new PollerWorker();
|
||||
pollingThread.start();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Executor class which shields the current thread from unchecked exceptions
|
||||
* that can shut it down.
|
||||
*/
|
||||
private static final class GuardedExecutor {
|
||||
public void execute(Runnable runnable) {
|
||||
try {
|
||||
runnable.run();
|
||||
} catch (Throwable ignore) {
|
||||
// We have to ignore exceptions, otherwise the will kill the
|
||||
// current thread.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class holding the state informations about the upcoming listener
|
||||
* callback.
|
||||
* <i>@Immutable</i>
|
||||
*/
|
||||
private static final class ToCall implements Runnable {
|
||||
private final SensorInfo info;
|
||||
private final SensorListener listener;
|
||||
private final boolean available;
|
||||
|
||||
public ToCall(SensorInfo info, SensorListener listener,
|
||||
boolean available) {
|
||||
this.info = info;
|
||||
this.listener = listener;
|
||||
this.available = available;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
if (available) {
|
||||
listener.sensorAvailable(info);
|
||||
} else {
|
||||
listener.sensorUnavailable(info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The poller worker thread which in a infinite loop fetches SensorInfo
|
||||
* availability and calls appropriate listeners.
|
||||
*/
|
||||
private class PollerWorker extends Thread {
|
||||
public void run() {
|
||||
while (true) {
|
||||
synchronized (infoListenerMap) {
|
||||
while (infoListenerMap.isEmpty()) {
|
||||
try {
|
||||
infoListenerMap.wait();
|
||||
} catch (InterruptedException ignore) {
|
||||
// Avoid interrupt, we control this thread
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// To avoid delay if isAvailable is time consuming
|
||||
long startTimeMillis = System.currentTimeMillis();
|
||||
|
||||
Vector toCall = new Vector();
|
||||
synchronized (infoListenerMap) {
|
||||
Enumeration enumeration = infoListenerMap.keys();
|
||||
while (enumeration.hasMoreElements()) {
|
||||
IdentityWrapper key = (IdentityWrapper) enumeration
|
||||
.nextElement();
|
||||
SensorInfo info = (SensorInfo) key.getWrapped();
|
||||
Boolean available = (Boolean) cachedAvailability
|
||||
.get(key);
|
||||
if (available == null) {
|
||||
available = info.isAvailable() ? Boolean.TRUE
|
||||
: Boolean.FALSE;
|
||||
cachedAvailability.put(key, available);
|
||||
}
|
||||
Boolean oldAvailable = (Boolean) lastAvailable.put(key,
|
||||
available);
|
||||
if (!available.equals(oldAvailable)) {
|
||||
Vector listeners = (Vector) infoListenerMap
|
||||
.get(key);
|
||||
for (int i = 0; i < listeners.size(); i++) {
|
||||
SensorListener listener = (SensorListener)
|
||||
((IdentityWrapper) listeners.elementAt(i))
|
||||
.getWrapped();
|
||||
toCall.addElement(new ToCall(info, listener,
|
||||
available.booleanValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
cachedAvailability.clear();
|
||||
}
|
||||
for (int i = 0; i < toCall.size(); i++) {
|
||||
Runnable runnable = (Runnable) toCall.elementAt(i);
|
||||
executor.execute(runnable);
|
||||
}
|
||||
long millisToWait = pollerSleep
|
||||
- (System.currentTimeMillis() - startTimeMillis);
|
||||
if (millisToWait > 0) {
|
||||
synchronized (sleepLock) {
|
||||
try {
|
||||
sleepLock.wait(millisToWait);
|
||||
} catch (InterruptedException ignore) {
|
||||
// Avoid interrupt, we control this thread
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Copyright 1990-2009 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version
|
||||
* 2 only, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License version 2 for more details (a copy is
|
||||
* included at /legal/license.txt).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* version 2 along with this work; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA
|
||||
*
|
||||
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
||||
* Clara, CA 95054 or visit www.sun.com if you need additional
|
||||
* information or have any questions.
|
||||
*/
|
||||
|
||||
package com.sun.javame.sensor;
|
||||
|
||||
interface ChannelDataListener {
|
||||
|
||||
/**
|
||||
* Notification about data from channel.
|
||||
*
|
||||
* @param number channel number
|
||||
* @param data dada instance from channel
|
||||
*/
|
||||
public void channelDataReceived(int number, DataImpl data);
|
||||
|
||||
/**
|
||||
* Notification about channel error.
|
||||
*
|
||||
* @param number channel number
|
||||
* @param errorCode code of channel error
|
||||
* @param timestamp the timestamp of error
|
||||
*/
|
||||
public void channelErrorReceived(int number, int errorCode, long timestamp);
|
||||
|
||||
}
|
|
@ -0,0 +1,165 @@
|
|||
/*
|
||||
* Copyright 1990-2009 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version
|
||||
* 2 only, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License version 2 for more details (a copy is
|
||||
* included at /legal/license.txt).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* version 2 along with this work; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA
|
||||
*
|
||||
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
||||
* Clara, CA 95054 or visit www.sun.com if you need additional
|
||||
* information or have any questions.
|
||||
*/
|
||||
|
||||
package com.sun.javame.sensor;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public abstract class ChannelDevice {
|
||||
|
||||
/** Sensor number. */
|
||||
protected int numberSensor;
|
||||
|
||||
/** Channel number. */
|
||||
protected int numberChannel;
|
||||
|
||||
/** Hashtable of listeners. */
|
||||
private Vector listeners = new Vector();
|
||||
|
||||
/**
|
||||
* Constructor of the device.
|
||||
*
|
||||
* @param numberSensor - number of sensor
|
||||
* @param numberChannel - number of channel
|
||||
* @param sensorType - Sensor type. This is an ID needed only at the native level.
|
||||
*/
|
||||
public ChannelDevice(int numberSensor, int numberChannel) {
|
||||
this.numberSensor = numberSensor;
|
||||
this.numberChannel = numberChannel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialization of channel device.
|
||||
*
|
||||
* @return true when initialization of channel device
|
||||
* was OK else false
|
||||
*/
|
||||
public abstract boolean initChannel();
|
||||
|
||||
/**
|
||||
* Measures the next data from channel.
|
||||
*
|
||||
* @param numberSensor - number of sensor
|
||||
* @param numberChannel - number of channel
|
||||
* @param sensorType - Sensor type. This is an ID needed only at the native level.
|
||||
* @return error code of measuring
|
||||
*/
|
||||
protected abstract int measureData(int numberSensor, int numberChannel);
|
||||
|
||||
/**
|
||||
* Gets the last data from channel.
|
||||
*
|
||||
* @param numberSensor - number of sensor
|
||||
* @param numberChannel - number of channel
|
||||
* @return data of measuring
|
||||
*/
|
||||
protected abstract Object[] getData(int numberSensor, int numberChannel);
|
||||
|
||||
/**
|
||||
* Gets the last uncertainty from channel.
|
||||
*
|
||||
* @param numberSensor - number of sensor
|
||||
* @param numberChannel - number of channel
|
||||
* @return uncertainty of measuring
|
||||
*/
|
||||
protected abstract float[] getUncertainty(int numberSensor, int numberChannel);
|
||||
|
||||
/**
|
||||
* Gets the last validity from channel.
|
||||
*
|
||||
* @param numberSensor - number of sensor
|
||||
* @param numberChannel - number of channel
|
||||
* @return validity of measuring
|
||||
*/
|
||||
protected abstract boolean[] getValidity(int numberSensor, int numberChannel);
|
||||
|
||||
/**
|
||||
* Gets the value listener.
|
||||
*
|
||||
* @return value listener instance
|
||||
*/
|
||||
synchronized ValueListener getListener() {
|
||||
ValueListener returnValue = null;
|
||||
if (listeners.size() > 0) {
|
||||
returnValue = (ValueListener)listeners.firstElement();
|
||||
listeners.removeElementAt(0);
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Measures the next data from channel.
|
||||
*
|
||||
* @return error code of measuring
|
||||
*/
|
||||
int measureData() {
|
||||
return measureData(numberSensor, numberChannel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the last data from channel.
|
||||
*
|
||||
* @return data of measuring
|
||||
*/
|
||||
Object[] getData() {
|
||||
return getData(numberSensor, numberChannel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the last uncertainty from channel.
|
||||
*
|
||||
* @return uncertainty of measuring
|
||||
*/
|
||||
float[] getUncertainty() {
|
||||
return getUncertainty(numberSensor, numberChannel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the last validity from channel.
|
||||
*
|
||||
* @return validity of measuring
|
||||
*/
|
||||
boolean[] getValidity() {
|
||||
return getValidity(numberSensor, numberChannel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts getting data from channel.
|
||||
*
|
||||
* @param listener - value listener instance
|
||||
*/
|
||||
synchronized void startGetData(ValueListener listener) {
|
||||
listeners.addElement(listener);
|
||||
NativeSensorRegistry.postSensorEvent(NativeSensorRegistry.EVENT_DATA_COLLECT_CODE,
|
||||
numberSensor, numberChannel, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks is channel device available.
|
||||
*
|
||||
* @return true when channel device is available else false
|
||||
*/
|
||||
public abstract boolean isAvailable();
|
||||
|
||||
}
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright 1990-2009 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version
|
||||
* 2 only, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License version 2 for more details (a copy is
|
||||
* included at /legal/license.txt).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* version 2 along with this work; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA
|
||||
*
|
||||
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
||||
* Clara, CA 95054 or visit www.sun.com if you need additional
|
||||
* information or have any questions.
|
||||
*/
|
||||
package com.sun.javame.sensor;
|
||||
|
||||
import javax.microedition.sensor.MeasurementRange;
|
||||
|
||||
|
||||
public class ChannelModel {
|
||||
public int scale;
|
||||
public String name;
|
||||
public String unit;
|
||||
public int dataType; // 1 == Double type, 2 == Integer type, 4 == Object type
|
||||
public int accuracy;
|
||||
public int mrangeCount;
|
||||
public long[] mrageArray;
|
||||
|
||||
public MeasurementRange[] getMeasurementRanges(){
|
||||
MeasurementRange[] res = new MeasurementRange[mrangeCount];
|
||||
for (int i=0;i<mrangeCount;i+=3){
|
||||
res[i] = new MeasurementRange(
|
||||
Double.longBitsToDouble(mrageArray[i*3]),
|
||||
Double.longBitsToDouble(mrageArray[i*3+1]),
|
||||
Double.longBitsToDouble(mrageArray[i*3+2]));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,99 @@
|
|||
/*
|
||||
* Copyright 1990-2009 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version
|
||||
* 2 only, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License version 2 for more details (a copy is
|
||||
* included at /legal/license.txt).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* version 2 along with this work; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA
|
||||
*
|
||||
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
||||
* Clara, CA 95054 or visit www.sun.com if you need additional
|
||||
* information or have any questions.
|
||||
*/
|
||||
|
||||
package com.sun.javame.sensor;
|
||||
|
||||
import java.util.*;
|
||||
import javax.microedition.sensor.*;
|
||||
|
||||
public class ChannelUrl {
|
||||
private static final String CHANNEL = "channel=";
|
||||
private static final char CH_SEP = '&';
|
||||
|
||||
|
||||
/** Creates a new instance of ChannelUrl */
|
||||
public ChannelUrl() {
|
||||
}
|
||||
|
||||
public static String createUrl(ChannelImpl ch) {
|
||||
StringBuffer b = new StringBuffer(CHANNEL);
|
||||
b.append(ch.getName()); // Need revisit
|
||||
|
||||
/* If there are conditions then add them to the URL */
|
||||
Condition[] allConds = ch.getAllConditions();
|
||||
if (allConds != null && allConds.length > 0) {
|
||||
/* Find all unique conditions
|
||||
******************************/
|
||||
Vector ucv = new Vector(allConds.length);
|
||||
|
||||
for (int i = 0; i < allConds.length; i++) {
|
||||
if (allConds[i] instanceof ObjectCondition) {
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean found = false;
|
||||
int count = ucv.size();
|
||||
for (int j = 0; j < count; j++) {
|
||||
if (allConds[i].equals(ucv.elementAt(j))) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
ucv.addElement(allConds[i]);
|
||||
}
|
||||
}
|
||||
|
||||
int scale = ch.getScale();
|
||||
|
||||
int count = ucv.size();
|
||||
for (int i = 0; i < count; i++) {
|
||||
b.append(CH_SEP);
|
||||
|
||||
Condition cond = (Condition)ucv.elementAt(i);
|
||||
|
||||
if (cond instanceof LimitCondition) {
|
||||
LimitCondition lc = (LimitCondition)cond;
|
||||
b.append("limit=");
|
||||
b.append(Double.toString(ConditionHelpers.resolve(lc.getLimit(), scale)));
|
||||
b.append(CH_SEP);
|
||||
b.append("op=");
|
||||
b.append(lc.getOperator());
|
||||
} else {
|
||||
RangeCondition rc = (RangeCondition)cond;
|
||||
b.append("lowerLimit=");
|
||||
b.append(Double.toString(ConditionHelpers.resolve(rc.getLowerLimit(), scale)));
|
||||
b.append("&lowerOp=");
|
||||
b.append(rc.getLowerOp());
|
||||
b.append("&upperLimit=");
|
||||
b.append(Double.toString(ConditionHelpers.resolve(rc.getUpperLimit(), scale)));
|
||||
b.append("&upperOp=");
|
||||
b.append(rc.getUpperOp());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return b.toString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
* Copyright 1990-2009 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version
|
||||
* 2 only, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License version 2 for more details (a copy is
|
||||
* included at /legal/license.txt).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* version 2 along with this work; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA
|
||||
*
|
||||
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
||||
* Clara, CA 95054 or visit www.sun.com if you need additional
|
||||
* information or have any questions.
|
||||
*/
|
||||
|
||||
package com.sun.javame.sensor;
|
||||
|
||||
import javax.microedition.sensor.*;
|
||||
|
||||
/**
|
||||
* Helpers to handle conditions, limits and operators
|
||||
*/
|
||||
public class ConditionHelpers {
|
||||
|
||||
public static boolean checkOperator(String operator) {
|
||||
return (
|
||||
operator.equals(Condition.OP_EQUALS) ||
|
||||
operator.equals(Condition.OP_GREATER_THAN) ||
|
||||
operator.equals(Condition.OP_GREATER_THAN_OR_EQUALS) ||
|
||||
operator.equals(Condition.OP_LESS_THAN) ||
|
||||
operator.equals(Condition.OP_LESS_THAN_OR_EQUALS)
|
||||
);
|
||||
}
|
||||
|
||||
public static boolean checkLowerOperator(String operator) {
|
||||
return (
|
||||
operator.equals(Condition.OP_GREATER_THAN) ||
|
||||
operator.equals(Condition.OP_GREATER_THAN_OR_EQUALS)
|
||||
);
|
||||
}
|
||||
|
||||
public static boolean checkUpperOperator(String operator) {
|
||||
return (
|
||||
operator.equals(Condition.OP_LESS_THAN) ||
|
||||
operator.equals(Condition.OP_LESS_THAN_OR_EQUALS)
|
||||
);
|
||||
}
|
||||
|
||||
public static boolean checkValue(String operator, double limit, double value) {
|
||||
if (operator.equals(Condition.OP_EQUALS)) {
|
||||
return (Double.doubleToLongBits(limit) ==
|
||||
Double.doubleToLongBits(value));
|
||||
}
|
||||
|
||||
if (operator.equals(Condition.OP_GREATER_THAN)) {
|
||||
return (value > limit);
|
||||
}
|
||||
|
||||
if (operator.equals(Condition.OP_GREATER_THAN_OR_EQUALS)) {
|
||||
return checkValue(Condition.OP_EQUALS, limit, value) ||
|
||||
checkValue(Condition.OP_GREATER_THAN, limit, value);
|
||||
}
|
||||
|
||||
if (operator.equals(Condition.OP_LESS_THAN)) {
|
||||
return (value < limit);
|
||||
}
|
||||
|
||||
if (operator.equals(Condition.OP_LESS_THAN_OR_EQUALS)) {
|
||||
return checkValue(Condition.OP_EQUALS, limit, value) ||
|
||||
checkValue(Condition.OP_LESS_THAN, limit, value);
|
||||
}
|
||||
|
||||
/* We should not be here */
|
||||
return false;
|
||||
}
|
||||
|
||||
public static double resolve(double value, int scale) {
|
||||
double mult = 1.0;
|
||||
for (int i = 0, limit = Math.abs(scale); i < limit; i++) {
|
||||
mult *= 10.0;
|
||||
}
|
||||
return (scale > 0)? value * mult : value / mult;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,340 @@
|
|||
/*
|
||||
* Copyright 1990-2009 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version
|
||||
* 2 only, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License version 2 for more details (a copy is
|
||||
* included at /legal/license.txt).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* version 2 along with this work; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA
|
||||
*
|
||||
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
||||
* Clara, CA 95054 or visit www.sun.com if you need additional
|
||||
* information or have any questions.
|
||||
*/
|
||||
|
||||
package com.sun.javame.sensor;
|
||||
|
||||
import javax.microedition.sensor.*;
|
||||
|
||||
public class DataImpl implements Data {
|
||||
|
||||
/** ChannelInfo instance. */
|
||||
private ChannelInfo channelInfo;
|
||||
|
||||
/** Time stamp included flag. */
|
||||
private boolean isTimestampIncluded;
|
||||
|
||||
/** Timestamps array. */
|
||||
private long[] timeStamps;
|
||||
|
||||
/** Uncertainty included flag. */
|
||||
private boolean isUncertaintyIncluded;
|
||||
|
||||
/** Uncertainties array. */
|
||||
private float[] uncertainties;
|
||||
|
||||
/** Validity included flag. */
|
||||
private boolean isValidityIncluded;
|
||||
|
||||
/** Validities array. */
|
||||
private boolean[] validities;
|
||||
|
||||
/** Data type. */
|
||||
private int dataType;
|
||||
|
||||
/** Size of buffer. */
|
||||
private int bufferSize;
|
||||
|
||||
/** Object values. */
|
||||
private Object[] objectValues;
|
||||
|
||||
/**
|
||||
* Creates a new instance of DataImpl.
|
||||
*
|
||||
* @param channelInfo - the ChannelInfo instance of the channel
|
||||
* from where the data values were fetched
|
||||
* @param bufferSize - the size of the buffer of the data values
|
||||
* @param dataType - the data type of the channel. The type alternatives are:
|
||||
* * TYPE_INT
|
||||
* * TYPE_DOUBLE
|
||||
* * TYPE_OBJECT
|
||||
* @param isTimestampIncluded - if true timestamps should be
|
||||
* included in returned Data objects
|
||||
* @param isUncertaintyIncluded - if true uncertainties should be
|
||||
* included in returned Data objects
|
||||
* @param isValidityIncluded - if true validities should be
|
||||
* included in returned Data objects
|
||||
*/
|
||||
DataImpl(ChannelInfo channelInfo, int bufferSize, int dataType,
|
||||
boolean isTimestampIncluded, boolean isUncertaintyIncluded,
|
||||
boolean isValidityIncluded) {
|
||||
this.channelInfo = channelInfo;
|
||||
this.isTimestampIncluded = isTimestampIncluded;
|
||||
if (isTimestampIncluded) {
|
||||
timeStamps = new long[bufferSize];
|
||||
}
|
||||
this.isUncertaintyIncluded = isUncertaintyIncluded;
|
||||
if (isUncertaintyIncluded) {
|
||||
uncertainties = new float[bufferSize];
|
||||
}
|
||||
this.isValidityIncluded = isValidityIncluded;
|
||||
if (isValidityIncluded) {
|
||||
validities = new boolean[bufferSize];
|
||||
}
|
||||
this.dataType = dataType;
|
||||
objectValues = new Object[bufferSize];
|
||||
this.bufferSize = bufferSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ChannelInfo that tells the data properties
|
||||
* of the channel from where the data values were fetched.
|
||||
*
|
||||
* @return ChannelInfo of the Data
|
||||
*/
|
||||
public ChannelInfo getChannelInfo() {
|
||||
return channelInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the data values as a double array if the data type
|
||||
* of the channel is ChannelInfo.TYPE_DOUBLE.
|
||||
*
|
||||
* @return the data values as a double array,
|
||||
* a zero-length double array if no values have been measured
|
||||
* @throws IllegalStateException - if the data type of the
|
||||
* channel is not ChannelInfo.TYPE_DOUBLE
|
||||
*/
|
||||
public double[] getDoubleValues() {
|
||||
if (dataType != ChannelInfo.TYPE_DOUBLE) {
|
||||
throw new IllegalStateException("Data type is not double");
|
||||
}
|
||||
double[] retValues = new double[0];
|
||||
if (objectValues != null) {
|
||||
if (bufferSize > 0) {
|
||||
retValues = new double[bufferSize];
|
||||
Object tmp;
|
||||
for (int i = 0; i < bufferSize; i++) {
|
||||
tmp = objectValues[i];
|
||||
if( tmp instanceof Double ){
|
||||
retValues[i] = ((Double)tmp).doubleValue();
|
||||
} else {
|
||||
retValues[i] = 0.0;
|
||||
if (isValidityIncluded && validities[i]) {
|
||||
validities[i] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return retValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the data values as an int array if the data type
|
||||
* of this channel is ChannelInfo.TYPE_INT.
|
||||
*
|
||||
* @return the data values as an int array, a zero-length
|
||||
* int array if no values have been measured
|
||||
* @throws IllegalStateException - if the data type of the
|
||||
* channel is not ChannelInfo.TYPE_INT
|
||||
*/
|
||||
public int[] getIntValues() {
|
||||
if (dataType != ChannelInfo.TYPE_INT) {
|
||||
throw new IllegalStateException("Data type is not int");
|
||||
}
|
||||
int[] retValues = new int[0];
|
||||
if (objectValues != null) {
|
||||
if (bufferSize > 0) {
|
||||
retValues = new int[bufferSize];
|
||||
Object tmp;
|
||||
for (int i = 0; i < bufferSize; i++) {
|
||||
tmp = objectValues[i];
|
||||
if (tmp instanceof Integer) {
|
||||
retValues[i] = ((Integer)tmp).intValue();
|
||||
} else {
|
||||
retValues[i] = 0;
|
||||
if (isValidityIncluded && validities[i]) {
|
||||
validities[i] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return retValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the data values as an array of Objects if the data
|
||||
* type of this channel is ChannelInfo.TYPE_OBJECT.
|
||||
*
|
||||
* @return the data values as an Object array, a zero-length
|
||||
* Object array if no values have been measured
|
||||
* @throws IllegalStateException - if the data type of the channel
|
||||
* is not ChannelInfo.TYPE_OBJECT
|
||||
*/
|
||||
public Object[] getObjectValues() {
|
||||
if (dataType != ChannelInfo.TYPE_OBJECT) {
|
||||
throw new IllegalStateException("Data type is not Object");
|
||||
}
|
||||
Object[] retValues = new Object[0];
|
||||
if (objectValues != null) {
|
||||
if (bufferSize == objectValues.length) {
|
||||
retValues = objectValues;
|
||||
} else if (bufferSize > 0) {
|
||||
retValues = new Object[bufferSize];
|
||||
System.arraycopy(objectValues, 0, retValues, 0, bufferSize);
|
||||
}
|
||||
}
|
||||
return retValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the timestamp corresponding to the time when
|
||||
* the data value indicated by the index was measured.
|
||||
*
|
||||
* @param index the index of the data value
|
||||
* @return the timestamp indicating when the data value was retrieved
|
||||
* @throws IndexOutOfBoundsException - if the index is out of the
|
||||
* closed range [0, (size of the data buffer - 1)]
|
||||
* @throws IllegalStateException - if the timestamp was not requested
|
||||
* according to the parameters of the SensorConnection.getData()
|
||||
* or the SensorConnection.setDataListener() methods.
|
||||
*/
|
||||
public long getTimestamp(int index) {
|
||||
if (!isTimestampIncluded) {
|
||||
throw new IllegalStateException("Timestamp wasn't requested");
|
||||
}
|
||||
return timeStamps[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the estimate of the error of the measured data value.
|
||||
*
|
||||
* @param index the index of the data value
|
||||
* @return the uncertainty of the data value
|
||||
* @throws IndexOutOfBoundsException - if the index is out of the
|
||||
* closed range [0,(size of the data buffer - 1)]
|
||||
* @throws IllegalStateException - if the uncertainty was not
|
||||
* requested according to the parameters of the
|
||||
* SensorConnection.getData() or the
|
||||
* SensorConnection.setDataListener() methods.
|
||||
*/
|
||||
public float getUncertainty(int index) {
|
||||
if (!isUncertaintyIncluded) {
|
||||
throw new IllegalStateException("Uncertainty wasn't requested");
|
||||
}
|
||||
return uncertainties[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the validity of the data value at the given index.
|
||||
*
|
||||
* @param index the index of the data value
|
||||
* @return the validity of the data value
|
||||
* @throws IndexOutOfBoundsException - if the index is out of the
|
||||
* closed range [0, (size of the data buffer - 1)]
|
||||
* @throws IllegalStateException - if the validity was not requested
|
||||
* according to the parameters of the method
|
||||
* SensorConnection.getData() or SensorConnection.setDataListener().
|
||||
*/
|
||||
public boolean isValid(int index) {
|
||||
if (!isValidityIncluded) {
|
||||
throw new IllegalStateException("Validity wasn't requested");
|
||||
}
|
||||
return validities[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the new size of buffer.
|
||||
*
|
||||
* @param bufferSize - new buffer size value
|
||||
*/
|
||||
void setBufferSize(int bufferSize) {
|
||||
if ( this.bufferSize != bufferSize ){
|
||||
//If buffer is not large enough, increase the buffer size so that all read data
|
||||
//can be stored in the Data instance.
|
||||
int minSize = Math.min(this.bufferSize, bufferSize);
|
||||
long[] tmpTimeStamps = null;
|
||||
float[] tmpUncertainties = null;
|
||||
boolean[] tmpValidities = null;
|
||||
Object[] tmpObjectValues = null;
|
||||
if (timeStamps != null) {
|
||||
tmpTimeStamps = new long[minSize];
|
||||
System.arraycopy( timeStamps, 0, tmpTimeStamps, 0, minSize);
|
||||
}
|
||||
if ( uncertainties != null) {
|
||||
tmpUncertainties = new float[minSize];
|
||||
System.arraycopy( uncertainties, 0, tmpUncertainties, 0, minSize);
|
||||
}
|
||||
if ( validities != null) {
|
||||
tmpValidities = new boolean[minSize];
|
||||
System.arraycopy( validities, 0, tmpValidities, 0, minSize);
|
||||
}
|
||||
tmpObjectValues = new Object[minSize];
|
||||
System.arraycopy( objectValues, 0, tmpObjectValues, 0, minSize);
|
||||
|
||||
timeStamps = tmpTimeStamps;
|
||||
uncertainties = tmpUncertainties;
|
||||
validities = tmpValidities;
|
||||
objectValues = tmpObjectValues;
|
||||
}
|
||||
this.bufferSize = bufferSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the data to buffer.
|
||||
*
|
||||
* @param index - index of place in buffer
|
||||
* @param item - data item for saving
|
||||
*/
|
||||
void setData(int index, Object item) {
|
||||
objectValues[index] = item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the timestamp to buffer.
|
||||
*
|
||||
* @param index - index of place in buffer
|
||||
* @param timestamp - data item for saving
|
||||
*/
|
||||
void setTimestamp(int index, long timestamp) {
|
||||
if (isTimestampIncluded) {
|
||||
timeStamps[index] = timestamp;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the uncertainty to buffer.
|
||||
*
|
||||
* @param index - index of place in buffer
|
||||
* @param uncertainty - uncertainty for saving
|
||||
*/
|
||||
void setUncertainty(int index, float uncertainty) {
|
||||
if (isUncertaintyIncluded) {
|
||||
uncertainties[index] = uncertainty;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the validity to buffer.
|
||||
*
|
||||
* @param index - index of place in buffer
|
||||
* @param validity - data item for saving
|
||||
*/
|
||||
void setValidity(int index, boolean validity) {
|
||||
if (isValidityIncluded) {
|
||||
validities[index] = validity;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -22,48 +22,39 @@
|
|||
* information or have any questions.
|
||||
*/
|
||||
|
||||
package com.sun.midp.appmanager;
|
||||
package com.sun.javame.sensor;
|
||||
|
||||
import java.util.Vector;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Interfase represente the set of pairs of ID and label.
|
||||
* One entity id market as selected.
|
||||
* It can be used to represent the data for exclusive
|
||||
* option buttons where each option has an ID.
|
||||
*/
|
||||
interface ValueChoice {
|
||||
|
||||
/**
|
||||
* Returns the ID of the selected item.
|
||||
*
|
||||
* @return ID of selected element
|
||||
*/
|
||||
int getSelectedID();
|
||||
|
||||
/**
|
||||
* Returns ID of specified item.
|
||||
* @param index item index
|
||||
* @return item ID
|
||||
*/
|
||||
int getID(int index);
|
||||
|
||||
/**
|
||||
* Returns label of specified choice items.
|
||||
* @param index item index
|
||||
* @return label
|
||||
*/
|
||||
String getLabel(int index);
|
||||
|
||||
/**
|
||||
* Returns count of items
|
||||
* @return count
|
||||
*/
|
||||
int getCount();
|
||||
|
||||
/**
|
||||
* Returns choice title.
|
||||
* @return title
|
||||
*/
|
||||
String getTitle();
|
||||
public class DefaultSensorProperties implements SensorProperties {
|
||||
private static final int DEFAULT_PROPS_MAX_NUMBER = 6;
|
||||
|
||||
private Hashtable props = new Hashtable(DEFAULT_PROPS_MAX_NUMBER);
|
||||
|
||||
/** Creates a new instance of DefaultSensorProperties */
|
||||
public DefaultSensorProperties() {
|
||||
}
|
||||
|
||||
public void setProperty(String key, Object value) {
|
||||
props.put(key, value);
|
||||
}
|
||||
|
||||
public Object getProperty(String key) {
|
||||
return props.get(key);
|
||||
}
|
||||
|
||||
public String[] getPropertyNames() {
|
||||
String[] keys = new String[props.size()];
|
||||
|
||||
int index = 0;
|
||||
for (Enumeration e = props.keys(); e.hasMoreElements(); ) {
|
||||
keys[index++] = (String)e.nextElement();
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
public boolean containsName(String name) {
|
||||
return props.containsKey(name);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* Copyright 1990-2009 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version
|
||||
* 2 only, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License version 2 for more details (a copy is
|
||||
* included at /legal/license.txt).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* version 2 along with this work; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA
|
||||
*
|
||||
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
||||
* Clara, CA 95054 or visit www.sun.com if you need additional
|
||||
* information or have any questions.
|
||||
*/
|
||||
|
||||
package com.sun.javame.sensor;
|
||||
|
||||
public class DeviceFactory {
|
||||
/**
|
||||
* Sensor types. These constants are recognized at the native level,
|
||||
* if there is native level.
|
||||
*/
|
||||
/** sensor:current_bearer */
|
||||
public static final int SENSOR_CURRENT_BEARER =0;
|
||||
/** sensor:network_code */
|
||||
public static final int SENSOR_NETWORK_CODE=1;
|
||||
/** sensor:network_quality */
|
||||
public static final int SENSOR_NETWORK_QUALITY=2;
|
||||
/** sensor:data_counter */
|
||||
public static final int SENSOR_DATA_COUNTER=3;
|
||||
/** sensor:cellid */
|
||||
public static final int SENSOR_CELL_ID=4;
|
||||
/** sensor:sound_level */
|
||||
public static final int SENSOR_SOUND_LEVEL=5;
|
||||
/** sensor:battery_level */
|
||||
public static final int SENSOR_BATTERY_LEVEL=6;
|
||||
/** sensor:battery_charge */
|
||||
public static final int SENSOR_BATTERY_CHARGE=7;
|
||||
/** sensor:flip_state */
|
||||
public static final int SENSOR_FLIP_STATE=8;
|
||||
/** sensor:dvbh_quality */
|
||||
public static final int SENSOR_DVBH_SIGNAL_QUALITY=9;
|
||||
/** sensor:dvbh_realtime*/
|
||||
public static final int SENSOR_DVBH_REALTIME=10;
|
||||
/** other type of sensor, that is, not recognized at the native level */
|
||||
public static final int SENSOR_OTHER=-1;
|
||||
/** Special testing sensor, sensor:sensor_tester. */
|
||||
public static final int SENSOR_TESTER = -2;
|
||||
|
||||
/**
|
||||
* Generates a channel implementation instance.
|
||||
*
|
||||
* @param numberSensor number of the sensor based 0
|
||||
* @param numberChannel number of the channel based 0
|
||||
* @return new channel implementation instance
|
||||
*/
|
||||
public static ChannelDevice generateChannel(int numberSensor, int numberChannel) {
|
||||
return new NativeChannel(numberSensor, numberChannel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a sensor implementation instance.
|
||||
*
|
||||
* @param numberSensor number of the sensor based 0
|
||||
* @param channelCount number of channels
|
||||
* @return new sensor implementation instance, or null
|
||||
*/
|
||||
public static SensorDevice generateSensor(int numberSensor) {
|
||||
return new NativeSensor(numberSensor);
|
||||
}
|
||||
}
|
Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше
Загрузка…
Ссылка в новой задаче