1#ifndef TIMER_SET_STATE_H
2#define TIMER_SET_STATE_H
5#include "../../../helper/machine_state.h"
26 const T mStoppedState;
49 bool WaitFor(std::chrono::milliseconds duration)
51 std::this_thread::sleep_for(duration);
52 bool _result = mStopped || mInterrupted;
62 auto _milliseconds = std::chrono::milliseconds(duration);
63 bool _result =
WaitFor(_milliseconds);
88 std::function<
void()> onTimerExpired) : mNextState{nextState},
89 mStoppedState{stoppedState},
126 mNextState = nextState;
Machine state abstract class.
Definition: machine_state.h:46
void Transit(T nextState)
Transit to the next state.
Definition: machine_state.h:59
Server's or client's service timer set state.
Definition: timer_set_state.h:24
virtual void Activate(T previousState) override
Activate the state.
Definition: timer_set_state.h:108
bool WaitFor(std::chrono::milliseconds duration)
Wait for certian period of time.
Definition: timer_set_state.h:49
bool WaitFor(int duration)
Wait for certian period of time.
Definition: timer_set_state.h:60
void Interrupt() noexcept
Interrupt the timer.
Definition: timer_set_state.h:70
const std::function< void()> OnTimerExpired
Delegate which is invoked by timer's thread when the timer is expired.
Definition: timer_set_state.h:76
void SetNextState(T nextState) noexcept
Set next state.
Definition: timer_set_state.h:124
TimerSetState(T nextState, T stoppedState, std::function< void()> onTimerExpired)
Constructor.
Definition: timer_set_state.h:85
void Deactivate(T nextState) override
Deactivating the current state before transiting to the next state.
Definition: timer_set_state.h:96
void ServiceStopped() noexcept
Inform the state that the server's service is stopped.
Definition: timer_set_state.h:117
virtual void SetTimer()=0
Set the phase time on state activation.