GNU Radio's TEST Package
device.h
Go to the documentation of this file.
1/* -*- c++ -*- */
2/*
3 * Copyright 2012 Dimitri Stolnikov <horiz0n@gmx.net>
4 *
5 * GNU Radio is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3, or (at your option)
8 * any later version.
9 *
10 * GNU Radio is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with GNU Radio; see the file COPYING. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street,
18 * Boston, MA 02110-1301, USA.
19 */
20
21#ifndef INCLUDED_OSMOSDR_DEVICE_H
22#define INCLUDED_OSMOSDR_DEVICE_H
23
24#include <osmosdr/api.h>
25#include <osmosdr/pimpl.h>
26#include <boost/noncopyable.hpp>
27#include <boost/lexical_cast.hpp>
28#include <stdexcept>
29#include <string>
30#include <vector>
31#include <map>
32
33typedef std::map<std::string, std::string> string_string_dict_t;
34
35namespace osmosdr {
36
37 /*!
38 * Mapping of key/value pairs for locating devices on the system.
39 * When left empty, the device discovery routines will search
40 * all available transports on the system (ethernet, usb...).
41 *
42 * The logical device can also be used to pass arguments into
43 * the transport layer control to set (for example) buffer sizes.
44 *
45 * An arguments string, is a way to represent a device address
46 * using a single string with delimiter characters.
47 */
49 {
50 public:
51 /*!
52 * Create a logical device from an args string.
53 * \param args the arguments string
54 */
55 device_t(const std::string &args = "");
56
57 /*!
58 * Convert a logical device into a pretty print string.
59 * \return a printable string representing the device
60 */
61 std::string to_pp_string(void) const;
62
63 /*!
64 * Convert the logical device into an args string.
65 * The args string contains delimiter symbols.
66 * \return a string with delimiter markup
67 */
68 std::string to_string(void) const;
69
70 /*!
71 * Lexically cast a parameter to the specified type,
72 * or use the default value if the key is not found.
73 * \param key the key as one of the parameters
74 * \param def the value to use when key is not present
75 * \return the casted value as type T or the default
76 * \throw error when the parameter cannot be casted
77 */
78 template <typename T> T cast(const std::string &key, const T &def) const
79 {
80 if (!this->count(key)) return def;
81 try { return boost::lexical_cast<T>(this->at(key)); }
82 catch(const boost::bad_lexical_cast &) {
83 throw std::runtime_error("cannot cast " + key + " = " + this->at(key));
84 }
85 }
86 };
87
88 //! A typedef for a vector of logical devices
89 typedef std::vector<device_t> devices_t;
90
91 /*!
92 * The device interface represents the underyling hardware.
93 * The api allows for discovery, configuration, and streaming.
94 */
95 class OSMOSDR_API device : boost::noncopyable
96 {
97 public:
98 /*!
99 * \brief Find logical radio devices attached to the host.
100 *
101 * The device hint should be used to narrow down the search
102 * to particular transport types and/or transport arguments.
103 *
104 * The device hint "nofake" switches off dummy devices created
105 * by "file" (and other) implementations.
106 *
107 * \param hint a partially (or fully) filled in logical device
108 * \return a vector of logical devices for all radios on the system
109 */
110 static devices_t find(const device_t &hint = osmosdr::device_t());
111 };
112
113} //namespace osmosdr
114
115#endif /* INCLUDED_OSMOSDR_DEVICE_H */
#define OSMOSDR_API
Definition api.h:30
Definition device.h:49
device_t(const std::string &args="")
std::string to_pp_string(void) const
T cast(const std::string &key, const T &def) const
Definition device.h:78
std::string to_string(void) const
Definition device.h:96
static devices_t find(const device_t &hint=osmosdr::device_t())
Find logical radio devices attached to the host.
std::map< std::string, std::string > string_string_dict_t
Definition device.h:33
Definition device.h:35
std::vector< device_t > devices_t
A typedef for a vector of logical devices.
Definition device.h:89