예제 #1
0
파일: SDDBGlue.c 프로젝트: sfsy1989/j2me
/**
 * Creates or updates service record in the SDDB.
 *
 * @param handle handle of the service record to be updated;
 *         if equals to 0, a new record will be created
 * @param classes device service classes associated with the record
 * @param data binary data containing attribute-value pairs in the format
 *         identical to the one used in the AttributeList parameter of
 *         the SDP_ServiceAttributeResponse PDU
 * @return service record handle, or 0 if the operation fails
 */
KNIEXPORT KNI_RETURNTYPE_INT
Java_com_sun_kvem_jsr082_bluetooth_SDDB_updateRecord(void)
{
    bt_sddbid_t retval;
    bt_record_t record;
    bt_sddbid_t old_id = (bt_sddbid_t)KNI_GetParameterAsInt(1);
    KNI_StartHandles(1);
    KNI_DeclareHandle(dataHandle);
    record.id = old_id;
    record.classes = KNI_GetParameterAsInt(2);
    KNI_GetParameterAsObject(3, dataHandle);
    record.data = JavaByteArray(dataHandle);
    record.size = KNI_GetArrayLength(dataHandle);
    if (javacall_bt_sddb_update_record(&record.id, record.classes,
            record.data, record.size) == JAVACALL_OK) {
        retval = record.id;
        if (old_id != BT_INVALID_SDDB_HANDLE) {
            bt_push_update_record(old_id, &record);
        }
        javacall_bt_stack_set_service_classes(javacall_bt_sddb_get_service_classes(0));
    } else {
        retval = BT_INVALID_SDDB_HANDLE;
    }
    KNI_EndHandles();
    KNI_ReturnInt(retval);
}
예제 #2
0
javacall_result bt_push_register_url(const char *url, const void *data,
        size_t size)
{
    bt_port_t port;
    bt_params_t params;
    bt_push_t *push;
    REPORT_INFO(LC_PUSH, "Bluetooth PushRegistry URL registration:");
    REPORT_INFO1(LC_PUSH, "%s", url);
    bt_push_parse_url(url, &port, &params);
    push = find_push(&port, NULL);
    if (push != NULL) {
        /* found existing entry with the same protocol/uuid, can not proceed */
        REPORT_ERROR(LC_PUSH, "Entry already exists, registration failed.");
        return JAVACALL_FAIL;
    }
    /* save the entry in the registry */
    push = (bt_push_t *)pcsl_mem_malloc(sizeof(bt_push_t));
    if (push == NULL) {
        REPORT_ERROR(LC_PUSH, "Failed to allocate memory.");
        return JAVACALL_FAIL;
    }
    memcpy(&push->port, &port, sizeof(bt_port_t));
    memcpy(&push->params, &params, sizeof(bt_params_t));
    push->record.id = BT_INVALID_SDDB_HANDLE;
    push->record.classes = 0;
    if (data != NULL) {
        push->record.data = pcsl_mem_malloc(size);
        if (push->record.data == NULL) {
            pcsl_mem_free(push);
            return JAVACALL_FAIL;
        }
        memcpy(push->record.data, data, size);
    } else {
        push->record.data = NULL;
    }
    push->record.size = size;
    push->server = BT_INVALID_HANDLE;
    push->client = NULL;
    push->next = g_registry;
    g_registry = push;
    g_count++;
    if (javacall_bt_sddb_update_record(&push->record.id, push->record.classes,
            push->record.data, push->record.size) != JAVACALL_OK) {
        return JAVACALL_FAIL;
    }
    push_save();
    REPORT_INFO(LC_PUSH, "Registration successful.");
    return JAVACALL_OK;
}
예제 #3
0
javacall_handle bt_push_start_server(const bt_port_t *port)
{
    int psm, cn;
    bt_params_t *params;
    bt_push_t *push = find_push(port, NULL);
    if (push == NULL || push->server != BT_INVALID_HANDLE) {
        return BT_INVALID_HANDLE;
    }
    if (javacall_bt_sddb_update_record(&push->record.id, push->record.classes,
            push->record.data, push->record.size) != JAVACALL_OK) {
        return BT_INVALID_HANDLE;
    }
    params = &push->params;
    switch (port->protocol) {
        case BT_L2CAP:
            if (javacall_bt_l2cap_create_server(params->rmtu, params->tmtu,
                    params->authenticate, params->authorize, params->encrypt,
                    params->master, &push->server, &psm) !=
                    JAVACALL_OK) {
                return BT_INVALID_HANDLE;
            }
            javacall_bt_sddb_update_psm(push->record.id, psm);
            javacall_bt_l2cap_listen(push->server);
            break;
        case BT_SPP:
        case BT_GOEP:
            if (javacall_bt_rfcomm_create_server(params->authenticate, params->authorize,
                    params->encrypt, params->master, &push->server, &cn) !=
                    JAVACALL_OK) {
                return BT_INVALID_HANDLE;
            }
            javacall_bt_sddb_update_channel(push->record.id, cn);
            javacall_bt_rfcomm_listen(push->server);
            break;
        default:
            return BT_INVALID_HANDLE;
    }
    javacall_bt_stack_set_service_classes(javacall_bt_sddb_get_service_classes(0));
    return push->server;
}