#include #include #include #include "_cgo_export.h" jboolean enabled(JNIEnv *env, jobject b) { jclass cls = (*env)->GetObjectClass(env, b); jmethodID mid = (*env)->GetMethodID(env, cls, "enabled", "()Z"); return (*env)->CallBooleanMethod(env, b, mid); } void scan(JNIEnv *env, jobject b) { jclass cls = (*env)->GetObjectClass(env, b); jmethodID mid = (*env)->GetMethodID(env, cls, "scan", "()V"); (*env)->CallVoidMethod(env, b, mid); } void stopScan(JNIEnv *env, jobject b) { jclass cls = (*env)->GetObjectClass(env, b); jmethodID mid = (*env)->GetMethodID(env, cls, "stopScan", "()V"); (*env)->CallVoidMethod(env, b, mid); } void connect(JNIEnv *env, jobject b, jobject d) { jclass cls = (*env)->GetObjectClass(env, b); jmethodID mid = (*env)->GetMethodID(env, cls, "connect", "(Lcom/welie/blessed/BluetoothPeripheral;)V"); (*env)->CallObjectMethod(env, b, mid, d); } void disconnect(JNIEnv *env, jobject b, jobject g) { jclass cls = (*env)->GetObjectClass(env, b); jmethodID mid = (*env)->GetMethodID(env, cls, "disconnect", "(Lcom/welie/blessed/BluetoothPeripheral;)V"); (*env)->CallVoidMethod(env, b, mid, g); } void discoverServices(JNIEnv *env, jobject b, jobject p) { jclass cls = (*env)->GetObjectClass(env, b); jmethodID mid = (*env)->GetMethodID(env, cls, "discoverServices", "(Lcom/welie/blessed/BluetoothPeripheral;)V"); (*env)->CallVoidMethod(env, b, mid, p); } void discoverCharacteristics(JNIEnv *env, jobject b, jobject g, jobject s) { jclass cls = (*env)->GetObjectClass(env, b); jmethodID mid = (*env)->GetMethodID(env, cls, "discoverCharacteristics", "(Lcom/welie/blessed/BluetoothPeripheral;Landroid/bluetooth/BluetoothGattService;)V"); (*env)->CallVoidMethod(env, b, mid, g, s); } jboolean setCharacteristicNotification(JNIEnv *env, jobject b, jobject g, jobject c) { jclass cls = (*env)->GetObjectClass(env, b); jmethodID mid = (*env)->GetMethodID(env, cls, "setCharacteristicNotification", "(Lcom/welie/blessed/BluetoothPeripheral;Landroid/bluetooth/BluetoothGattCharacteristic;)Z"); return (*env)->CallBooleanMethod(env, b, mid, g, c); } jint GetEnv(JavaVM *vm, JNIEnv **env, jint version) { return (*vm)->GetEnv(vm, (void **)env, version); } jint AttachCurrentThread(JavaVM *vm, JNIEnv **p_env, void *thr_args) { return (*vm)->AttachCurrentThread(vm, p_env, thr_args); } jint DetachCurrentThread(JavaVM *vm) { return (*vm)->DetachCurrentThread(vm); } jobject NewGlobalRef(JNIEnv *env, jobject o) { return (*env)->NewGlobalRef(env, o); } void Java_st_wow_git_ble_BlessedConnect_onScan(JNIEnv *env, jclass class, jstring jname, jstring jid, jint jrssi, jobject dev) { const char* name = (*env)->GetStringUTFChars(env, jname, NULL); const char* id = (*env)->GetStringUTFChars(env, jid, NULL); jobject gdev = (*env)->NewGlobalRef(env, dev); goOnScan(name, id, (int)jrssi, gdev); (*env)->ReleaseStringUTFChars(env, jname, name); (*env)->ReleaseStringUTFChars(env, jid, id); } void Java_st_wow_git_ble_BlessedConnect_onConnect(JNIEnv *env, jclass class, jobject gatt, jstring jid) { const char* id = (*env)->GetStringUTFChars(env, jid, NULL); jobject ggatt = (*env)->NewGlobalRef(env, gatt); goOnConnect(ggatt, id); (*env)->ReleaseStringUTFChars(env, jid, id); } void Java_st_wow_git_ble_BlessedConnect_onDiscoverService(JNIEnv *env, jclass class, jstring jid, jstring juuid, jobject serv) { const char* id = (*env)->GetStringUTFChars(env, jid, NULL); const char* uuid = (*env)->GetStringUTFChars(env, juuid, NULL); jobject gserv = (*env)->NewGlobalRef(env, serv); goOnDiscoverService(id, uuid, gserv); (*env)->ReleaseStringUTFChars(env, jid, id); (*env)->ReleaseStringUTFChars(env, juuid, uuid); } void Java_st_wow_git_ble_BlessedConnect_onDiscoverCharacteristic(JNIEnv *env, jclass class, jstring jid, jstring jsuuid, jobject serv, jstring jcuuid, jobject chr) { const char* id = (*env)->GetStringUTFChars(env, jid, NULL); const char* suuid = (*env)->GetStringUTFChars(env, jsuuid, NULL); const char* cuuid = (*env)->GetStringUTFChars(env, jcuuid, NULL); jobject gchr = (*env)->NewGlobalRef(env, chr); goOnDiscoverCharacteristic(id, suuid, serv, cuuid, gchr); (*env)->ReleaseStringUTFChars(env, jid, id); (*env)->ReleaseStringUTFChars(env, jsuuid, suuid); (*env)->ReleaseStringUTFChars(env, jcuuid, cuuid); } void Java_st_wow_git_ble_BlessedConnect_characteristicChanged(JNIEnv *env, jclass class, jstring jid, jstring jcuuid, jobject chr, jbyteArray jvalue, jint len) { const char* id = (*env)->GetStringUTFChars(env, jid, NULL); const char* cuuid = (*env)->GetStringUTFChars(env, jcuuid, NULL); jbyte* value = (*env)->GetByteArrayElements(env, jvalue, NULL); goOnCharacteristicChanged(id, cuuid, chr, value, len); (*env)->ReleaseStringUTFChars(env, jid, id); (*env)->ReleaseStringUTFChars(env, jcuuid, cuuid); (*env)->ReleaseByteArrayElements(env, jvalue, value, len); }