Exemplo n.º 1
0
  /// *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;
    }
  }
Exemplo n.º 2
0
  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;
    }
  }
Exemplo n.º 3
0
  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;
  }