Fields Summary |
---|
private static int | DEFAULT_ACInitial access code. |
private Inquiry | curInquiryKeeps current inquiry if any. |
byte[] | addressBluetooth address. |
private DeviceState | deviceStateDevice state i.e. discoverable mode and device class. |
private Object | serverTransactionLock for emulation server communications that require response. |
private static DeviceEmul | localDeviceEmulDevice emulation for the local device. |
static final int | UPDATE_CLASSRequest code for updating service classes. |
static final int | UPDATE_ACCESSRequest code for updating access code. |
static final int | START_INQUIRYRequest code for updating starting inquiry. |
static final int | CANCEL_INQUIRYRequest code for cancelling inquiry. |
static final int | INIT_DEVICERequest code for initing devie. |
Methods Summary |
---|
private synchronized void | cancelInquiry()Cancels current inquiry.
if (curInquiry != null) {
curInquiry.cancel();
}
|
private native void | deviceDiscovered(byte[] addr, int cod)Notifies on device discovery.
|
private native void | finalize()Saves device information in persistent storage for future use.
|
public byte[] | getAddress()Returns address of this device.
return address;
|
public static synchronized com.sun.midp.jsr82emul.DeviceEmul | getLocalDeviceEmul()Returns instance of this class for local device emulation.
if (localDeviceEmul == null) {
localDeviceEmul = new DeviceEmul();
}
return localDeviceEmul;
|
private byte[] | getLocalIpBytes()Retrieves IP address.
String ip = EmulationClient.getLocalIP();
byte[] res = null;
if (ip != null && ip.length() > 0) {
int from = 0;
int to = 0;
byte[] parsed = new byte[4];
try {
for (int i = 0; i < 4; i++) {
to = ip.indexOf('.", from);
if (to < 0) {
to = ip.length();
}
parsed[i] = (byte)Integer.parseInt(ip.substring(from, to));
from = to + 1;
}
res = parsed;
} catch (NumberFormatException e) {
// res == null idenitifies retrieving failure
}
}
if (res == null) {
res = new byte[] {127, 0, 0, 1};
}
return res;
|
private native int | initDevice(byte[] addr, int ac)Initializes local device parameters in shared emulation storage.
|
private native void | inquiryCompleted(boolean success)Notifies on inquiry completion.
|
public void | process(BytePack request)Processes the request.
switch (request.extract()) {
case UPDATE_CLASS:
Log.log("Processing UPDATE_CLASS");
deviceState.setServiceClasses(request.extractInt());
updateState();
break;
case UPDATE_ACCESS:
Log.log("Processing UPDATE_ACCESS");
deviceState.setDiscoverable(request.extractInt());
updateState();
break;
case START_INQUIRY:
Log.log("Processing START_INQUIRY");
startInquiry(request.extractInt());
break;
case CANCEL_INQUIRY:
Log.log("Processing CANCEL_INQUIRY");
cancelInquiry();
break;
case INIT_DEVICE:
Log.log("Processing INIT_DEVICE");
// Nothing to do: the request has already caused
// construction of all the objects required.
break;
}
|
void | registerService(ServiceConnectionData serviceData)Registers service at emulation server.
synchronized (serverTransaction) {
messenger.sendBytes(toServer, Messenger.REGISTER_SERVICE,
serviceData.toByteArray(ServiceConnectionData.SERVER_DATA));
}
|
private synchronized void | startInquiry(int accessCode)Starts inquiry.
curInquiry = new Inquiry(accessCode);
|
void | unregisterService(int serverSocketPort)Unregisters service at emulation server.
try {
messenger.sendInt(toServer, Messenger.UNREGISTER_SERVICE,
serverSocketPort);
} catch (IOException e) {
if (Logging.TRACE_ENABLED) {
Logging.trace(e, "Unregistering service failed");
}
}
|
private void | updateState()Sends device state update to emulation server.
try {
messenger.sendInt(toServer,
Messenger.UPDATE_DEVICE_STATE, deviceState.toInt());
} catch (IOException e) {
throw new EmulationException(e.getMessage());
}
|