summaryrefslogtreecommitdiff
path: root/test/network_tests/debounce_tests/debounce_test_client.hpp
blob: 0480ea3cab0dc186e4fc713150fb2e2bee44a6af (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright (C) 2020 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/.

#ifndef DEBOUNCE_TEST_CLIENT_HPP_
#define DEBOUNCE_TEST_CLIENT_HPP_

#include <condition_variable>
#include <mutex>
#include <thread>

#include <gtest/gtest.h>

#include <vsomeip/vsomeip.hpp>

#include "debounce_test_common.hpp"

class debounce_test_client {
public:
    debounce_test_client(debounce_test_id_e _test_id);

    bool init();
    void start();
    void stop();

    void run();
    void wait();

private:
    void on_availability(
            vsomeip::service_t _service, vsomeip::instance_t _instance,
            bool _is_available);
    void on_message(const std::shared_ptr<vsomeip::message> &_message);

    void run_test();
    void unsubscribe_all();
    void stop_service();

    bool compare_payload(const std::shared_ptr<vsomeip::payload> &_payload,
            std::size_t _index) const;

private:
    debounce_test_id_e test_id_;
    size_t index_;

    bool is_available_;

    std::mutex run_mutex_;
    std::condition_variable run_condition_;

    std::thread runner_;
    std::shared_ptr<vsomeip::application> app_;
};

#endif // DEBOUNCE_TEST_CLIENT_HPP_