1 // Copyright (C) 2015-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) 2 // This Source Code Form is subject to the terms of the Mozilla Public 3 // License, v. 2.0. If a copy of the MPL was not distributed with this 4 // file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 6 #ifndef PAYLOADTESTCLIENT_HPP_ 7 #define PAYLOADTESTCLIENT_HPP_ 8 9 #include <gtest/gtest.h> 10 11 #include <vsomeip/vsomeip.hpp> 12 13 #include <cmath> 14 #include <thread> 15 #include <mutex> 16 #include <condition_variable> 17 #include <functional> 18 19 #include "../someip_test_globals.hpp" 20 21 #include "stopwatch.hpp" 22 23 class payload_test_client 24 { 25 public: 26 payload_test_client(bool _use_tcp, bool _call_service_sync, std::uint32_t _sliding_window_size); 27 bool init(); 28 void start(); 29 void stop(); 30 void join_sender_thread(); 31 void on_state(vsomeip::state_type_e _state); 32 void on_availability(vsomeip::service_t _service, 33 vsomeip::instance_t _instance, bool _is_available); 34 void on_message(const std::shared_ptr<vsomeip::message> &_response); 35 void send(); 36 void run(); 37 38 private: 39 void print_throughput(); 40 void send_messages_sync(std::unique_lock<std::mutex>& lk); 41 void send_messages_async(std::unique_lock<std::mutex>& lk); 42 void shutdown_service(); 43 std::uint32_t get_max_allowed_payload(); 44 45 private: 46 std::shared_ptr<vsomeip::application> app_; 47 std::shared_ptr<vsomeip::message> request_; 48 bool call_service_sync_; 49 std::uint32_t sliding_window_size_; 50 std::mutex mutex_; 51 std::condition_variable condition_; 52 bool blocked_; 53 bool is_available_; 54 const std::uint32_t number_of_messages_to_send_; 55 std::uint32_t number_of_sent_messages_; 56 std::uint32_t number_of_sent_messages_total_; 57 std::uint32_t number_of_acknowledged_messages_; 58 59 std::uint32_t current_payload_size_; 60 61 stop_watch watch_; 62 63 bool all_msg_acknowledged_; 64 std::mutex all_msg_acknowledged_mutex_; 65 std::condition_variable all_msg_acknowledged_cv_; 66 67 std::thread sender_; 68 69 }; 70 71 #endif /* PAYLOADTESTCLIENT_HPP_ */ 72