javacall_result bt_push_unregister_url(const char *url) { bt_port_t port; bt_push_t *push, *prev; REPORT_INFO(LC_PUSH, "Bluetooth PushRegistry URL un-registration:"); REPORT_INFO1(LC_PUSH, "%s", url); bt_push_parse_url(url, &port, NULL); push = find_push(&port, &prev); if (push == NULL) { return JAVACALL_FAIL; } /* remove the service record */ javacall_bt_sddb_remove_record(push->record.id); /* close server and client connections */ close_all(push); /* remove the entry */ if (prev != NULL) { prev->next = push->next; } else { g_registry = push->next; } g_count--; pcsl_mem_free(push); push_save(); javacall_bt_stack_set_service_classes(javacall_bt_sddb_get_service_classes(0)); REPORT_INFO(LC_PUSH, "Un-registration successful."); return JAVACALL_OK; }
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, ¶ms); 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, ¶ms, 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; }
/* * Checks out (takes ownership of) an active server connection maintained * by push subsystem. * * @param url URL used during registration of the push entry * @param suiteId suite id * @return true if the operation succeeds, false otherwise */ KNIEXPORT KNI_RETURNTYPE_BOOLEAN Java_com_sun_jsr082_bluetooth_btl2cap_L2CAPNotifierImpl_pushCheckout(void) { jboolean retval = KNI_FALSE; SuiteIdType suiteId; MidpString wsUrl; char *szUrl; bt_port_t port; jfieldID notifHandleID = NULL; jfieldID pushHandleID = NULL; KNI_StartHandles(3); KNI_DeclareHandle(thisHandle); KNI_DeclareHandle(urlHandle); KNI_DeclareHandle(classHandle); KNI_GetThisPointer(thisHandle); KNI_GetClassPointer(classHandle); GET_FIELDID(classHandle, "handle", "I", notifHandleID) GET_FIELDID(classHandle, "pushHandle", "I", pushHandleID) KNI_GetParameterAsObject(1, urlHandle); suiteId = KNI_GetParameterAsInt(2); wsUrl = midpNewString(urlHandle); szUrl = midpJcharsToChars(wsUrl); if (bt_push_parse_url(szUrl, &port, NULL) == JAVACALL_OK) { if (pushcheckout(szUrl, 0, (char*)midp_suiteid2chars(suiteId)) == -2) { KNI_ThrowNew(midpIOException, "Port already in use."); } else { javacall_handle handle; bt_pushid_t pushid = bt_push_checkout_server(&port, &handle, NULL); if (pushid != BT_INVALID_PUSH_HANDLE) { KNI_SetIntField(thisHandle, pushHandleID, (jint)pushid); KNI_SetIntField(thisHandle, notifHandleID, (jint)handle); retval = KNI_TRUE; } } } midpFree(szUrl); MIDP_FREE_STRING(wsUrl); KNI_EndHandles(); KNI_ReturnBoolean(retval); }
/** * Checks out (takes ownership of) an active server connection maintained * by push subsystem. * * @param url URL used during registration of the push entry * @param suiteId suite id * @return true if the operation succeeds, false otherwise */ KNIEXPORT KNI_RETURNTYPE_BOOLEAN Java_com_sun_midp_io_j2me_btspp_BTSPPNotifierImpl_pushCheckout(void) { jboolean retval = KNI_FALSE; SuiteIdType suiteId; MidpString wsUrl; char *szUrl; bt_port_t port; KNI_StartHandles(2); KNI_DeclareHandle(thisHandle); KNI_DeclareHandle(urlHandle); KNI_GetThisPointer(thisHandle); KNI_GetParameterAsObject(1, urlHandle); suiteId = KNI_GetParameterAsInt(2); wsUrl = midpNewString(urlHandle); szUrl = midpJcharsToChars(wsUrl); if (bt_push_parse_url(szUrl, &port, NULL) == BT_RESULT_SUCCESS) { if (pushcheckout(szUrl, 0, (char*)midp_suiteid2chars(suiteId)) == -2) { KNI_ThrowNew(midpIOException, "Port already in use."); } else { bt_handle_t handle; bt_pushid_t pushid = bt_push_checkout_server(&port, &handle, NULL); if (pushid != BT_INVALID_PUSH_HANDLE) { KNI_SetIntField(thisHandle, pushHandleID, (jint)pushid); KNI_SetIntField(thisHandle, notifHandleID, (jint)handle); retval = KNI_TRUE; } } } midpFree(szUrl); MIDP_FREE_STRING(wsUrl); KNI_EndHandles(); KNI_ReturnBoolean(retval); }