1 #pragma once 2 3 // std 4 #include <cstdint> 5 #include <future> 6 #include <random> 7 #include <string> 8 9 /** 10 * @brief Contains the operation request data. 11 */ 12 class OperationRequest 13 { 14 public: 15 OperationRequest(const std::string& input); input()16 const std::string& input() const { return _input; } 17 18 private: 19 std::string _input; 20 }; 21 22 /** 23 * @brief Contains the operation response data. 24 */ 25 class OperationResponse 26 { 27 public: 28 OperationResponse(const std::string& output); output()29 const std::string& output() const { return _output; } 30 31 private: 32 std::string _output; 33 }; 34 35 /** 36 * @brief Provides the operation. 37 */ 38 class OperationProvider 39 { 40 public: 41 /** 42 * @brief Constructs an instance of OperationProvider. 43 * @param minLatencyMs The minimum latency to simulate for the operation. 44 * @param maxLatencyMs The maximum latency to simulate for the operation. 45 */ 46 OperationProvider(std::uint32_t minLatencyMs, std::uint32_t maxLatencyMs); 47 48 /** 49 * @brief Asynchronously executes the operation. 50 * @param request The request input data for the operation. 51 * @return A shared_future of the response of the operation. 52 */ 53 std::shared_future<OperationResponse> executeAsync(const OperationRequest& request); 54 55 private: 56 std::mt19937 _gen; ///< Used randomly determine an operation latency to simulate. 57 std::uniform_int_distribution<> _dis; ///< Used randomly determine an operation latency to simulate. 58 }; 59