26#include "jau_direct_bt_DBTGattChar.h"
43 if(
nullptr != sref.
pointer() ) {
44 std::shared_ptr<BTGattChar>* sref_ptr = castInstance<BTGattChar>(nativeInstance);
55 JavaAnonRef characteristic_java = characteristic->getJavaObject();
56 JavaGlobalObj::check(characteristic_java,
E_FILE_LINE);
69 JavaAnonRef characteristic_java = characteristic->getJavaObject();
70 JavaGlobalObj::check(characteristic_java,
E_FILE_LINE);
81 [](JNIEnv *env_, jclass clazz, jmethodID clazz_ctor,
const BTGattDescRef& descriptor)->jobject {
83 std::shared_ptr<BTGattChar> _characteristic = descriptor->getGattCharUnchecked();
84 if(
nullptr == _characteristic ) {
87 JavaAnonRef _characteristic_java = _characteristic->getJavaObject();
88 JavaGlobalObj::check(_characteristic_java,
E_FILE_LINE);
89 jobject jcharacteristic = JavaGlobalObj::GetObject(_characteristic_java);
94 const size_t value_size = descriptor->value.size();
95 jbyteArray jval = env_->NewByteArray((jsize)value_size);
96 env_->SetByteArrayRegion(jval, 0, (jsize)value_size, (
const jbyte *)descriptor->value.get_ptr());
100 jobject jdesc = env_->NewObject(clazz, clazz_ctor, descriptor_sref.
release_to_jlong(), jcharacteristic,
101 juuid, (jshort)descriptor->handle, jval);
104 JavaAnonRef jDescRef = descriptor->getJavaObject();
106 env_->DeleteLocalRef(juuid);
107 env_->DeleteLocalRef(jval);
108 env_->DeleteLocalRef(jdesc);
109 return JavaGlobalObj::GetObject(jDescRef);
111 return convert_vector_sharedptr_to_jarraylist<jau::darray<BTGattDescRef>,
BTGattDesc>(
122 JavaAnonRef characteristic_java = characteristic->getJavaObject();
123 JavaGlobalObj::check(characteristic_java,
E_FILE_LINE);
126 if( !characteristic->readValue(res) ) {
127 ERR_PRINT(
"Characteristic readValue failed: %s", characteristic->
toString().c_str());
128 return env->NewByteArray((jsize)0);
131 const size_t value_size = res.
size();
132 jbyteArray jres = env->NewByteArray((jsize)value_size);
133 env->SetByteArrayRegion(jres, 0, (jsize)value_size, (
const jbyte *)res.
get_ptr());
146 JavaAnonRef characteristic_java = characteristic->getJavaObject();
147 JavaGlobalObj::check(characteristic_java,
E_FILE_LINE);
149 if(
nullptr == jval ) {
152 const int value_size = env->GetArrayLength(jval);
153 if( 0 == value_size ) {
158 uint8_t * value_ptr = criticalArray.
get(jval, criticalArray.Mode::NO_UPDATE_AND_RELEASE);
159 if(
nullptr == value_ptr ) {
165 res = characteristic->writeValue(value);
167 res = characteristic->writeValueNoResp(value);
170 ERR_PRINT(
"Characteristic writeValue(withResponse %d) failed: %s",
171 withResponse, characteristic->
toString().c_str());
182 jboolean enableNotification, jboolean enableIndication, jbooleanArray jEnabledState) {
185 if( characteristic.
is_null() ) {
186 if( !enableNotification && !enableIndication ) {
188 DBG_PRINT(
"Characteristic's native instance has been deleted");
193 JavaAnonRef characteristic_java = characteristic->getJavaObject();
194 JavaGlobalObj::check(characteristic_java,
E_FILE_LINE);
196 if(
nullptr == jEnabledState ) {
199 const int state_size = env->GetArrayLength(jEnabledState);
200 if( 2 > state_size ) {
204 jboolean * state_ptr = criticalArray.
get(jEnabledState, criticalArray.Mode::UPDATE_AND_RELEASE);
205 if(
nullptr == state_ptr ) {
209 bool cccdEnableResult[2];
210 bool res = characteristic->configNotificationIndication(enableNotification, enableIndication, cccdEnableResult);
211 DBG_PRINT(
"BTGattChar::configNotificationIndication Config Notification(%d), Indication(%d): Result %d",
212 cccdEnableResult[0], cccdEnableResult[1], res);
213 state_ptr[0] = cccdEnableResult[0];
214 state_ptr[1] = cccdEnableResult[1];
void Java_jau_direct_1bt_DBTGattChar_deleteImpl(JNIEnv *env, jobject obj, jlong nativeInstance)
jboolean Java_jau_direct_1bt_DBTGattChar_writeValueImpl(JNIEnv *env, jobject obj, jbyteArray jval, jboolean withResponse)
jboolean Java_jau_direct_1bt_DBTGattChar_configNotificationIndicationImpl(JNIEnv *env, jobject obj, jboolean enableNotification, jboolean enableIndication, jbooleanArray jEnabledState)
jbyteArray Java_jau_direct_1bt_DBTGattChar_readValueImpl(JNIEnv *env, jobject obj)
jstring Java_jau_direct_1bt_DBTGattChar_toStringImpl(JNIEnv *env, jobject obj)
static const std::string _descriptorClazzCtorArgs("(JLjau/direct_bt/DBTGattChar;Ljava/lang/String;S[B)V")
jobject Java_jau_direct_1bt_DBTGattChar_getDescriptorsImpl(JNIEnv *env, jobject obj)
Representing a Gatt Characteristic Descriptor object from the GATTRole::Client perspective.
Persistent endian aware octet data, i.e.
Transient read only and endian aware octet data, i.e.
constexpr nsize_t size() const noexcept
Returns the used memory size for read and write operations, may be zero.
constexpr uint8_t const * get_ptr() const noexcept
Class template jau::function is a general-purpose static-polymorphic function wrapper.
T * get(U jarray_val, Mode mode_val=UPDATE_AND_RELEASE)
Acquired the primitive array.
A std::shared_ptr<T> storage instance to be copied from and released into a java object's long native...
bool is_null() const noexcept
Returns true if either this instances shared_ptr<T> storage or the managed object reference is nullpt...
std::shared_ptr< T > * pointer() noexcept
Provides access to the shared_ptr<T> pointer, l-value of storage.
std::string toString() const noexcept
jlong release_to_jlong() noexcept
Release ownership and return the jlong representation of the shared_ptr<T> storage.
#define ERR_PRINT(...)
Use for unconditional error messages, prefix '[elapsed_time] Error @ FILE:LINE FUNC: '.
#define DBG_PRINT(...)
Use for environment-variable environment::DEBUG conditional debug messages, prefix '[elapsed_time] De...
@ little
Identifier for little endian, equivalent to endian::little.
std::string to_string(const alphabet &v) noexcept
std::shared_ptr< BTGattDesc > BTGattDescRef
constexpr uint32_t number(const iostate rhs) noexcept
void java_exception_check_and_throw(JNIEnv *env, const char *file, int line)
Throws a C++ exception if a java exception occurred, otherwise do nothing.
jstring from_string_to_jstring(JNIEnv *env, const std::string &str)
std::shared_ptr< JavaAnon > JavaAnonRef
#define rethrow_and_raise_java_exception(E)
Re-throw current exception and raise respective java exception using any matching function above.