template<class IdType>
class SocCamera::tcPendingAckWatchdog< IdType >
The tcPendingAckWatchdog class provides a utility to allow transport message handlers to be notified if a message handling/response thread is taking too long. Many transport protocols used by cameras are request/response based, where a response is required within some defined about of time or a timeout condition is required. Such protocols typically provide a provision for sending a "pending acknowledgment" message back to the requested essentially requesting for more time.
This class allows transport message handlers to implement a callback via the tcPendingAckWatcher interface and start a timer when beginning a message handling cycle. If the timer expires before the message handler is complete, the pendingAckNeeded() interface method is called, which allows the message handler to transmit an appropriate pending-ack message and continue processing the message.
The goal of this framework is to support decoupling the transport handler from the Sensor / Camera message handling implementations. The transport handler doesn't need to know how long a specific message will take to process, and the sensor board doesn't have to know or care about how long it takes to handle a message and provide hints back to the transport for pending acks.
The implementation does support multiple message timers, though in practice it is unlikely that more than one timer would ever be running at any given time.
Message Handler Flow:
class tcHandler : public tcPendingAckWatcher()
tcHandler::tcHandler()
{
mpWatchDog = new tcPendingAckWatchdog<int>();
mpWatchDog->setTimeoutPeriod(std::chrono::microseconds{timeout});
mpWatchDog->addWatcher(this);
}
tcHandler::HandleMessage(message* msg)
{
mpWatchDog->newMessage(msg->id);
response = HandleMessage();
SendResponse();
mpWatchDog->messageDone(msg->id);
}
tcHandler::pendingAckNeeded(void * id)
{
SendPendingAck(*id);
}