mirror of
https://github.com/mudita/MuditaOS.git
synced 2026-01-24 13:58:00 -05:00
The system watchdog monitors whether there is message traffic on the Bus. If no message was sent for an extended period of time, a reset will occur. It should also protect against system-wide hangs. On Linux, watchdog is simulated by a FreeRTOS task that will call exit on timeout.
63 lines
1.8 KiB
C++
63 lines
1.8 KiB
C++
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
|
|
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
|
|
|
|
#include "BusProxy.hpp"
|
|
|
|
#include "details/bus/Bus.hpp"
|
|
|
|
namespace sys
|
|
{
|
|
BusProxy::BusProxy(Service *owner, Watchdog &watchdog)
|
|
: owner{owner}, watchdog{watchdog}, busImpl{std::make_unique<Bus>()}
|
|
{
|
|
channels.push_back(BusChannel::System); // Mandatory for each service.
|
|
}
|
|
|
|
BusProxy::~BusProxy() noexcept = default;
|
|
|
|
bool BusProxy::sendUnicast(std::shared_ptr<Message> message, const std::string &targetName)
|
|
{
|
|
auto ret = busImpl->SendUnicast(std::move(message), targetName, owner);
|
|
if (ret) {
|
|
watchdog.refresh();
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
SendResult BusProxy::sendUnicast(std::shared_ptr<Message> message, const std::string &targetName, uint32_t timeout)
|
|
{
|
|
auto ret = busImpl->SendUnicast(std::move(message), targetName, owner, timeout);
|
|
if (ret.first != ReturnCodes::Failure) {
|
|
watchdog.refresh();
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
void BusProxy::sendMulticast(std::shared_ptr<Message> message, BusChannel channel)
|
|
{
|
|
busImpl->SendMulticast(std::move(message), channel, owner);
|
|
watchdog.refresh();
|
|
}
|
|
|
|
void BusProxy::sendBroadcast(std::shared_ptr<Message> message)
|
|
{
|
|
busImpl->SendBroadcast(std::move(message), owner);
|
|
watchdog.refresh();
|
|
}
|
|
|
|
void BusProxy::sendResponse(std::shared_ptr<Message> response, std::shared_ptr<Message> request)
|
|
{
|
|
busImpl->SendResponse(std::move(response), std::move(request), owner);
|
|
}
|
|
|
|
void BusProxy::connect()
|
|
{
|
|
Bus::Add(owner);
|
|
}
|
|
|
|
void BusProxy::disconnect()
|
|
{
|
|
Bus::Remove(owner);
|
|
}
|
|
} // namespace sys
|