From 6debd1bc23229eb9e709ec5d7aeef9026a64b1e6 Mon Sep 17 00:00:00 2001 From: Takashi Sakamoto Date: Tue, 11 Aug 2020 13:06:02 +0000 Subject: [PATCH] update hinawa-sys/hinawa crates up to libhinawa v2.1.0 Signed-off-by: Takashi Sakamoto --- README.rst | 2 +- conf/gir-hinawa-sys.toml | 2 +- conf/gir-hinawa.toml | 39 +++ hinawa-sys/Cargo.toml | 6 +- hinawa-sys/src/lib.rs | 89 +++++++ hinawa-sys/tests/abi.rs | 38 +++ hinawa/Cargo.toml | 4 +- hinawa/src/auto/enums.rs | 513 +++++++++++++++++++++++++++++++++++++ hinawa/src/auto/fw_fcp.rs | 11 + hinawa/src/auto/mod.rs | 5 + hinawa/src/auto/snd_efw.rs | 14 + hinawa/src/enums.rs | 74 ++++++ hinawa/src/fw_fcp.rs | 62 +++++ hinawa/src/fw_req.rs | 93 +++++++ hinawa/src/lib.rs | 3 + hinawa/src/snd_efw.rs | 81 ++++++ 16 files changed, 1030 insertions(+), 6 deletions(-) create mode 100644 hinawa/src/enums.rs diff --git a/README.rst b/README.rst index 888f953..69ec6b2 100644 --- a/README.rst +++ b/README.rst @@ -2,7 +2,7 @@ hinawa Rust bindings ==================== -2020/06/03 +2020/08/17 Takashi Sakamoto Introduction diff --git a/conf/gir-hinawa-sys.toml b/conf/gir-hinawa-sys.toml index 3676a1f..282f77d 100644 --- a/conf/gir-hinawa-sys.toml +++ b/conf/gir-hinawa-sys.toml @@ -2,7 +2,7 @@ work_mode = "sys" library = "Hinawa" version = "3.0" -min_cfg_version = "2.0" +min_cfg_version = "2.1" single_version_file = "." external_libraries = [ "GLib", diff --git a/conf/gir-hinawa.toml b/conf/gir-hinawa.toml index 79374d1..93a5a8d 100644 --- a/conf/gir-hinawa.toml +++ b/conf/gir-hinawa.toml @@ -9,6 +9,11 @@ generate = [ "Hinawa.FwRcode", "Hinawa.FwTcode", "Hinawa.SndUnitType", + "Hinawa.FwNodeError", + "Hinawa.FwFcpError", + "Hinawa.SndUnitError", + "Hinawa.SndDiceError", + "Hinawa.SndEfwStatus", "Hinawa.SndDice", "Hinawa.SndMotu", "Hinawa.SndDg00x", @@ -32,10 +37,25 @@ manual_traits = ["FwNodeExtManual"] name = "Hinawa.FwReq" status = "generate" manual_traits = ["FwReqExtManual"] + [[object.signal]] + pattern = "responded" + ignore = true + doc_trait_name = "FwReqExtManual" + [[object.function]] + pattern = "transaction_async" + ignore = true + doc_trait_name = "FwReqExtManual" + [[object.function]] + pattern = "transaction_sync" + ignore = true + doc_trait_name = "FwReqExtManual" [[object.function]] pattern = "transaction" ignore = true doc_trait_name = "FwReqExtManual" + [[object.function]] + pattern = "error_quark" + ignore = true [[object]] name = "Hinawa.FwResp" @@ -50,10 +70,18 @@ manual_traits = ["FwRespExtManual"] name = "Hinawa.FwFcp" status = "generate" manual_traits = ["FwFcpExtManual"] + [[object.function]] + pattern = "avc_transaction" + ignore = true + doc_trait_name = "FwFcpExtManual" [[object.function]] pattern = "transaction" ignore = true doc_trait_name = "FwFcpExtManual" + [[object.signal]] + pattern = "responded" + ignore = true + doc_trait_name = "FwFcpExtManual" [[object]] name = "Hinawa.SndUnit" @@ -68,10 +96,21 @@ manual_traits = ["SndUnitExtManual"] name = "Hinawa.SndEfw" status = "generate" manual_traits = ["SndEfwExtManual"] + [[object.function]] + pattern = "transaction_sync" + ignore = true + doc_trait_name = "SndEfwExtManual" [[object.function]] pattern = "transaction" ignore = true doc_trait_name = "SndEfwExtManual" + [[object.signal]] + pattern = "responded" + ignore = true + doc_trait_name = "SndEfwExtManual" + [[object.function]] + pattern = "error_quark" + ignore = true [[object]] name = "Hinawa.SndTscm" diff --git a/hinawa-sys/Cargo.toml b/hinawa-sys/Cargo.toml index 8aab8c1..88b4b63 100644 --- a/hinawa-sys/Cargo.toml +++ b/hinawa-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hinawa-sys" -version = "0.1.1" +version = "0.2.0" description = "FFI bindings for libhinawa2 library" authors = ["Takashi Sakamoto "] links = "hinawa" @@ -11,9 +11,10 @@ repository = "https://github.com/alsa-project/hinawa-rs/" features = ["dox"] [package.metadata.system-deps.hinawa] name = "hinawa" -version = "2.0" +version = "2.1" [package.metadata.system-deps.hinawa.feature-versions] +v2_1 = "2.1" [lib] name = "hinawa_sys" @@ -33,3 +34,4 @@ tempfile = "3" [features] dox = [] +v2_1 = [] diff --git a/hinawa-sys/src/lib.rs b/hinawa-sys/src/lib.rs index 438f4fa..3f9a8ca 100644 --- a/hinawa-sys/src/lib.rs +++ b/hinawa-sys/src/lib.rs @@ -18,6 +18,16 @@ use libc::{c_int, c_char, c_uchar, c_float, c_uint, c_double, use glib::{gboolean, gconstpointer, gpointer, GType}; // Enums +pub type HinawaFwFcpError = c_int; +pub const HINAWA_FW_FCP_ERROR_TIMEOUT: HinawaFwFcpError = 0; +pub const HINAWA_FW_FCP_ERROR_LARGE_RESP: HinawaFwFcpError = 1; + +pub type HinawaFwNodeError = c_int; +pub const HINAWA_FW_NODE_ERROR_DISCONNECTED: HinawaFwNodeError = 0; +pub const HINAWA_FW_NODE_ERROR_OPENED: HinawaFwNodeError = 1; +pub const HINAWA_FW_NODE_ERROR_NOT_OPENED: HinawaFwNodeError = 2; +pub const HINAWA_FW_NODE_ERROR_FAILED: HinawaFwNodeError = 3; + pub type HinawaFwRcode = c_int; pub const HINAWA_FW_RCODE_COMPLETE: HinawaFwRcode = 0; pub const HINAWA_FW_RCODE_CONFLICT_ERROR: HinawaFwRcode = 4; @@ -29,6 +39,7 @@ pub const HINAWA_FW_RCODE_CANCELLED: HinawaFwRcode = 17; pub const HINAWA_FW_RCODE_BUSY: HinawaFwRcode = 18; pub const HINAWA_FW_RCODE_GENERATION: HinawaFwRcode = 19; pub const HINAWA_FW_RCODE_NO_ACK: HinawaFwRcode = 20; +pub const HINAWA_FW_RCODE_INVALID: HinawaFwRcode = 21; pub type HinawaFwTcode = c_int; pub const HINAWA_FW_TCODE_WRITE_QUADLET_REQUEST: HinawaFwTcode = 0; @@ -50,6 +61,38 @@ pub const HINAWA_FW_TCODE_LOCK_BOUNDED_ADD: HinawaFwTcode = 21; pub const HINAWA_FW_TCODE_LOCK_WRAP_ADD: HinawaFwTcode = 22; pub const HINAWA_FW_TCODE_LOCK_VENDOR_DEPENDENT: HinawaFwTcode = 23; +pub type HinawaSndDiceError = c_int; +pub const HINAWA_SND_DICE_ERROR_TIMEOUT: HinawaSndDiceError = 0; + +pub type HinawaSndEfwStatus = c_int; +pub const HINAWA_SND_EFW_STATUS_OK: HinawaSndEfwStatus = 0; +pub const HINAWA_SND_EFW_STATUS_BAD: HinawaSndEfwStatus = 1; +pub const HINAWA_SND_EFW_STATUS_BAD_COMMAND: HinawaSndEfwStatus = 2; +pub const HINAWA_SND_EFW_STATUS_COMM_ERR: HinawaSndEfwStatus = 3; +pub const HINAWA_SND_EFW_STATUS_BAD_QUAD_COUNT: HinawaSndEfwStatus = 4; +pub const HINAWA_SND_EFW_STATUS_UNSUPPORTED: HinawaSndEfwStatus = 5; +pub const HINAWA_SND_EFW_STATUS_TIMEOUT: HinawaSndEfwStatus = 6; +pub const HINAWA_SND_EFW_STATUS_DSP_TIMEOUT: HinawaSndEfwStatus = 7; +pub const HINAWA_SND_EFW_STATUS_BAD_RATE: HinawaSndEfwStatus = 8; +pub const HINAWA_SND_EFW_STATUS_BAD_CLOCK: HinawaSndEfwStatus = 9; +pub const HINAWA_SND_EFW_STATUS_BAD_CHANNEL: HinawaSndEfwStatus = 10; +pub const HINAWA_SND_EFW_STATUS_BAD_PAN: HinawaSndEfwStatus = 11; +pub const HINAWA_SND_EFW_STATUS_FLASH_BUSY: HinawaSndEfwStatus = 12; +pub const HINAWA_SND_EFW_STATUS_BAD_MIRROR: HinawaSndEfwStatus = 13; +pub const HINAWA_SND_EFW_STATUS_BAD_LED: HinawaSndEfwStatus = 14; +pub const HINAWA_SND_EFW_STATUS_BAD_PARAMETER: HinawaSndEfwStatus = 15; +pub const HINAWA_SND_EFW_STATUS_LARGE_RESP: HinawaSndEfwStatus = 16; + +pub type HinawaSndUnitError = c_int; +pub const HINAWA_SND_UNIT_ERROR_DISCONNECTED: HinawaSndUnitError = 0; +pub const HINAWA_SND_UNIT_ERROR_USED: HinawaSndUnitError = 1; +pub const HINAWA_SND_UNIT_ERROR_OPENED: HinawaSndUnitError = 2; +pub const HINAWA_SND_UNIT_ERROR_NOT_OPENED: HinawaSndUnitError = 3; +pub const HINAWA_SND_UNIT_ERROR_LOCKED: HinawaSndUnitError = 4; +pub const HINAWA_SND_UNIT_ERROR_UNLOCKED: HinawaSndUnitError = 5; +pub const HINAWA_SND_UNIT_ERROR_WRONG_CLASS: HinawaSndUnitError = 6; +pub const HINAWA_SND_UNIT_ERROR_FAILED: HinawaSndUnitError = 7; + pub type HinawaSndUnitType = c_int; pub const HINAWA_SND_UNIT_TYPE_DICE: HinawaSndUnitType = 1; pub const HINAWA_SND_UNIT_TYPE_FIREWORKS: HinawaSndUnitType = 2; @@ -65,12 +108,14 @@ pub const HINAWA_SND_UNIT_TYPE_FIREFACE: HinawaSndUnitType = 8; #[derive(Copy, Clone)] pub struct HinawaFwFcpClass { pub parent_class: HinawaFwRespClass, + pub responded: Option, } impl ::std::fmt::Debug for HinawaFwFcpClass { fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { f.debug_struct(&format!("HinawaFwFcpClass @ {:?}", self as *const _)) .field("parent_class", &self.parent_class) + .field("responded", &self.responded) .finish() } } @@ -107,12 +152,14 @@ pub type HinawaFwNodePrivate = *mut _HinawaFwNodePrivate; #[derive(Copy, Clone)] pub struct HinawaFwReqClass { pub parent_class: gobject::GObjectClass, + pub responded: Option, } impl ::std::fmt::Debug for HinawaFwReqClass { fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { f.debug_struct(&format!("HinawaFwReqClass @ {:?}", self as *const _)) .field("parent_class", &self.parent_class) + .field("responded", &self.responded) .finish() } } @@ -184,12 +231,14 @@ pub type HinawaSndDicePrivate = *mut _HinawaSndDicePrivate; #[derive(Copy, Clone)] pub struct HinawaSndEfwClass { pub parent_class: HinawaSndUnitClass, + pub responded: Option, } impl ::std::fmt::Debug for HinawaSndEfwClass { fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { f.debug_struct(&format!("HinawaSndEfwClass @ {:?}", self as *const _)) .field("parent_class", &self.parent_class) + .field("responded", &self.responded) .finish() } } @@ -425,6 +474,18 @@ impl ::std::fmt::Debug for HinawaSndUnit { extern "C" { + //========================================================================= + // HinawaFwFcpError + //========================================================================= + pub fn hinawa_fw_fcp_error_get_type() -> GType; + pub fn hinawa_fw_fcp_error_quark() -> glib::GQuark; + + //========================================================================= + // HinawaFwNodeError + //========================================================================= + pub fn hinawa_fw_node_error_get_type() -> GType; + pub fn hinawa_fw_node_error_quark() -> glib::GQuark; + //========================================================================= // HinawaFwRcode //========================================================================= @@ -435,6 +496,23 @@ extern "C" { //========================================================================= pub fn hinawa_fw_tcode_get_type() -> GType; + //========================================================================= + // HinawaSndDiceError + //========================================================================= + pub fn hinawa_snd_dice_error_get_type() -> GType; + pub fn hinawa_snd_dice_error_quark() -> glib::GQuark; + + //========================================================================= + // HinawaSndEfwStatus + //========================================================================= + pub fn hinawa_snd_efw_status_get_type() -> GType; + + //========================================================================= + // HinawaSndUnitError + //========================================================================= + pub fn hinawa_snd_unit_error_get_type() -> GType; + pub fn hinawa_snd_unit_error_quark() -> glib::GQuark; + //========================================================================= // HinawaSndUnitType //========================================================================= @@ -445,7 +523,9 @@ extern "C" { //========================================================================= pub fn hinawa_fw_fcp_get_type() -> GType; pub fn hinawa_fw_fcp_new() -> *mut HinawaFwFcp; + pub fn hinawa_fw_fcp_avc_transaction(self_: *mut HinawaFwFcp, cmd: *const u8, cmd_size: size_t, resp: *const *mut u8, resp_size: *mut size_t, timeout_ms: c_uint, error: *mut *mut glib::GError); pub fn hinawa_fw_fcp_bind(self_: *mut HinawaFwFcp, node: *mut HinawaFwNode, error: *mut *mut glib::GError); + pub fn hinawa_fw_fcp_command(self_: *mut HinawaFwFcp, cmd: *const u8, cmd_size: size_t, timeout_ms: c_uint, error: *mut *mut glib::GError); pub fn hinawa_fw_fcp_transaction(self_: *mut HinawaFwFcp, req_frame: *const u8, req_frame_size: size_t, resp_frame: *const *mut u8, resp_frame_size: *mut size_t, error: *mut *mut glib::GError); pub fn hinawa_fw_fcp_unbind(self_: *mut HinawaFwFcp); @@ -463,7 +543,10 @@ extern "C" { //========================================================================= pub fn hinawa_fw_req_get_type() -> GType; pub fn hinawa_fw_req_new() -> *mut HinawaFwReq; + pub fn hinawa_fw_req_error_quark() -> glib::GQuark; pub fn hinawa_fw_req_transaction(self_: *mut HinawaFwReq, node: *mut HinawaFwNode, tcode: HinawaFwTcode, addr: u64, length: size_t, frame: *const *mut u8, frame_size: *mut size_t, error: *mut *mut glib::GError); + pub fn hinawa_fw_req_transaction_async(self_: *mut HinawaFwReq, node: *mut HinawaFwNode, tcode: HinawaFwTcode, addr: u64, length: size_t, frame: *const *mut u8, frame_size: *mut size_t, error: *mut *mut glib::GError); + pub fn hinawa_fw_req_transaction_sync(self_: *mut HinawaFwReq, node: *mut HinawaFwNode, tcode: HinawaFwTcode, addr: u64, length: size_t, frame: *const *mut u8, frame_size: *mut size_t, timeout_ms: c_uint, error: *mut *mut glib::GError); //========================================================================= // HinawaFwResp @@ -495,8 +578,11 @@ extern "C" { //========================================================================= pub fn hinawa_snd_efw_get_type() -> GType; pub fn hinawa_snd_efw_new() -> *mut HinawaSndEfw; + pub fn hinawa_snd_efw_error_quark() -> glib::GQuark; pub fn hinawa_snd_efw_open(self_: *mut HinawaSndEfw, path: *mut c_char, error: *mut *mut glib::GError); pub fn hinawa_snd_efw_transaction(self_: *mut HinawaSndEfw, category: c_uint, command: c_uint, args: *const u32, arg_count: size_t, params: *const *mut u32, param_count: *mut size_t, error: *mut *mut glib::GError); + pub fn hinawa_snd_efw_transaction_async(self_: *mut HinawaSndEfw, category: c_uint, command: c_uint, args: *const u32, arg_count: size_t, resp_seqnum: *mut u32, error: *mut *mut glib::GError); + pub fn hinawa_snd_efw_transaction_sync(self_: *mut HinawaSndEfw, category: c_uint, command: c_uint, args: *const u32, arg_count: size_t, params: *const *mut u32, param_count: *mut size_t, timeout_ms: c_uint, error: *mut *mut glib::GError); //========================================================================= // HinawaSndMotu @@ -528,6 +614,9 @@ extern "C" { // Other functions //========================================================================= pub fn hinawa_sigs_marshal_ENUM__ENUM(closure: *mut gobject::GClosure, return_value: *mut gobject::GValue, n_param_values: c_uint, param_values: *const gobject::GValue, invocation_hint: gpointer, marshal_data: gpointer); + pub fn hinawa_sigs_marshal_VOID__ENUM_POINTER_UINT(closure: *mut gobject::GClosure, return_value: *mut gobject::GValue, n_param_values: c_uint, param_values: *const gobject::GValue, invocation_hint: gpointer, marshal_data: gpointer); + pub fn hinawa_sigs_marshal_VOID__ENUM_UINT_UINT_UINT_POINTER_UINT(closure: *mut gobject::GClosure, return_value: *mut gobject::GValue, n_param_values: c_uint, param_values: *const gobject::GValue, invocation_hint: gpointer, marshal_data: gpointer); + pub fn hinawa_sigs_marshal_VOID__POINTER_UINT(closure: *mut gobject::GClosure, return_value: *mut gobject::GValue, n_param_values: c_uint, param_values: *const gobject::GValue, invocation_hint: gpointer, marshal_data: gpointer); pub fn hinawa_sigs_marshal_VOID__UINT_UINT_UINT(closure: *mut gobject::GClosure, return_value: *mut gobject::GValue, n_param_values: c_uint, param_values: *const gobject::GValue, invocation_hint: gpointer, marshal_data: gpointer); } diff --git a/hinawa-sys/tests/abi.rs b/hinawa-sys/tests/abi.rs index cfd0764..edf0f6d 100644 --- a/hinawa-sys/tests/abi.rs +++ b/hinawa-sys/tests/abi.rs @@ -241,8 +241,10 @@ fn get_c_value(dir: &Path, cc: &Compiler, name: &str) -> Result(), alignment: align_of::()}), ("HinawaFwFcpClass", Layout {size: size_of::(), alignment: align_of::()}), + ("HinawaFwFcpError", Layout {size: size_of::(), alignment: align_of::()}), ("HinawaFwNode", Layout {size: size_of::(), alignment: align_of::()}), ("HinawaFwNodeClass", Layout {size: size_of::(), alignment: align_of::()}), + ("HinawaFwNodeError", Layout {size: size_of::(), alignment: align_of::()}), ("HinawaFwRcode", Layout {size: size_of::(), alignment: align_of::()}), ("HinawaFwReq", Layout {size: size_of::(), alignment: align_of::()}), ("HinawaFwReqClass", Layout {size: size_of::(), alignment: align_of::()}), @@ -253,18 +255,27 @@ const RUST_LAYOUTS: &[(&str, Layout)] = &[ ("HinawaSndDg00xClass", Layout {size: size_of::(), alignment: align_of::()}), ("HinawaSndDice", Layout {size: size_of::(), alignment: align_of::()}), ("HinawaSndDiceClass", Layout {size: size_of::(), alignment: align_of::()}), + ("HinawaSndDiceError", Layout {size: size_of::(), alignment: align_of::()}), ("HinawaSndEfw", Layout {size: size_of::(), alignment: align_of::()}), ("HinawaSndEfwClass", Layout {size: size_of::(), alignment: align_of::()}), + ("HinawaSndEfwStatus", Layout {size: size_of::(), alignment: align_of::()}), ("HinawaSndMotu", Layout {size: size_of::(), alignment: align_of::()}), ("HinawaSndMotuClass", Layout {size: size_of::(), alignment: align_of::()}), ("HinawaSndTscm", Layout {size: size_of::(), alignment: align_of::()}), ("HinawaSndTscmClass", Layout {size: size_of::(), alignment: align_of::()}), ("HinawaSndUnit", Layout {size: size_of::(), alignment: align_of::()}), ("HinawaSndUnitClass", Layout {size: size_of::(), alignment: align_of::()}), + ("HinawaSndUnitError", Layout {size: size_of::(), alignment: align_of::()}), ("HinawaSndUnitType", Layout {size: size_of::(), alignment: align_of::()}), ]; const RUST_CONSTANTS: &[(&str, &str)] = &[ + ("(gint) HINAWA_FW_FCP_ERROR_LARGE_RESP", "1"), + ("(gint) HINAWA_FW_FCP_ERROR_TIMEOUT", "0"), + ("(gint) HINAWA_FW_NODE_ERROR_DISCONNECTED", "0"), + ("(gint) HINAWA_FW_NODE_ERROR_FAILED", "3"), + ("(gint) HINAWA_FW_NODE_ERROR_NOT_OPENED", "2"), + ("(gint) HINAWA_FW_NODE_ERROR_OPENED", "1"), ("(gint) HINAWA_FW_RCODE_ADDRESS_ERROR", "7"), ("(gint) HINAWA_FW_RCODE_BUSY", "18"), ("(gint) HINAWA_FW_RCODE_CANCELLED", "17"), @@ -272,6 +283,7 @@ const RUST_CONSTANTS: &[(&str, &str)] = &[ ("(gint) HINAWA_FW_RCODE_CONFLICT_ERROR", "4"), ("(gint) HINAWA_FW_RCODE_DATA_ERROR", "5"), ("(gint) HINAWA_FW_RCODE_GENERATION", "19"), + ("(gint) HINAWA_FW_RCODE_INVALID", "21"), ("(gint) HINAWA_FW_RCODE_NO_ACK", "20"), ("(gint) HINAWA_FW_RCODE_SEND_ERROR", "16"), ("(gint) HINAWA_FW_RCODE_TYPE_ERROR", "6"), @@ -293,6 +305,32 @@ const RUST_CONSTANTS: &[(&str, &str)] = &[ ("(gint) HINAWA_FW_TCODE_WRITE_BLOCK_REQUEST", "1"), ("(gint) HINAWA_FW_TCODE_WRITE_QUADLET_REQUEST", "0"), ("(gint) HINAWA_FW_TCODE_WRITE_RESPONSE", "2"), + ("(gint) HINAWA_SND_DICE_ERROR_TIMEOUT", "0"), + ("(gint) HINAWA_SND_EFW_STATUS_BAD", "1"), + ("(gint) HINAWA_SND_EFW_STATUS_BAD_CHANNEL", "10"), + ("(gint) HINAWA_SND_EFW_STATUS_BAD_CLOCK", "9"), + ("(gint) HINAWA_SND_EFW_STATUS_BAD_COMMAND", "2"), + ("(gint) HINAWA_SND_EFW_STATUS_BAD_LED", "14"), + ("(gint) HINAWA_SND_EFW_STATUS_BAD_MIRROR", "13"), + ("(gint) HINAWA_SND_EFW_STATUS_BAD_PAN", "11"), + ("(gint) HINAWA_SND_EFW_STATUS_BAD_PARAMETER", "15"), + ("(gint) HINAWA_SND_EFW_STATUS_BAD_QUAD_COUNT", "4"), + ("(gint) HINAWA_SND_EFW_STATUS_BAD_RATE", "8"), + ("(gint) HINAWA_SND_EFW_STATUS_COMM_ERR", "3"), + ("(gint) HINAWA_SND_EFW_STATUS_DSP_TIMEOUT", "7"), + ("(gint) HINAWA_SND_EFW_STATUS_FLASH_BUSY", "12"), + ("(gint) HINAWA_SND_EFW_STATUS_LARGE_RESP", "16"), + ("(gint) HINAWA_SND_EFW_STATUS_OK", "0"), + ("(gint) HINAWA_SND_EFW_STATUS_TIMEOUT", "6"), + ("(gint) HINAWA_SND_EFW_STATUS_UNSUPPORTED", "5"), + ("(gint) HINAWA_SND_UNIT_ERROR_DISCONNECTED", "0"), + ("(gint) HINAWA_SND_UNIT_ERROR_FAILED", "7"), + ("(gint) HINAWA_SND_UNIT_ERROR_LOCKED", "4"), + ("(gint) HINAWA_SND_UNIT_ERROR_NOT_OPENED", "3"), + ("(gint) HINAWA_SND_UNIT_ERROR_OPENED", "2"), + ("(gint) HINAWA_SND_UNIT_ERROR_UNLOCKED", "5"), + ("(gint) HINAWA_SND_UNIT_ERROR_USED", "1"), + ("(gint) HINAWA_SND_UNIT_ERROR_WRONG_CLASS", "6"), ("(gint) HINAWA_SND_UNIT_TYPE_BEBOB", "3"), ("(gint) HINAWA_SND_UNIT_TYPE_DICE", "1"), ("(gint) HINAWA_SND_UNIT_TYPE_DIGI00X", "5"), diff --git a/hinawa/Cargo.toml b/hinawa/Cargo.toml index da9af2c..6ae4f23 100644 --- a/hinawa/Cargo.toml +++ b/hinawa/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hinawa" -version = "0.1.1" +version = "0.2.0" description = "API bindings for libhinawa2 library" authors = ["Takashi Sakamoto "] license = "MIT" @@ -16,7 +16,7 @@ glib = "0.10" glib-sys = "0.10" gobject-sys = "0.10" -hinawa-sys = { path = "../hinawa-sys", version = "0.1" } +hinawa-sys = { path = "../hinawa-sys", version = "0.2" } [dev-dependencies] gir-format-check = "^0.1" diff --git a/hinawa/src/auto/enums.rs b/hinawa/src/auto/enums.rs index f63ec8b..e5c0672 100644 --- a/hinawa/src/auto/enums.rs +++ b/hinawa/src/auto/enums.rs @@ -2,17 +2,201 @@ // from gir-files (https://github.com/gtk-rs/gir-files) // DO NOT EDIT +use glib::error::ErrorDomain; use glib::translate::*; use glib::value::FromValue; use glib::value::FromValueOptional; use glib::value::SetValue; use glib::value::Value; +use glib::Quark; use glib::StaticType; use glib::Type; use gobject_sys; use hinawa_sys; use std::fmt; +#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] +#[derive(Clone, Copy)] +#[non_exhaustive] +pub enum FwFcpError { + Timeout, + LargeResp, + #[doc(hidden)] + __Unknown(i32), +} + +impl fmt::Display for FwFcpError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "FwFcpError::{}", match *self { + FwFcpError::Timeout => "Timeout", + FwFcpError::LargeResp => "LargeResp", + _ => "Unknown", + }) + } +} + +#[doc(hidden)] +impl ToGlib for FwFcpError { + type GlibType = hinawa_sys::HinawaFwFcpError; + + fn to_glib(&self) -> hinawa_sys::HinawaFwFcpError { + match *self { + FwFcpError::Timeout => hinawa_sys::HINAWA_FW_FCP_ERROR_TIMEOUT, + FwFcpError::LargeResp => hinawa_sys::HINAWA_FW_FCP_ERROR_LARGE_RESP, + FwFcpError::__Unknown(value) => value + } + } +} + +#[doc(hidden)] +impl FromGlib for FwFcpError { + fn from_glib(value: hinawa_sys::HinawaFwFcpError) -> Self { + match value { + 0 => FwFcpError::Timeout, + 1 => FwFcpError::LargeResp, + value => FwFcpError::__Unknown(value), + } + } +} + +impl ErrorDomain for FwFcpError { + fn domain() -> Quark { + unsafe { from_glib(hinawa_sys::hinawa_fw_fcp_error_quark()) } + } + + fn code(self) -> i32 { + self.to_glib() + } + + fn from(code: i32) -> Option { + match code { + 0 => Some(FwFcpError::Timeout), + 1 => Some(FwFcpError::LargeResp), + value => Some(FwFcpError::__Unknown(value)), + } + } +} + +impl StaticType for FwFcpError { + fn static_type() -> Type { + unsafe { from_glib(hinawa_sys::hinawa_fw_fcp_error_get_type()) } + } +} + +impl<'a> FromValueOptional<'a> for FwFcpError { + unsafe fn from_value_optional(value: &Value) -> Option { + Some(FromValue::from_value(value)) + } +} + +impl<'a> FromValue<'a> for FwFcpError { + unsafe fn from_value(value: &Value) -> Self { + from_glib(gobject_sys::g_value_get_enum(value.to_glib_none().0)) + } +} + +impl SetValue for FwFcpError { + unsafe fn set_value(value: &mut Value, this: &Self) { + gobject_sys::g_value_set_enum(value.to_glib_none_mut().0, this.to_glib()) + } +} + +#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] +#[derive(Clone, Copy)] +#[non_exhaustive] +pub enum FwNodeError { + Disconnected, + Opened, + NotOpened, + Failed, + #[doc(hidden)] + __Unknown(i32), +} + +impl fmt::Display for FwNodeError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "FwNodeError::{}", match *self { + FwNodeError::Disconnected => "Disconnected", + FwNodeError::Opened => "Opened", + FwNodeError::NotOpened => "NotOpened", + FwNodeError::Failed => "Failed", + _ => "Unknown", + }) + } +} + +#[doc(hidden)] +impl ToGlib for FwNodeError { + type GlibType = hinawa_sys::HinawaFwNodeError; + + fn to_glib(&self) -> hinawa_sys::HinawaFwNodeError { + match *self { + FwNodeError::Disconnected => hinawa_sys::HINAWA_FW_NODE_ERROR_DISCONNECTED, + FwNodeError::Opened => hinawa_sys::HINAWA_FW_NODE_ERROR_OPENED, + FwNodeError::NotOpened => hinawa_sys::HINAWA_FW_NODE_ERROR_NOT_OPENED, + FwNodeError::Failed => hinawa_sys::HINAWA_FW_NODE_ERROR_FAILED, + FwNodeError::__Unknown(value) => value + } + } +} + +#[doc(hidden)] +impl FromGlib for FwNodeError { + fn from_glib(value: hinawa_sys::HinawaFwNodeError) -> Self { + match value { + 0 => FwNodeError::Disconnected, + 1 => FwNodeError::Opened, + 2 => FwNodeError::NotOpened, + 3 => FwNodeError::Failed, + value => FwNodeError::__Unknown(value), + } + } +} + +impl ErrorDomain for FwNodeError { + fn domain() -> Quark { + unsafe { from_glib(hinawa_sys::hinawa_fw_node_error_quark()) } + } + + fn code(self) -> i32 { + self.to_glib() + } + + fn from(code: i32) -> Option { + match code { + 0 => Some(FwNodeError::Disconnected), + 1 => Some(FwNodeError::Opened), + 2 => Some(FwNodeError::NotOpened), + 3 => Some(FwNodeError::Failed), + _ => Some(FwNodeError::Failed), + } + } +} + +impl StaticType for FwNodeError { + fn static_type() -> Type { + unsafe { from_glib(hinawa_sys::hinawa_fw_node_error_get_type()) } + } +} + +impl<'a> FromValueOptional<'a> for FwNodeError { + unsafe fn from_value_optional(value: &Value) -> Option { + Some(FromValue::from_value(value)) + } +} + +impl<'a> FromValue<'a> for FwNodeError { + unsafe fn from_value(value: &Value) -> Self { + from_glib(gobject_sys::g_value_get_enum(value.to_glib_none().0)) + } +} + +impl SetValue for FwNodeError { + unsafe fn set_value(value: &mut Value, this: &Self) { + gobject_sys::g_value_set_enum(value.to_glib_none_mut().0, this.to_glib()) + } +} + #[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] #[derive(Clone, Copy)] #[non_exhaustive] @@ -27,6 +211,7 @@ pub enum FwRcode { Busy, Generation, NoAck, + Invalid, #[doc(hidden)] __Unknown(i32), } @@ -44,6 +229,7 @@ impl fmt::Display for FwRcode { FwRcode::Busy => "Busy", FwRcode::Generation => "Generation", FwRcode::NoAck => "NoAck", + FwRcode::Invalid => "Invalid", _ => "Unknown", }) } @@ -65,6 +251,7 @@ impl ToGlib for FwRcode { FwRcode::Busy => hinawa_sys::HINAWA_FW_RCODE_BUSY, FwRcode::Generation => hinawa_sys::HINAWA_FW_RCODE_GENERATION, FwRcode::NoAck => hinawa_sys::HINAWA_FW_RCODE_NO_ACK, + FwRcode::Invalid => hinawa_sys::HINAWA_FW_RCODE_INVALID, FwRcode::__Unknown(value) => value } } @@ -84,6 +271,7 @@ impl FromGlib for FwRcode { 18 => FwRcode::Busy, 19 => FwRcode::Generation, 20 => FwRcode::NoAck, + 21 => FwRcode::Invalid, value => FwRcode::__Unknown(value), } } @@ -245,6 +433,331 @@ impl SetValue for FwTcode { } } +#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] +#[derive(Clone, Copy)] +#[non_exhaustive] +pub enum SndDiceError { + Timeout, + #[doc(hidden)] + __Unknown(i32), +} + +impl fmt::Display for SndDiceError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "SndDiceError::{}", match *self { + SndDiceError::Timeout => "Timeout", + _ => "Unknown", + }) + } +} + +#[doc(hidden)] +impl ToGlib for SndDiceError { + type GlibType = hinawa_sys::HinawaSndDiceError; + + fn to_glib(&self) -> hinawa_sys::HinawaSndDiceError { + match *self { + SndDiceError::Timeout => hinawa_sys::HINAWA_SND_DICE_ERROR_TIMEOUT, + SndDiceError::__Unknown(value) => value + } + } +} + +#[doc(hidden)] +impl FromGlib for SndDiceError { + fn from_glib(value: hinawa_sys::HinawaSndDiceError) -> Self { + match value { + 0 => SndDiceError::Timeout, + value => SndDiceError::__Unknown(value), + } + } +} + +impl ErrorDomain for SndDiceError { + fn domain() -> Quark { + unsafe { from_glib(hinawa_sys::hinawa_snd_dice_error_quark()) } + } + + fn code(self) -> i32 { + self.to_glib() + } + + fn from(code: i32) -> Option { + match code { + 0 => Some(SndDiceError::Timeout), + value => Some(SndDiceError::__Unknown(value)), + } + } +} + +impl StaticType for SndDiceError { + fn static_type() -> Type { + unsafe { from_glib(hinawa_sys::hinawa_snd_dice_error_get_type()) } + } +} + +impl<'a> FromValueOptional<'a> for SndDiceError { + unsafe fn from_value_optional(value: &Value) -> Option { + Some(FromValue::from_value(value)) + } +} + +impl<'a> FromValue<'a> for SndDiceError { + unsafe fn from_value(value: &Value) -> Self { + from_glib(gobject_sys::g_value_get_enum(value.to_glib_none().0)) + } +} + +impl SetValue for SndDiceError { + unsafe fn set_value(value: &mut Value, this: &Self) { + gobject_sys::g_value_set_enum(value.to_glib_none_mut().0, this.to_glib()) + } +} + +#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] +#[derive(Clone, Copy)] +#[non_exhaustive] +pub enum SndEfwStatus { + Ok, + Bad, + BadCommand, + CommErr, + BadQuadCount, + Unsupported, + Timeout, + DspTimeout, + BadRate, + BadClock, + BadChannel, + BadPan, + FlashBusy, + BadMirror, + BadLed, + BadParameter, + LargeResp, + #[doc(hidden)] + __Unknown(i32), +} + +impl fmt::Display for SndEfwStatus { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "SndEfwStatus::{}", match *self { + SndEfwStatus::Ok => "Ok", + SndEfwStatus::Bad => "Bad", + SndEfwStatus::BadCommand => "BadCommand", + SndEfwStatus::CommErr => "CommErr", + SndEfwStatus::BadQuadCount => "BadQuadCount", + SndEfwStatus::Unsupported => "Unsupported", + SndEfwStatus::Timeout => "Timeout", + SndEfwStatus::DspTimeout => "DspTimeout", + SndEfwStatus::BadRate => "BadRate", + SndEfwStatus::BadClock => "BadClock", + SndEfwStatus::BadChannel => "BadChannel", + SndEfwStatus::BadPan => "BadPan", + SndEfwStatus::FlashBusy => "FlashBusy", + SndEfwStatus::BadMirror => "BadMirror", + SndEfwStatus::BadLed => "BadLed", + SndEfwStatus::BadParameter => "BadParameter", + SndEfwStatus::LargeResp => "LargeResp", + _ => "Unknown", + }) + } +} + +#[doc(hidden)] +impl ToGlib for SndEfwStatus { + type GlibType = hinawa_sys::HinawaSndEfwStatus; + + fn to_glib(&self) -> hinawa_sys::HinawaSndEfwStatus { + match *self { + SndEfwStatus::Ok => hinawa_sys::HINAWA_SND_EFW_STATUS_OK, + SndEfwStatus::Bad => hinawa_sys::HINAWA_SND_EFW_STATUS_BAD, + SndEfwStatus::BadCommand => hinawa_sys::HINAWA_SND_EFW_STATUS_BAD_COMMAND, + SndEfwStatus::CommErr => hinawa_sys::HINAWA_SND_EFW_STATUS_COMM_ERR, + SndEfwStatus::BadQuadCount => hinawa_sys::HINAWA_SND_EFW_STATUS_BAD_QUAD_COUNT, + SndEfwStatus::Unsupported => hinawa_sys::HINAWA_SND_EFW_STATUS_UNSUPPORTED, + SndEfwStatus::Timeout => hinawa_sys::HINAWA_SND_EFW_STATUS_TIMEOUT, + SndEfwStatus::DspTimeout => hinawa_sys::HINAWA_SND_EFW_STATUS_DSP_TIMEOUT, + SndEfwStatus::BadRate => hinawa_sys::HINAWA_SND_EFW_STATUS_BAD_RATE, + SndEfwStatus::BadClock => hinawa_sys::HINAWA_SND_EFW_STATUS_BAD_CLOCK, + SndEfwStatus::BadChannel => hinawa_sys::HINAWA_SND_EFW_STATUS_BAD_CHANNEL, + SndEfwStatus::BadPan => hinawa_sys::HINAWA_SND_EFW_STATUS_BAD_PAN, + SndEfwStatus::FlashBusy => hinawa_sys::HINAWA_SND_EFW_STATUS_FLASH_BUSY, + SndEfwStatus::BadMirror => hinawa_sys::HINAWA_SND_EFW_STATUS_BAD_MIRROR, + SndEfwStatus::BadLed => hinawa_sys::HINAWA_SND_EFW_STATUS_BAD_LED, + SndEfwStatus::BadParameter => hinawa_sys::HINAWA_SND_EFW_STATUS_BAD_PARAMETER, + SndEfwStatus::LargeResp => hinawa_sys::HINAWA_SND_EFW_STATUS_LARGE_RESP, + SndEfwStatus::__Unknown(value) => value + } + } +} + +#[doc(hidden)] +impl FromGlib for SndEfwStatus { + fn from_glib(value: hinawa_sys::HinawaSndEfwStatus) -> Self { + match value { + 0 => SndEfwStatus::Ok, + 1 => SndEfwStatus::Bad, + 2 => SndEfwStatus::BadCommand, + 3 => SndEfwStatus::CommErr, + 4 => SndEfwStatus::BadQuadCount, + 5 => SndEfwStatus::Unsupported, + 6 => SndEfwStatus::Timeout, + 7 => SndEfwStatus::DspTimeout, + 8 => SndEfwStatus::BadRate, + 9 => SndEfwStatus::BadClock, + 10 => SndEfwStatus::BadChannel, + 11 => SndEfwStatus::BadPan, + 12 => SndEfwStatus::FlashBusy, + 13 => SndEfwStatus::BadMirror, + 14 => SndEfwStatus::BadLed, + 15 => SndEfwStatus::BadParameter, + 16 => SndEfwStatus::LargeResp, + value => SndEfwStatus::__Unknown(value), + } + } +} + +impl StaticType for SndEfwStatus { + fn static_type() -> Type { + unsafe { from_glib(hinawa_sys::hinawa_snd_efw_status_get_type()) } + } +} + +impl<'a> FromValueOptional<'a> for SndEfwStatus { + unsafe fn from_value_optional(value: &Value) -> Option { + Some(FromValue::from_value(value)) + } +} + +impl<'a> FromValue<'a> for SndEfwStatus { + unsafe fn from_value(value: &Value) -> Self { + from_glib(gobject_sys::g_value_get_enum(value.to_glib_none().0)) + } +} + +impl SetValue for SndEfwStatus { + unsafe fn set_value(value: &mut Value, this: &Self) { + gobject_sys::g_value_set_enum(value.to_glib_none_mut().0, this.to_glib()) + } +} + +#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] +#[derive(Clone, Copy)] +#[non_exhaustive] +pub enum SndUnitError { + Disconnected, + Used, + Opened, + NotOpened, + Locked, + Unlocked, + WrongClass, + Failed, + #[doc(hidden)] + __Unknown(i32), +} + +impl fmt::Display for SndUnitError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "SndUnitError::{}", match *self { + SndUnitError::Disconnected => "Disconnected", + SndUnitError::Used => "Used", + SndUnitError::Opened => "Opened", + SndUnitError::NotOpened => "NotOpened", + SndUnitError::Locked => "Locked", + SndUnitError::Unlocked => "Unlocked", + SndUnitError::WrongClass => "WrongClass", + SndUnitError::Failed => "Failed", + _ => "Unknown", + }) + } +} + +#[doc(hidden)] +impl ToGlib for SndUnitError { + type GlibType = hinawa_sys::HinawaSndUnitError; + + fn to_glib(&self) -> hinawa_sys::HinawaSndUnitError { + match *self { + SndUnitError::Disconnected => hinawa_sys::HINAWA_SND_UNIT_ERROR_DISCONNECTED, + SndUnitError::Used => hinawa_sys::HINAWA_SND_UNIT_ERROR_USED, + SndUnitError::Opened => hinawa_sys::HINAWA_SND_UNIT_ERROR_OPENED, + SndUnitError::NotOpened => hinawa_sys::HINAWA_SND_UNIT_ERROR_NOT_OPENED, + SndUnitError::Locked => hinawa_sys::HINAWA_SND_UNIT_ERROR_LOCKED, + SndUnitError::Unlocked => hinawa_sys::HINAWA_SND_UNIT_ERROR_UNLOCKED, + SndUnitError::WrongClass => hinawa_sys::HINAWA_SND_UNIT_ERROR_WRONG_CLASS, + SndUnitError::Failed => hinawa_sys::HINAWA_SND_UNIT_ERROR_FAILED, + SndUnitError::__Unknown(value) => value + } + } +} + +#[doc(hidden)] +impl FromGlib for SndUnitError { + fn from_glib(value: hinawa_sys::HinawaSndUnitError) -> Self { + match value { + 0 => SndUnitError::Disconnected, + 1 => SndUnitError::Used, + 2 => SndUnitError::Opened, + 3 => SndUnitError::NotOpened, + 4 => SndUnitError::Locked, + 5 => SndUnitError::Unlocked, + 6 => SndUnitError::WrongClass, + 7 => SndUnitError::Failed, + value => SndUnitError::__Unknown(value), + } + } +} + +impl ErrorDomain for SndUnitError { + fn domain() -> Quark { + unsafe { from_glib(hinawa_sys::hinawa_snd_unit_error_quark()) } + } + + fn code(self) -> i32 { + self.to_glib() + } + + fn from(code: i32) -> Option { + match code { + 0 => Some(SndUnitError::Disconnected), + 1 => Some(SndUnitError::Used), + 2 => Some(SndUnitError::Opened), + 3 => Some(SndUnitError::NotOpened), + 4 => Some(SndUnitError::Locked), + 5 => Some(SndUnitError::Unlocked), + 6 => Some(SndUnitError::WrongClass), + 7 => Some(SndUnitError::Failed), + _ => Some(SndUnitError::Failed), + } + } +} + +impl StaticType for SndUnitError { + fn static_type() -> Type { + unsafe { from_glib(hinawa_sys::hinawa_snd_unit_error_get_type()) } + } +} + +impl<'a> FromValueOptional<'a> for SndUnitError { + unsafe fn from_value_optional(value: &Value) -> Option { + Some(FromValue::from_value(value)) + } +} + +impl<'a> FromValue<'a> for SndUnitError { + unsafe fn from_value(value: &Value) -> Self { + from_glib(gobject_sys::g_value_get_enum(value.to_glib_none().0)) + } +} + +impl SetValue for SndUnitError { + unsafe fn set_value(value: &mut Value, this: &Self) { + gobject_sys::g_value_set_enum(value.to_glib_none_mut().0, this.to_glib()) + } +} + #[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] #[derive(Clone, Copy)] #[non_exhaustive] diff --git a/hinawa/src/auto/fw_fcp.rs b/hinawa/src/auto/fw_fcp.rs index f1384bc..e5a2dc0 100644 --- a/hinawa/src/auto/fw_fcp.rs +++ b/hinawa/src/auto/fw_fcp.rs @@ -47,6 +47,8 @@ pub const NONE_FW_FCP: Option<&FwFcp> = None; pub trait FwFcpExt: 'static { fn bind>(&self, node: &P) -> Result<(), glib::Error>; + fn command(&self, cmd: &[u8], timeout_ms: u32) -> Result<(), glib::Error>; + fn unbind(&self); fn get_property_is_bound(&self) -> bool; @@ -69,6 +71,15 @@ impl> FwFcpExt for O { } } + fn command(&self, cmd: &[u8], timeout_ms: u32) -> Result<(), glib::Error> { + let cmd_size = cmd.len() as usize; + unsafe { + let mut error = ptr::null_mut(); + let _ = hinawa_sys::hinawa_fw_fcp_command(self.as_ref().to_glib_none().0, cmd.to_glib_none().0, cmd_size, timeout_ms, &mut error); + if error.is_null() { Ok(()) } else { Err(from_glib_full(error)) } + } + } + fn unbind(&self) { unsafe { hinawa_sys::hinawa_fw_fcp_unbind(self.as_ref().to_glib_none().0); diff --git a/hinawa/src/auto/mod.rs b/hinawa/src/auto/mod.rs index c5fc5d5..0c4ab75 100644 --- a/hinawa/src/auto/mod.rs +++ b/hinawa/src/auto/mod.rs @@ -43,8 +43,13 @@ pub use self::snd_unit::{SndUnit, SndUnitClass, NONE_SND_UNIT}; pub use self::snd_unit::SndUnitExt; mod enums; +pub use self::enums::FwFcpError; +pub use self::enums::FwNodeError; pub use self::enums::FwRcode; pub use self::enums::FwTcode; +pub use self::enums::SndDiceError; +pub use self::enums::SndEfwStatus; +pub use self::enums::SndUnitError; pub use self::enums::SndUnitType; #[doc(hidden)] diff --git a/hinawa/src/auto/snd_efw.rs b/hinawa/src/auto/snd_efw.rs index 3af42c2..d80458e 100644 --- a/hinawa/src/auto/snd_efw.rs +++ b/hinawa/src/auto/snd_efw.rs @@ -7,6 +7,7 @@ use glib::object::IsA; use glib::translate::*; use hinawa_sys; use std::fmt; +use std::mem; use std::ptr; use SndUnit; @@ -36,6 +37,8 @@ pub const NONE_SND_EFW: Option<&SndEfw> = None; pub trait SndEfwExt: 'static { fn open(&self, path: &str) -> Result<(), glib::Error>; + + fn transaction_async(&self, category: u32, command: u32, args: &[u32]) -> Result; } impl> SndEfwExt for O { @@ -46,6 +49,17 @@ impl> SndEfwExt for O { if error.is_null() { Ok(()) } else { Err(from_glib_full(error)) } } } + + fn transaction_async(&self, category: u32, command: u32, args: &[u32]) -> Result { + let arg_count = args.len() as usize; + unsafe { + let mut resp_seqnum = mem::MaybeUninit::uninit(); + let mut error = ptr::null_mut(); + let _ = hinawa_sys::hinawa_snd_efw_transaction_async(self.as_ref().to_glib_none().0, category, command, args.to_glib_none().0, arg_count, resp_seqnum.as_mut_ptr(), &mut error); + let resp_seqnum = resp_seqnum.assume_init(); + if error.is_null() { Ok(resp_seqnum) } else { Err(from_glib_full(error)) } + } + } } impl fmt::Display for SndEfw { diff --git a/hinawa/src/enums.rs b/hinawa/src/enums.rs new file mode 100644 index 0000000..255c1fb --- /dev/null +++ b/hinawa/src/enums.rs @@ -0,0 +1,74 @@ +// SPDX-License-Identifier: MIT +use glib::error::ErrorDomain; +use glib::translate::*; +use glib::Quark; +use hinawa_sys; + +use FwRcode; +use SndEfwStatus; + +pub type FwReqError = FwRcode; + +impl ErrorDomain for FwReqError { + fn domain() -> Quark { + unsafe { from_glib(hinawa_sys::hinawa_fw_req_error_quark()) } + } + + fn code(self) -> i32 { + self.to_glib() + } + + fn from(code: i32) -> Option { + let val = match code { + 0 => Self::Complete, + 4 => Self::ConflictError, + 5 => Self::DataError, + 6 => Self::TypeError, + 7 => Self::AddressError, + 16 => Self::SendError, + 17 => Self::Cancelled, + 18 => Self::Busy, + 19 => Self::Generation, + 20 => Self::NoAck, + 21 => Self::Invalid, + value => Self::__Unknown(value), + }; + Some(val) + } +} + +pub type SndEfwError = SndEfwStatus; + +impl ErrorDomain for SndEfwError { + fn domain() -> Quark { + unsafe { from_glib(hinawa_sys::hinawa_snd_efw_error_quark()) } + } + + fn code(self) -> i32 { + self.to_glib() + } + + fn from(code: i32) -> Option { + let val = match code { + 0 => Self::Ok, + 1 => Self::Bad, + 2 => Self::BadCommand, + 3 => Self::CommErr, + 4 => Self::BadQuadCount, + 5 => Self::Unsupported, + 6 => Self::Timeout, + 7 => Self::DspTimeout, + 8 => Self::BadRate, + 9 => Self::BadClock, + 10 => Self::BadChannel, + 11 => Self::BadPan, + 12 => Self::FlashBusy, + 13 => Self::BadMirror, + 14 => Self::BadLed, + 15 => Self::BadParameter, + 16 => Self::LargeResp, + code => Self::__Unknown(code), + }; + Some(val) + } +} diff --git a/hinawa/src/fw_fcp.rs b/hinawa/src/fw_fcp.rs index c9c43e1..a515456 100644 --- a/hinawa/src/fw_fcp.rs +++ b/hinawa/src/fw_fcp.rs @@ -1,15 +1,46 @@ // SPDX-License-Identifier: MIT use glib::object::IsA; use glib::translate::*; +use glib::object::Cast; +use glib::signal::connect_raw; +use glib::signal::SignalHandlerId; use FwFcp; pub trait FwFcpExtManual { + fn avc_transaction(&self, req_frame: &[u8], resp_frame: &mut [u8], timeout_ms: u32) + -> Result; fn transaction(&self, req_frame: &[u8], resp_frame: &mut [u8]) -> Result; + fn connect_responded(&self, f: F) -> SignalHandlerId + where F: Fn(&Self, &[u8]) + 'static; } impl> FwFcpExtManual for O { + fn avc_transaction(&self, req_frame: &[u8], resp_frame: &mut [u8], timeout_ms: u32) + -> Result + { + unsafe { + let mut resp_frame_size = resp_frame.len(); + let mut error = std::ptr::null_mut(); + + hinawa_sys::hinawa_fw_fcp_avc_transaction( + self.as_ref().to_glib_none().0, + req_frame.as_ptr(), + req_frame.len(), + &mut resp_frame.as_mut_ptr(), + &mut resp_frame_size, + timeout_ms, + &mut error); + + if error.is_null() { + Ok(resp_frame_size) + } else { + Err(from_glib_full(error)) + } + } + } + fn transaction(&self, req_frame: &[u8], resp_frame: &mut [u8]) -> Result { @@ -32,4 +63,35 @@ impl> FwFcpExtManual for O { } } } + + fn connect_responded(&self, f: F) -> SignalHandlerId + where F: Fn(&Self, &[u8]) + 'static + { + unsafe extern "C" fn responded_trampoline( + this: *mut hinawa_sys::HinawaFwFcp, + frame: *const u8, + length: libc::c_uint, + f: glib_sys::gpointer, + ) where + P: IsA, + 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 = 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:: as *const (), + )), + std::boxed::Box::into_raw(f), + ) + } + } } diff --git a/hinawa/src/fw_req.rs b/hinawa/src/fw_req.rs index 817698b..debd4fc 100644 --- a/hinawa/src/fw_req.rs +++ b/hinawa/src/fw_req.rs @@ -1,18 +1,78 @@ // SPDX-License-Identifier: MIT use glib::object::IsA; use glib::translate::*; +use glib::object::Cast; +use glib::signal::connect_raw; +use glib::signal::SignalHandlerId; use FwReq; use FwTcode; use FwNode; +use FwRcode; pub trait FwReqExtManual { + fn transaction_async>(&self, node: &P, tcode: FwTcode, + addr: u64, length: usize, frame: &mut [u8]) + ->Result<(), glib::Error>; + fn transaction_sync>(&self, node: &P, tcode: FwTcode, + addr: u64, length: usize, frame: &mut [u8], + timeout_ms: u32) + ->Result<(), glib::Error>; fn transaction>(&self, node: &P, tcode: FwTcode, addr: u64, length: usize, frame: &mut [u8]) ->Result<(), glib::Error>; + fn connect_responded(&self, f: F) -> SignalHandlerId + where F: Fn(&Self, FwRcode, &[u8]) + 'static; } impl> FwReqExtManual for O { + fn transaction_async>(&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(); + + hinawa_sys::hinawa_fw_req_transaction_async( + self.as_ref().to_glib_none().0, + node.as_ref().to_glib_none().0, + tcode.to_glib(), addr, length, + &mut frame.as_mut_ptr(), &mut frame_size, + &mut error); + + if error.is_null() { + Ok(()) + } else { + Err(from_glib_full(error)) + } + } + } + + fn transaction_sync>(&self, node: &P, tcode: FwTcode, + addr: u64, length: usize, frame: &mut [u8], + timeout_ms: u32) + ->Result<(), glib::Error> + { + unsafe { + let mut frame_size = frame.len(); + let mut error = std::ptr::null_mut(); + + hinawa_sys::hinawa_fw_req_transaction_sync( + self.as_ref().to_glib_none().0, + node.as_ref().to_glib_none().0, + tcode.to_glib(), addr, length, + &mut frame.as_mut_ptr(), &mut frame_size, + timeout_ms, &mut error); + + if error.is_null() { + Ok(()) + } else { + Err(from_glib_full(error)) + } + } + } + fn transaction>(&self, node: &P, tcode: FwTcode, addr: u64, length: usize, frame: &mut [u8]) ->Result<(), glib::Error> @@ -35,4 +95,37 @@ impl> FwReqExtManual for O { } } } + + fn connect_responded(&self, f: F) -> SignalHandlerId + where F: Fn(&Self, FwRcode, &[u8]) + 'static + { + unsafe extern "C" fn responded_trampoline( + this: *mut hinawa_sys::HinawaFwReq, + rcode: hinawa_sys::HinawaFwRcode, + frame: *const u8, + length: libc::c_uint, + f: glib_sys::gpointer, + ) where + P: IsA, + 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 = 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:: as *const (), + )), + std::boxed::Box::into_raw(f), + ) + } + } } diff --git a/hinawa/src/lib.rs b/hinawa/src/lib.rs index 895add2..f836511 100644 --- a/hinawa/src/lib.rs +++ b/hinawa/src/lib.rs @@ -30,3 +30,6 @@ pub use snd_efw::*; mod snd_tscm; pub use snd_tscm::*; + +mod enums; +pub use enums::*; diff --git a/hinawa/src/snd_efw.rs b/hinawa/src/snd_efw.rs index 6862a1f..e47c037 100644 --- a/hinawa/src/snd_efw.rs +++ b/hinawa/src/snd_efw.rs @@ -1,12 +1,21 @@ // SPDX-License-Identifier: MIT use glib::object::IsA; use glib::translate::*; +use glib::object::Cast; +use glib::signal::connect_raw; +use glib::signal::SignalHandlerId; use SndEfw; +use SndEfwStatus; pub trait SndEfwExtManual { fn transaction(&self, category: u32, command: u32, args: &[u32], params: &mut [u32]) -> Result; + fn transaction_sync(&self, category: u32, command: u32, args: Option<&[u32]>, + params: Option<&mut [u32]>, timeout_ms: u32) + -> Result; + fn connect_responded(&self, f: F) -> SignalHandlerId + where F: Fn(&Self, SndEfwStatus, u32, u32, u32, &[u32]) + 'static; } impl> SndEfwExtManual for O { @@ -34,4 +43,76 @@ impl> SndEfwExtManual for O { } } } + + fn transaction_sync(&self, category: u32, command: u32, args: Option<&[u32]>, + params: Option<&mut [u32]>, timeout_ms: u32) + -> Result { + unsafe { + let (arg_ptr, arg_count) = match args { + Some(a) => (a.as_ptr(), a.len()), + None => (std::ptr::null(), 0), + }; + let (mut param_ptr, mut param_count) = match params { + Some(p) => (p.as_mut_ptr(), p.len()), + None => (std::ptr::null_mut(), 0), + }; + let mut error = std::ptr::null_mut(); + + hinawa_sys::hinawa_snd_efw_transaction_sync( + self.as_ref().to_glib_none().0, + category, + command, + arg_ptr, + arg_count, + &mut param_ptr, + &mut param_count, + timeout_ms, + &mut error); + + if error.is_null() { + Ok(param_count) + } else { + Err(from_glib_full(error)) + } + } + } + + fn connect_responded(&self, f: F) -> SignalHandlerId + where F: Fn(&Self, SndEfwStatus, u32, u32, u32, &[u32]) + 'static + { + unsafe extern "C" fn responded_trampoline( + this: *mut hinawa_sys::HinawaSndEfw, + status: hinawa_sys::HinawaSndEfwStatus, + seqnum: u32, + command: u32, + category: u32, + frame: *const u32, + length: libc::c_uint, + f: glib_sys::gpointer, + ) where + P: IsA, + F: Fn(&P, SndEfwStatus, u32, u32, u32, &[u32]) + 'static, + { + let f: &F = &*(f as *const F); + f( + &SndEfw::from_glib_borrow(this).unsafe_cast_ref(), + from_glib(status), + seqnum, + command, + category, + std::slice::from_raw_parts(frame, length as usize), + ) + } + unsafe { + let f: std::boxed::Box = 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:: as *const (), + )), + std::boxed::Box::into_raw(f), + ) + } + } }