USRP Hardware Driver and Device Manual Version: 4.11.0.0-0-unknown
UHD and USRP Manual
Loading...
Searching...
No Matches
msg_task.hpp
Go to the documentation of this file.
1//
2// Copyright 2011-2015 Ettus Research LLC
3// Copyright 2018 Ettus Research, a National Instruments Company
4// Copyright 2019 Ettus Research, a National Instruments Brand
5//
6// SPDX-License-Identifier: GPL-3.0-or-later
7//
8
9#pragma once
10
11#include <uhd/config.hpp>
14#include <stdint.h>
15#include <boost/optional/optional.hpp>
16#include <cstring>
17#include <functional>
18#include <memory>
19#include <optional>
20#include <vector>
21
22namespace uhd {
24{
25public:
26 typedef std::shared_ptr<msg_task> sptr;
27 typedef std::vector<uint8_t> msg_payload_t;
28 typedef std::pair<uint32_t, msg_payload_t> msg_type_t;
29 typedef std::function<std::optional<msg_type_t>(void)> task_fcn_type;
30 typedef std::function<boost::optional<msg_type_t>(void)> task_fcn_type_legacy;
31
32 /*
33 * During shutdown message queues for radio control cores might not be available
34 * anymore. Such stranded messages get pushed into a dump queue. With this function
35 * radio_ctrl_core can check if one of the messages meant for it got stranded.
36 */
37 virtual msg_payload_t get_msg_from_dump_queue(uint32_t sid) = 0;
38
39 UHD_INLINE static std::vector<uint8_t> buff_to_vector(uint8_t* p, size_t n)
40 {
41 if (p and n > 0) {
42 std::vector<uint8_t> v(n);
43 memcpy(&v.front(), p, n);
44 return v;
45 }
46 return std::vector<uint8_t>();
47 }
48
49 virtual ~msg_task(void) = 0;
50
67 static sptr make(const task_fcn_type& task_fcn);
68
71 [[deprecated("Prefer std::optional over boost::optional.")]] static sptr make(
72 const task_fcn_type_legacy& task_fcn)
73 {
74 return make([task_fcn]() -> std::optional<msg_type_t> {
75 auto task_result = task_fcn();
76 return bool(task_result) ? std::make_optional<msg_type_t>(*task_result)
77 : std::nullopt;
78 });
79 }
80};
81} // namespace uhd
Definition msg_task.hpp:24
std::shared_ptr< msg_task > sptr
Definition msg_task.hpp:26
virtual msg_payload_t get_msg_from_dump_queue(uint32_t sid)=0
std::vector< uint8_t > msg_payload_t
Definition msg_task.hpp:27
static sptr make(const task_fcn_type_legacy &task_fcn)
Definition msg_task.hpp:71
std::pair< uint32_t, msg_payload_t > msg_type_t
Definition msg_task.hpp:28
virtual ~msg_task(void)=0
static sptr make(const task_fcn_type &task_fcn)
static UHD_INLINE std::vector< uint8_t > buff_to_vector(uint8_t *p, size_t n)
Definition msg_task.hpp:39
std::function< boost::optional< msg_type_t >(void)> task_fcn_type_legacy
Definition msg_task.hpp:30
std::function< std::optional< msg_type_t >(void)> task_fcn_type
Definition msg_task.hpp:29
#define UHD_INLINE
Definition config.h:65
#define UHD_API
Definition config.h:87
Definition build_info.hpp:12
boost::noncopyable noncopyable
Definition noncopyable.hpp:45