summaryrefslogtreecommitdiff
path: root/implementation/service_discovery/src/fsm_base.cpp
blob: 07a0def07041f99f8262b55bae73f77fa9de64b0 (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
// Copyright (C) 2014-2015 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
// 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 (uint32_t) std::chrono::duration_cast < std::chrono::milliseconds
            > (timer_.expires_from_now()).count();
}

} // namespace sd
} // namespace vsomeip