summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.cproject50
-rw-r--r--.settings/language.settings.xml4
-rw-r--r--api/direct_bt/ATTPDUTypes.hpp50
-rw-r--r--api/direct_bt/BTTypes.hpp12
-rw-r--r--api/direct_bt/DBTAdapter.hpp9
-rw-r--r--api/direct_bt/DBTManager.hpp13
-rw-r--r--api/direct_bt/DBTTypes.hpp11
-rw-r--r--api/direct_bt/GATTCharacteristic.hpp3
-rw-r--r--api/direct_bt/GATTHandler.hpp9
-rw-r--r--api/direct_bt/GATTNumbers.hpp4
-rw-r--r--api/direct_bt/GATTService.hpp4
-rw-r--r--api/direct_bt/GATTTypes.hpp4
-rw-r--r--api/direct_bt/HCIHandler.hpp21
-rw-r--r--api/direct_bt/HCITypes.hpp58
-rw-r--r--api/direct_bt/L2CAPComm.hpp5
-rw-r--r--api/direct_bt/MgmtTypes.hpp68
-rw-r--r--api/direct_bt/OctetTypes.hpp51
-rw-r--r--api/direct_bt/UUID.hpp36
-rw-r--r--examples/CMakeLists.txt5
-rw-r--r--examples/direct_bt_scanner00/dbt_scanner00.cpp6
-rw-r--r--examples/direct_bt_scanner01/dbt_scanner01.cpp6
-rw-r--r--examples/direct_bt_scanner10/dbt_scanner10.cpp5
-rw-r--r--jaucpp/include/cppunit/cppunit.h110
-rw-r--r--jaucpp/include/jau/basic_algos.hpp (renamed from api/direct_bt/BasicAlgos.hpp)10
-rw-r--r--jaucpp/include/jau/basic_types.hpp (renamed from api/direct_bt/BasicTypes.hpp)19
-rw-r--r--jaucpp/include/jau/debug.hpp (renamed from api/direct_bt/dbt_debug.hpp)43
-rw-r--r--jaucpp/include/jau/dfa_utf8_decode.hpp (renamed from api/direct_bt/dfa_utf8_decode.hpp)36
-rw-r--r--jaucpp/include/jau/environment.hpp (renamed from api/direct_bt/DBTEnv.hpp)30
-rw-r--r--jaucpp/include/jau/function_def.hpp (renamed from api/direct_bt/FunctionDef.hpp)12
-rw-r--r--jaucpp/include/jau/java_uplink.hpp (renamed from api/direct_bt/JavaUplink.hpp)39
-rw-r--r--jaucpp/include/jau/jni/helper_jni.hpp434
-rw-r--r--jaucpp/include/jau/jni/jni_mem.hpp (renamed from java/jni/JNIMem.hpp)16
-rw-r--r--jaucpp/include/jau/ordered_atomic.hpp (renamed from api/direct_bt/OrderedAtomic.hpp)10
-rw-r--r--jaucpp/include/jau/ringbuffer.hpp (renamed from api/direct_bt/LFRingbuffer.hpp)54
-rw-r--r--jaucpp/include/jau/ringbuffer_if.hpp (renamed from api/direct_bt/Ringbuffer.hpp)17
-rw-r--r--jaucpp/java/jni/helper_jni.cxx354
-rw-r--r--jaucpp/java/jni/jni_mem.cxx (renamed from java/jni/JNIMem.cxx)24
-rw-r--r--jaucpp/src/basic_types.cpp (renamed from src/direct_bt/BasicTypes.cpp)42
-rw-r--r--jaucpp/src/debug.cpp (renamed from src/direct_bt/dbt_debug.cpp)54
-rw-r--r--jaucpp/src/dfa_utf8_decode.cpp (renamed from src/direct_bt/dfa_utf8_decode.cpp)8
-rw-r--r--jaucpp/src/environment.cpp (renamed from src/direct_bt/DBTEnv.cpp)76
-rw-r--r--jaucpp/test/CMakeLists.txt72
-rw-r--r--jaucpp/test/README.txt11
-rw-r--r--jaucpp/test/test_basictypes01.cpp (renamed from test/direct_bt/test_basictypes01.cpp)14
-rw-r--r--jaucpp/test/test_functiondef01.cpp (renamed from test/direct_bt/test_functiondef01.cpp)4
-rw-r--r--jaucpp/test/test_lfringbuffer01.cpp (renamed from test/direct_bt/test_lfringbuffer01.cpp)33
-rw-r--r--jaucpp/test/test_lfringbuffer11.cpp (renamed from test/direct_bt/test_lfringbuffer11.cpp)17
-rw-r--r--jaucpp/test/test_mm_sc_drf_00.cpp (renamed from test/direct_bt/test_mm_sc_drf_00.cpp)4
-rw-r--r--jaucpp/test/test_mm_sc_drf_01.cpp (renamed from test/direct_bt/test_mm_sc_drf_01.cpp)4
-rw-r--r--java/jni/BluetoothFactory.cxx3
-rw-r--r--java/jni/BluetoothUtils.cxx9
-rw-r--r--java/jni/direct_bt/CMakeLists.txt4
-rw-r--r--java/jni/direct_bt/DBTAdapter.cxx325
-rw-r--r--java/jni/direct_bt/DBTDevice.cxx74
-rw-r--r--java/jni/direct_bt/DBTGattCharacteristic.cxx17
-rw-r--r--java/jni/direct_bt/DBTGattDescriptor.cxx12
-rw-r--r--java/jni/direct_bt/DBTGattService.cxx10
-rw-r--r--java/jni/direct_bt/DBTManager.cxx8
-rw-r--r--java/jni/direct_bt/DBTNativeDownlink.cxx4
-rw-r--r--java/jni/direct_bt/DBTObject.cxx1
-rw-r--r--java/jni/direct_bt/helper_dbt.cxx23
-rw-r--r--java/jni/direct_bt/helper_dbt.hpp128
-rw-r--r--java/jni/helper_base.cxx290
-rw-r--r--java/jni/helper_base.hpp225
-rw-r--r--java/jni/tinyb/CMakeLists.txt6
-rw-r--r--java/jni/tinyb/DBusAdapter.cxx2
-rw-r--r--java/jni/tinyb/DBusDevice.cxx2
-rw-r--r--java/jni/tinyb/DBusGattCharacteristic.cxx2
-rw-r--r--java/jni/tinyb/DBusGattDescriptor.cxx2
-rw-r--r--java/jni/tinyb/DBusGattService.cxx1
-rw-r--r--java/jni/tinyb/DBusManager.cxx1
-rw-r--r--java/jni/tinyb/DBusObject.cxx1
-rw-r--r--java/jni/tinyb/helper_tinyb.cxx2
-rw-r--r--java/jni/tinyb/helper_tinyb.hpp1
-rw-r--r--src/direct_bt/ATTPDUTypes.cpp3
-rw-r--r--src/direct_bt/BTTypes.cpp33
-rw-r--r--src/direct_bt/CMakeLists.txt9
-rw-r--r--src/direct_bt/DBTAdapter.cpp42
-rw-r--r--src/direct_bt/DBTDevice.cpp32
-rw-r--r--src/direct_bt/DBTManager.cpp58
-rw-r--r--src/direct_bt/DBTTypes.cpp2
-rw-r--r--src/direct_bt/GATTCharacteristic.cpp4
-rw-r--r--src/direct_bt/GATTDescriptor.cpp4
-rw-r--r--src/direct_bt/GATTHandler.cpp17
-rw-r--r--src/direct_bt/GATTNumbers.cpp14
-rw-r--r--src/direct_bt/GATTService.cpp4
-rw-r--r--src/direct_bt/HCIComm.cpp2
-rw-r--r--src/direct_bt/HCIHandler.cpp64
-rw-r--r--src/direct_bt/HCITypes.cpp9
-rw-r--r--src/direct_bt/L2CAPComm.cpp18
-rw-r--r--src/direct_bt/MgmtTypes.cpp15
-rw-r--r--src/direct_bt/UUID.cpp61
-rw-r--r--src/ieee11073/DataTypes.cpp4
-rw-r--r--src/tinyb/CMakeLists.txt9
-rw-r--r--test/direct_bt/CMakeLists.txt67
95 files changed, 2008 insertions, 1597 deletions
diff --git a/.cproject b/.cproject
index 64d67df5..4d4bd784 100644
--- a/.cproject
+++ b/.cproject
@@ -18,10 +18,10 @@
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
- <configuration artifactName="dbt_scanner0" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.so.debug.368873367" name="Debug" parent="cdt.managedbuild.config.gnu.so.debug">
+ <configuration artifactName="dbt_scanner0" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug" cleanCommand="rm -rf" description="" errorParsers="org.eclipse.cdt.core.GASErrorParser;org.eclipse.cdt.core.GLDErrorParser;org.eclipse.cdt.core.GCCErrorParser" id="cdt.managedbuild.config.gnu.so.debug.368873367" name="Debug" parent="cdt.managedbuild.config.gnu.so.debug">
<folderInfo id="cdt.managedbuild.config.gnu.so.debug.368873367." name="/" resourcePath="">
<toolChain id="cdt.managedbuild.toolchain.gnu.so.debug.1276064502" name="Linux GCC" nonInternalBuilderId="cdt.managedbuild.target.gnu.builder.so.debug" superClass="cdt.managedbuild.toolchain.gnu.so.debug">
- <targetPlatform id="cdt.managedbuild.target.gnu.platform.so.debug.1970401811" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.so.debug"/>
+ <targetPlatform binaryParser="org.eclipse.cdt.core.GNU_ELF" id="cdt.managedbuild.target.gnu.platform.so.debug.1970401811" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.so.debug"/>
<builder autoBuildTarget="all" buildPath="${workspace_loc:/direct_bt}/Debug" cleanBuildTarget="clean" id="org.eclipse.cdt.build.core.internal.builder.1216391278" incrementalBuildTarget="all" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="CDT Internal Builder" superClass="org.eclipse.cdt.build.core.internal.builder"/>
<tool id="cdt.managedbuild.tool.gnu.archiver.base.704612215" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.so.debug.1624002274" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.so.debug">
@@ -29,13 +29,14 @@
<option defaultValue="gnu.cpp.compiler.debugging.level.max" id="gnu.cpp.compiler.so.debug.option.debugging.level.386385021" name="Debug Level" superClass="gnu.cpp.compiler.so.debug.option.debugging.level" useByScannerDiscovery="false" valueType="enumerated"/>
<option id="gnu.cpp.compiler.option.dialect.std.707637909" name="Language standard" superClass="gnu.cpp.compiler.option.dialect.std" useByScannerDiscovery="true" value="gnu.cpp.compiler.dialect.c++17" valueType="enumerated"/>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="gnu.cpp.compiler.option.include.paths.547715194" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
+ <listOptionValue builtIn="false" value="/usr/include/c++/10/"/>
+ <listOptionValue builtIn="false" value="&quot;${workspace_loc:/direct_bt/jaucpp/include}&quot;"/>
<listOptionValue builtIn="false" value="/opt-linux-x86_64/jdk1.8.0_121/include/"/>
<listOptionValue builtIn="false" value="/opt-linux-x86_64/jdk1.8.0_121/include/linux/"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/direct_bt/api/direct_bt}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/direct_bt/api}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/direct_bt/include/cppunit}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/direct_bt/include}&quot;"/>
- <listOptionValue builtIn="false" value="/usr/include/c++/10/"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/direct_bt/java/jni}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/direct_bt/build-amd64/java/CMakeFiles/tinybjar.dir/jni}&quot;"/>
</option>
@@ -54,6 +55,7 @@
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/direct_bt/api}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/direct_bt/include}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/direct_bt/include/cppunit}&quot;"/>
+ <listOptionValue builtIn="false" value="&quot;${workspace_loc:/direct_bt/jaucpp/include}&quot;"/>
</option>
<option id="gnu.c.compiler.option.pthread.858610172" name="Support for pthread (-pthread)" superClass="gnu.c.compiler.option.pthread" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="gnu.c.compiler.option.warnings.extrawarn.1874778119" name="Extra warnings (-Wextra)" superClass="gnu.c.compiler.option.warnings.extrawarn" useByScannerDiscovery="false" value="true" valueType="boolean"/>
@@ -66,6 +68,9 @@
<tool id="cdt.managedbuild.tool.gnu.cpp.linker.so.debug.603785955" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.so.debug">
<option defaultValue="true" id="gnu.cpp.link.so.debug.option.shared.486082612" name="Shared (-shared)" superClass="gnu.cpp.link.so.debug.option.shared" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="gnu.cpp.link.option.flags.1618463684" name="Linker flags" superClass="gnu.cpp.link.option.flags" useByScannerDiscovery="false" value="-pthread" valueType="string"/>
+ <option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="gnu.cpp.link.option.libs.1756006306" name="Libraries (-l)" superClass="gnu.cpp.link.option.libs" valueType="libs">
+ <listOptionValue builtIn="false" value="unwind"/>
+ </option>
<inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.503379509" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
@@ -80,17 +85,55 @@
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/direct_bt/api}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/direct_bt/include}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/direct_bt/include/cppunit}&quot;"/>
+ <listOptionValue builtIn="false" value="&quot;${workspace_loc:/direct_bt/jaucpp/include}&quot;"/>
</option>
<inputType id="cdt.managedbuild.tool.gnu.assembler.input.1065330340" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
</tool>
</toolChain>
</folderInfo>
+ <folderInfo id="cdt.managedbuild.config.gnu.so.debug.368873367.842993498" name="/" resourcePath="jaucpp">
+ <toolChain id="cdt.managedbuild.toolchain.gnu.so.debug.779868031" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.so.debug" unusedChildren="">
+ <targetPlatform id="cdt.managedbuild.target.gnu.platform.so.debug" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.so.debug"/>
+ <tool id="cdt.managedbuild.tool.gnu.archiver.base.417167386" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base.704612215"/>
+ <tool id="cdt.managedbuild.tool.gnu.cpp.compiler.so.debug.191513174" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.so.debug.1624002274">
+ <inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.876249905" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
+ </tool>
+ <tool id="cdt.managedbuild.tool.gnu.c.compiler.so.debug.306787993" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.so.debug.1384284733">
+ <option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="gnu.c.compiler.option.include.paths.1717870340" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
+ <listOptionValue builtIn="false" value="&quot;${workspace_loc:/direct_bt/jaucpp/include}&quot;"/>
+ <listOptionValue builtIn="false" value="/opt-linux-x86_64/jdk1.8.0_121/include/"/>
+ <listOptionValue builtIn="false" value="/opt-linux-x86_64/jdk1.8.0_121/include/linux/"/>
+ <listOptionValue builtIn="false" value="&quot;${workspace_loc:/direct_bt/api/direct_bt}&quot;"/>
+ <listOptionValue builtIn="false" value="&quot;${workspace_loc:/direct_bt/api}&quot;"/>
+ <listOptionValue builtIn="false" value="&quot;${workspace_loc:/direct_bt/include}&quot;"/>
+ <listOptionValue builtIn="false" value="&quot;${workspace_loc:/direct_bt/include/cppunit}&quot;"/>
+ </option>
+ <inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1824231521" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
+ </tool>
+ <tool id="cdt.managedbuild.tool.gnu.c.linker.so.debug.1551822587" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.so.debug.304323896"/>
+ <tool id="cdt.managedbuild.tool.gnu.cpp.linker.so.debug.407141367" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.so.debug.603785955"/>
+ <tool id="cdt.managedbuild.tool.gnu.assembler.so.debug.188335344" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.so.debug.21349791">
+ <option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="gnu.both.asm.option.include.paths.1517626135" name="Include paths (-I)" superClass="gnu.both.asm.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
+ <listOptionValue builtIn="false" value="&quot;${workspace_loc:/direct_bt/jaucpp/include}&quot;"/>
+ <listOptionValue builtIn="false" value="/opt-linux-x86_64/jdk1.8.0_121/include/"/>
+ <listOptionValue builtIn="false" value="/opt-linux-x86_64/jdk1.8.0_121/include/linux/"/>
+ <listOptionValue builtIn="false" value="&quot;${workspace_loc:/direct_bt/api/direct_bt}&quot;"/>
+ <listOptionValue builtIn="false" value="&quot;${workspace_loc:/direct_bt/api}&quot;"/>
+ <listOptionValue builtIn="false" value="&quot;${workspace_loc:/direct_bt/include}&quot;"/>
+ <listOptionValue builtIn="false" value="&quot;${workspace_loc:/direct_bt/include/cppunit}&quot;"/>
+ </option>
+ <inputType id="cdt.managedbuild.tool.gnu.assembler.input.1761771259" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
+ </tool>
+ </toolChain>
+ </folderInfo>
<sourceEntries>
<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="api/direct_bt"/>
<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="api/ieee11073"/>
<entry excluding="direct_bt/|tinyb/" flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="build-amd64/src"/>
<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="examples/direct_bt_scanner10"/>
<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="include/cppunit"/>
+ <entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="jaucpp/java/jni"/>
+ <entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="jaucpp/src"/>
<entry excluding="tinyb/" flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="java/jni"/>
<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="src/direct_bt"/>
<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="src/ieee11073"/>
@@ -130,6 +173,7 @@
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="gnu.cpp.compiler.option.include.paths.574040271" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/direct_bt/api/direct_bt}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/direct_bt/include/cppunit}&quot;"/>
+ <listOptionValue builtIn="false" value="&quot;${workspace_loc:/direct_bt/jaucpp/include}&quot;"/>
</option>
<option id="gnu.cpp.compiler.option.dialect.std.216768146" name="Language standard" superClass="gnu.cpp.compiler.option.dialect.std" useByScannerDiscovery="true" value="gnu.cpp.compiler.dialect.c++17" valueType="enumerated"/>
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.717986153" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
diff --git a/.settings/language.settings.xml b/.settings/language.settings.xml
index b89bb49f..cea69134 100644
--- a/.settings/language.settings.xml
+++ b/.settings/language.settings.xml
@@ -5,7 +5,7 @@
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
- <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1566207571723381920" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+ <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1566284796311381920" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
@@ -16,7 +16,7 @@
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
- <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1566207571723381920" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+ <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1566284796311381920" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
diff --git a/api/direct_bt/ATTPDUTypes.hpp b/api/direct_bt/ATTPDUTypes.hpp
index b0b709f1..e890fef8 100644
--- a/api/direct_bt/ATTPDUTypes.hpp
+++ b/api/direct_bt/ATTPDUTypes.hpp
@@ -35,6 +35,8 @@
#include <mutex>
#include <atomic>
+#include <jau/basic_types.hpp>
+
#include "UUID.hpp"
#include "BTTypes.hpp"
@@ -120,7 +122,7 @@
*/
namespace direct_bt {
- class AttException : public RuntimeException {
+ class AttException : public jau::RuntimeException {
protected:
AttException(std::string const type, std::string const m, const char* file, int line) noexcept
: RuntimeException(type, m, file, line) {}
@@ -315,27 +317,27 @@ namespace direct_bt {
{
const Opcode has = getOpcode();
if( expected != has ) {
- throw AttOpcodeException("Has opcode "+uint8HexString(has, true)+" "+getOpcodeString(has)+
- ", but expected "+uint8HexString(expected, true)+" "+getOpcodeString(expected), E_FILE_LINE);
+ throw AttOpcodeException("Has opcode "+jau::uint8HexString(has, true)+" "+getOpcodeString(has)+
+ ", but expected "+jau::uint8HexString(expected, true)+" "+getOpcodeString(expected), E_FILE_LINE);
}
}
void checkOpcode(const Opcode exp1, const Opcode exp2) const
{
const Opcode has = getOpcode();
if( exp1 != has && exp2 != has ) {
- throw AttOpcodeException("Has opcode "+uint8HexString(has, true)+" "+getOpcodeString(has)+
- ", but expected either "+uint8HexString(exp1, true)+" "+getOpcodeString(exp1)+
- " or "+uint8HexString(exp1, true)+" "+getOpcodeString(exp1), E_FILE_LINE);
+ throw AttOpcodeException("Has opcode "+jau::uint8HexString(has, true)+" "+getOpcodeString(has)+
+ ", but expected either "+jau::uint8HexString(exp1, true)+" "+getOpcodeString(exp1)+
+ " or "+jau::uint8HexString(exp1, true)+" "+getOpcodeString(exp1), E_FILE_LINE);
}
}
virtual std::string baseString() const noexcept {
- return "opcode="+uint8HexString(getOpcode(), true)+" "+getOpcodeString()+
+ return "opcode="+jau::uint8HexString(getOpcode(), true)+" "+getOpcodeString()+
", size[total="+std::to_string(pdu.getSize())+", param "+std::to_string(getPDUParamSize())+"]";
}
virtual std::string valueString() const noexcept {
return "size "+std::to_string(getPDUValueSize())+", data "
- +bytesHexString(pdu.get_ptr(), getPDUValueOffset(), getPDUValueSize(), true /* lsbFirst */, true /* leading0X */);
+ +jau::bytesHexString(pdu.get_ptr(), getPDUValueOffset(), getPDUValueSize(), true /* lsbFirst */, true /* leading0X */);
}
public:
@@ -355,14 +357,14 @@ namespace direct_bt {
/** Persistent memory, w/ ownership ..*/
AttPDUMsg(const uint8_t* source, const int size)
- : pdu(source, std::max(1, size)), ts_creation(getCurrentMilliseconds())
+ : pdu(source, std::max(1, size)), ts_creation(jau::getCurrentMilliseconds())
{
pdu.check_range(0, getPDUMinSize());
}
/** Persistent memory, w/ ownership ..*/
AttPDUMsg(const Opcode opc, const int size)
- : pdu(std::max(1, size)), ts_creation(getCurrentMilliseconds())
+ : pdu(std::max(1, size)), ts_creation(jau::getCurrentMilliseconds())
{
pdu.put_uint8_nc(0, opc);
pdu.check_range(0, getPDUMinSize());
@@ -571,7 +573,7 @@ namespace direct_bt {
std::string getErrorString() const noexcept {
const ErrorCode ec = getErrorCode();
- return uint8HexString(ec, true) + ": " + getPlainErrorString(ec);
+ return jau::uint8HexString(ec, true) + ": " + getPlainErrorString(ec);
}
std::string getName() const noexcept override {
@@ -656,7 +658,7 @@ namespace direct_bt {
protected:
std::string valueString() const noexcept override {
- return "handle "+uint16HexString(getHandle(), true);
+ return "handle "+jau::uint16HexString(getHandle(), true);
}
};
@@ -741,7 +743,7 @@ namespace direct_bt {
protected:
std::string valueString() const noexcept override {
- return "handle "+uint16HexString(getHandle(), true)+", valueOffset "+uint16HexString(getValueOffset(), true);
+ return "handle "+jau::uint16HexString(getHandle(), true)+", valueOffset "+jau::uint16HexString(getValueOffset(), true);
}
};
@@ -834,7 +836,7 @@ namespace direct_bt {
protected:
std::string valueString() const noexcept override {
- return "handle "+uint16HexString(getHandle(), true)+", data "+view.toString();;
+ return "handle "+jau::uint16HexString(getHandle(), true)+", data "+view.toString();;
}
};
@@ -906,7 +908,7 @@ namespace direct_bt {
protected:
std::string valueString() const noexcept override {
- return "handle "+uint16HexString(getHandle(), true)+", data "+view.toString();;
+ return "handle "+jau::uint16HexString(getHandle(), true)+", data "+view.toString();;
}
};
@@ -962,7 +964,7 @@ namespace direct_bt {
protected:
std::string valueString() const noexcept override {
- return "handle "+uint16HexString(getHandle(), true)+", size "+std::to_string(getPDUValueSize())+", data "+view.toString();
+ return "handle "+jau::uint16HexString(getHandle(), true)+", size "+std::to_string(getPDUValueSize())+", data "+view.toString();
}
};
@@ -1069,7 +1071,7 @@ namespace direct_bt {
: AttPDUMsg(groupTypeReq ? ATT_READ_BY_GROUP_TYPE_REQ : ATT_READ_BY_TYPE_REQ, 1+2+2+uuid.getTypeSizeInt())
{
if( uuid.getTypeSize() != uuid_t::TypeSize::UUID16_SZ && uuid.getTypeSize()!= uuid_t::TypeSize::UUID128_SZ ) {
- throw IllegalArgumentException("Only UUID16 and UUID128 allowed: "+uuid.toString(), E_FILE_LINE);
+ throw jau::IllegalArgumentException("Only UUID16 and UUID128 allowed: "+uuid.toString(), E_FILE_LINE);
}
pdu.put_uint16_nc(1, startHandle);
pdu.put_uint16_nc(3, endHandle);
@@ -1097,7 +1099,7 @@ namespace direct_bt {
protected:
std::string valueString() const noexcept override {
- return "handle ["+uint16HexString(getStartHandle(), true)+".."+uint16HexString(getEndHandle(), true)+
+ return "handle ["+jau::uint16HexString(getStartHandle(), true)+".."+jau::uint16HexString(getEndHandle(), true)+
"], uuid "+getNType()->toString();
}
};
@@ -1147,8 +1149,8 @@ namespace direct_bt {
int getValueSize() const noexcept { return view.getSize() - 2 /* handle size */; }
std::string toString() const {
- return "handle "+uint16HexString(getHandle(), true)+
- ", data "+bytesHexString(getValuePtr(), 0, getValueSize(), true /* lsbFirst */, true /* leading0X */);
+ return "handle "+jau::uint16HexString(getHandle(), true)+
+ ", data "+jau::bytesHexString(getValuePtr(), 0, getValueSize(), true /* lsbFirst */, true /* leading0X */);
}
};
@@ -1310,8 +1312,8 @@ namespace direct_bt {
protected:
std::string elementString(const int idx) const override {
Element e = getElement(idx);
- return "handle ["+uint16HexString(e.getStartHandle(), true)+".."+uint16HexString(e.getEndHandle(), true)+
- "], data "+bytesHexString(e.getValuePtr(), 0, e.getValueSize(), true /* lsbFirst */, true /* leading0X */);
+ return "handle ["+jau::uint16HexString(e.getStartHandle(), true)+".."+jau::uint16HexString(e.getEndHandle(), true)+
+ "], data "+jau::bytesHexString(e.getValuePtr(), 0, e.getValueSize(), true /* lsbFirst */, true /* leading0X */);
}
};
@@ -1352,7 +1354,7 @@ namespace direct_bt {
protected:
std::string valueString() const noexcept override {
- return "handle ["+uint16HexString(getStartHandle(), true)+".."+uint16HexString(getEndHandle(), true)+"]";
+ return "handle ["+jau::uint16HexString(getStartHandle(), true)+".."+jau::uint16HexString(getEndHandle(), true)+"]";
}
};
@@ -1453,7 +1455,7 @@ namespace direct_bt {
std::string elementString(const int idx) const override {
Element e = getElement(idx);
- return "handle "+uint16HexString(e.handle, true)+
+ return "handle "+jau::uint16HexString(e.handle, true)+
", uuid "+e.uuid.get()->toString();
}
};
diff --git a/api/direct_bt/BTTypes.hpp b/api/direct_bt/BTTypes.hpp
index 5b4ad420..e6ac2783 100644
--- a/api/direct_bt/BTTypes.hpp
+++ b/api/direct_bt/BTTypes.hpp
@@ -32,12 +32,24 @@
#include <cstdint>
#include <vector>
+#include <jau/basic_types.hpp>
+
#include "OctetTypes.hpp"
#include "BTAddress.hpp"
#include "UUID.hpp"
namespace direct_bt {
+ class BluetoothException : public jau::RuntimeException {
+ public:
+ BluetoothException(std::string const m, const char* file, int line) noexcept
+ : RuntimeException("BluetoothException", m, file, line) {}
+
+ BluetoothException(const char *m, const char* file, int line) noexcept
+ : RuntimeException("BluetoothException", m, file, line) {}
+ };
+
+
/**
* Bluetooth adapter operating mode
*/
diff --git a/api/direct_bt/DBTAdapter.hpp b/api/direct_bt/DBTAdapter.hpp
index deb83029..2e0268b2 100644
--- a/api/direct_bt/DBTAdapter.hpp
+++ b/api/direct_bt/DBTAdapter.hpp
@@ -151,6 +151,13 @@ namespace direct_bt {
// *************************************************
// *************************************************
// *************************************************
+ template <typename T> class CowList
+ {
+ bool add(T);
+ bool remove(T);
+ int removeAll();
+ int size();
+ };
/**
* DBTAdapter represents one Bluetooth Controller.
@@ -300,7 +307,7 @@ namespace direct_bt {
*/
inline void checkValidAdapter() const {
if( !isValid() ) {
- throw IllegalStateException("Adapter state invalid: "+aptrHexString(this)+", "+toString(), E_FILE_LINE);
+ throw jau::IllegalStateException("Adapter state invalid: "+jau::aptrHexString(this)+", "+toString(), E_FILE_LINE);
}
}
diff --git a/api/direct_bt/DBTManager.hpp b/api/direct_bt/DBTManager.hpp
index a9555f17..d8bca700 100644
--- a/api/direct_bt/DBTManager.hpp
+++ b/api/direct_bt/DBTManager.hpp
@@ -35,14 +35,15 @@
#include <atomic>
#include <thread>
-#include "DBTEnv.hpp"
+#include <jau/environment.hpp>
+#include <jau/ringbuffer.hpp>
+#include <jau/java_uplink.hpp>
+
#include "BTTypes.hpp"
#include "BTIoctl.hpp"
#include "OctetTypes.hpp"
#include "HCIComm.hpp"
-#include "JavaUplink.hpp"
#include "MgmtTypes.hpp"
-#include "LFRingbuffer.hpp"
namespace direct_bt {
@@ -54,7 +55,7 @@ namespace direct_bt {
* Also see {@link DBTEnv::getExplodingProperties(const std::string & prefixDomain)}.
* </p>
*/
- class MgmtEnv : public DBTEnvrionment {
+ class MgmtEnv : public jau::root_environment {
friend class DBTManager;
private:
@@ -142,7 +143,7 @@ namespace direct_bt {
* Controlling Environment variables, see {@link MgmtEnv}.
* </p>
*/
- class DBTManager : public JavaUplink {
+ class DBTManager : public jau::JavaUplink {
public:
enum Defaults : int32_t {
/* BT Core Spec v5.2: Vol 3, Part F 3.2.8: Maximum length of an attribute value. */
@@ -167,7 +168,7 @@ namespace direct_bt {
POctets rbuffer;
HCIComm comm;
- LFRingbuffer<std::shared_ptr<MgmtEvent>, nullptr> mgmtEventRing;
+ jau::ringbuffer<std::shared_ptr<MgmtEvent>, nullptr> mgmtEventRing;
std::atomic<bool> mgmtReaderShallStop;
std::mutex mtx_mgmtReaderLifecycle;
diff --git a/api/direct_bt/DBTTypes.hpp b/api/direct_bt/DBTTypes.hpp
index e94dceb6..5db1eba2 100644
--- a/api/direct_bt/DBTTypes.hpp
+++ b/api/direct_bt/DBTTypes.hpp
@@ -29,12 +29,13 @@
#include <mutex>
#include <atomic>
+#include <jau/java_uplink.hpp>
+
#include "UUID.hpp"
#include "BTAddress.hpp"
#include "BTTypes.hpp"
-#include "JavaUplink.hpp"
-
+#define JAVA_DBT_PACKAGE "direct_bt/tinyb/"
#define JAVA_MAIN_PACKAGE "org/tinyb"
#define JAVA_HCI_PACKAGE "tinyb/hci"
@@ -43,7 +44,7 @@ namespace direct_bt {
class DBTAdapter; // forward
class DBTDevice; // forward
- class DBTObject : public JavaUplink
+ class DBTObject : public jau::JavaUplink
{
protected:
std::atomic_bool valid;
@@ -76,9 +77,9 @@ namespace direct_bt {
/**
* Throws an IllegalStateException if isValid() == false
*/
- inline void checkValid() const {
+ void checkValid() const override {
if( !isValid() ) {
- throw IllegalStateException("DBTObject state invalid: "+aptrHexString(this), E_FILE_LINE);
+ throw jau::IllegalStateException("DBTObject state invalid: "+aptrHexString(this), E_FILE_LINE);
}
}
};
diff --git a/api/direct_bt/GATTCharacteristic.hpp b/api/direct_bt/GATTCharacteristic.hpp
index bf9a90ed..5c9f614f 100644
--- a/api/direct_bt/GATTCharacteristic.hpp
+++ b/api/direct_bt/GATTCharacteristic.hpp
@@ -35,6 +35,8 @@
#include <mutex>
#include <atomic>
+#include <jau/java_uplink.hpp>
+
#include "UUID.hpp"
#include "BTTypes.hpp"
#include "OctetTypes.hpp"
@@ -44,7 +46,6 @@
#include "GATTDescriptor.hpp"
-#include "JavaUplink.hpp"
/**
* - - - - - - - - - - - - - - -
diff --git a/api/direct_bt/GATTHandler.hpp b/api/direct_bt/GATTHandler.hpp
index d23b880a..2240f1d7 100644
--- a/api/direct_bt/GATTHandler.hpp
+++ b/api/direct_bt/GATTHandler.hpp
@@ -36,13 +36,14 @@
#include <atomic>
#include <thread>
-#include "DBTEnv.hpp"
+#include <jau/ringbuffer.hpp>
+#include <jau/environment.hpp>
+
#include "UUID.hpp"
#include "BTTypes.hpp"
#include "L2CAPComm.hpp"
#include "ATTPDUTypes.hpp"
#include "GATTTypes.hpp"
-#include "LFRingbuffer.hpp"
/**
* - - - - - - - - - - - - - - -
@@ -63,7 +64,7 @@ namespace direct_bt {
* Also see {@link DBTEnv::getExplodingProperties(const std::string & prefixDomain)}.
* </p>
*/
- class GATTEnv : public DBTEnvrionment {
+ class GATTEnv : public jau::root_environment {
private:
GATTEnv() noexcept;
@@ -161,7 +162,7 @@ namespace direct_bt {
std::atomic<bool> is_connected; // reflects state
std::atomic<bool> has_ioerror; // reflects state
- LFRingbuffer<std::shared_ptr<const AttPDUMsg>, nullptr> attPDURing;
+ jau::ringbuffer<std::shared_ptr<const AttPDUMsg>, nullptr> attPDURing;
std::atomic<bool> l2capReaderShallStop;
std::mutex mtx_l2capReaderLifecycle;
diff --git a/api/direct_bt/GATTNumbers.hpp b/api/direct_bt/GATTNumbers.hpp
index 037142df..89c4a0af 100644
--- a/api/direct_bt/GATTNumbers.hpp
+++ b/api/direct_bt/GATTNumbers.hpp
@@ -27,8 +27,10 @@
#define GATT_NUMBERS_HPP_
#include <cstdint>
+
+#include <jau/basic_types.hpp>
+
#include "UUID.hpp"
-#include "BasicTypes.hpp"
#include "OctetTypes.hpp"
#include "BTTypes.hpp"
#include "ieee11073/DataTypes.hpp"
diff --git a/api/direct_bt/GATTService.hpp b/api/direct_bt/GATTService.hpp
index b293f90a..f652ac5c 100644
--- a/api/direct_bt/GATTService.hpp
+++ b/api/direct_bt/GATTService.hpp
@@ -35,6 +35,8 @@
#include <mutex>
#include <atomic>
+#include <jau/java_uplink.hpp>
+
#include "UUID.hpp"
#include "BTTypes.hpp"
#include "OctetTypes.hpp"
@@ -44,8 +46,6 @@
#include "GATTCharacteristic.hpp"
-#include "JavaUplink.hpp"
-
/**
* - - - - - - - - - - - - - - -
*
diff --git a/api/direct_bt/GATTTypes.hpp b/api/direct_bt/GATTTypes.hpp
index 8b1a3ceb..fd246fc9 100644
--- a/api/direct_bt/GATTTypes.hpp
+++ b/api/direct_bt/GATTTypes.hpp
@@ -35,6 +35,8 @@
#include <mutex>
#include <atomic>
+#include <jau/java_uplink.hpp>
+
#include "UUID.hpp"
#include "BTTypes.hpp"
#include "OctetTypes.hpp"
@@ -45,8 +47,6 @@
#include "GATTService.hpp"
-#include "JavaUplink.hpp"
-
/**
* - - - - - - - - - - - - - - -
*
diff --git a/api/direct_bt/HCIHandler.hpp b/api/direct_bt/HCIHandler.hpp
index 38b20f99..f4f1757b 100644
--- a/api/direct_bt/HCIHandler.hpp
+++ b/api/direct_bt/HCIHandler.hpp
@@ -35,15 +35,16 @@
#include <atomic>
#include <thread>
-#include "DBTEnv.hpp"
+#include <jau/ringbuffer.hpp>
+#include <jau/environment.hpp>
+#include <jau/java_uplink.hpp>
+
#include "BTTypes.hpp"
#include "BTIoctl.hpp"
#include "OctetTypes.hpp"
#include "HCIComm.hpp"
-#include "JavaUplink.hpp"
#include "HCITypes.hpp"
#include "MgmtTypes.hpp"
-#include "LFRingbuffer.hpp"
/**
* - - - - - - - - - - - - - - -
@@ -85,7 +86,7 @@ namespace direct_bt {
{ return !(*this == rhs); }
std::string toString() const {
- return "HCIConnection[handle "+uint16HexString(handle)+
+ return "HCIConnection[handle "+jau::uint16HexString(handle)+
", address="+address.toString()+", addressType "+getBDAddressTypeString(addressType)+"]";
}
};
@@ -99,7 +100,7 @@ namespace direct_bt {
* Also see {@link DBTEnv::getExplodingProperties(const std::string & prefixDomain)}.
* </p>
*/
- class HCIEnv : public DBTEnvrionment {
+ class HCIEnv : public jau::root_environment {
friend class HCIHandler;
private:
@@ -199,21 +200,21 @@ namespace direct_bt {
std::atomic<uint32_t> metaev_filter_mask;
std::atomic<uint64_t> opcbit_filter_mask;
- inline bool filter_test_metaev(HCIMetaEventType mec) noexcept { return 0 != test_bit_uint32(number(mec)-1, metaev_filter_mask); }
+ inline bool filter_test_metaev(HCIMetaEventType mec) noexcept { return 0 != jau::test_bit_uint32(number(mec)-1, metaev_filter_mask); }
inline void filter_put_metaevs(const uint32_t mask) noexcept { metaev_filter_mask=mask; }
constexpr static void filter_clear_metaevs(uint32_t &mask) noexcept { mask=0; }
constexpr static void filter_all_metaevs(uint32_t &mask) noexcept { mask=0xffffffffU; }
- inline static void filter_set_metaev(HCIMetaEventType mec, uint32_t &mask) noexcept { set_bit_uint32(number(mec)-1, mask); }
+ inline static void filter_set_metaev(HCIMetaEventType mec, uint32_t &mask) noexcept { jau::set_bit_uint32(number(mec)-1, mask); }
- inline bool filter_test_opcbit(HCIOpcodeBit opcbit) noexcept { return 0 != test_bit_uint64(number(opcbit), opcbit_filter_mask); }
+ inline bool filter_test_opcbit(HCIOpcodeBit opcbit) noexcept { return 0 != jau::test_bit_uint64(number(opcbit), opcbit_filter_mask); }
inline void filter_put_opcbit(const uint64_t mask) noexcept { opcbit_filter_mask=mask; }
constexpr static void filter_clear_opcbit(uint64_t &mask) noexcept { mask=0; }
constexpr static void filter_all_opcbit(uint64_t &mask) noexcept { mask=0xffffffffffffffffUL; }
- inline static void filter_set_opcbit(HCIOpcodeBit opcbit, uint64_t &mask) noexcept { set_bit_uint64(number(opcbit), mask); }
+ inline static void filter_set_opcbit(HCIOpcodeBit opcbit, uint64_t &mask) noexcept { jau::set_bit_uint64(number(opcbit), mask); }
- LFRingbuffer<std::shared_ptr<HCIEvent>, nullptr> hciEventRing;
+ jau::ringbuffer<std::shared_ptr<HCIEvent>, nullptr> hciEventRing;
std::atomic<bool> hciReaderShallStop;
std::mutex mtx_hciReaderLifecycle;
diff --git a/api/direct_bt/HCITypes.hpp b/api/direct_bt/HCITypes.hpp
index 97f88cf7..e1d4a344 100644
--- a/api/direct_bt/HCITypes.hpp
+++ b/api/direct_bt/HCITypes.hpp
@@ -33,6 +33,8 @@
#include <algorithm>
#include <mutex>
+#include <jau/basic_types.hpp>
+
#include "BTTypes.hpp"
#include "BTIoctl.hpp"
#include "OctetTypes.hpp"
@@ -48,7 +50,7 @@
*/
namespace direct_bt {
- class HCIException : public RuntimeException {
+ class HCIException : public jau::RuntimeException {
protected:
HCIException(std::string const type, std::string const m, const char* file, int line) noexcept
: RuntimeException(type, m, file, line) {}
@@ -429,7 +431,7 @@ namespace direct_bt {
case HCIPacketType::VENDOR:
return; // OK
default:
- throw HCIPacketException("Unsupported packet type "+uint8HexString(number(type)), E_FILE_LINE);
+ throw HCIPacketException("Unsupported packet type "+jau::uint8HexString(number(type)), E_FILE_LINE);
}
}
@@ -438,7 +440,7 @@ namespace direct_bt {
: pdu(total_packet_size)
{
if( 0 == total_packet_size ) {
- throw IndexOutOfBoundsException(1, total_packet_size, E_FILE_LINE);
+ throw jau::IndexOutOfBoundsException(1, total_packet_size, E_FILE_LINE);
}
pdu.put_uint8_nc(0, number(type));
}
@@ -448,7 +450,7 @@ namespace direct_bt {
: pdu(packet_data, total_packet_size)
{
if( 0 == total_packet_size ) {
- throw IndexOutOfBoundsException(1, total_packet_size, E_FILE_LINE);
+ throw jau::IndexOutOfBoundsException(1, total_packet_size, E_FILE_LINE);
}
checkPacketType(getPacketType());
}
@@ -480,18 +482,18 @@ namespace direct_bt {
inline static void checkOpcode(const HCIOpcode has, const HCIOpcode min, const HCIOpcode max)
{
if( has < min || has > max ) {
- throw HCIOpcodeException("Has opcode "+uint16HexString(number(has))+
- ", not within range ["+uint16HexString(number(min))+
- ".."+uint16HexString(number(max))+"]", E_FILE_LINE);
+ throw HCIOpcodeException("Has opcode "+jau::uint16HexString(number(has))+
+ ", not within range ["+jau::uint16HexString(number(min))+
+ ".."+jau::uint16HexString(number(max))+"]", E_FILE_LINE);
}
}
virtual std::string baseString() const noexcept {
- return "opcode="+uint16HexString(number(getOpcode()))+" "+getOpcodeString();
+ return "opcode="+jau::uint16HexString(number(getOpcode()))+" "+getOpcodeString();
}
virtual std::string valueString() const noexcept {
const int psz = getParamSize();
- const std::string ps = psz > 0 ? bytesHexString(getParam(), 0, psz, true /* lsbFirst */, true /* leading0X */) : "";
+ const std::string ps = psz > 0 ? jau::bytesHexString(getParam(), 0, psz, true /* lsbFirst */, true /* leading0X */) : "";
return "param[size "+std::to_string(getParamSize())+", data "+ps+"], tsz "+std::to_string(getTotalSize());
}
@@ -590,26 +592,26 @@ namespace direct_bt {
inline static void checkEventType(const HCIEventType has, const HCIEventType min, const HCIEventType max)
{
if( has < min || has > max ) {
- throw HCIOpcodeException("Has evcode "+uint8HexString(number(has))+
- ", not within range ["+uint8HexString(number(min))+
- ".."+uint8HexString(number(max))+"]", E_FILE_LINE);
+ throw HCIOpcodeException("Has evcode "+jau::uint8HexString(number(has))+
+ ", not within range ["+jau::uint8HexString(number(min))+
+ ".."+jau::uint8HexString(number(max))+"]", E_FILE_LINE);
}
}
inline static void checkEventType(const HCIEventType has, const HCIEventType exp)
{
if( has != exp ) {
- throw HCIOpcodeException("Has evcode "+uint8HexString(number(has))+
- ", not matching "+uint8HexString(number(exp)), E_FILE_LINE);
+ throw HCIOpcodeException("Has evcode "+jau::uint8HexString(number(has))+
+ ", not matching "+jau::uint8HexString(number(exp)), E_FILE_LINE);
}
}
virtual std::string baseString() const noexcept {
- return "event="+uint8HexString(number(getEventType()))+" "+getEventTypeString();
+ return "event="+jau::uint8HexString(number(getEventType()))+" "+getEventTypeString();
}
virtual std::string valueString() const noexcept {
const int d_sz_base = getBaseParamSize();
const int d_sz = getParamSize();
- const std::string d_str = d_sz > 0 ? bytesHexString(getParam(), 0, d_sz, true /* lsbFirst */, true /* leading0X */) : "";
+ const std::string d_str = d_sz > 0 ? jau::bytesHexString(getParam(), 0, d_sz, true /* lsbFirst */, true /* leading0X */) : "";
return "data[size "+std::to_string(d_sz)+"/"+std::to_string(d_sz_base)+", data "+d_str+"], tsz "+std::to_string(getTotalSize());
}
@@ -627,19 +629,19 @@ namespace direct_bt {
/** Persistent memory, w/ ownership ..*/
HCIEvent(const uint8_t* buffer, const int buffer_len, const int exp_param_size)
- : HCIPacket(buffer, buffer_len), ts_creation(getCurrentMilliseconds())
+ : HCIPacket(buffer, buffer_len), ts_creation(jau::getCurrentMilliseconds())
{
const int baseParamSize = getBaseParamSize();
pdu.check_range(0, number(HCIConstU8::EVENT_HDR_SIZE)+baseParamSize);
if( exp_param_size > baseParamSize ) {
- throw IndexOutOfBoundsException(exp_param_size, baseParamSize, E_FILE_LINE);
+ throw jau::IndexOutOfBoundsException(exp_param_size, baseParamSize, E_FILE_LINE);
}
checkEventType(getEventType(), HCIEventType::INQUIRY_COMPLETE, HCIEventType::AMP_Receiver_Report);
}
/** Enabling manual construction of event without given value. */
HCIEvent(const HCIEventType evt, const uint16_t param_size=0)
- : HCIPacket(HCIPacketType::EVENT, number(HCIConstU8::EVENT_HDR_SIZE)+param_size), ts_creation(getCurrentMilliseconds())
+ : HCIPacket(HCIPacketType::EVENT, number(HCIConstU8::EVENT_HDR_SIZE)+param_size), ts_creation(jau::getCurrentMilliseconds())
{
checkEventType(evt, HCIEventType::INQUIRY_COMPLETE, HCIEventType::AMP_Receiver_Report);
pdu.put_uint8_nc(1, number(evt));
@@ -728,9 +730,9 @@ namespace direct_bt {
protected:
std::string baseString() const noexcept override {
return HCIEvent::baseString()+
- ", status "+uint8HexString(static_cast<uint8_t>(getStatus()), true)+" "+getHCIStatusCodeString(getStatus())+
- ", handle "+uint16HexString(getHandle())+
- ", reason "+uint8HexString(static_cast<uint8_t>(getReason()), true)+" "+getHCIStatusCodeString(getReason());
+ ", status "+jau::uint8HexString(static_cast<uint8_t>(getStatus()), true)+" "+getHCIStatusCodeString(getStatus())+
+ ", handle "+jau::uint16HexString(getHandle())+
+ ", reason "+jau::uint8HexString(static_cast<uint8_t>(getReason()), true)+" "+getHCIStatusCodeString(getReason());
}
public:
@@ -762,7 +764,7 @@ namespace direct_bt {
{
protected:
std::string baseString() const noexcept override {
- return HCIEvent::baseString()+", opcode="+uint16HexString(static_cast<uint16_t>(getOpcode()))+
+ return HCIEvent::baseString()+", opcode="+jau::uint16HexString(static_cast<uint16_t>(getOpcode()))+
" "+getHCIOpcodeString(getOpcode())+
", ncmd "+std::to_string(getNumCommandPackets());
}
@@ -815,10 +817,10 @@ namespace direct_bt {
{
protected:
std::string baseString() const noexcept override {
- return HCIEvent::baseString()+", opcode="+uint16HexString(static_cast<uint16_t>(getOpcode()))+
+ return HCIEvent::baseString()+", opcode="+jau::uint16HexString(static_cast<uint16_t>(getOpcode()))+
" "+getHCIOpcodeString(getOpcode())+
", ncmd "+std::to_string(getNumCommandPackets())+
- ", status "+uint8HexString(static_cast<uint8_t>(getStatus()), true)+" "+getHCIStatusCodeString(getStatus());
+ ", status "+jau::uint8HexString(static_cast<uint8_t>(getStatus()), true)+" "+getHCIStatusCodeString(getStatus());
}
public:
@@ -861,13 +863,13 @@ namespace direct_bt {
static void checkMetaType(const HCIMetaEventType has, const HCIMetaEventType exp)
{
if( has != exp ) {
- throw HCIOpcodeException("Has meta "+uint8HexString(number(has))+
- ", not matching "+uint8HexString(number(exp)), E_FILE_LINE);
+ throw HCIOpcodeException("Has meta "+jau::uint8HexString(number(has))+
+ ", not matching "+jau::uint8HexString(number(exp)), E_FILE_LINE);
}
}
virtual std::string baseString() const noexcept override {
- return "event="+uint8HexString(number(getMetaEventType()))+" "+getMetaEventTypeString()+" (le-meta)";
+ return "event="+jau::uint8HexString(number(getMetaEventType()))+" "+getMetaEventTypeString()+" (le-meta)";
}
public:
diff --git a/api/direct_bt/L2CAPComm.hpp b/api/direct_bt/L2CAPComm.hpp
index 572e6375..8ed3d6b2 100644
--- a/api/direct_bt/L2CAPComm.hpp
+++ b/api/direct_bt/L2CAPComm.hpp
@@ -35,7 +35,8 @@
#include <mutex>
#include <atomic>
-#include "DBTEnv.hpp"
+#include <jau/environment.hpp>
+
#include "UUID.hpp"
#include "BTTypes.hpp"
@@ -56,7 +57,7 @@ namespace direct_bt {
* Also see {@link DBTEnv::getExplodingProperties(const std::string & prefixDomain)}.
* </p>
*/
- class L2CAPEnv : public DBTEnvrionment {
+ class L2CAPEnv : public jau::root_environment {
private:
L2CAPEnv() noexcept;
diff --git a/api/direct_bt/MgmtTypes.hpp b/api/direct_bt/MgmtTypes.hpp
index ab31ce4b..b6c6c8ac 100644
--- a/api/direct_bt/MgmtTypes.hpp
+++ b/api/direct_bt/MgmtTypes.hpp
@@ -32,6 +32,8 @@
#include <mutex>
+#include <jau/function_def.hpp>
+
#include "BTTypes.hpp"
#include "BTIoctl.hpp"
#include "OctetTypes.hpp"
@@ -39,11 +41,9 @@
#include "DBTTypes.hpp"
-#include "FunctionDef.hpp"
-
namespace direct_bt {
- class MgmtException : public RuntimeException {
+ class MgmtException : public jau::RuntimeException {
protected:
MgmtException(std::string const type, std::string const m, const char* file, int line) noexcept
: RuntimeException(type, m, file, line) {}
@@ -185,18 +185,18 @@ namespace direct_bt {
inline static void checkOpcode(const MgmtOpcode has, const MgmtOpcode min, const MgmtOpcode max)
{
if( has < min || has > max ) {
- throw MgmtOpcodeException("Has opcode "+uint16HexString(static_cast<uint16_t>(has))+
- ", not within range ["+uint16HexString(static_cast<uint16_t>(min))+
- ".."+uint16HexString(static_cast<uint16_t>(max))+"]", E_FILE_LINE);
+ throw MgmtOpcodeException("Has opcode "+jau::uint16HexString(static_cast<uint16_t>(has))+
+ ", not within range ["+jau::uint16HexString(static_cast<uint16_t>(min))+
+ ".."+jau::uint16HexString(static_cast<uint16_t>(max))+"]", E_FILE_LINE);
}
}
virtual std::string baseString() const noexcept {
- return "opcode="+uint16HexString(static_cast<uint16_t>(getOpcode()))+" "+getOpcodeString()+", devID "+uint16HexString(getDevID());
+ return "opcode="+jau::uint16HexString(static_cast<uint16_t>(getOpcode()))+" "+getOpcodeString()+", devID "+jau::uint16HexString(getDevID());
}
virtual std::string valueString() const noexcept {
const int psz = getParamSize();
- const std::string ps = psz > 0 ? bytesHexString(getParam(), 0, psz, true /* lsbFirst */, true /* leading0X */) : "";
+ const std::string ps = psz > 0 ? jau::bytesHexString(getParam(), 0, psz, true /* lsbFirst */, true /* leading0X */) : "";
return "param[size "+std::to_string(getParamSize())+", data "+ps+"], tsz "+std::to_string(getTotalSize());
}
@@ -443,7 +443,7 @@ namespace direct_bt {
void checkParamIdx(const int idx) const {
const int pc = getParamCount();
if( 0 > idx || idx >= pc ) {
- throw IndexOutOfBoundsException(idx, pc, E_FILE_LINE);
+ throw jau::IndexOutOfBoundsException(idx, pc, E_FILE_LINE);
}
}
@@ -565,26 +565,26 @@ namespace direct_bt {
static void checkOpcode(const Opcode has, const Opcode min, const Opcode max)
{
if( has < min || has > max ) {
- throw MgmtOpcodeException("Has evcode "+uint16HexString(static_cast<uint16_t>(has))+
- ", not within range ["+uint16HexString(static_cast<uint16_t>(min))+
- ".."+uint16HexString(static_cast<uint16_t>(max))+"]", E_FILE_LINE);
+ throw MgmtOpcodeException("Has evcode "+jau::uint16HexString(static_cast<uint16_t>(has))+
+ ", not within range ["+jau::uint16HexString(static_cast<uint16_t>(min))+
+ ".."+jau::uint16HexString(static_cast<uint16_t>(max))+"]", E_FILE_LINE);
}
}
static void checkOpcode(const Opcode has, const Opcode exp)
{
if( has != exp ) {
- throw MgmtOpcodeException("Has evcode "+uint16HexString(static_cast<uint16_t>(has))+
- ", not matching "+uint16HexString(static_cast<uint16_t>(exp)), E_FILE_LINE);
+ throw MgmtOpcodeException("Has evcode "+jau::uint16HexString(static_cast<uint16_t>(has))+
+ ", not matching "+jau::uint16HexString(static_cast<uint16_t>(exp)), E_FILE_LINE);
}
}
virtual std::string baseString() const {
- return "opcode="+uint16HexString(static_cast<uint16_t>(getOpcode()))+
- " "+getOpcodeString()+", devID "+uint16HexString(getDevID(), true);
+ return "opcode="+jau::uint16HexString(static_cast<uint16_t>(getOpcode()))+
+ " "+getOpcodeString()+", devID "+jau::uint16HexString(getDevID(), true);
}
virtual std::string valueString() const {
const int d_sz = getDataSize();
- const std::string d_str = d_sz > 0 ? bytesHexString(getData(), 0, d_sz, true /* lsbFirst */, true /* leading0X */) : "";
+ const std::string d_str = d_sz > 0 ? jau::bytesHexString(getData(), 0, d_sz, true /* lsbFirst */, true /* leading0X */) : "";
return "data[size "+std::to_string(d_sz)+", data "+d_str+"], tsz "+std::to_string(getTotalSize());
}
@@ -600,18 +600,18 @@ namespace direct_bt {
/** Persistent memory, w/ ownership ..*/
MgmtEvent(const uint8_t* buffer, const int buffer_len, const int exp_param_size)
- : pdu(buffer, buffer_len), ts_creation(getCurrentMilliseconds())
+ : pdu(buffer, buffer_len), ts_creation(jau::getCurrentMilliseconds())
{
const int paramSize = getParamSize();
pdu.check_range(0, MGMT_HEADER_SIZE+paramSize);
if( exp_param_size > paramSize ) {
- throw IndexOutOfBoundsException(exp_param_size, paramSize, E_FILE_LINE);
+ throw jau::IndexOutOfBoundsException(exp_param_size, paramSize, E_FILE_LINE);
}
checkOpcode(getOpcode(), Opcode::CMD_COMPLETE, Opcode::PHY_CONFIGURATION_CHANGED);
}
MgmtEvent(const Opcode opc, const uint16_t dev_id, const uint16_t param_size=0)
- : pdu(MGMT_HEADER_SIZE+param_size), ts_creation(getCurrentMilliseconds())
+ : pdu(MGMT_HEADER_SIZE+param_size), ts_creation(jau::getCurrentMilliseconds())
{
// checkOpcode(opc, READ_VERSION, SET_BLOCKED_KEYS);
@@ -653,9 +653,9 @@ namespace direct_bt {
{
protected:
std::string baseString() const override {
- return MgmtEvent::baseString()+", req-opcode="+uint16HexString(static_cast<uint16_t>(getReqOpcode()))+
+ return MgmtEvent::baseString()+", req-opcode="+jau::uint16HexString(static_cast<uint16_t>(getReqOpcode()))+
" "+getMgmtOpcodeString(getReqOpcode())+
- ", status "+uint8HexString(static_cast<uint8_t>(getStatus()), true)+" "+getMgmtStatusString(getStatus());
+ ", status "+jau::uint8HexString(static_cast<uint8_t>(getStatus()), true)+" "+getMgmtStatusString(getStatus());
}
MgmtEvtCmdComplete(const uint8_t* buffer, const int buffer_len, const int exp_param_size)
@@ -667,7 +667,7 @@ namespace direct_bt {
public:
static MgmtOpcode getReqOpcode(const uint8_t *data) {
- return static_cast<MgmtOpcode>( get_uint16(data, MGMT_HEADER_SIZE, true /* littleEndian */) );
+ return static_cast<MgmtOpcode>( jau::get_uint16(data, MGMT_HEADER_SIZE, true /* littleEndian */) );
}
MgmtEvtCmdComplete(const uint8_t* buffer, const int buffer_len)
@@ -710,9 +710,9 @@ namespace direct_bt {
protected:
std::string baseString() const override {
- return MgmtEvent::baseString()+", req-opcode="+uint16HexString(static_cast<uint16_t>(getReqOpcode()))+
+ return MgmtEvent::baseString()+", req-opcode="+jau::uint16HexString(static_cast<uint16_t>(getReqOpcode()))+
" "+getMgmtOpcodeString(getReqOpcode())+
- ", status "+uint8HexString(static_cast<uint8_t>(getStatus()))+" "+getMgmtStatusString(getStatus());
+ ", status "+jau::uint8HexString(static_cast<uint8_t>(getStatus()))+" "+getMgmtStatusString(getStatus());
}
public:
@@ -850,7 +850,7 @@ namespace direct_bt {
} else {
return MgmtEvent::baseString()+", address="+getAddress().toString()+
", addressType "+getBDAddressTypeString(getAddressType())+
- ", rssi "+std::to_string(getRSSI())+", flags="+uint32HexString(getFlags(), true)+
+ ", rssi "+std::to_string(getRSSI())+", flags="+jau::uint32HexString(getFlags(), true)+
", eir-size "+std::to_string(getEIRSize());
}
}
@@ -903,9 +903,9 @@ namespace direct_bt {
std::string baseString() const override {
return MgmtEvent::baseString()+", address="+getAddress().toString()+
", addressType "+getBDAddressTypeString(getAddressType())+
- ", flags="+uint32HexString(getFlags(), true)+
+ ", flags="+jau::uint32HexString(getFlags(), true)+
", eir-size "+std::to_string(getEIRSize())+
- ", hci_handle "+uint16HexString(hci_conn_handle);
+ ", hci_handle "+jau::uint16HexString(hci_conn_handle);
}
public:
@@ -950,8 +950,8 @@ namespace direct_bt {
std::string baseString() const override {
return MgmtEvent::baseString()+", address="+getAddress().toString()+
", addressType "+getBDAddressTypeString(getAddressType())+
- ", status[mgmt["+uint8HexString(static_cast<uint8_t>(getStatus()))+" ("+getMgmtStatusString(getStatus())+")]"+
- ", hci["+uint8HexString(static_cast<uint8_t>(hciStatus))+" ("+getHCIStatusCodeString(hciStatus)+")]]";
+ ", status[mgmt["+jau::uint8HexString(static_cast<uint8_t>(getStatus()))+" ("+getMgmtStatusString(getStatus())+")]"+
+ ", hci["+jau::uint8HexString(static_cast<uint8_t>(hciStatus))+" ("+getHCIStatusCodeString(hciStatus)+")]]";
}
public:
@@ -1020,9 +1020,9 @@ namespace direct_bt {
const HCIStatusCode reason2 = getHCIReason();
return MgmtEvent::baseString()+", address="+getAddress().toString()+
", addressType "+getBDAddressTypeString(getAddressType())+
- ", reason[mgmt["+uint8HexString(static_cast<uint8_t>(reason1))+" ("+getDisconnectReasonString(reason1)+")]"+
- ", hci["+uint8HexString(static_cast<uint8_t>(reason2))+" ("+getHCIStatusCodeString(reason2)+")]]"+
- ", hci_handle "+uint16HexString(hci_conn_handle);
+ ", reason[mgmt["+jau::uint8HexString(static_cast<uint8_t>(reason1))+" ("+getDisconnectReasonString(reason1)+")]"+
+ ", hci["+jau::uint8HexString(static_cast<uint8_t>(reason2))+" ("+getHCIStatusCodeString(reason2)+")]]"+
+ ", hci_handle "+jau::uint16HexString(hci_conn_handle);
}
public:
@@ -1273,7 +1273,7 @@ namespace direct_bt {
};
- typedef FunctionDef<bool, std::shared_ptr<MgmtEvent>> MgmtEventCallback;
+ typedef jau::FunctionDef<bool, std::shared_ptr<MgmtEvent>> MgmtEventCallback;
typedef std::vector<MgmtEventCallback> MgmtEventCallbackList;
class MgmtAdapterEventCallback {
diff --git a/api/direct_bt/OctetTypes.hpp b/api/direct_bt/OctetTypes.hpp
index 29ed6fb4..42a22bd9 100644
--- a/api/direct_bt/OctetTypes.hpp
+++ b/api/direct_bt/OctetTypes.hpp
@@ -36,7 +36,8 @@
#include <mutex>
#include <atomic>
-#include "BasicTypes.hpp"
+#include <jau/basic_types.hpp>
+
#include "UUID.hpp"
#include "BTAddress.hpp"
@@ -66,7 +67,7 @@ namespace direct_bt {
protected:
static inline void checkPtr(uint8_t *d, int s) {
if( nullptr == d && 0 < s ) {
- throw IllegalArgumentException("TROOctets::setData: nullptr with size "+std::to_string(s)+" > 0", E_FILE_LINE);
+ throw jau::IllegalArgumentException("TROOctets::setData: nullptr with size "+std::to_string(s)+" > 0", E_FILE_LINE);
}
}
@@ -105,7 +106,7 @@ namespace direct_bt {
inline void check_range(const int i, const int count, const char *file, int line) const {
if( 0 > i || i+count > _size ) {
- throw IndexOutOfBoundsException(i, count, _size, file, line);
+ throw jau::IndexOutOfBoundsException(i, count, _size, file, line);
}
}
#define check_range(I,C) check_range((I), (C), E_FILE_LINE)
@@ -127,26 +128,26 @@ namespace direct_bt {
int8_t get_int8(const int i) const {
check_range(i, 1);
- return direct_bt::get_int8(_data, i);
+ return jau::get_int8(_data, i);
}
inline int8_t get_int8_nc(const int i) const noexcept {
- return direct_bt::get_int8(_data, i);
+ return jau::get_int8(_data, i);
}
uint16_t get_uint16(const int i) const {
check_range(i, 2);
- return direct_bt::get_uint16(_data, i, true /* littleEndian */);
+ return jau::get_uint16(_data, i, true /* littleEndian */);
}
inline uint16_t get_uint16_nc(const int i) const noexcept {
- return direct_bt::get_uint16(_data, i, true /* littleEndian */);
+ return jau::get_uint16(_data, i, true /* littleEndian */);
}
uint32_t get_uint32(const int i) const {
check_range(i, 4);
- return direct_bt::get_uint32(_data, i, true /* littleEndian */);
+ return jau::get_uint32(_data, i, true /* littleEndian */);
}
inline uint32_t get_uint32_nc(const int i) const noexcept {
- return direct_bt::get_uint32(_data, i, true /* littleEndian */);
+ return jau::get_uint32(_data, i, true /* littleEndian */);
}
EUI48 get_eui48(const int i) const {
@@ -182,10 +183,10 @@ namespace direct_bt {
uuid128_t get_uuid128(const int i) const {
check_range(i, uuid_t::number(uuid_t::TypeSize::UUID128_SZ));
- return uuid128_t(get_uint128(_data, i, true /* littleEndian */));
+ return uuid128_t(jau::get_uint128(_data, i, true /* littleEndian */));
}
inline uuid128_t get_uuid128_nc(const int i) const noexcept {
- return uuid128_t(get_uint128(_data, i, true /* littleEndian */));
+ return uuid128_t(jau::get_uint128(_data, i, true /* littleEndian */));
}
std::shared_ptr<const uuid_t> get_uuid(const int i, const uuid_t::TypeSize tsize) const {
@@ -210,7 +211,7 @@ namespace direct_bt {
}
std::string toString() const noexcept {
- return "size "+std::to_string(_size)+", ro: "+bytesHexString(_data, 0, _size, true /* lsbFirst */, true /* leading0X */);
+ return "size "+std::to_string(_size)+", ro: "+jau::bytesHexString(_data, 0, _size, true /* lsbFirst */, true /* leading0X */);
}
};
@@ -244,18 +245,18 @@ namespace direct_bt {
void put_uint16(const int i, const uint16_t v) {
check_range(i, 2);
- direct_bt::put_uint16(data(), i, v, true /* littleEndian */);
+ jau::put_uint16(data(), i, v, true /* littleEndian */);
}
void put_uint16_nc(const int i, const uint16_t v) noexcept {
- direct_bt::put_uint16(data(), i, v, true /* littleEndian */);
+ jau::put_uint16(data(), i, v, true /* littleEndian */);
}
void put_uint32(const int i, const uint32_t v) {
check_range(i, 4);
- direct_bt::put_uint32(data(), i, v, true /* littleEndian */);
+ jau::put_uint32(data(), i, v, true /* littleEndian */);
}
void put_uint32_nc(const int i, const uint32_t v) noexcept {
- direct_bt::put_uint32(data(), i, v, true /* littleEndian */);
+ jau::put_uint32(data(), i, v, true /* littleEndian */);
}
void put_eui48(const int i, const EUI48 & v) {
@@ -310,7 +311,7 @@ namespace direct_bt {
}
std::string toString() const noexcept {
- return "size "+std::to_string(getSize())+", rw: "+bytesHexString(get_ptr(), 0, getSize(), true /* lsbFirst */, true /* leading0X */);
+ return "size "+std::to_string(getSize())+", rw: "+jau::bytesHexString(get_ptr(), 0, getSize(), true /* lsbFirst */, true /* leading0X */);
}
};
@@ -326,7 +327,7 @@ namespace direct_bt {
: parent(buffer), offset(offset), size(len)
{
if( offset+size > buffer.getSize() ) {
- throw IndexOutOfBoundsException(offset, size, buffer.getSize(), E_FILE_LINE);
+ throw jau::IndexOutOfBoundsException(offset, size, buffer.getSize(), E_FILE_LINE);
}
}
@@ -356,7 +357,7 @@ namespace direct_bt {
}
std::string toString() const noexcept {
- return "offset "+std::to_string(offset)+", size "+std::to_string(size)+": "+bytesHexString(parent.get_ptr(), offset, size, true /* lsbFirst */, true /* leading0X */);
+ return "offset "+std::to_string(offset)+", size "+std::to_string(size)+": "+jau::bytesHexString(parent.get_ptr(), offset, size, true /* lsbFirst */, true /* leading0X */);
}
};
@@ -385,7 +386,7 @@ namespace direct_bt {
}
uint8_t * m = static_cast<uint8_t*>( std::malloc(size) );
if( nullptr == m ) {
- throw OutOfMemoryError("allocData size "+std::to_string(size)+" -> nullptr", E_FILE_LINE);
+ throw jau::OutOfMemoryError("allocData size "+std::to_string(size)+" -> nullptr", E_FILE_LINE);
}
return m;
}
@@ -416,7 +417,7 @@ namespace direct_bt {
capacity( _capacity )
{
if( capacity < getSize() ) {
- throw IllegalArgumentException("capacity "+std::to_string(capacity)+" < size "+std::to_string(getSize()), E_FILE_LINE);
+ throw jau::IllegalArgumentException("capacity "+std::to_string(capacity)+" < size "+std::to_string(getSize()), E_FILE_LINE);
}
TRACE_PRINT("POctets ctor2: %p", data());
}
@@ -517,7 +518,7 @@ namespace direct_bt {
POctets & resize(const int newSize, const int newCapacity) {
if( newCapacity < newSize ) {
- throw IllegalArgumentException("newCapacity "+std::to_string(newCapacity)+" < newSize "+std::to_string(newSize), E_FILE_LINE);
+ throw jau::IllegalArgumentException("newCapacity "+std::to_string(newCapacity)+" < newSize "+std::to_string(newSize), E_FILE_LINE);
}
if( newCapacity != capacity ) {
if( newSize > getSize() ) {
@@ -535,7 +536,7 @@ namespace direct_bt {
POctets & resize(const int newSize) {
if( capacity < newSize ) {
- throw IllegalArgumentException("capacity "+std::to_string(capacity)+" < newSize "+std::to_string(newSize), E_FILE_LINE);
+ throw jau::IllegalArgumentException("capacity "+std::to_string(capacity)+" < newSize "+std::to_string(newSize), E_FILE_LINE);
}
setSize(newSize);
return *this;
@@ -543,7 +544,7 @@ namespace direct_bt {
POctets & recapacity(const int newCapacity) {
if( newCapacity < getSize() ) {
- throw IllegalArgumentException("newCapacity "+std::to_string(newCapacity)+" < size "+std::to_string(getSize()), E_FILE_LINE);
+ throw jau::IllegalArgumentException("newCapacity "+std::to_string(newCapacity)+" < size "+std::to_string(getSize()), E_FILE_LINE);
}
if( newCapacity == capacity ) {
return *this;
@@ -583,7 +584,7 @@ namespace direct_bt {
}
std::string toString() const {
- return "size "+std::to_string(getSize())+", capacity "+std::to_string(getCapacity())+", l->h: "+bytesHexString(get_ptr(), 0, getSize(), true /* lsbFirst */, true /* leading0X */);
+ return "size "+std::to_string(getSize())+", capacity "+std::to_string(getCapacity())+", l->h: "+jau::bytesHexString(get_ptr(), 0, getSize(), true /* lsbFirst */, true /* leading0X */);
}
};
diff --git a/api/direct_bt/UUID.hpp b/api/direct_bt/UUID.hpp
index 809a33dc..04f93ff4 100644
--- a/api/direct_bt/UUID.hpp
+++ b/api/direct_bt/UUID.hpp
@@ -32,7 +32,7 @@
#include <cstdint>
#include <vector>
-#include "BasicTypes.hpp"
+#include <jau/basic_types.hpp>
namespace direct_bt {
@@ -103,7 +103,7 @@ public:
: uuid_t(TypeSize::UUID16_SZ), value(v) { }
uuid16_t(uint8_t const * const buffer, int const byte_offset, bool const littleEndian) noexcept
- : uuid_t(TypeSize::UUID16_SZ), value(get_uint16(buffer, byte_offset, littleEndian)) { }
+ : uuid_t(TypeSize::UUID16_SZ), value(jau::get_uint16(buffer, byte_offset, littleEndian)) { }
uuid16_t(const uuid16_t &o) noexcept = default;
uuid16_t(uuid16_t &&o) noexcept = default;
@@ -130,7 +130,7 @@ public:
: uuid_t(TypeSize::UUID32_SZ), value(v) {}
uuid32_t(uint8_t const * const buffer, int const byte_offset, bool const littleEndian) noexcept
- : uuid_t(TypeSize::UUID32_SZ), value(get_uint32(buffer, byte_offset, littleEndian)) { }
+ : uuid_t(TypeSize::UUID32_SZ), value(jau::get_uint32(buffer, byte_offset, littleEndian)) { }
uuid32_t(const uuid32_t &o) noexcept = default;
uuid32_t(uuid32_t &&o) noexcept = default;
@@ -151,17 +151,17 @@ public:
class uuid128_t : public uuid_t {
public:
- uint128_t value;
+ jau::uint128_t value;
uuid128_t() noexcept : uuid_t(TypeSize::UUID128_SZ) { bzero(value.data, sizeof(value)); }
- uuid128_t(uint128_t const v) noexcept
+ uuid128_t(jau::uint128_t const v) noexcept
: uuid_t(TypeSize::UUID128_SZ), value(v) {}
uuid128_t(const std::string str);
uuid128_t(uint8_t const * const buffer, int const byte_offset, bool const littleEndian) noexcept
- : uuid_t(TypeSize::UUID128_SZ), value(get_uint128(buffer, byte_offset, littleEndian)) { }
+ : uuid_t(TypeSize::UUID128_SZ), value(jau::get_uint128(buffer, byte_offset, littleEndian)) { }
uuid128_t(uuid16_t const & uuid16, uuid128_t const & base_uuid=BT_BASE_UUID, int const uuid16_le_octet_index=12) noexcept;
@@ -192,13 +192,13 @@ inline void put_uuid(uint8_t * buffer, int const byte_offset, const uuid_t &v) n
{
switch(v.getTypeSize()) {
case uuid_t::TypeSize::UUID16_SZ:
- put_uint16(buffer, byte_offset, static_cast<const uuid16_t &>(v).value);
+ jau::put_uint16(buffer, byte_offset, static_cast<const uuid16_t &>(v).value);
break;
case uuid_t::TypeSize::UUID32_SZ:
- put_uint32(buffer, byte_offset, static_cast<const uuid32_t &>(v).value);
+ jau::put_uint32(buffer, byte_offset, static_cast<const uuid32_t &>(v).value);
break;
case uuid_t::TypeSize::UUID128_SZ:
- put_uint128(buffer, byte_offset, static_cast<const uuid128_t &>(v).value);
+ jau::put_uint128(buffer, byte_offset, static_cast<const uuid128_t &>(v).value);
break;
}
}
@@ -206,40 +206,40 @@ inline void put_uuid(uint8_t * buffer, int const byte_offset, const uuid_t &v, b
{
switch(v.getTypeSize()) {
case uuid_t::TypeSize::UUID16_SZ:
- put_uint16(buffer, byte_offset, static_cast<const uuid16_t &>(v).value, littleEndian);
+ jau::put_uint16(buffer, byte_offset, static_cast<const uuid16_t &>(v).value, littleEndian);
break;
case uuid_t::TypeSize::UUID32_SZ:
- put_uint32(buffer, byte_offset, static_cast<const uuid32_t &>(v).value, littleEndian);
+ jau::put_uint32(buffer, byte_offset, static_cast<const uuid32_t &>(v).value, littleEndian);
break;
case uuid_t::TypeSize::UUID128_SZ:
- put_uint128(buffer, byte_offset, static_cast<const uuid128_t &>(v).value, littleEndian);
+ jau::put_uint128(buffer, byte_offset, static_cast<const uuid128_t &>(v).value, littleEndian);
break;
}
}
inline uuid16_t get_uuid16(uint8_t const * buffer, int const byte_offset) noexcept
{
- return uuid16_t(get_uint16(buffer, byte_offset));
+ return uuid16_t(jau::get_uint16(buffer, byte_offset));
}
inline uuid16_t get_uuid16(uint8_t const * buffer, int const byte_offset, bool littleEndian) noexcept
{
- return uuid16_t(get_uint16(buffer, byte_offset, littleEndian));
+ return uuid16_t(jau::get_uint16(buffer, byte_offset, littleEndian));
}
inline uuid32_t get_uuid32(uint8_t const * buffer, int const byte_offset) noexcept
{
- return uuid32_t(get_uint32(buffer, byte_offset));
+ return uuid32_t(jau::get_uint32(buffer, byte_offset));
}
inline uuid32_t get_uuid32(uint8_t const * buffer, int const byte_offset, bool littleEndian) noexcept
{
- return uuid32_t(get_uint32(buffer, byte_offset, littleEndian));
+ return uuid32_t(jau::get_uint32(buffer, byte_offset, littleEndian));
}
inline uuid128_t get_uuid128(uint8_t const * buffer, int const byte_offset) noexcept
{
- return uuid128_t(get_uint128(buffer, byte_offset));
+ return uuid128_t(jau::get_uint128(buffer, byte_offset));
}
inline uuid128_t get_uuid128(uint8_t const * buffer, int const byte_offset, bool littleEndian) noexcept
{
- return uuid128_t(get_uint128(buffer, byte_offset, littleEndian));
+ return uuid128_t(jau::get_uint128(buffer, byte_offset, littleEndian));
}
} /* namespace direct_bt */
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index e20ff993..94f08e8f 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -1,4 +1,7 @@
-include_directories(${PROJECT_SOURCE_DIR}/api)
+include_directories(
+ ${PROJECT_SOURCE_DIR}/jaucpp/include
+ ${PROJECT_SOURCE_DIR}/api
+)
#include_directories(
# ${PROJECT_SOURCE_DIR}/api
diff --git a/examples/direct_bt_scanner00/dbt_scanner00.cpp b/examples/direct_bt_scanner00/dbt_scanner00.cpp
index db42d2e6..0468ba6d 100644
--- a/examples/direct_bt_scanner00/dbt_scanner00.cpp
+++ b/examples/direct_bt_scanner00/dbt_scanner00.cpp
@@ -23,16 +23,18 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#include <direct_bt/DirectBT.hpp>
#include <cinttypes>
-#include "direct_bt/dfa_utf8_decode.hpp"
+#include <jau/dfa_utf8_decode.hpp>
+
+#include <direct_bt/DirectBT.hpp>
extern "C" {
#include <unistd.h>
}
using namespace direct_bt;
+using namespace jau;
/**
* This C++ direct_bt scanner example is a TinyB backward compatible and not fully event driven.
diff --git a/examples/direct_bt_scanner01/dbt_scanner01.cpp b/examples/direct_bt_scanner01/dbt_scanner01.cpp
index 7c666b28..1aed365a 100644
--- a/examples/direct_bt_scanner01/dbt_scanner01.cpp
+++ b/examples/direct_bt_scanner01/dbt_scanner01.cpp
@@ -23,14 +23,18 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#include <direct_bt/DirectBT.hpp>
#include <cinttypes>
+#include <jau/dfa_utf8_decode.hpp>
+
+#include <direct_bt/DirectBT.hpp>
+
extern "C" {
#include <unistd.h>
}
using namespace direct_bt;
+using namespace jau;
/**
* This C++ direct_bt scanner example is a TinyB backward compatible and not fully event driven.
diff --git a/examples/direct_bt_scanner10/dbt_scanner10.cpp b/examples/direct_bt_scanner10/dbt_scanner10.cpp
index 3ea3e0dc..a1dbf9a7 100644
--- a/examples/direct_bt_scanner10/dbt_scanner10.cpp
+++ b/examples/direct_bt_scanner10/dbt_scanner10.cpp
@@ -33,15 +33,16 @@
#include <pthread.h>
-#include <direct_bt/DirectBT.hpp>
+#include <jau/dfa_utf8_decode.hpp>
-#include "direct_bt/dfa_utf8_decode.hpp"
+#include <direct_bt/DirectBT.hpp>
extern "C" {
#include <unistd.h>
}
using namespace direct_bt;
+using namespace jau;
/**
* This C++ scanner example uses the Direct-BT fully event driven workflow
diff --git a/jaucpp/include/cppunit/cppunit.h b/jaucpp/include/cppunit/cppunit.h
new file mode 100644
index 00000000..09c60fb4
--- /dev/null
+++ b/jaucpp/include/cppunit/cppunit.h
@@ -0,0 +1,110 @@
+#ifndef CPPUNIT_H
+#define CPPUNIT_H
+
+// Required headers, or just use #include <bits/stdc++.h>
+#include <iostream>
+#include <sstream>
+#include <cstring>
+#include <string>
+#include <ctime>
+#include <cmath>
+
+
+// CPlusPlusUnit - C++ Unit testing TDD framework (github.com/cppunit/cppunit)
+class Cppunit {
+
+ private:
+ static float machineFloatEpsilon() {
+ float x = 1.0f, res;
+ do {
+ res = x;
+ } while (1.0f + (x /= 2.0f) > 1.0f);
+ return res;
+ }
+
+ static double machineDoubleEpsilon() {
+ double x = 1.0, res;
+ do {
+ res = x;
+ } while (1.0 + (x /= 2.0) > 1.0);
+ return res;
+ }
+
+ public:
+
+ #define PRINTM(m) print(m, __FILE__, __LINE__, __FUNCTION__);
+ #define CHECK(a,b) check<long long>("", a, b, #a, #b, __FILE__, __LINE__, __FUNCTION__);
+ #define CHECKM(m,a,b) check<long long>(m, a, b, #a, #b, __FILE__, __LINE__, __FUNCTION__);
+ #define CHECKD(m,a,b) checkDelta<double>(m, a, b, doubleEpsilon, #a, #b, __FILE__, __LINE__, __FUNCTION__);
+ #define CHECKDD(m,a,b,c) checkDelta<double>(m, a, b, c, #a, #b, __FILE__, __LINE__, __FUNCTION__);
+ #define CHECKT(a) check<bool>("", a, true, #a, "true", __FILE__, __LINE__, __FUNCTION__);
+ #define CHECKTM(m,a) check<bool>(m, a, true, #a, "true", __FILE__, __LINE__, __FUNCTION__);
+ #define CHECKS(a,b) check<cs>("", a, b, #a, #b, __FILE__, __LINE__, __FUNCTION__);
+ #define CHECKSM(m,a,b) check<cs>(m, a, b, #a, #b, __FILE__, __LINE__, __FUNCTION__);
+
+ typedef const std::string& cs;
+
+ int checks, fails; std::ostringstream serr; std::istringstream *in;
+ float floatEpsilon;
+ double doubleEpsilon;
+
+ Cppunit()
+ : checks(0), fails(0), floatEpsilon(machineFloatEpsilon()), doubleEpsilon(machineDoubleEpsilon())
+ {}
+
+ virtual ~Cppunit() {}
+
+ void test_cin(cs s){ in = new std::istringstream(s); std::cin.rdbuf(in->rdbuf()); }
+
+ void fail_hdr(cs stra, cs strb, cs file, int line, cs func) {
+ serr << "==================================================" << std::endl;
+ serr << "FAIL: " << func << std::endl;
+ serr << "--------------------------------------------------" << std::endl;
+ serr << "File \"" << file << "\", line " << line << " in " << func << std::endl;
+ serr << " Checking " << stra << " == " << strb << std::endl;
+ }
+
+ static void print(cs m, cs file, int line, cs func) {
+ std::cerr << std::endl << m << "; file \"" << file << "\", line " << line << " in " << func << std::endl;
+ }
+
+ template <typename T> void check(cs m, T a, T b, cs stra, cs strb, cs file, int line, cs func) {
+ checks++; if (a == b) { std::cout << "."; return; }
+ fails++; std::cout << "F"; fail_hdr(stra, strb, file, line, func);
+ serr << " Error: " << m << ": \"" << a << "\" ! = \"" << b << "\"" << std::endl << std::endl;
+ }
+
+ template <typename T> void checkDelta(cs m, T a, T b, T d, cs stra, cs strb, cs file, int line, cs func) {
+ checks++; if ( labs ( a - b ) < d ) { std::cout << "."; return; }
+ fails++; std::cout << "F"; fail_hdr(stra, strb, file, line, func);
+ serr << " Error: " << m << ": \"" << a << "\" ! = \"" << b << "\" (delta " << d << ")" << std::endl << std::endl;
+ }
+
+ virtual void single_test() {}
+ virtual void test_list() { single_test(); }
+ double dclock() { return double(clock()) / CLOCKS_PER_SEC; }
+ int status() {
+ std::cout << std::endl; if (fails) std::cout << serr.str();
+ std::cout << "--------------------------------------------------" << std::endl;
+ std::cout << "Ran " << checks << " checks in " << dclock() << "s" << std::endl << std::endl;
+ if (fails) std::cout << "FAILED (failures=" << fails << ")"; else std::cout << "OK" << std::endl;
+ return fails > 0;
+ }
+ int run() { std::streambuf* ocin = std::cin.rdbuf(); test_list(); std::cin.rdbuf(ocin); return status(); }
+};
+
+template<> void Cppunit::checkDelta<float>(cs m, float a, float b, float epsilon, cs stra, cs strb, cs file, int line, cs func) {
+ checks++; if ( fabsf( a - b ) < epsilon ) { std::cout << "."; return; }
+ fails++; std::cout << "F"; fail_hdr(stra, strb, file, line, func);
+ serr << " Error: " << m << ": \"" << a << "\" ! = \"" << b << "\" (epsilon " << epsilon << ")" << std::endl << std::endl;
+}
+
+template<> void Cppunit::checkDelta<double>(cs m, double a, double b, double epsilon, cs stra, cs strb, cs file, int line, cs func) {
+ checks++; if ( fabs( a - b ) < epsilon ) { std::cout << "."; return; }
+ fails++; std::cout << "F"; fail_hdr(stra, strb, file, line, func);
+ serr << " Error: " << m << ": \"" << a << "\" ! = \"" << b << "\" (epsilon " << epsilon << ")" << std::endl << std::endl;
+}
+
+
+#endif // CPPUNIT_H
+
diff --git a/api/direct_bt/BasicAlgos.hpp b/jaucpp/include/jau/basic_algos.hpp
index d6d48c95..796a1ce6 100644
--- a/api/direct_bt/BasicAlgos.hpp
+++ b/jaucpp/include/jau/basic_algos.hpp
@@ -23,12 +23,12 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#ifndef BASIC_ALGOS_HPP_
-#define BASIC_ALGOS_HPP_
+#ifndef JAU_BASIC_ALGOS_HPP_
+#define JAU_BASIC_ALGOS_HPP_
#include <mutex>
-namespace direct_bt {
+namespace jau {
/**
* Custom for_each template, using indices instead of iterators,
@@ -73,6 +73,6 @@ namespace direct_bt {
}
-} // namespace direct_bt
+} // namespace jau
-#endif /* BASIC_ALGOS_HPP_ */
+#endif /* JAU_BASIC_ALGOS_HPP_ */
diff --git a/api/direct_bt/BasicTypes.hpp b/jaucpp/include/jau/basic_types.hpp
index d0d60e8f..cdd59d91 100644
--- a/api/direct_bt/BasicTypes.hpp
+++ b/jaucpp/include/jau/basic_types.hpp
@@ -23,8 +23,8 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#ifndef BASIC_TYPES_HPP_
-#define BASIC_TYPES_HPP_
+#ifndef JAU_BASIC_TYPES_HPP_
+#define JAU_BASIC_TYPES_HPP_
#include <cstring>
#include <string>
@@ -37,7 +37,7 @@ extern "C" {
#include <byteswap.h>
}
-namespace direct_bt {
+namespace jau {
/**
* Returns current monotonic time in milliseconds.
@@ -115,15 +115,6 @@ namespace direct_bt {
: RuntimeException("IndexOutOfBoundsException", "Index "+std::to_string(index)+", count "+std::to_string(count)+", data length "+std::to_string(length), file, line) {}
};
- class BluetoothException : public RuntimeException {
- public:
- BluetoothException(std::string const m, const char* file, int line) noexcept
- : RuntimeException("BluetoothException", m, file, line) {}
-
- BluetoothException(const char *m, const char* file, int line) noexcept
- : RuntimeException("BluetoothException", m, file, line) {}
- };
-
/**
// *************************************************
// *************************************************
@@ -437,6 +428,6 @@ namespace direct_bt {
/** trim copy */
std::string trimCopy(const std::string &s) noexcept;
-} // namespace direct_bt
+} // namespace jau
-#endif /* BASIC_TYPES_HPP_ */
+#endif /* JAU_BASIC_TYPES_HPP_ */
diff --git a/api/direct_bt/dbt_debug.hpp b/jaucpp/include/jau/debug.hpp
index ab59cc91..3bc498ba 100644
--- a/api/direct_bt/dbt_debug.hpp
+++ b/jaucpp/include/jau/debug.hpp
@@ -23,8 +23,11 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#ifndef DBT_DEBUG_HPP_
-#define DBT_DEBUG_HPP_
+#ifndef JAU_DEBUG_HPP_
+#define JAU_DEBUG_HPP_
+
+#include <memory>
+#include <vector>
#include <cstdint>
#include <cinttypes>
@@ -37,11 +40,11 @@ extern "C" {
#include <errno.h>
}
-#include "DBTEnv.hpp"
+#include <jau/environment.hpp>
// #define PERF_PRINT_ON 1
-namespace direct_bt {
+namespace jau {
/**
* Returns a de-mangled backtrace string separated by newline excluding this function.
@@ -58,27 +61,27 @@ namespace direct_bt {
void DBG_PRINT_impl(const char * format, ...) noexcept;
- /** Use for environment-variable DBTEnv::DEBUG conditional debug messages, prefix '[elapsed_time] Debug: '. */
- #define DBG_PRINT(...) { if( direct_bt::DBTEnv::get().DEBUG ) { direct_bt::DBG_PRINT_impl(__VA_ARGS__); } }
+ /** Use for environment-variable environment::DEBUG conditional debug messages, prefix '[elapsed_time] Debug: '. */
+ #define DBG_PRINT(...) { if( jau::environment::get().DEBUG ) { jau::DBG_PRINT_impl(__VA_ARGS__); } }
- /** Use for environment-variable DBTEnv::DEBUG_JNI conditional debug messages, prefix '[elapsed_time] Debug: '. */
- #define DBG_JNI_PRINT(...) { if( direct_bt::DBTEnv::get().DEBUG_JNI ) { direct_bt::DBG_PRINT_impl(__VA_ARGS__); } }
+ /** Use for environment-variable environment::DEBUG_JNI conditional debug messages, prefix '[elapsed_time] Debug: '. */
+ #define DBG_JNI_PRINT(...) { if( jau::environment::get().DEBUG_JNI ) { jau::DBG_PRINT_impl(__VA_ARGS__); } }
void WORDY_PRINT_impl(const char * format, ...) noexcept;
/**
- * Use for environment-variable DBTEnv::VERBOSE conditional verbose messages, prefix '[elapsed_time] Wordy: '.
+ * Use for environment-variable environment::VERBOSE conditional verbose messages, prefix '[elapsed_time] Wordy: '.
* <p>
* 'Wordy' is the shorter English form of the Latin word 'verbosus', from which the word 'verbosity' is sourced.
* </p>
*/
- #define WORDY_PRINT(...) { if( direct_bt::DBTEnv::get().VERBOSE ) { direct_bt::WORDY_PRINT_impl(__VA_ARGS__); } }
+ #define WORDY_PRINT(...) { if( jau::environment::get().VERBOSE ) { jau::WORDY_PRINT_impl(__VA_ARGS__); } }
- #define PERF_TS_T0_BASE() const uint64_t _t0 = direct_bt::getCurrentMilliseconds()
+ #define PERF_TS_T0_BASE() const uint64_t _t0 = jau::getCurrentMilliseconds()
- #define PERF_TS_TD_BASE(m) { const uint64_t _td = direct_bt::getCurrentMilliseconds() - _t0; \
- fprintf(stderr, "[%'9" PRIu64 "] PERF %s done in %d ms,\n", direct_bt::DBTEnv::getElapsedMillisecond(), (m), (int)_td); }
+ #define PERF_TS_TD_BASE(m) { const uint64_t _td = jau::getCurrentMilliseconds() - _t0; \
+ fprintf(stderr, "[%'9" PRIu64 "] PERF %s done in %d ms,\n", jau::environment::getElapsedMillisecond(), (m), (int)_td); }
#ifdef PERF_PRINT_ON
#define PERF_TS_T0() PERF_TS_T0_BASE()
#define PERF_TS_TD(m) PERF_TS_TD_BASE(m)
@@ -105,7 +108,7 @@ namespace direct_bt {
void ABORT_impl(const char *func, const char *file, const int line, const char * format, ...) noexcept;
/** Use for unconditional ::abort() call with given messages, prefix '[elapsed_time] ABORT @ FILE:LINE: '. Function also appends last errno and strerror(errno). */
- #define ABORT(...) { direct_bt::ABORT_impl(__func__, __FILE__, __LINE__, __VA_ARGS__); }
+ #define ABORT(...) { jau::ABORT_impl(__func__, __FILE__, __LINE__, __VA_ARGS__); }
/** Use for unconditional error messages, prefix '[elapsed_time] Error @ file:line: '. Function also appends last errno and strerror(errno). */
void ERR_PRINTv(const char *func, const char *file, const int line, const char * format, va_list args) noexcept;
@@ -113,10 +116,10 @@ namespace direct_bt {
void ERR_PRINT_impl(const char *prefix, const bool backtrace, const char *func, const char *file, const int line, const char * format, ...) noexcept;
/** Use for unconditional error messages, prefix '[elapsed_time] Error @ FILE:LINE: '. Function also appends last errno and strerror(errno). */
- #define ERR_PRINT(...) { direct_bt::ERR_PRINT_impl("Error", true /* backtrace */, __func__, __FILE__, __LINE__, __VA_ARGS__); }
+ #define ERR_PRINT(...) { jau::ERR_PRINT_impl("Error", true /* backtrace */, __func__, __FILE__, __LINE__, __VA_ARGS__); }
/** Use for unconditional interruption messages, prefix '[elapsed_time] Interrupted @ FILE:LINE: '. Function also appends last errno and strerror(errno). */
- #define IRQ_PRINT(...) { direct_bt::ERR_PRINT_impl("Interrupted", false /* backtrace */, __func__, __FILE__, __LINE__, __VA_ARGS__); }
+ #define IRQ_PRINT(...) { jau::ERR_PRINT_impl("Interrupted", false /* backtrace */, __func__, __FILE__, __LINE__, __VA_ARGS__); }
/** Use for unconditional warning messages, prefix '[elapsed_time] Warning @ file:line: ' */
void WARN_PRINTv(const char *func, const char *file, const int line, const char * format, va_list args) noexcept;
@@ -124,7 +127,7 @@ namespace direct_bt {
void WARN_PRINT_impl(const char *func, const char *file, const int line, const char * format, ...) noexcept;
/** Use for unconditional warning messages, prefix '[elapsed_time] Warning @ FILE:LINE: ' */
- #define WARN_PRINT(...) { direct_bt::WARN_PRINT_impl(__func__, __FILE__, __LINE__, __VA_ARGS__); }
+ #define WARN_PRINT(...) { jau::WARN_PRINT_impl(__func__, __FILE__, __LINE__, __VA_ARGS__); }
/** Use for unconditional informal messages, prefix '[elapsed_time] Info: '. */
void INFO_PRINT(const char * format, ...) noexcept;
@@ -136,7 +139,7 @@ namespace direct_bt {
void COND_PRINT_impl(const char * format, ...) noexcept;
/** Use for conditional plain messages, prefix '[elapsed_time] '. */
- #define COND_PRINT(C, ...) { if( C ) { direct_bt::COND_PRINT_impl(__VA_ARGS__); } }
+ #define COND_PRINT(C, ...) { if( C ) { jau::COND_PRINT_impl(__VA_ARGS__); } }
template<class ListElemType>
@@ -154,6 +157,6 @@ namespace direct_bt {
}
}
-} // namespace direct_bt
+} // namespace jau
-#endif /* DBT_DEBUG_HPP_ */
+#endif /* JAU_DEBUG_HPP_ */
diff --git a/api/direct_bt/dfa_utf8_decode.hpp b/jaucpp/include/jau/dfa_utf8_decode.hpp
index ecd8ae54..308858ea 100644
--- a/api/direct_bt/dfa_utf8_decode.hpp
+++ b/jaucpp/include/jau/dfa_utf8_decode.hpp
@@ -24,8 +24,8 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#ifndef DFA_UTF8_DECODE_HPP_
-#define DFA_UTF8_DECODE_HPP_
+#ifndef JAU_DFA_UTF8_DECODE_HPP_
+#define JAU_DFA_UTF8_DECODE_HPP_
#define DFA_UTF8_ACCEPT 0
#define DFA_UTF8_REJECT 12
@@ -34,20 +34,22 @@
#include <cstdint>
#include <cinttypes>
-uint32_t dfa_utf8_decode(uint32_t & state, uint32_t & codep, const uint32_t byte_value);
+namespace jau {
+ uint32_t dfa_utf8_decode(uint32_t & state, uint32_t & codep, const uint32_t byte_value);
-/**
- * Returns all valid consecutive UTF-8 characters within buffer
- * in the range up to buffer_size or until EOS.
- * <p>
- * In case a non UTF-8 character has been detected,
- * the content will be cut off and the decoding loop ends.
- * </p>
- * <p>
- * Method utilizes a finite state machine detecting variable length UTF-8 codes.
- * See Bjoern Hoehrmann's site <http://bjoern.hoehrmann.de/utf-8/decoder/dfa/> for details.
- * </p>
- */
-std::string dfa_utf8_decode(const uint8_t *buffer, const size_t buffer_size);
+ /**
+ * Returns all valid consecutive UTF-8 characters within buffer
+ * in the range up to buffer_size or until EOS.
+ * <p>
+ * In case a non UTF-8 character has been detected,
+ * the content will be cut off and the decoding loop ends.
+ * </p>
+ * <p>
+ * Method utilizes a finite state machine detecting variable length UTF-8 codes.
+ * See Bjoern Hoehrmann's site <http://bjoern.hoehrmann.de/utf-8/decoder/dfa/> for details.
+ * </p>
+ */
+ std::string dfa_utf8_decode(const uint8_t *buffer, const size_t buffer_size);
+} /* namespace jau */
-#endif /* DFA_UTF8_DECODE_HPP_ */
+#endif /* JAU_DFA_UTF8_DECODE_HPP_ */
diff --git a/api/direct_bt/DBTEnv.hpp b/jaucpp/include/jau/environment.hpp
index 9cb8db20..33a05e65 100644
--- a/api/direct_bt/DBTEnv.hpp
+++ b/jaucpp/include/jau/environment.hpp
@@ -23,8 +23,8 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#ifndef DBT_ENV_HPP_
-#define DBT_ENV_HPP_
+#ifndef JAU_ENV_HPP_
+#define JAU_ENV_HPP_
#include <cstdint>
#include <cinttypes>
@@ -36,28 +36,28 @@ extern "C" {
#include <errno.h>
}
-#include "BasicTypes.hpp"
+#include <jau/basic_types.hpp>
-namespace direct_bt {
+namespace jau {
/**
- * Base direct_bt environment class,
+ * Base jau environment class,
* merely to tag all environment settings by inheritance and hence documentation.
* <p>
- * See main direct_bt environment {@link DBTEnv} and
- * {@link DBTEnv::getExplodingProperties(const std::string & prefixDomain)}.
+ * See main environment {@link environment} and
+ * {@link environment::getExplodingProperties(const std::string & prefixDomain)}.
* </p>
*/
- class DBTEnvrionment {
+ class root_environment {
};
/**
- * Main direct_bt environment class,
+ * Main jau environment class,
* supporting environment variable access and fetching elapsed time using its stored startup-time.
*/
- class DBTEnv : public DBTEnvrionment {
+ class environment : public root_environment {
private:
- DBTEnv() noexcept;
+ environment() noexcept;
static bool debug;
@@ -201,7 +201,7 @@ namespace direct_bt {
*/
static bool getExplodingProperties(const std::string & prefixDomain) noexcept;
- static DBTEnv& get() noexcept {
+ static environment& get() noexcept {
/**
* Thread safe starting with C++11 6.7:
*
@@ -212,7 +212,7 @@ namespace direct_bt {
*
* Avoiding non-working double checked locking.
*/
- static DBTEnv e;
+ static environment e;
return e;
}
@@ -261,7 +261,7 @@ namespace direct_bt {
const bool VERBOSE;
};
-} // namespace direct_bt
+} // namespace jau
-#endif /* DBT_ENV_HPP_ */
+#endif /* JAU_ENV_HPP_ */
diff --git a/api/direct_bt/FunctionDef.hpp b/jaucpp/include/jau/function_def.hpp
index b30e4bdd..d155c95e 100644
--- a/api/direct_bt/FunctionDef.hpp
+++ b/jaucpp/include/jau/function_def.hpp
@@ -23,8 +23,8 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#ifndef CLASS_FUNCTION_HPP_
-#define CLASS_FUNCTION_HPP_
+#ifndef JAU_FUNCTION_HPP_
+#define JAU_FUNCTION_HPP_
#include <cstring>
#include <string>
@@ -33,9 +33,9 @@
#include <vector>
#include <functional>
-#include "BasicTypes.hpp"
+#include <jau/basic_types.hpp>
-namespace direct_bt {
+namespace jau {
/**
* One goal to _produce_ the member-function type instance
@@ -408,6 +408,6 @@ namespace direct_bt {
return FunctionDef<R, A...>( new StdInvocationFunc<R, A...>(id) );
}
-} // namespace direct_bt
+} // namespace jau
-#endif /* CLASS_FUNCTION_HPP_ */
+#endif /* JAU_FUNCTION_HPP_ */
diff --git a/api/direct_bt/JavaUplink.hpp b/jaucpp/include/jau/java_uplink.hpp
index 9812a4e5..c9be15c6 100644
--- a/api/direct_bt/JavaUplink.hpp
+++ b/jaucpp/include/jau/java_uplink.hpp
@@ -23,52 +23,52 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#ifndef JAVA_ACCESS_HPP_
-#define JAVA_ACCESS_HPP_
+#ifndef JAU_JAVA_UPLINK_HPP_
+#define JAU_JAVA_UPLINK_HPP_
#include <string>
#include <memory>
-namespace direct_bt {
+#include <jau/basic_types.hpp>
- #define JAVA_DBT_PACKAGE "direct_bt/tinyb/"
+namespace jau {
/**
- * Pure virtual JavaAnonObj, hiding Java JNI details from API,
+ * Pure virtual JavaAnon, hiding Java JNI details from API,
* to be implemented by JNI module.
* <p>
* One implementation is JavaGlobalObj within the JNI module,
* wrapping a JNIGlobalRef instance.
* </p>
*/
- class JavaAnonObj {
+ class JavaAnon {
public:
- virtual ~JavaAnonObj() noexcept { }
- virtual std::string toString() const noexcept { return "JavaAnonObj[???]"; }
+ virtual ~JavaAnon() noexcept { }
+ virtual std::string toString() const noexcept { return "JavaAnon[???]"; }
/** Clears the java reference, i.e. nulling it, without deleting the global reference via JNI. */
virtual void clear() noexcept = 0;
};
/**
- * Sharing the anonymous Java object (JavaAnonObj),
+ * Sharing the anonymous Java object (JavaAnon),
* i.e. exposing the Java object uplink to the C++ implementation.
*/
class JavaUplink {
private:
- std::shared_ptr<JavaAnonObj> javaObjectRef;
+ std::shared_ptr<JavaAnon> javaObjectRef;
public:
- virtual std::string toString() const noexcept { return "JavaUplink["+direct_bt::aptrHexString(this)+"]"; }
+ virtual std::string toString() const noexcept { return "JavaUplink["+jau::aptrHexString(this)+"]"; }
virtual std::string get_java_class() const noexcept = 0;
- std::string javaObjectToString() const noexcept { return nullptr == javaObjectRef ? "JavaAnonObj[null]" : javaObjectRef->toString(); }
+ std::string javaObjectToString() const noexcept { return nullptr == javaObjectRef ? "JavaAnon[null]" : javaObjectRef->toString(); }
- std::shared_ptr<JavaAnonObj> getJavaObject() noexcept { return javaObjectRef; }
+ std::shared_ptr<JavaAnon> getJavaObject() noexcept { return javaObjectRef; }
- /** Assigns a new shared JavaAnonObj reference, replaced item might be deleted via JNI from dtor */
- void setJavaObject(std::shared_ptr<JavaAnonObj> objRef) noexcept { javaObjectRef = objRef; }
+ /** Assigns a new shared JavaAnon reference, replaced item might be deleted via JNI from dtor */
+ void setJavaObject(std::shared_ptr<JavaAnon> objRef) noexcept { javaObjectRef = objRef; }
/** Clears the java reference, i.e. nulling it, without deleting the global reference via JNI. */
void clearJavaObject() noexcept {
@@ -77,12 +77,17 @@ namespace direct_bt {
}
}
+ /**
+ * Throws an IllegalStateException if isValid() == false
+ */
+ virtual void checkValid() const {}
+
virtual ~JavaUplink() noexcept {
javaObjectRef = nullptr;
}
};
-} /* namespace direct_bt */
+} /* namespace jau */
-#endif /* JAVA_ACCESS_HPP_ */
+#endif /* JAU_JAVA_UPLINK_HPP_ */
diff --git a/jaucpp/include/jau/jni/helper_jni.hpp b/jaucpp/include/jau/jni/helper_jni.hpp
new file mode 100644
index 00000000..9605252d
--- /dev/null
+++ b/jaucpp/include/jau/jni/helper_jni.hpp
@@ -0,0 +1,434 @@
+/*
+ * Author: Sven Gothel <[email protected]>
+ * Copyright (c) 2020 Gothel Software e.K.
+ * Copyright (c) 2020 ZAFENA AB
+ *
+ * Author: Andrei Vasiliu <[email protected]>
+ * Copyright (c) 2016 Intel Corporation.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef JAU_HELPER_JNI_HPP_
+#define JAU_HELPER_JNI_HPP_
+
+#include <vector>
+#include <memory>
+#include <functional>
+#include <jni.h>
+
+#include <jau/java_uplink.hpp>
+#include <jau/basic_types.hpp>
+
+#include <jau/jni/jni_mem.hpp>
+
+namespace jau {
+
+ //
+ // C++ <-> java exceptions
+ //
+
+ /**
+ * Return true if a java exception occurred, otherwise false.
+ * <p>
+ * In case of an exception, the information might be logged to stderr.
+ * </p>
+ * <p>
+ * In case of an exception, user shall release resourced in their JNI code
+ * and leave immediately.
+ * </p>
+ */
+ bool java_exception_check(JNIEnv *env, const char* file, int line);
+
+ /**
+ * Throws a C++ exception if a java exception occurred, otherwise do nothing.
+ * <p>
+ * In case of an exception, the information might be logged to stderr.
+ * </p>
+ * <p>
+ * In case of an exception and hence thrown C++ exception,
+ * might want to catch all and handle it via {@link #rethrow_and_raise_java_exception(JNIEnv*)}.
+ * </p>
+ */
+ void java_exception_check_and_throw(JNIEnv *env, const char* file, int line);
+
+ void print_native_caught_exception_fwd2java(const std::exception &e, const char* file, int line);
+ void print_native_caught_exception_fwd2java(const std::string &msg, const char* file, int line);
+ void print_native_caught_exception_fwd2java(const char * cmsg, const char* file, int line);
+
+ void raise_java_exception(JNIEnv *env, const std::exception &e, const char* file, int line);
+ void raise_java_exception(JNIEnv *env, const std::runtime_error &e, const char* file, int line);
+ void raise_java_exception(JNIEnv *env, const jau::RuntimeException &e, const char* file, int line);
+ void raise_java_exception(JNIEnv *env, const jau::InternalError &e, const char* file, int line);
+ void raise_java_exception(JNIEnv *env, const jau::NullPointerException &e, const char* file, int line);
+ void raise_java_exception(JNIEnv *env, const jau::IllegalArgumentException &e, const char* file, int line);
+ void raise_java_exception(JNIEnv *env, const std::invalid_argument &e, const char* file, int line);
+ void raise_java_exception(JNIEnv *env, const jau::IllegalStateException &e, const char* file, int line);
+ void raise_java_exception(JNIEnv *env, const jau::UnsupportedOperationException &e, const char* file, int line);
+ void raise_java_exception(JNIEnv *env, const jau::IndexOutOfBoundsException &e, const char* file, int line);
+ void raise_java_exception(JNIEnv *env, const std::bad_alloc &e, const char* file, int line);
+ void raise_java_exception(JNIEnv *env, const jau::OutOfMemoryError &e, const char* file, int line);
+
+ /**
+ * Re-throw current exception and raise respective java exception
+ * using any matching function above.
+ */
+ void rethrow_and_raise_java_exception_jauimpl(JNIEnv *env, const char* file, int line);
+
+ /**
+ * Re-throw current exception and raise respective java exception
+ * using any matching function above.
+ */
+ #define rethrow_and_raise_java_exception_jau(E) rethrow_and_raise_java_exception_jauimpl((E), __FILE__, __LINE__)
+ // inline void rethrow_and_raise_java_exception_jau(JNIEnv *env) { rethrow_and_raise_java_exception_jauimpl(env, __FILE__, __LINE__); }
+
+ //
+ // Basic
+ //
+
+ jfieldID getField(JNIEnv *env, jobject obj, const char* field_name, const char* field_signature);
+ inline jfieldID getInstanceField(JNIEnv *env, jobject obj) {
+ return getField(env, obj, "nativeInstance", "J");
+ }
+
+ jclass search_class(JNIEnv *env, const char *clazz_name);
+ jclass search_class(JNIEnv *env, jobject obj);
+ jclass search_class(JNIEnv *env, JavaUplink &object);
+
+ jmethodID search_method(JNIEnv *env, jclass clazz, const char *method_name,
+ const char *prototype, bool is_static);
+ jfieldID search_field(JNIEnv *env, jclass clazz, const char *field_name,
+ const char *type, bool is_static);
+
+ bool from_jboolean_to_bool(jboolean val);
+ std::string from_jstring_to_string(JNIEnv *env, jstring str);
+ jstring from_string_to_jstring(JNIEnv *env, const std::string & str);
+
+ jobject get_new_arraylist(JNIEnv *env, unsigned int size, jmethodID *add);
+
+ //
+ // C++ JavaAnon implementation
+ //
+
+ /**
+ * Implementation for JavaAnon,
+ * by simply wrapping a JNIGlobalRef instance.
+ */
+ class JavaGlobalObj : public JavaAnon {
+ private:
+ JNIGlobalRef javaObjectRef;
+ jmethodID mNotifyDeleted;
+
+ public:
+ static inline void check(const std::shared_ptr<JavaAnon> & shref, const char* file, int line) {
+ if( nullptr == shref ) {
+ throw RuntimeException("JavaGlobalObj::check: Null shared-JavaAnonObj", file, line);
+ }
+ const jobject obj = static_cast<const JavaGlobalObj*>(shref.get())->getObject();
+ if( nullptr == obj ) {
+ throw RuntimeException("JavaGlobalObj::check: Null object", file, line);
+ }
+ }
+ static bool isValid(const std::shared_ptr<JavaAnon> & shref) noexcept {
+ if( nullptr == shref ) {
+ return false;
+ }
+ const jobject obj = static_cast<const JavaGlobalObj*>(shref.get())->getObject();
+ if( nullptr == obj ) {
+ return false;
+ }
+ return true;
+ }
+ JavaGlobalObj(jobject obj, jmethodID mNotifyDeleted) noexcept
+ : javaObjectRef(obj), mNotifyDeleted(mNotifyDeleted) { }
+
+ JavaGlobalObj(const JavaGlobalObj &o) noexcept = default;
+ JavaGlobalObj(JavaGlobalObj &&o) noexcept = default;
+ JavaGlobalObj& operator=(const JavaGlobalObj &o) noexcept = default;
+ JavaGlobalObj& operator=(JavaGlobalObj &&o) noexcept = default;
+
+ virtual ~JavaGlobalObj() noexcept;
+
+ std::string toString() const noexcept override {
+ const uint64_t ref = (uint64_t)(void*)javaObjectRef.getObject();
+ return "JavaGlobalObj["+uint64HexString(ref, true)+"]";
+ }
+
+ /** Clears the java reference, i.e. nulling it, without deleting the global reference via JNI. */
+ void clear() noexcept override { javaObjectRef.clear(); }
+
+ JNIGlobalRef & getJavaObject() noexcept { return javaObjectRef; }
+
+ /* Provides access to the stored GlobalRef as an jobject. */
+ jobject getObject() const noexcept { return javaObjectRef.getObject(); }
+ /* Provides access to the stored GlobalRef as a jclass. */
+ jclass getClass() const noexcept { return javaObjectRef.getClass(); }
+
+ /* Provides access to the stored GlobalRef as an getJavaObject. */
+ static JNIGlobalRef GetJavaObject(const std::shared_ptr<JavaAnon> & shref) noexcept {
+ return static_cast<JavaGlobalObj*>(shref.get())->getJavaObject();
+ }
+ /* Provides access to the stored GlobalRef as an jobject. */
+ static jobject GetObject(const std::shared_ptr<JavaAnon> & shref) noexcept {
+ return static_cast<JavaGlobalObj*>(shref.get())->getObject();
+ }
+
+ /* Provides access to the stored GlobalRef as a jclass. */
+ static jclass GetClass(const std::shared_ptr<JavaAnon> & shref) noexcept {
+ return static_cast<JavaGlobalObj*>(shref.get())->getClass();
+ }
+ };
+
+ //
+ // C++ JavaUplink <-> java access, assuming it implementats JavaUplink: field "long nativeInstance" and native method 'void checkValid()' etc
+ //
+
+ template <typename T>
+ T *getJavaUplinkObject(JNIEnv *env, jobject obj)
+ {
+ jlong instance = env->GetLongField(obj, getInstanceField(env, obj));
+ T *t = reinterpret_cast<T *>(instance);
+ if (t == nullptr) {
+ throw std::runtime_error("Trying to acquire null NativeObject");
+ }
+ t->checkValid();
+ return t;
+ }
+
+ template <typename T>
+ T *getJavaUplinkObjectUnchecked(JNIEnv *env, jobject obj)
+ {
+ jlong instance = env->GetLongField(obj, getInstanceField(env, obj));
+ return reinterpret_cast<T *>(instance);
+ }
+
+ template <typename T>
+ void setJavaUplinkObject(JNIEnv *env, jobject obj, T *t)
+ {
+ if (t == nullptr) {
+ throw std::runtime_error("Trying to create null NativeObject");
+ }
+ jlong instance = reinterpret_cast<jlong>(t);
+ env->SetLongField(obj, getInstanceField(env, obj), instance);
+ }
+
+ //
+ // C++ JavaAnon <-> java access, all generic
+ //
+
+ template <typename T>
+ T *castInstance(jlong instance)
+ {
+ T *t = reinterpret_cast<T *>(instance);
+ if (t == nullptr) {
+ throw std::runtime_error("Trying to cast null object");
+ }
+ return t;
+ }
+
+ template <typename T>
+ T *getObjectRef(JNIEnv *env, jobject obj, const char* field_name)
+ {
+ jlong jobj = env->GetLongField(obj, getField(env, obj, field_name, "J"));
+ java_exception_check_and_throw(env, E_FILE_LINE);
+ return reinterpret_cast<T *>(jobj);
+ }
+
+ template <typename T>
+ void setObjectRef(JNIEnv *env, jobject obj, T *t, const char* field_name)
+ {
+ jlong jobj = reinterpret_cast<jlong>(t);
+ env->SetLongField(obj, getField(env, obj, field_name, "J"), jobj);
+ java_exception_check_and_throw(env, E_FILE_LINE);
+ }
+
+ template <typename T>
+ T *getInstance(JNIEnv *env, jobject obj)
+ {
+ jlong instance = env->GetLongField(obj, getInstanceField(env, obj));
+ T *t = reinterpret_cast<T *>(instance);
+ if (t == nullptr) {
+ throw std::runtime_error("Trying to acquire null object");
+ }
+ return t;
+ }
+
+ template <typename T>
+ T *getInstanceUnchecked(JNIEnv *env, jobject obj)
+ {
+ jlong instance = env->GetLongField(obj, getInstanceField(env, obj));
+ return reinterpret_cast<T *>(instance);
+ }
+
+ template <typename T>
+ void setInstance(JNIEnv *env, jobject obj, T *t)
+ {
+ if (t == nullptr) {
+ throw std::runtime_error("Trying to create null object");
+ }
+ jlong instance = reinterpret_cast<jlong>(t);
+ env->SetLongField(obj, getInstanceField(env, obj), instance);
+ }
+
+ inline void clearInstance(JNIEnv *env, jobject obj) {
+ env->SetLongField(obj, getInstanceField(env, obj), 0);
+ }
+
+ template <typename T>
+ jobject generic_clone(JNIEnv *env, jobject obj)
+ {
+ T *obj_generic = getInstance<T>(env, obj);
+ T *copy_generic = obj_generic->clone();
+
+ jclass generic_class = search_class(env, *copy_generic);
+ jmethodID generic_ctor = search_method(env, generic_class, "<init>", "(J)V", false);
+
+ jobject result = env->NewObject(generic_class, generic_ctor, (jlong)copy_generic);
+ if (!result)
+ {
+ throw std::runtime_error("cannot create instance of class");
+ }
+
+ return result;
+ }
+
+ //
+ // C++ <-> java type mapping
+ //
+
+ template <typename T>
+ jobject convert_vector_sharedptr_to_jarraylist(JNIEnv *env, std::vector<std::shared_ptr<T>>& array)
+ {
+ unsigned int array_size = array.size();
+
+ jmethodID arraylist_add;
+ jobject result = get_new_arraylist(env, array_size, &arraylist_add);
+
+ if (0 == array_size) {
+ return result;
+ }
+
+ for (unsigned int i = 0; i < array_size; ++i) {
+ std::shared_ptr<T> elem = array[i];
+ std::shared_ptr<JavaAnon> objref = elem->getJavaObject();
+ if ( nullptr == objref ) {
+ throw InternalError("JavaUplink element of array has no valid java-object: "+elem->toString(), E_FILE_LINE);
+ }
+ env->CallBooleanMethod(result, arraylist_add, JavaGlobalObj::GetObject(objref));
+ }
+ return result;
+ }
+
+ template <typename T>
+ jobject convert_vector_uniqueptr_to_jarraylist(JNIEnv *env, std::vector<std::unique_ptr<T>>& array,
+ const char *ctor_prototype)
+ {
+ unsigned int array_size = array.size();
+
+ jmethodID arraylist_add;
+ jobject result = get_new_arraylist(env, array_size, &arraylist_add);
+
+ if (array_size == 0)
+ {
+ return result;
+ }
+
+ jclass clazz = search_class(env, T::java_class().c_str());
+ jmethodID clazz_ctor = search_method(env, clazz, "<init>", ctor_prototype, false);
+
+ for (unsigned int i = 0; i < array_size; ++i)
+ {
+ T *elem = array[i].release();
+ jobject object = env->NewObject(clazz, clazz_ctor, (jlong)elem);
+ if (!object)
+ {
+ throw jau::InternalError("cannot create instance of class", E_FILE_LINE);
+ }
+ env->CallBooleanMethod(result, arraylist_add, object);
+ java_exception_check_and_throw(env, E_FILE_LINE);
+ }
+ return result;
+ }
+
+ template <typename T>
+ jobject convert_vector_uniqueptr_to_jarraylist(JNIEnv *env, std::vector<std::unique_ptr<T>>& array,
+ const char *ctor_prototype, std::function<jobject(JNIEnv*, jclass, jmethodID, T*)> ctor)
+ {
+ unsigned int array_size = array.size();
+
+ jmethodID arraylist_add;
+ jobject result = get_new_arraylist(env, array_size, &arraylist_add);
+
+ if (array_size == 0)
+ {
+ return result;
+ }
+
+ jclass clazz = search_class(env, T::java_class().c_str());
+ jmethodID clazz_ctor = search_method(env, clazz, "<init>", ctor_prototype, false);
+
+ for (unsigned int i = 0; i < array_size; ++i)
+ {
+ T *elem = array[i].release();
+ jobject object = ctor(env, clazz, clazz_ctor, elem);
+ if (!object)
+ {
+ throw std::runtime_error("cannot create instance of class\n");
+ }
+ env->CallBooleanMethod(result, arraylist_add, object);
+ java_exception_check_and_throw(env, E_FILE_LINE);
+ }
+ return result;
+ }
+
+ template <typename T>
+ jobject convert_vector_sharedptr_to_jarraylist(JNIEnv *env, std::vector<std::shared_ptr<T>>& array,
+ const char *ctor_prototype, std::function<jobject(JNIEnv*, jclass, jmethodID, T*)> ctor)
+ {
+ unsigned int array_size = array.size();
+
+ jmethodID arraylist_add;
+ jobject result = get_new_arraylist(env, array_size, &arraylist_add);
+
+ if (array_size == 0)
+ {
+ return result;
+ }
+
+ jclass clazz = search_class(env, T::java_class().c_str());
+ jmethodID clazz_ctor = search_method(env, clazz, "<init>", ctor_prototype, false);
+
+ for (unsigned int i = 0; i < array_size; ++i)
+ {
+ T *elem = array[i].get();
+ jobject object = ctor(env, clazz, clazz_ctor, elem);
+ if (!object)
+ {
+ throw std::runtime_error("cannot create instance of class\n");
+ }
+ env->CallBooleanMethod(result, arraylist_add, object);
+ java_exception_check_and_throw(env, E_FILE_LINE);
+ }
+ return result;
+ }
+
+} // namespace direct_bt
+
+#endif /* JAU_HELPER_JNI_HPP_ */
diff --git a/java/jni/JNIMem.hpp b/jaucpp/include/jau/jni/jni_mem.hpp
index ac6cf11c..31fd6622 100644
--- a/java/jni/JNIMem.hpp
+++ b/jaucpp/include/jau/jni/jni_mem.hpp
@@ -1,11 +1,11 @@
/*
- * Author: Petre Eftime <[email protected]>
- * Copyright (c) 2016 Intel Corporation.
- *
* Author: Sven Gothel <[email protected]>
* Copyright (c) 2020 Gothel Software e.K.
* Copyright (c) 2020 ZAFENA AB
*
+ * Author: Petre Eftime <[email protected]>
+ * Copyright (c) 2016 Intel Corporation.
+ *
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
@@ -26,13 +26,13 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#ifndef JNIMEM__HPP_
-#define JNIMEM__HPP_
+#ifndef JAU_JNIMEM__HPP_
+#define JAU_JNIMEM__HPP_
#include <jni.h>
#include <stdexcept>
-#include "BasicTypes.hpp"
+#include <jau/basic_types.hpp>
extern JavaVM* vm;
@@ -79,7 +79,7 @@ private:
public:
static inline void check(jobject object, const char* file, int line) {
if( nullptr == object ) {
- throw direct_bt::RuntimeException("JNIGlobalRef::check: Null jobject", file, line);
+ throw jau::RuntimeException("JNIGlobalRef::check: Null jobject", file, line);
}
}
@@ -194,5 +194,5 @@ public:
bool getIsCopy() const { return isCopy; }
};
-#endif /* JNIMEM__HPP_ */
+#endif /* JAU_JNIMEM__HPP_ */
diff --git a/api/direct_bt/OrderedAtomic.hpp b/jaucpp/include/jau/ordered_atomic.hpp
index f17a5ffd..b4a6ba89 100644
--- a/api/direct_bt/OrderedAtomic.hpp
+++ b/jaucpp/include/jau/ordered_atomic.hpp
@@ -23,13 +23,13 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#ifndef ORDERED_ATOMIC_HPP_
-#define ORDERED_ATOMIC_HPP_
+#ifndef JAU_ORDERED_ATOMIC_HPP_
+#define JAU_ORDERED_ATOMIC_HPP_
#include <atomic>
#include <memory>
-namespace direct_bt {
+namespace jau {
#ifndef CXX_ALWAYS_INLINE
# define CXX_ALWAYS_INLINE inline __attribute__((__always_inline__))
@@ -213,6 +213,6 @@ template <typename _Tp, std::memory_order _MO> struct ordered_atomic : private s
/** Relaxed non-SC atomic integral scalar integer. Memory-Model (MM) only guarantees the atomic value, _no_ sequential consistency (SC) between acquire (read) and release (write). */
typedef ordered_atomic<int, std::memory_order::memory_order_relaxed> relaxed_atomic_int;
-} /* namespace direct_bt */
+} /* namespace jau */
-#endif /* ORDERED_ATOMIC_HPP_ */
+#endif /* JAU_ORDERED_ATOMIC_HPP_ */
diff --git a/api/direct_bt/LFRingbuffer.hpp b/jaucpp/include/jau/ringbuffer.hpp
index 0a255839..3c2646b8 100644
--- a/api/direct_bt/LFRingbuffer.hpp
+++ b/jaucpp/include/jau/ringbuffer.hpp
@@ -23,12 +23,9 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#ifndef LFRINGBUFFER_HPP_
-#define LFRINGBUFFER_HPP_
+#ifndef JAU_RINGBUFFER_HPP_
+#define JAU_RINGBUFFER_HPP_
-#include <cstring>
-#include <string>
-#include <cstdint>
#include <atomic>
#include <memory>
#include <mutex>
@@ -36,18 +33,19 @@
#include <chrono>
#include <algorithm>
-#include "dbt_debug.hpp"
-
-#include "OrderedAtomic.hpp"
-
-#include "BasicTypes.hpp"
+#include <cstring>
+#include <string>
+#include <cstdint>
-#include "Ringbuffer.hpp"
+#include <jau/debug.hpp>
+#include <jau/ordered_atomic.hpp>
+#include <jau/basic_types.hpp>
+#include <jau/ringbuffer_if.hpp>
-namespace direct_bt {
+namespace jau {
/**
- * Simple implementation of {@link Ringbuffer},
+ * Simple implementation of {@link ringbuffer_if},
* exposing <i>lock-free</i>
* {@link #get() get*(..)} and {@link #put(Object) put*(..)} methods.
* <p>
@@ -87,7 +85,7 @@ namespace direct_bt {
* - std::memory_order <https://en.cppreference.com/w/cpp/atomic/memory_order>
* </pre>
*/
-template <typename T, std::nullptr_t nullelem> class LFRingbuffer : public Ringbuffer<T> {
+template <typename T, std::nullptr_t nullelem> class ringbuffer : public ringbuffer_if<T> {
private:
std::mutex syncRead, syncMultiRead; // Memory-Model (MM) guaranteed sequential consistency (SC) between acquire and release
std::mutex syncWrite, syncMultiWrite; // ditto
@@ -107,7 +105,7 @@ template <typename T, std::nullptr_t nullelem> class LFRingbuffer : public Ringb
delete[] a;
}
- void cloneFrom(const bool allocArrayAndCapacity, const LFRingbuffer & source) noexcept {
+ void cloneFrom(const bool allocArrayAndCapacity, const ringbuffer & source) noexcept {
if( allocArrayAndCapacity ) {
capacityPlusOne = source.capacityPlusOne;
if( nullptr != array ) {
@@ -268,7 +266,7 @@ template <typename T, std::nullptr_t nullelem> class LFRingbuffer : public Ringb
std::string toString() const noexcept override {
const std::string es = isEmpty() ? ", empty" : "";
const std::string fs = isFull() ? ", full" : "";
- return "LFRingbuffer<?>[size "+std::to_string(size)+" / "+std::to_string(capacityPlusOne-1)+
+ return "ringbuffer<?>[size "+std::to_string(size)+" / "+std::to_string(capacityPlusOne-1)+
", writePos "+std::to_string(writePos)+", readPos "+std::to_string(readPos)+es+fs+"]";
}
@@ -287,7 +285,7 @@ template <typename T, std::nullptr_t nullelem> class LFRingbuffer : public Ringb
* <pre>
* Integer[] source = new Integer[10];
* // fill source with content ..
- * Ringbuffer<Integer> rb = new LFRingbuffer<Integer>(source);
+ * ringbuffer<Integer> rb = new ringbuffer<Integer>(source);
* </pre>
* </p>
* <p>
@@ -300,14 +298,14 @@ template <typename T, std::nullptr_t nullelem> class LFRingbuffer : public Ringb
* @param copyFrom mandatory source array determining ring buffer's net {@link #capacity()} and initial content.
* @throws IllegalArgumentException if <code>copyFrom</code> is <code>nullptr</code>
*/
- LFRingbuffer(const std::vector<T> & copyFrom) noexcept
+ ringbuffer(const std::vector<T> & copyFrom) noexcept
: capacityPlusOne(copyFrom.size() + 1), array(newArray(capacityPlusOne)),
readPos(0), writePos(0), size(0)
{
resetImpl(copyFrom.data(), copyFrom.size());
}
- LFRingbuffer(const T * copyFrom, const int copyFromSize) noexcept
+ ringbuffer(const T * copyFrom, const int copyFromSize) noexcept
: capacityPlusOne(copyFromSize + 1), array(newArray(capacityPlusOne)),
readPos(0), writePos(0), size(0)
{
@@ -319,7 +317,7 @@ template <typename T, std::nullptr_t nullelem> class LFRingbuffer : public Ringb
* <p>
* Example for a 10 element Integer array:
* <pre>
- * Ringbuffer<Integer> rb = new LFRingbuffer<Integer>(10, Integer[].class);
+ * ringbuffer<Integer> rb = new ringbuffer<Integer>(10, Integer[].class);
* </pre>
* </p>
* <p>
@@ -331,16 +329,16 @@ template <typename T, std::nullptr_t nullelem> class LFRingbuffer : public Ringb
* @param arrayType the array type of the created empty internal array.
* @param capacity the initial net capacity of the ring buffer
*/
- LFRingbuffer(const int capacity) noexcept
+ ringbuffer(const int capacity) noexcept
: capacityPlusOne(capacity + 1), array(newArray(capacityPlusOne)),
readPos(0), writePos(0), size(0)
{ }
- ~LFRingbuffer() noexcept {
+ ~ringbuffer() noexcept {
freeArray(array);
}
- LFRingbuffer(const LFRingbuffer &_source) noexcept
+ ringbuffer(const ringbuffer &_source) noexcept
: capacityPlusOne(_source.capacityPlusOne), array(newArray(capacityPlusOne)),
readPos(0), writePos(0), size(0)
{
@@ -350,7 +348,7 @@ template <typename T, std::nullptr_t nullelem> class LFRingbuffer : public Ringb
cloneFrom(false, _source);
}
- LFRingbuffer& operator=(const LFRingbuffer &_source) noexcept {
+ ringbuffer& operator=(const ringbuffer &_source) noexcept {
std::unique_lock<std::mutex> lockMultiReadS(_source.syncMultiRead, std::defer_lock); // utilize std::lock(r, w), allowing mixed order waiting on read/write ops
std::unique_lock<std::mutex> lockMultiWriteS(_source.syncMultiWrite, std::defer_lock); // otherwise RAII-style relinquish via destructor
std::unique_lock<std::mutex> lockMultiRead(syncMultiRead, std::defer_lock); // same for *this instance!
@@ -369,8 +367,8 @@ template <typename T, std::nullptr_t nullelem> class LFRingbuffer : public Ringb
return *this;
}
- LFRingbuffer(LFRingbuffer &&o) noexcept = default;
- LFRingbuffer& operator=(LFRingbuffer &&o) noexcept = default;
+ ringbuffer(ringbuffer &&o) noexcept = default;
+ ringbuffer& operator=(ringbuffer &&o) noexcept = default;
int capacity() const noexcept override { return capacityPlusOne-1; }
@@ -488,6 +486,6 @@ template <typename T, std::nullptr_t nullelem> class LFRingbuffer : public Ringb
}
};
-} /* namespace direct_bt */
+} /* namespace jau */
-#endif /* LFRINGBUFFER_HPP_ */
+#endif /* JAU_RINGBUFFER_HPP_ */
diff --git a/api/direct_bt/Ringbuffer.hpp b/jaucpp/include/jau/ringbuffer_if.hpp
index 2ea326de..d30990b5 100644
--- a/api/direct_bt/Ringbuffer.hpp
+++ b/jaucpp/include/jau/ringbuffer_if.hpp
@@ -23,18 +23,19 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#ifndef RINGBUFFER_HPP_
-#define RINGBUFFER_HPP_
+#ifndef JAU_RINGBUFFER_IF_HPP_
+#define JAU_RINGBUFFER_IF_HPP_
#include <cstring>
#include <string>
#include <memory>
#include <cstdint>
-#include "BasicTypes.hpp"
+#include <vector>
-namespace direct_bt {
+#include <jau/basic_types.hpp>
+namespace jau {
/**
* Ring buffer interface, a.k.a circular buffer.
@@ -49,9 +50,9 @@ namespace direct_bt {
* Synchronization and hence thread safety details belong to the implementation.
* </p>
*/
-template <class T> class Ringbuffer {
+template <typename T> class ringbuffer_if {
public:
- virtual ~Ringbuffer() noexcept {}
+ virtual ~ringbuffer_if() noexcept {}
/** Returns a short string representation incl. size/capacity and internal r/w index (impl. dependent). */
virtual std::string toString() const noexcept = 0;
@@ -211,6 +212,6 @@ template <class T> class Ringbuffer {
virtual void recapacity(const int newCapacity) = 0;
};
-} /* namespace direct_bt */
+} /* namespace jau */
-#endif /* RINGBUFFER_HPP_ */
+#endif /* JAU_RINGBUFFER_IF_HPP_ */
diff --git a/jaucpp/java/jni/helper_jni.cxx b/jaucpp/java/jni/helper_jni.cxx
new file mode 100644
index 00000000..da7cfe32
--- /dev/null
+++ b/jaucpp/java/jni/helper_jni.cxx
@@ -0,0 +1,354 @@
+/*
+ * Author: Sven Gothel <[email protected]>
+ * Copyright (c) 2020 Gothel Software e.K.
+ * Copyright (c) 2020 ZAFENA AB
+ *
+ * Author: Andrei Vasiliu <[email protected]>
+ * Copyright (c) 2016 Intel Corporation.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <jni.h>
+#include <memory>
+#include <stdexcept>
+#include <vector>
+
+#include <jau/jni/helper_jni.hpp>
+
+using namespace jau;
+
+//
+// C++ <-> java exceptions
+//
+
+bool jau::java_exception_check(JNIEnv *env, const char* file, int line)
+{
+ jthrowable e = env->ExceptionOccurred();
+ if( nullptr != e ) {
+#if 1
+ // ExceptionDescribe prints an exception and a backtrace of the stack to a system error-reporting channel, such as stderr.
+ // The pending exception is cleared as a side-effect of calling this function. This is a convenience routine provided for debugging.
+ env->ExceptionDescribe();
+#endif
+ env->ExceptionClear(); // just be sure, to have same side-effects
+
+ jclass eClazz = search_class(env, e);
+ jmethodID toString = search_method(env, eClazz, "toString", "()Ljava/lang/String;", false);
+ jstring jmsg = (jstring) env->CallObjectMethod(e, toString);
+ std::string msg = from_jstring_to_string(env, jmsg);
+ fprintf(stderr, "Java exception occurred @ %s:%d and forward to Java: %s\n", file, line, msg.c_str()); fflush(stderr);
+
+ env->Throw(e); // re-throw the java exception - java side!
+ return true;
+ }
+ return false;
+}
+
+void jau::java_exception_check_and_throw(JNIEnv *env, const char* file, int line)
+{
+ jthrowable e = env->ExceptionOccurred();
+ if( nullptr != e ) {
+ // ExceptionDescribe prints an exception and a backtrace of the stack to a system error-reporting channel, such as stderr.
+ // The pending exception is cleared as a side-effect of calling this function. This is a convenience routine provided for debugging.
+ env->ExceptionDescribe();
+ env->ExceptionClear(); // just be sure, to have same side-effects
+
+ jclass eClazz = search_class(env, e);
+ jmethodID toString = search_method(env, eClazz, "toString", "()Ljava/lang/String;", false);
+ jstring jmsg = (jstring) env->CallObjectMethod(e, toString);
+ std::string msg = from_jstring_to_string(env, jmsg);
+ fprintf(stderr, "Java exception occurred @ %s:%d and forward to Native: %s\n", file, line, msg.c_str()); fflush(stderr);
+
+ throw jau::RuntimeException("Java exception occurred @ %s : %d: "+msg, file, line);
+ }
+}
+
+void jau::print_native_caught_exception_fwd2java(const std::exception &e, const char* file, int line) {
+ fprintf(stderr, "Native exception caught @ %s:%d and forward to Java: %s\n", file, line, e.what()); fflush(stderr);
+}
+void jau::print_native_caught_exception_fwd2java(const std::string &msg, const char* file, int line) {
+ fprintf(stderr, "Native exception caught @ %s:%d and forward to Java: %s\n", file, line, msg.c_str()); fflush(stderr);
+}
+void jau::print_native_caught_exception_fwd2java(const char * cmsg, const char* file, int line) {
+ fprintf(stderr, "Native exception caught @ %s:%d and forward to Java: %s\n", file, line, cmsg); fflush(stderr);
+}
+
+void jau::raise_java_exception(JNIEnv *env, const std::exception &e, const char* file, int line) {
+ print_native_caught_exception_fwd2java(e, file, line);
+ env->ThrowNew(env->FindClass("java/lang/Error"), e.what());
+}
+void jau::raise_java_exception(JNIEnv *env, const std::runtime_error &e, const char* file, int line) {
+ print_native_caught_exception_fwd2java(e, file, line);
+ env->ThrowNew(env->FindClass("java/lang/RuntimeException"), e.what());
+}
+void jau::raise_java_exception(JNIEnv *env, const jau::RuntimeException &e, const char* file, int line) {
+ print_native_caught_exception_fwd2java(e, file, line);
+ env->ThrowNew(env->FindClass("java/lang/RuntimeException"), e.what());
+}
+void jau::raise_java_exception(JNIEnv *env, const jau::InternalError &e, const char* file, int line) {
+ print_native_caught_exception_fwd2java(e, file, line);
+ env->ThrowNew(env->FindClass("java/lang/InternalError"), e.what());
+}
+void jau::raise_java_exception(JNIEnv *env, const jau::NullPointerException &e, const char* file, int line) {
+ print_native_caught_exception_fwd2java(e, file, line);
+ env->ThrowNew(env->FindClass("java/lang/NullPointerException"), e.what());
+}
+void jau::raise_java_exception(JNIEnv *env, const jau::IllegalArgumentException &e, const char* file, int line) {
+ print_native_caught_exception_fwd2java(e, file, line);
+ env->ThrowNew(env->FindClass("java/lang/IllegalArgumentException"), e.what());
+}
+void jau::raise_java_exception(JNIEnv *env, const std::invalid_argument &e, const char* file, int line) {
+ print_native_caught_exception_fwd2java(e, file, line);
+ env->ThrowNew(env->FindClass("java/lang/IllegalArgumentException"), e.what());
+}
+void jau::raise_java_exception(JNIEnv *env, const jau::IllegalStateException &e, const char* file, int line) {
+ print_native_caught_exception_fwd2java(e, file, line);
+ env->ThrowNew(env->FindClass("java/lang/IllegalStateException"), e.what());
+}
+void jau::raise_java_exception(JNIEnv *env, const jau::UnsupportedOperationException &e, const char* file, int line) {
+ print_native_caught_exception_fwd2java(e, file, line);
+ env->ThrowNew(env->FindClass("java/lang/UnsupportedOperationException"), e.what());
+}
+void jau::raise_java_exception(JNIEnv *env, const jau::IndexOutOfBoundsException &e, const char* file, int line) {
+ print_native_caught_exception_fwd2java(e, file, line);
+ env->ThrowNew(env->FindClass("java/lang/IndexOutOfBoundsException"), e.what());
+}
+void jau::raise_java_exception(JNIEnv *env, const std::bad_alloc &e, const char* file, int line) {
+ print_native_caught_exception_fwd2java(e, file, line);
+ env->ThrowNew(env->FindClass("java/lang/OutOfMemoryError"), e.what());
+}
+void jau::raise_java_exception(JNIEnv *env, const jau::OutOfMemoryError &e, const char* file, int line) {
+ print_native_caught_exception_fwd2java(e, file, line);
+ env->ThrowNew(env->FindClass("java/lang/OutOfMemoryError"), e.what());
+}
+
+static std::string _unknown_exception_type_msg("Unknown exception type");
+
+void jau::rethrow_and_raise_java_exception_jauimpl(JNIEnv *env, const char* file, int line) {
+ // std::exception_ptr e = std::current_exception();
+ try {
+ // std::rethrow_exception(e);
+ throw; // re-throw current exception
+ } catch (const std::bad_alloc &e) {
+ jau::raise_java_exception(env, e, file, line);
+ } catch (const jau::OutOfMemoryError &e) {
+ jau::raise_java_exception(env, e, file, line);
+ } catch (const jau::InternalError &e) {
+ jau::raise_java_exception(env, e, file, line);
+ } catch (const jau::NullPointerException &e) {
+ jau::raise_java_exception(env, e, file, line);
+ } catch (const jau::IllegalArgumentException &e) {
+ jau::raise_java_exception(env, e, file, line);
+ } catch (const jau::IllegalStateException &e) {
+ jau::raise_java_exception(env, e, file, line);
+ } catch (const jau::UnsupportedOperationException &e) {
+ jau::raise_java_exception(env, e, file, line);
+ } catch (const jau::IndexOutOfBoundsException &e) {
+ jau::raise_java_exception(env, e, file, line);
+ } catch (const jau::RuntimeException &e) {
+ jau::raise_java_exception(env, e, file, line);
+ } catch (const std::runtime_error &e) {
+ jau::raise_java_exception(env, e, file, line);
+ } catch (const std::invalid_argument &e) {
+ jau::raise_java_exception(env, e, file, line);
+ } catch (const std::exception &e) {
+ jau::raise_java_exception(env, e, file, line);
+ } catch (const std::string &msg) {
+ jau::print_native_caught_exception_fwd2java(msg, file, line);
+ env->ThrowNew(env->FindClass("java/lang/Error"), msg.c_str());
+ } catch (const char *msg) {
+ jau::print_native_caught_exception_fwd2java(msg, file, line);
+ env->ThrowNew(env->FindClass("java/lang/Error"), msg);
+ } catch (...) {
+ jau::print_native_caught_exception_fwd2java(_unknown_exception_type_msg, file, line);
+ env->ThrowNew(env->FindClass("java/lang/Error"), _unknown_exception_type_msg.c_str());
+ }
+}
+
+//
+// Basic
+//
+
+jfieldID jau::getField(JNIEnv *env, jobject obj, const char* field_name, const char* field_signature) {
+ jclass clazz = env->GetObjectClass(obj);
+ java_exception_check_and_throw(env, E_FILE_LINE);
+ // J == long
+ jfieldID res = env->GetFieldID(clazz, field_name, field_signature);
+ java_exception_check_and_throw(env, E_FILE_LINE);
+ return res;
+}
+
+jclass jau::search_class(JNIEnv *env, const char *clazz_name)
+{
+ jclass clazz = env->FindClass(clazz_name);
+ java_exception_check_and_throw(env, E_FILE_LINE);
+ if (!clazz)
+ {
+ throw jau::InternalError(std::string("no class found: ")+clazz_name, E_FILE_LINE);
+ }
+ return clazz;
+}
+
+jclass jau::search_class(JNIEnv *env, jobject obj)
+{
+ jclass clazz = env->GetObjectClass(obj);
+ java_exception_check_and_throw(env, E_FILE_LINE);
+ if (!clazz)
+ {
+ throw jau::InternalError("no class found", E_FILE_LINE);
+ }
+ return clazz;
+}
+
+jclass jau::search_class(JNIEnv *env, JavaUplink &object)
+{
+ return search_class(env, object.get_java_class().c_str());
+}
+
+jmethodID jau::search_method(JNIEnv *env, jclass clazz, const char *method_name,
+ const char *prototype, bool is_static)
+{
+ jmethodID method;
+ if (is_static)
+ {
+ method = env->GetStaticMethodID(clazz, method_name, prototype);
+ }
+ else
+ {
+ method = env->GetMethodID(clazz, method_name, prototype);
+ }
+ java_exception_check_and_throw(env, E_FILE_LINE);
+
+ if (!method)
+ {
+ throw jau::InternalError(std::string("no method found: ")+method_name, E_FILE_LINE);
+ }
+
+ return method;
+}
+
+jfieldID jau::search_field(JNIEnv *env, jclass clazz, const char *field_name,
+ const char *type, bool is_static)
+{
+ jfieldID field;
+ if (is_static)
+ {
+ field = env->GetStaticFieldID(clazz, field_name, type);
+ }
+ else
+ {
+ field = env->GetFieldID(clazz, field_name, type);
+ }
+ java_exception_check_and_throw(env, E_FILE_LINE);
+
+ if (!field)
+ {
+ jau::InternalError(std::string("no field found: ")+field_name, E_FILE_LINE);
+ }
+
+ return field;
+}
+
+bool jau::from_jboolean_to_bool(jboolean val)
+{
+ bool result;
+
+ if (val == JNI_TRUE)
+ {
+ result = true;
+ }
+ else
+ {
+ if (val == JNI_FALSE)
+ {
+ result = false;
+ }
+ else
+ {
+ throw jau::InternalError("the jboolean value is not true/false", E_FILE_LINE);
+ }
+ }
+
+ return result;
+}
+
+std::string jau::from_jstring_to_string(JNIEnv *env, jstring str)
+{
+ jboolean is_copy = JNI_TRUE;
+ if (!str) {
+ throw std::invalid_argument("String should not be null");
+ }
+ const char *str_chars = (char *)env->GetStringUTFChars(str, &is_copy);
+ if (!str_chars) {
+ throw std::bad_alloc();
+ }
+ const std::string string_to_write = std::string(str_chars);
+
+ env->ReleaseStringUTFChars(str, str_chars);
+
+ return string_to_write;
+}
+
+jstring jau::from_string_to_jstring(JNIEnv *env, const std::string & str)
+{
+ return env->NewStringUTF(str.c_str());
+}
+
+jobject jau::get_new_arraylist(JNIEnv *env, unsigned int size, jmethodID *add)
+{
+ jclass arraylist_class = search_class(env, "java/util/ArrayList");
+ jmethodID arraylist_ctor = search_method(env, arraylist_class, "<init>", "(I)V", false);
+
+ jobject result = env->NewObject(arraylist_class, arraylist_ctor, size);
+ if (!result)
+ {
+ throw jau::InternalError("Cannot create instance of class ArrayList", E_FILE_LINE);
+ }
+
+ *add = search_method(env, arraylist_class, "add", "(Ljava/lang/Object;)Z", false);
+
+ env->DeleteLocalRef(arraylist_class);
+ return result;
+}
+
+
+//
+// C++ java_anon implementation
+//
+
+JavaGlobalObj::~JavaGlobalObj() noexcept {
+ jobject obj = javaObjectRef.getObject();
+ if( nullptr == obj || nullptr == mNotifyDeleted ) {
+ return;
+ }
+ JNIEnv *env = *jni_env;
+ env->CallVoidMethod(obj, mNotifyDeleted);
+ java_exception_check_and_throw(env, E_FILE_LINE); // would abort() if thrown
+}
+
+//
+// C++ java_anon <-> java access, assuming field "long nativeInstance" and native method 'void checkValid()'
+//
+
+//
+// C++ java_anon <-> java access, all generic
+//
+
diff --git a/java/jni/JNIMem.cxx b/jaucpp/java/jni/jni_mem.cxx
index e5b3aaf5..49516a43 100644
--- a/java/jni/JNIMem.cxx
+++ b/jaucpp/java/jni/jni_mem.cxx
@@ -1,11 +1,11 @@
/*
- * Author: Petre Eftime <[email protected]>
- * Copyright (c) 2016 Intel Corporation.
- *
* Author: Sven Gothel <[email protected]>
* Copyright (c) 2020 Gothel Software e.K.
* Copyright (c) 2020 ZAFENA AB
*
+ * Author: Petre Eftime <[email protected]>
+ * Copyright (c) 2016 Intel Corporation.
+ *
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
@@ -28,10 +28,8 @@
#include <cstdio>
-#include "JNIMem.hpp"
-
-#include "dbt_debug.hpp"
-
+#include <jau/debug.hpp>
+#include <jau/jni/jni_mem.hpp>
JavaVM* vm;
thread_local JNIEnvContainer jni_env;
@@ -69,14 +67,14 @@ void JNIEnvContainer::attach() {
if( JNI_EDETACHED == envRes ) {
envRes = vm->AttachCurrentThreadAsDaemon((void**) &newEnv, NULL);
if( JNI_OK != envRes ) {
- throw direct_bt::RuntimeException("Attach to VM failed", E_FILE_LINE);
+ throw jau::RuntimeException("Attach to VM failed", E_FILE_LINE);
}
env = newEnv;
} else if( JNI_OK != envRes ) {
- throw direct_bt::RuntimeException("GetEnv of VM failed", E_FILE_LINE);
+ throw jau::RuntimeException("GetEnv of VM failed", E_FILE_LINE);
}
if (env==NULL) {
- throw direct_bt::RuntimeException("GetEnv of VM is NULL", E_FILE_LINE);
+ throw jau::RuntimeException("GetEnv of VM is NULL", E_FILE_LINE);
}
needsDetach = NULL != newEnv;
}
@@ -99,7 +97,7 @@ JNIGlobalRef::JNIGlobalRef() noexcept {
JNIGlobalRef::JNIGlobalRef(jobject object) {
if( nullptr == object ) {
- throw direct_bt::RuntimeException("JNIGlobalRef ctor null jobject", E_FILE_LINE);
+ throw jau::RuntimeException("JNIGlobalRef ctor null jobject", E_FILE_LINE);
}
this->object = jni_env->NewGlobalRef(object);
DBG_JNI_PRINT("JNIGlobalRef::def_ctor %p -> %p", object, this->object);
@@ -107,7 +105,7 @@ JNIGlobalRef::JNIGlobalRef(jobject object) {
JNIGlobalRef::JNIGlobalRef(const JNIGlobalRef &o) {
if( nullptr == o.object ) {
- throw direct_bt::RuntimeException("Other JNIGlobalRef jobject is null", E_FILE_LINE);
+ throw jau::RuntimeException("Other JNIGlobalRef jobject is null", E_FILE_LINE);
}
object = jni_env->NewGlobalRef(o.object);
DBG_JNI_PRINT("JNIGlobalRef::copy_ctor %p -> %p", o.object, object);
@@ -126,7 +124,7 @@ JNIGlobalRef& JNIGlobalRef::operator=(const JNIGlobalRef &o) {
env->DeleteGlobalRef(object);
}
if( nullptr == o.object ) {
- throw direct_bt::RuntimeException("Other JNIGlobalRef jobject is null", E_FILE_LINE);
+ throw jau::RuntimeException("Other JNIGlobalRef jobject is null", E_FILE_LINE);
}
object = jni_env->NewGlobalRef(o.object);
DBG_JNI_PRINT("JNIGlobalRef::copy_assign %p -> %p", o.object, object);
diff --git a/src/direct_bt/BasicTypes.cpp b/jaucpp/src/basic_types.cpp
index ce3519e5..f9a9cc31 100644
--- a/src/direct_bt/BasicTypes.cpp
+++ b/jaucpp/src/basic_types.cpp
@@ -28,10 +28,10 @@
#include <algorithm>
-#include "direct_bt/dbt_debug.hpp"
-#include "direct_bt/BasicTypes.hpp"
+#include <jau/debug.hpp>
+#include <jau/basic_types.hpp>
-using namespace direct_bt;
+using namespace jau;
static const int64_t NanoPerMilli = 1000000L;
static const int64_t MilliPerOne = 1000L;
@@ -44,19 +44,19 @@ static const int64_t MilliPerOne = 1000L;
* clock_gettime seems to be well supported at least on kernel >= 4.4.
* Only bfin and sh are missing, while ia64 seems to be complicated.
*/
-int64_t direct_bt::getCurrentMilliseconds() noexcept {
+int64_t jau::getCurrentMilliseconds() noexcept {
struct timespec t;
clock_gettime(CLOCK_MONOTONIC, &t);
return t.tv_sec * MilliPerOne + t.tv_nsec / NanoPerMilli;
}
-direct_bt::RuntimeException::RuntimeException(std::string const type, std::string const m, const char* file, int line) noexcept
+jau::RuntimeException::RuntimeException(std::string const type, std::string const m, const char* file, int line) noexcept
: msg(std::string(type).append(" @ ").append(file).append(":").append(std::to_string(line)).append(": ").append(m)),
- backtrace(direct_bt::get_backtrace(1))
+ backtrace(jau::get_backtrace(1))
{
}
-const char* direct_bt::RuntimeException::what() const noexcept {
+const char* jau::RuntimeException::what() const noexcept {
// return std::runtime_error::what();
std::string out(msg);
out.append("\nNative backtrace:\n");
@@ -64,7 +64,7 @@ const char* direct_bt::RuntimeException::what() const noexcept {
return out.c_str();
}
-std::string direct_bt::get_string(const uint8_t *buffer, int const buffer_len, int const max_len) noexcept {
+std::string jau::get_string(const uint8_t *buffer, int const buffer_len, int const max_len) noexcept {
const int cstr_len = std::min(buffer_len, max_len);
char cstr[max_len+1]; // EOS
memcpy(cstr, buffer, cstr_len);
@@ -72,7 +72,7 @@ std::string direct_bt::get_string(const uint8_t *buffer, int const buffer_len, i
return std::string(cstr);
}
-uint128_t direct_bt::merge_uint128(uint16_t const uuid16, uint128_t const & base_uuid, int const uuid16_le_octet_index)
+uint128_t jau::merge_uint128(uint16_t const uuid16, uint128_t const & base_uuid, int const uuid16_le_octet_index)
{
if( 0 > uuid16_le_octet_index || uuid16_le_octet_index > 14 ) {
std::string msg("uuid16_le_octet_index ");
@@ -107,7 +107,7 @@ uint128_t direct_bt::merge_uint128(uint16_t const uuid16, uint128_t const & base
return dest;
}
-uint128_t direct_bt::merge_uint128(uint32_t const uuid32, uint128_t const & base_uuid, int const uuid32_le_octet_index)
+uint128_t jau::merge_uint128(uint32_t const uuid32, uint128_t const & base_uuid, int const uuid32_le_octet_index)
{
if( 0 > uuid32_le_octet_index || uuid32_le_octet_index > 12 ) {
std::string msg("uuid32_le_octet_index ");
@@ -142,7 +142,7 @@ uint128_t direct_bt::merge_uint128(uint32_t const uuid32, uint128_t const & base
return dest;
}
-std::string direct_bt::uint8HexString(const uint8_t v, const bool leading0X) noexcept {
+std::string jau::uint8HexString(const uint8_t v, const bool leading0X) noexcept {
const int length = leading0X ? 4 : 2; // ( '0x00' | '00' )
std::string str;
str.reserve(length+1); // including EOS for snprintf
@@ -155,7 +155,7 @@ std::string direct_bt::uint8HexString(const uint8_t v, const bool leading0X) noe
return str;
}
-std::string direct_bt::uint16HexString(const uint16_t v, const bool leading0X) noexcept {
+std::string jau::uint16HexString(const uint16_t v, const bool leading0X) noexcept {
const int length = leading0X ? 6 : 4; // ( '0x0000' | '0000' )
std::string str;
str.reserve(length+1); // including EOS for snprintf
@@ -168,7 +168,7 @@ std::string direct_bt::uint16HexString(const uint16_t v, const bool leading0X) n
return str;
}
-std::string direct_bt::uint32HexString(const uint32_t v, const bool leading0X) noexcept {
+std::string jau::uint32HexString(const uint32_t v, const bool leading0X) noexcept {
const int length = leading0X ? 10 : 8; // ( '0x00000000' | '00000000' )
std::string str;
str.reserve(length+1); // including EOS for snprintf
@@ -181,7 +181,7 @@ std::string direct_bt::uint32HexString(const uint32_t v, const bool leading0X) n
return str;
}
-std::string direct_bt::uint64HexString(const uint64_t v, const bool leading0X) noexcept {
+std::string jau::uint64HexString(const uint64_t v, const bool leading0X) noexcept {
const int length = leading0X ? 18 : 16; // ( '0x0000000000000000' | '0000000000000000' )
std::string str;
str.reserve(length+1); // including EOS for snprintf
@@ -194,13 +194,13 @@ std::string direct_bt::uint64HexString(const uint64_t v, const bool leading0X) n
return str;
}
-std::string direct_bt::aptrHexString(const void * v, const bool leading0X) noexcept {
+std::string jau::aptrHexString(const void * v, const bool leading0X) noexcept {
return uint64HexString((uint64_t)v, leading0X);
}
static const char* HEX_ARRAY = "0123456789ABCDEF";
-std::string direct_bt::bytesHexString(const uint8_t * bytes, const int offset, const int length, const bool lsbFirst, const bool leading0X) noexcept {
+std::string jau::bytesHexString(const uint8_t * bytes, const int offset, const int length, const bool lsbFirst, const bool leading0X) noexcept {
std::string str;
if( nullptr == bytes ) {
@@ -234,7 +234,7 @@ std::string direct_bt::bytesHexString(const uint8_t * bytes, const int offset, c
return str;
}
-std::string direct_bt::int32SeparatedString(const int32_t v, const char separator) noexcept {
+std::string jau::int32SeparatedString(const int32_t v, const char separator) noexcept {
// INT32_MIN: -2147483648 int32_t 11 chars
// INT32_MIN: -2,147,483,648 int32_t 14 chars
// INT32_MAX: 2147483647 int32_t 10 chars
@@ -263,7 +263,7 @@ std::string direct_bt::int32SeparatedString(const int32_t v, const char separato
return std::string(dst, p_dst - dst);
}
-std::string direct_bt::uint32SeparatedString(const uint32_t v, const char separator) noexcept {
+std::string jau::uint32SeparatedString(const uint32_t v, const char separator) noexcept {
// UINT32_MAX: 4294967295 uint32_t 10 chars
// UINT32_MAX: 4,294,967,295 uint32_t 13 chars
char src[16]; // aligned 4 byte
@@ -285,7 +285,7 @@ std::string direct_bt::uint32SeparatedString(const uint32_t v, const char separa
return std::string(dst, p_dst - dst);
}
-std::string direct_bt::uint64SeparatedString(const uint64_t v, const char separator) noexcept {
+std::string jau::uint64SeparatedString(const uint64_t v, const char separator) noexcept {
// UINT64_MAX: 18446744073709551615 uint64_t 20 chars
// UINT64_MAX: 18,446,744,073,709,551,615 uint64_t 26 chars
char src[28]; // aligned 4 byte
@@ -307,7 +307,7 @@ std::string direct_bt::uint64SeparatedString(const uint64_t v, const char separa
return std::string(dst, p_dst - dst);
}
-void direct_bt::trimInPlace(std::string &s) noexcept {
+void jau::trimInPlace(std::string &s) noexcept {
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](int ch) {
return !std::isspace(ch);
}));
@@ -316,7 +316,7 @@ void direct_bt::trimInPlace(std::string &s) noexcept {
}).base(), s.end());
}
-std::string direct_bt::trimCopy(const std::string &_s) noexcept {
+std::string jau::trimCopy(const std::string &_s) noexcept {
std::string s(_s);
trimInPlace(s);
return s;
diff --git a/src/direct_bt/dbt_debug.cpp b/jaucpp/src/debug.cpp
index 7ba778e3..f0cb8edd 100644
--- a/src/direct_bt/dbt_debug.cpp
+++ b/jaucpp/src/debug.cpp
@@ -23,7 +23,7 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#include "direct_bt/dbt_debug.hpp"
+#include <jau/debug.hpp>
#include <cstdarg>
@@ -31,9 +31,9 @@
#include <libunwind.h>
#include <cxxabi.h>
-using namespace direct_bt;
+using namespace jau;
-std::string direct_bt::get_backtrace(int skip_frames) noexcept {
+std::string jau::get_backtrace(int skip_frames) noexcept {
// symbol:
// 1: _ZN9direct_bt10DBTAdapter14startDiscoveryEbNS_19HCILEOwnAddressTypeEtt + 0x58d @ ip 0x7faa959d6daf, sp 0x7ffe38f301e0
// de-mangled:
@@ -77,13 +77,13 @@ std::string direct_bt::get_backtrace(int skip_frames) noexcept {
return out;
}
-void direct_bt::print_backtrace(int skip_frames) noexcept {
+void jau::print_backtrace(int skip_frames) noexcept {
fprintf(stderr, get_backtrace(skip_frames).c_str());
fflush(stderr);
}
-void direct_bt::DBG_PRINT_impl(const char * format, ...) noexcept {
- fprintf(stderr, "[%'9" PRIu64 "] Debug: ", DBTEnv::getElapsedMillisecond());
+void jau::DBG_PRINT_impl(const char * format, ...) noexcept {
+ fprintf(stderr, "[%'9" PRIu64 "] Debug: ", environment::getElapsedMillisecond());
va_list args;
va_start (args, format);
vfprintf(stderr, format, args);
@@ -92,8 +92,8 @@ void direct_bt::DBG_PRINT_impl(const char * format, ...) noexcept {
fflush(stderr);
}
-void direct_bt::WORDY_PRINT_impl(const char * format, ...) noexcept {
- fprintf(stderr, "[%'9" PRIu64 "] Wordy: ", DBTEnv::getElapsedMillisecond());
+void jau::WORDY_PRINT_impl(const char * format, ...) noexcept {
+ fprintf(stderr, "[%'9" PRIu64 "] Wordy: ", environment::getElapsedMillisecond());
va_list args;
va_start (args, format);
vfprintf(stderr, format, args);
@@ -102,28 +102,28 @@ void direct_bt::WORDY_PRINT_impl(const char * format, ...) noexcept {
fflush(stderr);
}
-void direct_bt::ABORT_impl(const char *func, const char *file, const int line, const char * format, ...) noexcept {
- fprintf(stderr, "[%'9" PRIu64 "] ABORT @ %s:%d %s: ", DBTEnv::getElapsedMillisecond(), file, line, func);
+void jau::ABORT_impl(const char *func, const char *file, const int line, const char * format, ...) noexcept {
+ fprintf(stderr, "[%'9" PRIu64 "] ABORT @ %s:%d %s: ", environment::getElapsedMillisecond(), file, line, func);
va_list args;
va_start (args, format);
vfprintf(stderr, format, args);
va_end (args);
fprintf(stderr, "; last errno %d %s\n", errno, strerror(errno));
fflush(stderr);
- direct_bt::print_backtrace(2);
+ jau::print_backtrace(2);
abort();
}
-void direct_bt::ERR_PRINTv(const char *func, const char *file, const int line, const char * format, va_list args) noexcept {
- fprintf(stderr, "[%'9" PRIu64 "] Error @ %s:%d %s: ", DBTEnv::getElapsedMillisecond(), file, line, func);
+void jau::ERR_PRINTv(const char *func, const char *file, const int line, const char * format, va_list args) noexcept {
+ fprintf(stderr, "[%'9" PRIu64 "] Error @ %s:%d %s: ", environment::getElapsedMillisecond(), file, line, func);
vfprintf(stderr, format, args);
fprintf(stderr, "; last errno %d %s\n", errno, strerror(errno));
fflush(stderr);
- direct_bt::print_backtrace(2);
+ jau::print_backtrace(2);
}
-void direct_bt::ERR_PRINT_impl(const char *prefix, const bool backtrace, const char *func, const char *file, const int line, const char * format, ...) noexcept {
- fprintf(stderr, "[%'9" PRIu64 "] %s @ %s:%d %s: ", DBTEnv::getElapsedMillisecond(), prefix, file, line, func);
+void jau::ERR_PRINT_impl(const char *prefix, const bool backtrace, const char *func, const char *file, const int line, const char * format, ...) noexcept {
+ fprintf(stderr, "[%'9" PRIu64 "] %s @ %s:%d %s: ", environment::getElapsedMillisecond(), prefix, file, line, func);
va_list args;
va_start (args, format);
vfprintf(stderr, format, args);
@@ -131,19 +131,19 @@ void direct_bt::ERR_PRINT_impl(const char *prefix, const bool backtrace, const c
fprintf(stderr, "; last errno %d %s\n", errno, strerror(errno));
fflush(stderr);
if( backtrace ) {
- direct_bt::print_backtrace(2);
+ jau::print_backtrace(2);
}
}
-void direct_bt::WARN_PRINTv(const char *func, const char *file, const int line, const char * format, va_list args) noexcept {
- fprintf(stderr, "[%'9" PRIu64 "] Warning @ %s:%d %s: ", DBTEnv::getElapsedMillisecond(), file, line, func);
+void jau::WARN_PRINTv(const char *func, const char *file, const int line, const char * format, va_list args) noexcept {
+ fprintf(stderr, "[%'9" PRIu64 "] Warning @ %s:%d %s: ", environment::getElapsedMillisecond(), file, line, func);
vfprintf(stderr, format, args);
fprintf(stderr, "\n");
fflush(stderr);
}
-void direct_bt::WARN_PRINT_impl(const char *func, const char *file, const int line, const char * format, ...) noexcept {
- fprintf(stderr, "[%'9" PRIu64 "] Warning @ %s:%d %s: ", DBTEnv::getElapsedMillisecond(), file, line, func);
+void jau::WARN_PRINT_impl(const char *func, const char *file, const int line, const char * format, ...) noexcept {
+ fprintf(stderr, "[%'9" PRIu64 "] Warning @ %s:%d %s: ", environment::getElapsedMillisecond(), file, line, func);
va_list args;
va_start (args, format);
vfprintf(stderr, format, args);
@@ -152,8 +152,8 @@ void direct_bt::WARN_PRINT_impl(const char *func, const char *file, const int li
fflush(stderr);
}
-void direct_bt::INFO_PRINT(const char * format, ...) noexcept {
- fprintf(stderr, "[%'9" PRIu64 "] Info: ", DBTEnv::getElapsedMillisecond());
+void jau::INFO_PRINT(const char * format, ...) noexcept {
+ fprintf(stderr, "[%'9" PRIu64 "] Info: ", environment::getElapsedMillisecond());
va_list args;
va_start (args, format);
vfprintf(stderr, format, args);
@@ -162,8 +162,8 @@ void direct_bt::INFO_PRINT(const char * format, ...) noexcept {
fflush(stderr);
}
-void direct_bt::PLAIN_PRINT(const char * format, ...) noexcept {
- fprintf(stderr, "[%'9" PRIu64 "] ", DBTEnv::getElapsedMillisecond());
+void jau::PLAIN_PRINT(const char * format, ...) noexcept {
+ fprintf(stderr, "[%'9" PRIu64 "] ", environment::getElapsedMillisecond());
va_list args;
va_start (args, format);
vfprintf(stderr, format, args);
@@ -172,8 +172,8 @@ void direct_bt::PLAIN_PRINT(const char * format, ...) noexcept {
fflush(stderr);
}
-void direct_bt::COND_PRINT_impl(const char * format, ...) noexcept {
- fprintf(stderr, "[%'9" PRIu64 "] ", DBTEnv::getElapsedMillisecond());
+void jau::COND_PRINT_impl(const char * format, ...) noexcept {
+ fprintf(stderr, "[%'9" PRIu64 "] ", environment::getElapsedMillisecond());
va_list args;
va_start (args, format);
vfprintf(stderr, format, args);
diff --git a/src/direct_bt/dfa_utf8_decode.cpp b/jaucpp/src/dfa_utf8_decode.cpp
index 19dc70a2..01252a64 100644
--- a/src/direct_bt/dfa_utf8_decode.cpp
+++ b/jaucpp/src/dfa_utf8_decode.cpp
@@ -24,9 +24,11 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#include "direct_bt/dfa_utf8_decode.hpp"
+#include <jau/dfa_utf8_decode.hpp>
-std::string dfa_utf8_decode(const uint8_t *buffer, const size_t buffer_size) {
+using namespace jau;
+
+std::string jau::dfa_utf8_decode(const uint8_t *buffer, const size_t buffer_size) {
uint32_t codepoint;
uint32_t state = DFA_UTF8_ACCEPT;
size_t byte_count;
@@ -85,7 +87,7 @@ static const uint8_t dfa_utf8d[] = {
12,36,12,12,12,12,12,12,12,12,12,12,
};
-uint32_t dfa_utf8_decode(uint32_t & state, uint32_t & codep, const uint32_t byte_value) {
+uint32_t jau::dfa_utf8_decode(uint32_t & state, uint32_t & codep, const uint32_t byte_value) {
const uint32_t type = dfa_utf8d[byte_value];
codep = (state != DFA_UTF8_ACCEPT) ?
diff --git a/src/direct_bt/DBTEnv.cpp b/jaucpp/src/environment.cpp
index ed05837a..87fdea1b 100644
--- a/src/direct_bt/DBTEnv.cpp
+++ b/jaucpp/src/environment.cpp
@@ -31,22 +31,22 @@
#include <vector>
#include <cstdio>
-#include "direct_bt/DBTEnv.hpp"
-#include "direct_bt/dbt_debug.hpp"
+#include <jau/environment.hpp>
+#include <jau/debug.hpp>
-using namespace direct_bt;
+using namespace jau;
-const uint64_t DBTEnv::startupTimeMilliseconds = direct_bt::getCurrentMilliseconds();
+const uint64_t environment::startupTimeMilliseconds = jau::getCurrentMilliseconds();
-bool DBTEnv::debug = false;
+bool environment::debug = false;
static const std::string s_true("true");
static const std::string s_false("false");
-std::string DBTEnv::getProperty(const std::string & name) noexcept {
+std::string environment::getProperty(const std::string & name) noexcept {
const char * value = getenv(name.c_str());
if( nullptr != value ) {
- COND_PRINT(debug, "DBTEnv::getProperty0 '%s': '%s'", name.c_str(), value);
+ COND_PRINT(debug, "env::getProperty0 '%s': '%s'", name.c_str(), value);
return std::string( value );
}
if( std::string::npos != name.find('.', 0) ) {
@@ -55,48 +55,48 @@ std::string DBTEnv::getProperty(const std::string & name) noexcept {
std::replace( alt_name.begin(), alt_name.end(), '.', '_');
value = getenv(alt_name.c_str());
if( nullptr != value ) {
- COND_PRINT(debug, "DBTEnv::getProperty0 '%s' -> '%s': '%s'", name.c_str(), alt_name.c_str(), value);
+ COND_PRINT(debug, "env::getProperty0 '%s' -> '%s': '%s'", name.c_str(), alt_name.c_str(), value);
return std::string( value );
}
- COND_PRINT(debug, "DBTEnv::getProperty0 '%s' -> '%s': NOT FOUND", name.c_str(), alt_name.c_str());
+ COND_PRINT(debug, "env::getProperty0 '%s' -> '%s': NOT FOUND", name.c_str(), alt_name.c_str());
} else {
- COND_PRINT(debug, "DBTEnv::getProperty0 '%s': NOT FOUND", name.c_str());
+ COND_PRINT(debug, "env::getProperty0 '%s': NOT FOUND", name.c_str());
}
// not found: empty string
return std::string();
}
-std::string DBTEnv::getProperty(const std::string & name, const std::string & default_value) noexcept {
+std::string environment::getProperty(const std::string & name, const std::string & default_value) noexcept {
const std::string value = getProperty(name);
if( 0 == value.length() ) {
- COND_PRINT(debug, "DBTEnv::getProperty1 %s: null -> %s (default)", name.c_str(), default_value.c_str());
+ COND_PRINT(debug, "env::getProperty1 %s: null -> %s (default)", name.c_str(), default_value.c_str());
return default_value;
} else {
- COND_PRINT(debug, "DBTEnv::getProperty1 %s (default %s): %s", name.c_str(), default_value.c_str(), value.c_str());
+ COND_PRINT(debug, "env::getProperty1 %s (default %s): %s", name.c_str(), default_value.c_str(), value.c_str());
return value;
}
}
-bool DBTEnv::getBooleanProperty(const std::string & name, const bool default_value) noexcept {
+bool environment::getBooleanProperty(const std::string & name, const bool default_value) noexcept {
const std::string value = getProperty(name);
if( 0 == value.length() ) {
- COND_PRINT(debug, "DBTEnv::getBooleanProperty %s: null -> %d (default)", name.c_str(), default_value);
+ COND_PRINT(debug, "env::getBooleanProperty %s: null -> %d (default)", name.c_str(), default_value);
return default_value;
} else {
const bool res = "true" == value;
- COND_PRINT(debug, "DBTEnv::getBooleanProperty %s (default %d): %d/%s", name.c_str(), default_value, res, value.c_str());
+ COND_PRINT(debug, "env::getBooleanProperty %s (default %d): %d/%s", name.c_str(), default_value, res, value.c_str());
return res;
}
}
#include <limits.h>
-int32_t DBTEnv::getInt32Property(const std::string & name, const int32_t default_value,
+int32_t environment::getInt32Property(const std::string & name, const int32_t default_value,
const int32_t min_allowed, const int32_t max_allowed) noexcept
{
const std::string value = getProperty(name);
if( 0 == value.length() ) {
- COND_PRINT(debug, "DBTEnv::getInt32Property %s: null -> %" PRId32 " (default)", name.c_str(), default_value);
+ COND_PRINT(debug, "env::getInt32Property %s: null -> %" PRId32 " (default)", name.c_str(), default_value);
return default_value;
} else {
int32_t res = default_value;
@@ -110,33 +110,33 @@ int32_t DBTEnv::getInt32Property(const std::string & name, const int32_t default
if( min_allowed <= res1 && res1 <= max_allowed ) {
// matching user value range
res = res1;
- COND_PRINT(debug, "DBTEnv::getInt32Property %s (default %" PRId32 "): %" PRId32 "/%s",
+ COND_PRINT(debug, "env::getInt32Property %s (default %" PRId32 "): %" PRId32 "/%s",
name.c_str(), default_value, res, value.c_str());
} else {
// invalid user value range
- ERR_PRINT("DBTEnv::getInt32Property %s: %" PRId32 "/%s (invalid user range [% " PRId32 "..%" PRId32 "]) -> %" PRId32 " (default)",
+ ERR_PRINT("env::getInt32Property %s: %" PRId32 "/%s (invalid user range [% " PRId32 "..%" PRId32 "]) -> %" PRId32 " (default)",
name.c_str(), res1, value.c_str(), min_allowed, max_allowed, res);
}
} else {
// invalid int32_t range
- ERR_PRINT("DBTEnv::getInt32Property %s: %" PRIu64 "/%s (invalid int32_t range) -> %" PRId32 " (default)",
+ ERR_PRINT("env::getInt32Property %s: %" PRIu64 "/%s (invalid int32_t range) -> %" PRId32 " (default)",
name.c_str(), (uint64_t)res0, value.c_str(), res);
}
} else {
// string value not fully valid
- ERR_PRINT("DBTEnv::getInt32Property %s: %s (invalid string) -> %" PRId32 " (default)",
+ ERR_PRINT("env::getInt32Property %s: %s (invalid string) -> %" PRId32 " (default)",
name.c_str(), value.c_str(), res);
}
return res;
}
}
-uint32_t DBTEnv::getUint32Property(const std::string & name, const uint32_t default_value,
+uint32_t environment::getUint32Property(const std::string & name, const uint32_t default_value,
const uint32_t min_allowed, const uint32_t max_allowed) noexcept
{
const std::string value = getProperty(name);
if( 0 == value.length() ) {
- COND_PRINT(debug, "DBTEnv::getUint32Property %s: null -> %" PRIu32 " (default)", name.c_str(), default_value);
+ COND_PRINT(debug, "env::getUint32Property %s: null -> %" PRIu32 " (default)", name.c_str(), default_value);
return default_value;
} else {
uint32_t res = default_value;
@@ -150,28 +150,28 @@ uint32_t DBTEnv::getUint32Property(const std::string & name, const uint32_t defa
if( min_allowed <= res1 && res1 <= max_allowed ) {
// matching user value range
res = res1;
- COND_PRINT(debug, "DBTEnv::getUint32Property %s (default %" PRIu32 "): %" PRIu32 "/%s",
+ COND_PRINT(debug, "env::getUint32Property %s (default %" PRIu32 "): %" PRIu32 "/%s",
name.c_str(), default_value, res, value.c_str());
} else {
// invalid user value range
- ERR_PRINT("DBTEnv::getUint32Property %s: %" PRIu32 "/%s (invalid user range [% " PRIu32 "..%" PRIu32 "]) -> %" PRIu32 " (default)",
+ ERR_PRINT("env::getUint32Property %s: %" PRIu32 "/%s (invalid user range [% " PRIu32 "..%" PRIu32 "]) -> %" PRIu32 " (default)",
name.c_str(), res1, value.c_str(), min_allowed, max_allowed, res);
}
} else {
// invalid uint32_t range
- ERR_PRINT("DBTEnv::getUint32Property %s: %" PRIu64 "/%s (invalid uint32_t range) -> %" PRIu32 " (default)",
+ ERR_PRINT("env::getUint32Property %s: %" PRIu64 "/%s (invalid uint32_t range) -> %" PRIu32 " (default)",
name.c_str(), (uint64_t)res0, value.c_str(), res);
}
} else {
// string value not fully valid
- ERR_PRINT("DBTEnv::getUint32Property %s: %s (invalid string) -> %" PRIu32 " (default)",
+ ERR_PRINT("env::getUint32Property %s: %s (invalid string) -> %" PRIu32 " (default)",
name.c_str(), value.c_str(), res);
}
return res;
}
}
-void DBTEnv::envSet(std::string prefixDomain, std::string basepair) noexcept {
+void environment::envSet(std::string prefixDomain, std::string basepair) noexcept {
trimInPlace(basepair);
if( basepair.length() > 0 ) {
size_t pos = 0, start = 0;
@@ -183,22 +183,22 @@ void DBTEnv::envSet(std::string prefixDomain, std::string basepair) noexcept {
trimInPlace(value);
if( name.length() > 0 ) {
if( value.length() > 0 ) {
- COND_PRINT(debug, "DBTEnv::setProperty %s -> %s (explode)", name.c_str(), value.c_str());
+ COND_PRINT(debug, "env::setProperty %s -> %s (explode)", name.c_str(), value.c_str());
setenv(name.c_str(), value.c_str(), 1 /* overwrite */);
} else {
- COND_PRINT(debug, "DBTEnv::setProperty %s -> true (explode default-1)", name.c_str());
+ COND_PRINT(debug, "env::setProperty %s -> true (explode default-1)", name.c_str());
setenv(name.c_str(), "true", 1 /* overwrite */);
}
}
} else {
const std::string name = prefixDomain+"."+basepair;
- COND_PRINT(debug, "DBTEnv::setProperty %s -> true (explode default-0)", name.c_str());
+ COND_PRINT(debug, "env::setProperty %s -> true (explode default-0)", name.c_str());
setenv(name.c_str(), "true", 1 /* overwrite */);
}
}
}
-void DBTEnv::envExplodeProperties(std::string prefixDomain, std::string list) noexcept {
+void environment::envExplodeProperties(std::string prefixDomain, std::string list) noexcept {
size_t pos = 0, start = 0;
while( (pos = list.find(',', start)) != std::string::npos ) {
const size_t elem_len = pos-start; // excluding ','
@@ -209,12 +209,12 @@ void DBTEnv::envExplodeProperties(std::string prefixDomain, std::string list) no
if( elem_len > 0 ) {
envSet(prefixDomain, list.substr(start, elem_len));
}
- COND_PRINT(debug, "DBTEnv::setProperty %s -> true (explode default)", prefixDomain.c_str());
+ COND_PRINT(debug, "env::setProperty %s -> true (explode default)", prefixDomain.c_str());
setenv(prefixDomain.c_str(), "true", 1 /* overwrite */);
}
-bool DBTEnv::getExplodingProperties(const std::string & prefixDomain) noexcept {
- std::string value = DBTEnv::getProperty(prefixDomain, s_false);
+bool environment::getExplodingProperties(const std::string & prefixDomain) noexcept {
+ std::string value = environment::getProperty(prefixDomain, s_false);
if( s_false == value ) {
return false;
}
@@ -228,9 +228,9 @@ bool DBTEnv::getExplodingProperties(const std::string & prefixDomain) noexcept {
return true;
}
-DBTEnv::DBTEnv() noexcept
+environment::environment() noexcept
: DEBUG( getExplodingProperties("direct_bt.debug") ),
DEBUG_JNI( getBooleanProperty("direct_bt.debug.jni", false) ),
- VERBOSE( getExplodingProperties("direct_bt.verbose") || DBTEnv::DEBUG )
+ VERBOSE( getExplodingProperties("direct_bt.verbose") || environment::DEBUG )
{
}
diff --git a/jaucpp/test/CMakeLists.txt b/jaucpp/test/CMakeLists.txt
new file mode 100644
index 00000000..a6c4c66c
--- /dev/null
+++ b/jaucpp/test/CMakeLists.txt
@@ -0,0 +1,72 @@
+include_directories(
+ ${PROJECT_SOURCE_DIR}/include/cppunit
+ ${PROJECT_SOURCE_DIR}/include
+)
+
+add_executable (test_functiondef01 test_functiondef01.cpp)
+set_target_properties(test_functiondef01
+ PROPERTIES
+ CXX_STANDARD 17
+ CXX_STANDARD_REQUIRED ON
+ COMPILE_FLAGS "-Wall -Wextra -Werror"
+)
+target_link_libraries (test_functiondef01 jaucpp)
+add_dependencies(test_functiondef01 jaucpp)
+add_test (NAME functiondef01 COMMAND test_functiondef01)
+
+add_executable (test_basictypes01 test_basictypes01.cpp)
+set_target_properties(test_basictypes01
+ PROPERTIES
+ CXX_STANDARD 17
+ CXX_STANDARD_REQUIRED ON
+ COMPILE_FLAGS "-Wall -Wextra -Werror"
+)
+target_link_libraries (test_basictypes01 jaucpp)
+add_dependencies(test_basictypes01 jaucpp)
+add_test (NAME basictypes01 COMMAND test_basictypes01)
+
+add_executable (test_lfringbuffer01 test_lfringbuffer01.cpp)
+set_target_properties(test_lfringbuffer01
+ PROPERTIES
+ CXX_STANDARD 17
+ CXX_STANDARD_REQUIRED ON
+ COMPILE_FLAGS "-Wall -Wextra -Werror"
+)
+target_link_libraries (test_lfringbuffer01 jaucpp)
+add_dependencies(test_lfringbuffer01 jaucpp)
+add_test (NAME lfringbuffer01 COMMAND test_lfringbuffer01)
+
+add_executable (test_lfringbuffer11 test_lfringbuffer11.cpp)
+set_target_properties(test_lfringbuffer11
+ PROPERTIES
+ CXX_STANDARD 17
+ CXX_STANDARD_REQUIRED ON
+ COMPILE_FLAGS "-Wall -Wextra -Werror"
+)
+target_link_libraries (test_lfringbuffer11 jaucpp)
+add_dependencies(test_lfringbuffer11 jaucpp)
+add_test (NAME lfringbuffer11 COMMAND test_lfringbuffer11)
+
+add_executable (test_mm_sc_drf_00 test_mm_sc_drf_00.cpp)
+set_target_properties(test_mm_sc_drf_00
+ PROPERTIES
+ CXX_STANDARD 17
+ CXX_STANDARD_REQUIRED ON
+ COMPILE_FLAGS "-Wall -Wextra -Werror"
+)
+target_link_libraries (test_mm_sc_drf_00 jaucpp)
+add_dependencies(test_mm_sc_drf_00 jaucpp)
+add_test (NAME mm_sc_drf_00 COMMAND test_mm_sc_drf_00)
+
+add_executable (test_mm_sc_drf_01 test_mm_sc_drf_01.cpp)
+set_target_properties(test_mm_sc_drf_01
+ PROPERTIES
+ CXX_STANDARD 17
+ CXX_STANDARD_REQUIRED ON
+ COMPILE_FLAGS "-Wall -Wextra -Werror"
+)
+target_link_libraries (test_mm_sc_drf_01 jaucpp)
+add_dependencies(test_mm_sc_drf_01 jaucpp)
+add_test (NAME mm_sc_drf_01 COMMAND test_mm_sc_drf_01)
+
+
diff --git a/jaucpp/test/README.txt b/jaucpp/test/README.txt
new file mode 100644
index 00000000..d49b9045
--- /dev/null
+++ b/jaucpp/test/README.txt
@@ -0,0 +1,11 @@
+Rudimentary unit testing for our direct_bt
+using the very flat cppunit <https://github.com/cppunit/cppunit.git>.
+
+The 'cppunit.h' file has been dropped to: ${PROJECT_SOURCE_DIR}/include/cppunit/cppunit.h
+
+After a normal build, you may invoke testing via 'ctest'
+
+To see the normal test stdout/stderr, invoke 'ctest -V'.
+Sadly I haven't seen a way to inject this into the CMakeLists.txt file.
+
+
diff --git a/test/direct_bt/test_basictypes01.cpp b/jaucpp/test/test_basictypes01.cpp
index d44ac0c4..43aab795 100644
--- a/test/direct_bt/test_basictypes01.cpp
+++ b/jaucpp/test/test_basictypes01.cpp
@@ -5,10 +5,9 @@
#include <cppunit.h>
-#include <direct_bt/BasicTypes.hpp>
-#include <direct_bt/BTAddress.hpp>
+#include <jau/basic_types.hpp>
-using namespace direct_bt;
+using namespace jau;
// Test examples.
class Cppunit_tests : public Cppunit {
@@ -57,15 +56,6 @@ class Cppunit_tests : public Cppunit {
test_uint64_t("uint64_t thousand", 1000, 5, "1,000");
test_uint64_t("UINT64_MAX", UINT64_MAX, 26, "18,446,744,073,709,551,615");
}
- {
- EUI48 mac01;
- PRINTM("EUI48 size: whole0 "+std::to_string(sizeof(EUI48)));
- PRINTM("EUI48 size: whole1 "+std::to_string(sizeof(mac01)));
- PRINTM("EUI48 size: data1 "+std::to_string(sizeof(mac01.b)));
- CHECKM("EUI48 struct and data size not matching", sizeof(EUI48), sizeof(mac01));
- CHECKM("EUI48 struct and data size not matching", sizeof(mac01), sizeof(mac01.b));
- }
-
}
};
diff --git a/test/direct_bt/test_functiondef01.cpp b/jaucpp/test/test_functiondef01.cpp
index 02872b66..3cd1fea4 100644
--- a/test/direct_bt/test_functiondef01.cpp
+++ b/jaucpp/test/test_functiondef01.cpp
@@ -5,9 +5,9 @@
#include <cppunit.h>
-#include <direct_bt/FunctionDef.hpp>
+#include <jau/function_def.hpp>
-using namespace direct_bt;
+using namespace jau;
// Test examples.
class Cppunit_tests : public Cppunit {
diff --git a/test/direct_bt/test_lfringbuffer01.cpp b/jaucpp/test/test_lfringbuffer01.cpp
index 98f3c101..8799e63c 100644
--- a/test/direct_bt/test_lfringbuffer01.cpp
+++ b/jaucpp/test/test_lfringbuffer01.cpp
@@ -6,11 +6,9 @@
#include <cppunit.h>
-#include <direct_bt/UUID.hpp>
-#include <direct_bt/Ringbuffer.hpp>
-#include <direct_bt/LFRingbuffer.hpp>
+#include <jau/ringbuffer.hpp>
-using namespace direct_bt;
+using namespace jau;
class Integer {
public:
@@ -33,18 +31,17 @@ class Integer {
std::shared_ptr<Integer> NullInteger = nullptr;
typedef std::shared_ptr<Integer> SharedType;
-typedef Ringbuffer<SharedType> SharedTypeRingbuffer;
-typedef LFRingbuffer<SharedType, nullptr> SharedTypeLFRingbuffer;
+typedef ringbuffer<SharedType, nullptr> SharedTypeRingbuffer;
// Test examples.
class Cppunit_tests : public Cppunit {
private:
std::shared_ptr<SharedTypeRingbuffer> createEmpty(int initialCapacity) {
- return std::shared_ptr<SharedTypeRingbuffer>(new SharedTypeLFRingbuffer(initialCapacity));
+ return std::shared_ptr<SharedTypeRingbuffer>(new SharedTypeRingbuffer(initialCapacity));
}
std::shared_ptr<SharedTypeRingbuffer> createFull(const std::vector<std::shared_ptr<Integer>> & source) {
- return std::shared_ptr<SharedTypeRingbuffer>(new SharedTypeLFRingbuffer(source));
+ return std::shared_ptr<SharedTypeRingbuffer>(new SharedTypeRingbuffer(source));
}
std::vector<SharedType> createIntArray(const int capacity, const int startValue) {
@@ -55,7 +52,7 @@ class Cppunit_tests : public Cppunit {
return array;
}
- void readTestImpl(Ringbuffer<SharedType> &rb, bool clearRef, int capacity, int len, int startValue) {
+ void readTestImpl(SharedTypeRingbuffer &rb, bool clearRef, int capacity, int len, int startValue) {
(void) clearRef;
int preSize = rb.getSize();
@@ -75,7 +72,7 @@ class Cppunit_tests : public Cppunit {
CHECKTM("Is full "+rb.toString(), !rb.isFull());
}
- void writeTestImpl(Ringbuffer<SharedType> &rb, int capacity, int len, int startValue) {
+ void writeTestImpl(SharedTypeRingbuffer &rb, int capacity, int len, int startValue) {
int preSize = rb.getSize();
CHECKM("Wrong capacity "+rb.toString(), capacity, rb.capacity());
@@ -92,7 +89,7 @@ class Cppunit_tests : public Cppunit {
CHECKTM("Is empty "+rb.toString(), !rb.isEmpty());
}
- void moveGetPutImpl(Ringbuffer<SharedType> &rb, int pos) {
+ void moveGetPutImpl(SharedTypeRingbuffer &rb, int pos) {
CHECKTM("RB is empty "+rb.toString(), !rb.isEmpty());
for(int i=0; i<pos; i++) {
CHECKM("MoveFull.get failed "+rb.toString(), i, rb.get()->intValue());
@@ -100,7 +97,7 @@ class Cppunit_tests : public Cppunit {
}
}
- void movePutGetImpl(Ringbuffer<SharedType> &rb, int pos) {
+ void movePutGetImpl(SharedTypeRingbuffer &rb, int pos) {
CHECKTM("RB is full "+rb.toString(), !rb.isFull());
for(int i=0; i<pos; i++) {
CHECKTM("MoveEmpty.put failed "+rb.toString(), rb.put( SharedType( new Integer(600+i) ) ) );
@@ -123,7 +120,7 @@ class Cppunit_tests : public Cppunit {
void test02_EmptyWrite() {
int capacity = 11;
- std::shared_ptr<Ringbuffer<SharedType>> rb = createEmpty(capacity);
+ std::shared_ptr<SharedTypeRingbuffer> rb = createEmpty(capacity);
fprintf(stderr, "test01_EmptyWrite: Created / %s\n", rb->toString().c_str());
CHECKM("Not zero size "+rb->toString(), 0, rb->getSize());
CHECKTM("Not empty "+rb->toString(), rb->isEmpty());
@@ -141,7 +138,7 @@ class Cppunit_tests : public Cppunit {
void test03_FullReadReset() {
int capacity = 11;
std::vector<SharedType> source = createIntArray(capacity, 0);
- std::shared_ptr<Ringbuffer<SharedType>> rb = createFull(source);
+ std::shared_ptr<SharedTypeRingbuffer> rb = createFull(source);
fprintf(stderr, "test01_FullReadReset: Created / %s\n", rb->toString().c_str());
CHECKTM("Not full "+rb->toString(), rb->isFull());
@@ -164,7 +161,7 @@ class Cppunit_tests : public Cppunit {
void test04_EmptyWriteClear() {
int capacity = 11;
- std::shared_ptr<Ringbuffer<SharedType>> rb = createEmpty(capacity);
+ std::shared_ptr<SharedTypeRingbuffer> rb = createEmpty(capacity);
CHECKTM("Not empty "+rb->toString(), rb->isEmpty());
rb->clear();
@@ -189,7 +186,7 @@ class Cppunit_tests : public Cppunit {
void test05_ReadResetMid01() {
int capacity = 11;
std::vector<SharedType> source = createIntArray(capacity, 0);
- std::shared_ptr<Ringbuffer<SharedType>> rb = createFull(source);
+ std::shared_ptr<SharedTypeRingbuffer> rb = createFull(source);
CHECKTM("Not full "+rb->toString(), rb->isFull());
rb->reset(source);
@@ -209,7 +206,7 @@ class Cppunit_tests : public Cppunit {
void test06_ReadResetMid02() {
int capacity = 11;
std::vector<SharedType> source = createIntArray(capacity, 0);
- std::shared_ptr<Ringbuffer<SharedType>> rb = createFull(source);
+ std::shared_ptr<SharedTypeRingbuffer> rb = createFull(source);
CHECKTM("Not full "+rb->toString(), rb->isFull());
rb->reset(source);
@@ -231,7 +228,7 @@ class Cppunit_tests : public Cppunit {
int growAmount = 5;
int grownCapacity = initialCapacity+growAmount;
std::vector<SharedType> source = createIntArray(initialCapacity, 0);
- std::shared_ptr<Ringbuffer<SharedType>> rb = createFull(source);
+ std::shared_ptr<SharedTypeRingbuffer> rb = createFull(source);
for(int i=0; i<initialCapacity; i++) {
SharedType svI = rb->get();
diff --git a/test/direct_bt/test_lfringbuffer11.cpp b/jaucpp/test/test_lfringbuffer11.cpp
index dcbba69e..13960e6f 100644
--- a/test/direct_bt/test_lfringbuffer11.cpp
+++ b/jaucpp/test/test_lfringbuffer11.cpp
@@ -8,11 +8,9 @@
#include <cppunit.h>
-#include <direct_bt/UUID.hpp>
-#include <direct_bt/Ringbuffer.hpp>
-#include <direct_bt/LFRingbuffer.hpp>
+#include <jau/ringbuffer.hpp>
-using namespace direct_bt;
+using namespace jau;
class Integer {
public:
@@ -35,18 +33,17 @@ class Integer {
std::shared_ptr<Integer> NullInteger = nullptr;
typedef std::shared_ptr<Integer> SharedType;
-typedef Ringbuffer<SharedType> SharedTypeRingbuffer;
-typedef LFRingbuffer<SharedType, nullptr> SharedTypeLFRingbuffer;
+typedef ringbuffer<SharedType, nullptr> SharedTypeRingbuffer;
// Test examples.
class Cppunit_tests : public Cppunit {
private:
std::shared_ptr<SharedTypeRingbuffer> createEmpty(int initialCapacity) {
- return std::shared_ptr<SharedTypeRingbuffer>(new SharedTypeLFRingbuffer(initialCapacity));
+ return std::shared_ptr<SharedTypeRingbuffer>(new SharedTypeRingbuffer(initialCapacity));
}
std::shared_ptr<SharedTypeRingbuffer> createFull(const std::vector<std::shared_ptr<Integer>> & source) {
- return std::shared_ptr<SharedTypeRingbuffer>(new SharedTypeLFRingbuffer(source));
+ return std::shared_ptr<SharedTypeRingbuffer>(new SharedTypeRingbuffer(source));
}
std::vector<SharedType> createIntArray(const int capacity, const int startValue) {
@@ -57,7 +54,7 @@ class Cppunit_tests : public Cppunit {
return array;
}
- void getThreadType01(const std::string msg, std::shared_ptr<Ringbuffer<SharedType>> rb, int len, int startValue) {
+ void getThreadType01(const std::string msg, std::shared_ptr<SharedTypeRingbuffer> rb, int len, int startValue) {
// std::thread::id this_id = std::this_thread::get_id();
// pthread_t this_id = pthread_self();
@@ -74,7 +71,7 @@ class Cppunit_tests : public Cppunit {
fprintf(stderr, "%s: Dies / %s\n", msg.c_str(), rb->toString().c_str());
}
- void putThreadType01(const std::string msg, std::shared_ptr<Ringbuffer<SharedType>> rb, int len, int startValue) {
+ void putThreadType01(const std::string msg, std::shared_ptr<SharedTypeRingbuffer> rb, int len, int startValue) {
// std::thread::id this_id = std::this_thread::get_id();
// pthread_t this_id = pthread_self();
diff --git a/test/direct_bt/test_mm_sc_drf_00.cpp b/jaucpp/test/test_mm_sc_drf_00.cpp
index 505cbcc1..6d40d7a0 100644
--- a/test/direct_bt/test_mm_sc_drf_00.cpp
+++ b/jaucpp/test/test_mm_sc_drf_00.cpp
@@ -11,9 +11,9 @@
#include <cppunit.h>
-#include <direct_bt/OrderedAtomic.hpp>
+#include <jau/ordered_atomic.hpp>
-using namespace direct_bt;
+using namespace jau;
static int loops = 10;
diff --git a/test/direct_bt/test_mm_sc_drf_01.cpp b/jaucpp/test/test_mm_sc_drf_01.cpp
index faddc96d..16225912 100644
--- a/test/direct_bt/test_mm_sc_drf_01.cpp
+++ b/jaucpp/test/test_mm_sc_drf_01.cpp
@@ -13,9 +13,9 @@
#include <cppunit.h>
-#include <direct_bt/OrderedAtomic.hpp>
+#include <jau/ordered_atomic.hpp>
-using namespace direct_bt;
+using namespace jau;
static int loops = 10;
diff --git a/java/jni/BluetoothFactory.cxx b/java/jni/BluetoothFactory.cxx
index f62984cd..b8f4520c 100644
--- a/java/jni/BluetoothFactory.cxx
+++ b/java/jni/BluetoothFactory.cxx
@@ -27,9 +27,10 @@
#include "version.h"
-#include "JNIMem.hpp"
#include "helper_base.hpp"
+using namespace jau;
+
jstring Java_org_tinyb_BluetoothFactory_getNativeAPIVersion(JNIEnv *env, jclass clazz)
{
try {
diff --git a/java/jni/BluetoothUtils.cxx b/java/jni/BluetoothUtils.cxx
index 0cf41284..98741e7e 100644
--- a/java/jni/BluetoothUtils.cxx
+++ b/java/jni/BluetoothUtils.cxx
@@ -30,10 +30,9 @@
#include <time.h>
-#include "JNIMem.hpp"
-#include "helper_base.hpp"
+#include <jau/dfa_utf8_decode.hpp>
-#include "direct_bt/dfa_utf8_decode.hpp"
+#include "helper_base.hpp"
static const int64_t NanoPerMilli = 1000000L;
static const int64_t MilliPerOne = 1000L;
@@ -77,7 +76,7 @@ jstring Java_org_tinyb_BluetoothUtils_decodeUTF8String(JNIEnv *env, jclass clazz
if( NULL == buffer_ptr ) {
throw std::invalid_argument("GetPrimitiveArrayCritical(byte array) is null");
}
- sres = dfa_utf8_decode(buffer_ptr+offset, size);
+ sres = jau::dfa_utf8_decode(buffer_ptr+offset, size);
}
- return from_string_to_jstring(env, sres);
+ return jau::from_string_to_jstring(env, sres);
}
diff --git a/java/jni/direct_bt/CMakeLists.txt b/java/jni/direct_bt/CMakeLists.txt
index bfe35734..b98bf943 100644
--- a/java/jni/direct_bt/CMakeLists.txt
+++ b/java/jni/direct_bt/CMakeLists.txt
@@ -6,6 +6,7 @@ if (JNI_FOUND)
endif (JNI_FOUND)
set (direct_bt_LIB_INCLUDE_DIRS
+ ${PROJECT_SOURCE_DIR}/jaucpp/include
${PROJECT_SOURCE_DIR}/api
${PROJECT_SOURCE_DIR}/api/direct_bt
${PROJECT_SOURCE_DIR}/include
@@ -19,7 +20,8 @@ include_directories(
)
set (direct_bt_JNI_SRCS
- ${PROJECT_SOURCE_DIR}/java/jni/JNIMem.cxx
+ ${PROJECT_SOURCE_DIR}/jaucpp/java/jni/jni_mem.cxx
+ ${PROJECT_SOURCE_DIR}/jaucpp/java/jni/helper_jni.cxx
${PROJECT_SOURCE_DIR}/java/jni/helper_base.cxx
${PROJECT_SOURCE_DIR}/java/jni/BluetoothFactory.cxx
${PROJECT_SOURCE_DIR}/java/jni/BluetoothUtils.cxx
diff --git a/java/jni/direct_bt/DBTAdapter.cxx b/java/jni/direct_bt/DBTAdapter.cxx
index beb153c2..ce0b451c 100644
--- a/java/jni/direct_bt/DBTAdapter.cxx
+++ b/java/jni/direct_bt/DBTAdapter.cxx
@@ -26,9 +26,8 @@
#include "direct_bt_tinyb_DBTAdapter.h"
// #define VERBOSE_ON 1
-#include <dbt_debug.hpp>
+#include <jau/debug.hpp>
-#include "JNIMem.hpp"
#include "helper_base.hpp"
#include "helper_dbt.hpp"
@@ -73,7 +72,7 @@ class JNIAdapterStatusListener : public AdapterStatusListener {
static std::atomic<int> iname_next;
int const iname;
DBTDevice const * const deviceMatchRef;
- std::shared_ptr<JavaAnonObj> adapterObjRef;
+ std::shared_ptr<jau::JavaAnon> adapterObjRef;
JNIGlobalRef adapterSettingsClazzRef;
jmethodID adapterSettingsClazzCtor;
JNIGlobalRef eirDataTypeSetClazzRef;
@@ -97,129 +96,129 @@ class JNIAdapterStatusListener : public AdapterStatusListener {
std::string toString() const override {
const std::string devMatchAddr = nullptr != deviceMatchRef ? deviceMatchRef->address.toString() : "nil";
- return "JNIAdapterStatusListener[this "+aptrHexString(this)+", iname "+std::to_string(iname)+", devMatchAddr "+devMatchAddr+"]";
+ return "JNIAdapterStatusListener[this "+jau::aptrHexString(this)+", iname "+std::to_string(iname)+", devMatchAddr "+devMatchAddr+"]";
}
JNIAdapterStatusListener(JNIEnv *env, DBTAdapter *adapter, jobject statusListener, const DBTDevice * _deviceMatchRef)
: iname(iname_next.fetch_add(1)), deviceMatchRef(_deviceMatchRef), listenerObjRef(statusListener)
{
adapterObjRef = adapter->getJavaObject();
- JavaGlobalObj::check(adapterObjRef, E_FILE_LINE);
+ jau::JavaGlobalObj::check(adapterObjRef, E_FILE_LINE);
- jclass listenerClazz = search_class(env, listenerObjRef.getObject());
- java_exception_check_and_throw(env, E_FILE_LINE);
+ jclass listenerClazz = jau::search_class(env, listenerObjRef.getObject());
+ jau::java_exception_check_and_throw(env, E_FILE_LINE);
if( nullptr == listenerClazz ) {
- throw InternalError("AdapterStatusListener not found", E_FILE_LINE);
+ throw jau::InternalError("AdapterStatusListener not found", E_FILE_LINE);
}
// adapterSettingsClazzRef, adapterSettingsClazzCtor
{
- jclass adapterSettingsClazz = search_class(env, _adapterSettingsClassName.c_str());
- java_exception_check_and_throw(env, E_FILE_LINE);
+ jclass adapterSettingsClazz = jau::search_class(env, _adapterSettingsClassName.c_str());
+ jau::java_exception_check_and_throw(env, E_FILE_LINE);
if( nullptr == adapterSettingsClazz ) {
- throw InternalError("DBTDevice::java_class not found: "+_adapterSettingsClassName, E_FILE_LINE);
+ throw jau::InternalError("DBTDevice::java_class not found: "+_adapterSettingsClassName, E_FILE_LINE);
}
adapterSettingsClazzRef = JNIGlobalRef(adapterSettingsClazz);
env->DeleteLocalRef(adapterSettingsClazz);
}
- adapterSettingsClazzCtor = search_method(env, adapterSettingsClazzRef.getClass(), "<init>", _adapterSettingsClazzCtorArgs.c_str(), false);
- java_exception_check_and_throw(env, E_FILE_LINE);
+ adapterSettingsClazzCtor = jau::search_method(env, adapterSettingsClazzRef.getClass(), "<init>", _adapterSettingsClazzCtorArgs.c_str(), false);
+ jau::java_exception_check_and_throw(env, E_FILE_LINE);
if( nullptr == adapterSettingsClazzCtor ) {
- throw InternalError("AdapterSettings ctor not found: "+_adapterSettingsClassName+".<init>"+_adapterSettingsClazzCtorArgs, E_FILE_LINE);
+ throw jau::InternalError("AdapterSettings ctor not found: "+_adapterSettingsClassName+".<init>"+_adapterSettingsClazzCtorArgs, E_FILE_LINE);
}
// eirDataTypeSetClazzRef, eirDataTypeSetClazzCtor
{
- jclass eirDataTypeSetClazz = search_class(env, _eirDataTypeSetClassName.c_str());
- java_exception_check_and_throw(env, E_FILE_LINE);
+ jclass eirDataTypeSetClazz = jau::search_class(env, _eirDataTypeSetClassName.c_str());
+ jau::java_exception_check_and_throw(env, E_FILE_LINE);
if( nullptr == eirDataTypeSetClazz ) {
- throw InternalError("DBTDevice::java_class not found: "+_eirDataTypeSetClassName, E_FILE_LINE);
+ throw jau::InternalError("DBTDevice::java_class not found: "+_eirDataTypeSetClassName, E_FILE_LINE);
}
eirDataTypeSetClazzRef = JNIGlobalRef(eirDataTypeSetClazz);
env->DeleteLocalRef(eirDataTypeSetClazz);
}
- eirDataTypeSetClazzCtor = search_method(env, eirDataTypeSetClazzRef.getClass(), "<init>", _eirDataTypeSetClazzCtorArgs.c_str(), false);
- java_exception_check_and_throw(env, E_FILE_LINE);
+ eirDataTypeSetClazzCtor = jau::search_method(env, eirDataTypeSetClazzRef.getClass(), "<init>", _eirDataTypeSetClazzCtorArgs.c_str(), false);
+ jau::java_exception_check_and_throw(env, E_FILE_LINE);
if( nullptr == eirDataTypeSetClazzCtor ) {
- throw InternalError("EIRDataType ctor not found: "+_eirDataTypeSetClassName+".<init>"+_eirDataTypeSetClazzCtorArgs, E_FILE_LINE);
+ throw jau::InternalError("EIRDataType ctor not found: "+_eirDataTypeSetClassName+".<init>"+_eirDataTypeSetClazzCtorArgs, E_FILE_LINE);
}
// hciErrorCodeClazzRef, hciErrorCodeClazzGet
{
- jclass hciErrorCodeClazz = search_class(env, _hciStatusCodeClassName.c_str());
- java_exception_check_and_throw(env, E_FILE_LINE);
+ jclass hciErrorCodeClazz = jau::search_class(env, _hciStatusCodeClassName.c_str());
+ jau::java_exception_check_and_throw(env, E_FILE_LINE);
if( nullptr == hciErrorCodeClazz ) {
- throw InternalError("DBTDevice::java_class not found: "+_hciStatusCodeClassName, E_FILE_LINE);
+ throw jau::InternalError("DBTDevice::java_class not found: "+_hciStatusCodeClassName, E_FILE_LINE);
}
hciErrorCodeClazzRef = JNIGlobalRef(hciErrorCodeClazz);
env->DeleteLocalRef(hciErrorCodeClazz);
}
- hciErrorCodeClazzGet = search_method(env, hciErrorCodeClazzRef.getClass(), "get", _hciStatusCodeClazzGetArgs.c_str(), true);
- java_exception_check_and_throw(env, E_FILE_LINE);
+ hciErrorCodeClazzGet = jau::search_method(env, hciErrorCodeClazzRef.getClass(), "get", _hciStatusCodeClazzGetArgs.c_str(), true);
+ jau::java_exception_check_and_throw(env, E_FILE_LINE);
if( nullptr == hciErrorCodeClazzGet ) {
- throw InternalError("EIRDataType ctor not found: "+_hciStatusCodeClassName+".get"+_hciStatusCodeClazzGetArgs, E_FILE_LINE);
+ throw jau::InternalError("EIRDataType ctor not found: "+_hciStatusCodeClassName+".get"+_hciStatusCodeClazzGetArgs, E_FILE_LINE);
}
// deviceClazzRef, deviceClazzCtor
{
- jclass deviceClazz = search_class(env, DBTDevice::java_class().c_str());
- java_exception_check_and_throw(env, E_FILE_LINE);
+ jclass deviceClazz = jau::search_class(env, DBTDevice::java_class().c_str());
+ jau::java_exception_check_and_throw(env, E_FILE_LINE);
if( nullptr == deviceClazz ) {
- throw InternalError("DBTDevice::java_class not found: "+DBTDevice::java_class(), E_FILE_LINE);
+ throw jau::InternalError("DBTDevice::java_class not found: "+DBTDevice::java_class(), E_FILE_LINE);
}
deviceClazzRef = JNIGlobalRef(deviceClazz);
env->DeleteLocalRef(deviceClazz);
}
- deviceClazzCtor = search_method(env, deviceClazzRef.getClass(), "<init>", _deviceClazzCtorArgs.c_str(), false);
- java_exception_check_and_throw(env, E_FILE_LINE);
+ deviceClazzCtor = jau::search_method(env, deviceClazzRef.getClass(), "<init>", _deviceClazzCtorArgs.c_str(), false);
+ jau::java_exception_check_and_throw(env, E_FILE_LINE);
if( nullptr == deviceClazzCtor ) {
- throw InternalError("DBTDevice::java_class ctor not found: "+DBTDevice::java_class()+".<init>"+_deviceClazzCtorArgs, E_FILE_LINE);
+ throw jau::InternalError("DBTDevice::java_class ctor not found: "+DBTDevice::java_class()+".<init>"+_deviceClazzCtorArgs, E_FILE_LINE);
}
deviceClazzTSLastDiscoveryField = env->GetFieldID(deviceClazzRef.getClass(), "ts_last_discovery", "J");
- java_exception_check_and_throw(env, E_FILE_LINE);
+ jau::java_exception_check_and_throw(env, E_FILE_LINE);
if( nullptr == deviceClazzTSLastDiscoveryField ) {
- throw InternalError("DBTDevice::java_class field not found: "+DBTDevice::java_class()+".ts_last_discovery", E_FILE_LINE);
+ throw jau::InternalError("DBTDevice::java_class field not found: "+DBTDevice::java_class()+".ts_last_discovery", E_FILE_LINE);
}
deviceClazzTSLastUpdateField = env->GetFieldID(deviceClazzRef.getClass(), "ts_last_update", "J");
- java_exception_check_and_throw(env, E_FILE_LINE);
+ jau::java_exception_check_and_throw(env, E_FILE_LINE);
if( nullptr == deviceClazzTSLastUpdateField ) {
- throw InternalError("DBTDevice::java_class field not found: "+DBTDevice::java_class()+".ts_last_update", E_FILE_LINE);
+ throw jau::InternalError("DBTDevice::java_class field not found: "+DBTDevice::java_class()+".ts_last_update", E_FILE_LINE);
}
deviceClazzConnectionHandleField = env->GetFieldID(deviceClazzRef.getClass(), "hciConnHandle", "S");
- java_exception_check_and_throw(env, E_FILE_LINE);
+ jau::java_exception_check_and_throw(env, E_FILE_LINE);
if( nullptr == deviceClazzConnectionHandleField ) {
- throw InternalError("DBTDevice::java_class field not found: "+DBTDevice::java_class()+".hciConnHandle", E_FILE_LINE);
+ throw jau::InternalError("DBTDevice::java_class field not found: "+DBTDevice::java_class()+".hciConnHandle", E_FILE_LINE);
}
- mAdapterSettingsChanged = search_method(env, listenerClazz, "adapterSettingsChanged", _adapterSettingsChangedMethodArgs.c_str(), false);
- java_exception_check_and_throw(env, E_FILE_LINE);
+ mAdapterSettingsChanged = jau::search_method(env, listenerClazz, "adapterSettingsChanged", _adapterSettingsChangedMethodArgs.c_str(), false);
+ jau::java_exception_check_and_throw(env, E_FILE_LINE);
if( nullptr == mAdapterSettingsChanged ) {
- throw InternalError("AdapterStatusListener has no adapterSettingsChanged"+_adapterSettingsChangedMethodArgs+" method, for "+adapter->toString(), E_FILE_LINE);
+ throw jau::InternalError("AdapterStatusListener has no adapterSettingsChanged"+_adapterSettingsChangedMethodArgs+" method, for "+adapter->toString(), E_FILE_LINE);
}
- mDiscoveringChanged = search_method(env, listenerClazz, "discoveringChanged", _discoveringChangedMethodArgs.c_str(), false);
- java_exception_check_and_throw(env, E_FILE_LINE);
+ mDiscoveringChanged = jau::search_method(env, listenerClazz, "discoveringChanged", _discoveringChangedMethodArgs.c_str(), false);
+ jau::java_exception_check_and_throw(env, E_FILE_LINE);
if( nullptr == mDiscoveringChanged ) {
- throw InternalError("AdapterStatusListener has no discoveringChanged"+_discoveringChangedMethodArgs+" method, for "+adapter->toString(), E_FILE_LINE);
+ throw jau::InternalError("AdapterStatusListener has no discoveringChanged"+_discoveringChangedMethodArgs+" method, for "+adapter->toString(), E_FILE_LINE);
}
- mDeviceFound = search_method(env, listenerClazz, "deviceFound", _deviceFoundMethodArgs.c_str(), false);
- java_exception_check_and_throw(env, E_FILE_LINE);
+ mDeviceFound = jau::search_method(env, listenerClazz, "deviceFound", _deviceFoundMethodArgs.c_str(), false);
+ jau::java_exception_check_and_throw(env, E_FILE_LINE);
if( nullptr == mDeviceFound ) {
- throw InternalError("AdapterStatusListener has no deviceFound"+_deviceFoundMethodArgs+" method, for "+adapter->toString(), E_FILE_LINE);
+ throw jau::InternalError("AdapterStatusListener has no deviceFound"+_deviceFoundMethodArgs+" method, for "+adapter->toString(), E_FILE_LINE);
}
- mDeviceUpdated = search_method(env, listenerClazz, "deviceUpdated", _deviceUpdatedMethodArgs.c_str(), false);
- java_exception_check_and_throw(env, E_FILE_LINE);
+ mDeviceUpdated = jau::search_method(env, listenerClazz, "deviceUpdated", _deviceUpdatedMethodArgs.c_str(), false);
+ jau::java_exception_check_and_throw(env, E_FILE_LINE);
if( nullptr == mDeviceUpdated ) {
- throw InternalError("AdapterStatusListener has no deviceUpdated"+_deviceUpdatedMethodArgs+" method, for "+adapter->toString(), E_FILE_LINE);
+ throw jau::InternalError("AdapterStatusListener has no deviceUpdated"+_deviceUpdatedMethodArgs+" method, for "+adapter->toString(), E_FILE_LINE);
}
- mDeviceConnected = search_method(env, listenerClazz, "deviceConnected", _deviceConnectedMethodArgs.c_str(), false);
- java_exception_check_and_throw(env, E_FILE_LINE);
+ mDeviceConnected = jau::search_method(env, listenerClazz, "deviceConnected", _deviceConnectedMethodArgs.c_str(), false);
+ jau::java_exception_check_and_throw(env, E_FILE_LINE);
if( nullptr == mDeviceConnected ) {
- throw InternalError("AdapterStatusListener has no deviceConnected"+_deviceConnectedMethodArgs+" method, for "+adapter->toString(), E_FILE_LINE);
+ throw jau::InternalError("AdapterStatusListener has no deviceConnected"+_deviceConnectedMethodArgs+" method, for "+adapter->toString(), E_FILE_LINE);
}
- mDeviceDisconnected = search_method(env, listenerClazz, "deviceDisconnected", _deviceDisconnectedMethodArgs.c_str(), false);
- java_exception_check_and_throw(env, E_FILE_LINE);
+ mDeviceDisconnected = jau::search_method(env, listenerClazz, "deviceDisconnected", _deviceDisconnectedMethodArgs.c_str(), false);
+ jau::java_exception_check_and_throw(env, E_FILE_LINE);
if( nullptr == mDeviceDisconnected ) {
- throw InternalError("AdapterStatusListener has no deviceDisconnected"+_deviceDisconnectedMethodArgs+" method, for "+adapter->toString(), E_FILE_LINE);
+ throw jau::InternalError("AdapterStatusListener has no deviceDisconnected"+_deviceDisconnectedMethodArgs+" method, for "+adapter->toString(), E_FILE_LINE);
}
}
@@ -235,20 +234,20 @@ class JNIAdapterStatusListener : public AdapterStatusListener {
JNIEnv *env = *jni_env;
(void)a;
jobject adapterSettingOld = env->NewObject(adapterSettingsClazzRef.getClass(), adapterSettingsClazzCtor, (jint)oldmask);
- java_exception_check_and_throw(env, E_FILE_LINE);
+ jau::java_exception_check_and_throw(env, E_FILE_LINE);
JNIGlobalRef::check(adapterSettingOld, E_FILE_LINE);
jobject adapterSettingNew = env->NewObject(adapterSettingsClazzRef.getClass(), adapterSettingsClazzCtor, (jint)newmask);
- java_exception_check_and_throw(env, E_FILE_LINE);
+ jau::java_exception_check_and_throw(env, E_FILE_LINE);
JNIGlobalRef::check(adapterSettingNew, E_FILE_LINE);
jobject adapterSettingChanged = env->NewObject(adapterSettingsClazzRef.getClass(), adapterSettingsClazzCtor, (jint)changedmask);
- java_exception_check_and_throw(env, E_FILE_LINE);
+ jau::java_exception_check_and_throw(env, E_FILE_LINE);
JNIGlobalRef::check(adapterSettingChanged, E_FILE_LINE);
env->CallVoidMethod(listenerObjRef.getObject(), mAdapterSettingsChanged,
- JavaGlobalObj::GetObject(adapterObjRef), adapterSettingOld, adapterSettingNew, adapterSettingChanged, (jlong)timestamp);
- java_exception_check_and_throw(env, E_FILE_LINE);
+ jau::JavaGlobalObj::GetObject(adapterObjRef), adapterSettingOld, adapterSettingNew, adapterSettingChanged, (jlong)timestamp);
+ jau::java_exception_check_and_throw(env, E_FILE_LINE);
env->DeleteLocalRef(adapterSettingOld);
env->DeleteLocalRef(adapterSettingNew);
env->DeleteLocalRef(adapterSettingChanged);
@@ -257,56 +256,56 @@ class JNIAdapterStatusListener : public AdapterStatusListener {
void discoveringChanged(DBTAdapter &a, const bool enabled, const bool keepAlive, const uint64_t timestamp) override {
JNIEnv *env = *jni_env;
(void)a;
- env->CallVoidMethod(listenerObjRef.getObject(), mDiscoveringChanged, JavaGlobalObj::GetObject(adapterObjRef),
+ env->CallVoidMethod(listenerObjRef.getObject(), mDiscoveringChanged, jau::JavaGlobalObj::GetObject(adapterObjRef),
(jboolean)enabled, (jboolean)keepAlive, (jlong)timestamp);
- java_exception_check_and_throw(env, E_FILE_LINE);
+ jau::java_exception_check_and_throw(env, E_FILE_LINE);
}
void deviceFound(std::shared_ptr<DBTDevice> device, const uint64_t timestamp) override {
JNIEnv *env = *jni_env;
jobject jdevice;
- std::shared_ptr<JavaAnonObj> jDeviceRef0 = device->getJavaObject();
- if( JavaGlobalObj::isValid(jDeviceRef0) ) {
+ std::shared_ptr<jau::JavaAnon> jDeviceRef0 = device->getJavaObject();
+ if( jau::JavaGlobalObj::isValid(jDeviceRef0) ) {
// Reuse Java instance
- jdevice = JavaGlobalObj::GetObject(jDeviceRef0);
+ jdevice = jau::JavaGlobalObj::GetObject(jDeviceRef0);
} else {
// New Java instance
// Device(final long nativeInstance, final Adapter adptr, final String address, final int intAddressType, final String name)
- const jstring addr = from_string_to_jstring(env, device->getAddressString());
- const jstring name = from_string_to_jstring(env, device->getName());
- java_exception_check_and_throw(env, E_FILE_LINE);
+ const jstring addr = jau::from_string_to_jstring(env, device->getAddressString());
+ const jstring name = jau::from_string_to_jstring(env, device->getName());
+ jau::java_exception_check_and_throw(env, E_FILE_LINE);
jobject tmp_jdevice = env->NewObject(deviceClazzRef.getClass(), deviceClazzCtor,
- (jlong)device.get(), JavaGlobalObj::GetObject(adapterObjRef), addr,
+ (jlong)device.get(), jau::JavaGlobalObj::GetObject(adapterObjRef), addr,
device->getAddressType(), device->getBLERandomAddressType(),
name, (jlong)timestamp);
- java_exception_check_and_throw(env, E_FILE_LINE);
+ jau::java_exception_check_and_throw(env, E_FILE_LINE);
JNIGlobalRef::check(tmp_jdevice, E_FILE_LINE);
- std::shared_ptr<JavaAnonObj> jDeviceRef1 = device->getJavaObject();
- JavaGlobalObj::check(jDeviceRef1, E_FILE_LINE);
- jdevice = JavaGlobalObj::GetObject(jDeviceRef1);
+ std::shared_ptr<jau::JavaAnon> jDeviceRef1 = device->getJavaObject();
+ jau::JavaGlobalObj::check(jDeviceRef1, E_FILE_LINE);
+ jdevice = jau::JavaGlobalObj::GetObject(jDeviceRef1);
env->DeleteLocalRef(addr);
env->DeleteLocalRef(name);
env->DeleteLocalRef(tmp_jdevice);
}
env->SetLongField(jdevice, deviceClazzTSLastDiscoveryField, (jlong)device->getLastDiscoveryTimestamp());
- java_exception_check_and_throw(env, E_FILE_LINE);
+ jau::java_exception_check_and_throw(env, E_FILE_LINE);
env->CallVoidMethod(listenerObjRef.getObject(), mDeviceFound, jdevice, (jlong)timestamp);
- java_exception_check_and_throw(env, E_FILE_LINE);
+ jau::java_exception_check_and_throw(env, E_FILE_LINE);
}
void deviceUpdated(std::shared_ptr<DBTDevice> device, const EIRDataType updateMask, const uint64_t timestamp) override {
JNIEnv *env = *jni_env;
- std::shared_ptr<JavaAnonObj> jDeviceRef = device->getJavaObject();
- JavaGlobalObj::check(jDeviceRef, E_FILE_LINE);
- env->SetLongField(JavaGlobalObj::GetObject(jDeviceRef), deviceClazzTSLastUpdateField, (jlong)timestamp);
- java_exception_check_and_throw(env, E_FILE_LINE);
+ std::shared_ptr<jau::JavaAnon> jDeviceRef = device->getJavaObject();
+ jau::JavaGlobalObj::check(jDeviceRef, E_FILE_LINE);
+ env->SetLongField(jau::JavaGlobalObj::GetObject(jDeviceRef), deviceClazzTSLastUpdateField, (jlong)timestamp);
+ jau::java_exception_check_and_throw(env, E_FILE_LINE);
jobject eirDataTypeSet = env->NewObject(eirDataTypeSetClazzRef.getClass(), eirDataTypeSetClazzCtor, (jint)updateMask);
- java_exception_check_and_throw(env, E_FILE_LINE);
+ jau::java_exception_check_and_throw(env, E_FILE_LINE);
JNIGlobalRef::check(eirDataTypeSet, E_FILE_LINE);
- env->CallVoidMethod(listenerObjRef.getObject(), mDeviceUpdated, JavaGlobalObj::GetObject(jDeviceRef), eirDataTypeSet, (jlong)timestamp);
- java_exception_check_and_throw(env, E_FILE_LINE);
+ env->CallVoidMethod(listenerObjRef.getObject(), mDeviceUpdated, jau::JavaGlobalObj::GetObject(jDeviceRef), eirDataTypeSet, (jlong)timestamp);
+ jau::java_exception_check_and_throw(env, E_FILE_LINE);
env->DeleteLocalRef(eirDataTypeSet);
}
@@ -314,59 +313,59 @@ class JNIAdapterStatusListener : public AdapterStatusListener {
JNIEnv *env = *jni_env;
jobject jdevice;
- std::shared_ptr<JavaAnonObj> jDeviceRef0 = device->getJavaObject();
- if( JavaGlobalObj::isValid(jDeviceRef0) ) {
+ std::shared_ptr<jau::JavaAnon> jDeviceRef0 = device->getJavaObject();
+ if( jau::JavaGlobalObj::isValid(jDeviceRef0) ) {
// Reuse Java instance
- jdevice = JavaGlobalObj::GetObject(jDeviceRef0);
+ jdevice = jau::JavaGlobalObj::GetObject(jDeviceRef0);
} else {
// New Java instance
// Device(final long nativeInstance, final Adapter adptr, final String address, final int intAddressType, final String name)
- const jstring addr = from_string_to_jstring(env, device->getAddressString());
- const jstring name = from_string_to_jstring(env, device->getName());
- java_exception_check_and_throw(env, E_FILE_LINE);
+ const jstring addr = jau::from_string_to_jstring(env, device->getAddressString());
+ const jstring name = jau::from_string_to_jstring(env, device->getName());
+ jau::java_exception_check_and_throw(env, E_FILE_LINE);
jobject tmp_jdevice = env->NewObject(deviceClazzRef.getClass(), deviceClazzCtor,
- (jlong)device.get(), JavaGlobalObj::GetObject(adapterObjRef), addr,
+ (jlong)device.get(), jau::JavaGlobalObj::GetObject(adapterObjRef), addr,
device->getAddressType(), device->getBLERandomAddressType(),
name, (jlong)timestamp);
- java_exception_check_and_throw(env, E_FILE_LINE);
+ jau::java_exception_check_and_throw(env, E_FILE_LINE);
JNIGlobalRef::check(tmp_jdevice, E_FILE_LINE);
- std::shared_ptr<JavaAnonObj> jDeviceRef1 = device->getJavaObject();
- JavaGlobalObj::check(jDeviceRef1, E_FILE_LINE);
- jdevice = JavaGlobalObj::GetObject(jDeviceRef1);
+ std::shared_ptr<jau::JavaAnon> jDeviceRef1 = device->getJavaObject();
+ jau::JavaGlobalObj::check(jDeviceRef1, E_FILE_LINE);
+ jdevice = jau::JavaGlobalObj::GetObject(jDeviceRef1);
env->DeleteLocalRef(addr);
env->DeleteLocalRef(name);
env->DeleteLocalRef(tmp_jdevice);
}
env->SetShortField(jdevice, deviceClazzConnectionHandleField, (jshort)handle);
- java_exception_check_and_throw(env, E_FILE_LINE);
+ jau::java_exception_check_and_throw(env, E_FILE_LINE);
env->SetLongField(jdevice, deviceClazzTSLastDiscoveryField, (jlong)device->getLastDiscoveryTimestamp());
- java_exception_check_and_throw(env, E_FILE_LINE);
+ jau::java_exception_check_and_throw(env, E_FILE_LINE);
env->SetLongField(jdevice, deviceClazzTSLastUpdateField, (jlong)timestamp);
- java_exception_check_and_throw(env, E_FILE_LINE);
+ jau::java_exception_check_and_throw(env, E_FILE_LINE);
env->CallVoidMethod(listenerObjRef.getObject(), mDeviceConnected, jdevice, (jshort)handle, (jlong)timestamp);
- java_exception_check_and_throw(env, E_FILE_LINE);
+ jau::java_exception_check_and_throw(env, E_FILE_LINE);
}
void deviceDisconnected(std::shared_ptr<DBTDevice> device, const HCIStatusCode reason, const uint16_t handle, const uint64_t timestamp) override {
JNIEnv *env = *jni_env;
- std::shared_ptr<JavaAnonObj> jDeviceRef = device->getJavaObject();
- JavaGlobalObj::check(jDeviceRef, E_FILE_LINE);
- jobject jdevice = JavaGlobalObj::GetObject(jDeviceRef);
+ std::shared_ptr<jau::JavaAnon> jDeviceRef = device->getJavaObject();
+ jau::JavaGlobalObj::check(jDeviceRef, E_FILE_LINE);
+ jobject jdevice = jau::JavaGlobalObj::GetObject(jDeviceRef);
env->SetLongField(jdevice, deviceClazzTSLastUpdateField, (jlong)timestamp);
- java_exception_check_and_throw(env, E_FILE_LINE);
+ jau::java_exception_check_and_throw(env, E_FILE_LINE);
jobject hciErrorCode = env->CallStaticObjectMethod(hciErrorCodeClazzRef.getClass(), hciErrorCodeClazzGet, (jbyte)static_cast<uint8_t>(reason));
- java_exception_check_and_throw(env, E_FILE_LINE);
+ jau::java_exception_check_and_throw(env, E_FILE_LINE);
JNIGlobalRef::check(hciErrorCode, E_FILE_LINE);
env->SetShortField(jdevice, deviceClazzConnectionHandleField, (jshort)0); // zero out, disconnected
- java_exception_check_and_throw(env, E_FILE_LINE);
+ jau::java_exception_check_and_throw(env, E_FILE_LINE);
env->SetLongField(jdevice, deviceClazzTSLastUpdateField, (jlong)timestamp);
- java_exception_check_and_throw(env, E_FILE_LINE);
+ jau::java_exception_check_and_throw(env, E_FILE_LINE);
env->CallVoidMethod(listenerObjRef.getObject(), mDeviceDisconnected, jdevice, hciErrorCode, (jshort)handle, (jlong)timestamp);
- java_exception_check_and_throw(env, E_FILE_LINE);
+ jau::java_exception_check_and_throw(env, E_FILE_LINE);
}
};
std::atomic<int> JNIAdapterStatusListener::iname_next(0);
@@ -375,35 +374,35 @@ jboolean Java_direct_1bt_tinyb_DBTAdapter_addStatusListener(JNIEnv *env, jobject
{
try {
if( nullptr == statusListener ) {
- throw IllegalArgumentException("JNIAdapterStatusListener::addStatusListener: statusListener is null", E_FILE_LINE);
+ throw jau::IllegalArgumentException("JNIAdapterStatusListener::addStatusListener: statusListener is null", E_FILE_LINE);
}
{
- JNIAdapterStatusListener * pre = getInstanceUnchecked<JNIAdapterStatusListener>(env, statusListener);
+ JNIAdapterStatusListener * pre = jau::getInstanceUnchecked<JNIAdapterStatusListener>(env, statusListener);
if( nullptr != pre ) {
WARN_PRINT("JNIAdapterStatusListener::addStatusListener: statusListener's nativeInstance not null, already in use");
return false;
}
}
- DBTAdapter *adapter = getDBTObject<DBTAdapter>(env, obj);
- JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE);
+ DBTAdapter *adapter = jau::getJavaUplinkObject<DBTAdapter>(env, obj);
+ jau::JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE);
DBTDevice * deviceMatchRef = nullptr;
if( nullptr != jdeviceMatch ) {
- deviceMatchRef = getDBTObject<DBTDevice>(env, jdeviceMatch);
- JavaGlobalObj::check(deviceMatchRef->getJavaObject(), E_FILE_LINE);
+ deviceMatchRef = jau::getJavaUplinkObject<DBTDevice>(env, jdeviceMatch);
+ jau::JavaGlobalObj::check(deviceMatchRef->getJavaObject(), E_FILE_LINE);
}
std::shared_ptr<AdapterStatusListener> l =
std::shared_ptr<AdapterStatusListener>( new JNIAdapterStatusListener(env, adapter, statusListener, deviceMatchRef) );
- setInstance(env, statusListener, l.get());
+ jau::setInstance(env, statusListener, l.get());
if( adapter->addStatusListener( l ) ) {
return JNI_TRUE;
}
- clearInstance(env, statusListener);
+ jau::clearInstance(env, statusListener);
ERR_PRINT("JNIAdapterStatusListener::addStatusListener: FAILED: %s", l->toString().c_str());
} catch(...) {
- clearInstance(env, statusListener);
+ jau::clearInstance(env, statusListener);
rethrow_and_raise_java_exception(env);
}
ERR_PRINT("JNIAdapterStatusListener::addStatusListener: FAILED XX");
@@ -414,17 +413,17 @@ jboolean Java_direct_1bt_tinyb_DBTAdapter_removeStatusListenerImpl(JNIEnv *env,
{
try {
if( nullptr == statusListener ) {
- throw IllegalArgumentException("statusListener is null", E_FILE_LINE);
+ throw jau::IllegalArgumentException("statusListener is null", E_FILE_LINE);
}
- JNIAdapterStatusListener * pre = getInstanceUnchecked<JNIAdapterStatusListener>(env, statusListener);
+ JNIAdapterStatusListener * pre = jau::getInstanceUnchecked<JNIAdapterStatusListener>(env, statusListener);
if( nullptr == pre ) {
DBG_PRINT("statusListener's nativeInstance is null, not in use");
return false;
}
- clearInstance(env, statusListener);
+ jau::clearInstance(env, statusListener);
- DBTAdapter *adapter = getDBTObject<DBTAdapter>(env, obj);
- JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE);
+ DBTAdapter *adapter = jau::getJavaUplinkObject<DBTAdapter>(env, obj);
+ jau::JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE);
if( ! adapter->removeStatusListener( pre ) ) {
WARN_PRINT("Failed to remove statusListener with nativeInstance: %p at %s", pre, adapter->toString().c_str());
@@ -439,8 +438,8 @@ jboolean Java_direct_1bt_tinyb_DBTAdapter_removeStatusListenerImpl(JNIEnv *env,
jint Java_direct_1bt_tinyb_DBTAdapter_removeAllStatusListener(JNIEnv *env, jobject obj) {
try {
- DBTAdapter *adapter = getDBTObject<DBTAdapter>(env, obj);
- JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE);
+ DBTAdapter *adapter = jau::getJavaUplinkObject<DBTAdapter>(env, obj);
+ jau::JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE);
return adapter->removeAllStatusListener();
} catch(...) {
@@ -451,10 +450,10 @@ jint Java_direct_1bt_tinyb_DBTAdapter_removeAllStatusListener(JNIEnv *env, jobje
jboolean Java_direct_1bt_tinyb_DBTAdapter_isDeviceWhitelisted(JNIEnv *env, jobject obj, jstring jaddress) {
try {
- DBTAdapter *adapter = getDBTObject<DBTAdapter>(env, obj);
- JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE);
+ DBTAdapter *adapter = jau::getJavaUplinkObject<DBTAdapter>(env, obj);
+ jau::JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE);
- std::string saddress = from_jstring_to_string(env, jaddress);
+ std::string saddress = jau::from_jstring_to_string(env, jaddress);
EUI48 address(saddress);
return adapter->isDeviceWhitelisted(address);
} catch(...) {
@@ -467,10 +466,10 @@ jboolean Java_direct_1bt_tinyb_DBTAdapter_addDeviceToWhitelist__Ljava_lang_Strin
jshort min_interval, jshort max_interval,
jshort latency, jshort timeout) {
try {
- DBTAdapter *adapter = getDBTObject<DBTAdapter>(env, obj);
- JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE);
+ DBTAdapter *adapter = jau::getJavaUplinkObject<DBTAdapter>(env, obj);
+ jau::JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE);
- std::string saddress = from_jstring_to_string(env, jaddress);
+ std::string saddress = jau::from_jstring_to_string(env, jaddress);
EUI48 address(saddress);
const BDAddressType addressType = static_cast<BDAddressType>( jaddressType );
const HCIWhitelistConnectType ctype = static_cast<HCIWhitelistConnectType>( jctype );
@@ -483,10 +482,10 @@ jboolean Java_direct_1bt_tinyb_DBTAdapter_addDeviceToWhitelist__Ljava_lang_Strin
jboolean Java_direct_1bt_tinyb_DBTAdapter_addDeviceToWhitelist__Ljava_lang_String_2II(JNIEnv *env, jobject obj,
jstring jaddress, int jaddressType, int jctype) {
try {
- DBTAdapter *adapter = getDBTObject<DBTAdapter>(env, obj);
- JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE);
+ DBTAdapter *adapter = jau::getJavaUplinkObject<DBTAdapter>(env, obj);
+ jau::JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE);
- std::string saddress = from_jstring_to_string(env, jaddress);
+ std::string saddress = jau::from_jstring_to_string(env, jaddress);
EUI48 address(saddress);
const BDAddressType addressType = static_cast<BDAddressType>( jaddressType );
const HCIWhitelistConnectType ctype = static_cast<HCIWhitelistConnectType>( jctype );
@@ -498,10 +497,10 @@ jboolean Java_direct_1bt_tinyb_DBTAdapter_addDeviceToWhitelist__Ljava_lang_Strin
}
jboolean Java_direct_1bt_tinyb_DBTAdapter_removeDeviceFromWhitelist(JNIEnv *env, jobject obj, jstring jaddress, int jaddressType) {
try {
- DBTAdapter *adapter = getDBTObject<DBTAdapter>(env, obj);
- JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE);
+ DBTAdapter *adapter = jau::getJavaUplinkObject<DBTAdapter>(env, obj);
+ jau::JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE);
- std::string saddress = from_jstring_to_string(env, jaddress);
+ std::string saddress = jau::from_jstring_to_string(env, jaddress);
EUI48 address(saddress);
const BDAddressType addressType = static_cast<BDAddressType>( jaddressType );
return adapter->removeDeviceFromWhitelist(address, addressType);
@@ -513,9 +512,9 @@ jboolean Java_direct_1bt_tinyb_DBTAdapter_removeDeviceFromWhitelist(JNIEnv *env,
jstring Java_direct_1bt_tinyb_DBTAdapter_toStringImpl(JNIEnv *env, jobject obj) {
try {
- DBTAdapter *nativePtr = getDBTObject<DBTAdapter>(env, obj);
- JavaGlobalObj::check(nativePtr->getJavaObject(), E_FILE_LINE);
- return from_string_to_jstring(env, nativePtr->toString());
+ DBTAdapter *nativePtr = jau::getJavaUplinkObject<DBTAdapter>(env, obj);
+ jau::JavaGlobalObj::check(nativePtr->getJavaObject(), E_FILE_LINE);
+ return jau::from_string_to_jstring(env, nativePtr->toString());
} catch(...) {
rethrow_and_raise_java_exception(env);
}
@@ -526,7 +525,7 @@ void Java_direct_1bt_tinyb_DBTAdapter_deleteImpl(JNIEnv *env, jobject obj, jlong
{
(void)obj;
try {
- DBTAdapter *adapter = castInstance<DBTAdapter>(nativeInstance);
+ DBTAdapter *adapter = jau::castInstance<DBTAdapter>(nativeInstance);
DBG_PRINT("Java_direct_1bt_tinyb_DBTAdapter_deleteImpl %s", adapter->toString().c_str());
delete adapter;
} catch(...) {
@@ -537,7 +536,7 @@ void Java_direct_1bt_tinyb_DBTAdapter_deleteImpl(JNIEnv *env, jobject obj, jlong
jboolean Java_direct_1bt_tinyb_DBTAdapter_isEnabled(JNIEnv *env, jobject obj)
{
try {
- DBTAdapter *adapter = getDBTObject<DBTAdapter>(env, obj);
+ DBTAdapter *adapter = jau::getJavaUplinkObject<DBTAdapter>(env, obj);
return adapter->isEnabled();
} catch(...) {
rethrow_and_raise_java_exception(env);
@@ -548,7 +547,7 @@ jboolean Java_direct_1bt_tinyb_DBTAdapter_isEnabled(JNIEnv *env, jobject obj)
jbyte Java_direct_1bt_tinyb_DBTAdapter_startDiscoveryImpl(JNIEnv *env, jobject obj, jboolean keepAlive)
{
try {
- DBTAdapter *adapter = getDBTObject<DBTAdapter>(env, obj);
+ DBTAdapter *adapter = jau::getJavaUplinkObject<DBTAdapter>(env, obj);
return (jbyte) number( adapter->startDiscovery(keepAlive) );
} catch(...) {
rethrow_and_raise_java_exception(env);
@@ -559,7 +558,7 @@ jbyte Java_direct_1bt_tinyb_DBTAdapter_startDiscoveryImpl(JNIEnv *env, jobject o
jbyte Java_direct_1bt_tinyb_DBTAdapter_stopDiscoveryImpl(JNIEnv *env, jobject obj)
{
try {
- DBTAdapter *adapter = getDBTObject<DBTAdapter>(env, obj);
+ DBTAdapter *adapter = jau::getJavaUplinkObject<DBTAdapter>(env, obj);
return (jbyte) number( adapter->stopDiscovery() );
} catch(...) {
rethrow_and_raise_java_exception(env);
@@ -570,7 +569,7 @@ jbyte Java_direct_1bt_tinyb_DBTAdapter_stopDiscoveryImpl(JNIEnv *env, jobject ob
jobject Java_direct_1bt_tinyb_DBTAdapter_getDiscoveredDevicesImpl(JNIEnv *env, jobject obj)
{
try {
- DBTAdapter *adapter = getDBTObject<DBTAdapter>(env, obj);
+ DBTAdapter *adapter = jau::getJavaUplinkObject<DBTAdapter>(env, obj);
std::vector<std::shared_ptr<DBTDevice>> array = adapter->getDiscoveredDevices();
return convert_vector_sharedptr_to_jarraylist(env, array);
} catch(...) {
@@ -582,7 +581,7 @@ jobject Java_direct_1bt_tinyb_DBTAdapter_getDiscoveredDevicesImpl(JNIEnv *env, j
jint Java_direct_1bt_tinyb_DBTAdapter_removeDevicesImpl(JNIEnv *env, jobject obj)
{
try {
- DBTAdapter *adapter = getDBTObject<DBTAdapter>(env, obj);
+ DBTAdapter *adapter = jau::getJavaUplinkObject<DBTAdapter>(env, obj);
return adapter->removeDiscoveredDevices();
} catch(...) {
rethrow_and_raise_java_exception(env);
@@ -596,8 +595,8 @@ jint Java_direct_1bt_tinyb_DBTAdapter_removeDevicesImpl(JNIEnv *env, jobject obj
jboolean Java_direct_1bt_tinyb_DBTAdapter_setPowered(JNIEnv *env, jobject obj, jboolean value) {
try {
- DBTAdapter *adapter = getDBTObject<DBTAdapter>(env, obj);
- JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE);
+ DBTAdapter *adapter = jau::getJavaUplinkObject<DBTAdapter>(env, obj);
+ jau::JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE);
return adapter->setPowered(JNI_TRUE == value ? true : false) ? JNI_TRUE : JNI_FALSE;
} catch(...) {
rethrow_and_raise_java_exception(env);
@@ -607,8 +606,8 @@ jboolean Java_direct_1bt_tinyb_DBTAdapter_setPowered(JNIEnv *env, jobject obj, j
jbyte Java_direct_1bt_tinyb_DBTAdapter_resetImpl(JNIEnv *env, jobject obj) {
try {
- DBTAdapter *adapter = getDBTObject<DBTAdapter>(env, obj);
- JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE);
+ DBTAdapter *adapter = jau::getJavaUplinkObject<DBTAdapter>(env, obj);
+ jau::JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE);
HCIStatusCode res = adapter->reset();
return (jbyte) number(res);
} catch(...) {
@@ -619,9 +618,9 @@ jbyte Java_direct_1bt_tinyb_DBTAdapter_resetImpl(JNIEnv *env, jobject obj) {
jstring Java_direct_1bt_tinyb_DBTAdapter_getAlias(JNIEnv *env, jobject obj) {
try {
- DBTAdapter *adapter = getDBTObject<DBTAdapter>(env, obj);
- JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE);
- return from_string_to_jstring(env, adapter->getLocalName().getName());
+ DBTAdapter *adapter = jau::getJavaUplinkObject<DBTAdapter>(env, obj);
+ jau::JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE);
+ return jau::from_string_to_jstring(env, adapter->getLocalName().getName());
} catch(...) {
rethrow_and_raise_java_exception(env);
}
@@ -630,9 +629,9 @@ jstring Java_direct_1bt_tinyb_DBTAdapter_getAlias(JNIEnv *env, jobject obj) {
void Java_direct_1bt_tinyb_DBTAdapter_setAlias(JNIEnv *env, jobject obj, jstring jnewalias) {
try {
- DBTAdapter *adapter = getDBTObject<DBTAdapter>(env, obj);
- JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE);
- std::string newalias = from_jstring_to_string(env, jnewalias);
+ DBTAdapter *adapter = jau::getJavaUplinkObject<DBTAdapter>(env, obj);
+ jau::JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE);
+ std::string newalias = jau::from_jstring_to_string(env, jnewalias);
adapter->setLocalName(newalias, std::string());
} catch(...) {
rethrow_and_raise_java_exception(env);
@@ -641,8 +640,8 @@ void Java_direct_1bt_tinyb_DBTAdapter_setAlias(JNIEnv *env, jobject obj, jstring
jboolean Java_direct_1bt_tinyb_DBTAdapter_setDiscoverable(JNIEnv *env, jobject obj, jboolean value) {
try {
- DBTAdapter *adapter = getDBTObject<DBTAdapter>(env, obj);
- JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE);
+ DBTAdapter *adapter = jau::getJavaUplinkObject<DBTAdapter>(env, obj);
+ jau::JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE);
return adapter->setDiscoverable(JNI_TRUE == value ? true : false) ? JNI_TRUE : JNI_FALSE;
} catch(...) {
rethrow_and_raise_java_exception(env);
@@ -652,9 +651,9 @@ jboolean Java_direct_1bt_tinyb_DBTAdapter_setDiscoverable(JNIEnv *env, jobject o
jobject Java_direct_1bt_tinyb_DBTAdapter_connectDevice(JNIEnv *env, jobject obj, jstring jaddress, jstring jaddressType) {
try {
- DBTAdapter *adapter = getDBTObject<DBTAdapter>(env, obj);
- JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE);
- std::string saddress = from_jstring_to_string(env, jaddress);
+ DBTAdapter *adapter = jau::getJavaUplinkObject<DBTAdapter>(env, obj);
+ jau::JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE);
+ std::string saddress = jau::from_jstring_to_string(env, jaddress);
EUI48 address(saddress);
const BDAddressType addressType = fromJavaAdressTypeToBDAddressType(env, jaddressType);
std::shared_ptr<DBTDevice> device = adapter->findDiscoveredDevice(address, addressType);
@@ -663,11 +662,11 @@ jobject Java_direct_1bt_tinyb_DBTAdapter_connectDevice(JNIEnv *env, jobject obj,
if( !hci.isOpen() ) {
throw BluetoothException("Adapter's HCI closed "+adapter->toString(), E_FILE_LINE);
}
- std::shared_ptr<JavaAnonObj> jDeviceRef = device->getJavaObject();
- JavaGlobalObj::check(jDeviceRef, E_FILE_LINE);
+ std::shared_ptr<jau::JavaAnon> jDeviceRef = device->getJavaObject();
+ jau::JavaGlobalObj::check(jDeviceRef, E_FILE_LINE);
device->connectDefault();
- return JavaGlobalObj::GetObject(jDeviceRef);
+ return jau::JavaGlobalObj::GetObject(jDeviceRef);
}
} catch(...) {
rethrow_and_raise_java_exception(env);
@@ -677,8 +676,8 @@ jobject Java_direct_1bt_tinyb_DBTAdapter_connectDevice(JNIEnv *env, jobject obj,
jboolean Java_direct_1bt_tinyb_DBTAdapter_setPairable(JNIEnv *env, jobject obj, jboolean value) {
try {
- DBTAdapter *adapter = getDBTObject<DBTAdapter>(env, obj);
- JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE);
+ DBTAdapter *adapter = jau::getJavaUplinkObject<DBTAdapter>(env, obj);
+ jau::JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE);
return adapter->setBondable(JNI_TRUE == value ? true : false) ? JNI_TRUE : JNI_FALSE;
} catch(...) {
rethrow_and_raise_java_exception(env);
diff --git a/java/jni/direct_bt/DBTDevice.cxx b/java/jni/direct_bt/DBTDevice.cxx
index 8bf1f463..54c7aab0 100644
--- a/java/jni/direct_bt/DBTDevice.cxx
+++ b/java/jni/direct_bt/DBTDevice.cxx
@@ -26,9 +26,8 @@
#include "direct_bt_tinyb_DBTDevice.h"
// #define VERBOSE_ON 1
-#include <dbt_debug.hpp>
+#include <jau/debug.hpp>
-#include "JNIMem.hpp"
#include "helper_base.hpp"
#include "helper_dbt.hpp"
@@ -36,6 +35,7 @@
#include "direct_bt/DBTAdapter.hpp"
using namespace direct_bt;
+using namespace jau;
static const std::string _notificationReceivedMethodArgs("(Lorg/tinyb/BluetoothGattCharacteristic;[BJ)V");
static const std::string _indicationReceivedMethodArgs("(Lorg/tinyb/BluetoothGattCharacteristic;[BJZ)V");
@@ -141,7 +141,7 @@ class JNICharacteristicListener : public GATTCharacteristicListener {
void Java_direct_1bt_tinyb_DBTDevice_initImpl(JNIEnv *env, jobject obj)
{
try {
- DBTDevice *device = getDBTObject<DBTDevice>(env, obj);
+ DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj);
JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE);
} catch(...) {
rethrow_and_raise_java_exception(env);
@@ -150,7 +150,7 @@ void Java_direct_1bt_tinyb_DBTDevice_initImpl(JNIEnv *env, jobject obj)
jstring Java_direct_1bt_tinyb_DBTDevice_getNameImpl(JNIEnv *env, jobject obj) {
try {
- DBTDevice *nativePtr = getDBTObject<DBTDevice>(env, obj);
+ DBTDevice *nativePtr = getJavaUplinkObject<DBTDevice>(env, obj);
JavaGlobalObj::check(nativePtr->getJavaObject(), E_FILE_LINE);
return from_string_to_jstring(env, nativePtr->getName());
} catch(...) {
@@ -161,7 +161,7 @@ jstring Java_direct_1bt_tinyb_DBTDevice_getNameImpl(JNIEnv *env, jobject obj) {
jstring Java_direct_1bt_tinyb_DBTDevice_toStringImpl(JNIEnv *env, jobject obj) {
try {
- DBTDevice *nativePtr = getDBTObject<DBTDevice>(env, obj);
+ DBTDevice *nativePtr = getJavaUplinkObject<DBTDevice>(env, obj);
JavaGlobalObj::check(nativePtr->getJavaObject(), E_FILE_LINE);
return from_string_to_jstring(env, nativePtr->toString());
} catch(...) {
@@ -183,7 +183,7 @@ jboolean Java_direct_1bt_tinyb_DBTDevice_addCharacteristicListener(JNIEnv *env,
return false;
}
}
- DBTDevice *device = getDBTObject<DBTDevice>(env, obj);
+ DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj);
JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE);
std::shared_ptr<GATTHandler> gatt = device->getGATTHandler();
if( nullptr == gatt ) {
@@ -192,7 +192,7 @@ jboolean Java_direct_1bt_tinyb_DBTDevice_addCharacteristicListener(JNIEnv *env,
GATTCharacteristic * associatedCharacteristicRef = nullptr;
if( nullptr != jAssociatedCharacteristic ) {
- associatedCharacteristicRef = getDBTObject<GATTCharacteristic>(env, jAssociatedCharacteristic);
+ associatedCharacteristicRef = getJavaUplinkObject<GATTCharacteristic>(env, jAssociatedCharacteristic);
}
std::shared_ptr<GATTCharacteristicListener> l =
@@ -221,7 +221,7 @@ jboolean Java_direct_1bt_tinyb_DBTDevice_removeCharacteristicListener(JNIEnv *en
}
setObjectRef<JNICharacteristicListener>(env, jlistener, nullptr, "nativeInstance");
- DBTDevice *device = getDBTObjectUnchecked<DBTDevice>(env, obj);
+ DBTDevice *device = getJavaUplinkObjectUnchecked<DBTDevice>(env, obj);
if( nullptr == device ) {
// OK to have device being deleted already @ shutdown
return 0;
@@ -250,7 +250,7 @@ jint Java_direct_1bt_tinyb_DBTDevice_removeAllAssociatedCharacteristicListener(J
if( nullptr == jAssociatedCharacteristic ) {
throw IllegalArgumentException("associatedCharacteristic argument is null", E_FILE_LINE);
}
- DBTDevice *device = getDBTObjectUnchecked<DBTDevice>(env, obj);
+ DBTDevice *device = getJavaUplinkObjectUnchecked<DBTDevice>(env, obj);
if( nullptr == device ) {
// OK to have device being deleted already @ shutdown
return 0;
@@ -263,7 +263,7 @@ jint Java_direct_1bt_tinyb_DBTDevice_removeAllAssociatedCharacteristicListener(J
return 0;
}
- GATTCharacteristic * associatedCharacteristicRef = getDBTObject<GATTCharacteristic>(env, jAssociatedCharacteristic);
+ GATTCharacteristic * associatedCharacteristicRef = getJavaUplinkObject<GATTCharacteristic>(env, jAssociatedCharacteristic);
JavaGlobalObj::check(associatedCharacteristicRef->getJavaObject(), E_FILE_LINE);
return gatt->removeAllAssociatedCharacteristicListener(associatedCharacteristicRef);
@@ -275,7 +275,7 @@ jint Java_direct_1bt_tinyb_DBTDevice_removeAllAssociatedCharacteristicListener(J
jint Java_direct_1bt_tinyb_DBTDevice_removeAllCharacteristicListener(JNIEnv *env, jobject obj) {
try {
- DBTDevice *device = getDBTObjectUnchecked<DBTDevice>(env, obj);
+ DBTDevice *device = getJavaUplinkObjectUnchecked<DBTDevice>(env, obj);
if( nullptr == device ) {
// OK to have device being deleted already @ shutdown
return 0;
@@ -310,7 +310,7 @@ void Java_direct_1bt_tinyb_DBTDevice_deleteImpl(JNIEnv *env, jobject obj, jlong
jbyte Java_direct_1bt_tinyb_DBTDevice_disconnectImpl(JNIEnv *env, jobject obj)
{
try {
- DBTDevice *device = getDBTObject<DBTDevice>(env, obj);
+ DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj);
JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE);
return (jint) number( device->disconnect() );
} catch(...) {
@@ -322,7 +322,7 @@ jbyte Java_direct_1bt_tinyb_DBTDevice_disconnectImpl(JNIEnv *env, jobject obj)
jboolean Java_direct_1bt_tinyb_DBTDevice_removeImpl(JNIEnv *env, jobject obj)
{
try {
- DBTDevice *device = getDBTObject<DBTDevice>(env, obj);
+ DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj);
JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE);
device->remove();
} catch(...) {
@@ -334,7 +334,7 @@ jboolean Java_direct_1bt_tinyb_DBTDevice_removeImpl(JNIEnv *env, jobject obj)
jbyte Java_direct_1bt_tinyb_DBTDevice_connectImpl__(JNIEnv *env, jobject obj)
{
try {
- DBTDevice *device = getDBTObject<DBTDevice>(env, obj);
+ DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj);
JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE);
return (jbyte) number( device->connectDefault() );
} catch(...) {
@@ -349,7 +349,7 @@ jbyte Java_direct_1bt_tinyb_DBTDevice_connectImpl__SSSSSS(JNIEnv *env, jobject o
jshort latency, jshort timeout)
{
try {
- DBTDevice *device = getDBTObject<DBTDevice>(env, obj);
+ DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj);
JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE);
HCIStatusCode res;
switch( device->addressType ) {
@@ -372,7 +372,7 @@ jbyte Java_direct_1bt_tinyb_DBTDevice_connectImpl__SSSSSS(JNIEnv *env, jobject o
jbyte Java_direct_1bt_tinyb_DBTDevice_pairImpl(JNIEnv *env, jobject obj, jstring jpasskey)
{
try {
- DBTDevice *device = getDBTObject<DBTDevice>(env, obj);
+ DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj);
JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE);
const std::string passkey = nullptr != jpasskey ? from_jstring_to_string(env, jpasskey) : std::string();
@@ -387,7 +387,7 @@ jbyte Java_direct_1bt_tinyb_DBTDevice_pairImpl(JNIEnv *env, jobject obj, jstring
jbyteArray Java_direct_1bt_tinyb_DBTDevice_getSupportedPairingModesImpl(JNIEnv *env, jobject obj) {
try {
- DBTDevice *device = getDBTObject<DBTDevice>(env, obj);
+ DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj);
JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE);
std::vector<PairingMode> res0 = device->getSupportedPairingModes();
@@ -409,7 +409,7 @@ jbyteArray Java_direct_1bt_tinyb_DBTDevice_getSupportedPairingModesImpl(JNIEnv *
jbyteArray Java_direct_1bt_tinyb_DBTDevice_getRequiredPairingModesImpl(JNIEnv *env, jobject obj) {
try {
- DBTDevice *device = getDBTObject<DBTDevice>(env, obj);
+ DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj);
JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE);
std::vector<PairingMode> res0 = device->getRequiredPairingModes();
@@ -437,7 +437,7 @@ static const std::string _serviceClazzCtorArgs("(JLdirect_bt/tinyb/DBTDevice;ZLj
jobject Java_direct_1bt_tinyb_DBTDevice_getServicesImpl(JNIEnv *env, jobject obj) {
try {
- DBTDevice *device = getDBTObject<DBTDevice>(env, obj);
+ DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj);
JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE);
std::vector<GATTServiceRef> services = device->getGATTServices(); // implicit GATT connect and discovery if required incl GenericAccess retrieval
@@ -471,7 +471,7 @@ jobject Java_direct_1bt_tinyb_DBTDevice_getServicesImpl(JNIEnv *env, jobject obj
juuid, service->startHandle, service->endHandle);
java_exception_check_and_throw(env, E_FILE_LINE);
JNIGlobalRef::check(jservice, E_FILE_LINE);
- std::shared_ptr<JavaAnonObj> jServiceRef = service->getJavaObject(); // GlobalRef
+ std::shared_ptr<JavaAnon> jServiceRef = service->getJavaObject(); // GlobalRef
JavaGlobalObj::check(jServiceRef, E_FILE_LINE);
env->DeleteLocalRef(juuid);
env->DeleteLocalRef(jservice);
@@ -487,7 +487,7 @@ jobject Java_direct_1bt_tinyb_DBTDevice_getServicesImpl(JNIEnv *env, jobject obj
jboolean Java_direct_1bt_tinyb_DBTDevice_pingGATTImpl(JNIEnv *env, jobject obj)
{
try {
- DBTDevice *device = getDBTObject<DBTDevice>(env, obj);
+ DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj);
JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE);
return device->pingGATT() ? JNI_TRUE : JNI_FALSE;
@@ -500,7 +500,7 @@ jboolean Java_direct_1bt_tinyb_DBTDevice_pingGATTImpl(JNIEnv *env, jobject obj)
jstring Java_direct_1bt_tinyb_DBTDevice_getIcon(JNIEnv *env, jobject obj)
{
try {
- DBTDevice *device = getDBTObject<DBTDevice>(env, obj);
+ DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj);
JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE);
return nullptr; // FIXME
} catch(...) {
@@ -512,7 +512,7 @@ jstring Java_direct_1bt_tinyb_DBTDevice_getIcon(JNIEnv *env, jobject obj)
void Java_direct_1bt_tinyb_DBTDevice_setTrustedImpl(JNIEnv *env, jobject obj, jboolean value)
{
try {
- DBTDevice *device = getDBTObject<DBTDevice>(env, obj);
+ DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj);
JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE);
(void)value;
// FIXME
@@ -524,7 +524,7 @@ void Java_direct_1bt_tinyb_DBTDevice_setTrustedImpl(JNIEnv *env, jobject obj, jb
void Java_direct_1bt_tinyb_DBTDevice_setBlockedImpl(JNIEnv *env, jobject obj, jboolean value)
{
try {
- DBTDevice *device = getDBTObject<DBTDevice>(env, obj);
+ DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj);
JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE);
(void)value;
// FIXME
@@ -536,7 +536,7 @@ void Java_direct_1bt_tinyb_DBTDevice_setBlockedImpl(JNIEnv *env, jobject obj, jb
jboolean JNICALL Java_direct_1bt_tinyb_DBTDevice_getLegacyPairing(JNIEnv *env, jobject obj)
{
try {
- DBTDevice *device = getDBTObject<DBTDevice>(env, obj);
+ DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj);
JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE);
return JNI_FALSE; // FIXME
} catch(...) {
@@ -548,7 +548,7 @@ jboolean JNICALL Java_direct_1bt_tinyb_DBTDevice_getLegacyPairing(JNIEnv *env, j
jshort Java_direct_1bt_tinyb_DBTDevice_getRSSI(JNIEnv *env, jobject obj)
{
try {
- DBTDevice *device = getDBTObject<DBTDevice>(env, obj);
+ DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj);
JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE);
return (jshort) device->getRSSI();
} catch(...) {
@@ -561,7 +561,7 @@ jshort Java_direct_1bt_tinyb_DBTDevice_getRSSI(JNIEnv *env, jobject obj)
jobjectArray Java_direct_1bt_tinyb_DBTDevice_getUUIDs(JNIEnv *env, jobject obj)
{
try {
- DBTDevice *device = getDBTObject<DBTDevice>(env, obj);
+ DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj);
JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE);
return nullptr; // FIXME
} catch(...) {
@@ -573,7 +573,7 @@ jobjectArray Java_direct_1bt_tinyb_DBTDevice_getUUIDs(JNIEnv *env, jobject obj)
jstring Java_direct_1bt_tinyb_DBTDevice_getModalias(JNIEnv *env, jobject obj)
{
try {
- DBTDevice *device = getDBTObject<DBTDevice>(env, obj);
+ DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj);
JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE);
return nullptr; // FIXME
} catch(...) {
@@ -585,7 +585,7 @@ jstring Java_direct_1bt_tinyb_DBTDevice_getModalias(JNIEnv *env, jobject obj)
jobject Java_direct_1bt_tinyb_DBTDevice_getManufacturerData(JNIEnv *env, jobject obj)
{
try {
- DBTDevice *device = getDBTObject<DBTDevice>(env, obj);
+ DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj);
JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE);
std::shared_ptr<ManufactureSpecificData> mdata = device->getManufactureSpecificData();
@@ -622,7 +622,7 @@ jobject Java_direct_1bt_tinyb_DBTDevice_getManufacturerData(JNIEnv *env, jobject
jshort Java_direct_1bt_tinyb_DBTDevice_getTxPower(JNIEnv *env, jobject obj)
{
try {
- DBTDevice *device = getDBTObject<DBTDevice>(env, obj);
+ DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj);
JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE);
return (jshort) device->getTxPower();
} catch(...) {
@@ -672,17 +672,17 @@ static void disableBlockedNotifications(JNIEnv *env, jobject obj, DBTManager &mg
setObjectRef(env, obj, funcptr, "blockedNotificationRef"); // clear java ref
int count;
if( 1 != ( count = mgmt.removeMgmtEventCallback(MgmtEvent::Opcode::DEVICE_BLOCKED, funcDef) ) ) {
- throw direct_bt::InternalError(std::string("removeMgmtEventCallback of ")+funcDef.toString()+" not 1 but "+std::to_string(count), E_FILE_LINE);
+ throw InternalError(std::string("removeMgmtEventCallback of ")+funcDef.toString()+" not 1 but "+std::to_string(count), E_FILE_LINE);
}
if( 1 != ( count = mgmt.removeMgmtEventCallback(MgmtEvent::Opcode::DEVICE_UNBLOCKED, funcDef) ) ) {
- throw direct_bt::InternalError(std::string("removeMgmtEventCallback of ")+funcDef.toString()+" not 1 but "+std::to_string(count), E_FILE_LINE);
+ throw InternalError(std::string("removeMgmtEventCallback of ")+funcDef.toString()+" not 1 but "+std::to_string(count), E_FILE_LINE);
}
}
}
void Java_direct_1bt_tinyb_DBTDevice_disableBlockedNotificationsImpl(JNIEnv *env, jobject obj)
{
try {
- DBTDevice *device = getDBTObject<DBTDevice>(env, obj);
+ DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj);
JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE);
DBTManager & mgmt = device->getAdapter().getManager();
@@ -694,7 +694,7 @@ void Java_direct_1bt_tinyb_DBTDevice_disableBlockedNotificationsImpl(JNIEnv *env
void Java_direct_1bt_tinyb_DBTDevice_enableBlockedNotificationsImpl(JNIEnv *env, jobject obj, jobject javaCallback)
{
try {
- DBTDevice *device= getDBTObject<DBTDevice>(env, obj);
+ DBTDevice *device= getJavaUplinkObject<DBTDevice>(env, obj);
JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE);
DBTAdapter & adapter = device->getAdapter();
DBTManager & mgmt = adapter.getManager();
@@ -762,14 +762,14 @@ static void disablePairedNotifications(JNIEnv *env, jobject obj, DBTManager &mgm
setObjectRef(env, obj, funcptr, "pairedNotificationRef"); // clear java ref
int count;
if( 1 != ( count = mgmt.removeMgmtEventCallback(MgmtEvent::Opcode::DEVICE_UNPAIRED, funcDef) ) ) {
- throw direct_bt::InternalError(std::string("removeMgmtEventCallback of ")+funcDef.toString()+" not 1 but "+std::to_string(count), E_FILE_LINE);
+ throw InternalError(std::string("removeMgmtEventCallback of ")+funcDef.toString()+" not 1 but "+std::to_string(count), E_FILE_LINE);
}
}
}
void Java_direct_1bt_tinyb_DBTDevice_disablePairedNotificationsImpl(JNIEnv *env, jobject obj)
{
try {
- DBTDevice *device = getDBTObject<DBTDevice>(env, obj);
+ DBTDevice *device = getJavaUplinkObject<DBTDevice>(env, obj);
JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE);
DBTManager & mgmt = device->getAdapter().getManager();
@@ -781,7 +781,7 @@ void Java_direct_1bt_tinyb_DBTDevice_disablePairedNotificationsImpl(JNIEnv *env,
void Java_direct_1bt_tinyb_DBTDevice_enablePairedNotificationsImpl(JNIEnv *env, jobject obj, jobject javaCallback)
{
try {
- DBTDevice *device= getDBTObject<DBTDevice>(env, obj);
+ DBTDevice *device= getJavaUplinkObject<DBTDevice>(env, obj);
JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE);
DBTAdapter & adapter = device->getAdapter();
DBTManager & mgmt = adapter.getManager();
diff --git a/java/jni/direct_bt/DBTGattCharacteristic.cxx b/java/jni/direct_bt/DBTGattCharacteristic.cxx
index e22602c1..d166a77d 100644
--- a/java/jni/direct_bt/DBTGattCharacteristic.cxx
+++ b/java/jni/direct_bt/DBTGattCharacteristic.cxx
@@ -25,10 +25,8 @@
#include "direct_bt_tinyb_DBTGattCharacteristic.h"
-// #define VERBOSE_ON 1
-#include <dbt_debug.hpp>
+#include <jau/debug.hpp>
-#include "JNIMem.hpp"
#include "helper_base.hpp"
#include "helper_dbt.hpp"
@@ -36,10 +34,11 @@
#include "direct_bt/DBTAdapter.hpp"
using namespace direct_bt;
+using namespace jau;
jstring Java_direct_1bt_tinyb_DBTGattCharacteristic_toStringImpl(JNIEnv *env, jobject obj) {
try {
- GATTCharacteristic *nativePtr = getDBTObject<GATTCharacteristic>(env, obj);
+ GATTCharacteristic *nativePtr = getJavaUplinkObject<GATTCharacteristic>(env, obj);
JavaGlobalObj::check(nativePtr->getJavaObject(), E_FILE_LINE);
return from_string_to_jstring(env, nativePtr->toString());
} catch(...) {
@@ -63,7 +62,7 @@ static const std::string _descriptorClazzCtorArgs("(JLdirect_bt/tinyb/DBTGattCha
jobject Java_direct_1bt_tinyb_DBTGattCharacteristic_getDescriptorsImpl(JNIEnv *env, jobject obj) {
try {
- GATTCharacteristic *characteristic = getDBTObject<GATTCharacteristic>(env, obj);
+ GATTCharacteristic *characteristic = getJavaUplinkObject<GATTCharacteristic>(env, obj);
JavaGlobalObj::check(characteristic->getJavaObject(), E_FILE_LINE);
std::vector<GATTDescriptorRef> & descriptorList = characteristic->descriptorList;
@@ -95,7 +94,7 @@ jobject Java_direct_1bt_tinyb_DBTGattCharacteristic_getDescriptorsImpl(JNIEnv *e
juuid, (jshort)descriptor->handle, jvalue);
java_exception_check_and_throw(env, E_FILE_LINE);
JNIGlobalRef::check(jdesc, E_FILE_LINE);
- std::shared_ptr<JavaAnonObj> jDescRef = descriptor->getJavaObject(); // GlobalRef
+ std::shared_ptr<JavaAnon> jDescRef = descriptor->getJavaObject(); // GlobalRef
JavaGlobalObj::check(jDescRef, E_FILE_LINE);
env->DeleteLocalRef(juuid);
env->DeleteLocalRef(jvalue);
@@ -111,7 +110,7 @@ jobject Java_direct_1bt_tinyb_DBTGattCharacteristic_getDescriptorsImpl(JNIEnv *e
jbyteArray Java_direct_1bt_tinyb_DBTGattCharacteristic_readValueImpl(JNIEnv *env, jobject obj) {
try {
- GATTCharacteristic *characteristic = getDBTObject<GATTCharacteristic>(env, obj);
+ GATTCharacteristic *characteristic = getJavaUplinkObject<GATTCharacteristic>(env, obj);
JavaGlobalObj::check(characteristic->getJavaObject(), E_FILE_LINE);
POctets res(GATTHandler::number(GATTHandler::Defaults::MAX_ATT_MTU), 0);
@@ -141,7 +140,7 @@ jboolean Java_direct_1bt_tinyb_DBTGattCharacteristic_writeValueImpl(JNIEnv *env,
if( 0 == value_size ) {
return JNI_TRUE;
}
- GATTCharacteristic *characteristic = getDBTObject<GATTCharacteristic>(env, obj);
+ GATTCharacteristic *characteristic = getJavaUplinkObject<GATTCharacteristic>(env, obj);
JavaGlobalObj::check(characteristic->getJavaObject(), E_FILE_LINE);
JNICriticalArray<uint8_t, jbyteArray> criticalArray(env); // RAII - release
@@ -171,7 +170,7 @@ jboolean Java_direct_1bt_tinyb_DBTGattCharacteristic_writeValueImpl(JNIEnv *env,
jboolean Java_direct_1bt_tinyb_DBTGattCharacteristic_configNotificationIndicationImpl(JNIEnv *env, jobject obj,
jboolean enableNotification, jboolean enableIndication, jbooleanArray jEnabledState) {
try {
- GATTCharacteristic *characteristic = getDBTObjectUnchecked<GATTCharacteristic>(env, obj);
+ GATTCharacteristic *characteristic = getJavaUplinkObjectUnchecked<GATTCharacteristic>(env, obj);
if( nullptr == characteristic ) {
if( !enableNotification && !enableIndication ) {
// OK to have native characteristic being shutdown @ disable
diff --git a/java/jni/direct_bt/DBTGattDescriptor.cxx b/java/jni/direct_bt/DBTGattDescriptor.cxx
index 1dfc372f..615ba60d 100644
--- a/java/jni/direct_bt/DBTGattDescriptor.cxx
+++ b/java/jni/direct_bt/DBTGattDescriptor.cxx
@@ -26,9 +26,8 @@
#include "direct_bt_tinyb_DBTGattDescriptor.h"
// #define VERBOSE_ON 1
-#include <dbt_debug.hpp>
+#include <jau/debug.hpp>
-#include "JNIMem.hpp"
#include "helper_base.hpp"
#include "helper_dbt.hpp"
@@ -36,10 +35,11 @@
#include "direct_bt/DBTAdapter.hpp"
using namespace direct_bt;
+using namespace jau;
void Java_direct_1bt_tinyb_DBTGattDescriptor_deleteImpl(JNIEnv *env, jobject obj) {
try {
- GATTDescriptor *descriptor = getDBTObject<GATTDescriptor>(env, obj);
+ GATTDescriptor *descriptor = getJavaUplinkObject<GATTDescriptor>(env, obj);
(void)descriptor;
// No delete: Service instance owned by GATTService -> DBTDevice
} catch(...) {
@@ -50,7 +50,7 @@ void Java_direct_1bt_tinyb_DBTGattDescriptor_deleteImpl(JNIEnv *env, jobject obj
jstring Java_direct_1bt_tinyb_DBTGattDescriptor_toStringImpl(JNIEnv *env, jobject obj) {
(void)obj;
try {
- GATTDescriptor *descriptor = getDBTObject<GATTDescriptor>(env, obj);
+ GATTDescriptor *descriptor = getJavaUplinkObject<GATTDescriptor>(env, obj);
JavaGlobalObj::check(descriptor->getJavaObject(), E_FILE_LINE);
return from_string_to_jstring(env, descriptor->toString());
} catch(...) {
@@ -61,7 +61,7 @@ jstring Java_direct_1bt_tinyb_DBTGattDescriptor_toStringImpl(JNIEnv *env, jobjec
jbyteArray Java_direct_1bt_tinyb_DBTGattDescriptor_readValueImpl(JNIEnv *env, jobject obj) {
try {
- GATTDescriptor *descriptor = getDBTObject<GATTDescriptor>(env, obj);
+ GATTDescriptor *descriptor = getJavaUplinkObject<GATTDescriptor>(env, obj);
JavaGlobalObj::check(descriptor->getJavaObject(), E_FILE_LINE);
if( !descriptor->readValue() ) {
@@ -89,7 +89,7 @@ jboolean Java_direct_1bt_tinyb_DBTGattDescriptor_writeValueImpl(JNIEnv *env, job
if( 0 == value_size ) {
return JNI_TRUE;
}
- GATTDescriptor *descriptor = getDBTObject<GATTDescriptor>(env, obj);
+ GATTDescriptor *descriptor = getJavaUplinkObject<GATTDescriptor>(env, obj);
JavaGlobalObj::check(descriptor->getJavaObject(), E_FILE_LINE);
JNICriticalArray<uint8_t, jbyteArray> criticalArray(env); // RAII - release
diff --git a/java/jni/direct_bt/DBTGattService.cxx b/java/jni/direct_bt/DBTGattService.cxx
index 8b18110e..24dbc20e 100644
--- a/java/jni/direct_bt/DBTGattService.cxx
+++ b/java/jni/direct_bt/DBTGattService.cxx
@@ -26,9 +26,8 @@
#include "direct_bt_tinyb_DBTGattService.h"
// #define VERBOSE_ON 1
-#include <dbt_debug.hpp>
+#include <jau/debug.hpp>
-#include "JNIMem.hpp"
#include "helper_base.hpp"
#include "helper_dbt.hpp"
@@ -36,10 +35,11 @@
#include "direct_bt/DBTAdapter.hpp"
using namespace direct_bt;
+using namespace jau;
jstring Java_direct_1bt_tinyb_DBTGattService_toStringImpl(JNIEnv *env, jobject obj) {
try {
- GATTService *nativePtr = getDBTObject<GATTService>(env, obj);
+ GATTService *nativePtr = getJavaUplinkObject<GATTService>(env, obj);
JavaGlobalObj::check(nativePtr->getJavaObject(), E_FILE_LINE);
return from_string_to_jstring(env, nativePtr->toString());
} catch(...) {
@@ -64,7 +64,7 @@ static const std::string _characteristicClazzCtorArgs("(JLdirect_bt/tinyb/DBTGat
jobject Java_direct_1bt_tinyb_DBTGattService_getCharacteristicsImpl(JNIEnv *env, jobject obj) {
try {
- GATTService *service = getDBTObject<GATTService>(env, obj);
+ GATTService *service = getJavaUplinkObject<GATTService>(env, obj);
JavaGlobalObj::check(service->getJavaObject(), E_FILE_LINE);
std::vector<std::shared_ptr<GATTCharacteristic>> & characteristics = service->characteristicList;
@@ -112,7 +112,7 @@ jobject Java_direct_1bt_tinyb_DBTGattService_getCharacteristicsImpl(JNIEnv *env,
uuid, characteristic->value_handle, characteristic->clientCharacteristicsConfigIndex);
java_exception_check_and_throw(env, E_FILE_LINE);
JNIGlobalRef::check(jchar, E_FILE_LINE);
- std::shared_ptr<JavaAnonObj> jCharRef = characteristic->getJavaObject(); // GlobalRef
+ std::shared_ptr<JavaAnon> jCharRef = characteristic->getJavaObject(); // GlobalRef
JavaGlobalObj::check(jCharRef, E_FILE_LINE);
env->DeleteLocalRef(jproperties);
env->DeleteLocalRef(jchar);
diff --git a/java/jni/direct_bt/DBTManager.cxx b/java/jni/direct_bt/DBTManager.cxx
index 393cc126..2cd71e64 100644
--- a/java/jni/direct_bt/DBTManager.cxx
+++ b/java/jni/direct_bt/DBTManager.cxx
@@ -26,9 +26,8 @@
#include "direct_bt_tinyb_DBTManager.h"
// #define VERBOSE_ON 1
-#include <dbt_debug.hpp>
+#include <jau/debug.hpp>
-#include "JNIMem.hpp"
#include "helper_base.hpp"
#include "helper_dbt.hpp"
@@ -37,6 +36,7 @@
#include "direct_bt/DBTAdapter.hpp"
using namespace direct_bt;
+using namespace jau;
void Java_direct_1bt_tinyb_DBTManager_initImpl(JNIEnv *env, jobject obj, jboolean unifyUUID128Bit, jint jbtMode)
{
@@ -46,7 +46,7 @@ void Java_direct_1bt_tinyb_DBTManager_initImpl(JNIEnv *env, jobject obj, jboolea
DBTManager *manager = &DBTManager::get(btMode); // special: static singleton
setInstance<DBTManager>(env, obj, manager);
java_exception_check_and_throw(env, E_FILE_LINE);
- manager->setJavaObject( std::shared_ptr<JavaAnonObj>( new JavaGlobalObj(obj, nullptr) ) );
+ manager->setJavaObject( std::shared_ptr<JavaAnon>( new JavaGlobalObj(obj, nullptr) ) );
JavaGlobalObj::check(manager->getJavaObject(), E_FILE_LINE);
DBG_PRINT("Java_direct_1bt_tinyb_DBTManager_init: Manager %s", manager->toString().c_str());
} catch(...) {
@@ -100,7 +100,7 @@ jobject Java_direct_1bt_tinyb_DBTManager_getAdapterListImpl(JNIEnv *env, jobject
jobject jAdapter = env->NewObject(clazz, clazz_ctor, (jlong)adapter, addr, name);
java_exception_check_and_throw(env, E_FILE_LINE);
JNIGlobalRef::check(jAdapter, E_FILE_LINE);
- std::shared_ptr<JavaAnonObj> jAdapterRef = adapter->getJavaObject(); // GlobalRef
+ std::shared_ptr<JavaAnon> jAdapterRef = adapter->getJavaObject(); // GlobalRef
JavaGlobalObj::check(jAdapterRef, E_FILE_LINE);
env->DeleteLocalRef(addr);
env->DeleteLocalRef(name);
diff --git a/java/jni/direct_bt/DBTNativeDownlink.cxx b/java/jni/direct_bt/DBTNativeDownlink.cxx
index 0ba8fe51..0202d78c 100644
--- a/java/jni/direct_bt/DBTNativeDownlink.cxx
+++ b/java/jni/direct_bt/DBTNativeDownlink.cxx
@@ -25,15 +25,15 @@
#include "direct_bt_tinyb_DBTNativeDownlink.h"
-#include <dbt_debug.hpp>
+#include <jau/debug.hpp>
-#include "JNIMem.hpp"
#include "helper_base.hpp"
#include "helper_dbt.hpp"
#include "direct_bt/DBTTypes.hpp"
using namespace direct_bt;
+using namespace jau;
void Java_direct_1bt_tinyb_DBTNativeDownlink_initNativeJavaObject(JNIEnv *env, jobject obj, jlong nativeInstance)
{
diff --git a/java/jni/direct_bt/DBTObject.cxx b/java/jni/direct_bt/DBTObject.cxx
index 25b578a0..d1116022 100644
--- a/java/jni/direct_bt/DBTObject.cxx
+++ b/java/jni/direct_bt/DBTObject.cxx
@@ -25,7 +25,6 @@
// #include "direct_bt_tinyb_DBTObject.h"
-#include "JNIMem.hpp"
#include "helper_base.hpp"
#include "direct_bt/DBTTypes.hpp"
diff --git a/java/jni/direct_bt/helper_dbt.cxx b/java/jni/direct_bt/helper_dbt.cxx
index 5ce0489d..23d54105 100644
--- a/java/jni/direct_bt/helper_dbt.cxx
+++ b/java/jni/direct_bt/helper_dbt.cxx
@@ -34,18 +34,13 @@ using namespace direct_bt;
DirectBTJNISettings direct_bt::directBTJNISettings;
-jclass direct_bt::search_class(JNIEnv *env, JavaUplink &object)
-{
- return search_class(env, object.get_java_class().c_str());
-}
-
static std::string jStringEmpty("");
static std::string jAddressTypePublic("public");
static std::string jAddressTypeRandom("random");
BDAddressType direct_bt::fromJavaAdressTypeToBDAddressType(JNIEnv *env, jstring jAddressType) {
if( nullptr != jAddressType ) {
- std::string saddressType = from_jstring_to_string(env, jAddressType);
+ std::string saddressType = jau::from_jstring_to_string(env, jAddressType);
if( jAddressTypePublic == saddressType ) {
return BDAddressType::BDADDR_LE_PUBLIC;
}
@@ -58,23 +53,13 @@ BDAddressType direct_bt::fromJavaAdressTypeToBDAddressType(JNIEnv *env, jstring
jstring direct_bt::fromBDAddressTypeToJavaAddressType(JNIEnv *env, BDAddressType bdAddressType) {
switch( bdAddressType ) {
case BDAddressType::BDADDR_LE_PUBLIC:
- return from_string_to_jstring(env, jAddressTypePublic);
+ return jau::from_string_to_jstring(env, jAddressTypePublic);
case BDAddressType::BDADDR_LE_RANDOM:
- return from_string_to_jstring(env, jAddressTypeRandom);
+ return jau::from_string_to_jstring(env, jAddressTypeRandom);
case BDAddressType::BDADDR_BREDR:
// fall through intended
default:
- return from_string_to_jstring(env, jStringEmpty);
- }
-}
-
-JavaGlobalObj::~JavaGlobalObj() noexcept {
- jobject obj = javaObjectRef.getObject();
- if( nullptr == obj || nullptr == mNotifyDeleted ) {
- return;
+ return jau::from_string_to_jstring(env, jStringEmpty);
}
- JNIEnv *env = *jni_env;
- env->CallVoidMethod(obj, mNotifyDeleted);
- java_exception_check_and_throw(env, E_FILE_LINE); // would abort() if thrown
}
diff --git a/java/jni/direct_bt/helper_dbt.hpp b/java/jni/direct_bt/helper_dbt.hpp
index 45d92d7a..584e842d 100644
--- a/java/jni/direct_bt/helper_dbt.hpp
+++ b/java/jni/direct_bt/helper_dbt.hpp
@@ -26,11 +26,8 @@
#ifndef HELPER_DBT_HPP_
#define HELPER_DBT_HPP_
-#include "JNIMem.hpp"
#include "helper_base.hpp"
-#include "direct_bt/JavaUplink.hpp"
-#include "direct_bt/BasicTypes.hpp"
#include "direct_bt/BTAddress.hpp"
namespace direct_bt {
@@ -52,134 +49,9 @@ namespace direct_bt {
};
extern DirectBTJNISettings directBTJNISettings;
- /**
- * Implementation for JavaAnonObj,
- * by simply wrapping a JNIGlobalRef instance.
- */
- class JavaGlobalObj : public JavaAnonObj {
- private:
- JNIGlobalRef javaObjectRef;
- jmethodID mNotifyDeleted;
-
- public:
- static inline void check(const std::shared_ptr<JavaAnonObj> & shref, const char* file, int line) {
- if( nullptr == shref ) {
- throw direct_bt::RuntimeException("JavaGlobalObj::check: Null shared-JavaAnonObj", file, line);
- }
- const jobject obj = static_cast<const JavaGlobalObj*>(shref.get())->getObject();
- if( nullptr == obj ) {
- throw direct_bt::RuntimeException("JavaGlobalObj::check: Null object", file, line);
- }
- }
- static bool isValid(const std::shared_ptr<JavaAnonObj> & shref) noexcept {
- if( nullptr == shref ) {
- return false;
- }
- const jobject obj = static_cast<const JavaGlobalObj*>(shref.get())->getObject();
- if( nullptr == obj ) {
- return false;
- }
- return true;
- }
- JavaGlobalObj(jobject obj, jmethodID mNotifyDeleted) noexcept
- : javaObjectRef(obj), mNotifyDeleted(mNotifyDeleted) { }
-
- JavaGlobalObj(const JavaGlobalObj &o) noexcept = default;
- JavaGlobalObj(JavaGlobalObj &&o) noexcept = default;
- JavaGlobalObj& operator=(const JavaGlobalObj &o) noexcept = default;
- JavaGlobalObj& operator=(JavaGlobalObj &&o) noexcept = default;
-
- virtual ~JavaGlobalObj() noexcept;
-
- std::string toString() const noexcept override {
- const uint64_t ref = (uint64_t)(void*)javaObjectRef.getObject();
- return "JavaGlobalObj["+uint64HexString(ref, true)+"]";
- }
-
- /** Clears the java reference, i.e. nulling it, without deleting the global reference via JNI. */
- void clear() noexcept override { javaObjectRef.clear(); }
-
- JNIGlobalRef & getJavaObject() noexcept { return javaObjectRef; }
-
- /* Provides access to the stored GlobalRef as an jobject. */
- jobject getObject() const noexcept { return javaObjectRef.getObject(); }
- /* Provides access to the stored GlobalRef as a jclass. */
- jclass getClass() const noexcept { return javaObjectRef.getClass(); }
-
- /* Provides access to the stored GlobalRef as an getJavaObject. */
- static JNIGlobalRef GetJavaObject(const std::shared_ptr<JavaAnonObj> & shref) noexcept {
- return static_cast<JavaGlobalObj*>(shref.get())->getJavaObject();
- }
- /* Provides access to the stored GlobalRef as an jobject. */
- static jobject GetObject(const std::shared_ptr<JavaAnonObj> & shref) noexcept {
- return static_cast<JavaGlobalObj*>(shref.get())->getObject();
- }
-
- /* Provides access to the stored GlobalRef as a jclass. */
- static jclass GetClass(const std::shared_ptr<JavaAnonObj> & shref) noexcept {
- return static_cast<JavaGlobalObj*>(shref.get())->getClass();
- }
- };
-
- jclass search_class(JNIEnv *env, JavaUplink &object);
-
- template <typename T>
- jobject convert_vector_sharedptr_to_jarraylist(JNIEnv *env, std::vector<std::shared_ptr<T>>& array)
- {
- unsigned int array_size = array.size();
-
- jmethodID arraylist_add;
- jobject result = get_new_arraylist(env, array_size, &arraylist_add);
-
- if (0 == array_size) {
- return result;
- }
-
- for (unsigned int i = 0; i < array_size; ++i) {
- std::shared_ptr<T> elem = array[i];
- std::shared_ptr<JavaAnonObj> objref = elem->getJavaObject();
- if ( nullptr == objref ) {
- throw InternalError("JavaUplink element of array has no valid java-object: "+elem->toString(), E_FILE_LINE);
- }
- env->CallBooleanMethod(result, arraylist_add, JavaGlobalObj::GetObject(objref));
- }
- return result;
- }
-
BDAddressType fromJavaAdressTypeToBDAddressType(JNIEnv *env, jstring jAddressType);
jstring fromBDAddressTypeToJavaAddressType(JNIEnv *env, BDAddressType bdAddressType);
- template <typename T>
- T *getDBTObject(JNIEnv *env, jobject obj)
- {
- jlong instance = env->GetLongField(obj, getInstanceField(env, obj));
- T *t = reinterpret_cast<T *>(instance);
- if (t == nullptr) {
- throw std::runtime_error("Trying to acquire null DBTObject");
- }
- t->checkValid();
- return t;
- }
-
- template <typename T>
- T *getDBTObjectUnchecked(JNIEnv *env, jobject obj)
- {
- jlong instance = env->GetLongField(obj, getInstanceField(env, obj));
- return reinterpret_cast<T *>(instance);
- }
-
- template <typename T>
- void setDBTObject(JNIEnv *env, jobject obj, T *t)
- {
- if (t == nullptr) {
- throw std::runtime_error("Trying to create null DBTObject");
- }
- jlong instance = reinterpret_cast<jlong>(t);
- env->SetLongField(obj, getInstanceField(env, obj), instance);
- }
-
-
-
} // namespace direct_bt
#endif /* HELPER_DBT_HPP_ */
diff --git a/java/jni/helper_base.cxx b/java/jni/helper_base.cxx
index d30ba9f0..ceac1c78 100644
--- a/java/jni/helper_base.cxx
+++ b/java/jni/helper_base.cxx
@@ -35,217 +35,23 @@
#define JAVA_MAIN_PACKAGE "org/tinyb"
-jfieldID getField(JNIEnv *env, jobject obj, const char* field_name, const char* field_signature) {
- jclass clazz = env->GetObjectClass(obj);
- java_exception_check_and_throw(env, E_FILE_LINE);
- // J == long
- jfieldID res = env->GetFieldID(clazz, field_name, field_signature);
- java_exception_check_and_throw(env, E_FILE_LINE);
- return res;
-}
-jclass search_class(JNIEnv *env, const char *clazz_name)
-{
- jclass clazz = env->FindClass(clazz_name);
- java_exception_check_and_throw(env, E_FILE_LINE);
- if (!clazz)
- {
- throw direct_bt::InternalError(std::string("no class found: ")+clazz_name, E_FILE_LINE);
- }
- return clazz;
-}
-
-jclass search_class(JNIEnv *env, jobject obj)
-{
- jclass clazz = env->GetObjectClass(obj);
- java_exception_check_and_throw(env, E_FILE_LINE);
- if (!clazz)
- {
- throw direct_bt::InternalError("no class found", E_FILE_LINE);
- }
- return clazz;
-}
-
-jmethodID search_method(JNIEnv *env, jclass clazz, const char *method_name,
- const char *prototype, bool is_static)
-{
- jmethodID method;
- if (is_static)
- {
- method = env->GetStaticMethodID(clazz, method_name, prototype);
- }
- else
- {
- method = env->GetMethodID(clazz, method_name, prototype);
- }
- java_exception_check_and_throw(env, E_FILE_LINE);
-
- if (!method)
- {
- throw direct_bt::InternalError(std::string("no method found: ")+method_name, E_FILE_LINE);
- }
-
- return method;
-}
-
-jfieldID search_field(JNIEnv *env, jclass clazz, const char *field_name,
- const char *type, bool is_static)
-{
- jfieldID field;
- if (is_static)
- {
- field = env->GetStaticFieldID(clazz, field_name, type);
- }
- else
- {
- field = env->GetFieldID(clazz, field_name, type);
- }
- java_exception_check_and_throw(env, E_FILE_LINE);
-
- if (!field)
- {
- direct_bt::InternalError(std::string("no field found: ")+field_name, E_FILE_LINE);
- }
-
- return field;
-}
-
-bool from_jboolean_to_bool(jboolean val)
-{
- bool result;
-
- if (val == JNI_TRUE)
- {
- result = true;
- }
- else
- {
- if (val == JNI_FALSE)
- {
- result = false;
- }
- else
- {
- throw direct_bt::InternalError("the jboolean value is not true/false", E_FILE_LINE);
- }
- }
-
- return result;
-}
-
-std::string from_jstring_to_string(JNIEnv *env, jstring str)
-{
- jboolean is_copy = JNI_TRUE;
- if (!str) {
- throw std::invalid_argument("String should not be null");
- }
- const char *str_chars = (char *)env->GetStringUTFChars(str, &is_copy);
- if (!str_chars) {
- throw std::bad_alloc();
- }
- const std::string string_to_write = std::string(str_chars);
-
- env->ReleaseStringUTFChars(str, str_chars);
-
- return string_to_write;
-}
-
-jstring from_string_to_jstring(JNIEnv *env, const std::string & str)
-{
- return env->NewStringUTF(str.c_str());
-}
-
jobject get_bluetooth_type(JNIEnv *env, const char *field_name)
{
- jclass b_type_enum = search_class(env, JAVA_MAIN_PACKAGE "/BluetoothType");
+ jclass b_type_enum = jau::search_class(env, JAVA_MAIN_PACKAGE "/BluetoothType");
- jfieldID b_type_field = search_field(env, b_type_enum, field_name, "L" JAVA_MAIN_PACKAGE "/BluetoothType;", true);
+ jfieldID b_type_field = jau::search_field(env, b_type_enum, field_name, "L" JAVA_MAIN_PACKAGE "/BluetoothType;", true);
jobject result = env->GetStaticObjectField(b_type_enum, b_type_field);
env->DeleteLocalRef(b_type_enum);
return result;
}
-jobject get_new_arraylist(JNIEnv *env, unsigned int size, jmethodID *add)
-{
- jclass arraylist_class = search_class(env, "java/util/ArrayList");
- jmethodID arraylist_ctor = search_method(env, arraylist_class, "<init>", "(I)V", false);
-
- jobject result = env->NewObject(arraylist_class, arraylist_ctor, size);
- if (!result)
- {
- throw direct_bt::InternalError("Cannot create instance of class ArrayList", E_FILE_LINE);
- }
-
- *add = search_method(env, arraylist_class, "add", "(Ljava/lang/Object;)Z", false);
-
- env->DeleteLocalRef(arraylist_class);
- return result;
-}
-
-static void print_native_caught_exception_fwd2java(const std::exception &e, const char* file, int line) {
- fprintf(stderr, "Native exception caught @ %s:%d and forward to Java: %s\n", file, line, e.what()); fflush(stderr);
-}
-static void print_native_caught_exception_fwd2java(const std::string &msg, const char* file, int line) {
- fprintf(stderr, "Native exception caught @ %s:%d and forward to Java: %s\n", file, line, msg.c_str()); fflush(stderr);
-}
-static void print_native_caught_exception_fwd2java(const char * cmsg, const char* file, int line) {
- fprintf(stderr, "Native exception caught @ %s:%d and forward to Java: %s\n", file, line, cmsg); fflush(stderr);
-}
-
-void raise_java_exception(JNIEnv *env, const std::exception &e, const char* file, int line) {
- print_native_caught_exception_fwd2java(e, file, line);
- env->ThrowNew(env->FindClass("java/lang/Error"), e.what());
-}
-void raise_java_exception(JNIEnv *env, const std::runtime_error &e, const char* file, int line) {
- print_native_caught_exception_fwd2java(e, file, line);
- env->ThrowNew(env->FindClass("java/lang/RuntimeException"), e.what());
-}
-void raise_java_exception(JNIEnv *env, const direct_bt::RuntimeException &e, const char* file, int line) {
- print_native_caught_exception_fwd2java(e, file, line);
- env->ThrowNew(env->FindClass("java/lang/RuntimeException"), e.what());
-}
-void raise_java_exception(JNIEnv *env, const direct_bt::InternalError &e, const char* file, int line) {
- print_native_caught_exception_fwd2java(e, file, line);
- env->ThrowNew(env->FindClass("java/lang/InternalError"), e.what());
-}
-void raise_java_exception(JNIEnv *env, const direct_bt::NullPointerException &e, const char* file, int line) {
- print_native_caught_exception_fwd2java(e, file, line);
- env->ThrowNew(env->FindClass("java/lang/NullPointerException"), e.what());
-}
-void raise_java_exception(JNIEnv *env, const direct_bt::IllegalArgumentException &e, const char* file, int line) {
- print_native_caught_exception_fwd2java(e, file, line);
- env->ThrowNew(env->FindClass("java/lang/IllegalArgumentException"), e.what());
-}
-void raise_java_exception(JNIEnv *env, const std::invalid_argument &e, const char* file, int line) {
- print_native_caught_exception_fwd2java(e, file, line);
- env->ThrowNew(env->FindClass("java/lang/IllegalArgumentException"), e.what());
-}
-void raise_java_exception(JNIEnv *env, const direct_bt::IllegalStateException &e, const char* file, int line) {
- print_native_caught_exception_fwd2java(e, file, line);
- env->ThrowNew(env->FindClass("java/lang/IllegalStateException"), e.what());
-}
-void raise_java_exception(JNIEnv *env, const direct_bt::UnsupportedOperationException &e, const char* file, int line) {
- print_native_caught_exception_fwd2java(e, file, line);
- env->ThrowNew(env->FindClass("java/lang/UnsupportedOperationException"), e.what());
-}
-void raise_java_exception(JNIEnv *env, const direct_bt::IndexOutOfBoundsException &e, const char* file, int line) {
- print_native_caught_exception_fwd2java(e, file, line);
- env->ThrowNew(env->FindClass("java/lang/IndexOutOfBoundsException"), e.what());
-}
-void raise_java_exception(JNIEnv *env, const std::bad_alloc &e, const char* file, int line) {
- print_native_caught_exception_fwd2java(e, file, line);
- env->ThrowNew(env->FindClass("java/lang/OutOfMemoryError"), e.what());
-}
-void raise_java_exception(JNIEnv *env, const direct_bt::OutOfMemoryError &e, const char* file, int line) {
- print_native_caught_exception_fwd2java(e, file, line);
- env->ThrowNew(env->FindClass("java/lang/OutOfMemoryError"), e.what());
-}
void raise_java_exception(JNIEnv *env, const direct_bt::BluetoothException &e, const char* file, int line) {
- print_native_caught_exception_fwd2java(e, file, line);
+ jau::print_native_caught_exception_fwd2java(e, file, line);
env->ThrowNew(env->FindClass("org/tinyb/BluetoothException"), e.what());
}
void raise_java_exception(JNIEnv *env, const tinyb::BluetoothException &e, const char* file, int line) {
- print_native_caught_exception_fwd2java(e, file, line);
+ jau::print_native_caught_exception_fwd2java(e, file, line);
env->ThrowNew(env->FindClass("org/tinyb/BluetoothException"), e.what());
}
@@ -257,83 +63,41 @@ void rethrow_and_raise_java_exception_impl(JNIEnv *env, const char* file, int li
// std::rethrow_exception(e);
throw; // re-throw current exception
} catch (const std::bad_alloc &e) {
- raise_java_exception(env, e, file, line);
- } catch (const direct_bt::OutOfMemoryError &e) {
- raise_java_exception(env, e, file, line);
- } catch (const direct_bt::InternalError &e) {
- raise_java_exception(env, e, file, line);
- } catch (const direct_bt::NullPointerException &e) {
- raise_java_exception(env, e, file, line);
- } catch (const direct_bt::IllegalArgumentException &e) {
- raise_java_exception(env, e, file, line);
- } catch (const direct_bt::IllegalStateException &e) {
- raise_java_exception(env, e, file, line);
- } catch (const direct_bt::UnsupportedOperationException &e) {
- raise_java_exception(env, e, file, line);
- } catch (const direct_bt::IndexOutOfBoundsException &e) {
- raise_java_exception(env, e, file, line);
+ jau::raise_java_exception(env, e, file, line);
+ } catch (const jau::OutOfMemoryError &e) {
+ jau::raise_java_exception(env, e, file, line);
+ } catch (const jau::InternalError &e) {
+ jau::raise_java_exception(env, e, file, line);
+ } catch (const jau::NullPointerException &e) {
+ jau::raise_java_exception(env, e, file, line);
+ } catch (const jau::IllegalArgumentException &e) {
+ jau::raise_java_exception(env, e, file, line);
+ } catch (const jau::IllegalStateException &e) {
+ jau::raise_java_exception(env, e, file, line);
+ } catch (const jau::UnsupportedOperationException &e) {
+ jau::raise_java_exception(env, e, file, line);
+ } catch (const jau::IndexOutOfBoundsException &e) {
+ jau::raise_java_exception(env, e, file, line);
} catch (const direct_bt::BluetoothException &e) {
raise_java_exception(env, e, file, line);
} catch (const tinyb::BluetoothException &e) {
raise_java_exception(env, e, file, line);
- } catch (const direct_bt::RuntimeException &e) {
- raise_java_exception(env, e, file, line);
+ } catch (const jau::RuntimeException &e) {
+ jau::raise_java_exception(env, e, file, line);
} catch (const std::runtime_error &e) {
- raise_java_exception(env, e, file, line);
+ jau::raise_java_exception(env, e, file, line);
} catch (const std::invalid_argument &e) {
- raise_java_exception(env, e, file, line);
+ jau::raise_java_exception(env, e, file, line);
} catch (const std::exception &e) {
- raise_java_exception(env, e, file, line);
+ jau::raise_java_exception(env, e, file, line);
} catch (const std::string &msg) {
- print_native_caught_exception_fwd2java(msg, file, line);
+ jau::print_native_caught_exception_fwd2java(msg, file, line);
env->ThrowNew(env->FindClass("java/lang/Error"), msg.c_str());
} catch (const char *msg) {
- print_native_caught_exception_fwd2java(msg, file, line);
+ jau::print_native_caught_exception_fwd2java(msg, file, line);
env->ThrowNew(env->FindClass("java/lang/Error"), msg);
} catch (...) {
- print_native_caught_exception_fwd2java(_unknown_exception_type_msg, file, line);
+ jau::print_native_caught_exception_fwd2java(_unknown_exception_type_msg, file, line);
env->ThrowNew(env->FindClass("java/lang/Error"), _unknown_exception_type_msg.c_str());
}
}
-
-bool java_exception_check(JNIEnv *env, const char* file, int line)
-{
- jthrowable e = env->ExceptionOccurred();
- if( nullptr != e ) {
-#if 1
- // ExceptionDescribe prints an exception and a backtrace of the stack to a system error-reporting channel, such as stderr.
- // The pending exception is cleared as a side-effect of calling this function. This is a convenience routine provided for debugging.
- env->ExceptionDescribe();
-#endif
- env->ExceptionClear(); // just be sure, to have same side-effects
-
- jclass eClazz = search_class(env, e);
- jmethodID toString = search_method(env, eClazz, "toString", "()Ljava/lang/String;", false);
- jstring jmsg = (jstring) env->CallObjectMethod(e, toString);
- std::string msg = from_jstring_to_string(env, jmsg);
- fprintf(stderr, "Java exception occurred @ %s:%d and forward to Java: %s\n", file, line, msg.c_str()); fflush(stderr);
-
- env->Throw(e); // re-throw the java exception - java side!
- return true;
- }
- return false;
-}
-
-void java_exception_check_and_throw(JNIEnv *env, const char* file, int line)
-{
- jthrowable e = env->ExceptionOccurred();
- if( nullptr != e ) {
- // ExceptionDescribe prints an exception and a backtrace of the stack to a system error-reporting channel, such as stderr.
- // The pending exception is cleared as a side-effect of calling this function. This is a convenience routine provided for debugging.
- env->ExceptionDescribe();
- env->ExceptionClear(); // just be sure, to have same side-effects
-
- jclass eClazz = search_class(env, e);
- jmethodID toString = search_method(env, eClazz, "toString", "()Ljava/lang/String;", false);
- jstring jmsg = (jstring) env->CallObjectMethod(e, toString);
- std::string msg = from_jstring_to_string(env, jmsg);
- fprintf(stderr, "Java exception occurred @ %s:%d and forward to Native: %s\n", file, line, msg.c_str()); fflush(stderr);
-
- throw direct_bt::RuntimeException("Java exception occurred @ %s : %d: "+msg, file, line);
- }
-}
diff --git a/java/jni/helper_base.hpp b/java/jni/helper_base.hpp
index fcc97c8c..7af77e2f 100644
--- a/java/jni/helper_base.hpp
+++ b/java/jni/helper_base.hpp
@@ -34,232 +34,13 @@
#include <functional>
#include <jni.h>
-#include "direct_bt/BasicTypes.hpp"
-#include "tinyb/BluetoothException.hpp"
+#include <jau/jni/helper_jni.hpp>
-/**
- * Return true if a java exception occurred, otherwise false.
- * <p>
- * In case of an exception, the information might be logged to stderr.
- * </p>
- * <p>
- * In case of an exception, user shall release resourced in their JNI code
- * and leave immediately.
- * </p>
- */
-bool java_exception_check(JNIEnv *env, const char* file, int line);
-
-/**
- * Throws a C++ exception if a java exception occurred, otherwise do nothing.
- * <p>
- * In case of an exception, the information might be logged to stderr.
- * </p>
- * <p>
- * In case of an exception and hence thrown C++ exception,
- * might want to catch all and handle it via {@link #rethrow_and_raise_java_exception(JNIEnv*)}.
- * </p>
- */
-void java_exception_check_and_throw(JNIEnv *env, const char* file, int line);
-
-
-jfieldID getField(JNIEnv *env, jobject obj, const char* field_name, const char* field_signature);
-inline jfieldID getInstanceField(JNIEnv *env, jobject obj) {
- return getField(env, obj, "nativeInstance", "J");
-}
+#include "direct_bt/BTTypes.hpp"
+#include "tinyb/BluetoothException.hpp"
-jclass search_class(JNIEnv *env, const char *clazz_name);
-jclass search_class(JNIEnv *env, jobject obj);
-jmethodID search_method(JNIEnv *env, jclass clazz, const char *method_name,
- const char *prototype, bool is_static);
-jfieldID search_field(JNIEnv *env, jclass clazz, const char *field_name,
- const char *type, bool is_static);
-bool from_jboolean_to_bool(jboolean val);
-std::string from_jstring_to_string(JNIEnv *env, jstring str);
-jstring from_string_to_jstring(JNIEnv *env, const std::string & str);
jobject get_bluetooth_type(JNIEnv *env, const char *field_name);
-jobject get_new_arraylist(JNIEnv *env, unsigned int size, jmethodID *add);
-
-template <typename T>
-T *castInstance(jlong instance)
-{
- T *t = reinterpret_cast<T *>(instance);
- if (t == nullptr) {
- throw std::runtime_error("Trying to cast null object");
- }
- return t;
-}
-
-template <typename T>
-T *getObjectRef(JNIEnv *env, jobject obj, const char* field_name)
-{
- jlong jobj = env->GetLongField(obj, getField(env, obj, field_name, "J"));
- java_exception_check_and_throw(env, E_FILE_LINE);
- return reinterpret_cast<T *>(jobj);
-}
-
-template <typename T>
-void setObjectRef(JNIEnv *env, jobject obj, T *t, const char* field_name)
-{
- jlong jobj = reinterpret_cast<jlong>(t);
- env->SetLongField(obj, getField(env, obj, field_name, "J"), jobj);
- java_exception_check_and_throw(env, E_FILE_LINE);
-}
-
-template <typename T>
-T *getInstance(JNIEnv *env, jobject obj)
-{
- jlong instance = env->GetLongField(obj, getInstanceField(env, obj));
- T *t = reinterpret_cast<T *>(instance);
- if (t == nullptr) {
- throw std::runtime_error("Trying to acquire null object");
- }
- return t;
-}
-
-template <typename T>
-T *getInstanceUnchecked(JNIEnv *env, jobject obj)
-{
- jlong instance = env->GetLongField(obj, getInstanceField(env, obj));
- return reinterpret_cast<T *>(instance);
-}
-
-template <typename T>
-void setInstance(JNIEnv *env, jobject obj, T *t)
-{
- if (t == nullptr) {
- throw std::runtime_error("Trying to create null object");
- }
- jlong instance = reinterpret_cast<jlong>(t);
- env->SetLongField(obj, getInstanceField(env, obj), instance);
-}
-
-inline void clearInstance(JNIEnv *env, jobject obj) {
- env->SetLongField(obj, getInstanceField(env, obj), 0);
-}
-
-template <typename T>
-jobject generic_clone(JNIEnv *env, jobject obj)
-{
- T *obj_generic = getInstance<T>(env, obj);
- T *copy_generic = obj_generic->clone();
-
- jclass generic_class = search_class(env, *copy_generic);
- jmethodID generic_ctor = search_method(env, generic_class, "<init>", "(J)V", false);
-
- jobject result = env->NewObject(generic_class, generic_ctor, (jlong)copy_generic);
- if (!result)
- {
- throw std::runtime_error("cannot create instance of class");
- }
-
- return result;
-}
-
-template <typename T>
-jobject convert_vector_uniqueptr_to_jarraylist(JNIEnv *env, std::vector<std::unique_ptr<T>>& array,
- const char *ctor_prototype)
-{
- unsigned int array_size = array.size();
-
- jmethodID arraylist_add;
- jobject result = get_new_arraylist(env, array_size, &arraylist_add);
-
- if (array_size == 0)
- {
- return result;
- }
-
- jclass clazz = search_class(env, T::java_class().c_str());
- jmethodID clazz_ctor = search_method(env, clazz, "<init>", ctor_prototype, false);
-
- for (unsigned int i = 0; i < array_size; ++i)
- {
- T *elem = array[i].release();
- jobject object = env->NewObject(clazz, clazz_ctor, (jlong)elem);
- if (!object)
- {
- throw direct_bt::InternalError("cannot create instance of class", E_FILE_LINE);
- }
- env->CallBooleanMethod(result, arraylist_add, object);
- java_exception_check_and_throw(env, E_FILE_LINE);
- }
- return result;
-}
-
-template <typename T>
-jobject convert_vector_uniqueptr_to_jarraylist(JNIEnv *env, std::vector<std::unique_ptr<T>>& array,
- const char *ctor_prototype, std::function<jobject(JNIEnv*, jclass, jmethodID, T*)> ctor)
-{
- unsigned int array_size = array.size();
-
- jmethodID arraylist_add;
- jobject result = get_new_arraylist(env, array_size, &arraylist_add);
-
- if (array_size == 0)
- {
- return result;
- }
-
- jclass clazz = search_class(env, T::java_class().c_str());
- jmethodID clazz_ctor = search_method(env, clazz, "<init>", ctor_prototype, false);
-
- for (unsigned int i = 0; i < array_size; ++i)
- {
- T *elem = array[i].release();
- jobject object = ctor(env, clazz, clazz_ctor, elem);
- if (!object)
- {
- throw std::runtime_error("cannot create instance of class\n");
- }
- env->CallBooleanMethod(result, arraylist_add, object);
- java_exception_check_and_throw(env, E_FILE_LINE);
- }
- return result;
-}
-
-template <typename T>
-jobject convert_vector_sharedptr_to_jarraylist(JNIEnv *env, std::vector<std::shared_ptr<T>>& array,
- const char *ctor_prototype, std::function<jobject(JNIEnv*, jclass, jmethodID, T*)> ctor)
-{
- unsigned int array_size = array.size();
-
- jmethodID arraylist_add;
- jobject result = get_new_arraylist(env, array_size, &arraylist_add);
-
- if (array_size == 0)
- {
- return result;
- }
-
- jclass clazz = search_class(env, T::java_class().c_str());
- jmethodID clazz_ctor = search_method(env, clazz, "<init>", ctor_prototype, false);
-
- for (unsigned int i = 0; i < array_size; ++i)
- {
- T *elem = array[i].get();
- jobject object = ctor(env, clazz, clazz_ctor, elem);
- if (!object)
- {
- throw std::runtime_error("cannot create instance of class\n");
- }
- env->CallBooleanMethod(result, arraylist_add, object);
- java_exception_check_and_throw(env, E_FILE_LINE);
- }
- return result;
-}
-void raise_java_exception(JNIEnv *env, const std::exception &e, const char* file, int line);
-void raise_java_exception(JNIEnv *env, const std::runtime_error &e, const char* file, int line);
-void raise_java_exception(JNIEnv *env, const direct_bt::RuntimeException &e, const char* file, int line);
-void raise_java_exception(JNIEnv *env, const direct_bt::InternalError &e, const char* file, int line);
-void raise_java_exception(JNIEnv *env, const direct_bt::NullPointerException &e, const char* file, int line);
-void raise_java_exception(JNIEnv *env, const direct_bt::IllegalArgumentException &e, const char* file, int line);
-void raise_java_exception(JNIEnv *env, const std::invalid_argument &e, const char* file, int line);
-void raise_java_exception(JNIEnv *env, const direct_bt::IllegalStateException &e, const char* file, int line);
-void raise_java_exception(JNIEnv *env, const direct_bt::UnsupportedOperationException &e, const char* file, int line);
-void raise_java_exception(JNIEnv *env, const direct_bt::IndexOutOfBoundsException &e, const char* file, int line);
-void raise_java_exception(JNIEnv *env, const std::bad_alloc &e, const char* file, int line);
-void raise_java_exception(JNIEnv *env, const direct_bt::OutOfMemoryError &e, const char* file, int line);
void raise_java_exception(JNIEnv *env, const direct_bt::BluetoothException &e, const char* file, int line);
void raise_java_exception(JNIEnv *env, const tinyb::BluetoothException &e, const char* file, int line);
diff --git a/java/jni/tinyb/CMakeLists.txt b/java/jni/tinyb/CMakeLists.txt
index 6d0b0a07..d163386e 100644
--- a/java/jni/tinyb/CMakeLists.txt
+++ b/java/jni/tinyb/CMakeLists.txt
@@ -6,6 +6,7 @@ if (JNI_FOUND)
endif (JNI_FOUND)
set (tinyb_LIB_INCLUDE_DIRS
+ ${PROJECT_SOURCE_DIR}/jaucpp/include
${PROJECT_SOURCE_DIR}/api
${PROJECT_SOURCE_DIR}/api/direct_bt
${PROJECT_SOURCE_DIR}/api/tinyb
@@ -20,8 +21,9 @@ include_directories(
)
set (tinyb_JNI_SRCS
- ${PROJECT_SOURCE_DIR}/src/direct_bt/BasicTypes.cpp
- ${PROJECT_SOURCE_DIR}/java/jni/JNIMem.cxx
+ ${PROJECT_SOURCE_DIR}/jaucpp/java/jni/jni_mem.cxx
+ ${PROJECT_SOURCE_DIR}/jaucpp/java/jni/helper_jni.cxx
+ ${PROJECT_SOURCE_DIR}/jaucpp/src/basic_types.cpp
${PROJECT_SOURCE_DIR}/java/jni/helper_base.cxx
${PROJECT_SOURCE_DIR}/java/jni/BluetoothFactory.cxx
${PROJECT_SOURCE_DIR}/java/jni/BluetoothUtils.cxx
diff --git a/java/jni/tinyb/DBusAdapter.cxx b/java/jni/tinyb/DBusAdapter.cxx
index fdc40101..f221d33a 100644
--- a/java/jni/tinyb/DBusAdapter.cxx
+++ b/java/jni/tinyb/DBusAdapter.cxx
@@ -28,10 +28,10 @@
#include "tinyb_dbus_DBusAdapter.h"
-#include "JNIMem.hpp"
#include "helper_tinyb.hpp"
using namespace tinyb;
+using namespace jau;
jobject Java_tinyb_dbus_DBusAdapter_getBluetoothType(JNIEnv *env, jobject obj)
{
diff --git a/java/jni/tinyb/DBusDevice.cxx b/java/jni/tinyb/DBusDevice.cxx
index c77b2261..61d23a2b 100644
--- a/java/jni/tinyb/DBusDevice.cxx
+++ b/java/jni/tinyb/DBusDevice.cxx
@@ -29,10 +29,10 @@
#include "tinyb_dbus_DBusDevice.h"
-#include "JNIMem.hpp"
#include "helper_tinyb.hpp"
using namespace tinyb;
+using namespace jau;
jobject Java_tinyb_dbus_DBusDevice_getBluetoothType(JNIEnv *env, jobject obj)
{
diff --git a/java/jni/tinyb/DBusGattCharacteristic.cxx b/java/jni/tinyb/DBusGattCharacteristic.cxx
index 781ec299..9c95110b 100644
--- a/java/jni/tinyb/DBusGattCharacteristic.cxx
+++ b/java/jni/tinyb/DBusGattCharacteristic.cxx
@@ -29,10 +29,10 @@
#include "tinyb_dbus_DBusGattCharacteristic.h"
-#include "JNIMem.hpp"
#include "helper_tinyb.hpp"
using namespace tinyb;
+using namespace jau;
jobject Java_tinyb_dbus_DBusGattCharacteristic_getBluetoothType(JNIEnv *env, jobject obj)
{
diff --git a/java/jni/tinyb/DBusGattDescriptor.cxx b/java/jni/tinyb/DBusGattDescriptor.cxx
index d6af712f..a1cc7606 100644
--- a/java/jni/tinyb/DBusGattDescriptor.cxx
+++ b/java/jni/tinyb/DBusGattDescriptor.cxx
@@ -28,10 +28,10 @@
#include "tinyb_dbus_DBusGattDescriptor.h"
-#include "JNIMem.hpp"
#include "helper_tinyb.hpp"
using namespace tinyb;
+using namespace jau;
jobject Java_tinyb_dbus_DBusGattDescriptor_getBluetoothType(JNIEnv *env, jobject obj)
{
diff --git a/java/jni/tinyb/DBusGattService.cxx b/java/jni/tinyb/DBusGattService.cxx
index a9101516..60978a42 100644
--- a/java/jni/tinyb/DBusGattService.cxx
+++ b/java/jni/tinyb/DBusGattService.cxx
@@ -32,6 +32,7 @@
#include "helper_tinyb.hpp"
using namespace tinyb;
+using namespace jau;
jobject Java_tinyb_dbus_DBusGattService_getBluetoothType(JNIEnv *env, jobject obj)
{
diff --git a/java/jni/tinyb/DBusManager.cxx b/java/jni/tinyb/DBusManager.cxx
index d8ee789e..8985495a 100644
--- a/java/jni/tinyb/DBusManager.cxx
+++ b/java/jni/tinyb/DBusManager.cxx
@@ -32,6 +32,7 @@
#include "helper_tinyb.hpp"
using namespace tinyb;
+using namespace jau;
jobject Java_tinyb_dbus_DBusManager_getBluetoothType(JNIEnv *env, jobject obj)
{
diff --git a/java/jni/tinyb/DBusObject.cxx b/java/jni/tinyb/DBusObject.cxx
index 8e3b93a2..1ab749f6 100644
--- a/java/jni/tinyb/DBusObject.cxx
+++ b/java/jni/tinyb/DBusObject.cxx
@@ -29,6 +29,7 @@
#include "helper_tinyb.hpp"
using namespace tinyb;
+using namespace jau;
jobject Java_tinyb_dbus_DBusObject_getBluetoothType(JNIEnv *env, jobject obj)
{
diff --git a/java/jni/tinyb/helper_tinyb.cxx b/java/jni/tinyb/helper_tinyb.cxx
index 68ee0408..f170b6fa 100644
--- a/java/jni/tinyb/helper_tinyb.cxx
+++ b/java/jni/tinyb/helper_tinyb.cxx
@@ -37,7 +37,7 @@ using namespace tinyb;
jclass tinyb::search_class(JNIEnv *env, BluetoothObject &object)
{
- return search_class(env, object.get_java_class().c_str());
+ return jau::search_class(env, object.get_java_class().c_str());
}
BluetoothType tinyb::from_int_to_btype(int type)
diff --git a/java/jni/tinyb/helper_tinyb.hpp b/java/jni/tinyb/helper_tinyb.hpp
index d91051c4..cdfad29c 100644
--- a/java/jni/tinyb/helper_tinyb.hpp
+++ b/java/jni/tinyb/helper_tinyb.hpp
@@ -29,6 +29,7 @@
#pragma once
#include "helper_base.hpp"
+
#include "tinyb/BluetoothObject.hpp"
#include "tinyb/BluetoothException.hpp"
diff --git a/src/direct_bt/ATTPDUTypes.cpp b/src/direct_bt/ATTPDUTypes.cpp
index 9567ac91..675089dd 100644
--- a/src/direct_bt/ATTPDUTypes.cpp
+++ b/src/direct_bt/ATTPDUTypes.cpp
@@ -23,7 +23,6 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#include <dbt_debug.hpp>
#include <cstring>
#include <string>
#include <memory>
@@ -33,6 +32,8 @@
#include <algorithm>
+#include <jau/debug.hpp>
+
#include "ATTPDUTypes.hpp"
diff --git a/src/direct_bt/BTTypes.cpp b/src/direct_bt/BTTypes.cpp
index 5ed893f0..f4a200be 100644
--- a/src/direct_bt/BTTypes.cpp
+++ b/src/direct_bt/BTTypes.cpp
@@ -23,7 +23,6 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#include <dbt_debug.hpp>
#include <cstring>
#include <string>
#include <memory>
@@ -33,6 +32,8 @@
#include <algorithm>
+#include <jau/debug.hpp>
+
#include "BTTypes.hpp"
using namespace direct_bt;
@@ -153,7 +154,7 @@ std::string EUI48::toString() const {
const int count = snprintf(&str[0], str.capacity(), "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
b[5], b[4], b[3], b[2], b[1], b[0]);
if( length != count ) {
- throw direct_bt::InternalError("EUI48 string not of length "+std::to_string(length)+" but "+std::to_string(count), E_FILE_LINE);
+ throw jau::InternalError("EUI48 string not of length "+std::to_string(length)+" but "+std::to_string(count), E_FILE_LINE);
}
return str;
}
@@ -163,13 +164,13 @@ EUI48::EUI48(const std::string str) {
std::string msg("EUI48 string not of length 17 but ");
msg.append(std::to_string(str.length()));
msg.append(": "+str);
- throw direct_bt::IllegalArgumentException(msg, E_FILE_LINE);
+ throw jau::IllegalArgumentException(msg, E_FILE_LINE);
}
if ( sscanf(str.c_str(), "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
&b[5], &b[4], &b[3], &b[2], &b[1], &b[0]) != 6 )
{
std::string msg("EUI48 string not in format '00:00:00:00:00:00' but "+str);
- throw direct_bt::IllegalArgumentException(msg, E_FILE_LINE);
+ throw jau::IllegalArgumentException(msg, E_FILE_LINE);
}
// sscanf provided host data type, in which we store the values,
@@ -253,7 +254,7 @@ ScanType direct_bt::getScanType(BTMode btMode) {
case BTMode::LE:
return ScanType::LE;
default:
- throw IllegalArgumentException("Unsupported BTMode "+getBTModeString(btMode), E_FILE_LINE);
+ throw jau::IllegalArgumentException("Unsupported BTMode "+getBTModeString(btMode), E_FILE_LINE);
}
}
@@ -468,12 +469,12 @@ void EInfoReport::setAddressType(BDAddressType at) noexcept {
}
void EInfoReport::setName(const uint8_t *buffer, int buffer_len) noexcept {
- name = get_string(buffer, buffer_len, 30);
+ name = jau::get_string(buffer, buffer_len, 30);
set(EIRDataType::NAME);
}
void EInfoReport::setShortName(const uint8_t *buffer, int buffer_len) noexcept {
- name_short = get_string(buffer, buffer_len, 30);
+ name_short = jau::get_string(buffer, buffer_len, 30);
set(EIRDataType::NAME_SHORT);
}
@@ -515,14 +516,14 @@ std::string EInfoReport::toString(const bool includeServices) const noexcept {
"], name['"+name+"'/'"+name_short+"'], "+eirDataMaskToString()+
", evt-type "+getAD_PDU_TypeString(evt_type)+", rssi "+std::to_string(rssi)+
", tx-power "+std::to_string(tx_power)+
- ", dev-class "+uint32HexString(device_class, true)+
- ", appearance "+uint16HexString(static_cast<uint16_t>(appearance))+" ("+getAppearanceCatString(appearance)+
+ ", dev-class "+jau::uint32HexString(device_class, true)+
+ ", appearance "+jau::uint16HexString(static_cast<uint16_t>(appearance))+" ("+getAppearanceCatString(appearance)+
"), hash["+hash.toString()+
"], randomizer["+randomizer.toString()+
- "], device-id[source "+uint16HexString(did_source, true)+
- ", vendor "+uint16HexString(did_vendor, true)+
- ", product "+uint16HexString(did_product, true)+
- ", version "+uint16HexString(did_version, true)+
+ "], device-id[source "+jau::uint16HexString(did_source, true)+
+ ", vendor "+jau::uint16HexString(did_vendor, true)+
+ ", product "+jau::uint16HexString(did_product, true)+
+ ", version "+jau::uint16HexString(did_version, true)+
"], "+msdstr+"]");
if( includeServices && services.size() > 0 ) {
@@ -661,7 +662,7 @@ int EInfoReport::read_data(uint8_t const * data, uint8_t const data_length) noex
case GAP_T::RND_TRGT_ADDR:
case GAP_T::GAP_APPEARANCE:
if( 2 <= elem_len ) {
- setAppearance(static_cast<AppearanceCat>( get_uint16(elem_data, 0, true /* littleEndian */) ));
+ setAppearance(static_cast<AppearanceCat>( jau::get_uint16(elem_data, 0, true /* littleEndian */) ));
}
break;
case GAP_T::SSP_HASH_C192:
@@ -680,7 +681,7 @@ int EInfoReport::read_data(uint8_t const * data, uint8_t const data_length) noex
break;
case GAP_T::MANUFACTURE_SPECIFIC:
if( 2 <= elem_len ) {
- const uint16_t company = get_uint16(elem_data, 0, true /* littleEndian */);
+ const uint16_t company = jau::get_uint16(elem_data, 0, true /* littleEndian */);
const int data_size = elem_len-2;
setManufactureSpecificData(company, data_size > 0 ? elem_data+2 : nullptr, data_size);
}
@@ -709,7 +710,7 @@ std::vector<std::shared_ptr<EInfoReport>> EInfoReport::read_ad_reports(uint8_t c
const int segment_count = 6;
int read_segments = 0;
int i;
- const uint64_t timestamp = getCurrentMilliseconds();
+ const uint64_t timestamp = jau::getCurrentMilliseconds();
for(i = 0; i < num_reports && i_octets < limes; i++) {
ad_reports.push_back(std::shared_ptr<EInfoReport>(new EInfoReport()));
diff --git a/src/direct_bt/CMakeLists.txt b/src/direct_bt/CMakeLists.txt
index 5f8d644e..c6e333de 100644
--- a/src/direct_bt/CMakeLists.txt
+++ b/src/direct_bt/CMakeLists.txt
@@ -1,4 +1,5 @@
set (direct_bt_LIB_INCLUDE_DIRS
+ ${PROJECT_SOURCE_DIR}/jaucpp/include
${PROJECT_SOURCE_DIR}/api
${PROJECT_SOURCE_DIR}/api/direct_bt
${PROJECT_SOURCE_DIR}/include
@@ -10,10 +11,10 @@ include_directories(
)
set (direct_bt_LIB_SRCS
- ${PROJECT_SOURCE_DIR}/src/direct_bt/dfa_utf8_decode.cpp
- ${PROJECT_SOURCE_DIR}/src/direct_bt/DBTEnv.cpp
- ${PROJECT_SOURCE_DIR}/src/direct_bt/dbt_debug.cpp
- ${PROJECT_SOURCE_DIR}/src/direct_bt/BasicTypes.cpp
+ ${PROJECT_SOURCE_DIR}/jaucpp/src/dfa_utf8_decode.cpp
+ ${PROJECT_SOURCE_DIR}/jaucpp/src/environment.cpp
+ ${PROJECT_SOURCE_DIR}/jaucpp/src/debug.cpp
+ ${PROJECT_SOURCE_DIR}/jaucpp/src/basic_types.cpp
${PROJECT_SOURCE_DIR}/src/ieee11073/DataTypes.cpp
${PROJECT_SOURCE_DIR}/src/direct_bt/UUID.cpp
${PROJECT_SOURCE_DIR}/src/direct_bt/BTTypes.cpp
diff --git a/src/direct_bt/DBTAdapter.cpp b/src/direct_bt/DBTAdapter.cpp
index f0c304ec..c56603b0 100644
--- a/src/direct_bt/DBTAdapter.cpp
+++ b/src/direct_bt/DBTAdapter.cpp
@@ -32,9 +32,9 @@
#include <algorithm>
-#include <dbt_debug.hpp>
+#include <jau/debug.hpp>
-#include "BasicAlgos.hpp"
+#include <jau/basic_algos.hpp>
#include "BTIoctl.hpp"
#include "HCIIoctl.hpp"
@@ -197,7 +197,7 @@ bool DBTAdapter::validateDevInfo() noexcept {
}
DBTAdapter::DBTAdapter() noexcept
-: debug_event(DBTEnv::getBooleanProperty("direct_bt.debug.adapter.event", false)),
+: debug_event(jau::environment::getBooleanProperty("direct_bt.debug.adapter.event", false)),
mgmt( DBTManager::get(BTMode::NONE /* use env default */) ),
dev_id( mgmt.getDefaultAdapterIdx() ),
hci( dev_id )
@@ -206,7 +206,7 @@ DBTAdapter::DBTAdapter() noexcept
}
DBTAdapter::DBTAdapter(EUI48 &mac) noexcept
-: debug_event(DBTEnv::getBooleanProperty("direct_bt.debug.adapter.event", false)),
+: debug_event(jau::environment::getBooleanProperty("direct_bt.debug.adapter.event", false)),
mgmt( DBTManager::get(BTMode::NONE /* use env default */) ),
dev_id( mgmt.findAdapterInfoIdx(mac) ),
hci( dev_id )
@@ -215,7 +215,7 @@ DBTAdapter::DBTAdapter(EUI48 &mac) noexcept
}
DBTAdapter::DBTAdapter(const int _dev_id) noexcept
-: debug_event(DBTEnv::getBooleanProperty("direct_bt.debug.adapter.event", false)),
+: debug_event(jau::environment::getBooleanProperty("direct_bt.debug.adapter.event", false)),
mgmt( DBTManager::get(BTMode::NONE /* use env default */) ),
dev_id( 0 <= _dev_id ? _dev_id : mgmt.getDefaultAdapterIdx() ),
hci( dev_id )
@@ -363,7 +363,7 @@ bool DBTAdapter::removeDeviceFromWhitelist(const EUI48 &address, const BDAddress
bool DBTAdapter::addStatusListener(std::shared_ptr<AdapterStatusListener> l) {
checkValidAdapter();
if( nullptr == l ) {
- throw IllegalArgumentException("DBTAdapterStatusListener ref is null", E_FILE_LINE);
+ throw jau::IllegalArgumentException("DBTAdapterStatusListener ref is null", E_FILE_LINE);
}
{
const std::lock_guard<std::recursive_mutex> lock(mtx_statusListenerList); // RAII-style acquire and relinquish via destructor
@@ -376,7 +376,7 @@ bool DBTAdapter::addStatusListener(std::shared_ptr<AdapterStatusListener> l) {
}
statusListenerList.push_back(l);
}
- sendAdapterSettingsChanged(*l, AdapterSetting::NONE, adapterInfo->getCurrentSettingMask(), getCurrentMilliseconds());
+ sendAdapterSettingsChanged(*l, AdapterSetting::NONE, adapterInfo->getCurrentSettingMask(), jau::getCurrentMilliseconds());
return true;
}
@@ -384,7 +384,7 @@ bool DBTAdapter::addStatusListener(std::shared_ptr<AdapterStatusListener> l) {
bool DBTAdapter::removeStatusListener(std::shared_ptr<AdapterStatusListener> l) {
checkValidAdapter();
if( nullptr == l ) {
- throw IllegalArgumentException("DBTAdapterStatusListener ref is null", E_FILE_LINE);
+ throw jau::IllegalArgumentException("DBTAdapterStatusListener ref is null", E_FILE_LINE);
}
const std::lock_guard<std::recursive_mutex> lock(mtx_statusListenerList); // RAII-style acquire and relinquish via destructor
for(auto it = statusListenerList.begin(); it != statusListenerList.end(); ) {
@@ -401,7 +401,7 @@ bool DBTAdapter::removeStatusListener(std::shared_ptr<AdapterStatusListener> l)
bool DBTAdapter::removeStatusListener(const AdapterStatusListener * l) {
checkValidAdapter();
if( nullptr == l ) {
- throw IllegalArgumentException("DBTAdapterStatusListener ref is null", E_FILE_LINE);
+ throw jau::IllegalArgumentException("DBTAdapterStatusListener ref is null", E_FILE_LINE);
}
const std::lock_guard<std::recursive_mutex> lock(mtx_statusListenerList); // RAII-style acquire and relinquish via destructor
for(auto it = statusListenerList.begin(); it != statusListenerList.end(); ) {
@@ -715,7 +715,7 @@ bool DBTAdapter::mgmtEvDeviceDiscoveringMgmt(std::shared_ptr<MgmtEvent> e) noexc
checkDiscoveryState();
int i=0;
- for_each_idx_mtx(mtx_statusListenerList, statusListenerList, [&](std::shared_ptr<AdapterStatusListener> &l) {
+ jau::for_each_idx_mtx(mtx_statusListenerList, statusListenerList, [&](std::shared_ptr<AdapterStatusListener> &l) {
try {
l->discoveringChanged(*this, enabled, keepDiscoveringAlive, event.getTimestamp());
} catch (std::exception &e) {
@@ -763,7 +763,7 @@ void DBTAdapter::sendAdapterSettingsChanged(const AdapterSetting old_settings, c
getAdapterSettingMaskString(current_settings).c_str(),
getAdapterSettingMaskString(changes).c_str(), toString(false).c_str() );
int i=0;
- for_each_idx_mtx(mtx_statusListenerList, statusListenerList, [&](std::shared_ptr<AdapterStatusListener> &l) {
+ jau::for_each_idx_mtx(mtx_statusListenerList, statusListenerList, [&](std::shared_ptr<AdapterStatusListener> &l) {
try {
l->adapterSettingsChanged(*this, old_settings, current_settings, changes, timestampMS);
} catch (std::exception &e) {
@@ -815,7 +815,7 @@ bool DBTAdapter::mgmtEvLocalNameChangedMgmt(std::shared_ptr<MgmtEvent> e) noexce
void DBTAdapter::sendDeviceUpdated(std::string cause, std::shared_ptr<DBTDevice> device, uint64_t timestamp, EIRDataType updateMask) noexcept {
int i=0;
- for_each_idx_mtx(mtx_statusListenerList, statusListenerList, [&](std::shared_ptr<AdapterStatusListener> &l) {
+ jau::for_each_idx_mtx(mtx_statusListenerList, statusListenerList, [&](std::shared_ptr<AdapterStatusListener> &l) {
try {
if( l->matchDevice(*device) ) {
l->deviceUpdated(device, updateMask, timestamp);
@@ -873,13 +873,13 @@ bool DBTAdapter::mgmtEvDeviceConnectedHCI(std::shared_ptr<MgmtEvent> e) noexcept
if( 0 == new_connect ) {
WARN_PRINT("DBTAdapter::EventHCI:DeviceConnected(dev_id %d, already connected, updated %s): %s, handle %s -> %s,\n %s,\n -> %s",
dev_id, getEIRDataMaskString(updateMask).c_str(), event.toString().c_str(),
- uint16HexString(device->getConnectionHandle()).c_str(), uint16HexString(event.getHCIHandle()).c_str(),
+ jau::uint16HexString(device->getConnectionHandle()).c_str(), jau::uint16HexString(event.getHCIHandle()).c_str(),
ad_report.toString().c_str(),
device->toString().c_str());
} else {
COND_PRINT(debug_event, "DBTAdapter::EventHCI:DeviceConnected(dev_id %d, new_connect %d, updated %s): %s, handle %s -> %s,\n %s,\n -> %s",
dev_id, new_connect, getEIRDataMaskString(updateMask).c_str(), event.toString().c_str(),
- uint16HexString(device->getConnectionHandle()).c_str(), uint16HexString(event.getHCIHandle()).c_str(),
+ jau::uint16HexString(device->getConnectionHandle()).c_str(), jau::uint16HexString(event.getHCIHandle()).c_str(),
ad_report.toString().c_str(),
device->toString().c_str());
}
@@ -887,7 +887,7 @@ bool DBTAdapter::mgmtEvDeviceConnectedHCI(std::shared_ptr<MgmtEvent> e) noexcept
device->notifyConnected(event.getHCIHandle());
int i=0;
- for_each_idx_mtx(mtx_statusListenerList, statusListenerList, [&](std::shared_ptr<AdapterStatusListener> &l) {
+ jau::for_each_idx_mtx(mtx_statusListenerList, statusListenerList, [&](std::shared_ptr<AdapterStatusListener> &l) {
try {
if( l->matchDevice(*device) ) {
if( EIRDataType::NONE != updateMask ) {
@@ -915,14 +915,14 @@ bool DBTAdapter::mgmtEvConnectFailedHCI(std::shared_ptr<MgmtEvent> e) noexcept {
if( nullptr != device ) {
const uint16_t handle = device->getConnectionHandle();
COND_PRINT(debug_event, "DBTAdapter::EventHCI:ConnectFailed(dev_id %d): %s, handle %s -> zero,\n -> %s",
- dev_id, event.toString().c_str(), uint16HexString(handle).c_str(),
+ dev_id, event.toString().c_str(), jau::uint16HexString(handle).c_str(),
device->toString().c_str());
device->notifyDisconnected();
removeConnectedDevice(*device);
int i=0;
- for_each_idx_mtx(mtx_statusListenerList, statusListenerList, [&](std::shared_ptr<AdapterStatusListener> &l) {
+ jau::for_each_idx_mtx(mtx_statusListenerList, statusListenerList, [&](std::shared_ptr<AdapterStatusListener> &l) {
try {
if( l->matchDevice(*device) ) {
l->deviceDisconnected(device, event.getHCIStatus(), handle, event.getTimestamp());
@@ -953,14 +953,14 @@ bool DBTAdapter::mgmtEvDeviceDisconnectedHCI(std::shared_ptr<MgmtEvent> e) noexc
return true;
}
COND_PRINT(debug_event, "DBTAdapter::EventHCI:DeviceDisconnected(dev_id %d): %s, handle %s -> zero,\n -> %s",
- dev_id, event.toString().c_str(), uint16HexString(event.getHCIHandle()).c_str(),
+ dev_id, event.toString().c_str(), jau::uint16HexString(event.getHCIHandle()).c_str(),
device->toString().c_str());
device->notifyDisconnected();
removeConnectedDevice(*device);
int i=0;
- for_each_idx_mtx(mtx_statusListenerList, statusListenerList, [&](std::shared_ptr<AdapterStatusListener> &l) {
+ jau::for_each_idx_mtx(mtx_statusListenerList, statusListenerList, [&](std::shared_ptr<AdapterStatusListener> &l) {
try {
if( l->matchDevice(*device) ) {
l->deviceDisconnected(device, event.getHCIReason(), event.getHCIHandle(), event.getTimestamp());
@@ -1033,7 +1033,7 @@ bool DBTAdapter::mgmtEvDeviceFoundHCI(std::shared_ptr<MgmtEvent> e) noexcept {
dev->getAddressString().c_str(), eir->toString().c_str());
int i=0;
- for_each_idx_mtx(mtx_statusListenerList, statusListenerList, [&](std::shared_ptr<AdapterStatusListener> &l) {
+ jau::for_each_idx_mtx(mtx_statusListenerList, statusListenerList, [&](std::shared_ptr<AdapterStatusListener> &l) {
try {
if( l->matchDevice(*dev) ) {
l->deviceFound(dev, eir->getTimestamp());
@@ -1061,7 +1061,7 @@ bool DBTAdapter::mgmtEvDeviceFoundHCI(std::shared_ptr<MgmtEvent> e) noexcept {
dev->getAddressString().c_str(), eir->toString().c_str());
int i=0;
- for_each_idx_mtx(mtx_statusListenerList, statusListenerList, [&](std::shared_ptr<AdapterStatusListener> &l) {
+ jau::for_each_idx_mtx(mtx_statusListenerList, statusListenerList, [&](std::shared_ptr<AdapterStatusListener> &l) {
try {
if( l->matchDevice(*dev) ) {
l->deviceFound(dev, eir->getTimestamp());
diff --git a/src/direct_bt/DBTDevice.cpp b/src/direct_bt/DBTDevice.cpp
index 4fc38a54..59a7b83d 100644
--- a/src/direct_bt/DBTDevice.cpp
+++ b/src/direct_bt/DBTDevice.cpp
@@ -33,7 +33,7 @@
#include <algorithm>
// #define VERBOSE_ON 1
-#include <dbt_debug.hpp>
+#include <jau/debug.hpp>
#include "HCIComm.hpp"
@@ -52,21 +52,21 @@ DBTDevice::DBTDevice(DBTAdapter & a, EInfoReport const & r)
isConnected = false;
allowDisconnect = false;
if( !r.isSet(EIRDataType::BDADDR) ) {
- throw IllegalArgumentException("Address not set: "+r.toString(), E_FILE_LINE);
+ throw jau::IllegalArgumentException("Address not set: "+r.toString(), E_FILE_LINE);
}
if( !r.isSet(EIRDataType::BDADDR_TYPE) ) {
- throw IllegalArgumentException("AddressType not set: "+r.toString(), E_FILE_LINE);
+ throw jau::IllegalArgumentException("AddressType not set: "+r.toString(), E_FILE_LINE);
}
update(r);
if( BDAddressType::BDADDR_LE_RANDOM == addressType ) {
if( BLERandomAddressType::UNDEFINED == leRandomAddressType ) {
- throw IllegalArgumentException("BDADDR_LE_RANDOM: Invalid BLERandomAddressType "+
+ throw jau::IllegalArgumentException("BDADDR_LE_RANDOM: Invalid BLERandomAddressType "+
getBLERandomAddressTypeString(leRandomAddressType)+": "+toString(), E_FILE_LINE);
}
} else {
if( BLERandomAddressType::UNDEFINED != leRandomAddressType ) {
- throw IllegalArgumentException("Not BDADDR_LE_RANDOM: Invalid given native BLERandomAddressType "+
+ throw jau::IllegalArgumentException("Not BDADDR_LE_RANDOM: Invalid given native BLERandomAddressType "+
getBLERandomAddressTypeString(leRandomAddressType)+": "+toString(), E_FILE_LINE);
}
}
@@ -131,7 +131,7 @@ std::vector<std::shared_ptr<uuid_t>> DBTDevice::getAdvertisedServices() const no
std::string DBTDevice::toString(bool includeDiscoveredServices) const noexcept {
const std::lock_guard<std::recursive_mutex> lock(const_cast<DBTDevice*>(this)->mtx_data); // RAII-style acquire and relinquish via destructor
- const uint64_t t0 = getCurrentMilliseconds();
+ const uint64_t t0 = jau::getCurrentMilliseconds();
std::string leaddrtype;
if( BLERandomAddressType::UNDEFINED != leRandomAddressType ) {
leaddrtype = ", random "+getBLERandomAddressTypeString(leRandomAddressType);
@@ -139,9 +139,9 @@ std::string DBTDevice::toString(bool includeDiscoveredServices) const noexcept {
std::string msdstr = nullptr != advMSD ? advMSD->toString() : "MSD[null]";
std::string out("Device[address["+getAddressString()+", "+getBDAddressTypeString(getAddressType())+leaddrtype+"], name['"+name+
"'], age[total "+std::to_string(t0-ts_creation)+", ldisc "+std::to_string(t0-ts_last_discovery)+", lup "+std::to_string(t0-ts_last_update)+
- "]ms, connected["+std::to_string(allowDisconnect)+"/"+std::to_string(isConnected)+", "+uint16HexString(hciConnHandle)+"], rssi "+std::to_string(getRSSI())+
+ "]ms, connected["+std::to_string(allowDisconnect)+"/"+std::to_string(isConnected)+", "+jau::uint16HexString(hciConnHandle)+"], rssi "+std::to_string(getRSSI())+
", tx-power "+std::to_string(tx_power)+
- ", appearance "+uint16HexString(static_cast<uint16_t>(appearance))+" ("+getAppearanceCatString(appearance)+
+ ", appearance "+jau::uint16HexString(static_cast<uint16_t>(appearance))+" ("+getAppearanceCatString(appearance)+
"), "+msdstr+", "+javaObjectToString()+"]");
if(includeDiscoveredServices && advServices.size() > 0 ) {
out.append("\n");
@@ -250,7 +250,7 @@ std::shared_ptr<ConnectionInfo> DBTDevice::getConnectionInfo() noexcept {
if( nullptr == sharedInstance ) {
ERR_PRINT("DBTDevice::getConnectionInfo: Device unknown to adapter and not tracked: %s", toString().c_str());
} else {
- adapter.sendDeviceUpdated("getConnectionInfo", sharedInstance, getCurrentMilliseconds(), updateMask);
+ adapter.sendDeviceUpdated("getConnectionInfo", sharedInstance, jau::getCurrentMilliseconds(), updateMask);
}
}
}
@@ -383,7 +383,7 @@ HCIStatusCode DBTDevice::connectDefault()
void DBTDevice::notifyConnected(const uint16_t handle) noexcept {
// coming from connected callback, update state and spawn-off connectGATT in background if appropriate (LE)
DBG_PRINT("DBTDevice::notifyConnected: handle %s -> %s, %s",
- uint16HexString(hciConnHandle).c_str(), uint16HexString(handle).c_str(), toString().c_str());
+ jau::uint16HexString(hciConnHandle).c_str(), jau::uint16HexString(handle).c_str(), toString().c_str());
allowDisconnect = true;
isConnected = true;
hciConnHandle = handle;
@@ -396,7 +396,7 @@ void DBTDevice::notifyConnected(const uint16_t handle) noexcept {
void DBTDevice::notifyDisconnected() noexcept {
// coming from disconnect callback, ensure cleaning up!
DBG_PRINT("DBTDevice::notifyDisconnected: handle %s -> zero, %s",
- uint16HexString(hciConnHandle).c_str(), toString().c_str());
+ jau::uint16HexString(hciConnHandle).c_str(), toString().c_str());
allowDisconnect = false;
isConnected = false;
hciConnHandle = 0;
@@ -423,7 +423,7 @@ HCIStatusCode DBTDevice::disconnect(const HCIStatusCode reason) noexcept {
DBG_PRINT("DBTDevice::disconnect: Not connected: isConnected %d/%d, reason 0x%X (%s), gattHandler %d, hciConnHandle %s",
allowDisconnect.load(), isConnected.load(),
static_cast<uint8_t>(reason), getHCIStatusCodeString(reason).c_str(),
- (nullptr != gattHandler), uint16HexString(hciConnHandle).c_str());
+ (nullptr != gattHandler), jau::uint16HexString(hciConnHandle).c_str());
return HCIStatusCode::CONNECTION_TERMINATED_BY_LOCAL_HOST;
}
if( !isConnected ) { // should not happen
@@ -441,7 +441,7 @@ HCIStatusCode DBTDevice::disconnect(const HCIStatusCode reason) noexcept {
WORDY_PRINT("DBTDevice::disconnect: Start: isConnected %d/%d, reason 0x%X (%s), gattHandler %d, hciConnHandle %s",
allowDisconnect.load(), isConnected.load(),
static_cast<uint8_t>(reason), getHCIStatusCodeString(reason).c_str(),
- (nullptr != gattHandler), uint16HexString(hciConnHandle).c_str());
+ (nullptr != gattHandler), jau::uint16HexString(hciConnHandle).c_str());
HCIHandler &hci = adapter.getHCI();
HCIStatusCode res = HCIStatusCode::SUCCESS;
@@ -559,7 +559,7 @@ std::vector<std::shared_ptr<GATTService>> DBTDevice::getGATTServices() noexcept
// discovery success, retrieve and parse GenericAccess
gattGenericAccess = gh->getGenericAccess(gattServices);
if( nullptr != gattGenericAccess ) {
- const uint64_t ts = getCurrentMilliseconds();
+ const uint64_t ts = jau::getCurrentMilliseconds();
EIRDataType updateMask = update(*gattGenericAccess, ts);
DBG_PRINT("DBTDevice::getGATTServices: updated %s:\n %s\n -> %s",
getEIRDataMaskString(updateMask).c_str(), gattGenericAccess->toString().c_str(), toString().c_str());
@@ -593,7 +593,7 @@ std::shared_ptr<GATTService> DBTDevice::findGATTService(std::shared_ptr<uuid_t>
bool DBTDevice::pingGATT() noexcept {
std::shared_ptr<GATTHandler> gh = getGATTHandler();
if( nullptr == gh || !gh->isConnected() ) {
- INFO_PRINT("DBTDevice::pingGATT: GATTHandler not connected -> disconnected on %s", toString().c_str());
+ jau::INFO_PRINT("DBTDevice::pingGATT: GATTHandler not connected -> disconnected on %s", toString().c_str());
disconnect(HCIStatusCode::REMOTE_USER_TERMINATED_CONNECTION);
return false;
}
@@ -612,7 +612,7 @@ std::shared_ptr<GattGenericAccessSvc> DBTDevice::getGATTGenericAccess() {
bool DBTDevice::addCharacteristicListener(std::shared_ptr<GATTCharacteristicListener> l) {
std::shared_ptr<GATTHandler> gatt = getGATTHandler();
if( nullptr == gatt ) {
- throw IllegalStateException("Device's GATTHandle not connected: "+
+ throw jau::IllegalStateException("Device's GATTHandle not connected: "+
toString(), E_FILE_LINE);
}
return gatt->addCharacteristicListener(l);
diff --git a/src/direct_bt/DBTManager.cpp b/src/direct_bt/DBTManager.cpp
index e0aaaa43..e0ab67d6 100644
--- a/src/direct_bt/DBTManager.cpp
+++ b/src/direct_bt/DBTManager.cpp
@@ -35,7 +35,7 @@
// #define PERF_PRINT_ON 1
// PERF3_PRINT_ON for close
// #define PERF3_PRINT_ON 1
-#include <dbt_debug.hpp>
+#include <jau/debug.hpp>
#include "BTIoctl.hpp"
@@ -56,21 +56,21 @@ using namespace direct_bt;
BTMode MgmtEnv::getEnvBTMode() {
// Environment variable is 'direct_bt.mgmt.btmode' or 'org.tinyb.btmode'
// Default is BTMode::LE, if non of the above environment variable is set.
- std::string val = DBTEnv::getProperty("direct_bt.mgmt.btmode");
+ std::string val = jau::environment::getProperty("direct_bt.mgmt.btmode");
if( val.empty() ) {
- val = DBTEnv::getProperty("org.tinyb.btmode");
+ val = jau::environment::getProperty("org.tinyb.btmode");
}
const BTMode res = direct_bt::getBTMode(val);
return BTMode::NONE != res ? res : BTMode::LE; // fallback to default LE
}
MgmtEnv::MgmtEnv() noexcept
-: DEBUG_GLOBAL( DBTEnv::get().DEBUG ),
- exploding( DBTEnv::getExplodingProperties("direct_bt.mgmt") ),
- MGMT_READER_THREAD_POLL_TIMEOUT( DBTEnv::getInt32Property("direct_bt.mgmt.reader.timeout", 10000, 1500 /* min */, INT32_MAX /* max */) ),
- MGMT_COMMAND_REPLY_TIMEOUT( DBTEnv::getInt32Property("direct_bt.mgmt.cmd.timeout", 3000, 1500 /* min */, INT32_MAX /* max */) ),
- MGMT_EVT_RING_CAPACITY( DBTEnv::getInt32Property("direct_bt.mgmt.ringsize", 64, 64 /* min */, 1024 /* max */) ),
- DEBUG_EVENT( DBTEnv::getBooleanProperty("direct_bt.debug.mgmt.event", false) ),
+: DEBUG_GLOBAL( jau::environment::get().DEBUG ),
+ exploding( jau::environment::getExplodingProperties("direct_bt.mgmt") ),
+ MGMT_READER_THREAD_POLL_TIMEOUT( jau::environment::getInt32Property("direct_bt.mgmt.reader.timeout", 10000, 1500 /* min */, INT32_MAX /* max */) ),
+ MGMT_COMMAND_REPLY_TIMEOUT( jau::environment::getInt32Property("direct_bt.mgmt.cmd.timeout", 3000, 1500 /* min */, INT32_MAX /* max */) ),
+ MGMT_EVT_RING_CAPACITY( jau::environment::getInt32Property("direct_bt.mgmt.ringsize", 64, 64 /* min */, 1024 /* max */) ),
+ DEBUG_EVENT( jau::environment::getBooleanProperty("direct_bt.debug.mgmt.event", false) ),
DEFAULT_BTMODE( getEnvBTMode() ),
MGMT_READ_PACKET_MAX_RETRY( MGMT_EVT_RING_CAPACITY )
{
@@ -358,7 +358,7 @@ DBTManager::DBTManager(const BTMode _defaultBTMode) noexcept
}
const uint8_t *data = res->getData();
const uint8_t version = data[0];
- const uint16_t revision = get_uint16(data, 1, true /* littleEndian */);
+ const uint16_t revision = jau::get_uint16(data, 1, true /* littleEndian */);
WORDY_PRINT("Bluetooth version %d.%d", version, revision);
if( version < 1 ) {
ERR_PRINT("Bluetooth version >= 1.0 required");
@@ -374,8 +374,8 @@ DBTManager::DBTManager(const BTMode _defaultBTMode) noexcept
}
if( MgmtEvent::Opcode::CMD_COMPLETE == res->getOpcode() && res->getDataSize() >= 4) {
const uint8_t *data = res->getData();
- const uint16_t num_commands = get_uint16(data, 0, true /* littleEndian */);
- const uint16_t num_events = get_uint16(data, 2, true /* littleEndian */);
+ const uint16_t num_commands = jau::get_uint16(data, 0, true /* littleEndian */);
+ const uint16_t num_events = jau::get_uint16(data, 2, true /* littleEndian */);
WORDY_PRINT("Bluetooth %d commands, %d events", num_commands, num_events);
#ifdef VERBOSE_ON
const int expDataSize = 4 + num_commands * 2 + num_events * 2;
@@ -406,7 +406,7 @@ next1:
goto fail;
}
const uint8_t *data = res->getData();
- const uint16_t num_adapter = get_uint16(data, 0, true /* littleEndian */);
+ const uint16_t num_adapter = jau::get_uint16(data, 0, true /* littleEndian */);
WORDY_PRINT("Bluetooth %d adapter", num_adapter);
const int expDataSize = 2 + num_adapter * 2;
@@ -416,7 +416,7 @@ next1:
}
adapterInfos.resize(num_adapter, nullptr);
for(int i=0; ok && i < num_adapter; i++) {
- const uint16_t dev_id = get_uint16(data, 2+i*2, true /* littleEndian */);
+ const uint16_t dev_id = jau::get_uint16(data, 2+i*2, true /* littleEndian */);
if( dev_id >= num_adapter ) {
ABORT("dev_id %d >= num_adapter %d", dev_id, num_adapter);
}
@@ -554,7 +554,7 @@ std::shared_ptr<AdapterInfo> DBTManager::findAdapterInfo(const EUI48 &mac) const
}
std::shared_ptr<AdapterInfo> DBTManager::getAdapterInfo(const int idx) const {
if( 0 > idx || idx >= static_cast<int>(adapterInfos.size()) ) {
- throw IndexOutOfBoundsException(idx, adapterInfos.size(), E_FILE_LINE);
+ throw jau::IndexOutOfBoundsException(idx, adapterInfos.size(), E_FILE_LINE);
}
std::shared_ptr<AdapterInfo> adapter = adapterInfos.at(idx);
return adapter;
@@ -853,84 +853,84 @@ void DBTManager::clearAllMgmtEventCallbacks() noexcept {
}
bool DBTManager::mgmtEvClassOfDeviceChangedCB(std::shared_ptr<MgmtEvent> e) noexcept {
- PLAIN_PRINT("DBTManager::EventCB:ClassOfDeviceChanged: %s", e->toString().c_str());
+ jau::PLAIN_PRINT("DBTManager::EventCB:ClassOfDeviceChanged: %s", e->toString().c_str());
(void)e;
return true;
}
bool DBTManager::mgmtEvDeviceDiscoveringCB(std::shared_ptr<MgmtEvent> e) noexcept {
- PLAIN_PRINT("DBTManager::EventCB:DeviceDiscovering: %s", e->toString().c_str());
+ jau::PLAIN_PRINT("DBTManager::EventCB:DeviceDiscovering: %s", e->toString().c_str());
const MgmtEvtDiscovering &event = *static_cast<const MgmtEvtDiscovering *>(e.get());
(void)event;
return true;
}
bool DBTManager::mgmtEvDeviceFoundCB(std::shared_ptr<MgmtEvent> e) noexcept {
- PLAIN_PRINT("DBTManager::EventCB:DeviceFound: %s", e->toString().c_str());
+ jau::PLAIN_PRINT("DBTManager::EventCB:DeviceFound: %s", e->toString().c_str());
const MgmtEvtDeviceFound &event = *static_cast<const MgmtEvtDeviceFound *>(e.get());
(void)event;
return true;
}
bool DBTManager::mgmtEvDeviceDisconnectedCB(std::shared_ptr<MgmtEvent> e) noexcept {
- PLAIN_PRINT("DBTManager::EventCB:DeviceDisconnected: %s", e->toString().c_str());
+ jau::PLAIN_PRINT("DBTManager::EventCB:DeviceDisconnected: %s", e->toString().c_str());
const MgmtEvtDeviceDisconnected &event = *static_cast<const MgmtEvtDeviceDisconnected *>(e.get());
(void)event;
return true;
}
bool DBTManager::mgmtEvDeviceConnectedCB(std::shared_ptr<MgmtEvent> e) noexcept {
- PLAIN_PRINT("DBTManager::EventCB:DeviceConnected: %s", e->toString().c_str());
+ jau::PLAIN_PRINT("DBTManager::EventCB:DeviceConnected: %s", e->toString().c_str());
const MgmtEvtDeviceConnected &event = *static_cast<const MgmtEvtDeviceConnected *>(e.get());
(void)event;
return true;
}
bool DBTManager::mgmtEvConnectFailedCB(std::shared_ptr<MgmtEvent> e) noexcept {
- PLAIN_PRINT("DBTManager::EventCB:ConnectFailed: %s", e->toString().c_str());
+ jau::PLAIN_PRINT("DBTManager::EventCB:ConnectFailed: %s", e->toString().c_str());
const MgmtEvtDeviceConnectFailed &event = *static_cast<const MgmtEvtDeviceConnectFailed *>(e.get());
(void)event;
return true;
}
bool DBTManager::mgmtEvDeviceBlockedCB(std::shared_ptr<MgmtEvent> e) noexcept {
- PLAIN_PRINT("DBTManager::EventCB:DeviceBlocked: %s", e->toString().c_str());
+ jau::PLAIN_PRINT("DBTManager::EventCB:DeviceBlocked: %s", e->toString().c_str());
const MgmtEvtDeviceBlocked &event = *static_cast<const MgmtEvtDeviceBlocked *>(e.get());
(void)event;
return true;
}
bool DBTManager::mgmtEvDeviceUnblockedCB(std::shared_ptr<MgmtEvent> e) noexcept {
- PLAIN_PRINT("DBTManager::EventCB:DeviceUnblocked: %s", e->toString().c_str());
+ jau::PLAIN_PRINT("DBTManager::EventCB:DeviceUnblocked: %s", e->toString().c_str());
const MgmtEvtDeviceUnblocked &event = *static_cast<const MgmtEvtDeviceUnblocked *>(e.get());
(void)event;
return true;
}
bool DBTManager::mgmtEvDeviceUnpairedCB(std::shared_ptr<MgmtEvent> e) noexcept {
- PLAIN_PRINT("DBTManager::EventCB:DeviceUnpaired: %s", e->toString().c_str());
+ jau::PLAIN_PRINT("DBTManager::EventCB:DeviceUnpaired: %s", e->toString().c_str());
const MgmtEvtDeviceUnpaired &event = *static_cast<const MgmtEvtDeviceUnpaired *>(e.get());
(void)event;
return true;
}
bool DBTManager::mgmtEvNewConnectionParamCB(std::shared_ptr<MgmtEvent> e) noexcept {
- PLAIN_PRINT("DBTManager::EventCB:NewConnectionParam: %s", e->toString().c_str());
+ jau::PLAIN_PRINT("DBTManager::EventCB:NewConnectionParam: %s", e->toString().c_str());
const MgmtEvtNewConnectionParam &event = *static_cast<const MgmtEvtNewConnectionParam *>(e.get());
(void)event;
return true;
}
bool DBTManager::mgmtEvDeviceWhitelistAddedCB(std::shared_ptr<MgmtEvent> e) noexcept {
- PLAIN_PRINT("DBTManager::EventCB:DeviceWhitelistAdded: %s", e->toString().c_str());
+ jau::PLAIN_PRINT("DBTManager::EventCB:DeviceWhitelistAdded: %s", e->toString().c_str());
const MgmtEvtDeviceWhitelistAdded &event = *static_cast<const MgmtEvtDeviceWhitelistAdded *>(e.get());
(void)event;
return true;
}
bool DBTManager::mgmtEvDeviceWhilelistRemovedCB(std::shared_ptr<MgmtEvent> e) noexcept {
- PLAIN_PRINT("DBTManager::EventCB:DeviceWhitelistRemoved: %s", e->toString().c_str());
+ jau::PLAIN_PRINT("DBTManager::EventCB:DeviceWhitelistRemoved: %s", e->toString().c_str());
const MgmtEvtDeviceWhitelistRemoved &event = *static_cast<const MgmtEvtDeviceWhitelistRemoved *>(e.get());
(void)event;
return true;
}
bool DBTManager::mgmtEvPinCodeRequestCB(std::shared_ptr<MgmtEvent> e) noexcept {
- PLAIN_PRINT("DBTManager::EventCB:PinCodeRequest: %s", e->toString().c_str());
+ jau::PLAIN_PRINT("DBTManager::EventCB:PinCodeRequest: %s", e->toString().c_str());
const MgmtEvtPinCodeRequest &event = *static_cast<const MgmtEvtPinCodeRequest *>(e.get());
(void)event;
return true;
}
bool DBTManager::mgmtEvUserPasskeyRequestCB(std::shared_ptr<MgmtEvent> e) noexcept {
- PLAIN_PRINT("DBTManager::EventCB:UserPasskeyRequest: %s", e->toString().c_str());
+ jau::PLAIN_PRINT("DBTManager::EventCB:UserPasskeyRequest: %s", e->toString().c_str());
const MgmtEvtUserPasskeyRequest &event = *static_cast<const MgmtEvtUserPasskeyRequest *>(e.get());
(void)event;
return true;
diff --git a/src/direct_bt/DBTTypes.cpp b/src/direct_bt/DBTTypes.cpp
index ca3624cc..8a8d4558 100644
--- a/src/direct_bt/DBTTypes.cpp
+++ b/src/direct_bt/DBTTypes.cpp
@@ -34,7 +34,7 @@
// #define PERF_PRINT_ON 1
// #define VERBOSE_ON 1
-#include <dbt_debug.hpp>
+#include <jau/debug.hpp>
#include "DBTTypes.hpp"
diff --git a/src/direct_bt/GATTCharacteristic.cpp b/src/direct_bt/GATTCharacteristic.cpp
index 450f7caa..fc55be5b 100644
--- a/src/direct_bt/GATTCharacteristic.cpp
+++ b/src/direct_bt/GATTCharacteristic.cpp
@@ -32,14 +32,14 @@
#include <algorithm>
-// #define VERBOSE_ON 1
-#include <dbt_debug.hpp>
+#include <jau/debug.hpp>
#include "GATTCharacteristic.hpp"
#include "GATTHandler.hpp"
#include "DBTDevice.hpp"
using namespace direct_bt;
+using namespace jau;
#define CHAR_DECL_PROPS_ENUM(X) \
X(Broadcast,broadcast) \
diff --git a/src/direct_bt/GATTDescriptor.cpp b/src/direct_bt/GATTDescriptor.cpp
index b77b97f0..9e6e5135 100644
--- a/src/direct_bt/GATTDescriptor.cpp
+++ b/src/direct_bt/GATTDescriptor.cpp
@@ -23,7 +23,6 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#include <dbt_debug.hpp>
#include <cstring>
#include <string>
#include <memory>
@@ -33,11 +32,14 @@
#include <algorithm>
+#include <jau/debug.hpp>
+
#include "GATTDescriptor.hpp"
#include "GATTHandler.hpp"
#include "DBTDevice.hpp"
using namespace direct_bt;
+using namespace jau;
const uuid16_t GATTDescriptor::TYPE_EXT_PROP(Type::CHARACTERISTIC_EXTENDED_PROPERTIES);
const uuid16_t GATTDescriptor::TYPE_USER_DESC(Type::CHARACTERISTIC_USER_DESCRIPTION);
diff --git a/src/direct_bt/GATTHandler.cpp b/src/direct_bt/GATTHandler.cpp
index 71268f54..c99dd091 100644
--- a/src/direct_bt/GATTHandler.cpp
+++ b/src/direct_bt/GATTHandler.cpp
@@ -44,9 +44,9 @@ extern "C" {
// #define PERF2_PRINT_ON 1
// PERF3_PRINT_ON for disconnect
// #define PERF3_PRINT_ON 1
-#include <dbt_debug.hpp>
+#include <jau/debug.hpp>
-#include "BasicAlgos.hpp"
+#include <jau/basic_algos.hpp>
#include "L2CAPIoctl.hpp"
#include "GATTNumbers.hpp"
@@ -58,14 +58,15 @@ extern "C" {
#include "DBTDevice.hpp"
using namespace direct_bt;
+using namespace jau;
GATTEnv::GATTEnv() noexcept
-: exploding( DBTEnv::getExplodingProperties("direct_bt.gatt") ),
- GATT_READ_COMMAND_REPLY_TIMEOUT( DBTEnv::getInt32Property("direct_bt.gatt.cmd.read.timeout", 500, 250 /* min */, INT32_MAX /* max */) ),
- GATT_WRITE_COMMAND_REPLY_TIMEOUT( DBTEnv::getInt32Property("direct_bt.gatt.cmd.write.timeout", 500, 250 /* min */, INT32_MAX /* max */) ),
- GATT_INITIAL_COMMAND_REPLY_TIMEOUT( DBTEnv::getInt32Property("direct_bt.gatt.cmd.init.timeout", 2500, 2000 /* min */, INT32_MAX /* max */) ),
- ATTPDU_RING_CAPACITY( DBTEnv::getInt32Property("direct_bt.gatt.ringsize", 128, 64 /* min */, 1024 /* max */) ),
- DEBUG_DATA( DBTEnv::getBooleanProperty("direct_bt.debug.gatt.data", false) )
+: exploding( environment::getExplodingProperties("direct_bt.gatt") ),
+ GATT_READ_COMMAND_REPLY_TIMEOUT( environment::getInt32Property("direct_bt.gatt.cmd.read.timeout", 500, 250 /* min */, INT32_MAX /* max */) ),
+ GATT_WRITE_COMMAND_REPLY_TIMEOUT( environment::getInt32Property("direct_bt.gatt.cmd.write.timeout", 500, 250 /* min */, INT32_MAX /* max */) ),
+ GATT_INITIAL_COMMAND_REPLY_TIMEOUT( environment::getInt32Property("direct_bt.gatt.cmd.init.timeout", 2500, 2000 /* min */, INT32_MAX /* max */) ),
+ ATTPDU_RING_CAPACITY( environment::getInt32Property("direct_bt.gatt.ringsize", 128, 64 /* min */, 1024 /* max */) ),
+ DEBUG_DATA( environment::getBooleanProperty("direct_bt.debug.gatt.data", false) )
{
}
diff --git a/src/direct_bt/GATTNumbers.cpp b/src/direct_bt/GATTNumbers.cpp
index ca7e1ff4..17448320 100644
--- a/src/direct_bt/GATTNumbers.cpp
+++ b/src/direct_bt/GATTNumbers.cpp
@@ -23,7 +23,6 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#include <dbt_debug.hpp>
#include <cstring>
#include <string>
#include <memory>
@@ -33,8 +32,9 @@
#include <algorithm>
-#include "GATTNumbers.hpp"
+#include <jau/debug.hpp>
+#include "GATTNumbers.hpp"
using namespace direct_bt;
@@ -381,7 +381,7 @@ std::string GattPeriphalPreferredConnectionParameters::toString() const noexcept
std::string GattGenericAccessSvc::toString() const noexcept {
std::string pcp(nullptr != prefConnParam ? prefConnParam->toString() : "");
- return "'"+deviceName+"'[appearance "+uint16HexString(static_cast<uint16_t>(appearance))+" ("+getAppearanceCatString(appearance)+"), "+pcp+"]";
+ return "'"+deviceName+"'[appearance "+jau::uint16HexString(static_cast<uint16_t>(appearance))+" ("+getAppearanceCatString(appearance)+"), "+pcp+"]";
}
GattPnP_ID::GattPnP_ID(const TROOctets &source) noexcept
@@ -398,10 +398,10 @@ std::shared_ptr<GattPnP_ID> GattPnP_ID::get(const TROOctets &source) noexcept {
}
std::string GattPnP_ID::toString() const noexcept {
- return "vendor_id[source "+uint8HexString(vendor_id_source, true)+
- ", id "+uint16HexString(vendor_id, true)+
- "], product_id "+uint16HexString(product_id, true)+
- ", product_version "+uint16HexString(product_version, true);
+ return "vendor_id[source "+jau::uint8HexString(vendor_id_source, true)+
+ ", id "+jau::uint16HexString(vendor_id, true)+
+ "], product_id "+jau::uint16HexString(product_id, true)+
+ ", product_version "+jau::uint16HexString(product_version, true);
}
std::string GattDeviceInformationSvc::toString() const noexcept {
diff --git a/src/direct_bt/GATTService.cpp b/src/direct_bt/GATTService.cpp
index b4af9a4e..70d537c2 100644
--- a/src/direct_bt/GATTService.cpp
+++ b/src/direct_bt/GATTService.cpp
@@ -23,7 +23,6 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#include <dbt_debug.hpp>
#include <cstring>
#include <string>
#include <memory>
@@ -33,12 +32,15 @@
#include <algorithm>
+#include <jau/debug.hpp>
+
#include "DBTDevice.hpp"
#include "GATTHandler.hpp"
#include "GATTService.hpp"
#include "GATTNumbers.hpp"
using namespace direct_bt;
+using namespace jau;
std::shared_ptr<GATTHandler> GATTService::getGATTHandlerChecked() const {
std::shared_ptr<GATTHandler> ref = wbr_handler.lock();
diff --git a/src/direct_bt/HCIComm.cpp b/src/direct_bt/HCIComm.cpp
index 19dcfaaf..9810fa1a 100644
--- a/src/direct_bt/HCIComm.cpp
+++ b/src/direct_bt/HCIComm.cpp
@@ -34,7 +34,7 @@
#include <type_traits>
// #define PERF_PRINT_ON 1
-#include <dbt_debug.hpp>
+#include <jau/debug.hpp>
#include "HCIComm.hpp"
diff --git a/src/direct_bt/HCIHandler.cpp b/src/direct_bt/HCIHandler.cpp
index 31cbda45..e0b9590b 100644
--- a/src/direct_bt/HCIHandler.cpp
+++ b/src/direct_bt/HCIHandler.cpp
@@ -33,9 +33,10 @@
#include <algorithm>
// #define PERF_PRINT_ON 1
-#include <dbt_debug.hpp>
+#include <jau/debug.hpp>
-#include "DBTEnv.hpp"
+#include <jau/environment.hpp>
+#include <jau/basic_algos.hpp>
#include "BTIoctl.hpp"
@@ -43,7 +44,6 @@
#include "HCIComm.hpp"
#include "HCIHandler.hpp"
#include "DBTTypes.hpp"
-#include "BasicAlgos.hpp"
extern "C" {
#include <inttypes.h>
@@ -58,12 +58,12 @@ extern "C" {
using namespace direct_bt;
HCIEnv::HCIEnv() noexcept
-: exploding( DBTEnv::getExplodingProperties("direct_bt.hci") ),
- HCI_READER_THREAD_POLL_TIMEOUT( DBTEnv::getInt32Property("direct_bt.hci.reader.timeout", 10000, 1500 /* min */, INT32_MAX /* max */) ),
- HCI_COMMAND_STATUS_REPLY_TIMEOUT( DBTEnv::getInt32Property("direct_bt.hci.cmd.status.timeout", 3000, 1500 /* min */, INT32_MAX /* max */) ),
- HCI_COMMAND_COMPLETE_REPLY_TIMEOUT( DBTEnv::getInt32Property("direct_bt.hci.cmd.complete.timeout", 10000, 1500 /* min */, INT32_MAX /* max */) ),
- HCI_EVT_RING_CAPACITY( DBTEnv::getInt32Property("direct_bt.hci.ringsize", 64, 64 /* min */, 1024 /* max */) ),
- DEBUG_EVENT( DBTEnv::getBooleanProperty("direct_bt.debug.hci.event", false) ),
+: exploding( jau::environment::getExplodingProperties("direct_bt.hci") ),
+ HCI_READER_THREAD_POLL_TIMEOUT( jau::environment::getInt32Property("direct_bt.hci.reader.timeout", 10000, 1500 /* min */, INT32_MAX /* max */) ),
+ HCI_COMMAND_STATUS_REPLY_TIMEOUT( jau::environment::getInt32Property("direct_bt.hci.cmd.status.timeout", 3000, 1500 /* min */, INT32_MAX /* max */) ),
+ HCI_COMMAND_COMPLETE_REPLY_TIMEOUT( jau::environment::getInt32Property("direct_bt.hci.cmd.complete.timeout", 10000, 1500 /* min */, INT32_MAX /* max */) ),
+ HCI_EVT_RING_CAPACITY( jau::environment::getInt32Property("direct_bt.hci.ringsize", 64, 64 /* min */, 1024 /* max */) ),
+ DEBUG_EVENT( jau::environment::getBooleanProperty("direct_bt.debug.hci.event", false) ),
HCI_READ_PACKET_MAX_RETRY( HCI_EVT_RING_CAPACITY )
{
}
@@ -83,12 +83,12 @@ HCIConnectionRef HCIHandler::addOrUpdateHCIConnection(std::vector<HCIConnectionR
if ( conn->equals(address, addrType) ) {
// reuse same entry
WORDY_PRINT("HCIHandler::addTrackerConnection: address[%s, %s], handle %s: reuse entry %s",
- address.toString().c_str(), getBDAddressTypeString(addrType).c_str(), uint16HexString(handle).c_str(), conn->toString().c_str());
+ address.toString().c_str(), getBDAddressTypeString(addrType).c_str(), jau::uint16HexString(handle).c_str(), conn->toString().c_str());
// Overwrite tracked connection handle with given _valid_ handle only, i.e. non zero!
if( 0 != handle ) {
if( 0 != conn->getHandle() && handle != conn->getHandle() ) {
WARN_PRINT("HCIHandler::addTrackerConnection: address[%s, %s], handle %s: reusing entry %s, overwriting non-zero handle",
- address.toString().c_str(), getBDAddressTypeString(addrType).c_str(), uint16HexString(handle).c_str(), conn->toString().c_str());
+ address.toString().c_str(), getBDAddressTypeString(addrType).c_str(), jau::uint16HexString(handle).c_str(), conn->toString().c_str());
}
conn->setHandle( handle );
}
@@ -232,13 +232,13 @@ std::shared_ptr<MgmtEvent> HCIHandler::translate(std::shared_ptr<HCIEvent> ev) n
HCIConnectionRef conn = removeTrackerConnection(ev_cc->handle);
if( nullptr == conn ) {
WORDY_PRINT("HCIHandler::translate(reader): DISCONN_COMPLETE: Not tracked handle %s: %s",
- uint16HexString(ev_cc->handle).c_str(), ev->toString().c_str());
+ jau::uint16HexString(ev_cc->handle).c_str(), ev->toString().c_str());
return nullptr;
} else {
if( HCIStatusCode::SUCCESS != status ) {
// FIXME: Ever occuring? Still sending out essential disconnect event!
ERR_PRINT("HCIHandler::translate(reader): DISCONN_COMPLETE: !SUCCESS[%s, %s], %s: %s",
- uint8HexString(static_cast<uint8_t>(status)).c_str(), getHCIStatusCodeString(status).c_str(),
+ jau::uint8HexString(static_cast<uint8_t>(status)).c_str(), getHCIStatusCodeString(status).c_str(),
conn->toString().c_str(), ev->toString().c_str());
}
const HCIStatusCode hciRootReason = static_cast<HCIStatusCode>(ev_cc->reason);
@@ -279,7 +279,7 @@ void HCIHandler::hciReaderThreadImpl() noexcept {
std::shared_ptr<HCIEvent> event = HCIEvent::getSpecialized(rbuffer.get_ptr(), len);
if( nullptr == event ) {
// not an event ...
- ERR_PRINT("HCIHandler-IO RECV Drop (non-event) %s", bytesHexString(rbuffer.get_ptr(), 0, len, true /* lsbFirst*/).c_str());
+ ERR_PRINT("HCIHandler-IO RECV Drop (non-event) %s", jau::bytesHexString(rbuffer.get_ptr(), 0, len, true /* lsbFirst*/).c_str());
continue;
}
@@ -302,7 +302,7 @@ void HCIHandler::hciReaderThreadImpl() noexcept {
} else if( event->isMetaEvent(HCIMetaEventType::LE_ADVERTISING_REPORT) ) {
// issue callbacks for the translated AD events
std::vector<std::shared_ptr<EInfoReport>> eirlist = EInfoReport::read_ad_reports(event->getParam(), event->getParamSize());
- for_each_idx(eirlist, [&](std::shared_ptr<EInfoReport> & eir) {
+ jau::for_each_idx(eirlist, [&](std::shared_ptr<EInfoReport> & eir) {
// COND_PRINT(env.DEBUG_EVENT, "HCIHandler-IO RECV (AD EIR) %s", eir->toString().c_str());
sendMgmtEvent( std::shared_ptr<MgmtEvent>( new MgmtEvtDeviceFound(dev_id, eir) ) );
});
@@ -651,10 +651,10 @@ HCIStatusCode HCIHandler::getLocalVersion(HCILocalVersion &version) noexcept {
bzero(&version, sizeof(version));
} else {
version.hci_ver = ev_lv->hci_ver;
- version.hci_rev = le_to_cpu(ev_lv->hci_rev);
- version.manufacturer = le_to_cpu(ev_lv->manufacturer);
+ version.hci_rev = jau::le_to_cpu(ev_lv->hci_rev);
+ version.manufacturer = jau::le_to_cpu(ev_lv->manufacturer);
version.lmp_ver = ev_lv->lmp_ver;
- version.lmp_subver = le_to_cpu(ev_lv->lmp_subver);
+ version.lmp_subver = jau::le_to_cpu(ev_lv->lmp_subver);
}
return status;
}
@@ -674,8 +674,8 @@ HCIStatusCode HCIHandler::le_set_scan_param(const bool le_scan_active,
HCIStructCommand<hci_cp_le_set_scan_param> req0(HCIOpcode::LE_SET_SCAN_PARAM);
hci_cp_le_set_scan_param * cp = req0.getWStruct();
cp->type = le_scan_active ? LE_SCAN_ACTIVE : LE_SCAN_PASSIVE;
- cp->interval = cpu_to_le(le_scan_interval);
- cp->window = cpu_to_le(le_scan_window);
+ cp->interval = jau::cpu_to_le(le_scan_interval);
+ cp->window = jau::cpu_to_le(le_scan_window);
cp->own_address_type = static_cast<uint8_t>(own_mac_type);
cp->filter_policy = filter_policy;
@@ -732,18 +732,18 @@ HCIStatusCode HCIHandler::le_create_conn(const EUI48 &peer_bdaddr,
HCIStructCommand<hci_cp_le_create_conn> req0(HCIOpcode::LE_CREATE_CONN);
hci_cp_le_create_conn * cp = req0.getWStruct();
- cp->scan_interval = cpu_to_le(le_scan_interval);
- cp->scan_window = cpu_to_le(le_scan_window);
+ cp->scan_interval = jau::cpu_to_le(le_scan_interval);
+ cp->scan_window = jau::cpu_to_le(le_scan_window);
cp->filter_policy = initiator_filter;
cp->peer_addr_type = static_cast<uint8_t>(peer_mac_type);
cp->peer_addr = peer_bdaddr;
cp->own_address_type = static_cast<uint8_t>(own_mac_type);
- cp->conn_interval_min = cpu_to_le(conn_interval_min);
- cp->conn_interval_max = cpu_to_le(conn_interval_max);
- cp->conn_latency = cpu_to_le(conn_latency);
- cp->supervision_timeout = cpu_to_le(supervision_timeout);
- cp->min_ce_len = cpu_to_le(min_ce_length);
- cp->max_ce_len = cpu_to_le(max_ce_length);
+ cp->conn_interval_min = jau::cpu_to_le(conn_interval_min);
+ cp->conn_interval_max = jau::cpu_to_le(conn_interval_max);
+ cp->conn_latency = jau::cpu_to_le(conn_latency);
+ cp->supervision_timeout = jau::cpu_to_le(supervision_timeout);
+ cp->min_ce_len = jau::cpu_to_le(min_ce_length);
+ cp->max_ce_len = jau::cpu_to_le(max_ce_length);
BDAddressType bdAddrType = getBDAddressType(peer_mac_type);
@@ -784,10 +784,10 @@ HCIStatusCode HCIHandler::create_conn(const EUI48 &bdaddr,
HCIStructCommand<hci_cp_create_conn> req0(HCIOpcode::CREATE_CONN);
hci_cp_create_conn * cp = req0.getWStruct();
cp->bdaddr = bdaddr;
- cp->pkt_type = cpu_to_le((uint16_t)(pkt_type & (uint16_t)ACL_PTYPE_MASK)); /* TODO OK excluding SCO_PTYPE_MASK (HCI_HV1 | HCI_HV2 | HCI_HV3) ? */
+ cp->pkt_type = jau::cpu_to_le((uint16_t)(pkt_type & (uint16_t)ACL_PTYPE_MASK)); /* TODO OK excluding SCO_PTYPE_MASK (HCI_HV1 | HCI_HV2 | HCI_HV3) ? */
cp->pscan_rep_mode = 0x02; /* TODO magic? */
cp->pscan_mode = 0x00; /* TODO magic? */
- cp->clock_offset = cpu_to_le(clock_offset);
+ cp->clock_offset = jau::cpu_to_le(clock_offset);
cp->role_switch = role_switch;
HCIConnectionRef disconn = findDisconnect(bdaddr, BDAddressType::BDADDR_BREDR);
@@ -848,7 +848,7 @@ HCIStatusCode HCIHandler::disconnect(const uint16_t conn_handle, const EUI48 &pe
}
DBG_PRINT("HCIHandler::disconnect: address[%s, %s], handle %s, %s",
peer_bdaddr.toString().c_str(), getBDAddressTypeString(peer_mac_type).c_str(),
- uint16HexString(conn_handle).c_str(),
+ jau::uint16HexString(conn_handle).c_str(),
conn->toString().c_str());
HCIStatusCode status;
@@ -859,7 +859,7 @@ HCIStatusCode HCIHandler::disconnect(const uint16_t conn_handle, const EUI48 &pe
{
HCIStructCommand<hci_cp_disconnect> req0(HCIOpcode::DISCONNECT);
hci_cp_disconnect * cp = req0.getWStruct();
- cp->handle = cpu_to_le(conn_handle);
+ cp->handle = jau::cpu_to_le(conn_handle);
cp->reason = number(reason);
std::shared_ptr<HCIEvent> ev = processCommandStatus(req0, &status);
diff --git a/src/direct_bt/HCITypes.cpp b/src/direct_bt/HCITypes.cpp
index 960e3e3e..7bbd1b9f 100644
--- a/src/direct_bt/HCITypes.cpp
+++ b/src/direct_bt/HCITypes.cpp
@@ -32,8 +32,7 @@
#include <algorithm>
-// #define VERBOSE_ON 1
-#include <dbt_debug.hpp>
+#include <jau/ringbuffer.hpp>
#include "HCITypes.hpp"
@@ -274,11 +273,11 @@ std::string getHCIMetaEventTypeString(const HCIMetaEventType op) noexcept {
}
std::shared_ptr<HCIEvent> HCIEvent::getSpecialized(const uint8_t * buffer, int const buffer_size) noexcept {
- const HCIPacketType pc = static_cast<HCIPacketType>( get_uint8(buffer, 0) );
+ const HCIPacketType pc = static_cast<HCIPacketType>( jau::get_uint8(buffer, 0) );
if( HCIPacketType::EVENT != pc ) {
return nullptr;
}
- const HCIEventType ec = static_cast<HCIEventType>( get_uint8(buffer, 1) );
+ const HCIEventType ec = static_cast<HCIEventType>( jau::get_uint8(buffer, 1) );
HCIEvent *res;
switch( ec ) {
case HCIEventType::DISCONN_COMPLETE:
@@ -300,7 +299,7 @@ std::shared_ptr<HCIEvent> HCIEvent::getSpecialized(const uint8_t * buffer, int c
std::string HCILocalVersion::toString() noexcept {
return "LocalVersion[version "+std::to_string(hci_ver)+"."+std::to_string(hci_rev)+
- ", manuf "+uint16HexString(manufacturer)+", lmp "+std::to_string(lmp_ver)+"."+std::to_string(lmp_subver)+"]";
+ ", manuf "+jau::uint16HexString(manufacturer)+", lmp "+std::to_string(lmp_ver)+"."+std::to_string(lmp_subver)+"]";
}
} /* namespace direct_bt */
diff --git a/src/direct_bt/L2CAPComm.cpp b/src/direct_bt/L2CAPComm.cpp
index af81807a..a20d8911 100644
--- a/src/direct_bt/L2CAPComm.cpp
+++ b/src/direct_bt/L2CAPComm.cpp
@@ -33,7 +33,7 @@
#include <algorithm>
// #define PERF_PRINT_ON 1
-#include <dbt_debug.hpp>
+#include <jau/debug.hpp>
#include "BTIoctl.hpp"
#include "HCIIoctl.hpp"
@@ -53,10 +53,10 @@ extern "C" {
using namespace direct_bt;
L2CAPEnv::L2CAPEnv() noexcept
-: exploding( DBTEnv::getExplodingProperties("direct_bt.l2cap") ),
- L2CAP_READER_POLL_TIMEOUT( DBTEnv::getInt32Property("direct_bt.l2cap.reader.timeout", 10000, 1500 /* min */, INT32_MAX /* max */) ),
- L2CAP_RESTART_COUNT_ON_ERROR( DBTEnv::getInt32Property("direct_bt.l2cap.restart.count", 5, INT32_MIN /* min */, INT32_MAX /* max */) ), // FIXME: Move to L2CAPComm
- DEBUG_DATA( DBTEnv::getBooleanProperty("direct_bt.debug.l2cap.data", false) )
+: exploding( jau::environment::getExplodingProperties("direct_bt.l2cap") ),
+ L2CAP_READER_POLL_TIMEOUT( jau::environment::getInt32Property("direct_bt.l2cap.reader.timeout", 10000, 1500 /* min */, INT32_MAX /* max */) ),
+ L2CAP_RESTART_COUNT_ON_ERROR( jau::environment::getInt32Property("direct_bt.l2cap.restart.count", 5, INT32_MIN /* min */, INT32_MAX /* max */) ), // FIXME: Move to L2CAPComm
+ DEBUG_DATA( jau::environment::getBooleanProperty("direct_bt.debug.l2cap.data", false) )
{
}
@@ -77,9 +77,9 @@ int L2CAPComm::l2cap_open_dev(const EUI48 & adapterAddress, const uint16_t psm,
// BT Core Spec v5.2: Vol 3, Part A: L2CAP_CONNECTION_REQ
bzero((void *)&a, sizeof(a));
a.l2_family=AF_BLUETOOTH;
- a.l2_psm = cpu_to_le(psm);
+ a.l2_psm = jau::cpu_to_le(psm);
a.l2_bdaddr = adapterAddress;
- a.l2_cid = cpu_to_le(cid);
+ a.l2_cid = jau::cpu_to_le(cid);
a.l2_bdaddr_type = pubaddrAdapter ? BDADDR_LE_PUBLIC : BDADDR_LE_RANDOM;
if ( bind(fd, (struct sockaddr *) &a, sizeof(a)) < 0 ) {
ERR_PRINT("L2CAPComm::l2cap_open_dev: bind failed");
@@ -127,9 +127,9 @@ L2CAPComm::L2CAPComm(std::shared_ptr<DBTDevice> device, const uint16_t psm, cons
// actual request to connect to remote device
bzero((void *)&req, sizeof(req));
req.l2_family = AF_BLUETOOTH;
- req.l2_psm = cpu_to_le(psm);
+ req.l2_psm = jau::cpu_to_le(psm);
req.l2_bdaddr = device->getAddress();
- req.l2_cid = cpu_to_le(cid);
+ req.l2_cid = jau::cpu_to_le(cid);
req.l2_bdaddr_type = device->getAddressType();
while( !interrupt_flag ) {
diff --git a/src/direct_bt/MgmtTypes.cpp b/src/direct_bt/MgmtTypes.cpp
index dcb95dc6..ace0b7b4 100644
--- a/src/direct_bt/MgmtTypes.cpp
+++ b/src/direct_bt/MgmtTypes.cpp
@@ -32,9 +32,8 @@
#include <algorithm>
-#define PERF_PRINT_ON 1
-// #define VERBOSE_ON 1
-#include <dbt_debug.hpp>
+// #define PERF_PRINT_ON 1
+#include <jau/debug.hpp>
#include "BTIoctl.hpp"
@@ -232,7 +231,7 @@ std::string MgmtEvent::getOpcodeString(const Opcode opc) noexcept {
}
std::shared_ptr<MgmtEvent> MgmtEvent::getSpecialized(const uint8_t * buffer, int const buffer_size) noexcept {
- const MgmtEvent::Opcode opc = static_cast<MgmtEvent::Opcode>( get_uint16(buffer, 0, true /* littleEndian */) );
+ const MgmtEvent::Opcode opc = static_cast<MgmtEvent::Opcode>( jau::get_uint16(buffer, 0, true /* littleEndian */) );
MgmtEvent * res;
switch( opc ) {
case MgmtEvent::Opcode::CMD_COMPLETE:
@@ -296,10 +295,10 @@ std::shared_ptr<ConnectionInfo> MgmtEvtCmdComplete::toConnectionInfo() const noe
const uint8_t *data = getData();
EUI48 address = EUI48( data );
- BDAddressType addressType = static_cast<BDAddressType>( direct_bt::get_uint8(data, 6) );
- int8_t rssi = direct_bt::get_int8(data, 7);
- int8_t tx_power = direct_bt::get_int8(data, 8);
- int8_t max_tx_power = direct_bt::get_int8(data, 9);
+ BDAddressType addressType = static_cast<BDAddressType>( jau::get_uint8(data, 6) );
+ int8_t rssi = jau::get_int8(data, 7);
+ int8_t tx_power = jau::get_int8(data, 8);
+ int8_t max_tx_power = jau::get_int8(data, 9);
return std::shared_ptr<ConnectionInfo>(new ConnectionInfo(address, addressType, rssi, tx_power, max_tx_power) );
}
diff --git a/src/direct_bt/UUID.cpp b/src/direct_bt/UUID.cpp
index 3d580cab..7252f02f 100644
--- a/src/direct_bt/UUID.cpp
+++ b/src/direct_bt/UUID.cpp
@@ -23,7 +23,8 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#include <dbt_debug.hpp>
+#include <jau/debug.hpp>
+
#include "UUID.hpp"
@@ -40,7 +41,7 @@ uuid_t::TypeSize uuid_t::toTypeSize(const int size) {
case TypeSize::UUID32_SZ: return TypeSize::UUID32_SZ;
case TypeSize::UUID128_SZ: return TypeSize::UUID128_SZ;
}
- throw IllegalArgumentException("Given size "+std::to_string(size)+", not matching uuid16_t, uuid32_t or uuid128_t", E_FILE_LINE);
+ throw jau::IllegalArgumentException("Given size "+std::to_string(size)+", not matching uuid16_t, uuid32_t or uuid128_t", E_FILE_LINE);
}
std::shared_ptr<const uuid_t> uuid_t::create(TypeSize t, uint8_t const * const buffer, int const byte_offset, bool littleEndian) {
@@ -51,7 +52,7 @@ std::shared_ptr<const uuid_t> uuid_t::create(TypeSize t, uint8_t const * const b
} else if( TypeSize::UUID128_SZ == t ) {
return std::shared_ptr<const uuid_t>(new uuid128_t(buffer, byte_offset, littleEndian));
}
- throw IllegalArgumentException("Unknown Type "+std::to_string(static_cast<int>(t)), E_FILE_LINE);
+ throw jau::IllegalArgumentException("Unknown Type "+std::to_string(static_cast<int>(t)), E_FILE_LINE);
}
uuid128_t uuid_t::toUUID128(uuid128_t const & base_uuid, int const uuid32_le_octet_index) const noexcept {
@@ -133,19 +134,19 @@ std::string uuid128_t::toString() const noexcept {
// snprintf uses host data type, in which values are stored,
// hence no endian conversion
#if __BYTE_ORDER == __BIG_ENDIAN
- part0 = get_uint32(value.data, 0);
- part1 = get_uint16(value.data, 4);
- part2 = get_uint16(value.data, 6);
- part3 = get_uint16(value.data, 8);
- part4 = get_uint32(value.data, 10);
- part5 = get_uint16(value.data, 14);
+ part0 = jau::get_uint32(value.data, 0);
+ part1 = jau::get_uint16(value.data, 4);
+ part2 = jau::get_uint16(value.data, 6);
+ part3 = jau::get_uint16(value.data, 8);
+ part4 = jau::get_uint32(value.data, 10);
+ part5 = jau::get_uint16(value.data, 14);
#elif __BYTE_ORDER == __LITTLE_ENDIAN
- part5 = get_uint16(value.data, 0);
- part4 = get_uint32(value.data, 2);
- part3 = get_uint16(value.data, 6);
- part2 = get_uint16(value.data, 8);
- part1 = get_uint16(value.data, 10);
- part0 = get_uint32(value.data, 12);
+ part5 = jau::get_uint16(value.data, 0);
+ part4 = jau::get_uint32(value.data, 2);
+ part3 = jau::get_uint16(value.data, 6);
+ part2 = jau::get_uint16(value.data, 8);
+ part1 = jau::get_uint16(value.data, 10);
+ part0 = jau::get_uint32(value.data, 12);
#else
#error "Unexpected __BYTE_ORDER"
#endif
@@ -167,32 +168,32 @@ uuid128_t::uuid128_t(const std::string str)
std::string msg("UUID128 string not of length 36 but ");
msg.append(std::to_string(str.length()));
msg.append(": "+str);
- throw IllegalArgumentException(msg, E_FILE_LINE);
+ throw jau::IllegalArgumentException(msg, E_FILE_LINE);
}
if ( sscanf(str.c_str(), "%08x-%04hx-%04hx-%04hx-%08x%04hx",
&part0, &part1, &part2, &part3, &part4, &part5) != 6 )
{
std::string msg("UUID128 string not in format '00000000-0000-1000-8000-00805F9B34FB' but "+str);
- throw IllegalArgumentException(msg, E_FILE_LINE);
+ throw jau::IllegalArgumentException(msg, E_FILE_LINE);
}
- uint128_t value;
+ jau::uint128_t value;
// sscanf provided host data type, in which we store the values,
// hence no endian conversion
#if __BYTE_ORDER == __BIG_ENDIAN
- put_uint32(value.data, 0, part0);
- put_uint16(value.data, 4, part1);
- put_uint16(value.data, 6, part2);
- put_uint16(value.data, 8, part3);
- put_uint32(value.data, 10, part4);
- put_uint16(value.data, 14, part5);
+ jau::put_uint32(value.data, 0, part0);
+ jau::put_uint16(value.data, 4, part1);
+ jau::put_uint16(value.data, 6, part2);
+ jau::put_uint16(value.data, 8, part3);
+ jau::put_uint32(value.data, 10, part4);
+ jau::put_uint16(value.data, 14, part5);
#elif __BYTE_ORDER == __LITTLE_ENDIAN
- put_uint16(value.data, 0, part5);
- put_uint32(value.data, 2, part4);
- put_uint16(value.data, 6, part3);
- put_uint16(value.data, 8, part2);
- put_uint16(value.data, 10, part1);
- put_uint32(value.data, 12, part0);
+ jau::put_uint16(value.data, 0, part5);
+ jau::put_uint32(value.data, 2, part4);
+ jau::put_uint16(value.data, 6, part3);
+ jau::put_uint16(value.data, 8, part2);
+ jau::put_uint16(value.data, 10, part1);
+ jau::put_uint32(value.data, 12, part0);
#else
#error "Unexpected __BYTE_ORDER"
#endif
diff --git a/src/ieee11073/DataTypes.cpp b/src/ieee11073/DataTypes.cpp
index 2c8c03fa..97c53ab5 100644
--- a/src/ieee11073/DataTypes.cpp
+++ b/src/ieee11073/DataTypes.cpp
@@ -23,14 +23,14 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#include "BasicTypes.hpp"
-
#include <cstdint>
#include <cinttypes>
#include <cmath>
#include <algorithm>
+#include <jau/basic_types.hpp>
+
#include "ieee11073/DataTypes.hpp"
using namespace ieee11073;
diff --git a/src/tinyb/CMakeLists.txt b/src/tinyb/CMakeLists.txt
index eb78dbdd..b725bb3b 100644
--- a/src/tinyb/CMakeLists.txt
+++ b/src/tinyb/CMakeLists.txt
@@ -1,4 +1,5 @@
set (tinyb_LIB_INCLUDE_DIRS
+ ${PROJECT_SOURCE_DIR}/jaucpp/include
${PROJECT_SOURCE_DIR}/api
${PROJECT_SOURCE_DIR}/api/tinyb
${PROJECT_SOURCE_DIR}/include
@@ -13,10 +14,10 @@ include_directories(
)
set (tinyb_LIB_SRCS
- ${PROJECT_SOURCE_DIR}/src/direct_bt/dfa_utf8_decode.cpp
- ${PROJECT_SOURCE_DIR}/src/direct_bt/DBTEnv.cpp
- ${PROJECT_SOURCE_DIR}/src/direct_bt/dbt_debug.cpp
- ${PROJECT_SOURCE_DIR}/src/direct_bt/BasicTypes.cpp
+ ${PROJECT_SOURCE_DIR}/jaucpp/src/dfa_utf8_decode.cpp
+ ${PROJECT_SOURCE_DIR}/jaucpp/src/environment.cpp
+ ${PROJECT_SOURCE_DIR}/jaucpp/src/debug.cpp
+ ${PROJECT_SOURCE_DIR}/jaucpp/src/basic_types.cpp
${PROJECT_SOURCE_DIR}/src/tinyb/BluetoothObject.cpp
${PROJECT_SOURCE_DIR}/src/tinyb/BluetoothEvent.cpp
${PROJECT_SOURCE_DIR}/src/tinyb/BluetoothManager.cpp
diff --git a/test/direct_bt/CMakeLists.txt b/test/direct_bt/CMakeLists.txt
index 135a2766..02bbf978 100644
--- a/test/direct_bt/CMakeLists.txt
+++ b/test/direct_bt/CMakeLists.txt
@@ -1,18 +1,19 @@
include_directories(
${PROJECT_SOURCE_DIR}/include/cppunit
+ ${PROJECT_SOURCE_DIR}/jaucpp/include
${PROJECT_SOURCE_DIR}/api
)
-add_executable (test_functiondef01 test_functiondef01.cpp)
-set_target_properties(test_functiondef01
+add_executable (test_basictypes01 test_basictypes01.cpp)
+set_target_properties(test_basictypes01
PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
COMPILE_FLAGS "-Wall -Wextra -Werror"
)
-target_link_libraries (test_functiondef01 direct_bt)
-add_dependencies(test_functiondef01 direct_bt)
-add_test (NAME functiondef01 COMMAND test_functiondef01)
+target_link_libraries (test_basictypes01 direct_bt)
+add_dependencies(test_basictypes01 direct_bt)
+add_test (NAME basictypes01 COMMAND test_basictypes01)
add_executable (test_uuid test_uuid.cpp)
set_target_properties(test_uuid
@@ -25,17 +26,6 @@ target_link_libraries (test_uuid direct_bt)
add_dependencies(test_uuid direct_bt)
add_test (NAME uuid COMMAND test_uuid)
-add_executable (test_basictypes01 test_basictypes01.cpp)
-set_target_properties(test_basictypes01
- PROPERTIES
- CXX_STANDARD 17
- CXX_STANDARD_REQUIRED ON
- COMPILE_FLAGS "-Wall -Wextra -Werror"
-)
-target_link_libraries (test_basictypes01 direct_bt)
-add_dependencies(test_basictypes01 direct_bt)
-add_test (NAME basictypes01 COMMAND test_basictypes01)
-
add_executable (test_attpdu01 test_attpdu01.cpp)
set_target_properties(test_attpdu01
PROPERTIES
@@ -47,48 +37,3 @@ target_link_libraries (test_attpdu01 direct_bt)
add_dependencies(test_attpdu01 direct_bt)
add_test (NAME attpdu01 COMMAND test_attpdu01)
-add_executable (test_lfringbuffer01 test_lfringbuffer01.cpp)
-set_target_properties(test_lfringbuffer01
- PROPERTIES
- CXX_STANDARD 17
- CXX_STANDARD_REQUIRED ON
- COMPILE_FLAGS "-Wall -Wextra -Werror"
-)
-target_link_libraries (test_lfringbuffer01 direct_bt)
-add_dependencies(test_lfringbuffer01 direct_bt)
-add_test (NAME lfringbuffer01 COMMAND test_lfringbuffer01)
-
-add_executable (test_lfringbuffer11 test_lfringbuffer11.cpp)
-set_target_properties(test_lfringbuffer11
- PROPERTIES
- CXX_STANDARD 17
- CXX_STANDARD_REQUIRED ON
- COMPILE_FLAGS "-Wall -Wextra -Werror"
-)
-target_link_libraries (test_lfringbuffer11 direct_bt)
-add_dependencies(test_lfringbuffer11 direct_bt)
-add_test (NAME lfringbuffer11 COMMAND test_lfringbuffer11)
-
-add_executable (test_mm_sc_drf_00 test_mm_sc_drf_00.cpp)
-set_target_properties(test_mm_sc_drf_00
- PROPERTIES
- CXX_STANDARD 17
- CXX_STANDARD_REQUIRED ON
- COMPILE_FLAGS "-Wall -Wextra -Werror"
-)
-target_link_libraries (test_mm_sc_drf_00 direct_bt)
-add_dependencies(test_mm_sc_drf_00 direct_bt)
-add_test (NAME mm_sc_drf_00 COMMAND test_mm_sc_drf_00)
-
-add_executable (test_mm_sc_drf_01 test_mm_sc_drf_01.cpp)
-set_target_properties(test_mm_sc_drf_01
- PROPERTIES
- CXX_STANDARD 17
- CXX_STANDARD_REQUIRED ON
- COMPILE_FLAGS "-Wall -Wextra -Werror"
-)
-target_link_libraries (test_mm_sc_drf_01 direct_bt)
-add_dependencies(test_mm_sc_drf_01 direct_bt)
-add_test (NAME mm_sc_drf_01 COMMAND test_mm_sc_drf_01)
-
-