Skip to content

Commit

Permalink
Merge pull request #169 from Y-Nak/allow-cast
Browse files Browse the repository at this point in the history
Allow implicit cast between (GenICam) int, float, and enum
  • Loading branch information
Y-Nak committed Aug 29, 2023
2 parents 513cb25 + 9902369 commit 9695010
Show file tree
Hide file tree
Showing 9 changed files with 271 additions and 87 deletions.
2 changes: 1 addition & 1 deletion device/src/u3v/async_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ impl Drop for AsyncTransfer {
/// timeout, or error, instead of potentially returning early.
///
/// This design is based on
/// https://libusb.sourceforge.io/api-1.0/libusb_mtasync.html#threadwait
/// <https://libusb.sourceforge.io/api-1.0/libusb_mtasync.html#threadwait>
fn poll_completed(
ctx: &impl UsbContext,
timeout: Duration,
Expand Down
6 changes: 3 additions & 3 deletions genapi/src/boolean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl IBoolean for BooleanNode {
store: &impl NodeStore,
cx: &mut ValueCtxt<T, U>,
) -> GenApiResult<bool> {
let value = self.value.value(device, store, cx)?;
let value: i64 = self.value.value(device, store, cx)?;
if value == self.on_value {
Ok(true)
} else if value == self.off_value {
Expand Down Expand Up @@ -102,7 +102,7 @@ impl IBoolean for BooleanNode {
cx: &mut ValueCtxt<T, U>,
) -> GenApiResult<bool> {
Ok(self.elem_base.is_readable(device, store, cx)?
&& self.value.is_readable(device, store, cx)?)
&& IValue::<i64>::is_readable(&self.value, device, store, cx)?)
}

#[tracing::instrument(skip(self, device, store, cx),
Expand All @@ -115,7 +115,7 @@ impl IBoolean for BooleanNode {
cx: &mut ValueCtxt<T, U>,
) -> GenApiResult<bool> {
Ok(self.elem_base.is_writable(device, store, cx)?
&& self.value.is_writable(device, store, cx)?)
&& IValue::<i64>::is_writable(&self.value, device, store, cx)?)
}
}

Expand Down
15 changes: 7 additions & 8 deletions genapi/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use super::{
elem_type::ImmOrPNode,
interface::{ICommand, IInteger, INode},
interface::{ICommand, INode},
ivalue::IValue,
node_base::{NodeAttributeBase, NodeBase, NodeElementBase},
store::{CacheStore, IntegerId, NodeStore, ValueStore},
Expand Down Expand Up @@ -59,7 +59,7 @@ impl ICommand for CommandNode {
) -> GenApiResult<()> {
cx.invalidate_cache_by(self.node_base().id());

let value = self.command_value.value(device, store, cx)?;
let value: i64 = self.command_value.value(device, store, cx)?;
self.value.set_value(value, device, store, cx)
}

Expand All @@ -71,15 +71,14 @@ impl ICommand for CommandNode {
store: &impl NodeStore,
cx: &mut ValueCtxt<T, U>,
) -> GenApiResult<bool> {
let nid = match self.value {
let node = match self.value {
ImmOrPNode::Imm(..) => return Ok(true),
ImmOrPNode::PNode(nid) => nid,
};

cx.invalidate_cache_of(nid);
let node = nid.expect_iinteger_kind(store)?;
if node.is_readable(device, store, cx)? {
let command_value = self.command_value.value(device, store, cx)?;
cx.invalidate_cache_of(node);
if IValue::<i64>::is_readable(&node, device, store, cx)? {
let command_value: i64 = self.command_value.value(device, store, cx)?;
let reg_value = node.value(device, store, cx)?;
Ok(command_value != reg_value)
} else {
Expand All @@ -97,6 +96,6 @@ impl ICommand for CommandNode {
cx: &mut ValueCtxt<T, U>,
) -> GenApiResult<bool> {
Ok(self.elem_base.is_writable(device, store, cx)?
&& self.value.is_writable(device, store, cx)?)
&& IValue::<i64>::is_writable(&self.value, device, store, cx)?)
}
}
11 changes: 4 additions & 7 deletions genapi/src/elem_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use std::marker::PhantomData;

use super::{
interface::IInteger,
ivalue::IValue,
store::{CacheStore, NodeId, NodeStore, ValueStore},
Device, GenApiResult, ValueCtxt,
Expand Down Expand Up @@ -281,7 +280,7 @@ impl AddressKind {
) -> GenApiResult<i64> {
match self {
Self::Address(i) => i.value(device, store, cx),
Self::IntSwissKnife(nid) => nid.expect_iinteger_kind(store)?.value(device, store, cx),
Self::IntSwissKnife(nid) => nid.value(device, store, cx),
Self::PIndex(p_index) => p_index.value(device, store, cx),
}
}
Expand Down Expand Up @@ -310,12 +309,10 @@ impl RegPIndex {
store: &impl NodeStore,
cx: &mut ValueCtxt<T, U>,
) -> GenApiResult<i64> {
let base = self
.p_index
.expect_iinteger_kind(store)?
.value(device, store, cx)?;
let base = self.p_index.value(device, store, cx)?;
if let Some(offset) = &self.offset {
Ok(base + offset.value(device, store, cx)?)
let offset: i64 = offset.value(device, store, cx)?;
Ok(base + offset)
} else {
Ok(base)
}
Expand Down
4 changes: 2 additions & 2 deletions genapi/src/enumeration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ impl IEnumeration for EnumerationNode {
cx: &mut ValueCtxt<T, U>,
) -> GenApiResult<bool> {
Ok(self.elem_base.is_readable(device, store, cx)?
&& self.value.is_readable(device, store, cx)?)
&& IValue::<i64>::is_readable(&self.value, device, store, cx)?)
}

#[tracing::instrument(skip(self, device, store, cx),
Expand All @@ -165,7 +165,7 @@ impl IEnumeration for EnumerationNode {
cx: &mut ValueCtxt<T, U>,
) -> GenApiResult<bool> {
Ok(self.elem_base.is_writable(device, store, cx)?
&& self.value.is_writable(device, store, cx)?)
&& IValue::<i64>::is_writable(&self.value, device, store, cx)?)
}
}

Expand Down
4 changes: 2 additions & 2 deletions genapi/src/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ impl IFloat for FloatNode {
cx: &mut ValueCtxt<T, U>,
) -> GenApiResult<bool> {
Ok(self.elem_base.is_readable(device, store, cx)?
&& self.value_kind.is_readable(device, store, cx)?)
&& IValue::<f64>::is_readable(&self.value_kind, device, store, cx)?)
}

#[tracing::instrument(skip(self, device, store, cx),
Expand All @@ -211,6 +211,6 @@ impl IFloat for FloatNode {
cx: &mut ValueCtxt<T, U>,
) -> GenApiResult<bool> {
Ok(self.elem_base.is_writable(device, store, cx)?
&& self.value_kind.is_writable(device, store, cx)?)
&& IValue::<f64>::is_writable(&self.value_kind, device, store, cx)?)
}
}
4 changes: 2 additions & 2 deletions genapi/src/integer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ impl IInteger for IntegerNode {
cx: &mut ValueCtxt<T, U>,
) -> GenApiResult<bool> {
Ok(self.elem_base.is_readable(device, store, cx)?
&& self.value_kind.is_readable(device, store, cx)?)
&& IValue::<i64>::is_readable(&self.value_kind, device, store, cx)?)
}

#[tracing::instrument(skip(self, device, store, cx),
Expand All @@ -201,7 +201,7 @@ impl IInteger for IntegerNode {
cx: &mut ValueCtxt<T, U>,
) -> GenApiResult<bool> {
Ok(self.elem_base.is_writable(device, store, cx)?
&& self.value_kind.is_writable(device, store, cx)?)
&& IValue::<i64>::is_writable(&self.value_kind, device, store, cx)?)
}
}

Expand Down
Loading

0 comments on commit 9695010

Please sign in to comment.