PeriodicService.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <swarmio/Mailbox.h>
4 #include <thread>
5 
6 namespace swarmio::services
7 {
13  class PeriodicService : public Mailbox
14  {
15  private:
16 
21  std::thread* _worker = nullptr;
22 
27  std::atomic<bool> _shutdownRequested;
28 
33  std::chrono::milliseconds _period;
34 
39  void Worker();
40 
41  protected:
42 
49  PeriodicService(Endpoint* endpoint, std::chrono::milliseconds period)
50  : Mailbox(endpoint), _shutdownRequested(false), _period(period), _worker(nullptr) { }
51 
57  virtual void MailboxWasConnected() noexcept override;
58 
64  virtual void MailboxWillBeDisconnected() noexcept override;
65 
70  virtual void Update() = 0;
71  };
72 }
PeriodicService(Endpoint *endpoint, std::chrono::milliseconds period)
Construct a new Periodic Service object.
std::atomic< bool > _shutdownRequested
Worker thread shutdown requested.
virtual void MailboxWillBeDisconnected() noexceptoverride
Called right before the mailbox is disconnected from its endpoint or if the attached endpoint is abou...
virtual void MailboxWasConnected() noexceptoverride
Called when the mailbox is attached to an already running endpoint or if the attached endpoint has ju...
void Worker()
Worker thread entry point.
A service that uses a periodic background worker to perform its work.
std::thread * _worker
Worker thread.
Abstract base class for Endpoint implementations.
Definition: Endpoint.h:25
std::chrono::milliseconds _period
Tick period.
virtual void Update()=0
Called periodically to perform work.
Abstract base class for Mailbox implementations.
Definition: Mailbox.h:13


swarmros
Author(s):
autogenerated on Fri Apr 3 2020 03:42:48