Line data Source code
1 : /**
2 : * @file ListCreator.cpp
3 : *
4 : * Helper methods for sending CreateList requests (implementation)
5 : *
6 : * This is part of the DUNE DAQ Software Suite, copyright 2020.
7 : * Licensing/copyright details are in the COPYING file that you should have
8 : * received with this code.
9 : */
10 :
11 : #include "ListCreator.hpp"
12 :
13 : #include "iomanager/IOManager.hpp"
14 : #include "iomanager/Sender.hpp"
15 :
16 : #include <string>
17 : #include <utility>
18 :
19 7 : dunedaq::listrev::ListCreator::ListCreator(std::string conn,
20 : std::chrono::milliseconds tmo,
21 : size_t min_list_size,
22 7 : size_t max_list_size)
23 7 : : m_random_generator(std::random_device()())
24 7 : , m_create_connection(conn)
25 7 : , m_send_timeout(tmo)
26 : {
27 7 : int min = static_cast<int>(min_list_size);
28 7 : int max = static_cast<int>(max_list_size);
29 7 : if (min < 0) {
30 1 : min = 1;
31 : }
32 7 : if (max < min) {
33 : max = min;
34 : }
35 7 : m_size_dist = std::uniform_int_distribution<>{ min, max };
36 :
37 7 : get_iomanager()->get_sender<CreateList>(m_create_connection);
38 7 : }
39 :
40 : size_t
41 42 : dunedaq::listrev::ListCreator::send_create(int id)
42 : {
43 42 : CreateList req;
44 42 : req.list_id = id;
45 42 : req.list_size = m_size_dist(m_random_generator);
46 42 : size_t output = req.list_size; // Save list_size since std::move may invalidate object
47 43 : get_iomanager()->get_sender<CreateList>(m_create_connection)->send(std::move(req), m_send_timeout); // NOLINT
48 41 : return output;
49 : }
|