OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
parsec/ticket_machine/client.hpp
Go to the documentation of this file.
1// Copyright (c) 2021 MIT Digital Currency Initiative,
2// Federal Reserve Bank of Boston
3// Distributed under the MIT software license, see the accompanying
4// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6#ifndef OPENCBDC_TX_SRC_PARSEC_TICKET_MACHINE_CLIENT_H_
7#define OPENCBDC_TX_SRC_PARSEC_TICKET_MACHINE_CLIENT_H_
8
9#include "interface.hpp"
10#include "messages.hpp"
12
15 class client : public interface {
16 public:
20 explicit client(std::vector<network::endpoint_t> endpoints);
21
22 client() = delete;
23 ~client() override = default;
24 client(const client&) = delete;
25 auto operator=(const client&) -> client& = delete;
26 client(client&&) = delete;
27 auto operator=(client&&) -> client& = delete;
28
31 auto init() -> bool;
32
41 -> bool override;
42
43 private:
44 std::unique_ptr<cbdc::rpc::tcp_client<request, response>> m_client;
45 std::queue<ticket_number_type> m_tickets;
46 bool m_fetching_tickets{false};
47
48 mutable std::mutex m_mut;
49
50 std::queue<get_ticket_number_callback_type> m_callbacks;
51
52 auto fetch_tickets() -> bool;
53
54 void handle_ticket_numbers(ticket_number_range_type range);
55 };
56}
57
58#endif
std::function< void(get_ticket_number_return_type)> get_ticket_number_callback_type
Callback function type for asynchronously handling ticket number requests.
std::pair< ticket_number_type, ticket_number_type > ticket_number_range_type
Return value from the ticket machine in the success case.
auto init() -> bool
Initializes the underlying TCP client.
auto get_ticket_number(get_ticket_number_callback_type result_callback) -> bool override
Requests a new batch of ticket numbers from the remote ticket machine.
auto operator=(client &&) -> client &=delete
auto operator=(const client &) -> client &=delete