/// *package*/void registerInstance(int instanceId, String name, int messageType) { private synchronized boolean registerInstance(Instance instance) { int id = instance.getInstanceId(); String masName = instance.getName(); int messageType = instance.getType(); String rootPath = instance.getRootPath(); log("registerInstance():id is " + id + ", name is " + masName + ", type is " + messageType); // it is allowed to set id as zero in MAP profile. // but not permitted in externall layer. // so we will follow external rule temprorily if (id < 0 || id > 255) { log("the id is invalid"); return false; } if (masName == null || rootPath == null) { log("error, the mas name or root path is null"); return false; } if (isEnabled()) { registerInstanceNative(id, masName, messageType, rootPath); return true; } else { log("MAP service has not been initialized"); return false; } }
private synchronized int disconnectMasSession(Instance instance) { int result = FAIL; if (instance == null || !instance.isMasConnected()) { return result; } result = disconnectMasNative(instance.getInstanceId()); if (result == SUCCESS) { instance.onDeviceDisconnecting(instance.getDevice()); return PENDING; } else { instance.onDeviceDisconnected(instance.getDevice()); return SUCCESS; } }
private synchronized boolean deregisterInstance(Instance instance) { int id = instance.getInstanceId(); boolean ret = false; log("deregisterInstance: id=" + id); if (getState() == BluetoothMap.STATE_DISABLED || id > 255 || id < 0) { log("fail to deregister instance"); return false; } /* if (instance.isMasConnected()) { disconnectMasNative(id); } */ deregisterInstanceNative(id); return true; }