1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT
use crate::{ffi, FwScode};
use glib::{
prelude::*,
signal::{connect_raw, SignalHandlerId},
translate::*,
};
use std::boxed::Box as Box_;
glib::wrapper! {
/// A set of basic interfaces to listen to events about isochronous resource.
///
/// [`FwIsoResource`][crate::FwIsoResource] includes interfaces to listen to events about allocation and
/// deallocation of isochronous resource.
///
/// ## Properties
///
///
/// #### `generation`
/// Readable
///
/// ## Signals
///
///
/// #### `allocated`
/// Emitted when allocation of isochronous resource finishes.
///
/// Action
///
///
/// #### `deallocated`
/// Emitted when deallocation of isochronous resource finishes.
///
/// Action
///
/// # Implements
///
/// [`FwIsoResourceExt`][trait@crate::prelude::FwIsoResourceExt]
#[doc(alias = "HinokoFwIsoResource")]
pub struct FwIsoResource(Interface<ffi::HinokoFwIsoResource, ffi::HinokoFwIsoResourceInterface>);
match fn {
type_ => || ffi::hinoko_fw_iso_resource_get_type(),
}
}
impl FwIsoResource {
pub const NONE: Option<&'static FwIsoResource> = None;
/// Calculate the amount of bandwidth expected to be consumed in allocation unit
/// by given parameters.
/// ## `bytes_per_payload`
/// The number of bytes in payload of isochronous packet.
/// ## `scode`
/// The speed of transmission.
///
/// # Returns
///
/// The amount of bandwidth expected to be consumed.
#[doc(alias = "hinoko_fw_iso_resource_calculate_bandwidth")]
pub fn calculate_bandwidth(bytes_per_payload: u32, scode: FwScode) -> u32 {
unsafe {
ffi::hinoko_fw_iso_resource_calculate_bandwidth(bytes_per_payload, scode.into_glib())
}
}
}
/// Trait containing all [`struct@FwIsoResource`] methods.
///
/// # Implementors
///
/// [`FwIsoResourceAuto`][struct@crate::FwIsoResourceAuto], [`FwIsoResourceOnce`][struct@crate::FwIsoResourceOnce], [`FwIsoResource`][struct@crate::FwIsoResource]
pub trait FwIsoResourceExt: IsA<FwIsoResource> + 'static {
/// Initiate allocation of isochronous resource without any wait. One of the candidates is actually
/// allocated for channel. When the allocation finishes, [`allocated`][struct@crate::FwIsoResource#allocated] signal is
/// emitted to notify the result, channel, and bandwidth.
/// ## `channel_candidates`
/// The array with elements for
/// numeric number of isochronous channel to be allocated.
/// ## `bandwidth`
/// The amount of bandwidth to be allocated.
///
/// # Returns
///
/// TRUE if the overall operation finishes successfully, otherwise FALSE.
#[doc(alias = "hinoko_fw_iso_resource_allocate")]
fn allocate(&self, channel_candidates: &[u8], bandwidth: u32) -> Result<(), glib::Error> {
let channel_candidates_count = channel_candidates.len() as _;
unsafe {
let mut error = std::ptr::null_mut();
let is_ok = ffi::hinoko_fw_iso_resource_allocate(
self.as_ref().to_glib_none().0,
channel_candidates.to_glib_none().0,
channel_candidates_count,
bandwidth,
&mut error,
);
debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
if error.is_null() {
Ok(())
} else {
Err(from_glib_full(error))
}
}
}
/// Initiate allocation of isochronous resource and wait for [`allocated`][struct@crate::FwIsoResource#allocated]
/// signal. One of the candidates is actually allocated for channel.
/// ## `channel_candidates`
/// The array with elements for
/// numeric number for isochronous channel to be allocated.
/// ## `bandwidth`
/// The amount of bandwidth to be allocated.
/// ## `timeout_ms`
/// The timeout to wait for allocated event.
///
/// # Returns
///
/// TRUE if the overall operation finishes successfully, otherwise FALSE.
#[doc(alias = "hinoko_fw_iso_resource_allocate_wait")]
fn allocate_wait(
&self,
channel_candidates: &[u8],
bandwidth: u32,
timeout_ms: u32,
) -> Result<(), glib::Error> {
let channel_candidates_count = channel_candidates.len() as _;
unsafe {
let mut error = std::ptr::null_mut();
let is_ok = ffi::hinoko_fw_iso_resource_allocate_wait(
self.as_ref().to_glib_none().0,
channel_candidates.to_glib_none().0,
channel_candidates_count,
bandwidth,
timeout_ms,
&mut error,
);
debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
if error.is_null() {
Ok(())
} else {
Err(from_glib_full(error))
}
}
}
/// Create [`glib::Source`][crate::glib::Source] for [`gLib::MainContext`][crate::glib::MainContext]
/// to dispatch events for isochronous resource.
///
/// # Returns
///
/// TRUE if the overall operation finished successfully, otherwise FALSE.
///
/// ## `source`
/// A [`glib::Source`][crate::glib::Source]
#[doc(alias = "hinoko_fw_iso_resource_create_source")]
fn create_source(&self) -> Result<glib::Source, glib::Error> {
unsafe {
let mut source = std::ptr::null_mut();
let mut error = std::ptr::null_mut();
let is_ok = ffi::hinoko_fw_iso_resource_create_source(
self.as_ref().to_glib_none().0,
&mut source,
&mut error,
);
debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
if error.is_null() {
Ok(from_glib_full(source))
} else {
Err(from_glib_full(error))
}
}
}
/// Open Linux FireWire character device to delegate any request for isochronous
/// resource management to Linux FireWire subsystem.
/// ## `path`
/// A path of any Linux FireWire character device.
/// ## `open_flag`
/// The flag of open(2) system call. O_RDONLY is forced to fulfil
/// internally.
///
/// # Returns
///
/// TRUE if the overall operation finished successfully, otherwise FALSE.
#[doc(alias = "hinoko_fw_iso_resource_open")]
fn open(&self, path: &str, open_flag: i32) -> Result<(), glib::Error> {
unsafe {
let mut error = std::ptr::null_mut();
let is_ok = ffi::hinoko_fw_iso_resource_open(
self.as_ref().to_glib_none().0,
path.to_glib_none().0,
open_flag,
&mut error,
);
debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
if error.is_null() {
Ok(())
} else {
Err(from_glib_full(error))
}
}
}
fn generation(&self) -> u32 {
ObjectExt::property(self.as_ref(), "generation")
}
/// Emitted when allocation of isochronous resource finishes.
/// ## `channel`
/// The deallocated channel number.
/// ## `bandwidth`
/// The deallocated amount of bandwidth.
/// ## `error`
/// A [`glib::Error`][crate::glib::Error]. Error can be generated
/// with domain of [`FwIsoResourceError`][crate::FwIsoResourceError] and its EVENT code.
#[doc(alias = "allocated")]
fn connect_allocated<F: Fn(&Self, u32, u32, Option<&glib::Error>) + 'static>(
&self,
f: F,
) -> SignalHandlerId {
unsafe extern "C" fn allocated_trampoline<
P: IsA<FwIsoResource>,
F: Fn(&P, u32, u32, Option<&glib::Error>) + 'static,
>(
this: *mut ffi::HinokoFwIsoResource,
channel: std::ffi::c_uint,
bandwidth: std::ffi::c_uint,
error: *mut glib::ffi::GError,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(
FwIsoResource::from_glib_borrow(this).unsafe_cast_ref(),
channel,
bandwidth,
Option::<glib::Error>::from_glib_borrow(error)
.as_ref()
.as_ref(),
)
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
c"allocated".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
allocated_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
fn emit_allocated(&self, channel: u32, bandwidth: u32, error: Option<&glib::Error>) {
self.emit_by_name::<()>("allocated", &[&channel, &bandwidth, &error]);
}
/// Emitted when deallocation of isochronous resource finishes.
/// ## `channel`
/// The deallocated channel number.
/// ## `bandwidth`
/// The deallocated amount of bandwidth.
/// ## `error`
/// A [`glib::Error`][crate::glib::Error]. Error can be generated
/// with domain of [`FwIsoResourceError`][crate::FwIsoResourceError] and its EVENT code.
#[doc(alias = "deallocated")]
fn connect_deallocated<F: Fn(&Self, u32, u32, Option<&glib::Error>) + 'static>(
&self,
f: F,
) -> SignalHandlerId {
unsafe extern "C" fn deallocated_trampoline<
P: IsA<FwIsoResource>,
F: Fn(&P, u32, u32, Option<&glib::Error>) + 'static,
>(
this: *mut ffi::HinokoFwIsoResource,
channel: std::ffi::c_uint,
bandwidth: std::ffi::c_uint,
error: *mut glib::ffi::GError,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(
FwIsoResource::from_glib_borrow(this).unsafe_cast_ref(),
channel,
bandwidth,
Option::<glib::Error>::from_glib_borrow(error)
.as_ref()
.as_ref(),
)
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
c"deallocated".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
deallocated_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
fn emit_deallocated(&self, channel: u32, bandwidth: u32, error: Option<&glib::Error>) {
self.emit_by_name::<()>("deallocated", &[&channel, &bandwidth, &error]);
}
#[doc(alias = "generation")]
fn connect_generation_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_generation_trampoline<
P: IsA<FwIsoResource>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::HinokoFwIsoResource,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(FwIsoResource::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
c"notify::generation".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_generation_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
impl<O: IsA<FwIsoResource>> FwIsoResourceExt for O {}