summaryrefslogtreecommitdiff
path: root/implementation/service_discovery/src/fsm_base.cpp
blob: 1feba930bf22c377b94fa125d8a8f92a61e18ce4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright (C) 2014 BMW Group
// Author: Lutz Bichler (lutz.bichler@bmw.de)
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include "../include/fsm_base.hpp"

namespace vsomeip {
namespace sd {

fsm_base::fsm_base(boost::asio::io_service &_io) : timer_(_io) {
}

fsm_base::~fsm_base() {
}

void fsm_base::start_timer(uint32_t _milliseconds) {
	timer_.expires_from_now(std::chrono::milliseconds(_milliseconds));
	timer_.async_wait(
		std::bind(
			&fsm_base::timer_expired,
			shared_from_this(),
			std::placeholders::_1
		)
	);
}

void fsm_base::stop_timer() {
	timer_.cancel();
}

uint32_t fsm_base::expired_from_now() {
	return std::chrono::duration_cast<
				std::chrono::milliseconds>(
					timer_.expires_from_now()).count();
}

} // namespace sd
} // namespace vsomeip