26#include "jau_direct_bt_DBTManager.h"
64 {
return !( *
this == rhs ); }
70 const std::string &jmethodName,
const std::string &jmethodArgs)
78 if( MgmtEvent::Opcode::INDEX_REMOVED == ctx_ref->opc ) {
79 env_->CallVoidMethod(*(ctx_ref->jmgmtRef), ctx_ref->mid, dev_id, ctx_ref->opc);
80 }
else if( MgmtEvent::Opcode::INDEX_ADDED == ctx_ref->opc ) {
81 env_->CallVoidMethod(*(ctx_ref->jmgmtRef), ctx_ref->mid, dev_id, ctx_ref->opc);
82 }
else if( MgmtEvent::Opcode::NEW_SETTINGS == ctx_ref->opc ) {
86 env_->CallVoidMethod(*(ctx_ref->jmgmtRef), ctx_ref->mid, dev_id, ctx_ref->opc);
94 if(
nullptr == mgmtClazz ) {
97 jmethodID mid =
search_method(env, mgmtClazz, jmethodName.c_str(), jmethodArgs.c_str(),
false);
99 if(
nullptr == mid ) {
117 ref->setJavaObject( std::make_shared<JavaGlobalObj>( std::move(global_obj),
nullptr ) );
118 JavaGlobalObj::check(ref->getJavaObject(),
E_FILE_LINE);
120 JNIGlobalRef jmgmtRef = JavaGlobalObj::GetJavaObject(ref->getJavaObject());
124 DBG_PRINT(
"Java_jau_direct_1bt_DBTManager_init: Manager %s", ref->
toString().c_str());
129 return (jlong) (intptr_t)
nullptr;
137 if(
nullptr != manager.
pointer() ) {
139 JavaAnonRef manager_java = manager->getJavaObject();
141 manager->setJavaObject();
144 std::shared_ptr<BTManager>* ref_ptr = castInstance<BTManager>(nativeInstance);
153static jobject
_createJavaAdapter(JNIEnv *env_, jclass clazz, jmethodID clazz_ctor,
const std::shared_ptr<BTAdapter>& adapter) {
155 const EUI48 addr = adapter->getAddressAndType().address;
156 jbyteArray jaddr = env_->NewByteArray(
sizeof(addr));
157 env_->SetByteArrayRegion(jaddr, 0,
sizeof(addr), (
const jbyte*)(addr.
b));
162 jobject jAdapter = env_->NewObject(clazz, clazz_ctor, adapter_ref.
release_to_jlong(), jaddr, adapter->getAddressAndType().type, name, adapter->dev_id);
165 JavaAnonRef jAdapterRef = adapter->getJavaObject();
167 env_->DeleteLocalRef(jaddr);
168 env_->DeleteLocalRef(name);
169 env_->DeleteLocalRef(jAdapter);
171 DBG_PRINT(
"Java_jau_direct_1bt_DBTManager_createJavaAdapter: New Adapter %p %s", adapter.get(), adapter->toString().c_str());
172 return JavaGlobalObj::GetObject(jAdapterRef);
179 DBG_PRINT(
"Java_jau_direct_1bt_DBTManager_getAdapterListImpl: Manager %s", ref->
toString().c_str());
182 return convert_vector_sharedptr_to_jarraylist<jau::darray<std::shared_ptr<BTAdapter>>,
BTAdapter>(
195 std::shared_ptr<BTAdapter> adapter = ref->getAdapter(dev_id);
196 if(
nullptr == adapter ) {
197 ERR_PRINT(
"BTManager::getAdapterImpl: Adapter dev_id %d: Not found", dev_id);
200 DBG_PRINT(
"BTManager::getAdapterImpl: Adapter dev_id %d: %s", dev_id, adapter->toString().c_str());
static void _addMgmtCBOnce(JNIEnv *env, BTManager &mgmt, const JNIGlobalRef &jmgmtRef, MgmtEvent::Opcode opc, const std::string &jmethodName, const std::string &jmethodArgs)
static const std::string _removeAdapterCBMethodArgs("(II)V")
jobject Java_jau_direct_1bt_DBTManager_getAdapterListImpl(JNIEnv *env, jobject obj)
jlong Java_jau_direct_1bt_DBTManager_ctorImpl(JNIEnv *env, jobject obj)
static const std::string _adapterClazzCtorArgs("(J[BBLjava/lang/String;I)V")
jobject Java_jau_direct_1bt_DBTManager_getAdapterImpl(JNIEnv *env, jobject obj, jint dev_id)
static const std::string _updatedAdapterCBMethodArgs("(II)V")
void Java_jau_direct_1bt_DBTManager_dtorImpl(JNIEnv *env, jobject obj, jlong nativeInstance)
std::shared_ptr< BooleanMgmtCBContext > BooleanMgmtCBContextRef
static jobject _createJavaAdapter(JNIEnv *env_, jclass clazz, jmethodID clazz_ctor, const std::shared_ptr< BTAdapter > &adapter)
static const std::string _updatedAdapterCBMethodName("updatedAdapterCB")
static const std::string _removeAdapterCBMethodName("removeAdapterCB")
BTAdapter represents one local Bluetooth Controller.
A thread safe singleton handler of the BTAdapter manager, e.g.
std::string toString() const noexcept override
bool addMgmtEventCallback(const int dev_id, const MgmtEvent::Opcode opc, const MgmtEventCallback &cb) noexcept
MgmtEventCallback handling
uint16_t opcode, uint16_t dev-id, uint16_t param_size
static uint16_t getDevID(const uint8_t *data)
Implementation of a dynamic linear array storage, aka vector.
Class template jau::function is a general-purpose static-polymorphic function wrapper.
jobject getObject() const noexcept
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...
Entry * get(const EUI48 &addr, const std::string &name, AddressNameEntryMatchFunc m) noexcept
Returns a matching BTSecurityRegistry::Entry with the given addr and/or name.
constexpr bool isAdapterSettingBitSet(const AdapterSetting mask, const AdapterSetting bit) noexcept
jau::function< R(A...)> bind_capval(const I &data, R(*func)(I &, A...)) noexcept
Bind given data by copying the captured value and the given non-void function to an anonymous functio...
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.
thread_local JNIEnvContainer jni_env
jstring from_string_to_jstring(JNIEnv *env, const std::string &str)
jmethodID search_method(JNIEnv *env, jclass clazz, const char *method_name, const char *prototype, bool is_static)
std::shared_ptr< JavaAnon > JavaAnonRef
jclass search_class(JNIEnv *env, const char *clazz_name)
#define rethrow_and_raise_java_exception(E)
Re-throw current exception and raise respective java exception using any matching function above.
bool operator!=(const BooleanMgmtCBContext &rhs) const
BooleanMgmtCBContext(MgmtEvent::Opcode opc_, JNIGlobalRef jmgmtRef_, jmethodID mid_)
bool operator==(const BooleanMgmtCBContext &rhs) const
A packed 48 bit EUI-48 identifier, formerly known as MAC-48 or simply network device MAC address (Med...