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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
// 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, ClientInfo, ClientPool, Event, EventCntr, PortInfo, QueueInfo, QueueTempo, RemoveFilter,
SubscribeData,
};
use glib::{
prelude::*,
signal::{connect_raw, SignalHandlerId},
translate::*,
};
use std::boxed::Box as Box_;
glib::wrapper! {
/// A GObject-derived object to express user client.
///
/// A [`UserClient`][crate::UserClient] is a GObject-derived object to express user client. Any port can be added
/// to the client as destination or source for any event.
///
/// When the call of [`UserClientExt::open()`][crate::prelude::UserClientExt::open()] the object maintain file descriptor till object
/// destruction. The call of [`UserClientExt::create_source()`][crate::prelude::UserClientExt::create_source()] returns the instance of
/// [`glib::Source`][crate::glib::Source]. Once attached to the [`glib::Source`][crate::glib::Source],
/// `GLib::MainContext` / `GLib::MainLoop` is available as event dispatcher. The
/// [`handle-event`][struct@crate::UserClient#handle-event] signal is emitted in the event dispatcher to notify the
/// event. The call of [`UserClientExt::schedule_event()`][crate::prelude::UserClientExt::schedule_event()] schedules event with given parameters.
///
/// ## Properties
///
///
/// #### `client-id`
/// The numeric ID of the client.
///
/// Readable
///
/// ## Signals
///
///
/// #### `handle-event`
/// When event occurs, this signal is emit with the instance of object which includes batch of
/// of events.
///
///
///
/// # Implements
///
/// [`UserClientExt`][trait@crate::prelude::UserClientExt], [`UserClientExtManual`][trait@crate::prelude::UserClientExtManual]
#[doc(alias = "ALSASeqUserClient")]
pub struct UserClient(Object<ffi::ALSASeqUserClient, ffi::ALSASeqUserClientClass>);
match fn {
type_ => || ffi::alsaseq_user_client_get_type(),
}
}
impl UserClient {
pub const NONE: Option<&'static UserClient> = None;
/// Allocate and return an instance of [`UserClient`][crate::UserClient].
///
/// # Returns
///
/// An instance of [`UserClient`][crate::UserClient].
#[doc(alias = "alsaseq_user_client_new")]
pub fn new() -> UserClient {
unsafe { from_glib_full(ffi::alsaseq_user_client_new()) }
}
}
impl Default for UserClient {
fn default() -> Self {
Self::new()
}
}
/// Trait containing the part of [`struct@UserClient`] methods.
///
/// # Implementors
///
/// [`UserClient`][struct@crate::UserClient]
pub trait UserClientExt: IsA<UserClient> + 'static {
/// Allocate [`glib::Source`][crate::glib::Source] structure to handle events from ALSA seq character device. In each
/// iteration of `GLib::MainContext`, the `read(2)` system call is exected to dispatch
/// sequencer event for [`handle-event`][struct@crate::UserClient#handle-event] signal, according to the result of
/// `poll(2)` system call.
///
/// # Returns
///
/// [`true`] when the overall operation finishes successfully, else [`false`].
///
/// ## `gsrc`
/// A #GSource to handle events from ALSA seq character device.
#[doc(alias = "alsaseq_user_client_create_source")]
fn create_source(&self) -> Result<glib::Source, glib::Error> {
unsafe {
let mut gsrc = std::ptr::null_mut();
let mut error = std::ptr::null_mut();
let is_ok = ffi::alsaseq_user_client_create_source(
self.as_ref().to_glib_none().0,
&mut gsrc,
&mut error,
);
debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
if error.is_null() {
Ok(from_glib_full(gsrc))
} else {
Err(from_glib_full(error))
}
}
}
/// Delete a port from the client.
///
/// The call of function executes `ioctl(2)` system call with `SNDRV_SEQ_IOCTL_DELETE_PORT` command
/// for ALSA sequencer character device.
/// ## `port_id`
/// The numeric ID of port.
///
/// # Returns
///
/// [`true`] when the overall operation finishes successfully, else [`false`].
#[doc(alias = "alsaseq_user_client_delete_port")]
fn delete_port(&self, port_id: u8) -> Result<(), glib::Error> {
unsafe {
let mut error = std::ptr::null_mut();
let is_ok = ffi::alsaseq_user_client_delete_port(
self.as_ref().to_glib_none().0,
port_id,
&mut error,
);
debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
if error.is_null() {
Ok(())
} else {
Err(from_glib_full(error))
}
}
}
/// Delete the queue owned by the client.
///
/// The call of function executes `ioctl(2)` system call with `SNDRV_SEQ_IOCTL_DELETE_QUEUE` command
/// for ALSA sequencer character device.
/// ## `queue_id`
/// The numeric ID of queue. An entry of [`SpecificQueueId`][crate::SpecificQueueId] is available as well.
///
/// # Returns
///
/// [`true`] when the overall operation finishes successfully, else [`false`].
#[doc(alias = "alsaseq_user_client_delete_queue")]
fn delete_queue(&self, queue_id: u8) -> Result<(), glib::Error> {
unsafe {
let mut error = std::ptr::null_mut();
let is_ok = ffi::alsaseq_user_client_delete_queue(
self.as_ref().to_glib_none().0,
queue_id,
&mut error,
);
debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
if error.is_null() {
Ok(())
} else {
Err(from_glib_full(error))
}
}
}
/// Get the data of tempo for the queue.
///
/// The call of function executes `ioctl(2)` system call with `SNDRV_SEQ_IOCTL_GET_QUEUE_TEMPO`
/// command for ALSA sequencer character device.
/// ## `queue_id`
/// The numeric ID of queue. An entry of [`SpecificQueueId`][crate::SpecificQueueId] is available as well.
///
/// # Returns
///
/// [`true`] when the overall operation finishes successfully, else [`false`].
///
/// ## `queue_tempo`
/// The data of tempo for queue.
#[doc(alias = "alsaseq_user_client_get_queue_tempo")]
#[doc(alias = "get_queue_tempo")]
fn queue_tempo(&self, queue_id: u8) -> Result<QueueTempo, glib::Error> {
unsafe {
let mut queue_tempo = std::ptr::null_mut();
let mut error = std::ptr::null_mut();
let is_ok = ffi::alsaseq_user_client_get_queue_tempo(
self.as_ref().to_glib_none().0,
queue_id,
&mut queue_tempo,
&mut error,
);
debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
if error.is_null() {
Ok(from_glib_full(queue_tempo))
} else {
Err(from_glib_full(error))
}
}
}
/// Get usage of the queue by the client.
///
/// The call of function executes `ioctl(2)` system call with `SNDRV_SEQ_IOCTL_GET_QUEUE_CLIENT`
/// command for ALSA sequencer character device.
/// ## `queue_id`
/// The numeric ID of queue. An entry of [`SpecificQueueId`][crate::SpecificQueueId] is available as well.
///
/// # Returns
///
/// [`true`] when the overall operation finishes successfully, else [`false`].
///
/// ## `use_`
/// Whether the client uses the queue or not.
#[doc(alias = "alsaseq_user_client_get_queue_usage")]
#[doc(alias = "get_queue_usage")]
fn queue_usage(&self, queue_id: u8) -> Result<bool, glib::Error> {
unsafe {
let mut use_ = std::mem::MaybeUninit::uninit();
let mut error = std::ptr::null_mut();
let is_ok = ffi::alsaseq_user_client_get_queue_usage(
self.as_ref().to_glib_none().0,
queue_id,
use_.as_mut_ptr(),
&mut error,
);
debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
if error.is_null() {
Ok(from_glib(use_.assume_init()))
} else {
Err(from_glib_full(error))
}
}
}
/// Open ALSA sequencer character device.
///
/// The call of function executes `open(2)` system call, then executes `ioctl(2)` system call with
/// `SNDRV_SEQ_IOCTL_CLIENT_ID` command for ALSA sequencer character device.
/// ## `open_flag`
/// The flag of `open(2)` system call. `O_RDWR` is forced to fulfil internally.
///
/// # Returns
///
/// [`true`] when the overall operation finishes successfully, else [`false`].
#[doc(alias = "alsaseq_user_client_open")]
fn open(&self, open_flag: i32) -> Result<(), glib::Error> {
unsafe {
let mut error = std::ptr::null_mut();
let is_ok = ffi::alsaseq_user_client_open(
self.as_ref().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))
}
}
}
/// Operate subscription between two ports pointed by the data.
///
/// The call of function executes `ioctl(2)` system call with `SNDRV_SEQ_IOCTL_SUBSCRIBE_PORT` and
/// `SNDRV_SEQ_IOCTL_UNSUBSCRIBE_PORT` commands for ALSA sequencer character device.
/// ## `subs_data`
/// A [`SubscribeData`][crate::SubscribeData].
/// ## `establish`
/// Whether to establish subscription between two ports, or break it.
///
/// # Returns
///
/// [`true`] when the overall operation finishes successfully, else [`false`].
#[doc(alias = "alsaseq_user_client_operate_subscription")]
fn operate_subscription(
&self,
subs_data: &impl IsA<SubscribeData>,
establish: bool,
) -> Result<(), glib::Error> {
unsafe {
let mut error = std::ptr::null_mut();
let is_ok = ffi::alsaseq_user_client_operate_subscription(
self.as_ref().to_glib_none().0,
subs_data.as_ref().to_glib_none().0,
establish.into_glib(),
&mut error,
);
debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
if error.is_null() {
Ok(())
} else {
Err(from_glib_full(error))
}
}
}
/// Remove queued events according to the filter.
///
/// The call of function executes `ioctl(2)` system call with `SNDRV_SEQ_IOCTL_REMOVE_EVENTS`
/// command for ALSA sequencer character device.
/// ## `filter`
/// A [`RemoveFilter`][crate::RemoveFilter].
///
/// # Returns
///
/// [`true`] when the overall operation finishes successfully, else [`false`].
#[doc(alias = "alsaseq_user_client_remove_events")]
fn remove_events(&self, filter: &impl IsA<RemoveFilter>) -> Result<(), glib::Error> {
unsafe {
let mut error = std::ptr::null_mut();
let is_ok = ffi::alsaseq_user_client_remove_events(
self.as_ref().to_glib_none().0,
filter.as_ref().to_glib_none().0,
&mut error,
);
debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
if error.is_null() {
Ok(())
} else {
Err(from_glib_full(error))
}
}
}
/// Deliver the event immediately, or schedule it into memory pool of the client.
///
/// The call of function executes `write(2)` system call for ALSA sequencer character device. When
/// [`output-free`][struct@crate::ClientPool#output-free] is less than [`Event::calculate_pool_consumption()`][crate::Event::calculate_pool_consumption()] and
/// [`open()`][Self::open()] is called without non-blocking flag, the user process can be blocked
/// untill enough number of cells becomes available.
/// ## `event`
/// An instance of [`Event`][crate::Event].
///
/// # Returns
///
/// [`true`] when the overall operation finishes successfully, else [`false`].
#[doc(alias = "alsaseq_user_client_schedule_event")]
fn schedule_event(&self, event: &Event) -> Result<(), glib::Error> {
unsafe {
let mut error = std::ptr::null_mut();
let is_ok = ffi::alsaseq_user_client_schedule_event(
self.as_ref().to_glib_none().0,
event.to_glib_none().0,
&mut error,
);
debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
if error.is_null() {
Ok(())
} else {
Err(from_glib_full(error))
}
}
}
/// Get client information.
///
/// The call of function executes `ioctl(2)` system call with `SNDRV_SEQ_IOCTL_SET_CLIENT_INFO`
/// command for ALSA sequencer character device.
/// ## `client_info`
/// A [`ClientInfo`][crate::ClientInfo].
///
/// # Returns
///
/// [`true`] when the overall operation finishes successfully, else [`false`].
#[doc(alias = "alsaseq_user_client_set_info")]
fn set_info(&self, client_info: &impl IsA<ClientInfo>) -> Result<(), glib::Error> {
unsafe {
let mut error = std::ptr::null_mut();
let is_ok = ffi::alsaseq_user_client_set_info(
self.as_ref().to_glib_none().0,
client_info.as_ref().to_glib_none().0,
&mut error,
);
debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
if error.is_null() {
Ok(())
} else {
Err(from_glib_full(error))
}
}
}
/// Configure memory pool in the client.
///
/// The call of function executes `ioctl(2)` system call with `SNDRV_SEQ_IOCTL_SET_CLIENT_POOL`
/// command for ALSA sequencer character device.
/// ## `client_pool`
/// A [`ClientPool`][crate::ClientPool] to be configured for the client.
///
/// # Returns
///
/// [`true`] when the overall operation finishes successfully, else [`false`].
#[doc(alias = "alsaseq_user_client_set_pool")]
fn set_pool(&self, client_pool: &impl IsA<ClientPool>) -> Result<(), glib::Error> {
unsafe {
let mut error = std::ptr::null_mut();
let is_ok = ffi::alsaseq_user_client_set_pool(
self.as_ref().to_glib_none().0,
client_pool.as_ref().to_glib_none().0,
&mut error,
);
debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
if error.is_null() {
Ok(())
} else {
Err(from_glib_full(error))
}
}
}
/// Set the data of tempo to the queue.
///
/// The call of function executes `ioctl(2)` system call with `SNDRV_SEQ_IOCTL_SET_QUEUE_TEMPO`
/// command for ALSA sequencer character device.
/// ## `queue_id`
/// The numeric ID of queue. An entry of [`SpecificQueueId`][crate::SpecificQueueId] is available as well.
/// ## `queue_tempo`
/// The data of tempo for queue.
///
/// # Returns
///
/// [`true`] when the overall operation finishes successfully, else [`false`].
#[doc(alias = "alsaseq_user_client_set_queue_tempo")]
fn set_queue_tempo(
&self,
queue_id: u8,
queue_tempo: &impl IsA<QueueTempo>,
) -> Result<(), glib::Error> {
unsafe {
let mut error = std::ptr::null_mut();
let is_ok = ffi::alsaseq_user_client_set_queue_tempo(
self.as_ref().to_glib_none().0,
queue_id,
queue_tempo.as_ref().to_glib_none().0,
&mut error,
);
debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
if error.is_null() {
Ok(())
} else {
Err(from_glib_full(error))
}
}
}
/// Start the queue to use or not.
///
/// The call of function executes `ioctl(2)` system call with `SNDRV_SEQ_IOCTL_SET_QUEUE_CLIENT`
/// command for ALSA sequencer character device.
/// ## `queue_id`
/// The numeric ID of queue. An entry of [`SpecificQueueId`][crate::SpecificQueueId] is available as well.
/// ## `use_`
/// Whether to use the queue or not.
///
/// # Returns
///
/// [`true`] when the overall operation finishes successfully, else [`false`].
#[doc(alias = "alsaseq_user_client_set_queue_usage")]
fn set_queue_usage(&self, queue_id: u8, use_: bool) -> Result<(), glib::Error> {
unsafe {
let mut error = std::ptr::null_mut();
let is_ok = ffi::alsaseq_user_client_set_queue_usage(
self.as_ref().to_glib_none().0,
queue_id,
use_.into_glib(),
&mut error,
);
debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
if error.is_null() {
Ok(())
} else {
Err(from_glib_full(error))
}
}
}
/// Update port information.
///
/// The call of function executes `ioctl(2)` system call with `SNDRV_SEQ_IOCTL_SET_PORT_INFO` command
/// for ALSA sequencer character device.
/// ## `port_info`
/// A [`PortInfo`][crate::PortInfo].
/// ## `port_id`
/// The numeric ID of port.
///
/// # Returns
///
/// [`true`] when the overall operation finishes successfully, else [`false`].
#[doc(alias = "alsaseq_user_client_update_port")]
fn update_port(&self, port_info: &impl IsA<PortInfo>, port_id: u8) -> Result<(), glib::Error> {
unsafe {
let mut error = std::ptr::null_mut();
let is_ok = ffi::alsaseq_user_client_update_port(
self.as_ref().to_glib_none().0,
port_info.as_ref().to_glib_none().0,
port_id,
&mut error,
);
debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
if error.is_null() {
Ok(())
} else {
Err(from_glib_full(error))
}
}
}
/// Update owned queue according to the information.
///
/// The call of function executes `ioctl(2)` system call with `SNDRV_SEQ_IOCTL_SET_QUEUE_INFO`
/// command for ALSA sequencer character device.
/// ## `queue_info`
/// The information of queue to add.
///
/// # Returns
///
/// [`true`] when the overall operation finishes successfully, else [`false`].
#[doc(alias = "alsaseq_user_client_update_queue")]
fn update_queue(&self, queue_info: &impl IsA<QueueInfo>) -> Result<(), glib::Error> {
unsafe {
let mut error = std::ptr::null_mut();
let is_ok = ffi::alsaseq_user_client_update_queue(
self.as_ref().to_glib_none().0,
queue_info.as_ref().to_glib_none().0,
&mut error,
);
debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
if error.is_null() {
Ok(())
} else {
Err(from_glib_full(error))
}
}
}
/// The numeric ID of the client.
#[doc(alias = "client-id")]
fn client_id(&self) -> u8 {
ObjectExt::property(self.as_ref(), "client-id")
}
/// When event occurs, this signal is emit with the instance of object which includes batch of
/// of events.
/// ## `ev_cntr`
/// The instance of [`EventCntr`][crate::EventCntr] which includes batch of events.
#[doc(alias = "handle-event")]
fn connect_handle_event<F: Fn(&Self, &EventCntr) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn handle_event_trampoline<
P: IsA<UserClient>,
F: Fn(&P, &EventCntr) + 'static,
>(
this: *mut ffi::ALSASeqUserClient,
ev_cntr: *mut ffi::ALSASeqEventCntr,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(
UserClient::from_glib_borrow(this).unsafe_cast_ref(),
&from_glib_borrow(ev_cntr),
)
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
c"handle-event".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
handle_event_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "client-id")]
fn connect_client_id_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_client_id_trampoline<
P: IsA<UserClient>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::ALSASeqUserClient,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(UserClient::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
c"notify::client-id".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_client_id_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
impl<O: IsA<UserClient>> UserClientExt for O {}