Lockable renamed to Lock (#219)
Also changed usage from unique_ptr to class value.
This commit is contained in:
committed by
GitHub
parent
2e86d4774b
commit
55bfb9fe3b
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "./I2cCompat.h"
|
||||
#include "Tactility/Lockable.h"
|
||||
#include "Tactility/Lock.h"
|
||||
|
||||
#include <Tactility/RtosCompat.h>
|
||||
|
||||
@@ -89,6 +89,6 @@ bool masterHasDeviceAtAddress(i2c_port_t port, uint8_t address, TickType_t timeo
|
||||
* The lock for the specified bus.
|
||||
* This can be used when calling native I2C functionality outside of Tactility.
|
||||
*/
|
||||
Lockable& getLock(i2c_port_t port);
|
||||
Lock& getLock(i2c_port_t port);
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -29,7 +29,7 @@ private:
|
||||
public:
|
||||
|
||||
explicit SdCardDevice(MountBehaviour mountBehaviour) : mountBehaviour(mountBehaviour) {}
|
||||
virtual ~SdCardDevice() override = default;
|
||||
~SdCardDevice() override = default;
|
||||
|
||||
Type getType() const final { return Type::SdCard; };
|
||||
|
||||
@@ -39,7 +39,7 @@ public:
|
||||
/** Return empty string when not mounted or the mount path if mounted */
|
||||
virtual std::string getMountPath() const = 0;
|
||||
|
||||
virtual std::shared_ptr<Lockable> getLockable() const = 0;
|
||||
virtual Lock& getLock() const = 0;
|
||||
|
||||
virtual MountBehaviour getMountBehaviour() const { return mountBehaviour; }
|
||||
bool isMounted() const { return getState() == State::Mounted; }
|
||||
@@ -55,10 +55,9 @@ std::shared_ptr<SdCardDevice> _Nullable find(const std::string& path);
|
||||
template<typename ReturnType>
|
||||
inline ReturnType withSdCardLock(const std::string& path, std::function<ReturnType()> fn) {
|
||||
auto sdcard = find(path);
|
||||
std::unique_ptr<ScopedLockableUsage> scoped_lockable;
|
||||
if (sdcard != nullptr) {
|
||||
scoped_lockable = sdcard->getLockable()->scoped();
|
||||
scoped_lockable->lock(portMAX_DELAY);
|
||||
auto scoped_lockable = sdcard->getLock().asScopedLock();
|
||||
scoped_lockable.lock(portMAX_DELAY);
|
||||
}
|
||||
|
||||
return fn();
|
||||
|
||||
@@ -26,7 +26,7 @@ public:
|
||||
gpio_num_t spiPinWp,
|
||||
gpio_num_t spiPinInt,
|
||||
MountBehaviour mountBehaviourAtBoot,
|
||||
std::shared_ptr<Lockable> lockable = std::make_shared<Mutex>(),
|
||||
std::shared_ptr<Lock> lockable = std::make_shared<Mutex>(),
|
||||
std::vector<gpio_num_t> csPinWorkAround = std::vector<gpio_num_t>(),
|
||||
spi_host_device_t spiHost = SPI2_HOST,
|
||||
int spiFrequencyKhz = SDMMC_FREQ_DEFAULT
|
||||
@@ -49,7 +49,7 @@ public:
|
||||
gpio_num_t spiPinWp; // Write-protect
|
||||
gpio_num_t spiPinInt; // Interrupt
|
||||
SdCardDevice::MountBehaviour mountBehaviourAtBoot;
|
||||
std::shared_ptr<Lockable> _Nullable lockable;
|
||||
std::shared_ptr<Lock> _Nullable lockable;
|
||||
std::vector<gpio_num_t> csPinWorkAround;
|
||||
spi_host_device_t spiHost;
|
||||
bool formatOnMountFailed = false;
|
||||
@@ -80,7 +80,7 @@ public:
|
||||
bool unmount() final;
|
||||
std::string getMountPath() const final { return mountPath; }
|
||||
|
||||
std::shared_ptr<Lockable> getLockable() const final { return config->lockable; }
|
||||
Lock& getLock() const final { return *config->lockable; }
|
||||
|
||||
State getState() const override;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "SpiCompat.h"
|
||||
|
||||
#include <Tactility/Lockable.h>
|
||||
#include <Tactility/Lock.h>
|
||||
#include <Tactility/RtosCompat.h>
|
||||
|
||||
namespace tt::hal::spi {
|
||||
@@ -26,7 +26,7 @@ struct Configuration {
|
||||
/** Whether configuration can be changed. */
|
||||
bool hasMutableConfiguration;
|
||||
/** Optional custom lock */
|
||||
std::shared_ptr<Lockable> _Nullable lock;
|
||||
std::shared_ptr<Lock> _Nullable lock;
|
||||
};
|
||||
|
||||
enum class Status {
|
||||
@@ -45,6 +45,6 @@ bool stop(spi_host_device_t device);
|
||||
bool isStarted(spi_host_device_t device);
|
||||
|
||||
/** @return the lock that represents the specified device. Can be used with third party SPI implementations or native API calls (e.g. ESP-IDF). */
|
||||
Lockable& getLock(spi_host_device_t device);
|
||||
Lock& getLock(spi_host_device_t device);
|
||||
|
||||
} // namespace tt::hal::spi
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <Tactility/RtosCompat.h>
|
||||
|
||||
#include "../Gpio.h"
|
||||
#include "Tactility/Lockable.h"
|
||||
#include "Tactility/Lock.h"
|
||||
#include "UartCompat.h"
|
||||
|
||||
#include <memory>
|
||||
@@ -59,7 +59,7 @@ bool stop(uart_port_t port);
|
||||
bool isStarted(uart_port_t port);
|
||||
|
||||
/** @return a lock that is usable for using ESP-IDF directly, or for use with third party APIs */
|
||||
Lockable& getLock(uart_port_t port);
|
||||
Lock& getLock(uart_port_t port);
|
||||
|
||||
/**
|
||||
* Read up to a specified amount of bytes
|
||||
|
||||
@@ -19,56 +19,55 @@ auto toVector(RangeType&& range) {
|
||||
}
|
||||
|
||||
void registerDevice(const std::shared_ptr<Device>& device) {
|
||||
auto scoped_mutex = mutex.scoped();
|
||||
if (scoped_mutex->lock()) {
|
||||
if (findDevice(device->getId()) == nullptr) {
|
||||
devices.push_back(device);
|
||||
TT_LOG_I(TAG, "Registered %s with id %lu", device->getName().c_str(), device->getId());
|
||||
} else {
|
||||
TT_LOG_W(TAG, "Device %s with id %lu was already registered", device->getName().c_str(), device->getId());
|
||||
}
|
||||
auto scoped_mutex = mutex.asScopedLock();
|
||||
scoped_mutex.lock();
|
||||
|
||||
if (findDevice(device->getId()) == nullptr) {
|
||||
devices.push_back(device);
|
||||
TT_LOG_I(TAG, "Registered %s with id %lu", device->getName().c_str(), device->getId());
|
||||
} else {
|
||||
TT_LOG_W(TAG, "Device %s with id %lu was already registered", device->getName().c_str(), device->getId());
|
||||
}
|
||||
}
|
||||
|
||||
void deregisterDevice(const std::shared_ptr<Device>& device) {
|
||||
auto scoped_mutex = mutex.scoped();
|
||||
auto scoped_mutex = mutex.asScopedLock();
|
||||
scoped_mutex.lock();
|
||||
|
||||
auto id_to_remove = device->getId();
|
||||
if (scoped_mutex->lock()) {
|
||||
auto remove_iterator = std::remove_if(devices.begin(), devices.end(), [id_to_remove](const auto& device) {
|
||||
return device->getId() == id_to_remove;
|
||||
});
|
||||
if (remove_iterator != devices.end()) {
|
||||
TT_LOG_I(TAG, "Deregistering %s with id %lu", device->getName().c_str(), device->getId());
|
||||
devices.erase(remove_iterator);
|
||||
} else {
|
||||
TT_LOG_W(TAG, "Deregistering %s with id %lu failed: not found", device->getName().c_str(), device->getId());
|
||||
}
|
||||
auto remove_iterator = std::remove_if(devices.begin(), devices.end(), [id_to_remove](const auto& device) {
|
||||
return device->getId() == id_to_remove;
|
||||
});
|
||||
if (remove_iterator != devices.end()) {
|
||||
TT_LOG_I(TAG, "Deregistering %s with id %lu", device->getName().c_str(), device->getId());
|
||||
devices.erase(remove_iterator);
|
||||
} else {
|
||||
TT_LOG_W(TAG, "Deregistering %s with id %lu failed: not found", device->getName().c_str(), device->getId());
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<Device>> findDevices(const std::function<bool(const std::shared_ptr<Device>&)>& filterFunction) {
|
||||
auto scoped_mutex = mutex.scoped();
|
||||
if (scoped_mutex->lock()) {
|
||||
auto devices_view = devices | std::views::filter([&filterFunction](auto& device) {
|
||||
return filterFunction(device);
|
||||
});
|
||||
return toVector(devices_view);
|
||||
}
|
||||
return {};
|
||||
auto scoped_mutex = mutex.asScopedLock();
|
||||
scoped_mutex.lock();
|
||||
|
||||
auto devices_view = devices | std::views::filter([&filterFunction](auto& device) {
|
||||
return filterFunction(device);
|
||||
});
|
||||
return toVector(devices_view);
|
||||
}
|
||||
|
||||
std::shared_ptr<Device> _Nullable findDevice(const std::function<bool(const std::shared_ptr<Device>&)>& filterFunction) {
|
||||
auto scoped_mutex = mutex.scoped();
|
||||
if (scoped_mutex->lock()) {
|
||||
auto result_set = devices | std::views::filter([&filterFunction](auto& device) {
|
||||
return filterFunction(device);
|
||||
});
|
||||
if (!result_set.empty()) {
|
||||
return result_set.front();
|
||||
}
|
||||
}
|
||||
auto scoped_mutex = mutex.asScopedLock();
|
||||
scoped_mutex.lock();
|
||||
|
||||
return nullptr;
|
||||
auto result_set = devices | std::views::filter([&filterFunction](auto& device) {
|
||||
return filterFunction(device);
|
||||
});
|
||||
if (!result_set.empty()) {
|
||||
return result_set.front();
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<Device> _Nullable findDevice(std::string name) {
|
||||
|
||||
@@ -75,8 +75,8 @@ int32_t GpsDevice::threadMain() {
|
||||
}
|
||||
|
||||
bool GpsDevice::start() {
|
||||
auto scoped_lockable = mutex.scoped();
|
||||
scoped_lockable->lock(portMAX_DELAY);
|
||||
auto lock = mutex.asScopedLock();
|
||||
lock.lock();
|
||||
|
||||
if (thread != nullptr && thread->getState() != Thread::State::Stopped) {
|
||||
TT_LOG_W(TAG, "Already started");
|
||||
@@ -108,8 +108,8 @@ bool GpsDevice::start() {
|
||||
}
|
||||
|
||||
bool GpsDevice::stop() {
|
||||
auto scoped_lockable = mutex.scoped();
|
||||
scoped_lockable->lock();
|
||||
auto lock = mutex.asScopedLock();
|
||||
lock.lock(portMAX_DELAY);
|
||||
|
||||
if (thread != nullptr) {
|
||||
threadInterrupted = true;
|
||||
@@ -119,11 +119,11 @@ bool GpsDevice::stop() {
|
||||
|
||||
if (old_thread->getState() != Thread::State::Stopped) {
|
||||
// Unlock so thread can lock
|
||||
scoped_lockable->unlock();
|
||||
lock.unlock();
|
||||
// Wait for thread to finish
|
||||
old_thread->join();
|
||||
// Re-lock to continue logic below
|
||||
scoped_lockable->lock();
|
||||
lock.lock();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,14 +138,14 @@ bool GpsDevice::stop() {
|
||||
}
|
||||
|
||||
bool GpsDevice::isStarted() const {
|
||||
auto scoped_lockable = mutex.scoped();
|
||||
scoped_lockable->lock(portMAX_DELAY);
|
||||
auto lock = mutex.asScopedLock();
|
||||
lock.lock();
|
||||
return thread != nullptr && thread->getState() != Thread::State::Stopped;
|
||||
}
|
||||
|
||||
bool GpsDevice::isThreadInterrupted() const {
|
||||
auto scoped_lockable = mutex.scoped();
|
||||
scoped_lockable->lock(portMAX_DELAY);
|
||||
auto lock = mutex.asScopedLock();
|
||||
lock.lock(portMAX_DELAY);
|
||||
return threadInterrupted;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,8 +23,8 @@ SatelliteStorage::SatelliteRecord* SatelliteStorage::findRecord(int number) {
|
||||
}
|
||||
|
||||
SatelliteStorage::SatelliteRecord* SatelliteStorage::findUnusedRecord() {
|
||||
auto lockable = mutex.scoped();
|
||||
lockable->lock();
|
||||
auto lock = mutex.asScopedLock();
|
||||
lock.lock();
|
||||
|
||||
auto result = records | std::views::filter([](auto& record) {
|
||||
return !record.inUse;
|
||||
@@ -41,8 +41,8 @@ SatelliteStorage::SatelliteRecord* SatelliteStorage::findUnusedRecord() {
|
||||
}
|
||||
|
||||
SatelliteStorage::SatelliteRecord* SatelliteStorage::findRecordToRecycle() {
|
||||
auto lockable = mutex.scoped();
|
||||
lockable->lock();
|
||||
auto lock = mutex.asScopedLock();
|
||||
lock.lock();
|
||||
|
||||
int candidate_index = -1;
|
||||
auto candidate_age = portMAX_DELAY;
|
||||
@@ -72,8 +72,8 @@ SatelliteStorage::SatelliteRecord* SatelliteStorage::findRecordToRecycle() {
|
||||
}
|
||||
|
||||
SatelliteStorage::SatelliteRecord* SatelliteStorage::findWithFallback(int number) {
|
||||
auto lockable = mutex.scoped();
|
||||
lockable->lock();
|
||||
auto lock = mutex.asScopedLock();
|
||||
lock.lock();
|
||||
|
||||
if (auto* found_record = findRecord(number)) {
|
||||
return found_record;
|
||||
@@ -85,8 +85,8 @@ SatelliteStorage::SatelliteRecord* SatelliteStorage::findWithFallback(int number
|
||||
}
|
||||
|
||||
void SatelliteStorage::notify(const minmea_sat_info& data) {
|
||||
auto lockable = mutex.scoped();
|
||||
lockable->lock();
|
||||
auto lock = mutex.asScopedLock();
|
||||
lock.lock();
|
||||
|
||||
auto* record = findWithFallback(data.nr);
|
||||
if (record != nullptr) {
|
||||
@@ -98,8 +98,8 @@ void SatelliteStorage::notify(const minmea_sat_info& data) {
|
||||
}
|
||||
|
||||
void SatelliteStorage::getRecords(const std::function<void(const minmea_sat_info&)>& onRecord) const {
|
||||
auto lockable = mutex.scoped();
|
||||
lockable->lock();
|
||||
auto lock = mutex.asScopedLock();
|
||||
lock.lock();
|
||||
|
||||
TickType_t expire_duration = kernel::secondsToTicks(recentTimeSeconds);
|
||||
TickType_t now = kernel::getTicks();
|
||||
|
||||
@@ -76,8 +76,8 @@ bool init(const std::vector<i2c::Configuration>& configurations) {
|
||||
}
|
||||
|
||||
bool configure(i2c_port_t port, const i2c_config_t& configuration) {
|
||||
auto lockable = getLock(port).asScopedLock();
|
||||
lockable.lock();
|
||||
auto lock = getLock(port).asScopedLock();
|
||||
lock.lock();
|
||||
|
||||
Data& data = dataArray[port];
|
||||
if (data.isStarted) {
|
||||
@@ -93,8 +93,8 @@ bool configure(i2c_port_t port, const i2c_config_t& configuration) {
|
||||
}
|
||||
|
||||
bool start(i2c_port_t port) {
|
||||
auto lockable = getLock(port).asScopedLock();
|
||||
lockable.lock();
|
||||
auto lock = getLock(port).asScopedLock();
|
||||
lock.lock();
|
||||
|
||||
Data& data = dataArray[port];
|
||||
printInfo(data);
|
||||
@@ -131,8 +131,8 @@ bool start(i2c_port_t port) {
|
||||
}
|
||||
|
||||
bool stop(i2c_port_t port) {
|
||||
auto lockable = getLock(port).asScopedLock();
|
||||
lockable.lock();
|
||||
auto lock = getLock(port).asScopedLock();
|
||||
lock.lock();
|
||||
|
||||
Data& data = dataArray[port];
|
||||
Configuration& config = data.configuration;
|
||||
@@ -162,14 +162,14 @@ bool stop(i2c_port_t port) {
|
||||
}
|
||||
|
||||
bool isStarted(i2c_port_t port) {
|
||||
auto lockable = getLock(port).asScopedLock();
|
||||
lockable.lock();
|
||||
auto lock = getLock(port).asScopedLock();
|
||||
lock.lock();
|
||||
return dataArray[port].isStarted;
|
||||
}
|
||||
|
||||
bool masterRead(i2c_port_t port, uint8_t address, uint8_t* data, size_t dataSize, TickType_t timeout) {
|
||||
auto lockable = getLock(port).asScopedLock();
|
||||
if (!lockable.lock(timeout)) {
|
||||
auto lock = getLock(port).asScopedLock();
|
||||
if (!lock.lock(timeout)) {
|
||||
TT_LOG_E(TAG, "(%d) Mutex timeout", port);
|
||||
return false;
|
||||
}
|
||||
@@ -184,8 +184,8 @@ bool masterRead(i2c_port_t port, uint8_t address, uint8_t* data, size_t dataSize
|
||||
}
|
||||
|
||||
bool masterReadRegister(i2c_port_t port, uint8_t address, uint8_t reg, uint8_t* data, size_t dataSize, TickType_t timeout) {
|
||||
auto lockable = getLock(port).asScopedLock();
|
||||
if (!lockable.lock(timeout)) {
|
||||
auto lock = getLock(port).asScopedLock();
|
||||
if (!lock.lock(timeout)) {
|
||||
TT_LOG_E(TAG, "(%d) Mutex timeout", port);
|
||||
return false;
|
||||
}
|
||||
@@ -217,8 +217,8 @@ bool masterReadRegister(i2c_port_t port, uint8_t address, uint8_t reg, uint8_t*
|
||||
}
|
||||
|
||||
bool masterWrite(i2c_port_t port, uint8_t address, const uint8_t* data, uint16_t dataSize, TickType_t timeout) {
|
||||
auto lockable = getLock(port).asScopedLock();
|
||||
if (!lockable.lock(timeout)) {
|
||||
auto lock = getLock(port).asScopedLock();
|
||||
if (!lock.lock(timeout)) {
|
||||
TT_LOG_E(TAG, "(%d) Mutex timeout", port);
|
||||
return false;
|
||||
}
|
||||
@@ -235,8 +235,8 @@ bool masterWrite(i2c_port_t port, uint8_t address, const uint8_t* data, uint16_t
|
||||
bool masterWriteRegister(i2c_port_t port, uint8_t address, uint8_t reg, const uint8_t* data, uint16_t dataSize, TickType_t timeout) {
|
||||
tt_check(reg != 0);
|
||||
|
||||
auto lockable = getLock(port).asScopedLock();
|
||||
if (!lockable.lock(timeout)) {
|
||||
auto lock = getLock(port).asScopedLock();
|
||||
if (!lock.lock(timeout)) {
|
||||
TT_LOG_E(TAG, "(%d) Mutex timeout", port);
|
||||
return false;
|
||||
}
|
||||
@@ -277,8 +277,8 @@ bool masterWriteRegisterArray(i2c_port_t port, uint8_t address, const uint8_t* d
|
||||
}
|
||||
|
||||
bool masterWriteRead(i2c_port_t port, uint8_t address, const uint8_t* writeData, size_t writeDataSize, uint8_t* readData, size_t readDataSize, TickType_t timeout) {
|
||||
auto lockable = getLock(port).asScopedLock();
|
||||
if (!lockable.lock(timeout)) {
|
||||
auto lock = getLock(port).asScopedLock();
|
||||
if (!lock.lock(timeout)) {
|
||||
TT_LOG_E(TAG, "(%d) Mutex timeout", port);
|
||||
return false;
|
||||
}
|
||||
@@ -293,8 +293,8 @@ bool masterWriteRead(i2c_port_t port, uint8_t address, const uint8_t* writeData,
|
||||
}
|
||||
|
||||
bool masterHasDeviceAtAddress(i2c_port_t port, uint8_t address, TickType_t timeout) {
|
||||
auto lockable = getLock(port).asScopedLock();
|
||||
if (!lockable.lock(timeout)) {
|
||||
auto lock = getLock(port).asScopedLock();
|
||||
if (!lock.lock(timeout)) {
|
||||
TT_LOG_E(TAG, "(%d) Mutex timeout", port);
|
||||
return false;
|
||||
}
|
||||
@@ -308,7 +308,7 @@ bool masterHasDeviceAtAddress(i2c_port_t port, uint8_t address, TickType_t timeo
|
||||
#endif // ESP_PLATFORM
|
||||
}
|
||||
|
||||
Lockable& getLock(i2c_port_t port) {
|
||||
Lock& getLock(i2c_port_t port) {
|
||||
return dataArray[port].mutex;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
namespace tt::hal::spi {
|
||||
|
||||
struct Data {
|
||||
std::shared_ptr<Lockable> lock;
|
||||
std::shared_ptr<Lock> lock;
|
||||
bool isConfigured = false;
|
||||
bool isStarted = false;
|
||||
Configuration configuration;
|
||||
@@ -169,7 +169,7 @@ bool isStarted(spi_host_device_t device) {
|
||||
return dataArray[device].isStarted;
|
||||
}
|
||||
|
||||
Lockable& getLock(spi_host_device_t device) {
|
||||
Lock& getLock(spi_host_device_t device) {
|
||||
return *dataArray[device].lock;
|
||||
}
|
||||
|
||||
|
||||
@@ -180,7 +180,7 @@ bool isStarted(uart_port_t port) {
|
||||
return dataArray[port].isStarted;
|
||||
}
|
||||
|
||||
Lockable& getLock(uart_port_t port) {
|
||||
Lock& getLock(uart_port_t port) {
|
||||
return dataArray[port].mutex;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@ using tt::hal::gps::GpsDevice;
|
||||
namespace tt::service::gps {
|
||||
|
||||
GpsService::GpsDeviceRecord* _Nullable GpsService::findGpsRecord(const std::shared_ptr<GpsDevice>& device) {
|
||||
auto lockable = mutex.scoped();
|
||||
lockable->lock();
|
||||
auto lock = mutex.asScopedLock();
|
||||
lock.lock();
|
||||
|
||||
auto result = std::views::filter(deviceRecords, [&device](auto& record){
|
||||
return record.device.get() == device.get();
|
||||
@@ -22,8 +22,8 @@ GpsService::GpsDeviceRecord* _Nullable GpsService::findGpsRecord(const std::shar
|
||||
}
|
||||
|
||||
void GpsService::addGpsDevice(const std::shared_ptr<GpsDevice>& device) {
|
||||
auto lockable = mutex.scoped();
|
||||
lockable->lock();
|
||||
auto lock = mutex.asScopedLock();
|
||||
lock.lock();
|
||||
|
||||
GpsDeviceRecord record = { .device = device };
|
||||
|
||||
@@ -35,8 +35,8 @@ void GpsService::addGpsDevice(const std::shared_ptr<GpsDevice>& device) {
|
||||
}
|
||||
|
||||
void GpsService::removeGpsDevice(const std::shared_ptr<GpsDevice>& device) {
|
||||
auto lockable = mutex.scoped();
|
||||
lockable->lock();
|
||||
auto lock = mutex.asScopedLock();
|
||||
lock.lock();
|
||||
|
||||
GpsDeviceRecord* record = findGpsRecord(device);
|
||||
|
||||
@@ -50,8 +50,8 @@ void GpsService::removeGpsDevice(const std::shared_ptr<GpsDevice>& device) {
|
||||
}
|
||||
|
||||
void GpsService::onStart(tt::service::ServiceContext &serviceContext) {
|
||||
auto lockable = mutex.scoped();
|
||||
lockable->lock();
|
||||
auto lock = mutex.asScopedLock();
|
||||
lock.lock();
|
||||
|
||||
deviceRecords.clear();
|
||||
|
||||
@@ -71,8 +71,8 @@ void GpsService::onStop(tt::service::ServiceContext &serviceContext) {
|
||||
bool GpsService::startGpsDevice(GpsDeviceRecord& record) {
|
||||
TT_LOG_I(TAG, "[device %lu] starting", record.device->getId());
|
||||
|
||||
auto lockable = mutex.scoped();
|
||||
lockable->lock();
|
||||
auto lock = mutex.asScopedLock();
|
||||
lock.lock();
|
||||
|
||||
auto device = record.device;
|
||||
|
||||
@@ -114,8 +114,8 @@ bool GpsService::stopGpsDevice(GpsDeviceRecord& record) {
|
||||
bool GpsService::startReceiving() {
|
||||
TT_LOG_I(TAG, "Start receiving");
|
||||
|
||||
auto lockable = mutex.scoped();
|
||||
lockable->lock();
|
||||
auto lock = mutex.asScopedLock();
|
||||
lock.lock();
|
||||
|
||||
bool started_one_or_more = false;
|
||||
|
||||
@@ -131,8 +131,8 @@ bool GpsService::startReceiving() {
|
||||
void GpsService::stopReceiving() {
|
||||
TT_LOG_I(TAG, "Stop receiving");
|
||||
|
||||
auto lockable = mutex.scoped();
|
||||
lockable->lock();
|
||||
auto lock = mutex.asScopedLock();
|
||||
lock.lock();
|
||||
|
||||
for (auto& record : deviceRecords) {
|
||||
stopGpsDevice(record);
|
||||
@@ -142,8 +142,8 @@ void GpsService::stopReceiving() {
|
||||
}
|
||||
|
||||
bool GpsService::isReceiving() {
|
||||
auto lockable = mutex.scoped();
|
||||
lockable->lock();
|
||||
auto lock = mutex.asScopedLock();
|
||||
lock.lock();
|
||||
return receiving;
|
||||
}
|
||||
|
||||
|
||||
@@ -73,54 +73,54 @@ public:
|
||||
bool connection_target_remember = false; // Whether to store the connection_target on successful connection or not
|
||||
|
||||
RadioState getRadioState() const {
|
||||
auto lockable = dataMutex.scoped();
|
||||
lockable->lock();
|
||||
auto lock = dataMutex.asScopedLock();
|
||||
lock.lock();
|
||||
// TODO: Handle lock failure
|
||||
return radio_state;
|
||||
}
|
||||
|
||||
void setRadioState(RadioState newState) {
|
||||
auto lockable = dataMutex.scoped();
|
||||
lockable->lock();
|
||||
auto lock = dataMutex.asScopedLock();
|
||||
lock.lock();
|
||||
// TODO: Handle lock failure
|
||||
radio_state = newState;
|
||||
}
|
||||
|
||||
bool isScanning() const {
|
||||
auto lockable = dataMutex.scoped();
|
||||
lockable->lock();
|
||||
auto lock = dataMutex.asScopedLock();
|
||||
lock.lock();
|
||||
// TODO: Handle lock failure
|
||||
return scan_active;
|
||||
}
|
||||
|
||||
void setScanning(bool newState) {
|
||||
auto lockable = dataMutex.scoped();
|
||||
lockable->lock();
|
||||
auto lock = dataMutex.asScopedLock();
|
||||
lock.lock();
|
||||
// TODO: Handle lock failure
|
||||
scan_active = newState;
|
||||
}
|
||||
|
||||
bool isScanActive() const {
|
||||
auto lcokable = dataMutex.scoped();
|
||||
lcokable->lock();
|
||||
auto lock = dataMutex.asScopedLock();
|
||||
lock.lock();
|
||||
return scan_active;
|
||||
}
|
||||
|
||||
void setScanActive(bool newState) {
|
||||
auto lockable = dataMutex.scoped();
|
||||
lockable->lock();
|
||||
auto lock = dataMutex.asScopedLock();
|
||||
lock.lock();
|
||||
scan_active = newState;
|
||||
}
|
||||
|
||||
bool isSecureConnection() const {
|
||||
auto lockable = dataMutex.scoped();
|
||||
lockable->lock();
|
||||
auto lock = dataMutex.asScopedLock();
|
||||
lock.lock();
|
||||
return secure_connection;
|
||||
}
|
||||
|
||||
void setSecureConnection(bool newState) {
|
||||
auto lockable = dataMutex.scoped();
|
||||
lockable->lock();
|
||||
auto lock = dataMutex.asScopedLock();
|
||||
lock.lock();
|
||||
secure_connection = newState;
|
||||
}
|
||||
};
|
||||
@@ -191,8 +191,8 @@ void connect(const settings::WifiApSettings* ap, bool remember) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto lockable = wifi->dataMutex.scoped();
|
||||
if (!lockable->lock(10 / portTICK_PERIOD_MS)) {
|
||||
auto lock = wifi->dataMutex.asScopedLock();
|
||||
if (!lock.lock(10 / portTICK_PERIOD_MS)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -215,8 +215,8 @@ void disconnect() {
|
||||
return;
|
||||
}
|
||||
|
||||
auto lockable = wifi->dataMutex.scoped();
|
||||
if (!lockable->lock(10 / portTICK_PERIOD_MS)) {
|
||||
auto lock = wifi->dataMutex.asScopedLock();
|
||||
if (!lock.lock(10 / portTICK_PERIOD_MS)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -237,8 +237,8 @@ void setScanRecords(uint16_t records) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto lockable = wifi->dataMutex.scoped();
|
||||
if (!lockable->lock(10 / portTICK_PERIOD_MS)) {
|
||||
auto lock = wifi->dataMutex.asScopedLock();
|
||||
if (!lock.lock(10 / portTICK_PERIOD_MS)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -258,8 +258,8 @@ std::vector<ApRecord> getScanResults() {
|
||||
return records;
|
||||
}
|
||||
|
||||
auto lockable = wifi->dataMutex.scoped();
|
||||
if (!lockable->lock(10 / portTICK_PERIOD_MS)) {
|
||||
auto lock = wifi->dataMutex.asScopedLock();
|
||||
if (!lock.lock(10 / portTICK_PERIOD_MS)) {
|
||||
return records;
|
||||
}
|
||||
|
||||
@@ -285,8 +285,8 @@ void setEnabled(bool enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto lockable = wifi->dataMutex.scoped();
|
||||
if (!lockable->lock(10 / portTICK_PERIOD_MS)) {
|
||||
auto lock = wifi->dataMutex.asScopedLock();
|
||||
if (!lock.lock(10 / portTICK_PERIOD_MS)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -305,8 +305,8 @@ bool isConnectionSecure() {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto lockable = wifi->dataMutex.scoped();
|
||||
if (!lockable->lock(10 / portTICK_PERIOD_MS)) {
|
||||
auto lock = wifi->dataMutex.asScopedLock();
|
||||
if (!lock.lock(10 / portTICK_PERIOD_MS)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -326,8 +326,8 @@ int getRssi() {
|
||||
// endregion Public functions
|
||||
|
||||
static void scan_list_alloc(std::shared_ptr<Wifi> wifi) {
|
||||
auto lockable = wifi->dataMutex.scoped();
|
||||
if (lockable->lock()) {
|
||||
auto lock = wifi->dataMutex.asScopedLock();
|
||||
if (lock.lock()) {
|
||||
assert(wifi->scan_list == nullptr);
|
||||
wifi->scan_list = static_cast<wifi_ap_record_t*>(malloc(sizeof(wifi_ap_record_t) * wifi->scan_list_limit));
|
||||
wifi->scan_list_count = 0;
|
||||
@@ -335,8 +335,8 @@ static void scan_list_alloc(std::shared_ptr<Wifi> wifi) {
|
||||
}
|
||||
|
||||
static void scan_list_alloc_safely(std::shared_ptr<Wifi> wifi) {
|
||||
auto lockable = wifi->dataMutex.scoped();
|
||||
if (lockable->lock()) {
|
||||
auto lock = wifi->dataMutex.asScopedLock();
|
||||
if (lock.lock()) {
|
||||
if (wifi->scan_list == nullptr) {
|
||||
scan_list_alloc(wifi);
|
||||
}
|
||||
@@ -344,8 +344,8 @@ static void scan_list_alloc_safely(std::shared_ptr<Wifi> wifi) {
|
||||
}
|
||||
|
||||
static void scan_list_free(std::shared_ptr<Wifi> wifi) {
|
||||
auto lockable = wifi->dataMutex.scoped();
|
||||
if (lockable->lock()) {
|
||||
auto lock = wifi->dataMutex.asScopedLock();
|
||||
if (lock.lock()) {
|
||||
assert(wifi->scan_list != nullptr);
|
||||
free(wifi->scan_list);
|
||||
wifi->scan_list = nullptr;
|
||||
@@ -354,8 +354,8 @@ static void scan_list_free(std::shared_ptr<Wifi> wifi) {
|
||||
}
|
||||
|
||||
static void scan_list_free_safely(std::shared_ptr<Wifi> wifi) {
|
||||
auto lockable = wifi->dataMutex.scoped();
|
||||
if (lockable->lock()) {
|
||||
auto lock = wifi->dataMutex.asScopedLock();
|
||||
if (lock.lock()) {
|
||||
if (wifi->scan_list != nullptr) {
|
||||
scan_list_free(wifi);
|
||||
}
|
||||
@@ -363,8 +363,8 @@ static void scan_list_free_safely(std::shared_ptr<Wifi> wifi) {
|
||||
}
|
||||
|
||||
static void publish_event_simple(std::shared_ptr<Wifi> wifi, EventType type) {
|
||||
auto lockable = wifi->dataMutex.scoped();
|
||||
if (lockable->lock()) {
|
||||
auto lock = wifi->dataMutex.asScopedLock();
|
||||
if (lock.lock()) {
|
||||
Event turning_on_event = {.type = type};
|
||||
wifi->pubsub->publish(&turning_on_event);
|
||||
}
|
||||
@@ -380,8 +380,8 @@ static bool copy_scan_list(std::shared_ptr<Wifi> wifi) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto lockable = wifi->dataMutex.scoped();
|
||||
if (!lockable->lock()) {
|
||||
auto lock = wifi->dataMutex.asScopedLock();
|
||||
if (lock.lock()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -407,9 +407,9 @@ static bool copy_scan_list(std::shared_ptr<Wifi> wifi) {
|
||||
|
||||
static bool find_auto_connect_ap(std::shared_ptr<void> context, settings::WifiApSettings& settings) {
|
||||
auto wifi = std::static_pointer_cast<Wifi>(context);
|
||||
auto lockable = wifi->dataMutex.scoped();
|
||||
auto lock = wifi->dataMutex.asScopedLock();
|
||||
|
||||
if (lockable->lock(10 / portTICK_PERIOD_MS)) {
|
||||
if (lock.lock(10 / portTICK_PERIOD_MS)) {
|
||||
TT_LOG_I(TAG, "auto_connect()");
|
||||
for (int i = 0; i < wifi->scan_list_count; ++i) {
|
||||
auto ssid = reinterpret_cast<const char*>(wifi->scan_list[i].ssid);
|
||||
@@ -512,9 +512,8 @@ static void dispatchEnable(std::shared_ptr<void> context) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto lockable = wifi->radioMutex.scoped();
|
||||
|
||||
if (lockable->lock(50 / portTICK_PERIOD_MS)) {
|
||||
auto lock = wifi->radioMutex.asScopedLock();
|
||||
if (lock.lock(50 / portTICK_PERIOD_MS)) {
|
||||
TT_LOG_I(TAG, "Enabling");
|
||||
wifi->setRadioState(RadioState::OnPending);
|
||||
publish_event_simple(wifi, EventType::RadioStateOnPending);
|
||||
@@ -590,9 +589,9 @@ static void dispatchEnable(std::shared_ptr<void> context) {
|
||||
static void dispatchDisable(std::shared_ptr<void> context) {
|
||||
TT_LOG_I(TAG, "dispatchDisable()");
|
||||
auto wifi = std::static_pointer_cast<Wifi>(context);
|
||||
auto lockable = wifi->radioMutex.scoped();
|
||||
auto lock = wifi->radioMutex.asScopedLock();
|
||||
|
||||
if (!lockable->lock(50 / portTICK_PERIOD_MS)) {
|
||||
if (!lock.lock(50 / portTICK_PERIOD_MS)) {
|
||||
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "disable()");
|
||||
return;
|
||||
}
|
||||
@@ -657,9 +656,9 @@ static void dispatchDisable(std::shared_ptr<void> context) {
|
||||
static void dispatchScan(std::shared_ptr<void> context) {
|
||||
TT_LOG_I(TAG, "dispatchScan()");
|
||||
auto wifi = std::static_pointer_cast<Wifi>(context);
|
||||
auto lockable = wifi->radioMutex.scoped();
|
||||
auto lock = wifi->radioMutex.asScopedLock();
|
||||
|
||||
if (!lockable->lock(10 / portTICK_PERIOD_MS)) {
|
||||
if (!lock.lock(10 / portTICK_PERIOD_MS)) {
|
||||
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
||||
return;
|
||||
}
|
||||
@@ -691,9 +690,9 @@ static void dispatchScan(std::shared_ptr<void> context) {
|
||||
static void dispatchConnect(std::shared_ptr<void> context) {
|
||||
TT_LOG_I(TAG, "dispatchConnect()");
|
||||
auto wifi = std::static_pointer_cast<Wifi>(context);
|
||||
auto lockable = wifi->radioMutex.scoped();
|
||||
auto lock = wifi->radioMutex.asScopedLock();
|
||||
|
||||
if (!lockable->lock(50 / portTICK_PERIOD_MS)) {
|
||||
if (!lock.lock(50 / portTICK_PERIOD_MS)) {
|
||||
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "dispatchConnect()");
|
||||
return;
|
||||
}
|
||||
@@ -790,9 +789,9 @@ static void dispatchConnect(std::shared_ptr<void> context) {
|
||||
static void dispatchDisconnectButKeepActive(std::shared_ptr<void> context) {
|
||||
TT_LOG_I(TAG, "dispatchDisconnectButKeepActive()");
|
||||
auto wifi = std::static_pointer_cast<Wifi>(context);
|
||||
auto lockable = wifi->radioMutex.scoped();
|
||||
auto lock = wifi->radioMutex.asScopedLock();
|
||||
|
||||
if (!lockable->lock(50 / portTICK_PERIOD_MS)) {
|
||||
if (!lock.lock(50 / portTICK_PERIOD_MS)) {
|
||||
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
||||
return;
|
||||
}
|
||||
@@ -835,9 +834,8 @@ static void dispatchDisconnectButKeepActive(std::shared_ptr<void> context) {
|
||||
}
|
||||
|
||||
static bool shouldScanForAutoConnect(std::shared_ptr<Wifi> wifi) {
|
||||
auto lockable = wifi->dataMutex.scoped();
|
||||
|
||||
if (!lockable->lock(100)) {
|
||||
auto lock = wifi->dataMutex.asScopedLock();
|
||||
if (!lock.lock(100)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user