Direct-BT
2.3.1
Direct-BT - Direct Bluetooth Programming.
|
Go to the documentation of this file.
26 #include "jau_direct_bt_DBTManager.h"
52 : opc(opc_), jmgmtRef(jmgmtRef_), mid(mid_) { }
59 return rhs.
opc == opc &&
64 {
return !( *
this == rhs ); }
70 const std::string &jmethodName,
const std::string &jmethodArgs)
79 env_->CallVoidMethod(*(ctx_ref->jmgmtRef), ctx_ref->mid, dev_id, ctx_ref->opc);
81 env_->CallVoidMethod(*(ctx_ref->jmgmtRef), ctx_ref->mid, dev_id, ctx_ref->opc);
86 env_->CallVoidMethod(*(ctx_ref->jmgmtRef), ctx_ref->mid, dev_id, ctx_ref->opc);
95 if(
nullptr == mgmtClazz ) {
98 jmethodID mid =
jau::search_method(env, mgmtClazz, jmethodName.c_str(), jmethodArgs.c_str(),
false);
100 if(
nullptr == mid ) {
118 setInstance<BTManager>(env, obj, manager);
127 DBG_PRINT(
"Java_jau_direct_1bt_DBTManager_init: Manager %s", manager->
toString().c_str());
137 BTManager *manager = castInstance<BTManager>(nativeInstance);
150 jbyteArray jaddr = env_->NewByteArray(
sizeof(addr));
151 env_->SetByteArrayRegion(jaddr, 0,
sizeof(addr), (
const jbyte*)(addr.
b));
155 jobject jAdapter = env_->NewObject(clazz, clazz_ctor, (jlong)adapter, jaddr, adapter->
getAddressAndType().
type, name, adapter->dev_id);
158 std::shared_ptr<JavaAnon> jAdapterRef = adapter->getJavaObject();
160 env_->DeleteLocalRef(jaddr);
161 env_->DeleteLocalRef(name);
162 env_->DeleteLocalRef(jAdapter);
164 DBG_PRINT(
"Java_jau_direct_1bt_DBTManager_createJavaAdapter: New Adapter %p %s", adapter, adapter->toString().c_str());
165 return JavaGlobalObj::GetObject(jAdapterRef);
171 BTManager *manager = getInstance<BTManager>(env, obj);
172 DBG_PRINT(
"Java_jau_direct_1bt_DBTManager_getAdapterListImpl: Manager %s", manager->
toString().c_str());
175 return convert_vector_sharedptr_to_jarraylist<jau::darray<std::shared_ptr<BTAdapter>>,
BTAdapter>(
186 BTManager *manager = getInstance<BTManager>(env, obj);
188 std::shared_ptr<BTAdapter> adapter = manager->
getAdapter(dev_id);
189 if(
nullptr == adapter ) {
190 ERR_PRINT(
"BTManager::getAdapterImpl: Adapter dev_id %d: Not found", dev_id);
193 DBG_PRINT(
"BTManager::getAdapterImpl: Adapter dev_id %d: %s", dev_id, adapter->
toString().c_str());
BDAddressAndType const & getAddressAndType() const noexcept
Returns the adapter's public BDAddressAndType.
void setJavaObject(std::shared_ptr< JavaAnon > objRef) noexcept
Assigns a new shared JavaAnon reference, replaced item might be deleted via JNI from dtor.
std::shared_ptr< JavaAnon > getJavaObject() noexcept
static const std::string _updatedAdapterCBMethodArgs("(II)V")
jau::FunctionDef< R, A... > bindCaptureFunc(const I &data, R(*func)(I &, A...), bool dataIsIdentity=true) noexcept
const I& data will be copied into the InvocationFunc<..> specialization and hence captured by copy.
jstring from_string_to_jstring(JNIEnv *env, const std::string &str)
jobject getObject() const noexcept
static jobject _createJavaAdapter(JNIEnv *env_, jclass clazz, jmethodID clazz_ctor, BTAdapter *adapter)
static const std::string _updatedAdapterCBMethodName("updatedAdapterCB")
jclass search_class(JNIEnv *env, const char *clazz_name)
std::string toString() const noexcept override
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.
void Java_jau_direct_1bt_DBTManager_deleteImpl(JNIEnv *env, jobject obj, jlong nativeInstance)
void setUnifyUUID128Bit(bool v)
uint16_t opcode, uint16_t dev-id, uint16_t param_size
thread_local JNIEnvContainer jni_env
DirectBTJNISettings directBTJNISettings
Implementation of a dynamic linear array storage, aka vector.
jmethodID search_method(JNIEnv *env, jclass clazz, const char *method_name, const char *prototype, bool is_static)
jau::darray< std::shared_ptr< BTAdapter > > getAdapters()
Returns a list of currently added DBTAdapter.
static uint16_t getDevID(const uint8_t *data)
std::string toString() const noexcept override
jobject Java_jau_direct_1bt_DBTManager_getAdapterListImpl(JNIEnv *env, jobject obj)
static void check(jobject object, const char *file, int line)
static BTManager & get(const BTMode defaultBTMode=BTMode::NONE)
Retrieves the singleton instance.
A thread safe singleton handler of the Linux Kernel's BlueZ manager control channel.
#define rethrow_and_raise_java_exception(E)
Re-throw current exception and raise respective java exception using any matching function above.
std::shared_ptr< BooleanMgmtCBContext > BooleanMgmtCBContextRef
Implementation for JavaAnon, by simply wrapping a JNIGlobalRef instance.
BTAdapter represents one Bluetooth Controller.
static const std::string _removeAdapterCBMethodName("removeAdapterCB")
A packed 48 bit EUI-48 identifier, formerly known as MAC-48 or simply network device MAC address (Med...
#define ERR_PRINT(...)
Use for unconditional error messages, prefix '[elapsed_time] Error @ FILE:LINE: '.
bool operator==(const BooleanMgmtCBContext &rhs) const
static const std::string _adapterClazzCtorArgs("(J[BBLjava/lang/String;I)V")
BooleanMgmtCBContext(MgmtEvent::Opcode opc_, JNIGlobalRef jmgmtRef_, jmethodID mid_)
static const std::string _removeAdapterCBMethodArgs("(II)V")
static void _addMgmtCBOnce(JNIEnv *env, BTManager &mgmt, JNIGlobalRef jmgmtRef, MgmtEvent::Opcode opc, const std::string &jmethodName, const std::string &jmethodArgs)
bool operator!=(const BooleanMgmtCBContext &rhs) const
bool addMgmtEventCallback(const int dev_id, const MgmtEvent::Opcode opc, const MgmtEventCallback &cb) noexcept
MgmtEventCallback handling
constexpr bool isAdapterSettingBitSet(const AdapterSetting mask, const AdapterSetting bit) noexcept
std::shared_ptr< BTAdapter > getAdapter(const uint16_t dev_id) const noexcept
Returns the DBTAdapter with the given dev_id, or nullptr if not found.
std::string getName() const noexcept
Returns the system name.
BTMode
Bluetooth adapter operating mode.
jobject Java_jau_direct_1bt_DBTManager_getAdapterImpl(JNIEnv *env, jobject obj, jint dev_id)
#define DBG_PRINT(...)
Use for environment-variable environment::DEBUG conditional debug messages, prefix '[elapsed_time] De...
void Java_jau_direct_1bt_DBTManager_initImpl(JNIEnv *env, jobject obj, jboolean unifyUUID128Bit, jint jbtMode)