use rs_teststand_sys::Dispatch;
use crate::Error;
use crate::dispids::sequence_context;
#[derive(Debug)]
pub struct SequenceContext {
dispatch: Box<dyn Dispatch>,
}
impl SequenceContext {
pub(crate) fn new(dispatch: Box<dyn Dispatch>) -> Self {
Self { dispatch }
}
pub fn as_property_object(&self) -> Result<crate::PropertyObject, Error> {
Ok(crate::PropertyObject::new(
self.dispatch
.call(sequence_context::AS_PROPERTY_OBJECT, &[])?
.into_object()?,
))
}
pub fn locals(&self) -> Result<crate::PropertyObject, Error> {
Ok(crate::PropertyObject::new(
self.dispatch.get(sequence_context::LOCALS)?.into_object()?,
))
}
pub fn parameters(&self) -> Result<crate::PropertyObject, Error> {
Ok(crate::PropertyObject::new(
self.dispatch
.get(sequence_context::PARAMETERS)?
.into_object()?,
))
}
pub fn file_globals(&self) -> Result<crate::PropertyObject, Error> {
Ok(crate::PropertyObject::new(
self.dispatch
.get(sequence_context::FILE_GLOBALS)?
.into_object()?,
))
}
pub fn station_globals(&self) -> Result<crate::PropertyObject, Error> {
Ok(crate::PropertyObject::new(
self.dispatch
.get(sequence_context::STATION_GLOBALS)?
.into_object()?,
))
}
pub fn run_state(&self) -> Result<crate::PropertyObject, Error> {
self.as_property_object()?
.get_property_object("RunState", crate::property::PropertyOptions::NONE.bits())
}
pub fn execution(&self) -> Result<crate::Execution, Error> {
Ok(crate::Execution::new(
self.dispatch
.get(sequence_context::EXECUTION)?
.into_object()?,
))
}
pub fn thread(&self) -> Result<crate::Thread, Error> {
Ok(crate::Thread::new(
self.dispatch.get(sequence_context::THREAD)?.into_object()?,
))
}
pub fn sequence_file(&self) -> Result<crate::SequenceFile, Error> {
Ok(crate::SequenceFile::new(
self.dispatch
.get(sequence_context::SEQUENCE_FILE)?
.into_object()?,
))
}
pub fn sequence(&self) -> Result<crate::Sequence, Error> {
Ok(crate::Sequence::new(
self.dispatch
.get(sequence_context::SEQUENCE)?
.into_object()?,
))
}
pub fn call_stack_depth(&self) -> Result<i32, Error> {
Ok(self
.dispatch
.get(sequence_context::CALL_STACK_DEPTH)?
.as_i32()?)
}
pub fn step_index(&self) -> Result<i32, Error> {
Ok(self.dispatch.get(sequence_context::STEP_INDEX)?.as_i32()?)
}
pub fn next_step_index(&self) -> Result<i32, Error> {
Ok(self
.dispatch
.get(sequence_context::NEXT_STEP_INDEX)?
.as_i32()?)
}
pub fn previous_step_index(&self) -> Result<i32, Error> {
Ok(self
.dispatch
.get(sequence_context::PREVIOUS_STEP_INDEX)?
.as_i32()?)
}
pub fn set_next_step_index(&self, index: i32) -> Result<(), Error> {
self.dispatch.put(
sequence_context::NEXT_STEP_INDEX,
rs_teststand_sys::Value::I32(index),
)?;
Ok(())
}
pub fn set_previous_step_index(&self, index: i32) -> Result<(), Error> {
self.dispatch.put(
sequence_context::PREVIOUS_STEP_INDEX,
rs_teststand_sys::Value::I32(index),
)?;
Ok(())
}
pub fn loop_index(&self) -> Result<i32, Error> {
Ok(self.dispatch.get(sequence_context::LOOP_INDEX)?.as_i32()?)
}
pub fn set_loop_index(&self, index: i32) -> Result<(), Error> {
self.dispatch.put(
sequence_context::LOOP_INDEX,
rs_teststand_sys::Value::I32(index),
)?;
Ok(())
}
pub fn next_step(&self) -> Result<crate::Step, Error> {
Ok(crate::Step::new(
self.dispatch
.get(sequence_context::NEXT_STEP)?
.into_object()?,
))
}
pub fn previous_step(&self) -> Result<crate::Step, Error> {
Ok(crate::Step::new(
self.dispatch
.get(sequence_context::PREVIOUS_STEP)?
.into_object()?,
))
}
pub fn num_steps_executed(&self) -> Result<i32, Error> {
Ok(self
.dispatch
.get(sequence_context::NUM_STEPS_EXECUTED)?
.as_i32()?)
}
pub fn sequence_failed(&self) -> Result<bool, Error> {
Ok(self
.dispatch
.get(sequence_context::SEQUENCE_FAILED)?
.as_bool()?)
}
pub fn error_reported(&self) -> Result<bool, Error> {
Ok(self
.dispatch
.get(sequence_context::ERROR_REPORTED)?
.as_bool()?)
}
pub fn run_time_error_message(&self) -> Result<String, Error> {
Ok(self
.dispatch
.get(sequence_context::RUN_TIME_ERROR_MESSAGE)?
.into_string()?)
}
pub fn step(&self) -> Result<crate::Step, Error> {
Ok(crate::Step::new(
self.dispatch.get(sequence_context::STEP)?.into_object()?,
))
}
}