Skip to content
Snippets Groups Projects
Commit 47a03f2a authored by Hoop77's avatar Hoop77
Browse files

removed unneccessary functions in Timer.h

parent ad236380
No related merge requests found
...@@ -37,10 +37,6 @@ public: ...@@ -37,10 +37,6 @@ public:
void stop(); void stop();
void enable() noexcept;
bool isEnabled() const noexcept;
private: private:
boost::asio::basic_waitable_timer<time::Clock> timer; boost::asio::basic_waitable_timer<time::Clock> timer;
std::atomic<bool> enabled{true}; std::atomic<bool> enabled{true};
......
...@@ -21,49 +21,35 @@ Timer::Ptr Timer::create(Networking & net) ...@@ -21,49 +21,35 @@ Timer::Ptr Timer::create(Networking & net)
void Timer::startTimeout(const time::Duration & duration, TimeoutHandler handler) void Timer::startTimeout(const time::Duration & duration, TimeoutHandler handler)
{ {
try enabled = true;
{
enabled = true; auto self = shared_from_this();
timer.expires_from_now(duration);
auto self = shared_from_this(); timer.async_wait(
timer.expires_from_now(duration); [self, handler](const boost::system::error_code & error)
timer.async_wait( {
[self, handler](const boost::system::error_code & error) if (error || !self->enabled)
{ return;
if (error || !self->enabled)
return; handler();
});
handler();
});
}
catch (...)
{
throw error::FailedOperation{};
}
} }
void Timer::startPeriodicTimeout(const time::Duration & interval, Timer::TimeoutHandler handler) void Timer::startPeriodicTimeout(const time::Duration & interval, Timer::TimeoutHandler handler)
{ {
try enabled = true;
{
enabled = true; auto self = shared_from_this();
timer.expires_from_now(interval);
auto self = shared_from_this(); timer.async_wait(
timer.expires_from_now(interval); [self, interval, handler](const boost::system::error_code & error)
timer.async_wait( {
[self, interval, handler](const boost::system::error_code & error) if (error || !self->enabled)
{ return;
if (error || !self->enabled)
return; handler();
self->nextPeriod(interval, handler);
handler(); });
self->nextPeriod(interval, handler);
});
}
catch (...)
{
throw error::FailedOperation{};
}
} }
void Timer::stop() void Timer::stop()
...@@ -76,16 +62,6 @@ void Timer::stop() ...@@ -76,16 +62,6 @@ void Timer::stop()
timer.cancel(ignoredError); timer.cancel(ignoredError);
} }
void Timer::enable() noexcept
{
enabled = true;
}
bool Timer::isEnabled() const noexcept
{
return enabled;
}
void Timer::nextPeriod(const time::Duration & interval, Timer::TimeoutHandler handler) void Timer::nextPeriod(const time::Duration & interval, Timer::TimeoutHandler handler)
{ {
if (!enabled) if (!enabled)
......
...@@ -114,7 +114,7 @@ void FollowerVehicle::makePlatoonCreateResponse(const networking::Resolver::Endp ...@@ -114,7 +114,7 @@ void FollowerVehicle::makePlatoonCreateResponse(const networking::Resolver::Endp
{ {
if (state != State::CREATING_PLATOON) if (state != State::CREATING_PLATOON)
{ {
response = PlatoonMessage::rejectResponse(getOwnEndpoint().getVehicleId()); response = PlatoonMessage::rejectResponse(getOwnEndpoint().getVehicleId());
return; return;
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment