Skip to main content

dvbv5_sys/
debug.rs

1/*
2 *  libdvbv5-sys — a Rust FFI binding for the libdvbv5 library from V4L2.
3 *
4 *  Copyright © 2019, 2020  Russel Winder
5 *
6 *  This program is free software: you can redistribute it and/or modify
7 *  it under the terms of the GNU General Public License as published by
8 *  the Free Software Foundation, either version 3 of the License, or
9 *  (at your option) any later version.
10 *
11 *  This program is distributed in the hope that it will be useful,
12 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 *  GNU General Public License for more details.
15 *
16 *  You should have received a copy of the GNU General Public License
17 *  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20//! Various implementations of std::fmt::Debug for types that bindgen does not
21//! annotate with #[derive(Debug)]
22
23use crate::ffi;
24
25/// A manually written implementation of `Debug` trait for `dvb_frontend_info`.
26///
27/// Bindgen does not mark `dvb_frontend_info` as `#[derive(Debug)]` because of the array
28/// entry `name` being >32 items in length and so not having a `Debug` definition.
29/// Hence this manual realisation.
30impl std::fmt::Debug for ffi::dvb_frontend_info {
31    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32        write!(
33            f,
34            "dvb_frontend_info{{\
35            name: {:?}…,\
36            type_: {:?},\
37            frequency_min: {:?},\
38            frequency_max: {:?},\
39            frequency_stepsize: {:?},\
40            frequency_tolerance: {:?},\
41            symbol_rate_min: {:?},\
42            symbol_rate_max: {:?},\
43            symbol_rate_tolerance: {:?},\
44            notifier_delay: {:?},\
45            caps: {:?}}}",
46            &self.name[..32], // NB Only first 32 of 128 chars.
47            &self.type_,
48            &self.frequency_min,
49            &self.frequency_max,
50            &self.frequency_stepsize,
51            &self.frequency_tolerance,
52            &self.symbol_rate_min,
53            &self.symbol_rate_max,
54            &self.symbol_rate_tolerance,
55            &self.notifier_delay,
56            &self.caps,
57        )
58    }
59}
60
61/// A manually written implementation of `Debug` for `dvb_v5_fe_parms`.
62///
63/// Bindgen does not mark `dvb_v5_fe_parms` as `#[derive(Debug)#` because the `info` field
64/// is a [dvb_frontend_info](struct.dvb_frontend_info.html) which is not marked
65/// `#[derive(Debug)]`.  Hence this manual realisation.
66impl std::fmt::Debug for ffi::dvb_v5_fe_parms {
67    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
68        write!(
69            f,
70            "dvb_v5_fe_parms{{\
71            info: {:?},\
72            version: {:?},\
73            has_v5_stats: {:?},\
74            current_sys: {:?},\
75            num_systems: {:?},\
76            systems: {:?},\
77            legacy_fe: {:?},\
78            abort: {:?},\
79            lna: {:?},\
80            lnb: {:?},\
81            sat_number: {:?},\
82            freq_bpf: {:?},\
83            diseqc_wait: {:?},\
84            verbose: {:?},\
85            logfunc: {:?},\
86            default_charset: {:?},\
87            output_charset: {:?}}}",
88            &self.info,
89            &self.version,
90            &self.has_v5_stats,
91            &self.current_sys,
92            &self.num_systems,
93            &self.systems,
94            &self.legacy_fe,
95            &self.abort,
96            &self.lna,
97            &self.lnb,
98            &self.sat_number,
99            &self.freq_bpf,
100            &self.diseqc_wait,
101            &self.verbose,
102            &self.logfunc,
103            &self.default_charset,
104            &self.output_charset,
105        )
106    }
107}
108
109/// A manually written implementation of `Debug` for `dtv_property`.
110///
111/// Bindgen does not mark `dtv_property` as `#[derive(Debug)#` because the `u` field
112/// is a bindgen generated union.  Hence this manual realisation.
113impl std::fmt::Debug for ffi::dtv_property {
114    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
115        unsafe {
116            write!(
117                f,
118                "dtv_property{{\
119            cmd: {:?},\
120            reserved: {:?},\
121            u: …,\
122            result: {:?}}}",
123                &self.cmd,
124                &self.reserved,
125                // &self.u, // TODO See how to output the union.
126                &self.result,
127            )
128        }
129    }
130}
131
132/// A manually written implementation of `Debug` for `dvb_entry`.
133///
134/// Bindgen does not mark `dvb_entry` as `#[derive(Debug)#` because the `props` field
135/// is an array of 70 `dtv_property` items.  Hence this manual realisation.
136impl std::fmt::Debug for ffi::dvb_entry {
137    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
138        write!(
139            f,
140            "dvb_entry{{\
141            props: {:?}…,\
142            n_props: {:?},\
143            next: {:?},\
144            service_id: {:?},\
145            video_pid: {:?},\
146            audio_pid: {:?},\
147            other_el_pid: {:?},\
148            video_pid_len: {:?},\
149            audio_pid_len: {:?},\
150            other_el_pid_len: {:?},\
151            channel: {:?},\
152            vchannel: {:?},\
153            location: {:?},\
154            sat_number: {:?},\
155            freq_bpf: {:?},\
156            diseqc_wait: {:?},\
157            lnb: {:?},\
158            network_id: {:?},\
159            transport_id: {:?}}}",
160            &self.props[0..32],
161            &self.n_props,
162            &self.next,
163            &self.service_id,
164            &self.video_pid,
165            &self.audio_pid,
166            &self.other_el_pid,
167            &self.video_pid_len,
168            &self.audio_pid_len,
169            &self.other_el_pid_len,
170            &self.channel,
171            &self.vchannel,
172            &self.location,
173            &self.sat_number,
174            &self.freq_bpf,
175            &self.diseqc_wait,
176            &self.lnb,
177            &self.network_id,
178            &self.transport_id,
179        )
180    }
181}