summaryrefslogtreecommitdiff
path: root/test/payload_tests/payload_test_client.hpp
blob: 2757d0004835995aac13e0f36f1a7a923aa895c3 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright (C) 2015-2017 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 PAYLOADTESTCLIENT_HPP_
#define PAYLOADTESTCLIENT_HPP_

#include <gtest/gtest.h>

#include <vsomeip/vsomeip.hpp>

#include <cmath>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <functional>

#include "../someip_test_globals.hpp"

#include "stopwatch.hpp"

class payload_test_client
{
public:
    payload_test_client(bool _use_tcp, bool _call_service_sync, std::uint32_t _sliding_window_size);
    bool init();
    void start();
    void stop();
    void join_sender_thread();
    void on_state(vsomeip::state_type_e _state);
    void on_availability(vsomeip::service_t _service,
            vsomeip::instance_t _instance, bool _is_available);
    void on_message(const std::shared_ptr<vsomeip::message> &_response);
    void send();
    void run();

private:
    void print_throughput();
    void send_messages_sync(std::unique_lock<std::mutex>& lk);
    void send_messages_async(std::unique_lock<std::mutex>& lk);
    void shutdown_service();
    std::uint32_t get_max_allowed_payload();

private:
    std::shared_ptr<vsomeip::application> app_;
    std::shared_ptr<vsomeip::message> request_;
    bool call_service_sync_;
    std::uint32_t sliding_window_size_;
    std::mutex mutex_;
    std::condition_variable condition_;
    bool blocked_;
    bool is_available_;
    const std::uint32_t number_of_messages_to_send_;
    std::uint32_t number_of_sent_messages_;
    std::uint32_t number_of_sent_messages_total_;
    std::uint32_t number_of_acknowledged_messages_;

    std::uint32_t current_payload_size_;

    stop_watch watch_;

    bool all_msg_acknowledged_;
    std::mutex all_msg_acknowledged_mutex_;
    std::condition_variable all_msg_acknowledged_cv_;

    std::thread sender_;

};

#endif /* PAYLOADTESTCLIENT_HPP_ */