diff options
author | Sven Gothel <[email protected]> | 2022-05-01 10:45:21 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2022-05-01 10:45:21 +0200 |
commit | 468fbc8adc1b81d584803d60f6cdbb45fd2991be (patch) | |
tree | a10785652335a2357cee3bb7aa991328bad89ad0 /api | |
parent | b9fcb827dae5d986d1bd42ec8d4a919e3de03811 (diff) |
Bump jaulib v0.9.1 and adopt to fraction changes, use wait_until() w/ out-of-loop absolute timeout_time, avoiding deadlocks
Diffstat (limited to 'api')
-rw-r--r-- | api/direct_bt/BTAdapter.hpp | 2 | ||||
-rw-r--r-- | api/direct_bt/BTGattCmd.hpp | 5 | ||||
-rw-r--r-- | api/direct_bt/BTGattHandler.hpp | 16 | ||||
-rw-r--r-- | api/direct_bt/BTManager.hpp | 10 | ||||
-rw-r--r-- | api/direct_bt/DBTConst.hpp | 15 | ||||
-rw-r--r-- | api/direct_bt/DirectBT.hpp | 2 | ||||
-rw-r--r-- | api/direct_bt/HCIComm.hpp | 4 | ||||
-rw-r--r-- | api/direct_bt/HCIHandler.hpp | 10 | ||||
-rw-r--r-- | api/direct_bt/SMPHandler.hpp | 2 |
9 files changed, 36 insertions, 30 deletions
diff --git a/api/direct_bt/BTAdapter.hpp b/api/direct_bt/BTAdapter.hpp index 58ad73c1..3fd1e084 100644 --- a/api/direct_bt/BTAdapter.hpp +++ b/api/direct_bt/BTAdapter.hpp @@ -392,7 +392,7 @@ namespace direct_bt { weak_device_list_t pausing_discovery_devices; /** An SMP event watchdog for each device in pairing state */ jau::simple_timer smp_watchdog; - jau::nsize_t smp_timeoutfunc(jau::simple_timer& timer); + jau::fraction_i64 smp_timeoutfunc(jau::simple_timer& timer); typedef jau::cow_darray<impl::StatusListenerPair> statusListenerList_t; statusListenerList_t statusListenerList; diff --git a/api/direct_bt/BTGattCmd.hpp b/api/direct_bt/BTGattCmd.hpp index 024c5477..c3a7e1b4 100644 --- a/api/direct_bt/BTGattCmd.hpp +++ b/api/direct_bt/BTGattCmd.hpp @@ -28,6 +28,7 @@ #include <jau/uuid.hpp> #include <jau/octets.hpp> +#include <jau/fraction_type.hpp> #include "BTGattDesc.hpp" #include "BTGattChar.hpp" @@ -273,11 +274,11 @@ namespace direct_bt { * * @param prefNoAck pass true to prefer command write without acknowledge, otherwise use with-ack if available * @param cmd_data raw command octets - * @param timeoutMS timeout in milliseconds. Defaults to 10 seconds limited blocking for the response to become available, if any. + * @param timeout maximum duration in fractions of seconds to wait for the response to become available, if any. * @return * @see getResponse() */ - HCIStatusCode send(const bool prefNoAck, const jau::TROOctets& cmd_data, const int timeoutMS=10000) noexcept; + HCIStatusCode send(const bool prefNoAck, const jau::TROOctets& cmd_data, const jau::fraction_i64& timeout) noexcept; std::string toString() const noexcept; }; diff --git a/api/direct_bt/BTGattHandler.hpp b/api/direct_bt/BTGattHandler.hpp index beee8b5a..e51d5fc9 100644 --- a/api/direct_bt/BTGattHandler.hpp +++ b/api/direct_bt/BTGattHandler.hpp @@ -83,7 +83,7 @@ namespace direct_bt { * Actually used timeout will be `max(connection_supervisor_timeout + 50ms, GATT_READ_COMMAND_REPLY_TIMEOUT)`, * additional 50ms to allow L2CAP timeout hit first. */ - const int32_t GATT_READ_COMMAND_REPLY_TIMEOUT; + const jau::fraction_i64 GATT_READ_COMMAND_REPLY_TIMEOUT; /** * Timeout for GATT write command replies, defaults to 550ms minimum, @@ -94,7 +94,7 @@ namespace direct_bt { * Actually used timeout will be `max(connection_supervisor_timeout + 50ms, GATT_WRITE_COMMAND_REPLY_TIMEOUT)`, * additional 50ms to allow L2CAP timeout hit first. */ - const int32_t GATT_WRITE_COMMAND_REPLY_TIMEOUT; + const jau::fraction_i64 GATT_WRITE_COMMAND_REPLY_TIMEOUT; /** * Timeout for l2cap _initial_ command reply, defaults to 2500ms (2000ms minimum). @@ -104,7 +104,7 @@ namespace direct_bt { * Actually used timeout will be `min(10000, max(2 * connection_supervisor_timeout, GATT_INITIAL_COMMAND_REPLY_TIMEOUT))`, * double of connection_supervisor_timeout, to make sure L2CAP timeout hits first. */ - const int32_t GATT_INITIAL_COMMAND_REPLY_TIMEOUT; + const jau::fraction_i64 GATT_INITIAL_COMMAND_REPLY_TIMEOUT; /** * Medium ringbuffer capacity, defaults to 128 messages. @@ -181,9 +181,9 @@ namespace direct_bt { /** Environment runtime configuration, usually used internally only. */ const BTGattEnv & env; /** Derived environment runtime configuration, usually used internally only. */ - const int32_t read_cmd_reply_timeout; + const jau::fraction_i64 read_cmd_reply_timeout; /** Derived environment runtime configuration, usually used internally only. */ - const int32_t write_cmd_reply_timeout; + const jau::fraction_i64 write_cmd_reply_timeout; /** * Internal handler implementation for given DBGattServer instance @@ -498,7 +498,7 @@ namespace direct_bt { * * @see initClientGatt() */ - uint16_t clientMTUExchange(const int32_t timeout) noexcept; + uint16_t clientMTUExchange(const jau::fraction_i64& timeout) noexcept; /** * Discover all primary services _only_. @@ -674,10 +674,10 @@ namespace direct_bt { * the message has been send out and a reply has also been received and is returned as the result. * * @param msg the message to be send - * @param timeout milliseconds to wait for a reply + * @param timeout fractions of seconds to wait for a reply * @return non nullptr for a valid reply, otherwise nullptr */ - std::unique_ptr<const AttPDUMsg> sendWithReply(const AttPDUMsg & msg, const int timeout) noexcept; + std::unique_ptr<const AttPDUMsg> sendWithReply(const AttPDUMsg & msg, const jau::fraction_i64& timeout) noexcept; /** * Generic read GATT value and long value diff --git a/api/direct_bt/BTManager.hpp b/api/direct_bt/BTManager.hpp index 3e2ab3ec..226f7ec2 100644 --- a/api/direct_bt/BTManager.hpp +++ b/api/direct_bt/BTManager.hpp @@ -78,7 +78,7 @@ namespace direct_bt { * Environment variable is 'direct_bt.mgmt.reader.timeout'. * </p> */ - const int32_t MGMT_READER_THREAD_POLL_TIMEOUT; + const jau::fraction_i64 MGMT_READER_THREAD_POLL_TIMEOUT; /** * Timeout for mgmt command replies, defaults to 3s. @@ -86,7 +86,7 @@ namespace direct_bt { * Environment variable is 'direct_bt.mgmt.cmd.timeout'. * </p> */ - const int32_t MGMT_COMMAND_REPLY_TIMEOUT; + const jau::fraction_i64 MGMT_COMMAND_REPLY_TIMEOUT; /** * Timeout for mgmt SET_POWER command reply, defaults to max(MGMT_COMMAND_REPLY_TIMEOUT, 6s). @@ -94,7 +94,7 @@ namespace direct_bt { * Environment variable is 'direct_bt.mgmt.setpower.timeout'. * </p> */ - const int32_t MGMT_SET_POWER_COMMAND_TIMEOUT; + const jau::fraction_i64 MGMT_SET_POWER_COMMAND_TIMEOUT; /** * Small ringbuffer capacity for synchronized commands, defaults to 64 messages. @@ -256,10 +256,10 @@ namespace direct_bt { * function returns NULL. * * @param req the command request - * @param timeoutMS timeout in milliseconds + * @param timeout timeout in fractions of seconds * @return the resulting event or nullptr on failure (timeout) */ - std::unique_ptr<MgmtEvent> sendWithReply(MgmtCommand &req, const int timeoutMS) noexcept; + std::unique_ptr<MgmtEvent> sendWithReply(MgmtCommand &req, const jau::fraction_i64& timeout) noexcept; /** * In case response size check or devID and optional opcode validation fails, diff --git a/api/direct_bt/DBTConst.hpp b/api/direct_bt/DBTConst.hpp index a2810ba6..0dbbe5f8 100644 --- a/api/direct_bt/DBTConst.hpp +++ b/api/direct_bt/DBTConst.hpp @@ -32,6 +32,9 @@ namespace direct_bt { + using namespace jau::fractions_i64_literals; + using namespace jau::int_literals; + #ifdef __linux__ /** @@ -58,21 +61,21 @@ namespace direct_bt { #endif /** - * Maximum time in milliseconds to wait for a thread shutdown. + * Maximum time in fractions of seconds to wait for a thread shutdown. * * Usually used for socket reader threads, like used within HCIHandler. */ - inline constexpr const jau::nsize_t THREAD_SHUTDOWN_TIMEOUT_MS = 8000; + inline constexpr const jau::fraction_i64 THREAD_SHUTDOWN_TIMEOUT_MS = 8_s; /** - * Maximum time in milliseconds to wait for the next SMP event. + * Maximum time in fractions of seconds to wait for the next SMP event. */ - inline constexpr const jau::nsize_t SMP_NEXT_EVENT_TIMEOUT_MS = 2000; + inline constexpr const jau::fraction_i64 SMP_NEXT_EVENT_TIMEOUT_MS = 2_s; /** - * Maximum time in milliseconds to wait for L2CAP client connection when adapter is in server mode. + * Maximum time in fractions of seconds to wait for L2CAP client connection when adapter is in server mode. */ - inline constexpr const jau::nsize_t L2CAP_CLIENT_CONNECT_TIMEOUT_MS = 1000; + inline constexpr const jau::fraction_i64 L2CAP_CLIENT_CONNECT_TIMEOUT_MS = 1_s; /** * Maximum number of enabling discovery in background in case of failure diff --git a/api/direct_bt/DirectBT.hpp b/api/direct_bt/DirectBT.hpp index dfb6ee0a..0af35eab 100644 --- a/api/direct_bt/DirectBT.hpp +++ b/api/direct_bt/DirectBT.hpp @@ -54,6 +54,8 @@ #include "BTGattCmd.hpp" +#include "DBGattServer.hpp" + #include "BTDeviceRegistry.hpp" #include "BTSecurityRegistry.hpp" diff --git a/api/direct_bt/HCIComm.hpp b/api/direct_bt/HCIComm.hpp index 3d3bd8c5..25138f24 100644 --- a/api/direct_bt/HCIComm.hpp +++ b/api/direct_bt/HCIComm.hpp @@ -96,8 +96,8 @@ namespace direct_bt { /** Return the recursive write mutex for multithreading access. */ inline std::recursive_mutex & mutex_write() noexcept { return mtx_write; } - /** Generic read w/ own timeoutMS, w/o locking suitable for a unique ringbuffer sink. */ - jau::snsize_t read(uint8_t* buffer, const jau::nsize_t capacity, const int32_t timeoutMS) noexcept; + /** Generic read w/ own timeout, w/o locking suitable for a unique ringbuffer sink. */ + jau::snsize_t read(uint8_t* buffer, const jau::nsize_t capacity, const jau::fraction_i64& timeout) noexcept; /** Generic write, locking {@link #mutex_write()}. */ jau::snsize_t write(const uint8_t* buffer, const jau::nsize_t size) noexcept; diff --git a/api/direct_bt/HCIHandler.hpp b/api/direct_bt/HCIHandler.hpp index fc8366fe..c6a39ff1 100644 --- a/api/direct_bt/HCIHandler.hpp +++ b/api/direct_bt/HCIHandler.hpp @@ -79,7 +79,7 @@ namespace direct_bt { * Environment variable is 'direct_bt.hci.reader.timeout'. * </p> */ - const int32_t HCI_READER_THREAD_POLL_TIMEOUT; + const jau::fraction_i64 HCI_READER_THREAD_POLL_TIMEOUT; /** * Timeout for HCI command status replies, excluding command complete, defaults to 3s. @@ -87,7 +87,7 @@ namespace direct_bt { * Environment variable is 'direct_bt.hci.cmd.status.timeout'. * </p> */ - const int32_t HCI_COMMAND_STATUS_REPLY_TIMEOUT; + const jau::fraction_i64 HCI_COMMAND_STATUS_REPLY_TIMEOUT; /** * Timeout for HCI command complete replies, defaults to 10s. @@ -96,7 +96,7 @@ namespace direct_bt { * Environment variable is 'direct_bt.hci.cmd.complete.timeout'. * </p> */ - const int32_t HCI_COMMAND_COMPLETE_REPLY_TIMEOUT; + const jau::fraction_i64 HCI_COMMAND_COMPLETE_REPLY_TIMEOUT; /** * Poll period for certain HCI commands actively waiting for clearance, defaults to 125ms. @@ -109,7 +109,7 @@ namespace direct_bt { * Environment variable is 'direct_bt.hci.cmd.complete.timeout'. * </p> */ - const int32_t HCI_COMMAND_POLL_PERIOD; + const jau::fraction_i64 HCI_COMMAND_POLL_PERIOD; /** * Small ringbuffer capacity for synchronized commands, defaults to 64 messages. @@ -331,7 +331,7 @@ namespace direct_bt { void hciReaderEndLocked(jau::service_runner& sr) noexcept; bool sendCommand(HCICommand &req, const bool quiet=false) noexcept; - std::unique_ptr<HCIEvent> getNextReply(HCICommand &req, int32_t & retryCount, const int32_t replyTimeoutMS) noexcept; + std::unique_ptr<HCIEvent> getNextReply(HCICommand &req, int32_t & retryCount, const jau::fraction_i64& replyTimeout) noexcept; std::unique_ptr<HCIEvent> getNextCmdCompleteReply(HCICommand &req, HCICommandCompleteEvent **res) noexcept; std::unique_ptr<HCIEvent> processCommandStatus(HCICommand &req, HCIStatusCode *status, const bool quiet=false) noexcept; diff --git a/api/direct_bt/SMPHandler.hpp b/api/direct_bt/SMPHandler.hpp index 984c9168..8f5c6cf9 100644 --- a/api/direct_bt/SMPHandler.hpp +++ b/api/direct_bt/SMPHandler.hpp @@ -202,7 +202,7 @@ namespace direct_bt { void smpReaderEndLocked(jau::service_runner& sr) noexcept; void send(const SMPPDUMsg & msg); - std::unique_ptr<const SMPPDUMsg> sendWithReply(const SMPPDUMsg & msg, const int timeout); + std::unique_ptr<const SMPPDUMsg> sendWithReply(const SMPPDUMsg & msg, const jau::fraction_i64& timeout); void clearAllCallbacks() noexcept; |