DevMgr: Add DeviceReattacher daemon plumbing
This is the plumbing for a periodic polling thread that tries to reattach DA specs that failed to attach in the startup phase.
This commit is contained in:
@@ -24,6 +24,14 @@ if(NOT MIND_VOSCILLATOR_PERIOD_MS GREATER 0)
|
||||
endif()
|
||||
math(EXPR MIND_VOSCILLATOR_FREQ_MS "1000 / ${MIND_VOSCILLATOR_PERIOD_MS}")
|
||||
|
||||
# Device manager reattacher configuration
|
||||
set(MRNTT_DEVMGR_REATTACHER_PERIOD_MS 1500
|
||||
CACHE STRING "Device manager reattacher period (ms)")
|
||||
if(NOT MRNTT_DEVMGR_REATTACHER_PERIOD_MS GREATER 0)
|
||||
message(FATAL_ERROR
|
||||
"MRNTT_DEVMGR_REATTACHER_PERIOD_MS must be a positive integer > 0")
|
||||
endif()
|
||||
|
||||
# World thread configuration
|
||||
option(WORLD_USE_BODY_THREAD
|
||||
"Use body thread for world component instead of separate world thread" OFF)
|
||||
|
||||
@@ -9,6 +9,9 @@
|
||||
#define CONFIG_MIND_VOSCILLATOR_PERIOD_MS @MIND_VOSCILLATOR_PERIOD_MS@
|
||||
#define CONFIG_MIND_VOSCILLATOR_FREQ_MS @MIND_VOSCILLATOR_FREQ_MS@
|
||||
|
||||
/* Device manager reattacher configuration */
|
||||
#define CONFIG_MRNTT_DEVMGR_REATTACHER_PERIOD_MS @MRNTT_DEVMGR_REATTACHER_PERIOD_MS@
|
||||
|
||||
/* World thread configuration */
|
||||
#cmakedefine WORLD_USE_BODY_THREAD
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ add_library(smocore STATIC
|
||||
|
||||
# DeviceManager
|
||||
deviceManager/deviceManager.cpp
|
||||
deviceManager/deviceReattacher.cpp
|
||||
deviceManager/deviceAttachmentPipeSpecParser.cpp
|
||||
${LEX_OUTPUT}
|
||||
${YACC_OUTPUT}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
#include <config.h>
|
||||
#include <iostream>
|
||||
#include <functional>
|
||||
#include <componentThread.h>
|
||||
#include <deviceManager/deviceReattacher.h>
|
||||
#include <deviceManager/deviceManager.h>
|
||||
|
||||
namespace smo {
|
||||
namespace device {
|
||||
|
||||
DeviceReattacher::DeviceReattacher(
|
||||
DeviceManager& parent, std::shared_ptr<ComponentThread> ioThread)
|
||||
: parent(parent), ioThread(ioThread), shouldContinue(false),
|
||||
timer(ioThread->getIoService())
|
||||
{
|
||||
}
|
||||
|
||||
void DeviceReattacher::start()
|
||||
{
|
||||
shouldContinue.store(true);
|
||||
scheduleNextTimeout();
|
||||
}
|
||||
|
||||
void DeviceReattacher::stop()
|
||||
{
|
||||
shouldContinue.store(false);
|
||||
timer.cancel();
|
||||
}
|
||||
|
||||
void DeviceReattacher::scheduleNextTimeout()
|
||||
{
|
||||
if (!shouldContinue.load()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Schedule the next timeout using the configured period
|
||||
timer.expires_from_now(
|
||||
boost::posix_time::milliseconds(
|
||||
CONFIG_MRNTT_DEVMGR_REATTACHER_PERIOD_MS));
|
||||
|
||||
timer.async_wait(
|
||||
std::bind(&DeviceReattacher::onTimeout, this, std::placeholders::_1));
|
||||
}
|
||||
|
||||
void DeviceReattacher::onTimeout(const boost::system::error_code& error)
|
||||
{
|
||||
// Timer was cancelled, which is expected when stopping
|
||||
if (error == boost::asio::error::operation_aborted) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (error)
|
||||
{
|
||||
std::cerr << "DeviceReattacher: Timer error: " << error.message()
|
||||
<< std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!shouldContinue.load()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Schedule the next timeout
|
||||
scheduleNextTimeout();
|
||||
}
|
||||
|
||||
} // namespace device
|
||||
} // namespace smo
|
||||
@@ -0,0 +1,44 @@
|
||||
#ifndef DEVICEREATTACHER_H
|
||||
#define DEVICEREATTACHER_H
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
#include <boost/asio.hpp>
|
||||
|
||||
namespace smo {
|
||||
|
||||
class ComponentThread;
|
||||
|
||||
namespace device {
|
||||
|
||||
class DeviceManager;
|
||||
|
||||
class DeviceReattacher
|
||||
{
|
||||
public:
|
||||
DeviceReattacher(
|
||||
DeviceManager& parent, std::shared_ptr<ComponentThread> ioThread);
|
||||
~DeviceReattacher() = default;
|
||||
|
||||
// Non-copyable
|
||||
DeviceReattacher(const DeviceReattacher&) = delete;
|
||||
DeviceReattacher& operator=(const DeviceReattacher&) = delete;
|
||||
|
||||
// Control methods
|
||||
void start();
|
||||
void stop();
|
||||
|
||||
private:
|
||||
void scheduleNextTimeout();
|
||||
void onTimeout(const boost::system::error_code& error);
|
||||
|
||||
DeviceManager &parent;
|
||||
std::shared_ptr<ComponentThread> ioThread;
|
||||
std::atomic<bool> shouldContinue;
|
||||
boost::asio::deadline_timer timer;
|
||||
};
|
||||
|
||||
} // namespace device
|
||||
} // namespace smo
|
||||
|
||||
#endif // DEVICEREATTACHER_H
|
||||
Reference in New Issue
Block a user