alsaseq/auto/user_client.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from
3// from gir-files (https://github.com/gtk-rs/gir-files)
4// DO NOT EDIT
5
6use crate::{
7 ffi, ClientInfo, ClientPool, Event, EventCntr, PortInfo, QueueInfo, QueueTempo, RemoveFilter,
8 SubscribeData,
9};
10use glib::{
11 prelude::*,
12 signal::{connect_raw, SignalHandlerId},
13 translate::*,
14};
15use std::boxed::Box as Box_;
16
17glib::wrapper! {
18 /// A GObject-derived object to express user client.
19 ///
20 /// A [`UserClient`][crate::UserClient] is a GObject-derived object to express user client. Any port can be added
21 /// to the client as destination or source for any event.
22 ///
23 /// When the call of [`UserClientExt::open()`][crate::prelude::UserClientExt::open()] the object maintain file descriptor till object
24 /// destruction. The call of [`UserClientExt::create_source()`][crate::prelude::UserClientExt::create_source()] returns the instance of
25 /// [`glib::Source`][crate::glib::Source]. Once attached to the [`glib::Source`][crate::glib::Source],
26 /// `GLib::MainContext` / `GLib::MainLoop` is available as event dispatcher. The
27 /// [`handle-event`][struct@crate::UserClient#handle-event] signal is emitted in the event dispatcher to notify the
28 /// event. The call of [`UserClientExt::schedule_event()`][crate::prelude::UserClientExt::schedule_event()] schedules event with given parameters.
29 ///
30 /// ## Properties
31 ///
32 ///
33 /// #### `client-id`
34 /// The numeric ID of the client.
35 ///
36 /// Readable
37 ///
38 /// ## Signals
39 ///
40 ///
41 /// #### `handle-event`
42 /// When event occurs, this signal is emit with the instance of object which includes batch of
43 /// of events.
44 ///
45 ///
46 ///
47 /// # Implements
48 ///
49 /// [`UserClientExt`][trait@crate::prelude::UserClientExt], [`UserClientExtManual`][trait@crate::prelude::UserClientExtManual]
50 #[doc(alias = "ALSASeqUserClient")]
51 pub struct UserClient(Object<ffi::ALSASeqUserClient, ffi::ALSASeqUserClientClass>);
52
53 match fn {
54 type_ => || ffi::alsaseq_user_client_get_type(),
55 }
56}
57
58impl UserClient {
59 pub const NONE: Option<&'static UserClient> = None;
60
61 /// Allocate and return an instance of [`UserClient`][crate::UserClient].
62 ///
63 /// # Returns
64 ///
65 /// An instance of [`UserClient`][crate::UserClient].
66 #[doc(alias = "alsaseq_user_client_new")]
67 pub fn new() -> UserClient {
68 unsafe { from_glib_full(ffi::alsaseq_user_client_new()) }
69 }
70}
71
72impl Default for UserClient {
73 fn default() -> Self {
74 Self::new()
75 }
76}
77
78/// Trait containing the part of [`struct@UserClient`] methods.
79///
80/// # Implementors
81///
82/// [`UserClient`][struct@crate::UserClient]
83pub trait UserClientExt: IsA<UserClient> + 'static {
84 /// Allocate [`glib::Source`][crate::glib::Source] structure to handle events from ALSA seq character device. In each
85 /// iteration of `GLib::MainContext`, the `read(2)` system call is exected to dispatch
86 /// sequencer event for [`handle-event`][struct@crate::UserClient#handle-event] signal, according to the result of
87 /// `poll(2)` system call.
88 ///
89 /// # Returns
90 ///
91 /// [`true`] when the overall operation finishes successfully, else [`false`].
92 ///
93 /// ## `gsrc`
94 /// A #GSource to handle events from ALSA seq character device.
95 #[doc(alias = "alsaseq_user_client_create_source")]
96 fn create_source(&self) -> Result<glib::Source, glib::Error> {
97 unsafe {
98 let mut gsrc = std::ptr::null_mut();
99 let mut error = std::ptr::null_mut();
100 let is_ok = ffi::alsaseq_user_client_create_source(
101 self.as_ref().to_glib_none().0,
102 &mut gsrc,
103 &mut error,
104 );
105 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
106 if error.is_null() {
107 Ok(from_glib_full(gsrc))
108 } else {
109 Err(from_glib_full(error))
110 }
111 }
112 }
113
114 /// Delete a port from the client.
115 ///
116 /// The call of function executes `ioctl(2)` system call with `SNDRV_SEQ_IOCTL_DELETE_PORT` command
117 /// for ALSA sequencer character device.
118 /// ## `port_id`
119 /// The numeric ID of port.
120 ///
121 /// # Returns
122 ///
123 /// [`true`] when the overall operation finishes successfully, else [`false`].
124 #[doc(alias = "alsaseq_user_client_delete_port")]
125 fn delete_port(&self, port_id: u8) -> Result<(), glib::Error> {
126 unsafe {
127 let mut error = std::ptr::null_mut();
128 let is_ok = ffi::alsaseq_user_client_delete_port(
129 self.as_ref().to_glib_none().0,
130 port_id,
131 &mut error,
132 );
133 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
134 if error.is_null() {
135 Ok(())
136 } else {
137 Err(from_glib_full(error))
138 }
139 }
140 }
141
142 /// Delete the queue owned by the client.
143 ///
144 /// The call of function executes `ioctl(2)` system call with `SNDRV_SEQ_IOCTL_DELETE_QUEUE` command
145 /// for ALSA sequencer character device.
146 /// ## `queue_id`
147 /// The numeric ID of queue. An entry of [`SpecificQueueId`][crate::SpecificQueueId] is available as well.
148 ///
149 /// # Returns
150 ///
151 /// [`true`] when the overall operation finishes successfully, else [`false`].
152 #[doc(alias = "alsaseq_user_client_delete_queue")]
153 fn delete_queue(&self, queue_id: u8) -> Result<(), glib::Error> {
154 unsafe {
155 let mut error = std::ptr::null_mut();
156 let is_ok = ffi::alsaseq_user_client_delete_queue(
157 self.as_ref().to_glib_none().0,
158 queue_id,
159 &mut error,
160 );
161 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
162 if error.is_null() {
163 Ok(())
164 } else {
165 Err(from_glib_full(error))
166 }
167 }
168 }
169
170 /// Get the data of tempo for the queue.
171 ///
172 /// The call of function executes `ioctl(2)` system call with `SNDRV_SEQ_IOCTL_GET_QUEUE_TEMPO`
173 /// command for ALSA sequencer character device.
174 /// ## `queue_id`
175 /// The numeric ID of queue. An entry of [`SpecificQueueId`][crate::SpecificQueueId] is available as well.
176 ///
177 /// # Returns
178 ///
179 /// [`true`] when the overall operation finishes successfully, else [`false`].
180 ///
181 /// ## `queue_tempo`
182 /// The data of tempo for queue.
183 #[doc(alias = "alsaseq_user_client_get_queue_tempo")]
184 #[doc(alias = "get_queue_tempo")]
185 fn queue_tempo(&self, queue_id: u8) -> Result<QueueTempo, glib::Error> {
186 unsafe {
187 let mut queue_tempo = std::ptr::null_mut();
188 let mut error = std::ptr::null_mut();
189 let is_ok = ffi::alsaseq_user_client_get_queue_tempo(
190 self.as_ref().to_glib_none().0,
191 queue_id,
192 &mut queue_tempo,
193 &mut error,
194 );
195 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
196 if error.is_null() {
197 Ok(from_glib_full(queue_tempo))
198 } else {
199 Err(from_glib_full(error))
200 }
201 }
202 }
203
204 /// Get usage of the queue by the client.
205 ///
206 /// The call of function executes `ioctl(2)` system call with `SNDRV_SEQ_IOCTL_GET_QUEUE_CLIENT`
207 /// command for ALSA sequencer character device.
208 /// ## `queue_id`
209 /// The numeric ID of queue. An entry of [`SpecificQueueId`][crate::SpecificQueueId] is available as well.
210 ///
211 /// # Returns
212 ///
213 /// [`true`] when the overall operation finishes successfully, else [`false`].
214 ///
215 /// ## `use_`
216 /// Whether the client uses the queue or not.
217 #[doc(alias = "alsaseq_user_client_get_queue_usage")]
218 #[doc(alias = "get_queue_usage")]
219 fn queue_usage(&self, queue_id: u8) -> Result<bool, glib::Error> {
220 unsafe {
221 let mut use_ = std::mem::MaybeUninit::uninit();
222 let mut error = std::ptr::null_mut();
223 let is_ok = ffi::alsaseq_user_client_get_queue_usage(
224 self.as_ref().to_glib_none().0,
225 queue_id,
226 use_.as_mut_ptr(),
227 &mut error,
228 );
229 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
230 if error.is_null() {
231 Ok(from_glib(use_.assume_init()))
232 } else {
233 Err(from_glib_full(error))
234 }
235 }
236 }
237
238 /// Open ALSA sequencer character device.
239 ///
240 /// The call of function executes `open(2)` system call, then executes `ioctl(2)` system call with
241 /// `SNDRV_SEQ_IOCTL_CLIENT_ID` command for ALSA sequencer character device.
242 /// ## `open_flag`
243 /// The flag of `open(2)` system call. `O_RDWR` is forced to fulfil internally.
244 ///
245 /// # Returns
246 ///
247 /// [`true`] when the overall operation finishes successfully, else [`false`].
248 #[doc(alias = "alsaseq_user_client_open")]
249 fn open(&self, open_flag: i32) -> Result<(), glib::Error> {
250 unsafe {
251 let mut error = std::ptr::null_mut();
252 let is_ok = ffi::alsaseq_user_client_open(
253 self.as_ref().to_glib_none().0,
254 open_flag,
255 &mut error,
256 );
257 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
258 if error.is_null() {
259 Ok(())
260 } else {
261 Err(from_glib_full(error))
262 }
263 }
264 }
265
266 /// Operate subscription between two ports pointed by the data.
267 ///
268 /// The call of function executes `ioctl(2)` system call with `SNDRV_SEQ_IOCTL_SUBSCRIBE_PORT` and
269 /// `SNDRV_SEQ_IOCTL_UNSUBSCRIBE_PORT` commands for ALSA sequencer character device.
270 /// ## `subs_data`
271 /// A [`SubscribeData`][crate::SubscribeData].
272 /// ## `establish`
273 /// Whether to establish subscription between two ports, or break it.
274 ///
275 /// # Returns
276 ///
277 /// [`true`] when the overall operation finishes successfully, else [`false`].
278 #[doc(alias = "alsaseq_user_client_operate_subscription")]
279 fn operate_subscription(
280 &self,
281 subs_data: &impl IsA<SubscribeData>,
282 establish: bool,
283 ) -> Result<(), glib::Error> {
284 unsafe {
285 let mut error = std::ptr::null_mut();
286 let is_ok = ffi::alsaseq_user_client_operate_subscription(
287 self.as_ref().to_glib_none().0,
288 subs_data.as_ref().to_glib_none().0,
289 establish.into_glib(),
290 &mut error,
291 );
292 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
293 if error.is_null() {
294 Ok(())
295 } else {
296 Err(from_glib_full(error))
297 }
298 }
299 }
300
301 /// Remove queued events according to the filter.
302 ///
303 /// The call of function executes `ioctl(2)` system call with `SNDRV_SEQ_IOCTL_REMOVE_EVENTS`
304 /// command for ALSA sequencer character device.
305 /// ## `filter`
306 /// A [`RemoveFilter`][crate::RemoveFilter].
307 ///
308 /// # Returns
309 ///
310 /// [`true`] when the overall operation finishes successfully, else [`false`].
311 #[doc(alias = "alsaseq_user_client_remove_events")]
312 fn remove_events(&self, filter: &impl IsA<RemoveFilter>) -> Result<(), glib::Error> {
313 unsafe {
314 let mut error = std::ptr::null_mut();
315 let is_ok = ffi::alsaseq_user_client_remove_events(
316 self.as_ref().to_glib_none().0,
317 filter.as_ref().to_glib_none().0,
318 &mut error,
319 );
320 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
321 if error.is_null() {
322 Ok(())
323 } else {
324 Err(from_glib_full(error))
325 }
326 }
327 }
328
329 /// Deliver the event immediately, or schedule it into memory pool of the client.
330 ///
331 /// The call of function executes `write(2)` system call for ALSA sequencer character device. When
332 /// [`output-free`][struct@crate::ClientPool#output-free] is less than [`Event::calculate_pool_consumption()`][crate::Event::calculate_pool_consumption()] and
333 /// [`open()`][Self::open()] is called without non-blocking flag, the user process can be blocked
334 /// untill enough number of cells becomes available.
335 /// ## `event`
336 /// An instance of [`Event`][crate::Event].
337 ///
338 /// # Returns
339 ///
340 /// [`true`] when the overall operation finishes successfully, else [`false`].
341 #[doc(alias = "alsaseq_user_client_schedule_event")]
342 fn schedule_event(&self, event: &Event) -> Result<(), glib::Error> {
343 unsafe {
344 let mut error = std::ptr::null_mut();
345 let is_ok = ffi::alsaseq_user_client_schedule_event(
346 self.as_ref().to_glib_none().0,
347 event.to_glib_none().0,
348 &mut error,
349 );
350 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
351 if error.is_null() {
352 Ok(())
353 } else {
354 Err(from_glib_full(error))
355 }
356 }
357 }
358
359 /// Get client information.
360 ///
361 /// The call of function executes `ioctl(2)` system call with `SNDRV_SEQ_IOCTL_SET_CLIENT_INFO`
362 /// command for ALSA sequencer character device.
363 /// ## `client_info`
364 /// A [`ClientInfo`][crate::ClientInfo].
365 ///
366 /// # Returns
367 ///
368 /// [`true`] when the overall operation finishes successfully, else [`false`].
369 #[doc(alias = "alsaseq_user_client_set_info")]
370 fn set_info(&self, client_info: &impl IsA<ClientInfo>) -> Result<(), glib::Error> {
371 unsafe {
372 let mut error = std::ptr::null_mut();
373 let is_ok = ffi::alsaseq_user_client_set_info(
374 self.as_ref().to_glib_none().0,
375 client_info.as_ref().to_glib_none().0,
376 &mut error,
377 );
378 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
379 if error.is_null() {
380 Ok(())
381 } else {
382 Err(from_glib_full(error))
383 }
384 }
385 }
386
387 /// Configure memory pool in the client.
388 ///
389 /// The call of function executes `ioctl(2)` system call with `SNDRV_SEQ_IOCTL_SET_CLIENT_POOL`
390 /// command for ALSA sequencer character device.
391 /// ## `client_pool`
392 /// A [`ClientPool`][crate::ClientPool] to be configured for the client.
393 ///
394 /// # Returns
395 ///
396 /// [`true`] when the overall operation finishes successfully, else [`false`].
397 #[doc(alias = "alsaseq_user_client_set_pool")]
398 fn set_pool(&self, client_pool: &impl IsA<ClientPool>) -> Result<(), glib::Error> {
399 unsafe {
400 let mut error = std::ptr::null_mut();
401 let is_ok = ffi::alsaseq_user_client_set_pool(
402 self.as_ref().to_glib_none().0,
403 client_pool.as_ref().to_glib_none().0,
404 &mut error,
405 );
406 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
407 if error.is_null() {
408 Ok(())
409 } else {
410 Err(from_glib_full(error))
411 }
412 }
413 }
414
415 /// Set the data of tempo to the queue.
416 ///
417 /// The call of function executes `ioctl(2)` system call with `SNDRV_SEQ_IOCTL_SET_QUEUE_TEMPO`
418 /// command for ALSA sequencer character device.
419 /// ## `queue_id`
420 /// The numeric ID of queue. An entry of [`SpecificQueueId`][crate::SpecificQueueId] is available as well.
421 /// ## `queue_tempo`
422 /// The data of tempo for queue.
423 ///
424 /// # Returns
425 ///
426 /// [`true`] when the overall operation finishes successfully, else [`false`].
427 #[doc(alias = "alsaseq_user_client_set_queue_tempo")]
428 fn set_queue_tempo(
429 &self,
430 queue_id: u8,
431 queue_tempo: &impl IsA<QueueTempo>,
432 ) -> Result<(), glib::Error> {
433 unsafe {
434 let mut error = std::ptr::null_mut();
435 let is_ok = ffi::alsaseq_user_client_set_queue_tempo(
436 self.as_ref().to_glib_none().0,
437 queue_id,
438 queue_tempo.as_ref().to_glib_none().0,
439 &mut error,
440 );
441 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
442 if error.is_null() {
443 Ok(())
444 } else {
445 Err(from_glib_full(error))
446 }
447 }
448 }
449
450 /// Start the queue to use or not.
451 ///
452 /// The call of function executes `ioctl(2)` system call with `SNDRV_SEQ_IOCTL_SET_QUEUE_CLIENT`
453 /// command for ALSA sequencer character device.
454 /// ## `queue_id`
455 /// The numeric ID of queue. An entry of [`SpecificQueueId`][crate::SpecificQueueId] is available as well.
456 /// ## `use_`
457 /// Whether to use the queue or not.
458 ///
459 /// # Returns
460 ///
461 /// [`true`] when the overall operation finishes successfully, else [`false`].
462 #[doc(alias = "alsaseq_user_client_set_queue_usage")]
463 fn set_queue_usage(&self, queue_id: u8, use_: bool) -> Result<(), glib::Error> {
464 unsafe {
465 let mut error = std::ptr::null_mut();
466 let is_ok = ffi::alsaseq_user_client_set_queue_usage(
467 self.as_ref().to_glib_none().0,
468 queue_id,
469 use_.into_glib(),
470 &mut error,
471 );
472 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
473 if error.is_null() {
474 Ok(())
475 } else {
476 Err(from_glib_full(error))
477 }
478 }
479 }
480
481 /// Update port information.
482 ///
483 /// The call of function executes `ioctl(2)` system call with `SNDRV_SEQ_IOCTL_SET_PORT_INFO` command
484 /// for ALSA sequencer character device.
485 /// ## `port_info`
486 /// A [`PortInfo`][crate::PortInfo].
487 /// ## `port_id`
488 /// The numeric ID of port.
489 ///
490 /// # Returns
491 ///
492 /// [`true`] when the overall operation finishes successfully, else [`false`].
493 #[doc(alias = "alsaseq_user_client_update_port")]
494 fn update_port(&self, port_info: &impl IsA<PortInfo>, port_id: u8) -> Result<(), glib::Error> {
495 unsafe {
496 let mut error = std::ptr::null_mut();
497 let is_ok = ffi::alsaseq_user_client_update_port(
498 self.as_ref().to_glib_none().0,
499 port_info.as_ref().to_glib_none().0,
500 port_id,
501 &mut error,
502 );
503 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
504 if error.is_null() {
505 Ok(())
506 } else {
507 Err(from_glib_full(error))
508 }
509 }
510 }
511
512 /// Update owned queue according to the information.
513 ///
514 /// The call of function executes `ioctl(2)` system call with `SNDRV_SEQ_IOCTL_SET_QUEUE_INFO`
515 /// command for ALSA sequencer character device.
516 /// ## `queue_info`
517 /// The information of queue to add.
518 ///
519 /// # Returns
520 ///
521 /// [`true`] when the overall operation finishes successfully, else [`false`].
522 #[doc(alias = "alsaseq_user_client_update_queue")]
523 fn update_queue(&self, queue_info: &impl IsA<QueueInfo>) -> Result<(), glib::Error> {
524 unsafe {
525 let mut error = std::ptr::null_mut();
526 let is_ok = ffi::alsaseq_user_client_update_queue(
527 self.as_ref().to_glib_none().0,
528 queue_info.as_ref().to_glib_none().0,
529 &mut error,
530 );
531 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
532 if error.is_null() {
533 Ok(())
534 } else {
535 Err(from_glib_full(error))
536 }
537 }
538 }
539
540 /// The numeric ID of the client.
541 #[doc(alias = "client-id")]
542 fn client_id(&self) -> u8 {
543 ObjectExt::property(self.as_ref(), "client-id")
544 }
545
546 /// When event occurs, this signal is emit with the instance of object which includes batch of
547 /// of events.
548 /// ## `ev_cntr`
549 /// The instance of [`EventCntr`][crate::EventCntr] which includes batch of events.
550 #[doc(alias = "handle-event")]
551 fn connect_handle_event<F: Fn(&Self, &EventCntr) + 'static>(&self, f: F) -> SignalHandlerId {
552 unsafe extern "C" fn handle_event_trampoline<
553 P: IsA<UserClient>,
554 F: Fn(&P, &EventCntr) + 'static,
555 >(
556 this: *mut ffi::ALSASeqUserClient,
557 ev_cntr: *mut ffi::ALSASeqEventCntr,
558 f: glib::ffi::gpointer,
559 ) {
560 let f: &F = &*(f as *const F);
561 f(
562 UserClient::from_glib_borrow(this).unsafe_cast_ref(),
563 &from_glib_borrow(ev_cntr),
564 )
565 }
566 unsafe {
567 let f: Box_<F> = Box_::new(f);
568 connect_raw(
569 self.as_ptr() as *mut _,
570 c"handle-event".as_ptr() as *const _,
571 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
572 handle_event_trampoline::<Self, F> as *const (),
573 )),
574 Box_::into_raw(f),
575 )
576 }
577 }
578
579 #[doc(alias = "client-id")]
580 fn connect_client_id_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
581 unsafe extern "C" fn notify_client_id_trampoline<
582 P: IsA<UserClient>,
583 F: Fn(&P) + 'static,
584 >(
585 this: *mut ffi::ALSASeqUserClient,
586 _param_spec: glib::ffi::gpointer,
587 f: glib::ffi::gpointer,
588 ) {
589 let f: &F = &*(f as *const F);
590 f(UserClient::from_glib_borrow(this).unsafe_cast_ref())
591 }
592 unsafe {
593 let f: Box_<F> = Box_::new(f);
594 connect_raw(
595 self.as_ptr() as *mut _,
596 c"notify::client-id".as_ptr() as *const _,
597 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
598 notify_client_id_trampoline::<Self, F> as *const (),
599 )),
600 Box_::into_raw(f),
601 )
602 }
603 }
604}
605
606impl<O: IsA<UserClient>> UserClientExt for O {}