26 #include "jau_direct_bt_DBTGattChar.h"
41 BTGattChar *nativePtr = getJavaUplinkObject<BTGattChar>(env, obj);
53 BTGattChar *characteristic = castInstance<BTGattChar>(nativeInstance);
65 BTGattChar *characteristic = getJavaUplinkObject<BTGattChar>(env, obj);
76 std::function<jobject(JNIEnv*, jclass, jmethodID,
BTGattDesc *)> ctor_desc =
77 [](JNIEnv *env_, jclass clazz, jmethodID clazz_ctor,
BTGattDesc *descriptor)->jobject {
79 std::shared_ptr<BTGattChar> _characteristic = descriptor->getGattCharChecked();
81 jobject jcharacteristic = JavaGlobalObj::GetObject(_characteristic->
getJavaObject());
85 descriptor->type->toString());
88 const size_t value_size = descriptor->value.getSize();
89 jbyteArray jval = env_->NewByteArray((jsize)value_size);
90 env_->SetByteArrayRegion(jval, 0, (jsize)value_size, (
const jbyte *)descriptor->value.get_ptr());
93 jobject jdesc = env_->NewObject(clazz, clazz_ctor, (jlong)descriptor, jcharacteristic,
94 juuid, (jshort)descriptor->handle, jval);
97 std::shared_ptr<JavaAnon> jDescRef = descriptor->getJavaObject();
99 env_->DeleteLocalRef(juuid);
100 env_->DeleteLocalRef(jval);
101 env_->DeleteLocalRef(jdesc);
102 return JavaGlobalObj::GetObject(jDescRef);
104 return convert_vector_sharedptr_to_jarraylist<jau::darray<BTGattDescRef>,
BTGattDesc>(
114 BTGattChar *characteristic = getJavaUplinkObject<BTGattChar>(env, obj);
119 ERR_PRINT(
"Characteristic readValue failed: %s", characteristic->
toString().c_str());
120 return env->NewByteArray((jsize)0);
123 const size_t value_size = res.
getSize();
124 jbyteArray jres = env->NewByteArray((jsize)value_size);
125 env->SetByteArrayRegion(jres, 0, (jsize)value_size, (
const jbyte *)res.
get_ptr());
137 if(
nullptr == jval ) {
140 const int value_size = env->GetArrayLength(jval);
141 if( 0 == value_size ) {
144 BTGattChar *characteristic = getJavaUplinkObject<BTGattChar>(env, obj);
148 uint8_t * value_ptr = criticalArray.
get(jval, criticalArray.Mode::NO_UPDATE_AND_RELEASE);
149 if( NULL == value_ptr ) {
160 ERR_PRINT(
"Characteristic writeValue(withResponse %d) failed: %s",
161 withResponse, characteristic->
toString().c_str());
172 jboolean enableNotification, jboolean enableIndication, jbooleanArray jEnabledState) {
174 BTGattChar *characteristic = getJavaUplinkObjectUnchecked<BTGattChar>(env, obj);
175 if(
nullptr == characteristic ) {
176 if( !enableNotification && !enableIndication ) {
178 DBG_PRINT(
"Characteristic's native instance has been deleted");
185 if(
nullptr == jEnabledState ) {
188 const int state_size = env->GetArrayLength(jEnabledState);
189 if( 2 > state_size ) {
193 jboolean * state_ptr = criticalArray.
get(jEnabledState, criticalArray.Mode::UPDATE_AND_RELEASE);
194 if( NULL == state_ptr ) {
198 bool cccdEnableResult[2];
200 DBG_PRINT(
"BTGattChar::configNotificationIndication Config Notification(%d), Indication(%d): Result %d",
201 cccdEnableResult[0], cccdEnableResult[1], res);
202 state_ptr[0] = cccdEnableResult[0];
203 state_ptr[1] = cccdEnableResult[1];