summaryrefslogtreecommitdiffstats
path: root/src/direct_bt/DBGattServer.cpp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2022-01-28 04:19:47 +0100
committerSven Gothel <[email protected]>2022-01-28 04:19:47 +0100
commit68e8dc229c0344c900740c9c2706d0face0cc47f (patch)
treecca530e0c13fd82b1d5c25f2bb86f8197a84aeb9 /src/direct_bt/DBGattServer.cpp
parentd26240eb2c8aca0a4027a1fb0b86a656436d59c7 (diff)
DBGatt[Char|Desc] (Server): Add setValue(..), allowing user to safely overwrite (initial) value server side.
Also refine getValue() API doc. Implemented on C++ and Java side. Peripheral00 example uses this facility to set the DEVICE_NAME GATT value using the current adapter name.
Diffstat (limited to 'src/direct_bt/DBGattServer.cpp')
-rw-r--r--src/direct_bt/DBGattServer.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/direct_bt/DBGattServer.cpp b/src/direct_bt/DBGattServer.cpp
index 28f05292..6b160e9a 100644
--- a/src/direct_bt/DBGattServer.cpp
+++ b/src/direct_bt/DBGattServer.cpp
@@ -38,6 +38,40 @@
using namespace direct_bt;
+bool DBGattDesc::setValue(const uint8_t* source, const jau::nsize_t source_len, const jau::nsize_t dest_pos) noexcept {
+ if( hasVariableLength() ) {
+ if( value.capacity() < dest_pos + source_len ) {
+ return false;
+ }
+ if( value.size() != dest_pos + source_len ) {
+ value.resize( dest_pos + source_len );
+ }
+ } else {
+ if( value.size() < dest_pos + source_len ) {
+ return false;
+ }
+ }
+ value.put_bytes_nc(dest_pos, source, source_len);
+ return true;
+}
+
+bool DBGattChar::setValue(const uint8_t* source, const jau::nsize_t source_len, const jau::nsize_t dest_pos) noexcept {
+ if( hasVariableLength() ) {
+ if( value.capacity() < dest_pos + source_len ) {
+ return false;
+ }
+ if( value.size() != dest_pos + source_len ) {
+ value.resize( dest_pos + source_len );
+ }
+ } else {
+ if( value.size() < dest_pos + source_len ) {
+ return false;
+ }
+ }
+ value.put_bytes_nc(dest_pos, source, source_len);
+ return true;
+}
+
static jau::cow_darray<DBGattServer::ListenerRef>::equal_comparator _listenerRefEqComparator =
[](const DBGattServer::ListenerRef &a, const DBGattServer::ListenerRef &b) -> bool { return *a == *b; };