Device: Allow the suppression of disconnects from extensions

This commit is contained in:
Paul Hollinsky
2021-04-23 20:04:02 -04:00
parent 6c1cbc9db8
commit 4cd7bafca7
4 changed files with 68 additions and 2 deletions
+7 -2
View File
@@ -240,13 +240,13 @@ bool Device::open() {
while(!stopHeartbeatThread) {
// Wait for 110ms for a possible heartbeat
std::this_thread::sleep_for(std::chrono::milliseconds(110));
if(!receivedMessage) {
if(!receivedMessage && !heartbeatSuppressed()) {
// No heartbeat received, request a status
com->sendCommand(Command::RequestStatusUpdate);
// The response should come back quickly if the com is quiet
std::this_thread::sleep_for(std::chrono::milliseconds(10));
// Check if we got a message, and if not, if settings are being applied
if(!receivedMessage && !settings->applyingSettings) {
if(!receivedMessage && !heartbeatSuppressed()) {
if(!stopHeartbeatThread && !isDisconnected())
report(APIEvent::Type::DeviceDisconnected, APIEvent::Severity::Error);
break;
@@ -630,6 +630,11 @@ optional<double> Device::getAnalogIO(IO type, size_t number /* = 1 */) {
return nullopt;
}
Lifetime Device::suppressDisconnects() {
heartbeatSuppressedByUser++;
return Lifetime([this] { heartbeatSuppressedByUser--; });
}
void Device::addExtension(std::shared_ptr<DeviceExtension>&& extension) {
std::lock_guard<std::mutex> lk(extensionsLock);
extensions.push_back(extension);