diff options
author | Takashi Sakamoto <o-takashi@sakamocchi.jp> | 2023-08-03 22:07:38 +0900 |
---|---|---|
committer | Takashi Sakamoto <o-takashi@sakamocchi.jp> | 2023-08-03 22:07:38 +0900 |
commit | 02e0b53c0bea858822030cb1300e1af8b40bdce9 (patch) | |
tree | 09f71d488b422501d10453cdc5da3a5faeb07137 | |
parent | b2a0b4b7ff87511253354c35e015414a24f02a9f (diff) | |
download | hinawa-rs-02e0b53c0bea858822030cb1300e1af8b40bdce9.tar.gz |
hinawa: regenerate crate
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
-rw-r--r-- | hinawa/README.md | 4 | ||||
-rw-r--r-- | hinawa/examples/read-quadlet.rs | 2 | ||||
-rw-r--r-- | hinawa/src/auto/cycle_time.rs | 2 | ||||
-rw-r--r-- | hinawa/src/auto/enums.rs | 16 | ||||
-rw-r--r-- | hinawa/src/auto/fw_fcp.rs | 22 | ||||
-rw-r--r-- | hinawa/src/auto/fw_node.rs | 67 | ||||
-rw-r--r-- | hinawa/src/auto/fw_req.rs | 9 | ||||
-rw-r--r-- | hinawa/src/auto/fw_resp.rs | 47 | ||||
-rw-r--r-- | hinawa/src/cycle_time.rs | 4 | ||||
-rw-r--r-- | hinawa/src/fw_fcp.rs | 115 | ||||
-rw-r--r-- | hinawa/src/fw_node.rs | 10 | ||||
-rw-r--r-- | hinawa/src/fw_req.rs | 198 | ||||
-rw-r--r-- | hinawa/src/fw_resp.rs | 76 | ||||
-rw-r--r-- | hinawa/src/subclass/fw_fcp.rs | 47 | ||||
-rw-r--r-- | hinawa/src/subclass/fw_req.rs | 52 | ||||
-rw-r--r-- | hinawa/src/subclass/fw_resp.rs | 101 |
16 files changed, 231 insertions, 541 deletions
diff --git a/hinawa/README.md b/hinawa/README.md index 5d81022..b0514db 100644 --- a/hinawa/README.md +++ b/hinawa/README.md @@ -4,10 +4,10 @@ Rust API bindings and wrappers for [hinawa library](https://git.kernel.org/pub/scm/libs/ieee1394/libhinawa.git/) to operate OHCI 1394 hardware via Linux FireWire character device for asynchronous communication in IEEE 1394 bus. -The hinawa library version 2.6 is the minimum supported version for underlying library. +The hinawa library version 4.0 is the minimum supported version for underlying library. The hinawa crate is automatically generated by [gir tool](https://gtk-rs.org/gir/book/) provided -by [gtk-rs project](https://gtk-rs.org/). Hinawa-3.0 file from hinawa library is used for the +by [gtk-rs project](https://gtk-rs.org/). Hinawa-4.0 file from hinawa library is used for the generation. But some functions are implemented manually. ## Usage diff --git a/hinawa/examples/read-quadlet.rs b/hinawa/examples/read-quadlet.rs index f42415e..8d4bdf0 100644 --- a/hinawa/examples/read-quadlet.rs +++ b/hinawa/examples/read-quadlet.rs @@ -7,7 +7,7 @@ const OFFSET: u64 = 0xfffff0000404; fn main() { let node = FwNode::new(); - node.open(PATH).unwrap(); + node.open(PATH, 0).unwrap(); let ctx = MainContext::new(); let src = node.create_source().unwrap(); diff --git a/hinawa/src/auto/cycle_time.rs b/hinawa/src/auto/cycle_time.rs index a03e4ef..172f819 100644 --- a/hinawa/src/auto/cycle_time.rs +++ b/hinawa/src/auto/cycle_time.rs @@ -51,7 +51,7 @@ impl CycleTime { } } - /// Get the value of cycle time in 1394 OHCI controller. + /// Get the value of cycle time in 1394 OHCI hardware. /// /// # Returns /// diff --git a/hinawa/src/auto/enums.rs b/hinawa/src/auto/enums.rs index 9c954a2..52abc15 100644 --- a/hinawa/src/auto/enums.rs +++ b/hinawa/src/auto/enums.rs @@ -12,7 +12,7 @@ use glib::StaticType; use glib::Type; use std::fmt; -/// A set of error code for [`glib::Error`][crate::glib::Error] with domain which equals to Hinawa.FwFcpError. +/// A set of error code for [`glib::Error`][crate::glib::Error] for operations in [`FwFcp`][crate::FwFcp]. #[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)] #[non_exhaustive] #[doc(alias = "HinawaFwFcpError")] @@ -23,6 +23,8 @@ pub enum FwFcpError { /// The size of response is larger than expected. #[doc(alias = "HINAWA_FW_FCP_ERROR_LARGE_RESP")] LargeResp, + #[doc(alias = "HINAWA_FW_FCP_ERROR_ABORTED")] + Aborted, #[doc(hidden)] __Unknown(i32), } @@ -35,6 +37,7 @@ impl fmt::Display for FwFcpError { match *self { Self::Timeout => "Timeout", Self::LargeResp => "LargeResp", + Self::Aborted => "Aborted", _ => "Unknown", } ) @@ -49,6 +52,7 @@ impl IntoGlib for FwFcpError { match self { Self::Timeout => ffi::HINAWA_FW_FCP_ERROR_TIMEOUT, Self::LargeResp => ffi::HINAWA_FW_FCP_ERROR_LARGE_RESP, + Self::Aborted => ffi::HINAWA_FW_FCP_ERROR_ABORTED, Self::__Unknown(value) => value, } } @@ -60,6 +64,7 @@ impl FromGlib<ffi::HinawaFwFcpError> for FwFcpError { match value { ffi::HINAWA_FW_FCP_ERROR_TIMEOUT => Self::Timeout, ffi::HINAWA_FW_FCP_ERROR_LARGE_RESP => Self::LargeResp, + ffi::HINAWA_FW_FCP_ERROR_ABORTED => Self::Aborted, value => Self::__Unknown(value), } } @@ -78,6 +83,7 @@ impl ErrorDomain for FwFcpError { match code { ffi::HINAWA_FW_FCP_ERROR_TIMEOUT => Some(Self::Timeout), ffi::HINAWA_FW_FCP_ERROR_LARGE_RESP => Some(Self::LargeResp), + ffi::HINAWA_FW_FCP_ERROR_ABORTED => Some(Self::Aborted), value => Some(Self::__Unknown(value)), } } @@ -115,7 +121,7 @@ impl ToValue for FwFcpError { } } -/// A set of error code for [`glib::Error`][crate::glib::Error] with domain which equals to Hinawa.FwNodeError. +/// A set of error code for [`glib::Error`][crate::glib::Error] for operations in [`FwNode`][crate::FwNode]. #[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)] #[non_exhaustive] #[doc(alias = "HinawaFwNodeError")] @@ -371,8 +377,8 @@ impl ToValue for FwRcode { } } -/// A set of error code for [`FwReq`][crate::FwReq]. Each of them has the same value as the -/// corresponding enumeration in [`FwRcode`][crate::FwRcode]. +/// A set of error code for [`glib::Error`][crate::glib::Error] for operations in [`FwReq`][crate::FwReq]. +/// The actual value is equivalent to [`FwRcode`][crate::FwRcode]. #[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)] #[non_exhaustive] #[doc(alias = "HinawaFwReqError")] @@ -531,7 +537,7 @@ impl ToValue for FwReqError { } } -/// A set of error code for [`glib::Error`][crate::glib::Error] with domain which equals to Hinawa.FwRespError. +/// A set of error code for [`glib::Error`][crate::glib::Error] for operations in [`FwResp`][crate::FwResp]. #[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)] #[non_exhaustive] #[doc(alias = "HinawaFwRespError")] diff --git a/hinawa/src/auto/fw_fcp.rs b/hinawa/src/auto/fw_fcp.rs index 025662c..60cf92f 100644 --- a/hinawa/src/auto/fw_fcp.rs +++ b/hinawa/src/auto/fw_fcp.rs @@ -17,13 +17,13 @@ use std::ptr; glib::wrapper! { /// A FCP transaction executor to node in IEEE 1394 bus. + /// [`FwFcp`][crate::FwFcp] supports Function Control Protocol (FCP) in IEC 61883-1. FCP transaction consists + /// of a pair of asynchronous transactions for command and response, while the protocol has no + /// mechanism to match them. In AV/C Digital Interface Command Set General Specification Version 4.2 + /// (Sep 1 2004, 1394TA), they are loosely matched by the content of their frames, and this class + /// employs the way. /// - /// A HinawaFwFcp supports Function Control Protocol (FCP) in IEC 61883-1, in which no way is defined - /// to match response against command by the contents of frames. In 'AV/C Digital Interface Command - /// Set General Specification Version 4.2' (Sep 1 2004, 1394TA), a pair of command and response is - /// loosely matched by the contents of frames. - /// - /// Any of transaction frames should be aligned to 8bit (byte). This class is an application of + /// Any of transaction frames should be aligned to 8 bit (1 byte). This class is an application of /// [`FwReq`][crate::FwReq] / [`FwResp`][crate::FwResp]. /// /// # Implements @@ -66,6 +66,10 @@ pub trait FwFcpExt: 'static { /// Start to listen to FCP responses. /// ## `node` /// A [`FwNode`][crate::FwNode]. + /// + /// # Returns + /// + /// TRUE if the overall operation finishes successfully, otherwise FALSE. #[doc(alias = "hinawa_fw_fcp_bind")] fn bind(&self, node: &impl IsA<FwNode>) -> Result<(), glib::Error>; @@ -76,10 +80,14 @@ pub trait FwFcpExt: 'static { /// argument should point to the array and immutable. /// ## `timeout_ms` /// The timeout to wait for response subaction of transaction for command frame. + /// + /// # Returns + /// + /// TRUE if the overall operation finishes successfully, otherwise FALSE. #[doc(alias = "hinawa_fw_fcp_command")] fn command(&self, cmd: &[u8], timeout_ms: u32) -> Result<(), glib::Error>; - /// Stop to listen to FCP responses. + /// Stop to listen to FCP responses. Any pending transactions are forced to be aborted. #[doc(alias = "hinawa_fw_fcp_unbind")] fn unbind(&self); diff --git a/hinawa/src/auto/fw_node.rs b/hinawa/src/auto/fw_node.rs index c139b54..a4a3201 100644 --- a/hinawa/src/auto/fw_node.rs +++ b/hinawa/src/auto/fw_node.rs @@ -14,11 +14,9 @@ use std::mem::transmute; use std::ptr; glib::wrapper! { - /// An event listener for FireWire node - /// - /// A [`FwNode`][crate::FwNode] is an event listener for a specified node on IEEE 1394 bus. This class is an - /// application of Linux FireWire subsystem. All of operations utilize ioctl(2) with subsystem - /// specific request commands. + /// An event listener for node in IEEE 1394 bus. + /// [`FwNode`][crate::FwNode] listens to any events for an associated node in IEEE 1394 bus. Additionally, + /// it provides some methods to retrieve fundamental information about the bus. /// /// # Implements /// @@ -61,20 +59,35 @@ pub trait FwNodeExt: 'static { /// IEEE 1394 bus. /// /// # Returns + /// + /// TRUE if the overall operation finishes successfully, otherwise FALSE. + /// + /// ## `gsrc` /// A [`glib::Source`][crate::glib::Source]. #[doc(alias = "hinawa_fw_node_create_source")] fn create_source(&self) -> Result<glib::Source, glib::Error>; - /// Open Linux FireWire character device to operate node on IEEE 1394 bus. + /// Open Linux FireWire character device to operate node in IEEE 1394 bus. /// ## `path` /// A path to Linux FireWire character device + /// ## `open_flag` + /// The flag of `open(2)` system call. `O_RDONLY` is fulfilled internally. + /// + /// # Returns + /// + /// TRUE if the overall operation finishes successfully, otherwise FALSE. #[doc(alias = "hinawa_fw_node_open")] - fn open(&self, path: &str) -> Result<(), glib::Error>; + fn open(&self, path: &str, open_flag: i32) -> Result<(), glib::Error>; /// Node ID of node which plays role of bus manager at current generation of bus topology. #[doc(alias = "bus-manager-node-id")] fn bus_manager_node_id(&self) -> u32; + /// The numeric index for 1394 OHCI hardware used for the communication with the node. The + /// value is stable against bus generation. + #[doc(alias = "card-id")] + fn card_id(&self) -> u32; + /// Current generation of bus topology. fn generation(&self) -> u32; @@ -84,7 +97,7 @@ pub trait FwNodeExt: 'static { fn ir_manager_node_id(&self) -> u32; /// Node ID of node which application uses to communicate to node associated to instance of - /// object at current generation of bus topology. In general, it is for 1394 OHCI controller. + /// object at current generation of bus topology. In general, it is for 1394 OHCI hardware. #[doc(alias = "local-node-id")] fn local_node_id(&self) -> u32; @@ -93,7 +106,7 @@ pub trait FwNodeExt: 'static { #[doc(alias = "node-id")] fn node_id(&self) -> u32; - /// Node ID of root node in bus topology at current generation of the bus topology. + /// Node ID of root node in bus topology at current generation of bus topology. #[doc(alias = "root-node-id")] fn root_node_id(&self) -> u32; @@ -102,14 +115,17 @@ pub trait FwNodeExt: 'static { #[doc(alias = "bus-update")] fn connect_bus_update<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId; - /// Emitted when the node is not available anymore due to removal from IEEE 1394 bus. It's - /// preferable to call `GObject::Object::unref()` immediately to release file descriptor. + /// Emitted when the node is not available anymore in Linux system. It's preferable to call + /// `GObject::Object::unref()` immediately to release file descriptor. #[doc(alias = "disconnected")] fn connect_disconnected<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId; #[doc(alias = "bus-manager-node-id")] fn connect_bus_manager_node_id_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId; + #[doc(alias = "card-id")] + fn connect_card_id_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId; + #[doc(alias = "generation")] fn connect_generation_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId; @@ -144,12 +160,13 @@ impl<O: IsA<FwNode>> FwNodeExt for O { } } - fn open(&self, path: &str) -> Result<(), glib::Error> { + fn open(&self, path: &str, open_flag: i32) -> Result<(), glib::Error> { unsafe { let mut error = ptr::null_mut(); let _ = ffi::hinawa_fw_node_open( self.as_ref().to_glib_none().0, path.to_glib_none().0, + open_flag, &mut error, ); if error.is_null() { @@ -164,6 +181,10 @@ impl<O: IsA<FwNode>> FwNodeExt for O { glib::ObjectExt::property(self.as_ref(), "bus-manager-node-id") } + fn card_id(&self) -> u32 { + glib::ObjectExt::property(self.as_ref(), "card-id") + } + fn generation(&self) -> u32 { glib::ObjectExt::property(self.as_ref(), "generation") } @@ -251,6 +272,28 @@ impl<O: IsA<FwNode>> FwNodeExt for O { } } + fn connect_card_id_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId { + unsafe extern "C" fn notify_card_id_trampoline<P: IsA<FwNode>, F: Fn(&P) + 'static>( + this: *mut ffi::HinawaFwNode, + _param_spec: glib::ffi::gpointer, + f: glib::ffi::gpointer, + ) { + let f: &F = &*(f as *const F); + f(FwNode::from_glib_borrow(this).unsafe_cast_ref()) + } + unsafe { + let f: Box_<F> = Box_::new(f); + connect_raw( + self.as_ptr() as *mut _, + b"notify::card-id\0".as_ptr() as *const _, + Some(transmute::<_, unsafe extern "C" fn()>( + notify_card_id_trampoline::<Self, F> as *const (), + )), + Box_::into_raw(f), + ) + } + } + fn connect_generation_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId { unsafe extern "C" fn notify_generation_trampoline<P: IsA<FwNode>, F: Fn(&P) + 'static>( this: *mut ffi::HinawaFwNode, diff --git a/hinawa/src/auto/fw_req.rs b/hinawa/src/auto/fw_req.rs index 3471c25..de3a3aa 100644 --- a/hinawa/src/auto/fw_req.rs +++ b/hinawa/src/auto/fw_req.rs @@ -7,13 +7,8 @@ use glib::translate::*; use std::fmt; glib::wrapper! { - /// A transaction executor to a FireWire unit. - /// - /// A HinawaFwReq supports some types of transactions in IEEE 1212. Mainly for read, write and lock - /// operations. - /// - /// This class is an application of Linux FireWire subsystem. All of operations utilize ioctl(2) - /// with subsystem specific request commands. + /// A transaction executor to a node in IEEE 1394 bus. + /// [`FwReq`][crate::FwReq] supports all types of transactions defiend in IEEE 1212. /// /// # Implements /// diff --git a/hinawa/src/auto/fw_resp.rs b/hinawa/src/auto/fw_resp.rs index 239c13a..be3509f 100644 --- a/hinawa/src/auto/fw_resp.rs +++ b/hinawa/src/auto/fw_resp.rs @@ -15,12 +15,8 @@ use std::mem::transmute; use std::ptr; glib::wrapper! { - /// A transaction responder for request initiated by node in IEEE 1394 bus. - /// - /// The [`FwResp`][crate::FwResp] responds transaction initiated by node in IEEE 1394 bus. - /// - /// This class is an application of Linux FireWire subsystem. All of operations utilize ioctl(2) - /// with subsystem specific request commands. + /// A transaction responder for request subaction initiated by node in IEEE 1394 bus. + /// [`FwResp`][crate::FwResp] responds to request subaction initiated by node in IEEE 1394 bus. /// /// # Implements /// @@ -59,25 +55,36 @@ impl Default for FwResp { /// /// [`FwFcp`][struct@crate::FwFcp], [`FwResp`][struct@crate::FwResp] pub trait FwRespExt: 'static { - /// stop to listen to a range of address in local node (e.g. OHCI 1394 controller). + /// Stop listening to the address range in Linux system for local nodes. #[doc(alias = "hinawa_fw_resp_release")] fn release(&self); - /// Start to listen to a range of address in host controller which connects to the node. The function - /// is a variant of [`reserve_within_region()`][Self::reserve_within_region()] so that the exact range of address should - /// be reserved as given. + /// Allocate an address range within Linux system for local nodes, each of which expresses 1394 + /// OHCI hardware. Once successful, `signal::FwResp::requested` signal will be emitted whenever any + /// request subactions arrive at the 1394 OHCI hardware within the dedicated range. + /// + /// The range is precisely reserved at the address specified by @addr with the size indicated by + /// @width. In essence, this function is a variant of [`reserve_within_region()`][Self::reserve_within_region()] in + /// which the specified address range is reserved as provided. /// ## `node` /// A [`FwNode`][crate::FwNode]. /// ## `addr` - /// A start address to listen to in host controller. + /// A start address to listen to in 1394 OHCI hardware. /// ## `width` - /// The byte width of address to listen to host controller. + /// The byte width of address to listen to 1394 OHCI hardware. + /// + /// # Returns + /// + /// TRUE if the overall operation finishes successfully, otherwise FALSE. #[doc(alias = "hinawa_fw_resp_reserve")] fn reserve(&self, node: &impl IsA<FwNode>, addr: u64, width: u32) -> Result<(), glib::Error>; - /// Start to listen to range of address equals to #width in local node (e.g. 1394 OHCI host - /// controller), which is used to communicate to the node given as parameter. The range of address - /// is looked up in region between region_start and region_end. + /// Allocate an address range within Linux system for local nodes, each of which expresses 1394 + /// OHCI hardware. Once successful, `signal::FwResp::requested` signal will be emitted whenever any + /// request subactions arrive at the 1394 OHCI hardware within the dedicated range. + /// + /// The range is reserved between the values specified by @region_start and @region_end with the size + /// indicated by @width. The starting offset may vary every time. /// ## `node` /// A [`FwNode`][crate::FwNode]. /// ## `region_start` @@ -86,6 +93,10 @@ pub trait FwRespExt: 'static { /// End offset of address region in which range of address is looked up. /// ## `width` /// The width for range of address to be looked up. + /// + /// # Returns + /// + /// TRUE if the overall operation finishes successfully, otherwise FALSE. #[doc(alias = "hinawa_fw_resp_reserve_within_region")] fn reserve_within_region( &self, @@ -95,13 +106,13 @@ pub trait FwRespExt: 'static { width: u32, ) -> Result<(), glib::Error>; - /// Register byte frame as response. + /// Register byte frame for the response subaction of transaction. /// ## `frame` - /// a 8bit array for response frame. + /// a 8 bit array for response frame. #[doc(alias = "hinawa_fw_resp_set_resp_frame")] fn set_resp_frame(&self, frame: &[u8]); - /// Whether a range of address is reserved or not in host controller. + /// Whether a range of address is reserved or not. #[doc(alias = "is-reserved")] fn is_reserved(&self) -> bool; diff --git a/hinawa/src/cycle_time.rs b/hinawa/src/cycle_time.rs index 2806eea..f46740c 100644 --- a/hinawa/src/cycle_time.rs +++ b/hinawa/src/cycle_time.rs @@ -2,7 +2,7 @@ use crate::*; impl CycleTime { - /// Get the value of cycle time in 1394 OHCI controller. The first element of array expresses the + /// Get the value of cycle time in 1394 OHCI hardware. The first element of array expresses the /// value of sec field, up to 127. The second element of array expresses the value of cycle field, /// up to 7999. The third element of array expresses the value of offset field, up to 3071. /// @@ -11,7 +11,7 @@ impl CycleTime { /// /// ## `fields` /// The value of cycle time register of 1394 - /// OHCI, including three elements; second, cycle, and offset in its order. + /// OHCI hardware, including three elements; second, cycle, and offset in its order. #[doc(alias = "hinawa_cycle_time_get_fields")] pub fn fields(&mut self) -> [u16; 3] { let mut fields = [0; 3]; diff --git a/hinawa/src/fw_fcp.rs b/hinawa/src/fw_fcp.rs index f345acf..a178689 100644 --- a/hinawa/src/fw_fcp.rs +++ b/hinawa/src/fw_fcp.rs @@ -15,7 +15,7 @@ pub trait FwFcpExtManual { /// /// If the version of kernel ABI for Linux FireWire subsystem is less than 6, each element of @tstamp /// has invalid value (=G_MAXUINT16). - /// ## `cmd_frame` + /// ## `cmd` /// An array with elements for request byte data. The value of this /// argument should point to the array and immutable. /// ## `timeout_ms` @@ -23,8 +23,6 @@ pub trait FwFcpExtManual { /// /// # Returns /// - /// TRUE if the overall operation finishes successfully, otherwise FALSE. - /// /// ## `tstamp` /// The array with two elements for time stamps. /// The first element is for the isochronous cycle at which the request arrived. The second @@ -36,47 +34,36 @@ pub trait FwFcpExtManual { timeout_ms: u32, ) -> Result<[u32; 2], glib::Error>; - /// Finish the pair of asynchronous transaction for AV/C command and response transactions. The - /// timeout_ms parameter is used to wait for response transaction since the command transaction - /// is initiated, ignoring [property@FwFcp:timeout] property of instance. The timeout is not - /// expanded in the case that AV/C INTERIM status is arrived, thus the caller should expand the - /// timeout in advance for the case. - /// - /// ## `cmd_frame` + /// Finish the pair of asynchronous transaction for AV/C command and response. The @timeout_ms + /// parameter is used to wait for response transaction since the command transaction is initiated. + /// The timeout is not expanded in the case that AV/C INTERIM status arrived, thus the caller should + /// expand the timeout in advance for the case. + /// ## `cmd` /// An array with elements for request byte data. The value of /// this argument should point to the array and immutable. - /// ## `resp_frame` + /// ## `resp` /// An array with elements for response byte data. Callers /// should give it for buffer with enough space against the request since this library /// performs no reallocation. Due to the reason, the value of this argument should point to /// the pointer to the array and immutable. The content of array is mutable. /// ## `timeout_ms` /// The timeout to wait for response transaction since command transactions finishes. - /// - /// # Returns - /// - /// TRUE if the overall operation finishes successfully, otherwise FALSE. - /// - /// ## `resp_size` - /// The size of response buffer consumed for response frame. - /// #[doc(alias = "hinawa_fw_fcp_avc_transaction")] fn avc_transaction( &self, cmd_frame: &[u8], - resp_frame: &mut [u8], + resp_frame: &mut Vec<u8>, timeout_ms: u32, - ) -> Result<usize, glib::Error>; + ) -> Result<(), glib::Error>; - /// Finish the pair of asynchronous transaction for AV/C command and response transactions. The - /// timeout_ms parameter is used to wait for response transaction since the command transaction is - /// initiated, ignoring `property::FwFcp::timeout` property of instance. The timeout is not expanded in - /// the case that AV/C INTERIM status is arrived, thus the caller should expand the timeout in - /// advance for the case. - /// ## `cmd_frame` + /// Finish the pair of asynchronous transaction for AV/C command and response. The @timeout_ms + /// parameter is used to wait for response transaction since the command transaction is initiated. + /// The timeout is not expanded in the case that AV/C INTERIM status arrived, thus the caller should + /// expand the timeout in advance for the case. + /// ## `cmd` /// An array with elements for request byte data. The value of /// this argument should point to the array and immutable. - /// ## `resp_frame` + /// ## `resp` /// An array with elements for response byte data. Callers /// should give it for buffer with enough space against the request since this library /// performs no reallocation. Due to the reason, the value of this argument should point to @@ -86,8 +73,6 @@ pub trait FwFcpExtManual { /// /// # Returns /// - /// TRUE if the overall operation finishes successfully, otherwise FALSE. - /// /// ## `tstamp` /// The array with three elements for time /// stamps. The first element is for the isochronous cycle at which the request was sent @@ -103,18 +88,6 @@ pub trait FwFcpExtManual { ) -> Result<[u32; 3], glib::Error>; /// Emitted when the node transfers asynchronous packet as response for FCP and the process - /// successfully read the content of packet, except for the case that `signal@FwFcp::responded2` - /// signal handler is already assigned. - /// - /// ## `frame` - /// The array with elements for byte - /// data of response for FCP. - #[doc(alias = "responded")] - fn connect_responded<F>(&self, f: F) -> SignalHandlerId - where - F: Fn(&Self, &[u8]) + 'static; - - /// Emitted when the node transfers asynchronous packet as response for FCP and the process /// successfully read the content of packet. /// /// The values of @tstamp is unsigned 16 bit integer including higher 3 bits for three low @@ -123,17 +96,18 @@ pub trait FwFcpExtManual { /// /// If the version of kernel ABI for Linux FireWire subsystem is less than 6, the value of /// @tstamp argument has invalid value (=G_MAXUINT). - /// + /// ## `generation` + /// The generation of bus topology. /// ## `tstamp` /// The time stamp at which the request arrived for the response of FCP /// transaction. /// ## `frame` /// The array with elements for byte /// data of response for FCP. - #[doc(alias = "responded2")] - fn connect_responded2<F>(&self, f: F) -> SignalHandlerId + #[doc(alias = "responded")] + fn connect_responded<F>(&self, f: F) -> SignalHandlerId where - F: Fn(&Self, u32, &[u8]) + 'static; + F: Fn(&Self, u32, u32, &[u8]) + 'static; } impl<O: IsA<FwFcp>> FwFcpExtManual for O { @@ -166,9 +140,9 @@ impl<O: IsA<FwFcp>> FwFcpExtManual for O { fn avc_transaction( &self, cmd_frame: &[u8], - resp_frame: &mut [u8], + resp_frame: &mut Vec<u8>, timeout_ms: u32, - ) -> Result<usize, glib::Error> { + ) -> Result<(), glib::Error> { unsafe { let mut resp_frame_size = resp_frame.len(); let mut error = std::ptr::null_mut(); @@ -184,7 +158,8 @@ impl<O: IsA<FwFcp>> FwFcpExtManual for O { ); if error.is_null() { - Ok(resp_frame_size) + resp_frame.truncate(resp_frame_size); + Ok(()) } else { Err(from_glib_full(error)) } @@ -224,53 +199,23 @@ impl<O: IsA<FwFcp>> FwFcpExtManual for O { fn connect_responded<F>(&self, f: F) -> SignalHandlerId where - F: Fn(&Self, &[u8]) + 'static, + F: Fn(&Self, u32, u32, &[u8]) + 'static, { unsafe extern "C" fn responded_trampoline<P, F>( this: *mut ffi::HinawaFwFcp, - frame: *const u8, - length: libc::c_uint, - f: glib::ffi::gpointer, - ) where - P: IsA<FwFcp>, - F: Fn(&P, &[u8]) + 'static, - { - let f: &F = &*(f as *const F); - f( - &FwFcp::from_glib_borrow(this).unsafe_cast_ref(), - std::slice::from_raw_parts(frame, length as usize), - ) - } - unsafe { - let f: std::boxed::Box<F> = std::boxed::Box::new(f); - connect_raw( - self.as_ptr() as *mut _, - b"responded\0".as_ptr() as *const _, - Some(std::mem::transmute::<_, unsafe extern "C" fn()>( - responded_trampoline::<Self, F> as *const (), - )), - std::boxed::Box::into_raw(f), - ) - } - } - - fn connect_responded2<F>(&self, f: F) -> SignalHandlerId - where - F: Fn(&Self, u32, &[u8]) + 'static, - { - unsafe extern "C" fn responded2_trampoline<P, F>( - this: *mut ffi::HinawaFwFcp, + generation: libc::c_uint, tstamp: libc::c_uint, frame: *const u8, length: libc::c_uint, f: glib::ffi::gpointer, ) where P: IsA<FwFcp>, - F: Fn(&P, u32, &[u8]) + 'static, + F: Fn(&P, u32, u32, &[u8]) + 'static, { let f: &F = &*(f as *const F); f( &FwFcp::from_glib_borrow(this).unsafe_cast_ref(), + generation, tstamp, std::slice::from_raw_parts(frame, length as usize), ) @@ -279,9 +224,9 @@ impl<O: IsA<FwFcp>> FwFcpExtManual for O { let f: std::boxed::Box<F> = std::boxed::Box::new(f); connect_raw( self.as_ptr() as *mut _, - b"responded2\0".as_ptr() as *const _, + b"responded\0".as_ptr() as *const _, Some(std::mem::transmute::<_, unsafe extern "C" fn()>( - responded2_trampoline::<Self, F> as *const (), + responded_trampoline::<Self, F> as *const (), )), std::boxed::Box::into_raw(f), ) diff --git a/hinawa/src/fw_node.rs b/hinawa/src/fw_node.rs index 6a48d2d..4e2d6bf 100644 --- a/hinawa/src/fw_node.rs +++ b/hinawa/src/fw_node.rs @@ -11,23 +11,19 @@ pub trait FwNodeExtManual { /// /// # Returns /// - /// /// ## `image` /// The content of configuration ROM. #[doc(alias = "hinawa_fw_node_get_config_rom")] #[doc(alias = "get_config_rom")] fn config_rom(&self) -> Result<&[u8], glib::Error>; - /// Read current value of CYCLE_TIME register in 1394 OHCI controller. + /// Read current value of CYCLE_TIME register in 1394 OHCI hardware dedicated to communicate with + /// the associated node in IEEE 1394 bus. /// ## `clock_id` /// The numeric ID of clock source for the reference timestamp. One of CLOCK_REALTIME(0), /// CLOCK_MONOTONIC(1), and CLOCK_MONOTONIC_RAW(4) is available in UAPI of Linux kernel. /// ## `cycle_time` /// A [`CycleTime`][crate::CycleTime]. - /// - /// # Returns - /// - /// TRUE if the overall operation finishes successfully, otherwise FALSE. #[doc(alias = "hinawa_fw_node_read_cycle_time")] fn read_cycle_time(&self, clock_id: i32, cycle_time: &mut CycleTime) -> Result<(), glib::Error>; @@ -66,7 +62,7 @@ impl<O: IsA<FwNode>> FwNodeExtManual for O { let _ = ffi::hinawa_fw_node_read_cycle_time( self.as_ref().to_glib_none().0, clock_id, - &cycle_time.to_glib_none_mut().0, + &mut cycle_time.to_glib_none_mut().0, &mut error, ); diff --git a/hinawa/src/fw_req.rs b/hinawa/src/fw_req.rs index fe7d34e..9e6404d 100644 --- a/hinawa/src/fw_req.rs +++ b/hinawa/src/fw_req.rs @@ -7,9 +7,9 @@ use crate::*; /// /// [`FwReq`][struct@crate::FwReq] pub trait FwReqExtManual { - /// Execute request subaction of transactions to the given node according to given code. When the - /// response subaction arrives and read the contents, `signal::FwReq::responded` signal handler is called - /// as long as event dispatcher runs. + /// Execute request subaction of transaction to the given node according to given code. When the + /// response subaction arrives and running event dispatcher reads the contents, + /// `signal::FwReq::responded` signal handler is called. /// ## `node` /// A [`FwNode`][crate::FwNode]. /// ## `tcode` @@ -24,8 +24,8 @@ pub trait FwReqExtManual { /// reallocation. Due to the reason, the value of this argument should point to the pointer /// to the array and immutable. The content of array is mutable for read and lock /// transaction. - #[doc(alias = "hinawa_fw_req_transaction_async")] - fn transaction_async<P: IsA<FwNode>>( + #[doc(alias = "hinawa_fw_req_request")] + fn request<P: IsA<FwNode>>( &self, node: &P, tcode: FwTcode, @@ -35,8 +35,13 @@ pub trait FwReqExtManual { ) -> Result<(), glib::Error>; /// Execute request subaction of transaction to the given node according to given code, then wait - /// for response subaction within the given timeout. The `property::FwReq::timeout` property of - /// instance is ignored. + /// for response subaction within the given timeout. + /// + /// Each value of @tstamp is unsigned 16 bit integer including higher 3 bits for three low order bits + /// of second field and the rest 13 bits for cycle field in the format of IEEE 1394 CYCLE_TIMER register. + /// + /// If the version of kernel ABI for Linux FireWire subsystem is less than 6, each element of @tstamp + /// has invalid value (=G_MAXUINT). /// ## `node` /// A [`FwNode`][crate::FwNode]. /// ## `tcode` @@ -52,59 +57,29 @@ pub trait FwReqExtManual { /// to the array and immutable. The content of array is mutable for read and lock /// transaction. /// ## `timeout_ms` - /// The timeout to wait for response subaction of the transaction since request + /// The timeout to wait for the response subaction of transaction since the request /// subaction is initiated, in milliseconds. - #[doc(alias = "hinawa_fw_req_transaction_sync")] - fn transaction_sync<P: IsA<FwNode>>( - &self, - node: &P, - tcode: FwTcode, - addr: u64, - length: usize, - frame: &mut [u8], - timeout_ms: u32, - ) -> Result<(), glib::Error>; - - /// Execute request subaction of transactions to the given node according to given code. When the - /// response subaction arrives and running event dispatcher reads the contents, - /// `signal::FwReq::responded` signal handler is called. - /// ## `node` - /// A [`FwNode`][crate::FwNode]. - /// ## `tcode` - /// A transaction code of [`FwTcode`][crate::FwTcode]. - /// ## `addr` - /// A destination address of target device - /// ## `length` - /// The range of address in byte unit. - /// ## `frame` - /// An array with elements for byte data. Callers should - /// give it for buffer with enough space against the request since this library performs no - /// reallocation. Due to the reason, the value of this argument should point to the pointer - /// to the array and immutable. The content of array is mutable for read and lock - /// transaction. /// /// # Returns /// - /// TRUE if the overall operation finishes successfully, otherwise FALSE. - #[doc(alias = "hinawa_fw_req_request")] - fn request<P: IsA<FwNode>>( + /// ## `tstamp` + /// The array with two elements for time stamps. + /// The first element is for the isochronous cycle at which the request subaction was sent. + /// The second element is for the isochronous cycle at which the response subaction arrived. + #[doc(alias = "hinawa_fw_req_transaction_with_tstamp")] + fn transaction_with_tstamp<P: IsA<FwNode>>( &self, node: &P, tcode: FwTcode, addr: u64, length: usize, frame: &mut [u8], - ) -> Result<(), glib::Error>; + timeout_ms: u32, + ) -> Result<[u32; 2], glib::Error>; /// Execute request subaction of transaction to the given node according to given code, then wait - /// for response subaction within the given timeout. The `property::FwReq::timeout` property of - /// instance is ignored. - /// - /// Each value of @tstamp is unsigned 16 bit integer including higher 3 bits for three low order bits - /// of second field and the rest 13 bits for cycle field in the format of IEEE 1394 CYCLE_TIMER register. - /// - /// If the version of kernel ABI for Linux FireWire subsystem is less than 6, each element of @tstamp - /// has invalid value (=G_MAXUINT). + /// for response subaction within the value of timeout argument. The function is a thin wrapper to + /// [`FwReqExtManual::transaction_with_tstamp()`][crate::prelude::FwReqExtManual::transaction_with_tstamp()]. /// ## `node` /// A [`FwNode`][crate::FwNode]. /// ## `tcode` @@ -122,17 +97,8 @@ pub trait FwReqExtManual { /// ## `timeout_ms` /// The timeout to wait for response subaction of the transaction since request /// subaction is initiated, in milliseconds. - /// - /// # Returns - /// - /// TRUE if the overall operation finishes successfully, otherwise FALSE. - /// - /// ## `tstamp` - /// The array with two elements for time stamps. - /// The first element is for the isochronous cycle at which the request was sent. The second - /// element is for the isochronous cycle at which the response arrived. - #[doc(alias = "hinawa_fw_req_transaction_with_tstamp")] - fn transaction_with_tstamp<P: IsA<FwNode>>( + #[doc(alias = "hinawa_fw_req_transaction")] + fn transaction<P: IsA<FwNode>>( &self, node: &P, tcode: FwTcode, @@ -140,21 +106,8 @@ pub trait FwReqExtManual { length: usize, frame: &mut [u8], timeout_ms: u32, - ) -> Result<[u32; 2], glib::Error>; + ) -> Result<(), glib::Error>; - /// Emitted when the unit transfers asynchronous packet as response subaction for the - /// transaction and the process successfully reads the content of packet from Linux firewire - /// subsystem, except for the case that `signal@FwReq::responded2` signal handler is already - /// assigned. - /// - /// ## `rcode` - /// One of [`FwRcode`][crate::FwRcode]. - /// ## `frame` - /// The array with elements for byte data of response subaction for transaction. - #[doc(alias = "responded")] - fn connect_responded<F>(&self, f: F) -> SignalHandlerId - where - F: Fn(&Self, FwRcode, &[u8]) + 'static; /// Emitted when the unit transfers asynchronous packet as response subaction for the /// transaction and the process successfully reads the content of packet from Linux firewire @@ -175,14 +128,14 @@ pub trait FwReqExtManual { /// The isochronous cycle at which the response arrived. /// ## `frame` /// The array with elements for byte data of response subaction for transaction. - #[doc(alias = "responded2")] - fn connect_responded2<F>(&self, f: F) -> SignalHandlerId + #[doc(alias = "responded")] + fn connect_responded<F>(&self, f: F) -> SignalHandlerId where F: Fn(&Self, FwRcode, u32, u32, &[u8]) + 'static; } impl<O: IsA<FwReq>> FwReqExtManual for O { - fn transaction_async<P: IsA<FwNode>>( + fn request<P: IsA<FwNode>>( &self, node: &P, tcode: FwTcode, @@ -194,7 +147,7 @@ impl<O: IsA<FwReq>> FwReqExtManual for O { let mut frame_size = frame.len(); let mut error = std::ptr::null_mut(); - ffi::hinawa_fw_req_transaction_async( + let _ = ffi::hinawa_fw_req_request( self.as_ref().to_glib_none().0, node.as_ref().to_glib_none().0, tcode.into_glib(), @@ -213,7 +166,7 @@ impl<O: IsA<FwReq>> FwReqExtManual for O { } } - fn transaction_sync<P: IsA<FwNode>>( + fn transaction_with_tstamp<P: IsA<FwNode>>( &self, node: &P, tcode: FwTcode, @@ -221,12 +174,13 @@ impl<O: IsA<FwReq>> FwReqExtManual for O { length: usize, frame: &mut [u8], timeout_ms: u32, - ) -> Result<(), glib::Error> { + ) -> Result<[u32; 2], glib::Error> { unsafe { let mut frame_size = frame.len(); + let mut tstamp = [0; 2]; let mut error = std::ptr::null_mut(); - ffi::hinawa_fw_req_transaction_sync( + let _ = ffi::hinawa_fw_req_transaction_with_tstamp( self.as_ref().to_glib_none().0, node.as_ref().to_glib_none().0, tcode.into_glib(), @@ -234,50 +188,20 @@ impl<O: IsA<FwReq>> FwReqExtManual for O { length, &mut frame.as_mut_ptr(), &mut frame_size, + &mut tstamp, timeout_ms, &mut error, ); if error.is_null() { - Ok(()) - } else { - Err(from_glib_full(error)) - } - } - } - - fn request<P: IsA<FwNode>>( - &self, - node: &P, - tcode: FwTcode, - addr: u64, - length: usize, - frame: &mut [u8], - ) -> Result<(), glib::Error> { - unsafe { - let mut frame_size = frame.len(); - let mut error = std::ptr::null_mut(); - - let _ = ffi::hinawa_fw_req_request( - self.as_ref().to_glib_none().0, - node.as_ref().to_glib_none().0, - tcode.into_glib(), - addr, - length, - &mut frame.as_mut_ptr(), - &mut frame_size, - &mut error, - ); - - if error.is_null() { - Ok(()) + Ok(tstamp) } else { Err(from_glib_full(error)) } } } - fn transaction_with_tstamp<P: IsA<FwNode>>( + fn transaction<P: IsA<FwNode>>( &self, node: &P, tcode: FwTcode, @@ -285,13 +209,12 @@ impl<O: IsA<FwReq>> FwReqExtManual for O { length: usize, frame: &mut [u8], timeout_ms: u32, - ) -> Result<[u32; 2], glib::Error> { + ) -> Result<(), glib::Error> { unsafe { let mut frame_size = frame.len(); - let mut tstamp = [0; 2]; let mut error = std::ptr::null_mut(); - let _ = ffi::hinawa_fw_req_transaction_with_tstamp( + let _ = ffi::hinawa_fw_req_transaction( self.as_ref().to_glib_none().0, node.as_ref().to_glib_none().0, tcode.into_glib(), @@ -299,13 +222,12 @@ impl<O: IsA<FwReq>> FwReqExtManual for O { length, &mut frame.as_mut_ptr(), &mut frame_size, - &mut tstamp, timeout_ms, &mut error, ); if error.is_null() { - Ok(tstamp) + Ok(()) } else { Err(from_glib_full(error)) } @@ -314,43 +236,9 @@ impl<O: IsA<FwReq>> FwReqExtManual for O { fn connect_responded<F>(&self, f: F) -> SignalHandlerId where - F: Fn(&Self, FwRcode, &[u8]) + 'static, - { - unsafe extern "C" fn responded_trampoline<P, F>( - this: *mut ffi::HinawaFwReq, - rcode: ffi::HinawaFwRcode, - frame: *const u8, - length: libc::c_uint, - f: glib::ffi::gpointer, - ) where - P: IsA<FwReq>, - F: Fn(&P, FwRcode, &[u8]) + 'static, - { - let f: &F = &*(f as *const F); - f( - &FwReq::from_glib_borrow(this).unsafe_cast_ref(), - from_glib(rcode), - std::slice::from_raw_parts(frame, length as usize), - ) - } - unsafe { - let f: std::boxed::Box<F> = std::boxed::Box::new(f); - connect_raw( - self.as_ptr() as *mut _, - b"responded\0".as_ptr() as *const _, - Some(std::mem::transmute::<_, unsafe extern "C" fn()>( - responded_trampoline::<Self, F> as *const (), - )), - std::boxed::Box::into_raw(f), - ) - } - } - - fn connect_responded2<F>(&self, f: F) -> SignalHandlerId - where F: Fn(&Self, FwRcode, u32, u32, &[u8]) + 'static, { - unsafe extern "C" fn responded2_trampoline<P, F>( + unsafe extern "C" fn responded_trampoline<P, F>( this: *mut ffi::HinawaFwReq, rcode: ffi::HinawaFwRcode, request_tstamp: libc::c_uint, @@ -375,9 +263,9 @@ impl<O: IsA<FwReq>> FwReqExtManual for O { let f: std::boxed::Box<F> = std::boxed::Box::new(f); connect_raw( self.as_ptr() as *mut _, - b"responded2\0".as_ptr() as *const _, + b"responded\0".as_ptr() as *const _, Some(std::mem::transmute::<_, unsafe extern "C" fn()>( - responded2_trampoline::<Self, F> as *const (), + responded_trampoline::<Self, F> as *const (), )), std::boxed::Box::into_raw(f), ) diff --git a/hinawa/src/fw_resp.rs b/hinawa/src/fw_resp.rs index afdf9ac..a2e8869 100644 --- a/hinawa/src/fw_resp.rs +++ b/hinawa/src/fw_resp.rs @@ -7,13 +7,8 @@ use crate::*; /// /// [`FwResp`][struct@crate::FwResp] pub trait FwRespExtManual { - #[doc(alias = "requested2")] - fn connect_requested2<F>(&self, f: F) -> SignalHandlerId - where - F: Fn(&Self, FwTcode, u64, u32, u32, u32, u32, &[u8]) -> FwRcode + 'static; - - /// Emitted when any node transfers request subaction to the range of address in 1394 OHCI - /// controller to which this object listening. + /// Emitted when any node transfers request subaction to local nodes within the address + /// range reserved in Linux system. /// /// The handler is expected to call [`FwRespExt::set_resp_frame()`][crate::prelude::FwRespExt::set_resp_frame()] with frame and return /// [`FwRcode`][crate::FwRcode] for response subaction. @@ -29,12 +24,13 @@ pub trait FwRespExtManual { /// One of [`FwTcode`][crate::FwTcode] enumerations /// ## `offset` /// The address offset at which the transaction arrives. - /// ## `src` + /// ## `src_node_id` /// The node ID of source for the transaction. - /// ## `dst` + /// ## `dst_node_id` /// The node ID of destination for the transaction. - /// ## `card` - /// The index of card corresponding to 1394 OHCI controller. + /// ## `card_id` + /// The index of card specific to the 1394 OHCI hardware at which the request + /// subaction arrived. /// ## `generation` /// The generation of bus when the transaction is transferred. /// ## `tstamp` @@ -47,64 +43,18 @@ pub trait FwRespExtManual { /// /// One of [`FwRcode`][crate::FwRcode] enumerations corresponding to rcodes defined in IEEE 1394 /// specification. - #[doc(alias = "requested3")] - fn connect_requested3<F>(&self, f: F) -> SignalHandlerId + #[doc(alias = "requested")] + fn connect_requested<F>(&self, f: F) -> SignalHandlerId where F: Fn(&Self, FwTcode, u64, u32, u32, u32, u32, u32, &[u8]) -> FwRcode + 'static; } impl<O: IsA<FwResp>> FwRespExtManual for O { - fn connect_requested2<F>(&self, f: F) -> SignalHandlerId - where - F: Fn(&Self, FwTcode, u64, u32, u32, u32, u32, &[u8]) -> FwRcode + 'static, - { - unsafe extern "C" fn requested2_trampoline<P, F>( - this: *mut ffi::HinawaFwResp, - tcode: ffi::HinawaFwTcode, - offset: u64, - src: u32, - dst: u32, - card: u32, - generation: u32, - frame: *const u8, - length: libc::c_uint, - f: glib::ffi::gpointer, - ) -> ffi::HinawaFwRcode - where - P: IsA<FwResp>, - F: Fn(&P, FwTcode, u64, u32, u32, u32, u32, &[u8]) -> FwRcode + 'static, - { - let f: &F = &*(f as *const F); - f( - &FwResp::from_glib_borrow(this).unsafe_cast_ref(), - from_glib(tcode), - offset, - src, - dst, - card, - generation, - std::slice::from_raw_parts(frame, length as usize), - ) - .into_glib() - } - unsafe { - let f: std::boxed::Box<F> = std::boxed::Box::new(f); - connect_raw( - self.as_ptr() as *mut _, - b"requested2\0".as_ptr() as *const _, - Some(std::mem::transmute::<_, unsafe extern "C" fn()>( - requested2_trampoline::<Self, F> as *const (), - )), - std::boxed::Box::into_raw(f), - ) - } - } - - fn connect_requested3<F>(&self, f: F) -> SignalHandlerId + fn connect_requested<F>(&self, f: F) -> SignalHandlerId where F: Fn(&Self, FwTcode, u64, u32, u32, u32, u32, u32, &[u8]) -> FwRcode + 'static, { - unsafe extern "C" fn requested3_trampoline<P, F>( + unsafe extern "C" fn requested_trampoline<P, F>( this: *mut ffi::HinawaFwResp, tcode: ffi::HinawaFwTcode, offset: u64, @@ -139,9 +89,9 @@ impl<O: IsA<FwResp>> FwRespExtManual for O { let f: std::boxed::Box<F> = std::boxed::Box::new(f); connect_raw( self.as_ptr() as *mut _, - b"requested3\0".as_ptr() as *const _, + b"requested\0".as_ptr() as *const _, Some(std::mem::transmute::<_, unsafe extern "C" fn()>( - requested3_trampoline::<Self, F> as *const (), + requested_trampoline::<Self, F> as *const (), )), std::boxed::Box::into_raw(f), ) diff --git a/hinawa/src/subclass/fw_fcp.rs b/hinawa/src/subclass/fw_fcp.rs index af76cca..272007a 100644 --- a/hinawa/src/subclass/fw_fcp.rs +++ b/hinawa/src/subclass/fw_fcp.rs @@ -4,22 +4,18 @@ use super::*; /// Trait which should be implemented by subclass of [`FwFcp`][crate::FwFcp]. pub trait FwFcpImpl: ObjectImpl + FwRespImpl { - fn responded(&self, fcp: &Self::Type, frame: &[u8]) { - self.parent_responded(fcp, frame) - } - fn responded2(&self, fcp: &Self::Type, tstamp: u32, frame: &[u8]) { - self.parent_responded2(fcp, tstamp, frame) + fn responded(&self, fcp: &Self::Type, generation: u32, tstamp: u32, frame: &[u8]) { + self.parent_responded(fcp, generation, tstamp, frame) } } /// Trait which is automatically implemented to implementator of [`FwFcpImpl`][self::FwFcpImpl]. pub trait FwFcpImplExt: ObjectSubclass { - fn parent_responded(&self, fcp: &Self::Type, frame: &[u8]); - fn parent_responded2(&self, fcp: &Self::Type, tstamp: u32, frame: &[u8]); + fn parent_responded(&self, fcp: &Self::Type, generation: u32, tstamp: u32, frame: &[u8]); } impl<T: FwFcpImpl> FwFcpImplExt for T { - fn parent_responded(&self, fcp: &Self::Type, frame: &[u8]) { + fn parent_responded(&self, fcp: &Self::Type, generation: u32, tstamp: u32, frame: &[u8]) { unsafe { let data = T::type_data(); let parent_class = data.as_ref().parent_class() as *mut ffi::HinawaFwFcpClass; @@ -28,20 +24,7 @@ impl<T: FwFcpImpl> FwFcpImplExt for T { .expect("No parent class implementation for \"responded\""); f( fcp.unsafe_cast_ref::<FwFcp>().to_glib_none().0, - frame.as_ptr(), - frame.len() as u32, - ) - } - } - fn parent_responded2(&self, fcp: &Self::Type, tstamp: u32, frame: &[u8]) { - unsafe { - let data = T::type_data(); - let parent_class = data.as_ref().parent_class() as *mut ffi::HinawaFwFcpClass; - let f = (*parent_class) - .responded2 - .expect("No parent class implementation for \"responded2\""); - f( - fcp.unsafe_cast_ref::<FwFcp>().to_glib_none().0, + generation, tstamp, frame.as_ptr(), frame.len() as u32, @@ -56,27 +39,12 @@ unsafe impl<T: FwFcpImpl> IsSubclassable<T> for FwFcp { let klass = class.as_mut(); klass.responded = Some(fw_fcp_responded::<T>); - klass.responded2 = Some(fw_fcp_responded2::<T>); } } unsafe extern "C" fn fw_fcp_responded<T: FwFcpImpl>( ptr: *mut ffi::HinawaFwFcp, - frame: *const u8, - length: c_uint, -) { - let instance = &*(ptr as *mut T::Instance); - let imp = instance.imp(); - let wrap: Borrowed<FwFcp> = from_glib_borrow(ptr); - - imp.responded( - wrap.unsafe_cast_ref(), - std::slice::from_raw_parts(frame, length as usize), - ) -} - -unsafe extern "C" fn fw_fcp_responded2<T: FwFcpImpl>( - ptr: *mut ffi::HinawaFwFcp, + generation: c_uint, tstamp: c_uint, frame: *const u8, length: c_uint, @@ -85,8 +53,9 @@ unsafe extern "C" fn fw_fcp_responded2<T: FwFcpImpl>( let imp = instance.imp(); let wrap: Borrowed<FwFcp> = from_glib_borrow(ptr); - imp.responded2( + imp.responded( wrap.unsafe_cast_ref(), + generation, tstamp, std::slice::from_raw_parts(frame, length as usize), ) diff --git a/hinawa/src/subclass/fw_req.rs b/hinawa/src/subclass/fw_req.rs index 21c3a8f..7dc77ea 100644 --- a/hinawa/src/subclass/fw_req.rs +++ b/hinawa/src/subclass/fw_req.rs @@ -4,10 +4,7 @@ use super::*; /// Trait which should be implemented by subclass of [`FwReq`][crate::FwReq]. pub trait FwReqImpl: ObjectImpl { - fn responded(&self, req: &Self::Type, rcode: FwRcode, frame: &[u8]) { - self.parent_responded(req, rcode, frame) - } - fn responded2( + fn responded( &self, req: &Self::Type, rcode: FwRcode, @@ -15,14 +12,13 @@ pub trait FwReqImpl: ObjectImpl { response_tstamp: u32, frame: &[u8], ) { - self.parent_responded2(req, rcode, request_tstamp, response_tstamp, frame) + self.parent_responded(req, rcode, request_tstamp, response_tstamp, frame) } } /// Trait which is automatically implemented to implementator of [`FwReqImpl`][self::FwReqImpl]. pub trait FwReqImplExt: ObjectSubclass { - fn parent_responded(&self, req: &Self::Type, rcode: FwRcode, frame: &[u8]); - fn parent_responded2( + fn parent_responded( &self, req: &Self::Type, rcode: FwRcode, @@ -33,23 +29,7 @@ pub trait FwReqImplExt: ObjectSubclass { } impl<T: FwReqImpl> FwReqImplExt for T { - fn parent_responded(&self, req: &Self::Type, rcode: FwRcode, frame: &[u8]) { - unsafe { - let data = T::type_data(); - let parent_class = data.as_ref().parent_class() as *mut ffi::HinawaFwReqClass; - let f = (*parent_class) - .responded - .expect("No parent class implementation for \"responded\""); - f( - req.unsafe_cast_ref::<FwReq>().to_glib_none().0, - rcode.into_glib(), - frame.as_ptr(), - frame.len() as u32, - ) - } - } - - fn parent_responded2( + fn parent_responded( &self, req: &Self::Type, rcode: FwRcode, @@ -61,8 +41,8 @@ impl<T: FwReqImpl> FwReqImplExt for T { let data = T::type_data(); let parent_class = data.as_ref().parent_class() as *mut ffi::HinawaFwReqClass; let f = (*parent_class) - .responded2 - .expect("No parent class implementation for \"responded2\""); + .responded + .expect("No parent class implementation for \"responded\""); f( req.unsafe_cast_ref::<FwReq>().to_glib_none().0, rcode.into_glib(), @@ -81,30 +61,12 @@ unsafe impl<T: FwReqImpl> IsSubclassable<T> for FwReq { let klass = class.as_mut(); klass.responded = Some(fw_req_responded::<T>); - klass.responded2 = Some(fw_req_responded2::<T>); } } unsafe extern "C" fn fw_req_responded<T: FwReqImpl>( ptr: *mut ffi::HinawaFwReq, rcode: ffi::HinawaFwRcode, - frame: *const u8, - length: c_uint, -) { - let instance = &*(ptr as *mut T::Instance); - let imp = instance.imp(); - let wrap: Borrowed<FwReq> = from_glib_borrow(ptr); - - imp.responded( - wrap.unsafe_cast_ref(), - from_glib(rcode), - std::slice::from_raw_parts(frame, length as usize), - ) -} - -unsafe extern "C" fn fw_req_responded2<T: FwReqImpl>( - ptr: *mut ffi::HinawaFwReq, - rcode: ffi::HinawaFwRcode, request_tstamp: c_uint, response_tstamp: c_uint, frame: *const u8, @@ -114,7 +76,7 @@ unsafe extern "C" fn fw_req_responded2<T: FwReqImpl>( let imp = instance.imp(); let wrap: Borrowed<FwReq> = from_glib_borrow(ptr); - imp.responded2( + imp.responded( wrap.unsafe_cast_ref(), from_glib(rcode), request_tstamp, diff --git a/hinawa/src/subclass/fw_resp.rs b/hinawa/src/subclass/fw_resp.rs index 997db3a..36f77e0 100644 --- a/hinawa/src/subclass/fw_resp.rs +++ b/hinawa/src/subclass/fw_resp.rs @@ -4,20 +4,7 @@ use super::*; /// Trait which should be implemented by subclass of [`FwResp`][crate::FwResp]. pub trait FwRespImpl: ObjectImpl { - fn requested2( - &self, - resp: &Self::Type, - tcode: FwTcode, - offset: u64, - src: u32, - dst: u32, - card: u32, - generation: u32, - frame: &[u8], - ) -> FwRcode { - self.parent_requested2(resp, tcode, offset, src, dst, card, generation, frame) - } - fn requested3( + fn requested( &self, resp: &Self::Type, tcode: FwTcode, @@ -29,7 +16,7 @@ pub trait FwRespImpl: ObjectImpl { tstamp: u32, frame: &[u8], ) -> FwRcode { - self.parent_requested3( + self.parent_requested( resp, tcode, offset, src, dst, card, generation, tstamp, frame, ) } @@ -37,18 +24,7 @@ pub trait FwRespImpl: ObjectImpl { /// Trait which is automatically implemented to implementator of [`FwRespImpl`][self::FwRespImpl]. pub trait FwRespImplExt: ObjectSubclass { - fn parent_requested2( - &self, - resp: &Self::Type, - tcode: FwTcode, - offset: u64, - src: u32, - dst: u32, - card: u32, - generation: u32, - frame: &[u8], - ) -> FwRcode; - fn parent_requested3( + fn parent_requested( &self, resp: &Self::Type, tcode: FwTcode, @@ -63,37 +39,7 @@ pub trait FwRespImplExt: ObjectSubclass { } impl<T: FwRespImpl> FwRespImplExt for T { - fn parent_requested2( - &self, - resp: &Self::Type, - tcode: FwTcode, - offset: u64, - src: u32, - dst: u32, - card: u32, - generation: u32, - frame: &[u8], - ) -> FwRcode { - unsafe { - let data = T::type_data(); - let parent_class = data.as_ref().parent_class() as *mut ffi::HinawaFwRespClass; - let f = (*parent_class) - .requested2 - .expect("No parent class implementation for \"requested2\""); - from_glib(f( - resp.unsafe_cast_ref::<FwResp>().to_glib_none().0, - tcode.into_glib(), - offset, - src, - dst, - card, - generation, - frame.as_ptr(), - frame.len() as u32, - )) - } - } - fn parent_requested3( + fn parent_requested( &self, resp: &Self::Type, tcode: FwTcode, @@ -109,8 +55,8 @@ impl<T: FwRespImpl> FwRespImplExt for T { let data = T::type_data(); let parent_class = data.as_ref().parent_class() as *mut ffi::HinawaFwRespClass; let f = (*parent_class) - .requested3 - .expect("No parent class implementation for \"requested3\""); + .requested + .expect("No parent class implementation for \"requested\""); from_glib(f( resp.unsafe_cast_ref::<FwResp>().to_glib_none().0, tcode.into_glib(), @@ -132,40 +78,11 @@ unsafe impl<T: FwRespImpl> IsSubclassable<T> for FwResp { Self::parent_class_init::<T>(class); let klass = class.as_mut(); - klass.requested2 = Some(fw_resp_requested2::<T>); - klass.requested3 = Some(fw_resp_requested3::<T>); + klass.requested = Some(fw_resp_requested::<T>); } } -unsafe extern "C" fn fw_resp_requested2<T: FwRespImpl>( - ptr: *mut ffi::HinawaFwResp, - tcode: ffi::HinawaFwTcode, - offset: u64, - src: u32, - dst: u32, - card: u32, - generation: u32, - frame: *const u8, - length: c_uint, -) -> ffi::HinawaFwRcode { - let instance = &*(ptr as *mut T::Instance); - let imp = instance.imp(); - let wrap: Borrowed<FwResp> = from_glib_borrow(ptr); - - imp.requested2( - wrap.unsafe_cast_ref(), - from_glib(tcode), - offset, - src, - dst, - card, - generation, - std::slice::from_raw_parts(frame, length as usize), - ) - .into_glib() -} - -unsafe extern "C" fn fw_resp_requested3<T: FwRespImpl>( +unsafe extern "C" fn fw_resp_requested<T: FwRespImpl>( ptr: *mut ffi::HinawaFwResp, tcode: ffi::HinawaFwTcode, offset: u64, @@ -181,7 +98,7 @@ unsafe extern "C" fn fw_resp_requested3<T: FwRespImpl>( let imp = instance.imp(); let wrap: Borrowed<FwResp> = from_glib_borrow(ptr); - imp.requested3( + imp.requested( wrap.unsafe_cast_ref(), from_glib(tcode), offset, |