コード例 #1
0
JNIEXPORT jboolean JNICALL Java_com_intel_bluetooth_BluetoothStackBlueZ_populateServiceRecordAttributeValuesImpl
  (JNIEnv *env, jobject peer, jlong localDeviceBTAddress, jlong remoteDeviceAddressLong, jlong sdpSession, jlong handle, jintArray attrIDs, jobject serviceRecord) {
    sdp_session_t* session = (sdp_session_t*)jlong2ptr(sdpSession);
    sdp_session_t* close_session_on_return = NULL;
    if (session != NULL) {
        debug("populateServiceRecordAttributeValuesImpl connected %p, recordHandle %li", session, handle);
    } else {
        debug("populateServiceRecordAttributeValuesImpl connects, recordHandle %li", handle);
        bdaddr_t localAddr;
        longToDeviceAddr(localDeviceBTAddress, &localAddr);
        bdaddr_t remoteAddress;
        longToDeviceAddr(remoteDeviceAddressLong, &remoteAddress);
        session = sdp_connect(&localAddr, &remoteAddress, SDP_RETRY_IF_BUSY);
        if (session == NULL) {
            debug("populateServiceRecordAttributeValuesImpl can't connect");
            return JNI_FALSE;
        }
        // Close session on exit
       close_session_on_return = session;
    }

    sdp_list_t *attr_list = NULL;
    jboolean isCopy = JNI_FALSE;
    jint* ids = (*env)->GetIntArrayElements(env, attrIDs, &isCopy);
    int i;
    for(i = 0; i < (*env)->GetArrayLength(env, attrIDs); i++) {
        uint16_t* id = (uint16_t*)malloc(sizeof(uint16_t));
        *id=(uint16_t)ids[i];
        attr_list = sdp_list_append(attr_list,id);
    }

    jboolean rc = JNI_FALSE;
    sdp_record_t *sdpRecord = sdp_service_attr_req(session, (uint32_t)handle, SDP_ATTR_REQ_INDIVIDUAL, attr_list);
    if (!sdpRecord) {
        debug("sdp_service_attr_req return error");
        rc = JNI_FALSE;
    } else {
        populateServiceRecord(env, serviceRecord, sdpRecord, attr_list);
        sdp_record_free(sdpRecord);
        rc = JNI_TRUE;
    }
    sdp_list_free(attr_list, free);
    if (close_session_on_return != NULL) {
        sdp_close(close_session_on_return);
    }

    return rc;
}
コード例 #2
0
static unpacker* get_unpacker(JNIEnv *env, jobject pObj, bool noCreate=false) {
  unpacker* uPtr;
  uPtr = (unpacker*)jlong2ptr(env->GetLongField(pObj, unpackerPtrFID));
  //fprintf(stderr, "get_unpacker(%p) uPtr=%p\n", pObj, uPtr);
  if (uPtr == null) {
    if (noCreate)  return null;
    uPtr = new unpacker();
    if (uPtr == null) {
      THROW_IOE(ERROR_ENOMEM);
      return null;
    }
    //fprintf(stderr, "get_unpacker(%p) uPtr=%p initializing\n", pObj, uPtr);
    uPtr->init(read_input_via_jni);
    uPtr->jniobj = (void*) env->NewGlobalRef(pObj);
    env->SetLongField(pObj, unpackerPtrFID, ptr2jlong(uPtr));
  }
  uPtr->jnienv = env;  // keep refreshing this in case of MT access
  return uPtr;
}